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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ffe382f7ba81b49db2b6d48c84dac2df231fdda7 | fe84e287c662151bb313504482b218a503b972f3 | /src/undergraduate/MAS114/Semester 2/Q01.lean | f0386ead5b8df094a22a84d3b43e2fbeeb0a77e3 | [] | no_license | NeilStrickland/lean_lib | 91e163f514b829c42fe75636407138b5c75cba83 | 6a9563de93748ace509d9db4302db6cd77d8f92c | refs/heads/master | 1,653,408,198,261 | 1,652,996,419,000 | 1,652,996,419,000 | 181,006,067 | 4 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 7,817 | lean | import data.fintype.basic
import algebra.power_mod
import group_theory.group_action
import algebra.group_power
import algebra.big_operators
import data.zmod.basic
import tactic.ring tactic.abel
import group_theory.self_map
import group_theory.action_instances
import group_theory.burnside_count
import group_theory.dihedral
import data.fin_extra
import data.enumeration
import order.lattice order.lattice_extra
open group_theory
namespace MAS114
namespace exercises_2
namespace Q01
def finset.mk' {α : Type*} (l : list α) (h : l.nodup) : finset α :=
finset.mk l h
lemma finset.eq_iff_veq {α : Type*} (s₀ s₁ : finset α) :
s₀ = s₁ ↔ s₀.val = s₁.val :=
⟨ λ h, by rw[h], λ h, finset.eq_of_veq h⟩
lemma finset.eq_iff_perm {α : Type*} (l₀ l₁ : list α) (h₀ : l₀.nodup) (h₁ : l₁.nodup) :
finset.mk' l₀ h₀ = finset.mk' l₁ h₁ ↔ list.perm l₀ l₁ :=
begin
rw [finset.eq_iff_veq],
change (l₀ : multiset α) = (l₁ : multiset α) ↔ _,
split,
exact quotient.exact,
exact @quotient.sound (list α) (list.is_setoid α) l₀ l₁
end
def X := (fin 4) × (fin 4)
namespace X
instance : decidable_eq X := by { dsimp [X], apply_instance }
instance : fintype X := by { dsimp [X], apply_instance }
instance : has_repr X := ⟨λ ij, ij.1.val.repr ++ ij.2.val.repr⟩
instance : distrib_lattice X := by { dsimp [X], apply_instance }
instance : bounded_order X := by { dsimp [X], apply_instance }
/-
instance : linear_order X :=
by { dsimp [X], exact lex_order }
-/
def s : self_map X := λ ij, ⟨ij.1, ij.2.reflect⟩
def r : self_map X := λ ij, ⟨ij.2.reflect, ij.1⟩
def p : dihedral.prehom 4 (self_map X) :=
begin
refine_struct {
r := r,
s := s
}; funext ij; rcases ij with ⟨i,j⟩;
simp [self_map.one_app, self_map.mul_app, r, s, pow_succ, fin.reflect_reflect];
refl
end
instance : mul_action (dihedral 4) X := self_map.mul_action_of_hom p.to_hom
lemma smul_s (ij : X) : (dihedral.s (0 : zmod 4)) • ij = ⟨ij.1, ij.2.reflect⟩ := rfl
lemma smul_r (ij : X) : (dihedral.r (1 : zmod 4)) • ij = ⟨ij.2.reflect, ij.1⟩ := rfl
def F : (finset (orbits (dihedral 4) X)) := finset.univ
def L (o : orbits (dihedral 4) X) : finset X :=
finset.univ.filter (λ x, o = orbit x)
#eval F.image L
end X
def Y := finset X
namespace Y
instance : decidable_eq Y := by { dsimp [Y], apply_instance }
instance : fintype Y := by { dsimp [Y], apply_instance }
instance : has_repr Y := by { dsimp [Y], apply_instance }
def bounding_box : Y → X × X :=
λ (xs : finset X), ⟨xs.inf id,xs.sup id⟩
def size (y : Y) : ℕ × ℕ :=
let b := y.bounding_box in prod.mk (b.2.1 - b.1.1) (b.2.2 - b.1.2)
def is_horizontal (y : Y) : bool := y.size.2 = 0
def is_vertical (y : Y) : bool := y.size.1 = 0
instance : mul_action (dihedral 4) Y :=
_root_.mul_action.finset_action
end Y
@[derive decidable_eq]
inductive Z_single
| H : (fin 3) → (fin 4) → Z_single
| V : (fin 4) → (fin 3) → Z_single
namespace Z_single
def to_string : Z_single → string
| (H i j) := "H" ++ i.val.repr ++ j.val.repr
| (V i j) := "V" ++ i.val.repr ++ j.val.repr
instance : has_repr Z_single := ⟨to_string⟩
def bounding_box : Z_single → X × X
| (H i j) := ⟨⟨i.inc,j⟩,⟨i.succ,j⟩⟩
| (V i j) := ⟨⟨i,j.inc⟩,⟨i,j.succ⟩⟩
def size : Z_single → ℕ × ℕ
| (H _ _) := ⟨1,0⟩
| (V _ _) := ⟨0,1⟩
instance : enumeration Z_single := {
elems :=
((enumeration.elems : list (fin 3)).bind
(λ i, (enumeration.elems : list (fin 4)).map (Z_single.H i))) ++
((enumeration.elems : list (fin 4)).bind
(λ i, (enumeration.elems : list (fin 3)).map (Z_single.V i))),
nodup := dec_trivial,
complete := λ z,
begin
cases z with i j i j; rw [list.mem_append],
{ left,
exact @list.mem_bind_of_mem (fin 3) Z_single (H i j)
(enumeration.elems : list (fin 3))
(λ i, (enumeration.elems : list (fin 4)).map (Z_single.H i))
i (enumeration.complete i)
(list.mem_map_of_mem (H i) (enumeration.complete j)) },
{ right,
exact @list.mem_bind_of_mem (fin 4) Z_single (V i j)
(enumeration.elems : list (fin 4))
(λ i, (enumeration.elems : list (fin 3)).map (Z_single.V i))
i (enumeration.complete i)
(list.mem_map_of_mem (V i) (enumeration.complete j)) },
end
}
def to_Y₀ : ∀ (z : Z_single), list X
| (H i j) := [prod.mk i.inc j, prod.mk i.succ j]
| (V i j) := [prod.mk i j.inc, prod.mk i j.succ]
lemma to_Y₀_nodup (z : Z_single) : z.to_Y₀.nodup :=
begin
have : ∀ {n : ℕ} (k : fin n), k.inc ≠ k.succ :=
λ n k, ne_of_lt k.inc_lt_succ,
cases z with i j i j; dsimp[to_Y₀];
simp [fin.eq_iff_veq,(nat.succ_ne_self i.val).symm, this]
end
def to_Y (z : Z_single) : Y := @finset.mk X z.to_Y₀ z.to_Y₀_nodup
lemma to_Y_card (z : Z_single) : z.to_Y.card = 2 :=
by { cases z with i j i j; refl }
lemma to_Y_bounding_box (z : Z_single) :
z.to_Y.bounding_box = z.bounding_box :=
begin
cases z with i j i j,
focus {
let u : X := ⟨i.inc,j⟩, let v : X := ⟨i.succ,j⟩,
have huv : u ≤ v := ⟨le_of_lt i.inc_lt_succ,le_refl j⟩, },
swap, focus
{ let u : X := ⟨i,j.inc⟩, let v : X := ⟨i,j.succ⟩,
have huv : u ≤ v := ⟨le_refl i,le_of_lt j.inc_lt_succ⟩ },
all_goals {
change prod.mk (u ⊓ (v ⊓ ⊤)) (u ⊔ (v ⊔ ⊥)) = ⟨u,v⟩,
rw [inf_top_eq, sup_bot_eq],
rw [inf_of_le_left huv, sup_of_le_right huv] }
end
lemma to_Y_size (z : Z_single) :
z.to_Y.size = z.size :=
begin
dsimp [Y.size], rw [to_Y_bounding_box],
rcases z with ⟨⟨i,hi⟩,⟨j,hj⟩⟩ | ⟨⟨i,hi⟩,⟨j,hj⟩⟩,
{ change prod.mk ((i + 1) - i) (j - j) = ⟨1,0⟩,
rw [nat.sub_self, nat.add_sub_cancel_left] },
{ change prod.mk (i - i) ((j + 1) - j) = ⟨0,1⟩,
rw [nat.sub_self, nat.add_sub_cancel_left] }
end
lemma to_Y_inj : function.injective to_Y :=
begin
intros z₀ z₁ he,
have hb := congr_arg Y.bounding_box he,
rw [to_Y_bounding_box, to_Y_bounding_box] at hb, clear he,
cases z₀ with i₀ j₀ i₀ j₀; cases z₁ with i₁ j₁ i₁ j₁,
all_goals {
simp only [bounding_box] at hb,
injection hb with hb₀ hb₁,
injection hb₀ with hb₂ hb₃,
injection hb₁ with hb₄ hb₅ },
{ replace hb₄ := fin.succ_inj.mp hb₄, cc },
{ exfalso, exact ne_of_lt (fin.inc_lt_succ i₀) (hb₂.trans hb₄.symm) },
{ exfalso, exact ne_of_lt (fin.inc_lt_succ j₀) (hb₃.trans hb₅.symm) },
{ replace hb₅ := fin.succ_inj.mp hb₅, cc }
end
def s : Z_single → Z_single
| (H i j) := H i j.reflect
| (V i j) := V i j.reflect
def r : Z_single → Z_single
| (H i j) := V j.reflect i
| (V i j) := H j.reflect i
lemma to_Y_s (z : Z_single) :
(s z).to_Y = (dihedral.s (0 : zmod 4)) • z.to_Y :=
begin
cases z with i j i j; dsimp[s, to_Y, to_Y₀] ;
change finset.mk (_ : multiset X) _ = _;
ext x;
simp only [
mul_action.mem_smul_finset', dihedral.s_inv,
finset.mem_mk, multiset.mem_coe,
list.mem_cons_iff, list.mem_singleton,
mul_action.smul_eq_iff_eq_smul_inv];
simp only [
fin.reflect_inc, fin.reflect_succ, X.smul_s, or_comm],
end
lemma to_Y_r (z : Z_single) :
(r z).to_Y = (dihedral.r (1 : zmod 4)) • z.to_Y :=
begin
cases z with i j i j; dsimp[s, to_Y, to_Y₀] ;
change finset.mk (([_,_] : list X) : multiset X) _ = _;
ext x;
simp only [
mul_action.mem_smul_finset', dihedral.r_inv, neg_neg,
finset.mem_mk, multiset.mem_coe,
list.mem_cons_iff, list.mem_singleton,
mul_action.smul_eq_iff_eq_smul_inv];
simp only [
fin.reflect_inc, fin.reflect_succ, X.smul_r, X.smul_r, or.comm],
end
end Z_single
end Q01
end exercises_2
end MAS114 |
69b70063ad93a542d733e0c5c782a850346a6735 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/elim2.lean | 7d51cf1a5ab13098e9ea4f4fb290c90585afdb7a | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 266 | lean | import logic
open tactic
constant p : num → num → num → Prop
axiom H1 : ∃ x y z, p x y z
axiom H2 : ∀ {x y z : num}, p x y z → p x x x
theorem tst : ∃ x, p x x x
:= obtain a b c H [visible], from H1,
by (apply exists_intro; apply H2; eassumption)
|
3cfdc753d5f1f961d13846d7f6fe51ff8c4abb9d | 80746c6dba6a866de5431094bf9f8f841b043d77 | /src/data/set/basic.lean | bca603e2ad9351b6f59e6f18f9c58178b1df3ddb | [
"Apache-2.0"
] | permissive | leanprover-fork/mathlib-backup | 8b5c95c535b148fca858f7e8db75a76252e32987 | 0eb9db6a1a8a605f0cf9e33873d0450f9f0ae9b0 | refs/heads/master | 1,585,156,056,139 | 1,548,864,430,000 | 1,548,864,438,000 | 143,964,213 | 0 | 0 | Apache-2.0 | 1,550,795,966,000 | 1,533,705,322,000 | Lean | UTF-8 | Lean | false | false | 46,635 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Leonardo de Moura
-/
import tactic.ext tactic.finish data.subtype tactic.interactive
open function
/- set coercion to a type -/
namespace set
instance {α : Type*} : has_coe_to_sort (set α) := ⟨_, λ s, {x // x ∈ s}⟩
end set
section set_coe
universe u
variables {α : Type u}
@[simp] theorem set.set_coe_eq_subtype (s : set α) :
coe_sort.{(u+1) (u+2)} s = {x // x ∈ s} := rfl
@[simp] theorem set_coe.forall {s : set α} {p : s → Prop} :
(∀ x : s, p x) ↔ (∀ x (h : x ∈ s), p ⟨x, h⟩) :=
subtype.forall
@[simp] theorem set_coe.exists {s : set α} {p : s → Prop} :
(∃ x : s, p x) ↔ (∃ x (h : x ∈ s), p ⟨x, h⟩) :=
subtype.exists
@[simp] theorem set_coe_cast : ∀ {s t : set α} (H' : s = t) (H : @eq (Type u) s t) (x : s),
cast H x = ⟨x.1, H' ▸ x.2⟩
| s _ rfl _ ⟨x, h⟩ := rfl
theorem set_coe.ext {s : set α} {a b : s} : (↑a : α) = ↑b → a = b :=
subtype.eq
theorem set_coe.ext_iff {s : set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
iff.intro set_coe.ext (assume h, h ▸ rfl)
end set_coe
lemma subtype.mem {α : Type*} {s : set α} (p : s) : (p : α) ∈ s := p.property
namespace set
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a : α} {s t : set α}
instance : inhabited (set α) := ⟨∅⟩
@[extensionality]
theorem ext {a b : set α} (h : ∀ x, x ∈ a ↔ x ∈ b) : a = b :=
funext (assume x, propext (h x))
theorem ext_iff (s t : set α) : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t :=
⟨begin intros h x, rw h end, ext⟩
@[trans] theorem mem_of_mem_of_subset {α : Type u} {x : α} {s t : set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
/- mem and set_of -/
@[simp] theorem mem_set_of_eq {a : α} {p : α → Prop} : a ∈ {a | p a} = p a := rfl
@[simp] theorem nmem_set_of_eq {a : α} {P : α → Prop} : a ∉ {a : α | P a} = ¬ P a := rfl
@[simp] theorem set_of_mem_eq {s : set α} : {x | x ∈ s} = s := rfl
theorem mem_def {a : α} {s : set α} : a ∈ s ↔ s a := iff.rfl
instance decidable_mem (s : set α) [H : decidable_pred s] : ∀ a, decidable (a ∈ s) := H
instance decidable_set_of (p : α → Prop) [H : decidable_pred p] : decidable_pred {a | p a} := H
@[simp] theorem set_of_subset_set_of {p q : α → Prop} : {a | p a} ⊆ {a | q a} ↔ (∀a, p a → q a) := iff.rfl
@[simp] lemma sep_set_of {α} {p q : α → Prop} : {a ∈ {a | p a } | q a} = {a | p a ∧ q a} :=
rfl
@[simp] lemma set_of_mem {α} {s : set α} : {a | a ∈ s} = s := rfl
/- subset -/
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def {s t : set α} : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl
@[refl] theorem subset.refl (a : set α) : a ⊆ a := assume x, id
@[trans] theorem subset.trans {a b c : set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c :=
assume x h, bc (ab h)
@[trans] theorem mem_of_eq_of_mem {α : Type u} {x y : α} {s : set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem subset.antisymm {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
ext (λ x, iff.intro (λ ina, h₁ ina) (λ inb, h₂ inb))
theorem subset.antisymm_iff {a b : set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨λ e, e ▸ ⟨subset.refl _, subset.refl _⟩,
λ ⟨h₁, h₂⟩, subset.antisymm h₁ h₂⟩
-- an alterantive name
theorem eq_of_subset_of_subset {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
subset.antisymm h₁ h₂
theorem mem_of_subset_of_mem {s₁ s₂ : set α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ :=
assume h₁ h₂, h₁ h₂
theorem not_subset : (¬ s ⊆ t) ↔ ∃a, a ∈ s ∧ a ∉ t :=
by simp [subset_def, classical.not_forall]
/- strict subset -/
/-- `s ⊂ t` means that `s` is a strict subset of `t`, that is, `s ⊆ t` but `s ≠ t`. -/
def strict_subset (s t : set α) := s ⊆ t ∧ s ≠ t
instance : has_ssubset (set α) := ⟨strict_subset⟩
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ s ≠ t) := rfl
lemma exists_of_ssubset {α : Type u} {s t : set α} (h : s ⊂ t) : (∃x∈t, x ∉ s) :=
classical.by_contradiction $ assume hn,
have t ⊆ s, from assume a hat, classical.by_contradiction $ assume has, hn ⟨a, hat, has⟩,
h.2 $ subset.antisymm h.1 this
lemma ssubset_iff_subset_not_subset {s t : set α} : s ⊂ t ↔ s ⊆ t ∧ ¬ t ⊆ s :=
by split; simp [set.ssubset_def, ne.def, set.subset.antisymm_iff] {contextual := tt}
theorem not_mem_empty (x : α) : ¬ (x ∈ (∅ : set α)) :=
assume h : x ∈ ∅, h
@[simp] theorem not_not_mem [decidable (a ∈ s)] : ¬ (a ∉ s) ↔ a ∈ s :=
not_not
/- empty set -/
theorem empty_def : (∅ : set α) = {x | false} := rfl
@[simp] theorem mem_empty_eq (x : α) : x ∈ (∅ : set α) = false := rfl
@[simp] theorem set_of_false : {a : α | false} = ∅ := rfl
theorem eq_empty_iff_forall_not_mem {s : set α} : s = ∅ ↔ ∀ x, x ∉ s :=
by simp [ext_iff]
theorem ne_empty_of_mem {s : set α} {x : α} (h : x ∈ s) : s ≠ ∅ :=
by { intro hs, rw hs at h, apply not_mem_empty _ h }
@[simp] theorem empty_subset (s : set α) : ∅ ⊆ s :=
assume x, assume h, false.elim h
theorem subset_empty_iff {s : set α} : s ⊆ ∅ ↔ s = ∅ :=
by simp [subset.antisymm_iff]
theorem eq_empty_of_subset_empty {s : set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
theorem ne_empty_iff_exists_mem {s : set α} : s ≠ ∅ ↔ ∃ x, x ∈ s :=
by haveI := classical.prop_decidable;
simp [eq_empty_iff_forall_not_mem]
theorem exists_mem_of_ne_empty {s : set α} : s ≠ ∅ → ∃ x, x ∈ s :=
ne_empty_iff_exists_mem.1
theorem coe_nonempty_iff_ne_empty {s : set α} : nonempty s ↔ s ≠ ∅ :=
nonempty_subtype.trans ne_empty_iff_exists_mem.symm
-- TODO: remove when simplifier stops rewriting `a ≠ b` to `¬ a = b`
theorem not_eq_empty_iff_exists {s : set α} : ¬ (s = ∅) ↔ ∃ x, x ∈ s :=
ne_empty_iff_exists_mem
theorem subset_eq_empty {s t : set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 $ e ▸ h
theorem subset_ne_empty {s t : set α} (h : t ⊆ s) : t ≠ ∅ → s ≠ ∅ :=
mt (subset_eq_empty h)
theorem ball_empty_iff {p : α → Prop} :
(∀ x ∈ (∅ : set α), p x) ↔ true :=
by simp [iff_def]
/- universal set -/
theorem univ_def : @univ α = {x | true} := rfl
@[simp] theorem mem_univ (x : α) : x ∈ @univ α := trivial
theorem empty_ne_univ [h : inhabited α] : (∅ : set α) ≠ univ :=
by simp [ext_iff]
@[simp] theorem subset_univ (s : set α) : s ⊆ univ := λ x H, trivial
theorem univ_subset_iff {s : set α} : univ ⊆ s ↔ s = univ :=
by simp [subset.antisymm_iff]
theorem eq_univ_of_univ_subset {s : set α} : univ ⊆ s → s = univ :=
univ_subset_iff.1
theorem eq_univ_iff_forall {s : set α} : s = univ ↔ ∀ x, x ∈ s :=
by simp [ext_iff]
theorem eq_univ_of_forall {s : set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2
@[simp] lemma univ_eq_empty_iff {α : Type*} : (univ : set α) = ∅ ↔ ¬ nonempty α :=
eq_empty_iff_forall_not_mem.trans ⟨λ H ⟨x⟩, H x trivial, λ H x _, H ⟨x⟩⟩
lemma nonempty_iff_univ_ne_empty {α : Type*} : nonempty α ↔ (univ : set α) ≠ ∅ :=
by classical; exact iff_not_comm.1 univ_eq_empty_iff
lemma exists_mem_of_nonempty (α) : ∀ [nonempty α], ∃x:α, x ∈ (univ : set α)
| ⟨x⟩ := ⟨x, trivial⟩
@[simp] lemma univ_ne_empty {α} [h : nonempty α] : (univ : set α) ≠ ∅ :=
λ e, univ_eq_empty_iff.1 e h
instance univ_decidable : decidable_pred (@set.univ α) :=
λ x, is_true trivial
/- union -/
theorem union_def {s₁ s₂ : set α} : s₁ ∪ s₂ = {a | a ∈ s₁ ∨ a ∈ s₂} := rfl
theorem mem_union_left {x : α} {a : set α} (b : set α) : x ∈ a → x ∈ a ∪ b := or.inl
theorem mem_union_right {x : α} {b : set α} (a : set α) : x ∈ b → x ∈ a ∪ b := or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H
theorem mem_union.elim {x : α} {a b : set α} {P : Prop}
(H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P :=
or.elim H₁ H₂ H₃
theorem mem_union (x : α) (a b : set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := iff.rfl
@[simp] theorem mem_union_eq (x : α) (a b : set α) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl
@[simp] theorem union_self (a : set α) : a ∪ a = a :=
ext (assume x, or_self _)
@[simp] theorem union_empty (a : set α) : a ∪ ∅ = a :=
ext (assume x, or_false _)
@[simp] theorem empty_union (a : set α) : ∅ ∪ a = a :=
ext (assume x, false_or _)
theorem union_comm (a b : set α) : a ∪ b = b ∪ a :=
ext (assume x, or.comm)
theorem union_assoc (a b c : set α) : (a ∪ b) ∪ c = a ∪ (b ∪ c) :=
ext (assume x, or.assoc)
instance union_is_assoc : is_associative (set α) (∪) :=
⟨union_assoc⟩
instance union_is_comm : is_commutative (set α) (∪) :=
⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
by finish
theorem union_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ :=
by finish
theorem union_eq_self_of_subset_left {s t : set α} (h : s ⊆ t) : s ∪ t = t :=
by finish [subset_def, ext_iff, iff_def]
theorem union_eq_self_of_subset_right {s t : set α} (h : t ⊆ s) : s ∪ t = s :=
by finish [subset_def, ext_iff, iff_def]
@[simp] theorem subset_union_left (s t : set α) : s ⊆ s ∪ t := λ x, or.inl
@[simp] theorem subset_union_right (s t : set α) : t ⊆ s ∪ t := λ x, or.inr
theorem union_subset {s t r : set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r :=
by finish [subset_def, union_def]
@[simp] theorem union_subset_iff {s t u : set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
by finish [iff_def, subset_def]
theorem union_subset_union {s₁ s₂ t₁ t₂ : set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ :=
by finish [subset_def]
theorem union_subset_union_left {s₁ s₂ : set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h (by refl)
theorem union_subset_union_right (s) {t₁ t₂ : set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union (by refl) h
@[simp] theorem union_empty_iff {s t : set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ :=
⟨by finish [ext_iff], by finish [ext_iff]⟩
/- intersection -/
theorem inter_def {s₁ s₂ : set α} : s₁ ∩ s₂ = {a | a ∈ s₁ ∧ a ∈ s₂} := rfl
theorem mem_inter_iff (x : α) (a b : set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := iff.rfl
@[simp] theorem mem_inter_eq (x : α) (a b : set α) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl
theorem mem_inter {x : α} {a b : set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
theorem mem_of_mem_inter_right {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
@[simp] theorem inter_self (a : set α) : a ∩ a = a :=
ext (assume x, and_self _)
@[simp] theorem inter_empty (a : set α) : a ∩ ∅ = ∅ :=
ext (assume x, and_false _)
@[simp] theorem empty_inter (a : set α) : ∅ ∩ a = ∅ :=
ext (assume x, false_and _)
theorem inter_comm (a b : set α) : a ∩ b = b ∩ a :=
ext (assume x, and.comm)
theorem inter_assoc (a b c : set α) : (a ∩ b) ∩ c = a ∩ (b ∩ c) :=
ext (assume x, and.assoc)
instance inter_is_assoc : is_associative (set α) (∩) :=
⟨inter_assoc⟩
instance inter_is_comm : is_commutative (set α) (∩) :=
⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
by finish
theorem inter_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ :=
by finish
@[simp] theorem inter_subset_left (s t : set α) : s ∩ t ⊆ s := λ x H, and.left H
@[simp] theorem inter_subset_right (s t : set α) : s ∩ t ⊆ t := λ x H, and.right H
theorem subset_inter {s t r : set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t :=
by finish [subset_def, inter_def]
@[simp] theorem subset_inter_iff {s t r : set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
⟨λ h, ⟨subset.trans h (inter_subset_left _ _), subset.trans h (inter_subset_right _ _)⟩,
λ ⟨h₁, h₂⟩, subset_inter h₁ h₂⟩
@[simp] theorem inter_univ (a : set α) : a ∩ univ = a :=
ext (assume x, and_true _)
@[simp] theorem univ_inter (a : set α) : univ ∩ a = a :=
ext (assume x, true_and _)
theorem inter_subset_inter_left {s t : set α} (u : set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
by finish [subset_def]
theorem inter_subset_inter_right {s t : set α} (u : set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
by finish [subset_def]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ :=
by finish [subset_def]
theorem inter_eq_self_of_subset_left {s t : set α} (h : s ⊆ t) : s ∩ t = s :=
by finish [subset_def, ext_iff, iff_def]
theorem inter_eq_self_of_subset_right {s t : set α} (h : t ⊆ s) : s ∩ t = t :=
by finish [subset_def, ext_iff, iff_def]
theorem union_inter_cancel_left {s t : set α} : (s ∪ t) ∩ s = s :=
by finish [ext_iff, iff_def]
theorem union_inter_cancel_right {s t : set α} : (s ∪ t) ∩ t = t :=
by finish [ext_iff, iff_def]
-- TODO(Mario): remove?
theorem nonempty_of_inter_nonempty_right {s t : set α} (h : s ∩ t ≠ ∅) : t ≠ ∅ :=
by finish [ext_iff, iff_def]
theorem nonempty_of_inter_nonempty_left {s t : set α} (h : s ∩ t ≠ ∅) : s ≠ ∅ :=
by finish [ext_iff, iff_def]
/- distributivity laws -/
theorem inter_distrib_left (s t u : set α) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
ext (assume x, and_or_distrib_left)
theorem inter_distrib_right (s t u : set α) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
ext (assume x, or_and_distrib_right)
theorem union_distrib_left (s t u : set α) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
ext (assume x, or_and_distrib_left)
theorem union_distrib_right (s t u : set α) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
ext (assume x, and_or_distrib_right)
/- insert -/
theorem insert_def (x : α) (s : set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl
@[simp] theorem insert_of_has_insert (x : α) (s : set α) : has_insert.insert x s = insert x s := rfl
@[simp] theorem subset_insert (x : α) (s : set α) : s ⊆ insert x s :=
assume y ys, or.inr ys
theorem mem_insert (x : α) (s : set α) : x ∈ insert x s :=
or.inl rfl
theorem mem_insert_of_mem {x : α} {s : set α} (y : α) : x ∈ s → x ∈ insert y s := or.inr
theorem eq_or_mem_of_mem_insert {x a : α} {s : set α} : x ∈ insert a s → x = a ∨ x ∈ s := id
theorem mem_of_mem_insert_of_ne {x a : α} {s : set α} (xin : x ∈ insert a s) : x ≠ a → x ∈ s :=
by finish [insert_def]
@[simp] theorem mem_insert_iff {x a : α} {s : set α} : x ∈ insert a s ↔ (x = a ∨ x ∈ s) := iff.rfl
@[simp] theorem insert_eq_of_mem {a : α} {s : set α} (h : a ∈ s) : insert a s = s :=
by finish [ext_iff, iff_def]
theorem insert_subset : insert a s ⊆ t ↔ (a ∈ t ∧ s ⊆ t) :=
by simp [subset_def, or_imp_distrib, forall_and_distrib]
theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t :=
assume a', or.imp_right (@h a')
theorem ssubset_insert {s : set α} {a : α} (h : a ∉ s) : s ⊂ insert a s :=
by finish [ssubset_def, ext_iff]
theorem insert_comm (a b : α) (s : set α) : insert a (insert b s) = insert b (insert a s) :=
ext $ by simp [or.left_comm]
theorem insert_union : insert a s ∪ t = insert a (s ∪ t) :=
ext $ assume a, by simp [or.comm, or.left_comm]
@[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) :=
ext $ assume a, by simp [or.comm, or.left_comm]
-- TODO(Jeremy): make this automatic
theorem insert_ne_empty (a : α) (s : set α) : insert a s ≠ ∅ :=
by safe [ext_iff, iff_def]; have h' := a_1 a; finish
-- useful in proofs by induction
theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : set α} (h : ∀ x, x ∈ insert a s → P x) :
∀ x, x ∈ s → P x :=
by finish
theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : set α} (h : ∀ x, x ∈ s → P x) (ha : P a) :
∀ x, x ∈ insert a s → P x :=
by finish
theorem ball_insert_iff {P : α → Prop} {a : α} {s : set α} :
(∀ x ∈ insert a s, P x) ↔ P a ∧ (∀x ∈ s, P x) :=
by finish [iff_def]
/- singletons -/
theorem singleton_def (a : α) : ({a} : set α) = insert a ∅ := rfl
@[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : set α) ↔ a = b :=
by finish [singleton_def]
-- TODO: again, annotation needed
@[simp] theorem mem_singleton (a : α) : a ∈ ({a} : set α) := by finish
theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : set α)) : x = y :=
by finish
@[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : set α) ↔ x = y :=
by finish [ext_iff, iff_def]
theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : set α) :=
by finish
theorem insert_eq (x : α) (s : set α) : insert x s = ({x} : set α) ∪ s :=
by finish [ext_iff, or_comm]
@[simp] theorem pair_eq_singleton (a : α) : ({a, a} : set α) = {a} :=
by finish
@[simp] theorem singleton_ne_empty (a : α) : ({a} : set α) ≠ ∅ := insert_ne_empty _ _
@[simp] theorem singleton_subset_iff {a : α} {s : set α} : {a} ⊆ s ↔ a ∈ s :=
⟨λh, h (by simp), λh b e, by simp at e; simp [*]⟩
theorem set_compr_eq_eq_singleton {a : α} : {b | b = a} = {a} :=
ext $ by simp
@[simp] theorem union_singleton : s ∪ {a} = insert a s :=
by simp [singleton_def]
@[simp] theorem singleton_union : {a} ∪ s = insert a s :=
by rw [union_comm, union_singleton]
theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s :=
by simp [eq_empty_iff_forall_not_mem]
theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s :=
by rw [inter_comm, singleton_inter_eq_empty]
/- separation -/
theorem mem_sep {s : set α} {p : α → Prop} {x : α} (xs : x ∈ s) (px : p x) : x ∈ {x ∈ s | p x} :=
⟨xs, px⟩
@[simp] theorem mem_sep_eq {s : set α} {p : α → Prop} {x : α} : x ∈ {x ∈ s | p x} = (x ∈ s ∧ p x) := rfl
theorem mem_sep_iff {s : set α} {p : α → Prop} {x : α} : x ∈ {x ∈ s | p x} ↔ x ∈ s ∧ p x :=
iff.rfl
theorem eq_sep_of_subset {s t : set α} (ssubt : s ⊆ t) : s = {x ∈ t | x ∈ s} :=
by finish [ext_iff, iff_def, subset_def]
theorem sep_subset (s : set α) (p : α → Prop) : {x ∈ s | p x} ⊆ s :=
assume x, and.left
theorem forall_not_of_sep_empty {s : set α} {p : α → Prop} (h : {x ∈ s | p x} = ∅) :
∀ x ∈ s, ¬ p x :=
by finish [ext_iff]
@[simp] lemma sep_univ {α} {p : α → Prop} : {a ∈ (univ : set α) | p a} = {a | p a} :=
set.ext $ by simp
/- complement -/
theorem mem_compl {s : set α} {x : α} (h : x ∉ s) : x ∈ -s := h
lemma compl_set_of {α} (p : α → Prop) : - {a | p a} = { a | ¬ p a } := rfl
theorem not_mem_of_mem_compl {s : set α} {x : α} (h : x ∈ -s) : x ∉ s := h
@[simp] theorem mem_compl_eq (s : set α) (x : α) : x ∈ -s = (x ∉ s) := rfl
theorem mem_compl_iff (s : set α) (x : α) : x ∈ -s ↔ x ∉ s := iff.rfl
@[simp] theorem inter_compl_self (s : set α) : s ∩ -s = ∅ :=
by finish [ext_iff]
@[simp] theorem compl_inter_self (s : set α) : -s ∩ s = ∅ :=
by finish [ext_iff]
@[simp] theorem compl_empty : -(∅ : set α) = univ :=
by finish [ext_iff]
@[simp] theorem compl_union (s t : set α) : -(s ∪ t) = -s ∩ -t :=
by finish [ext_iff]
@[simp] theorem compl_compl (s : set α) : -(-s) = s :=
by finish [ext_iff]
-- ditto
theorem compl_inter (s t : set α) : -(s ∩ t) = -s ∪ -t :=
by finish [ext_iff]
@[simp] theorem compl_univ : -(univ : set α) = ∅ :=
by finish [ext_iff]
theorem union_eq_compl_compl_inter_compl (s t : set α) : s ∪ t = -(-s ∩ -t) :=
by simp [compl_inter, compl_compl]
theorem inter_eq_compl_compl_union_compl (s t : set α) : s ∩ t = -(-s ∪ -t) :=
by simp [compl_compl]
@[simp] theorem union_compl_self (s : set α) : s ∪ -s = univ :=
by finish [ext_iff]
@[simp] theorem compl_union_self (s : set α) : -s ∪ s = univ :=
by finish [ext_iff]
theorem compl_comp_compl : compl ∘ compl = @id (set α) :=
funext compl_compl
theorem compl_subset_comm {s t : set α} : -s ⊆ t ↔ -t ⊆ s :=
by haveI := classical.prop_decidable; exact
forall_congr (λ a, not_imp_comm)
lemma compl_subset_compl {s t : set α} : -s ⊆ -t ↔ t ⊆ s :=
by rw [compl_subset_comm, compl_compl]
theorem compl_subset_iff_union {s t : set α} : -s ⊆ t ↔ s ∪ t = univ :=
iff.symm $ eq_univ_iff_forall.trans $ forall_congr $ λ a,
by haveI := classical.prop_decidable; exact or_iff_not_imp_left
theorem subset_compl_comm {s t : set α} : s ⊆ -t ↔ t ⊆ -s :=
forall_congr $ λ a, imp_not_comm
theorem subset_compl_iff_disjoint {s t : set α} : s ⊆ -t ↔ s ∩ t = ∅ :=
iff.trans (forall_congr $ λ a, and_imp.symm) subset_empty_iff
/- set difference -/
theorem diff_eq (s t : set α) : s \ t = s ∩ -t := rfl
@[simp] theorem mem_diff {s t : set α} (x : α) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := iff.rfl
theorem mem_diff_of_mem {s t : set α} {x : α} (h1 : x ∈ s) (h2 : x ∉ t) : x ∈ s \ t :=
⟨h1, h2⟩
theorem mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
theorem not_mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
theorem union_diff_cancel {s t : set α} (h : s ⊆ t) : s ∪ (t \ s) = t :=
by finish [ext_iff, iff_def, subset_def]
theorem union_diff_cancel_left {s t : set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
by finish [ext_iff, iff_def, subset_def]
theorem union_diff_cancel_right {s t : set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
by finish [ext_iff, iff_def, subset_def]
theorem union_diff_left {s t : set α} : (s ∪ t) \ s = t \ s :=
by finish [ext_iff, iff_def]
theorem union_diff_right {s t : set α} : (s ∪ t) \ t = s \ t :=
by finish [ext_iff, iff_def]
theorem union_diff_distrib {s t u : set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
inter_distrib_right _ _ _
theorem inter_diff_assoc (a b c : set α) : (a ∩ b) \ c = a ∩ (b \ c) :=
inter_assoc _ _ _
theorem inter_diff_self (a b : set α) : a ∩ (b \ a) = ∅ :=
by finish [ext_iff]
theorem inter_union_diff (s t : set α) : (s ∩ t) ∪ (s \ t) = s :=
by finish [ext_iff, iff_def]
theorem diff_subset (s t : set α) : s \ t ⊆ s :=
by finish [subset_def]
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
by finish [subset_def]
theorem diff_subset_diff_left {s₁ s₂ t : set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
diff_subset_diff h (by refl)
theorem diff_subset_diff_right {s t u : set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
diff_subset_diff (subset.refl s) h
theorem compl_eq_univ_diff (s : set α) : -s = univ \ s :=
by finish [ext_iff]
@[simp] lemma empty_diff {α : Type*} (s : set α) : (∅ \ s : set α) = ∅ :=
eq_empty_of_subset_empty $ assume x ⟨hx, _⟩, hx
theorem diff_eq_empty {s t : set α} : s \ t = ∅ ↔ s ⊆ t :=
⟨assume h x hx, classical.by_contradiction $ assume : x ∉ t, show x ∈ (∅ : set α), from h ▸ ⟨hx, this⟩,
assume h, eq_empty_of_subset_empty $ assume x ⟨hx, hnx⟩, hnx $ h hx⟩
@[simp] theorem diff_empty {s : set α} : s \ ∅ = s :=
ext $ assume x, ⟨assume ⟨hx, _⟩, hx, assume h, ⟨h, not_false⟩⟩
theorem diff_diff {u : set α} : s \ t \ u = s \ (t ∪ u) :=
ext $ by simp [not_or_distrib, and.comm, and.left_comm]
lemma diff_subset_iff {s t u : set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
⟨assume h x xs, classical.by_cases or.inl (assume nxt, or.inr (h ⟨xs, nxt⟩)),
assume h x ⟨xs, nxt⟩, or.resolve_left (h xs) nxt⟩
lemma diff_subset_comm {s t u : set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
by rw [diff_subset_iff, diff_subset_iff, union_comm]
@[simp] theorem insert_diff (h : a ∈ t) : insert a s \ t = s \ t :=
ext $ by intro; constructor; simp [or_imp_distrib, h] {contextual := tt}
theorem union_diff_self {s t : set α} : s ∪ (t \ s) = s ∪ t :=
by finish [ext_iff, iff_def]
theorem diff_union_self {s t : set α} : (s \ t) ∪ t = s ∪ t :=
by rw [union_comm, union_diff_self, union_comm]
theorem diff_inter_self {a b : set α} : (b \ a) ∩ a = ∅ :=
ext $ by simp [iff_def] {contextual:=tt}
theorem diff_eq_self {s t : set α} : s \ t = s ↔ t ∩ s ⊆ ∅ :=
by finish [ext_iff, iff_def, subset_def]
@[simp] theorem diff_singleton_eq_self {a : α} {s : set α} (h : a ∉ s) : s \ {a} = s :=
diff_eq_self.2 $ by simp [singleton_inter_eq_empty.2 h]
@[simp] theorem insert_diff_singleton {a : α} {s : set α} :
insert a (s \ {a}) = insert a s :=
by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union]
@[simp] lemma diff_self {s : set α} : s \ s = ∅ := ext $ by simp
/- powerset -/
theorem mem_powerset {x s : set α} (h : x ⊆ s) : x ∈ powerset s := h
theorem subset_of_mem_powerset {x s : set α} (h : x ∈ powerset s) : x ⊆ s := h
theorem mem_powerset_iff (x s : set α) : x ∈ powerset s ↔ x ⊆ s := iff.rfl
/- inverse image -/
/-- The preimage of `s : set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : set β) : set α := {x | f x ∈ s}
infix ` ⁻¹' `:80 := preimage
section preimage
variables {f : α → β} {g : β → γ}
@[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl
@[simp] theorem mem_preimage_eq {s : set β} {a : α} : (a ∈ f ⁻¹' s) = (f a ∈ s) := rfl
theorem preimage_mono {s t : set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t :=
assume x hx, h hx
@[simp] theorem preimage_univ : f ⁻¹' univ = univ := rfl
@[simp] theorem preimage_inter {s t : set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl
@[simp] theorem preimage_union {s t : set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl
@[simp] theorem preimage_compl {s : set β} : f ⁻¹' (- s) = - (f ⁻¹' s) := rfl
@[simp] theorem preimage_diff (f : α → β) (s t : set β) :
f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl
@[simp] theorem preimage_set_of_eq {p : α → Prop} {f : β → α} : f ⁻¹' {a | p a} = {a | p (f a)} :=
rfl
theorem preimage_id {s : set α} : id ⁻¹' s = s := rfl
theorem preimage_comp {s : set γ} : (g ∘ f) ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : set (subtype p)} {t : set α} :
s = subtype.val ⁻¹' t ↔ (∀x (h : p x), (⟨x, h⟩ : subtype p) ∈ s ↔ x ∈ t) :=
⟨assume s_eq x h, by rw [s_eq]; simp,
assume h, ext $ assume ⟨x, hx⟩, by simp [h]⟩
end preimage
/- function image -/
section image
infix ` '' `:80 := image
/-- Two functions `f₁ f₂ : α → β` are equal on `s`
if `f₁ x = f₂ x` for all `x ∈ a`. -/
@[reducible] def eq_on (f1 f2 : α → β) (a : set α) : Prop :=
∀ x ∈ a, f1 x = f2 x
-- TODO(Jeremy): use bounded exists in image
theorem mem_image_iff_bex {f : α → β} {s : set α} {y : β} :
y ∈ f '' s ↔ ∃ x (_ : x ∈ s), f x = y := bex_def.symm
theorem mem_image_eq (f : α → β) (s : set α) (y: β) : y ∈ f '' s = ∃ x, x ∈ s ∧ f x = y := rfl
@[simp] theorem mem_image (f : α → β) (s : set α) (y : β) : y ∈ f '' s ↔ ∃ x, x ∈ s ∧ f x = y := iff.rfl
theorem mem_image_of_mem (f : α → β) {x : α} {a : set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
theorem mem_image_of_injective {f : α → β} {a : α} {s : set α} (hf : injective f) :
f a ∈ f '' s ↔ a ∈ s :=
iff.intro
(assume ⟨b, hb, eq⟩, (hf eq) ▸ hb)
(assume h, mem_image_of_mem _ h)
theorem ball_image_of_ball {f : α → β} {s : set α} {p : β → Prop}
(h : ∀ x ∈ s, p (f x)) : ∀ y ∈ f '' s, p y :=
by finish [mem_image_eq]
@[simp] theorem ball_image_iff {f : α → β} {s : set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ (∀ x ∈ s, p (f x)) :=
iff.intro
(assume h a ha, h _ $ mem_image_of_mem _ ha)
(assume h b ⟨a, ha, eq⟩, eq ▸ h a ha)
theorem mono_image {f : α → β} {s t : set α} (h : s ⊆ t) : f '' s ⊆ f '' t :=
assume x ⟨y, hy, y_eq⟩, y_eq ▸ mem_image_of_mem _ $ h hy
theorem mem_image_elim {f : α → β} {s : set α} {C : β → Prop} (h : ∀ (x : α), x ∈ s → C (f x)) :
∀{y : β}, y ∈ f '' s → C y
| ._ ⟨a, a_in, rfl⟩ := h a a_in
theorem mem_image_elim_on {f : α → β} {s : set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ (x : α), x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
@[congr] lemma image_congr {f g : α → β} {s : set α}
(h : ∀a∈s, f a = g a) : f '' s = g '' s :=
by safe [ext_iff, iff_def]
theorem image_eq_image_of_eq_on {f₁ f₂ : α → β} {s : set α} (heq : eq_on f₁ f₂ s) :
f₁ '' s = f₂ '' s :=
image_congr heq
theorem image_comp (f : β → γ) (g : α → β) (a : set α) : (f ∘ g) '' a = f '' (g '' a) :=
subset.antisymm
(ball_image_of_ball $ assume a ha, mem_image_of_mem _ $ mem_image_of_mem _ ha)
(ball_image_of_ball $ ball_image_of_ball $ assume a ha, mem_image_of_mem _ ha)
/- Proof is removed as it uses generated names
TODO(Jeremy): make automatic,
begin
safe [ext_iff, iff_def, mem_image, (∘)],
have h' := h_2 (g a_2),
finish
end -/
theorem image_subset {a b : set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b :=
by finish [subset_def, mem_image_eq]
theorem image_union (f : α → β) (s t : set α) :
f '' (s ∪ t) = f '' s ∪ f '' t :=
by finish [ext_iff, iff_def, mem_image_eq]
@[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := ext $ by simp
theorem image_inter_on {f : α → β} {s t : set α} (h : ∀x∈t, ∀y∈s, f x = f y → x = y) :
f '' s ∩ f '' t = f '' (s ∩ t) :=
subset.antisymm
(assume b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩,
have a₂ = a₁, from h _ ha₂ _ ha₁ (by simp *),
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩)
(subset_inter (mono_image $ inter_subset_left _ _) (mono_image $ inter_subset_right _ _))
theorem image_inter {f : α → β} {s t : set α} (H : injective f) :
f '' s ∩ f '' t = f '' (s ∩ t) :=
image_inter_on (assume x _ y _ h, H h)
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : surjective f) : f '' univ = univ :=
eq_univ_of_forall $ by simp [image]; exact H
@[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} :=
ext $ λ x, by simp [image]; rw eq_comm
@[simp] lemma image_eq_empty {α β} {f : α → β} {s : set α} : f '' s = ∅ ↔ s = ∅ :=
by simp only [eq_empty_iff_forall_not_mem]; exact
⟨λ H a ha, H _ ⟨_, ha, rfl⟩, λ H b ⟨_, ha, _⟩, H _ ha⟩
lemma inter_singleton_ne_empty {α : Type*} {s : set α} {a : α} : s ∩ {a} ≠ ∅ ↔ a ∈ s :=
by finish [set.inter_singleton_eq_empty]
theorem fix_set_compl (t : set α) : compl t = - t := rfl
-- TODO(Jeremy): there is an issue with - t unfolding to compl t
theorem mem_compl_image (t : set α) (S : set (set α)) :
t ∈ compl '' S ↔ -t ∈ S :=
begin
suffices : ∀ x, -x = t ↔ -t = x, {simp [fix_set_compl, this]},
intro x, split; { intro e, subst e, simp }
end
@[simp] theorem image_id (s : set α) : id '' s = s := ext $ by simp
theorem compl_compl_image (S : set (set α)) :
compl '' (compl '' S) = S :=
by rw [← image_comp, compl_comp_compl, image_id]
theorem image_insert_eq {f : α → β} {a : α} {s : set α} :
f '' (insert a s) = insert (f a) (f '' s) :=
ext $ by simp [and_or_distrib_left, exists_or_distrib, eq_comm, or_comm, and_comm]
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set α) : f '' s ⊆ g ⁻¹' s :=
λ b ⟨a, h, e⟩, e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set β) : f ⁻¹' s ⊆ g '' s :=
λ b h, ⟨f b, h, I b⟩
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
image f = preimage g :=
funext $ λ s, subset.antisymm
(image_subset_preimage_of_inverse h₁ s)
(preimage_subset_image_of_inverse h₂ s)
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : set α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
b ∈ f '' s ↔ g b ∈ s :=
by rw image_eq_preimage_of_inverse h₁ h₂; refl
theorem image_compl_subset {f : α → β} {s : set α} (H : injective f) : f '' -s ⊆ -(f '' s) :=
subset_compl_iff_disjoint.2 $ by simp [image_inter H]
theorem subset_image_compl {f : α → β} {s : set α} (H : surjective f) : -(f '' s) ⊆ f '' -s :=
compl_subset_iff_union.2 $
by rw ← image_union; simp [image_univ_of_surjective H]
theorem image_compl_eq {f : α → β} {s : set α} (H : bijective f) : f '' -s = -(f '' s) :=
subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
/- image and preimage are a Galois connection -/
theorem image_subset_iff {s : set α} {t : set β} {f : α → β} :
f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
theorem image_preimage_subset (f : α → β) (s : set β) :
f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 (subset.refl _)
theorem subset_preimage_image (f : α → β) (s : set α) :
s ⊆ f ⁻¹' (f '' s) :=
λ x, mem_image_of_mem f
theorem preimage_image_eq {f : α → β} (s : set α) (h : injective f) : f ⁻¹' (f '' s) = s :=
subset.antisymm
(λ x ⟨y, hy, e⟩, h e ▸ hy)
(subset_preimage_image f s)
theorem image_preimage_eq {f : α → β} {s : set β} (h : surjective f) : f '' (f ⁻¹' s) = s :=
subset.antisymm
(image_preimage_subset f s)
(λ x hx, let ⟨y, e⟩ := h x in ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩)
lemma preimage_eq_preimage {f : β → α} (hf : surjective f) : f ⁻¹' s = preimage f t ↔ s = t :=
iff.intro
(assume eq, by rw [← @image_preimage_eq β α f s hf, ← @image_preimage_eq β α f t hf, eq])
(assume eq, eq ▸ rfl)
lemma surjective_preimage {f : β → α} (hf : surjective f) : injective (preimage f) :=
assume s t, (preimage_eq_preimage hf).1
theorem compl_image : image (@compl α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
theorem compl_image_set_of {α : Type u} {p : set α → Prop} :
compl '' {x | p x} = {x | p (- x)} :=
congr_fun compl_image p
theorem inter_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) :=
λ x h, ⟨mem_image_of_mem _ h.left, h.right⟩
theorem union_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) :=
λ x h, or.elim h (λ l, or.inl $ mem_image_of_mem _ l) (λ r, or.inr r)
theorem subset_image_union (f : α → β) (s : set α) (t : set β) :
f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
lemma subtype_val_image {p : α → Prop} {s : set (subtype p)} :
subtype.val '' s = {x | ∃h : p x, (⟨x, h⟩ : subtype p) ∈ s} :=
ext $ assume a,
⟨assume ⟨⟨a', ha'⟩, in_s, h_eq⟩, h_eq ▸ ⟨ha', in_s⟩,
assume ⟨ha, in_s⟩, ⟨⟨a, ha⟩, in_s, rfl⟩⟩
lemma preimage_subset_iff {A : set α} {B : set β} {f : α → β} :
f⁻¹' B ⊆ A ↔ (∀ a : α, f a ∈ B → a ∈ A) := iff.rfl
lemma image_eq_image {f : α → β} (hf : injective f) : f '' s = f '' t ↔ s = t :=
iff.symm $ iff.intro (assume eq, eq ▸ rfl) $ assume eq,
by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
lemma image_subset_image_iff {f : α → β} (hf : injective f) : f '' s ⊆ f '' t ↔ s ⊆ t :=
begin
refine (iff.symm $ iff.intro (image_subset f) $ assume h, _),
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf],
exact preimage_mono h
end
lemma injective_image {f : α → β} (hf : injective f) : injective (('') f) :=
assume s t, (image_eq_image hf).1
lemma prod_quotient_preimage_eq_image [s : setoid α] (g : quotient s → β) {h : α → β}
(Hh : h = g ∘ quotient.mk) (r : set (β × β)) :
{x : quotient s × quotient s | (g x.1, g x.2) ∈ r} =
(λ a : α × α, (⟦a.1⟧, ⟦a.2⟧)) '' ((λ a : α × α, (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸ set.ext (λ ⟨a₁, a₂⟩, ⟨quotient.induction_on₂ a₁ a₂
(λ a₁ a₂ h, ⟨(a₁, a₂), h, rfl⟩),
λ ⟨⟨b₁, b₂⟩, h₁, h₂⟩, show (g a₁, g a₂) ∈ r, from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := prod.ext_iff.1 h₂,
h₃.1 ▸ h₃.2 ▸ h₁⟩)
def image_factorization (f : α → β) (s : set α) : s → f '' s :=
λ p, ⟨f p.1, mem_image_of_mem f p.2⟩
lemma image_factorization_eq {f : α → β} {s : set α} :
subtype.val ∘ image_factorization f s = f ∘ subtype.val :=
funext $ λ p, rfl
lemma surjective_onto_image {f : α → β} {s : set α} :
surjective (image_factorization f s) :=
λ ⟨_, ⟨a, ha, rfl⟩⟩, ⟨⟨a, ha⟩, rfl⟩
end image
theorem univ_eq_true_false : univ = ({true, false} : set Prop) :=
eq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp)
section range
variables {f : ι → α}
open function
/-- Range of a function.
This function is more flexible than `f '' univ`, as the image requires that the domain is in Type
and not an arbitrary Sort. -/
def range (f : ι → α) : set α := {x | ∃y, f y = x}
@[simp] theorem mem_range {x : α} : x ∈ range f ↔ ∃ y, f y = x := iff.rfl
theorem mem_range_self (i : ι) : f i ∈ range f := ⟨i, rfl⟩
theorem forall_range_iff {p : α → Prop} : (∀ a ∈ range f, p a) ↔ (∀ i, p (f i)) :=
⟨assume h i, h (f i) (mem_range_self _), assume h a ⟨i, (hi : f i = a)⟩, hi ▸ h i⟩
theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ (∃ i, p (f i)) :=
⟨assume ⟨a, ⟨i, eq⟩, h⟩, ⟨i, eq.symm ▸ h⟩, assume ⟨i, h⟩, ⟨f i, mem_range_self _, h⟩⟩
theorem range_iff_surjective : range f = univ ↔ surjective f :=
eq_univ_iff_forall
@[simp] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id
@[simp] theorem image_univ {ι : Type*} {f : ι → β} : f '' univ = range f :=
ext $ by simp [image, range]
theorem image_subset_range {ι : Type*} (f : ι → β) (s : set ι) : f '' s ⊆ range f :=
by rw ← image_univ; exact image_subset _ (subset_univ _)
theorem range_comp {g : α → β} : range (g ∘ f) = g '' range f :=
subset.antisymm
(forall_range_iff.mpr $ assume i, mem_image_of_mem g (mem_range_self _))
(ball_image_iff.mpr $ forall_range_iff.mpr mem_range_self)
theorem range_subset_iff {ι : Type*} {f : ι → β} {s : set β} : range f ⊆ s ↔ ∀ y, f y ∈ s :=
forall_range_iff
lemma nonempty_of_nonempty_range {α : Type*} {β : Type*} {f : α → β} (H : ¬range f = ∅) : nonempty α :=
begin
cases exists_mem_of_ne_empty H with x h,
cases mem_range.1 h with y _,
exact ⟨y⟩
end
@[simp] lemma range_eq_empty {α : Type u} {β : Type v} {f : α → β} : range f = ∅ ↔ ¬ nonempty α :=
by rw ← set.image_univ; simp [-set.image_univ]
theorem image_preimage_eq_inter_range {f : α → β} {t : set β} :
f '' (f ⁻¹' t) = t ∩ range f :=
ext $ assume x, ⟨assume ⟨x, hx, heq⟩, heq ▸ ⟨hx, mem_range_self _⟩,
assume ⟨hx, ⟨y, h_eq⟩⟩, h_eq ▸ mem_image_of_mem f $
show y ∈ f ⁻¹' t, by simp [preimage, h_eq, hx]⟩
lemma image_preimage_eq_of_subset {f : α → β} {s : set β} (hs : s ⊆ range f) :
f '' (f ⁻¹' s) = s :=
by rw [image_preimage_eq_inter_range, inter_eq_self_of_subset_left hs]
theorem preimage_inter_range {f : α → β} {s : set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s :=
set.ext $ λ x, and_iff_left ⟨x, rfl⟩
theorem preimage_image_preimage {f : α → β} {s : set β} :
f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s :=
by rw [image_preimage_eq_inter_range, preimage_inter_range]
@[simp] theorem quot_mk_range_eq [setoid α] : range (λx : α, ⟦x⟧) = univ :=
range_iff_surjective.2 quot.exists_rep
@[simp] lemma subtype_val_range {p : α → Prop} :
range (@subtype.val _ p) = {x | p x} :=
by rw ← image_univ; simp [-image_univ, subtype_val_image]
@[simp] lemma range_coe_subtype (s : set α): range (coe : s → α) = s :=
subtype_val_range
lemma range_const_subset {c : β} : range (λx:α, c) ⊆ {c} :=
range_subset_iff.2 $ λ x, or.inl rfl
@[simp] lemma range_const [h : nonempty α] {c : β} : range (λx:α, c) = {c} :=
begin
refine subset.antisymm range_const_subset (λy hy, _),
rw set.mem_singleton_iff.1 hy,
rcases exists_mem_of_nonempty α with ⟨x, _⟩,
exact mem_range_self x
end
def range_factorization (f : ι → β) : ι → range f :=
λ i, ⟨f i, mem_range_self i⟩
lemma range_factorization_eq {f : ι → β} :
subtype.val ∘ range_factorization f = f :=
funext $ λ i, rfl
lemma surjective_onto_range : surjective (range_factorization f) :=
λ ⟨_, ⟨i, rfl⟩⟩, ⟨i, rfl⟩
end range
/-- The set `s` is pairwise `r` if `r x y` for all *distinct* `x y ∈ s`. -/
def pairwise_on (s : set α) (r : α → α → Prop) := ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r x y
theorem pairwise_on.mono {s t : set α} {r}
(h : t ⊆ s) (hp : pairwise_on s r) : pairwise_on t r :=
λ x xt y yt, hp x (h xt) y (h yt)
theorem pairwise_on.mono' {s : set α} {r r' : α → α → Prop}
(H : ∀ a b, r a b → r' a b) (hp : pairwise_on s r) : pairwise_on s r' :=
λ x xs y ys h, H _ _ (hp x xs y ys h)
end set
namespace set
section prod
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables {s s₁ s₂ : set α} {t t₁ t₂ : set β}
/-- The cartesian product `prod s t` is the set of `(a, b)`
such that `a ∈ s` and `b ∈ t`. -/
protected def prod (s : set α) (t : set β) : set (α × β) :=
{p | p.1 ∈ s ∧ p.2 ∈ t}
lemma prod_eq (s : set α) (t : set β) : set.prod s t = prod.fst ⁻¹' s ∩ prod.snd ⁻¹' t := rfl
theorem mem_prod_eq {p : α × β} : p ∈ set.prod s t = (p.1 ∈ s ∧ p.2 ∈ t) := rfl
@[simp] theorem mem_prod {p : α × β} : p ∈ set.prod s t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
lemma mk_mem_prod {a : α} {b : β} (a_in : a ∈ s) (b_in : b ∈ t) : (a, b) ∈ set.prod s t := ⟨a_in, b_in⟩
@[simp] theorem prod_empty {s : set α} : set.prod s ∅ = (∅ : set (α × β)) :=
ext $ by simp [set.prod]
@[simp] theorem empty_prod {t : set β} : set.prod ∅ t = (∅ : set (α × β)) :=
ext $ by simp [set.prod]
theorem insert_prod {a : α} {s : set α} {t : set β} :
set.prod (insert a s) t = (prod.mk a '' t) ∪ set.prod s t :=
ext begin simp [set.prod, image, iff_def, or_imp_distrib] {contextual := tt}; cc end
theorem prod_insert {b : β} {s : set α} {t : set β} :
set.prod s (insert b t) = ((λa, (a, b)) '' s) ∪ set.prod s t :=
ext begin simp [set.prod, image, iff_def, or_imp_distrib] {contextual := tt}; cc end
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
set.prod (preimage f s) (preimage g t) = preimage (λp, (f p.1, g p.2)) (set.prod s t) := rfl
theorem prod_mono {s₁ s₂ : set α} {t₁ t₂ : set β} (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) :
set.prod s₁ t₁ ⊆ set.prod s₂ t₂ :=
assume x ⟨h₁, h₂⟩, ⟨hs h₁, ht h₂⟩
theorem prod_inter_prod : set.prod s₁ t₁ ∩ set.prod s₂ t₂ = set.prod (s₁ ∩ s₂) (t₁ ∩ t₂) :=
subset.antisymm
(assume ⟨a, b⟩ ⟨⟨ha₁, hb₁⟩, ⟨ha₂, hb₂⟩⟩, ⟨⟨ha₁, ha₂⟩, ⟨hb₁, hb₂⟩⟩)
(subset_inter
(prod_mono (inter_subset_left _ _) (inter_subset_left _ _))
(prod_mono (inter_subset_right _ _) (inter_subset_right _ _)))
theorem image_swap_prod : (λp:β×α, (p.2, p.1)) '' set.prod t s = set.prod s t :=
ext $ assume ⟨a, b⟩, by simp [mem_image_eq, set.prod, and_comm]; exact
⟨ assume ⟨b', a', ⟨h_a, h_b⟩, h⟩, by subst a'; subst b'; assumption,
assume h, ⟨b, a, ⟨rfl, rfl⟩, h⟩⟩
theorem image_swap_eq_preimage_swap : image (@prod.swap α β) = preimage prod.swap :=
image_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
set.prod (image m₁ s) (image m₂ t) = image (λp:α×β, (m₁ p.1, m₂ p.2)) (set.prod s t) :=
ext $ by simp [-exists_and_distrib_right, exists_and_distrib_right.symm, and.left_comm, and.assoc, and.comm]
theorem prod_range_range_eq {α β γ δ} {m₁ : α → γ} {m₂ : β → δ} :
set.prod (range m₁) (range m₂) = range (λp:α×β, (m₁ p.1, m₂ p.2)) :=
ext $ by simp [range]
@[simp] theorem prod_singleton_singleton {a : α} {b : β} :
set.prod {a} {b} = ({(a, b)} : set (α×β)) :=
ext $ by simp [set.prod]
theorem prod_neq_empty_iff {s : set α} {t : set β} :
set.prod s t ≠ ∅ ↔ (s ≠ ∅ ∧ t ≠ ∅) :=
by simp [not_eq_empty_iff_exists]
@[simp] theorem prod_mk_mem_set_prod_eq {a : α} {b : β} {s : set α} {t : set β} :
(a, b) ∈ set.prod s t = (a ∈ s ∧ b ∈ t) := rfl
@[simp] theorem univ_prod_univ : set.prod (@univ α) (@univ β) = univ :=
ext $ assume ⟨a, b⟩, by simp
lemma prod_sub_preimage_iff {W : set γ} {f : α × β → γ} :
set.prod s t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W :=
by simp [subset_def]
end prod
section pi
variables {α : Type*} {π : α → Type*}
def pi (i : set α) (s : Πa, set (π a)) : set (Πa, π a) := { f | ∀a∈i, f a ∈ s a }
@[simp] lemma pi_empty_index (s : Πa, set (π a)) : pi ∅ s = univ := by ext; simp [pi]
@[simp] lemma pi_insert_index (a : α) (i : set α) (s : Πa, set (π a)) :
pi (insert a i) s = ((λf, f a) ⁻¹' s a) ∩ pi i s :=
by ext; simp [pi, or_imp_distrib, forall_and_distrib]
@[simp] lemma pi_singleton_index (a : α) (s : Πa, set (π a)) :
pi {a} s = ((λf:(Πa, π a), f a) ⁻¹' s a) :=
by ext; simp [pi]
lemma pi_if {p : α → Prop} [h : decidable_pred p] (i : set α) (s t : Πa, set (π a)) :
pi i (λa, if p a then s a else t a) = pi {a ∈ i | p a} s ∩ pi {a ∈ i | ¬ p a} t :=
begin
ext f,
split,
{ assume h, split; { rintros a ⟨hai, hpa⟩, simpa [*] using h a } },
{ rintros ⟨hs, ht⟩ a hai,
by_cases p a; simp [*, pi] at * }
end
end pi
end set
|
30acd4995a1887bcf5f1e550cd0b9b2d23a47514 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/functor/epi_mono.lean | 2ed2ad6f30291514adee3e5c205352d1c148320e | [
"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 | 7,358 | lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.epi_mono
/-!
# Preservation and reflection of monomorphisms and epimorphisms
We provide typeclasses that state that a functor preserves or reflects monomorphisms or
epimorphisms.
-/
open category_theory
universes v₁ v₂ v₃ u₁ u₂ u₃
namespace category_theory.functor
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
/-- A functor preserves monomorphisms if it maps monomorphisms to monomorphisms. -/
class preserves_monomorphisms (F : C ⥤ D) : Prop :=
(preserves : ∀ {X Y : C} (f : X ⟶ Y) [mono f], mono (F.map f))
instance map_mono (F : C ⥤ D) [preserves_monomorphisms F] {X Y : C} (f : X ⟶ Y) [mono f] :
mono (F.map f) :=
preserves_monomorphisms.preserves f
/-- A functor preserves epimorphisms if it maps epimorphisms to epimorphisms. -/
class preserves_epimorphisms (F : C ⥤ D) : Prop :=
(preserves : ∀ {X Y : C} (f : X ⟶ Y) [epi f], epi (F.map f))
instance map_epi (F : C ⥤ D) [preserves_epimorphisms F] {X Y : C} (f : X ⟶ Y) [epi f] :
epi (F.map f) :=
preserves_epimorphisms.preserves f
/-- A functor reflects monomorphisms if morphisms that are mapped to monomorphisms are themselves
monomorphisms. -/
class reflects_monomorphisms (F : C ⥤ D) : Prop :=
(reflects : ∀ {X Y : C} (f : X ⟶ Y), mono (F.map f) → mono f)
lemma mono_of_mono_map (F : C ⥤ D) [reflects_monomorphisms F] {X Y : C} {f : X ⟶ Y}
(h : mono (F.map f)) : mono f :=
reflects_monomorphisms.reflects f h
/-- A functor reflects epimorphisms if morphisms that are mapped to epimorphisms are themselves
epimorphisms. -/
class reflects_epimorphisms (F : C ⥤ D) : Prop :=
(reflects : ∀ {X Y : C} (f : X ⟶ Y), epi (F.map f) → epi f)
lemma epi_of_epi_map (F : C ⥤ D) [reflects_epimorphisms F] {X Y : C} {f : X ⟶ Y}
(h : epi (F.map f)) : epi f :=
reflects_epimorphisms.reflects f h
instance preserves_monomorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [preserves_monomorphisms F]
[preserves_monomorphisms G] : preserves_monomorphisms (F ⋙ G) :=
{ preserves := λ X Y f h, by { rw comp_map, exactI infer_instance } }
instance preserves_epimorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [preserves_epimorphisms F]
[preserves_epimorphisms G] : preserves_epimorphisms (F ⋙ G) :=
{ preserves := λ X Y f h, by { rw comp_map, exactI infer_instance } }
instance reflects_monomorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [reflects_monomorphisms F]
[reflects_monomorphisms G] : reflects_monomorphisms (F ⋙ G) :=
{ reflects := λ X Y f h, (F.mono_of_mono_map (G.mono_of_mono_map h)) }
instance reflects_epimorphisms_comp (F : C ⥤ D) (G : D ⥤ E) [reflects_epimorphisms F]
[reflects_epimorphisms G] : reflects_epimorphisms (F ⋙ G) :=
{ reflects := λ X Y f h, (F.epi_of_epi_map (G.epi_of_epi_map h)) }
lemma preserves_monomorphisms.of_iso {F G : C ⥤ D} [preserves_monomorphisms F] (α : F ≅ G) :
preserves_monomorphisms G :=
{ preserves := λ X Y f h,
begin
haveI : mono (F.map f ≫ (α.app Y).hom) := by exactI mono_comp _ _,
convert (mono_comp _ _ : mono ((α.app X).inv ≫ F.map f ≫ (α.app Y).hom)),
rw [iso.eq_inv_comp, iso.app_hom, iso.app_hom, nat_trans.naturality]
end }
lemma preserves_monomorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) :
preserves_monomorphisms F ↔ preserves_monomorphisms G :=
⟨λ h, by exactI preserves_monomorphisms.of_iso α,
λ h, by exactI preserves_monomorphisms.of_iso α.symm⟩
lemma preserves_epimorphisms.of_iso {F G : C ⥤ D} [preserves_epimorphisms F] (α : F ≅ G) :
preserves_epimorphisms G :=
{ preserves := λ X Y f h,
begin
haveI : epi (F.map f ≫ (α.app Y).hom) := by exactI epi_comp _ _,
convert (epi_comp _ _ : epi ((α.app X).inv ≫ F.map f ≫ (α.app Y).hom)),
rw [iso.eq_inv_comp, iso.app_hom, iso.app_hom, nat_trans.naturality]
end }
lemma preserves_epimorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) :
preserves_epimorphisms F ↔ preserves_epimorphisms G :=
⟨λ h, by exactI preserves_epimorphisms.of_iso α,
λ h, by exactI preserves_epimorphisms.of_iso α.symm⟩
lemma reflects_monomorphisms.of_iso {F G : C ⥤ D} [reflects_monomorphisms F] (α : F ≅ G) :
reflects_monomorphisms G :=
{ reflects := λ X Y f h,
begin
apply F.mono_of_mono_map,
haveI : mono (G.map f ≫ (α.app Y).inv) := by exactI mono_comp _ _,
convert (mono_comp _ _ : mono ((α.app X).hom ≫ G.map f ≫ (α.app Y).inv)),
rw [← category.assoc, iso.eq_comp_inv, iso.app_hom, iso.app_hom, nat_trans.naturality]
end }
lemma reflects_monomorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) :
reflects_monomorphisms F ↔ reflects_monomorphisms G :=
⟨λ h, by exactI reflects_monomorphisms.of_iso α,
λ h, by exactI reflects_monomorphisms.of_iso α.symm⟩
lemma reflects_epimorphisms.of_iso {F G : C ⥤ D} [reflects_epimorphisms F] (α : F ≅ G) :
reflects_epimorphisms G :=
{ reflects := λ X Y f h,
begin
apply F.epi_of_epi_map,
haveI : epi (G.map f ≫ (α.app Y).inv) := by exactI epi_comp _ _,
convert (epi_comp _ _ : epi ((α.app X).hom ≫ G.map f ≫ (α.app Y).inv)),
rw [← category.assoc, iso.eq_comp_inv, iso.app_hom, iso.app_hom, nat_trans.naturality]
end }
lemma reflects_epimorphisms.iso_iff {F G : C ⥤ D} (α : F ≅ G) :
reflects_epimorphisms F ↔ reflects_epimorphisms G :=
⟨λ h, by exactI reflects_epimorphisms.of_iso α, λ h, by exactI reflects_epimorphisms.of_iso α.symm⟩
lemma preserves_epimorphsisms_of_adjunction {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) :
preserves_epimorphisms F :=
{ preserves := λ X Y f hf,
⟨begin
introsI 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⟩ }
@[priority 100]
instance preserves_epimorphisms_of_is_left_adjoint (F : C ⥤ D) [is_left_adjoint F] :
preserves_epimorphisms F :=
preserves_epimorphsisms_of_adjunction (adjunction.of_left_adjoint F)
lemma preserves_monomorphisms_of_adjunction {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) :
preserves_monomorphisms G :=
{ preserves := λ X Y f hf,
⟨begin
introsI 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⟩ }
@[priority 100]
instance preserves_monomorphisms_of_is_right_adjoint (F : C ⥤ D) [is_right_adjoint F] :
preserves_monomorphisms F :=
preserves_monomorphisms_of_adjunction (adjunction.of_right_adjoint F)
@[priority 100]
instance reflects_monomorphisms_of_faithful (F : C ⥤ D) [faithful F] : reflects_monomorphisms F :=
{ reflects := λ X Y f hf, ⟨λ Z g h hgh, by exactI F.map_injective ((cancel_mono (F.map f)).1
(by rw [← F.map_comp, hgh, F.map_comp]))⟩ }
@[priority 100]
instance reflects_epimorphisms_of_faithful (F : C ⥤ D) [faithful F] : reflects_epimorphisms F :=
{ reflects := λ X Y f hf, ⟨λ Z g h hgh, by exactI F.map_injective ((cancel_epi (F.map f)).1
(by rw [← F.map_comp, hgh, F.map_comp]))⟩ }
end category_theory.functor
|
e71dfd063c3d4bd45ef214d5b5d9a2a9c668649c | dd4e652c749fea9ac77e404005cb3470e5f75469 | /src/missing_mathlib/algebra/big_operators.lean | e3aa637cd6ffeb921d14cfc11b5b9e355e5400a1 | [] | no_license | skbaek/cvx | e32822ad5943541539966a37dee162b0a5495f55 | c50c790c9116f9fac8dfe742903a62bdd7292c15 | refs/heads/master | 1,623,803,010,339 | 1,618,058,958,000 | 1,618,058,958,000 | 176,293,135 | 3 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 570 | lean | import algebra.big_operators
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
section comm_monoid
variables [comm_monoid β]
@[to_additive finset.sum_filter']
lemma prod_filter' [decidable_eq β] (s : finset α) (f : α → β) :
finset.prod (finset.filter (λ (x : α), f x ≠ 1) s) f = finset.prod s f :=
finset.prod_subset (finset.filter_subset s)
(λ x hx₁ hx₂, not_not.1 (λ h, hx₂ (finset.mem_filter.2 ⟨hx₁, h⟩)))
end comm_monoid
end finset |
536cd29f18576ea219087843b183ca39602dcb0f | 1a9d3677cccdaaccacb163507570e75d34043a38 | /src/week_1/Part_C_functions.lean | 3a763a6c6eb35e1150d127ad29371cc23c92d4ce | [
"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 | 3,372 | lean | import tactic
-- injective and surjective functions are already in Lean.
-- They are called `function.injective` and `function.surjective`.
-- It gets a bit boring typing `function.` a lot so we start
-- by opening the `function` namespace
open function
-- We now move into the `xena` namespace
namespace xena
-- let X, Y, Z be "types", i.e. sets, and let `f : X → Y` and `g : Y → Z`
-- be functions
variables {X Y Z : Type} {f : X → Y} {g : Y → Z}
-- let a,b,x be elements of X, let y be an element of Y and let z be an
-- element of Z
variables (a b x : X) (y : Y) (z : Z)
/-!
# Injective functions
-/
-- let's start by checking the definition of injective is
-- what we think it is.
lemma injective_def : injective f ↔ ∀ a b : X, f a = f b → a = b :=
begin
-- true by definition
refl
end
-- You can now `rw injective_def` to change `injective f` into its definition.
-- The identity function id : X → X is defined by id(x) = x. Let's check this
lemma id_def : id x = x :=
begin
-- true by definition
refl
end
-- you can now `rw id_def` to change `id x` into `x`
/-- The identity function is injective -/
lemma injective_id : injective (id : X → X) :=
begin
intros a b, exact id
end
-- function composition g ∘ f is satisfies (g ∘ f) (x) = g(f(x)). This
-- is true by definition. Let's check this
lemma comp_def : (g ∘ f) x = g (f x) :=
begin
-- true by definition
refl
end
/-- Composite of two injective functions is injective -/
lemma injective_comp (hf : injective f) (hg : injective g) : injective (g ∘ f) :=
begin
-- you could start with `rw injective_def at *` if you like.
-- In some sense it doesn't do anything, but it might make you happier.
intros a b h, apply hf, exact hg h
end
/-!
### Surjective functions
-/
-- Let's start by checking the definition of surjectivity is what we think it is
lemma surjective_def : surjective f ↔ ∀ y : Y, ∃ x : X, f x = y :=
begin
-- true by definition
refl
end
/-- The identity function is surjective -/
lemma surjective_id : surjective (id : X → X) :=
begin
-- you can start with `rw surjective_def` if you like.
intro a, exact ⟨a,rfl⟩
end
-- If you started with `rw surjective_def` -- try deleting it.
-- Probably your proof still works! This is because
-- `surjective_def` is true *by definition*. The proof is `refl`.
-- For this next one, the `have` tactic is helpful.
/-- Composite of two surjective functions is surjective -/
lemma surjective_comp (hf : surjective f) (hg : surjective g) : surjective (g ∘ f) :=
begin
intro a, cases hg a with b hb, cases hf b with c hc,
rw ← hc at hb, exact ⟨c,hb⟩
end
/-!
### Bijective functions
In Lean a function is defined to be bijective if it is injective and surjective.
Let's check this.
-/
lemma bijective_def : bijective f ↔ injective f ∧ surjective f :=
begin
-- true by definition
refl
end
-- You can now use the lemmas you've proved already to make these
-- proofs very short.
/-- The identity function is bijective. -/
lemma bijective_id : bijective (id : X → X) :=
begin
exact ⟨injective_id, surjective_id⟩
end
/-- A composite of bijective functions is bijective. -/
lemma bijective_comp (hf : bijective f) (hg : bijective g) : bijective (g ∘ f) :=
begin
exact ⟨injective_comp hf.1 hg.1, surjective_comp hf.2 hg.2⟩
end
end xena
|
41270de1f22fb566e1d5d0a016d6e0ceb278ae26 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/semiquot_auto.lean | 0a10415dc7e4bd1e677dd7f3aa3d4ffcaddea0a6 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,850 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
A data type for semiquotients, which are classically equivalent to
nonempty sets, but are useful for programming; the idea is that
a semiquotient set `S` represents some (particular but unknown)
element of `S`. This can be used to model nondeterministic functions,
which return something in a range of values (represented by the
predicate `S`) but are not completely determined.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.set.lattice
import Mathlib.PostPort
universes u u_1 l u_2 u_3 u_4 u_5
namespace Mathlib
/-- A member of `semiquot α` is classically a nonempty `set α`,
and in the VM is represented by an element of `α`; the relation
between these is that the VM element is required to be a member
of the set `s`. The specific element of `s` that the VM computes
is hidden by a quotient construction, allowing for the representation
of nondeterministic functions. -/
structure semiquot (α : Type u_1) where
mk' :: (s : set α) (val : trunc ↥s)
namespace semiquot
protected instance has_mem {α : Type u_1} : has_mem α (semiquot α) :=
has_mem.mk fun (a : α) (q : semiquot α) => a ∈ s q
/-- Construct a `semiquot α` from `h : a ∈ s` where `s : set α`. -/
def mk {α : Type u_1} {a : α} {s : set α} (h : a ∈ s) : semiquot α :=
mk' s (trunc.mk { val := a, property := h })
theorem ext_s {α : Type u_1} {q₁ : semiquot α} {q₂ : semiquot α} : q₁ = q₂ ↔ s q₁ = s q₂ := sorry
theorem ext {α : Type u_1} {q₁ : semiquot α} {q₂ : semiquot α} :
q₁ = q₂ ↔ ∀ (a : α), a ∈ q₁ ↔ a ∈ q₂ :=
iff.trans ext_s set.ext_iff
theorem exists_mem {α : Type u_1} (q : semiquot α) : ∃ (a : α), a ∈ q := sorry
theorem eq_mk_of_mem {α : Type u_1} {q : semiquot α} {a : α} (h : a ∈ q) : q = mk h :=
iff.mpr ext_s rfl
theorem nonempty {α : Type u_1} (q : semiquot α) : set.nonempty (s q) := exists_mem q
/-- `pure a` is `a` reinterpreted as an unspecified element of `{a}`. -/
protected def pure {α : Type u_1} (a : α) : semiquot α := mk (set.mem_singleton a)
@[simp] theorem mem_pure' {α : Type u_1} {a : α} {b : α} : a ∈ semiquot.pure b ↔ a = b :=
set.mem_singleton_iff
/-- Replace `s` in a `semiquot` with a superset. -/
def blur' {α : Type u_1} (q : semiquot α) {s : set α} (h : s q ⊆ s) : semiquot α :=
mk' s
(trunc.lift (fun (a : ↥(s q)) => trunc.mk { val := subtype.val a, property := sorry }) sorry
(val q))
/-- Replace `s` in a `q : semiquot α` with a union `s ∪ q.s` -/
def blur {α : Type u_1} (s : set α) (q : semiquot α) : semiquot α := blur' q sorry
theorem blur_eq_blur' {α : Type u_1} (q : semiquot α) (s : set α) (h : s q ⊆ s) :
blur s q = blur' q h :=
sorry
@[simp] theorem mem_blur' {α : Type u_1} (q : semiquot α) {s : set α} (h : s q ⊆ s) {a : α} :
a ∈ blur' q h ↔ a ∈ s :=
iff.rfl
/-- Convert a `trunc α` to a `semiquot α`. -/
def of_trunc {α : Type u_1} (q : trunc α) : semiquot α :=
mk' set.univ (trunc.map (fun (a : α) => { val := a, property := trivial }) q)
/-- Convert a `semiquot α` to a `trunc α`. -/
def to_trunc {α : Type u_1} (q : semiquot α) : trunc α := trunc.map subtype.val (val q)
/-- If `f` is a constant on `q.s`, then `q.lift_on f` is the value of `f`
at any point of `q`. -/
def lift_on {α : Type u_1} {β : Type u_2} (q : semiquot α) (f : α → β)
(h : ∀ (a b : α), a ∈ q → b ∈ q → f a = f b) : β :=
trunc.lift_on (val q) (fun (x : ↥(s q)) => f (subtype.val x)) sorry
theorem lift_on_of_mem {α : Type u_1} {β : Type u_2} (q : semiquot α) (f : α → β)
(h : ∀ (a b : α), a ∈ q → b ∈ q → f a = f b) (a : α) (aq : a ∈ q) : lift_on q f h = f a :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (∀ (h : ∀ (a b : α), a ∈ q → b ∈ q → f a = f b), lift_on q f h = f a))
(eq_mk_of_mem aq)))
(fun (h : ∀ (a_1 b : α), a_1 ∈ mk aq → b ∈ mk aq → f a_1 = f b) =>
Eq.refl (lift_on (mk aq) f h))
h
def map {α : Type u_1} {β : Type u_2} (f : α → β) (q : semiquot α) : semiquot β :=
mk' (f '' s q)
(trunc.map (fun (x : ↥(s q)) => { val := f (subtype.val x), property := sorry }) (val q))
@[simp] theorem mem_map {α : Type u_1} {β : Type u_2} (f : α → β) (q : semiquot α) (b : β) :
b ∈ map f q ↔ ∃ (a : α), a ∈ q ∧ f a = b :=
set.mem_image (fun (a : α) => f a) (s q) b
def bind {α : Type u_1} {β : Type u_2} (q : semiquot α) (f : α → semiquot β) : semiquot β :=
mk' (set.Union fun (a : α) => set.Union fun (H : a ∈ s q) => s (f a))
(trunc.bind (val q)
fun (a : ↥(s q)) =>
trunc.map
(fun (b : ↥(s (f (subtype.val a)))) => { val := subtype.val b, property := sorry })
(val (f (subtype.val a))))
@[simp] theorem mem_bind {α : Type u_1} {β : Type u_2} (q : semiquot α) (f : α → semiquot β)
(b : β) : b ∈ bind q f ↔ ∃ (a : α), ∃ (H : a ∈ q), b ∈ f a :=
set.mem_bUnion_iff
protected instance monad : Monad semiquot :=
{ toApplicative :=
{ toFunctor := { map := map, mapConst := fun (α β : Type u_1) => map ∘ function.const β },
toPure := { pure := semiquot.pure },
toSeq :=
{ seq :=
fun (α β : Type u_1) (f : semiquot (α → β)) (x : semiquot α) =>
bind f fun (_x : α → β) => map _x x },
toSeqLeft :=
{ seqLeft :=
fun (α β : Type u_1) (a : semiquot α) (b : semiquot β) =>
(fun (α β : Type u_1) (f : semiquot (α → β)) (x : semiquot α) =>
bind f fun (_x : α → β) => map _x x)
β α (map (function.const β) a) b },
toSeqRight :=
{ seqRight :=
fun (α β : Type u_1) (a : semiquot α) (b : semiquot β) =>
(fun (α β : Type u_1) (f : semiquot (α → β)) (x : semiquot α) =>
bind f fun (_x : α → β) => map _x x)
β β (map (function.const α id) a) b } },
toBind := { bind := bind } }
@[simp] theorem map_def {α : Type u_1} {β : Type u_1} : Functor.map = map := rfl
@[simp] theorem bind_def {α : Type u_1} {β : Type u_1} : bind = bind := rfl
@[simp] theorem mem_pure {α : Type u_1} {a : α} {b : α} : a ∈ pure b ↔ a = b :=
set.mem_singleton_iff
theorem mem_pure_self {α : Type u_1} (a : α) : a ∈ pure a := set.mem_singleton a
@[simp] theorem pure_inj {α : Type u_1} {a : α} {b : α} : pure a = pure b ↔ a = b :=
iff.trans ext_s set.singleton_eq_singleton_iff
protected instance is_lawful_monad : is_lawful_monad semiquot := sorry
protected instance has_le {α : Type u_1} : HasLessEq (semiquot α) :=
{ LessEq := fun (s t : semiquot α) => s s ⊆ s t }
protected instance partial_order {α : Type u_1} : partial_order (semiquot α) :=
partial_order.mk (fun (s t : semiquot α) => ∀ {x : α}, x ∈ s → x ∈ t)
(preorder.lt._default fun (s t : semiquot α) => ∀ {x : α}, x ∈ s → x ∈ t) sorry sorry sorry
protected instance semilattice_sup {α : Type u_1} : semilattice_sup (semiquot α) :=
semilattice_sup.mk (fun (s : semiquot α) => blur (s s)) partial_order.le partial_order.lt sorry
sorry sorry sorry sorry sorry
@[simp] theorem pure_le {α : Type u_1} {a : α} {s : semiquot α} : pure a ≤ s ↔ a ∈ s :=
set.singleton_subset_iff
def is_pure {α : Type u_1} (q : semiquot α) := ∀ (a b : α), a ∈ q → b ∈ q → a = b
def get {α : Type u_1} (q : semiquot α) (h : is_pure q) : α := lift_on q id h
theorem get_mem {α : Type u_1} {q : semiquot α} (p : is_pure q) : get q p ∈ q := sorry
theorem eq_pure {α : Type u_1} {q : semiquot α} (p : is_pure q) : q = pure (get q p) := sorry
@[simp] theorem pure_is_pure {α : Type u_1} (a : α) : is_pure (pure a) :=
fun (a_1 b : α) (H : a_1 ∈ pure a) (H_1 : b ∈ pure a) =>
idRhs (a_1 = b)
(of_eq_true
(eq_true_intro
(Eq.trans (eq.mp (propext mem_pure) H) (Eq.symm (eq.mp (propext mem_pure) H_1)))))
theorem is_pure_iff {α : Type u_1} {s : semiquot α} : is_pure s ↔ ∃ (a : α), s = pure a := sorry
theorem is_pure.mono {α : Type u_1} {s : semiquot α} {t : semiquot α} (st : s ≤ t) (h : is_pure t) :
is_pure s :=
fun (a b : α) (H : a ∈ s) (H_1 : b ∈ s) => idRhs (a = b) (h a b (st H) (st H_1))
theorem is_pure.min {α : Type u_1} {s : semiquot α} {t : semiquot α} (h : is_pure t) :
s ≤ t ↔ s = t :=
sorry
theorem is_pure_of_subsingleton {α : Type u_1} [subsingleton α] (q : semiquot α) : is_pure q :=
fun (a b : α) (H : a ∈ q) (H : b ∈ q) => idRhs (a = b) (subsingleton.elim a b)
/-- `univ : semiquot α` represents an unspecified element of `univ : set α`. -/
def univ {α : Type u_1} [Inhabited α] : semiquot α := mk sorry
protected instance inhabited {α : Type u_1} [Inhabited α] : Inhabited (semiquot α) :=
{ default := univ }
@[simp] theorem mem_univ {α : Type u_1} [Inhabited α] (a : α) : a ∈ univ := set.mem_univ
theorem univ_unique {α : Type u_1} (I : Inhabited α) (J : Inhabited α) : univ = univ := sorry
@[simp] theorem is_pure_univ {α : Type u_1} [Inhabited α] : is_pure univ ↔ subsingleton α := sorry
protected instance order_top {α : Type u_1} [Inhabited α] : order_top (semiquot α) :=
order_top.mk univ partial_order.le partial_order.lt sorry sorry sorry sorry
protected instance semilattice_sup_top {α : Type u_1} [Inhabited α] :
semilattice_sup_top (semiquot α) :=
semilattice_sup_top.mk order_top.top order_top.le order_top.lt sorry sorry sorry sorry
semilattice_sup.sup sorry sorry sorry
end Mathlib |
f75a24b0015f0662b97182a6d7e14647da28a818 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /stage0/src/Lean/PrettyPrinter/Parenthesizer.lean | deddcaf363fa219275c171718953d5dd36b7bcec | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 29,525 | lean | /-
Copyright (c) 2020 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
-/
import Lean.Parser.Extension
import Lean.Parser.StrInterpolation
import Lean.ParserCompiler.Attribute
import Lean.PrettyPrinter.Basic
/-!
The parenthesizer inserts parentheses into a `Syntax` object where syntactically necessary, usually as an intermediary
step between the delaborator and the formatter. While the delaborator outputs structurally well-formed syntax trees that
can be re-elaborated without post-processing, this tree structure is lost in the formatter and thus needs to be
preserved by proper insertion of parentheses.
# The abstract problem & solution
The Lean 4 grammar is unstructured and extensible with arbitrary new parsers, so in general it is undecidable whether
parentheses are necessary or even allowed at any point in the syntax tree. Parentheses for different categories, e.g.
terms and levels, might not even have the same structure. In this module, we focus on the correct parenthesization of
parsers defined via `Lean.Parser.prattParser`, which includes both aforementioned built-in categories. Custom
parenthesizers can be added for new node kinds, but the data collected in the implementation below might not be
appropriate for other parenthesization strategies.
Usages of a parser defined via `prattParser` in general have the form `p prec`, where `prec` is the minimum precedence
or binding power. Recall that a Pratt parser greedily runs a leading parser with precedence at least `prec` (otherwise
it fails) followed by zero or more trailing parsers with precedence at least `prec`; the precedence of a parser is
encoded in the call to `leadingNode/trailingNode`, respectively. Thus we should parenthesize a syntax node `stx`
supposedly produced by `p prec` if
1. the leading/any trailing parser involved in `stx` has precedence < `prec` (because without parentheses, `p prec`
would not produce all of `stx`), or
2. the trailing parser parsing the input to *the right of* `stx`, if any, has precedence >= `prec` (because without
parentheses, `p prec` would have parsed it as well and made it a part of `stx`). We also check that the two parsers
are from the same syntax category.
Note that in case 2, it is also sufficient to parenthesize a *parent* node as long as the offending parser is still to
the right of that node. For example, imagine the tree structure of `(f fun x => x) y` without parentheses. We need to
insert *some* parentheses between `x` and `y` since the lambda body is parsed with precedence 0, while the identifier
parser for `y` has precedence `maxPrec`. But we need to parenthesize the `$` node anyway since the precedence of its
RHS (0) again is smaller than that of `y`. So it's better to only parenthesize the outer node than ending up with
`(f $ (fun x => x)) y`.
# Implementation
We transform the syntax tree and collect the necessary precedence information for that in a single traversal. The
traversal is right-to-left to cover case 2. More specifically, for every Pratt parser call, we store as monadic state
the precedence of the left-most trailing parser and the minimum precedence of any parser (`contPrec`/`minPrec`) in this
call, if any, and the precedence of the nested trailing Pratt parser call (`trailPrec`), if any. If `stP` is the state
resulting from the traversal of a Pratt parser call `p prec`, and `st` is the state of the surrounding call, we
parenthesize if `prec > stP.minPrec` (case 1) or if `stP.trailPrec <= st.contPrec` (case 2).
The traversal can be customized for each `[*Parser]` parser declaration `c` (more specifically, each `SyntaxNodeKind`
`c`) using the `[parenthesizer c]` attribute. Otherwise, a default parenthesizer will be synthesized from the used
parser combinators by recursively replacing them with declarations tagged as `[combinatorParenthesizer]` for the
respective combinator. If a called function does not have a registered combinator parenthesizer and is not reducible,
the synthesizer fails. This happens mostly at the `Parser.mk` decl, which is irreducible, when some parser primitive has
not been handled yet.
The traversal over the `Syntax` object is complicated by the fact that a parser does not produce exactly one syntax
node, but an arbitrary (but constant, for each parser) amount that it pushes on top of the parser stack. This amount can
even be zero for parsers such as `checkWsBefore`. Thus we cannot simply pass and return a `Syntax` object to and from
`visit`. Instead, we use a `Syntax.Traverser` that allows arbitrary movement and modification inside the syntax tree.
Our traversal invariant is that a parser interpreter should stop at the syntax object to the *left* of all syntax
objects its parser produced, except when it is already at the left-most child. This special case is not an issue in
practice since if there is another parser to the left that produced zero nodes in this case, it should always do so, so
there is no danger of the left-most child being processed multiple times.
Ultimately, most parenthesizers are implemented via three primitives that do all the actual syntax traversal:
`maybeParenthesize mkParen prec x` runs `x` and afterwards transforms it with `mkParen` if the above
condition for `p prec` is fulfilled. `visitToken` advances to the preceding sibling and is used on atoms. `visitArgs x`
executes `x` on the last child of the current node and then advances to the preceding sibling (of the original current
node).
-/
namespace Lean
namespace PrettyPrinter
namespace Parenthesizer
structure Context where
-- We need to store this `categoryParser` argument to deal with the implicit Pratt parser call in `trailingNode.parenthesizer`.
cat : Name := Name.anonymous
structure State where
stxTrav : Syntax.Traverser
--- precedence and category of the current left-most trailing parser, if any; see module doc for details
contPrec : Option Nat := none
contCat : Name := Name.anonymous
-- current minimum precedence in this Pratt parser call, if any; see module doc for details
minPrec : Option Nat := none
-- precedence and category of the trailing Pratt parser call if any; see module doc for details
trailPrec : Option Nat := none
trailCat : Name := Name.anonymous
-- true iff we have already visited a token on this parser level; used for detecting trailing parsers
visitedToken : Bool := false
end Parenthesizer
abbrev ParenthesizerM := ReaderT Parenthesizer.Context $ StateRefT Parenthesizer.State CoreM
abbrev Parenthesizer := ParenthesizerM Unit
@[inline] def ParenthesizerM.orElse (p₁ : ParenthesizerM α) (p₂ : Unit → ParenthesizerM α) : ParenthesizerM α := do
let s ← get
catchInternalId backtrackExceptionId
p₁
(fun _ => do set s; p₂ ())
instance : OrElse (ParenthesizerM α) := ⟨ParenthesizerM.orElse⟩
unsafe def mkParenthesizerAttribute : IO (KeyedDeclsAttribute Parenthesizer) :=
KeyedDeclsAttribute.init {
builtinName := `builtinParenthesizer,
name := `parenthesizer,
descr := "Register a parenthesizer for a parser.
[parenthesizer k] registers a declaration of type `Lean.PrettyPrinter.Parenthesizer` for the `SyntaxNodeKind` `k`.",
valueTypeName := `Lean.PrettyPrinter.Parenthesizer,
evalKey := fun builtin stx => do
let env ← getEnv
let id ← Attribute.Builtin.getId stx
-- `isValidSyntaxNodeKind` is updated only in the next stage for new `[builtin*Parser]`s, but we try to
-- synthesize a parenthesizer for it immediately, so we just check for a declaration in this case
if (builtin && (env.find? id).isSome) || Parser.isValidSyntaxNodeKind env id then pure id
else throwError "invalid [parenthesizer] argument, unknown syntax kind '{id}'"
} `Lean.PrettyPrinter.parenthesizerAttribute
@[builtinInit mkParenthesizerAttribute] opaque parenthesizerAttribute : KeyedDeclsAttribute Parenthesizer
abbrev CategoryParenthesizer := (prec : Nat) → Parenthesizer
unsafe def mkCategoryParenthesizerAttribute : IO (KeyedDeclsAttribute CategoryParenthesizer) :=
KeyedDeclsAttribute.init {
builtinName := `builtinCategoryParenthesizer,
name := `categoryParenthesizer,
descr := "Register a parenthesizer for a syntax category.
[categoryParenthesizer cat] registers a declaration of type `Lean.PrettyPrinter.CategoryParenthesizer` for the category `cat`,
which is used when parenthesizing calls of `categoryParser cat prec`. Implementations should call `maybeParenthesize`
with the precedence and `cat`. If no category parenthesizer is registered, the category will never be parenthesized,
but still be traversed for parenthesizing nested categories.",
valueTypeName := `Lean.PrettyPrinter.CategoryParenthesizer,
evalKey := fun _ stx => do
let env ← getEnv
let id ← Attribute.Builtin.getId stx
if Parser.isParserCategory env id then pure id
else throwError "invalid [categoryParenthesizer] argument, unknown parser category '{toString id}'"
} `Lean.PrettyPrinter.categoryParenthesizerAttribute
@[builtinInit mkCategoryParenthesizerAttribute] opaque categoryParenthesizerAttribute : KeyedDeclsAttribute CategoryParenthesizer
unsafe def mkCombinatorParenthesizerAttribute : IO ParserCompiler.CombinatorAttribute :=
ParserCompiler.registerCombinatorAttribute
`combinatorParenthesizer
"Register a parenthesizer for a parser combinator.
[combinatorParenthesizer c] registers a declaration of type `Lean.PrettyPrinter.Parenthesizer` for the `Parser` declaration `c`.
Note that, unlike with [parenthesizer], this is not a node kind since combinators usually do not introduce their own node kinds.
The tagged declaration may optionally accept parameters corresponding to (a prefix of) those of `c`, where `Parser` is replaced
with `Parenthesizer` in the parameter types."
@[builtinInit mkCombinatorParenthesizerAttribute] opaque combinatorParenthesizerAttribute : ParserCompiler.CombinatorAttribute
namespace Parenthesizer
open Lean.Core
open Std.Format
def throwBacktrack {α} : ParenthesizerM α :=
throw $ Exception.internal backtrackExceptionId
instance : Syntax.MonadTraverser ParenthesizerM := ⟨{
get := State.stxTrav <$> get,
set := fun t => modify (fun st => { st with stxTrav := t }),
modifyGet := fun f => modifyGet (fun st => let (a, t) := f st.stxTrav; (a, { st with stxTrav := t }))
}⟩
open Syntax.MonadTraverser
def addPrecCheck (prec : Nat) : ParenthesizerM Unit :=
modify fun st => { st with contPrec := Nat.min (st.contPrec.getD prec) prec, minPrec := Nat.min (st.minPrec.getD prec) prec }
/-- Execute `x` at the right-most child of the current node, if any, then advance to the left. -/
def visitArgs (x : ParenthesizerM Unit) : ParenthesizerM Unit := do
let stx ← getCur
if stx.getArgs.size > 0 then
goDown (stx.getArgs.size - 1) *> x <* goUp
goLeft
-- Macro scopes in the parenthesizer output are ultimately ignored by the pretty printer,
-- so give a trivial implementation.
instance : MonadQuotation ParenthesizerM := {
getCurrMacroScope := pure default
getMainModule := pure default
withFreshMacroScope := fun x => x
}
/--
Run `x` and parenthesize the result using `mkParen` if necessary.
If `canJuxtapose` is false, we assume the category does not have a token-less juxtaposition syntax a la function application and deactivate rule 2. -/
def maybeParenthesize (cat : Name) (canJuxtapose : Bool) (mkParen : Syntax → Syntax) (prec : Nat) (x : ParenthesizerM Unit) : ParenthesizerM Unit := do
let stx ← getCur
let idx ← getIdx
let st ← get
-- reset precs for the recursive call
set { stxTrav := st.stxTrav : State }
trace[PrettyPrinter.parenthesize] "parenthesizing (cont := {(st.contPrec, st.contCat)}){indentD (format stx)}"
x
let { minPrec := some minPrec, trailPrec := trailPrec, trailCat := trailCat, .. } ← get
| trace[PrettyPrinter.parenthesize] "visited a syntax tree without precedences?!{line ++ format stx}"
trace[PrettyPrinter.parenthesize] (m!"...precedences are {prec} >? {minPrec}" ++ if canJuxtapose then m!", {(trailPrec, trailCat)} <=? {(st.contPrec, st.contCat)}" else "")
-- Should we parenthesize?
if (prec > minPrec || canJuxtapose && match trailPrec, st.contPrec with | some trailPrec, some contPrec => trailCat == st.contCat && trailPrec <= contPrec | _, _ => false) then
-- The recursive `visit` call, by the invariant, has moved to the preceding node. In order to parenthesize
-- the original node, we must first move to the right, except if we already were at the left-most child in the first
-- place.
if idx > 0 then goRight
let mut stx ← getCur
-- Move leading/trailing whitespace of `stx` outside of parentheses
if let SourceInfo.original _ pos trail endPos := stx.getHeadInfo then
stx := stx.setHeadInfo (SourceInfo.original "".toSubstring pos trail endPos)
if let SourceInfo.original lead pos _ endPos := stx.getTailInfo then
stx := stx.setTailInfo (SourceInfo.original lead pos "".toSubstring endPos)
let mut stx' := mkParen stx
if let SourceInfo.original lead pos _ endPos := stx.getHeadInfo then
stx' := stx'.setHeadInfo (SourceInfo.original lead pos "".toSubstring endPos)
if let SourceInfo.original _ pos trail endPos := stx.getTailInfo then
stx' := stx'.setTailInfo (SourceInfo.original "".toSubstring pos trail endPos)
trace[PrettyPrinter.parenthesize] "parenthesized: {stx'.formatStx none}"
setCur stx'
goLeft
-- after parenthesization, there is no more trailing parser
modify (fun st => { st with contPrec := Parser.maxPrec, contCat := cat, trailPrec := none })
let { trailPrec := trailPrec, .. } ← get
-- If we already had a token at this level, keep the trailing parser. Otherwise, use the minimum of
-- `prec` and `trailPrec`.
if st.visitedToken then
modify fun stP => { stP with trailPrec := st.trailPrec, trailCat := st.trailCat }
else
let trailPrec := match trailPrec with
| some trailPrec => Nat.min trailPrec prec
| _ => prec
modify fun stP => { stP with trailPrec := trailPrec, trailCat := cat }
modify fun stP => { stP with minPrec := st.minPrec }
/-- Adjust state and advance. -/
def visitToken : Parenthesizer := do
modify fun st => { st with contPrec := none, contCat := Name.anonymous, visitedToken := true }
goLeft
@[combinatorParenthesizer Lean.Parser.orelse] def orelse.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer := do
-- HACK: We have no (immediate) information on which side of the orelse could have produced the current node, so try
-- them in turn. Uses the syntax traverser non-linearly!
p1 <|> p2
-- `mkAntiquot` is quite complex, so we'd rather have its parenthesizer synthesized below the actual parser definition.
-- Note that there is a mutual recursion
-- `categoryParser -> mkAntiquot -> termParser -> categoryParser`, so we need to introduce an indirection somewhere
-- anyway.
@[extern "lean_mk_antiquot_parenthesizer"]
opaque mkAntiquot.parenthesizer' (name : String) (kind : SyntaxNodeKind) (anonymous := true) (isPseudoKind := false) : Parenthesizer
@[inline] def liftCoreM {α} (x : CoreM α) : ParenthesizerM α :=
liftM x
-- break up big mutual recursion
@[extern "lean_pretty_printer_parenthesizer_interpret_parser_descr"]
opaque interpretParserDescr' : ParserDescr → CoreM Parenthesizer
unsafe def parenthesizerForKindUnsafe (k : SyntaxNodeKind) : Parenthesizer := do
if k == `missing then
pure ()
else
let p ← runForNodeKind parenthesizerAttribute k interpretParserDescr'
p
@[implementedBy parenthesizerForKindUnsafe]
opaque parenthesizerForKind (k : SyntaxNodeKind) : Parenthesizer
@[combinatorParenthesizer Lean.Parser.withAntiquot]
def withAntiquot.parenthesizer (antiP p : Parenthesizer) : Parenthesizer := do
let stx ← getCur
-- early check as minor optimization that also cleans up the backtrack traces
if stx.isAntiquot || stx.isAntiquotSplice then
orelse.parenthesizer antiP p
else
p
@[combinatorParenthesizer Lean.Parser.withAntiquotSuffixSplice]
def withAntiquotSuffixSplice.parenthesizer (_ : SyntaxNodeKind) (p suffix : Parenthesizer) : Parenthesizer := do
if (← getCur).isAntiquotSuffixSplice then
visitArgs <| suffix *> p
else
p
@[combinatorParenthesizer Lean.Parser.tokenWithAntiquot]
def tokenWithAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do
if (← getCur).isTokenAntiquot then
visitArgs p
else
p
def parenthesizeCategoryCore (cat : Name) (_prec : Nat) : Parenthesizer :=
withReader (fun ctx => { ctx with cat := cat }) do
let stx ← getCur
if stx.getKind == `choice then
visitArgs $ stx.getArgs.size.forM fun _ => do
let stx ← getCur
parenthesizerForKind stx.getKind
else
withAntiquot.parenthesizer (mkAntiquot.parenthesizer' cat.toString cat (isPseudoKind := true)) (parenthesizerForKind stx.getKind)
modify fun st => { st with contCat := cat }
@[combinatorParenthesizer Lean.Parser.categoryParser]
def categoryParser.parenthesizer (cat : Name) (prec : Nat) : Parenthesizer := do
let env ← getEnv
match categoryParenthesizerAttribute.getValues env cat with
| p::_ => p prec
-- Fall back to the generic parenthesizer.
-- In this case this node will never be parenthesized since we don't know which parentheses to use.
| _ => parenthesizeCategoryCore cat prec
@[combinatorParenthesizer Lean.Parser.categoryParserOfStack]
def categoryParserOfStack.parenthesizer (offset : Nat) (prec : Nat) : Parenthesizer := do
let st ← get
let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)
categoryParser.parenthesizer stx.getId prec
@[combinatorParenthesizer Lean.Parser.parserOfStack]
def parserOfStack.parenthesizer (offset : Nat) (_prec : Nat := 0) : Parenthesizer := do
let st ← get
let stx := st.stxTrav.parents.back.getArg (st.stxTrav.idxs.back - offset)
parenthesizerForKind stx.getKind
@[builtinCategoryParenthesizer term]
def term.parenthesizer : CategoryParenthesizer | prec => do
maybeParenthesize `term true (fun stx => Unhygienic.run `(($(⟨stx⟩)))) prec $
parenthesizeCategoryCore `term prec
@[builtinCategoryParenthesizer tactic]
def tactic.parenthesizer : CategoryParenthesizer | prec => do
maybeParenthesize `tactic false (fun stx => Unhygienic.run `(tactic|($(⟨stx⟩)))) prec $
parenthesizeCategoryCore `tactic prec
@[builtinCategoryParenthesizer level]
def level.parenthesizer : CategoryParenthesizer | prec => do
maybeParenthesize `level false (fun stx => Unhygienic.run `(level|($(⟨stx⟩)))) prec $
parenthesizeCategoryCore `level prec
@[builtinCategoryParenthesizer rawStx]
def rawStx.parenthesizer : CategoryParenthesizer | _ => do
goLeft
@[combinatorParenthesizer Lean.Parser.error]
def error.parenthesizer (_msg : String) : Parenthesizer :=
pure ()
@[combinatorParenthesizer Lean.Parser.errorAtSavedPos]
def errorAtSavedPos.parenthesizer (_msg : String) (_delta : Bool) : Parenthesizer :=
pure ()
@[combinatorParenthesizer Lean.Parser.atomic]
def atomic.parenthesizer (p : Parenthesizer) : Parenthesizer :=
p
@[combinatorParenthesizer Lean.Parser.lookahead]
def lookahead.parenthesizer (_ : Parenthesizer) : Parenthesizer :=
pure ()
@[combinatorParenthesizer Lean.Parser.notFollowedBy]
def notFollowedBy.parenthesizer (_ : Parenthesizer) : Parenthesizer :=
pure ()
@[combinatorParenthesizer Lean.Parser.andthen]
def andthen.parenthesizer (p1 p2 : Parenthesizer) : Parenthesizer :=
p2 *> p1
def checkKind (k : SyntaxNodeKind) : Parenthesizer := do
let stx ← getCur
if k != stx.getKind then
trace[PrettyPrinter.parenthesize.backtrack] "unexpected node kind '{stx.getKind}', expected '{k}'"
-- HACK; see `orelse.parenthesizer`
throwBacktrack
@[combinatorParenthesizer Lean.Parser.node]
def node.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer := do
checkKind k
visitArgs p
@[combinatorParenthesizer Lean.Parser.checkPrec]
def checkPrec.parenthesizer (prec : Nat) : Parenthesizer :=
addPrecCheck prec
@[combinatorParenthesizer Lean.Parser.leadingNode]
def leadingNode.parenthesizer (k : SyntaxNodeKind) (prec : Nat) (p : Parenthesizer) : Parenthesizer := do
node.parenthesizer k p
addPrecCheck prec
-- Limit `cont` precedence to `maxPrec-1`.
-- This is because `maxPrec-1` is the precedence of function application, which is the only way to turn a leading parser
-- into a trailing one.
modify fun st => { st with contPrec := Nat.min (Parser.maxPrec-1) prec }
@[combinatorParenthesizer Lean.Parser.trailingNode]
def trailingNode.parenthesizer (k : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parenthesizer) : Parenthesizer := do
checkKind k
visitArgs do
p
addPrecCheck prec
let ctx ← read
modify fun st => { st with contCat := ctx.cat }
-- After visiting the nodes actually produced by the parser passed to `trailingNode`, we are positioned on the
-- left-most child, which is the term injected by `trailingNode` in place of the recursion. Left recursion is not an
-- issue for the parenthesizer, so we can think of this child being produced by `termParser lhsPrec`, or whichever Pratt
-- parser is calling us.
categoryParser.parenthesizer ctx.cat lhsPrec
@[combinatorParenthesizer Lean.Parser.rawCh] def rawCh.parenthesizer (_ch : Char) := visitToken
@[combinatorParenthesizer Lean.Parser.symbolNoAntiquot] def symbolNoAntiquot.parenthesizer (_sym : String) := visitToken
@[combinatorParenthesizer Lean.Parser.unicodeSymbolNoAntiquot] def unicodeSymbolNoAntiquot.parenthesizer (_sym _asciiSym : String) := visitToken
@[combinatorParenthesizer Lean.Parser.identNoAntiquot] def identNoAntiquot.parenthesizer := do checkKind identKind; visitToken
@[combinatorParenthesizer Lean.Parser.rawIdentNoAntiquot] def rawIdentNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.identEq] def identEq.parenthesizer (_id : Name) := visitToken
@[combinatorParenthesizer Lean.Parser.nonReservedSymbolNoAntiquot] def nonReservedSymbolNoAntiquot.parenthesizer (_sym : String) (_includeIdent : Bool) := visitToken
@[combinatorParenthesizer Lean.Parser.charLitNoAntiquot] def charLitNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.strLitNoAntiquot] def strLitNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.nameLitNoAntiquot] def nameLitNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.numLitNoAntiquot] def numLitNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.scientificLitNoAntiquot] def scientificLitNoAntiquot.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.fieldIdx] def fieldIdx.parenthesizer := visitToken
@[combinatorParenthesizer Lean.Parser.manyNoAntiquot]
def manyNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do
let stx ← getCur
visitArgs $ stx.getArgs.size.forM fun _ => p
@[combinatorParenthesizer Lean.Parser.many1NoAntiquot]
def many1NoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do
manyNoAntiquot.parenthesizer p
@[combinatorParenthesizer Lean.Parser.many1Unbox]
def many1Unbox.parenthesizer (p : Parenthesizer) : Parenthesizer := do
let stx ← getCur
if stx.getKind == nullKind then
manyNoAntiquot.parenthesizer p
else
p
@[combinatorParenthesizer Lean.Parser.optionalNoAntiquot]
def optionalNoAntiquot.parenthesizer (p : Parenthesizer) : Parenthesizer := do
visitArgs p
@[combinatorParenthesizer Lean.Parser.sepByNoAntiquot]
def sepByNoAntiquot.parenthesizer (p pSep : Parenthesizer) : Parenthesizer := do
let stx ← getCur
visitArgs <| (List.range stx.getArgs.size).reverse.forM fun i => if i % 2 == 0 then p else pSep
@[combinatorParenthesizer Lean.Parser.sepBy1NoAntiquot] def sepBy1NoAntiquot.parenthesizer := sepByNoAntiquot.parenthesizer
@[combinatorParenthesizer Lean.Parser.withPosition] def withPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := do
-- We assume the formatter will indent syntax sufficiently such that parenthesizing a `withPosition` node is never necessary
modify fun st => { st with contPrec := none }
p
@[combinatorParenthesizer Lean.Parser.withPositionAfterLinebreak] def withPositionAfterLinebreak.parenthesizer (p : Parenthesizer) : Parenthesizer :=
-- TODO: improve?
withPosition.parenthesizer p
@[combinatorParenthesizer Lean.Parser.withoutPosition] def withoutPosition.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.withForbidden] def withForbidden.parenthesizer (_tk : Parser.Token) (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.withoutForbidden] def withoutForbidden.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.withoutInfo] def withoutInfo.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.setExpected]
def setExpected.parenthesizer (_expected : List String) (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.incQuotDepth] def incQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.decQuotDepth] def decQuotDepth.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.suppressInsideQuot] def suppressInsideQuot.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.evalInsideQuot] def evalInsideQuot.parenthesizer (_declName : Name) (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.checkStackTop] def checkStackTop.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkWsBefore] def checkWsBefore.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkNoWsBefore] def checkNoWsBefore.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkLinebreakBefore] def checkLinebreakBefore.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkTailWs] def checkTailWs.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkColEq] def checkColEq.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkColGe] def checkColGe.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkColGt] def checkColGt.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkLineEq] def checkLineEq.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.eoi] def eoi.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.checkNoImmediateColon] def checkNoImmediateColon.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.skip] def skip.parenthesizer : Parenthesizer := pure ()
@[combinatorParenthesizer Lean.Parser.pushNone] def pushNone.parenthesizer : Parenthesizer := goLeft
@[combinatorParenthesizer Lean.Parser.withOpenDecl] def withOpenDecl.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.withOpen] def withOpen.parenthesizer (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer Lean.Parser.interpolatedStr]
def interpolatedStr.parenthesizer (p : Parenthesizer) : Parenthesizer := do
visitArgs $ (← getCur).getArgs.reverse.forM fun chunk =>
if chunk.isOfKind interpolatedStrLitKind then
goLeft
else
p
@[combinatorParenthesizer Lean.Parser.dbgTraceState] def dbgTraceState.parenthesizer (_label : String) (p : Parenthesizer) : Parenthesizer := p
@[combinatorParenthesizer ite, macroInline] def ite {_ : Type} (c : Prop) [Decidable c] (t e : Parenthesizer) : Parenthesizer :=
if c then t else e
open Parser
abbrev ParenthesizerAliasValue := AliasValue Parenthesizer
builtin_initialize parenthesizerAliasesRef : IO.Ref (NameMap ParenthesizerAliasValue) ← IO.mkRef {}
def registerAlias (aliasName : Name) (v : ParenthesizerAliasValue) : IO Unit := do
Parser.registerAliasCore parenthesizerAliasesRef aliasName v
instance : Coe Parenthesizer ParenthesizerAliasValue := { coe := AliasValue.const }
instance : Coe (Parenthesizer → Parenthesizer) ParenthesizerAliasValue := { coe := AliasValue.unary }
instance : Coe (Parenthesizer → Parenthesizer → Parenthesizer) ParenthesizerAliasValue := { coe := AliasValue.binary }
end Parenthesizer
open Parenthesizer
/-- Add necessary parentheses in `stx` parsed by `parser`. -/
def parenthesize (parenthesizer : Parenthesizer) (stx : Syntax) : CoreM Syntax := do
trace[PrettyPrinter.parenthesize.input] "{format stx}"
catchInternalId backtrackExceptionId
(do
let (_, st) ← (parenthesizer {}).run { stxTrav := Syntax.Traverser.fromSyntax stx }
pure st.stxTrav.cur)
(fun _ => throwError "parenthesize: uncaught backtrack exception")
def parenthesizeCategory (cat : Name) := parenthesize <| categoryParser.parenthesizer cat 0
def parenthesizeTerm := parenthesizeCategory `term
def parenthesizeTactic := parenthesizeCategory `tactic
def parenthesizeCommand := parenthesizeCategory `command
builtin_initialize registerTraceClass `PrettyPrinter.parenthesize
end PrettyPrinter
end Lean
|
c745b8afa366231f8fe852758034b5ab4da0b72f | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/tactic/interactive.lean | 5278d57cd421a3de9cf8f45efbb9c406c788394d | [
"Apache-2.0"
] | permissive | aestriplex/mathlib | 77513ff2b176d74a3bec114f33b519069788811d | e2fa8b2b1b732d7c25119229e3cdfba8370cb00f | refs/heads/master | 1,621,969,960,692 | 1,586,279,279,000 | 1,586,279,279,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 41,749 | lean |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Sebastien Gouezel, Scott Morrison
-/
import tactic.lint
open lean
open lean.parser
local postfix `?`:9001 := optional
local postfix *:9001 := many
namespace tactic
namespace interactive
open interactive interactive.types expr
/-- Similar to `constructor`, but does not reorder goals. -/
meta def fconstructor : tactic unit := concat_tags tactic.fconstructor
add_tactic_doc
{ name := "fconstructor",
category := doc_category.tactic,
decl_names := [`tactic.interactive.fconstructor],
tags := ["logic", "goal management"] }
/-- `try_for n { tac }` executes `tac` for `n` ticks, otherwise uses `sorry` to close the goal.
Never fails. Useful for debugging. -/
meta def try_for (max : parse parser.pexpr) (tac : itactic) : tactic unit :=
do max ← i_to_expr_strict max >>= tactic.eval_expr nat,
λ s, match _root_.try_for max (tac s) with
| some r := r
| none := (tactic.trace "try_for timeout, using sorry" >> admit) s
end
/-- Multiple `subst`. `substs x y z` is the same as `subst x, subst y, subst z`. -/
meta def substs (l : parse ident*) : tactic unit :=
l.mmap' (λ h, get_local h >>= tactic.subst) >> try (tactic.reflexivity reducible)
add_tactic_doc
{ name := "substs",
category := doc_category.tactic,
decl_names := [`tactic.interactive.substs],
tags := ["rewrite"] }
/-- Unfold coercion-related definitions -/
meta def unfold_coes (loc : parse location) : tactic unit :=
unfold [
``coe, ``coe_t, ``has_coe_t.coe, ``coe_b,``has_coe.coe,
``lift, ``has_lift.lift, ``lift_t, ``has_lift_t.lift,
``coe_fn, ``has_coe_to_fun.coe, ``coe_sort, ``has_coe_to_sort.coe] loc
add_tactic_doc
{ name := "unfold_coes",
category := doc_category.tactic,
decl_names := [`tactic.interactive.unfold_coes],
tags := ["simplification"] }
/-- Unfold auxiliary definitions associated with the current declaration. -/
meta def unfold_aux : tactic unit :=
do tgt ← target,
name ← decl_name,
let to_unfold := (tgt.list_names_with_prefix name),
guard (¬ to_unfold.empty),
-- should we be using simp_lemmas.mk_default?
simp_lemmas.mk.dsimplify to_unfold.to_list tgt >>= tactic.change
/-- For debugging only. This tactic checks the current state for any
missing dropped goals and restores them. Useful when there are no
goals to solve but "result contains meta-variables". -/
meta def recover : tactic unit :=
metavariables >>= tactic.set_goals
/-- Like `try { tac }`, but in the case of failure it continues
from the failure state instead of reverting to the original state. -/
meta def continue (tac : itactic) : tactic unit :=
λ s, result.cases_on (tac s)
(λ a, result.success ())
(λ e ref, result.success ())
/--
`swap n` will move the `n`th goal to the front.
`swap` defaults to `swap 2`, and so interchanges the first and second goals.
-/
meta def swap (n := 2) : tactic unit :=
do gs ← get_goals,
match gs.nth (n-1) with
| (some g) := set_goals (g :: gs.remove_nth (n-1))
| _ := skip
end
add_tactic_doc
{ name := "swap",
category := doc_category.tactic,
decl_names := [`tactic.interactive.swap],
tags := ["goal management"] }
/-- `rotate` moves the first goal to the back. `rotate n` will do this `n` times. -/
meta def rotate (n := 1) : tactic unit := tactic.rotate n
add_tactic_doc
{ name := "rotate",
category := doc_category.tactic,
decl_names := [`tactic.interactive.rotate],
tags := ["goal management"] }
/-- Clear all hypotheses starting with `_`, like `_match` and `_let_match`. -/
meta def clear_ : tactic unit := tactic.repeat $ do
l ← local_context,
l.reverse.mfirst $ λ h, do
name.mk_string s p ← return $ local_pp_name h,
guard (s.front = '_'),
cl ← infer_type h >>= is_class, guard (¬ cl),
tactic.clear h
add_tactic_doc
{ name := "clear_",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_],
tags := ["context management"] }
meta def apply_iff_congr_core : tactic unit :=
applyc ``iff_of_eq
meta def congr_core' : tactic unit :=
do tgt ← target,
apply_eq_congr_core tgt
<|> apply_heq_congr_core
<|> apply_iff_congr_core
<|> fail "congr tactic failed"
/--
Same as the `congr` tactic, but takes an optional argument which gives
the depth of recursive applications. This is useful when `congr`
is too aggressive in breaking down the goal. For example, given
`⊢ f (g (x + y)) = f (g (y + x))`, `congr'` produces the goals `⊢ x = y`
and `⊢ y = x`, while `congr' 2` produces the intended `⊢ x + y = y + x`.
If, at any point, a subgoal matches a hypothesis then the subgoal will be closed. -/
meta def congr' : parse (with_desc "n" small_nat)? → tactic unit
| (some 0) := failed
| o := focus1 (assumption <|> (congr_core' >>
all_goals (reflexivity <|> `[apply proof_irrel_heq] <|>
`[apply proof_irrel] <|> try (congr' (nat.pred <$> o)))))
add_tactic_doc
{ name := "congr'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.congr', `tactic.interactive.congr],
tags := ["congruence"],
inherit_description_from := `tactic.interactive.congr' }
/--
Acts like `have`, but removes a hypothesis with the same name as
this one. For example if the state is `h : p ⊢ goal` and `f : p → q`,
then after `replace h := f h` the goal will be `h : q ⊢ goal`,
where `have h := f h` would result in the state `h : p, h : q ⊢ goal`.
This can be used to simulate the `specialize` and `apply at` tactics
of Coq. -/
meta def replace (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?)
(q₂ : parse $ (tk ":=" *> texpr)?) : tactic unit :=
do let h := h.get_or_else `this,
old ← try_core (get_local h),
«have» h q₁ q₂,
match old, q₂ with
| none, _ := skip
| some o, some _ := tactic.clear o
| some o, none := swap >> tactic.clear o >> swap
end
add_tactic_doc
{ name := "replace",
category := doc_category.tactic,
decl_names := [`tactic.interactive.replace],
tags := ["context management"] }
/-- Make every proposition in the context decidable. -/
meta def classical := tactic.classical
add_tactic_doc
{ name := "classical",
category := doc_category.tactic,
decl_names := [`tactic.interactive.classical],
tags := ["classical logic", "type class"] }
private meta def generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `eq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def generalize_arg_p : parser (pexpr × name) :=
with_desc "expr = id" $ parser.pexpr 0 >>= generalize_arg_p_aux
@[nolint def_lemma]
lemma {u} generalize_a_aux {α : Sort u}
(h : ∀ x : Sort u, (α → x) → x) : α := h α id
/--
Like `generalize` but also considers assumptions
specified by the user. The user can also specify to
omit the goal.
-/
meta def generalize_hyp (h : parse ident?) (_ : parse $ tk ":")
(p : parse generalize_arg_p)
(l : parse location) :
tactic unit :=
do h' ← get_unused_name `h,
x' ← get_unused_name `x,
g ← if ¬ l.include_goal then
do refine ``(generalize_a_aux _),
some <$> (prod.mk <$> tactic.intro x' <*> tactic.intro h')
else pure none,
n ← l.get_locals >>= tactic.revert_lst,
generalize h () p,
intron n,
match g with
| some (x',h') :=
do tactic.apply h',
tactic.clear h',
tactic.clear x'
| none := return ()
end
add_tactic_doc
{ name := "generalize_hyp",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalize_hyp],
tags := ["context management"] }
/--
The `exact e` and `refine e` tactics require a term `e` whose type is
definitionally equal to the goal. `convert e` is similar to `refine
e`, but the type of `e` is not required to exactly match the
goal. Instead, new goals are created for differences between the type
of `e` and the goal. For example, in the proof state
```lean
n : ℕ,
e : prime (2 * n + 1)
⊢ prime (n + n + 1)
```
the tactic `convert e` will change the goal to
```lean
⊢ n + n = 2 * n
```
In this example, the new goal can be solved using `ring`.
The syntax `convert ← e` will reverse the direction of the new goals
(producing `⊢ 2 * n = n + n` in this example).
Internally, `convert e` works by creating a new goal asserting that
the goal equals the type of `e`, then simplifying it using
`congr'`. The syntax `convert e using n` can be used to control the
depth of matching (like `congr' n`). In the example, `convert e using
1` would produce a new goal `⊢ n + n + 1 = 2 * n + 1`.
-/
meta def convert (sym : parse (with_desc "←" (tk "<-")?)) (r : parse texpr)
(n : parse (tk "using" *> small_nat)?) : tactic unit :=
do v ← mk_mvar,
if sym.is_some
then refine ``(eq.mp %%v %%r)
else refine ``(eq.mpr %%v %%r),
gs ← get_goals,
set_goals [v],
try (congr' n),
gs' ← get_goals,
set_goals $ gs' ++ gs
add_tactic_doc
{ name := "convert",
category := doc_category.tactic,
decl_names := [`tactic.interactive.convert],
tags := ["congruence"] }
meta def compact_decl_aux : list name → binder_info → expr → list expr →
tactic (list (list name × binder_info × expr))
| ns bi t [] := pure [(ns.reverse, bi, t)]
| ns bi t (v'@(local_const n pp bi' t') :: xs) :=
do t' ← get_local pp >>= infer_type,
if bi = bi' ∧ t = t'
then compact_decl_aux (pp :: ns) bi t xs
else do vs ← compact_decl_aux [pp] bi' t' xs,
pure $ (ns.reverse, bi, t) :: vs
| ns bi t (_ :: xs) := compact_decl_aux ns bi t xs
/-- go from (x₀ : t₀) (x₁ : t₀) (x₂ : t₀) to (x₀ x₁ x₂ : t₀) -/
meta def compact_decl : list expr → tactic (list (list name × binder_info × expr))
| [] := pure []
| (v@(local_const n pp bi t) :: xs) :=
do t ← infer_type v,
compact_decl_aux [pp] bi t xs
| (_ :: xs) := compact_decl xs
meta def clean_ids : list name :=
[``id, ``id_rhs, ``id_delta, ``hidden]
/--
Remove identity functions from a term. These are normally
automatically generated with terms like `show t, from p` or
`(p : t)` which translate to some variant on `@id t p` in
order to retain the type. -/
meta def clean (q : parse texpr) : tactic unit :=
do tgt : expr ← target,
e ← i_to_expr_strict ``(%%q : %%tgt),
tactic.exact $ e.replace (λ e n,
match e with
| (app (app (const n _) _) e') :=
if n ∈ clean_ids then some e' else none
| (app (lam _ _ _ (var 0)) e') := some e'
| _ := none
end)
meta def source_fields (missing : list name) (e : pexpr) : tactic (list (name × pexpr)) :=
do e ← to_expr e,
t ← infer_type e,
let struct_n : name := t.get_app_fn.const_name,
fields ← expanded_field_list struct_n,
let exp_fields := fields.filter (λ x, x.2 ∈ missing),
exp_fields.mmap $ λ ⟨p,n⟩,
(prod.mk n ∘ to_pexpr) <$> mk_mapp (n.update_prefix p) [none,some e]
meta def collect_struct' : pexpr → state_t (list $ expr×structure_instance_info) tactic pexpr | e :=
do some str ← pure (e.get_structure_instance_info)
| e.traverse collect_struct',
v ← monad_lift mk_mvar,
modify (list.cons (v,str)),
pure $ to_pexpr v
meta def collect_struct (e : pexpr) : tactic $ pexpr × list (expr×structure_instance_info) :=
prod.map id list.reverse <$> (collect_struct' e).run []
meta def refine_one (str : structure_instance_info) :
tactic $ list (expr×structure_instance_info) :=
do tgt ← target,
let struct_n : name := tgt.get_app_fn.const_name,
exp_fields ← expanded_field_list struct_n,
let missing_f := exp_fields.filter (λ f, (f.2 : name) ∉ str.field_names),
(src_field_names,src_field_vals) ← (@list.unzip name _ ∘ list.join) <$>
str.sources.mmap (source_fields $ missing_f.map prod.snd),
let provided := exp_fields.filter (λ f, (f.2 : name) ∈ str.field_names),
let missing_f' := missing_f.filter (λ x, x.2 ∉ src_field_names),
vs ← mk_mvar_list missing_f'.length,
(field_values,new_goals) ← list.unzip <$> (str.field_values.mmap collect_struct : tactic _),
e' ← to_expr $ pexpr.mk_structure_instance
{ struct := some struct_n
, field_names := str.field_names ++ missing_f'.map prod.snd ++ src_field_names
, field_values := field_values ++ vs.map to_pexpr ++ src_field_vals },
tactic.exact e',
gs ← with_enable_tags (
mzip_with (λ (n : name × name) v, do
set_goals [v],
try (dsimp_target simp_lemmas.mk),
apply_auto_param
<|> apply_opt_param
<|> (set_main_tag [`_field,n.2,n.1]),
get_goals)
missing_f' vs),
set_goals gs.join,
return new_goals.join
meta def refine_recursively : expr × structure_instance_info → tactic (list expr) | (e,str) :=
do set_goals [e],
rs ← refine_one str,
gs ← get_goals,
gs' ← rs.mmap refine_recursively,
return $ gs'.join ++ gs
/--
`refine_struct { .. }` acts like `refine` but works only with structure instance
literals. It creates a goal for each missing field and tags it with the name of the
field so that `have_field` can be used to generically refer to the field currently
being refined.
As an example, we can use `refine_struct` to automate the construction semigroup
instances:
```lean
refine_struct ( { .. } : semigroup α ),
-- case semigroup, mul
-- α : Type u,
-- ⊢ α → α → α
-- case semigroup, mul_assoc
-- α : Type u,
-- ⊢ ∀ (a b c : α), a * b * c = a * (b * c)
```
`have_field`, used after `refine_struct _`, poses `field` as a local constant
with the type of the field of the current goal:
```lean
refine_struct ({ .. } : semigroup α),
{ have_field, ... },
{ have_field, ... },
```
behaves like
```lean
refine_struct ({ .. } : semigroup α),
{ have field := @semigroup.mul, ... },
{ have field := @semigroup.mul_assoc, ... },
```
-/
meta def refine_struct : parse texpr → tactic unit | e :=
do (x,xs) ← collect_struct e,
refine x,
gs ← get_goals,
xs' ← xs.mmap refine_recursively,
set_goals (xs'.join ++ gs)
/--
`guard_hyp h := t` fails if the hypothesis `h` does not have type `t`.
We use this tactic for writing tests.
Fixes `guard_hyp` by instantiating meta variables
-/
meta def guard_hyp' (n : parse ident) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_eq h p
/--
`guard_expr_strict t := e` fails if the expr `t` is not equal to `e`. By contrast
to `guard_expr`, this tests strict (syntactic) equality.
We use this tactic for writing tests.
-/
meta def guard_expr_strict (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e ← to_expr p, guard (t = e)
/--
`guard_target_strict t` fails if the target of the main goal is not syntactically `t`.
We use this tactic for writing tests.
-/
meta def guard_target_strict (p : parse texpr) : tactic unit :=
do t ← target, guard_expr_strict t p
/--
`guard_hyp_strict h := t` fails if the hypothesis `h` does not have type syntactically equal
to `t`.
We use this tactic for writing tests.
-/
meta def guard_hyp_strict (n : parse ident) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_strict h p
meta def guard_hyp_nums (n : ℕ) : tactic unit :=
do k ← local_context,
guard (n = k.length) <|> fail format!"{k.length} hypotheses found"
meta def guard_tags (tags : parse ident*) : tactic unit :=
do (t : list name) ← get_main_tag,
guard (t = tags)
/-- `success_if_fail_with_msg { tac } msg` succeeds if the interactive tactic `tac` fails with
error message `msg` (for test writing purposes). -/
meta def success_if_fail_with_msg (tac : tactic.interactive.itactic) :=
tactic.success_if_fail_with_msg tac
meta def get_current_field : tactic name :=
do [_,field,str] ← get_main_tag,
expr.const_name <$> resolve_name (field.update_prefix str)
meta def field (n : parse ident) (tac : itactic) : tactic unit :=
do gs ← get_goals,
ts ← gs.mmap get_tag,
([g],gs') ← pure $ (list.zip gs ts).partition (λ x, x.snd.nth 1 = some n),
set_goals [g.1],
tac, done,
set_goals $ gs'.map prod.fst
/--
`have_field`, used after `refine_struct _` poses `field` as a local constant
with the type of the field of the current goal:
```lean
refine_struct ({ .. } : semigroup α),
{ have_field, ... },
{ have_field, ... },
```
behaves like
```lean
refine_struct ({ .. } : semigroup α),
{ have field := @semigroup.mul, ... },
{ have field := @semigroup.mul_assoc, ... },
```
-/
meta def have_field : tactic unit :=
propagate_tags $
get_current_field
>>= mk_const
>>= note `field none
>> return ()
/-- `apply_field` functions as `have_field, apply field, clear field` -/
meta def apply_field : tactic unit :=
propagate_tags $
get_current_field >>= applyc
add_tactic_doc
{ name := "refine_struct",
category := doc_category.tactic,
decl_names := [`tactic.interactive.refine_struct, `tactic.interactive.apply_field,
`tactic.interactive.have_field],
tags := ["structures"],
inherit_description_from := `tactic.interactive.refine_struct }
/--
`apply_rules hs n` applies the list of lemmas `hs` and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times.
`n` is optional, equal to 50 by default.
`hs` can contain user attributes: in this case all theorems with this
attribute are added to the list of rules.
For instance:
```lean
@[user_attribute]
meta def mono_rules : user_attribute :=
{ name := `mono_rules,
descr := "lemmas usable to prove monotonicity" }
attribute [mono_rules] add_le_add mul_le_mul_of_nonneg_right
lemma my_test {a b c d e : real} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
-- any of the following lines solve the goal:
add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3
by apply_rules [add_le_add, mul_le_mul_of_nonneg_right]
by apply_rules [mono_rules]
by apply_rules mono_rules
```
-/
meta def apply_rules (hs : parse pexpr_list_or_texpr) (n : nat := 50) : tactic unit :=
tactic.apply_rules hs n
add_tactic_doc
{ name := "apply_rules",
category := doc_category.tactic,
decl_names := [`tactic.interactive.apply_rules],
tags := ["lemma application"] }
meta def return_cast (f : option expr) (t : option (expr × expr))
(es : list (expr × expr × expr))
(e x x' eq_h : expr) :
tactic (option (expr × expr) × list (expr × expr × expr)) :=
(do guard (¬ e.has_var),
unify x x',
u ← mk_meta_univ,
f ← f <|> mk_mapp ``_root_.id [(expr.sort u : expr)],
t' ← infer_type e,
some (f',t) ← pure t | return (some (f,t'), (e,x',eq_h) :: es),
infer_type e >>= is_def_eq t,
unify f f',
return (some (f,t), (e,x',eq_h) :: es)) <|>
return (t, es)
meta def list_cast_of_aux (x : expr) (t : option (expr × expr))
(es : list (expr × expr × expr)) :
expr → tactic (option (expr × expr) × list (expr × expr × expr))
| e@`(cast %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mp %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mpr %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast none t es e x x'
| e@`(@eq.subst %%α %%p %%a %%b %%eq_h %%x') := return_cast p t es e x x' eq_h
| e@`(@eq.substr %%α %%p %%a %%b %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast p t es e x x'
| e@`(@eq.rec %%α %%a %%f %%x' _ %%eq_h) := return_cast f t es e x x' eq_h
| e@`(@eq.rec_on %%α %%a %%f %%b %%eq_h %%x') := return_cast f t es e x x' eq_h
| e := return (t,es)
meta def list_cast_of (x tgt : expr) : tactic (list (expr × expr × expr)) :=
(list.reverse ∘ prod.snd) <$> tgt.mfold (none, []) (λ e i es, list_cast_of_aux x es.1 es.2 e)
private meta def h_generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `heq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def h_generalize_arg_p : parser (pexpr × name) :=
with_desc "expr == id" $ parser.pexpr 0 >>= h_generalize_arg_p_aux
/--
`h_generalize Hx : e == x` matches on `cast _ e` in the goal and replaces it with
`x`. It also adds `Hx : e == x` as an assumption. If `cast _ e` appears multiple
times (not necessarily with the same proof), they are all replaced by `x`. `cast`
`eq.mp`, `eq.mpr`, `eq.subst`, `eq.substr`, `eq.rec` and `eq.rec_on` are all treated
as casts.
- `h_generalize Hx : e == x with h` adds hypothesis `α = β` with `e : α, x : β`;
- `h_generalize Hx : e == x with _` chooses automatically chooses the name of
assumption `α = β`;
- `h_generalize! Hx : e == x` reverts `Hx`;
- when `Hx` is omitted, assumption `Hx : e == x` is not added.
-/
meta def h_generalize (rev : parse (tk "!")?)
(h : parse ident_?)
(_ : parse (tk ":"))
(arg : parse h_generalize_arg_p)
(eqs_h : parse ( (tk "with" >> pure <$> ident_) <|> pure [])) :
tactic unit :=
do let (e,n) := arg,
let h' := if h = `_ then none else h,
h' ← (h' : tactic name) <|> get_unused_name ("h" ++ n.to_string : string),
e ← to_expr e,
tgt ← target,
((e,x,eq_h)::es) ← list_cast_of e tgt | fail "no cast found",
interactive.generalize h' () (to_pexpr e, n),
asm ← get_local h',
v ← get_local n,
hs ← es.mmap (λ ⟨e,_⟩, mk_app `eq [e,v]),
(eqs_h.zip [e]).mmap' (λ ⟨h,e⟩, do
h ← if h ≠ `_ then pure h else get_unused_name `h,
() <$ note h none eq_h ),
hs.mmap' (λ h,
do h' ← assert `h h,
tactic.exact asm,
try (rewrite_target h'),
tactic.clear h' ),
when h.is_some (do
(to_expr ``(heq_of_eq_rec_left %%eq_h %%asm)
<|> to_expr ``(heq_of_eq_mp %%eq_h %%asm))
>>= note h' none >> pure ()),
tactic.clear asm,
when rev.is_some (interactive.revert [n])
add_tactic_doc
{ name := "h_generalize",
category := doc_category.tactic,
decl_names := [`tactic.interactive.h_generalize],
tags := ["context management"] }
/-- `choose a b h using hyp` takes an hypothesis `hyp` of the form
`∀ (x : X) (y : Y), ∃ (a : A) (b : B), P x y a b` for some `P : X → Y → A → B → Prop` and outputs
into context a function `a : X → Y → A`, `b : X → Y → B` and a proposition `h` stating
`∀ (x : X) (y : Y), P x y (a x y) (b x y)`. It presumably also works with dependent versions.
Example:
```lean
example (h : ∀n m : ℕ, ∃i j, m = n + i ∨ m + j = n) : true :=
begin
choose i j h using h,
guard_hyp i := ℕ → ℕ → ℕ,
guard_hyp j := ℕ → ℕ → ℕ,
guard_hyp h := ∀ (n m : ℕ), m = n + i n m ∨ m + j n m = n,
trivial
end
```
-/
meta def choose (first : parse ident) (names : parse ident*) (tgt : parse (tk "using" *> texpr)?) :
tactic unit := do
tgt ← match tgt with
| none := get_local `this
| some e := tactic.i_to_expr_strict e
end,
tactic.choose tgt (first :: names),
try (interactive.simp none tt [simp_arg_type.expr ``(exists_prop)] [] (loc.ns $ some <$> names)),
try (tactic.clear tgt)
add_tactic_doc
{ name := "choose",
category := doc_category.tactic,
decl_names := [`tactic.interactive.choose],
tags := ["classical logic"] }
/--
The goal of `field_simp` is to reduce an expression in a field to an expression of the form `n / d`
where neither `n` nor `d` contains any division symbol, just using the simplifier (with a carefully
crafted simpset named `field_simps`) to reduce the number of division symbols whenever possible by
iterating the following steps:
- write an inverse as a division
- in any product, move the division to the right
- if there are several divisions in a product, group them together at the end and write them as a
single division
- reduce a sum to a common denominator
If the goal is an equality, this simpset will also clear the denominators, so that the proof
can normally be concluded by an application of `ring` or `ring_exp`.
`field_simp [hx, hy]` is a short form for `simp [-one_div_eq_inv, hx, hy] with field_simps`
Note that this naive algorithm will not try to detect common factors in denominators to reduce the
complexity of the resulting expression. Instead, it relies on the ability of `ring` to handle
complicated expressions in the next step.
As always with the simplifier, reduction steps will only be applied if the preconditions of the
lemmas can be checked. This means that proofs that denominators are nonzero should be included. The
fact that a product is nonzero when all factors are, and that a power of a nonzero number is
nonzero, are included in the simpset, but more complicated assertions (especially dealing with sums)
should be given explicitly. If your expression is not completely reduced by the simplifier
invocation, check the denominators of the resulting expression and provide proofs that they are
nonzero to enable further progress.
The invocation of `field_simp` removes the lemma `one_div_eq_inv` (which is marked as a simp lemma
in core) from the simpset, as this lemma works against the algorithm explained above.
For example,
```lean
example (a b c d x y : ℂ) (hx : x ≠ 0) (hy : y ≠ 0) :
a + b / x + c / x^2 + d / x^3 = a + x⁻¹ * (y * b / y + (d / x + c) / x) :=
begin
field_simp [hx, hy],
ring
end
```
-/
meta def field_simp (no_dflt : parse only_flag) (hs : parse simp_arg_list)
(attr_names : parse with_ident_list)
(locat : parse location) (cfg : simp_config_ext := {}) : tactic unit :=
let attr_names := `field_simps :: attr_names,
hs := simp_arg_type.except `one_div_eq_inv :: hs in
propagate_tags (simp_core cfg.to_simp_config cfg.discharger no_dflt hs attr_names locat)
add_tactic_doc
{ name := "field_simp",
category := doc_category.tactic,
decl_names := [`tactic.interactive.field_simp],
tags := ["simplification", "arithmetic"] }
meta def guard_expr_eq' (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e ← to_expr p, is_def_eq t e
/--
`guard_target t` fails if the target of the main goal is not `t`.
We use this tactic for writing tests.
-/
meta def guard_target' (p : parse texpr) : tactic unit :=
do t ← target, guard_expr_eq' t p
add_tactic_doc
{ name := "guard_target'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.guard_target'],
tags := ["testing"] }
/--
a weaker version of `trivial` that tries to solve the goal by reflexivity or by reducing it to true,
unfolding only `reducible` constants. -/
meta def triv : tactic unit :=
tactic.triv' <|> tactic.reflexivity reducible <|> tactic.contradiction <|> fail "triv tactic failed"
add_tactic_doc
{ name := "triv",
category := doc_category.tactic,
decl_names := [`tactic.interactive.triv],
tags := ["finishing"] }
/--
Similar to `existsi`. `use x` will instantiate the first term of an `∃` or `Σ` goal with `x`.
It will then try to close the new goal using `triv`, or try to simplify it by applying `exists_prop`.
Unlike `existsi`, `x` is elaborated with respect to the expected type.
`use` will alternatively take a list of terms `[x0, ..., xn]`.
`use` will work with constructors of arbitrary inductive types.
Examples:
```lean
example (α : Type) : ∃ S : set α, S = S :=
by use ∅
example : ∃ x : ℤ, x = x :=
by use 42
example : ∃ n > 0, n = n :=
begin
use 1,
-- goal is now 1 > 0 ∧ 1 = 1, whereas it would be ∃ (H : 1 > 0), 1 = 1 after existsi 1.
exact ⟨zero_lt_one, rfl⟩,
end
example : ∃ a b c : ℤ, a + b + c = 6 :=
by use [1, 2, 3]
example : ∃ p : ℤ × ℤ, p.1 = 1 :=
by use ⟨1, 42⟩
example : Σ x y : ℤ, (ℤ × ℤ) × ℤ :=
by use [1, 2, 3, 4, 5]
inductive foo
| mk : ℕ → bool × ℕ → ℕ → foo
example : foo :=
by use [100, tt, 4, 3]
```
-/
meta def use (l : parse pexpr_list_or_texpr) : tactic unit :=
focus1 $
tactic.use l;
try (triv <|> (do
`(Exists %%p) ← target,
to_expr ``(exists_prop.mpr) >>= tactic.apply >> skip))
add_tactic_doc
{ name := "use",
category := doc_category.tactic,
decl_names := [`tactic.interactive.use, `tactic.interactive.existsi],
tags := ["logic"],
inherit_description_from := `tactic.interactive.use }
/--
`clear_aux_decl` clears every `aux_decl` in the local context for the current goal.
This includes the induction hypothesis when using the equation compiler and
`_let_match` and `_fun_match`.
It is useful when using a tactic such as `finish`, `simp *` or `subst` that may use these
auxiliary declarations, and produce an error saying the recursion is not well founded.
```lean
example (n m : ℕ) (h₁ : n = m) (h₂ : ∃ a : ℕ, a = n ∧ a = m) : 2 * m = 2 * n :=
let ⟨a, ha⟩ := h₂ in
begin
clear_aux_decl, -- subst will fail without this line
subst h₁
end
example (x y : ℕ) (h₁ : ∃ n : ℕ, n * 1 = 2) (h₂ : 1 + 1 = 2 → x * 1 = y) : x = y :=
let ⟨n, hn⟩ := h₁ in
begin
clear_aux_decl, -- finish produces an error without this line
finish
end
```
-/
meta def clear_aux_decl : tactic unit := tactic.clear_aux_decl
add_tactic_doc
{ name := "clear_aux_decl",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_aux_decl, `tactic.clear_aux_decl],
tags := ["context management"],
inherit_description_from := `tactic.interactive.clear_aux_decl }
meta def loc.get_local_pp_names : loc → tactic (list name)
| loc.wildcard := list.map expr.local_pp_name <$> local_context
| (loc.ns l) := return l.reduce_option
meta def loc.get_local_uniq_names (l : loc) : tactic (list name) :=
list.map expr.local_uniq_name <$> l.get_locals
/--
The logic of `change x with y at l` fails when there are dependencies.
`change'` mimics the behavior of `change`, except in the case of `change x with y at l`.
In this case, it will correctly replace occurences of `x` with `y` at all possible hypotheses
in `l`. As long as `x` and `y` are defeq, it should never fail.
-/
meta def change' (q : parse texpr) : parse (tk "with" *> texpr)? → parse location → tactic unit
| none (loc.ns [none]) := do e ← i_to_expr q, change_core e none
| none (loc.ns [some h]) := do eq ← i_to_expr q, eh ← get_local h, change_core eq (some eh)
| none _ := fail "change-at does not support multiple locations"
| (some w) l :=
do l' ← loc.get_local_pp_names l,
l'.mmap' (λ e, try (change_with_at q w e)),
when l.include_goal $ change q w (loc.ns [none])
add_tactic_doc
{ name := "change'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.change', `tactic.interactive.change],
tags := ["renaming"],
inherit_description_from := `tactic.interactive.change' }
meta def convert_to_core (r : pexpr) : tactic unit :=
do tgt ← target,
h ← to_expr ``(_ : %%tgt = %%r),
rewrite_target h,
swap
/--
`convert_to g using n` attempts to change the current goal to `g`, but unlike `change`,
it will generate equality proof obligations using `congr' n` to resolve discrepancies.
`convert_to g` defaults to using `congr' 1`.
`ac_change` is `convert_to` followed by `ac_refl`. It is useful for rearranging/reassociating
e.g. sums:
```lean
example (a b c d e f g N : ℕ) : (a + b) + (c + d) + (e + f) + g ≤ N :=
begin
ac_change a + d + e + f + c + g + b ≤ _,
-- ⊢ a + d + e + f + c + g + b ≤ N
end
```
-/
meta def convert_to (r : parse texpr) (n : parse (tk "using" *> small_nat)?) : tactic unit :=
match n with
| none := convert_to_core r >> `[congr' 1]
| (some 0) := convert_to_core r
| (some o) := convert_to_core r >> congr' o
end
/-- `ac_change g using n` is `convert_to g using n; try {ac_refl}`. -/
meta def ac_change (r : parse texpr) (n : parse (tk "using" *> small_nat)?) : tactic unit :=
convert_to r n; try ac_refl
add_tactic_doc
{ name := "convert_to",
category := doc_category.tactic,
decl_names := [`tactic.interactive.convert_to, `tactic.interactive.ac_change],
tags := ["congruence"],
inherit_description_from := `tactic.interactive.convert_to }
private meta def opt_dir_with : parser (option (bool × name)) :=
(do tk "with",
arrow ← (tk "<-")?,
h ← ident,
return (arrow.is_some, h)) <|> return none
/--
`set a := t with h` is a variant of `let a := t`. It adds the hypothesis `h : a = t` to
the local context and replaces `t` with `a` everywhere it can.
`set a := t with ←h` will add `h : t = a` instead.
`set! a := t with h` does not do any replacing.
```lean
example (x : ℕ) (h : x = 3) : x + x + x = 9 :=
begin
set y := x with ←h_xy,
/-
x : ℕ,
y : ℕ := x,
h_xy : x = y,
h : y = 3
⊢ y + y + y = 9
-/
end
```
-/
meta def set (h_simp : parse (tk "!")?) (a : parse ident) (tp : parse ((tk ":") >> texpr)?)
(_ : parse (tk ":=")) (pv : parse texpr)
(rev_name : parse opt_dir_with) :=
do let vt := match tp with | some t := t | none := pexpr.mk_placeholder end,
let pv := ``(%%pv : %%vt),
v ← to_expr pv,
tp ← infer_type v,
definev a tp v,
when h_simp.is_none $ change' pv (some (expr.const a [])) loc.wildcard,
match rev_name with
| some (flip, id) :=
do nv ← get_local a,
pf ← to_expr (cond flip ``(%%pv = %%nv) ``(%%nv = %%pv)) >>= assert id,
reflexivity
| none := skip
end
add_tactic_doc
{ name := "set",
category := doc_category.tactic,
decl_names := [`tactic.interactive.set],
tags := ["context management"] }
/--
`clear_except h₀ h₁` deletes all the assumptions it can except for `h₀` and `h₁`.
-/
meta def clear_except (xs : parse ident *) : tactic unit :=
do n ← xs.mmap (try_core ∘ get_local) >>= revert_lst ∘ list.filter_map id,
ls ← local_context,
ls.reverse.mmap' $ try ∘ tactic.clear,
intron n
add_tactic_doc
{ name := "clear_except",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_except],
tags := ["context management"] }
meta def format_names (ns : list name) : format :=
format.join $ list.intersperse " " (ns.map to_fmt)
private meta def indent_bindents (l r : string) : option (list name) → expr → tactic format
| none e :=
do e ← pp e,
pformat!"{l}{format.nest l.length e}{r}"
| (some ns) e :=
do e ← pp e,
let ns := format_names ns,
let margin := l.length + ns.to_string.length + " : ".length,
pformat!"{l}{ns} : {format.nest margin e}{r}"
private meta def format_binders : list name × binder_info × expr → tactic format
| (ns, binder_info.default, t) := indent_bindents "(" ")" ns t
| (ns, binder_info.implicit, t) := indent_bindents "{" "}" ns t
| (ns, binder_info.strict_implicit, t) := indent_bindents "⦃" "⦄" ns t
| ([n], binder_info.inst_implicit, t) :=
if "_".is_prefix_of n.to_string
then indent_bindents "[" "]" none t
else indent_bindents "[" "]" [n] t
| (ns, binder_info.inst_implicit, t) := indent_bindents "[" "]" ns t
| (ns, binder_info.aux_decl, t) := indent_bindents "(" ")" ns t
private meta def partition_vars' (s : name_set) : list expr → list expr → list expr → tactic (list expr × list expr)
| [] as bs := pure (as.reverse, bs.reverse)
| (x :: xs) as bs :=
do t ← infer_type x,
if t.has_local_in s then partition_vars' xs as (x :: bs)
else partition_vars' xs (x :: as) bs
private meta def partition_vars : tactic (list expr × list expr) :=
do ls ← local_context,
partition_vars' (name_set.of_list $ ls.map expr.local_uniq_name) ls [] []
/--
Format the current goal as a stand-alone example. Useful for testing tactic.
* `extract_goal`: formats the statement as an `example` declaration
* `extract_goal my_decl`: formats the statement as a `lemma` or `def` declaration
called `my_decl`
* `extract_goal with i j k:` only use local constants `i`, `j`, `k` in the declaration
Examples:
```lean
example (i j k : ℕ) (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
begin
extract_goal,
-- prints:
-- example {i j k : ℕ} (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
-- begin
-- end
extract_goal my_lemma
-- lemma my_lemma {i j k : ℕ} (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
-- begin
-- end
end
example {i j k x y z w p q r m n : ℕ} (h₀ : i ≤ j) (h₁ : j ≤ k) (h₁ : k ≤ p) (h₁ : p ≤ q) : i ≤ k :=
begin
extract_goal my_lemma,
-- prints:
-- lemma my_lemma {i j k x y z w p q r m n : ℕ} (h₀ : i ≤ j) (h₁ : j ≤ k)
-- (h₁ : k ≤ p) (h₁ : p ≤ q) : i ≤ k :=
-- begin
-- end
extract_goal my_lemma with i j k
-- prints:
-- lemma my_lemma {i j k : ℕ} : i ≤ k :=
-- begin
-- end
end
```
-/
meta def extract_goal (print_use : parse $ tt <$ tk "!" <|> pure ff)
(n : parse ident?) (vs : parse with_ident_list)
: tactic unit :=
do tgt ← target,
((cxt₀,cxt₁),_) ← solve_aux tgt $
when (¬ vs.empty) (clear_except vs) >>
partition_vars,
tgt ← target,
is_prop ← is_prop tgt,
let title := match n, is_prop with
| none, _ := to_fmt "example"
| (some n), tt := format!"lemma {n}"
| (some n), ff := format!"def {n}"
end,
cxt₀ ← compact_decl cxt₀ >>= list.mmap format_binders,
cxt₁ ← compact_decl cxt₁ >>= list.mmap format_binders,
stmt ← pformat!"{tgt} :=",
let fmt :=
format.group $ format.nest 2 $
title ++ cxt₀.foldl (λ acc x, acc ++ format.group (format.line ++ x)) "" ++
format.line ++ format.intercalate format.line cxt₁ ++ " :" ++
format.line ++ stmt,
trace $ fmt.to_string $ options.mk.set_nat `pp.width 80,
trace!"begin\n admit\nend\n"
add_tactic_doc
{ name := "extract_goal",
category := doc_category.tactic,
decl_names := [`tactic.interactive.extract_goal],
tags := ["goal management"] }
/--
`inhabit α` tries to derive a `nonempty α` instance and then upgrades this
to an `inhabited α` instance.
If the target is a `Prop`, this is done constructively;
otherwise, it uses `classical.choice`.
```lean
example (α) [nonempty α] : ∃ a : α, true :=
begin
inhabit α,
existsi default α,
trivial
end
```
-/
meta def inhabit (t : parse parser.pexpr) (inst_name : parse ident?) : tactic unit :=
do ty ← i_to_expr t,
nm ← get_unused_name `inst,
mcond (target >>= is_prop)
(do mk_mapp `nonempty.elim_to_inhabited [ty, none] >>= tactic.apply <|>
fail "could not infer nonempty instance",
introI $ inst_name.get_or_else nm)
(do mk_mapp `classical.inhabited_of_nonempty' [ty, none] >>= note nm none <|>
fail "could not infer nonempty instance",
resetI)
add_tactic_doc
{ name := "inhabit",
category := doc_category.tactic,
decl_names := [`tactic.interactive.inhabit],
tags := ["context management", "type class"] }
/-- `revert_deps n₁ n₂ ...` reverts all the hypotheses that depend on one of `n₁, n₂, ...`
It does not revert `n₁, n₂, ...` themselves (unless they depend on another `nᵢ`). -/
meta def revert_deps (ns : parse ident*) : tactic unit :=
propagate_tags $ ns.reverse.mmap' $ λ n, get_local n >>= tactic.revert_deps
add_tactic_doc
{ name := "revert_deps",
category := doc_category.tactic,
decl_names := [`tactic.interactive.revert_deps],
tags := ["context management", "goal management"] }
/-- `revert_after n` reverts all the hypotheses after `n`. -/
meta def revert_after (n : parse ident) : tactic unit :=
propagate_tags $ get_local n >>= tactic.revert_after >> skip
add_tactic_doc
{ name := "revert_after",
category := doc_category.tactic,
decl_names := [`tactic.interactive.revert_after],
tags := ["context management", "goal management"] }
/-- `clear_value n₁ n₂ ...` clears the bodies of the local definitions `n₁, n₂ ...`, changing them
into regular hypotheses. A hypothesis `n : α := t` is changed to `n : α`. -/
meta def clear_value (ns : parse ident*) : tactic unit :=
propagate_tags $ ns.reverse.mmap' $ λ n, get_local n >>= tactic.clear_value
add_tactic_doc
{ name := "clear_value",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_value],
tags := ["context management"] }
/--
`generalize' : e = x` replaces all occurrences of `e` in the target with a new hypothesis `x` of
the same type.
`generalize' h : e = x` in addition registers the hypothesis `h : e = x`.
`generalize'` is similar to `generalize`. The difference is that `generalize' : e = x` also
succeeds when `e` does not occur in the goal. It is similar to `set`, but the resulting hypothesis
`x` is not a local definition.
-/
meta def generalize' (h : parse ident?) (_ : parse $ tk ":") (p : parse generalize_arg_p) : tactic unit :=
propagate_tags $
do let (p, x) := p,
e ← i_to_expr p,
some h ← pure h | tactic.generalize' e x >> skip,
tgt ← target,
-- if generalizing fails, fall back to not replacing anything
tgt' ← do {
⟨tgt', _⟩ ← solve_aux tgt (tactic.generalize' e x >> target),
to_expr ``(Π x, %%e = x → %%(tgt'.binding_body.lift_vars 0 1))
} <|> to_expr ``(Π x, %%e = x → %%tgt),
t ← assert h tgt',
swap,
exact ``(%%t %%e rfl),
intro x,
intro h
add_tactic_doc
{ name := "generalize'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalize'],
tags := ["context management"] }
end interactive
end tactic
|
3c9835ea3e07ffb3300b3a27f6b0269e9a9f4803 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/algebra/direct_limit.lean | dfc997c81c6f80d86aa22e46ade663db12003f80 | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 25,324 | lean | /-
Copyright (c) 2019 Kenny Lau, Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes
-/
import ring_theory.free_comm_ring
import linear_algebra.direct_sum_module
import data.finset.order
/-!
# Direct limit of modules, abelian groups, rings, and fields.
See Atiyah-Macdonald PP.32-33, Matsumura PP.269-270
Generalizes the notion of "union", or "gluing", of incomparable modules over the same ring,
or incomparable abelian groups, or rings, or fields.
It is constructed as a quotient of the free module (for the module case) or quotient of
the free commutative ring (for the ring case) instead of a quotient of the disjoint union
so as to make the operations (addition etc.) "computable".
-/
universes u v w u₁
open submodule
variables {R : Type u} [ring R]
variables {ι : Type v} [nonempty ι]
variables [decidable_eq ι] [directed_order ι]
variables (G : ι → Type w) [Π i, decidable_eq (G i)]
/-- A directed system is a functor from the category (directed poset) to another category.
This is used for abelian groups and rings and fields because their maps are not bundled.
See module.directed_system -/
class directed_system (f : Π i j, i ≤ j → G i → G j) : Prop :=
(map_self [] : ∀ i x h, f i i h x = x)
(map_map [] : ∀ i j k hij hjk x, f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x)
namespace module
variables [Π i, add_comm_group (G i)] [Π i, module R (G i)]
/-- A directed system is a functor from the category (directed poset) to the category of R-modules. -/
class directed_system (f : Π i j, i ≤ j → G i →ₗ[R] G j) : Prop :=
(map_self [] : ∀ i x h, f i i h x = x)
(map_map [] : ∀ i j k hij hjk x, f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x)
variables (f : Π i j, i ≤ j → G i →ₗ[R] G j) [directed_system G f]
/-- The direct limit of a directed system is the modules glued together along the maps. -/
def direct_limit : Type (max v w) :=
(span R $ { a | ∃ (i j) (H : i ≤ j) x,
direct_sum.lof R ι G i x - direct_sum.lof R ι G j (f i j H x) = a }).quotient
namespace direct_limit
instance : add_comm_group (direct_limit G f) := quotient.add_comm_group _
instance : semimodule R (direct_limit G f) := quotient.semimodule _
variables (R ι)
/-- The canonical map from a component to the direct limit. -/
def of (i) : G i →ₗ[R] direct_limit G f :=
(mkq _).comp $ direct_sum.lof R ι G i
variables {R ι G f}
@[simp] lemma of_f {i j hij x} : (of R ι G f j (f i j hij x)) = of R ι G f i x :=
eq.symm $ (submodule.quotient.eq _).2 $ subset_span ⟨i, j, hij, x, rfl⟩
/-- Every element of the direct limit corresponds to some element in
some component of the directed system. -/
theorem exists_of (z : direct_limit G f) : ∃ i x, of R ι G f i x = z :=
nonempty.elim (by apply_instance) $ assume ind : ι,
quotient.induction_on' z $ λ z, direct_sum.induction_on z
⟨ind, 0, linear_map.map_zero _⟩
(λ i x, ⟨i, x, rfl⟩)
(λ p q ⟨i, x, ihx⟩ ⟨j, y, ihy⟩, let ⟨k, hik, hjk⟩ := directed_order.directed i j in
⟨k, f i k hik x + f j k hjk y, by rw [linear_map.map_add, of_f, of_f, ihx, ihy]; refl⟩)
@[elab_as_eliminator]
protected theorem induction_on {C : direct_limit G f → Prop} (z : direct_limit G f)
(ih : ∀ i x, C (of R ι G f i x)) : C z :=
let ⟨i, x, h⟩ := exists_of z in h ▸ ih i x
variables {P : Type u₁} [add_comm_group P] [module R P] (g : Π i, G i →ₗ[R] P)
variables (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
include Hg
variables (R ι G f)
/-- The universal property of the direct limit: maps from the components to another module
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : direct_limit G f →ₗ[R] P :=
liftq _ (direct_sum.to_module R ι P g)
(span_le.2 $ λ a ⟨i, j, hij, x, hx⟩, by rw [← hx, mem_coe, linear_map.sub_mem_ker_iff,
direct_sum.to_module_lof, direct_sum.to_module_lof, Hg])
variables {R ι G f}
omit Hg
lemma lift_of {i} (x) : lift R ι G f g Hg (of R ι G f i x) = g i x :=
direct_sum.to_module_lof R _ _
theorem lift_unique (F : direct_limit G f →ₗ[R] P) (x) :
F x = lift R ι G f (λ i, F.comp $ of R ι G f i)
(λ i j hij x, by rw [linear_map.comp_apply, of_f]; refl) x :=
direct_limit.induction_on x $ λ i x, by rw lift_of; refl
section totalize
open_locale classical
variables (G f)
noncomputable def totalize : Π i j, G i →ₗ[R] G j :=
λ i j, if h : i ≤ j then f i j h else 0
variables {G f}
lemma totalize_apply (i j x) :
totalize G f i j x = if h : i ≤ j then f i j h x else 0 :=
if h : i ≤ j
then by dsimp only [totalize]; rw [dif_pos h, dif_pos h]
else by dsimp only [totalize]; rw [dif_neg h, dif_neg h, linear_map.zero_apply]
end totalize
lemma to_module_totalize_of_le {x : direct_sum ι G} {i j : ι}
(hij : i ≤ j) (hx : ∀ k ∈ x.support, k ≤ i) :
direct_sum.to_module R ι (G j) (λ k, totalize G f k j) x =
f i j hij (direct_sum.to_module R ι (G i) (λ k, totalize G f k i) x) :=
begin
rw [← @dfinsupp.sum_single ι G _ _ _ x],
unfold dfinsupp.sum,
simp only [linear_map.map_sum],
refine finset.sum_congr rfl (λ k hk, _),
rw direct_sum.single_eq_lof R k (x k),
simp [totalize_apply, hx k hk, le_trans (hx k hk) hij, directed_system.map_map f]
end
lemma of.zero_exact_aux {x : direct_sum ι G} (H : submodule.quotient.mk x = (0 : direct_limit G f)) :
∃ j, (∀ k ∈ x.support, k ≤ j) ∧ direct_sum.to_module R ι (G j) (λ i, totalize G f i j) x = (0 : G j) :=
nonempty.elim (by apply_instance) $ assume ind : ι,
span_induction ((quotient.mk_eq_zero _).1 H)
(λ x ⟨i, j, hij, y, hxy⟩, let ⟨k, hik, hjk⟩ := directed_order.directed i j in
⟨k, begin
clear_,
subst hxy,
split,
{ intros i0 hi0,
rw [dfinsupp.mem_support_iff, dfinsupp.sub_apply, ← direct_sum.single_eq_lof,
← direct_sum.single_eq_lof, dfinsupp.single_apply, dfinsupp.single_apply] at hi0,
split_ifs at hi0 with hi hj hj, { rwa hi at hik }, { rwa hi at hik }, { rwa hj at hjk },
exfalso, apply hi0, rw sub_zero },
simp [linear_map.map_sub, totalize_apply, hik, hjk,
directed_system.map_map f, direct_sum.apply_eq_component,
direct_sum.component.of],
end⟩)
⟨ind, λ _ h, (finset.not_mem_empty _ h).elim, linear_map.map_zero _⟩
(λ x y ⟨i, hi, hxi⟩ ⟨j, hj, hyj⟩,
let ⟨k, hik, hjk⟩ := directed_order.directed i j in
⟨k, λ l hl,
(finset.mem_union.1 (dfinsupp.support_add hl)).elim
(λ hl, le_trans (hi _ hl) hik)
(λ hl, le_trans (hj _ hl) hjk),
by simp [linear_map.map_add, hxi, hyj,
to_module_totalize_of_le hik hi,
to_module_totalize_of_le hjk hj]⟩)
(λ a x ⟨i, hi, hxi⟩,
⟨i, λ k hk, hi k (dfinsupp.support_smul hk),
by simp [linear_map.map_smul, hxi]⟩)
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact {i x} (H : of R ι G f i x = 0) :
∃ j hij, f i j hij x = (0 : G j) :=
let ⟨j, hj, hxj⟩ := of.zero_exact_aux H in
if hx0 : x = 0 then ⟨i, le_refl _, by simp [hx0]⟩
else
have hij : i ≤ j, from hj _ $
by simp [direct_sum.apply_eq_component, hx0],
⟨j, hij, by simpa [totalize_apply, hij] using hxj⟩
end direct_limit
end module
namespace add_comm_group
variables [Π i, add_comm_group (G i)]
/-- The direct limit of a directed system is the abelian groups glued together along the maps. -/
def direct_limit (f : Π i j, i ≤ j → G i → G j)
[Π i j hij, is_add_group_hom (f i j hij)] [directed_system G f] : Type* :=
@module.direct_limit ℤ _ ι _ _ _ G _ _ _
(λ i j hij, (add_monoid_hom.of $ f i j hij).to_int_linear_map)
⟨directed_system.map_self f, directed_system.map_map f⟩
namespace direct_limit
variables (f : Π i j, i ≤ j → G i → G j)
variables [Π i j hij, is_add_group_hom (f i j hij)] [directed_system G f]
lemma directed_system :
module.directed_system G (λ i j hij, (add_monoid_hom.of $ f i j hij).to_int_linear_map) :=
⟨directed_system.map_self f, directed_system.map_map f⟩
local attribute [instance] directed_system
instance : add_comm_group (direct_limit G f) :=
module.direct_limit.add_comm_group G (λ i j hij, (add_monoid_hom.of $f i j hij).to_int_linear_map)
/-- The canonical map from a component to the direct limit. -/
def of (i) : G i → direct_limit G f :=
module.direct_limit.of ℤ ι G (λ i j hij, (add_monoid_hom.of $ f i j hij).to_int_linear_map) i
variables {G f}
instance of.is_add_group_hom (i) : is_add_group_hom (of G f i) :=
linear_map.is_add_group_hom _
@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=
module.direct_limit.of_f
@[simp] lemma of_zero (i) : of G f i 0 = 0 := is_add_group_hom.map_zero _
@[simp] lemma of_add (i x y) : of G f i (x + y) = of G f i x + of G f i y := is_add_hom.map_add _ _ _
@[simp] lemma of_neg (i x) : of G f i (-x) = -of G f i x := is_add_group_hom.map_neg _ _
@[simp] lemma of_sub (i x y) : of G f i (x - y) = of G f i x - of G f i y := is_add_group_hom.map_sub _ _ _
@[elab_as_eliminator]
protected theorem induction_on {C : direct_limit G f → Prop} (z : direct_limit G f)
(ih : ∀ i x, C (of G f i x)) : C z :=
module.direct_limit.induction_on z ih
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
theorem of.zero_exact (i x) (h : of G f i x = 0) : ∃ j hij, f i j hij x = 0 :=
module.direct_limit.of.zero_exact h
variables (P : Type u₁) [add_comm_group P]
variables (g : Π i, G i → P) [Π i, is_add_group_hom (g i)]
variables (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
variables (G f)
/-- The universal property of the direct limit: maps from the components to another abelian group
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : direct_limit G f → P :=
module.direct_limit.lift ℤ ι G (λ i j hij, (add_monoid_hom.of $ f i j hij).to_int_linear_map)
(λ i, (add_monoid_hom.of $ g i).to_int_linear_map) Hg
variables {G f}
instance lift.is_add_group_hom : is_add_group_hom (lift G f P g Hg) :=
linear_map.is_add_group_hom _
@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x :=
module.direct_limit.lift_of _ _ _
@[simp] lemma lift_zero : lift G f P g Hg 0 = 0 := is_add_group_hom.map_zero _
@[simp] lemma lift_add (x y) : lift G f P g Hg (x + y) = lift G f P g Hg x + lift G f P g Hg y := is_add_hom.map_add _ _ _
@[simp] lemma lift_neg (x) : lift G f P g Hg (-x) = -lift G f P g Hg x := is_add_group_hom.map_neg _ _
@[simp] lemma lift_sub (x y) : lift G f P g Hg (x - y) = lift G f P g Hg x - lift G f P g Hg y := is_add_group_hom.map_sub _ _ _
lemma lift_unique (F : direct_limit G f → P) [is_add_group_hom F] (x) :
F x = @lift _ _ _ _ G _ _ f _ _ P _ (λ i x, F $ of G f i x) (λ i, is_add_group_hom.comp _ _)
(λ i j hij x, by dsimp; rw of_f) x :=
direct_limit.induction_on x $ λ i x, by rw lift_of
end direct_limit
end add_comm_group
namespace ring
variables [Π i, comm_ring (G i)]
variables (f : Π i j, i ≤ j → G i → G j)
variables [Π i j hij, is_ring_hom (f i j hij)]
variables [directed_system G f]
open free_comm_ring
/-- The direct limit of a directed system is the rings glued together along the maps. -/
def direct_limit : Type (max v w) :=
(ideal.span { a | (∃ i j H x, of (⟨j, f i j H x⟩ : Σ i, G i) - of ⟨i, x⟩ = a) ∨
(∃ i, of (⟨i, 1⟩ : Σ i, G i) - 1 = a) ∨
(∃ i x y, of (⟨i, x + y⟩ : Σ i, G i) - (of ⟨i, x⟩ + of ⟨i, y⟩) = a) ∨
(∃ i x y, of (⟨i, x * y⟩ : Σ i, G i) - (of ⟨i, x⟩ * of ⟨i, y⟩) = a) }).quotient
namespace direct_limit
instance : comm_ring (direct_limit G f) :=
ideal.quotient.comm_ring _
instance : ring (direct_limit G f) :=
comm_ring.to_ring _
/-- The canonical map from a component to the direct limit. -/
def of (i) (x : G i) : direct_limit G f :=
ideal.quotient.mk _ (of (⟨i, x⟩ : Σ i, G i))
variables {G f}
instance of.is_ring_hom (i) : is_ring_hom (of G f i) :=
{ map_one := ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inl ⟨i, rfl⟩,
map_mul := λ x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inr ⟨i, x, y, rfl⟩,
map_add := λ x y, ideal.quotient.eq.2 $ subset_span $ or.inr $ or.inr $ or.inl ⟨i, x, y, rfl⟩ }
@[simp] lemma of_f {i j} (hij) (x) : of G f j (f i j hij x) = of G f i x :=
ideal.quotient.eq.2 $ subset_span $ or.inl ⟨i, j, hij, x, rfl⟩
@[simp] lemma of_zero (i) : of G f i 0 = 0 := is_ring_hom.map_zero _
@[simp] lemma of_one (i) : of G f i 1 = 1 := is_ring_hom.map_one _
@[simp] lemma of_add (i x y) : of G f i (x + y) = of G f i x + of G f i y := is_ring_hom.map_add _
@[simp] lemma of_neg (i x) : of G f i (-x) = -of G f i x := is_ring_hom.map_neg _
@[simp] lemma of_sub (i x y) : of G f i (x - y) = of G f i x - of G f i y := is_ring_hom.map_sub _
@[simp] lemma of_mul (i x y) : of G f i (x * y) = of G f i x * of G f i y := is_ring_hom.map_mul _
@[simp] lemma of_pow (i x) (n : ℕ) : of G f i (x ^ n) = of G f i x ^ n := is_semiring_hom.map_pow _ _ _
/-- Every element of the direct limit corresponds to some element in
some component of the directed system. -/
theorem exists_of (z : direct_limit G f) : ∃ i x, of G f i x = z :=
nonempty.elim (by apply_instance) $ assume ind : ι,
quotient.induction_on' z $ λ x, free_abelian_group.induction_on x
⟨ind, 0, of_zero ind⟩
(λ s, multiset.induction_on s
⟨ind, 1, of_one ind⟩
(λ a s ih, let ⟨i, x⟩ := a, ⟨j, y, hs⟩ := ih, ⟨k, hik, hjk⟩ := directed_order.directed i j in
⟨k, f i k hik x * f j k hjk y, by rw [of_mul, of_f, of_f, hs]; refl⟩))
(λ s ⟨i, x, ih⟩, ⟨i, -x, by rw [of_neg, ih]; refl⟩)
(λ p q ⟨i, x, ihx⟩ ⟨j, y, ihy⟩, let ⟨k, hik, hjk⟩ := directed_order.directed i j in
⟨k, f i k hik x + f j k hjk y, by rw [of_add, of_f, of_f, ihx, ihy]; refl⟩)
@[elab_as_eliminator] theorem induction_on {C : direct_limit G f → Prop} (z : direct_limit G f)
(ih : ∀ i x, C (of G f i x)) : C z :=
let ⟨i, x, hx⟩ := exists_of z in hx ▸ ih i x
section of_zero_exact
open_locale classical
variables (G f)
lemma of.zero_exact_aux2 {x : free_comm_ring Σ i, G i} {s t} (hxs : is_supported x s) {j k}
(hj : ∀ z : Σ i, G i, z ∈ s → z.1 ≤ j) (hk : ∀ z : Σ i, G i, z ∈ t → z.1 ≤ k)
(hjk : j ≤ k) (hst : s ⊆ t) :
f j k hjk (lift (λ ix : s, f ix.1.1 j (hj ix ix.2) ix.1.2) (restriction s x)) =
lift (λ ix : t, f ix.1.1 k (hk ix ix.2) ix.1.2) (restriction t x) :=
begin
refine ring.in_closure.rec_on hxs _ _ _ _,
{ rw [restriction_one, lift_one, is_ring_hom.map_one (f j k hjk), restriction_one, lift_one] },
{ rw [restriction_neg, restriction_one, lift_neg, lift_one,
is_ring_hom.map_neg (f j k hjk), is_ring_hom.map_one (f j k hjk),
restriction_neg, restriction_one, lift_neg, lift_one] },
{ rintros _ ⟨p, hps, rfl⟩ n ih,
rw [restriction_mul, lift_mul, is_ring_hom.map_mul (f j k hjk), ih, restriction_mul, lift_mul,
restriction_of, dif_pos hps, lift_of, restriction_of, dif_pos (hst hps), lift_of],
dsimp only, rw directed_system.map_map f, refl },
{ rintros x y ihx ihy,
rw [restriction_add, lift_add, is_ring_hom.map_add (f j k hjk), ihx, ihy, restriction_add, lift_add] }
end
variables {G f}
lemma of.zero_exact_aux {x : free_comm_ring Σ i, G i} (H : ideal.quotient.mk _ x = (0 : direct_limit G f)) :
∃ j s, ∃ H : (∀ k : Σ i, G i, k ∈ s → k.1 ≤ j), is_supported x s ∧
lift (λ ix : s, f ix.1.1 j (H ix ix.2) ix.1.2) (restriction s x) = (0 : G j) :=
begin
refine span_induction (ideal.quotient.eq_zero_iff_mem.1 H) _ _ _ _,
{ rintros x (⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩),
{ refine ⟨j, {⟨i, x⟩, ⟨j, f i j hij x⟩}, _,
is_supported_sub (is_supported_of.2 $ or.inr rfl) (is_supported_of.2 $ or.inl rfl), _⟩,
{ rintros k (rfl | ⟨rfl | _⟩), exact hij, refl },
{ rw [restriction_sub, lift_sub, restriction_of, dif_pos, restriction_of, dif_pos, lift_of, lift_of],
dsimp only, rw directed_system.map_map f, exact sub_self _,
exacts [or.inr rfl, or.inl rfl] } },
{ refine ⟨i, {⟨i, 1⟩}, _, is_supported_sub (is_supported_of.2 rfl) is_supported_one, _⟩,
{ rintros k (rfl|h), refl },
{ rw [restriction_sub, lift_sub, restriction_of, dif_pos, restriction_one, lift_of, lift_one],
dsimp only, rw [is_ring_hom.map_one (f i i _), sub_self], exacts [_inst_7 i i _, rfl] } },
{ refine ⟨i, {⟨i, x+y⟩, ⟨i, x⟩, ⟨i, y⟩}, _,
is_supported_sub (is_supported_of.2 $ or.inl rfl)
(is_supported_add (is_supported_of.2 $ or.inr $ or.inl rfl)
(is_supported_of.2 $ or.inr $ or.inr rfl)), _⟩,
{ rintros k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩); refl },
{ rw [restriction_sub, restriction_add, restriction_of, restriction_of, restriction_of,
dif_pos, dif_pos, dif_pos, lift_sub, lift_add, lift_of, lift_of, lift_of],
dsimp only, rw is_ring_hom.map_add (f i i _), exact sub_self _,
exacts [or.inl rfl, by apply_instance, or.inr (or.inr rfl), or.inr (or.inl rfl)] } },
{ refine ⟨i, {⟨i, x*y⟩, ⟨i, x⟩, ⟨i, y⟩}, _,
is_supported_sub (is_supported_of.2 $ or.inl rfl)
(is_supported_mul (is_supported_of.2 $ or.inr $ or.inl rfl)
(is_supported_of.2 $ or.inr $ or.inr rfl)), _⟩,
{ rintros k (rfl | ⟨rfl | ⟨rfl | hk⟩⟩); refl },
{ rw [restriction_sub, restriction_mul, restriction_of, restriction_of, restriction_of,
dif_pos, dif_pos, dif_pos, lift_sub, lift_mul, lift_of, lift_of, lift_of],
dsimp only, rw is_ring_hom.map_mul (f i i _),
exacts [sub_self _, or.inl rfl, by apply_instance, or.inr (or.inr rfl),
or.inr (or.inl rfl)] } } },
{ refine nonempty.elim (by apply_instance) (assume ind : ι, _),
refine ⟨ind, ∅, λ _, false.elim, is_supported_zero, _⟩,
rw [restriction_zero, lift_zero] },
{ rintros x y ⟨i, s, hi, hxs, ihs⟩ ⟨j, t, hj, hyt, iht⟩,
rcases directed_order.directed i j with ⟨k, hik, hjk⟩,
have : ∀ z : Σ i, G i, z ∈ s ∪ t → z.1 ≤ k,
{ rintros z (hz | hz), exact le_trans (hi z hz) hik, exact le_trans (hj z hz) hjk },
refine ⟨k, s ∪ t, this, is_supported_add (is_supported_upwards hxs $ set.subset_union_left s t)
(is_supported_upwards hyt $ set.subset_union_right s t), _⟩,
{ rw [restriction_add, lift_add,
← of.zero_exact_aux2 G f hxs hi this hik (set.subset_union_left s t),
← of.zero_exact_aux2 G f hyt hj this hjk (set.subset_union_right s t),
ihs, is_ring_hom.map_zero (f i k hik), iht, is_ring_hom.map_zero (f j k hjk), zero_add] } },
{ rintros x y ⟨j, t, hj, hyt, iht⟩, rw smul_eq_mul,
rcases exists_finset_support x with ⟨s, hxs⟩,
rcases (s.image sigma.fst).exists_le with ⟨i, hi⟩,
rcases directed_order.directed i j with ⟨k, hik, hjk⟩,
have : ∀ z : Σ i, G i, z ∈ ↑s ∪ t → z.1 ≤ k,
{ rintros z (hz | hz), exact le_trans (hi z.1 $ finset.mem_image.2 ⟨z, hz, rfl⟩) hik, exact le_trans (hj z hz) hjk },
refine ⟨k, ↑s ∪ t, this, is_supported_mul (is_supported_upwards hxs $ set.subset_union_left ↑s t)
(is_supported_upwards hyt $ set.subset_union_right ↑s t), _⟩,
rw [restriction_mul, lift_mul,
← of.zero_exact_aux2 G f hyt hj this hjk (set.subset_union_right ↑s t),
iht, is_ring_hom.map_zero (f j k hjk), mul_zero] }
end
/-- A component that corresponds to zero in the direct limit is already zero in some
bigger module in the directed system. -/
lemma of.zero_exact {i x} (hix : of G f i x = 0) : ∃ j, ∃ hij : i ≤ j, f i j hij x = 0 :=
let ⟨j, s, H, hxs, hx⟩ := of.zero_exact_aux hix in
have hixs : (⟨i, x⟩ : Σ i, G i) ∈ s, from is_supported_of.1 hxs,
⟨j, H ⟨i, x⟩ hixs, by rw [restriction_of, dif_pos hixs, lift_of] at hx; exact hx⟩
end of_zero_exact
/-- If the maps in the directed system are injective, then the canonical maps
from the components to the direct limits are injective. -/
theorem of_injective (hf : ∀ i j hij, function.injective (f i j hij)) (i) :
function.injective (of G f i) :=
begin
suffices : ∀ x, of G f i x = 0 → x = 0,
{ intros x y hxy, rw ← sub_eq_zero_iff_eq, apply this,
rw [is_ring_hom.map_sub (of G f i), hxy, sub_self] },
intros x hx, rcases of.zero_exact hx with ⟨j, hij, hfx⟩,
apply hf i j hij, rw [hfx, is_ring_hom.map_zero (f i j hij)]
end
variables (P : Type u₁) [comm_ring P]
variables (g : Π i, G i → P) [Π i, is_ring_hom (g i)]
variables (Hg : ∀ i j hij x, g j (f i j hij x) = g i x)
include Hg
open free_comm_ring
variables (G f)
/-- The universal property of the direct limit: maps from the components to another ring
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit.
We don't use this function as the canonical form because Lean 3 fails to automatically coerce
it to a function; use `lift` instead. -/
def lift_hom : direct_limit G f →+* P :=
ideal.quotient.lift _ (free_comm_ring.lift_hom $ λ x, g x.1 x.2) begin
suffices : ideal.span _ ≤
ideal.comap (free_comm_ring.lift_hom (λ (x : Σ (i : ι), G i), g (x.fst) (x.snd))) ⊥,
{ intros x hx, exact (mem_bot P).1 (this hx) },
rw ideal.span_le, intros x hx,
rw [mem_coe, ideal.mem_comap, mem_bot],
rcases hx with ⟨i, j, hij, x, rfl⟩ | ⟨i, rfl⟩ | ⟨i, x, y, rfl⟩ | ⟨i, x, y, rfl⟩;
simp only [coe_lift_hom, lift_sub, lift_of, Hg, lift_one, lift_add, lift_mul,
is_ring_hom.map_one (g i), is_ring_hom.map_add (g i), is_ring_hom.map_mul (g i), sub_self]
end
/-- The universal property of the direct limit: maps from the components to another ring
that respect the directed system structure (i.e. make some diagram commute) give rise
to a unique map out of the direct limit. -/
def lift : direct_limit G f → P := lift_hom G f P g Hg
instance lift_is_ring_hom : is_ring_hom (lift G f P g Hg) := (lift_hom G f P g Hg).is_ring_hom
variables {G f}
omit Hg
@[simp] lemma lift_of (i x) : lift G f P g Hg (of G f i x) = g i x := free_comm_ring.lift_of _ _
@[simp] lemma lift_zero : lift G f P g Hg 0 = 0 := (lift_hom G f P g Hg).map_zero
@[simp] lemma lift_one : lift G f P g Hg 1 = 1 := (lift_hom G f P g Hg).map_one
@[simp] lemma lift_add (x y) : lift G f P g Hg (x + y) = lift G f P g Hg x + lift G f P g Hg y :=
(lift_hom G f P g Hg).map_add x y
@[simp] lemma lift_neg (x) : lift G f P g Hg (-x) = -lift G f P g Hg x :=
(lift_hom G f P g Hg).map_neg x
@[simp] lemma lift_sub (x y) : lift G f P g Hg (x - y) = lift G f P g Hg x - lift G f P g Hg y :=
(lift_hom G f P g Hg).map_sub x y
@[simp] lemma lift_mul (x y) : lift G f P g Hg (x * y) = lift G f P g Hg x * lift G f P g Hg y :=
(lift_hom G f P g Hg).map_mul x y
@[simp] lemma lift_pow (x) (n : ℕ) : lift G f P g Hg (x ^ n) = lift G f P g Hg x ^ n :=
(lift_hom G f P g Hg).map_pow x n
local attribute [instance, priority 100] is_ring_hom.comp
theorem lift_unique (F : direct_limit G f → P) [is_ring_hom F] (x) :
F x = lift G f P (λ i x, F $ of G f i x) (λ i j hij x, by rw [of_f]) x :=
direct_limit.induction_on x $ λ i x, by rw lift_of
end direct_limit
end ring
namespace field
variables [Π i, field (G i)]
variables (f : Π i j, i ≤ j → G i → G j) [Π i j hij, is_ring_hom (f i j hij)]
variables [directed_system G f]
namespace direct_limit
instance nontrivial : nontrivial (ring.direct_limit G f) :=
⟨⟨0, 1, nonempty.elim (by apply_instance) $ assume i : ι, begin
change (0 : ring.direct_limit G f) ≠ 1,
rw ← ring.direct_limit.of_one,
intros H, rcases ring.direct_limit.of.zero_exact H.symm with ⟨j, hij, hf⟩,
rw is_ring_hom.map_one (f i j hij) at hf,
exact one_ne_zero hf
end ⟩⟩
theorem exists_inv {p : ring.direct_limit G f} : p ≠ 0 → ∃ y, p * y = 1 :=
ring.direct_limit.induction_on p $ λ i x H,
⟨ring.direct_limit.of G f i (x⁻¹), by erw [← ring.direct_limit.of_mul,
mul_inv_cancel (assume h : x = 0, H $ by rw [h, ring.direct_limit.of_zero]),
ring.direct_limit.of_one]⟩
section
open_locale classical
noncomputable def inv (p : ring.direct_limit G f) : ring.direct_limit G f :=
if H : p = 0 then 0 else classical.some (direct_limit.exists_inv G f H)
protected theorem mul_inv_cancel {p : ring.direct_limit G f} (hp : p ≠ 0) : p * inv G f p = 1 :=
by rw [inv, dif_neg hp, classical.some_spec (direct_limit.exists_inv G f hp)]
protected theorem inv_mul_cancel {p : ring.direct_limit G f} (hp : p ≠ 0) : inv G f p * p = 1 :=
by rw [_root_.mul_comm, direct_limit.mul_inv_cancel G f hp]
protected noncomputable def field : field (ring.direct_limit G f) :=
{ inv := inv G f,
mul_inv_cancel := λ p, direct_limit.mul_inv_cancel G f,
inv_zero := dif_pos rfl,
.. ring.direct_limit.comm_ring G f,
.. direct_limit.nontrivial G f }
end
end direct_limit
end field
|
b7b791699d9a6dc13ff8f96d5adee29c371ea84e | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/defeq_simp3.lean | 9768789142dfce3727eb9f0299fd5ce3edc2ed0b | [
"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 | 492 | lean | attribute [reducible]
definition nat_has_add2 : has_add nat :=
has_add.mk (λ x y : nat, x + y)
attribute [reducible]
definition nat_has_add3 : nat → has_add nat :=
λ n, has_add.mk (λ x y : nat, x + y)
open tactic
set_option pp.all true
example (a b : nat) (H : (λ x : nat, @has_add.add nat nat_has_add2 a x) = (λ x : nat, @has_add.add nat (nat_has_add3 x) a b)) : true :=
by do
s ← simp_lemmas.mk_default,
get_local `H >>= infer_type >>= s^.dsimplify >>= trace,
constructor
|
0cae54386713a6a12153f88fb3e5569e8ac0c456 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/have4.lean | 1c23eff0b0dcbef954dd7d836570c6f619b53b13 | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 232 | lean | definition Prop : Type.{1} := Type.{0}
constants a b c : Prop
axiom Ha : a
axiom Hb : b
axiom Hc : c
check have H1 : a, from Ha,
then have H2 : a, from H1,
have H3 : a, from H2,
then have H4 : a, from H3,
H4
|
1010c03bc1ef1e12ee20147e0f3ad605c407abba | 4727251e0cd73359b15b664c3170e5d754078599 | /src/tactic/generalize_proofs.lean | 205f46294d8a6c8534348c7c9fcc4dd41045fb2b | [
"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,146 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import tactic.doc_commands
/-!
# `generalize_proofs`
A simple tactic to find and replace all occurrences of proof terms in the
context and goal with new variables.
-/
open interactive interactive.types lean.parser
namespace tactic
private meta def collect_proofs_in :
expr → list expr → list name × list expr → tactic (list name × list expr)
| e ctx (ns, hs) :=
let go (tac : list name × list expr → tactic (list name × list expr)) :
tactic (list name × list expr) :=
do t ← infer_type e,
mcond (is_prop t) (do
first (hs.map $ λ h, do
t' ← infer_type h,
is_def_eq t t',
g ← target,
change $ g.replace (λ a n, if a = e then some h else none),
return (ns, hs)) <|>
(let (n, ns) := (match ns with
| [] := (`_x, [])
| (n :: ns) := (n, ns)
end : name × list name) in
do generalize e n,
h ← intro n,
return (ns, h::hs)) <|> return (ns, hs)) (tac (ns, hs)) in
match e with
| expr.const _ _ := go return
| expr.local_const _ _ _ _ := do t ← infer_type e, collect_proofs_in t ctx (ns, hs)
| expr.mvar _ _ _ := do
e ← instantiate_mvars e,
match e with
| expr.mvar _ _ _ := do t ← infer_type e, collect_proofs_in t ctx (ns, hs)
| _ := collect_proofs_in e ctx (ns, hs)
end
| expr.app f x :=
go (λ nh, collect_proofs_in f ctx nh >>= collect_proofs_in x ctx)
| expr.lam n b d e :=
go (λ nh, do
nh ← collect_proofs_in d ctx nh,
var ← mk_local' n b d,
collect_proofs_in (expr.instantiate_var e var) (var::ctx) nh)
| expr.pi n b d e := do
nh ← collect_proofs_in d ctx (ns, hs),
var ← mk_local' n b d,
collect_proofs_in (expr.instantiate_var e var) (var::ctx) nh
| expr.elet n t d e :=
go (λ nh, do
nh ← collect_proofs_in t ctx nh,
nh ← collect_proofs_in d ctx nh,
collect_proofs_in (expr.instantiate_var e d) ctx nh)
| expr.macro m l :=
go (λ nh, mfoldl (λ x e, collect_proofs_in e ctx x) nh l)
| _ := return (ns, hs)
end
/-- Generalize proofs in the goal, naming them with the provided list. -/
meta def generalize_proofs (ns : list name) (loc : interactive.loc) : tactic unit :=
do intros_dep,
hs ← local_context >>= mfilter is_proof,
n ← loc.get_locals >>= revert_lst,
t ← target,
collect_proofs_in t [] (ns, hs),
intron n <|> (intros $> ())
local postfix *:9001 := many
namespace interactive
/-- Generalize proofs in the goal, naming them with the provided list.
For example:
```lean
example : list.nth_le [1, 2] 1 dec_trivial = 2 :=
begin
-- ⊢ [1, 2].nth_le 1 _ = 2
generalize_proofs h,
-- h : 1 < [1, 2].length
-- ⊢ [1, 2].nth_le 1 h = 2
end
```
-/
meta def generalize_proofs : parse ident_* → parse location → tactic unit :=
tactic.generalize_proofs
end interactive
add_tactic_doc
{ name := "generalize_proofs",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalize_proofs],
tags := ["context management"] }
end tactic
|
ca68e87a3716703fac47dc221b341e6e752600c0 | 6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf | /src/game/world7/level4.lean | b939bdee0a93aa5058679ae8189c10f96872c7ab | [
"Apache-2.0"
] | permissive | arolihas/natural_number_game | 4f0c93feefec93b8824b2b96adff8b702b8b43ce | 8e4f7b4b42888a3b77429f90cce16292bd288138 | refs/heads/master | 1,621,872,426,808 | 1,586,270,467,000 | 1,586,270,467,000 | 253,648,466 | 0 | 0 | null | 1,586,219,694,000 | 1,586,219,694,000 | null | UTF-8 | Lean | false | false | 665 | lean | /-
# Advanced proposition world.
## Level 4: `iff_trans`.
The mathematical statement $P\iff Q$ is equivalent to $(P\implies Q)\land(Q\implies P)$. The `cases`
and `split` tactics work on hypotheses and goals (respectively) of the form `P ↔ Q`. If you need
to write an `↔` arrow you can do so by typing `\iff`, but you shouldn't need to. After an initial
`intro h,` you can type `cases h with hpq hqp` to break `h : P ↔ Q` into its constituent parts.
-/
/- Lemma
If $P$, $Q$ and $R$ are true/false statements, then
$P\iff Q$ and $Q\iff R$ together imply $P\iff R$.
-/
lemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=
begin
end
|
57e3a089b3c4a122e2635f117f8c4eeec1c8acb7 | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/data/equiv/basic.lean | 996dea42570d3a103a26ff1fb3b4f203e0f307b1 | [
"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 | 42,847 | 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, Mario Carneiro
In the standard library we cannot assume the univalence axiom.
We say two types are equivalent if they are isomorphic.
Two equivalent types have the same cardinality.
-/
import tactic.split_ifs logic.function logic.unique data.set.function data.bool data.quot
open function
universes u v w
variables {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
structure equiv (α : Sort*) (β : Sort*) :=
(to_fun : α → β)
(inv_fun : β → α)
(left_inv : left_inverse inv_fun to_fun)
(right_inv : right_inverse inv_fun to_fun)
infix ` ≃ `:25 := equiv
def function.involutive.to_equiv {f : α → α} (h : involutive f) : α ≃ α :=
⟨f, f, h.left_inverse, h.right_inverse⟩
namespace equiv
/-- `perm α` is the type of bijections from `α` to itself. -/
@[reducible] def perm (α : Sort*) := equiv α α
instance : has_coe_to_fun (α ≃ β) :=
⟨_, to_fun⟩
@[simp] theorem coe_fn_mk (f : α → β) (g l r) : (equiv.mk f g l r : α → β) = f :=
rfl
theorem eq_of_to_fun_eq : ∀ {e₁ e₂ : equiv α β}, (e₁ : α → β) = e₂ → e₁ = e₂
| ⟨f₁, g₁, l₁, r₁⟩ ⟨f₂, g₂, l₂, r₂⟩ h :=
have f₁ = f₂, from h,
have g₁ = g₂, from funext $ assume x,
have f₁ (g₁ x) = f₂ (g₂ x), from (r₁ x).trans (r₂ x).symm,
have f₁ (g₁ x) = f₁ (g₂ x), by { subst f₂, exact this },
show g₁ x = g₂ x, from injective_of_left_inverse l₁ this,
by simp *
@[ext] lemma ext (f g : equiv α β) (H : ∀ x, f x = g x) : f = g :=
eq_of_to_fun_eq (funext H)
@[ext] lemma perm.ext (σ τ : equiv.perm α) (H : ∀ x, σ x = τ x) : σ = τ :=
equiv.ext _ _ H
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, λ x, rfl, λ x, rfl⟩
@[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun, e.right_inv, e.left_inv⟩
@[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂.to_fun ∘ e₁.to_fun, e₁.inv_fun ∘ e₂.inv_fun,
e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
protected theorem injective : ∀ f : α ≃ β, injective f
| ⟨f, g, h₁, h₂⟩ := injective_of_left_inverse h₁
protected theorem surjective : ∀ f : α ≃ β, surjective f
| ⟨f, g, h₁, h₂⟩ := surjective_of_has_right_inverse ⟨_, h₂⟩
protected theorem bijective (f : α ≃ β) : bijective f :=
⟨f.injective, f.surjective⟩
protected theorem subsingleton (e : α ≃ β) : ∀ [subsingleton β], subsingleton α
| ⟨H⟩ := ⟨λ a b, e.injective (H _ _)⟩
protected def decidable_eq (e : α ≃ β) [H : decidable_eq β] : decidable_eq α
| a b := decidable_of_iff _ e.injective.eq_iff
lemma nonempty_iff_nonempty : α ≃ β → (nonempty α ↔ nonempty β)
| ⟨f, g, _, _⟩ := nonempty.congr f g
protected def cast {α β : Sort*} (h : α = β) : α ≃ β :=
⟨cast h, cast h.symm, λ x, by { cases h, refl }, λ x, by { cases h, refl }⟩
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((equiv.mk f g l r).symm : β → α) = g :=
rfl
@[simp] theorem refl_apply (x : α) : equiv.refl α x = x := rfl
@[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl
@[simp] theorem apply_symm_apply : ∀ (e : α ≃ β) (x : β), e (e.symm x) = x
| ⟨f₁, g₁, l₁, r₁⟩ x := by { simp [equiv.symm], rw r₁ }
@[simp] theorem symm_apply_apply : ∀ (e : α ≃ β) (x : α), e.symm (e x) = x
| ⟨f₁, g₁, l₁, r₁⟩ x := by { simp [equiv.symm], rw l₁ }
@[simp] lemma symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
@[simp] theorem apply_eq_iff_eq : ∀ (f : α ≃ β) (x y : α), f x = f y ↔ x = y
| ⟨f₁, g₁, l₁, r₁⟩ x y := (injective_of_left_inverse l₁).eq_iff
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : equiv.cast h x = cast h x := rfl
lemma symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x :=
(eq_comm.trans e.symm_apply_eq).trans eq_comm
@[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by { cases e, refl }
@[simp] theorem symm_symm_apply (e : α ≃ β) (a : α) : e.symm.symm a = e a := by { cases e, refl }
@[simp] theorem trans_refl (e : α ≃ β) : e.trans (equiv.refl β) = e := by { cases e, refl }
@[simp] theorem refl_symm : (equiv.refl α).symm = equiv.refl α := rfl
@[simp] theorem refl_trans (e : α ≃ β) : (equiv.refl α).trans e = e := by { cases e, refl }
@[simp] theorem symm_trans (e : α ≃ β) : e.symm.trans e = equiv.refl β := ext _ _ (by simp)
@[simp] theorem trans_symm (e : α ≃ β) : e.trans e.symm = equiv.refl α := ext _ _ (by simp)
lemma trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) :=
equiv.ext _ _ $ assume a, rfl
theorem left_inverse_symm (f : equiv α β) : left_inverse f.symm f := f.left_inv
theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f := f.right_inv
def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) :=
⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm,
assume ac, begin simp [trans_assoc], rw [← trans_assoc], simp end,
assume ac, begin simp [trans_assoc], rw [← trans_assoc], simp end, ⟩
def perm_congr {α : Type*} {β : Type*} (e : α ≃ β) : perm α ≃ perm β :=
equiv_congr e e
protected lemma image_eq_preimage {α β} (e : α ≃ β) (s : set α) : e '' s = e.symm ⁻¹' s :=
set.ext $ assume x, set.mem_image_iff_of_inverse e.left_inv e.right_inv
protected lemma subset_image {α β} (e : α ≃ β) (s : set α) (t : set β) : t ⊆ e '' s ↔ e.symm '' t ⊆ s :=
by rw [set.image_subset_iff, e.image_eq_preimage]
lemma symm_image_image {α β} (f : equiv α β) (s : set α) : f.symm '' (f '' s) = s :=
by { rw [← set.image_comp], simp }
protected lemma image_compl {α β} (f : equiv α β) (s : set α) :
f '' -s = -(f '' s) :=
set.image_compl_eq f.bijective
/- The group of permutations (self-equivalences) of a type `α` -/
namespace perm
instance perm_group {α : Type u} : group (perm α) :=
begin
refine { mul := λ f g, equiv.trans g f, one := equiv.refl α, inv:= equiv.symm, ..};
intros; apply equiv.ext; try { apply trans_apply },
apply symm_apply_apply
end
@[simp] theorem mul_apply {α : Type u} (f g : perm α) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
@[simp] theorem one_apply {α : Type u} (x) : (1 : perm α) x = x := rfl
@[simp] lemma inv_apply_self {α : Type u} (f : perm α) (x) :
f⁻¹ (f x) = x := equiv.symm_apply_apply _ _
@[simp] lemma apply_inv_self {α : Type u} (f : perm α) (x) :
f (f⁻¹ x) = x := equiv.apply_symm_apply _ _
lemma one_def {α : Type u} : (1 : perm α) = equiv.refl α := rfl
lemma mul_def {α : Type u} (f g : perm α) : f * g = g.trans f := rfl
lemma inv_def {α : Type u} (f : perm α) : f⁻¹ = f.symm := rfl
end perm
def equiv_empty (h : α → false) : α ≃ empty :=
⟨λ x, (h x).elim, λ e, e.rec _, λ x, (h x).elim, λ e, e.rec _⟩
def false_equiv_empty : false ≃ empty :=
equiv_empty _root_.id
def equiv_pempty (h : α → false) : α ≃ pempty :=
⟨λ x, (h x).elim, λ e, e.rec _, λ x, (h x).elim, λ e, e.rec _⟩
def false_equiv_pempty : false ≃ pempty :=
equiv_pempty _root_.id
def empty_equiv_pempty : empty ≃ pempty :=
equiv_pempty $ empty.rec _
def pempty_equiv_pempty : pempty.{v} ≃ pempty.{w} :=
equiv_pempty pempty.elim
def empty_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : α ≃ empty :=
equiv_empty $ assume a, h ⟨a⟩
def pempty_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : α ≃ pempty :=
equiv_pempty $ assume a, h ⟨a⟩
def prop_equiv_punit {p : Prop} (h : p) : p ≃ punit :=
⟨λ x, (), λ x, h, λ _, rfl, λ ⟨⟩, rfl⟩
def true_equiv_punit : true ≃ punit := prop_equiv_punit trivial
protected def ulift {α : Type u} : ulift α ≃ α :=
⟨ulift.down, ulift.up, ulift.up_down, λ a, rfl⟩
protected def plift : plift α ≃ α :=
⟨plift.down, plift.up, plift.up_down, plift.down_up⟩
@[congr] def arrow_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(α₁ → β₁) ≃ (α₂ → β₂) :=
{ to_fun := λ f, e₂.to_fun ∘ f ∘ e₁.inv_fun,
inv_fun := λ f, e₂.inv_fun ∘ f ∘ e₁.to_fun,
left_inv := λ f, funext $ λ x, by { dsimp, rw [e₂.left_inv, e₁.left_inv] },
right_inv := λ f, funext $ λ x, by { dsimp, rw [e₂.right_inv, e₁.right_inv] } }
@[simp] lemma arrow_congr_apply {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂)
(f : α₁ → β₁) (x : α₂) :
arrow_congr e₁ e₂ f x = (e₂ $ f $ e₁.symm x) :=
rfl
lemma arrow_congr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*}
(ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) :
arrow_congr ea ec (g ∘ f) = (arrow_congr eb ec g) ∘ (arrow_congr ea eb f) :=
by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] }
@[simp] lemma arrow_congr_refl {α β : Sort*} :
arrow_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl
@[simp] lemma arrow_congr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') :=
rfl
@[simp] lemma arrow_congr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm :=
rfl
def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrow_congr e e
@[simp] lemma conj_apply (e : α ≃ β) (f : α → α) (x : β) :
e.conj f x = (e $ f $ e.symm x) :=
rfl
@[simp] lemma conj_refl : conj (equiv.refl α) = equiv.refl (α → α) := rfl
@[simp] lemma conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl
@[simp] lemma conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
(e₁.trans e₂).conj = e₁.conj.trans e₂.conj :=
rfl
@[simp] lemma conj_comp (e : α ≃ β) (f₁ f₂ : α → α) :
e.conj (f₁ ∘ f₂) = (e.conj f₁) ∘ (e.conj f₂) :=
by apply arrow_congr_comp
def punit_equiv_punit : punit.{v} ≃ punit.{w} :=
⟨λ _, punit.star, λ _, punit.star, λ u, by { cases u, refl }, λ u, by { cases u, reflexivity }⟩
section
@[simp] def arrow_punit_equiv_punit (α : Sort*) : (α → punit.{v}) ≃ punit.{w} :=
⟨λ f, punit.star, λ u f, punit.star,
λ f, by { funext x, cases f x, refl }, λ u, by { cases u, reflexivity }⟩
@[simp] def punit_arrow_equiv (α : Sort*) : (punit.{u} → α) ≃ α :=
⟨λ f, f punit.star, λ a u, a, λ f, by { funext x, cases x, refl }, λ u, rfl⟩
@[simp] def empty_arrow_equiv_punit (α : Sort*) : (empty → α) ≃ punit.{u} :=
⟨λ f, punit.star, λ u e, e.rec _, λ f, funext $ λ x, x.rec _, λ u, by { cases u, refl }⟩
@[simp] def pempty_arrow_equiv_punit (α : Sort*) : (pempty → α) ≃ punit.{u} :=
⟨λ f, punit.star, λ u e, e.rec _, λ f, funext $ λ x, x.rec _, λ u, by { cases u, refl }⟩
@[simp] def false_arrow_equiv_punit (α : Sort*) : (false → α) ≃ punit.{u} :=
calc (false → α) ≃ (empty → α) : arrow_congr false_equiv_empty (equiv.refl _)
... ≃ punit : empty_arrow_equiv_punit _
end
@[congr] def prod_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ :β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
⟨λp, (e₁ p.1, e₂ p.2), λp, (e₁.symm p.1, e₂.symm p.2),
λ ⟨a, b⟩, show (e₁.symm (e₁ a), e₂.symm (e₂ b)) = (a, b), by rw [symm_apply_apply, symm_apply_apply],
λ ⟨a, b⟩, show (e₁ (e₁.symm a), e₂ (e₂.symm b)) = (a, b), by rw [apply_symm_apply, apply_symm_apply]⟩
@[simp] theorem prod_congr_apply {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) (a : α₁) (b : β₁) :
prod_congr e₁ e₂ (a, b) = (e₁ a, e₂ b) :=
rfl
@[simp] def prod_comm (α β : Sort*) : α × β ≃ β × α :=
⟨λ p, (p.2, p.1), λ p, (p.2, p.1), λ⟨a, b⟩, rfl, λ⟨a, b⟩, rfl⟩
@[simp] def prod_assoc (α β γ : Sort*) : (α × β) × γ ≃ α × (β × γ) :=
⟨λ p, ⟨p.1.1, ⟨p.1.2, p.2⟩⟩, λp, ⟨⟨p.1, p.2.1⟩, p.2.2⟩, λ ⟨⟨a, b⟩, c⟩, rfl, λ ⟨a, ⟨b, c⟩⟩, rfl⟩
@[simp] theorem prod_assoc_apply {α β γ : Sort*} (p : (α × β) × γ) :
prod_assoc α β γ p = ⟨p.1.1, ⟨p.1.2, p.2⟩⟩ := rfl
section
@[simp] def prod_punit (α : Sort*) : α × punit.{u+1} ≃ α :=
⟨λ p, p.1, λ a, (a, punit.star), λ ⟨_, punit.star⟩, rfl, λ a, rfl⟩
@[simp] theorem prod_punit_apply {α : Sort*} (a : α × punit.{u+1}) : prod_punit α a = a.1 := rfl
@[simp] def punit_prod (α : Sort*) : punit.{u+1} × α ≃ α :=
calc punit × α ≃ α × punit : prod_comm _ _
... ≃ α : prod_punit _
@[simp] theorem punit_prod_apply {α : Sort*} (a : punit.{u+1} × α) : punit_prod α a = a.2 := rfl
@[simp] def prod_empty (α : Sort*) : α × empty ≃ empty :=
equiv_empty (λ ⟨_, e⟩, e.rec _)
@[simp] def empty_prod (α : Sort*) : empty × α ≃ empty :=
equiv_empty (λ ⟨e, _⟩, e.rec _)
@[simp] def prod_pempty (α : Sort*) : α × pempty ≃ pempty :=
equiv_pempty (λ ⟨_, e⟩, e.rec _)
@[simp] def pempty_prod (α : Sort*) : pempty × α ≃ pempty :=
equiv_pempty (λ ⟨e, _⟩, e.rec _)
end
section
open sum
def psum_equiv_sum (α β : Sort*) : psum α β ≃ α ⊕ β :=
⟨λ s, psum.cases_on s inl inr,
λ s, sum.cases_on s psum.inl psum.inr,
λ s, by cases s; refl,
λ s, by cases s; refl⟩
def sum_congr {α₁ β₁ α₂ β₂ : Sort*} : α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ ⊕ β₁ ≃ α₂ ⊕ β₂
| ⟨f₁, g₁, l₁, r₁⟩ ⟨f₂, g₂, l₂, r₂⟩ :=
⟨λ s, match s with inl a₁ := inl (f₁ a₁) | inr b₁ := inr (f₂ b₁) end,
λ s, match s with inl a₂ := inl (g₁ a₂) | inr b₂ := inr (g₂ b₂) end,
λ s, match s with inl a := congr_arg inl (l₁ a) | inr a := congr_arg inr (l₂ a) end,
λ s, match s with inl a := congr_arg inl (r₁ a) | inr a := congr_arg inr (r₂ a) end⟩
@[simp] theorem sum_congr_apply_inl {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) (a : α₁) :
sum_congr e₁ e₂ (inl a) = inl (e₁ a) :=
by { cases e₁, cases e₂, refl }
@[simp] theorem sum_congr_apply_inr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) (b : β₁) :
sum_congr e₁ e₂ (inr b) = inr (e₂ b) :=
by { cases e₁, cases e₂, refl }
@[simp] lemma sum_congr_symm {α β γ δ : Type u} (e : α ≃ β) (f : γ ≃ δ) (x) :
(equiv.sum_congr e f).symm x = (equiv.sum_congr (e.symm) (f.symm)) x :=
by { cases e, cases f, cases x; refl }
def bool_equiv_punit_sum_punit : bool ≃ punit.{u+1} ⊕ punit.{v+1} :=
⟨λ b, cond b (inr punit.star) (inl punit.star),
λ s, sum.rec_on s (λ_, ff) (λ_, tt),
λ b, by cases b; refl,
λ s, by rcases s with ⟨⟨⟩⟩ | ⟨⟨⟩⟩; refl⟩
noncomputable def Prop_equiv_bool : Prop ≃ bool :=
⟨λ p, @to_bool p (classical.prop_decidable _),
λ b, b, λ p, by simp, λ b, by simp⟩
@[simp] def sum_comm (α β : Sort*) : α ⊕ β ≃ β ⊕ α :=
⟨λ s, match s with inl a := inr a | inr b := inl b end,
λ s, match s with inl b := inr b | inr a := inl a end,
λ s, by cases s; refl,
λ s, by cases s; refl⟩
@[simp] def sum_assoc (α β γ : Sort*) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) :=
⟨λ s, match s with inl (inl a) := inl a | inl (inr b) := inr (inl b) | inr c := inr (inr c) end,
λ s, match s with inl a := inl (inl a) | inr (inl b) := inl (inr b) | inr (inr c) := inr c end,
λ s, by rcases s with ⟨_ | _⟩ | _; refl,
λ s, by rcases s with _ | _ | _; refl⟩
@[simp] theorem sum_assoc_apply_in1 {α β γ} (a) : sum_assoc α β γ (inl (inl a)) = inl a := rfl
@[simp] theorem sum_assoc_apply_in2 {α β γ} (b) : sum_assoc α β γ (inl (inr b)) = inr (inl b) := rfl
@[simp] theorem sum_assoc_apply_in3 {α β γ} (c) : sum_assoc α β γ (inr c) = inr (inr c) := rfl
@[simp] def sum_empty (α : Sort*) : α ⊕ empty ≃ α :=
⟨λ s, match s with inl a := a | inr e := empty.rec _ e end,
inl,
λ s, by { rcases s with _ | ⟨⟨⟩⟩, refl },
λ a, rfl⟩
@[simp] def empty_sum (α : Sort*) : empty ⊕ α ≃ α :=
(sum_comm _ _).trans $ sum_empty _
@[simp] def sum_pempty (α : Sort*) : α ⊕ pempty ≃ α :=
⟨λ s, match s with inl a := a | inr e := pempty.rec _ e end,
inl,
λ s, by { rcases s with _ | ⟨⟨⟩⟩, refl },
λ a, rfl⟩
@[simp] def pempty_sum (α : Sort*) : pempty ⊕ α ≃ α :=
(sum_comm _ _).trans $ sum_pempty _
@[simp] def option_equiv_sum_punit (α : Sort*) : option α ≃ α ⊕ punit.{u+1} :=
⟨λ o, match o with none := inr punit.star | some a := inl a end,
λ s, match s with inr _ := none | inl a := some a end,
λ o, by cases o; refl,
λ s, by rcases s with _ | ⟨⟨⟩⟩; refl⟩
def sum_equiv_sigma_bool (α β : Sort*) : α ⊕ β ≃ (Σ b: bool, cond b α β) :=
⟨λ s, match s with inl a := ⟨tt, a⟩ | inr b := ⟨ff, b⟩ end,
λ s, match s with ⟨tt, a⟩ := inl a | ⟨ff, b⟩ := inr b end,
λ s, by cases s; refl,
λ s, by rcases s with ⟨_|_, _⟩; refl⟩
def sigma_preimage_equiv {α β : Type*} (f : α → β) :
(Σ y : β, {x // f x = y}) ≃ α :=
⟨λ x, x.2.1, λ x, ⟨f x, x, rfl⟩, λ ⟨y, x, rfl⟩, rfl, λ x, rfl⟩
end
section
def Pi_congr_right {α} {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (Π a, β₁ a) ≃ (Π a, β₂ a) :=
⟨λ H a, F a (H a), λ H a, (F a).symm (H a),
λ H, funext $ by simp, λ H, funext $ by simp⟩
def Pi_curry {α} {β : α → Sort*} (γ : Π a, β a → Sort*) : (Π x : sigma β, γ x.1 x.2) ≃ (Π a b, γ a b) :=
{ to_fun := λ f x y, f ⟨x,y⟩,
inv_fun := λ f x, f x.1 x.2,
left_inv := λ f, funext $ λ ⟨x,y⟩, rfl,
right_inv := λ f, funext $ λ x, funext $ λ y, rfl }
end
section
def psigma_equiv_sigma {α} (β : α → Sort*) : psigma β ≃ sigma β :=
⟨λ ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
def sigma_congr_right {α} {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : sigma β₁ ≃ sigma β₂ :=
⟨λ ⟨a, b⟩, ⟨a, F a b⟩, λ ⟨a, b⟩, ⟨a, (F a).symm b⟩,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ apply_symm_apply (F a) b⟩
def sigma_congr_left {α₁ α₂} {β : α₂ → Sort*} : ∀ f : α₁ ≃ α₂, (Σ a:α₁, β (f a)) ≃ (Σ a:α₂, β a)
| ⟨f, g, l, r⟩ :=
⟨λ ⟨a, b⟩, ⟨f a, b⟩, λ ⟨a, b⟩, ⟨g a, @@eq.rec β b (r a).symm⟩,
λ ⟨a, b⟩, match g (f a), l a : ∀ a' (h : a' = a),
@sigma.mk _ (β ∘ f) _ (@@eq.rec β b (congr_arg f h.symm)) = ⟨a, b⟩ with
| _, rfl := rfl end,
λ ⟨a, b⟩, match f (g a), _ : ∀ a' (h : a' = a), sigma.mk a' (@@eq.rec β b h.symm) = ⟨a, b⟩ with
| _, rfl := rfl end⟩
def sigma_equiv_prod (α β : Sort*) : (Σ_:α, β) ≃ α × β :=
⟨λ ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, ⟨a, b⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
def sigma_equiv_prod_of_equiv {α β} {β₁ : α → Sort*} (F : ∀ a, β₁ a ≃ β) : sigma β₁ ≃ α × β :=
(sigma_congr_right F).trans (sigma_equiv_prod α β)
end
section
def arrow_prod_equiv_prod_arrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) :=
⟨λ f, (λ c, (f c).1, λ c, (f c).2),
λ p c, (p.1 c, p.2 c),
λ f, funext $ λ c, prod.mk.eta,
λ p, by { cases p, refl }⟩
def arrow_arrow_equiv_prod_arrow (α β γ : Sort*) : (α → β → γ) ≃ (α × β → γ) :=
⟨λ f, λ p, f p.1 p.2,
λ f, λ a b, f (a, b),
λ f, rfl,
λ f, by { funext p, cases p, refl }⟩
open sum
def sum_arrow_equiv_prod_arrow (α β γ : Type*) : ((α ⊕ β) → γ) ≃ (α → γ) × (β → γ) :=
⟨λ f, (f ∘ inl, f ∘ inr),
λ p s, sum.rec_on s p.1 p.2,
λ f, by { funext s, cases s; refl },
λ p, by { cases p, refl }⟩
def sum_prod_distrib (α β γ : Sort*) : (α ⊕ β) × γ ≃ (α × γ) ⊕ (β × γ) :=
⟨λ p, match p with (inl a, c) := inl (a, c) | (inr b, c) := inr (b, c) end,
λ s, match s with inl (a, c) := (inl a, c) | inr (b, c) := (inr b, c) end,
λ p, by rcases p with ⟨_ | _, _⟩; refl,
λ s, by rcases s with ⟨_, _⟩ | ⟨_, _⟩; refl⟩
@[simp] theorem sum_prod_distrib_apply_left {α β γ} (a : α) (c : γ) :
sum_prod_distrib α β γ (sum.inl a, c) = sum.inl (a, c) := rfl
@[simp] theorem sum_prod_distrib_apply_right {α β γ} (b : β) (c : γ) :
sum_prod_distrib α β γ (sum.inr b, c) = sum.inr (b, c) := rfl
def prod_sum_distrib (α β γ : Sort*) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) :=
calc α × (β ⊕ γ) ≃ (β ⊕ γ) × α : prod_comm _ _
... ≃ (β × α) ⊕ (γ × α) : sum_prod_distrib _ _ _
... ≃ (α × β) ⊕ (α × γ) : sum_congr (prod_comm _ _) (prod_comm _ _)
@[simp] theorem prod_sum_distrib_apply_left {α β γ} (a : α) (b : β) :
prod_sum_distrib α β γ (a, sum.inl b) = sum.inl (a, b) := rfl
@[simp] theorem prod_sum_distrib_apply_right {α β γ} (a : α) (c : γ) :
prod_sum_distrib α β γ (a, sum.inr c) = sum.inr (a, c) := rfl
def sigma_prod_distrib {ι : Type*} (α : ι → Type*) (β : Type*) :
((Σ i, α i) × β) ≃ (Σ i, (α i × β)) :=
⟨λ p, ⟨p.1.1, (p.1.2, p.2)⟩,
λ p, (⟨p.1, p.2.1⟩, p.2.2),
λ p, by { rcases p with ⟨⟨_, _⟩, _⟩, refl },
λ p, by { rcases p with ⟨_, ⟨_, _⟩⟩, refl }⟩
def bool_prod_equiv_sum (α : Type u) : bool × α ≃ α ⊕ α :=
calc bool × α ≃ (unit ⊕ unit) × α : prod_congr bool_equiv_punit_sum_punit (equiv.refl _)
... ≃ α × (unit ⊕ unit) : prod_comm _ _
... ≃ (α × unit) ⊕ (α × unit) : prod_sum_distrib _ _ _
... ≃ α ⊕ α : sum_congr (prod_punit _) (prod_punit _)
end
section
open sum nat
def nat_equiv_nat_sum_punit : ℕ ≃ ℕ ⊕ punit.{u+1} :=
⟨λ n, match n with zero := inr punit.star | succ a := inl a end,
λ s, match s with inl n := succ n | inr punit.star := zero end,
λ n, begin cases n, repeat { refl } end,
λ s, begin cases s with a u, { refl }, {cases u, { refl }} end⟩
@[simp] def nat_sum_punit_equiv_nat : ℕ ⊕ punit.{u+1} ≃ ℕ :=
nat_equiv_nat_sum_punit.symm
def int_equiv_nat_sum_nat : ℤ ≃ ℕ ⊕ ℕ :=
by refine ⟨_, _, _, _⟩; intro z; {cases z; [left, right]; assumption} <|> {cases z; refl}
end
def list_equiv_of_equiv {α β : Type*} : α ≃ β → list α ≃ list β
| ⟨f, g, l, r⟩ :=
by refine ⟨list.map f, list.map g, λ x, _, λ x, _⟩;
simp [id_of_left_inverse l, id_of_right_inverse r]
def fin_equiv_subtype (n : ℕ) : fin n ≃ {m // m < n} :=
⟨λ x, ⟨x.1, x.2⟩, λ x, ⟨x.1, x.2⟩, λ ⟨a, b⟩, rfl,λ ⟨a, b⟩, rfl⟩
def decidable_eq_of_equiv [decidable_eq β] (e : α ≃ β) : decidable_eq α
| a₁ a₂ := decidable_of_iff (e a₁ = e a₂) e.injective.eq_iff
def inhabited_of_equiv [inhabited β] (e : α ≃ β) : inhabited α :=
⟨e.symm (default _)⟩
def unique_of_equiv (e : α ≃ β) (h : unique β) : unique α :=
unique.of_surjective e.symm.surjective
def unique_congr (e : α ≃ β) : unique α ≃ unique β :=
{ to_fun := e.symm.unique_of_equiv,
inv_fun := e.unique_of_equiv,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
section
open subtype
def subtype_congr {p : α → Prop} {q : β → Prop}
(e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : {a : α // p a} ≃ {b : β // q b} :=
⟨λ x, ⟨e x.1, (h _).1 x.2⟩,
λ y, ⟨e.symm y.1, (h _).2 (by { simp, exact y.2 })⟩,
λ ⟨x, h⟩, subtype.eq' $ by simp,
λ ⟨y, h⟩, subtype.eq' $ by simp⟩
def subtype_congr_right {p q : α → Prop} (e : ∀x, p x ↔ q x) : subtype p ≃ subtype q :=
subtype_congr (equiv.refl _) e
@[simp] lemma subtype_congr_right_mk {p q : α → Prop} (e : ∀x, p x ↔ q x)
{x : α} (h : p x) : subtype_congr_right e ⟨x, h⟩ = ⟨x, (e x).1 h⟩ := rfl
def subtype_equiv_of_subtype' {p : α → Prop} (e : α ≃ β) :
{a : α // p a} ≃ {b : β // p (e.symm b)} :=
subtype_congr e $ by simp
def subtype_congr_prop {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q :=
subtype_congr (equiv.refl α) (assume a, h ▸ iff.rfl)
def set_congr {α : Type*} {s t : set α} (h : s = t) : s ≃ t :=
subtype_congr_prop h
def subtype_subtype_equiv_subtype_exists {α : Type u} (p : α → Prop) (q : subtype p → Prop) :
subtype q ≃ {a : α // ∃h:p a, q ⟨a, h⟩ } :=
⟨λ⟨⟨a, ha⟩, ha'⟩, ⟨a, ha, ha'⟩,
λ⟨a, ha⟩, ⟨⟨a, ha.cases_on $ assume h _, h⟩, by { cases ha, exact ha_h }⟩,
assume ⟨⟨a, ha⟩, h⟩, rfl, assume ⟨a, h₁, h₂⟩, rfl⟩
def subtype_subtype_equiv_subtype_inter {α : Type u} (p q : α → Prop) :
{x : subtype p // q x.1} ≃ subtype (λ x, p x ∧ q x) :=
(subtype_subtype_equiv_subtype_exists p _).trans $
subtype_congr_right $ λ x, exists_prop
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
def subtype_subtype_equiv_subtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{x : subtype p // q x.1} ≃ subtype q :=
(subtype_subtype_equiv_subtype_inter p _).trans $
subtype_congr_right $
assume x,
⟨and.right, λ h₁, ⟨h h₁, h₁⟩⟩
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
def subtype_univ_equiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) :
subtype p ≃ α :=
⟨λ x, x, λ x, ⟨x, h x⟩, λ x, subtype.eq rfl, λ x, rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtype_sigma_equiv {α : Type u} (p : α → Type v) (q : α → Prop) :
{ y : sigma p // q y.1 } ≃ Σ(x : subtype q), p x.1 :=
⟨λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ ⟨⟨x, h⟩, y⟩, rfl,
λ ⟨⟨x, y⟩, h⟩, rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigma_subtype_equiv_of_subset {α : Type u} (p : α → Type v) (q : α → Prop)
(h : ∀ x, p x → q x) :
(Σ x : subtype q, p x) ≃ Σ x : α, p x :=
(subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ λ x, h x.1 x.2
def sigma_subtype_preimage_equiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop)
(h : ∀ x, p (f x)) :
(Σ y : subtype p, {x : α // f x = y}) ≃ α :=
calc _ ≃ Σ y : β, {x : α // f x = y} : sigma_subtype_equiv_of_subset _ p (λ y ⟨x, h'⟩, h' ▸ h x)
... ≃ α : sigma_preimage_equiv f
def sigma_subtype_preimage_equiv_subtype {α : Type u} {β : Type v} (f : α → β)
{p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) :
(Σ y : subtype q, {x : α // f x = y}) ≃ subtype p :=
calc (Σ y : subtype q, {x : α // f x = y}) ≃
Σ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} :
begin
apply sigma_congr_right,
assume y,
symmetry,
refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_congr_right _),
assume x,
exact ⟨λ ⟨hp, h'⟩, congr_arg subtype.val h', λ h', ⟨(h x).2 (h'.symm ▸ y.2), subtype.eq h'⟩⟩
end
... ≃ subtype p : sigma_preimage_equiv (λ x : subtype p, (⟨f x, (h x).1 x.property⟩ : subtype q))
def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) :
(Πi, π i) ≃ {f : ι → Σi, π i | ∀i, (f i).1 = i } :=
⟨ λf, ⟨λi, ⟨i, f i⟩, assume i, rfl⟩, λf i, begin rw ← f.2 i, exact (f.1 i).2 end,
assume f, funext $ assume i, rfl,
assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩
def subtype_pi_equiv_pi {α : Sort u} {β : α → Sort v} {p : Πa, β a → Prop} :
{f : Πa, β a // ∀a, p a (f a) } ≃ Πa, { b : β a // p a b } :=
⟨λf a, ⟨f.1 a, f.2 a⟩, λf, ⟨λa, (f a).1, λa, (f a).2⟩,
by { rintro ⟨f, h⟩, refl },
by { rintro f, funext a, exact subtype.eq' rfl }⟩
end
namespace set
open set
protected def univ (α) : @univ α ≃ α :=
⟨subtype.val, λ a, ⟨a, trivial⟩, λ ⟨a, _⟩, rfl, λ a, rfl⟩
@[simp] lemma univ_apply {α : Type u} (x : @univ α) :
equiv.set.univ α x = x := rfl
@[simp] lemma univ_symm_apply {α : Type u} (x : α) :
(equiv.set.univ α).symm x = ⟨x, trivial⟩ := rfl
protected def empty (α) : (∅ : set α) ≃ empty :=
equiv_empty $ λ ⟨x, h⟩, not_mem_empty x h
protected def pempty (α) : (∅ : set α) ≃ pempty :=
equiv_pempty $ λ ⟨x, h⟩, not_mem_empty x h
protected def union' {α} {s t : set α}
(p : α → Prop) [decidable_pred p]
(hs : ∀ x ∈ s, p x)
(ht : ∀ x ∈ t, ¬ p x) : (s ∪ t : set α) ≃ s ⊕ t :=
{ to_fun := λ x, if hp : p x.1
then sum.inl ⟨_, x.2.resolve_right (λ xt, ht _ xt hp)⟩
else sum.inr ⟨_, x.2.resolve_left (λ xs, hp (hs _ xs))⟩,
inv_fun := λ o, match o with
| (sum.inl x) := ⟨x.1, or.inl x.2⟩
| (sum.inr x) := ⟨x.1, or.inr x.2⟩
end,
left_inv := λ ⟨x, h'⟩, by by_cases p x; simp [union'._match_1, h]; congr,
right_inv := λ o, begin
rcases o with ⟨x, h⟩ | ⟨x, h⟩;
dsimp [union'._match_1];
[simp [hs _ h], simp [ht _ h]]
end }
protected def union {α} {s t : set α} [decidable_pred s] (H : s ∩ t = ∅) :
(s ∪ t : set α) ≃ s ⊕ t :=
set.union' s (λ _, id) (λ x xt xs, subset_empty_iff.2 H ⟨xs, xt⟩)
lemma union_apply_left {α} {s t : set α} [decidable_pred s] (H : s ∩ t = ∅)
{a : (s ∪ t : set α)} (ha : ↑a ∈ s) : equiv.set.union H a = sum.inl ⟨a, ha⟩ :=
dif_pos ha
lemma union_apply_right {α} {s t : set α} [decidable_pred s] (H : s ∩ t = ∅)
{a : (s ∪ t : set α)} (ha : ↑a ∈ t) : equiv.set.union H a = sum.inr ⟨a, ha⟩ :=
dif_neg (show ↑a ∉ s, by finish [set.ext_iff])
protected def singleton {α} (a : α) : ({a} : set α) ≃ punit.{u} :=
⟨λ _, punit.star, λ _, ⟨a, mem_singleton _⟩,
λ ⟨x, h⟩, by { simp at h, subst x },
λ ⟨⟩, rfl⟩
protected def of_eq {α : Type u} {s t : set α} (h : s = t) : s ≃ t :=
{ to_fun := λ x, ⟨x.1, h ▸ x.2⟩,
inv_fun := λ x, ⟨x.1, h.symm ▸ x.2⟩,
left_inv := λ _, subtype.eq rfl,
right_inv := λ _, subtype.eq rfl }
@[simp] lemma of_eq_apply {α : Type u} {s t : set α} (h : s = t) (a : s) :
equiv.set.of_eq h a = ⟨a, h ▸ a.2⟩ := rfl
@[simp] lemma of_eq_symm_apply {α : Type u} {s t : set α} (h : s = t) (a : t) :
(equiv.set.of_eq h).symm a = ⟨a, h.symm ▸ a.2⟩ := rfl
protected def insert {α} {s : set.{u} α} [decidable_pred s] {a : α} (H : a ∉ s) :
(insert a s : set α) ≃ s ⊕ punit.{u+1} :=
calc (insert a s : set α) ≃ ↥(s ∪ {a}) : equiv.set.of_eq (by simp)
... ≃ s ⊕ ({a} : set α) : equiv.set.union (by finish [set.ext_iff])
... ≃ s ⊕ punit.{u+1} : sum_congr (equiv.refl _) (equiv.set.singleton _)
protected def sum_compl {α} (s : set α) [decidable_pred s] : s ⊕ (-s : set α) ≃ α :=
calc s ⊕ (-s : set α) ≃ ↥(s ∪ -s) : (equiv.set.union (by simp [set.ext_iff])).symm
... ≃ @univ α : equiv.set.of_eq (by simp)
... ≃ α : equiv.set.univ _
@[simp] lemma sum_compl_apply_inl {α : Type u} (s : set α) [decidable_pred s] (x : s) :
equiv.set.sum_compl s (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {α : Type u} (s : set α) [decidable_pred s] (x : -s) :
equiv.set.sum_compl s (sum.inr x) = x := rfl
lemma sum_compl_symm_apply_of_mem {α : Type u} {s : set α} [decidable_pred s] {x : α}
(hx : x ∈ s) : (equiv.set.sum_compl s).symm x = sum.inl ⟨x, hx⟩ :=
have ↑(⟨x, or.inl hx⟩ : (s ∪ -s : set α)) ∈ s, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_left _ this }
lemma sum_compl_symm_apply_of_not_mem {α : Type u} {s : set α} [decidable_pred s] {x : α}
(hx : x ∉ s) : (equiv.set.sum_compl s).symm x = sum.inr ⟨x, hx⟩ :=
have ↑(⟨x, or.inr hx⟩ : (s ∪ -s : set α)) ∈ -s, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_right _ this }
protected def union_sum_inter {α : Type u} (s t : set α) [decidable_pred s] :
(s ∪ t : set α) ⊕ (s ∩ t : set α) ≃ s ⊕ t :=
calc (s ∪ t : set α) ⊕ (s ∩ t : set α)
≃ (s ∪ t \ s : set α) ⊕ (s ∩ t : set α) : by rw [union_diff_self]
... ≃ (s ⊕ (t \ s : set α)) ⊕ (s ∩ t : set α) :
sum_congr (set.union (inter_diff_self _ _)) (equiv.refl _)
... ≃ s ⊕ (t \ s : set α) ⊕ (s ∩ t : set α) : sum_assoc _ _ _
... ≃ s ⊕ (t \ s ∪ s ∩ t : set α) : sum_congr (equiv.refl _) begin
refine (set.union' (∉ s) _ _).symm,
exacts [λ x hx, hx.2, λ x hx, not_not_intro hx.1]
end
... ≃ s ⊕ t : by { rw (_ : t \ s ∪ s ∩ t = t), rw [union_comm, inter_comm, inter_union_diff] }
protected def prod {α β} (s : set α) (t : set β) :
s.prod t ≃ s × t :=
⟨λp, ⟨⟨p.1.1, p.2.1⟩, ⟨p.1.2, p.2.2⟩⟩,
λp, ⟨⟨p.1.1, p.2.1⟩, ⟨p.1.2, p.2.2⟩⟩,
λ ⟨⟨x, y⟩, ⟨h₁, h₂⟩⟩, rfl,
λ ⟨⟨x, h₁⟩, ⟨y, h₂⟩⟩, rfl⟩
protected noncomputable def image_of_inj_on {α β} (f : α → β) (s : set α) (H : inj_on f s) :
s ≃ (f '' s) :=
⟨λ ⟨x, h⟩, ⟨f x, mem_image_of_mem f h⟩,
λ ⟨y, h⟩, ⟨classical.some h, (classical.some_spec h).1⟩,
λ ⟨x, h⟩, subtype.eq (H (classical.some_spec (mem_image_of_mem f h)).1 h
(classical.some_spec (mem_image_of_mem f h)).2),
λ ⟨y, h⟩, subtype.eq (classical.some_spec h).2⟩
protected noncomputable def image {α β} (f : α → β) (s : set α) (H : injective f) : s ≃ (f '' s) :=
equiv.set.image_of_inj_on f s (λ x y hx hy hxy, H hxy)
@[simp] theorem image_apply {α β} (f : α → β) (s : set α) (H : injective f) (a h) :
set.image f s H ⟨a, h⟩ = ⟨f a, mem_image_of_mem _ h⟩ := rfl
protected noncomputable def range {α β} (f : α → β) (H : injective f) :
α ≃ range f :=
{ to_fun := λ x, ⟨f x, mem_range_self _⟩,
inv_fun := λ x, classical.some x.2,
left_inv := λ x, H (classical.some_spec (show f x ∈ range f, from mem_range_self _)),
right_inv := λ x, subtype.eq $ classical.some_spec x.2 }
@[simp] theorem range_apply {α β} (f : α → β) (H : injective f) (a) :
set.range f H a = ⟨f a, set.mem_range_self _⟩ := rfl
protected def congr {α β : Type*} (e : α ≃ β) : set α ≃ set β :=
⟨λ s, e '' s, λ t, e.symm '' t, symm_image_image e, symm_image_image e.symm⟩
protected def sep {α : Type u} (s : set α) (t : α → Prop) :
({ x ∈ s | t x } : set α) ≃ { x : s | t x.1 } :=
(equiv.subtype_subtype_equiv_subtype_inter s t).symm
end set
noncomputable def of_bijective {α β} {f : α → β} (hf : bijective f) : α ≃ β :=
⟨f, λ x, classical.some (hf.2 x), λ x, hf.1 (classical.some_spec (hf.2 (f x))),
λ x, classical.some_spec (hf.2 x)⟩
@[simp] theorem of_bijective_to_fun {α β} {f : α → β} (hf : bijective f) : (of_bijective hf : α → β) = f := rfl
def subtype_quotient_equiv_quotient_subtype (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) :
{x // p₂ x} ≃ quotient s₂ :=
{ to_fun := λ a, quotient.hrec_on a.1 (λ a h, ⟦⟨a, (hp₂ _).2 h⟩⟧)
(λ a b hab, hfunext (by rw quotient.sound hab)
(λ h₁ h₂ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2,
inv_fun := λ a, quotient.lift_on a (λ a, (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : {x // p₂ x}))
(λ a b hab, subtype.eq' (quotient.sound ((h _ _).1 hab))),
left_inv := λ ⟨a, ha⟩, quotient.induction_on a (λ a ha, rfl) ha,
right_inv := λ a, quotient.induction_on a (λ ⟨a, ha⟩, rfl) }
section swap
variable [decidable_eq α]
open decidable
def swap_core (a b r : α) : α :=
if r = a then b
else if r = b then a
else r
theorem swap_core_self (r a : α) : swap_core a a r = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_swap_core (r a b : α) : swap_core a b (swap_core a b r) = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_comm (r a b : α) : swap_core a b r = swap_core b a r :=
by { unfold swap_core, split_ifs; cc }
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : perm α :=
⟨swap_core a b, swap_core a b, λr, swap_core_swap_core r a b, λr, swap_core_swap_core r a b⟩
theorem swap_self (a : α) : swap a a = equiv.refl _ :=
eq_of_to_fun_eq $ funext $ λ r, swap_core_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
eq_of_to_fun_eq $ funext $ λ r, swap_core_comm r _ _
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp] theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp] theorem swap_apply_right (a b : α) : swap a b b = a :=
by { by_cases b = a; simp [swap_apply_def, *] }
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x :=
by simp [swap_apply_def] {contextual := tt}
@[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = equiv.refl _ :=
eq_of_to_fun_eq $ funext $ λ x, swap_core_swap_core _ _ _
theorem swap_comp_apply {a b x : α} (π : perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x :=
by { cases π, refl }
@[simp] lemma swap_inv {α : Type*} [decidable_eq α] (x y : α) :
(swap x y)⁻¹ = swap x y := rfl
@[simp] lemma symm_trans_swap_trans [decidable_eq β] (a b : α)
(e : α ≃ β) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
equiv.ext _ _ (λ x, begin
have : ∀ a, e.symm x = a ↔ x = e a :=
λ a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * },
simp [swap_apply_def, this],
split_ifs; simp
end)
@[simp] lemma swap_mul_self {α : Type*} [decidable_eq α] (i j : α) : swap i j * swap i j = 1 :=
equiv.swap_swap i j
@[simp] lemma swap_apply_self {α : Type*} [decidable_eq α] (i j a : α) : swap i j (swap i j a) = a :=
by rw [← perm.mul_apply, swap_mul_self, perm.one_apply]
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def set_value (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp] theorem set_value_eq (f : α ≃ β) (a : α) (b : β) : set_value f a b a = b :=
by { dsimp [set_value], simp [swap_apply_left] }
end swap
protected lemma forall_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p x ↔ q (f x)) : (∀x, p x) ↔ (∀y, q y) :=
begin
split; intros h₂ x,
{ rw [←f.right_inv x], apply h.mp, apply h₂ },
apply h.mpr, apply h₂
end
end equiv
instance {α} [subsingleton α] : subsingleton (ulift α) := equiv.ulift.subsingleton
instance {α} [subsingleton α] : subsingleton (plift α) := equiv.plift.subsingleton
instance {α} [decidable_eq α] : decidable_eq (ulift α) := equiv.ulift.decidable_eq
instance {α} [decidable_eq α] : decidable_eq (plift α) := equiv.plift.decidable_eq
def unique_unique_equiv : unique (unique α) ≃ unique α :=
{ to_fun := λ h, h.default,
inv_fun := λ h, { default := h, uniq := λ _, subsingleton.elim _ _ },
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
def equiv_of_unique_of_unique [unique α] [unique β] : α ≃ β :=
{ to_fun := λ _, default β,
inv_fun := λ _, default α,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
def equiv_punit_of_unique [unique α] : α ≃ punit.{v} :=
equiv_of_unique_of_unique
namespace quot
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) :
quot ra ≃ quot rb :=
{ to_fun := quot.map e (assume a₁ a₂, (eq a₁ a₂).1),
inv_fun := quot.map e.symm
(assume b₁ b₂ h,
(eq (e.symm b₁) (e.symm b₂)).2
((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)),
left_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.symm_apply_apply] },
right_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.apply_symm_apply] } }
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : α → α → Prop} (eq : ∀a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) :
quot r ≃ quot r' :=
quot.congr (equiv.refl α) eq
/-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α`
by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/
protected def congr_left {r : α → α → Prop} (e : α ≃ β) :
quot r ≃ quot (λ b b', r (e.symm b) (e.symm b')) :=
@quot.congr α β r (λ b b', r (e.symm b) (e.symm b')) e (λ a₁ a₂, by simp only [e.symm_apply_apply])
end quot
namespace quotient
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : setoid α} {rb : setoid β} (e : α ≃ β)
(eq : ∀a₁ a₂, @setoid.r α ra a₁ a₂ ↔ @setoid.r β rb (e a₁) (e a₂)) :
quotient ra ≃ quotient rb :=
quot.congr e eq
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : setoid α}
(eq : ∀a₁ a₂, @setoid.r α r a₁ a₂ ↔ @setoid.r α r' a₁ a₂) : quotient r ≃ quotient r' :=
quot.congr_right eq
end quotient
|
1fa7e9271e7abe17c4281164dde886a7443661bc | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Lean/Elab/Match.lean | 4a58d5d88ee122c0f80ab9d9c27ec9d3c5abd74a | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 52,004 | 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.Util.CollectFVars
import Lean.Meta.Match.MatchPatternAttr
import Lean.Meta.Match.Match
import Lean.Meta.SortLocalDecls
import Lean.Meta.GeneralizeVars
import Lean.Elab.SyntheticMVars
import Lean.Elab.App
import Lean.Parser.Term
namespace Lean.Elab.Term
open Meta
open Lean.Parser.Term
/- This modules assumes "match"-expressions use the following syntax.
```lean
def matchDiscr := leading_parser optional (try (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> termParser
def «match» := leading_parser:leadPrec "match " >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts
```
-/
structure MatchAltView where
ref : Syntax
patterns : Array Syntax
rhs : Syntax
deriving Inhabited
private def expandSimpleMatch (stx discr lhsVar rhs : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
let newStx ← `(let $lhsVar := $discr; $rhs)
withMacroExpansion stx newStx <| elabTerm newStx expectedType?
private def elabDiscrsWitMatchType (discrStxs : Array Syntax) (matchType : Expr) (expectedType : Expr) : TermElabM (Array Expr × Bool) := do
let mut discrs := #[]
let mut i := 0
let mut matchType := matchType
let mut isDep := false
for discrStx in discrStxs do
i := i + 1
matchType ← whnf matchType
match matchType with
| Expr.forallE _ d b _ =>
let discr ← fullApproxDefEq <| elabTermEnsuringType discrStx[1] d
trace[Elab.match] "discr #{i} {discr} : {d}"
if b.hasLooseBVars then
isDep := true
matchType ← b.instantiate1 discr
discrs := discrs.push discr
| _ =>
throwError "invalid type provided to match-expression, function type with arity #{discrStxs.size} expected"
pure (discrs, isDep)
private def mkUserNameFor (e : Expr) : TermElabM Name := do
match e with
/- Remark: we use `mkFreshUserName` to make sure we don't add a variable to the local context that can be resolved to `e`. -/
| Expr.fvar fvarId _ => mkFreshUserName ((← getLocalDecl fvarId).userName)
| _ => mkFreshBinderName
/-- Return true iff `n` is an auxiliary variable created by `expandNonAtomicDiscrs?` -/
def isAuxDiscrName (n : Name) : Bool :=
n.hasMacroScopes && n.eraseMacroScopes == `_discr
/- We treat `@x` as atomic to avoid unnecessary extra local declarations from being
inserted into the local context. Recall that `expandMatchAltsIntoMatch` uses `@` modifier.
Thus this is kind of discriminant is quite common.
Remark: if the discriminat is `Systax.missing`, we abort the elaboration of the `match`-expression.
This can happen due to error recovery. Example
```
example : (p ∨ p) → p := fun h => match
```
If we don't abort, the elaborator loops because we will keep trying to expand
```
match
```
into
```
let d := <Syntax.missing>; match
```
Recall that `Syntax.setArg stx i arg` is a no-op when `i` is out-of-bounds. -/
def isAtomicDiscr? (discr : Syntax) : TermElabM (Option Expr) := do
match discr with
| `($x:ident) => isLocalIdent? x
| `(@$x:ident) => isLocalIdent? x
| _ => if discr.isMissing then throwAbortTerm else return none
-- See expandNonAtomicDiscrs?
private def elabAtomicDiscr (discr : Syntax) : TermElabM Expr := do
let term := discr[1]
match (← isAtomicDiscr? term) with
| some e@(Expr.fvar fvarId _) =>
let localDecl ← getLocalDecl fvarId
if !isAuxDiscrName localDecl.userName then
pure e -- it is not an auxiliary local created by `expandNonAtomicDiscrs?`
else
pure localDecl.value
| _ => throwErrorAt discr "unexpected discriminant"
structure ElabMatchTypeAndDiscsResult where
discrs : Array Expr
matchType : Expr
/- `true` when performing dependent elimination. We use this to decide whether we optimize the "match unit" case.
See `isMatchUnit?`. -/
isDep : Bool
alts : Array MatchAltView
private def elabMatchTypeAndDiscrs (discrStxs : Array Syntax) (matchOptType : Syntax) (matchAltViews : Array MatchAltView) (expectedType : Expr)
: TermElabM ElabMatchTypeAndDiscsResult := do
let numDiscrs := discrStxs.size
if matchOptType.isNone then
let rec loop (i : Nat) (discrs : Array Expr) (matchType : Expr) (isDep : Bool) (matchAltViews : Array MatchAltView) := do
match i with
| 0 => return { discrs := discrs.reverse, matchType := matchType, isDep := isDep, alts := matchAltViews }
| i+1 =>
let discrStx := discrStxs[i]
let discr ← elabAtomicDiscr discrStx
let discr ← instantiateMVars discr
let discrType ← inferType discr
let discrType ← instantiateMVars discrType
let matchTypeBody ← kabstract matchType discr
let isDep := isDep || matchTypeBody.hasLooseBVars
let userName ← mkUserNameFor discr
if discrStx[0].isNone then
loop i (discrs.push discr) (Lean.mkForall userName BinderInfo.default discrType matchTypeBody) isDep matchAltViews
else
let identStx := discrStx[0][0]
withLocalDeclD userName discrType fun x => do
let eqType ← mkEq discr x
withLocalDeclD identStx.getId eqType fun h => do
let matchTypeBody := matchTypeBody.instantiate1 x
let matchType ← mkForallFVars #[x, h] matchTypeBody
let refl ← mkEqRefl discr
let discrs := (discrs.push refl).push discr
let matchAltViews := matchAltViews.map fun altView =>
{ altView with patterns := altView.patterns.insertAt (i+1) identStx }
loop i discrs matchType isDep matchAltViews
loop discrStxs.size (discrs := #[]) (isDep := false) expectedType matchAltViews
else
let matchTypeStx := matchOptType[0][1]
let matchType ← elabType matchTypeStx
let (discrs, isDep) ← elabDiscrsWitMatchType discrStxs matchType expectedType
return { discrs := discrs, matchType := matchType, isDep := isDep, alts := matchAltViews }
def expandMacrosInPatterns (matchAlts : Array MatchAltView) : MacroM (Array MatchAltView) := do
matchAlts.mapM fun matchAlt => do
let patterns ← matchAlt.patterns.mapM expandMacros
pure { matchAlt with patterns := patterns }
private def getMatchGeneralizing? : Syntax → Option Bool
| `(match (generalizing := true) $discrs,* $[: $ty?]? with $alts:matchAlt*) => some true
| `(match (generalizing := false) $discrs,* $[: $ty?]? with $alts:matchAlt*) => some false
| _ => none
/- Given `stx` a match-expression, return its alternatives. -/
private def getMatchAlts : Syntax → Array MatchAltView
| `(match $[$gen]? $discrs,* $[: $ty?]? with $alts:matchAlt*) =>
alts.filterMap fun alt => match alt with
| `(matchAltExpr| | $patterns,* => $rhs) => some {
ref := alt,
patterns := patterns,
rhs := rhs
}
| _ => none
| _ => #[]
/--
Auxiliary annotation used to mark terms marked with the "inaccessible" annotation `.(t)` and
`_` in patterns. -/
def mkInaccessible (e : Expr) : Expr :=
mkAnnotation `_inaccessible e
def inaccessible? (e : Expr) : Option Expr :=
annotation? `_inaccessible e
inductive PatternVar where
| localVar (userName : Name)
-- anonymous variables (`_`) are encoded using metavariables
| anonymousVar (mvarId : MVarId)
instance : ToString PatternVar := ⟨fun
| PatternVar.localVar x => toString x
| PatternVar.anonymousVar mvarId => s!"?m{mvarId}"⟩
builtin_initialize Parser.registerBuiltinNodeKind `MVarWithIdKind
/--
Create an auxiliary Syntax node wrapping a fresh metavariable id.
We use this kind of Syntax for representing `_` occurring in patterns.
The metavariables are created before we elaborate the patterns into `Expr`s. -/
private def mkMVarSyntax : TermElabM Syntax := do
let mvarId ← mkFreshId
return Syntax.node `MVarWithIdKind #[Syntax.node mvarId #[]]
/-- Given a syntax node constructed using `mkMVarSyntax`, return its MVarId -/
private def getMVarSyntaxMVarId (stx : Syntax) : MVarId :=
stx[0].getKind
/--
The elaboration function for `Syntax` created using `mkMVarSyntax`.
It just converts the metavariable id wrapped by the Syntax into an `Expr`. -/
@[builtinTermElab MVarWithIdKind] def elabMVarWithIdKind : TermElab := fun stx expectedType? =>
return mkInaccessible <| mkMVar (getMVarSyntaxMVarId stx)
@[builtinTermElab inaccessible] def elabInaccessible : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[1] expectedType?
return mkInaccessible e
/-
Patterns define new local variables.
This module collect them and preprocess `_` occurring in patterns.
Recall that an `_` may represent anonymous variables or inaccessible terms
that are implied by typing constraints. Thus, we represent them with fresh named holes `?x`.
After we elaborate the pattern, if the metavariable remains unassigned, we transform it into
a regular pattern variable. Otherwise, it becomes an inaccessible term.
Macros occurring in patterns are expanded before the `collectPatternVars` method is executed.
The following kinds of Syntax are handled by this module
- Constructor applications
- Applications of functions tagged with the `[matchPattern]` attribute
- Identifiers
- Anonymous constructors
- Structure instances
- Inaccessible terms
- Named patterns
- Tuple literals
- Type ascriptions
- Literals: num, string and char
-/
namespace CollectPatternVars
structure State where
found : NameSet := {}
vars : Array PatternVar := #[]
abbrev M := StateRefT State TermElabM
private def throwCtorExpected {α} : M α :=
throwError "invalid pattern, constructor or constant marked with '[matchPattern]' expected"
private def getNumExplicitCtorParams (ctorVal : ConstructorVal) : TermElabM Nat :=
forallBoundedTelescope ctorVal.type ctorVal.numParams fun ps _ => do
let mut result := 0
for p in ps do
let localDecl ← getLocalDecl p.fvarId!
if localDecl.binderInfo.isExplicit then
result := result+1
pure result
private def throwInvalidPattern {α} : M α :=
throwError "invalid pattern"
/-
An application in a pattern can be
1- A constructor application
The elaborator assumes fields are accessible and inductive parameters are not accessible.
2- A regular application `(f ...)` where `f` is tagged with `[matchPattern]`.
The elaborator assumes implicit arguments are not accessible and explicit ones are accessible.
-/
structure Context where
funId : Syntax
ctorVal? : Option ConstructorVal -- It is `some`, if constructor application
explicit : Bool
ellipsis : Bool
paramDecls : Array (Name × BinderInfo) -- parameters names and binder information
paramDeclIdx : Nat := 0
namedArgs : Array NamedArg
args : List Arg
newArgs : Array Syntax := #[]
deriving Inhabited
private def isDone (ctx : Context) : Bool :=
ctx.paramDeclIdx ≥ ctx.paramDecls.size
private def finalize (ctx : Context) : M Syntax := do
if ctx.namedArgs.isEmpty && ctx.args.isEmpty then
let fStx ← `(@$(ctx.funId):ident)
return Syntax.mkApp fStx ctx.newArgs
else
throwError "too many arguments"
private def isNextArgAccessible (ctx : Context) : Bool :=
let i := ctx.paramDeclIdx
match ctx.ctorVal? with
| some ctorVal => i ≥ ctorVal.numParams -- For constructor applications only fields are accessible
| none =>
if h : i < ctx.paramDecls.size then
-- For `[matchPattern]` applications, only explicit parameters are accessible.
let d := ctx.paramDecls.get ⟨i, h⟩
d.2.isExplicit
else
false
private def getNextParam (ctx : Context) : (Name × BinderInfo) × Context :=
let i := ctx.paramDeclIdx
let d := ctx.paramDecls[i]
(d, { ctx with paramDeclIdx := ctx.paramDeclIdx + 1 })
private def processVar (idStx : Syntax) : M Syntax := do
unless idStx.isIdent do
throwErrorAt idStx "identifier expected"
let id := idStx.getId
unless id.eraseMacroScopes.isAtomic do
throwError "invalid pattern variable, must be atomic"
if (← get).found.contains id then
throwError "invalid pattern, variable '{id}' occurred more than once"
modify fun s => { s with vars := s.vars.push (PatternVar.localVar id), found := s.found.insert id }
return idStx
private def nameToPattern : Name → TermElabM Syntax
| Name.anonymous => `(Name.anonymous)
| Name.str p s _ => do let p ← nameToPattern p; `(Name.str $p $(quote s) _)
| Name.num p n _ => do let p ← nameToPattern p; `(Name.num $p $(quote n) _)
private def quotedNameToPattern (stx : Syntax) : TermElabM Syntax :=
match stx[0].isNameLit? with
| some val => nameToPattern val
| none => throwIllFormedSyntax
private def doubleQuotedNameToPattern (stx : Syntax) : TermElabM Syntax := do
match stx[1].isNameLit? with
| some val => nameToPattern (← resolveGlobalConstNoOverloadWithInfo stx[1] val)
| none => throwIllFormedSyntax
partial def collect (stx : Syntax) : M Syntax := withRef stx <| withFreshMacroScope do
let k := stx.getKind
if k == identKind then
processId stx
else if k == ``Lean.Parser.Term.app then
processCtorApp stx
else if k == ``Lean.Parser.Term.anonymousCtor then
let elems ← stx[1].getArgs.mapSepElemsM collect
return stx.setArg 1 <| mkNullNode elems
else if k == ``Lean.Parser.Term.structInst then
/-
```
leading_parser "{" >> optional (atomic (termParser >> " with "))
>> manyIndent (group (structInstField >> optional ", "))
>> optional ".."
>> optional (" : " >> termParser)
>> " }"
```
-/
let withMod := stx[1]
unless withMod.isNone do
throwErrorAt withMod "invalid struct instance pattern, 'with' is not allowed in patterns"
let fields ← stx[2].getArgs.mapM fun p => do
-- p is of the form (group (structInstField >> optional ", "))
let field := p[0]
-- leading_parser structInstLVal >> " := " >> termParser
let newVal ← collect field[2]
let field := field.setArg 2 newVal
pure <| field.setArg 0 field
return stx.setArg 2 <| mkNullNode fields
else if k == ``Lean.Parser.Term.hole then
let r ← mkMVarSyntax
modify fun s => { s with vars := s.vars.push <| PatternVar.anonymousVar <| getMVarSyntaxMVarId r }
return r
else if k == ``Lean.Parser.Term.paren then
let arg := stx[1]
if arg.isNone then
return stx -- `()`
else
let t := arg[0]
let s := arg[1]
if s.isNone || s[0].getKind == ``Lean.Parser.Term.typeAscription then
-- Ignore `s`, since it empty or it is a type ascription
let t ← collect t
let arg := arg.setArg 0 t
return stx.setArg 1 arg
else
-- Tuple literal is a constructor
let t ← collect t
let arg := arg.setArg 0 t
let tupleTail := s[0]
let tupleTailElems := tupleTail[1].getArgs
let tupleTailElems ← tupleTailElems.mapSepElemsM collect
let tupleTail := tupleTail.setArg 1 <| mkNullNode tupleTailElems
let s := s.setArg 0 tupleTail
let arg := arg.setArg 1 s
return stx.setArg 1 arg
else if k == ``Lean.Parser.Term.explicitUniv then
processCtor stx[0]
else if k == ``Lean.Parser.Term.namedPattern then
/- Recall that
def namedPattern := check... >> trailing_parser "@" >> termParser -/
let id := stx[0]
discard <| processVar id
let pat := stx[2]
let pat ← collect pat
`(_root_.namedPattern $id $pat)
else if k == ``Lean.Parser.Term.inaccessible then
return stx
else if k == strLitKind then
return stx
else if k == numLitKind then
return stx
else if k == scientificLitKind then
return stx
else if k == charLitKind then
return stx
else if k == ``Lean.Parser.Term.quotedName then
/- Quoted names have an elaboration function associated with them, and they will not be macro expanded.
Note that macro expansion is not a good option since it produces a term using the smart constructors `Name.mkStr`, `Name.mkNum`
instead of the constructors `Name.str` and `Name.num` -/
quotedNameToPattern stx
else if k == ``Lean.Parser.Term.doubleQuotedName then
/- Similar to previous case -/
doubleQuotedNameToPattern stx
else if k == choiceKind then
throwError "invalid pattern, notation is ambiguous"
else
throwInvalidPattern
where
processCtorApp (stx : Syntax) : M Syntax := do
let (f, namedArgs, args, ellipsis) ← expandApp stx true
processCtorAppCore f namedArgs args ellipsis
processCtor (stx : Syntax) : M Syntax := do
processCtorAppCore stx #[] #[] false
/- Check whether `stx` is a pattern variable or constructor-like (i.e., constructor or constant tagged with `[matchPattern]` attribute) -/
processId (stx : Syntax) : M Syntax := do
match (← resolveId? stx "pattern") with
| none => processVar stx
| some f => match f with
| Expr.const fName _ _ =>
match (← getEnv).find? fName with
| some (ConstantInfo.ctorInfo _) => processCtor stx
| some _ =>
if hasMatchPatternAttribute (← getEnv) fName then
processCtor stx
else
processVar stx
| none => throwCtorExpected
| _ => processVar stx
pushNewArg (accessible : Bool) (ctx : Context) (arg : Arg) : M Context := do
match arg with
| Arg.stx stx =>
let stx ← if accessible then collect stx else pure stx
return { ctx with newArgs := ctx.newArgs.push stx }
| _ => unreachable!
processExplicitArg (accessible : Bool) (ctx : Context) : M Context := do
match ctx.args with
| [] =>
if ctx.ellipsis then
pushNewArg accessible ctx (Arg.stx (← `(_)))
else
throwError "explicit parameter is missing, unused named arguments {ctx.namedArgs.map fun narg => narg.name}"
| arg::args =>
pushNewArg accessible { ctx with args := args } arg
processImplicitArg (accessible : Bool) (ctx : Context) : M Context := do
if ctx.explicit then
processExplicitArg accessible ctx
else
pushNewArg accessible ctx (Arg.stx (← `(_)))
processCtorAppContext (ctx : Context) : M Syntax := do
if isDone ctx then
finalize ctx
else
let accessible := isNextArgAccessible ctx
let (d, ctx) := getNextParam ctx
match ctx.namedArgs.findIdx? fun namedArg => namedArg.name == d.1 with
| some idx =>
let arg := ctx.namedArgs[idx]
let ctx := { ctx with namedArgs := ctx.namedArgs.eraseIdx idx }
let ctx ← pushNewArg accessible ctx arg.val
processCtorAppContext ctx
| none =>
let ctx ← match d.2 with
| BinderInfo.implicit => processImplicitArg accessible ctx
| BinderInfo.instImplicit => processImplicitArg accessible ctx
| _ => processExplicitArg accessible ctx
processCtorAppContext ctx
processCtorAppCore (f : Syntax) (namedArgs : Array NamedArg) (args : Array Arg) (ellipsis : Bool) : M Syntax := do
let args := args.toList
let (fId, explicit) ← match f with
| `($fId:ident) => pure (fId, false)
| `(@$fId:ident) => pure (fId, true)
| _ => throwError "identifier expected"
let some (Expr.const fName _ _) ← resolveId? fId "pattern" | throwCtorExpected
let fInfo ← getConstInfo fName
let paramDecls ← forallTelescopeReducing fInfo.type fun xs _ => xs.mapM fun x => do
let d ← getFVarLocalDecl x
return (d.userName, d.binderInfo)
match fInfo with
| ConstantInfo.ctorInfo val =>
processCtorAppContext
{ funId := fId, explicit := explicit, ctorVal? := val, paramDecls := paramDecls, namedArgs := namedArgs, args := args, ellipsis := ellipsis }
| _ =>
if hasMatchPatternAttribute (← getEnv) fName then
processCtorAppContext
{ funId := fId, explicit := explicit, ctorVal? := none, paramDecls := paramDecls, namedArgs := namedArgs, args := args, ellipsis := ellipsis }
else
throwCtorExpected
def main (alt : MatchAltView) : M MatchAltView := do
let patterns ← alt.patterns.mapM fun p => do
trace[Elab.match] "collecting variables at pattern: {p}"
collect p
return { alt with patterns := patterns }
end CollectPatternVars
private def collectPatternVars (alt : MatchAltView) : TermElabM (Array PatternVar × MatchAltView) := do
let (alt, s) ← (CollectPatternVars.main alt).run {}
return (s.vars, alt)
/- Return the pattern variables in the given pattern.
Remark: this method is not used here, but in other macros (e.g., at `Do.lean`). -/
def getPatternVars (patternStx : Syntax) : TermElabM (Array PatternVar) := do
let patternStx ← liftMacroM <| expandMacros patternStx
let (_, s) ← (CollectPatternVars.collect patternStx).run {}
return s.vars
def getPatternsVars (patterns : Array Syntax) : TermElabM (Array PatternVar) := do
let collect : CollectPatternVars.M Unit := do
for pattern in patterns do
discard <| CollectPatternVars.collect (← liftMacroM <| expandMacros pattern)
let (_, s) ← collect.run {}
return s.vars
/- We convert the collected `PatternVar`s intro `PatternVarDecl` -/
inductive PatternVarDecl where
/- For `anonymousVar`, we create both a metavariable and a free variable. The free variable is used as an assignment for the metavariable
when it is not assigned during pattern elaboration. -/
| anonymousVar (mvarId : MVarId) (fvarId : FVarId)
| localVar (fvarId : FVarId)
private partial def withPatternVars {α} (pVars : Array PatternVar) (k : Array PatternVarDecl → TermElabM α) : TermElabM α :=
let rec loop (i : Nat) (decls : Array PatternVarDecl) := do
if h : i < pVars.size then
match pVars.get ⟨i, h⟩ with
| PatternVar.anonymousVar mvarId =>
let type ← mkFreshTypeMVar
let userName ← mkFreshBinderName
withLocalDecl userName BinderInfo.default type fun x =>
loop (i+1) (decls.push (PatternVarDecl.anonymousVar mvarId x.fvarId!))
| PatternVar.localVar userName =>
let type ← mkFreshTypeMVar
withLocalDecl userName BinderInfo.default type fun x =>
loop (i+1) (decls.push (PatternVarDecl.localVar x.fvarId!))
else
/- We must create the metavariables for `PatternVar.anonymousVar` AFTER we create the new local decls using `withLocalDecl`.
Reason: their scope must include the new local decls since some of them are assigned by typing constraints. -/
decls.forM fun decl => match decl with
| PatternVarDecl.anonymousVar mvarId fvarId => do
let type ← inferType (mkFVar fvarId)
discard <| mkFreshExprMVarWithId mvarId type
| _ => pure ()
k decls
loop 0 #[]
/-
Remark: when performing dependent pattern matching, we often had to write code such as
```lean
def Vec.map' (f : α → β) (xs : Vec α n) : Vec β n :=
match n, xs with
| _, nil => nil
| _, cons a as => cons (f a) (map' f as)
```
We had to include `n` and the `_`s because the type of `xs` depends on `n`.
Moreover, `nil` and `cons a as` have different types.
This was quite tedious. So, we have implemented an automatic "discriminant refinement procedure".
The procedure is based on the observation that we get a type error whenenver we forget to include `_`s
and the indices a discriminant depends on. So, we catch the exception, check whether the type of the discriminant
is an indexed family, and add their indices as new discriminants.
The current implementation, adds indices as they are found, and does not
try to "sort" the new discriminants.
If the refinement process fails, we report the original error message.
-/
/- Auxiliary structure for storing an type mismatch exception when processing the
pattern #`idx` of some alternative. -/
structure PatternElabException where
ex : Exception
idx : Nat
private def elabPatterns (patternStxs : Array Syntax) (matchType : Expr) : ExceptT PatternElabException TermElabM (Array Expr × Expr) :=
withReader (fun ctx => { ctx with implicitLambda := false }) do
let mut patterns := #[]
let mut matchType := matchType
for idx in [:patternStxs.size] do
let patternStx := patternStxs[idx]
matchType ← whnf matchType
match matchType with
| Expr.forallE _ d b _ =>
let pattern ←
try
liftM <| withSynthesize <| withoutErrToSorry <| elabTermEnsuringType patternStx d
catch ex =>
-- Wrap the type mismatch exception for the "discriminant refinement" feature.
throwThe PatternElabException { ex := ex, idx := idx }
matchType := b.instantiate1 pattern
patterns := patterns.push pattern
| _ => throwError "unexpected match type"
return (patterns, matchType)
def finalizePatternDecls (patternVarDecls : Array PatternVarDecl) : TermElabM (Array LocalDecl) := do
let mut decls := #[]
for pdecl in patternVarDecls do
match pdecl with
| PatternVarDecl.localVar fvarId =>
let decl ← getLocalDecl fvarId
let decl ← instantiateLocalDeclMVars decl
decls := decls.push decl
| PatternVarDecl.anonymousVar mvarId fvarId =>
let e ← instantiateMVars (mkMVar mvarId);
trace[Elab.match] "finalizePatternDecls: mvarId: {mvarId} := {e}, fvar: {mkFVar fvarId}"
match e with
| Expr.mvar newMVarId _ =>
/- Metavariable was not assigned, or assigned to another metavariable. So,
we assign to the auxiliary free variable we created at `withPatternVars` to `newMVarId`. -/
assignExprMVar newMVarId (mkFVar fvarId)
trace[Elab.match] "finalizePatternDecls: {mkMVar newMVarId} := {mkFVar fvarId}"
let decl ← getLocalDecl fvarId
let decl ← instantiateLocalDeclMVars decl
decls := decls.push decl
| _ => pure ()
/- We perform a topological sort (dependecies) on `decls` because the pattern elaboration process may produce a sequence where a declaration d₁ may occur after d₂ when d₂ depends on d₁. -/
sortLocalDecls decls
open Meta.Match (Pattern Pattern.var Pattern.inaccessible Pattern.ctor Pattern.as Pattern.val Pattern.arrayLit AltLHS MatcherResult)
namespace ToDepElimPattern
structure State where
found : NameSet := {}
localDecls : Array LocalDecl
newLocals : NameSet := {}
abbrev M := StateRefT State TermElabM
private def alreadyVisited (fvarId : FVarId) : M Bool := do
let s ← get
return s.found.contains fvarId
private def markAsVisited (fvarId : FVarId) : M Unit :=
modify fun s => { s with found := s.found.insert fvarId }
private def throwInvalidPattern {α} (e : Expr) : M α :=
throwError "invalid pattern {indentExpr e}"
/- Create a new LocalDecl `x` for the metavariable `mvar`, and return `Pattern.var x` -/
private def mkLocalDeclFor (mvar : Expr) : M Pattern := do
let mvarId := mvar.mvarId!
let s ← get
match (← getExprMVarAssignment? mvarId) with
| some val => return Pattern.inaccessible val
| none =>
let fvarId ← mkFreshId
let type ← inferType mvar
/- HACK: `fvarId` is not in the scope of `mvarId`
If this generates problems in the future, we should update the metavariable declarations. -/
assignExprMVar mvarId (mkFVar fvarId)
let userName ← mkFreshBinderName
let newDecl := LocalDecl.cdecl arbitrary fvarId userName type BinderInfo.default;
modify fun s =>
{ s with
newLocals := s.newLocals.insert fvarId,
localDecls :=
match s.localDecls.findIdx? fun decl => mvar.occurs decl.type with
| none => s.localDecls.push newDecl -- None of the existing declarations depend on `mvar`
| some i => s.localDecls.insertAt i newDecl }
return Pattern.var fvarId
partial def main (e : Expr) : M Pattern := do
let isLocalDecl (fvarId : FVarId) : M Bool := do
return (← get).localDecls.any fun d => d.fvarId == fvarId
let mkPatternVar (fvarId : FVarId) (e : Expr) : M Pattern := do
if (← alreadyVisited fvarId) then
return Pattern.inaccessible e
else
markAsVisited fvarId
return Pattern.var e.fvarId!
let mkInaccessible (e : Expr) : M Pattern := do
match e with
| Expr.fvar fvarId _ =>
if (← isLocalDecl fvarId) then
mkPatternVar fvarId e
else
return Pattern.inaccessible e
| _ =>
return Pattern.inaccessible e
match inaccessible? e with
| some t => mkInaccessible t
| none =>
match e.arrayLit? with
| some (α, lits) =>
return Pattern.arrayLit α (← lits.mapM main)
| none =>
if e.isAppOfArity `namedPattern 3 then
let p ← main <| e.getArg! 2
match e.getArg! 1 with
| Expr.fvar fvarId _ => return Pattern.as fvarId p
| _ => throwError "unexpected occurrence of auxiliary declaration 'namedPattern'"
else if e.isNatLit || e.isStringLit || e.isCharLit then
return Pattern.val e
else if e.isFVar then
let fvarId := e.fvarId!
unless (← isLocalDecl fvarId) do
throwInvalidPattern e
mkPatternVar fvarId e
else if e.isMVar then
mkLocalDeclFor e
else
let newE ← whnf e
if newE != e then
main newE
else matchConstCtor e.getAppFn (fun _ => throwInvalidPattern e) fun v us => do
let args := e.getAppArgs
unless args.size == v.numParams + v.numFields do
throwInvalidPattern e
let params := args.extract 0 v.numParams
let fields := args.extract v.numParams args.size
let fields ← fields.mapM main
return Pattern.ctor v.name us params.toList fields.toList
end ToDepElimPattern
def withDepElimPatterns {α} (localDecls : Array LocalDecl) (ps : Array Expr) (k : Array LocalDecl → Array Pattern → TermElabM α) : TermElabM α := do
let (patterns, s) ← (ps.mapM ToDepElimPattern.main).run { localDecls := localDecls }
let localDecls ← s.localDecls.mapM fun d => instantiateLocalDeclMVars d
/- toDepElimPatterns may have added new localDecls. Thus, we must update the local context before we execute `k` -/
let lctx ← getLCtx
let lctx := localDecls.foldl (fun (lctx : LocalContext) d => lctx.erase d.fvarId) lctx
let lctx := localDecls.foldl (fun (lctx : LocalContext) d => lctx.addDecl d) lctx
withTheReader Meta.Context (fun ctx => { ctx with lctx := lctx }) do
k localDecls patterns
private def withElaboratedLHS {α} (ref : Syntax) (patternVarDecls : Array PatternVarDecl) (patternStxs : Array Syntax) (matchType : Expr)
(k : AltLHS → Expr → TermElabM α) : ExceptT PatternElabException TermElabM α := do
let (patterns, matchType) ← withSynthesize <| elabPatterns patternStxs matchType
id (α := TermElabM α) do
let localDecls ← finalizePatternDecls patternVarDecls
let patterns ← patterns.mapM (instantiateMVars ·)
withDepElimPatterns localDecls patterns fun localDecls patterns =>
k { ref := ref, fvarDecls := localDecls.toList, patterns := patterns.toList } matchType
private def elabMatchAltView (alt : MatchAltView) (matchType : Expr) : ExceptT PatternElabException TermElabM (AltLHS × Expr) := withRef alt.ref do
let (patternVars, alt) ← collectPatternVars alt
trace[Elab.match] "patternVars: {patternVars}"
withPatternVars patternVars fun patternVarDecls => do
withElaboratedLHS alt.ref patternVarDecls alt.patterns matchType fun altLHS matchType => do
let rhs ← elabTermEnsuringType alt.rhs matchType
let xs := altLHS.fvarDecls.toArray.map LocalDecl.toExpr
let rhs ← if xs.isEmpty then pure <| mkSimpleThunk rhs else mkLambdaFVars xs rhs
trace[Elab.match] "rhs: {rhs}"
return (altLHS, rhs)
/--
Collect indices for the "discriminant refinement feature". This method is invoked
when we detect a type mismatch at a pattern #`idx` of some alternative. -/
private def getIndicesToInclude (discrs : Array Expr) (idx : Nat) : TermElabM (Array Expr) := do
let discrType ← whnfD (← inferType discrs[idx])
matchConstInduct discrType.getAppFn (fun _ => return #[]) fun info _ => do
let mut result := #[]
let args := discrType.getAppArgs
for arg in args[info.numParams : args.size] do
unless (← discrs.anyM fun discr => isDefEq discr arg) do
result := result.push arg
return result
private partial def elabMatchAltViews (discrs : Array Expr) (matchType : Expr) (altViews : Array MatchAltView) : TermElabM (Array Expr × Expr × Array (AltLHS × Expr) × Bool) := do
loop discrs matchType altViews none
where
/-
"Discriminant refinement" main loop.
`first?` contains the first error message we found before updated the `discrs`. -/
loop (discrs : Array Expr) (matchType : Expr) (altViews : Array MatchAltView) (first? : Option (SavedState × Exception))
: TermElabM (Array Expr × Expr × Array (AltLHS × Expr) × Bool) := do
let s ← saveState
match ← altViews.mapM (fun alt => elabMatchAltView alt matchType) |>.run with
| Except.ok alts => return (discrs, matchType, alts, first?.isSome)
| Except.error { idx := idx, ex := ex } =>
let indices ← getIndicesToInclude discrs idx
if indices.isEmpty then
throwEx (← updateFirst first? ex)
else
let first ← updateFirst first? ex
s.restore
let indices ← collectDeps indices discrs
let matchType ←
try
updateMatchType indices matchType
catch ex =>
throwEx first
let altViews ← addWildcardPatterns indices.size altViews
let discrs := indices ++ discrs
loop discrs matchType altViews first
throwEx {α} (p : SavedState × Exception) : TermElabM α := do
p.1.restore; throw p.2
updateFirst (first? : Option (SavedState × Exception)) (ex : Exception) : TermElabM (SavedState × Exception) := do
match first? with
| none => return (← saveState, ex)
| some first => return first
containsFVar (es : Array Expr) (fvarId : FVarId) : Bool :=
es.any fun e => e.isFVar && e.fvarId! == fvarId
/- Update `indices` by including any free variable `x` s.t.
- Type of some `discr` depends on `x`.
- Type of `x` depends on some free variable in `indices`.
If we don't include these extra variables in indices, then
`updateMatchType` will generate a type incorrect term.
For example, suppose `discr` contains `h : @HEq α a α b`, and
`indices` is `#[α, b]`, and `matchType` is `@HEq α a α b → B`.
`updateMatchType indices matchType` produces the type
`(α' : Type) → (b : α') → @HEq α' a α' b → B` which is type incorrect
because we have `a : α`.
The method `collectDeps` will include `a` into `indices`.
This method does not handle dependencies among non-free variables.
We rely on the type checking method `check` at `updateMatchType`. -/
collectDeps (indices : Array Expr) (discrs : Array Expr) : TermElabM (Array Expr) := do
let mut s : CollectFVars.State := {}
for discr in discrs do
s := collectFVars s (← instantiateMVars (← inferType discr))
let (indicesFVar, indicesNonFVar) := indices.split Expr.isFVar
let indicesFVar := indicesFVar.map Expr.fvarId!
let mut toAdd := #[]
for fvarId in s.fvarSet.toList do
unless containsFVar discrs fvarId || containsFVar indices fvarId do
let localDecl ← getLocalDecl fvarId
let mctx ← getMCtx
for indexFVarId in indicesFVar do
if mctx.localDeclDependsOn localDecl indexFVarId then
toAdd := toAdd.push fvarId
let lctx ← getLCtx
let indicesFVar := (indicesFVar ++ toAdd).qsort fun fvarId₁ fvarId₂ =>
(lctx.get! fvarId₁).index < (lctx.get! fvarId₂).index
return indicesFVar.map mkFVar ++ indicesNonFVar
updateMatchType (indices : Array Expr) (matchType : Expr) : TermElabM Expr := do
let matchType ← indices.foldrM (init := matchType) fun index matchType => do
let indexType ← inferType index
let matchTypeBody ← kabstract matchType index
let userName ← mkUserNameFor index
return Lean.mkForall userName BinderInfo.default indexType matchTypeBody
check matchType
return matchType
addWildcardPatterns (num : Nat) (altViews : Array MatchAltView) : TermElabM (Array MatchAltView) := do
let hole := mkHole (← getRef)
let wildcards := mkArray num hole
return altViews.map fun altView => { altView with patterns := wildcards ++ altView.patterns }
def mkMatcher (elimName : Name) (matchType : Expr) (numDiscrs : Nat) (lhss : List AltLHS) : TermElabM MatcherResult :=
Meta.Match.mkMatcher elimName matchType numDiscrs lhss
register_builtin_option match.ignoreUnusedAlts : Bool := {
defValue := false
descr := "if true, do not generate error if an alternative is not used"
}
def reportMatcherResultErrors (altLHSS : List AltLHS) (result : MatcherResult) : TermElabM Unit := do
unless result.counterExamples.isEmpty do
withHeadRefOnly <| throwError "missing cases:\n{Meta.Match.counterExamplesToMessageData result.counterExamples}"
unless match.ignoreUnusedAlts.get (← getOptions) || result.unusedAltIdxs.isEmpty do
let mut i := 0
for alt in altLHSS do
if result.unusedAltIdxs.contains i then
withRef alt.ref do
logError "redundant alternative"
i := i + 1
/--
If `altLHSS + rhss` is encoding `| PUnit.unit => rhs[0]`, return `rhs[0]`
Otherwise, return none.
-/
private def isMatchUnit? (altLHSS : List Match.AltLHS) (rhss : Array Expr) : MetaM (Option Expr) := do
assert! altLHSS.length == rhss.size
match altLHSS with
| [ { fvarDecls := [], patterns := [ Pattern.ctor `PUnit.unit .. ], .. } ] =>
/- Recall that for alternatives of the form `| PUnit.unit => rhs`, `rhss[0]` is of the form `fun _ : Unit => b`. -/
match rhss[0] with
| Expr.lam _ _ b _ => return if b.hasLooseBVars then none else b
| _ => return none
| _ => return none
/--
"Generalize" variables that depend on the discriminants.
Remarks and limitations:
- If `matchType` is a proposition, then we generalize even when the user did not provide `(generalizing := true)`.
Motivation: users should have control about the actual `match`-expressions in their programs.
- We currently do not generalize let-decls.
- We abort generalization if the new `matchType` is type incorrect.
- Only discriminants that are free variables are considered during specialization.
- We "generalize" by adding new discriminants and pattern variables. We do not "clear" the generalized variables,
but they become inaccessible since they are shadowed by the patterns variables. We assume this is ok since
this is the exact behavior users would get if they had written it by hand. Recall there is no `clear` in term mode.
-/
private def generalize (discrs : Array Expr) (matchType : Expr) (altViews : Array MatchAltView) (generalizing? : Option Bool) : TermElabM (Array Expr × Expr × Array MatchAltView × Bool) := do
let gen ←
match generalizing? with
| some g => pure g
| _ => isProp matchType
if !gen then
return (discrs, matchType, altViews, false)
else
let ysFVarIds ← getFVarsToGeneralize discrs
/- let-decls are currently being ignored by the generalizer. -/
let ysFVarIds ← ysFVarIds.filterM fun fvarId => return !(← getLocalDecl fvarId).isLet
if ysFVarIds.isEmpty then
return (discrs, matchType, altViews, false)
else
let ys := ysFVarIds.map mkFVar
-- trace[Meta.debug] "ys: {ys}, discrs: {discrs}"
let matchType' ← forallBoundedTelescope matchType discrs.size fun ds type => do
let type ← mkForallFVars ys type
let (discrs', ds') := Array.unzip <| Array.zip discrs ds |>.filter fun (di, d) => di.isFVar
let type := type.replaceFVars discrs' ds'
mkForallFVars ds type
-- trace[Meta.debug] "matchType': {matchType'}"
if (← isTypeCorrect matchType') then
let discrs := discrs ++ ys
let ysIds ← ys.mapM fun y => do
let yDecl ← getLocalDecl y.fvarId!
return mkIdentFrom (← getRef) yDecl.userName
let altViews := altViews.map fun altView => { altView with patterns := altView.patterns ++ ysIds }
return (discrs, matchType', altViews, true)
else
return (discrs, matchType, altViews, true)
private def elabMatchAux (generalizing? : Option Bool) (discrStxs : Array Syntax) (altViews : Array MatchAltView) (matchOptType : Syntax) (expectedType : Expr)
: TermElabM Expr := do
let mut generalizing? := generalizing?
if !matchOptType.isNone then
if generalizing? == some true then
throwError "the '(generalizing := true)' parameter is not supported when the 'match' type is explicitly provided"
generalizing? := some false
let (discrs, matchType, altLHSS, isDep, rhss) ← commitIfDidNotPostpone do
let ⟨discrs, matchType, isDep, altViews⟩ ← elabMatchTypeAndDiscrs discrStxs matchOptType altViews expectedType
let (discrs, matchType, altViews, gen) ← generalize discrs matchType altViews generalizing?
let isDep := isDep || gen
let matchAlts ← liftMacroM <| expandMacrosInPatterns altViews
trace[Elab.match] "matchType: {matchType}"
let (discrs, matchType, alts, refined) ← elabMatchAltViews discrs matchType matchAlts
let isDep := isDep || refined
/-
We should not use `synthesizeSyntheticMVarsNoPostponing` here. Otherwise, we will not be
able to elaborate examples such as:
```
def f (x : Nat) : Option Nat := none
def g (xs : List (Nat × Nat)) : IO Unit :=
xs.forM fun x =>
match f x.fst with
| _ => pure ()
```
If `synthesizeSyntheticMVarsNoPostponing`, the example above fails at `x.fst` because
the type of `x` is only available after we proces the last argument of `List.forM`.
We apply pending default types to make sure we can process examples such as
```
let (a, b) := (0, 0)
```
-/
synthesizeSyntheticMVarsUsingDefault
let rhss := alts.map Prod.snd
let matchType ← instantiateMVars matchType
let altLHSS ← alts.toList.mapM fun alt => do
let altLHS ← Match.instantiateAltLHSMVars alt.1
/- Remark: we try to postpone before throwing an error.
The combinator `commitIfDidNotPostpone` ensures we backtrack any updates that have been performed.
The quick-check `waitExpectedTypeAndDiscrs` minimizes the number of scenarios where we have to postpone here.
Here is an example that passes the `waitExpectedTypeAndDiscrs` test, but postpones here.
```
def bad (ps : Array (Nat × Nat)) : Array (Nat × Nat) :=
(ps.filter fun (p : Prod _ _) =>
match p with
| (x, y) => x == 0)
++
ps
```
When we try to elaborate `fun (p : Prod _ _) => ...` for the first time, we haven't propagated the type of `ps` yet
because `Array.filter` has type `{α : Type u_1} → (α → Bool) → (as : Array α) → optParam Nat 0 → optParam Nat (Array.size as) → Array α`
However, the partial type annotation `(p : Prod _ _)` makes sure we succeed at the quick-check `waitExpectedTypeAndDiscrs`.
-/
withRef altLHS.ref do
for d in altLHS.fvarDecls do
if d.hasExprMVar then
withExistingLocalDecls altLHS.fvarDecls do
tryPostpone
throwMVarError m!"invalid match-expression, type of pattern variable '{d.toExpr}' contains metavariables{indentExpr d.type}"
for p in altLHS.patterns do
if p.hasExprMVar then
withExistingLocalDecls altLHS.fvarDecls do
tryPostpone
throwMVarError m!"invalid match-expression, pattern contains metavariables{indentExpr (← p.toExpr)}"
pure altLHS
return (discrs, matchType, altLHSS, isDep, rhss)
if let some r ← if isDep then pure none else isMatchUnit? altLHSS rhss then
return r
else
let numDiscrs := discrs.size
let matcherName ← mkAuxName `match
let matcherResult ← mkMatcher matcherName matchType numDiscrs altLHSS
let motive ← forallBoundedTelescope matchType numDiscrs fun xs matchType => mkLambdaFVars xs matchType
reportMatcherResultErrors altLHSS matcherResult
let r := mkApp matcherResult.matcher motive
let r := mkAppN r discrs
let r := mkAppN r rhss
trace[Elab.match] "result: {r}"
return r
private def getDiscrs (matchStx : Syntax) : Array Syntax :=
matchStx[2].getSepArgs
private def getMatchOptType (matchStx : Syntax) : Syntax :=
matchStx[3]
private def expandNonAtomicDiscrs? (matchStx : Syntax) : TermElabM (Option Syntax) :=
let matchOptType := getMatchOptType matchStx;
if matchOptType.isNone then do
let discrs := getDiscrs matchStx;
let allLocal ← discrs.allM fun discr => Option.isSome <$> isAtomicDiscr? discr[1]
if allLocal then
return none
else
-- We use `foundFVars` to make sure the discriminants are distinct variables.
-- See: code for computing "matchType" at `elabMatchTypeAndDiscrs`
let rec loop (discrs : List Syntax) (discrsNew : Array Syntax) (foundFVars : NameSet) := do
match discrs with
| [] =>
let discrs := Syntax.mkSep discrsNew (mkAtomFrom matchStx ", ");
pure (matchStx.setArg 2 discrs)
| discr :: discrs =>
-- Recall that
-- matchDiscr := leading_parser optional (ident >> ":") >> termParser
let term := discr[1]
let addAux : TermElabM Syntax := withFreshMacroScope do
let d ← `(_discr);
unless isAuxDiscrName d.getId do -- Use assertion?
throwError "unexpected internal auxiliary discriminant name"
let discrNew := discr.setArg 1 d;
let r ← loop discrs (discrsNew.push discrNew) foundFVars
`(let _discr := $term; $r)
match (← isAtomicDiscr? term) with
| some x => if x.isFVar then loop discrs (discrsNew.push discr) (foundFVars.insert x.fvarId!) else addAux
| none => addAux
return some (← loop discrs.toList #[] {})
else
-- We do not pull non atomic discriminants when match type is provided explicitly by the user
return none
private def waitExpectedType (expectedType? : Option Expr) : TermElabM Expr := do
tryPostponeIfNoneOrMVar expectedType?
match expectedType? with
| some expectedType => pure expectedType
| none => mkFreshTypeMVar
private def tryPostponeIfDiscrTypeIsMVar (matchStx : Syntax) : TermElabM Unit := do
-- We don't wait for the discriminants types when match type is provided by user
if getMatchOptType matchStx |>.isNone then
let discrs := getDiscrs matchStx
for discr in discrs do
let term := discr[1]
match (← isAtomicDiscr? term) with
| none => throwErrorAt discr "unexpected discriminant" -- see `expandNonAtomicDiscrs?
| some d =>
let dType ← inferType d
trace[Elab.match] "discr {d} : {dType}"
tryPostponeIfMVar dType
/-
We (try to) elaborate a `match` only when the expected type is available.
If the `matchType` has not been provided by the user, we also try to postpone elaboration if the type
of a discriminant is not available. That is, it is of the form `(?m ...)`.
We use `expandNonAtomicDiscrs?` to make sure all discriminants are local variables.
This is a standard trick we use in the elaborator, and it is also used to elaborate structure instances.
Suppose, we are trying to elaborate
```
match g x with
| ... => ...
```
`expandNonAtomicDiscrs?` converts it intro
```
let _discr := g x
match _discr with
| ... => ...
```
Thus, at `tryPostponeIfDiscrTypeIsMVar` we only need to check whether the type of `_discr` is not of the form `(?m ...)`.
Note that, the auxiliary variable `_discr` is expanded at `elabAtomicDiscr`.
This elaboration technique is needed to elaborate terms such as:
```lean
xs.filter fun (a, b) => a > b
```
which are syntax sugar for
```lean
List.filter (fun p => match p with | (a, b) => a > b) xs
```
When we visit `match p with | (a, b) => a > b`, we don't know the type of `p` yet.
-/
private def waitExpectedTypeAndDiscrs (matchStx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
tryPostponeIfNoneOrMVar expectedType?
tryPostponeIfDiscrTypeIsMVar matchStx
match expectedType? with
| some expectedType => return expectedType
| none => mkFreshTypeMVar
/-
```
leading_parser:leadPrec "match " >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts
```
Remark the `optIdent` must be `none` at `matchDiscr`. They are expanded by `expandMatchDiscr?`.
-/
private def elabMatchCore (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
let expectedType ← waitExpectedTypeAndDiscrs stx expectedType?
let discrStxs := (getDiscrs stx).map fun d => d
let gen? := getMatchGeneralizing? stx
let altViews := getMatchAlts stx
let matchOptType := getMatchOptType stx
elabMatchAux gen? discrStxs altViews matchOptType expectedType
private def isPatternVar (stx : Syntax) : TermElabM Bool := do
match (← resolveId? stx "pattern") with
| none => isAtomicIdent stx
| some f => match f with
| Expr.const fName _ _ =>
match (← getEnv).find? fName with
| some (ConstantInfo.ctorInfo _) => return false
| some _ => return !hasMatchPatternAttribute (← getEnv) fName
| _ => isAtomicIdent stx
| _ => isAtomicIdent stx
where
isAtomicIdent (stx : Syntax) : Bool :=
stx.isIdent && stx.getId.eraseMacroScopes.isAtomic
-- leading_parser "match " >> sepBy1 termParser ", " >> optType >> " with " >> matchAlts
@[builtinTermElab «match»] def elabMatch : TermElab := fun stx expectedType? => do
match stx with
| `(match $discr:term with | $y:ident => $rhs:term) =>
if (← isPatternVar y) then expandSimpleMatch stx discr y rhs expectedType? else elabMatchDefault stx expectedType?
| _ => elabMatchDefault stx expectedType?
where
elabMatchDefault (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
match (← expandNonAtomicDiscrs? stx) with
| some stxNew => withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
| none =>
let discrs := getDiscrs stx;
let matchOptType := getMatchOptType stx;
if !matchOptType.isNone && discrs.any fun d => !d[0].isNone then
throwErrorAt matchOptType "match expected type should not be provided when discriminants with equality proofs are used"
elabMatchCore stx expectedType?
builtin_initialize
registerTraceClass `Elab.match
-- leading_parser:leadPrec "nomatch " >> termParser
@[builtinTermElab «nomatch»] def elabNoMatch : TermElab := fun stx expectedType? => do
match stx with
| `(nomatch $discrExpr) =>
match ← isLocalIdent? discrExpr with
| some _ =>
let expectedType ← waitExpectedType expectedType?
let discr := Syntax.node ``Lean.Parser.Term.matchDiscr #[mkNullNode, discrExpr]
elabMatchAux none #[discr] #[] mkNullNode expectedType
| _ =>
let stxNew ← `(let _discr := $discrExpr; nomatch _discr)
withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
| _ => throwUnsupportedSyntax
end Lean.Elab.Term
|
9e86606f5f5ef1e15592cf75a21dffa7aa02a638 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/group_theory/perm/sign.lean | a2722421263f9ed39129e892fb043a8fa35bb8c3 | [] | 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 | 19,688 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fintype.basic
import Mathlib.data.finset.sort
import Mathlib.group_theory.perm.basic
import Mathlib.group_theory.order_of_element
import Mathlib.PostPort
universes u u_1 v
namespace Mathlib
/-!
# Sign of a permutation
The main definition of this file is `equiv.perm.sign`, associating a `units ℤ` sign with a
permutation.
This file also contains miscellaneous lemmas about `equiv.perm` and `equiv.swap`, building on top
of those in `data/equiv/basic` and `data/equiv/perm`.
-/
namespace equiv.perm
/--
`mod_swap i j` contains permutations up to swapping `i` and `j`.
We use this to partition permutations in `matrix.det_zero_of_row_eq`, such that each partition
sums up to `0`.
-/
def mod_swap {α : Type u} [DecidableEq α] (i : α) (j : α) : setoid (perm α) :=
setoid.mk (fun (σ τ : perm α) => σ = τ ∨ σ = swap i j * τ) sorry
protected instance r.decidable_rel {α : Type u_1} [fintype α] [DecidableEq α] (i : α) (j : α) : DecidableRel setoid.r :=
fun (σ τ : perm α) => or.decidable
/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation
on `{x // p x}` induced by `f`. -/
def subtype_perm {α : Type u} (f : perm α) {p : α → Prop} (h : ∀ (x : α), p x ↔ p (coe_fn f x)) : perm (Subtype fun (x : α) => p x) :=
mk (fun (x : Subtype fun (x : α) => p x) => { val := coe_fn f ↑x, property := sorry })
(fun (x : Subtype fun (x : α) => p x) => { val := coe_fn (f⁻¹) ↑x, property := sorry }) sorry sorry
@[simp] theorem subtype_perm_one {α : Type u} (p : α → Prop) (h : ∀ (x : α), p x ↔ p (coe_fn 1 x)) : subtype_perm 1 h = 1 := sorry
/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,
fixing the other points. -/
def of_subtype {α : Type u} {p : α → Prop} [decidable_pred p] : perm (Subtype p) →* perm α :=
monoid_hom.mk
(fun (f : perm (Subtype p)) =>
mk (fun (x : α) => dite (p x) (fun (h : p x) => ↑(coe_fn f { val := x, property := h })) fun (h : ¬p x) => x)
(fun (x : α) => dite (p x) (fun (h : p x) => ↑(coe_fn (f⁻¹) { val := x, property := h })) fun (h : ¬p x) => x)
sorry sorry)
sorry sorry
/-- Two permutations `f` and `g` are `disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def disjoint {α : Type u} (f : perm α) (g : perm α) :=
∀ (x : α), coe_fn f x = x ∨ coe_fn g x = x
theorem disjoint.symm {α : Type u} {f : perm α} {g : perm α} : disjoint f g → disjoint g f := sorry
theorem disjoint_comm {α : Type u} {f : perm α} {g : perm α} : disjoint f g ↔ disjoint g f :=
{ mp := disjoint.symm, mpr := disjoint.symm }
theorem disjoint.mul_comm {α : Type u} {f : perm α} {g : perm α} (h : disjoint f g) : f * g = g * f := sorry
@[simp] theorem disjoint_one_left {α : Type u} (f : perm α) : disjoint 1 f :=
fun (_x : α) => Or.inl rfl
@[simp] theorem disjoint_one_right {α : Type u} (f : perm α) : disjoint f 1 :=
fun (_x : α) => Or.inr rfl
theorem disjoint.mul_left {α : Type u} {f : perm α} {g : perm α} {h : perm α} (H1 : disjoint f h) (H2 : disjoint g h) : disjoint (f * g) h := sorry
theorem disjoint.mul_right {α : Type u} {f : perm α} {g : perm α} {h : perm α} (H1 : disjoint f g) (H2 : disjoint f h) : disjoint f (g * h) :=
eq.mpr (id (Eq._oldrec (Eq.refl (disjoint f (g * h))) (propext disjoint_comm)))
(disjoint.mul_left (disjoint.symm H1) (disjoint.symm H2))
theorem disjoint_prod_right {α : Type u} {f : perm α} (l : List (perm α)) (h : ∀ (g : perm α), g ∈ l → disjoint f g) : disjoint f (list.prod l) := sorry
theorem disjoint_prod_perm {α : Type u} {l₁ : List (perm α)} {l₂ : List (perm α)} (hl : list.pairwise disjoint l₁) (hp : l₁ ~ l₂) : list.prod l₁ = list.prod l₂ :=
list.perm.prod_eq' hp (list.pairwise.imp (fun (f g : perm α) => disjoint.mul_comm) hl)
theorem of_subtype_subtype_perm {α : Type u} {f : perm α} {p : α → Prop} [decidable_pred p] (h₁ : ∀ (x : α), p x ↔ p (coe_fn f x)) (h₂ : ∀ (x : α), coe_fn f x ≠ x → p x) : coe_fn of_subtype (subtype_perm f h₁) = f := sorry
theorem of_subtype_apply_of_not_mem {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) {x : α} (hx : ¬p x) : coe_fn (coe_fn of_subtype f) x = x :=
dif_neg hx
theorem mem_iff_of_subtype_apply_mem {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) (x : α) : p x ↔ p (coe_fn (coe_fn of_subtype f) x) := sorry
@[simp] theorem subtype_perm_of_subtype {α : Type u} {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) : subtype_perm (coe_fn of_subtype f) (mem_iff_of_subtype_apply_mem f) = f := sorry
theorem pow_apply_eq_self_of_apply_eq_self {α : Type u} {f : perm α} {x : α} (hfx : coe_fn f x = x) (n : ℕ) : coe_fn (f ^ n) x = x := sorry
theorem gpow_apply_eq_self_of_apply_eq_self {α : Type u} {f : perm α} {x : α} (hfx : coe_fn f x = x) (n : ℤ) : coe_fn (f ^ n) x = x := sorry
theorem pow_apply_eq_of_apply_apply_eq_self {α : Type u} {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) = x) (n : ℕ) : coe_fn (f ^ n) x = x ∨ coe_fn (f ^ n) x = coe_fn f x := sorry
theorem gpow_apply_eq_of_apply_apply_eq_self {α : Type u} {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) = x) (i : ℤ) : coe_fn (f ^ i) x = x ∨ coe_fn (f ^ i) x = coe_fn f x := sorry
/-- The `finset` of nonfixed points of a permutation. -/
def support {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : finset α :=
finset.filter (fun (x : α) => coe_fn f x ≠ x) finset.univ
@[simp] theorem mem_support {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} : x ∈ support f ↔ coe_fn f x ≠ x := sorry
/-- `f.is_swap` indicates that the permutation `f` is a transposition of two elements. -/
def is_swap {α : Type u} [DecidableEq α] (f : perm α) :=
∃ (x : α), ∃ (y : α), x ≠ y ∧ f = swap x y
theorem is_swap.of_subtype_is_swap {α : Type u} [DecidableEq α] {p : α → Prop} [decidable_pred p] {f : perm (Subtype p)} (h : is_swap f) : is_swap (coe_fn of_subtype f) := sorry
theorem ne_and_ne_of_swap_mul_apply_ne_self {α : Type u} [DecidableEq α] {f : perm α} {x : α} {y : α} (hy : coe_fn (swap x (coe_fn f x) * f) y ≠ y) : coe_fn f y ≠ y ∧ y ≠ x := sorry
theorem support_swap_mul_eq {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} (hffx : coe_fn f (coe_fn f x) ≠ x) : support (swap x (coe_fn f x) * f) = finset.erase (support f) x := sorry
theorem card_support_swap_mul {α : Type u} [DecidableEq α] [fintype α] {f : perm α} {x : α} (hx : coe_fn f x ≠ x) : finset.card (support (swap x (coe_fn f x) * f)) < finset.card (support f) := sorry
/-- Given a list `l : list α` and a permutation `f : perm α` such that the nonfixed points of `f`
are in `l`, recursively factors `f` as a product of transpositions. -/
def swap_factors_aux {α : Type u} [DecidableEq α] (l : List α) (f : perm α) : (∀ {x : α}, coe_fn f x ≠ x → x ∈ l) →
Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g :=
sorry
/-- `swap_factors` represents a permutation as a product of a list of transpositions.
The representation is non unique and depends on the linear order structure.
For types without linear order `trunc_swap_factors` can be used. -/
def swap_factors {α : Type u} [DecidableEq α] [fintype α] [linear_order α] (f : perm α) : Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g :=
swap_factors_aux (finset.sort LessEq finset.univ) f sorry
/-- This computably represents the fact that any permutation can be represented as the product of
a list of transpositions. -/
def trunc_swap_factors {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : trunc (Subtype fun (l : List (perm α)) => list.prod l = f ∧ ∀ (g : perm α), g ∈ l → is_swap g) :=
quotient.rec_on_subsingleton (finset.val finset.univ)
(fun (l : List α) (h : ∀ (x : α), coe_fn f x ≠ x → x ∈ quotient.mk l) => trunc.mk (swap_factors_aux l f h)) sorry
/-- An induction principle for permutations. If `P` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/
theorem swap_induction_on {α : Type u} [DecidableEq α] [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ (f : perm α) (x y : α), x ≠ y → P f → P (swap x y * f)) → P f := sorry
/-- Like `swap_induction_on`, but with the composition on the right of `f`.
An induction principle for permutations. If `P` holds for the identity permutation, and
is preserved under composition with a non-trivial swap, then `P` holds for all permutations. -/
theorem swap_induction_on' {α : Type u} [DecidableEq α] [fintype α] {P : perm α → Prop} (f : perm α) : P 1 → (∀ (f : perm α) (x y : α), x ≠ y → P f → P (f * swap x y)) → P f :=
fun (h1 : P 1) (IH : ∀ (f : perm α) (x y : α), x ≠ y → P f → P (f * swap x y)) =>
inv_inv f ▸ swap_induction_on (f⁻¹) h1 fun (f : perm α) => IH (f⁻¹)
theorem is_conj_swap {α : Type u} [DecidableEq α] {w : α} {x : α} {y : α} {z : α} (hwx : w ≠ x) (hyz : y ≠ z) : is_conj (swap w x) (swap y z) := sorry
/-- set of all pairs (⟨a, b⟩ : Σ a : fin n, fin n) such that b < a -/
def fin_pairs_lt (n : ℕ) : finset (sigma fun (a : fin n) => fin n) :=
finset.sigma finset.univ fun (a : fin n) => finset.attach_fin (finset.range ↑a) sorry
theorem mem_fin_pairs_lt {n : ℕ} {a : sigma fun (a : fin n) => fin n} : a ∈ fin_pairs_lt n ↔ sigma.snd a < sigma.fst a := sorry
/-- `sign_aux σ` is the sign of a permutation on `fin n`, defined as the parity of the number of
pairs `(x₁, x₂)` such that `x₂ < x₁` but `σ x₁ ≤ σ x₂` -/
def sign_aux {n : ℕ} (a : perm (fin n)) : units ℤ :=
finset.prod (fin_pairs_lt n)
fun (x : sigma fun (a : fin n) => fin n) => ite (coe_fn a (sigma.fst x) ≤ coe_fn a (sigma.snd x)) (-1) 1
@[simp] theorem sign_aux_one (n : ℕ) : sign_aux 1 = 1 := sorry
/-- `sign_bij_aux f ⟨a, b⟩` returns the pair consisting of `f a` and `f b` in decreasing order. -/
def sign_bij_aux {n : ℕ} (f : perm (fin n)) (a : sigma fun (a : fin n) => fin n) : sigma fun (a : fin n) => fin n :=
dite (coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a))
(fun (hxa : coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a)) =>
sigma.mk (coe_fn f (sigma.fst a)) (coe_fn f (sigma.snd a)))
fun (hxa : ¬coe_fn f (sigma.snd a) < coe_fn f (sigma.fst a)) =>
sigma.mk (coe_fn f (sigma.snd a)) (coe_fn f (sigma.fst a))
theorem sign_bij_aux_inj {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) (b : sigma fun (a : fin n) => fin n) : a ∈ fin_pairs_lt n → b ∈ fin_pairs_lt n → sign_bij_aux f a = sign_bij_aux f b → a = b := sorry
theorem sign_bij_aux_surj {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) (H : a ∈ fin_pairs_lt n) : ∃ (b : sigma fun (a : fin n) => fin n), ∃ (H : b ∈ fin_pairs_lt n), a = sign_bij_aux f b := sorry
theorem sign_bij_aux_mem {n : ℕ} {f : perm (fin n)} (a : sigma fun (a : fin n) => fin n) : a ∈ fin_pairs_lt n → sign_bij_aux f a ∈ fin_pairs_lt n := sorry
@[simp] theorem sign_aux_inv {n : ℕ} (f : perm (fin n)) : sign_aux (f⁻¹) = sign_aux f := sorry
theorem sign_aux_mul {n : ℕ} (f : perm (fin n)) (g : perm (fin n)) : sign_aux (f * g) = sign_aux f * sign_aux g := sorry
-- TODO: slow
theorem sign_aux_swap {n : ℕ} {x : fin n} {y : fin n} (hxy : x ≠ y) : sign_aux (swap x y) = -1 := sorry
/-- When the list `l : list α` contains all nonfixed points of the permutation `f : perm α`,
`sign_aux2 l f` recursively calculates the sign of `f`. -/
def sign_aux2 {α : Type u} [DecidableEq α] : List α → perm α → units ℤ :=
sorry
theorem sign_aux_eq_sign_aux2 {α : Type u} [DecidableEq α] {n : ℕ} (l : List α) (f : perm α) (e : α ≃ fin n) (h : ∀ (x : α), coe_fn f x ≠ x → x ∈ l) : sign_aux (equiv.trans (equiv.trans (equiv.symm e) f) e) = sign_aux2 l f := sorry
/-- When the multiset `s : multiset α` contains all nonfixed points of the permutation `f : perm α`,
`sign_aux2 f _` recursively calculates the sign of `f`. -/
def sign_aux3 {α : Type u} [DecidableEq α] [fintype α] (f : perm α) {s : multiset α} : (∀ (x : α), x ∈ s) → units ℤ :=
quotient.hrec_on s (fun (l : List α) (h : ∀ (x : α), x ∈ quotient.mk l) => sign_aux2 l f) sorry
theorem sign_aux3_mul_and_swap {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) (s : multiset α) (hs : ∀ (x : α), x ∈ s) : sign_aux3 (f * g) hs = sign_aux3 f hs * sign_aux3 g hs ∧ ∀ (x y : α), x ≠ y → sign_aux3 (swap x y) hs = -1 := sorry
/-- `sign` of a permutation returns the signature or parity of a permutation, `1` for even
permutations, `-1` for odd permutations. It is the unique surjective group homomorphism from
`perm α` to the group with two elements.-/
def sign {α : Type u} [DecidableEq α] [fintype α] : perm α →* units ℤ :=
monoid_hom.mk' (fun (f : perm α) => sign_aux3 f finset.mem_univ) sorry
@[simp] theorem sign_mul {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) : coe_fn sign (f * g) = coe_fn sign f * coe_fn sign g :=
monoid_hom.map_mul sign f g
@[simp] theorem sign_trans {α : Type u} [DecidableEq α] [fintype α] (f : perm α) (g : perm α) : coe_fn sign (equiv.trans f g) = coe_fn sign g * coe_fn sign f := sorry
@[simp] theorem sign_one {α : Type u} [DecidableEq α] [fintype α] : coe_fn sign 1 = 1 :=
monoid_hom.map_one sign
@[simp] theorem sign_refl {α : Type u} [DecidableEq α] [fintype α] : coe_fn sign (equiv.refl α) = 1 :=
monoid_hom.map_one sign
@[simp] theorem sign_inv {α : Type u} [DecidableEq α] [fintype α] (f : perm α) : coe_fn sign (f⁻¹) = coe_fn sign f :=
eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn sign (f⁻¹) = coe_fn sign f)) (monoid_hom.map_inv sign f)))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn sign f⁻¹ = coe_fn sign f)) (int.units_inv_eq_self (coe_fn sign f))))
(Eq.refl (coe_fn sign f)))
@[simp] theorem sign_symm {α : Type u} [DecidableEq α] [fintype α] (e : perm α) : coe_fn sign (equiv.symm e) = coe_fn sign e :=
sign_inv e
theorem sign_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (h : x ≠ y) : coe_fn sign (swap x y) = -1 :=
and.right (sign_aux3_mul_and_swap 1 1 (finset.val finset.univ) finset.mem_univ) x y h
@[simp] theorem sign_swap' {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} : coe_fn sign (swap x y) = ite (x = y) 1 (-1) := sorry
theorem is_swap.sign_eq {α : Type u} [DecidableEq α] [fintype α] {f : perm α} (h : is_swap f) : coe_fn sign f = -1 := sorry
theorem sign_aux3_symm_trans_trans {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (e : α ≃ β) {s : multiset α} {t : multiset β} (hs : ∀ (x : α), x ∈ s) (ht : ∀ (x : β), x ∈ t) : sign_aux3 (equiv.trans (equiv.trans (equiv.symm e) f) e) ht = sign_aux3 f hs := sorry
@[simp] theorem sign_symm_trans_trans {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (e : α ≃ β) : coe_fn sign (equiv.trans (equiv.trans (equiv.symm e) f) e) = coe_fn sign f :=
sign_aux3_symm_trans_trans f e finset.mem_univ finset.mem_univ
@[simp] theorem sign_trans_trans_symm {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm β) (e : α ≃ β) : coe_fn sign (equiv.trans (equiv.trans e f) (equiv.symm e)) = coe_fn sign f :=
sign_symm_trans_trans f (equiv.symm e)
theorem sign_prod_list_swap {α : Type u} [DecidableEq α] [fintype α] {l : List (perm α)} (hl : ∀ (g : perm α), g ∈ l → is_swap g) : coe_fn sign (list.prod l) = (-1) ^ list.length l := sorry
theorem sign_surjective {α : Type u} [DecidableEq α] [fintype α] (hα : 1 < fintype.card α) : function.surjective ⇑sign := sorry
theorem eq_sign_of_surjective_hom {α : Type u} [DecidableEq α] [fintype α] {s : perm α →* units ℤ} (hs : function.surjective ⇑s) : s = sign := sorry
theorem sign_subtype_perm {α : Type u} [DecidableEq α] [fintype α] (f : perm α) {p : α → Prop} [decidable_pred p] (h₁ : ∀ (x : α), p x ↔ p (coe_fn f x)) (h₂ : ∀ (x : α), coe_fn f x ≠ x → p x) : coe_fn sign (subtype_perm f h₁) = coe_fn sign f := sorry
@[simp] theorem sign_of_subtype {α : Type u} [DecidableEq α] [fintype α] {p : α → Prop} [decidable_pred p] (f : perm (Subtype p)) : coe_fn sign (coe_fn of_subtype f) = coe_fn sign f := sorry
theorem sign_eq_sign_of_equiv {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (f : perm α) (g : perm β) (e : α ≃ β) (h : ∀ (x : α), coe_fn e (coe_fn f x) = coe_fn g (coe_fn e x)) : coe_fn sign f = coe_fn sign g := sorry
theorem sign_bij {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] {f : perm α} {g : perm β} (i : (x : α) → coe_fn f x ≠ x → β) (h : ∀ (x : α) (hx : coe_fn f x ≠ x) (hx' : coe_fn f (coe_fn f x) ≠ coe_fn f x), i (coe_fn f x) hx' = coe_fn g (i x hx)) (hi : ∀ (x₁ x₂ : α) (hx₁ : coe_fn f x₁ ≠ x₁) (hx₂ : coe_fn f x₂ ≠ x₂), i x₁ hx₁ = i x₂ hx₂ → x₁ = x₂) (hg : ∀ (y : β), coe_fn g y ≠ y → ∃ (x : α), ∃ (hx : coe_fn f x ≠ x), i x hx = y) : coe_fn sign f = coe_fn sign g := sorry
@[simp] theorem support_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (hxy : x ≠ y) : support (swap x y) = insert x (singleton y) := sorry
theorem card_support_swap {α : Type u} [DecidableEq α] [fintype α] {x : α} {y : α} (hxy : x ≠ y) : finset.card (support (swap x y)) = bit0 1 := sorry
/-- If we apply `prod_extend_right a (σ a)` for all `a : α` in turn,
we get `prod_congr_right σ`. -/
theorem prod_prod_extend_right {β : Type v} {α : Type u_1} [DecidableEq α] (σ : α → perm β) {l : List α} (hl : list.nodup l) (mem_l : ∀ (a : α), a ∈ l) : list.prod (list.map (fun (a : α) => prod_extend_right a (σ a)) l) = prod_congr_right σ := sorry
@[simp] theorem sign_prod_extend_right {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (a : α) (σ : perm β) : coe_fn sign (prod_extend_right a σ) = coe_fn sign σ := sorry
theorem sign_prod_congr_right {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σ : α → perm β) : coe_fn sign (prod_congr_right σ) = finset.prod finset.univ fun (k : α) => coe_fn sign (σ k) := sorry
theorem sign_prod_congr_left {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σ : α → perm β) : coe_fn sign (prod_congr_left σ) = finset.prod finset.univ fun (k : α) => coe_fn sign (σ k) := sorry
@[simp] theorem sign_perm_congr {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (e : α ≃ β) (p : perm α) : coe_fn sign (coe_fn (perm_congr e) p) = coe_fn sign p := sorry
@[simp] theorem sign_sum_congr {α : Type u} {β : Type v} [DecidableEq α] [fintype α] [DecidableEq β] [fintype β] (σa : perm α) (σb : perm β) : coe_fn sign (sum_congr σa σb) = coe_fn sign σa * coe_fn sign σb := sorry
|
9f22486de16c5d635af25253bd46c58b50d01359 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/elab_failure.lean | 8a8bcdf42973566c94637b49cd1a2cd03486a672 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 436 | lean | import data.nat.basic data.bool
open bool nat
attribute nat.rec_on [reducible]
definition is_eq (a b : nat) : bool :=
nat.rec_on a
(λ b, nat.cases_on b tt (λb₁, ff))
(λ a₁ r₁ b, nat.cases_on b ff (λb₁, r₁ b₁))
b
example (a₁ : nat) (b : nat) : true :=
@nat.cases_on (λ (n : nat), true) b
true.intro
(λ (b₁ : _),
have aux : is_eq a₁ b₁ = is_eq (succ a₁) (succ b₁), from rfl,
true.intro)
|
0325cd2014d87215dc814fc96569374e34fb322d | 947b78d97130d56365ae2ec264df196ce769371a | /doc/examples/compiler/test.lean | f162825b9eb281a3062e569c06e90fb10564b1b1 | [
"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 | 80 | lean | def main (n : List String) : IO UInt32 :=
do IO.println (toString n);
pure 0
|
db3c6a5369f8707ae9d8191606dd453be2f21e5a | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/linear_algebra/multilinear.lean | 6475cb711f032ec466d241694531b1df39b0c1ab | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 36,917 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import linear_algebra.basic
import algebra.algebra.basic
import tactic.omega
import data.fintype.sort
/-!
# Multilinear maps
We define multilinear maps as maps from `Π(i : ι), M₁ i` to `M₂` which are linear in each
coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`multilinear_map R M₁ M₂`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `multilinear_map R M₁ M₂` is the space of multilinear maps from `Π(i : ι), M₁ i` to `M₂`.
* `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curry_left` and `f.curry_right` respectively
(with inverses `f.uncurry_left` and `f.uncurry_right`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinear_curry_left_equiv` and
`multilinear_curry_right_equiv`.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : Π(j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : Πj, M₁ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`function.update` that allows to change the value of `m` at `i`.
-/
open function fin set
open_locale big_operators
universes u v v' v₁ v₂ v₃ w u'
variables {R : Type u} {ι : Type u'} {n : ℕ}
{M : fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
[decidable_eq ι]
/-- Multilinear maps over the ring `R`, from `Πi, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules
over `R`. -/
structure multilinear_map (R : Type u) {ι : Type u'} (M₁ : ι → Type v) (M₂ : Type w)
[decidable_eq ι] [semiring R] [∀i, add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [∀i, semimodule R (M₁ i)]
[semimodule R M₂] :=
(to_fun : (Πi, M₁ i) → M₂)
(map_add' : ∀(m : Πi, M₁ i) (i : ι) (x y : M₁ i),
to_fun (update m i (x + y)) = to_fun (update m i x) + to_fun (update m i y))
(map_smul' : ∀(m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i),
to_fun (update m i (c • x)) = c • to_fun (update m i x))
namespace multilinear_map
section semiring
variables [semiring R]
[∀i, add_comm_monoid (M i)] [∀i, add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃]
[add_comm_monoid M']
[∀i, semimodule R (M i)] [∀i, semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] [semimodule R M']
(f f' : multilinear_map R M₁ M₂)
instance : has_coe_to_fun (multilinear_map R M₁ M₂) := ⟨_, to_fun⟩
@[ext] theorem ext {f f' : multilinear_map R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' :=
by cases f; cases f'; congr'; exact funext H
@[simp] lemma map_add (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp] lemma map_smul (m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update m i (c • x)) = c • f (update m i x) :=
f.map_smul' m i c x
lemma map_coord_zero {m : Πi, M₁ i} (i : ι) (h : m i = 0) : f m = 0 :=
begin
have : (0 : R) • (0 : M₁ i) = 0, by simp,
rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul]
end
@[simp] lemma map_zero [nonempty ι] : f 0 = 0 :=
begin
obtain ⟨i, _⟩ : ∃i:ι, i ∈ set.univ := set.exists_mem_of_nonempty ι,
exact map_coord_zero f i rfl
end
instance : has_add (multilinear_map R M₁ M₂) :=
⟨λf f', ⟨λx, f x + f' x, λm i x y, by simp [add_left_comm, add_assoc], λm i c x, by simp [smul_add]⟩⟩
@[simp] lemma add_apply (m : Πi, M₁ i) : (f + f') m = f m + f' m := rfl
instance : has_zero (multilinear_map R M₁ M₂) :=
⟨⟨λ _, 0, λm i x y, by simp, λm i c x, by simp⟩⟩
instance : inhabited (multilinear_map R M₁ M₂) := ⟨0⟩
@[simp] lemma zero_apply (m : Πi, M₁ i) : (0 : multilinear_map R M₁ M₂) m = 0 := rfl
instance : add_comm_monoid (multilinear_map R M₁ M₂) :=
by refine {zero := 0, add := (+), ..};
intros; ext; simp [add_comm, add_left_comm]
@[simp] lemma sum_apply {α : Type*} (f : α → multilinear_map R M₁ M₂)
(m : Πi, M₁ i) : ∀ {s : finset α}, (∑ a in s, f a) m = ∑ a in s, f a m :=
begin
classical,
apply finset.induction,
{ rw finset.sum_empty, simp },
{ assume a s has H, rw finset.sum_insert has, simp [H, has] }
end
/-- If `f` is a multilinear map, then `f.to_linear_map m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
def to_linear_map (m : Πi, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ :=
{ to_fun := λx, f (update m i x),
map_add' := λx y, by simp,
map_smul' := λc x, by simp }
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
def prod (f : multilinear_map R M₁ M₂) (g : multilinear_map R M₁ M₃) :
multilinear_map R M₁ (M₂ × M₃) :=
{ to_fun := λ m, (f m, g m),
map_add' := λ m i x y, by simp,
map_smul' := λ m i c x, by simp }
/-- Given a multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that
we use is the canonical (increasing) bijection. -/
noncomputable def restr {k n : ℕ} (f : multilinear_map R (λ i : fin n, M') M₂) (s : finset (fin n))
(hk : s.card = k) (z : M') :
multilinear_map R (λ i : fin k, M') M₂ :=
{ to_fun := λ v, f (λ j, if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z),
map_add' := λ v i x y,
by { erw [dite_comp_equiv_update, dite_comp_equiv_update, dite_comp_equiv_update], simp },
map_smul' := λ v i c x, by { erw [dite_comp_equiv_update, dite_comp_equiv_update], simp } }
variable {R}
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma cons_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
by rw [← update_cons_zero x m (x+y), f.map_add, update_cons_zero, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma cons_smul (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c • x) m) = c • f (cons x m) :=
by rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma snoc_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x y : M (last n)) :
f (snoc m (x+y)) = f (snoc m x) + f (snoc m y) :=
by rw [← update_snoc_last x m (x+y), f.map_add, update_snoc_last, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma snoc_smul (f : multilinear_map R M M₂)
(m : Π(i : fin n), M i.cast_succ) (c : R) (x : M (last n)) :
f (snoc m (c • x)) = c • f (snoc m x) :=
by rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last]
section
variables {M₁' : ι → Type*} [Π i, add_comm_monoid (M₁' i)] [Π i, semimodule R (M₁' i)]
/-- If `g` is a multilinear map and `f` is a collection of linear maps,
then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call
`g.comp_linear_map f`. -/
def comp_linear_map (g : multilinear_map R M₁' M₂) (f : Π i, M₁ i →ₗ[R] M₁' i) :
multilinear_map R M₁ M₂ :=
{ to_fun := λ m, g $ λ i, f i (m i),
map_add' := λ m i x y,
have ∀ j z, f j (update m i z j) = update (λ k, f k (m k)) i (f i z) j :=
λ j z, function.apply_update (λ k, f k) _ _ _ _,
by simp [this],
map_smul' := λ m i c x,
have ∀ j z, f j (update m i z j) = update (λ k, f k (m k)) i (f i z) j :=
λ j z, function.apply_update (λ k, f k) _ _ _ _,
by simp [this] }
@[simp] lemma comp_linear_map_apply (g : multilinear_map R M₁' M₂) (f : Π i, M₁ i →ₗ[R] M₁' i)
(m : Π i, M₁ i) :
g.comp_linear_map f m = g (λ i, f i (m i)) :=
rfl
end
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ι`
to be finite.-/
lemma map_piecewise_add (m m' : Πi, M₁ i) (t : finset ι) :
f (t.piecewise (m + m') m') = ∑ s in t.powerset, f (s.piecewise m m') :=
begin
revert m',
refine finset.induction_on t (by simp) _,
assume i t hit Hrec m',
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _,
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m',
{ ext j,
by_cases h : j = i,
{ rw h, simp [hit] },
{ simp [h] } },
let m'' := update m' i (m i),
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', hit] },
{ by_cases h' : j ∈ t; simp [h, hit, m'', h'] } },
rw [A, f.map_add, B, C, finset.sum_powerset_insert hit, Hrec, Hrec, add_comm],
congr' 1,
apply finset.sum_congr rfl (λs hs, _),
have : (insert i s).piecewise m m' = s.piecewise m m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', finset.not_mem_of_mem_powerset_of_not_mem hs hit] },
{ by_cases h' : j ∈ s; simp [h, m'', h'] } },
rw this
end
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [fintype ι] (m m' : Πi, M₁ i) :
f (m + m') = ∑ s : finset ι, f (s.piecewise m m') :=
by simpa using f.map_piecewise_add m m' finset.univ
section apply_sum
variables {α : ι → Type*} [fintype ι] (g : Π i, α i → M₁ i) (A : Π i, finset (α i))
open_locale classical
open fintype finset
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
lemma map_sum_finset_aux {n : ℕ} (h : ∑ i, (A i).card = n) :
f (λ i, ∑ j in A i, g i j) = ∑ r in pi_finset A, f (λ i, g i (r i)) :=
begin
induction n using nat.strong_induction_on with n IH generalizing A,
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : ∃ i, A i = ∅,
{ rcases Ai_empty with ⟨i, hi⟩,
have : ∑ j in A i, g i j = 0, by convert sum_empty,
rw f.map_coord_zero i this,
have : pi_finset A = ∅,
{ apply finset.eq_empty_of_forall_not_mem (λ r hr, _),
have : r i ∈ A i := mem_pi_finset.mp hr i,
rwa hi at this },
convert sum_empty.symm },
push_neg at Ai_empty,
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : ∀ i, (A i).card ≤ 1,
{ have Ai_card : ∀ i, (A i).card = 1,
{ assume i,
have : finset.card (A i) ≠ 0, by simp [finset.card_eq_zero, Ai_empty i],
have : finset.card (A i) ≤ 1 := Ai_singleton i,
omega },
have : ∀ (r : Π i, α i), r ∈ pi_finset A → f (λ i, g i (r i)) = f (λ i, ∑ j in A i, g i j),
{ assume r hr,
unfold_coes,
congr' with i,
have : ∀ j ∈ A i, g i j = g i (r i),
{ assume j hj,
congr,
apply finset.card_le_one_iff.1 (Ai_singleton i) hj,
exact mem_pi_finset.mp hr i },
simp only [finset.sum_congr rfl this, finset.mem_univ, finset.sum_const, Ai_card i,
one_nsmul] },
simp only [sum_congr rfl this, Ai_card, card_pi_finset, prod_const_one, one_nsmul,
sum_const] },
-- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2.
-- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i`
-- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton,
obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < (A i).card := Ai_singleton,
obtain ⟨j₁, j₂, hj₁, hj₂, j₁_ne_j₂⟩ : ∃ j₁ j₂, (j₁ ∈ A i₀) ∧ (j₂ ∈ A i₀) ∧ j₁ ≠ j₂ :=
finset.one_lt_card_iff.1 hi₀,
let B := function.update A i₀ (A i₀ \ {j₂}),
let C := function.update A i₀ {j₂},
have B_subset_A : ∀ i, B i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [B, sdiff_subset, update_same]},
{ simp only [hi, B, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
have C_subset_A : ∀ i, C i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [C, hj₂, finset.singleton_subset_iff, update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
-- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity.
have A_eq_BC : (λ i, ∑ j in A i, g i j) =
function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in B i₀, g i₀ j + ∑ j in C i₀, g i₀ j),
{ ext i,
by_cases hi : i = i₀,
{ rw [hi],
simp only [function.update_same],
have : A i₀ = B i₀ ∪ C i₀,
{ simp only [B, C, function.update_same, finset.sdiff_union_self_eq_union],
symmetry,
simp only [hj₂, finset.singleton_subset_iff, union_eq_left_iff_subset] },
rw this,
apply finset.sum_union,
apply finset.disjoint_right.2 (λ j hj, _),
have : j = j₂, by { dsimp [C] at hj, simpa using hj },
rw this,
dsimp [B],
simp only [mem_sdiff, eq_self_iff_true, not_true, not_false_iff, finset.mem_singleton,
update_same, and_false] },
{ simp [hi] } },
have Beq : function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in B i₀, g i₀ j) =
(λ i, ∑ j in B i, g i j),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, B, update_noteq, ne.def, not_false_iff] } },
have Ceq : function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in C i₀, g i₀ j) =
(λ i, ∑ j in C i, g i j),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff] } },
-- Express the inductive assumption for `B`
have Brec : f (λ i, ∑ j in B i, g i j) = ∑ r in pi_finset B, f (λ i, g i (r i)),
{ have : ∑ i, finset.card (B i) < ∑ i, finset.card (A i),
{ refine finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (B_subset_A i))
⟨i₀, finset.mem_univ _, _⟩,
have : {j₂} ⊆ A i₀, by simp [hj₂],
simp only [B, finset.card_sdiff this, function.update_same, finset.card_singleton],
exact nat.pred_lt (ne_of_gt (lt_trans nat.zero_lt_one hi₀)) },
rw h at this,
exact IH _ this B rfl },
-- Express the inductive assumption for `C`
have Crec : f (λ i, ∑ j in C i, g i j) = ∑ r in pi_finset C, f (λ i, g i (r i)),
{ have : ∑ i, finset.card (C i) < ∑ i, finset.card (A i) :=
finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (C_subset_A i))
⟨i₀, finset.mem_univ _, by simp [C, hi₀]⟩,
rw h at this,
exact IH _ this C rfl },
have D : disjoint (pi_finset B) (pi_finset C),
{ have : disjoint (B i₀) (C i₀), by simp [B, C],
exact pi_finset_disjoint_of_disjoint B C this },
have pi_BC : pi_finset A = pi_finset B ∪ pi_finset C,
{ apply finset.subset.antisymm,
{ assume r hr,
by_cases hri₀ : r i₀ = j₂,
{ apply finset.mem_union_right,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ C i₀, by simp [C, hri₀],
convert this },
{ simp [C, hi, mem_pi_finset.1 hr i] } },
{ apply finset.mem_union_left,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ B i₀,
by simp [B, hri₀, mem_pi_finset.1 hr i₀],
convert this },
{ simp [B, hi, mem_pi_finset.1 hr i] } } },
{ exact finset.union_subset (pi_finset_subset _ _ (λ i, B_subset_A i))
(pi_finset_subset _ _ (λ i, C_subset_A i)) } },
rw A_eq_BC,
simp only [multilinear_map.map_add, Beq, Ceq, Brec, Crec, pi_BC],
rw ← finset.sum_union D,
end
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset :
f (λ i, ∑ j in A i, g i j) = ∑ r in pi_finset A, f (λ i, g i (r i)) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [∀ i, fintype (α i)] :
f (λ i, ∑ j, g i j) = ∑ r : Π i, α i, f (λ i, g i (r i)) :=
f.map_sum_finset g (λ i, finset.univ)
end apply_sum
end semiring
end multilinear_map
namespace linear_map
variables [semiring R] [Πi, add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃]
[∀i, semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃]
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def comp_multilinear_map (g : M₂ →ₗ[R] M₃) (f : multilinear_map R M₁ M₂) :
multilinear_map R M₁ M₃ :=
{ to_fun := g ∘ f,
map_add' := λ m i x y, by simp,
map_smul' := λ m i c x, by simp }
@[simp] lemma coe_comp_multilinear_map (g : M₂ →ₗ[R] M₃) (f : multilinear_map R M₁ M₂) :
⇑(g.comp_multilinear_map f) = g ∘ f := rfl
lemma comp_multilinear_map_apply (g : M₂ →ₗ[R] M₃) (f : multilinear_map R M₁ M₂) (m : Π i, M₁ i) :
g.comp_multilinear_map f m = g (f m) := rfl
end linear_map
namespace multilinear_map
section comm_semiring
variables [comm_semiring R] [∀i, add_comm_monoid (M₁ i)] [∀i, add_comm_monoid (M i)] [add_comm_monoid M₂]
[∀i, semimodule R (M i)] [∀i, semimodule R (M₁ i)] [semimodule R M₂]
(f f' : multilinear_map R M₁ M₂)
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `∏ i in s, c i`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ι` to be finite. -/
lemma map_piecewise_smul (c : ι → R) (m : Πi, M₁ i) (s : finset ι) :
f (s.piecewise (λi, c i • m i) m) = (∏ i in s, c i) • f m :=
begin
refine s.induction_on (by simp) _,
assume j s j_not_mem_s Hrec,
have A : function.update (s.piecewise (λi, c i • m i) m) j (m j) =
s.piecewise (λi, c i • m i) m,
{ ext i,
by_cases h : i = j,
{ rw h, simp [j_not_mem_s] },
{ simp [h] } },
rw [s.piecewise_insert, f.map_smul, A, Hrec],
simp [j_not_mem_s, mul_smul]
end
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`. -/
lemma map_smul_univ [fintype ι] (c : ι → R) (m : Πi, M₁ i) :
f (λi, c i • m i) = (∏ i, c i) • f m :=
by simpa using map_piecewise_smul f c m finset.univ
instance : has_scalar R (multilinear_map R M₁ M₂) := ⟨λ c f,
⟨λ m, c • f m, λm i x y, by simp [smul_add], λl i x d, by simp [smul_smul, mul_comm]⟩⟩
@[simp] lemma smul_apply (c : R) (m : Πi, M₁ i) : (c • f) m = c • f m := rfl
section
variables (R ι) (A : Type*) [comm_semiring A] [algebra R A] [fintype ι]
/-- Given an `R`-algebra `A`, `mk_pi_algebra` is the multilinear map on `A^ι` associating
to `m` the product of all the `m i`.
See also `multilinear_map.mk_pi_algebra_fin` for a version that works with a non-commutative
algebra `A` but requires `ι = fin n`. -/
protected def mk_pi_algebra : multilinear_map R (λ i : ι, A) A :=
{ to_fun := λ m, ∏ i, m i,
map_add' := λ m i x y, by simp [finset.prod_update_of_mem, add_mul],
map_smul' := λ m i c x, by simp [finset.prod_update_of_mem] }
variables {R A ι}
@[simp] lemma mk_pi_algebra_apply (m : ι → A) :
multilinear_map.mk_pi_algebra R ι A m = ∏ i, m i :=
rfl
end
section
variables (R n) (A : Type*) [semiring A] [algebra R A]
/-- Given an `R`-algebra `A`, `mk_pi_algebra_fin` is the multilinear map on `A^n` associating
to `m` the product of all the `m i`.
See also `multilinear_map.mk_pi_algebra` for a version that assumes `[comm_semiring A]` but works
for `A^ι` with any finite type `ι`. -/
protected def mk_pi_algebra_fin : multilinear_map R (λ i : fin n, A) A :=
{ to_fun := λ m, (list.of_fn m).prod,
map_add' :=
begin
intros m i x y,
have : (list.fin_range n).index_of i < n,
by simpa using list.index_of_lt_length.2 (list.mem_fin_range i),
simp [list.of_fn_eq_map, (list.nodup_fin_range n).map_update, list.prod_update_nth, add_mul,
this, mul_add, add_mul]
end,
map_smul' :=
begin
intros m i c x,
have : (list.fin_range n).index_of i < n,
by simpa using list.index_of_lt_length.2 (list.mem_fin_range i),
simp [list.of_fn_eq_map, (list.nodup_fin_range n).map_update, list.prod_update_nth, this]
end }
variables {R A n}
@[simp] lemma mk_pi_algebra_fin_apply (m : fin n → A) :
multilinear_map.mk_pi_algebra_fin R n A m = (list.of_fn m).prod :=
rfl
lemma mk_pi_algebra_fin_apply_const (a : A) :
multilinear_map.mk_pi_algebra_fin R n A (λ _, a) = a ^ n :=
by simp
end
/-- Given an `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map
sending `m` to `f m • z`. -/
def smul_right (f : multilinear_map R M₁ R) (z : M₂) : multilinear_map R M₁ M₂ :=
(linear_map.smul_right linear_map.id z).comp_multilinear_map f
@[simp] lemma smul_right_apply (f : multilinear_map R M₁ R) (z : M₂) (m : Π i, M₁ i) :
f.smul_right z m = f m • z :=
rfl
variables (R ι)
/-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module). See also
`mk_pi_algebra` for a more general version. -/
protected def mk_pi_ring [fintype ι] (z : M₂) : multilinear_map R (λ(i : ι), R) M₂ :=
(multilinear_map.mk_pi_algebra R ι R).smul_right z
variables {R ι}
@[simp] lemma mk_pi_ring_apply [fintype ι] (z : M₂) (m : ι → R) :
(multilinear_map.mk_pi_ring R ι z : (ι → R) → M₂) m = (∏ i, m i) • z := rfl
lemma mk_pi_ring_apply_one_eq_self [fintype ι] (f : multilinear_map R (λ(i : ι), R) M₂) :
multilinear_map.mk_pi_ring R ι (f (λi, 1)) = f :=
begin
ext m,
have : m = (λi, m i • 1), by { ext j, simp },
conv_rhs { rw [this, f.map_smul_univ] },
refl
end
end comm_semiring
section ring
variables [ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂]
[∀i, semimodule R (M₁ i)] [semimodule R M₂]
(f : multilinear_map R M₁ M₂)
@[simp] lemma map_sub (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
by { simp only [map_add, add_left_inj, sub_eq_add_neg, (neg_one_smul R y).symm, map_smul], simp }
instance : has_neg (multilinear_map R M₁ M₂) :=
⟨λ f, ⟨λ m, - f m, λm i x y, by simp [add_comm], λm i c x, by simp⟩⟩
@[simp] lemma neg_apply (m : Πi, M₁ i) : (-f) m = - (f m) := rfl
instance : add_comm_group (multilinear_map R M₁ M₂) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
intros; ext; simp [add_comm, add_left_comm]
end ring
section comm_ring
variables [comm_ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂]
[∀i, semimodule R (M₁ i)] [semimodule R M₂]
variables (R ι M₁ M₂)
/-- The space of multilinear maps is a module over `R`, for the pointwise addition and scalar
multiplication. -/
instance semimodule : semimodule R (multilinear_map R M₁ M₂) :=
semimodule.of_core $ by refine { smul := (•), ..};
intros; ext; simp [smul_add, add_smul, smul_smul]
-- This instance should not be needed!
instance semimodule_ring : semimodule R (multilinear_map R (λ (i : ι), R) M₂) :=
multilinear_map.semimodule _ _ (λ (i : ι), R) _
/-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `multilinear_map.pi_ring_equiv`. -/
protected def pi_ring_equiv [fintype ι] : M₂ ≃ₗ[R] (multilinear_map R (λ(i : ι), R) M₂) :=
{ to_fun := λ z, multilinear_map.mk_pi_ring R ι z,
inv_fun := λ f, f (λi, 1),
map_add' := λ z z', by { ext m, simp [smul_add] },
map_smul' := λ c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := λ z, by simp,
right_inv := λ f, f.mk_pi_ring_apply_one_eq_self }
end comm_ring
end multilinear_map
section currying
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curry_right` (wich is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `fin n`.
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register linear equiv versions of these correspondences, in
`multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`.
-/
open multilinear_map
variables {R M M₂}
[comm_ring R] [∀i, add_comm_group (M i)] [add_comm_group M'] [add_comm_group M₂]
[∀i, module R (M i)] [module R M'] [module R M₂]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def linear_map.uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (m 0) (tail m),
map_add' := λm i x y, begin
by_cases h : i = 0,
{ revert x y,
rw h,
assume x y,
rw [update_same, update_same, update_same, f.map_add, add_apply,
tail_update_zero, tail_update_zero, tail_update_zero] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x y,
rw ← succ_pred i h,
assume x y,
rw [tail_update_succ, map_add, tail_update_succ, tail_update_succ] }
end,
map_smul' := λm i c x, begin
by_cases h : i = 0,
{ revert x,
rw h,
assume x,
rw [update_same, update_same, tail_update_zero, tail_update_zero,
← smul_apply, f.map_smul] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x,
rw ← succ_pred i h,
assume x,
rw [tail_update_succ, tail_update_succ, map_smul] }
end }
@[simp] lemma linear_map.uncurry_left_apply
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) (m : Πi, M i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/
def multilinear_map.curry_left
(f : multilinear_map R M M₂) :
M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂) :=
{ to_fun := λx,
{ to_fun := λm, f (cons x m),
map_add' := λm i y y', by simp,
map_smul' := λm i y c, by simp },
map_add' := λx y, by { ext m, exact cons_add f m x y },
map_smul' := λc x, by { ext m, exact cons_smul f m c x } }
@[simp] lemma multilinear_map.curry_left_apply
(f : multilinear_map R M M₂) (x : M 0) (m : Π(i : fin n), M i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma linear_map.curry_uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, linear_map.uncurry_left_apply, multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma multilinear_map.uncurry_curry_left
(f : multilinear_map R M M₂) :
f.curry_left.uncurry_left = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Π(i : fin n), M i.succ `, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinear_curry_left_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_left_equiv :
(M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) ≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := linear_map.uncurry_left,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := multilinear_map.curry_left,
left_inv := linear_map.curry_uncurry_left,
right_inv := multilinear_map.uncurry_curry_left }
variables {R M M₂}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))`-/
def multilinear_map.uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) (M (last n) →ₗ[R] M₂))) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (init m) (m (last n)),
map_add' := λm i x y, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this, update_noteq this],
revert x y,
rw [(cast_succ_cast_lt i h).symm],
assume x y,
rw [init_update_cast_succ, map_add, init_update_cast_succ, init_update_cast_succ,
linear_map.add_apply] },
{ revert x y,
rw eq_last_of_not_lt h,
assume x y,
rw [init_update_last, init_update_last, init_update_last,
update_same, update_same, update_same, linear_map.map_add] }
end,
map_smul' := λm i c x, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this],
revert x,
rw [(cast_succ_cast_lt i h).symm],
assume x,
rw [init_update_cast_succ, init_update_cast_succ, map_smul, linear_map.smul_apply] },
{ revert x,
rw eq_last_of_not_lt h,
assume x,
rw [update_same, update_same, init_update_last, init_update_last,
linear_map.map_smul] }
end }
@[simp] lemma multilinear_map.uncurry_right_apply
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) (m : Πi, M i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def multilinear_map.curry_right (f : multilinear_map R M M₂) :
multilinear_map R (λ(i : fin n), M (fin.cast_succ i)) ((M (last n)) →ₗ[R] M₂) :=
{ to_fun := λm,
{ to_fun := λx, f (snoc m x),
map_add' := λx y, by rw f.snoc_add,
map_smul' := λc x, by rw f.snoc_smul },
map_add' := λm i x y, begin
ext z,
change f (snoc (update m i (x + y)) z)
= f (snoc (update m i x) z) + f (snoc (update m i y) z),
rw [snoc_update, snoc_update, snoc_update, f.map_add]
end,
map_smul' := λm i c x, begin
ext z,
change f (snoc (update m i (c • x)) z) = c • f (snoc (update m i x) z),
rw [snoc_update, snoc_update, f.map_smul]
end }
@[simp] lemma multilinear_map.curry_right_apply
(f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x : M (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma multilinear_map.curry_uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, multilinear_map.curry_right_apply, multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma multilinear_map.uncurry_curry_right
(f : multilinear_map R M M₂) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Π(i : fin n), M i.cast_succ` to the
space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism
as a linear isomorphism in `multilinear_curry_right_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_right_equiv :
(multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))
≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := multilinear_map.uncurry_right,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, rw [smul_apply], refl },
inv_fun := multilinear_map.curry_right,
left_inv := multilinear_map.curry_uncurry_right,
right_inv := multilinear_map.uncurry_curry_right }
end currying
|
be92761a83aa1c06bc7131f697998277c2d2c91d | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/category_theory/equivalence.lean | beb39d8ac7e528c1cf7bb5a1045a9a09c8fc53c5 | [
"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 | 15,247 | 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.whiskering
import category_theory.natural_isomorphism
import tactic.slice
namespace category_theory
open category_theory.functor nat_iso category
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
/-- 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.
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`.
-/
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]
include 𝒞 𝒟
namespace equivalence
@[simp] def unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse := e.unit_iso.hom
@[simp] def counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D := e.counit_iso.hom
@[simp] def unit_inv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C := e.unit_iso.inv
@[simp] def counit_inv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor := e.counit_iso.inv
lemma unit_def (e : C ≌ D) : e.unit_iso.hom = e.unit := rfl
lemma counit_def (e : C ≌ D) : e.counit_iso.hom = e.counit := rfl
lemma unit_inv_def (e : C ≌ D) : e.unit_iso.inv = e.unit_inv := rfl
lemma counit_inv_def (e : C ≌ D) : e.counit_iso.inv = e.counit_inv := rfl
@[simp] lemma functor_unit_comp (e : C ≌ D) (X : C) : e.functor.map (e.unit_iso.hom.app X) ≫
e.counit_iso.hom.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_iso.inv.app (e.functor.obj X) ≫ e.functor.map (e.unit_iso.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 functor_unit (e : C ≌ D) (X : C) :
e.functor.map (e.unit.app X) = e.counit_inv.app (e.functor.obj X) :=
by { erw [←iso.comp_hom_eq_id (e.counit_iso.app _), functor_unit_comp], refl }
lemma counit_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_iso.hom.app (e.inverse.obj Y) ≫ e.inverse.map (e.counit_iso.hom.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, unit_def, unit_inv_def],
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_iso.inv.app Y) ≫ e.unit_iso.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_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 inverse_counit (e : C ≌ D) (Y : D) :
e.inverse.map (e.counit.app Y) = e.unit_inv.app (e.inverse.obj Y) :=
by { 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)
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
protected definition mk (F : C ⥤ D) (G : D ⥤ C)
(η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D) : C ≌ D :=
⟨F, G, adjointify_η η ε, ε, adjointify_η_ε η ε⟩
section
omit 𝒟
@[refl] def refl : C ≌ C := equivalence.mk (𝟭 C) (𝟭 C) (iso.refl _) (iso.refl _)
end
@[symm] 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]
include ℰ
@[trans] def trans (e : C ≌ D) (f : D ≌ E) : C ≌ E :=
begin
apply equivalence.mk (e.functor ⋙ f.functor) (f.inverse ⋙ e.inverse),
{ refine iso.trans e.unit_iso _,
exact iso_whisker_left e.functor (iso_whisker_right f.unit_iso e.inverse) },
{ refine iso.trans _ f.counit_iso,
exact iso_whisker_left f.inverse (iso_whisker_right e.counit_iso f.functor) }
end
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 }
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 }
section
omit 𝒟 ℰ
-- There's of course a monoid structure on `C ≌ C`,
-- but let's not encourage using it.
-- The power structure is nevertheless useful.
/-- Powers of an auto-equivalence. -/
def pow (e : C ≌ C) : ℤ → (C ≌ C)
| (int.of_nat 0) := equivalence.refl
| (int.of_nat 1) := e
| (int.of_nat (n+2)) := e.trans (pow (int.of_nat (n+1)))
| (int.neg_succ_of_nat 0) := e.symm
| (int.neg_succ_of_nat (n+1)) := e.symm.trans (pow (int.neg_succ_of_nat n))
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_minus_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
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
def as_equivalence (F : C ⥤ D) [is_equivalence F] : C ≌ D :=
⟨F, is_equivalence.inverse F, is_equivalence.unit_iso F, is_equivalence.counit_iso F,
is_equivalence.functor_unit_iso_comp F⟩
omit 𝒟
instance is_equivalence_refl : is_equivalence (𝟭 C) :=
is_equivalence.of_equivalence equivalence.refl
include 𝒟
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
def fun_inv_id (F : C ⥤ D) [is_equivalence F] : F ⋙ F.inv ≅ 𝟭 C :=
(is_equivalence.unit_iso F).symm
def inv_fun_id (F : C ⥤ D) [is_equivalence F] : F.inv ⋙ F ≅ 𝟭 D :=
is_equivalence.counit_iso F
variables {E : Type u₃} [ℰ : category.{v₃} E]
include ℰ
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 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.inv_fun_id.hom.app X) ≫ f ≫ (F.inv_fun_id.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.fun_inv_id.hom.app X) ≫ f ≫ (F.fun_inv_id.inv.app Y) :=
begin
erw [nat_iso.naturality_2],
refl
end
-- We should probably restate many of the lemmas about `equivalence` for `is_equivalence`,
-- but these are the only ones I need for now.
@[simp] lemma functor_unit_comp (E : C ⥤ D) [is_equivalence E] (Y) :
E.map (((is_equivalence.unit_iso E).hom).app Y) ≫ ((is_equivalence.counit_iso E).hom).app (E.obj Y) = 𝟙 _ :=
equivalence.functor_unit_comp (E.as_equivalence) Y
@[simp] lemma counit_inv_functor_comp (E : C ⥤ D) [is_equivalence E] (Y) :
((is_equivalence.counit_iso E).inv).app (E.obj Y) ≫ E.map (((is_equivalence.unit_iso E).inv).app Y) = 𝟙 _ :=
eq_of_inv_eq_inv (functor_unit_comp _ _)
end is_equivalence
class ess_surj (F : C ⥤ D) :=
(obj_preimage (d : D) : C)
(iso' (d : D) : F.obj (obj_preimage d) ≅ d . obviously)
restate_axiom ess_surj.iso'
namespace functor
def obj_preimage (F : C ⥤ D) [ess_surj F] (d : D) : C := ess_surj.obj_preimage.{v₁ v₂} F d
def fun_obj_preimage_iso (F : C ⥤ D) [ess_surj F] (d : D) : F.obj (F.obj_preimage d) ≅ d :=
ess_surj.iso F d
end functor
namespace equivalence
def ess_surj_of_equivalence (F : C ⥤ D) [is_equivalence F] : ess_surj F :=
⟨ λ Y : D, F.inv.obj Y, λ Y : D, (F.inv_fun_id.app Y) ⟩
@[priority 100] -- see Note [lower instance priority]
instance faithful_of_equivalence (F : C ⥤ D) [is_equivalence F] : faithful F :=
{ injectivity' := λ 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 }.
@[priority 100] -- see Note [lower instance priority]
instance full_of_equivalence (F : C ⥤ D) [is_equivalence F] : full F :=
{ preimage := λ X Y f, (F.fun_inv_id.app X).inv ≫ (F.inv.map f) ≫ (F.fun_inv_id.app Y).hom,
witness' := λ X Y f,
begin
apply F.inv.injectivity,
/- obviously can finish from here... -/
dsimp, simp, dsimp,
slice_lhs 4 6 {
rw [←functor.map_comp, ←functor.map_comp],
rw [←is_equivalence.fun_inv_map],
},
slice_lhs 1 2 { simp },
dsimp, simp,
slice_lhs 2 4 {
rw [←functor.map_comp, ←functor.map_comp],
erw [nat_iso.naturality_2],
},
erw [nat_iso.naturality_1], refl
end }.
@[simp] private 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.fun_obj_preimage_iso X).hom ≫ f ≫ (F.fun_obj_preimage_iso Y).inv),
map_id' := λ X, begin apply F.injectivity, tidy end,
map_comp' := λ X Y Z f g, by apply F.injectivity; simp }.
def equivalence_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.fun_obj_preimage_iso $ F.obj X).symm)
(λ X Y f, by { apply F.injectivity, obviously }))
(nat_iso.of_components
(λ Y, F.fun_obj_preimage_iso Y)
(by obviously))
end equivalence
end category_theory
|
8ddad79bc50a50dd77ac0b474fbb2bad8572af7b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/combinatorics/pigeonhole_auto.lean | 3582002153a15f73c22eb5503f6adcda5a904579 | [] | 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 | 21,592 | lean | /-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fintype.basic
import Mathlib.algebra.big_operators.order
import Mathlib.PostPort
universes u v w
namespace Mathlib
/-!
# Pigeonhole principles
Given pigeons (possibly infinitely many) in pigeonholes, the
pigeonhole principle states that, if there are more pigeons than
pigeonholes, then there is a pigeonhole with two or more pigeons.
There are a few variations on this statement, and the conclusion can
be made stronger depending on how many pigeons you know you might
have.
The basic statements of the pigeonhole principle appear in the
following locations:
* `data.finset.basic` has `finset.exists_ne_map_eq_of_card_lt_of_maps_to`
* `data.fintype.basic` has `fintype.exists_ne_map_eq_of_card_lt`
* `data.fintype.basic` has `fintype.exists_ne_map_eq_of_infinite`
* `data.fintype.basic` has `fintype.exists_infinite_fiber`
This module gives access to these pigeonhole principles along with 20 more.
The versions vary by:
* using a function between `fintype`s or a function between possibly infinite types restricted to
`finset`s;
* counting pigeons by a general weight function (`∑ x in s, w x`) or by heads (`finset.card s`);
* using strict or non-strict inequalities;
* establishing upper or lower estimate on the number (or the total weight) of the pigeons in one
pigeonhole;
* in case when we count pigeons by some weight function `w` and consider a function `f` between
`finset`s `s` and `t`, we can either assume that each pigeon is in one of the pigeonholes
(`∀ x ∈ s, f x ∈ t`), or assume that for `y ∉ t`, the total weight of the pigeons in this
pigeonhole `∑ x in s.filter (λ x, f x = y), w x` is nonpositive or nonnegative depending on
the inequality we are proving.
Lemma names follow `mathlib` convention (e.g.,
`finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`); "pigeonhole principle" is mentioned in the
docstrings instead of the names.
## See also
* `ordinal.infinite_pigeonhole`: pigeonhole principle for cardinals, formulated using cofinality;
* `measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure`,
`measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure`: pigeonhole principle in a
measure space.
## Tags
pigeonhole principle
-/
namespace finset
/-!
### The pigeonhole principles on `finset`s, pigeons counted by weight
In this section we prove the following version of the pigeonhole principle: if the total weight of a
finite set of pigeons is greater than `n •ℕ b`, and they are sorted into `n` pigeonholes, then for
some pigeonhole, the total weight of the pigeons in this pigeonhole is greateer than `b`, and a few
variations of this theorem.
The principle is formalized in the following way, see
`finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum`: if `f : α → β` is a function which maps all
elements of `s : finset α` to `t : finset β` and `card t •ℕ b < ∑ x in s, w x`, where `w : α → M` is
a weight function taking values in a `linear_ordered_cancel_add_comm_monoid`, then for
some `y ∈ t`, the sum of the weights of all `x ∈ s` such that `f x = y` is greater than `b`.
There are a few bits we can change in this theorem:
* reverse all inequalities, with obvious adjustments to the name;
* replace the assumption `∀ a ∈ s, f a ∈ t` with
`∀ y ∉ t, (∑ x in s.filter (λ x, f x = y), w x) ≤ 0`,
and replace `of_maps_to` with `of_sum_fiber_nonpos` in the name;
* use non-strict inequalities assuming `t` is nonempty.
We can do all these variations independently, so we have eight versions of the theorem.
-/
/-!
#### Strict inequality versions
-/
/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:
if the total weight of a finite set of pigeons is greater than `n •ℕ b`, and they are sorted into
`n` pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is
greater than `b`. -/
theorem exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α} {t : finset β}
{f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a ∈ s → f a ∈ t)
(hb : card t •ℕ b < finset.sum s fun (x : α) => w x) :
∃ (y : β),
∃ (H : y ∈ t), b < finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:
if the total weight of a finite set of pigeons is less than `n •ℕ b`, and they are sorted into `n`
pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less
than `b`. -/
theorem exists_sum_fiber_lt_of_maps_to_of_sum_lt_nsmul {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α} {t : finset β}
{f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a ∈ s → f a ∈ t)
(hb : (finset.sum s fun (x : α) => w x) < card t •ℕ b) :
∃ (y : β),
∃ (H : y ∈ t), (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) < b :=
exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum hf hb
/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:
if the total weight of a finite set of pigeons is greater than `n •ℕ b`, they are sorted into some
pigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonpositive,
then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole
is greater than `b`. -/
theorem exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum {α : Type u} {β : Type v}
{M : Type w} [linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {w : α → M} {b : M}
(ht :
∀ (y : β), ¬y ∈ t → (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) ≤ 0)
(hb : card t •ℕ b < finset.sum s fun (x : α) => w x) :
∃ (y : β),
∃ (H : y ∈ t), b < finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version:
if the total weight of a finite set of pigeons is less than `n •ℕ b`, they are sorted into some
pigeonholes, and for all but `n` pigeonholes the total weight of the pigeons there is nonnegative,
then for at least one of these `n` pigeonholes, the total weight of the pigeons in this pigeonhole
is less than `b`. -/
theorem exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul {α : Type u} {β : Type v}
{M : Type w} [linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {w : α → M} {b : M}
(ht : ∀ (y : β), ¬y ∈ t → 0 ≤ finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x)
(hb : (finset.sum s fun (x : α) => w x) < card t •ℕ b) :
∃ (y : β),
∃ (H : y ∈ t), (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) < b :=
exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum ht hb
/-!
#### Non-strict inequality versions
-/
/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality
version: if the total weight of a finite set of pigeons is greater than or equal to `n •ℕ b`, and
they are sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons
in this pigeonhole is greater than or equal to `b`. -/
theorem exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α} {t : finset β}
{f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a ∈ s → f a ∈ t) (ht : finset.nonempty t)
(hb : card t •ℕ b ≤ finset.sum s fun (x : α) => w x) :
∃ (y : β),
∃ (H : y ∈ t), b ≤ finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality
version: if the total weight of a finite set of pigeons is less than or equal to `n •ℕ b`, and they
are sorted into `n > 0` pigeonholes, then for some pigeonhole, the total weight of the pigeons in
this pigeonhole is less than or equal to `b`. -/
theorem exists_sum_fiber_le_of_maps_to_of_sum_le_nsmul {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α} {t : finset β}
{f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a ∈ s → f a ∈ t) (ht : finset.nonempty t)
(hb : (finset.sum s fun (x : α) => w x) ≤ card t •ℕ b) :
∃ (y : β),
∃ (H : y ∈ t), (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) ≤ b :=
exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum hf ht hb
/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality
version: if the total weight of a finite set of pigeons is greater than or equal to `n •ℕ b`, they
are sorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the
pigeons there is nonpositive, then for at least one of these `n` pigeonholes, the total weight of
the pigeons in this pigeonhole is greater than or equal to `b`. -/
theorem exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum {α : Type u} {β : Type v}
{M : Type w} [linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {w : α → M} {b : M}
(hf :
∀ (y : β), ¬y ∈ t → (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) ≤ 0)
(ht : finset.nonempty t) (hb : card t •ℕ b ≤ finset.sum s fun (x : α) => w x) :
∃ (y : β),
∃ (H : y ∈ t), b ≤ finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality
version: if the total weight of a finite set of pigeons is less than or equal to `n •ℕ b`, they are
sorted into some pigeonholes, and for all but `n > 0` pigeonholes the total weight of the pigeons
there is nonnegative, then for at least one of these `n` pigeonholes, the total weight of the
pigeons in this pigeonhole is less than or equal to `b`. -/
theorem exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul {α : Type u} {β : Type v}
{M : Type w} [linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {w : α → M} {b : M}
(hf : ∀ (y : β), ¬y ∈ t → 0 ≤ finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x)
(ht : finset.nonempty t) (hb : (finset.sum s fun (x : α) => w x) ≤ card t •ℕ b) :
∃ (y : β),
∃ (H : y ∈ t), (finset.sum (filter (fun (x : α) => f x = y) s) fun (x : α) => w x) ≤ b :=
exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum hf ht hb
/-!
### The pigeonhole principles on `finset`s, pigeons counted by heads
In this section we formalize a few versions of the following pigeonhole principle: there is a
pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all
pigeonholes.
First, we can use strict or non-strict inequalities. While the versions with non-strict inequalities
are weaker than those with strict inequalities, sometimes it might be more convenient to apply the
weaker version. Second, we can either state that there exists a pigeonhole with at least `n`
pigeons, or state that there exists a pigeonhole with at most `n` pigeons. In the latter case we do
not need the assumption `∀ a ∈ s, f a ∈ t`.
So, we prove four theorems: `finset.exists_lt_card_fiber_of_maps_to_of_mul_lt_card`,
`finset.exists_le_card_fiber_of_maps_to_of_mul_le_card`,
`finset.exists_card_fiber_lt_of_card_lt_mul`, and `finset.exists_card_fiber_le_of_card_le_mul`. -/
/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with
at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes.
("The maximum is at least the mean" specialized to integers.)
More formally, given a function between finite sets `s` and `t` and a natural number `n` such that
`card t * n < card s`, there exists `y ∈ t` such that its preimage in `s` has more than `n`
elements. -/
theorem exists_lt_card_fiber_of_mul_lt_card_of_maps_to {α : Type u} {β : Type v} [DecidableEq β]
{s : finset α} {t : finset β} {f : α → β} {n : ℕ} (hf : ∀ (a : α), a ∈ s → f a ∈ t)
(hn : card t * n < card s) :
∃ (y : β), ∃ (H : y ∈ t), n < card (filter (fun (x : α) => f x = y) s) :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with
at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. ("The
minimum is at most the mean" specialized to integers.)
More formally, given a function `f`, a finite sets `s` in its domain, a finite set `t` in its
codomain, and a natural number `n` such that `card s < card t * n`, there exists `y ∈ t` such that
its preimage in `s` has less than `n` elements. -/
theorem exists_card_fiber_lt_of_card_lt_mul {α : Type u} {β : Type v} [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {n : ℕ} (hn : card s < card t * n) :
∃ (y : β), ∃ (H : y ∈ t), card (filter (fun (x : α) => f x = y) s) < n :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function between
finite sets `s` and `t` and a natural number `n` such that `card t * n ≤ card s`, there exists `y ∈
t` such that its preimage in `s` has at least `n` elements. See also
`finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to` for a stronger statement. -/
theorem exists_le_card_fiber_of_mul_le_card_of_maps_to {α : Type u} {β : Type v} [DecidableEq β]
{s : finset α} {t : finset β} {f : α → β} {n : ℕ} (hf : ∀ (a : α), a ∈ s → f a ∈ t)
(ht : finset.nonempty t) (hn : card t * n ≤ card s) :
∃ (y : β), ∃ (H : y ∈ t), n ≤ card (filter (fun (x : α) => f x = y) s) :=
sorry
/-- The pigeonhole principle for finitely many pigeons counted by heads: given a function `f`, a
finite sets `s` in its domain, a finite set `t` in its codomain, and a natural number `n` such that
`card s ≤ card t * n`, there exists `y ∈ t` such that its preimage in `s` has no more than `n`
elements. See also `finset.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/
theorem exists_card_fiber_le_of_card_le_mul {α : Type u} {β : Type v} [DecidableEq β] {s : finset α}
{t : finset β} {f : α → β} {n : ℕ} (ht : finset.nonempty t) (hn : card s ≤ card t * n) :
∃ (y : β), ∃ (H : y ∈ t), card (filter (fun (x : α) => f x = y) s) ≤ n :=
sorry
end finset
namespace fintype
/-!
### The pigeonhole principles on `fintypes`s, pigeons counted by weight
In this section we specialize theorems from the previous section to the special case of functions
between `fintype`s and `s = univ`, `t = univ`. In this case the assumption `∀ x ∈ s, f x ∈ t` always
holds, so we have four theorems instead of eight. -/
/-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality
version: there is a pigeonhole with the total weight of pigeons in it greater than `b` provided that
the total number of pigeonholes times `b` is less than the total weight of all pigeons. -/
theorem exists_lt_sum_fiber_of_nsmul_lt_sum {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] [fintype α] [fintype β] (f : α → β)
{w : α → M} {b : M} (hb : card β •ℕ b < finset.sum finset.univ fun (x : α) => w x) :
∃ (y : β),
b < finset.sum (finset.filter (fun (x : α) => f x = y) finset.univ) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality
version: there is a pigeonhole with the total weight of pigeons in it greater than or equal to `b`
provided that the total number of pigeonholes times `b` is less than or equal to the total weight of
all pigeons. -/
theorem exists_le_sum_fiber_of_nsmul_le_sum {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] [fintype α] [fintype β] (f : α → β)
{w : α → M} {b : M} [Nonempty β]
(hb : card β •ℕ b ≤ finset.sum finset.univ fun (x : α) => w x) :
∃ (y : β),
b ≤ finset.sum (finset.filter (fun (x : α) => f x = y) finset.univ) fun (x : α) => w x :=
sorry
/-- The pigeonhole principle for finitely many pigeons of different weights, strict inequality
version: there is a pigeonhole with the total weight of pigeons in it less than `b` provided that
the total number of pigeonholes times `b` is greater than the total weight of all pigeons. -/
theorem exists_sum_fiber_lt_of_sum_lt_nsmul {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] [fintype α] [fintype β] (f : α → β)
{w : α → M} {b : M} (hb : (finset.sum finset.univ fun (x : α) => w x) < card β •ℕ b) :
∃ (y : β),
(finset.sum (finset.filter (fun (x : α) => f x = y) finset.univ) fun (x : α) => w x) < b :=
exists_lt_sum_fiber_of_nsmul_lt_sum (fun (x : α) => f x) hb
/-- The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality
version: there is a pigeonhole with the total weight of pigeons in it less than or equal to `b`
provided that the total number of pigeonholes times `b` is greater than or equal to the total weight
of all pigeons. -/
theorem exists_sum_fiber_le_of_sum_le_nsmul {α : Type u} {β : Type v} {M : Type w}
[linear_ordered_cancel_add_comm_monoid M] [DecidableEq β] [fintype α] [fintype β] (f : α → β)
{w : α → M} {b : M} [Nonempty β]
(hb : (finset.sum finset.univ fun (x : α) => w x) ≤ card β •ℕ b) :
∃ (y : β),
(finset.sum (finset.filter (fun (x : α) => f x = y) finset.univ) fun (x : α) => w x) ≤ b :=
exists_le_sum_fiber_of_nsmul_le_sum (fun (x : α) => f x) hb
/--
The strong pigeonhole principle for finitely many pigeons and pigeonholes.
There is a pigeonhole with at least as many pigeons as
the ceiling of the average number of pigeons across all pigeonholes.
("The maximum is at least the mean" specialized to integers.)
More formally, given a function `f` between finite types `α` and `β` and a number `n` such that
`card β * n < card α`, there exists an element `y : β` such that its preimage has more than `n`
elements. -/
theorem exists_lt_card_fiber_of_mul_lt_card {α : Type u} {β : Type v} [DecidableEq β] [fintype α]
[fintype β] (f : α → β) {n : ℕ} (hn : card β * n < card α) :
∃ (y : β), n < finset.card (finset.filter (fun (x : α) => f x = y) finset.univ) :=
sorry
/--
The strong pigeonhole principle for finitely many pigeons and pigeonholes.
There is a pigeonhole with at most as many pigeons as
the floor of the average number of pigeons across all pigeonholes.
("The minimum is at most the mean" specialized to integers.)
More formally, given a function `f` between finite types `α` and `β` and a number `n` such that
`card α < card β * n`, there exists an element `y : β` such that its preimage has less than `n`
elements. -/
theorem exists_card_fiber_lt_of_card_lt_mul {α : Type u} {β : Type v} [DecidableEq β] [fintype α]
[fintype β] (f : α → β) {n : ℕ} (hn : card α < card β * n) :
∃ (y : β), finset.card (finset.filter (fun (x : α) => f x = y) finset.univ) < n :=
sorry
/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `n` such that `card β * n ≤ card α`, there exists an
element `y : β` such that its preimage has at least `n` elements. See also
`fintype.exists_lt_card_fiber_of_mul_lt_card` for a stronger statement. -/
theorem exists_le_card_fiber_of_mul_le_card {α : Type u} {β : Type v} [DecidableEq β] [fintype α]
[fintype β] (f : α → β) {n : ℕ} [Nonempty β] (hn : card β * n ≤ card α) :
∃ (y : β), n ≤ finset.card (finset.filter (fun (x : α) => f x = y) finset.univ) :=
sorry
/-- The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function `f`
between finite types `α` and `β` and a number `n` such that `card α ≤ card β * n`, there exists an
element `y : β` such that its preimage has at most `n` elements. See also
`fintype.exists_card_fiber_lt_of_card_lt_mul` for a stronger statement. -/
theorem exists_card_fiber_le_of_card_le_mul {α : Type u} {β : Type v} [DecidableEq β] [fintype α]
[fintype β] (f : α → β) {n : ℕ} [Nonempty β] (hn : card α ≤ card β * n) :
∃ (y : β), finset.card (finset.filter (fun (x : α) => f x = y) finset.univ) ≤ n :=
sorry
end Mathlib |
9d768747f5f2fcedc0ccbbd4eab57bdc11fb4a02 | 2fbe653e4bc441efde5e5d250566e65538709888 | /src/measure_theory/integration.lean | 3ae0b717a9570a865b8cd3ed3b9eac3f61355e6e | [
"Apache-2.0"
] | permissive | aceg00/mathlib | 5e15e79a8af87ff7eb8c17e2629c442ef24e746b | 8786ea6d6d46d6969ac9a869eb818bf100802882 | refs/heads/master | 1,649,202,698,930 | 1,580,924,783,000 | 1,580,924,783,000 | 149,197,272 | 0 | 0 | Apache-2.0 | 1,537,224,208,000 | 1,537,224,207,000 | null | UTF-8 | Lean | false | false | 56,446 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
Lebesgue integral on `ennreal`.
We define simple functions and show that each Borel measurable function on `ennreal` can be
approximated by a sequence of simple functions.
-/
import
algebra.pi_instances
measure_theory.measure_space
measure_theory.borel_space
noncomputable theory
open lattice set filter
open_locale classical topological_space
namespace measure_theory
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- A function `f` from a measurable space to any type is called *simple*,
if every preimage `f ⁻¹' {x}` is measurable, and the range is finite. This structure bundles
a function with these properties. -/
structure {u v} simple_func (α : Type u) [measurable_space α] (β : Type v) :=
(to_fun : α → β)
(measurable_sn : ∀ x, is_measurable (to_fun ⁻¹' {x}))
(finite : (set.range to_fun).finite)
local infixr ` →ₛ `:25 := simple_func
namespace simple_func
section measurable
variables [measurable_space α]
instance has_coe_to_fun : has_coe_to_fun (α →ₛ β) := ⟨_, to_fun⟩
@[ext] theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g :=
by cases f; cases g; congr; exact funext H
/-- Range of a simple function `α →ₛ β` as a `finset β`. -/
protected def range (f : α →ₛ β) : finset β := f.finite.to_finset
@[simp] theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ ∃ a, f a = b :=
finite.mem_to_finset
lemma preimage_eq_empty_iff (f : α →ₛ β) (b : β) : f ⁻¹' {b} = ∅ ↔ b ∉ f.range :=
iff.intro
(by simp [set.eq_empty_iff_forall_not_mem, mem_range])
(by simp [set.eq_empty_iff_forall_not_mem, mem_range])
/-- Constant function as a `simple_func`. -/
def const (α) {β} [measurable_space α] (b : β) : α →ₛ β :=
⟨λ a, b, λ x, is_measurable.const _,
finite_subset (set.finite_singleton b) $ by rintro _ ⟨a, rfl⟩; simp⟩
instance [inhabited β] : inhabited (α →ₛ β) := ⟨const _ (default _)⟩
@[simp] theorem const_apply (a : α) (b : β) : (const α b) a = b := rfl
lemma range_const (α) [measurable_space α] [ne : nonempty α] (b : β) :
(const α b).range = {b} :=
begin
ext b',
simp [mem_range],
exact ⟨assume ⟨_, h⟩, h.symm, assume h, ne.elim $ λa, ⟨a, h.symm⟩⟩
end
lemma is_measurable_cut (p : α → β → Prop) (f : α →ₛ β)
(h : ∀b, is_measurable {a | p a b}) : is_measurable {a | p a (f a)} :=
begin
rw (_ : {a | p a (f a)} = ⋃ b ∈ set.range f, {a | p a b} ∩ f ⁻¹' {b}),
{ exact is_measurable.bUnion (countable_finite f.finite)
(λ b _, is_measurable.inter (h b) (f.measurable_sn _)) },
ext a, simp,
exact ⟨λ h, ⟨_, ⟨a, rfl⟩, h, rfl⟩, λ ⟨_, ⟨a', rfl⟩, h', e⟩, e.symm ▸ h'⟩
end
theorem preimage_measurable (f : α →ₛ β) (s) : is_measurable (f ⁻¹' s) :=
is_measurable_cut (λ _ b, b ∈ s) f (λ b, by simp [is_measurable.const])
/-- A simple function is measurable -/
theorem measurable [measurable_space β] (f : α →ₛ β) : measurable f :=
λ s _, preimage_measurable f s
def ite {s : set α} (hs : is_measurable s) (f g : α →ₛ β) : α →ₛ β :=
⟨λ a, if a ∈ s then f a else g a,
λ x, by letI : measurable_space β := ⊤; exact
measurable.if hs f.measurable g.measurable _ trivial,
finite_subset (finite_union f.finite g.finite) begin
rintro _ ⟨a, rfl⟩,
by_cases a ∈ s; simp [h],
exacts [or.inl ⟨_, rfl⟩, or.inr ⟨_, rfl⟩]
end⟩
@[simp] theorem ite_apply {s : set α} (hs : is_measurable s)
(f g : α →ₛ β) (a) : ite hs f g a = if a ∈ s then f a else g a := rfl
/-- If `f : α →ₛ β` is a simple function and `g : β → α →ₛ γ` is a family of simple functions,
then `f.bind g` binds the first argument of `g` to `f`. In other words, `f.bind g a = g (f a) a`. -/
def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ :=
⟨λa, g (f a) a,
λ c, is_measurable_cut (λa b, g b a ∈ ({c} : set γ)) f (λ b, (g b).measurable_sn c),
finite_subset (finite_bUnion f.finite (λ b, (g b).finite)) $
by rintro _ ⟨a, rfl⟩; simp; exact ⟨_, ⟨a, rfl⟩, _, rfl⟩⟩
@[simp] theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) :
f.bind g a = g (f a) a := rfl
/-- Restrict a simple function `f : α →ₛ β`` to a set `s`. If `s` is measurable,
then `f.restrict s a = if a ∈ s then f a else 0`, otherwise `f.restrict s = const α 0`. -/
def restrict [has_zero β] (f : α →ₛ β) (s : set α) : α →ₛ β :=
if hs : is_measurable s then ite hs f (const α 0) else const α 0
@[simp] theorem restrict_apply [has_zero β]
(f : α →ₛ β) {s : set α} (hs : is_measurable s) (a) :
restrict f s a = if a ∈ s then f a else 0 :=
by unfold_coes; simp [restrict, hs]; apply ite_apply hs
theorem restrict_preimage [has_zero β]
(f : α →ₛ β) {s : set α} (hs : is_measurable s)
{t : set β} (ht : (0:β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t :=
by ext a; dsimp [preimage]; rw [restrict_apply]; by_cases a ∈ s; simp [h, hs, ht]
/-- Given a function `g : β → γ` and a simple function `f : α →ₛ β`, `f.map g` return the simple
function `g ∘ f : α →ₛ γ` -/
def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ := bind f (const α ∘ g)
@[simp] theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) := rfl
theorem map_map (g : β → γ) (h: γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) := rfl
theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f := rfl
@[simp] theorem range_map [decidable_eq γ] (g : β → γ) (f : α →ₛ β) :
(f.map g).range = f.range.image g :=
begin
ext c,
simp only [mem_range, exists_prop, mem_range, finset.mem_image, map_apply],
split,
{ rintros ⟨a, rfl⟩, exact ⟨f a, ⟨_, rfl⟩, rfl⟩ },
{ rintros ⟨_, ⟨a, rfl⟩, rfl⟩, exact ⟨_, rfl⟩ }
end
lemma map_preimage (f : α →ₛ β) (g : β → γ) (s : set γ) :
(f.map g) ⁻¹' s = (⋃b∈f.range.filter (λb, g b ∈ s), f ⁻¹' {b}) :=
begin
/- True because `f` only takes finitely many values. -/
ext a',
simp only [mem_Union, set.mem_preimage, exists_prop, set.mem_preimage, map_apply,
finset.mem_filter, mem_range, mem_singleton_iff, exists_eq_right'],
split,
{ assume eq, exact ⟨⟨_, rfl⟩, eq⟩ },
{ rintros ⟨_, eq⟩, exact eq }
end
lemma map_preimage_singleton (f : α →ₛ β) (g : β → γ) (c : γ) :
(f.map g) ⁻¹' {c} = (⋃b∈f.range.filter (λb, g b = c), f ⁻¹' {b}) :=
begin
rw map_preimage,
have : (λb, g b = c) = λb, g b ∈ _root_.singleton c,
funext, rw [eq_iff_iff, mem_singleton_iff],
rw this
end
/-- If `f` is a simple function taking values in `β → γ` and `g` is another simple function
with the same domain and codomain `β`, then `f.seq g = f a (g a)`. -/
def seq (f : α →ₛ (β → γ)) (g : α →ₛ β) : α →ₛ γ := f.bind (λf, g.map f)
@[simp] lemma seq_apply (f : α →ₛ (β → γ)) (g : α →ₛ β) (a : α) : f.seq g a = f a (g a) := rfl
/-- Combine two simple functions `f : α →ₛ β` and `g : α →ₛ β`
into `λ a, (f a, g a)`. -/
def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ (β × γ) := (f.map prod.mk).seq g
@[simp] lemma pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) := rfl
lemma pair_preimage (f : α →ₛ β) (g : α →ₛ γ) (s : set β) (t : set γ) :
(pair f g) ⁻¹' (set.prod s t) = (f ⁻¹' s) ∩ (g ⁻¹' t) := rfl
/- A special form of `pair_preimage` -/
lemma pair_preimage_singleton (f : α →ₛ β) (g : α →ₛ γ) (b : β) (c : γ) :
(pair f g) ⁻¹' {(b, c)} = (f ⁻¹' {b}) ∩ (g ⁻¹' {c}) :=
by { rw ← prod_singleton_singleton, exact pair_preimage _ _ _ _ }
theorem bind_const (f : α →ₛ β) : f.bind (const α) = f := by ext; simp
instance [has_zero β] : has_zero (α →ₛ β) := ⟨const α 0⟩
instance [has_add β] : has_add (α →ₛ β) := ⟨λf g, (f.map (+)).seq g⟩
instance [has_mul β] : has_mul (α →ₛ β) := ⟨λf g, (f.map (*)).seq g⟩
instance [has_sup β] : has_sup (α →ₛ β) := ⟨λf g, (f.map (⊔)).seq g⟩
instance [has_inf β] : has_inf (α →ₛ β) := ⟨λf g, (f.map (⊓)).seq g⟩
instance [has_le β] : has_le (α →ₛ β) := ⟨λf g, ∀a, f a ≤ g a⟩
@[simp] lemma sup_apply [has_sup β] (f g : α →ₛ β) (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl
@[simp] lemma mul_apply [has_mul β] (f g : α →ₛ β) (a : α) : (f * g) a = f a * g a := rfl
lemma add_apply [has_add β] (f g : α →ₛ β) (a : α) : (f + g) a = f a + g a := rfl
lemma add_eq_map₂ [has_add β] (f g : α →ₛ β) : f + g = (pair f g).map (λp:β×β, p.1 + p.2) :=
rfl
lemma sup_eq_map₂ [has_sup β] (f g : α →ₛ β) : f ⊔ g = (pair f g).map (λp:β×β, p.1 ⊔ p.2) :=
rfl
lemma const_mul_eq_map [has_mul β] (f : α →ₛ β) (b : β) : const α b * f = f.map (λa, b * a) := rfl
instance [add_monoid β] : add_monoid (α →ₛ β) :=
{ add := (+), zero := 0,
add_assoc := assume f g h, ext (assume a, add_assoc _ _ _),
zero_add := assume f, ext (assume a, zero_add _),
add_zero := assume f, ext (assume a, add_zero _) }
instance add_comm_monoid [add_comm_monoid β] : add_comm_monoid (α →ₛ β) :=
{ add_comm := λ f g, ext (λa, add_comm _ _),
.. simple_func.add_monoid }
instance [has_neg β] : has_neg (α →ₛ β) := ⟨λf, f.map (has_neg.neg)⟩
instance [add_group β] : add_group (α →ₛ β) :=
{ neg := has_neg.neg,
add_left_neg := λf, ext (λa, add_left_neg _),
.. simple_func.add_monoid }
instance [add_comm_group β] : add_comm_group (α →ₛ β) :=
{ add_comm := λ f g, ext (λa, add_comm _ _) ,
.. simple_func.add_group }
variables {K : Type*}
instance [has_scalar K β] : has_scalar K (α →ₛ β) := ⟨λk f, f.map (λb, k • b)⟩
instance [semiring K] [add_comm_monoid β] [semimodule K β] : semimodule K (α →ₛ β) :=
{ one_smul := λ f, ext (λa, one_smul _ _),
mul_smul := λ x y f, ext (λa, mul_smul _ _ _),
smul_add := λ r f g, ext (λa, smul_add _ _ _),
smul_zero := λ r, ext (λa, smul_zero _),
add_smul := λ r s f, ext (λa, add_smul _ _ _),
zero_smul := λ f, ext (λa, zero_smul _ _) }
instance [ring K] [add_comm_group β] [module K β] : module K (α →ₛ β) :=
{ .. simple_func.semimodule }
instance [discrete_field K] [add_comm_group β] [module K β] : vector_space K (α →ₛ β) :=
{ .. simple_func.module }
lemma smul_apply [has_scalar K β] (k : K) (f : α →ₛ β) (a : α) : (k • f) a = k • f a := rfl
lemma smul_eq_map [has_scalar K β] (k : K) (f : α →ₛ β) : k • f = f.map (λb, k • b) := rfl
instance [preorder β] : preorder (α →ₛ β) :=
{ le_refl := λf a, le_refl _,
le_trans := λf g h hfg hgh a, le_trans (hfg _) (hgh a),
.. simple_func.has_le }
instance [partial_order β] : partial_order (α →ₛ β) :=
{ le_antisymm := assume f g hfg hgf, ext $ assume a, le_antisymm (hfg a) (hgf a),
.. simple_func.preorder }
instance [order_bot β] : order_bot (α →ₛ β) :=
{ bot := const α ⊥, bot_le := λf a, bot_le, .. simple_func.partial_order }
instance [order_top β] : order_top (α →ₛ β) :=
{ top := const α⊤, le_top := λf a, le_top, .. simple_func.partial_order }
instance [semilattice_inf β] : semilattice_inf (α →ₛ β) :=
{ inf := (⊓),
inf_le_left := assume f g a, inf_le_left,
inf_le_right := assume f g a, inf_le_right,
le_inf := assume f g h hfh hgh a, le_inf (hfh a) (hgh a),
.. simple_func.partial_order }
instance [semilattice_sup β] : semilattice_sup (α →ₛ β) :=
{ sup := (⊔),
le_sup_left := assume f g a, le_sup_left,
le_sup_right := assume f g a, le_sup_right,
sup_le := assume f g h hfh hgh a, sup_le (hfh a) (hgh a),
.. simple_func.partial_order }
instance [semilattice_sup_bot β] : semilattice_sup_bot (α →ₛ β) :=
{ .. simple_func.lattice.semilattice_sup,.. simple_func.lattice.order_bot }
instance [lattice β] : lattice (α →ₛ β) :=
{ .. simple_func.lattice.semilattice_sup,.. simple_func.lattice.semilattice_inf }
instance [bounded_lattice β] : bounded_lattice (α →ₛ β) :=
{ .. simple_func.lattice.lattice, .. simple_func.lattice.order_bot, .. simple_func.lattice.order_top }
lemma finset_sup_apply [semilattice_sup_bot β] {f : γ → α →ₛ β} (s : finset γ) (a : α) :
s.sup f a = s.sup (λc, f c a) :=
begin
refine finset.induction_on s rfl _,
assume a s hs ih,
rw [finset.sup_insert, finset.sup_insert, sup_apply, ih]
end
section approx
section
variables [semilattice_sup_bot β] [has_zero β]
/-- Fix a sequence `i : ℕ → β`. Given a function `α → β`, its `n`-th approximation
by simple functions is defined so that in case `β = ennreal` it sends each `a` to the supremum
of the set `{i k | k ≤ n ∧ i k ≤ f a}`, see `approx_apply` and `supr_approx_apply` for details. -/
def approx (i : ℕ → β) (f : α → β) (n : ℕ) : α →ₛ β :=
(finset.range n).sup (λk, restrict (const α (i k)) {a:α | i k ≤ f a})
lemma approx_apply [topological_space β] [order_closed_topology β] {i : ℕ → β} {f : α → β} {n : ℕ}
(a : α) (hf : _root_.measurable f) :
(approx i f n : α →ₛ β) a = (finset.range n).sup (λk, if i k ≤ f a then i k else 0) :=
begin
dsimp only [approx],
rw [finset_sup_apply],
congr,
funext k,
rw [restrict_apply],
refl,
exact (hf.preimage $ is_measurable_of_is_closed $ is_closed_ge' _)
end
lemma monotone_approx (i : ℕ → β) (f : α → β) : monotone (approx i f) :=
assume n m h, finset.sup_mono $ finset.range_subset.2 h
lemma approx_comp [topological_space β] [order_closed_topology β] [measurable_space γ]
{i : ℕ → β} {f : γ → β} {g : α → γ} {n : ℕ} (a : α)
(hf : _root_.measurable f) (hg : _root_.measurable g) :
(approx i (f ∘ g) n : α →ₛ β) a = (approx i f n : γ →ₛ β) (g a) :=
by rw [approx_apply _ hf, approx_apply _ (hf.comp hg)]
end
lemma supr_approx_apply [topological_space β] [complete_lattice β] [order_closed_topology β] [has_zero β]
(i : ℕ → β) (f : α → β) (a : α) (hf : _root_.measurable f) (h_zero : (0 : β) = ⊥) :
(⨆n, (approx i f n : α →ₛ β) a) = (⨆k (h : i k ≤ f a), i k) :=
begin
refine le_antisymm (supr_le $ assume n, _) (supr_le $ assume k, supr_le $ assume hk, _),
{ rw [approx_apply a hf, h_zero],
refine finset.sup_le (assume k hk, _),
split_ifs,
exact le_supr_of_le k (le_supr _ h),
exact bot_le },
{ refine le_supr_of_le (k+1) _,
rw [approx_apply a hf],
have : k ∈ finset.range (k+1) := finset.mem_range.2 (nat.lt_succ_self _),
refine le_trans (le_of_eq _) (finset.le_sup this),
rw [if_pos hk] }
end
end approx
section eapprox
/-- A sequence of `ennreal`s such that its range is the set of non-negative rational numbers. -/
def ennreal_rat_embed (n : ℕ) : ennreal :=
nnreal.of_real ((encodable.decode ℚ n).get_or_else (0 : ℚ))
lemma ennreal_rat_embed_encode (q : ℚ) :
ennreal_rat_embed (encodable.encode q) = nnreal.of_real q :=
by rw [ennreal_rat_embed, encodable.encodek]; refl
def eapprox : (α → ennreal) → ℕ → α →ₛ ennreal :=
approx ennreal_rat_embed
lemma monotone_eapprox (f : α → ennreal) : monotone (eapprox f) :=
monotone_approx _ f
lemma supr_eapprox_apply (f : α → ennreal) (hf : _root_.measurable f) (a : α) :
(⨆n, (eapprox f n : α →ₛ ennreal) a) = f a :=
begin
rw [eapprox, supr_approx_apply ennreal_rat_embed f a hf rfl],
refine le_antisymm (supr_le $ assume i, supr_le $ assume hi, hi) (le_of_not_gt _),
assume h,
rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨q, hq, lt_q, q_lt⟩,
have : (nnreal.of_real q : ennreal) ≤
(⨆ (k : ℕ) (h : ennreal_rat_embed k ≤ f a), ennreal_rat_embed k),
{ refine le_supr_of_le (encodable.encode q) _,
rw [ennreal_rat_embed_encode q],
refine le_supr_of_le (le_of_lt q_lt) _,
exact le_refl _ },
exact lt_irrefl _ (lt_of_le_of_lt this lt_q)
end
lemma eapprox_comp [measurable_space γ] {f : γ → ennreal} {g : α → γ} {n : ℕ}
(hf : _root_.measurable f) (hg : _root_.measurable g) :
(eapprox (f ∘ g) n : α → ennreal) = (eapprox f n : γ →ₛ ennreal) ∘ g :=
funext $ assume a, approx_comp a hf hg
end eapprox
end measurable
section measure
variables [measure_space α]
lemma volume_bUnion_preimage (s : finset β) (f : α →ₛ β) :
volume (⋃b ∈ s, f ⁻¹' {b}) = s.sum (λb, volume (f ⁻¹' {b})) :=
begin
/- Taking advantage of the fact that `f ⁻¹' {b}` are disjoint for `b ∈ s`. -/
rw [volume_bUnion_finset],
{ simp only [pairwise_on, (on), finset.mem_coe, ne.def],
rintros _ _ _ _ ne _ ⟨h₁, h₂⟩,
simp only [mem_singleton_iff, mem_preimage] at h₁ h₂,
rw [← h₁, h₂] at ne,
exact ne rfl },
exact assume a ha, preimage_measurable _ _
end
/-- Integral of a simple function whose codomain is `ennreal`. -/
def integral (f : α →ₛ ennreal) : ennreal :=
f.range.sum (λ x, x * volume (f ⁻¹' {x}))
/-- Calculate the integral of `(g ∘ f)`, where `g : β → ennreal` and `f : α →ₛ β`. -/
lemma map_integral (g : β → ennreal) (f : α →ₛ β) :
(f.map g).integral = f.range.sum (λ x, g x * volume (f ⁻¹' {x})) :=
begin
simp only [integral, range_map],
refine finset.sum_image' _ (assume b hb, _),
rcases mem_range.1 hb with ⟨a, rfl⟩,
rw [map_preimage_singleton, volume_bUnion_preimage, finset.mul_sum],
refine finset.sum_congr _ _,
{ congr },
{ assume x, simp only [finset.mem_filter], rintro ⟨_, h⟩, rw h }
end
lemma zero_integral : (0 : α →ₛ ennreal).integral = 0 :=
begin
refine (finset.sum_eq_zero_iff_of_nonneg $ assume _ _, zero_le _).2 _,
assume r hr, rcases mem_range.1 hr with ⟨a, rfl⟩,
exact zero_mul _
end
lemma add_integral (f g : α →ₛ ennreal) : (f + g).integral = f.integral + g.integral :=
calc (f + g).integral =
(pair f g).range.sum (λx, x.1 * volume (pair f g ⁻¹' {x}) + x.2 * volume (pair f g ⁻¹' {x})) :
by rw [add_eq_map₂, map_integral]; exact finset.sum_congr rfl (assume a ha, add_mul _ _ _)
... = (pair f g).range.sum (λx, x.1 * volume (pair f g ⁻¹' {x})) +
(pair f g).range.sum (λx, x.2 * volume (pair f g ⁻¹' {x})) : by rw [finset.sum_add_distrib]
... = ((pair f g).map prod.fst).integral + ((pair f g).map prod.snd).integral :
by rw [map_integral, map_integral]
... = integral f + integral g : rfl
lemma const_mul_integral (f : α →ₛ ennreal) (x : ennreal) :
(const α x * f).integral = x * f.integral :=
calc (f.map (λa, x * a)).integral = f.range.sum (λr, x * r * volume (f ⁻¹' {r})) :
by rw [map_integral]
... = f.range.sum (λr, x * (r * volume (f ⁻¹' {r}))) :
finset.sum_congr rfl (assume a ha, mul_assoc _ _ _)
... = x * f.integral :
finset.mul_sum.symm
lemma mem_restrict_range [has_zero β] {r : β} {s : set α} {f : α →ₛ β} (hs : is_measurable s) :
r ∈ (restrict f s).range ↔ (r = 0 ∧ s ≠ univ) ∨ (∃a∈s, f a = r) :=
begin
simp only [mem_range, restrict_apply, hs],
split,
{ rintros ⟨a, ha⟩,
split_ifs at ha,
{ exact or.inr ⟨a, h, ha⟩ },
{ exact or.inl ⟨ha.symm, assume eq, h $ eq.symm ▸ trivial⟩ } },
{ rintros (⟨rfl, h⟩ | ⟨a, ha, rfl⟩),
{ have : ¬ ∀a, a ∈ s := assume this, h $ eq_univ_of_forall this,
rcases not_forall.1 this with ⟨a, ha⟩,
refine ⟨a, _⟩,
rw [if_neg ha] },
{ refine ⟨a, _⟩,
rw [if_pos ha] } }
end
lemma restrict_preimage' {r : ennreal} {s : set α}
(f : α →ₛ ennreal) (hs : is_measurable s) (hr : r ≠ 0) :
(restrict f s) ⁻¹' {r} = (f ⁻¹' {r} ∩ s) :=
begin
ext a,
by_cases a ∈ s; simp [hs, h, hr.symm]
end
lemma restrict_integral (f : α →ₛ ennreal) (s : set α) (hs : is_measurable s) :
(restrict f s).integral = f.range.sum (λr, r * volume (f ⁻¹' {r} ∩ s)) :=
begin
refine finset.sum_bij_ne_zero (λr _ _, r) _ _ _ _,
{ assume r hr,
rcases (mem_restrict_range hs).1 hr with ⟨rfl, h⟩ | ⟨a, ha, rfl⟩,
{ simp },
{ assume _, exact mem_range.2 ⟨a, rfl⟩ } },
{ assume a b _ _ _ _ h, exact h },
{ assume r hr,
by_cases r0 : r = 0, { simp [r0] },
assume h0,
rcases mem_range.1 hr with ⟨a, rfl⟩,
have : f ⁻¹' {f a} ∩ s ≠ ∅,
{ assume h, simpa [h] using h0 },
rcases ne_empty_iff_nonempty.1 this with ⟨a', eq', ha'⟩,
refine ⟨_, (mem_restrict_range hs).2 (or.inr ⟨a', ha', _⟩), _, rfl⟩,
{ simpa using eq' },
{ rwa [restrict_preimage' _ hs r0] } },
{ assume r hr ne,
by_cases r = 0, { simp [h] },
rw [restrict_preimage' _ hs h] }
end
lemma restrict_const_integral (c : ennreal) (s : set α) (hs : is_measurable s) :
(restrict (const α c) s).integral = c * volume s :=
have (@const α ennreal _ c) ⁻¹' {c} = univ,
begin
refine eq_univ_of_forall (assume a, _),
simp,
end,
calc (restrict (const α c) s).integral = c * volume ((const α c) ⁻¹' {c} ∩ s) :
begin
rw [restrict_integral (const α c) s hs],
refine finset.sum_eq_single c _ _,
{ assume r hr, rcases mem_range.1 hr with ⟨a, rfl⟩, contradiction },
{ by_cases nonempty α,
{ assume ne,
rcases h with ⟨a⟩,
exfalso,
exact ne (mem_range.2 ⟨a, rfl⟩) },
{ assume empty,
have : (@const α ennreal _ c) ⁻¹' {c} ∩ s = ∅,
{ ext a, exfalso, exact h ⟨a⟩ },
simp only [this, volume_empty, mul_zero] } }
end
... = c * volume s : by rw [this, univ_inter]
lemma integral_sup_le (f g : α →ₛ ennreal) : f.integral ⊔ g.integral ≤ (f ⊔ g).integral :=
calc f.integral ⊔ g.integral =
((pair f g).map prod.fst).integral ⊔ ((pair f g).map prod.snd).integral : rfl
... ≤ (pair f g).range.sum (λx, (x.1 ⊔ x.2) * volume (pair f g ⁻¹' {x})) :
begin
rw [map_integral, map_integral],
refine sup_le _ _;
refine finset.sum_le_sum (λ a _, canonically_ordered_semiring.mul_le_mul _ (le_refl _)),
exact le_sup_left,
exact le_sup_right
end
... = (f ⊔ g).integral : by rw [sup_eq_map₂, map_integral]
lemma integral_le_integral (f g : α →ₛ ennreal) (h : f ≤ g) : f.integral ≤ g.integral :=
calc f.integral ≤ f.integral ⊔ g.integral : le_sup_left
... ≤ (f ⊔ g).integral : integral_sup_le _ _
... = g.integral : by rw [sup_of_le_right h]
lemma integral_congr (f g : α →ₛ ennreal) (h : ∀ₘ a, f a = g a) :
f.integral = g.integral :=
show ((pair f g).map prod.fst).integral = ((pair f g).map prod.snd).integral, from
begin
rw [map_integral, map_integral],
refine finset.sum_congr rfl (assume p hp, _),
rcases mem_range.1 hp with ⟨a, rfl⟩,
by_cases eq : f a = g a,
{ dsimp only [pair_apply], rw eq },
{ have : volume ((pair f g) ⁻¹' {(f a, g a)}) = 0,
{ refine volume_mono_null (assume a' ha', _) h,
simp at ha',
show f a' ≠ g a',
rwa [ha'.1, ha'.2] },
simp [this] }
end
lemma integral_map {β} [measure_space β] (f : α →ₛ ennreal) (g : β →ₛ ennreal)(m : α → β)
(eq : ∀a:α, f a = g (m a)) (h : ∀s:set β, is_measurable s → volume s = volume (m ⁻¹' s)) :
f.integral = g.integral :=
have f_eq : (f : α → ennreal) = g ∘ m := funext eq,
have vol_f : ∀r, volume (f ⁻¹' {r}) = volume (g ⁻¹' {r}),
by { assume r, rw [h, f_eq, preimage_comp], exact measurable_sn _ _ },
begin
simp [integral, vol_f],
refine finset.sum_subset _ _,
{ simp [finset.subset_iff, f_eq],
rintros r a rfl, exact ⟨_, rfl⟩ },
{ assume r hrg hrf,
rw [simple_func.mem_range, not_exists] at hrf,
have : f ⁻¹' {r} = ∅ := set.eq_empty_of_subset_empty (assume a, by simpa using hrf a),
simp [(vol_f _).symm, this] }
end
end measure
section fin_vol_supp
variables [measure_space α] [has_zero β] [has_zero γ]
open finset ennreal
protected def fin_vol_supp (f : α →ₛ β) : Prop := ∀b ≠ 0, volume (f ⁻¹' {b}) < ⊤
lemma fin_vol_supp_map {f : α →ₛ β} {g : β → γ} (hf : f.fin_vol_supp) (hg : g 0 = 0) :
(f.map g).fin_vol_supp :=
begin
assume c hc,
simp only [map_preimage, volume_bUnion_preimage],
apply sum_lt_top,
intro b,
simp only [mem_filter, mem_range, mem_singleton_iff, and_imp, exists_imp_distrib],
intros a fab gbc,
apply hf,
intro b0,
rw [b0, hg] at gbc, rw gbc at hc,
contradiction
end
lemma fin_vol_supp_of_fin_vol_supp_map (f : α →ₛ β) {g : β → γ} (h : (f.map g).fin_vol_supp)
(hg : ∀b, g b = 0 → b = 0) : f.fin_vol_supp :=
begin
assume b hb,
by_cases b_mem : b ∈ f.range,
{ have gb0 : g b ≠ 0, { assume h, have := hg b h, contradiction },
have : f ⁻¹' {b} ⊆ (f.map g) ⁻¹' {g b},
rw [coe_map, @preimage_comp _ _ _ f g, preimage_subset_preimage_iff],
{ simp only [set.mem_preimage, set.mem_singleton, set.singleton_subset_iff] },
{ rw singleton_subset_iff, rw mem_range at b_mem, exact b_mem },
exact lt_of_le_of_lt (volume_mono this) (h (g b) gb0) },
{ rw ← preimage_eq_empty_iff at b_mem,
rw [b_mem, volume_empty],
exact with_top.zero_lt_top }
end
lemma fin_vol_supp_pair {f : α →ₛ β} {g : α →ₛ γ} (hf : f.fin_vol_supp) (hg : g.fin_vol_supp) :
(pair f g).fin_vol_supp :=
begin
rintros ⟨b, c⟩ hbc,
rw [pair_preimage_singleton],
rw [ne.def, prod.eq_iff_fst_eq_snd_eq, not_and_distrib] at hbc,
refine or.elim hbc (λ h : b≠0, _) (λ h : c≠0, _),
{ calc _ ≤ volume (f ⁻¹' {b}) : volume_mono (set.inter_subset_left _ _)
... < ⊤ : hf _ h },
{ calc _ ≤ volume (g ⁻¹' {c}) : volume_mono (set.inter_subset_right _ _)
... < ⊤ : hg _ h },
end
lemma integral_lt_top_of_fin_vol_supp {f : α →ₛ ennreal} (h₁ : ∀ₘ a, f a < ⊤) (h₂ : f.fin_vol_supp) :
integral f < ⊤ :=
begin
rw integral, apply sum_lt_top,
intros a ha,
have : f ⁻¹' {⊤} = -{a : α | f a < ⊤}, { ext, simp },
have vol_top : volume (f ⁻¹' {⊤}) = 0, { rw [this, volume, ← measure.mem_a_e_iff], exact h₁ },
by_cases hat : a = ⊤,
{ rw [hat, vol_top, mul_zero], exact with_top.zero_lt_top },
{ by_cases haz : a = 0,
{ rw [haz, zero_mul], exact with_top.zero_lt_top },
apply mul_lt_top,
{ rw ennreal.lt_top_iff_ne_top, exact hat },
apply h₂,
exact haz }
end
lemma fin_vol_supp_of_integral_lt_top {f : α →ₛ ennreal} (h : integral f < ⊤) : f.fin_vol_supp :=
begin
assume b hb,
rw [integral, sum_lt_top_iff] at h,
by_cases b_mem : b ∈ f.range,
{ rw ennreal.lt_top_iff_ne_top,
have h : ¬ _ = ⊤ := ennreal.lt_top_iff_ne_top.1 (h b b_mem),
simp only [mul_eq_top, not_or_distrib, not_and_distrib] at h,
rcases h with ⟨h, h'⟩,
refine or.elim h (λh, by contradiction) (λh, h) },
{ rw ← preimage_eq_empty_iff at b_mem,
rw [b_mem, volume_empty],
exact with_top.zero_lt_top }
end
/-- A technical lemma dealing with the definition of `integrable` in `l1_space.lean`. -/
lemma integral_map_coe_lt_top {f : α →ₛ β} {g : β → nnreal} (h : f.fin_vol_supp) (hg : g 0 = 0) :
integral (f.map ((coe : nnreal → ennreal) ∘ g)) < ⊤ :=
integral_lt_top_of_fin_vol_supp
(by { filter_upwards[], assume a, simp only [mem_set_of_eq, map_apply], exact ennreal.coe_lt_top})
(by { apply fin_vol_supp_map h, simp only [hg, function.comp_app, ennreal.coe_zero] })
end fin_vol_supp
end simple_func
section lintegral
open simple_func
variable [measure_space α]
/-- The lower Lebesgue integral -/
def lintegral (f : α → ennreal) : ennreal :=
⨆ (s : α →ₛ ennreal) (hf : f ≥ s), s.integral
notation `∫⁻` binders `, ` r:(scoped f, lintegral f) := r
theorem simple_func.lintegral_eq_integral (f : α →ₛ ennreal) : (∫⁻ a, f a) = f.integral :=
le_antisymm
(supr_le $ assume s, supr_le $ assume hs, integral_le_integral _ _ hs)
(le_supr_of_le f $ le_supr_of_le (le_refl f) $ le_refl _)
lemma lintegral_le_lintegral (f g : α → ennreal) (h : f ≤ g) : (∫⁻ a, f a) ≤ (∫⁻ a, g a) :=
supr_le_supr $ assume s, supr_le $ assume hs, le_supr_of_le (le_trans hs h) (le_refl _)
lemma lintegral_eq_nnreal (f : α → ennreal) :
(∫⁻ a, f a) =
(⨆ (s : α →ₛ nnreal) (hf : f ≥ s.map (coe : nnreal → ennreal)), (s.map (coe : nnreal → ennreal)).integral) :=
begin
let c : nnreal → ennreal := coe,
refine le_antisymm
(supr_le $ assume s, supr_le $ assume hs, _)
(supr_le $ assume s, supr_le $ assume hs, le_supr_of_le (s.map c) $ le_supr _ hs),
by_cases ∀ₘ a, s a ≠ ⊤,
{ have : f ≥ (s.map ennreal.to_nnreal).map c :=
le_trans (assume a, ennreal.coe_to_nnreal_le_self) hs,
refine le_supr_of_le (s.map ennreal.to_nnreal) (le_supr_of_le this (le_of_eq $ integral_congr _ _ _)),
exact filter.mem_sets_of_superset h (assume a ha, (ennreal.coe_to_nnreal ha).symm) },
{ have h_vol_s : volume {a : α | s a = ⊤} ≠ 0,
{ simp [measure_theory.all_ae_iff, set.compl_set_of] at h, assumption },
let n : ℕ → (α →ₛ nnreal) := λn, restrict (const α (n : nnreal)) (s ⁻¹' {⊤}),
have n_le_s : ∀i, (n i).map c ≤ s,
{ assume i a,
dsimp [n, c],
rw [restrict_apply _ (s.preimage_measurable _)],
split_ifs with ha,
{ simp at ha, exact ha.symm ▸ le_top },
{ exact zero_le _ } },
have approx_s : ∀ (i : ℕ), ↑i * volume {a : α | s a = ⊤} ≤ integral (map c (n i)),
{ assume i,
have : {a : α | s a = ⊤} = s ⁻¹' {⊤}, { ext a, simp },
rw [this, ← restrict_const_integral _ _ (s.preimage_measurable _)],
{ refine integral_le_integral _ _ (assume a, le_of_eq _),
simp [n, c, restrict_apply, s.preimage_measurable],
split_ifs; simp [ennreal.coe_nat] },
},
calc s.integral ≤ ⊤ : le_top
... = (⨆i:ℕ, (i : ennreal) * volume {a | s a = ⊤}) :
by rw [← ennreal.supr_mul, ennreal.supr_coe_nat, ennreal.top_mul, if_neg h_vol_s]
... ≤ (⨆i, ((n i).map c).integral) : supr_le_supr approx_s
... ≤ ⨆ (s : α →ₛ nnreal) (hf : f ≥ s.map c), (s.map c).integral :
have ∀i, ((n i).map c : α → ennreal) ≤ f := assume i, le_trans (n_le_s i) hs,
(supr_le $ assume i, le_supr_of_le (n i) (le_supr (λh, ((n i).map c).integral) (this i))) }
end
/-- Monotone convergence theorem -- somtimes called Beppo-Levi convergence.
See `lintegral_supr_directed` for a more general form. -/
theorem lintegral_supr
{f : ℕ → α → ennreal} (hf : ∀n, measurable (f n)) (h_mono : monotone f) :
(∫⁻ a, ⨆n, f n a) = (⨆n, ∫⁻ a, f n a) :=
let c : nnreal → ennreal := coe in
let F (a:α) := ⨆n, f n a in
have hF : measurable F := measurable.supr hf,
show (∫⁻ a, F a) = (⨆n, ∫⁻ a, f n a),
begin
refine le_antisymm _ _,
{ rw [lintegral_eq_nnreal],
refine supr_le (assume s, supr_le (assume hsf, _)),
refine ennreal.le_of_forall_lt_one_mul_lt (assume a ha, _),
rcases ennreal.lt_iff_exists_coe.1 ha with ⟨r, rfl, ha⟩,
have ha : r < 1 := ennreal.coe_lt_coe.1 ha,
let rs := s.map (λa, r * a),
have eq_rs : (const α r : α →ₛ ennreal) * map c s = rs.map c,
{ ext1 a, exact ennreal.coe_mul.symm },
have eq : ∀p, (rs.map c) ⁻¹' {p} = (⋃n, (rs.map c) ⁻¹' {p} ∩ {a | p ≤ f n a}),
{ assume p,
rw [← inter_Union, ← inter_univ ((map c rs) ⁻¹' {p})] {occs := occurrences.pos [1]},
refine set.ext (assume x, and_congr_right $ assume hx, (true_iff _).2 _),
by_cases p_eq : p = 0, { simp [p_eq] },
simp at hx, subst hx,
have : r * s x ≠ 0, { rwa [(≠), ← ennreal.coe_eq_zero] },
have : s x ≠ 0, { refine mt _ this, assume h, rw [h, mul_zero] },
have : (rs.map c) x < ⨆ (n : ℕ), f n x,
{ refine lt_of_lt_of_le (ennreal.coe_lt_coe.2 (_)) (hsf x),
suffices : r * s x < 1 * s x, simpa [rs],
exact mul_lt_mul_of_pos_right ha (zero_lt_iff_ne_zero.2 this) },
rcases lt_supr_iff.1 this with ⟨i, hi⟩,
exact mem_Union.2 ⟨i, le_of_lt hi⟩ },
have mono : ∀r:ennreal, monotone (λn, (rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a}),
{ assume r i j h,
refine inter_subset_inter (subset.refl _) _,
assume x hx, exact le_trans hx (h_mono h x) },
have h_meas : ∀n, is_measurable {a : α | ⇑(map c rs) a ≤ f n a} :=
assume n, is_measurable_le (simple_func.measurable _) (hf n),
calc (r:ennreal) * integral (s.map c) = (rs.map c).range.sum (λr, r * volume ((rs.map c) ⁻¹' {r})) :
by rw [← const_mul_integral, integral, eq_rs]
... ≤ (rs.map c).range.sum (λr, r * volume (⋃n, (rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a})) :
le_of_eq (finset.sum_congr rfl $ assume x hx, by rw ← eq)
... ≤ (rs.map c).range.sum (λr, (⨆n, r * volume ((rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a}))) :
le_of_eq (finset.sum_congr rfl $ assume x hx,
begin
rw [volume, measure_Union_eq_supr_nat _ (mono x), ennreal.mul_supr],
{ assume i,
refine is_measurable.inter ((rs.map c).preimage_measurable _) _,
refine (hf i).preimage _,
exact is_measurable_of_is_closed (is_closed_ge' _) }
end)
... ≤ ⨆n, (rs.map c).range.sum (λr, r * volume ((rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a})) :
begin
refine le_of_eq _,
rw [ennreal.finset_sum_supr_nat],
assume p i j h,
exact canonically_ordered_semiring.mul_le_mul (le_refl _) (volume_mono $ mono p h)
end
... ≤ (⨆n:ℕ, ((rs.map c).restrict {a | (rs.map c) a ≤ f n a}).integral) :
begin
refine supr_le_supr (assume n, _),
rw [restrict_integral _ _ (h_meas n)],
{ refine le_of_eq (finset.sum_congr rfl $ assume r hr, _),
congr' 2,
ext a,
refine and_congr_right _,
simp {contextual := tt} }
end
... ≤ (⨆n, ∫⁻ a, f n a) :
begin
refine supr_le_supr (assume n, _),
rw [← simple_func.lintegral_eq_integral],
refine lintegral_le_lintegral _ _ (assume a, _),
dsimp,
rw [restrict_apply],
split_ifs; simp, simpa using h,
exact h_meas n
end },
{ exact supr_le (assume n, lintegral_le_lintegral _ _ $ assume a, le_supr _ n) }
end
lemma lintegral_eq_supr_eapprox_integral {f : α → ennreal} (hf : measurable f) :
(∫⁻ a, f a) = (⨆n, (eapprox f n).integral) :=
calc (∫⁻ a, f a) = (∫⁻ a, ⨆n, (eapprox f n : α → ennreal) a) :
by congr; ext a; rw [supr_eapprox_apply f hf]
... = (⨆n, ∫⁻ a, (eapprox f n : α → ennreal) a) :
begin
rw [lintegral_supr],
{ assume n, exact (eapprox f n).measurable },
{ assume i j h, exact (monotone_eapprox f h) }
end
... = (⨆n, (eapprox f n).integral) : by congr; ext n; rw [(eapprox f n).lintegral_eq_integral]
lemma lintegral_add {f g : α → ennreal} (hf : measurable f) (hg : measurable g) :
(∫⁻ a, f a + g a) = (∫⁻ a, f a) + (∫⁻ a, g a) :=
calc (∫⁻ a, f a + g a) =
(∫⁻ a, (⨆n, (eapprox f n : α → ennreal) a) + (⨆n, (eapprox g n : α → ennreal) a)) :
by congr; funext a; rw [supr_eapprox_apply f hf, supr_eapprox_apply g hg]
... = (∫⁻ a, (⨆n, (eapprox f n + eapprox g n : α → ennreal) a)) :
begin
congr, funext a,
rw [ennreal.supr_add_supr_of_monotone], { refl },
{ assume i j h, exact monotone_eapprox _ h a },
{ assume i j h, exact monotone_eapprox _ h a },
end
... = (⨆n, (eapprox f n).integral + (eapprox g n).integral) :
begin
rw [lintegral_supr],
{ congr, funext n, rw [← simple_func.add_integral, ← simple_func.lintegral_eq_integral], refl },
{ assume n, exact measurable.add (eapprox f n).measurable (eapprox g n).measurable },
{ assume i j h a, exact add_le_add' (monotone_eapprox _ h _) (monotone_eapprox _ h _) }
end
... = (⨆n, (eapprox f n).integral) + (⨆n, (eapprox g n).integral) :
by refine (ennreal.supr_add_supr_of_monotone _ _).symm;
{ assume i j h, exact simple_func.integral_le_integral _ _ (monotone_eapprox _ h) }
... = (∫⁻ a, f a) + (∫⁻ a, g a) :
by rw [lintegral_eq_supr_eapprox_integral hf, lintegral_eq_supr_eapprox_integral hg]
@[simp] lemma lintegral_zero : (∫⁻ a:α, 0) = 0 :=
show (∫⁻ a:α, (0 : α →ₛ ennreal) a) = 0, by rw [simple_func.lintegral_eq_integral, zero_integral]
lemma lintegral_finset_sum (s : finset β) {f : β → α → ennreal} (hf : ∀b, measurable (f b)) :
(∫⁻ a, s.sum (λb, f b a)) = s.sum (λb, ∫⁻ a, f b a) :=
begin
refine finset.induction_on s _ _,
{ simp },
{ assume a s has ih,
simp [has],
rw [lintegral_add (hf _) (measurable_finset_sum s hf), ih] }
end
lemma lintegral_const_mul (r : ennreal) {f : α → ennreal} (hf : measurable f) :
(∫⁻ a, r * f a) = r * (∫⁻ a, f a) :=
calc (∫⁻ a, r * f a) = (∫⁻ a, (⨆n, (const α r * eapprox f n) a)) :
by congr; funext a; rw [← supr_eapprox_apply f hf, ennreal.mul_supr]; refl
... = (⨆n, r * (eapprox f n).integral) :
begin
rw [lintegral_supr],
{ congr, funext n, rw [← simple_func.const_mul_integral, ← simple_func.lintegral_eq_integral] },
{ assume n, exact simple_func.measurable _ },
{ assume i j h a, exact canonically_ordered_semiring.mul_le_mul (le_refl _)
(monotone_eapprox _ h _) }
end
... = r * (∫⁻ a, f a) : by rw [← ennreal.mul_supr, lintegral_eq_supr_eapprox_integral hf]
lemma lintegral_const_mul_le (r : ennreal) (f : α → ennreal) : r * (∫⁻ a, f a) ≤ (∫⁻ a, r * f a) :=
begin
rw [lintegral, ennreal.mul_supr],
refine supr_le (λs, _),
rw [ennreal.mul_supr],
simp only [supr_le_iff, ge_iff_le],
assume hs,
rw ← simple_func.const_mul_integral,
refine le_supr_of_le (const α r * s) (le_supr_of_le (λx, _) (le_refl _)),
exact canonically_ordered_semiring.mul_le_mul (le_refl _) (hs x)
end
lemma lintegral_const_mul' (r : ennreal) (f : α → ennreal) (hr : r ≠ ⊤) :
(∫⁻ a, r * f a) = r * (∫⁻ a, f a) :=
begin
by_cases h : r = 0,
{ simp [h] },
apply le_antisymm _ (lintegral_const_mul_le r f),
have rinv : r * r⁻¹ = 1 := ennreal.mul_inv_cancel h hr,
have rinv' : r ⁻¹ * r = 1, by { rw mul_comm, exact rinv },
have := lintegral_const_mul_le (r⁻¹) (λx, r * f x),
simp [(mul_assoc _ _ _).symm, rinv'] at this,
simpa [(mul_assoc _ _ _).symm, rinv]
using canonically_ordered_semiring.mul_le_mul (le_refl r) this
end
lemma lintegral_supr_const (r : ennreal) {s : set α} (hs : is_measurable s) :
(∫⁻ a, ⨆(h : a ∈ s), r) = r * volume s :=
begin
rw [← restrict_const_integral r s hs, ← (restrict (const α r) s).lintegral_eq_integral],
congr; ext a; by_cases a ∈ s; simp [h, hs]
end
lemma lintegral_le_lintegral_ae {f g : α → ennreal} (h : ∀ₘ a, f a ≤ g a) :
(∫⁻ a, f a) ≤ (∫⁻ a, g a) :=
begin
rcases exists_is_measurable_superset_of_measure_eq_zero h with ⟨t, hts, ht, ht0⟩,
have : - t ∈ (@measure_space.μ α _).a_e,
{ rw [measure.mem_a_e_iff, lattice.neg_neg, ht0] },
refine (supr_le $ assume s, supr_le $ assume hfs,
le_supr_of_le (s.restrict (- t)) $ le_supr_of_le _ _),
{ assume a,
by_cases a ∈ t;
simp [h, simple_func.restrict_apply, ht.compl],
exact le_trans (hfs a) (by_contradiction $ assume hnfg, h (hts hnfg)) },
{ refine le_of_eq (s.integral_congr _ _),
filter_upwards [this],
refine assume a hnt, _,
by_cases hat : a ∈ t; simp [hat, ht.compl],
exact (hnt hat).elim }
end
lemma lintegral_congr_ae {f g : α → ennreal} (h : ∀ₘ a, f a = g a) :
(∫⁻ a, f a) = (∫⁻ a, g a) :=
le_antisymm
(lintegral_le_lintegral_ae $ by filter_upwards [h] assume a h, le_of_eq h)
(lintegral_le_lintegral_ae $ by filter_upwards [h] assume a h, le_of_eq h.symm)
-- TODO: Need a better way of rewriting inside of a integral
lemma lintegral_rw₁ {f f' : α → β} (h : ∀ₘ a, f a = f' a) (g : β → ennreal) :
(∫⁻ a, g (f a)) = (∫⁻ a, g (f' a)) :=
begin
apply lintegral_congr_ae,
filter_upwards [h],
assume a,
simp only [mem_set_of_eq],
assume h,
rw h
end
-- TODO: Need a better way of rewriting inside of a integral
lemma lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : ∀ₘ a, f₁ a = f₁' a)
(h₂ : ∀ₘ a, f₂ a = f₂' a) (g : β → γ → ennreal) :
(∫⁻ a, g (f₁ a) (f₂ a)) = (∫⁻ a, g (f₁' a) (f₂' a)) :=
begin
apply lintegral_congr_ae,
filter_upwards [h₁, h₂],
assume a,
simp only [mem_set_of_eq],
repeat { assume h, rw h }
end
lemma simple_func.lintegral_map (f : α →ₛ β) (g : β → ennreal) :
(∫⁻ a, (f.map g) a) = ∫⁻ a, g (f a) :=
by { apply lintegral_congr_ae, filter_upwards [], assume a, exact map_apply _ _ _ }
lemma lintegral_eq_zero_iff {f : α → ennreal} (hf : measurable f) :
lintegral f = 0 ↔ (∀ₘ a, f a = 0) :=
begin
refine iff.intro (assume h, _) (assume h, _),
{ have : ∀n:ℕ, ∀ₘ a, f a < n⁻¹,
{ assume n,
have : is_measurable {a : α | f a ≥ n⁻¹ },
{ exact hf _ (is_measurable_of_is_closed $ is_closed_ge' _) },
have : (n : ennreal)⁻¹ * volume {a | f a ≥ n⁻¹ } = 0,
{ rw [← simple_func.restrict_const_integral _ _ this, ← le_zero_iff_eq,
← simple_func.lintegral_eq_integral],
refine le_trans (lintegral_le_lintegral _ _ _) (le_of_eq h),
assume a, by_cases h : (n : ennreal)⁻¹ ≤ f a; simp [h, (≥), this] },
rw [ennreal.mul_eq_zero, ennreal.inv_eq_zero] at this,
simpa [ennreal.nat_ne_top, all_ae_iff] using this },
filter_upwards [all_ae_all_iff.2 this],
dsimp,
assume a ha,
by_contradiction h,
rcases ennreal.exists_inv_nat_lt h with ⟨n, hn⟩,
exact (lt_irrefl _ $ lt_trans hn $ ha n).elim },
{ calc lintegral f = lintegral (λa:α, 0) : lintegral_congr_ae h
... = 0 : lintegral_zero }
end
/-- Weaker version of the monotone convergence theorem-/
lemma lintegral_supr_ae {f : ℕ → α → ennreal} (hf : ∀n, measurable (f n))
(h_mono : ∀n, ∀ₘ a, f n a ≤ f n.succ a) :
(∫⁻ a, ⨆n, f n a) = (⨆n, ∫⁻ a, f n a) :=
let ⟨s, hs⟩ := exists_is_measurable_superset_of_measure_eq_zero
(all_ae_iff.1 (all_ae_all_iff.2 h_mono)) in
let g := λ n a, if a ∈ s then 0 else f n a in
have g_eq_f : ∀ₘ a, ∀n, g n a = f n a,
begin
have := hs.2.2, rw [← compl_compl s] at this,
filter_upwards [(measure.mem_a_e_iff (-s)).2 this] assume a ha n, if_neg ha
end,
calc
(∫⁻ a, ⨆n, f n a) = (∫⁻ a, ⨆n, g n a) :
lintegral_congr_ae
begin
filter_upwards [g_eq_f], assume a ha, congr, funext, exact (ha n).symm
end
... = ⨆n, (∫⁻ a, g n a) :
lintegral_supr
(assume n, measurable.if hs.2.1 measurable_const (hf n))
(monotone_of_monotone_nat $ assume n a, classical.by_cases
(assume h : a ∈ s, by simp [g, if_pos h])
(assume h : a ∉ s,
begin
simp only [g, if_neg h], have := hs.1, rw subset_def at this, have := mt (this a) h,
simp only [not_not, mem_set_of_eq] at this, exact this n
end))
... = ⨆n, (∫⁻ a, f n a) :
begin
congr, funext, apply lintegral_congr_ae, filter_upwards [g_eq_f] assume a ha, ha n
end
lemma lintegral_sub {f g : α → ennreal} (hf : measurable f) (hg : measurable g)
(hg_fin : lintegral g < ⊤) (h_le : ∀ₘ a, g a ≤ f a) :
(∫⁻ a, f a - g a) = (∫⁻ a, f a) - (∫⁻ a, g a) :=
begin
rw [← ennreal.add_right_inj hg_fin,
ennreal.sub_add_cancel_of_le (lintegral_le_lintegral_ae h_le),
← lintegral_add (ennreal.measurable.sub hf hg) hg],
show (∫⁻ (a : α), f a - g a + g a) = ∫⁻ (a : α), f a,
apply lintegral_congr_ae, filter_upwards [h_le], simp only [add_comm, mem_set_of_eq],
assume a ha, exact ennreal.add_sub_cancel_of_le ha
end
/-- Monotone convergence theorem for nonincreasing sequences of functions -/
lemma lintegral_infi_ae
{f : ℕ → α → ennreal} (h_meas : ∀n, measurable (f n))
(h_mono : ∀n:ℕ, ∀ₘ a, f n.succ a ≤ f n a) (h_fin : lintegral (f 0) < ⊤) :
(∫⁻ a, ⨅n, f n a) = (⨅n, ∫⁻ a, f n a) :=
have fn_le_f0 : (∫⁻ a, ⨅n, f n a) ≤ lintegral (f 0), from
lintegral_le_lintegral _ _ (assume a, infi_le_of_le 0 (le_refl _)),
have fn_le_f0' : (⨅n, ∫⁻ a, f n a) ≤ lintegral (f 0), from infi_le_of_le 0 (le_refl _),
(ennreal.sub_left_inj h_fin fn_le_f0 fn_le_f0').1 $
show lintegral (f 0) - (∫⁻ a, ⨅n, f n a) = lintegral (f 0) - (⨅n, ∫⁻ a, f n a), from
calc
lintegral (f 0) - (∫⁻ a, ⨅n, f n a) = ∫⁻ a, f 0 a - ⨅n, f n a :
(lintegral_sub (h_meas 0) (measurable.infi h_meas)
(calc
(∫⁻ a, ⨅n, f n a) ≤ lintegral (f 0) : lintegral_le_lintegral _ _
(assume a, infi_le _ _)
... < ⊤ : h_fin )
(all_ae_of_all $ assume a, infi_le _ _)).symm
... = ∫⁻ a, ⨆n, f 0 a - f n a : congr rfl (funext (assume a, ennreal.sub_infi))
... = ⨆n, ∫⁻ a, f 0 a - f n a :
lintegral_supr_ae
(assume n, ennreal.measurable.sub (h_meas 0) (h_meas n))
(assume n, by
filter_upwards [h_mono n] assume a ha, ennreal.sub_le_sub (le_refl _) ha)
... = ⨆n, lintegral (f 0) - ∫⁻ a, f n a :
have h_mono : ∀ₘ a, ∀n:ℕ, f n.succ a ≤ f n a := all_ae_all_iff.2 h_mono,
have h_mono : ∀n, ∀ₘa, f n a ≤ f 0 a := assume n,
begin
filter_upwards [h_mono], simp only [mem_set_of_eq], assume a, assume h, induction n with n ih,
{exact le_refl _}, {exact le_trans (h n) ih}
end,
congr rfl (funext $ assume n, lintegral_sub (h_meas _) (h_meas _)
(calc
(∫⁻ a, f n a) ≤ ∫⁻ a, f 0 a : lintegral_le_lintegral_ae $ h_mono n
... < ⊤ : h_fin)
(h_mono n))
... = lintegral (f 0) - (⨅n, ∫⁻ a, f n a) : ennreal.sub_infi.symm
section priority
-- for some reason the next proof fails without changing the priority of this instance
local attribute [instance, priority 1000] classical.prop_decidable
/-- Known as Fatou's lemma -/
lemma lintegral_liminf_le {f : ℕ → α → ennreal} (h_meas : ∀n, measurable (f n)) :
(∫⁻ a, liminf at_top (λ n, f n a)) ≤ liminf at_top (λ n, lintegral (f n)) :=
calc
(∫⁻ a, liminf at_top (λ n, f n a)) = ∫⁻ a, ⨆n:ℕ, ⨅i≥n, f i a :
congr rfl (funext (assume a, liminf_eq_supr_infi_of_nat))
... = ⨆n:ℕ, ∫⁻ a, ⨅i≥n, f i a :
lintegral_supr
begin
assume n, apply measurable.infi, assume i, by_cases h : i ≥ n,
{convert h_meas i, simp [h]},
{convert measurable_const, simp [h]}
end
begin
assume n m hnm a, simp only [le_infi_iff], assume i hi,
refine infi_le_of_le i (infi_le_of_le (le_trans hnm hi) (le_refl _))
end
... ≤ ⨆n:ℕ, ⨅i≥n, lintegral (f i) :
supr_le_supr $ assume n, le_infi $
assume i, le_infi $ assume hi, lintegral_le_lintegral _ _
$ assume a, infi_le_of_le i $ infi_le_of_le hi $ le_refl _
... = liminf at_top (λ n, lintegral (f n)) : liminf_eq_supr_infi_of_nat.symm
end priority
lemma limsup_lintegral_le {f : ℕ → α → ennreal} {g : α → ennreal}
(hf_meas : ∀ n, measurable (f n)) (h_bound : ∀n, ∀ₘa, f n a ≤ g a) (h_fin : lintegral g < ⊤) :
limsup at_top (λn, lintegral (f n)) ≤ ∫⁻ a, limsup at_top (λn, f n a) :=
calc
limsup at_top (λn, lintegral (f n)) = ⨅n:ℕ, ⨆i≥n, lintegral (f i) :
limsup_eq_infi_supr_of_nat
... ≤ ⨅n:ℕ, ∫⁻ a, ⨆i≥n, f i a :
infi_le_infi $ assume n, supr_le $ assume i, supr_le $ assume hi,
lintegral_le_lintegral _ _ $ assume a, le_supr_of_le i $ le_supr_of_le hi (le_refl _)
... = ∫⁻ a, ⨅n:ℕ, ⨆i≥n, f i a :
(lintegral_infi_ae
(assume n,
@measurable.supr _ _ _ _ _ _ _ _ _ (λ i a, supr (λ (h : i ≥ n), f i a))
(assume i, measurable.supr_Prop (hf_meas i)))
(assume n, all_ae_of_all $ assume a,
begin
simp only [supr_le_iff], assume i hi, refine le_supr_of_le i _,
rw [supr_pos _], exact le_refl _, exact nat.le_of_succ_le hi
end )
(lt_of_le_of_lt
(lintegral_le_lintegral_ae
begin
filter_upwards [all_ae_all_iff.2 h_bound],
simp only [supr_le_iff, mem_set_of_eq],
assume a ha i hi, exact ha i
end )
h_fin)).symm
... = ∫⁻ a, limsup at_top (λn, f n a) :
lintegral_congr_ae $ all_ae_of_all $ assume a, limsup_eq_infi_supr_of_nat.symm
/-- Dominated convergence theorem for nonnegative functions -/
lemma tendsto_lintegral_of_dominated_convergence
{F : ℕ → α → ennreal} {f : α → ennreal} (bound : α → ennreal)
(hF_meas : ∀n, measurable (F n)) (h_bound : ∀n, ∀ₘ a, F n a ≤ bound a)
(h_fin : lintegral bound < ⊤)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, lintegral (F n)) at_top (𝓝 (lintegral f)) :=
begin
have limsup_le_lintegral :=
calc
limsup at_top (λ (n : ℕ), lintegral (F n)) ≤ ∫⁻ (a : α), limsup at_top (λn, F n a) :
limsup_lintegral_le hF_meas h_bound h_fin
... = lintegral f :
lintegral_congr_ae $
by filter_upwards [h_lim] assume a h, limsup_eq_of_tendsto at_top_ne_bot h,
have lintegral_le_liminf :=
calc
lintegral f = ∫⁻ (a : α), liminf at_top (λ (n : ℕ), F n a) :
lintegral_congr_ae $
by filter_upwards [h_lim] assume a h, (liminf_eq_of_tendsto at_top_ne_bot h).symm
... ≤ liminf at_top (λ n, lintegral (F n)) :
lintegral_liminf_le hF_meas,
have liminf_eq_limsup :=
le_antisymm
(liminf_le_limsup (map_ne_bot at_top_ne_bot))
(le_trans limsup_le_lintegral lintegral_le_liminf),
have liminf_eq_lintegral : liminf at_top (λ n, lintegral (F n)) = lintegral f :=
le_antisymm (by convert limsup_le_lintegral) lintegral_le_liminf,
have limsup_eq_lintegral : limsup at_top (λ n, lintegral (F n)) = lintegral f :=
le_antisymm
limsup_le_lintegral
begin convert lintegral_le_liminf, exact liminf_eq_limsup.symm end,
exact tendsto_of_liminf_eq_limsup ⟨liminf_eq_lintegral, limsup_eq_lintegral⟩
end
/-- Dominated convergence theorem for filters with a countable basis -/
lemma tendsto_lintegral_filter_of_dominated_convergence {ι} {l : filter ι}
{F : ι → α → ennreal} {f : α → ennreal} (bound : α → ennreal)
(hl_cb : l.has_countable_basis)
(hF_meas : ∀ᶠ n in l, measurable (F n))
(h_bound : ∀ᶠ n in l, ∀ₘ a, F n a ≤ bound a)
(h_fin : lintegral bound < ⊤)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) l (nhds (f a))) :
tendsto (λn, lintegral (F n)) l (nhds (lintegral f)) :=
begin
rw hl_cb.tendsto_iff_seq_tendsto,
{ intros x xl,
have hxl, { rw tendsto_at_top' at xl, exact xl },
have h := inter_mem_sets hF_meas h_bound,
replace h := hxl _ h,
rcases h with ⟨k, h⟩,
rw ← tendsto_add_at_top_iff_nat k,
refine tendsto_lintegral_of_dominated_convergence _ _ _ _ _,
{ exact bound },
{ intro, refine (h _ _).1, exact nat.le_add_left _ _ },
{ intro, refine (h _ _).2, exact nat.le_add_left _ _ },
{ assumption },
{ filter_upwards [h_lim],
simp only [mem_set_of_eq],
assume a h_lim,
apply @tendsto.comp _ _ _ (λn, x (n + k)) (λn, F n a),
{ assumption },
rw tendsto_add_at_top_iff_nat,
assumption } },
end
section
open encodable
/-- Monotone convergence for a suprema over a directed family and indexed by an encodable type -/
theorem lintegral_supr_directed [encodable β] {f : β → α → ennreal}
(hf : ∀b, measurable (f b)) (h_directed : directed (≤) f) :
(∫⁻ a, ⨆b, f b a) = (⨆b, ∫⁻ a, f b a) :=
begin
by_cases hβ : ¬ nonempty β,
{ have : ∀f : β → ennreal, (⨆(b : β), f b) = 0 :=
assume f, supr_eq_bot.2 (assume b, (hβ ⟨b⟩).elim),
simp [this] },
cases of_not_not hβ with b,
haveI iβ : inhabited β := ⟨b⟩, clear hβ b,
have : ∀a, (⨆ b, f b a) = (⨆ n, f (h_directed.sequence f n) a),
{ assume a,
refine le_antisymm (supr_le $ assume b, _) (supr_le $ assume n, le_supr (λn, f n a) _),
exact le_supr_of_le (encode b + 1) (h_directed.le_sequence b a) },
calc (∫⁻ a, ⨆ b, f b a) = (∫⁻ a, ⨆ n, f (h_directed.sequence f n) a) :
by simp only [this]
... = (⨆ n, ∫⁻ a, f (h_directed.sequence f n) a) :
lintegral_supr (assume n, hf _) h_directed.sequence_mono
... = (⨆ b, ∫⁻ a, f b a) :
begin
refine le_antisymm (supr_le $ assume n, _) (supr_le $ assume b, _),
{ exact le_supr (λb, lintegral (f b)) _ },
{ exact le_supr_of_le (encode b + 1)
(lintegral_le_lintegral _ _ $ h_directed.le_sequence b) }
end
end
end
lemma lintegral_tsum [encodable β] {f : β → α → ennreal} (hf : ∀i, measurable (f i)) :
(∫⁻ a, ∑ i, f i a) = (∑ i, ∫⁻ a, f i a) :=
begin
simp only [ennreal.tsum_eq_supr_sum],
rw [lintegral_supr_directed],
{ simp [lintegral_finset_sum _ hf] },
{ assume b, exact measurable_finset_sum _ hf },
{ assume s t,
use [s ∪ t],
split,
exact assume a, finset.sum_le_sum_of_subset (finset.subset_union_left _ _),
exact assume a, finset.sum_le_sum_of_subset (finset.subset_union_right _ _) }
end
end lintegral
namespace measure
def integral [measurable_space α] (m : measure α) (f : α → ennreal) : ennreal :=
@lintegral α { μ := m } f
variables [measurable_space α] {m : measure α}
@[simp] lemma integral_zero : m.integral (λa, 0) = 0 := @lintegral_zero α { μ := m }
lemma integral_map [measurable_space β] {f : β → ennreal} {g : α → β}
(hf : measurable f) (hg : measurable g) : (map g m).integral f = m.integral (f ∘ g) :=
begin
rw [integral, integral, lintegral_eq_supr_eapprox_integral, lintegral_eq_supr_eapprox_integral],
{ congr, funext n, symmetry,
apply simple_func.integral_map,
{ assume a, exact congr_fun (simple_func.eapprox_comp hf hg) a },
{ assume s hs, exact map_apply hg hs } },
exact hf.comp hg,
assumption
end
lemma integral_dirac (a : α) {f : α → ennreal} (hf : measurable f) : (dirac a).integral f = f a :=
have ∀f:α →ₛ ennreal, @simple_func.integral α {μ := dirac a} f = f a,
begin
assume f,
have : ∀r, @volume α { μ := dirac a } (⇑f ⁻¹' {r}) = ⨆ h : f a = r, 1,
{ assume r,
transitivity,
apply dirac_apply,
apply simple_func.measurable_sn,
refine supr_congr_Prop _ _; simp },
transitivity,
apply finset.sum_eq_single (f a),
{ assume b hb h, simp [this, ne.symm h], },
{ assume h, simp at h, exact (h a rfl).elim },
{ rw [this], simp }
end,
begin
rw [integral, lintegral_eq_supr_eapprox_integral],
{ simp [this, simple_func.supr_eapprox_apply f hf] },
assumption
end
def with_density (m : measure α) (f : α → ennreal) : measure α :=
if hf : measurable f then
measure.of_measurable (λs hs, m.integral (λa, ⨆(h : a ∈ s), f a))
(by simp)
begin
assume s hs hd,
have : ∀a, (⨆ (h : a ∈ ⋃i, s i), f a) = (∑i, (⨆ (h : a ∈ s i), f a)),
{ assume a,
by_cases ha : ∃j, a ∈ s j,
{ rcases ha with ⟨j, haj⟩,
have : ∀i, a ∈ s i ↔ j = i := assume i,
iff.intro
(assume hai, by_contradiction $ assume hij, hd j i hij ⟨haj, hai⟩)
(by rintros rfl; assumption),
simp [this, ennreal.tsum_supr_eq] },
{ have : ∀i, ¬ a ∈ s i, { simpa using ha },
simp [this] } },
simp only [this],
apply lintegral_tsum,
{ assume i,
simp [supr_eq_if],
exact measurable.if (hs i) hf measurable_const }
end
else 0
lemma with_density_apply {m : measure α} {f : α → ennreal} {s : set α}
(hf : measurable f) (hs : is_measurable s) :
m.with_density f s = m.integral (λa, ⨆(h : a ∈ s), f a) :=
by rw [with_density, dif_pos hf]; exact measure.of_measurable_apply s hs
end measure
end measure_theory
|
78d799c1dc562a867c1c7261199b00bdd49a32d8 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/logic/examples/propositional/soundness.lean | a8e7ae84c7413bbcf2ae12ca369b327c49312b18 | [
"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 | 6,389 | 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
Define propositional calculus, valuation, provability, validity, prove soundness.
This file is based on Floris van Doorn Coq files.
-/
import data.nat data.list
open nat bool list decidable
attribute [reducible]
definition PropVar := nat
inductive PropF :=
| Var : PropVar → PropF
| Bot : PropF
| Conj : PropF → PropF → PropF
| Disj : PropF → PropF → PropF
| Impl : PropF → PropF → PropF
namespace PropF
notation `#`:max P:max := Var P
notation A ∨ B := Disj A B
notation A ∧ B := Conj A B
infixr `⇒`:27 := Impl
notation `⊥` := Bot
definition Neg A := A ⇒ ⊥
notation ~ A := Neg A
definition Top := ~⊥
notation `⊤` := Top
definition BiImpl A B := A ⇒ B ∧ B ⇒ A
infixr `⇔`:27 := BiImpl
definition valuation := PropVar → bool
definition TrueQ (v : valuation) : PropF → bool
| TrueQ (# P) := v P
| TrueQ ⊥ := ff
| TrueQ (A ∨ B) := TrueQ A || TrueQ B
| TrueQ (A ∧ B) := TrueQ A && TrueQ B
| TrueQ (A ⇒ B) := bnot (TrueQ A) || TrueQ B
attribute [reducible]
definition is_true (b : bool) := b = tt
-- the valuation v satisfies a list of PropF, if forall (A : PropF) in Γ,
-- (TrueQ v A) is tt (the Boolean true)
definition Satisfies v Γ := ∀ A, A ∈ Γ → is_true (TrueQ v A)
definition Models Γ A := ∀ v, Satisfies v Γ → is_true (TrueQ v A)
infix `⊨`:80 := Models
definition Valid p := [] ⊨ p
reserve infix `⊢`:26
/- Provability -/
inductive Nc : list PropF → PropF → Prop :=
infix ⊢ := Nc
| Nax : ∀ Γ A, A ∈ Γ → Γ ⊢ A
| ImpI : ∀ Γ A B, A::Γ ⊢ B → Γ ⊢ A ⇒ B
| ImpE : ∀ Γ A B, Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B
| BotC : ∀ Γ A, (~A)::Γ ⊢ ⊥ → Γ ⊢ A
| AndI : ∀ Γ A B, Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
| AndE₁ : ∀ Γ A B, Γ ⊢ A ∧ B → Γ ⊢ A
| AndE₂ : ∀ Γ A B, Γ ⊢ A ∧ B → Γ ⊢ B
| OrI₁ : ∀ Γ A B, Γ ⊢ A → Γ ⊢ A ∨ B
| OrI₂ : ∀ Γ A B, Γ ⊢ B → Γ ⊢ A ∨ B
| OrE : ∀ Γ A B C, Γ ⊢ A ∨ B → A::Γ ⊢ C → B::Γ ⊢ C → Γ ⊢ C
infix ⊢ := Nc
definition Provable A := [] ⊢ A
definition Prop_Soundness := ∀ A, Provable A → Valid A
definition Prop_Completeness := ∀ A, Valid A → Provable A
open Nc
lemma weakening2 : ∀ Γ A, Γ ⊢ A → ∀ Δ, Γ ⊆ Δ → Δ ⊢ A :=
λ Γ A H, Nc.induction_on H
(λ Γ A Hin Δ Hs, !Nax (Hs A Hin))
(λ Γ A B H w Δ Hs, !ImpI (w _ (cons_sub_cons A Hs)))
(λ Γ A B H₁ H₂ w₁ w₂ Δ Hs, !ImpE (w₁ _ Hs) (w₂ _ Hs))
(λ Γ A H w Δ Hs, !BotC (w _ (cons_sub_cons (~A) Hs)))
(λ Γ A B H₁ H₂ w₁ w₂ Δ Hs, !AndI (w₁ _ Hs) (w₂ _ Hs))
(λ Γ A B H w Δ Hs, !AndE₁ (w _ Hs))
(λ Γ A B H w Δ Hs, !AndE₂ (w _ Hs))
(λ Γ A B H w Δ Hs, !OrI₁ (w _ Hs))
(λ Γ A B H w Δ Hs, !OrI₂ (w _ Hs))
(λ Γ A B C H₁ H₂ H₃ w₁ w₂ w₃ Δ Hs, !OrE (w₁ _ Hs) (w₂ _ (cons_sub_cons A Hs)) (w₃ _ (cons_sub_cons B Hs)))
lemma weakening : ∀ Γ Δ A, Γ ⊢ A → Γ++Δ ⊢ A :=
λ Γ Δ A H, weakening2 Γ A H (Γ++Δ) (sub_append_left Γ Δ)
lemma deduction : ∀ Γ A B, Γ ⊢ A ⇒ B → A::Γ ⊢ B :=
λ Γ A B H, ImpE _ A _ (!weakening2 H _ (sub_cons A Γ)) (!Nax (mem_cons A Γ))
lemma prov_impl : ∀ A B, Provable (A ⇒ B) → ∀ Γ, Γ ⊢ A → Γ ⊢ B :=
λ A B Hp Γ Ha,
have wHp : Γ ⊢ (A ⇒ B), from !weakening Hp,
!ImpE wHp Ha
lemma Satisfies_cons : ∀ {A Γ v}, Satisfies v Γ → is_true (TrueQ v A) → Satisfies v (A::Γ) :=
λ A Γ v s t B BinAG,
or.elim BinAG
(λ e : B = A, by rewrite e; exact t)
(λ i : B ∈ Γ, s _ i)
theorem Soundness_general : ∀ A Γ, Γ ⊢ A → Γ ⊨ A :=
λ A Γ H, Nc.induction_on H
(λ Γ A Hin v s, (s _ Hin))
(λ Γ A B H r v s,
by_cases
(λ t : is_true (TrueQ v A),
have aux₁ : Satisfies v (A::Γ), from Satisfies_cons s t,
have aux₂ : is_true (TrueQ v B), from r v aux₁,
bor_inr aux₂)
(λ f : ¬ is_true (TrueQ v A),
have aux : bnot (TrueQ v A) = tt, by rewrite (eq_ff_of_ne_tt f),
bor_inl aux))
(λ Γ A B H₁ H₂ r₁ r₂ v s,
have aux₁ : bnot (TrueQ v A) || TrueQ v B = tt, from r₁ v s,
have aux₂ : TrueQ v A = tt, from r₂ v s,
by rewrite [aux₂ at aux₁, bnot_true at aux₁, ff_bor at aux₁]; exact aux₁)
(λ Γ A H r v s, by_contradiction
(λ n : TrueQ v A ≠ tt,
have aux₁ : TrueQ v A = ff, from eq_ff_of_ne_tt n,
have aux₂ : TrueQ v (~A) = tt, begin change (bnot (TrueQ v A) || ff = tt), rewrite aux₁ end,
have aux₃ : Satisfies v ((~A)::Γ), from Satisfies_cons s aux₂,
have aux₄ : TrueQ v ⊥ = tt, from r v aux₃,
absurd aux₄ ff_ne_tt))
(λ Γ A B H₁ H₂ r₁ r₂ v s,
have aux₁ : TrueQ v A = tt, from r₁ v s,
have aux₂ : TrueQ v B = tt, from r₂ v s,
band_intro aux₁ aux₂)
(λ Γ A B H r v s,
have aux : TrueQ v (A ∧ B) = tt, from r v s,
band_elim_left aux)
(λ Γ A B H r v s,
have aux : TrueQ v (A ∧ B) = tt, from r v s,
band_elim_right aux)
(λ Γ A B H r v s,
have aux : TrueQ v A = tt, from r v s,
bor_inl aux)
(λ Γ A B H r v s,
have aux : TrueQ v B = tt, from r v s,
bor_inr aux)
(λ Γ A B C H₁ H₂ H₃ r₁ r₂ r₃ v s,
have aux : TrueQ v A || TrueQ v B = tt, from r₁ v s,
or.elim (or_of_bor_eq aux)
(λ At : TrueQ v A = tt,
have aux : Satisfies v (A::Γ), from Satisfies_cons s At,
r₂ v aux)
(λ Bt : TrueQ v B = tt,
have aux : Satisfies v (B::Γ), from Satisfies_cons s Bt,
r₃ v aux))
theorem Soundness : Prop_Soundness :=
λ A, Soundness_general A []
end PropF
|
57b3b198c36574094133686ac5f55cd52f5757f6 | 367134ba5a65885e863bdc4507601606690974c1 | /src/topology/algebra/ordered.lean | 9423a17e38b06b090c55c2780eaba13b55c60576 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 157,379 | 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 tactic.linarith
import tactic.tfae
import algebra.archimedean
import algebra.group.pi
import algebra.ordered_ring
import order.liminf_limsup
import data.set.intervals.image_preimage
import data.set.intervals.ord_connected
import data.set.intervals.surj_on
import data.set.intervals.pi
import topology.algebra.group
import topology.extend_from_subset
import order.filter.interval
/-!
# Theory of topology on ordered spaces
## Main definitions
The order topology on an ordered space is the topology generated by all open intervals (or
equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `preorder.topology α`.
However, we do *not* register it as an instance (as many existing ordered types already have
topologies, which would be equal but not definitionally equal to `preorder.topology α`). Instead,
we introduce a class `order_topology α`(which is a `Prop`, also known as a mixin) saying that on
the type `α` having already a topological space structure and a preorder structure, the topological
structure is equal to the order topology.
We also introduce another (mixin) class `order_closed_topology α` saying that the set of points
`(x, y)` with `x ≤ y` is closed in the product space. This is automatically satisfied on a linear
order with the order topology.
We prove many basic properties of such topologies.
## Main statements
This file contains the proofs of the following facts. For exact requirements
(`order_closed_topology` vs `order_topology`, `preorder` vs `partial_order` vs `linear_order` etc)
see their statements.
### Open / closed sets
* `is_open_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open;
* `is_open_Iio`, `is_open_Ioi`, `is_open_Ioo` : open intervals are open;
* `is_closed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed;
* `is_closed_Iic`, `is_closed_Ici`, `is_closed_Icc` : closed intervals are closed;
* `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}`
and `{x | f x < g x}` are included by `{x | f x = g x}`;
* `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any
neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood
of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`.
### Convergence and inequalities
* `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually
`f x ≤ g x`, then `a ≤ b`
* `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b`
(resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a); we also provide primed versions
that assume the inequalities to hold for all `x`.
### Min, max, `Sup` and `Inf`
* `continuous.min`, `continuous.max`: pointwise `min`/`max` of two continuous functions is
continuous.
* `tendsto.min`, `tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise
`min`/`max` tend to `min a b` and `max a b`, respectively.
* `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem,
sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h`
both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`.
### Connected sets and Intermediate Value Theorem
* `is_preconnected_I??` : all intervals `I??` are preconnected,
* `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for
connected sets and connected spaces, respectively;
* `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions
on closed intervals.
### Miscellaneous facts
* `is_compact.exists_forall_le`, `is_compact.exists_forall_ge` : extreme value theorem, a continuous
function on a compact set takes its minimum and maximum values.
* `is_closed.Icc_subset_of_forall_mem_nhds_within` : “Continuous induction” principle;
if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods
is included `s`, then `[a, b] ⊆ s`.
* `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two
other versions of the “continuous induction” principle.
## Implementation
We do _not_ register the order topology as an instance on a preorder (or even on a linear order).
Indeed, on many such spaces, a topology has already been constructed in a different way (think
of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`),
and is in general not defeq to the one generated by the intervals. We make it available as a
definition `preorder.topology α` though, that can be registered as an instance when necessary, or
for specific types.
-/
open classical set filter topological_space
open function (curry uncurry)
open_locale topological_space classical filter
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the
set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin.
This property is satisfied for the order topology on a linear order, but it can be satisfied more
generally, and suffices to derive many interesting properties relating order and topology. -/
class order_closed_topology (α : Type*) [topological_space α] [preorder α] : Prop :=
(is_closed_le' : is_closed {p:α×α | p.1 ≤ p.2})
instance : Π [topological_space α], topological_space (order_dual α) := id
section order_closed_topology
section preorder
variables [topological_space α] [preorder α] [t : order_closed_topology α]
include t
lemma is_closed_le_prod : is_closed {p : α × α | p.1 ≤ p.2} :=
t.is_closed_le'
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) _ is_closed_le_prod
lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} :=
is_closed_le continuous_id continuous_const
lemma is_closed_Iic {a : α} : is_closed (Iic a) :=
is_closed_le' a
lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} :=
is_closed_le continuous_const continuous_id
lemma is_closed_Ici {a : α} : is_closed (Ici a) :=
is_closed_ge' a
instance : order_closed_topology (order_dual α) :=
⟨(@order_closed_topology.is_closed_le' α _ _ _).preimage continuous_swap⟩
lemma is_closed_Icc {a b : α} : is_closed (Icc a b) :=
is_closed_inter is_closed_Ici is_closed_Iic
@[simp] lemma closure_Icc (a b : α) : closure (Icc a b) = Icc a b :=
is_closed_Icc.closure_eq
@[simp] lemma closure_Iic (a : α) : closure (Iic a) = Iic a :=
is_closed_Iic.closure_eq
@[simp] lemma closure_Ici (a : α) : closure (Ici a) = Ici a :=
is_closed_Ici.closure_eq
lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b]
(hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) :
a₁ ≤ a₂ :=
have tendsto (λb, (f b, g b)) b (𝓝 (a₁, a₂)),
by rw [nhds_prod_eq]; exact hf.prod_mk hg,
show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2},
from t.is_closed_le'.mem_of_tendsto this h
lemma le_of_tendsto_of_tendsto' {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b]
(hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) :
a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto hf hg (eventually_of_forall h)
lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β}
[ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b :=
le_of_tendsto_of_tendsto lim tendsto_const_nhds h
lemma le_of_tendsto' {f : β → α} {a b : α} {x : filter β}
[ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b :=
le_of_tendsto lim (eventually_of_forall h)
lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x]
(lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, b ≤ f c) : b ≤ a :=
le_of_tendsto_of_tendsto tendsto_const_nhds lim h
lemma ge_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x]
(lim : tendsto f x (𝓝 a)) (h : ∀ c, b ≤ f c) : b ≤ a :=
ge_of_tendsto lim (eventually_of_forall 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} :=
(is_closed_le hf hg).closure_eq
lemma closure_lt_subset_le [topological_space β] {f g : β → α} (hf : continuous f)
(hg : continuous g) :
closure {b | f b < g b} ⊆ {b | f b ≤ g b} :=
by { rw [←closure_le_eq hf hg], exact closure_mono (λ b, le_of_lt) }
lemma continuous_within_at.closure_le [topological_space β]
{f g : β → α} {s : set β} {x : β} (hx : x ∈ closure s)
(hf : continuous_within_at f s x)
(hg : continuous_within_at g s x)
(h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x :=
show (f x, g x) ∈ {p : α × α | p.1 ≤ p.2},
from order_closed_topology.is_closed_le'.closure_subset ((hf.prod hg).mem_closure hx h)
/-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`,
then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/
lemma is_closed.is_closed_le [topological_space β] {f g : β → α} {s : set β} (hs : is_closed s)
(hf : continuous_on f s) (hg : continuous_on g s) :
is_closed {x ∈ s | f x ≤ g x} :=
(hf.prod hg).preimage_closed_of_closed hs order_closed_topology.is_closed_le'
omit t
lemma nhds_within_Ici_ne_bot {a b : α} (H₂ : a ≤ b) :
ne_bot (𝓝[Ici a] b) :=
nhds_within_ne_bot_of_mem H₂
@[instance] lemma nhds_within_Ici_self_ne_bot (a : α) :
ne_bot (𝓝[Ici a] a) :=
nhds_within_Ici_ne_bot (le_refl a)
lemma nhds_within_Iic_ne_bot {a b : α} (H : a ≤ b) :
ne_bot (𝓝[Iic b] a) :=
nhds_within_ne_bot_of_mem H
@[instance] lemma nhds_within_Iic_self_ne_bot (a : α) :
ne_bot (𝓝[Iic a] a) :=
nhds_within_Iic_ne_bot (le_refl a)
end preorder
section partial_order
variables [topological_space α] [partial_order α] [t : order_closed_topology α]
include t
private lemma is_closed_eq_aux : is_closed {p : α × α | p.1 = p.2} :=
by simp only [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
@[priority 90] -- see Note [lower instance priority]
instance order_closed_topology.to_t2_space : t2_space α :=
{ t2 :=
have is_open {p : α × α | p.1 ≠ p.2} := is_closed_eq_aux.is_open_compl,
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 α] [order_closed_topology α]
lemma is_open_lt_prod : is_open {p : α × α | p.1 < p.2} :=
by { simp_rw [← is_closed_compl_iff, compl_set_of, not_lt],
exact is_closed_le continuous_snd continuous_fst }
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).is_open_compl
variables {a b : α}
lemma is_open_Iio : is_open (Iio a) :=
is_open_lt continuous_id continuous_const
lemma is_open_Ioi : is_open (Ioi a) :=
is_open_lt continuous_const continuous_id
lemma is_open_Ioo : is_open (Ioo a b) :=
is_open_inter is_open_Ioi is_open_Iio
@[simp] lemma interior_Ioi : interior (Ioi a) = Ioi a :=
is_open_Ioi.interior_eq
@[simp] lemma interior_Iio : interior (Iio a) = Iio a :=
is_open_Iio.interior_eq
@[simp] lemma interior_Ioo : interior (Ioo a b) = Ioo a b :=
is_open_Ioo.interior_eq
variables [topological_space γ]
/-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions
on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/
lemma intermediate_value_univ₂ [preconnected_space γ] {a b : γ} {f g : γ → α} (hf : continuous f)
(hg : continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) :
∃ x, f x = g x :=
begin
obtain ⟨x, h, hfg, hgf⟩ : (univ ∩ {x | f x ≤ g x ∧ g x ≤ f x}).nonempty,
from is_preconnected_closed_iff.1 preconnected_space.is_preconnected_univ _ _
(is_closed_le hf hg) (is_closed_le hg hf) (λ x hx, le_total _ _) ⟨a, trivial, ha⟩
⟨b, trivial, hb⟩,
exact ⟨x, le_antisymm hfg hgf⟩
end
/-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous
on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`,
then for some `x ∈ s` we have `f x = g x`. -/
lemma is_preconnected.intermediate_value₂ {s : set γ} (hs : is_preconnected s)
{a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f g : γ → α}
(hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) :
∃ x ∈ s, f x = g x :=
let ⟨x, hx⟩ := @intermediate_value_univ₂ α s _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ ⟨b, hb⟩
_ _ (continuous_on_iff_continuous_restrict.1 hf) (continuous_on_iff_continuous_restrict.1 hg)
ha' hb'
in ⟨x, x.2, hx⟩
/-- Intermediate Value Theorem for continuous functions on connected sets. -/
lemma is_preconnected.intermediate_value {s : set γ} (hs : is_preconnected s)
{a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f : γ → α} (hf : continuous_on f s) :
Icc (f a) (f b) ⊆ f '' s :=
λ x hx, mem_image_iff_bex.2 $ hs.intermediate_value₂ ha hb hf continuous_on_const hx.1 hx.2
/-- Intermediate Value Theorem for continuous functions on connected spaces. -/
lemma intermediate_value_univ [preconnected_space γ] (a b : γ) {f : γ → α} (hf : continuous f) :
Icc (f a) (f b) ⊆ range f :=
λ x hx, intermediate_value_univ₂ hf continuous_const hx.1 hx.2
/-- Intermediate Value Theorem for continuous functions on connected spaces. -/
lemma mem_range_of_exists_le_of_exists_ge [preconnected_space γ] {c : α} {f : γ → α}
(hf : continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) :
c ∈ range f :=
let ⟨a, ha⟩ := h₁, ⟨b, hb⟩ := h₂ in intermediate_value_univ a b hf ⟨ha, hb⟩
/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/
lemma is_preconnected.Icc_subset {s : set α} (hs : is_preconnected s)
{a b : α} (ha : a ∈ s) (hb : b ∈ s) :
Icc a b ⊆ s :=
by simpa only [image_id] using hs.intermediate_value ha hb continuous_on_id
/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/
lemma is_connected.Icc_subset {s : set α} (hs : is_connected s)
{a b : α} (ha : a ∈ s) (hb : b ∈ s) :
Icc a b ⊆ s :=
hs.2.Icc_subset ha hb
/-- If preconnected set in a linear order space is unbounded below and above, then it is the whole
space. -/
lemma is_preconnected.eq_univ_of_unbounded {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s)
(ha : ¬bdd_above s) :
s = univ :=
begin
refine eq_univ_of_forall (λ x, _),
obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bdd_below_iff.1 hb x,
obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x,
exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
end
/-!
### Neighborhoods to the left and to the right on an `order_closed_topology`
Limits to the left and to the right of real functions are defined in terms of neighborhoods to
the left and to the right, either open or closed, i.e., members of `𝓝[Ioi a] a` and
`𝓝[Ici a] a` on the right, and similarly on the left. Here we simply prove that all
right-neighborhoods of a point are equal, and we'll prove later other useful characterizations which
require the stronger hypothesis `order_topology α` -/
/-!
#### Right neighborhoods, point excluded
-/
lemma Ioo_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) :
Ioo a c ∈ 𝓝[Ioi b] b :=
mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2,
by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩
lemma Ioc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) :
Ioc a c ∈ 𝓝[Ioi b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ioc_self
lemma Ico_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) :
Ico a c ∈ 𝓝[Ioi b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ico_self
lemma Icc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) :
Icc a c ∈ 𝓝[Ioi b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Icc_self
@[simp] lemma nhds_within_Ioc_eq_nhds_within_Ioi {a b : α} (h : a < b) :
𝓝[Ioc a b] a = 𝓝[Ioi a] a :=
le_antisymm (nhds_within_mono _ Ioc_subset_Ioi_self) $
nhds_within_le_of_mem $ Ioc_mem_nhds_within_Ioi $ left_mem_Ico.2 h
@[simp] lemma nhds_within_Ioo_eq_nhds_within_Ioi {a b : α} (h : a < b) :
𝓝[Ioo a b] a = 𝓝[Ioi a] a :=
le_antisymm (nhds_within_mono _ Ioo_subset_Ioi_self) $
nhds_within_le_of_mem $ Ioo_mem_nhds_within_Ioi $ left_mem_Ico.2 h
@[simp]
lemma continuous_within_at_Ioc_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Ioc a b) a ↔ continuous_within_at f (Ioi a) a :=
by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Ioi h]
@[simp]
lemma continuous_within_at_Ioo_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Ioo a b) a ↔ continuous_within_at f (Ioi a) a :=
by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Ioi h]
/-!
#### Left neighborhoods, point excluded
-/
lemma Ioo_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) :
Ioo a c ∈ 𝓝[Iio b] b :=
by simpa only [dual_Ioo] using @Ioo_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩
lemma Ico_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) :
Ico a c ∈ 𝓝[Iio b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ico_self
lemma Ioc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) :
Ioc a c ∈ 𝓝[Iio b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ioc_self
lemma Icc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) :
Icc a c ∈ 𝓝[Iio b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Icc_self
@[simp] lemma nhds_within_Ico_eq_nhds_within_Iio {a b : α} (h : a < b) :
𝓝[Ico a b] b = 𝓝[Iio b] b :=
by simpa only [dual_Ioc] using @nhds_within_Ioc_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h
@[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : α} (h : a < b) :
𝓝[Ioo a b] b = 𝓝[Iio b] b :=
by simpa only [dual_Ioo] using @nhds_within_Ioo_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h
@[simp] lemma continuous_within_at_Ico_iff_Iio {a b : α} {f : α → γ} (h : a < b) :
continuous_within_at f (Ico a b) b ↔ continuous_within_at f (Iio b) b :=
by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Iio h]
@[simp] lemma continuous_within_at_Ioo_iff_Iio {a b : α} {f : α → γ} (h : a < b) :
continuous_within_at f (Ioo a b) b ↔ continuous_within_at f (Iio b) b :=
by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Iio h]
/-!
#### Right neighborhoods, point included
-/
lemma Ioo_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) :
Ioo a c ∈ 𝓝[Ici b] b :=
mem_nhds_within_of_mem_nhds $ mem_nhds_sets is_open_Ioo H
lemma Ioc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) :
Ioc a c ∈ 𝓝[Ici b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ici H) Ioo_subset_Ioc_self
lemma Ico_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) :
Ico a c ∈ 𝓝[Ici b] b :=
mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2,
by simp only [inter_comm, Ici_inter_Iio, Ico_subset_Ico_left H.1]⟩
lemma Icc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) :
Icc a c ∈ 𝓝[Ici b] b :=
mem_sets_of_superset (Ico_mem_nhds_within_Ici H) Ico_subset_Icc_self
@[simp] lemma nhds_within_Icc_eq_nhds_within_Ici {a b : α} (h : a < b) :
𝓝[Icc a b] a = 𝓝[Ici a] a :=
le_antisymm (nhds_within_mono _ Icc_subset_Ici_self) $
nhds_within_le_of_mem $ Icc_mem_nhds_within_Ici $ left_mem_Ico.2 h
@[simp] lemma nhds_within_Ico_eq_nhds_within_Ici {a b : α} (h : a < b) :
𝓝[Ico a b] a = 𝓝[Ici a] a :=
le_antisymm (nhds_within_mono _ (λ x, and.left)) $
nhds_within_le_of_mem $ Ico_mem_nhds_within_Ici $ left_mem_Ico.2 h
@[simp]
lemma continuous_within_at_Icc_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Icc a b) a ↔ continuous_within_at f (Ici a) a :=
by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Ici h]
@[simp]
lemma continuous_within_at_Ico_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Ico a b) a ↔ continuous_within_at f (Ici a) a :=
by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Ici h]
/-!
#### Left neighborhoods, point included
-/
lemma Ioo_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) :
Ioo a c ∈ 𝓝[Iic b] b :=
mem_nhds_within_of_mem_nhds $ mem_nhds_sets is_open_Ioo H
lemma Ico_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) :
Ico a c ∈ 𝓝[Iic b] b :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iic H) Ioo_subset_Ico_self
lemma Ioc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) :
Ioc a c ∈ 𝓝[Iic b] b :=
by simpa only [dual_Ico] using @Ico_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩
lemma Icc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) :
Icc a c ∈ 𝓝[Iic b] b :=
mem_sets_of_superset (Ioc_mem_nhds_within_Iic H) Ioc_subset_Icc_self
@[simp] lemma nhds_within_Icc_eq_nhds_within_Iic {a b : α} (h : a < b) :
𝓝[Icc a b] b = 𝓝[Iic b] b :=
by simpa only [dual_Icc] using @nhds_within_Icc_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h
@[simp] lemma nhds_within_Ioc_eq_nhds_within_Iic {a b : α} (h : a < b) :
𝓝[Ioc a b] b = 𝓝[Iic b] b :=
by simpa only [dual_Ico] using @nhds_within_Ico_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h
@[simp]
lemma continuous_within_at_Icc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Icc a b) b ↔ continuous_within_at f (Iic b) b :=
by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Iic h]
@[simp]
lemma continuous_within_at_Ioc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) :
continuous_within_at f (Ioc a b) b ↔ continuous_within_at f (Iic b) b :=
by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Iic h]
end linear_order
section linear_order
variables [topological_space α] [linear_order α] [order_closed_topology α] {f g : β → α}
section
variables [topological_space β]
lemma frontier_le_subset_eq (hf : continuous f) (hg : continuous g) :
frontier {b | f b ≤ g b} ⊆ {b | f b = g b} :=
begin
rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg],
rintros b ⟨hb₁, hb₂⟩,
refine le_antisymm hb₁ (closure_lt_subset_le hg hf _),
convert hb₂ using 2, simp only [not_le.symm], refl
end
lemma frontier_Iic_subset (a : α) : frontier (Iic a) ⊆ {a} :=
frontier_le_subset_eq (@continuous_id α _) continuous_const
lemma frontier_Ici_subset (a : α) : frontier (Ici a) ⊆ {a} :=
@frontier_Iic_subset (order_dual α) _ _ _ _
lemma frontier_lt_subset_eq (hf : continuous f) (hg : continuous g) :
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_if_le [topological_space γ] [Π x, decidable (f x ≤ g x)]
{f' g' : β → γ} (hf : continuous f) (hg : continuous g)
(hf' : continuous_on f' {x | f x ≤ g x}) (hg' : continuous_on g' {x | g x ≤ f x})
(hfg : ∀ x, f x = g x → f' x = g' x) :
continuous (λ x, if f x ≤ g x then f' x else g' x) :=
begin
refine continuous_if (λ a ha, hfg _ (frontier_le_subset_eq hf hg ha)) _ (hg'.mono _),
{ rwa [(is_closed_le hf hg).closure_eq] },
{ simp only [not_le], exact closure_lt_subset_le hg hf }
end
lemma continuous.if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ}
(hf' : continuous f') (hg' : continuous g') (hf : continuous f) (hg : continuous g)
(hfg : ∀ x, f x = g x → f' x = g' x) :
continuous (λ x, if f x ≤ g x then f' x else g' x) :=
continuous_if_le hf hg hf'.continuous_on hg'.continuous_on hfg
@[continuity] lemma continuous.min (hf : continuous f) (hg : continuous g) :
continuous (λb, min (f b) (g b)) :=
hf.if_le hg hf hg (λ x, id)
@[continuity] lemma continuous.max (hf : continuous f) (hg : continuous g) :
continuous (λb, max (f b) (g b)) :=
@continuous.min (order_dual α) _ _ _ _ _ _ _ hf hg
end
lemma continuous_min : continuous (λ p : α × α, min p.1 p.2) := continuous_fst.min continuous_snd
lemma continuous_max : continuous (λ p : α × α, max p.1 p.2) := continuous_fst.max continuous_snd
lemma filter.tendsto.max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁))
(hg : tendsto g b (𝓝 a₂)) :
tendsto (λb, max (f b) (g b)) b (𝓝 (max a₁ a₂)) :=
(continuous_max.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg)
lemma filter.tendsto.min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁))
(hg : tendsto g b (𝓝 a₂)) :
tendsto (λb, min (f b) (g b)) b (𝓝 (min a₁ a₂)) :=
(continuous_min.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg)
end linear_order
end order_closed_topology
/-- The order topology on an ordered type is the topology generated by open intervals. We register
it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed.
We define it as a mixin. If you want to introduce the order topology on a preorder, use
`preorder.topology`. -/
class order_topology (α : Type*) [t : topological_space α] [preorder α] : Prop :=
(topology_eq_generate_intervals : t = generate_from {s | ∃a, s = Ioi a ∨ s = Iio a})
/-- (Order) topology on a partial order `α` generated by the subbase of open intervals
`(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an
instance as many ordered sets are already endowed with the same topology, most often in a non-defeq
way though. Register as a local instance when necessary. -/
def preorder.topology (α : Type*) [preorder α] : topological_space α :=
generate_from {s : set α | ∃ (a : α), s = {b : α | a < b} ∨ s = {b : α | b < a}}
section order_topology
instance {α : Type*} [topological_space α] [partial_order α] [order_topology α] :
order_topology (order_dual α) :=
⟨by convert @order_topology.topology_eq_generate_intervals α _ _ _;
conv in (_ ∨ _) { rw or.comm }; refl⟩
section partial_order
variables [topological_space α] [partial_order α] [t : order_topology α]
include t
lemma is_open_iff_generate_intervals {s : set α} :
is_open s ↔ generate_open {s | ∃a, s = Ioi a ∨ s = Iio 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) : ∀ᶠ x in 𝓝 b, a < x :=
mem_nhds_sets (is_open_lt' _) h
lemma le_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x :=
(𝓝 b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma gt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b :=
mem_nhds_sets (is_open_gt' _) h
lemma ge_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b :=
(𝓝 a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma nhds_eq_order (a : α) :
𝓝 a = (⨅b ∈ Iio a, 𝓟 (Ioi b)) ⊓ (⨅b ∈ Ioi a, 𝓟 (Iio b)) :=
by rw [t.topology_eq_generate_intervals, nhds_generate_from];
from le_antisymm
(le_inf
(le_binfi $ assume b hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩)
(le_binfi $ assume b 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_order {f : β → α} {a : α} {x : filter β} :
tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ (∀ a' > a, ∀ᶠ b in x, f b < a') :=
by simp [nhds_eq_order a, tendsto_inf, tendsto_infi, tendsto_principal]
instance tendsto_Icc_class_nhds (a : α) : tendsto_Ixx_class Icc (𝓝 a) (𝓝 a) :=
begin
simp only [nhds_eq_order, infi_subtype'],
refine ((has_basis_infi_principal_finite _).inf
(has_basis_infi_principal_finite _)).tendsto_Ixx_class (λ s hs, _),
refine (ord_connected_bInter _).inter (ord_connected_bInter _); intros _ _,
exacts [ord_connected_Ioi, ord_connected_Iio]
end
instance tendsto_Ico_class_nhds (a : α) : tendsto_Ixx_class Ico (𝓝 a) (𝓝 a) :=
tendsto_Ixx_class_of_subset (λ _ _, Ico_subset_Icc_self)
instance tendsto_Ioc_class_nhds (a : α) : tendsto_Ixx_class Ioc (𝓝 a) (𝓝 a) :=
tendsto_Ixx_class_of_subset (λ _ _, Ioc_subset_Icc_self)
instance tendsto_Ioo_class_nhds (a : α) : tendsto_Ixx_class Ioo (𝓝 a) (𝓝 a) :=
tendsto_Ixx_class_of_subset (λ _ _, Ioo_subset_Icc_self)
/-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold
eventually for the filter. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : β → α} {b : filter β} {a : α}
(hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a))
(hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) :
tendsto f b (𝓝 a) :=
tendsto_order.2
⟨assume a' h',
have ∀ᶠ b in b, a' < g b, from (tendsto_order.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have ∀ᶠ b in b, h b < a', from (tendsto_order.1 hh).right a' h',
by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩
/-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold
everywhere. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α}
(hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) :
tendsto f b (𝓝 a) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh
(eventually_of_forall hgf) (eventually_of_forall hfh)
lemma nhds_order_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
𝓝 a = (⨅l (h₂ : l < a) u (h₂ : a < u), 𝓟 (Ioo l u)) :=
have ∃ u, u ∈ Ioi a, from hu, have ∃ l, l ∈ Iio a, from hl,
by { simp only [nhds_eq_order, inf_binfi, binfi_inf, *, inf_principal, Ioi_inter_Iio], refl }
lemma tendsto_order_unbounded {f : β → α} {a : α} {x : filter β}
(hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) :
tendsto f x (𝓝 a) :=
by rw [nhds_order_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
instance tendsto_Ixx_nhds_within {α : Type*} [preorder α] [topological_space α]
(a : α) {s t : set α} {Ixx}
[tendsto_Ixx_class Ixx (𝓝 a) (𝓝 a)] [tendsto_Ixx_class Ixx (𝓟 s) (𝓟 t)]:
tendsto_Ixx_class Ixx (𝓝[s] a) (𝓝[t] a) :=
filter.tendsto_Ixx_class_inf
instance tendsto_Icc_class_nhds_pi {ι : Type*} {α : ι → Type*} [nonempty ι]
[Π i, partial_order (α i)] [Π i, topological_space (α i)] [∀ i, order_topology (α i)]
(f : Π i, α i) :
tendsto_Ixx_class Icc (𝓝 f) (𝓝 f) :=
begin
constructor,
conv in ((𝓝 f).lift' powerset) { rw [nhds_pi] },
simp only [lift'_infi_powerset, comap_lift'_eq2 monotone_powerset, tendsto_infi, tendsto_lift',
mem_powerset_iff, subset_def, mem_preimage],
intros i s hs,
have : tendsto (λ g : Π i, α i, g i) (𝓝 f) (𝓝 (f i)) := ((continuous_apply i).tendsto f),
refine (tendsto_lift'.1 ((this.comp tendsto_fst).Icc (this.comp tendsto_snd)) s hs).mono _,
exact λ p hp g hg, hp ⟨hg.1 _, hg.2 _⟩
end
theorem induced_order_topology' {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [order_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) :
@order_topology _ (induced f ta) _ :=
begin
letI := induced f ta,
refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩,
rw [nhds_induced, nhds_generate_from, nhds_eq_order (f a)],
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_order_topology {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [order_topology β]
(f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y)
(H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) :
@order_topology _ (induced f ta) _ :=
induced_order_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⟩)
/-- On an `ord_connected` subset of a linear order, the order topology for the restriction of the
order is the same as the restriction to the subset of the order topology. -/
instance order_topology_of_ord_connected {α : Type u}
[ta : topological_space α] [linear_order α] [order_topology α]
{t : set α} [ht : ord_connected t] :
order_topology t :=
begin
letI := induced (coe : t → α) ta,
refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩,
rw [nhds_induced, nhds_generate_from, nhds_eq_order (a : α)],
apply le_antisymm,
{ refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _),
rcases hs with ⟨ab, b, rfl|rfl⟩,
{ refine ⟨Ioi b, _, λ _, id⟩,
refine mem_inf_sets_of_left (mem_infi_sets b _),
exact mem_infi_sets ab (mem_principal_self (Ioi ↑b)) },
{ refine ⟨Iio b, _, λ _, id⟩,
refine mem_inf_sets_of_right (mem_infi_sets b _),
exact mem_infi_sets ab (mem_principal_self (Iio b)) } },
{ rw [← map_le_iff_le_comap],
refine le_inf _ _,
{ refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _),
by_cases hx : x ∈ t,
{ refine mem_infi_sets (Ioi ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inl rfl⟩⟩ _),
exact λ _, id },
simp only [set_coe.exists, mem_set_of_eq, mem_map],
convert univ_sets _,
suffices hx' : ∀ (y : t), ↑y ∈ Ioi x,
{ simp [hx'] },
intros y,
revert hx,
contrapose!,
-- here we use the `ord_connected` hypothesis
exact λ hx, ht y.2 a.2 ⟨le_of_not_gt hx, le_of_lt h⟩ },
{ refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _),
by_cases hx : x ∈ t,
{ refine mem_infi_sets (Iio ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inr rfl⟩⟩ _),
exact λ _, id },
simp only [set_coe.exists, mem_set_of_eq, mem_map],
convert univ_sets _,
suffices hx' : ∀ (y : t), ↑y ∈ Iio x,
{ simp [hx'] },
intros y,
revert hx,
contrapose!,
-- here we use the `ord_connected` hypothesis
exact λ hx, ht a.2 y.2 ⟨le_of_lt h, le_of_not_gt hx⟩ } }
end
lemma nhds_top_order [topological_space α] [order_top α] [order_topology α] :
𝓝 (⊤:α) = (⨅l (h₂ : l < ⊤), 𝓟 (Ioi l)) :=
by simp [nhds_eq_order (⊤:α)]
lemma nhds_bot_order [topological_space α] [order_bot α] [order_topology α] :
𝓝 (⊥:α) = (⨅l (h₂ : ⊥ < l), 𝓟 (Iio l)) :=
by simp [nhds_eq_order (⊥:α)]
lemma tendsto_nhds_top_mono [topological_space β] [order_top β] [order_topology β] {l : filter α}
{f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) :
tendsto g l (𝓝 ⊤) :=
begin
simp only [nhds_top_order, tendsto_infi, tendsto_principal] at hf ⊢,
intros x hx,
filter_upwards [hf x hx, hg],
exact λ x, lt_of_lt_of_le
end
lemma tendsto_nhds_bot_mono [topological_space β] [order_bot β] [order_topology β] {l : filter α}
{f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) :
tendsto g l (𝓝 ⊥) :=
@tendsto_nhds_top_mono α (order_dual β) _ _ _ _ _ _ hf hg
lemma tendsto_nhds_top_mono' [topological_space β] [order_top β] [order_topology β] {l : filter α}
{f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ g) :
tendsto g l (𝓝 ⊤) :=
tendsto_nhds_top_mono hf (eventually_of_forall hg)
lemma tendsto_nhds_bot_mono' [topological_space β] [order_bot β] [order_topology β] {l : filter α}
{f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ f) :
tendsto g l (𝓝 ⊥) :=
tendsto_nhds_bot_mono hf (eventually_of_forall hg)
section linear_order
variables [topological_space α] [linear_order α] [order_topology α]
lemma exists_Ioc_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) :
∃ l' ∈ Ico l a, Ioc l' a ⊆ s :=
begin
rw [nhds_eq_order a] at hs,
rcases hs with ⟨t₁, ht₁, t₂, ht₂, hts⟩,
-- First we show that `t₂` includes `(-∞, a]`, so it suffices to show `(l', ∞) ⊆ t₁`
suffices : ∃ l' ∈ Ico l a, Ioi l' ⊆ t₁,
{ have A : 𝓟 (Iic a) ≤ ⨅ b ∈ Ioi a, 𝓟 (Iio b),
from (le_infi $ λ b, le_infi $ λ hb, principal_mono.2 $ Iic_subset_Iio.2 hb),
have B : t₁ ∩ Iic a ⊆ s,
from subset.trans (inter_subset_inter_right _ (A ht₂)) hts,
from this.imp (λ l', Exists.imp $ λ hl' hl x hx, B ⟨hl hx.1, hx.2⟩) },
clear hts ht₂ t₂,
-- Now we find `l` such that `(l', ∞) ⊆ t₁`
rw [mem_binfi] at ht₁,
{ rcases ht₁ with ⟨b, hb, hb'⟩,
exact ⟨max b l, ⟨le_max_right _ _, max_lt hb hl⟩,
λ x hx, hb' $ Ioi_subset_Ioi (le_max_left _ _) hx⟩ },
{ intros b hb b' hb', simp only [mem_Iio] at hb hb',
use [max b b', max_lt hb hb'],
simp [le_refl] },
exact ⟨l, hl⟩
end
lemma exists_Ico_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) :
∃ u' ∈ Ioc a u, Ico a u' ⊆ s :=
begin
convert @exists_Ioc_subset_of_mem_nhds' (order_dual α) _ _ _ _ _ hs _ hu,
ext, rw [dual_Ico, dual_Ioc]
end
lemma exists_Ioc_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) :
∃ l < a, Ioc l a ⊆ s :=
let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ioc_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.2, hl.snd⟩
lemma exists_Ico_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) :
∃ u (_ : a < u), Ico a u ⊆ s :=
let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.1, hl.snd⟩
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
@[priority 100] -- see Note [lower instance priority]
instance order_topology.to_order_closed_topology : order_closed_topology α :=
{ is_closed_le' :=
is_open_compl_iff.1 $ 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₁⟩ }
lemma order_topology.t2_space : t2_space α := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance order_topology.regular_space : regular_space α :=
{ regular := assume s a hs ha,
have hs' : sᶜ ∈ 𝓝 a, from mem_nhds_sets hs.is_open_compl ha,
have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ 𝓝[t] a = ⊥,
from by_cases
(assume h : ∃l, l < a,
let ⟨l, hl, h⟩ := exists_Ioc_subset_of_mem_nhds hs' 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 ⟨lt_of_lt_of_le hb₁ hbc, le_of_lt hca⟩ hcs,
inf_principal_eq_bot.2 $ (𝓝 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.2 $ (𝓝 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,
nhds_within_empty _⟩),
let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in
have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ 𝓝[t] a = ⊥,
from by_cases
(assume h : ∃u, u > a,
let ⟨u, hu, h⟩ := exists_Ico_subset_of_mem_nhds hs' 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 ⟨le_of_lt hca, lt_of_le_of_lt hbc hb₂⟩ hcs,
inf_principal_eq_bot.2 $ (𝓝 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.2 $ (𝓝 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,
nhds_within_empty _⟩),
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 [nhds_within_union, ht₁a, ht₂a, bot_sup_eq]⟩,
..order_topology.t2_space }
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`,
provided `a` is neither a bottom element nor a top element. -/
lemma mem_nhds_iff_exists_Ioo_subset' {a : α} {s : set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) :
s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s :=
begin
split,
{ assume h,
rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩,
rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩,
refine ⟨l, u, ⟨la, au⟩, λx hx, _⟩,
cases le_total a x with hax hax,
{ exact hu ⟨hax, hx.2⟩ },
{ exact hl ⟨hx.1, hax⟩ } },
{ rintros ⟨l, u, ha, h⟩,
apply mem_sets_of_superset (mem_nhds_sets is_open_Ioo ha) h }
end
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`.
-/
lemma mem_nhds_iff_exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s :=
mem_nhds_iff_exists_Ioo_subset' (no_bot a) (no_top a)
lemma nhds_basis_Ioo' {a : α} (hl : ∃l, l < a) (hu : ∃u, a < u) :
(𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) :=
⟨λ s, (mem_nhds_iff_exists_Ioo_subset' hl hu).trans $ by simp⟩
lemma nhds_basis_Ioo [no_top_order α] [no_bot_order α] {a : α} :
(𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) :=
nhds_basis_Ioo' (no_bot a) (no_top a)
lemma filter.eventually.exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {p : α → Prop}
(hp : ∀ᶠ x in 𝓝 a, p x) :
∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ {x | p x} :=
mem_nhds_iff_exists_Ioo_subset.1 hp
lemma Iio_mem_nhds {a b : α} (h : a < b) : Iio b ∈ 𝓝 a :=
mem_nhds_sets is_open_Iio h
lemma Ioi_mem_nhds {a b : α} (h : a < b) : Ioi a ∈ 𝓝 b :=
mem_nhds_sets is_open_Ioi h
lemma Iic_mem_nhds {a b : α} (h : a < b) : Iic b ∈ 𝓝 a :=
mem_sets_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self
lemma Ici_mem_nhds {a b : α} (h : a < b) : Ici a ∈ 𝓝 b :=
mem_sets_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self
lemma Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x :=
mem_nhds_sets is_open_Ioo ⟨ha, hb⟩
lemma Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x :=
mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self
lemma Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x :=
mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self
lemma Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x :=
mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self
section pi
/-!
### Intervals in `Π i, π i` belong to `𝓝 x`
For each leamma `pi_Ixx_mem_nhds` we add a non-dependent version `pi_Ixx_mem_nhds'` because
sometimes Lean fails to unify different instances while trying to apply the dependent version to,
e.g., `ι → ℝ`.
-/
variables {ι : Type*} {π : ι → Type*} [fintype ι] [Π i, linear_order (π i)]
[Π i, topological_space (π i)] [∀ i, order_topology (π i)] {a b x : Π i, π i} {a' b' x' : ι → α}
lemma pi_Iic_mem_nhds (ha : ∀ i, x i < a i) : Iic a ∈ 𝓝 x :=
pi_univ_Iic a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Iic_mem_nhds (ha _))
lemma pi_Iic_mem_nhds' (ha : ∀ i, x' i < a' i) : Iic a' ∈ 𝓝 x' :=
pi_Iic_mem_nhds ha
lemma pi_Ici_mem_nhds (ha : ∀ i, a i < x i) : Ici a ∈ 𝓝 x :=
pi_univ_Ici a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Ici_mem_nhds (ha _))
lemma pi_Ici_mem_nhds' (ha : ∀ i, a' i < x' i) : Ici a' ∈ 𝓝 x' :=
pi_Ici_mem_nhds ha
lemma pi_Icc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Icc a b ∈ 𝓝 x :=
pi_univ_Icc a b ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Icc_mem_nhds (ha _) (hb _))
lemma pi_Icc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Icc a' b' ∈ 𝓝 x' :=
pi_Icc_mem_nhds ha hb
variables [nonempty ι]
lemma pi_Iio_mem_nhds (ha : ∀ i, x i < a i) : Iio a ∈ 𝓝 x :=
begin
refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _))
(pi_univ_Iio_subset a),
exact Iio_mem_nhds (ha i)
end
lemma pi_Iio_mem_nhds' (ha : ∀ i, x' i < a' i) : Iio a' ∈ 𝓝 x' :=
pi_Iio_mem_nhds ha
lemma pi_Ioi_mem_nhds (ha : ∀ i, a i < x i) : Ioi a ∈ 𝓝 x :=
@pi_Iio_mem_nhds ι (λ i, order_dual (π i)) _ _ _ _ _ _ _ ha
lemma pi_Ioi_mem_nhds' (ha : ∀ i, a' i < x' i) : Ioi a' ∈ 𝓝 x' :=
pi_Ioi_mem_nhds ha
lemma pi_Ioc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioc a b ∈ 𝓝 x :=
begin
refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _))
(pi_univ_Ioc_subset a b),
exact Ioc_mem_nhds (ha i) (hb i)
end
lemma pi_Ioc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioc a' b' ∈ 𝓝 x' :=
pi_Ioc_mem_nhds ha hb
lemma pi_Ico_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ico a b ∈ 𝓝 x :=
begin
refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _))
(pi_univ_Ico_subset a b),
exact Ico_mem_nhds (ha i) (hb i)
end
lemma pi_Ico_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ico a' b' ∈ 𝓝 x' :=
pi_Ico_mem_nhds ha hb
lemma pi_Ioo_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioo a b ∈ 𝓝 x :=
begin
refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _))
(pi_univ_Ioo_subset a b),
exact Ioo_mem_nhds (ha i) (hb i)
end
lemma pi_Ioo_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioo a' b' ∈ 𝓝 x' :=
pi_Ioo_mem_nhds ha hb
end pi
lemma disjoint_nhds_at_top [no_top_order α] (x : α) :
disjoint (𝓝 x) at_top :=
begin
rw filter.disjoint_iff,
cases no_top x with a ha,
use [Iio a, Iio_mem_nhds ha, Ici a, mem_at_top a],
rw [inter_comm, Ici_inter_Iio, Ico_self]
end
@[simp] lemma inf_nhds_at_top [no_top_order α] (x : α) :
𝓝 x ⊓ at_top = ⊥ :=
disjoint_iff.1 (disjoint_nhds_at_top x)
lemma disjoint_nhds_at_bot [no_bot_order α] (x : α) :
disjoint (𝓝 x) at_bot :=
@disjoint_nhds_at_top (order_dual α) _ _ _ _ x
@[simp] lemma inf_nhds_at_bot [no_bot_order α] (x : α) :
𝓝 x ⊓ at_bot = ⊥ :=
@inf_nhds_at_top (order_dual α) _ _ _ _ x
lemma not_tendsto_nhds_of_tendsto_at_top [no_top_order α]
{F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_top) (x : α) :
¬ tendsto f F (𝓝 x) :=
hf.not_tendsto (disjoint_nhds_at_top x).symm
lemma not_tendsto_at_top_of_tendsto_nhds [no_top_order α]
{F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) :
¬ tendsto f F at_top :=
hf.not_tendsto (disjoint_nhds_at_top x)
lemma not_tendsto_nhds_of_tendsto_at_bot [no_bot_order α]
{F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_bot) (x : α) :
¬ tendsto f F (𝓝 x) :=
hf.not_tendsto (disjoint_nhds_at_bot x).symm
lemma not_tendsto_at_bot_of_tendsto_nhds [no_bot_order α]
{F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) :
¬ tendsto f F at_bot :=
hf.not_tendsto (disjoint_nhds_at_bot x)
/-!
### Neighborhoods to the left and to the right on an `order_topology`
We've seen some properties of left and right neighborhood of a point in an `order_closed_topology`.
In an `order_topology`, such neighborhoods can be characterized as the sets containing suitable
intervals to the right or to the left of `a`. We give now these characterizations. -/
-- NB: If you extend the list, append to the end please to avoid breaking the API
/-- The following statements are equivalent:
0. `s` is a neighborhood of `a` within `(a, +∞)`
1. `s` is a neighborhood of `a` within `(a, b]`
2. `s` is a neighborhood of `a` within `(a, b)`
3. `s` includes `(a, u)` for some `u ∈ (a, b]`
4. `s` includes `(a, u)` for some `u > a` -/
lemma tfae_mem_nhds_within_Ioi {a b : α} (hab : a < b) (s : set α) :
tfae [s ∈ 𝓝[Ioi a] a, -- 0 : `s` is a neighborhood of `a` within `(a, +∞)`
s ∈ 𝓝[Ioc a b] a, -- 1 : `s` is a neighborhood of `a` within `(a, b]`
s ∈ 𝓝[Ioo a b] a, -- 2 : `s` is a neighborhood of `a` within `(a, b)`
∃ u ∈ Ioc a b, Ioo a u ⊆ s, -- 3 : `s` includes `(a, u)` for some `u ∈ (a, b]`
∃ u ∈ Ioi a, Ioo a u ⊆ s] := -- 4 : `s` includes `(a, u)` for some `u > a`
begin
tfae_have : 1 ↔ 2, by rw [nhds_within_Ioc_eq_nhds_within_Ioi hab],
tfae_have : 1 ↔ 3, by rw [nhds_within_Ioo_eq_nhds_within_Ioi hab],
tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩,
tfae_have : 5 → 1,
{ rintros ⟨u, hau, hu⟩,
exact mem_sets_of_superset (Ioo_mem_nhds_within_Ioi ⟨le_refl a, hau⟩) hu },
tfae_have : 1 → 4,
{ assume h,
rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩,
rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩,
refine ⟨u, au, λx hx, _⟩,
refine hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, _⟩,
exact hx.1 },
tfae_finish
end
lemma mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : set α} (hu' : a < u') :
s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioc a u', Ioo a u ⊆ s :=
(tfae_mem_nhds_within_Ioi hu' s).out 0 3
/-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)`
with `a < u < u'`, provided `a` is not a top element. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset' {a u' : α} {s : set α} (hu' : a < u') :
s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s :=
(tfae_mem_nhds_within_Ioi hu' s).out 0 4
/-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)`
with `a < u`. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset [no_top_order α] {a : α} {s : set α} :
s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s :=
let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ioi_iff_exists_Ioo_subset' hu'
/-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]`
with `a < u`. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioc_subset [no_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioc a u ⊆ s :=
begin
rw mem_nhds_within_Ioi_iff_exists_Ioo_subset,
split,
{ rintros ⟨u, au, as⟩,
rcases exists_between au with ⟨v, hv⟩,
exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ },
{ rintros ⟨u, au, as⟩,
exact ⟨u, au, subset.trans Ioo_subset_Ioc_self as⟩ }
end
/-- The following statements are equivalent:
0. `s` is a neighborhood of `b` within `(-∞, b)`
1. `s` is a neighborhood of `b` within `[a, b)`
2. `s` is a neighborhood of `b` within `(a, b)`
3. `s` includes `(l, b)` for some `l ∈ [a, b)`
4. `s` includes `(l, b)` for some `l < b` -/
lemma tfae_mem_nhds_within_Iio {a b : α} (h : a < b) (s : set α) :
tfae [s ∈ 𝓝[Iio b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b)`
s ∈ 𝓝[Ico a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b)`
s ∈ 𝓝[Ioo a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b)`
∃ l ∈ Ico a b, Ioo l b ⊆ s, -- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)`
∃ l ∈ Iio b, Ioo l b ⊆ s] := -- 4 : `s` includes `(l, b)` for some `l < b`
begin
have := @tfae_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ h s,
-- If we call `convert` here, it generates wrong equations, so we need to simplify first
simp only [exists_prop] at this ⊢,
rw [dual_Ioi, dual_Ioc, dual_Ioo] at this,
convert this; ext l; rw [dual_Ioo]
end
lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Ico l' a, Ioo l a ⊆ s :=
(tfae_mem_nhds_within_Iio hl' s).out 0 3
/-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)`
with `l < a`, provided `a` is not a bottom element. -/
lemma mem_nhds_within_Iio_iff_exists_Ioo_subset' {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s :=
(tfae_mem_nhds_within_Iio hl' s).out 0 4
/-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)`
with `l < a`. -/
lemma mem_nhds_within_Iio_iff_exists_Ioo_subset [no_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s :=
let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iio_iff_exists_Ioo_subset' hl'
/-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)`
with `l < a`. -/
lemma mem_nhds_within_Iio_iff_exists_Ico_subset [no_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ico l a ⊆ s :=
begin
convert @mem_nhds_within_Ioi_iff_exists_Ioc_subset (order_dual α) _ _ _ _ _ _ _,
simp only [dual_Ioc], refl
end
/-- The following statements are equivalent:
0. `s` is a neighborhood of `a` within `[a, +∞)`
1. `s` is a neighborhood of `a` within `[a, b]`
2. `s` is a neighborhood of `a` within `[a, b)`
3. `s` includes `[a, u)` for some `u ∈ (a, b]`
4. `s` includes `[a, u)` for some `u > a` -/
lemma tfae_mem_nhds_within_Ici {a b : α} (hab : a < b) (s : set α) :
tfae [s ∈ 𝓝[Ici a] a, -- 0 : `s` is a neighborhood of `a` within `[a, +∞)`
s ∈ 𝓝[Icc a b] a, -- 1 : `s` is a neighborhood of `a` within `[a, b]`
s ∈ 𝓝[Ico a b] a, -- 2 : `s` is a neighborhood of `a` within `[a, b)`
∃ u ∈ Ioc a b, Ico a u ⊆ s, -- 3 : `s` includes `[a, u)` for some `u ∈ (a, b]`
∃ u ∈ Ioi a, Ico a u ⊆ s] := -- 4 : `s` includes `[a, u)` for some `u > a`
begin
tfae_have : 1 ↔ 2, by rw [nhds_within_Icc_eq_nhds_within_Ici hab],
tfae_have : 1 ↔ 3, by rw [nhds_within_Ico_eq_nhds_within_Ici hab],
tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩,
tfae_have : 5 → 1,
{ rintros ⟨u, hau, hu⟩,
exact mem_sets_of_superset (Ico_mem_nhds_within_Ici ⟨le_refl a, hau⟩) hu },
tfae_have : 1 → 4,
{ assume h,
rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩,
rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩,
refine ⟨u, au, λx hx, _⟩,
refine hv ⟨hu ⟨hx.1, hx.2⟩, _⟩,
exact hx.1 },
tfae_finish
end
lemma mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : set α} (hu' : a < u') :
s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioc a u', Ico a u ⊆ s :=
(tfae_mem_nhds_within_Ici hu' s).out 0 3 (by norm_num) (by norm_num)
/-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)`
with `a < u < u'`, provided `a` is not a top element. -/
lemma mem_nhds_within_Ici_iff_exists_Ico_subset' {a u' : α} {s : set α} (hu' : a < u') :
s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s :=
(tfae_mem_nhds_within_Ici hu' s).out 0 4 (by norm_num) (by norm_num)
/-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)`
with `a < u`. -/
lemma mem_nhds_within_Ici_iff_exists_Ico_subset [no_top_order α] {a : α} {s : set α} :
s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s :=
let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ici_iff_exists_Ico_subset' hu'
/-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]`
with `a < u`. -/
lemma mem_nhds_within_Ici_iff_exists_Icc_subset' [no_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Icc a u ⊆ s :=
begin
rw mem_nhds_within_Ici_iff_exists_Ico_subset,
split,
{ rintros ⟨u, au, as⟩,
rcases exists_between au with ⟨v, hv⟩,
exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ },
{ rintros ⟨u, au, as⟩,
exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ }
end
/-- The following statements are equivalent:
0. `s` is a neighborhood of `b` within `(-∞, b]`
1. `s` is a neighborhood of `b` within `[a, b]`
2. `s` is a neighborhood of `b` within `(a, b]`
3. `s` includes `(l, b]` for some `l ∈ [a, b)`
4. `s` includes `(l, b]` for some `l < b` -/
lemma tfae_mem_nhds_within_Iic {a b : α} (h : a < b) (s : set α) :
tfae [s ∈ 𝓝[Iic b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b]`
s ∈ 𝓝[Icc a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b]`
s ∈ 𝓝[Ioc a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b]`
∃ l ∈ Ico a b, Ioc l b ⊆ s, -- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)`
∃ l ∈ Iio b, Ioc l b ⊆ s] := -- 4 : `s` includes `(l, b]` for some `l < b`
begin
have := @tfae_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ h s,
-- If we call `convert` here, it generates wrong equations, so we need to simplify first
simp only [exists_prop] at this ⊢,
rw [dual_Icc, dual_Ioc, dual_Ioi] at this,
convert this; ext l; rw [dual_Ico]
end
lemma mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Ico l' a, Ioc l a ⊆ s :=
(tfae_mem_nhds_within_Iic hl' s).out 0 3 (by norm_num) (by norm_num)
/-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]`
with `l < a`, provided `a` is not a bottom element. -/
lemma mem_nhds_within_Iic_iff_exists_Ioc_subset' {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s :=
(tfae_mem_nhds_within_Iic hl' s).out 0 4 (by norm_num) (by norm_num)
/-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]`
with `l < a`. -/
lemma mem_nhds_within_Iic_iff_exists_Ioc_subset [no_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s :=
let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iic_iff_exists_Ioc_subset' hl'
/-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]`
with `l < a`. -/
lemma mem_nhds_within_Iic_iff_exists_Icc_subset' [no_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Icc l a ⊆ s :=
begin
convert @mem_nhds_within_Ici_iff_exists_Icc_subset' (order_dual α) _ _ _ _ _ _ _,
simp_rw (show ∀ u : order_dual α, @Icc (order_dual α) _ a u = @Icc α _ u a, from λ u, dual_Icc),
refl,
end
/-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]`
with `a < u`. -/
lemma mem_nhds_within_Ici_iff_exists_Icc_subset [no_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u, a < u ∧ Icc a u ⊆ s :=
begin
rw mem_nhds_within_Ici_iff_exists_Ico_subset,
split,
{ rintros ⟨u, au, as⟩,
rcases exists_between au with ⟨v, hv⟩,
exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ },
{ rintros ⟨u, au, as⟩,
exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ }
end
/-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]`
with `l < a`. -/
lemma mem_nhds_within_Iic_iff_exists_Icc_subset [no_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l, l < a ∧ Icc l a ⊆ s :=
begin
rw mem_nhds_within_Iic_iff_exists_Ioc_subset,
split,
{ rintros ⟨l, la, as⟩,
rcases exists_between la with ⟨v, hv⟩,
refine ⟨v, hv.2, λx hx, as ⟨lt_of_lt_of_le hv.1 hx.1, hx.2⟩⟩, },
{ rintros ⟨l, la, as⟩,
exact ⟨l, la, subset.trans Ioc_subset_Icc_self as⟩ }
end
end linear_order
section linear_ordered_add_comm_group
variables [topological_space α] [linear_ordered_add_comm_group α] [order_topology α]
variables {l : filter β} {f g : β → α}
local notation `|` x `|` := abs x
lemma nhds_eq_infi_abs_sub (a : α) : 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r}) :=
begin
simp only [le_antisymm_iff, nhds_eq_order, le_inf_iff, le_infi_iff, le_principal_iff, mem_Ioi,
mem_Iio, abs_sub_lt_iff, @sub_lt_iff_lt_add _ _ _ _ a, @sub_lt _ _ a, set_of_and],
refine ⟨_, _, _⟩,
{ intros ε ε0,
exact inter_mem_inf_sets
(mem_infi_sets (a - ε) $ mem_infi_sets (sub_lt_self a ε0) (mem_principal_self _))
(mem_infi_sets (ε + a) $ mem_infi_sets (by simpa) (mem_principal_self _)) },
{ intros b hb,
exact mem_infi_sets (a - b) (mem_infi_sets (sub_pos.2 hb) (by simp [Ioi])) },
{ intros b hb,
exact mem_infi_sets (b - a) (mem_infi_sets (sub_pos.2 hb) (by simp [Iio])) }
end
lemma order_topology_of_nhds_abs {α : Type*} [topological_space α] [linear_ordered_add_comm_group α]
(h_nhds : ∀a:α, 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r})) : order_topology α :=
begin
refine ⟨eq_of_nhds_eq_nhds $ λ a, _⟩,
rw [h_nhds],
letI := preorder.topology α, letI : order_topology α := ⟨rfl⟩,
exact (nhds_eq_infi_abs_sub a).symm
end
lemma linear_ordered_add_comm_group.tendsto_nhds {x : filter β} {a : α} :
tendsto f x (𝓝 a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε :=
by simp [nhds_eq_infi_abs_sub, abs_sub a]
lemma eventually_abs_sub_lt (a : α) {ε : α} (hε : 0 < ε) : ∀ᶠ x in 𝓝 a, |x - a| < ε :=
(nhds_eq_infi_abs_sub a).symm ▸ mem_infi_sets ε
(mem_infi_sets hε $ by simp only [abs_sub, mem_principal_self])
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_add_comm_group.topological_add_group : topological_add_group α :=
{ continuous_add :=
begin
refine continuous_iff_continuous_at.2 _,
rintro ⟨a, b⟩,
refine linear_ordered_add_comm_group.tendsto_nhds.2 (λ ε ε0, _),
rcases dense_or_discrete 0 ε with (⟨δ, δ0, δε⟩|⟨h₁, h₂⟩),
{ -- If there exists `δ ∈ (0, ε)`, then we choose `δ`-nhd of `a` and `(ε-δ)`-nhd of `b`
filter_upwards [prod_mem_nhds_sets (eventually_abs_sub_lt a δ0)
(eventually_abs_sub_lt b (sub_pos.2 δε))],
rintros ⟨x, y⟩ ⟨hx : |x - a| < δ, hy : |y - b| < ε - δ⟩,
rw [add_sub_comm],
calc |x - a + (y - b)| ≤ |x - a| + |y - b| : abs_add _ _
... < δ + (ε - δ) : add_lt_add hx hy
... = ε : add_sub_cancel'_right _ _ },
{ -- Otherewise `ε`-nhd of each point `a` is `{a}`
have hε : ∀ {x y}, abs (x - y) < ε → x = y,
{ intros x y h,
simpa [sub_eq_zero] using h₂ _ h },
filter_upwards [prod_mem_nhds_sets (eventually_abs_sub_lt a ε0)
(eventually_abs_sub_lt b ε0)],
rintros ⟨x, y⟩ ⟨hx : |x - a| < ε, hy : |y - b| < ε⟩,
simpa [hε hx, hε hy] }
end,
continuous_neg := continuous_iff_continuous_at.2 $ λ a,
linear_ordered_add_comm_group.tendsto_nhds.2 $ λ ε ε0,
(eventually_abs_sub_lt a ε0).mono $ λ x hx, by rwa [neg_sub_neg, abs_sub] }
@[continuity]
lemma continuous_abs : continuous (abs : α → α) := continuous_id.max continuous_neg
lemma filter.tendsto.abs {f : β → α} {a : α} {l : filter β} (h : tendsto f l (𝓝 a)) :
tendsto (λ x, |f x|) l (𝓝 (|a|)) :=
(continuous_abs.tendsto _).comp h
section
variables [topological_space β] {b : β} {a : α} {s : set β}
lemma continuous.abs (h : continuous f) : continuous (λ x, |f x|) := continuous_abs.comp h
lemma continuous_at.abs (h : continuous_at f b) : continuous_at (λ x, |f x|) b := h.abs
lemma continuous_within_at.abs (h : continuous_within_at f s b) :
continuous_within_at (λ x, |f x|) s b := h.abs
lemma continuous_on.abs (h : continuous_on f s) : continuous_on (λ x, |f x|) s :=
λ x hx, (h x hx).abs
lemma tendsto_abs_nhds_within_zero : tendsto (abs : α → α) (𝓝[{0}ᶜ] 0) (𝓝[Ioi 0] 0) :=
(continuous_abs.tendsto' (0 : α) 0 abs_zero).inf $ tendsto_principal_principal.2 $ λ x, abs_pos.2
end
/-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C`
and `g` tends to `at_top` then `f + g` tends to `at_top`. -/
lemma filter.tendsto.add_at_top {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
begin
nontriviality α,
obtain ⟨C', hC'⟩ : ∃ C', C' < C := no_bot C,
refine tendsto_at_top_add_left_of_le' _ C' _ hg,
exact (hf.eventually (lt_mem_nhds hC')).mono (λ x, le_of_lt)
end
/-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C`
and `g` tends to `at_bot` then `f + g` tends to `at_bot`. -/
lemma filter.tendsto.add_at_bot {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
@filter.tendsto.add_at_top (order_dual α) _ _ _ _ _ _ _ _ hf hg
/-- In a linearly ordered additive commutative group with the order topology, if `f` tends to
`at_top` and `g` tends to `C` then `f + g` tends to `at_top`. -/
lemma filter.tendsto.at_top_add {C : α} (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, f x + g x) l at_top :=
by { conv in (_ + _) { rw add_comm }, exact hg.add_at_top hf }
/-- In a linearly ordered additive commutative group with the order topology, if `f` tends to
`at_bot` and `g` tends to `C` then `f + g` tends to `at_bot`. -/
lemma filter.tendsto.at_bot_add {C : α} (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, f x + g x) l at_bot :=
by { conv in (_ + _) { rw add_comm }, exact hg.add_at_bot hf }
end linear_ordered_add_comm_group
section linear_ordered_field
variables [linear_ordered_field α] [topological_space α] [order_topology α]
variables {l : filter β} {f g : β → α}
/-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to
a positive constant `C` then `f * g` tends to `at_top`. -/
lemma filter.tendsto.at_top_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_top)
(hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_top :=
begin
refine tendsto_at_top_mono' _ _ (hf.at_top_mul_const (half_pos hC)),
filter_upwards [hg.eventually (lt_mem_nhds (half_lt_self hC)),
hf.eventually (eventually_ge_at_top 0)],
exact λ x hg hf, mul_le_mul_of_nonneg_left hg.le hf
end
/-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and
`g` tends to `at_top` then `f * g` tends to `at_top`. -/
lemma filter.tendsto.mul_at_top {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C))
(hg : tendsto g l at_top) :
tendsto (λ x, (f x * g x)) l at_top :=
by simpa only [mul_comm] using hg.at_top_mul hC hf
/-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to
a negative constant `C` then `f * g` tends to `at_bot`. -/
lemma filter.tendsto.at_top_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_top)
(hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_bot :=
by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg]
using tendsto_neg_at_top_at_bot.comp (hf.at_top_mul (neg_pos.2 hC) hg.neg)
/-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and
`g` tends to `at_top` then `f * g` tends to `at_bot`. -/
lemma filter.tendsto.neg_mul_at_top {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C))
(hg : tendsto g l at_top) :
tendsto (λ x, (f x * g x)) l at_bot :=
by simpa only [mul_comm] using hg.at_top_mul_neg hC hf
/-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to
a positive constant `C` then `f * g` tends to `at_bot`. -/
lemma filter.tendsto.at_bot_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_bot)
(hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_bot :=
by simpa [(∘)]
using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul hC hg)
/-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to
a negative constant `C` then `f * g` tends to `at_top`. -/
lemma filter.tendsto.at_bot_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_bot)
(hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_top :=
by simpa [(∘)]
using tendsto_neg_at_bot_at_top.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul_neg hC hg)
/-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and
`g` tends to `at_bot` then `f * g` tends to `at_bot`. -/
lemma filter.tendsto.mul_at_bot {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C))
(hg : tendsto g l at_bot) :
tendsto (λ x, (f x * g x)) l at_bot :=
by simpa only [mul_comm] using hg.at_bot_mul hC hf
/-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and
`g` tends to `at_bot` then `f * g` tends to `at_top`. -/
lemma filter.tendsto.neg_mul_at_bot {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C))
(hg : tendsto g l at_bot) :
tendsto (λ x, (f x * g x)) l at_top :=
by simpa only [mul_comm] using hg.at_bot_mul_neg hC hf
/-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/
lemma tendsto_inv_zero_at_top : tendsto (λx:α, x⁻¹) (𝓝[set.Ioi (0:α)] 0) at_top :=
begin
refine (at_top_basis' 1).tendsto_right_iff.2 (λ b hb, _),
have hb' : 0 < b := zero_lt_one.trans_le hb,
filter_upwards [Ioc_mem_nhds_within_Ioi ⟨le_rfl, inv_pos.2 hb'⟩],
exact λ x hx, (le_inv hx.1 hb').1 hx.2
end
/-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/
lemma tendsto_inv_at_top_zero' : tendsto (λr:α, r⁻¹) at_top (𝓝[set.Ioi (0:α)] 0) :=
begin
refine (has_basis.tendsto_iff at_top_basis ⟨λ s, mem_nhds_within_Ioi_iff_exists_Ioc_subset⟩).2 _,
refine λ b hb, ⟨b⁻¹, trivial, λ x hx, _⟩,
have : 0 < x := lt_of_lt_of_le (inv_pos.2 hb) hx,
exact ⟨inv_pos.2 this, (inv_le this hb).2 hx⟩
end
lemma tendsto_inv_at_top_zero : tendsto (λr:α, r⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero'.mono_right inf_le_left
lemma filter.tendsto.div_at_top [has_continuous_mul α] {f g : β → α} {l : filter β} {a : α}
(h : tendsto f l (𝓝 a)) (hg : tendsto g l at_top) : tendsto (λ x, f x / g x) l (𝓝 0) :=
by { simp only [div_eq_mul_inv], exact mul_zero a ▸ h.mul (tendsto_inv_at_top_zero.comp hg) }
lemma filter.tendsto.inv_tendsto_at_top (h : tendsto f l at_top) : tendsto (f⁻¹) l (𝓝 0) :=
tendsto_inv_at_top_zero.comp h
lemma filter.tendsto.inv_tendsto_zero (h : tendsto f l (𝓝[set.Ioi 0] 0)) :
tendsto (f⁻¹) l at_top :=
tendsto_inv_zero_at_top.comp h
/-- The function `x^(-n)` tends to `0` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_neg_at_top`. -/
lemma tendsto_pow_neg_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ (-(n:ℤ))) at_top (𝓝 0) :=
tendsto.congr (λ x, (fpow_neg x n).symm)
(filter.tendsto.inv_tendsto_at_top (tendsto_pow_at_top hn))
lemma tendsto_fpow_at_top_zero {n : ℤ} (hn : n < 0) :
tendsto (λ x : α, x^n) at_top (𝓝 0) :=
begin
have : 1 ≤ -n, by linarith,
apply tendsto.congr (show ∀ x : α, x^-(-n) = x^n, by simp),
lift -n to ℕ using le_of_lt (neg_pos.mpr hn) with N,
exact tendsto_pow_neg_at_top (by exact_mod_cast this)
end
end linear_ordered_field
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 order_topology
variables [topological_space α] [topological_space β]
[linear_order α] [linear_order β] [order_topology α] [order_topology β]
lemma is_lub.frequently_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
∃ᶠ x in 𝓝[Iic a] a, x ∈ s :=
begin
rcases hs with ⟨a', ha'⟩,
intro h,
rcases (ha.1 ha').eq_or_lt with (rfl|ha'a),
{ exact h.self_of_nhds_within le_rfl ha' },
{ rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' ha'a).1 h
with ⟨b, hba, hb⟩,
rcases ha.exists_between hba with ⟨b', hb's, hb'⟩,
exact hb hb' hb's },
end
lemma is_lub.frequently_nhds_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
∃ᶠ x in 𝓝 a, x ∈ s :=
(ha.frequently_mem hs).filter_mono inf_le_left
lemma is_glb.frequently_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) :
∃ᶠ x in 𝓝[Ici a] a, x ∈ s :=
@is_lub.frequently_mem (order_dual α) _ _ _ _ _ ha hs
lemma is_glb.frequently_nhds_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) :
∃ᶠ x in 𝓝 a, x ∈ s :=
(ha.frequently_mem hs).filter_mono inf_le_left
lemma is_lub.mem_closure {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
a ∈ closure s :=
(ha.frequently_nhds_mem hs).mem_closure
lemma is_glb.mem_closure {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) :
a ∈ closure s :=
(ha.frequently_nhds_mem hs).mem_closure
lemma is_lub.nhds_within_ne_bot {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
ne_bot (𝓝[s] a) :=
mem_closure_iff_nhds_within_ne_bot.1 (ha.mem_closure hs)
lemma is_glb.nhds_within_ne_bot : ∀ {a : α} {s : set α}, is_glb s a → s.nonempty →
ne_bot (𝓝[s] a) :=
@is_lub.nhds_within_ne_bot (order_dual α) _ _ _
lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α}
(hsa : a ∈ upper_bounds s) (hsf : s ∈ f) [ne_bot (f ⊓ 𝓝 a)] : is_lub s a :=
⟨hsa, assume b hb,
not_lt.1 $ assume hba,
have s ∩ {a | b < a} ∈ f ⊓ 𝓝 a,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := nonempty_of_mem_sets 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 → ne_bot (f ⊓ 𝓝 a) → is_glb s a :=
@is_lub_of_mem_nhds (order_dual α) _ _ _
lemma is_lub.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) :=
begin
rintro _ ⟨x, hx, rfl⟩,
replace ha := ha.inter_Ici_of_mem hx,
haveI := ha.nhds_within_ne_bot ⟨x, hx, le_rfl⟩,
refine ge_of_tendsto (hb.mono_left (nhds_within_mono _ (inter_subset_left s (Ici x)))) _,
exact mem_sets_of_superset self_mem_nhds_within (λ y hy, hf _ hx _ hy.1 hy.2)
end
lemma is_lub.is_lub_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s.nonempty)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : is_lub (f '' s) b :=
begin
haveI := ha.nhds_within_ne_bot hs,
exact ⟨ha.mem_upper_bounds_of_tendsto hf hb, λ b' hb', le_of_tendsto hb
(mem_sets_of_superset self_mem_nhds_within $ λ x hx, hb' $ mem_image_of_mem _ hx)⟩
end
lemma is_glb.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_glb s a)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) :=
@is_lub.mem_upper_bounds_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ _ _ _ _
(λ x hx y hy, hf y hy x hx) ha hb
lemma is_glb.is_glb_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b :=
@is_lub.is_lub_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ f s a b
(λ x hx y hy, hf y hy x hx)
lemma is_lub.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_lub s a)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) :=
@is_lub.mem_upper_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb
lemma is_lub.is_glb_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b :=
@is_lub.is_lub_of_tendsto α (order_dual γ) _ _ _ _ _ _
lemma is_glb.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_glb s a)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) :=
@is_glb.mem_lower_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb
lemma is_glb.is_lub_of_tendsto [preorder γ] [topological_space γ]
[order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_lub (f '' s) b :=
@is_glb.is_glb_of_tendsto α (order_dual γ) _ _ _ _ _ _
lemma is_lub.mem_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty)
(sc : is_closed s) : a ∈ s :=
sc.closure_subset $ ha.mem_closure hs
alias is_lub.mem_of_is_closed ← is_closed.is_lub_mem
lemma is_glb.mem_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty)
(sc : is_closed s) : a ∈ s :=
sc.closure_subset $ ha.mem_closure hs
alias is_glb.mem_of_is_closed ← is_closed.is_glb_mem
/-- A compact set is bounded below -/
lemma is_compact.bdd_below {α : Type u} [topological_space α] [linear_order α]
[order_closed_topology α] [nonempty α] {s : set α} (hs : is_compact s) : bdd_below s :=
begin
by_contra H,
rcases hs.elim_finite_subcover_image (λ x (_ : x ∈ s), @is_open_Ioi _ _ _ _ x) _
with ⟨t, st, ft, ht⟩,
{ refine H (ft.bdd_below.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 is_compact.bdd_above {α : Type u} [topological_space α] [linear_order α]
[order_topology α] : Π [nonempty α] {s : set α}, is_compact s → bdd_above s :=
@is_compact.bdd_below (order_dual α) _ _ _
end order_topology
section linear_order
variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α]
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top
element. -/
lemma closure_Ioi' {a b : α} (hab : a < b) :
closure (Ioi a) = Ici a :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioi_subset_Ici_self is_closed_Ici },
{ rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff],
exact is_glb_Ioi.mem_closure ⟨_, hab⟩ }
end
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/
@[simp] lemma closure_Ioi (a : α) [no_top_order α] :
closure (Ioi a) = Ici a :=
let ⟨b, hb⟩ := no_top a in closure_Ioi' hb
/-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom
element. -/
lemma closure_Iio' {a b : α} (hab : b < a) :
closure (Iio a) = Iic a :=
@closure_Ioi' (order_dual α) _ _ _ _ _ _ hab
/-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/
@[simp] lemma closure_Iio (a : α) [no_bot_order α] :
closure (Iio a) = Iic a :=
let ⟨b, hb⟩ := no_bot a in closure_Iio' hb
/-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/
@[simp] lemma closure_Ioo {a b : α} (hab : a < b) :
closure (Ioo a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioo_subset_Icc_self is_closed_Icc },
{ rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le],
have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab,
simp only [insert_subset, singleton_subset_iff],
exact ⟨(is_glb_Ioo hab).mem_closure hab', (is_lub_Ioo hab).mem_closure hab'⟩ }
end
/-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/
@[simp] lemma closure_Ioc {a b : α} (hab : a < b) :
closure (Ioc a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioc_subset_Icc_self is_closed_Icc },
{ apply subset.trans _ (closure_mono Ioo_subset_Ioc_self),
rw closure_Ioo hab }
end
/-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/
@[simp] lemma closure_Ico {a b : α} (hab : a < b) :
closure (Ico a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ico_subset_Icc_self is_closed_Icc },
{ apply subset.trans _ (closure_mono Ioo_subset_Ico_self),
rw closure_Ioo hab }
end
@[simp] lemma interior_Ici [no_bot_order α] {a : α} : interior (Ici a) = Ioi a :=
by rw [← compl_Iio, interior_compl, closure_Iio, compl_Iic]
@[simp] lemma interior_Iic [no_top_order α] {a : α} : interior (Iic a) = Iio a :=
by rw [← compl_Ioi, interior_compl, closure_Ioi, compl_Ici]
@[simp] lemma interior_Icc [no_bot_order α] [no_top_order α] {a b : α}:
interior (Icc a b) = Ioo a b :=
by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio]
@[simp] lemma interior_Ico [no_bot_order α] {a b : α} : interior (Ico a b) = Ioo a b :=
by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio]
@[simp] lemma interior_Ioc [no_top_order α] {a b : α} : interior (Ioc a b) = Ioo a b :=
by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio]
@[simp] lemma frontier_Ici [no_bot_order α] {a : α} : frontier (Ici a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Iic [no_top_order α] {a : α} : frontier (Iic a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Ioi [no_top_order α] {a : α} : frontier (Ioi a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Iio [no_bot_order α] {a : α} : frontier (Iio a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Icc [no_bot_order α] [no_top_order α] {a b : α} (h : a < b) :
frontier (Icc a b) = {a, b} :=
by simp [frontier, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ico [no_bot_order α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ioc [no_top_order α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
lemma nhds_within_Ioi_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : a ≤ b) :
ne_bot (𝓝[Ioi a] b) :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Ioi' H₁], exact H₂ }
lemma nhds_within_Ioi_ne_bot [no_top_order α] {a b : α} (H : a ≤ b) :
ne_bot (𝓝[Ioi a] b) :=
let ⟨c, hc⟩ := no_top a in nhds_within_Ioi_ne_bot' hc H
lemma nhds_within_Ioi_self_ne_bot' {a b : α} (H : a < b) :
ne_bot (𝓝[Ioi a] a) :=
nhds_within_Ioi_ne_bot' H (le_refl a)
@[instance]
lemma nhds_within_Ioi_self_ne_bot [no_top_order α] (a : α) :
ne_bot (𝓝[Ioi a] a) :=
nhds_within_Ioi_ne_bot (le_refl a)
lemma nhds_within_Iio_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : b ≤ c) :
ne_bot (𝓝[Iio c] b) :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Iio' H₁], exact H₂ }
lemma nhds_within_Iio_ne_bot [no_bot_order α] {a b : α} (H : a ≤ b) :
ne_bot (𝓝[Iio b] a) :=
let ⟨c, hc⟩ := no_bot b in nhds_within_Iio_ne_bot' hc H
lemma nhds_within_Iio_self_ne_bot' {a b : α} (H : a < b) :
ne_bot (𝓝[Iio b] b) :=
nhds_within_Iio_ne_bot' H (le_refl b)
@[instance]
lemma nhds_within_Iio_self_ne_bot [no_bot_order α] (a : α) :
ne_bot (𝓝[Iio a] a) :=
nhds_within_Iio_ne_bot (le_refl a)
end linear_order
section linear_order
variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α]
{a b : α} {s : set α}
lemma comap_coe_nhds_within_Iio_of_Ioo_subset (hb : s ⊆ Iio b)
(hs : s.nonempty → ∃ a < b, Ioo a b ⊆ s) :
comap (coe : s → α) (𝓝[Iio b] b) = at_top :=
begin
nontriviality,
haveI : nonempty s := nontrivial_iff_nonempty.1 ‹_›,
rcases hs (nonempty_subtype.1 ‹_›) with ⟨a, h, hs⟩,
ext u, split,
{ rintros ⟨t, ht, hts⟩,
obtain ⟨x, ⟨hxa : a ≤ x, hxb : x < b⟩, hxt : Ioo x b ⊆ t⟩ :=
(mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset h).mp ht,
obtain ⟨y, hxy, hyb⟩ := exists_between hxb,
refine mem_sets_of_superset (mem_at_top ⟨y, hs ⟨hxa.trans_lt hxy, hyb⟩⟩) _,
rintros ⟨z, hzs⟩ (hyz : y ≤ z),
refine hts (hxt ⟨hxy.trans_le _, hb _⟩); assumption },
{ intros hu,
obtain ⟨x : s, hx : ∀ z, x ≤ z → z ∈ u⟩ := mem_at_top_sets.1 hu,
exact ⟨Ioo x b, Ioo_mem_nhds_within_Iio (right_mem_Ioc.2 $ hb x.2), λ z hz, hx _ hz.1.le⟩ }
end
lemma comap_coe_nhds_within_Ioi_of_Ioo_subset (ha : s ⊆ Ioi a)
(hs : s.nonempty → ∃ b > a, Ioo a b ⊆ s) :
comap (coe : s → α) (𝓝[Ioi a] a) = at_bot :=
begin
refine @comap_coe_nhds_within_Iio_of_Ioo_subset (order_dual α) _ _ _ _ _ _ ha (λ h, _),
rcases hs h with ⟨b, hab, h⟩,
use [b, hab],
rwa dual_Ioo
end
lemma map_coe_at_top_of_Ioo_subset (hb : s ⊆ Iio b)
(hs : ∀ a' < b, ∃ a < b, Ioo a b ⊆ s) :
map (coe : s → α) at_top = 𝓝[Iio b] b :=
begin
rcases eq_empty_or_nonempty (Iio b) with (hb'|⟨a, ha⟩),
{ rw [filter_eq_bot_of_not_nonempty at_top, map_bot, hb', nhds_within_empty],
exact λ ⟨⟨x, hx⟩⟩, not_nonempty_iff_eq_empty.2 hb' ⟨x, hb hx⟩ },
{ rw [← comap_coe_nhds_within_Iio_of_Ioo_subset hb (λ _, hs a ha), map_comap_of_mem],
rw subtype.range_coe,
exact (mem_nhds_within_Iio_iff_exists_Ioo_subset' ha).2 (hs a ha) },
end
lemma map_coe_at_bot_of_Ioo_subset (ha : s ⊆ Ioi a)
(hs : ∀ b' > a, ∃ b > a, Ioo a b ⊆ s) :
map (coe : s → α) at_bot = (𝓝[Ioi a] a) :=
begin
refine @map_coe_at_top_of_Ioo_subset (order_dual α) _ _ _ _ a s ha (λ b' hb', _),
rcases hs b' hb' with ⟨b, hab, hbs⟩,
use [b, hab],
rwa dual_Ioo
end
/-- The `at_top` filter for an open interval `Ioo a b` comes from the left-neighbourhoods filter at
the right endpoint in the ambient order. -/
lemma comap_coe_Ioo_nhds_within_Iio (a b : α) :
comap (coe : Ioo a b → α) (𝓝[Iio b] b) = at_top :=
comap_coe_nhds_within_Iio_of_Ioo_subset Ioo_subset_Iio_self $
λ h, ⟨a, nonempty_Ioo.1 h, subset.refl _⟩
/-- The `at_bot` filter for an open interval `Ioo a b` comes from the right-neighbourhoods filter at
the left endpoint in the ambient order. -/
lemma comap_coe_Ioo_nhds_within_Ioi (a b : α) :
comap (coe : Ioo a b → α) (𝓝[Ioi a] a) = at_bot :=
comap_coe_nhds_within_Ioi_of_Ioo_subset Ioo_subset_Ioi_self $
λ h, ⟨b, nonempty_Ioo.1 h, subset.refl _⟩
lemma comap_coe_Ioi_nhds_within_Ioi (a : α) : comap (coe : Ioi a → α) (𝓝[Ioi a] a) = at_bot :=
comap_coe_nhds_within_Ioi_of_Ioo_subset (subset.refl _) $
λ ⟨x, hx⟩, ⟨x, hx, Ioo_subset_Ioi_self⟩
lemma comap_coe_Iio_nhds_within_Iio (a : α) :
comap (coe : Iio a → α) (𝓝[Iio a] a) = at_top :=
@comap_coe_Ioi_nhds_within_Ioi (order_dual α) _ _ _ _ a
@[simp] lemma map_coe_Ioo_at_top {a b : α} (h : a < b) :
map (coe : Ioo a b → α) at_top = 𝓝[Iio b] b :=
map_coe_at_top_of_Ioo_subset Ioo_subset_Iio_self $ λ _ _, ⟨_, h, subset.refl _⟩
@[simp] lemma map_coe_Ioo_at_bot {a b : α} (h : a < b) :
map (coe : Ioo a b → α) at_bot = 𝓝[Ioi a] a :=
map_coe_at_bot_of_Ioo_subset Ioo_subset_Ioi_self $ λ _ _, ⟨_, h, subset.refl _⟩
@[simp] lemma map_coe_Ioi_at_bot (a : α) :
map (coe : Ioi a → α) at_bot = 𝓝[Ioi a] a :=
map_coe_at_bot_of_Ioo_subset (subset.refl _) $ λ b hb, ⟨b, hb, Ioo_subset_Ioi_self⟩
@[simp] lemma map_coe_Iio_at_top (a : α) :
map (coe : Iio a → α) at_top = 𝓝[Iio a] a :=
@map_coe_Ioi_at_bot (order_dual α) _ _ _ _ _
variables {l : filter β} {f : α → β}
@[simp] lemma tendsto_comp_coe_Ioo_at_top (h : a < b) :
tendsto (λ x : Ioo a b, f x) at_top l ↔ tendsto f (𝓝[Iio b] b) l :=
by rw [← map_coe_Ioo_at_top h, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Ioo_at_bot (h : a < b) :
tendsto (λ x : Ioo a b, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l :=
by rw [← map_coe_Ioo_at_bot h, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Ioi_at_bot :
tendsto (λ x : Ioi a, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l :=
by rw [← map_coe_Ioi_at_bot, tendsto_map'_iff]
@[simp] lemma tendsto_comp_coe_Iio_at_top :
tendsto (λ x : Iio a, f x) at_top l ↔ tendsto f (𝓝[Iio a] a) l :=
by rw [← map_coe_Iio_at_top, tendsto_map'_iff]
@[simp] lemma tendsto_Ioo_at_top {f : β → Ioo a b} :
tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio b] b) :=
by rw [← comap_coe_Ioo_nhds_within_Iio, tendsto_comap_iff]
@[simp] lemma tendsto_Ioo_at_bot {f : β → Ioo a b} :
tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) :=
by rw [← comap_coe_Ioo_nhds_within_Ioi, tendsto_comap_iff]
@[simp] lemma tendsto_Ioi_at_bot {f : β → Ioi a} :
tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) :=
by rw [← comap_coe_Ioi_nhds_within_Ioi, tendsto_comap_iff]
@[simp] lemma tendsto_Iio_at_top {f : β → Iio a} :
tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio a] a) :=
by rw [← comap_coe_Iio_nhds_within_Iio, tendsto_comap_iff]
end linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [order_topology α]
[complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ]
lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) :
Sup s ∈ closure s :=
(is_lub_Sup s).mem_closure hs
lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) :
Inf s ∈ closure s :=
(is_glb_Inf s).mem_closure hs
lemma is_closed.Sup_mem {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) :
Sup s ∈ s :=
(is_lub_Sup s).mem_of_is_closed hs hc
lemma is_closed.Inf_mem {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) :
Inf s ∈ s :=
(is_glb_Inf s).mem_of_is_closed hs hc
/-- A monotone function continuous at the supremum of a nonempty set sends this supremum to
the supremum of the image of this set. -/
lemma map_Sup_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Sup s))
(Mf : monotone f) (hs : s.nonempty) :
f (Sup s) = Sup (f '' s) :=
--This is a particular case of the more general is_lub.is_lub_of_tendsto
((is_lub_Sup _).is_lub_of_tendsto (λ x hx y hy xy, Mf xy) hs $
Cf.mono_left inf_le_left).Sup_eq.symm
/-- A monotone function `s` sending `bot` to `bot` and continuous at the supremum of a set sends
this supremum to the supremum of the image of this set. -/
lemma map_Sup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s))
(Mf : monotone f) (fbot : f ⊥ = ⊥) :
f (Sup s) = Sup (f '' s) :=
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, fbot] },
{ exact map_Sup_of_continuous_at_of_monotone' Cf Mf h }
end
/-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed
supremum to the indexed supremum of the composition. -/
lemma map_supr_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α}
(Cf : continuous_at f (supr g)) (Mf : monotone f) :
f (⨆ i, g i) = ⨆ i, f (g i) :=
by rw [supr, map_Sup_of_continuous_at_of_monotone' Cf Mf (range_nonempty g), ← range_comp, supr]
/-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over
a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/
lemma map_supr_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : continuous_at f (supr g)) (Mf : monotone f) (fbot : f ⊥ = ⊥) :
f (⨆ i, g i) = ⨆ i, f (g i) :=
by rw [supr, map_Sup_of_continuous_at_of_monotone Cf Mf fbot, ← range_comp, supr]
/-- A monotone function continuous at the infimum of a nonempty set sends this infimum to
the infimum of the image of this set. -/
lemma map_Inf_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s))
(Mf : monotone f) (hs : s.nonempty) :
f (Inf s) = Inf (f '' s) :=
@map_Sup_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_dual hs
/-- A monotone function `s` sending `top` to `top` and continuous at the infimum of a set sends
this infimum to the infimum of the image of this set. -/
lemma map_Inf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s))
(Mf : monotone f) (ftop : f ⊤ = ⊤) :
f (Inf s) = Inf (f '' s) :=
@map_Sup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_dual ftop
/-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed
infimum to the indexed infimum of the composition. -/
lemma map_infi_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α}
(Cf : continuous_at f (infi g)) (Mf : monotone f) :
f (⨅ i, g i) = ⨅ i, f (g i) :=
@map_supr_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ ι _ f g Cf
Mf.order_dual
/-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over
a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/
lemma map_infi_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : continuous_at f (infi g)) (Mf : monotone f) (ftop : f ⊤ = ⊤) :
f (infi g) = infi (f ∘ g) :=
@map_supr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ ι f g Cf
Mf.order_dual ftop
end complete_linear_order
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] [topological_space α] [order_topology α]
[conditionally_complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ]
lemma cSup_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ closure s :=
(is_lub_cSup hs B).mem_closure hs
lemma cInf_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ closure s :=
(is_glb_cInf hs B).mem_closure hs
lemma is_closed.cSup_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_above s) :
Sup s ∈ s :=
(is_lub_cSup hs B).mem_of_is_closed hs hc
lemma is_closed.cInf_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_below s) :
Inf s ∈ s :=
(is_glb_cInf hs B).mem_of_is_closed hs hc
/-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`,
then it sends this supremum to the supremum of the image of `s`. -/
lemma map_cSup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s))
(Mf : monotone f) (ne : s.nonempty) (H : bdd_above s) :
f (Sup s) = Sup (f '' s) :=
begin
refine ((is_lub_cSup (ne.image f) (Mf.map_bdd_above H)).unique _).symm,
refine (is_lub_cSup ne H).is_lub_of_tendsto (λx hx y hy xy, Mf xy) ne _,
exact Cf.mono_left inf_le_left
end
/-- If a monotone function is continuous at the indexed supremum of a bounded function on
a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/
lemma map_csupr_of_continuous_at_of_monotone {f : α → β} {g : γ → α}
(Cf : continuous_at f (⨆ i, g i)) (Mf : monotone f) (H : bdd_above (range g)) :
f (⨆ i, g i) = ⨆ i, f (g i) :=
by rw [supr, map_cSup_of_continuous_at_of_monotone Cf Mf (range_nonempty _) H, ← range_comp, supr]
/-- If a monotone function is continuous at the infimum of a nonempty bounded below set `s`,
then it sends this infimum to the infimum of the image of `s`. -/
lemma map_cInf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s))
(Mf : monotone f) (ne : s.nonempty) (H : bdd_below s) :
f (Inf s) = Inf (f '' s) :=
@map_cSup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_dual ne H
/-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally
complete linear order, under a boundedness assumption. -/
lemma map_cinfi_of_continuous_at_of_monotone {f : α → β} {g : γ → α}
(Cf : continuous_at f (⨅ i, g i)) (Mf : monotone f) (H : bdd_below (range g)) :
f (⨅ i, g i) = ⨅ i, f (g i) :=
@map_csupr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ _ _ _ _
Cf Mf.order_dual H
/-- A bounded connected subset of a conditionally complete linear order includes the open interval
`(Inf s, Sup s)`. -/
lemma is_connected.Ioo_cInf_cSup_subset {s : set α} (hs : is_connected s) (hb : bdd_below s)
(ha : bdd_above s) :
Ioo (Inf s) (Sup s) ⊆ s :=
λ x hx, let ⟨y, ys, hy⟩ := (is_glb_lt_iff (is_glb_cInf hs.nonempty hb)).1 hx.1 in
let ⟨z, zs, hz⟩ := (lt_is_lub_iff (is_lub_cSup hs.nonempty ha)).1 hx.2 in
hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
lemma eq_Icc_cInf_cSup_of_connected_bdd_closed {s : set α} (hc : is_connected s) (hb : bdd_below s)
(ha : bdd_above s) (hcl : is_closed s) :
s = Icc (Inf s) (Sup s) :=
subset.antisymm (subset_Icc_cInf_cSup hb ha) $
hc.Icc_subset (hcl.cInf_mem hc.nonempty hb) (hcl.cSup_mem hc.nonempty ha)
lemma is_preconnected.Ioi_cInf_subset {s : set α} (hs : is_preconnected s) (hb : bdd_below s)
(ha : ¬bdd_above s) :
Ioi (Inf s) ⊆ s :=
begin
have sne : s.nonempty := @nonempty_of_not_bdd_above α _ s ⟨Inf ∅⟩ ha,
intros x hx,
obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := (is_glb_lt_iff (is_glb_cInf sne hb)).1 hx,
obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x,
exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
end
lemma is_preconnected.Iio_cSup_subset {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s)
(ha : bdd_above s) :
Iio (Sup s) ⊆ s :=
@is_preconnected.Ioi_cInf_subset (order_dual α) _ _ _ s hs ha hb
/-- A preconnected set in a conditionally complete linear order is either one of the intervals
`[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`,
`(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires
`α` to be densely ordererd. -/
lemma is_preconnected.mem_intervals {s : set α} (hs : is_preconnected s) :
s ∈ ({Icc (Inf s) (Sup s), Ico (Inf s) (Sup s), Ioc (Inf s) (Sup s), Ioo (Inf s) (Sup s),
Ici (Inf s), Ioi (Inf s), Iic (Sup s), Iio (Sup s), univ, ∅} : set (set α)) :=
begin
rcases s.eq_empty_or_nonempty with rfl|hne,
{ apply_rules [or.inr, mem_singleton] },
have hs' : is_connected s := ⟨hne, hs⟩,
by_cases hb : bdd_below s; by_cases ha : bdd_above s,
{ rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha)
(subset_Icc_cInf_cSup hb ha) with hs|hs|hs|hs,
{ exact (or.inl hs) },
{ exact (or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inr $ or.inl hs) } },
{ refine (or.inr $ or.inr $ or.inr $ or.inr _),
cases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) (λ x hx, cInf_le hb hx)
with hs hs,
{ exact or.inl hs },
{ exact or.inr (or.inl hs) } },
{ iterate 6 { apply or.inr },
cases mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) (λ x hx, le_cSup ha hx)
with hs hs,
{ exact or.inl hs },
{ exact or.inr (or.inl hs) } },
{ iterate 8 { apply or.inr },
exact or.inl (hs.eq_univ_of_unbounded hb ha) }
end
/-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`,
`Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordererd. Though
one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve
readability. -/
lemma set_of_is_preconnected_subset_of_ordered :
{s : set α | is_preconnected s} ⊆
-- bounded intervals
(range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪
-- unbounded intervals and `univ`
(range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) :=
begin
intros s hs,
rcases hs.mem_intervals with hs|hs|hs|hs|hs|hs|hs|hs|hs|hs,
{ exact (or.inl $ or.inl $ or.inl $ or.inl ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inl ⟨Inf s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inr ⟨Inf s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) },
{ exact (or.inr $ or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inr hs) }
end
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/
lemma is_closed.mem_of_ge_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b))
(ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).nonempty) :
b ∈ s :=
begin
let S := s ∩ Icc a b,
replace ha : a ∈ S, from ⟨ha, left_mem_Icc.2 hab⟩,
have Sbd : bdd_above S, from ⟨b, λ z hz, hz.2.2⟩,
let c := Sup (s ∩ Icc a b),
have c_mem : c ∈ S, from hs.cSup_mem ⟨_, ha⟩ Sbd,
have c_le : c ≤ b, from cSup_le ⟨_, ha⟩ (λ x hx, hx.2.2),
cases eq_or_lt_of_le c_le with hc hc, from hc ▸ c_mem.1,
exfalso,
rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩,
exact not_lt_of_le (le_cSup Sbd ⟨xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xb⟩) cx
end
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]`
is not empty, then `[a, b] ⊆ s`. -/
lemma is_closed.Icc_subset_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b))
(ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).nonempty) :
Icc a b ⊆ s :=
begin
assume y hy,
have : is_closed (s ∩ Icc a y),
{ suffices : s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y,
{ rw this, exact is_closed_inter hs is_closed_Icc },
rw [inter_assoc],
congr,
exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm },
exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1
(λ x hx, hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2)
end
section densely_ordered
variables [densely_ordered α] {a b : α}
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open
neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/
lemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : α} {s : set α}
(hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s)
(hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[Ioi x] x) :
Icc a b ⊆ s :=
begin
apply hs.Icc_subset_of_forall_exists_gt ha,
rintros x ⟨hxs, hxab⟩ y hyxb,
have : s ∩ Ioc x y ∈ 𝓝[Ioi x] x,
from inter_mem_sets (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhds_within_Ioi ⟨le_refl _, hyxb⟩),
exact (nhds_within_Ioi_self_ne_bot' hxab.2).nonempty_of_mem this
end
/-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/
lemma is_preconnected_Icc : is_preconnected (Icc a b) :=
is_preconnected_closed_iff.2
begin
rintros s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩,
wlog hxy : x ≤ y := le_total x y using [x y s t, y x t s],
have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2,
by_contradiction hst,
suffices : Icc x y ⊆ s,
from hst ⟨y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2⟩,
apply (is_closed_inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2,
rintros z ⟨zs, hz⟩,
have zt : z ∈ tᶜ, from λ zt, hst ⟨z, xyab $ Ico_subset_Icc_self hz, zs, zt⟩,
have : tᶜ ∩ Ioc z y ∈ 𝓝[Ioi z] z,
{ rw [← nhds_within_Ioc_eq_nhds_within_Ioi hz.2],
exact mem_nhds_within.2 ⟨tᶜ, ht.is_open_compl, zt, subset.refl _⟩},
apply mem_sets_of_superset this,
have : Ioc z y ⊆ s ∪ t, from λ w hw, hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩),
exact λ w ⟨wt, wzy⟩, (this wzy).elim id (λ h, (wt h).elim)
end
lemma is_preconnected_interval : is_preconnected (interval a b) := is_preconnected_Icc
lemma is_preconnected_iff_ord_connected {s : set α} :
is_preconnected s ↔ ord_connected s :=
⟨λ h x hx y hy, h.Icc_subset hx hy, λ h, is_preconnected_of_forall_pair $ λ x y hx hy,
⟨interval x y, h.interval_subset hx hy, left_mem_interval, right_mem_interval,
is_preconnected_interval⟩⟩
alias is_preconnected_iff_ord_connected ↔
is_preconnected.ord_connected set.ord_connected.is_preconnected
lemma is_preconnected_Ici : is_preconnected (Ici a) := ord_connected_Ici.is_preconnected
lemma is_preconnected_Iic : is_preconnected (Iic a) := ord_connected_Iic.is_preconnected
lemma is_preconnected_Iio : is_preconnected (Iio a) := ord_connected_Iio.is_preconnected
lemma is_preconnected_Ioi : is_preconnected (Ioi a) := ord_connected_Ioi.is_preconnected
lemma is_preconnected_Ioo : is_preconnected (Ioo a b) := ord_connected_Ioo.is_preconnected
lemma is_preconnected_Ioc : is_preconnected (Ioc a b) := ord_connected_Ioc.is_preconnected
lemma is_preconnected_Ico : is_preconnected (Ico a b) := ord_connected_Ico.is_preconnected
@[priority 100]
instance ordered_connected_space : preconnected_space α :=
⟨ord_connected_univ.is_preconnected⟩
/-- In a dense conditionally complete linear order, the set of preconnected sets is exactly
the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`,
or `∅`. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of
possible cases to improve readability. -/
lemma set_of_is_preconnected_eq_of_ordered :
{s : set α | is_preconnected s} =
-- bounded intervals
(range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪
-- unbounded intervals and `univ`
(range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) :=
begin
refine subset.antisymm set_of_is_preconnected_subset_of_ordered _,
simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp_distrib, forall_and_distrib,
mem_union, mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true,
is_preconnected_Icc, is_preconnected_Ico, is_preconnected_Ioc,
is_preconnected_Ioo, is_preconnected_Ioi, is_preconnected_Iio, is_preconnected_Ici,
is_preconnected_Iic, is_preconnected_univ, is_preconnected_empty],
end
variables {δ : Type*} [linear_order δ] [topological_space δ] [order_closed_topology δ]
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≤ t ≤ f b`.-/
lemma intermediate_value_Icc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) :
Icc (f a) (f b) ⊆ f '' (Icc a b) :=
is_preconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≥ t ≥ f b`.-/
lemma intermediate_value_Icc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) :
Icc (f b) (f a) ⊆ f '' (Icc a b) :=
is_preconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf
/-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/
lemma continuous.surjective {f : α → δ} (hf : continuous f) (h_top : tendsto f at_top at_top)
(h_bot : tendsto f at_bot at_bot) :
function.surjective f :=
λ p, mem_range_of_exists_le_of_exists_ge hf
(h_bot.eventually (eventually_le_at_bot p)).exists
(h_top.eventually (eventually_ge_at_top p)).exists
/-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/
lemma continuous.surjective' {f : α → δ} (hf : continuous f) (h_top : tendsto f at_bot at_top)
(h_bot : tendsto f at_top at_bot) :
function.surjective f :=
@continuous.surjective (order_dual α) _ _ _ _ _ _ _ _ _ hf h_top h_bot
/-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s`
tends to `at_bot : filter β` along `at_bot : filter ↥s` and tends to `at_top : filter β` along
`at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the
conclusion as `surj_on f s univ`. -/
lemma continuous_on.surj_on_of_tendsto {f : α → β} {s : set α} [ord_connected s]
(hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_bot)
(htop : tendsto (λ x : s, f x) at_top at_top) :
surj_on f s univ :=
by haveI := inhabited_of_nonempty hs.to_subtype;
exact (surj_on_iff_surjective.2 $
(continuous_on_iff_continuous_restrict.1 hf).surjective htop hbot)
/-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s`
tends to `at_top : filter β` along `at_bot : filter ↥s` and tends to `at_bot : filter β` along
`at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the
conclusion as `surj_on f s univ`. -/
lemma continuous_on.surj_on_of_tendsto' {f : α → β} {s : set α} [ord_connected s]
(hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_top)
(htop : tendsto (λ x : s, f x) at_top at_bot) :
surj_on f s univ :=
@continuous_on.surj_on_of_tendsto α (order_dual β) _ _ _ _ _ _ _ _ _ _ hs hf hbot htop
end densely_ordered
/-- A closed interval in a conditionally complete linear order is compact. -/
lemma compact_Icc {a b : α} : is_compact (Icc a b) :=
begin
cases le_or_lt a b with hab hab, swap, { simp [hab] },
refine compact_iff_ultrafilter_le_nhds.2 (λ f hf, _),
contrapose! hf,
rw [le_principal_iff],
have hpt : ∀ x ∈ Icc a b, {x} ∉ f,
from λ x hx hxf, hf x hx ((le_pure_iff.2 hxf).trans (pure_le_nhds x)),
set s := {x ∈ Icc a b | Icc a x ∉ f},
have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2,
have sbd : bdd_above s, from ⟨b, hsb⟩,
have ha : a ∈ s, by simp [hpt, hab],
rcases hab.eq_or_lt with rfl|hlt, { exact ha.2 },
set c := Sup s,
have hsc : is_lub s c, from is_lub_cSup ⟨a, ha⟩ sbd,
have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩,
specialize hf c hc,
have hcs : c ∈ s,
{ cases hc.1.eq_or_lt with heq hlt, { rwa ← heq },
refine ⟨hc, λ hcf, hf (λ U hU, _)⟩,
rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' hlt).1 (mem_nhds_within_of_mem_nhds hU)
with ⟨x, hxc, hxU⟩,
rcases ((hsc.frequently_mem ⟨a, ha⟩).and_eventually
(Ioc_mem_nhds_within_Iic ⟨hxc, le_rfl⟩)).exists
with ⟨y, ⟨hyab, hyf⟩, hy⟩,
refine mem_sets_of_superset(f.diff_mem_iff.2 ⟨hcf, hyf⟩) (subset.trans _ hxU),
rw diff_subset_iff,
exact subset.trans Icc_subset_Icc_union_Ioc
(union_subset_union subset.rfl $ Ioc_subset_Ioc_left hy.1.le) },
cases hc.2.eq_or_lt with heq hlt, { rw ← heq, exact hcs.2 },
contrapose! hf,
intros U hU,
rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1 (mem_nhds_within_of_mem_nhds hU)
with ⟨y, hxy, hyU⟩,
refine mem_sets_of_superset _ hyU, clear_dependent U,
have hy : y ∈ Icc a b, from ⟨hc.1.trans hxy.1.le, hxy.2⟩,
by_cases hay : Icc a y ∈ f,
{ refine mem_sets_of_superset (f.diff_mem_iff.2 ⟨f.diff_mem_iff.2 ⟨hay, hcs.2⟩, hpt y hy⟩) _,
rw [diff_subset_iff, union_comm, Ico_union_right hxy.1.le, diff_subset_iff],
exact Icc_subset_Icc_union_Icc },
{ exact ((hsc.1 ⟨hy, hay⟩).not_lt hxy.1).elim },
end
/-- An unordered closed interval in a conditionally complete linear order is compact. -/
lemma compact_interval {a b : α} : is_compact (interval a b) := compact_Icc
lemma compact_pi_Icc {ι : Type*} {α : ι → Type*} [Π i, conditionally_complete_linear_order (α i)]
[Π i, topological_space (α i)] [Π i, order_topology (α i)] (a b : Π i, α i) :
is_compact (Icc a b) :=
pi_univ_Icc a b ▸ compact_univ_pi $ λ i, compact_Icc
instance compact_space_Icc (a b : α) : compact_space (Icc a b) :=
compact_iff_compact_space.mp compact_Icc
instance compact_space_pi_Icc {ι : Type*} {α : ι → Type*}
[Π i, conditionally_complete_linear_order (α i)] [Π i, topological_space (α i)]
[Π i, order_topology (α i)] (a b : Π i, α i) : compact_space (Icc a b) :=
compact_iff_compact_space.mp (compact_pi_Icc a b)
@[priority 100] -- See note [lower instance priority]
instance compact_space_of_complete_linear_order {α : Type*} [complete_linear_order α]
[topological_space α] [order_topology α] :
compact_space α :=
⟨by simp only [← Icc_bot_top, compact_Icc]⟩
lemma is_compact.Inf_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
Inf s ∈ s :=
hs.is_closed.cInf_mem ne_s hs.bdd_below
lemma is_compact.Sup_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
Sup s ∈ s :=
@is_compact.Inf_mem (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.is_glb_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_glb s (Inf s) :=
is_glb_cInf ne_s hs.bdd_below
lemma is_compact.is_lub_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_lub s (Sup s) :=
@is_compact.is_glb_Inf (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.is_least_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_least s (Inf s) :=
⟨hs.Inf_mem ne_s, (hs.is_glb_Inf ne_s).1⟩
lemma is_compact.is_greatest_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_greatest s (Sup s) :=
@is_compact.is_least_Inf (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.exists_is_least {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x, is_least s x :=
⟨_, hs.is_least_Inf ne_s⟩
lemma is_compact.exists_is_greatest {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x, is_greatest s x :=
⟨_, hs.is_greatest_Sup ne_s⟩
lemma is_compact.exists_is_glb {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x ∈ s, is_glb s x :=
⟨_, hs.Inf_mem ne_s, hs.is_glb_Inf ne_s⟩
lemma is_compact.exists_is_lub {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x ∈ s, is_lub s x :=
⟨_, hs.Sup_mem ne_s, hs.is_lub_Sup ne_s⟩
lemma is_compact.exists_Inf_image_eq {α : Type u} [topological_space α]
{s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) :
∃ x ∈ s, Inf (f '' s) = f x :=
let ⟨x, hxs, hx⟩ := (hs.image_of_continuous_on hf).Inf_mem (ne_s.image f)
in ⟨x, hxs, hx.symm⟩
lemma is_compact.exists_Sup_image_eq {α : Type u} [topological_space α]:
∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s →
∃ x ∈ s, Sup (f '' s) = f x :=
@is_compact.exists_Inf_image_eq (order_dual β) _ _ _ _ _
lemma eq_Icc_of_connected_compact {s : set α} (h₁ : is_connected s) (h₂ : is_compact s) :
s = Icc (Inf s) (Sup s) :=
eq_Icc_cInf_cSup_of_connected_bdd_closed h₁ h₂.bdd_below h₂.bdd_above h₂.is_closed
/-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/
lemma is_compact.exists_forall_le {α : Type u} [topological_space α]
{s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) :
∃x∈s, ∀y∈s, f x ≤ f y :=
begin
rcases hs.exists_Inf_image_eq ne_s hf with ⟨x, hxs, hx⟩,
refine ⟨x, hxs, λ y hy, _⟩,
rw ← hx,
exact ((hs.image_of_continuous_on hf).is_glb_Inf (ne_s.image f)).1 (mem_image_of_mem _ hy)
end
/-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/
lemma is_compact.exists_forall_ge {α : Type u} [topological_space α]:
∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s →
∃x∈s, ∀y∈s, f y ≤ f x :=
@is_compact.exists_forall_le (order_dual β) _ _ _ _ _
/-- The extreme value theorem: if a continuous function `f` tends to infinity away from compact
sets, then it has a global minimum. -/
lemma continuous.exists_forall_le {α : Type*} [topological_space α] [nonempty α] {f : α → β}
(hf : continuous f) (hlim : tendsto f (cocompact α) at_top) :
∃ x, ∀ y, f x ≤ f y :=
begin
inhabit α,
obtain ⟨s : set α, hsc : is_compact s, hsf : ∀ x ∉ s, f (default α) ≤ f x⟩ :=
(has_basis_cocompact.tendsto_iff at_top_basis).1 hlim (f $ default α) trivial,
obtain ⟨x, -, hx⟩ :=
(hsc.insert (default α)).exists_forall_le (nonempty_insert _ _) hf.continuous_on,
refine ⟨x, λ y, _⟩,
by_cases hy : y ∈ s,
exacts [hx y (or.inr hy), (hx _ (or.inl rfl)).trans (hsf y hy)]
end
/-- The extreme value theorem: if a continuous function `f` tends to negative infinity away from
compactx sets, then it has a global maximum. -/
lemma continuous.exists_forall_ge {α : Type*} [topological_space α] [nonempty α] {f : α → β}
(hf : continuous f) (hlim : tendsto f (cocompact α) at_bot) :
∃ x, ∀ y, f y ≤ f x :=
@continuous.exists_forall_le (order_dual β) _ _ _ _ _ _ _ hf hlim
end conditionally_complete_linear_order
section liminf_limsup
section order_closed_topology
variables [semilattice_sup α] [topological_space α] [order_topology α]
lemma is_bounded_le_nhds (a : α) : (𝓝 a).is_bounded (≤) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := ⟨a, eventually_of_forall h⟩
| or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩
end
lemma filter.tendsto.is_bounded_under_le {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (𝓝 a)) : f.is_bounded_under (≤) u :=
(is_bounded_le_nhds a).mono h
lemma is_cobounded_ge_nhds (a : α) : (𝓝 a).is_cobounded (≥) :=
(is_bounded_le_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_ge {f : filter β} {u : β → α} {a : α}
[ne_bot f] (h : tendsto u f (𝓝 a)) : f.is_cobounded_under (≥) u :=
h.is_bounded_under_le.is_cobounded_flip
end order_closed_topology
section order_closed_topology
variables [semilattice_inf α] [topological_space α] [order_topology α]
lemma is_bounded_ge_nhds (a : α) : (𝓝 a).is_bounded (≥) :=
@is_bounded_le_nhds (order_dual α) _ _ _ a
lemma filter.tendsto.is_bounded_under_ge {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (𝓝 a)) : f.is_bounded_under (≥) u :=
(is_bounded_ge_nhds a).mono h
lemma is_cobounded_le_nhds (a : α) : (𝓝 a).is_cobounded (≤) :=
(is_bounded_ge_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_le {f : filter β} {u : β → α} {a : α}
[ne_bot f] (h : tendsto u f (𝓝 a)) : f.is_cobounded_under (≤) u :=
h.is_bounded_under_ge.is_cobounded_flip
end order_closed_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 in f, a < b :=
let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_cInf_lt 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 (≥) → b < f.Liminf →
∀ᶠ a in f, b < a :=
@lt_mem_sets_of_Limsup_lt (order_dual α) _
variables [topological_space α] [order_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 ≤ 𝓝 a :=
tendsto_order.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 (𝓝 a) = a :=
cInf_intro (is_bounded_le_nhds a)
(assume a' (h : {n : α | n ≤ a'} ∈ 𝓝 a), show a ≤ a', from @mem_of_nhds α _ a _ h)
(assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ 𝓝 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, (𝓝 a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
end)
theorem Liminf_nhds : ∀ (a : α), Liminf (𝓝 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 : α} [ne_bot f] (h : f ≤ 𝓝 a) : f.Liminf = a :=
have hb_ge : is_bounded (≥) f, from (is_bounded_ge_nhds a).mono h,
have hb_le : is_bounded (≤) f, from (is_bounded_le_nhds a).mono h,
le_antisymm
(calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hb_le hb_ge
... ≤ (𝓝 a).Limsup :
Limsup_le_Limsup_of_le h hb_ge.is_cobounded_flip (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (𝓝 a).Liminf : (Liminf_nhds a).symm
... ≤ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) hb_le.is_cobounded_flip)
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : ∀ {f : filter α} {a : α} [ne_bot f], f ≤ 𝓝 a → f.Limsup = a :=
@Liminf_eq_of_le_nhds (order_dual α) _ _ _
/-- If a function has a limit, then its limsup coincides with its limit. -/
theorem filter.tendsto.limsup_eq {f : filter β} {u : β → α} {a : α} [ne_bot f]
(h : tendsto u f (𝓝 a)) : limsup f u = a :=
Limsup_eq_of_le_nhds h
/-- If a function has a limit, then its liminf coincides with its limit. -/
theorem filter.tendsto.liminf_eq {f : filter β} {u : β → α} {a : α} [ne_bot f]
(h : tendsto u f (𝓝 a)) : liminf f u = a :=
Liminf_eq_of_le_nhds h
end conditionally_complete_linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [order_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 : α}
(hinf : liminf f u = a) (hsup : limsup f u = a) : tendsto u f (𝓝 a) :=
le_nhds_of_Limsup_eq_Liminf is_bounded_le_of_top is_bounded_ge_of_bot hsup hinf
/-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter
and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/
theorem tendsto_of_le_liminf_of_limsup_le {f : filter β} {u : β → α} {a : α}
(hinf : a ≤ liminf f u) (hsup : limsup f u ≤ a) :
tendsto u f (𝓝 a) :=
if hf : f = ⊥ then hf.symm ▸ tendsto_bot
else by haveI : ne_bot f := ⟨hf⟩; exact tendsto_of_liminf_eq_limsup
(le_antisymm (le_trans liminf_le_limsup hsup) hinf)
(le_antisymm hsup (le_trans hinf liminf_le_limsup))
end complete_linear_order
end liminf_limsup
end order_topology
/-!
Here is a counter-example to a version of the following with `conditionally_complete_lattice α`.
Take `α = [0, 1) → ℝ` with the natural lattice structure, `ι = ℕ`. Put `f n x = -x^n`. Then
`⨆ n, f n = 0` while none of `f n` is strictly greater than the constant function `-0.5`.
-/
lemma tendsto_at_top_csupr {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : monotone f) (hbdd : bdd_above $ range f) :
tendsto f at_top (𝓝 (⨆i, f i)) :=
begin
by_cases hi : nonempty ι,
{ resetI,
rw tendsto_order,
split,
{ intros a h,
cases exists_lt_of_lt_csupr h with N hN,
apply eventually.mono (mem_at_top N),
exact λ i hi, lt_of_lt_of_le hN (h_mono hi) },
{ exact λ a h, eventually_of_forall (λ n, lt_of_le_of_lt (le_csupr hbdd n) h) } },
{ exact tendsto_of_not_nonempty hi }
end
lemma tendsto_at_bot_cinfi {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : monotone f) (hbdd : bdd_below $ range f) :
tendsto f at_bot (𝓝 (⨅i, f i)) :=
@tendsto_at_top_csupr (order_dual ι) (order_dual α) _ _ _ _ _ h_mono.order_dual hbdd
lemma tendsto_at_top_cinfi {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_below $ range f) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
@tendsto_at_top_csupr _ (order_dual α) _ _ _ _ _ @h_mono hbdd
lemma tendsto_at_bot_csupr {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_above $ range f) :
tendsto f at_bot (𝓝 (⨆i, f i)) :=
@tendsto_at_bot_cinfi ι (order_dual α) _ _ _ _ _ h_mono hbdd
lemma tendsto_at_top_supr {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_top (𝓝 (⨆i, f i)) :=
tendsto_at_top_csupr h_mono (order_top.bdd_above _)
lemma tendsto_at_bot_infi {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_bot (𝓝 (⨅i, f i)) :=
tendsto_at_bot_cinfi h_mono (order_bot.bdd_below _)
lemma tendsto_at_top_infi {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
tendsto_at_top_cinfi @h_mono (order_bot.bdd_below _)
lemma tendsto_at_bot_supr {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) :
tendsto f at_bot (𝓝 (⨆i, f i)) :=
tendsto_at_bot_csupr h_mono (order_top.bdd_above _)
lemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) :=
if H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩
else or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H
lemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) :
tendsto f at_top (𝓝 a) → supr f = a :=
tendsto_nhds_unique (tendsto_at_top_supr hf)
lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) :
tendsto f at_top (𝓝 a) → infi f = a :=
tendsto_nhds_unique (tendsto_at_top_infi hf)
@[to_additive] lemma tendsto_inv_nhds_within_Ioi [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ioi a] a) (𝓝[Iio (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iio [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iio a] a) (𝓝[Ioi (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ioi (a⁻¹)] (a⁻¹)) (𝓝[Iio a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iio_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iio (a⁻¹)] (a⁻¹)) (𝓝[Ioi a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Ici [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ici a] a) (𝓝[Iic (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iic [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iic a] a) (𝓝[Ici (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ici_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ici (a⁻¹)] (a⁻¹)) (𝓝[Iic a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iic_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iic (a⁻¹)] (a⁻¹)) (𝓝[Ici a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹)
lemma nhds_left_sup_nhds_right (a : α) [topological_space α] [linear_order α] :
𝓝[Iic a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=
by rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ]
lemma nhds_left'_sup_nhds_right (a : α) [topological_space α] [linear_order α] :
𝓝[Iio a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=
by rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ]
lemma nhds_left_sup_nhds_right' (a : α) [topological_space α] [linear_order α] :
𝓝[Iic a] a ⊔ 𝓝[Ioi a] a = 𝓝 a :=
by rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ]
lemma continuous_at_iff_continuous_left_right [topological_space α] [linear_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a :=
by simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right]
lemma continuous_on_Icc_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [regular_space β] {f : α → β} {a b : α}
{la lb : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) (hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
continuous_on (extend_from (Ioo a b) f) (Icc a b) :=
begin
apply continuous_on_extend_from,
{ rw closure_Ioo hab, },
{ intros x x_in,
rcases mem_Ioo_or_eq_endpoints_of_mem_Icc x_in with rfl | rfl | h,
{ use la,
simpa [hab] },
{ use lb,
simpa [hab] },
{ use [f x, hf x h] } }
end
lemma eq_lim_at_left_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [t2_space β] {f : α → β} {a b : α}
{la : β} (hab : a < b) (ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) :
extend_from (Ioo a b) f a = la :=
begin
apply extend_from_eq,
{ rw closure_Ioo hab,
simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc] },
{ simpa [hab] }
end
lemma eq_lim_at_right_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [t2_space β] {f : α → β} {a b : α}
{lb : β} (hab : a < b) (hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
extend_from (Ioo a b) f b = lb :=
begin
apply extend_from_eq,
{ rw closure_Ioo hab,
simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc] },
{ simpa [hab] }
end
lemma continuous_on_Ico_extend_from_Ioo [topological_space α]
[linear_order α] [densely_ordered α] [order_topology α] [topological_space β]
[regular_space β] {f : α → β} {a b : α} {la : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) :
continuous_on (extend_from (Ioo a b) f) (Ico a b) :=
begin
apply continuous_on_extend_from,
{ rw [closure_Ioo hab], exact Ico_subset_Icc_self, },
{ intros x x_in,
rcases mem_Ioo_or_eq_left_of_mem_Ico x_in with rfl | h,
{ use la,
simpa [hab] },
{ use [f x, hf x h] } }
end
lemma continuous_on_Ioc_extend_from_Ioo [topological_space α]
[linear_order α] [densely_ordered α] [order_topology α] [topological_space β]
[regular_space β] {f : α → β} {a b : α} {lb : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
continuous_on (extend_from (Ioo a b) f) (Ioc a b) :=
begin
have := @continuous_on_Ico_extend_from_Ioo (order_dual α) _ _ _ _ _ _ _ f _ _ _ hab,
erw [dual_Ico, dual_Ioi, dual_Ioo] at this,
exact this hf hb
end
lemma continuous_within_at_Ioi_iff_Ici {α β : Type*} [topological_space α] [partial_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a :=
by simp only [← Ici_diff_left, continuous_within_at_diff_self]
lemma continuous_within_at_Iio_iff_Iic
{α β : Type*} [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} :
continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a :=
begin
have := @continuous_within_at_Ioi_iff_Ici (order_dual α) _ _ _ _ _ f,
erw [dual_Ici, dual_Ioi] at this,
exact this,
end
lemma continuous_at_iff_continuous_left'_right' [topological_space α] [linear_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a :=
by rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic,
continuous_at_iff_continuous_left_right]
/-!
### Continuity of monotone functions
In this section we prove the following fact: if `f` is a monotone function on a neighborhood of `a`
and the image of this neighborhood is a neighborhood of `f a`, then `f` is continuous at `a`, see
`continuous_at_of_mono_incr_on_of_image_mem_nhds`, as well as several similar facts.
-/
section linear_order
variables [linear_order α] [topological_space α] [order_topology α]
variables [linear_order β] [topological_space β] [order_topology β]
/-- If `f` is a function strictly monotonically increasing on a right neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(f a, b]`, `b > f a`, then `f` is
continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x ≤ 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
lemma strict_mono_incr_on.continuous_at_right_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) :
continuous_within_at f (Ici a) a :=
begin
have ha : a ∈ Ici a := left_mem_Ici,
have has : a ∈ s := mem_of_mem_nhds_within ha hs,
refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩,
{ filter_upwards [hs, self_mem_nhds_within],
intros x hxs hxa,
exact hb.trans_le ((h_mono.le_iff_le has hxs).2 hxa) },
{ rcases hfs b hb with ⟨c, hcs, hac, hcb⟩,
rw [h_mono.lt_iff_lt has hcs] at hac,
filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 hac)],
rintros x hx ⟨hax, hxc⟩,
exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb }
end
/-- If `f` is a function monotonically increasing function on a right neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(f a, b)`, `b > f a`, then `f` is
continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b` cannot be replaced by the weaker
assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` we use for strictly monotone functions
because otherwise the function `ceil : ℝ → ℤ` would be a counter-example at `a = 0`. -/
lemma continuous_at_right_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a)
(hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) :
continuous_within_at f (Ici a) a :=
begin
have ha : a ∈ Ici a := left_mem_Ici,
have has : a ∈ s := mem_of_mem_nhds_within ha hs,
refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩,
{ filter_upwards [hs, self_mem_nhds_within],
intros x hxs hxa,
exact hb.trans_le (h_mono _ has _ hxs hxa) },
{ rcases hfs b hb with ⟨c, hcs, hac, hcb⟩,
have : a < c, from not_le.1 (λ h, hac.not_le $ h_mono _ hcs _ has h),
filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 this)],
rintros x hx ⟨hax, hxc⟩,
exact (h_mono _ hx _ hcs hxc.le).trans_lt hcb }
end
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a right
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right
neighborhood of `f a`, then `f` is continuous at `a` from the right. -/
lemma continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
begin
refine continuous_at_right_of_mono_incr_on_of_exists_between h_mono hs (λ b hb, _),
rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩,
rcases exists_between hab' with ⟨c', hc'⟩,
rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') is_open_Ioo hc'
with ⟨_, hc, ⟨c, hcs, rfl⟩⟩,
exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩
end
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a right
neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`,
then `f` is continuous at `a` from the right. -/
lemma continuous_at_right_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a)
(hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs $
mem_sets_of_superset hfs subset_closure
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right
neighborhood of `f a`, then `f` is continuous at `a` from the right. -/
lemma strict_mono_incr_on.continuous_at_right_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within
(λ x hx y hy, (h_mono.le_iff_le hx hy).2) hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of
`f a`, then `f` is continuous at `a` from the right. -/
lemma strict_mono_incr_on.continuous_at_right_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
h_mono.continuous_at_right_of_closure_image_mem_nhds_within hs
(mem_sets_of_superset hfs subset_closure)
/-- If a function `f` is strictly monotonically increasing on a right neighborhood of `a` and the
image of this neighborhood under `f` includes `Ioi (f a)`, then `f` is continuous at `a` from the
right. -/
lemma strict_mono_incr_on.continuous_at_right_of_surj_on {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : surj_on f s (Ioi (f a))) :
continuous_within_at f (Ici a) a :=
h_mono.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb⟩ := hfs hb in
⟨c, hcs, hcb.symm ▸ hb, hcb.le⟩
/-- If `f` is a function strictly monotonically increasing on a left neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, then `f` is
continuous at `a` from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x < 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
lemma strict_mono_incr_on.continuous_at_left_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_exists_between hs $
λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩
/-- If `f` is a function monotonically increasing function on a left neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, then `f` is
continuous at `a` from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)` cannot be replaced by the weaker
assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` we use for strictly monotone functions
because otherwise the function `floor : ℝ → ℤ` would be a counter-example at `a = 0`. -/
lemma continuous_at_left_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a)
(hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) :
continuous_within_at f (Iic a) a :=
@continuous_at_right_of_mono_incr_on_of_exists_between (order_dual α) (order_dual β) _ _ _ _ _ _
f s a (λ x hx y hy, h_mono y hy x hx) hs $
λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a left
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left
neighborhood of `f a`, then `f` is continuous at `a` from the left -/
lemma continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
@continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (order_dual α) (order_dual β)
_ _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs hfs
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a left
neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`,
then `f` is continuous at `a` from the left. -/
lemma continuous_at_left_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs
(mem_sets_of_superset hfs subset_closure)
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left
neighborhood of `f a`, then `f` is continuous at `a` from the left. -/
lemma strict_mono_incr_on.continuous_at_left_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_closure_image_mem_nhds_within hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of
`f a`, then `f` is continuous at `a` from the left. -/
lemma strict_mono_incr_on.continuous_at_left_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_image_mem_nhds_within hs hfs
/-- If a function `f` is strictly monotonically increasing on a left neighborhood of `a` and the
image of this neighborhood under `f` includes `Iio (f a)`, then `f` is continuous at `a` from the
left. -/
lemma strict_mono_incr_on.continuous_at_left_of_surj_on {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : surj_on f s (Iio (f a))) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_surj_on hs hfs
/-- If a function `f` is strictly monotonically increasing on a neighborhood of `a` and the image of
this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, and every interval
`(f a, b]`, `b > f a`, then `f` is continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a)
(hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨h_mono.continuous_at_left_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_l,
h_mono.continuous_at_right_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of
`f a`, then `f` is continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_closure_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨h_mono.continuous_at_left_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs)
(mem_nhds_within_of_mem_nhds hfs),
h_mono.continuous_at_right_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs)
(mem_nhds_within_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
neighborhood of `a` and the image of this set under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) :
continuous_at f a :=
h_mono.continuous_at_of_closure_image_mem_nhds hs (mem_sets_of_superset hfs subset_closure)
/-- If `f` is a function monotonically increasing function on a neighborhood of `a` and the image of
this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, and every interval `(f a,
b)`, `b > f a`, then `f` is continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨continuous_at_left_of_mono_incr_on_of_exists_between h_mono
(mem_nhds_within_of_mem_nhds hs) hfs_l,
continuous_at_right_of_mono_incr_on_of_exists_between h_mono
(mem_nhds_within_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood
of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then
`f` is continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_closure_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono
(mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs),
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono
(mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood
of `a` and the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs : f '' s ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_of_mono_incr_on_of_closure_image_mem_nhds h_mono hs
(mem_sets_of_superset hfs subset_closure)
/-- A monotone function with densely ordered codomain and a dense range is continuous. -/
lemma monotone.continuous_of_dense_range [densely_ordered β] {f : α → β}
(h_mono : monotone f) (h_dense : dense_range f) :
continuous f :=
continuous_iff_continuous_at.mpr $ λ a,
continuous_at_of_mono_incr_on_of_closure_image_mem_nhds (λ x hx y hy hxy, h_mono hxy)
univ_mem_sets $ by simp only [image_univ, h_dense.closure_eq, univ_mem_sets]
/-- A monotone surjective function with a densely ordered codomain is surjective. -/
lemma monotone.continuous_of_surjective [densely_ordered β] {f : α → β} (h_mono : monotone f)
(h_surj : function.surjective f) :
continuous f :=
h_mono.continuous_of_dense_range h_surj.dense_range
end linear_order
/-!
### Continuity of order isomorphisms
In this section we prove that an `order_iso` is continuous, hence it is a `homeomorph`. We prove
this for an `order_iso` between to partial orders with order topology.
-/
namespace order_iso
variables [partial_order α] [partial_order β] [topological_space α] [topological_space β]
[order_topology α] [order_topology β]
protected lemma continuous (e : α ≃o β) : continuous e :=
begin
rw [‹order_topology β›.topology_eq_generate_intervals],
refine continuous_generated_from (λ s hs, _),
rcases hs with ⟨a, rfl|rfl⟩,
{ rw e.preimage_Ioi, apply is_open_lt' },
{ rw e.preimage_Iio, apply is_open_gt' }
end
/-- An order isomorphism between two linear order `order_topology` spaces is a homeomorphism. -/
def to_homeomorph (e : α ≃o β) : α ≃ₜ β :=
{ continuous_to_fun := e.continuous,
continuous_inv_fun := e.symm.continuous,
.. e }
@[simp] lemma coe_to_homeomorph (e : α ≃o β) : ⇑e.to_homeomorph = e := rfl
@[simp] lemma coe_to_homeomorph_symm (e : α ≃o β) : ⇑e.to_homeomorph.symm = e.symm := rfl
end order_iso
|
96addeb9c7d222ac9041b11d28727053dda1fff9 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Init/Data/Nat/Log2.lean | 5bacca9e682feedf15b78c51b4b1b09b75caf570 | [
"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 | 762 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
prelude
import Init.NotationExtra
import Init.Data.Nat.Linear
namespace Nat
private theorem log2_terminates : ∀ n, n ≥ 2 → n / 2 < n
| 2, _ => by decide
| 3, _ => by decide
| n+4, _ => by
rw [div_eq, if_pos]
refine succ_lt_succ (Nat.lt_trans ?_ (lt_succ_self _))
exact log2_terminates (n+2) (by simp_arith)
simp_arith
/--
Computes `⌊max 0 (log₂ n)⌋`.
`log2 0 = log2 1 = 0`, `log2 2 = 1`, ..., `log2 (2^i) = i`, etc.
-/
@[extern "lean_nat_log2"]
def log2 (n : @& Nat) : Nat :=
if n ≥ 2 then log2 (n / 2) + 1 else 0
decreasing_by exact log2_terminates _ ‹_›
|
2663046255048906de3c6b3bcba21e111fa0f49e | 4aca55eba10c989f0d58647d3c2f371e7da44355 | /src/main1.lean | 177bd5cfa5cd157abb399c8ab6754b2756e81eef | [] | no_license | eric-wieser/l534zhan-my_project | f9fc75fb5454405e1a2fa9b56cf96c355f6f2336 | febc91e76b7b00fe2517f258ca04d27b7f35fcf3 | refs/heads/master | 1,689,218,910,420 | 1,630,439,440,000 | 1,630,439,440,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,604 | lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Lu-Ming Zhang.
-/
import data.matrix.notation
import symmetric_matrix
/-!
# Hadamard product and Kronecker product.
This file defines the Hadamard product `matrix.Hadamard` and the Kronecker product `matrix.Kronecker` and
contains basic properties about them.
## Main definitions
- `matrix.Hadamard`: defines the Hadamard product, which is the pointwise product of two matrices of the same size.
- `matrix.Kronecker`: defines the Kronecker product, denoted by `⊗`.
For `A : matrix I J α` and `B : matrix K L α`, `A ⊗ B ⟨a, b⟩ ⟨c, d⟩` is defined to be ` (A a c) * (B b d)`.
- `matrix.fin_Kronecker`: the `fin` version of `matrix.Kronecker`, denoted by `⊗ₖ`.
For `A : matrix (fin m) (fin n) α` and `B : matrix (fin p) (fin q) α`, `A ⊗ₖ B` is of type `matrix (fin (m * p)) (fin (n * q))`.
The difference from `A ⊗ B` is that each of the index types `fin (m * p)` and `fin (n * q)` of the resulting matrix has a natural order.
## Notation
* `⊙`: the Hadamard product `matrix.Hadamard`;
* `⊗`: the Kronecker product `matrix.Kronecker`;
* `⊗ₖ`: the Kronecker product `fin_Kronecker` of matrices with index types `fin _`.
## References
* <https://en.wikipedia.org/wiki/Hadamard_product_(matrices)>
* <https://en.wikipedia.org/wiki/Kronecker_product>
## Tags
Hadamard product, Kronecker product, Hadamard, Kronecker
-/
variables {α β γ I J K L M N: Type*}
variables {R : Type*}
variables {m n p q r s t: ℕ}
variables [fintype I] [fintype J] [fintype K] [fintype L] [fintype M] [fintype N]
namespace matrix
open_locale matrix big_operators
open complex
/- ## Hadamard product -/
section Hadamard_product
def Hadamard [has_mul α] (A : matrix I J α) (B : matrix I J α) :
matrix I J α :=
λ i j, (A i j) * (B i j)
localized "infix `⊙`:100 := matrix.Hadamard" in matrix -- declares the notation
section basic_properties
variables (A : matrix I J α) (B : matrix I J α) (C : matrix I J α)
/- commutativity -/
lemma Had_comm [comm_semigroup α] : A ⊙ B = B ⊙ A :=
by ext; simp [Hadamard, mul_comm]
/- associativity -/
lemma Had_assoc [semigroup α] : A ⊙ B ⊙ C = A ⊙ (B ⊙ C) :=
by ext; simp [Hadamard, mul_assoc]
/- distributivity -/
section distrib
variables [distrib α]
lemma Had_add : A ⊙ (B + C) = A ⊙ B + A ⊙ C :=
by ext; simp [Hadamard, left_distrib]
lemma add_Had : (B + C) ⊙ A = B ⊙ A + C ⊙ A :=
by ext; simp [Hadamard, right_distrib]
end distrib
/- scalar multiplication -/
section scalar
@[simp] lemma smul_Had
[has_mul α] [has_scalar R α] [is_scalar_tower R α α] (k : R) :
(k • A) ⊙ B = k • A ⊙ B :=
by {ext, simp [Hadamard], exact smul_assoc _ (A i j) _}
@[simp] lemma Had_smul
[has_mul α] [has_scalar R α] [smul_comm_class R α α] (k : R):
A ⊙ (k • B) = k • A ⊙ B :=
by {ext, simp [Hadamard], exact (smul_comm k (A i j) (B i j)).symm}
end scalar
section zero
variables [mul_zero_class α]
@[simp] lemma Had_zero : A ⊙ (0 : matrix I J α) = 0 :=
by ext; simp [Hadamard]
@[simp] lemma zero_Had : (0 : matrix I J α) ⊙ A = 0 :=
by ext; simp [Hadamard]
end zero
section trace
variables [comm_semiring α] [decidable_eq I] [decidable_eq J]
/--`vᵀ (M₁ ⊙ M₂) w = tr ((diagonal v)ᵀ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ)` -/
lemma tr_identity (v : I → α) (w : J → α) (M₁ : matrix I J α) (M₂ : matrix I J α):
dot_product (vec_mul v (M₁ ⊙ M₂)) w =
tr ((diagonal v)ᵀ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ) :=
begin
simp [dot_product, vec_mul, Hadamard, finset.sum_mul],
rw finset.sum_comm,
apply finset.sum_congr, refl, intros i hi,
simp [diagonal, transpose, matrix.mul, dot_product],
apply finset.sum_congr, refl, intros j hj,
ring,
end
/-- `trace` version of `tr_identity` -/
lemma trace_identity (v : I → α) (w : J → α) (M₁ : matrix I J α) (M₂ : matrix I J α):
dot_product (vec_mul v (M₁ ⊙ M₂)) w =
trace I α α ((diagonal v)ᵀ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ) :=
by rw [trace_eq_tr, tr_identity]
/-- `∑ (i : I) (j : J), (M₁ ⊙ M₂) i j = tr (M₁ ⬝ M₂ᵀ)` -/
lemma sum_Had_eq_tr_mul (M₁ : matrix I J α) (M₂ : matrix I J α) :
∑ (i : I) (j : J), (M₁ ⊙ M₂) i j = tr (M₁ ⬝ M₂ᵀ) :=
begin
have h:= tr_identity (λ i, 1 : I → α) (λ i, 1 : J → α) M₁ M₂,
simp at h,
rw finset.sum_comm at h,
assumption,
end
/-- `vᴴ (M₁ ⊙ M₂) w = tr ((diagonal v)ᴴ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ)` over `ℂ` -/
lemma tr_identity_over_ℂ
(v : I → ℂ) (w : J → ℂ) (M₁ : matrix I J ℂ) (M₂ : matrix I J ℂ):
dot_product (vec_mul (star v) (M₁ ⊙ M₂)) w =
tr ((diagonal v)ᴴ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ) :=
begin
simp [dot_product, vec_mul, Hadamard, finset.sum_mul],
rw finset.sum_comm,
apply finset.sum_congr, refl, intros i hi,
simp [diagonal, transpose, conj_transpose, matrix.mul, dot_product, star, has_star.star],
apply finset.sum_congr, refl, intros j hj,
ring_nf,
end
/-- `trace` version of `tr_identity_over_ℂ` -/
lemma trace_identity_over_ℂ
(v : I → ℂ) (w : J → ℂ) (M₁ : matrix I J ℂ) (M₂ : matrix I J ℂ):
dot_product (vec_mul (star v) (M₁ ⊙ M₂)) w =
trace I ℂ ℂ ((diagonal v)ᴴ ⬝ M₁ ⬝ (diagonal w) ⬝ M₂ᵀ) :=
by rw [trace_eq_tr, tr_identity_over_ℂ]
end trace
/-
section rank
variables [decidable_eq J] [field α]
theorem rank_Had_le_rank_mul :
matrix.rank (A ⊙ B) ≤ A.rank * B.rank := sorry
end rank
-/
end basic_properties
/-
section psd
open_locale complex_order
variables {A B : matrix I I ℂ}
variables (ha : A.is_pos_semidef) (hb : B.is_pos_semidef)
--Schur_product_theorem
theorem Hadamard.is_pos_semidef_of_is_pos_semidef : (A ⊙ B).is_pos_semidef :=
sorry
--#check det
variable [decidable_eq I]
theorem det_Had_ge_det_mul_of_psd : ((A ⊙ B).det) ≥ (A.det) * (B.det) :=
sorry
end psd
-/
end Hadamard_product
/- ## end Hadamard product -/
----------------------------------------------------------------------------------
/- ## Kronecker product -/
section Kronecker_product
open_locale matrix
@[elab_as_eliminator]
def Kronecker [has_mul α] (A : matrix I J α) (B : matrix K L α) :
matrix (I × K) (J × L) α :=
λ ⟨i, k⟩ ⟨j, l⟩, (A i j) * (B k l)
/- an infix notation for the Kronecker product -/
localized "infix `⊗`:100 := matrix.Kronecker" in matrix
/- The advantage of the following def is that one can directly #eval the Kronecker product of specific matrices-/
/- ## fin_Kronecker_prodcut -/
@[elab_as_eliminator]
def fin_Kronecker [has_mul α]
(A : matrix (fin m) (fin n) α) (B : matrix (fin p) (fin q) α)
: matrix (fin (m * p)) (fin (n * q)) α :=
λ i j,
A ⟨(i / p), by {have h:= i.2, simp [mul_comm m] at *, apply nat.div_lt_of_lt_mul h}⟩
⟨(j / q), by {have h:= j.2, simp [mul_comm n] at *, apply nat.div_lt_of_lt_mul h}⟩
*
B ⟨(i % p), by {cases p, linarith [i.2], apply nat.mod_lt _ (nat.succ_pos _)}⟩
⟨(j % q), by {cases q, linarith [j.2], apply nat.mod_lt _ (nat.succ_pos _)}⟩
localized "infix `⊗ₖ`:100 := matrix.fin_Kronecker" in matrix
section notations
def matrix_empty : matrix (fin 0) (fin 0) α := λ x, ![]
localized "notation `!![]` := matrix.matrix_empty" in matrix
example : (!![]: matrix (fin 0) (fin 0) α) = ![] := by {ext, have h:= x.2, simp* at *}
end notations
section examples
open_locale matrix
def ex1:= ![![1, 2], ![3, 4]]
def ex2:= ![![0, 5], ![6, 7]]
def ex3:= ![![(1:ℤ), -4, 7], ![-2, 3, 3]]
def ex4:= ![![(8:ℤ), -9, -6, 5], ![1, -3, -4, 7], ![2, 8, -8, -3], ![1, 2, -5, -1]]
#eval (!![]: matrix (fin 0) (fin 0) ℕ)
#eval ex3 ⊗ₖ ex4
#eval ex1 ⊗ₖ ex2
#eval 2 • (ex1 ⊗ₖ ex2)
#eval ex2 ⊗ₖ ![![]]
#eval ![![]] ⊗ₖ ex2
#eval ex2 ⊗ₖ !![]
#eval !![] ⊗ₖ ex2
#eval ![![]] ⊗ₖ (![![]] :matrix (fin 1) (fin 0) ℕ)
end examples
/- ## end fin_Kronecker_prodcut -/
lemma Kronecker_apply [has_mul α]
(A : matrix I J α) (B : matrix K L α) (a : I × K) (b : J × L) :
(A ⊗ B) a b = (A a.1 b.1) * (B a.2 b.2) :=
begin
have ha : a = ⟨a.1, a.2⟩ := by {ext; simp},
have hb : b = ⟨b.1, b.2⟩ := by {ext; simp},
rw [ha, hb], dsimp [Kronecker], refl
end
/- distributivity -/
section distrib
variables [distrib α] -- variables are restricted to this section
variables (A : matrix I J α) (B : matrix K L α) (B' : matrix K L α)
lemma K_add :A ⊗ (B + B') = A ⊗ B + A ⊗ B' :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker, left_distrib]}
lemma add_K :(B + B') ⊗ A = B ⊗ A + B' ⊗ A :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker, right_distrib]}
end distrib
/- distributivity over substraction -/
section distrib_sub
variables [ring α]
variables (A : matrix I J α) (B : matrix K L α) (B' : matrix K L α)
lemma K_sub :A ⊗ (B - B') = A ⊗ B - A ⊗ B' :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker, mul_sub]}
lemma sub_K :(B - B') ⊗ A = B ⊗ A - B' ⊗ A :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker, sub_mul]}
end distrib_sub
/-
section non_comm
variables [decidable_eq I] [decidable_eq K] [decidable_eq J] [decidable_eq L] [mul_one_class α] [add_comm_monoid α]
variables (A : matrix I J α) (B : matrix K L α)
lemma non_comm : ∃ P Q, B ⊗ A = reindex_prod_comm (P ⬝ (A ⊗ B) ⬝ Q) ∧ P.is_perfect_shuffle ∧ Q.is_perfect_shuffle :=
sorry
end non_comm
-/
/-- associativity -/
lemma K_assoc
[semigroup α] (A : matrix I J α) (B : matrix K L α) (C : matrix M N α) :
A ⊗ B ⊗ C = A ⊗ (B ⊗ C) :=
by {ext ⟨⟨a1, b1⟩, c1⟩ ⟨⟨a2, b2⟩, c2⟩, simp[Kronecker, mul_assoc], refl}
section zero
variables [mul_zero_class α] (A : matrix I J α)
@[simp] lemma K_zero : A ⊗ (0 : matrix K L α) = 0 :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker]}
@[simp] lemma K_zero' : A ⊗ ((λ _ _, 0):matrix K L α) = 0 :=
K_zero A
@[simp] lemma zero_K : (0 : matrix K L α) ⊗ A = 0 :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker]}
@[simp] lemma zero_K' : ((λ _ _, 0):matrix K L α) ⊗ A = 0 :=
zero_K A
end zero
/-- `1 ⊗ 1 = 1`.
The Kronecker product of two identity matrices is an identity matrix. -/
@[simp] lemma one_K_one
[mul_zero_one_class α] [decidable_eq I] [decidable_eq J] :
(1 :matrix I I α) ⊗ (1 :matrix J J α) = 1 :=
begin
ext ⟨a,b⟩ ⟨c,d⟩,
by_cases h: a = c,
any_goals {by_cases g: b = d},
any_goals {simp[*, Kronecker] at *},
end
section neg
variables [ring α]
variables (A : matrix I J α) (B : matrix K L α)
@[simp] lemma neg_K: (-A) ⊗ B = - A ⊗ B := by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker]}
@[simp] lemma K_neg: A ⊗ (-B) = - A ⊗ B := by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker]}
end neg
/- scalar multiplication -/
section scalar
@[simp] lemma smul_K
[has_mul α] [has_scalar R α] [is_scalar_tower R α α]
(k : R) (A : matrix I J α) (B : matrix K L α) :
(k • A) ⊗ B = k • A ⊗ B :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker], exact smul_assoc _ (A a c) _}
@[simp] lemma K_smul
[has_mul α] [has_scalar R α] [smul_comm_class R α α]
(k : R) (A : matrix I J α) (B : matrix K L α) :
A ⊗ (k • B) = k • A ⊗ B :=
by {ext ⟨a,b⟩ ⟨c,d⟩, simp [Kronecker], exact (smul_comm k (A a c) _).symm}
end scalar
/- Kronecker product mixes matrix multiplication -/
section Kronecker_mul
variables [comm_ring α]
variables
(A : matrix I J α) (C : matrix J K α)
(B : matrix L M α) (D : matrix M N α)
lemma K_mul: (A ⊗ B) ⬝ (C ⊗ D) = (A ⬝ C) ⊗ (B ⬝ D) :=
begin
ext ⟨a,b⟩ ⟨c,d⟩,
simp [matrix.mul,dot_product,Kronecker,finset.sum_mul,finset.mul_sum],
rw [←finset.univ_product_univ,finset.sum_product],
simp [Kronecker._match_1,Kronecker._match_2],
rw finset.sum_comm,
repeat {congr, ext},
ring,
end
variables [decidable_eq I] [decidable_eq M] [decidable_eq L] [decidable_eq J]
@[simp] lemma one_K_mul: (1 ⊗ B) ⬝ (A ⊗ 1) = A ⊗ B := by simp [K_mul]
@[simp] lemma K_one_mul: (A ⊗ 1) ⬝ (1 ⊗ B) = A ⊗ B := by simp [K_mul]
end Kronecker_mul
/- Kronecker product mixes Hadamard product -/
section Kronecker_Hadamard
variables [comm_semigroup α]
(A : matrix I J α) (C : matrix I J α)
(B : matrix K L α) (D : matrix K L α)
lemma Kronecker_Hadamard : (A ⊗ B) ⊙ (C ⊗ D) = (A ⊙ C) ⊗ (B ⊙ D) :=
begin
ext ⟨a, b⟩ ⟨c, d⟩,
simp [Hadamard, Kronecker],
rw ← mul_assoc,
rw mul_assoc _ (B b d),
rw mul_comm (B b d),
simp [mul_assoc]
end
end Kronecker_Hadamard
lemma transpose_K
[has_mul α] (A : matrix I J α) (B : matrix K L α):
(A ⊗ B)ᵀ = Aᵀ ⊗ Bᵀ :=
by ext ⟨a,b⟩ ⟨c,d⟩; simp [transpose, Kronecker]
lemma conj_transpose_K
[comm_monoid α] [star_monoid α] (M₁ : matrix I J α) (M₂ : matrix K L α) :
(M₁ ⊗ M₂)ᴴ = M₁ᴴ ⊗ M₂ᴴ:=
by ext ⟨a,b⟩ ⟨c,d⟩; simp [conj_transpose,Kronecker, mul_comm]
section trace
variables [semiring β] [non_unital_non_assoc_semiring α] [module β α]
variables (A : matrix I I α) (B : matrix J J α)
lemma trace_K: trace (I × J) β α (A ⊗ B) = (trace I β α A) * (trace J β α B) :=
begin
simp[Kronecker, trace, ←finset.univ_product_univ, finset.sum_product,
Kronecker._match_2,finset.sum_mul,finset.mul_sum],
rw finset.sum_comm,
end
end trace
section inverse
variables [decidable_eq I] [decidable_eq J] [comm_ring α]
variables (A : matrix I I α) (B : matrix J J α) (C : matrix I I α)
lemma K_inverse [invertible A] [invertible B] :(A ⊗ B)⁻¹ = A⁻¹ ⊗ B⁻¹ :=
begin
suffices : (A⁻¹ ⊗ B⁻¹) ⬝ (A ⊗ B) = 1,
apply inv_eq_left_inv this,
simp [K_mul],
end
@[simp] noncomputable
def Kronecker.invertible_of_invertible [invertible A] [invertible B] : invertible (A ⊗ B) :=
⟨A⁻¹ ⊗ B⁻¹, by simp [K_mul], by simp [K_mul]⟩
@[simp] lemma Kronecker.unit_of_unit (ha : is_unit A) (hb : is_unit B) : is_unit (A ⊗ B) :=
@is_unit_of_invertible _ _ (A ⊗ B) (@Kronecker.invertible_of_invertible _ _ _ _ _ _ _ _ A B (is_unit.invertible ha) (is_unit.invertible hb))
end inverse
section symmetric
variables [has_mul α]
@[simp] lemma Kronecker.is_sym_of_is_sym {A : matrix I I α} {B : matrix J J α} (ha: A.is_sym) (hb: B.is_sym) :
(A ⊗ B).is_sym := by simp [matrix.is_sym, transpose_K, *] at *
@[simp] lemma Kronecker.is_Hermitian_of_is_Hermitian {A : matrix I I ℂ} {B : matrix J J ℂ} (ha: A.is_Hermitian) (hb: B.is_Hermitian) :
(A ⊗ B).is_Hermitian := by simp [matrix.is_Hermitian, conj_transpose_K, *] at *
end symmetric
/-
section pos_def
@[simp]
lemma Kronecker.is_pos_def_of_is_pos_def {A : matrix I I ℂ} {B : matrix J J ℂ} (ha : A.is_pos_def) (hb : B.is_pos_def) :
(A ⊗ B).is_pos_def :=
begin
/-
simp [matrix.is_pos_def, *] at *,
simp [dot_product, mul_vec] at *,
intros v hv,
simp [←finset.univ_product_univ, finset.sum_product],
simp [Kronecker,finset.mul_sum] at *,
have h1 := ha.2,
have h2 := hb.2,
-/
sorry -- I suspect there are more missing lemmas to get this
end
end pos_def
-/
section ortho
variables [decidable_eq I] [decidable_eq J]
@[simp] lemma Kronecker.is_ortho_of_is_ortho {A : matrix I I ℝ} {B : matrix J J ℝ} (ha : A.is_ortho) (hb : B.is_ortho) :
(A ⊗ B).is_ortho := by simp [matrix.is_ortho, transpose_K, K_mul, ha, hb, *] at *
end ortho
section perm
open equiv
variables [decidable_eq I] [decidable_eq J] [mul_zero_one_class α]
variables {A : matrix I I α} {B : matrix J J α}
@[simp] lemma Kronecker.is_perm_of_is_perm (ha : A.is_perm) (hb : B.is_perm) :
(A ⊗ B).is_perm :=
begin
rcases ha with ⟨σ₁, rfl⟩,
rcases hb with ⟨σ₂, rfl⟩,
use prod_congr σ₁ σ₂,
ext ⟨a,b⟩ ⟨c,d⟩,
by_cases h1: σ₁ a = c,
all_goals {simp [*, perm.to_matrix, Kronecker]},
end
end perm
/-
section det
variables [comm_ring α] [decidable_eq I] [decidable_eq J]
variables
#check det
lemma K_det (A : matrix I I α) (B : matrix J J α) :
(A ⊗ B).det = (A.det)^(fintype.card J) * (B.det)^(fintype.card I) :=
sorry
lemma K_det' (A : matrix (fin n) (fin n) α) (B : matrix (fin m) (fin m) α) :
(A ⊗ B).det = (A.det)^m * (B.det)^n := by simp [K_det, fintype.card_fin]
end det
-/
end Kronecker_product
open_locale matrix
section dot_product
lemma dot_product_Kronecker_row [has_mul α] [add_comm_monoid α]
(A : matrix I K α) (B : matrix J L α) (a b : I × J):
dot_product ((A ⊗ B) a) ((A ⊗ B) b) =
∑ (k : K) (l : L), (A a.1 k * B a.2 l) * (A b.1 k * B b.2 l) :=
by simp [dot_product, ←finset.univ_product_univ, finset.sum_product, Kronecker_apply]
lemma dot_product_Kronecker_row' [comm_semiring α]
(A : matrix I K α) (B : matrix J L α) (a b : I × J):
dot_product ((A ⊗ B) a) ((A ⊗ B) b) =
(∑ (k : K), (A a.1 k * A b.1 k)) * ∑ (l : L), (B a.2 l * B b.2 l) :=
begin
simp [dot_product_Kronecker_row, finset.mul_sum, finset.sum_mul],
repeat {apply finset.sum_congr rfl, intros _ _},
ring
end
lemma dot_product_Kronecker_row_split [comm_semiring α]
(A : matrix I K α) (B : matrix J L α) (a b : I × J):
dot_product ((A ⊗ B) a) ((A ⊗ B) b) =
(dot_product (A a.1) (A b.1)) * (dot_product (B a.2) (B b.2)) :=
by rw [dot_product_Kronecker_row', dot_product, dot_product]
end dot_product
section sym
/-- `A ⊗ B` is symmetric if `A` and `B` are symmetric. -/
lemma is_sym_K_of [has_mul α] {A : matrix I I α} {B : matrix J J α}
(ha : A.is_sym) (hb : B.is_sym) : (A ⊗ B).is_sym :=
begin
ext ⟨a, b⟩ ⟨c, d⟩,
simp [transpose_K, Kronecker, ha.apply', hb.apply'],
end
end sym
/- ## end Kronecker product -/
end matrix
----------------------------------------------- end of file |
419d9f3e258b02563caaa298c09e4692bbd58499 | 5a5e1bb8063d7934afac91f30aa17c715821040b | /lean3SOS/src/test/float.lean | 0347093c23253346d7da7ecb6dc72c2b1f7c95c8 | [] | no_license | ramonfmir/leanSOS | 1883392d73710db5c6e291a2abd03a6c5b44a42b | 14b50713dc887f6d408b7b2bce1f8af5bb619958 | refs/heads/main | 1,683,348,826,105 | 1,622,056,982,000 | 1,622,056,982,000 | 341,232,766 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,755 | lean | import float.basic
import float.round
import float.div
set_option profiler true
-- Test add 1: 0 + 1
#eval rat.mk 0 1 + rat.mk 1 1
#eval float.mk 0 0 + float.mk 1 0 -- OK
-- Test add 2: 1/1024 + 3/4096
#eval rat.mk 1 1024 + rat.mk 3 4096
#eval float.mk 1 (-10) + float.mk 3 (-12)
-- Test add 3: 12345/1048576 + -6789/32768
#eval rat.mk 12345 1048576 + rat.mk (-6789) 32768
#eval float.mk 12345 (-20) + float.mk (-6789) (-15)
-- Test add 4: 12345789101112/2^100 + -123457891011/2^7898
#eval rat.mk 12345789101112 (2 ^ 100) + rat.mk (-123457891011) (2 ^ 7898)
#eval float.mk 12345789101112 (-100) + float.mk (-1234578910111) (-7898)
-- Test mul 1: 0 * 1
#eval rat.mk 0 1 * rat.mk 1 1
#eval float.mk 0 0 * float.mk 1 0
-- Test mul 2: 1/1024 * 3/4096
#eval rat.mk 1 1024 * rat.mk 3 4096
#eval float.mk 1 (-10) * float.mk 3 (-12)
-- Test mul 3: 12345/1048576 * -6789/32768
#eval rat.mk 12345 1048576 * rat.mk (-6789) 32768
#eval float.mk 12345 (-20) * float.mk (-6789) (-15)
-- Test mul 4: 12345789101112/2^100 * -123457891011/2^7898
#eval rat.mk 12345789101112 (2 ^ 100) * rat.mk (-123457891011) (2 ^ 7898)
#eval float.mk 12345789101112 (-100) * float.mk (-1234578910111) (-7898)
-- Test div 1: 0 / 1
#eval rat.mk 0 1 / rat.mk 1 1
#eval float.mk 0 0 / float.mk 1 0
-- Test div 2: 1/1024 / 3/4096
#eval rat.mk 1 1024 / rat.mk 3 4096
#eval float.mk 1 (-10) / float.mk 3 (-12)
-- Test div 3: 12345/1048576 / -6789/32768
#eval rat.mk 12345 1048576 / rat.mk (-6789) 32768
#eval float.mk 12345 (-20) / float.mk (-6789) (-15)
-- Test div 4: 12345789101112/2^100 / -123457891011/2^7898
#eval rat.mk 12345789101112 (2 ^ 100) / rat.mk (-123457891011) (2 ^ 7898)
#eval float.mk 12345789101112 (-100) / float.mk (-1234578910111) (-7898)
|
fb295087408d07acd0408e71afd437a373ef9fe8 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/run/ac_expr.lean | ee8ce1c51c540d75d80ebf81dd4e7bd8911cf61e | [
"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,288 | lean | import Std
inductive Expr where
| var (i : Nat)
| op (lhs rhs : Expr)
deriving Inhabited, Repr
def List.getIdx : List α → Nat → α → α
| [], i, u => u
| a::as, 0, u => a
| a::as, i+1, u => getIdx as i u
structure Context (α : Type u) where
op : α → α → α
assoc : (a b c : α) → op (op a b) c = op a (op b c)
comm : (a b : α) → op a b = op b a
vars : List α
someVal : α
theorem Context.left_comm (ctx : Context α) (a b c : α) : ctx.op a (ctx.op b c) = ctx.op b (ctx.op a c) := by
rw [← ctx.assoc, ctx.comm a b, ctx.assoc]
def Expr.denote (ctx : Context α) : Expr → α
| Expr.op a b => ctx.op (denote ctx a) (denote ctx b)
| Expr.var i => ctx.vars.getIdx i ctx.someVal
theorem Expr.denote_op (ctx : Context α) (a b : Expr) : denote ctx (Expr.op a b) = ctx.op (denote ctx a) (denote ctx b) :=
rfl
def Expr.concat : Expr → Expr → Expr
| Expr.op a b, c => Expr.op a (concat b c)
| Expr.var i, c => Expr.op (Expr.var i) c
theorem Expr.denote_concat (ctx : Context α) (a b : Expr) : denote ctx (concat a b) = denote ctx (Expr.op a b) := by
induction a with
| var i => rfl
| op _ _ _ ih => simp [denote, ih, ctx.assoc]
def Expr.flat : Expr → Expr
| Expr.op a b => concat (flat a) (flat b)
| Expr.var i => Expr.var i
theorem Expr.denote_flat (ctx : Context α) (e : Expr) : denote ctx (flat e) = denote ctx e := by
induction e with
| var i => rfl
| op a b ih₁ ih₂ => simp [flat, denote, denote_concat, ih₁, ih₂]
theorem Expr.eq_of_flat (ctx : Context α) (a b : Expr) (h : flat a = flat b) : denote ctx a = denote ctx b := by
have h := congrArg (denote ctx) h
simp [denote_flat] at h
assumption
def Expr.length : Expr → Nat
| op a b => 1 + b.length
| _ => 1
def Expr.sort (e : Expr) : Expr :=
loop e.length e
where
loop : Nat → Expr → Expr
| fuel+1, Expr.op a e =>
let (e₁, e₂) := swap a e
Expr.op e₁ (loop fuel e₂)
| _, e => e
swap : Expr → Expr → Expr × Expr
| Expr.var i, Expr.op (Expr.var j) e =>
if i > j then
let (e₁, e₂) := swap (Expr.var j) e
(e₁, Expr.op (Expr.var i) e₂)
else
let (e₁, e₂) := swap (Expr.var i) e
(e₁, Expr.op (Expr.var j) e₂)
| Expr.var i, Expr.var j =>
if i > j then
(Expr.var j, Expr.var i)
else
(Expr.var i, Expr.var j)
| e₁, e₂ => (e₁, e₂)
theorem Expr.denote_sort (ctx : Context α) (e : Expr) : denote ctx (sort e) = denote ctx e := by
apply denote_loop
where
denote_loop (n : Nat) (e : Expr) : denote ctx (sort.loop n e) = denote ctx e := by
induction n generalizing e with
| zero => rfl
| succ n ih =>
match e with
| var _ => rfl
| op a b =>
simp [denote, sort.loop]
match h:sort.swap a b with
| (r₁, r₂) =>
have hs := denote_swap a b
rw [h] at hs
simp [denote] at hs
simp [denote, ih]
assumption
denote_swap (e₁ e₂ : Expr) : denote ctx (Expr.op (sort.swap e₁ e₂).1 (sort.swap e₁ e₂).2) = denote ctx (Expr.op e₁ e₂) := by
induction e₂ generalizing e₁ with
| op a b ih' ih =>
clear ih'
cases e₁ with
| var i =>
cases a with
| var j =>
by_cases h : i > j
focus
simp [sort.swap, h]
match h:sort.swap (var j) b with
| (r₁, r₂) => simp; rw [denote_op (a := var i), ← ih]; simp [h, denote]; rw [Context.left_comm]
focus
simp [sort.swap, h]
match h:sort.swap (var i) b with
| (r₁, r₂) =>
simp
rw [denote_op (a := var i), denote_op (a := var j), Context.left_comm, ← denote_op (a := var i), ← ih]
simp [h, denote]
rw [Context.left_comm]
| _ => rfl
| _ => rfl
| var j =>
cases e₁ with
| var i =>
by_cases h : i > j
focus simp [sort.swap, h, denote, Context.comm]
focus simp [sort.swap, h]
| _ => rfl
theorem Expr.eq_of_sort_flat (ctx : Context α) (a b : Expr) (h : sort (flat a) = sort (flat b)) : denote ctx a = denote ctx b := by
have h := congrArg (denote ctx) h
simp [denote_flat, denote_sort] at h
assumption
theorem ex₁ (x₁ x₂ x₃ x₄ : Nat) : (x₁ + x₂) + (x₃ + x₄) = x₁ + x₂ + x₃ + x₄ :=
Expr.eq_of_flat
{ op := Nat.add
assoc := Nat.add_assoc
comm := Nat.add_comm
vars := [x₁, x₂, x₃, x₄],
someVal := x₁ }
(Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))
(Expr.op (Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.var 2)) (Expr.var 3))
rfl
theorem ex₂ (x₁ x₂ x₃ x₄ : Nat) : (x₁ + x₂) + (x₃ + x₄) = x₃ + x₁ + x₂ + x₄ :=
Expr.eq_of_sort_flat
{ op := Nat.add
assoc := Nat.add_assoc
comm := Nat.add_comm
vars := [x₁, x₂, x₃, x₄],
someVal := x₁ }
(Expr.op (Expr.op (Expr.var 0) (Expr.var 1)) (Expr.op (Expr.var 2) (Expr.var 3)))
(Expr.op (Expr.op (Expr.op (Expr.var 2) (Expr.var 0)) (Expr.var 1)) (Expr.var 3))
rfl
#print ex₂
|
f9ed648b7eaf3cc0023cf615396b6f3bd176f038 | 2914802b4ed2844bcc7ef2a02cda40ec82fb975f | /hott/algebra/category/constructions/functor.hlean | 974cc3b8b62c072cd5f0768cacff46dd7d9b85b4 | [
"Apache-2.0"
] | permissive | UlrikBuchholtz/lean | 60a81367f049cddb37083d3fe3e6fd2f96b7d5e7 | cc70845332e63a1f1be21dc1f96d17269fc85909 | refs/heads/master | 1,586,129,615,121 | 1,467,727,039,000 | 1,468,085,570,000 | 30,432,484 | 0 | 0 | null | 1,423,255,902,000 | 1,423,255,902,000 | null | UTF-8 | Lean | false | false | 15,970 | 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, Jakob von Raumer
Functor precategory and category
-/
import ..nat_trans ..category .opposite
open eq category is_trunc nat_trans iso is_equiv category.hom
namespace functor
definition precategory_functor [instance] [constructor] (D C : Precategory)
: precategory (functor C D) :=
precategory.mk (λa b, nat_trans a b)
(λ a b c g f, nat_trans.compose g f)
(λ a, nat_trans.id)
(λ a b c d h g f, !nat_trans.assoc)
(λ a b f, !nat_trans.id_left)
(λ a b f, !nat_trans.id_right)
definition Precategory_functor [reducible] [constructor] (D C : Precategory) : Precategory :=
precategory.Mk (precategory_functor D C)
infixr ` ^c `:80 := Precategory_functor
section
/- we prove that if a natural transformation is pointwise an iso, then it is an iso -/
variables {C D : Precategory} {F G : C ⇒ D} (η : F ⟹ G) [iso : Π(a : C), is_iso (η a)]
include iso
definition nat_trans_inverse [constructor] : G ⟹ F :=
nat_trans.mk
(λc, (η c)⁻¹)
(λc d f,
abstract begin
apply comp_inverse_eq_of_eq_comp,
transitivity (natural_map η d)⁻¹ ∘ to_fun_hom G f ∘ natural_map η c,
{apply eq_inverse_comp_of_comp_eq, symmetry, apply naturality},
{apply assoc}
end end)
definition nat_trans_left_inverse : nat_trans_inverse η ∘n η = 1 :=
begin
fapply (apdt011 nat_trans.mk),
apply eq_of_homotopy, intro c, apply left_inverse,
apply eq_of_homotopy3, intros, apply is_set.elim
end
definition nat_trans_right_inverse : η ∘n nat_trans_inverse η = 1 :=
begin
fapply (apdt011 nat_trans.mk),
apply eq_of_homotopy, intro c, apply right_inverse,
apply eq_of_homotopy3, intros, apply is_set.elim
end
definition is_natural_iso [constructor] : is_iso η :=
is_iso.mk _ (nat_trans_left_inverse η) (nat_trans_right_inverse η)
variable (iso)
definition natural_iso.mk [constructor] : F ≅ G :=
iso.mk _ (is_natural_iso η)
omit iso
variables (F G)
definition is_natural_inverse (η : Πc, F c ≅ G c)
(nat : Π⦃a b : C⦄ (f : hom a b), G f ∘ to_hom (η a) = to_hom (η b) ∘ F f)
{a b : C} (f : hom a b) : F f ∘ to_inv (η a) = to_inv (η b) ∘ G f :=
let η' : F ⟹ G := nat_trans.mk (λc, to_hom (η c)) @nat in
naturality (nat_trans_inverse η') f
definition is_natural_inverse' (η₁ : Πc, F c ≅ G c) (η₂ : F ⟹ G) (p : η₁ ~ η₂)
{a b : C} (f : hom a b) : F f ∘ to_inv (η₁ a) = to_inv (η₁ b) ∘ G f :=
is_natural_inverse F G η₁ abstract λa b g, (p a)⁻¹ ▸ (p b)⁻¹ ▸ naturality η₂ g end f
variables {F G}
definition natural_iso.MK [constructor]
(η : Πc, F c ⟶ G c) (p : Π(c c' : C) (f : c ⟶ c'), G f ∘ η c = η c' ∘ F f)
(θ : Πc, G c ⟶ F c) (r : Πc, θ c ∘ η c = id) (q : Πc, η c ∘ θ c = id) : F ≅ G :=
iso.mk (nat_trans.mk η p) (@(is_natural_iso _) (λc, is_iso.mk (θ c) (r c) (q c)))
end
section
/- and conversely, if a natural transformation is an iso, it is componentwise an iso -/
variables {A B C D : Precategory} {F G : C ⇒ D} (η : hom F G) [isoη : is_iso η] (c : C)
include isoη
definition componentwise_is_iso [constructor] : is_iso (η c) :=
@is_iso.mk _ _ _ _ _ (natural_map η⁻¹ c) (ap010 natural_map ( left_inverse η) c)
(ap010 natural_map (right_inverse η) c)
local attribute componentwise_is_iso [instance]
variable {isoη}
definition natural_map_inverse : natural_map η⁻¹ c = (η c)⁻¹ := idp
variable [isoη]
definition naturality_iso {c c' : C} (f : c ⟶ c') : G f = η c' ∘ F f ∘ (η c)⁻¹ :=
calc
G f = (G f ∘ η c) ∘ (η c)⁻¹ : by rewrite comp_inverse_cancel_right
... = (η c' ∘ F f) ∘ (η c)⁻¹ : by rewrite naturality
... = η c' ∘ F f ∘ (η c)⁻¹ : by rewrite assoc
definition naturality_iso' {c c' : C} (f : c ⟶ c') : (η c')⁻¹ ∘ G f ∘ η c = F f :=
calc
(η c')⁻¹ ∘ G f ∘ η c = (η c')⁻¹ ∘ η c' ∘ F f : by rewrite naturality
... = F f : by rewrite inverse_comp_cancel_left
omit isoη
definition componentwise_iso (η : F ≅ G) (c : C) : F c ≅ G c :=
iso.mk (natural_map (to_hom η) c)
(@componentwise_is_iso _ _ _ _ (to_hom η) (struct η) c)
definition componentwise_iso_id (c : C) : componentwise_iso (iso.refl F) c = iso.refl (F c) :=
iso_eq (idpath (ID (F c)))
definition componentwise_iso_iso_of_eq (p : F = G) (c : C)
: componentwise_iso (iso_of_eq p) c = iso_of_eq (ap010 to_fun_ob p c) :=
eq.rec_on p !componentwise_iso_id
theorem naturality_iso_id {F : C ⇒ C} (η : F ≅ 1) (c : C)
: componentwise_iso η (F c) = F (componentwise_iso η c) :=
comp.cancel_left (to_hom (componentwise_iso η c))
((naturality (to_hom η)) (to_hom (componentwise_iso η c)))
definition natural_map_hom_of_eq (p : F = G) (c : C)
: natural_map (hom_of_eq p) c = hom_of_eq (ap010 to_fun_ob p c) :=
eq.rec_on p idp
definition natural_map_inv_of_eq (p : F = G) (c : C)
: natural_map (inv_of_eq p) c = hom_of_eq (ap010 to_fun_ob p c)⁻¹ :=
eq.rec_on p idp
definition hom_of_eq_compose_right {H : B ⇒ C} (p : F = G)
: hom_of_eq (ap (λx, x ∘f H) p) = hom_of_eq p ∘nf H :=
eq.rec_on p idp
definition inv_of_eq_compose_right {H : B ⇒ C} (p : F = G)
: inv_of_eq (ap (λx, x ∘f H) p) = inv_of_eq p ∘nf H :=
eq.rec_on p idp
definition hom_of_eq_compose_left {H : D ⇒ C} (p : F = G)
: hom_of_eq (ap (λx, H ∘f x) p) = H ∘fn hom_of_eq p :=
by induction p; exact !fn_id⁻¹
definition inv_of_eq_compose_left {H : D ⇒ C} (p : F = G)
: inv_of_eq (ap (λx, H ∘f x) p) = H ∘fn inv_of_eq p :=
by induction p; exact !fn_id⁻¹
definition assoc_natural [constructor] (H : C ⇒ D) (G : B ⇒ C) (F : A ⇒ B)
: H ∘f (G ∘f F) ⟹ (H ∘f G) ∘f F :=
change_natural_map (hom_of_eq !functor.assoc)
(λa, id)
(λa, !natural_map_hom_of_eq ⬝ ap hom_of_eq !ap010_assoc)
definition assoc_natural_rev [constructor] (H : C ⇒ D) (G : B ⇒ C) (F : A ⇒ B)
: (H ∘f G) ∘f F ⟹ H ∘f (G ∘f F) :=
change_natural_map (inv_of_eq !functor.assoc)
(λa, id)
(λa, !natural_map_inv_of_eq ⬝ ap (λx, hom_of_eq x⁻¹) !ap010_assoc)
definition id_left_natural [constructor] (F : C ⇒ D) : functor.id ∘f F ⟹ F :=
change_natural_map
(hom_of_eq !functor.id_left)
(λc, id)
(λc, by induction F; exact !natural_map_hom_of_eq ⬝ ap hom_of_eq !ap010_functor_mk_eq_constant)
definition id_left_natural_rev [constructor] (F : C ⇒ D) : F ⟹ functor.id ∘f F :=
change_natural_map
(inv_of_eq !functor.id_left)
(λc, id)
(λc, by induction F; exact !natural_map_inv_of_eq ⬝
ap (λx, hom_of_eq x⁻¹) !ap010_functor_mk_eq_constant)
definition id_right_natural [constructor] (F : C ⇒ D) : F ∘f functor.id ⟹ F :=
change_natural_map
(hom_of_eq !functor.id_right)
(λc, id)
(λc, by induction F; exact !natural_map_hom_of_eq ⬝ ap hom_of_eq !ap010_functor_mk_eq_constant)
definition id_right_natural_rev [constructor] (F : C ⇒ D) : F ⟹ F ∘f functor.id :=
change_natural_map
(inv_of_eq !functor.id_right)
(λc, id)
(λc, by induction F; exact !natural_map_inv_of_eq ⬝
ap (λx, hom_of_eq x⁻¹) !ap010_functor_mk_eq_constant)
end
section
variables {C D E : Precategory} {G G' : D ⇒ E} {F F' : C ⇒ D} {J : D ⇒ D}
definition is_iso_nf_compose [constructor] (G : D ⇒ E) (η : F ⟹ F') [H : is_iso η]
: is_iso (G ∘fn η) :=
is_iso.mk
(G ∘fn @inverse (C ⇒ D) _ _ _ η _)
abstract !fn_n_distrib⁻¹ ⬝ ap (λx, G ∘fn x) (@left_inverse (C ⇒ D) _ _ _ η _) ⬝ !fn_id end
abstract !fn_n_distrib⁻¹ ⬝ ap (λx, G ∘fn x) (@right_inverse (C ⇒ D) _ _ _ η _) ⬝ !fn_id end
definition is_iso_fn_compose [constructor] (η : G ⟹ G') (F : C ⇒ D) [H : is_iso η]
: is_iso (η ∘nf F) :=
is_iso.mk
(@inverse (D ⇒ E) _ _ _ η _ ∘nf F)
abstract !n_nf_distrib⁻¹ ⬝ ap (λx, x ∘nf F) (@left_inverse (D ⇒ E) _ _ _ η _) ⬝ !id_nf end
abstract !n_nf_distrib⁻¹ ⬝ ap (λx, x ∘nf F) (@right_inverse (D ⇒ E) _ _ _ η _) ⬝ !id_nf end
definition functor_iso_compose [constructor] (G : D ⇒ E) (η : F ≅ F') : G ∘f F ≅ G ∘f F' :=
iso.mk _ (is_iso_nf_compose G (to_hom η))
definition iso_functor_compose [constructor] (η : G ≅ G') (F : C ⇒ D) : G ∘f F ≅ G' ∘f F :=
iso.mk _ (is_iso_fn_compose (to_hom η) F)
infixr ` ∘fi ` :62 := functor_iso_compose
infixr ` ∘if ` :62 := iso_functor_compose
/- TODO: also needs n_nf_distrib and id_nf for these compositions
definition nidf_compose [constructor] (η : J ⟹ 1) (F : C ⇒ D) [H : is_iso η]
: is_iso (η ∘n1f F) :=
is_iso.mk
(@inverse (D ⇒ D) _ _ _ η _ ∘1nf F)
abstract _ end
_
definition idnf_compose [constructor] (η : 1 ⟹ J) (F : C ⇒ D) [H : is_iso η]
: is_iso (η ∘1nf F) :=
is_iso.mk _
_
_
definition fnid_compose [constructor] (F : D ⇒ E) (η : J ⟹ 1) [H : is_iso η]
: is_iso (F ∘fn1 η) :=
is_iso.mk _
_
_
definition fidn_compose [constructor] (F : D ⇒ E) (η : 1 ⟹ J) [H : is_iso η]
: is_iso (F ∘f1n η) :=
is_iso.mk _
_
_
-/
end
namespace functor
variables {C : Precategory} {D : Category} {F G : D ^c C}
definition eq_of_iso_ob (η : F ≅ G) (c : C) : F c = G c :=
by apply eq_of_iso; apply componentwise_iso; exact η
local attribute functor.to_fun_hom [reducible]
definition eq_of_iso (η : F ≅ G) : F = G :=
begin
fapply functor_eq,
{exact (eq_of_iso_ob η)},
{intro c c' f,
esimp [eq_of_iso_ob, inv_of_eq, hom_of_eq, eq_of_iso],
rewrite [*right_inv iso_of_eq],
symmetry, apply @naturality_iso _ _ _ _ _ (iso.struct _)
}
end
definition iso_of_eq_eq_of_iso (η : F ≅ G) : iso_of_eq (eq_of_iso η) = η :=
begin
apply iso_eq,
apply nat_trans_eq,
intro c,
rewrite natural_map_hom_of_eq, esimp [eq_of_iso],
rewrite ap010_functor_eq, esimp [hom_of_eq,eq_of_iso_ob],
rewrite (right_inv iso_of_eq),
end
definition eq_of_iso_iso_of_eq (p : F = G) : eq_of_iso (iso_of_eq p) = p :=
begin
apply functor_eq2,
intro c,
esimp [eq_of_iso],
rewrite ap010_functor_eq,
esimp [eq_of_iso_ob],
rewrite componentwise_iso_iso_of_eq,
rewrite (left_inv iso_of_eq)
end
definition is_univalent (D : Category) (C : Precategory) : is_univalent (D ^c C) :=
λF G, adjointify _ eq_of_iso
iso_of_eq_eq_of_iso
eq_of_iso_iso_of_eq
end functor
definition category_functor [instance] [constructor] (D : Category) (C : Precategory)
: category (D ^c C) :=
category.mk (D ^c C) (functor.is_univalent D C)
definition Category_functor [constructor] (D : Category) (C : Precategory) : Category :=
category.Mk (D ^c C) !category_functor
--this definition is only useful if the exponent is a category,
-- and the elaborator has trouble with inserting the coercion
definition Category_functor' [constructor] (D C : Category) : Category :=
Category_functor D C
namespace ops
infixr ` ^c2 `:35 := Category_functor
end ops
namespace functor
variables {C : Precategory} {D : Category} {F G : D ^c C}
definition eq_of_pointwise_iso (η : F ⟹ G) (iso : Π(a : C), is_iso (η a)) : F = G :=
eq_of_iso (natural_iso.mk η iso)
definition iso_of_eq_eq_of_pointwise_iso (η : F ⟹ G) (iso : Π(c : C), is_iso (η c))
: iso_of_eq (eq_of_pointwise_iso η iso) = natural_iso.mk η iso :=
!iso_of_eq_eq_of_iso
definition hom_of_eq_eq_of_pointwise_iso (η : F ⟹ G) (iso : Π(c : C), is_iso (η c))
: hom_of_eq (eq_of_pointwise_iso η iso) = η :=
!hom_of_eq_eq_of_iso
definition inv_of_eq_eq_of_pointwise_iso (η : F ⟹ G) (iso : Π(c : C), is_iso (η c))
: inv_of_eq (eq_of_pointwise_iso η iso) = nat_trans_inverse η :=
!inv_of_eq_eq_of_iso
end functor
/-
functors involving only the functor category
(see ..functor.curry for some other functors involving also products)
-/
variables {C D I : Precategory}
definition constant2_functor [constructor] (F : I ⇒ D ^c C) (c : C) : I ⇒ D :=
functor.mk (λi, to_fun_ob (F i) c)
(λi j f, natural_map (F f) c)
abstract (λi, ap010 natural_map !respect_id c ⬝ proof idp qed) end
abstract (λi j k g f, ap010 natural_map !respect_comp c) end
definition constant2_functor_natural [constructor] (F : I ⇒ D ^c C) {c d : C} (f : c ⟶ d)
: constant2_functor F c ⟹ constant2_functor F d :=
nat_trans.mk (λi, to_fun_hom (F i) f)
(λi j k, (naturality (F k) f)⁻¹)
definition functor_flip [constructor] (F : I ⇒ D ^c C) : C ⇒ D ^c I :=
functor.mk (constant2_functor F)
@(constant2_functor_natural F)
abstract begin intros, apply nat_trans_eq, intro i, esimp, apply respect_id end end
abstract begin intros, apply nat_trans_eq, intro i, esimp, apply respect_comp end end
definition eval_functor [constructor] (C D : Precategory) (d : D) : C ^c D ⇒ C :=
begin
fapply functor.mk: esimp,
{ intro F, exact F d},
{ intro G F η, exact η d},
{ intro F, reflexivity},
{ intro H G F η θ, reflexivity},
end
definition precomposition_functor [constructor] {C D} (E) (F : C ⇒ D)
: E ^c D ⇒ E ^c C :=
begin
fapply functor.mk: esimp,
{ intro G, exact G ∘f F},
{ intro G H η, exact η ∘nf F},
{ intro G, reflexivity},
{ intro G H I η θ, reflexivity},
end
definition postcomposition_functor [constructor] {C D} (E) (F : C ⇒ D)
: C ^c E ⇒ D ^c E :=
begin
fapply functor.mk: esimp,
{ intro G, exact F ∘f G},
{ intro G H η, exact F ∘fn η},
{ intro G, apply fn_id},
{ intro G H I η θ, apply fn_n_distrib},
end
definition constant_diagram [constructor] (C D) : C ⇒ C ^c D :=
begin
fapply functor.mk: esimp,
{ intro c, exact constant_functor D c},
{ intro c d f, exact constant_nat_trans D f},
{ intro c, fapply nat_trans_eq, reflexivity},
{ intro c d e g f, fapply nat_trans_eq, reflexivity},
end
definition opposite_functor_opposite_left [constructor] (C D : Precategory)
: (C ^c D)ᵒᵖ ⇒ Cᵒᵖ ^c Dᵒᵖ :=
begin
fapply functor.mk: esimp,
{ exact opposite_functor},
{ intro F G, exact opposite_nat_trans},
{ intro F, apply nat_trans_eq, reflexivity},
{ intro u v w g f, apply nat_trans_eq, reflexivity}
end
definition opposite_functor_opposite_right [constructor] (C D : Precategory)
: Cᵒᵖ ^c Dᵒᵖ ⇒ (C ^c D)ᵒᵖ :=
begin
fapply functor.mk: esimp,
{ exact opposite_functor_rev},
{ apply @opposite_rev_nat_trans},
{ intro F, apply nat_trans_eq, intro d, reflexivity},
{ intro F G H η θ, apply nat_trans_eq, intro d, reflexivity}
end
definition constant_diagram_opposite [constructor] (C D)
: (constant_diagram C D)ᵒᵖᶠ = opposite_functor_opposite_right C D ∘f constant_diagram Cᵒᵖ Dᵒᵖ :=
begin
fapply functor_eq,
{ reflexivity},
{ intro c c' f, esimp at *, refine !nat_trans.id_right ⬝ !nat_trans.id_left ⬝ _,
apply nat_trans_eq, intro d, reflexivity}
end
end functor
|
f1ce551af57aa2e76a81f1c8fe1d676daf4bdbc1 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /test/library_search/basic.lean | c78f735c5dc5cfe8a045d65b2d091ca27a574ed3 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 2,422 | 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 data.nat.basic
import tactic.library_search
/- Turn off trace messages so they don't pollute the test build: -/
set_option trace.silence_library_search true
/- For debugging purposes, we can display the list of lemmas: -/
-- set_option trace.library_search true
namespace test.library_search
-- Check that `library_search` fails if there are no goals.
example : true :=
begin
trivial,
success_if_fail { library_search },
end
example (a b : ℕ) : a + b = b + a :=
by library_search -- says: `exact add_comm a b`
example {a b : ℕ} : a ≤ a + b :=
by library_search -- says: `exact le_add_right a b`
example (n m k : ℕ) : n * (m - k) = n * m - n * k :=
by library_search -- says: `exact nat.mul_sub_left_distrib n m k`
example {n m : ℕ} (h : m < n) : m ≤ n - 1 :=
by library_search -- says: `exact nat.le_pred_of_lt h`
example {α : Type} (x y : α) : x = y ↔ y = x :=
by library_search -- says: `exact eq_comm`
example (a b : ℕ) (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
by library_search -- says: `exact add_pos ha hb`
example (a b : ℕ) : 0 < a → 0 < b → 0 < a + b :=
by library_search -- says: `exact add_pos`
example (a b : ℕ) (h : a ∣ b) (w : b > 0) : a ≤ b :=
by library_search -- says: `exact nat.le_of_dvd w h`
-- We even find `iff` results:
example {b : ℕ} (w : b > 0) : b ≥ 1 :=
by library_search -- says: `exact nat.succ_le_iff.mpr w`
example : ∀ P : Prop, ¬(P ↔ ¬P) :=
by library_search -- says: `λ (a : Prop), (iff_not_self a).mp`
example {a b c : ℕ} (ha : a > 0) (w : b ∣ c) : a * b ∣ a * c :=
by library_search -- exact mul_dvd_mul_left a w
def P : Prop := true
def Q : Prop := true
def f (n : ℕ) : P ↔ Q := by refl
example (n : ℕ) (q : Q) : P := by library_search -- exact (f n).mpr q
example {a b c : ℕ} (h₁ : a ∣ c) (h₂ : a ∣ b + c) : a ∣ b :=
by library_search -- says `exact (nat.dvd_add_left h₁).mp h₂`
/-
It would be really nice to have `norm_num` or `dec_trivial` discharge
easy side goals.
We'll need a cleverer architecture before this is possible without
slowly things down too badly.
-/
-- example {a b : ℕ} (h : a * 2 ≤ b) : a ≤ b / 2 :=
-- by library_search -- exact (nat.le_div_iff_mul_le a b (dec_trivial)).mpr h
end test.library_search
|
b6931ddae6d479e12fa1940693753050c1b3eb94 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/number_theory/bernoulli_polynomials.lean | 51929522e22af46f622bb1b7007cf81737323548 | [
"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 | 7,128 | lean | /-
Copyright (c) 2021 Ashvni Narayanan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ashvni Narayanan
-/
import data.polynomial.algebra_map
import data.nat.choose.cast
import number_theory.bernoulli
/-!
# Bernoulli polynomials
The Bernoulli polynomials (defined here : https://en.wikipedia.org/wiki/Bernoulli_polynomials)
are an important tool obtained from Bernoulli numbers.
## Mathematical overview
The $n$-th Bernoulli polynomial is defined as
$$ B_n(X) = ∑_{k = 0}^n {n \choose k} (-1)^k * B_k * X^{n - k} $$
where $B_k$ is the $k$-th Bernoulli number. The Bernoulli polynomials are generating functions,
$$ t * e^{tX} / (e^t - 1) = ∑_{n = 0}^{\infty} B_n(X) * \frac{t^n}{n!} $$
## Implementation detail
Bernoulli polynomials are defined using `bernoulli`, the Bernoulli numbers.
## Main theorems
- `sum_bernoulli_poly`: The sum of the $k^\mathrm{th}$ Bernoulli polynomial with binomial
coefficients up to n is `(n + 1) * X^n`.
- `exp_bernoulli_poly`: The Bernoulli polynomials act as generating functions for the exponential.
## TODO
- `bernoulli_poly_eval_one_neg` : $$ B_n(1 - x) = (-1)^n*B_n(x) $$
- ``bernoulli_poly_eval_one` : Follows as a consequence of `bernoulli_poly_eval_one_neg`.
-/
noncomputable theory
open_locale big_operators
open_locale nat
open nat finset
/-- The Bernoulli polynomials are defined in terms of the negative Bernoulli numbers. -/
def bernoulli_poly (n : ℕ) : polynomial ℚ :=
∑ i in range (n + 1), polynomial.monomial (n - i) ((bernoulli i) * (choose n i))
lemma bernoulli_poly_def (n : ℕ) : bernoulli_poly n =
∑ i in range (n + 1), polynomial.monomial i ((bernoulli (n - i)) * (choose n i)) :=
begin
rw [←sum_range_reflect, add_succ_sub_one, add_zero, bernoulli_poly],
apply sum_congr rfl,
rintros x hx,
rw mem_range_succ_iff at hx, rw [choose_symm hx, tsub_tsub_cancel_of_le hx],
end
namespace bernoulli_poly
/-
### examples
-/
section examples
@[simp] lemma bernoulli_poly_zero : bernoulli_poly 0 = 1 :=
by simp [bernoulli_poly]
@[simp] lemma bernoulli_poly_eval_zero (n : ℕ) : (bernoulli_poly n).eval 0 = bernoulli n :=
begin
rw [bernoulli_poly, polynomial.eval_finset_sum, sum_range_succ],
have : ∑ (x : ℕ) in range n, bernoulli x * (n.choose x) * 0 ^ (n - x) = 0,
{ apply sum_eq_zero (λ x hx, _),
have h : 0 < n - x := tsub_pos_of_lt (mem_range.1 hx),
simp [h] },
simp [this],
end
@[simp] lemma bernoulli_poly_eval_one (n : ℕ) : (bernoulli_poly n).eval 1 = bernoulli' n :=
begin
simp only [bernoulli_poly, polynomial.eval_finset_sum],
simp only [←succ_eq_add_one, sum_range_succ, mul_one, cast_one, choose_self,
(bernoulli _).mul_comm, sum_bernoulli, one_pow, mul_one, polynomial.eval_C,
polynomial.eval_monomial],
by_cases h : n = 1,
{ norm_num [h], },
{ simp [h],
exact bernoulli_eq_bernoulli'_of_ne_one h, }
end
end examples
@[simp] theorem sum_bernoulli_poly (n : ℕ) :
∑ k in range (n + 1), ((n + 1).choose k : ℚ) • bernoulli_poly k =
polynomial.monomial n (n + 1 : ℚ) :=
begin
simp_rw [bernoulli_poly_def, finset.smul_sum, finset.range_eq_Ico, ←finset.sum_Ico_Ico_comm,
finset.sum_Ico_eq_sum_range],
simp only [cast_succ, add_tsub_cancel_left, tsub_zero, zero_add, linear_map.map_add],
simp_rw [polynomial.smul_monomial, mul_comm (bernoulli _) _, smul_eq_mul, ←mul_assoc],
conv_lhs { apply_congr, skip, conv
{ apply_congr, skip,
rw [← nat.cast_mul, choose_mul ((le_tsub_iff_left $ mem_range_le H).1
$ mem_range_le H_1) (le.intro rfl), nat.cast_mul, add_comm x x_1, add_tsub_cancel_right,
mul_assoc, mul_comm, ←smul_eq_mul, ←polynomial.smul_monomial] },
rw [←sum_smul], },
rw [sum_range_succ_comm],
simp only [add_right_eq_self, cast_succ, mul_one, cast_one, cast_add, add_tsub_cancel_left,
choose_succ_self_right, one_smul, bernoulli_zero, sum_singleton, zero_add,
linear_map.map_add, range_one],
apply sum_eq_zero (λ x hx, _),
have f : ∀ x ∈ range n, ¬ n + 1 - x = 1,
{ rintros x H, rw [mem_range] at H,
rw [eq_comm],
exact ne_of_lt (nat.lt_of_lt_of_le one_lt_two (le_tsub_of_add_le_left (succ_le_succ H))) },
rw [sum_bernoulli],
have g : (ite (n + 1 - x = 1) (1 : ℚ) 0) = 0,
{ simp only [ite_eq_right_iff, one_ne_zero],
intro h₁,
exact (f x hx) h₁, },
rw [g, zero_smul],
end
open power_series
open polynomial (aeval)
variables {A : Type*} [comm_ring A] [algebra ℚ A]
-- TODO: define exponential generating functions, and use them here
-- This name should probably be updated afterwards
/-- The theorem that `∑ Bₙ(t)X^n/n!)(e^X-1)=Xe^{tX}` -/
theorem exp_bernoulli_poly' (t : A) :
mk (λ n, aeval t ((1 / n! : ℚ) • bernoulli_poly n)) * (exp A - 1) = X * rescale t (exp A) :=
begin
-- check equality of power series by checking coefficients of X^n
ext n,
-- n = 0 case solved by `simp`
cases n, { simp },
-- n ≥ 1, the coefficients is a sum to n+2, so use `sum_range_succ` to write as
-- last term plus sum to n+1
rw [coeff_succ_X_mul, coeff_rescale, coeff_exp, coeff_mul,
nat.sum_antidiagonal_eq_sum_range_succ_mk, sum_range_succ],
-- last term is zero so kill with `add_zero`
simp only [ring_hom.map_sub, tsub_self, constant_coeff_one, constant_coeff_exp,
coeff_zero_eq_constant_coeff, mul_zero, sub_self, add_zero],
-- Let's multiply both sides by (n+1)! (OK because it's a unit)
set u : units ℚ := ⟨(n+1)!, (n+1)!⁻¹,
mul_inv_cancel (by exact_mod_cast factorial_ne_zero (n+1)),
inv_mul_cancel (by exact_mod_cast factorial_ne_zero (n+1))⟩ with hu,
rw ←units.mul_right_inj (units.map (algebra_map ℚ A).to_monoid_hom u),
-- now tidy up unit mess and generally do trivial rearrangements
-- to make RHS (n+1)*t^n
rw [units.coe_map, mul_left_comm, ring_hom.to_monoid_hom_eq_coe,
ring_hom.coe_monoid_hom, ←ring_hom.map_mul, hu, units.coe_mk],
change _ = t^n * algebra_map ℚ A (((n+1)*n! : ℕ)*(1/n!)),
rw [cast_mul, mul_assoc, mul_one_div_cancel
(show (n! : ℚ) ≠ 0, from cast_ne_zero.2 (factorial_ne_zero n)), mul_one, mul_comm (t^n),
← polynomial.aeval_monomial, cast_add, cast_one],
-- But this is the RHS of `sum_bernoulli_poly`
rw [← sum_bernoulli_poly, finset.mul_sum, alg_hom.map_sum],
-- and now we have to prove a sum is a sum, but all the terms are equal.
apply finset.sum_congr rfl,
-- The rest is just trivialities, hampered by the fact that we're coercing
-- factorials and binomial coefficients between ℕ and ℚ and A.
intros i hi,
-- deal with coefficients of e^X-1
simp only [nat.cast_choose ℚ (mem_range_le hi), coeff_mk,
if_neg (mem_range_sub_ne_zero hi), one_div, alg_hom.map_smul, coeff_one, units.coe_mk,
coeff_exp, sub_zero, linear_map.map_sub, algebra.smul_mul_assoc, algebra.smul_def,
mul_right_comm _ ((aeval t) _), ←mul_assoc, ← ring_hom.map_mul, succ_eq_add_one],
-- finally cancel the Bernoulli polynomial and the algebra_map
congr',
apply congr_arg,
rw [mul_assoc, div_eq_mul_inv, ← mul_inv₀],
end
end bernoulli_poly
|
fe495beec0c7e594e63e9a998752aa3095ecbaa7 | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/data/tree_paths.lean | 4ec26c03b5ae6c1542effd010da3927b9dcc146e | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,737 | lean | import .lptree_to_tree
universes u
namespace binary_tree
section paths
parameter A : Type
/-- We use lr to denote a direction a path follows from the root-/
inductive lr : Type
| left
| right
/-- A path through a tree is a left or right direction, and the siblings that
weren't visited-/
@[reducible]
def path := list (lr × A)
parameter {link : Type}
parameter mk_link : lr → A → A → link
def all_paths_core : tree A -> list link -> list (list link)
| (tree.node i l r) path :=
all_paths_core r ((mk_link lr.left (root l) (root r)) ::path)
++ all_paths_core l ((mk_link lr.right (root l) (root r)) ::path)
| (tree.leaf i) path := [path]
/-- get all paths (in order left to right) from root to leaf
these paths start with leafs, and are meant to be followed
up the tree in order to reconstruct a root in log(n) operations
-/
def all_paths (tr : tree A): list (list link) :=
all_paths_core tr []
def all_paths' : tree A -> list (list link)
| (tree.leaf i) := [[]]
| (tree.node i l r) :=
list.map (λ p, p ++ [mk_link lr.left (root l) (root r)]) (all_paths' r)
++ list.map (λ p, p ++ [mk_link lr.right (root l) (root r)]) (all_paths' l)
/-- Get all paths, but this time the paths give the direction
to follow from the root to the leaf. Finally, we also return the
leaf element that the path leads to.
-/
def all_paths_rev : tree A -> list (list link)
| (tree.leaf i) := [[]]
| (tree.node i l r) :=
list.map (list.cons (mk_link lr.left (root l) (root r))) (all_paths_rev r)
++ list.map (list.cons (mk_link lr.right (root l) (root r))) (all_paths_rev l)
lemma all_paths_rev_height (t : tree A)
: list.Forall (λ ls : list link, ls.length ≤ t.height) (all_paths_rev t)
:= begin
induction t; dsimp [all_paths_rev, tree.height],
{ constructor, apply le_refl, constructor },
{ apply list.concat_Forall; apply list.map_Forall;
apply list.impl_Forall; try { assumption },
{ intros x H,
dsimp [list.length], apply nat.add_le_add_right,
apply le_trans, assumption, apply le_max_right,
},
{ intros x H,
dsimp [list.length], apply nat.add_le_add_right,
apply le_trans, assumption, apply le_max_left, }
}
end
def all_paths_rev_option : option (tree A) → list (list link)
| none := []
| (some t) := all_paths_rev t
lemma all_paths_core_app (t : tree A) (p p' : list link)
: all_paths_core t (p ++ p') =
list.map (λ z, z ++ p') (all_paths_core t p)
:= begin
revert p p',
induction t; intros,
{ reflexivity },
{ dsimp [all_paths_core],
repeat { rw ← list.cons_append },
rw [ih_1, ih_2],
rw list.map_append,
}
end
lemma all_paths_same_core (t : tree A) (p : list link)
: all_paths_core t p = list.map (λ z, z ++ p) (all_paths' t)
:=
begin
revert p,
induction t; intros,
{ reflexivity },
{ simp [all_paths_core, all_paths'],
f_equal,
{ rw ih_2,
f_equal, apply funext,
intros x,
dsimp [function.comp],
rw list.append_assoc,
reflexivity, },
{ rw ih_1,
f_equal, apply funext,
intros x,
dsimp [function.comp],
rw list.append_assoc,
reflexivity, }
}
end
lemma all_paths_same (t : tree A)
: all_paths t = all_paths' t
:= begin
unfold all_paths,
rw all_paths_same_core,
apply list.map_id',
intros x, simp,
end
/-- Indeed, `all_paths` and `all_paths` are the same, except one
gives paths in the reverse order compared to the other
-/
lemma all_paths_reverse (t : tree A)
: list.map (list.reverse) (all_paths_rev t) = all_paths' t
:=
begin
induction t,
{ reflexivity },
{ simp [all_paths_rev, all_paths'],
f_equal,
{ rw <- ih_2,
rw <- list.map_compose,
f_equal, apply funext,
intros x,
simp [function.comp], },
{ rw <- ih_1,
rw <- list.map_compose,
f_equal, apply funext,
intros x,
simp [function.comp] }
}
end
protected def right_core : tree A -> path -> path
| (tree.node i l r) path :=
right_core r ((lr.right, root l) ::path)
| (tree.leaf i) path := path
/-- get only the rightmost path of a tree (all directions will be lr.right) -/
def right_path (tr : tree A) : path :=
right_core tr []
/-- given a path (in reverse order from the paths obtained by right_path and all_paths!!)
follow that path from the root and return the tree at that point-/
def tree_at_path : tree A -> path -> option (tree A)
| t [] := some t
| (tree.node i l r) (h :: t) := match h with
| (lr.left, _) := tree_at_path l t
| (lr.right, _) := tree_at_path r t
end
| (tree.leaf _) _ := none
parameter (compute_parent : link → A → A)
def reconstruct_root (xs : list link) (x : A) : A
:= xs.foldr compute_parent x
def reconstruct_items_rev : list link → A → list A
| [] lf := []
| (x :: xs) lf := reconstruct_root (x :: xs) lf :: reconstruct_items_rev xs lf
/-- Rebuilds all of the items in a path given the combination function, a
path, and an initial value, path moves towards the root-/
def reconstruct_items (node_combine : A -> A -> A) : path → A → list A
| [] _ := []
| ((lr.left, i) :: t) last_item := let new_item := node_combine last_item i in
new_item :: (reconstruct_items t new_item)
| ((lr.right, i) :: t) last_item := let new_item := node_combine i last_item in
new_item :: (reconstruct_items t new_item)
/-- Given
a prospective leaf item `lf`,
a path `p` that is supposed to lead to that leaf item,
and a tree `t`, this predicate indicates that indeed
following the path `p` along the tree `t` leads to the leaf `lf`.
-/
inductive path_in_tree_rev : A -> list A -> tree A -> Prop
| leaf : ∀ lf : A, path_in_tree_rev lf [] (tree.leaf lf)
| left : ∀ lf x xs l r,
path_in_tree_rev lf xs l -> path_in_tree_rev lf (x :: xs) (tree.node x l r)
| right : ∀ lf x xs l r,
path_in_tree_rev lf xs r -> path_in_tree_rev lf (x :: xs) (tree.node x l r)
parameter combine_data : A → A → A
def compute_parent_correct := forall (left right : A) dir,
compute_parent (mk_link dir left right) (match dir with
| lr.left := right
| lr.right := left end)
= combine_data left right
lemma tree_leaves_all_paths_rev_len (x : tree A)
: x.leaves.length = (all_paths_rev x).length
:= begin
induction x; dsimp [tree.leaves, all_paths_rev, list.length],
{ reflexivity },
{ repeat { rw list.length_append },
repeat { rw list.length_map },
f_equal; assumption,
}
end
lemma tree_leaves_all_paths_rev {X : Type u} (l r : tree A) (f g : list link → X) :
(list.zip (r.leaves ++ l.leaves)
(list.map f (all_paths_rev r) ++ list.map g (all_paths_rev l)))
=
list.zip r.leaves (list.map f (all_paths_rev r))
++ list.zip l.leaves (list.map g (all_paths_rev l))
:= begin
apply list.zip_same_length, rw list.length_map,
apply tree_leaves_all_paths_rev_len,
end
/-- If we compute the list of paths to all leaves in a tree
where the internal nodes are all the result of applying
and then use those paths and the leaves they point to
to try to
-/
lemma reconstruct_root_correct
(t : tree A)
(H : internal_nodes_ok combine_data t)
(comp_par_corr : compute_parent_correct)
: list.Forall (λ p : A × list link,
reconstruct_root p.snd p.fst = root t) (list.zip t.leaves (all_paths_rev t))
:= begin
induction H,
{ simp [all_paths_rev], constructor,
{ dsimp, simp [reconstruct_root], reflexivity },
{ constructor }
},
{ dsimp [all_paths_rev, tree.leaves],
rw tree_leaves_all_paths_rev,
apply list.concat_Forall,
{ clear ih_1, rw list.zip_map_r, apply list.map_Forall,
apply list.impl_Forall, apply ih_2,
clear ih_2 a a_1,
simp [root],
intros lf p,
subst x,
intros H,
dsimp [second],
dsimp [reconstruct_root],
have H' := comp_par_corr (root l) (root r) lr.left,
simp [compute_parent_correct] at H',
dsimp [reconstruct_root] at H,
rw H, apply H', },
{ clear ih_2, rw list.zip_map_r, apply list.map_Forall,
apply list.impl_Forall, apply ih_1,
clear ih_1 a a_1,
simp [root],
intros lf p,
subst x,
intros H,
simp only [second],
simp only [reconstruct_root],
have H' := comp_par_corr (root l) (root r) lr.right,
simp only [compute_parent_correct] at H',
dsimp [reconstruct_root] at H,
dsimp [list.foldr],
rw H, apply H', }
}
end
lemma reconstruct_items_correct
(comp_par_corr : compute_parent_correct)
(t : tree A)
: internal_nodes_ok combine_data t
-> list.Forall (λ p : A × list link, let (lf, pth) := p in
path_in_tree_rev lf (reconstruct_items_rev pth lf) t)
(list.zip t.leaves (all_paths_rev t))
:= begin
intros H, induction H,
{ dsimp [all_paths_rev],
constructor, dsimp, constructor, constructor },
{ dsimp at ih_1 ih_2,
dsimp, dsimp [all_paths_rev, tree.leaves],
rw tree_leaves_all_paths_rev,
apply list.concat_Forall,
{ rw list.zip_map_r, apply list.map_Forall,
apply_in a_1 (reconstruct_root_correct),
apply comp_par_corr,
apply list.impl_Forall2, apply a_1, apply ih_2,
intros p H H', induction p with lf pth,
dsimp at H H', dsimp [second],
dsimp [reconstruct_items_rev],
dsimp [reconstruct_root],
dsimp [reconstruct_root] at H, rw H,
have H2 := comp_par_corr (root l) (root r) lr.left,
dsimp [compute_parent_correct] at H2,
rw H2,
rw ← a_2, apply path_in_tree_rev.right, assumption,
},
{ rw list.zip_map_r, apply list.map_Forall,
apply_in a reconstruct_root_correct,
apply comp_par_corr,
apply list.impl_Forall2, apply a, apply ih_1,
intros p H H', induction p with lf pth,
dsimp at H H', dsimp [second],
simp [reconstruct_items_rev],
simp [reconstruct_root],
dsimp [reconstruct_root] at H, rw H,
have H2 := comp_par_corr (root l) (root r) lr.right,
dsimp [compute_parent_correct] at H2,
rw H2,
rw ← a_2, apply path_in_tree_rev.left, assumption, }
}
end
theorem end_to_end_height (xs : list A)
(f : A → A → A)
: list.Forall (λ ls : list link, ls.length ≤ log2 (xs.length + 1)) $
all_paths_rev_option (lptree_to_tree f (list_to_lptree xs))
:= begin
destruct (lptree_to_tree f (list_to_lptree xs)),
{ intros Hnone, rw Hnone, constructor, },
{ intros t Ht, rw Ht, dsimp [all_paths_rev_option],
apply list.impl_Forall, apply all_paths_rev_height,
intros, apply le_trans, assumption,
clear a x,
rw ← lptree_to_tree_option_equiv at Ht,
have H2 := lptree_to_tree_option_height f (list_to_lptree xs),
rw Ht at H2, dsimp at H2,
apply le_trans, apply H2, clear H2,
rw list_to_lptree_height' xs,
}
end
end paths
end binary_tree |
6e6d7d827b711307b4df3902c1f01eb10a8ec923 | 0d2e44896897eda703992595d71a0b19ed30b8a1 | /uexp/tactic_paper_supplemental_material/monoid_cancellation/benchmark.lean | 3582dd9259b1ab0c8fb8987ceaa8b17ab082300c | [
"BSD-2-Clause"
] | permissive | wwombat/Cosette | a87312aabefdb53ea8b67c37731bd58c7485afb6 | 4c5dc6172e24d3546c9818ac1fad06f72fe1c991 | refs/heads/master | 1,619,479,568,051 | 1,520,292,502,000 | 1,520,292,502,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,144 | lean | -- You need to run this file using `lean -j0`, otherwise the timings
-- will be influenced by parallel compilation.
import .monoid .smt .simp .cancellation_solver .cancellation_solver_opt
local infix * := star
meta def build_plus_l : ℕ → expr
| 0 := `(asM 0)
| (n+1) := `(asM %%(reflect n.succ) * %%(build_plus_l n))
meta def build_plus_r : ℕ → expr
| 0 := `(asM 0)
| (n+1) := `(%%(build_plus_r n) * asM %%(reflect n.succ))
meta def benchmark (n : ℕ) : expr :=
`(%%(build_plus_l n) = (%%(build_plus_r n) : m))
open tactic monad
meta def run_single_bench (n : ℕ) (t : tactic unit) := run_async $ do
bench_goal ← mk_meta_var (benchmark n),
set_goals [bench_goal],
dunfold [`benchmark, `build_plus_l, `build_plus_r],
timetac ("n = " ++ to_string n ++ ": ") (abstract t)
meta def run_benchs (solver_name : string) (t : tactic unit) :=
do trace solver_name, sequence' $ do
n ← list.range 11, n ← return (nat.mul 10 n),
[run_single_bench n t]
run_cmd run_benchs "simp" `[simp]
run_cmd run_benchs "smt" `[cc]
run_cmd run_benchs "cancellation_solver" `[solve]
run_cmd run_benchs "cancellation_solver_opt" `[opt.solve]
|
a3d230a9fbaf7d2bb152441ddd810d51f9d7bf29 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /library/data/nat/order.lean | 400363b0a66851203451d37be25dc88075bf01a6 | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 19,285 | lean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.nat.order
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad
The order relation on the natural numbers.
-/
import data.nat.basic data.nat.comm_semiring algebra.ordered_ring
open eq.ops
namespace nat
/- lt and le -/
theorem le_of_lt_or_eq {m n : ℕ} (H : m < n ∨ m = n) : m ≤ n :=
or.elim H (take H1, le_of_lt H1) (take H1, H1 ▸ !le.refl)
theorem lt.by_cases {a b : ℕ} {P : Prop}
(H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P :=
or.elim !lt.trichotomy
(assume H, H1 H)
(assume H, or.elim H (assume H', H2 H') (assume H', H3 H'))
theorem lt_or_eq_of_le {m n : ℕ} (H : m ≤ n) : m < n ∨ m = n :=
lt.by_cases
(assume H1 : m < n, or.inl H1)
(assume H1 : m = n, or.inr H1)
(assume H1 : m > n, absurd (lt_of_le_of_lt H H1) !lt.irrefl)
theorem le_iff_lt_or_eq (m n : ℕ) : m ≤ n ↔ m < n ∨ m = n :=
iff.intro lt_or_eq_of_le le_of_lt_or_eq
theorem lt_of_le_and_ne {m n : ℕ} (H1 : m ≤ n) (H2 : m ≠ n) : m < n :=
or.elim (lt_or_eq_of_le H1)
(take H3 : m < n, H3)
(take H3 : m = n, absurd H3 H2)
theorem lt_iff_le_and_ne (m n : ℕ) : m < n ↔ m ≤ n ∧ m ≠ n :=
iff.intro
(take H, and.intro (le_of_lt H) (take H1, lt.irrefl _ (H1 ▸ H)))
(take H, lt_of_le_and_ne (and.elim_left H) (and.elim_right H))
theorem le_add_right (n k : ℕ) : n ≤ n + k :=
induction_on k
(calc n ≤ n : le.refl n
... = n + zero : add_zero)
(λ k (ih : n ≤ n + k), calc
n ≤ succ (n + k) : le_succ_of_le ih
... = n + succ k : add_succ)
theorem le_add_left (n m : ℕ): n ≤ m + n :=
!add.comm ▸ !le_add_right
theorem le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m :=
h ▸ le_add_right n k
theorem le.elim {n m : ℕ} (h : n ≤ m) : ∃k, n + k = m :=
le.rec_on h
(exists.intro 0 rfl)
(λ m (h : n < m), lt.rec_on h
(exists.intro 1 rfl)
(λ b hlt (ih : ∃ (k : ℕ), n + k = b),
obtain (k : ℕ) (h : n + k = b), from ih,
exists.intro (succ k) (calc
n + succ k = succ (n + k) : add_succ
... = succ b : h)))
theorem le.total {m n : ℕ} : m ≤ n ∨ n ≤ m :=
lt.by_cases
(assume H : m < n, or.inl (le_of_lt H))
(assume H : m = n, or.inl (H ▸ !le.refl))
(assume H : m > n, or.inr (le_of_lt H))
/- addition -/
theorem add_le_add_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k + n ≤ k + m :=
obtain (l : ℕ) (Hl : n + l = m), from le.elim H,
le.intro
(calc
k + n + l = k + (n + l) : !add.assoc
... = k + m : {Hl})
theorem add_le_add_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n + k ≤ m + k :=
!add.comm ▸ !add.comm ▸ add_le_add_left H k
theorem le_of_add_le_add_left {k n m : ℕ} (H : k + n ≤ k + m) : n ≤ m :=
obtain (l : ℕ) (Hl : k + n + l = k + m), from (le.elim H),
le.intro (add.cancel_left
(calc
k + (n + l) = k + n + l : (!add.assoc)⁻¹
... = k + m : Hl))
theorem add_lt_add_left {n m : ℕ} (H : n < m) (k : ℕ) : k + n < k + m :=
lt_of_succ_le (!add_succ ▸ add_le_add_left (succ_le_of_lt H) k)
theorem add_lt_add_right {n m : ℕ} (H : n < m) (k : ℕ) : n + k < m + k :=
!add.comm ▸ !add.comm ▸ add_lt_add_left H k
theorem lt_add_of_pos_right {n k : ℕ} (H : k > 0) : n < n + k :=
!add_zero ▸ add_lt_add_left H n
/- multiplication -/
theorem mul_le_mul_left {n m : ℕ} (H : n ≤ m) (k : ℕ) : k * n ≤ k * m :=
obtain (l : ℕ) (Hl : n + l = m), from le.elim H,
have H2 : k * n + k * l = k * m, from
calc
k * n + k * l = k * (n + l) : mul.left_distrib
... = k * m : {Hl},
le.intro H2
theorem mul_le_mul_right {n m : ℕ} (H : n ≤ m) (k : ℕ) : n * k ≤ m * k :=
!mul.comm ▸ !mul.comm ▸ (mul_le_mul_left H k)
theorem mul_le_mul {n m k l : ℕ} (H1 : n ≤ k) (H2 : m ≤ l) : n * m ≤ k * l :=
le.trans (mul_le_mul_right H1 m) (mul_le_mul_left H2 k)
theorem mul_lt_mul_of_pos_left {n m k : ℕ} (H : n < m) (Hk : k > 0) : k * n < k * m :=
have H2 : k * n < k * n + k, from lt_add_of_pos_right Hk,
have H3 : k * n + k ≤ k * m, from !mul_succ ▸ mul_le_mul_left (succ_le_of_lt H) k,
lt_of_lt_of_le H2 H3
theorem mul_lt_mul_of_pos_right {n m k : ℕ} (H : n < m) (Hk : k > 0) : n * k < m * k :=
!mul.comm ▸ !mul.comm ▸ mul_lt_mul_of_pos_left H Hk
theorem le.antisymm {n m : ℕ} (H1 : n ≤ m) (H2 : m ≤ n) : n = m :=
obtain (k : ℕ) (Hk : n + k = m), from (le.elim H1),
obtain (l : ℕ) (Hl : m + l = n), from (le.elim H2),
have L1 : k + l = 0, from
add.cancel_left
(calc
n + (k + l) = n + k + l : (!add.assoc)⁻¹
... = m + l : {Hk}
... = n : Hl
... = n + 0 : (!add_zero)⁻¹),
have L2 : k = 0, from eq_zero_of_add_eq_zero_right L1,
calc
n = n + 0 : (!add_zero)⁻¹
... = n + k : {L2⁻¹}
... = m : Hk
theorem zero_le (n : ℕ) : 0 ≤ n :=
le.intro !zero_add
/- nat is an instance of a linearly ordered semiring -/
section
open [classes] algebra
protected definition linear_ordered_semiring [instance] [reducible] :
algebra.linear_ordered_semiring nat :=
⦃ algebra.linear_ordered_semiring, nat.comm_semiring,
add_left_cancel := @add.cancel_left,
add_right_cancel := @add.cancel_right,
lt := lt,
le := le,
le_refl := le.refl,
le_trans := @le.trans,
le_antisymm := @le.antisymm,
le_total := @le.total,
le_iff_lt_or_eq := @le_iff_lt_or_eq,
lt_iff_le_ne := lt_iff_le_and_ne,
add_le_add_left := @add_le_add_left,
le_of_add_le_add_left := @le_of_add_le_add_left,
mul_le_mul_of_nonneg_left := (take a b c H1 H2, mul_le_mul_left H1 c),
mul_le_mul_of_nonneg_right := (take a b c H1 H2, mul_le_mul_right H1 c),
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right ⦄
end
section port_algebra
theorem ge_of_eq_of_ge : ∀{a b c : ℕ}, a = b → b ≥ c → a ≥ c := @algebra.ge_of_eq_of_ge _ _
theorem ge_of_ge_of_eq : ∀{a b c : ℕ}, a ≥ b → b = c → a ≥ c := @algebra.ge_of_ge_of_eq _ _
theorem gt_of_eq_of_gt : ∀{a b c : ℕ}, a = b → b > c → a > c := @algebra.gt_of_eq_of_gt _ _
theorem gt_of_gt_of_eq : ∀{a b c : ℕ}, a > b → b = c → a > c := @algebra.gt_of_gt_of_eq _ _
theorem ge.trans: ∀{a b c : ℕ}, a ≥ b → b ≥ c → a ≥ c := @algebra.ge.trans _ _
theorem gt.trans: ∀{a b c : ℕ}, a ≥ b → b ≥ c → a ≥ c := @algebra.ge.trans _ _
theorem gt_of_gt_of_ge : ∀{a b c : ℕ}, a > b → b ≥ c → a > c := @algebra.gt_of_gt_of_ge _ _
theorem gt_of_ge_of_gt : ∀{a b c : ℕ}, a ≥ b → b > c → a > c := @algebra.gt_of_ge_of_gt _ _
calc_trans ge_of_eq_of_ge
calc_trans ge_of_ge_of_eq
calc_trans gt_of_eq_of_gt
calc_trans gt_of_gt_of_eq
theorem ne_of_lt : ∀{a b : ℕ}, a < b → a ≠ b := @algebra.ne_of_lt _ _
theorem lt_of_le_of_ne : ∀{a b : ℕ}, a ≤ b → a ≠ b → a < b :=
@algebra.lt_of_le_of_ne _ _
theorem not_le_of_lt : ∀{a b : ℕ}, a < b → ¬ b ≤ a := @algebra.not_le_of_lt _ _
theorem not_lt_of_le : ∀{a b : ℕ}, a ≤ b → ¬ b < a := @algebra.not_lt_of_le _ _
theorem le_of_not_lt : ∀{a b : ℕ}, ¬ a < b → b ≤ a := @algebra.le_of_not_lt _ _
theorem lt_of_not_le : ∀{a b : ℕ}, ¬ a ≤ b → b < a := @algebra.lt_of_not_le _ _
theorem lt_or_ge : ∀a b : ℕ, a < b ∨ a ≥ b := @algebra.lt_or_ge _ _
theorem le_or_gt : ∀a b : ℕ, a ≤ b ∨ a > b := @algebra.le_or_gt _ _
theorem lt_or_gt_of_ne : ∀{a b : ℕ}, a ≠ b → a < b ∨ a > b := @algebra.lt_or_gt_of_ne _ _
theorem add_le_add : ∀{a b c d : ℕ}, a ≤ b → c ≤ d → a + c ≤ b + d := @algebra.add_le_add _ _
theorem add_lt_add : ∀{a b c d : ℕ}, a < b → c < d → a + c < b + d := @algebra.add_lt_add _ _
theorem add_lt_add_of_le_of_lt : ∀{a b c d : ℕ}, a ≤ b → c < d → a + c < b + d :=
@algebra.add_lt_add_of_le_of_lt _ _
theorem add_lt_add_of_lt_of_le : ∀{a b c d : ℕ}, a < b → c ≤ d → a + c < b + d :=
@algebra.add_lt_add_of_lt_of_le _ _
theorem lt_add_of_pos_left : ∀{a b : ℕ}, b > 0 → a < b + a := @algebra.lt_add_of_pos_left _ _
theorem le_of_add_le_add_right : ∀{a b c : ℕ}, a + b ≤ c + b → a ≤ c :=
@algebra.le_of_add_le_add_right _ _
theorem lt_of_add_lt_add_left : ∀{a b c : ℕ}, a + b < a + c → b < c :=
@algebra.lt_of_add_lt_add_left _ _
theorem lt_of_add_lt_add_right : ∀{a b c : ℕ}, a + b < c + b → a < c :=
@algebra.lt_of_add_lt_add_right _ _
theorem add_le_add_left_iff : ∀a b c : ℕ, a + b ≤ a + c ↔ b ≤ c := algebra.add_le_add_left_iff
theorem add_le_add_right_iff : ∀a b c : ℕ, a + b ≤ c + b ↔ a ≤ c := algebra.add_le_add_right_iff
theorem add_lt_add_left_iff : ∀a b c : ℕ, a + b < a + c ↔ b < c := algebra.add_lt_add_left_iff
theorem add_lt_add_right_iff : ∀a b c : ℕ, a + b < c + b ↔ a < c := algebra.add_lt_add_right_iff
theorem add_pos_left : ∀{a : ℕ}, 0 < a → ∀b : ℕ, 0 < a + b :=
take a H b, @algebra.add_pos_of_pos_of_nonneg _ _ a b H !zero_le
theorem add_pos_right : ∀{a : ℕ}, 0 < a → ∀b : ℕ, 0 < b + a :=
take a H b, !add.comm ▸ add_pos_left H b
theorem add_eq_zero_iff_eq_zero_and_eq_zero : ∀{a b : ℕ},
a + b = 0 ↔ a = 0 ∧ b = 0 :=
take a b : ℕ,
@algebra.add_eq_zero_iff_eq_zero_and_eq_zero_of_nonneg_of_nonneg _ _ a b !zero_le !zero_le
theorem le_add_of_le_left : ∀{a b c : ℕ}, b ≤ c → b ≤ a + c :=
take a b c H, @algebra.le_add_of_nonneg_of_le _ _ a b c !zero_le H
theorem le_add_of_le_right : ∀{a b c : ℕ}, b ≤ c → b ≤ c + a :=
take a b c H, @algebra.le_add_of_le_of_nonneg _ _ a b c H !zero_le
theorem lt_add_of_pos_of_le : ∀{a b c : ℕ}, 0 < a → b ≤ c → b < a + c :=
@algebra.lt_add_of_pos_of_le _ _
theorem lt_add_of_le_of_pos : ∀{a b c : ℕ}, b ≤ c → 0 < a → b < c + a :=
@algebra.lt_add_of_le_of_pos _ _
theorem lt_add_of_lt_left : ∀{b c : ℕ}, b < c → ∀a, b < a + c :=
take b c H a, @algebra.lt_add_of_nonneg_of_lt _ _ a b c !zero_le H
theorem lt_add_of_lt_right : ∀{b c : ℕ}, b < c → ∀a, b < c + a :=
take b c H a, @algebra.lt_add_of_lt_of_nonneg _ _ a b c H !zero_le
theorem lt_add_of_pos_of_lt : ∀{a b c : ℕ}, 0 < a → b < c → b < a + c :=
@algebra.lt_add_of_pos_of_lt _ _
theorem lt_add_of_lt_of_pos : ∀{a b c : ℕ}, b < c → 0 < a → b < c + a :=
@algebra.lt_add_of_lt_of_pos _ _
theorem mul_pos : ∀{a b : ℕ}, 0 < a → 0 < b → 0 < a * b := @algebra.mul_pos _ _
theorem lt_of_mul_lt_mul_left : ∀{a b c : ℕ}, c * a < c * b → a < b :=
take a b c H, @algebra.lt_of_mul_lt_mul_left _ _ a b c H !zero_le
theorem lt_of_mul_lt_mul_right : ∀{a b c : ℕ}, a * c < b * c → a < b :=
take a b c H, @algebra.lt_of_mul_lt_mul_right _ _ a b c H !zero_le
theorem le_of_mul_le_mul_left : ∀{a b c : ℕ}, c * a ≤ c * b → c > 0 → a ≤ b :=
@algebra.le_of_mul_le_mul_left _ _
theorem le_of_mul_le_mul_right : ∀{a b c : ℕ}, a * c ≤ b * c → c > 0 → a ≤ b :=
@algebra.le_of_mul_le_mul_right _ _
theorem pos_of_mul_pos_left : ∀{a b : ℕ}, 0 < a * b → 0 < b :=
take a b H, @algebra.pos_of_mul_pos_left _ _ a b H !zero_le
theorem pos_of_mul_pos_right : ∀{a b : ℕ}, 0 < a * b → 0 < a :=
take a b H, @algebra.pos_of_mul_pos_right _ _ a b H !zero_le
end port_algebra
theorem zero_le_one : 0 ≤ 1 := dec_trivial
theorem zero_lt_one : 0 < 1 := dec_trivial
/- properties specific to nat -/
theorem lt_intro {n m k : ℕ} (H : succ n + k = m) : n < m :=
lt_of_succ_le (le.intro H)
theorem lt_elim {n m : ℕ} (H : n < m) : ∃k, succ n + k = m :=
le.elim (succ_le_of_lt H)
theorem lt_add_succ (n m : ℕ) : n < n + succ m :=
lt_intro !succ_add_eq_add_succ
theorem eq_zero_of_le_zero {n : ℕ} (H : n ≤ 0) : n = 0 :=
obtain (k : ℕ) (Hk : n + k = 0), from le.elim H,
eq_zero_of_add_eq_zero_right Hk
/- succ and pred -/
theorem lt_iff_succ_le (m n : nat) : m < n ↔ succ m ≤ n :=
iff.intro succ_le_of_lt lt_of_succ_le
theorem not_succ_le_zero (n : ℕ) : ¬ succ n ≤ 0 :=
(assume H : succ n ≤ 0,
have H2 : succ n = 0, from eq_zero_of_le_zero H,
absurd H2 !succ_ne_zero)
theorem succ_le_succ {n m : ℕ} (H : n ≤ m) : succ n ≤ succ m :=
!add_one ▸ !add_one ▸ add_le_add_right H 1
theorem le_of_succ_le_succ {n m : ℕ} (H : succ n ≤ succ m) : n ≤ m :=
le_of_add_le_add_right ((!add_one)⁻¹ ▸ (!add_one)⁻¹ ▸ H)
theorem self_le_succ (n : ℕ) : n ≤ succ n :=
le.intro !add_one
theorem succ_le_or_eq_of_le {n m : ℕ} (H : n ≤ m) : succ n ≤ m ∨ n = m :=
or.elim (lt_or_eq_of_le H)
(assume H1 : n < m, or.inl (succ_le_of_lt H1))
(assume H1 : n = m, or.inr H1)
theorem le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m :=
nat.cases_on n
(assume H : pred 0 ≤ m, !zero_le)
(take n',
assume H : pred (succ n') ≤ m,
have H1 : n' ≤ m, from pred_succ n' ▸ H,
succ_le_succ H1)
theorem pred_le_of_le_succ {n m : ℕ} : n ≤ succ m → pred n ≤ m :=
nat.cases_on n
(assume H, !pred_zero⁻¹ ▸ zero_le m)
(take n',
assume H : succ n' ≤ succ m,
have H1 : n' ≤ m, from le_of_succ_le_succ H,
!pred_succ⁻¹ ▸ H1)
theorem succ_le_of_le_pred {n m : ℕ} : succ n ≤ m → n ≤ pred m :=
nat.cases_on m
(assume H, absurd H !not_succ_le_zero)
(take m',
assume H : succ n ≤ succ m',
have H1 : n ≤ m', from le_of_succ_le_succ H,
!pred_succ⁻¹ ▸ H1)
theorem pred_le_pred_of_le {n m : ℕ} : n ≤ m → pred n ≤ pred m :=
nat.cases_on n
(assume H, pred_zero⁻¹ ▸ zero_le (pred m))
(take n',
assume H : succ n' ≤ m,
!pred_succ⁻¹ ▸ succ_le_of_le_pred H)
theorem lt_of_pred_lt_pred {n m : ℕ} (H : pred n < pred m) : n < m :=
lt_of_not_le
(take H1 : m ≤ n,
not_lt_of_le (pred_le_pred_of_le H1) H)
theorem le_or_eq_succ_of_le_succ {n m : ℕ} (H : n ≤ succ m) : n ≤ m ∨ n = succ m :=
or_of_or_of_imp_left (succ_le_or_eq_of_le H)
(take H2 : succ n ≤ succ m, show n ≤ m, from le_of_succ_le_succ H2)
theorem le_pred_self (n : ℕ) : pred n ≤ n :=
cases_on n
(pred_zero⁻¹ ▸ !le.refl)
(take k : ℕ, (!pred_succ)⁻¹ ▸ !self_le_succ)
theorem succ_pos (n : ℕ) : 0 < succ n :=
!zero_lt_succ
theorem succ_pred_of_pos {n : ℕ} (H : n > 0) : succ (pred n) = n :=
(or_resolve_right (eq_zero_or_eq_succ_pred n) (ne.symm (ne_of_lt H)))⁻¹
theorem exists_eq_succ_of_lt {n m : ℕ} (H : n < m) : exists k, m = succ k :=
discriminate
(take (Hm : m = 0), absurd (Hm ▸ H) !not_lt_zero)
(take (l : ℕ) (Hm : m = succ l), exists.intro l Hm)
theorem self_lt_succ (n : ℕ) : n < succ n :=
lt.base n
theorem le_of_lt_succ {n m : ℕ} (H : n < succ m) : n ≤ m :=
le_of_succ_le_succ (succ_le_of_lt H)
/- other forms of induction -/
protected theorem strong_induction_on {P : nat → Prop} (n : ℕ) (H : ∀n, (∀m, m < n → P m) → P n) :
P n :=
have H1 : ∀ {n m : nat}, m < n → P m, from
take n,
induction_on n
(show ∀m, m < 0 → P m, from take m H, absurd H !not_lt_zero)
(take n',
assume IH : ∀ {m : nat}, m < n' → P m,
have H2: P n', from H n' @IH,
show ∀m, m < succ n' → P m, from
take m,
assume H3 : m < succ n',
or.elim (lt_or_eq_of_le (le_of_lt_succ H3))
(assume H4: m < n', IH H4)
(assume H4: m = n', H4⁻¹ ▸ H2)),
H1 !self_lt_succ
protected theorem case_strong_induction_on {P : nat → Prop} (a : nat) (H0 : P 0)
(Hind : ∀(n : nat), (∀m, m ≤ n → P m) → P (succ n)) : P a :=
strong_induction_on a (
take n,
show (∀m, m < n → P m) → P n, from
cases_on n
(assume H : (∀m, m < 0 → P m), show P 0, from H0)
(take n,
assume H : (∀m, m < succ n → P m),
show P (succ n), from
Hind n (take m, assume H1 : m ≤ n, H _ (lt_succ_of_le H1))))
/- pos -/
theorem by_cases_zero_pos {P : ℕ → Prop} (y : ℕ) (H0 : P 0) (H1 : ∀ {y : nat}, y > 0 → P y) : P y :=
cases_on y H0 (take y, H1 !succ_pos)
theorem zero_or_pos {n : ℕ} : n = 0 ∨ n > 0 :=
or_of_or_of_imp_left
(or.swap (lt_or_eq_of_le !zero_le))
(take H : 0 = n, H⁻¹)
theorem pos_of_ne_zero {n : ℕ} (H : n ≠ 0) : n > 0 :=
or.elim zero_or_pos (take H2 : n = 0, absurd H2 H) (take H2 : n > 0, H2)
theorem ne_zero_of_pos {n : ℕ} (H : n > 0) : n ≠ 0 :=
ne.symm (ne_of_lt H)
theorem exists_eq_succ_of_pos {n : ℕ} (H : n > 0) : exists l, n = succ l :=
exists_eq_succ_of_lt H
/- multiplication -/
theorem mul_lt_mul_of_le_of_lt {n m k l : ℕ} (Hk : k > 0) (H1 : n ≤ k) (H2 : m < l) :
n * m < k * l :=
lt_of_le_of_lt (mul_le_mul_right H1 m) (mul_lt_mul_of_pos_left H2 Hk)
theorem mul_lt_mul_of_lt_of_le {n m k l : ℕ} (Hl : l > 0) (H1 : n < k) (H2 : m ≤ l) :
n * m < k * l :=
lt_of_le_of_lt (mul_le_mul_left H2 n) (mul_lt_mul_of_pos_right H1 Hl)
theorem mul_lt_mul_of_le_of_le {n m k l : ℕ} (H1 : n < k) (H2 : m < l) : n * m < k * l :=
have H3 : n * m ≤ k * m, from mul_le_mul_right (le_of_lt H1) m,
have H4 : k * m < k * l, from mul_lt_mul_of_pos_left H2 (lt_of_le_of_lt !zero_le H1),
lt_of_le_of_lt H3 H4
theorem eq_of_mul_eq_mul_left {m k n : ℕ} (Hn : n > 0) (H : n * m = n * k) : m = k :=
have H2 : n * m ≤ n * k, from H ▸ !le.refl,
have H3 : n * k ≤ n * m, from H ▸ !le.refl,
have H4 : m ≤ k, from le_of_mul_le_mul_left H2 Hn,
have H5 : k ≤ m, from le_of_mul_le_mul_left H3 Hn,
le.antisymm H4 H5
theorem eq_of_mul_eq_mul_right {n m k : ℕ} (Hm : m > 0) (H : n * m = k * m) : n = k :=
eq_of_mul_eq_mul_left Hm (!mul.comm ▸ !mul.comm ▸ H)
theorem eq_zero_or_eq_of_mul_eq_mul_left {n m k : ℕ} (H : n * m = n * k) : n = 0 ∨ m = k :=
or_of_or_of_imp_right zero_or_pos
(assume Hn : n > 0, eq_of_mul_eq_mul_left Hn H)
theorem eq_zero_or_eq_of_mul_eq_mul_right {n m k : ℕ} (H : n * m = k * m) : m = 0 ∨ n = k :=
eq_zero_or_eq_of_mul_eq_mul_left (!mul.comm ▸ !mul.comm ▸ H)
theorem eq_one_of_mul_eq_one_right {n m : ℕ} (H : n * m = 1) : n = 1 :=
have H2 : n * m > 0, from H⁻¹ ▸ !succ_pos,
have H3 : n > 0, from pos_of_mul_pos_right H2,
have H4 : m > 0, from pos_of_mul_pos_left H2,
or.elim (le_or_gt n 1)
(assume H5 : n ≤ 1,
show n = 1, from le.antisymm H5 (succ_le_of_lt H3))
(assume H5 : n > 1,
have H6 : n * m ≥ 2 * 1, from mul_le_mul (succ_le_of_lt H5) (succ_le_of_lt H4),
have H7 : 1 ≥ 2, from !mul_one ▸ H ▸ H6,
absurd !self_lt_succ (not_lt_of_le H7))
theorem eq_one_of_mul_eq_one_left {n m : ℕ} (H : n * m = 1) : m = 1 :=
eq_one_of_mul_eq_one_right (!mul.comm ▸ H)
theorem eq_one_of_mul_eq_self_left {n m : ℕ} (Hpos : n > 0) (H : m * n = n) : m = 1 :=
eq_of_mul_eq_mul_right Hpos (H ⬝ !one_mul⁻¹)
theorem eq_one_of_mul_eq_self_right {n m : ℕ} (Hpos : m > 0) (H : m * n = m) : n = 1 :=
eq_one_of_mul_eq_self_left Hpos (!mul.comm ▸ H)
end nat
|
efa52dee77ef056710f309099129932c3c7b929c | 8e6cad62ec62c6c348e5faaa3c3f2079012bdd69 | /src/analysis/normed_space/basic.lean | bd3124eae38fa44b7d65ad10f2622aed4becc202 | [
"Apache-2.0"
] | permissive | benjamindavidson/mathlib | 8cc81c865aa8e7cf4462245f58d35ae9a56b150d | fad44b9f670670d87c8e25ff9cdf63af87ad731e | refs/heads/master | 1,679,545,578,362 | 1,615,343,014,000 | 1,615,343,014,000 | 312,926,983 | 0 | 0 | Apache-2.0 | 1,615,360,301,000 | 1,605,399,418,000 | Lean | UTF-8 | Lean | false | false | 58,313 | 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.instances.nnreal
import topology.algebra.module
import topology.metric_space.antilipschitz
/-!
# Normed spaces
-/
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*}
noncomputable theory
open filter metric
open_locale topological_space big_operators nnreal ennreal
/-- Auxiliary class, endowing a type `α` with a function `norm : α → ℝ`. This class is designed to
be extended in more interesting classes specifying the properties of the norm. -/
class has_norm (α : Type*) := (norm : α → ℝ)
export has_norm (norm)
notation `∥`:1024 e:1 `∥`:1 := norm e
/-- A normed group is an additive group endowed with a norm for which `dist x y = ∥x - y∥` defines
a metric space structure. -/
class normed_group (α : Type*) extends has_norm α, add_comm_group α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
/-- Construct a normed group from a translation invariant distance -/
def normed_group.of_add_dist [has_norm α] [add_comm_group α] [metric_space α]
(H1 : ∀ x:α, ∥x∥ = dist x 0)
(H2 : ∀ x y z : α, dist x y ≤ dist (x + z) (y + z)) : normed_group α :=
{ dist_eq := λ x y, begin
rw H1, apply le_antisymm,
{ rw [sub_eq_add_neg, ← add_right_neg y], apply H2 },
{ have := H2 (x-y) 0 y, rwa [sub_add_cancel, zero_add] at this }
end }
/-- Construct a normed group from a translation invariant distance -/
def normed_group.of_add_dist' [has_norm α] [add_comm_group α] [metric_space α]
(H1 : ∀ x:α, ∥x∥ = dist x 0)
(H2 : ∀ x y z : α, dist (x + z) (y + z) ≤ dist x y) : normed_group α :=
{ dist_eq := λ x y, begin
rw H1, apply le_antisymm,
{ have := H2 (x-y) 0 y, rwa [sub_add_cancel, zero_add] at this },
{ rw [sub_eq_add_neg, ← add_right_neg y], apply H2 }
end }
/-- A normed group can be built from a norm that satisfies algebraic properties. This is
formalised in this structure. -/
structure normed_group.core (α : Type*) [add_comm_group α] [has_norm α] : Prop :=
(norm_eq_zero_iff : ∀ x : α, ∥x∥ = 0 ↔ x = 0)
(triangle : ∀ x y : α, ∥x + y∥ ≤ ∥x∥ + ∥y∥)
(norm_neg : ∀ x : α, ∥-x∥ = ∥x∥)
/-- Constructing a normed group from core properties of a norm, i.e., registering the distance and
the metric space structure from the norm properties. -/
noncomputable def normed_group.of_core (α : Type*) [add_comm_group α] [has_norm α]
(C : normed_group.core α) : normed_group α :=
{ dist := λ x y, ∥x - y∥,
dist_eq := assume x y, by refl,
dist_self := assume x, (C.norm_eq_zero_iff (x - x)).mpr (show x - x = 0, by simp),
eq_of_dist_eq_zero := assume x y h, sub_eq_zero.mp $ (C.norm_eq_zero_iff (x - y)).mp h,
dist_triangle := assume x y z,
calc ∥x - z∥ = ∥x - y + (y - z)∥ : by rw sub_add_sub_cancel
... ≤ ∥x - y∥ + ∥y - z∥ : C.triangle _ _,
dist_comm := assume x y,
calc ∥x - y∥ = ∥ -(y - x)∥ : by simp
... = ∥y - x∥ : by { rw [C.norm_neg] } }
instance : normed_group ℝ :=
{ norm := λ x, abs x,
dist_eq := assume x y, rfl }
lemma real.norm_eq_abs (r : ℝ) : ∥r∥ = abs r := rfl
section normed_group
variables [normed_group α] [normed_group β]
lemma dist_eq_norm (g h : α) : dist g h = ∥g - h∥ :=
normed_group.dist_eq _ _
lemma dist_eq_norm' (g h : α) : dist g h = ∥h - g∥ :=
by rw [dist_comm, dist_eq_norm]
@[simp] lemma dist_zero_right (g : α) : dist g 0 = ∥g∥ :=
by rw [dist_eq_norm, sub_zero]
@[simp] lemma dist_zero_left : dist (0:α) = norm :=
funext $ λ g, by rw [dist_comm, dist_zero_right]
lemma tendsto_norm_cocompact_at_top [proper_space α] :
tendsto norm (cocompact α) at_top :=
by simpa only [dist_zero_right] using tendsto_dist_right_cocompact_at_top (0:α)
lemma norm_sub_rev (g h : α) : ∥g - h∥ = ∥h - g∥ :=
by simpa only [dist_eq_norm] using dist_comm g h
@[simp] lemma norm_neg (g : α) : ∥-g∥ = ∥g∥ :=
by simpa using norm_sub_rev 0 g
@[simp] lemma dist_add_left (g h₁ h₂ : α) : dist (g + h₁) (g + h₂) = dist h₁ h₂ :=
by simp [dist_eq_norm]
@[simp] lemma dist_add_right (g₁ g₂ h : α) : dist (g₁ + h) (g₂ + h) = dist g₁ g₂ :=
by simp [dist_eq_norm]
@[simp] lemma dist_neg_neg (g h : α) : dist (-g) (-h) = dist g h :=
by simp only [dist_eq_norm, neg_sub_neg, norm_sub_rev]
@[simp] lemma dist_sub_left (g h₁ h₂ : α) : dist (g - h₁) (g - h₂) = dist h₁ h₂ :=
by simp only [sub_eq_add_neg, dist_add_left, dist_neg_neg]
@[simp] lemma dist_sub_right (g₁ g₂ h : α) : dist (g₁ - h) (g₂ - h) = dist g₁ g₂ :=
by simpa only [sub_eq_add_neg] using dist_add_right _ _ _
/-- Triangle inequality for the norm. -/
lemma norm_add_le (g h : α) : ∥g + h∥ ≤ ∥g∥ + ∥h∥ :=
by simpa [dist_eq_norm] using dist_triangle g 0 (-h)
lemma norm_add_le_of_le {g₁ g₂ : α} {n₁ n₂ : ℝ} (H₁ : ∥g₁∥ ≤ n₁) (H₂ : ∥g₂∥ ≤ n₂) :
∥g₁ + g₂∥ ≤ n₁ + n₂ :=
le_trans (norm_add_le g₁ g₂) (add_le_add H₁ H₂)
lemma dist_add_add_le (g₁ g₂ h₁ h₂ : α) :
dist (g₁ + g₂) (h₁ + h₂) ≤ dist g₁ h₁ + dist g₂ h₂ :=
by simpa only [dist_add_left, dist_add_right] using dist_triangle (g₁ + g₂) (h₁ + g₂) (h₁ + h₂)
lemma dist_add_add_le_of_le {g₁ g₂ h₁ h₂ : α} {d₁ d₂ : ℝ}
(H₁ : dist g₁ h₁ ≤ d₁) (H₂ : dist g₂ h₂ ≤ d₂) :
dist (g₁ + g₂) (h₁ + h₂) ≤ d₁ + d₂ :=
le_trans (dist_add_add_le g₁ g₂ h₁ h₂) (add_le_add H₁ H₂)
lemma dist_sub_sub_le (g₁ g₂ h₁ h₂ : α) :
dist (g₁ - g₂) (h₁ - h₂) ≤ dist g₁ h₁ + dist g₂ h₂ :=
by simpa only [sub_eq_add_neg, dist_neg_neg] using dist_add_add_le g₁ (-g₂) h₁ (-h₂)
lemma dist_sub_sub_le_of_le {g₁ g₂ h₁ h₂ : α} {d₁ d₂ : ℝ}
(H₁ : dist g₁ h₁ ≤ d₁) (H₂ : dist g₂ h₂ ≤ d₂) :
dist (g₁ - g₂) (h₁ - h₂) ≤ d₁ + d₂ :=
le_trans (dist_sub_sub_le g₁ g₂ h₁ h₂) (add_le_add H₁ H₂)
lemma abs_dist_sub_le_dist_add_add (g₁ g₂ h₁ h₂ : α) :
abs (dist g₁ h₁ - dist g₂ h₂) ≤ dist (g₁ + g₂) (h₁ + h₂) :=
by simpa only [dist_add_left, dist_add_right, dist_comm h₂]
using abs_dist_sub_le (g₁ + g₂) (h₁ + h₂) (h₁ + g₂)
@[simp] lemma norm_nonneg (g : α) : 0 ≤ ∥g∥ :=
by { rw[←dist_zero_right], exact dist_nonneg }
@[simp] lemma norm_eq_zero {g : α} : ∥g∥ = 0 ↔ g = 0 :=
dist_zero_right g ▸ dist_eq_zero
@[simp] lemma norm_zero : ∥(0:α)∥ = 0 := norm_eq_zero.2 rfl
@[nontriviality] lemma norm_of_subsingleton [subsingleton α] (x : α) : ∥x∥ = 0 :=
by rw [subsingleton.elim x 0, norm_zero]
lemma norm_sum_le {β} : ∀(s : finset β) (f : β → α), ∥∑ a in s, f a∥ ≤ ∑ a in s, ∥ f a ∥ :=
finset.le_sum_of_subadditive norm norm_zero norm_add_le
lemma norm_sum_le_of_le {β} (s : finset β) {f : β → α} {n : β → ℝ} (h : ∀ b ∈ s, ∥f b∥ ≤ n b) :
∥∑ b in s, f b∥ ≤ ∑ b in s, n b :=
le_trans (norm_sum_le s f) (finset.sum_le_sum h)
@[simp] lemma norm_pos_iff {g : α} : 0 < ∥ g ∥ ↔ g ≠ 0 :=
dist_zero_right g ▸ dist_pos
@[simp] lemma norm_le_zero_iff {g : α} : ∥g∥ ≤ 0 ↔ g = 0 :=
by { rw[←dist_zero_right], exact dist_le_zero }
lemma eq_of_norm_sub_le_zero {g h : α} (a : ∥g - h∥ ≤ 0) : g = h :=
by rwa [← sub_eq_zero, ← norm_le_zero_iff]
lemma norm_sub_le (g h : α) : ∥g - h∥ ≤ ∥g∥ + ∥h∥ :=
by simpa [dist_eq_norm] using dist_triangle g 0 h
lemma norm_sub_le_of_le {g₁ g₂ : α} {n₁ n₂ : ℝ} (H₁ : ∥g₁∥ ≤ n₁) (H₂ : ∥g₂∥ ≤ n₂) :
∥g₁ - g₂∥ ≤ n₁ + n₂ :=
le_trans (norm_sub_le g₁ g₂) (add_le_add H₁ H₂)
lemma dist_le_norm_add_norm (g h : α) : dist g h ≤ ∥g∥ + ∥h∥ :=
by { rw dist_eq_norm, apply norm_sub_le }
lemma abs_norm_sub_norm_le (g h : α) : abs(∥g∥ - ∥h∥) ≤ ∥g - h∥ :=
by simpa [dist_eq_norm] using abs_dist_sub_le g h 0
lemma norm_sub_norm_le (g h : α) : ∥g∥ - ∥h∥ ≤ ∥g - h∥ :=
le_trans (le_abs_self _) (abs_norm_sub_norm_le g h)
lemma dist_norm_norm_le (g h : α) : dist ∥g∥ ∥h∥ ≤ ∥g - h∥ :=
abs_norm_sub_norm_le g h
lemma eq_of_norm_sub_eq_zero {u v : α} (h : ∥u - v∥ = 0) : u = v :=
begin
apply eq_of_dist_eq_zero,
rwa dist_eq_norm
end
lemma norm_sub_eq_zero_iff {u v : α} : ∥u - v∥ = 0 ↔ u = v :=
begin
convert dist_eq_zero,
rwa dist_eq_norm
end
lemma norm_le_insert (u v : α) : ∥v∥ ≤ ∥u∥ + ∥u - v∥ :=
calc ∥v∥ = ∥u - (u - v)∥ : by abel
... ≤ ∥u∥ + ∥u - v∥ : norm_sub_le u _
lemma ball_0_eq (ε : ℝ) : ball (0:α) ε = {x | ∥x∥ < ε} :=
set.ext $ assume a, by simp
lemma mem_ball_iff_norm {g h : α} {r : ℝ} :
h ∈ ball g r ↔ ∥h - g∥ < r :=
by rw [mem_ball, dist_eq_norm]
lemma mem_ball_iff_norm' {g h : α} {r : ℝ} :
h ∈ ball g r ↔ ∥g - h∥ < r :=
by rw [mem_ball', dist_eq_norm]
lemma mem_closed_ball_iff_norm {g h : α} {r : ℝ} :
h ∈ closed_ball g r ↔ ∥h - g∥ ≤ r :=
by rw [mem_closed_ball, dist_eq_norm]
lemma mem_closed_ball_iff_norm' {g h : α} {r : ℝ} :
h ∈ closed_ball g r ↔ ∥g - h∥ ≤ r :=
by rw [mem_closed_ball', dist_eq_norm]
lemma norm_le_of_mem_closed_ball {g h : α} {r : ℝ} (H : h ∈ closed_ball g r) :
∥h∥ ≤ ∥g∥ + r :=
calc
∥h∥ = ∥g + (h - g)∥ : by rw [add_sub_cancel'_right]
... ≤ ∥g∥ + ∥h - g∥ : norm_add_le _ _
... ≤ ∥g∥ + r : by { apply add_le_add_left, rw ← dist_eq_norm, exact H }
lemma norm_lt_of_mem_ball {g h : α} {r : ℝ} (H : h ∈ ball g r) :
∥h∥ < ∥g∥ + r :=
calc
∥h∥ = ∥g + (h - g)∥ : by rw [add_sub_cancel'_right]
... ≤ ∥g∥ + ∥h - g∥ : norm_add_le _ _
... < ∥g∥ + r : by { apply add_lt_add_left, rw ← dist_eq_norm, exact H }
@[simp] lemma mem_sphere_iff_norm (v w : α) (r : ℝ) : w ∈ sphere v r ↔ ∥w - v∥ = r :=
by simp [dist_eq_norm]
@[simp] lemma mem_sphere_zero_iff_norm {w : α} {r : ℝ} : w ∈ sphere (0:α) r ↔ ∥w∥ = r :=
by simp [dist_eq_norm]
@[simp] lemma norm_eq_of_mem_sphere {r : ℝ} (x : sphere (0:α) r) : ∥(x:α)∥ = r :=
mem_sphere_zero_iff_norm.mp x.2
lemma nonzero_of_mem_sphere {r : ℝ} (hr : 0 < r) (x : sphere (0:α) r) : (x:α) ≠ 0 :=
by rwa [← norm_pos_iff, norm_eq_of_mem_sphere]
lemma nonzero_of_mem_unit_sphere (x : sphere (0:α) 1) : (x:α) ≠ 0 :=
by { apply nonzero_of_mem_sphere, norm_num }
/-- We equip the sphere, in a normed group, with a formal operation of negation, namely the
antipodal map. -/
instance {r : ℝ} : has_neg (sphere (0:α) r) :=
{ neg := λ w, ⟨-↑w, by simp⟩ }
@[simp] lemma coe_neg_sphere {r : ℝ} (v : sphere (0:α) r) :
(((-v) : sphere _ _) : α) = - (v:α) :=
rfl
theorem normed_group.tendsto_nhds_zero {f : γ → α} {l : filter γ} :
tendsto f l (𝓝 0) ↔ ∀ ε > 0, ∀ᶠ x in l, ∥ f x ∥ < ε :=
metric.tendsto_nhds.trans $ by simp only [dist_zero_right]
lemma normed_group.tendsto_nhds_nhds {f : α → β} {x : α} {y : β} :
tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ∥x' - x∥ < δ → ∥f x' - y∥ < ε :=
by simp_rw [metric.tendsto_nhds_nhds, dist_eq_norm]
/-- A homomorphism `f` of normed groups is Lipschitz, if there exists a constant `C` such that for
all `x`, one has `∥f x∥ ≤ C * ∥x∥`.
The analogous condition for a linear map of normed spaces is in `normed_space.operator_norm`. -/
lemma add_monoid_hom.lipschitz_of_bound (f :α →+ β) (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)
lemma lipschitz_on_with_iff_norm_sub_le {f : α → β} {C : ℝ≥0} {s : set α} :
lipschitz_on_with C f s ↔ ∀ (x ∈ s) (y ∈ s), ∥f x - f y∥ ≤ C * ∥x - y∥ :=
by simp only [lipschitz_on_with_iff_dist_le_mul, dist_eq_norm]
lemma lipschitz_on_with.norm_sub_le {f : α → β} {C : ℝ≥0} {s : set α} (h : lipschitz_on_with C f s)
{x y : α} (x_in : x ∈ s) (y_in : y ∈ s) : ∥f x - f y∥ ≤ C * ∥x - y∥ :=
lipschitz_on_with_iff_norm_sub_le.mp h x x_in y y_in
/-- A homomorphism `f` of normed groups is continuous, if there exists a constant `C` such that for
all `x`, one has `∥f x∥ ≤ C * ∥x∥`.
The analogous condition for a linear map of normed spaces is in `normed_space.operator_norm`. -/
lemma add_monoid_hom.continuous_of_bound (f :α →+ β) (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
continuous f :=
(f.lipschitz_of_bound C h).continuous
section nnnorm
/-- Version of the norm taking values in nonnegative reals. -/
def nnnorm (a : α) : ℝ≥0 := ⟨norm a, norm_nonneg a⟩
@[simp, norm_cast] lemma coe_nnnorm (a : α) : (nnnorm a : ℝ) = norm a := rfl
lemma nndist_eq_nnnorm (a b : α) : nndist a b = nnnorm (a - b) := nnreal.eq $ dist_eq_norm _ _
@[simp] lemma nnnorm_eq_zero {a : α} : nnnorm a = 0 ↔ a = 0 :=
by simp only [nnreal.eq_iff.symm, nnreal.coe_zero, coe_nnnorm, norm_eq_zero]
@[simp] lemma nnnorm_zero : nnnorm (0 : α) = 0 :=
nnreal.eq norm_zero
lemma nnnorm_add_le (g h : α) : nnnorm (g + h) ≤ nnnorm g + nnnorm h :=
nnreal.coe_le_coe.2 $ norm_add_le g h
@[simp] lemma nnnorm_neg (g : α) : nnnorm (-g) = nnnorm g :=
nnreal.eq $ norm_neg g
lemma nndist_nnnorm_nnnorm_le (g h : α) : nndist (nnnorm g) (nnnorm h) ≤ nnnorm (g - h) :=
nnreal.coe_le_coe.2 $ dist_norm_norm_le g h
lemma of_real_norm_eq_coe_nnnorm (x : β) : ennreal.of_real ∥x∥ = (nnnorm x : ℝ≥0∞) :=
ennreal.of_real_eq_coe_nnreal _
lemma edist_eq_coe_nnnorm_sub (x y : β) : edist x y = (nnnorm (x - y) : ℝ≥0∞) :=
by rw [edist_dist, dist_eq_norm, of_real_norm_eq_coe_nnnorm]
lemma edist_eq_coe_nnnorm (x : β) : edist x 0 = (nnnorm x : ℝ≥0∞) :=
by rw [edist_eq_coe_nnnorm_sub, _root_.sub_zero]
lemma mem_emetric_ball_0_iff {x : β} {r : ℝ≥0∞} : x ∈ emetric.ball (0 : β) r ↔ ↑(nnnorm x) < r :=
by rw [emetric.mem_ball, edist_eq_coe_nnnorm]
lemma nndist_add_add_le (g₁ g₂ h₁ h₂ : α) :
nndist (g₁ + g₂) (h₁ + h₂) ≤ nndist g₁ h₁ + nndist g₂ h₂ :=
nnreal.coe_le_coe.2 $ dist_add_add_le g₁ g₂ h₁ h₂
lemma edist_add_add_le (g₁ g₂ h₁ h₂ : α) :
edist (g₁ + g₂) (h₁ + h₂) ≤ edist g₁ h₁ + edist g₂ h₂ :=
by { simp only [edist_nndist], norm_cast, apply nndist_add_add_le }
lemma nnnorm_sum_le {β} : ∀(s : finset β) (f : β → α),
nnnorm (∑ a in s, f a) ≤ ∑ a in s, nnnorm (f a) :=
finset.le_sum_of_subadditive nnnorm nnnorm_zero nnnorm_add_le
end nnnorm
lemma lipschitz_with.neg {α : Type*} [emetric_space α] {K : ℝ≥0} {f : α → β}
(hf : lipschitz_with K f) : lipschitz_with K (λ x, -f x) :=
λ x y, by simpa only [edist_dist, dist_neg_neg] using hf x y
lemma lipschitz_with.add {α : Type*} [emetric_space α] {Kf : ℝ≥0} {f : α → β}
(hf : lipschitz_with Kf f) {Kg : ℝ≥0} {g : α → β} (hg : lipschitz_with Kg g) :
lipschitz_with (Kf + Kg) (λ x, f x + g x) :=
λ x y,
calc edist (f x + g x) (f y + g y) ≤ edist (f x) (f y) + edist (g x) (g y) :
edist_add_add_le _ _ _ _
... ≤ Kf * edist x y + Kg * edist x y :
add_le_add (hf x y) (hg x y)
... = (Kf + Kg) * edist x y :
(add_mul _ _ _).symm
lemma lipschitz_with.sub {α : Type*} [emetric_space α] {Kf : ℝ≥0} {f : α → β}
(hf : lipschitz_with Kf f) {Kg : ℝ≥0} {g : α → β} (hg : lipschitz_with Kg g) :
lipschitz_with (Kf + Kg) (λ x, f x - g x) :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma antilipschitz_with.add_lipschitz_with {α : Type*} [metric_space α] {Kf : ℝ≥0} {f : α → β}
(hf : antilipschitz_with Kf f) {Kg : ℝ≥0} {g : α → β} (hg : lipschitz_with Kg g)
(hK : Kg < Kf⁻¹) :
antilipschitz_with (Kf⁻¹ - Kg)⁻¹ (λ x, f x + g x) :=
begin
refine antilipschitz_with.of_le_mul_dist (λ x y, _),
rw [nnreal.coe_inv, ← div_eq_inv_mul],
rw le_div_iff (nnreal.coe_pos.2 $ nnreal.sub_pos.2 hK),
rw [mul_comm, nnreal.coe_sub (le_of_lt hK), sub_mul],
calc ↑Kf⁻¹ * dist x y - Kg * dist x y ≤ dist (f x) (f y) - dist (g x) (g y) :
sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y)
... ≤ _ : le_trans (le_abs_self _) (abs_dist_sub_le_dist_add_add _ _ _ _)
end
/-- A subgroup of a normed group is also a normed group, with the restriction of the norm. -/
instance add_subgroup.normed_group {E : Type*} [normed_group E] (s : add_subgroup E) :
normed_group s :=
{ norm := λx, norm (x : E),
dist_eq := λx y, dist_eq_norm (x : E) (y : E) }
/-- If `x` is an element of a subgroup `s` of a normed group `E`, its norm in `s` is equal to its
norm in `E`. -/
@[simp] lemma coe_norm_subgroup {E : Type*} [normed_group E] {s : add_subgroup E} (x : s) :
∥x∥ = ∥(x:E)∥ :=
rfl
/-- A submodule of a normed group is also a normed group, with the restriction of the norm.
See note [implicit instance arguments]. -/
instance submodule.normed_group {𝕜 : Type*} {_ : ring 𝕜}
{E : Type*} [normed_group E] {_ : module 𝕜 E} (s : submodule 𝕜 E) : normed_group s :=
{ norm := λx, norm (x : E),
dist_eq := λx y, dist_eq_norm (x : E) (y : E) }
/-- If `x` is an element of a submodule `s` of a normed group `E`, its norm in `E` is equal to its
norm in `s`.
See note [implicit instance arguments]. -/
@[simp, norm_cast] lemma submodule.norm_coe {𝕜 : Type*} {_ : ring 𝕜}
{E : Type*} [normed_group E] {_ : module 𝕜 E} {s : submodule 𝕜 E} (x : s) :
∥(x : E)∥ = ∥x∥ :=
rfl
@[simp] lemma submodule.norm_mk {𝕜 : Type*} {_ : ring 𝕜}
{E : Type*} [normed_group E] {_ : module 𝕜 E} {s : submodule 𝕜 E} (x : E) (hx : x ∈ s) :
∥(⟨x, hx⟩ : s)∥ = ∥x∥ :=
rfl
/-- normed group instance on the product of two normed groups, using the sup norm. -/
instance prod.normed_group : normed_group (α × β) :=
{ norm := λx, max ∥x.1∥ ∥x.2∥,
dist_eq := assume (x y : α × β),
show max (dist x.1 y.1) (dist x.2 y.2) = (max ∥(x - y).1∥ ∥(x - y).2∥), by simp [dist_eq_norm] }
lemma prod.norm_def (x : α × β) : ∥x∥ = (max ∥x.1∥ ∥x.2∥) := rfl
lemma prod.nnnorm_def (x : α × β) : nnnorm x = max (nnnorm x.1) (nnnorm x.2) :=
by { have := x.norm_def, simp only [← coe_nnnorm] at this, exact_mod_cast this }
lemma norm_fst_le (x : α × β) : ∥x.1∥ ≤ ∥x∥ :=
le_max_left _ _
lemma norm_snd_le (x : α × β) : ∥x.2∥ ≤ ∥x∥ :=
le_max_right _ _
lemma norm_prod_le_iff {x : α × β} {r : ℝ} :
∥x∥ ≤ r ↔ ∥x.1∥ ≤ r ∧ ∥x.2∥ ≤ r :=
max_le_iff
/-- normed group instance on the product of finitely many normed groups, using the sup norm. -/
instance pi.normed_group {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] :
normed_group (Πi, π i) :=
{ norm := λf, ((finset.sup finset.univ (λ b, nnnorm (f b)) : ℝ≥0) : ℝ),
dist_eq := assume x y,
congr_arg (coe : ℝ≥0 → ℝ) $ congr_arg (finset.sup finset.univ) $ funext $ assume a,
show nndist (x a) (y a) = nnnorm (x a - y a), from nndist_eq_nnnorm _ _ }
/-- The norm of an element in a product space is `≤ r` if and only if the norm of each
component is. -/
lemma pi_norm_le_iff {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] {r : ℝ} (hr : 0 ≤ r)
{x : Πi, π i} : ∥x∥ ≤ r ↔ ∀i, ∥x i∥ ≤ r :=
by simp only [← dist_zero_right, dist_pi_le_iff hr, pi.zero_apply]
/-- The norm of an element in a product space is `< r` if and only if the norm of each
component is. -/
lemma pi_norm_lt_iff {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] {r : ℝ} (hr : 0 < r)
{x : Πi, π i} : ∥x∥ < r ↔ ∀i, ∥x i∥ < r :=
by simp only [← dist_zero_right, dist_pi_lt_iff hr, pi.zero_apply]
lemma norm_le_pi_norm {π : ι → Type*} [fintype ι] [∀i, normed_group (π i)] (x : Πi, π i) (i : ι) :
∥x i∥ ≤ ∥x∥ :=
(pi_norm_le_iff (norm_nonneg x)).1 (le_refl _) i
@[simp] lemma pi_norm_const [nonempty ι] [fintype ι] (a : α) : ∥(λ i : ι, a)∥ = ∥a∥ :=
by simpa only [← dist_zero_right] using dist_pi_const a 0
@[simp] lemma pi_nnnorm_const [nonempty ι] [fintype ι] (a : α) :
nnnorm (λ i : ι, a) = nnnorm a :=
nnreal.eq $ pi_norm_const a
lemma tendsto_iff_norm_tendsto_zero {f : ι → β} {a : filter ι} {b : β} :
tendsto f a (𝓝 b) ↔ tendsto (λ e, ∥f e - b∥) a (𝓝 0) :=
by { convert tendsto_iff_dist_tendsto_zero, simp [dist_eq_norm] }
lemma tendsto_zero_iff_norm_tendsto_zero {f : γ → β} {a : filter γ} :
tendsto f a (𝓝 0) ↔ tendsto (λ e, ∥f e∥) a (𝓝 0) :=
by { rw [tendsto_iff_norm_tendsto_zero], simp only [sub_zero] }
/-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real
function `g` which tends to `0`, then `f` tends to `0`.
In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of
similar lemmas in `topology.metric_space.basic` and `topology.algebra.ordered`, the `'` version is
phrased using "eventually" and the non-`'` version is phrased absolutely. -/
lemma squeeze_zero_norm' {f : γ → α} {g : γ → ℝ} {t₀ : filter γ}
(h : ∀ᶠ n in t₀, ∥f n∥ ≤ g n)
(h' : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
tendsto_zero_iff_norm_tendsto_zero.mpr
(squeeze_zero' (eventually_of_forall (λ n, norm_nonneg _)) h h')
/-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `g` which
tends to `0`, then `f` tends to `0`. -/
lemma squeeze_zero_norm {f : γ → α} {g : γ → ℝ} {t₀ : filter γ}
(h : ∀ (n:γ), ∥f n∥ ≤ g n)
(h' : tendsto g t₀ (𝓝 0)) :
tendsto f t₀ (𝓝 0) :=
squeeze_zero_norm' (eventually_of_forall h) h'
lemma tendsto_norm_sub_self (x : α) : tendsto (λ g : α, ∥g - x∥) (𝓝 x) (𝓝 0) :=
by simpa [dist_eq_norm] using tendsto_id.dist (tendsto_const_nhds : tendsto (λ g, (x:α)) (𝓝 x) _)
lemma tendsto_norm {x : α} : tendsto (λg : α, ∥g∥) (𝓝 x) (𝓝 ∥x∥) :=
by simpa using tendsto_id.dist (tendsto_const_nhds : tendsto (λ g, (0:α)) _ _)
lemma tendsto_norm_zero : tendsto (λg : α, ∥g∥) (𝓝 0) (𝓝 0) :=
by simpa using tendsto_norm_sub_self (0:α)
@[continuity]
lemma continuous_norm : continuous (λg:α, ∥g∥) :=
by simpa using continuous_id.dist (continuous_const : continuous (λ g, (0:α)))
@[continuity]
lemma continuous_nnnorm : continuous (nnnorm : α → ℝ≥0) :=
continuous_subtype_mk _ continuous_norm
lemma lipschitz_with_one_norm : lipschitz_with 1 (norm : α → ℝ) :=
by simpa only [dist_zero_left] using lipschitz_with.dist_right (0 : α)
lemma uniform_continuous_norm : uniform_continuous (norm : α → ℝ) :=
lipschitz_with_one_norm.uniform_continuous
lemma uniform_continuous_nnnorm : uniform_continuous (nnnorm : α → ℝ≥0) :=
uniform_continuous_subtype_mk uniform_continuous_norm _
lemma tendsto_norm_nhds_within_zero : tendsto (norm : α → ℝ) (𝓝[{0}ᶜ] 0) (𝓝[set.Ioi 0] 0) :=
(continuous_norm.tendsto' (0 : α) 0 norm_zero).inf $ tendsto_principal_principal.2 $
λ x, norm_pos_iff.2
section
variables {l : filter γ} {f : γ → α} {a : α}
lemma filter.tendsto.norm {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ x, ∥f x∥) l (𝓝 ∥a∥) :=
tendsto_norm.comp h
lemma filter.tendsto.nnnorm (h : tendsto f l (𝓝 a)) :
tendsto (λ x, nnnorm (f x)) l (𝓝 (nnnorm a)) :=
tendsto.comp continuous_nnnorm.continuous_at h
end
section
variables [topological_space γ] {f : γ → α} {s : set γ} {a : γ} {b : α}
lemma continuous.norm (h : continuous f) : continuous (λ x, ∥f x∥) := continuous_norm.comp h
lemma continuous.nnnorm (h : continuous f) : continuous (λ x, nnnorm (f x)) :=
continuous_nnnorm.comp h
lemma continuous_at.norm (h : continuous_at f a) : continuous_at (λ x, ∥f x∥) a := h.norm
lemma continuous_at.nnnorm (h : continuous_at f a) : continuous_at (λ x, nnnorm (f x)) a := h.nnnorm
lemma continuous_within_at.norm (h : continuous_within_at f s a) :
continuous_within_at (λ x, ∥f x∥) s a :=
h.norm
lemma continuous_within_at.nnnorm (h : continuous_within_at f s a) :
continuous_within_at (λ x, nnnorm (f x)) s a :=
h.nnnorm
lemma continuous_on.norm (h : continuous_on f s) : continuous_on (λ x, ∥f x∥) s :=
λ x hx, (h x hx).norm
lemma continuous_on.nnnorm (h : continuous_on f s) : continuous_on (λ x, nnnorm (f x)) s :=
λ x hx, (h x hx).nnnorm
end
/-- If `∥y∥→∞`, then we can assume `y≠x` for any fixed `x`. -/
lemma eventually_ne_of_tendsto_norm_at_top {l : filter γ} {f : γ → α}
(h : tendsto (λ y, ∥f y∥) l at_top) (x : α) :
∀ᶠ y in l, f y ≠ x :=
begin
have : ∀ᶠ y in l, 1 + ∥x∥ ≤ ∥f y∥ := h (mem_at_top (1 + ∥x∥)),
refine this.mono (λ y hy hxy, _),
subst x,
exact not_le_of_lt zero_lt_one (add_le_iff_nonpos_left.1 hy)
end
/-- A normed group is a uniform additive group, i.e., addition and subtraction are uniformly
continuous. -/
@[priority 100] -- see Note [lower instance priority]
instance normed_uniform_group : uniform_add_group α :=
⟨(lipschitz_with.prod_fst.sub lipschitz_with.prod_snd).uniform_continuous⟩
@[priority 100] -- see Note [lower instance priority]
instance normed_top_monoid : has_continuous_add α :=
by apply_instance -- short-circuit type class inference
@[priority 100] -- see Note [lower instance priority]
instance normed_top_group : topological_add_group α :=
by apply_instance -- short-circuit type class inference
lemma nat.norm_cast_le [has_one α] : ∀ n : ℕ, ∥(n : α)∥ ≤ n * ∥(1 : α)∥
| 0 := by simp
| (n + 1) := by { rw [n.cast_succ, n.cast_succ, add_mul, one_mul],
exact norm_add_le_of_le (nat.norm_cast_le n) le_rfl }
end normed_group
section normed_ring
/-- A normed ring is a ring endowed with a norm which satisfies the inequality `∥x y∥ ≤ ∥x∥ ∥y∥`. -/
class normed_ring (α : Type*) extends has_norm α, ring α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_mul : ∀ a b, norm (a * b) ≤ norm a * norm b)
/-- A normed commutative ring is a commutative ring endowed with a norm which satisfies
the inequality `∥x y∥ ≤ ∥x∥ ∥y∥`. -/
class normed_comm_ring (α : Type*) extends normed_ring α :=
(mul_comm : ∀ x y : α, x * y = y * x)
/-- A mixin class with the axiom `∥1∥ = 1`. Many `normed_ring`s and all `normed_field`s satisfy this
axiom. -/
class norm_one_class (α : Type*) [has_norm α] [has_one α] : Prop :=
(norm_one : ∥(1:α)∥ = 1)
export norm_one_class (norm_one)
attribute [simp] norm_one
@[simp] lemma nnnorm_one [normed_group α] [has_one α] [norm_one_class α] : nnnorm (1:α) = 1 :=
nnreal.eq norm_one
@[priority 100] -- see Note [lower instance priority]
instance normed_comm_ring.to_comm_ring [β : normed_comm_ring α] : comm_ring α := { ..β }
@[priority 100] -- see Note [lower instance priority]
instance normed_ring.to_normed_group [β : normed_ring α] : normed_group α := { ..β }
instance prod.norm_one_class [normed_group α] [has_one α] [norm_one_class α]
[normed_group β] [has_one β] [norm_one_class β] :
norm_one_class (α × β) :=
⟨by simp [prod.norm_def]⟩
variables [normed_ring α]
lemma norm_mul_le (a b : α) : (∥a*b∥) ≤ (∥a∥) * (∥b∥) :=
normed_ring.norm_mul _ _
lemma list.norm_prod_le' : ∀ {l : list α}, l ≠ [] → ∥l.prod∥ ≤ (l.map norm).prod
| [] h := (h rfl).elim
| [a] _ := by simp
| (a :: b :: l) _ :=
begin
rw [list.map_cons, list.prod_cons, @list.prod_cons _ _ _ ∥a∥],
refine le_trans (norm_mul_le _ _) (mul_le_mul_of_nonneg_left _ (norm_nonneg _)),
exact list.norm_prod_le' (list.cons_ne_nil b l)
end
lemma list.norm_prod_le [norm_one_class α] : ∀ l : list α, ∥l.prod∥ ≤ (l.map norm).prod
| [] := by simp
| (a::l) := list.norm_prod_le' (list.cons_ne_nil a l)
lemma finset.norm_prod_le' {α : Type*} [normed_comm_ring α] (s : finset ι) (hs : s.nonempty)
(f : ι → α) :
∥∏ i in s, f i∥ ≤ ∏ i in s, ∥f i∥ :=
begin
rcases s with ⟨⟨l⟩, hl⟩,
have : l.map f ≠ [], by simpa using hs,
simpa using list.norm_prod_le' this
end
lemma finset.norm_prod_le {α : Type*} [normed_comm_ring α] [norm_one_class α] (s : finset ι)
(f : ι → α) :
∥∏ i in s, f i∥ ≤ ∏ i in s, ∥f i∥ :=
begin
rcases s with ⟨⟨l⟩, hl⟩,
simpa using (l.map f).norm_prod_le
end
/-- If `α` is a normed ring, then `∥a^n∥≤ ∥a∥^n` for `n > 0`. See also `norm_pow_le`. -/
lemma norm_pow_le' (a : α) : ∀ {n : ℕ}, 0 < n → ∥a^n∥ ≤ ∥a∥^n
| 1 h := by simp
| (n+2) h :=
le_trans (norm_mul_le a (a^(n+1)))
(mul_le_mul (le_refl _)
(norm_pow_le' (nat.succ_pos _)) (norm_nonneg _) (norm_nonneg _))
/-- If `α` is a normed ring with `∥1∥=1`, then `∥a^n∥≤ ∥a∥^n`. See also `norm_pow_le'`. -/
lemma norm_pow_le [norm_one_class α] (a : α) : ∀ (n : ℕ), ∥a^n∥ ≤ ∥a∥^n
| 0 := by simp
| (n+1) := norm_pow_le' a n.zero_lt_succ
lemma eventually_norm_pow_le (a : α) : ∀ᶠ (n:ℕ) in at_top, ∥a ^ n∥ ≤ ∥a∥ ^ n :=
eventually_at_top.mpr ⟨1, λ b h, norm_pow_le' a (nat.succ_le_iff.mp h)⟩
lemma units.norm_pos [nontrivial α] (x : units α) : 0 < ∥(x:α)∥ :=
norm_pos_iff.mpr (units.ne_zero x)
/-- In a normed ring, the left-multiplication `add_monoid_hom` is bounded. -/
lemma mul_left_bound (x : α) :
∀ (y:α), ∥add_monoid_hom.mul_left x y∥ ≤ ∥x∥ * ∥y∥ :=
norm_mul_le x
/-- In a normed ring, the right-multiplication `add_monoid_hom` is bounded. -/
lemma mul_right_bound (x : α) :
∀ (y:α), ∥add_monoid_hom.mul_right x y∥ ≤ ∥x∥ * ∥y∥ :=
λ y, by {rw mul_comm, convert norm_mul_le y x}
/-- Normed ring structure on the product of two normed rings, using the sup norm. -/
instance prod.normed_ring [normed_ring β] : normed_ring (α × β) :=
{ norm_mul := assume x y,
calc
∥x * y∥ = ∥(x.1*y.1, x.2*y.2)∥ : rfl
... = (max ∥x.1*y.1∥ ∥x.2*y.2∥) : rfl
... ≤ (max (∥x.1∥*∥y.1∥) (∥x.2∥*∥y.2∥)) :
max_le_max (norm_mul_le (x.1) (y.1)) (norm_mul_le (x.2) (y.2))
... = (max (∥x.1∥*∥y.1∥) (∥y.2∥*∥x.2∥)) : by simp[mul_comm]
... ≤ (max (∥x.1∥) (∥x.2∥)) * (max (∥y.2∥) (∥y.1∥)) :
by apply max_mul_mul_le_max_mul_max; simp [norm_nonneg]
... = (max (∥x.1∥) (∥x.2∥)) * (max (∥y.1∥) (∥y.2∥)) : by simp [max_comm]
... = (∥x∥*∥y∥) : rfl,
..prod.normed_group }
end normed_ring
@[priority 100] -- see Note [lower instance priority]
instance normed_ring_top_monoid [normed_ring α] : has_continuous_mul α :=
⟨ continuous_iff_continuous_at.2 $ λ x, tendsto_iff_norm_tendsto_zero.2 $
begin
have : ∀ e : α × α, ∥e.1 * e.2 - x.1 * x.2∥ ≤ ∥e.1∥ * ∥e.2 - x.2∥ + ∥e.1 - x.1∥ * ∥x.2∥,
{ intro e,
calc ∥e.1 * e.2 - x.1 * x.2∥ ≤ ∥e.1 * (e.2 - x.2) + (e.1 - x.1) * x.2∥ :
by rw [mul_sub, sub_mul, sub_add_sub_cancel]
... ≤ ∥e.1∥ * ∥e.2 - x.2∥ + ∥e.1 - x.1∥ * ∥x.2∥ :
norm_add_le_of_le (norm_mul_le _ _) (norm_mul_le _ _) },
refine squeeze_zero (λ e, norm_nonneg _) this _,
convert ((continuous_fst.tendsto x).norm.mul ((continuous_snd.tendsto x).sub
tendsto_const_nhds).norm).add
(((continuous_fst.tendsto x).sub tendsto_const_nhds).norm.mul _),
show tendsto _ _ _, from tendsto_const_nhds,
simp
end ⟩
/-- A normed ring is a topological ring. -/
@[priority 100] -- see Note [lower instance priority]
instance normed_top_ring [normed_ring α] : topological_ring α :=
⟨ continuous_iff_continuous_at.2 $ λ x, tendsto_iff_norm_tendsto_zero.2 $
have ∀ e : α, -e - -x = -(e - x), by intro; simp,
by simp only [this, norm_neg]; apply tendsto_norm_sub_self ⟩
/-- A normed field is a field with a norm satisfying ∥x y∥ = ∥x∥ ∥y∥. -/
class normed_field (α : Type*) extends has_norm α, field α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_mul' : ∀ a b, norm (a * b) = norm a * norm b)
/-- A nondiscrete normed field is a normed field in which there is an element of norm different from
`0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by multiplication
by the powers of any element, and thus to relate algebra and topology. -/
class nondiscrete_normed_field (α : Type*) extends normed_field α :=
(non_trivial : ∃x:α, 1<∥x∥)
namespace normed_field
section normed_field
variables [normed_field α]
@[simp] lemma norm_mul (a b : α) : ∥a * b∥ = ∥a∥ * ∥b∥ :=
normed_field.norm_mul' a b
@[priority 100] -- see Note [lower instance priority]
instance to_normed_comm_ring : normed_comm_ring α :=
{ norm_mul := λ a b, (norm_mul a b).le, ..‹normed_field α› }
@[priority 900]
instance to_norm_one_class : norm_one_class α :=
⟨mul_left_cancel' (mt norm_eq_zero.1 (@one_ne_zero α _ _)) $
by rw [← norm_mul, mul_one, mul_one]⟩
@[simp] lemma nnnorm_mul (a b : α) : nnnorm (a * b) = nnnorm a * nnnorm b :=
nnreal.eq $ norm_mul a b
/-- `norm` as a `monoid_hom`. -/
@[simps] def norm_hom : monoid_with_zero_hom α ℝ := ⟨norm, norm_zero, norm_one, norm_mul⟩
/-- `nnnorm` as a `monoid_hom`. -/
@[simps] def nnnorm_hom : monoid_with_zero_hom α ℝ≥0 :=
⟨nnnorm, nnnorm_zero, nnnorm_one, nnnorm_mul⟩
@[simp] lemma norm_pow (a : α) : ∀ (n : ℕ), ∥a ^ n∥ = ∥a∥ ^ n :=
norm_hom.to_monoid_hom.map_pow a
@[simp] lemma nnnorm_pow (a : α) (n : ℕ) : nnnorm (a ^ n) = nnnorm a ^ n :=
nnnorm_hom.to_monoid_hom.map_pow a n
@[simp] lemma norm_prod (s : finset β) (f : β → α) :
∥∏ b in s, f b∥ = ∏ b in s, ∥f b∥ :=
(norm_hom.to_monoid_hom : α →* ℝ).map_prod f s
@[simp] lemma nnnorm_prod (s : finset β) (f : β → α) :
nnnorm (∏ b in s, f b) = ∏ b in s, nnnorm (f b) :=
(nnnorm_hom.to_monoid_hom : α →* ℝ≥0).map_prod f s
@[simp] lemma norm_div (a b : α) : ∥a / b∥ = ∥a∥ / ∥b∥ :=
(norm_hom : monoid_with_zero_hom α ℝ).map_div a b
@[simp] lemma nnnorm_div (a b : α) : nnnorm (a / b) = nnnorm a / nnnorm b :=
(nnnorm_hom : monoid_with_zero_hom α ℝ≥0).map_div a b
@[simp] lemma norm_inv (a : α) : ∥a⁻¹∥ = ∥a∥⁻¹ :=
(norm_hom : monoid_with_zero_hom α ℝ).map_inv' a
@[simp] lemma nnnorm_inv (a : α) : nnnorm (a⁻¹) = (nnnorm a)⁻¹ :=
nnreal.eq $ by simp
@[simp] lemma norm_fpow : ∀ (a : α) (n : ℤ), ∥a^n∥ = ∥a∥^n :=
(norm_hom : monoid_with_zero_hom α ℝ).map_fpow
@[simp] lemma nnnorm_fpow : ∀ (a : α) (n : ℤ), nnnorm (a^n) = (nnnorm a)^n :=
(nnnorm_hom : monoid_with_zero_hom α ℝ≥0).map_fpow
@[priority 100] -- see Note [lower instance priority]
instance : has_continuous_inv' α :=
begin
refine ⟨λ r r0, tendsto_iff_norm_tendsto_zero.2 _⟩,
have r0' : 0 < ∥r∥ := norm_pos_iff.2 r0,
rcases exists_between r0' with ⟨ε, ε0, εr⟩,
have : ∀ᶠ e in 𝓝 r, ∥e⁻¹ - r⁻¹∥ ≤ ∥r - e∥ / ∥r∥ / ε,
{ filter_upwards [(is_open_lt continuous_const continuous_norm).eventually_mem εr],
intros e he,
have e0 : e ≠ 0 := norm_pos_iff.1 (ε0.trans he),
calc ∥e⁻¹ - r⁻¹∥ = ∥r - e∥ / ∥r∥ / ∥e∥ : by field_simp [mul_comm]
... ≤ ∥r - e∥ / ∥r∥ / ε :
div_le_div_of_le_left (div_nonneg (norm_nonneg _) (norm_nonneg _)) ε0 he.le },
refine squeeze_zero' (eventually_of_forall $ λ _, norm_nonneg _) this _,
refine (continuous_const.sub continuous_id).norm.div_const.div_const.tendsto' _ _ _,
simp
end
end normed_field
variables (α) [nondiscrete_normed_field α]
lemma exists_one_lt_norm : ∃x : α, 1 < ∥x∥ := ‹nondiscrete_normed_field α›.non_trivial
lemma exists_norm_lt_one : ∃x : α, 0 < ∥x∥ ∧ ∥x∥ < 1 :=
begin
rcases exists_one_lt_norm α with ⟨y, hy⟩,
refine ⟨y⁻¹, _, _⟩,
{ simp only [inv_eq_zero, ne.def, norm_pos_iff],
rintro rfl,
rw norm_zero at hy,
exact lt_asymm zero_lt_one hy },
{ simp [inv_lt_one hy] }
end
lemma exists_lt_norm (r : ℝ) : ∃ x : α, r < ∥x∥ :=
let ⟨w, hw⟩ := exists_one_lt_norm α in
let ⟨n, hn⟩ := pow_unbounded_of_one_lt r hw in
⟨w^n, by rwa norm_pow⟩
lemma exists_norm_lt {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ∥x∥ ∧ ∥x∥ < r :=
let ⟨w, hw⟩ := exists_one_lt_norm α in
let ⟨n, hle, hlt⟩ := exists_int_pow_near' hr hw in
⟨w^n, by { rw norm_fpow; exact fpow_pos_of_pos (lt_trans zero_lt_one hw) _},
by rwa norm_fpow⟩
variable {α}
@[instance]
lemma punctured_nhds_ne_bot (x : α) : ne_bot (𝓝[{x}ᶜ] x) :=
begin
rw [← mem_closure_iff_nhds_within_ne_bot, metric.mem_closure_iff],
rintros ε ε0,
rcases normed_field.exists_norm_lt α ε0 with ⟨b, hb0, hbε⟩,
refine ⟨x + b, mt (set.mem_singleton_iff.trans add_right_eq_self).1 $ norm_pos_iff.1 hb0, _⟩,
rwa [dist_comm, dist_eq_norm, add_sub_cancel'],
end
@[instance]
lemma nhds_within_is_unit_ne_bot : ne_bot (𝓝[{x : α | is_unit x}] 0) :=
by simpa only [is_unit_iff_ne_zero] using punctured_nhds_ne_bot (0:α)
end normed_field
instance : normed_field ℝ :=
{ norm_mul' := abs_mul,
.. real.normed_group }
instance : nondiscrete_normed_field ℝ :=
{ non_trivial := ⟨2, by { unfold norm, rw abs_of_nonneg; norm_num }⟩ }
namespace real
lemma norm_of_nonneg {x : ℝ} (hx : 0 ≤ x) : ∥x∥ = x :=
abs_of_nonneg hx
@[simp] lemma norm_coe_nat (n : ℕ) : ∥(n : ℝ)∥ = n := abs_of_nonneg n.cast_nonneg
@[simp] lemma nnnorm_coe_nat (n : ℕ) : nnnorm (n : ℝ) = n := nnreal.eq $ by simp
@[simp] lemma norm_two : ∥(2:ℝ)∥ = 2 := abs_of_pos (@zero_lt_two ℝ _ _)
@[simp] lemma nnnorm_two : nnnorm (2:ℝ) = 2 := nnreal.eq $ by simp
lemma nnnorm_of_nonneg {x : ℝ} (hx : 0 ≤ x) : nnnorm x = ⟨x, hx⟩ :=
nnreal.eq $ norm_of_nonneg hx
lemma ennnorm_eq_of_real {x : ℝ} (hx : 0 ≤ x) : (nnnorm x : ℝ≥0∞) = ennreal.of_real x :=
by { rw [← of_real_norm_eq_coe_nnnorm, norm_of_nonneg hx] }
end real
namespace nnreal
open_locale nnreal
@[simp] lemma norm_eq (x : ℝ≥0) : ∥(x : ℝ)∥ = x :=
by rw [real.norm_eq_abs, x.abs_eq]
@[simp] lemma nnnorm_eq (x : ℝ≥0) : nnnorm (x : ℝ) = x :=
nnreal.eq $ real.norm_of_nonneg x.2
end nnreal
@[simp] lemma norm_norm [normed_group α] (x : α) : ∥∥x∥∥ = ∥x∥ :=
real.norm_of_nonneg (norm_nonneg _)
@[simp] lemma nnnorm_norm [normed_group α] (a : α) : nnnorm ∥a∥ = nnnorm a :=
by simp only [nnnorm, norm_norm]
instance : normed_comm_ring ℤ :=
{ norm := λ n, ∥(n : ℝ)∥,
norm_mul := λ m n, le_of_eq $ by simp only [norm, int.cast_mul, abs_mul],
dist_eq := λ m n, by simp only [int.dist_eq, norm, int.cast_sub],
mul_comm := mul_comm }
@[norm_cast] lemma int.norm_cast_real (m : ℤ) : ∥(m : ℝ)∥ = ∥m∥ := rfl
instance : norm_one_class ℤ :=
⟨by simp [← int.norm_cast_real]⟩
instance : normed_field ℚ :=
{ norm := λ r, ∥(r : ℝ)∥,
norm_mul' := λ r₁ r₂, by simp only [norm, rat.cast_mul, abs_mul],
dist_eq := λ r₁ r₂, by simp only [rat.dist_eq, norm, rat.cast_sub] }
instance : nondiscrete_normed_field ℚ :=
{ non_trivial := ⟨2, by { unfold norm, rw abs_of_nonneg; norm_num }⟩ }
@[norm_cast, simp] lemma rat.norm_cast_real (r : ℚ) : ∥(r : ℝ)∥ = ∥r∥ := rfl
@[norm_cast, simp] lemma int.norm_cast_rat (m : ℤ) : ∥(m : ℚ)∥ = ∥m∥ :=
by rw [← rat.norm_cast_real, ← int.norm_cast_real]; congr' 1; norm_cast
section normed_space
section prio
set_option extends_priority 920
-- Here, we set a rather high priority for the instance `[normed_space α β] : semimodule α β`
-- to take precedence over `semiring.to_semimodule` as this leads to instance paths with better
-- unification properties.
-- see Note[vector space definition] for why we extend `semimodule`.
/-- A normed space over a normed field is a vector space endowed with a norm which satisfies the
equality `∥c • x∥ = ∥c∥ ∥x∥`. We require only `∥c • x∥ ≤ ∥c∥ ∥x∥` in the definition, then prove
`∥c • x∥ = ∥c∥ ∥x∥` in `norm_smul`. -/
class normed_space (α : Type*) (β : Type*) [normed_field α] [normed_group β]
extends semimodule α β :=
(norm_smul_le : ∀ (a:α) (b:β), ∥a • b∥ ≤ ∥a∥ * ∥b∥)
end prio
variables [normed_field α] [normed_group β]
instance normed_field.to_normed_space : normed_space α α :=
{ norm_smul_le := λ a b, le_of_eq (normed_field.norm_mul a b) }
lemma norm_smul [normed_space α β] (s : α) (x : β) : ∥s • x∥ = ∥s∥ * ∥x∥ :=
begin
classical,
by_cases h : s = 0,
{ simp [h] },
{ refine le_antisymm (normed_space.norm_smul_le s x) _,
calc ∥s∥ * ∥x∥ = ∥s∥ * ∥s⁻¹ • s • x∥ : by rw [inv_smul_smul' h]
... ≤ ∥s∥ * (∥s⁻¹∥ * ∥s • x∥) : _
... = ∥s • x∥ : _,
exact mul_le_mul_of_nonneg_left (normed_space.norm_smul_le _ _) (norm_nonneg _),
rw [normed_field.norm_inv, ← mul_assoc, mul_inv_cancel, one_mul],
rwa [ne.def, norm_eq_zero] }
end
@[simp] lemma abs_norm_eq_norm (z : β) : abs ∥z∥ = ∥z∥ :=
(abs_eq (norm_nonneg z)).mpr (or.inl rfl)
lemma dist_smul [normed_space α β] (s : α) (x y : β) : dist (s • x) (s • y) = ∥s∥ * dist x y :=
by simp only [dist_eq_norm, (norm_smul _ _).symm, smul_sub]
lemma nnnorm_smul [normed_space α β] (s : α) (x : β) : nnnorm (s • x) = nnnorm s * nnnorm x :=
nnreal.eq $ norm_smul s x
lemma nndist_smul [normed_space α β] (s : α) (x y : β) :
nndist (s • x) (s • y) = nnnorm s * nndist x y :=
nnreal.eq $ dist_smul s x y
lemma norm_smul_of_nonneg [normed_space ℝ β] {t : ℝ} (ht : 0 ≤ t) (x : β) : ∥t • x∥ = t * ∥x∥ :=
by rw [norm_smul, real.norm_eq_abs, abs_of_nonneg ht]
variables {E : Type*} {F : Type*}
[normed_group E] [normed_space α E] [normed_group F] [normed_space α F]
@[priority 100] -- see Note [lower instance priority]
instance normed_space.topological_vector_space : topological_vector_space α E :=
begin
refine { continuous_smul := continuous_iff_continuous_at.2 $
λ p, tendsto_iff_norm_tendsto_zero.2 _ },
refine squeeze_zero (λ _, norm_nonneg _) _ _,
{ exact λ q, ∥q.1 - p.1∥ * ∥q.2∥ + ∥p.1∥ * ∥q.2 - p.2∥ },
{ intro q,
rw [← sub_add_sub_cancel, ← norm_smul, ← norm_smul, smul_sub, sub_smul],
exact norm_add_le _ _ },
{ conv { congr, skip, skip, congr, rw [← zero_add (0:ℝ)], congr,
rw [← zero_mul ∥p.2∥], skip, rw [← mul_zero ∥p.1∥] },
exact ((tendsto_iff_norm_tendsto_zero.1 (continuous_fst.tendsto p)).mul
(continuous_snd.tendsto p).norm).add
(tendsto_const_nhds.mul (tendsto_iff_norm_tendsto_zero.1 (continuous_snd.tendsto p))) }
end
theorem closure_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) :
closure (ball x r) = closed_ball x r :=
begin
refine set.subset.antisymm closure_ball_subset_closed_ball (λ y hy, _),
have : continuous_within_at (λ c : ℝ, c • (y - x) + x) (set.Ico 0 1) 1 :=
((continuous_id.smul continuous_const).add continuous_const).continuous_within_at,
convert this.mem_closure _ _,
{ rw [one_smul, sub_add_cancel] },
{ simp [closure_Ico (@zero_lt_one ℝ _ _), zero_le_one] },
{ rintros c ⟨hc0, hc1⟩,
rw [set.mem_preimage, mem_ball, dist_eq_norm, add_sub_cancel, norm_smul, real.norm_eq_abs,
abs_of_nonneg hc0, mul_comm, ← mul_one r],
rw [mem_closed_ball, dist_eq_norm] at hy,
apply mul_lt_mul'; assumption }
end
theorem frontier_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) :
frontier (ball x r) = sphere x r :=
begin
rw [frontier, closure_ball x hr, is_open_ball.interior_eq],
ext x, exact (@eq_iff_le_not_lt ℝ _ _ _).symm
end
theorem interior_closed_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) :
interior (closed_ball x r) = ball x r :=
begin
refine set.subset.antisymm _ ball_subset_interior_closed_ball,
intros y hy,
rcases le_iff_lt_or_eq.1 (mem_closed_ball.1 $ interior_subset hy) with hr|rfl, { exact hr },
set f : ℝ → E := λ c : ℝ, c • (y - x) + x,
suffices : f ⁻¹' closed_ball x (dist y x) ⊆ set.Icc (-1) 1,
{ have hfc : continuous f := (continuous_id.smul continuous_const).add continuous_const,
have hf1 : (1:ℝ) ∈ f ⁻¹' (interior (closed_ball x $ dist y x)), by simpa [f],
have h1 : (1:ℝ) ∈ interior (set.Icc (-1:ℝ) 1) :=
interior_mono this (preimage_interior_subset_interior_preimage hfc hf1),
contrapose h1,
simp },
intros c hc,
rw [set.mem_Icc, ← abs_le, ← real.norm_eq_abs, ← mul_le_mul_right hr],
simpa [f, dist_eq_norm, norm_smul] using hc
end
theorem interior_closed_ball' [normed_space ℝ E] [nontrivial E] (x : E) (r : ℝ) :
interior (closed_ball x r) = ball x r :=
begin
rcases lt_trichotomy r 0 with hr|rfl|hr,
{ simp [closed_ball_eq_empty_iff_neg.2 hr, ball_eq_empty_iff_nonpos.2 (le_of_lt hr)] },
{ suffices : x ∉ interior {x},
{ rw [ball_zero, closed_ball_zero, ← set.subset_empty_iff],
intros y hy,
obtain rfl : y = x := set.mem_singleton_iff.1 (interior_subset hy),
exact this hy },
rw [← set.mem_compl_iff, ← closure_compl],
rcases exists_ne (0 : E) with ⟨z, hz⟩,
suffices : (λ c : ℝ, x + c • z) 0 ∈ closure ({x}ᶜ : set E),
by simpa only [zero_smul, add_zero] using this,
have : (0:ℝ) ∈ closure (set.Ioi (0:ℝ)), by simp [closure_Ioi],
refine (continuous_const.add (continuous_id.smul
continuous_const)).continuous_within_at.mem_closure this _,
intros c hc,
simp [smul_eq_zero, hz, ne_of_gt hc] },
{ exact interior_closed_ball x hr }
end
theorem frontier_closed_ball [normed_space ℝ E] (x : E) {r : ℝ} (hr : 0 < r) :
frontier (closed_ball x r) = sphere x r :=
by rw [frontier, closure_closed_ball, interior_closed_ball x hr,
closed_ball_diff_ball]
theorem frontier_closed_ball' [normed_space ℝ E] [nontrivial E] (x : E) (r : ℝ) :
frontier (closed_ball x r) = sphere x r :=
by rw [frontier, closure_closed_ball, interior_closed_ball' x r, closed_ball_diff_ball]
variables (α)
lemma ne_neg_of_mem_sphere [char_zero α] {r : ℝ} (hr : 0 < r) (x : sphere (0:E) r) : x ≠ - x :=
λ h, nonzero_of_mem_sphere hr x (eq_zero_of_eq_neg α (by { conv_lhs {rw h}, simp }))
lemma ne_neg_of_mem_unit_sphere [char_zero α] (x : sphere (0:E) 1) : x ≠ - x :=
ne_neg_of_mem_sphere α (by norm_num) x
variables {α}
open normed_field
/-- If there is a scalar `c` with `∥c∥>1`, then any element can be moved by scalar multiplication to
any shell of width `∥c∥`. Also recap information on the norm of the rescaling element that shows
up in applications. -/
lemma rescale_to_shell {c : α} (hc : 1 < ∥c∥) {ε : ℝ} (εpos : 0 < ε) {x : E} (hx : x ≠ 0) :
∃d:α, d ≠ 0 ∧ ∥d • x∥ < ε ∧ (ε/∥c∥ ≤ ∥d • x∥) ∧ (∥d∥⁻¹ ≤ ε⁻¹ * ∥c∥ * ∥x∥) :=
begin
have xεpos : 0 < ∥x∥/ε := div_pos (norm_pos_iff.2 hx) εpos,
rcases exists_int_pow_near xεpos hc with ⟨n, hn⟩,
have cpos : 0 < ∥c∥ := lt_trans (zero_lt_one : (0 :ℝ) < 1) hc,
have cnpos : 0 < ∥c^(n+1)∥ := by { rw norm_fpow, exact lt_trans xεpos hn.2 },
refine ⟨(c^(n+1))⁻¹, _, _, _, _⟩,
show (c ^ (n + 1))⁻¹ ≠ 0,
by rwa [ne.def, inv_eq_zero, ← ne.def, ← norm_pos_iff],
show ∥(c ^ (n + 1))⁻¹ • x∥ < ε,
{ rw [norm_smul, norm_inv, ← div_eq_inv_mul, div_lt_iff cnpos, mul_comm, norm_fpow],
exact (div_lt_iff εpos).1 (hn.2) },
show ε / ∥c∥ ≤ ∥(c ^ (n + 1))⁻¹ • x∥,
{ rw [div_le_iff cpos, norm_smul, norm_inv, norm_fpow, fpow_add (ne_of_gt cpos),
fpow_one, mul_inv_rev', mul_comm, ← mul_assoc, ← mul_assoc, mul_inv_cancel (ne_of_gt cpos),
one_mul, ← div_eq_inv_mul, le_div_iff (fpow_pos_of_pos cpos _), mul_comm],
exact (le_div_iff εpos).1 hn.1 },
show ∥(c ^ (n + 1))⁻¹∥⁻¹ ≤ ε⁻¹ * ∥c∥ * ∥x∥,
{ have : ε⁻¹ * ∥c∥ * ∥x∥ = ε⁻¹ * ∥x∥ * ∥c∥, by ring,
rw [norm_inv, inv_inv', norm_fpow, fpow_add (ne_of_gt cpos), fpow_one, this, ← div_eq_inv_mul],
exact mul_le_mul_of_nonneg_right hn.1 (norm_nonneg _) }
end
/-- The product of two normed spaces is a normed space, with the sup norm. -/
instance : normed_space α (E × F) :=
{ norm_smul_le := λ s x, le_of_eq $ by simp [prod.norm_def, norm_smul, mul_max_of_nonneg],
-- TODO: without the next two lines Lean unfolds `≤` to `real.le`
add_smul := λ r x y, prod.ext (add_smul _ _ _) (add_smul _ _ _),
smul_add := λ r x y, prod.ext (smul_add _ _ _) (smul_add _ _ _),
..prod.normed_group,
..prod.semimodule }
/-- The product of finitely many normed spaces is a normed space, with the sup norm. -/
instance pi.normed_space {E : ι → Type*} [fintype ι] [∀i, normed_group (E i)]
[∀i, normed_space α (E i)] : normed_space α (Πi, E i) :=
{ norm_smul_le := λ a f, le_of_eq $
show (↑(finset.sup finset.univ (λ (b : ι), nnnorm (a • f b))) : ℝ) =
nnnorm a * ↑(finset.sup finset.univ (λ (b : ι), nnnorm (f b))),
by simp only [(nnreal.coe_mul _ _).symm, nnreal.mul_finset_sup, nnnorm_smul] }
/-- A subspace of a normed space is also a normed space, with the restriction of the norm. -/
instance submodule.normed_space {𝕜 : Type*} [normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (s : submodule 𝕜 E) : normed_space 𝕜 s :=
{ norm_smul_le := λc x, le_of_eq $ norm_smul c (x : E) }
end normed_space
section normed_algebra
/-- A normed algebra `𝕜'` over `𝕜` is an algebra endowed with a norm for which the embedding of
`𝕜` in `𝕜'` is an isometry. -/
class normed_algebra (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜']
extends algebra 𝕜 𝕜' :=
(norm_algebra_map_eq : ∀x:𝕜, ∥algebra_map 𝕜 𝕜' x∥ = ∥x∥)
@[simp] lemma norm_algebra_map_eq {𝕜 : Type*} (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜']
[h : normed_algebra 𝕜 𝕜'] (x : 𝕜) : ∥algebra_map 𝕜 𝕜' x∥ = ∥x∥ :=
normed_algebra.norm_algebra_map_eq _
variables (𝕜 : Type*) [normed_field 𝕜]
variables (𝕜' : Type*) [normed_ring 𝕜']
@[priority 100]
instance normed_algebra.to_normed_space [h : normed_algebra 𝕜 𝕜'] : normed_space 𝕜 𝕜' :=
{ norm_smul_le := λ s x, calc
∥s • x∥ = ∥((algebra_map 𝕜 𝕜') s) * x∥ : by { rw h.smul_def', refl }
... ≤ ∥algebra_map 𝕜 𝕜' s∥ * ∥x∥ : normed_ring.norm_mul _ _
... = ∥s∥ * ∥x∥ : by rw norm_algebra_map_eq,
..h }
instance normed_algebra.id : normed_algebra 𝕜 𝕜 :=
{ norm_algebra_map_eq := by simp,
.. algebra.id 𝕜}
variables (𝕜') [normed_algebra 𝕜 𝕜']
include 𝕜
lemma normed_algebra.norm_one : ∥(1:𝕜')∥ = 1 :=
by simpa using (norm_algebra_map_eq 𝕜' (1:𝕜))
lemma normed_algebra.norm_one_class : norm_one_class 𝕜' :=
⟨normed_algebra.norm_one 𝕜 𝕜'⟩
lemma normed_algebra.zero_ne_one : (0:𝕜') ≠ 1 :=
begin
refine (norm_pos_iff.mp _).symm,
rw normed_algebra.norm_one 𝕜 𝕜', norm_num,
end
lemma normed_algebra.nontrivial : nontrivial 𝕜' :=
⟨⟨0, 1, normed_algebra.zero_ne_one 𝕜 𝕜'⟩⟩
end normed_algebra
section restrict_scalars
variables (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
(E : Type*) [normed_group E] [normed_space 𝕜' E]
/-- Warning: This declaration should be used judiciously.
Please consider using `is_scalar_tower` instead.
`𝕜`-normed space structure induced by a `𝕜'`-normed space structure when `𝕜'` is a
normed algebra over `𝕜`. Not registered as an instance as `𝕜'` can not be inferred.
The type synonym `semimodule.restrict_scalars 𝕜 𝕜' E` will be endowed with this instance by default.
-/
def normed_space.restrict_scalars : normed_space 𝕜 E :=
{ norm_smul_le := λc x, le_of_eq $ begin
change ∥(algebra_map 𝕜 𝕜' c) • x∥ = ∥c∥ * ∥x∥,
simp [norm_smul]
end,
..restrict_scalars.semimodule 𝕜 𝕜' E }
instance {𝕜 : Type*} {𝕜' : Type*} {E : Type*} [I : normed_group E] :
normed_group (restrict_scalars 𝕜 𝕜' E) := I
instance semimodule.restrict_scalars.normed_space_orig {𝕜 : Type*} {𝕜' : Type*} {E : Type*}
[normed_field 𝕜'] [normed_group E] [I : normed_space 𝕜' E] :
normed_space 𝕜' (restrict_scalars 𝕜 𝕜' E) := I
instance : normed_space 𝕜 (restrict_scalars 𝕜 𝕜' E) :=
(normed_space.restrict_scalars 𝕜 𝕜' E : normed_space 𝕜 E)
end restrict_scalars
section summable
open_locale classical
open finset filter
variables [normed_group α] [normed_group β]
lemma cauchy_seq_finset_iff_vanishing_norm {f : ι → α} :
cauchy_seq (λ s : finset ι, ∑ i in s, f i) ↔
∀ε > (0 : ℝ), ∃s:finset ι, ∀t, disjoint t s → ∥ ∑ i in t, f i ∥ < ε :=
begin
rw [cauchy_seq_finset_iff_vanishing, nhds_basis_ball.forall_iff],
{ simp only [ball_0_eq, set.mem_set_of_eq] },
{ rintros s t hst ⟨s', hs'⟩,
exact ⟨s', λ t' ht', hst $ hs' _ ht'⟩ }
end
lemma summable_iff_vanishing_norm [complete_space α] {f : ι → α} :
summable f ↔ ∀ε > (0 : ℝ), ∃s:finset ι, ∀t, disjoint t s → ∥ ∑ i in t, f i ∥ < ε :=
by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing_norm]
lemma cauchy_seq_finset_of_norm_bounded {f : ι → α} (g : ι → ℝ) (hg : summable g)
(h : ∀i, ∥f i∥ ≤ g i) : cauchy_seq (λ s : finset ι, ∑ i in s, f i) :=
cauchy_seq_finset_iff_vanishing_norm.2 $ assume ε hε,
let ⟨s, hs⟩ := summable_iff_vanishing_norm.1 hg ε hε in
⟨s, assume t ht,
have ∥∑ i in t, g i∥ < ε := hs t ht,
have nn : 0 ≤ ∑ i in t, g i := finset.sum_nonneg (assume a _, le_trans (norm_nonneg _) (h a)),
lt_of_le_of_lt (norm_sum_le_of_le t (λ i _, h i)) $
by rwa [real.norm_eq_abs, abs_of_nonneg nn] at this⟩
lemma cauchy_seq_finset_of_summable_norm {f : ι → α} (hf : summable (λa, ∥f a∥)) :
cauchy_seq (λ s : finset ι, ∑ a in s, f a) :=
cauchy_seq_finset_of_norm_bounded _ hf (assume i, le_refl _)
/-- If a function `f` is summable in norm, and along some sequence of finsets exhausting the space
its sum is converging to a limit `a`, then this holds along all finsets, i.e., `f` is summable
with sum `a`. -/
lemma has_sum_of_subseq_of_summable {f : ι → α} (hf : summable (λa, ∥f a∥))
{s : γ → finset ι} {p : filter γ} [ne_bot p]
(hs : tendsto s p at_top) {a : α} (ha : tendsto (λ b, ∑ i in s b, f i) p (𝓝 a)) :
has_sum f a :=
tendsto_nhds_of_cauchy_seq_of_subseq (cauchy_seq_finset_of_summable_norm hf) hs ha
lemma has_sum_iff_tendsto_nat_of_summable_norm {f : ℕ → α} {a : α} (hf : summable (λi, ∥f i∥)) :
has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
⟨λ h, h.tendsto_sum_nat,
λ h, has_sum_of_subseq_of_summable hf tendsto_finset_range h⟩
/-- The direct comparison test for series: if the norm of `f` is bounded by a real function `g`
which is summable, then `f` is summable. -/
lemma summable_of_norm_bounded
[complete_space α] {f : ι → α} (g : ι → ℝ) (hg : summable g) (h : ∀i, ∥f i∥ ≤ g i) :
summable f :=
by { rw summable_iff_cauchy_seq_finset, exact cauchy_seq_finset_of_norm_bounded g hg h }
lemma has_sum.norm_le_of_bounded {f : ι → α} {g : ι → ℝ} {a : α} {b : ℝ}
(hf : has_sum f a) (hg : has_sum g b) (h : ∀ i, ∥f i∥ ≤ g i) :
∥a∥ ≤ b :=
le_of_tendsto_of_tendsto' hf.norm hg $ λ s, norm_sum_le_of_le _ $ λ i hi, h i
/-- Quantitative result associated to the direct comparison test for series: If `∑' i, g i` is
summable, and for all `i`, `∥f i∥ ≤ g i`, then `∥∑' i, f i∥ ≤ ∑' i, g i`. Note that we do not
assume that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete space. -/
lemma tsum_of_norm_bounded {f : ι → α} {g : ι → ℝ} {a : ℝ} (hg : has_sum g a)
(h : ∀ i, ∥f i∥ ≤ g i) :
∥∑' i : ι, f i∥ ≤ a :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.norm_le_of_bounded hg h },
{ rw [tsum_eq_zero_of_not_summable hf, norm_zero],
exact ge_of_tendsto' hg (λ s, sum_nonneg $ λ i hi, (norm_nonneg _).trans (h i)) }
end
/-- If `∑' i, ∥f i∥` is summable, then `∥∑' i, f i∥ ≤ (∑' i, ∥f i∥)`. Note that we do not assume
that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete space. -/
lemma norm_tsum_le_tsum_norm {f : ι → α} (hf : summable (λi, ∥f i∥)) :
∥∑'i, f i∥ ≤ ∑' i, ∥f i∥ :=
tsum_of_norm_bounded hf.has_sum $ λ i, le_rfl
variable [complete_space α]
/-- Variant of the direct comparison test for series: if the norm of `f` is eventually bounded by a
real function `g` which is summable, then `f` is summable. -/
lemma summable_of_norm_bounded_eventually {f : ι → α} (g : ι → ℝ) (hg : summable g)
(h : ∀ᶠ i in cofinite, ∥f i∥ ≤ g i) : summable f :=
begin
replace h := mem_cofinite.1 h,
refine h.summable_compl_iff.mp _,
refine summable_of_norm_bounded _ (h.summable_compl_iff.mpr hg) _,
rintros ⟨a, h'⟩,
simpa using h'
end
lemma summable_of_nnnorm_bounded {f : ι → α} (g : ι → ℝ≥0) (hg : summable g)
(h : ∀i, nnnorm (f i) ≤ g i) : summable f :=
summable_of_norm_bounded (λ i, (g i : ℝ)) (nnreal.summable_coe.2 hg) (λ i, by exact_mod_cast h i)
lemma summable_of_summable_norm {f : ι → α} (hf : summable (λa, ∥f a∥)) : summable f :=
summable_of_norm_bounded _ hf (assume i, le_refl _)
lemma summable_of_summable_nnnorm {f : ι → α} (hf : summable (λa, nnnorm (f a))) : summable f :=
summable_of_nnnorm_bounded _ hf (assume i, le_refl _)
end summable
|
fac034e1078dc1a9202bb1163b7ed216a03692ca | 08bd4ba4ca87dba1f09d2c96a26f5d65da81f4b4 | /src/Lean/Elab/BuiltinTerm.lean | cd9cebafa755b229125672f76392c460693d5cfd | [
"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",
"Apache-2.0",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | gebner/lean4 | d51c4922640a52a6f7426536ea669ef18a1d9af5 | 8cd9ce06843c9d42d6d6dc43d3e81e3b49dfc20f | refs/heads/master | 1,685,732,780,391 | 1,672,962,627,000 | 1,673,459,398,000 | 373,307,283 | 0 | 0 | Apache-2.0 | 1,691,316,730,000 | 1,622,669,271,000 | Lean | UTF-8 | Lean | false | false | 14,539 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Open
import Lean.Elab.SetOption
import Lean.Elab.Eval
namespace Lean.Elab.Term
open Meta
@[builtin_term_elab «prop»] def elabProp : TermElab := fun _ _ =>
return mkSort levelZero
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
if stx.isNone then
pure levelZero
else
elabLevel stx[0]
@[builtin_term_elab «sort»] def elabSort : TermElab := fun stx _ =>
return mkSort (← elabOptLevel stx[1])
@[builtin_term_elab «type»] def elabTypeStx : TermElab := fun stx _ =>
return mkSort (mkLevelSucc (← elabOptLevel stx[1]))
/-!
the method `resolveName` adds a completion point for it using the given
expected type. Thus, we propagate the expected type if `stx[0]` is an identifier.
It doesn't "hurt" if the identifier can be resolved because the expected type is not used in this case.
Recall that if the name resolution fails a synthetic sorry is returned.-/
@[builtin_term_elab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[0] none
unless e.isSorry do
addDotCompletionInfo stx e expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
@[builtin_term_elab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
/- `ident.` is ambiguous in Lean, we may try to be completing a declaration name or access a "field". -/
if stx[0].isIdent then
/- If we can elaborate the identifier successfully, we assume it is a dot-completion. Otherwise, we treat it as
identifier completion with a dangling `.`.
Recall that the server falls back to identifier completion when dot-completion fails. -/
let s ← saveState
try
let e ← elabTerm stx[0] none
addDotCompletionInfo stx e expectedType?
catch _ =>
s.restore
addCompletionInfo <| CompletionInfo.id stx stx[0].getId (danglingDot := true) (← getLCtx) expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
else
elabPipeCompletion stx expectedType?
@[builtin_term_elab «hole»] def elabHole : TermElab := fun stx expectedType? => do
let kind := if (← read).inPattern || !(← read).holesAsSyntheticOpaque then MetavarKind.natural else MetavarKind.syntheticOpaque
let mvar ← mkFreshExprMVar expectedType? kind
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
@[builtin_term_elab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
let arg := stx[1]
let userName := if arg.isIdent then arg.getId else Name.anonymous
let mkNewHole : Unit → TermElabM Expr := fun _ => do
let kind := if (← read).inPattern then MetavarKind.natural else MetavarKind.syntheticOpaque
let mvar ← mkFreshExprMVar expectedType? kind userName
registerMVarErrorHoleInfo mvar.mvarId! stx
return mvar
if userName.isAnonymous || (← read).inPattern then
mkNewHole ()
else
match (← getMCtx).findUserName? userName with
| none => mkNewHole ()
| some mvarId =>
let mvar := mkMVar mvarId
let mvarDecl ← getMVarDecl mvarId
let lctx ← getLCtx
if mvarDecl.lctx.isSubPrefixOf lctx then
return mvar
else match (← getExprMVarAssignment? mvarId) with
| some val =>
let val ← instantiateMVars val
if (← MetavarContext.isWellFormed lctx val) then
return val
else
withLCtx mvarDecl.lctx mvarDecl.localInstances do
throwError "synthetic hole has already been defined and assigned to value incompatible with the current context{indentExpr val}"
| none =>
if (← mvarId.isDelayedAssigned) then
-- We can try to improve this case if needed.
throwError "synthetic hole has already beend defined and delayed assigned with an incompatible local context"
else if lctx.isSubPrefixOf mvarDecl.lctx then
let mvarNew ← mkNewHole ()
mvarId.assign mvarNew
return mvarNew
else
throwError "synthetic hole has already been defined with an incompatible local context"
@[builtin_term_elab «letMVar»] def elabLetMVar : TermElab := fun stx expectedType? => do
match stx with
| `(let_mvar% ? $n := $e; $b) =>
match (← getMCtx).findUserName? n.getId with
| some _ => throwError "invalid 'let_mvar%', metavariable '?{n.getId}' has already been used"
| none =>
let e ← elabTerm e none
let mvar ← mkFreshExprMVar (← inferType e) MetavarKind.syntheticOpaque n.getId
mvar.mvarId!.assign e
-- We use `mkSaveInfoAnnotation` to make sure the info trees for `e` are saved even if `b` is a metavariable.
return mkSaveInfoAnnotation (← elabTerm b expectedType?)
| _ => throwUnsupportedSyntax
private def getMVarFromUserName (ident : Syntax) : MetaM Expr := do
match (← getMCtx).findUserName? ident.getId with
| none => throwError "unknown metavariable '?{ident.getId}'"
| some mvarId => instantiateMVars (mkMVar mvarId)
@[builtin_term_elab «waitIfTypeMVar»] def elabWaitIfTypeMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_mvar% ? $n; $b) =>
tryPostponeIfMVar (← inferType (← getMVarFromUserName n))
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtin_term_elab «waitIfTypeContainsMVar»] def elabWaitIfTypeContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_contains_mvar% ? $n; $b) =>
if (← instantiateMVars (← inferType (← getMVarFromUserName n))).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtin_term_elab «waitIfContainsMVar»] def elabWaitIfContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_contains_mvar% ? $n; $b) =>
if (← getMVarFromUserName n).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr := do
let mvar ← mkFreshExprMVar type MetavarKind.syntheticOpaque
let mvarId := mvar.mvarId!
let ref ← getRef
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
return mvar
@[builtin_term_elab byTactic] def elabByTactic : TermElab := fun stx expectedType? => do
match expectedType? with
| some expectedType => mkTacticMVar expectedType stx
| none =>
tryPostpone
throwError ("invalid 'by' tactic, expected type has not been provided")
@[builtin_term_elab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
@[builtin_term_elab cdot] def elabBadCDot : TermElab := fun _ _ =>
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
@[builtin_term_elab str] def elabStrLit : TermElab := fun stx _ => do
match stx.isStrLit? with
| some val => pure $ mkStrLit val
| none => throwIllFormedSyntax
private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr := do
let typeMVar ← mkFreshTypeMVar MetavarKind.synthetic
match expectedType? with
| some expectedType => discard <| isDefEq expectedType typeMVar
| _ => pure ()
return typeMVar
@[builtin_term_elab num] def elabNumLit : TermElab := fun stx expectedType? => do
let val ← match stx.isNatLit? with
| some val => pure val
| none => throwIllFormedSyntax
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp2 (Lean.mkConst ``OfNat [u]) typeMVar (mkRawNatLit val))
let r := mkApp3 (Lean.mkConst ``OfNat.ofNat [u]) typeMVar (mkRawNatLit val) mvar
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtin_term_elab rawNatLit] def elabRawNatLit : TermElab := fun stx _ => do
match stx[1].isNatLit? with
| some val => return mkRawNatLit val
| none => throwIllFormedSyntax
@[builtin_term_elab scientific]
def elabScientificLit : TermElab := fun stx expectedType? => do
match stx.isScientificLit? with
| none => throwIllFormedSyntax
| some (m, sign, e) =>
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp (Lean.mkConst ``OfScientific [u]) typeMVar)
let r := mkApp5 (Lean.mkConst ``OfScientific.ofScientific [u]) typeMVar mvar (mkRawNatLit m) (toExpr sign) (mkRawNatLit e)
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtin_term_elab char] def elabCharLit : TermElab := fun stx _ => do
match stx.isCharLit? with
| some val => return mkApp (Lean.mkConst ``Char.ofNat) (mkRawNatLit val.toNat)
| none => throwIllFormedSyntax
@[builtin_term_elab quotedName] def elabQuotedName : TermElab := fun stx _ =>
match stx[0].isNameLit? with
| some val => pure $ toExpr val
| none => throwIllFormedSyntax
@[builtin_term_elab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ =>
return toExpr (← resolveGlobalConstNoOverloadWithInfo stx[2])
@[builtin_term_elab declName] def elabDeclName : TermElab := adaptExpander fun _ => do
let some declName ← getDeclName?
| throwError "invalid `decl_name%` macro, the declaration name is not available"
return (quote declName : Term)
@[builtin_term_elab Parser.Term.withDeclName] def elabWithDeclName : TermElab := fun stx expectedType? => do
let id := stx[2].getId
let id := if stx[1].isNone then id else (← getCurrNamespace) ++ id
let e := stx[3]
withMacroExpansion stx e <| withDeclName id <| elabTerm e expectedType?
@[builtin_term_elab typeOf] def elabTypeOf : TermElab := fun stx _ => do
inferType (← elabTerm stx[1] none)
/--
Recall that `mkTermInfo` does not create an `ofTermInfo` node in the info tree
if `e` corresponds to a hole that is going to be filled "later" by executing a tactic or resuming elaboration.
This behavior is problematic for auxiliary elaboration steps that are "almost" no-ops.
For example, consider the elaborator for
```
ensure_type_of% s msg e
```
It elaborates `s`, infers its type `t`, and then elaborates `e` ensuring the resulting type is `t`.
If the elaboration of `e` is postponed, then the result is just a metavariable, and an `ofTermInfo` would not be created.
This happens because `ensure_type_of%` is almost a no-op. The elaboration of `s` does not directly contribute to the
final result, just its type.
To make sure, we don't miss any information in the `InfoTree`, we can just create a "silent" annotation to force
`mTermInfo` to create a node for the `ensure_type_of% s msg e` even if `e` has been postponed.
Another possible solution is to elaborate `ensure_type_of% s msg e` as `ensureType s e` where `ensureType` has type
```
ensureType (s e : α) := e
```
We decided to use the silent notation because `ensure_type_of%` is heavily used in the `Do` elaborator, and the extra
overhead could be significant.
-/
private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
if (← isTacticOrPostponedHole? e).isSome then
return mkAnnotation `_silent e
else
return e
@[builtin_term_elab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx _ =>
match stx[2].isStrLit? with
| none => throwIllFormedSyntax
| some msg => do
let refTerm ← elabTerm stx[1] none
let refTermType ← inferType refTerm
-- See comment at `mkSilentAnnotationIfHole`
mkSilentAnnotationIfHole (← elabTermEnsuringType stx[3] refTermType (errorMsgHeader? := msg))
@[builtin_term_elab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => elabTermEnsuringType stx[2] expectedType? (errorMsgHeader? := msg)
@[builtin_term_elab clear] def elabClear : TermElab := fun stx expectedType? => do
let some (.fvar fvarId) ← isLocalIdent? stx[1]
| throwErrorAt stx[1] "not in scope"
let body := stx[3]
let canClear ← id do
if let some expectedType := expectedType? then
if ← dependsOn expectedType fvarId then
return false
for ldecl in ← getLCtx do
if ldecl.fvarId != fvarId then
if ← localDeclDependsOn ldecl fvarId then
return false
return true
if canClear then
let lctx := (← getLCtx).erase fvarId
let localInsts := (← getLocalInstances).filter (·.fvar.fvarId! != fvarId)
withLCtx lctx localInsts do elabTerm body expectedType?
else
elabTerm body expectedType?
@[builtin_term_elab «open»] def elabOpen : TermElab := fun stx expectedType? => do
let `(open $decl in $e) := stx | throwUnsupportedSyntax
try
pushScope
let openDecls ← elabOpenDecl decl
withTheReader Core.Context (fun ctx => { ctx with openDecls := openDecls }) do
elabTerm e expectedType?
finally
popScope
@[builtin_term_elab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
let options ← Elab.elabSetOption stx[1] stx[2]
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
elabTerm stx[4] expectedType?
@[builtin_term_elab withAnnotateTerm] def elabWithAnnotateTerm : TermElab := fun stx expectedType? => do
match stx with
| `(with_annotate_term $stx $e) =>
withInfoContext' stx (elabTerm e expectedType?) (mkTermInfo .anonymous (expectedType? := expectedType?) stx)
| _ => throwUnsupportedSyntax
private unsafe def evalFilePathUnsafe (stx : Syntax) : TermElabM System.FilePath :=
evalTerm System.FilePath (Lean.mkConst ``System.FilePath) stx
@[implemented_by evalFilePathUnsafe]
private opaque evalFilePath (stx : Syntax) : TermElabM System.FilePath
@[builtin_term_elab includeStr] def elabIncludeStr : TermElab
| `(include_str $path:term), _ => do
let path ← evalFilePath path
let ctx ← readThe Lean.Core.Context
let srcPath := System.FilePath.mk ctx.fileName
let some srcDir := srcPath.parent
| throwError "cannot compute parent directory of '{srcPath}'"
let path := srcDir / path
mkStrLit <$> IO.FS.readFile path
| _, _ => throwUnsupportedSyntax
end Lean.Elab.Term
|
8e00f02b76c608559333423fd0f930e005add9a1 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/topology/opens.lean | 75219abc35b106e8e3fa26a91b2286a111691271 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 6,358 | 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
Subtype of open subsets in a topological space.
-/
import topology.bases topology.subset_properties topology.constructions
open filter lattice
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
namespace topological_space
variable (α)
/-- The type of open subsets of a topological space. -/
def opens := {s : set α // _root_.is_open s}
/-- The type of closed subsets of a topological space. -/
def closeds := {s : set α // is_closed s}
/-- The type of non-empty compact subsets of a topological space. The
non-emptiness will be useful in metric spaces, as we will be able to put
a distance (and not merely an edistance) on this space. -/
def nonempty_compacts := {s : set α // s ≠ ∅ ∧ compact s}
section nonempty_compacts
open topological_space set
variable {α}
instance nonempty_compacts.to_compact_space {p : nonempty_compacts α} : compact_space p.val :=
⟨compact_iff_compact_univ.1 p.property.2⟩
instance nonempty_compacts.to_nonempty {p : nonempty_compacts α} : nonempty p.val :=
nonempty_subtype.2 $ ne_empty_iff_exists_mem.1 p.property.1
/-- Associate to a nonempty compact subset the corresponding closed subset -/
def nonempty_compacts.to_closeds [t2_space α] (s : nonempty_compacts α) : closeds α :=
⟨s.val, closed_of_compact _ s.property.2⟩
end nonempty_compacts
variable {α}
namespace opens
instance : has_coe (opens α) (set α) := { coe := subtype.val }
instance : has_subset (opens α) :=
{ subset := λ U V, U.val ⊆ V.val }
instance : has_mem α (opens α) :=
{ mem := λ a U, a ∈ U.val }
@[extensionality] lemma ext {U V : opens α} (h : U.val = V.val) : U = V := subtype.ext.mpr h
instance : partial_order (opens α) := subtype.partial_order _
def interior (s : set α) : opens α := ⟨interior s, is_open_interior⟩
def gc : galois_connection (subtype.val : opens α → set α) interior :=
λ U s, ⟨λ h, interior_maximal h U.property, λ h, le_trans h interior_subset⟩
def gi : @galois_insertion (order_dual (set α)) (order_dual (opens α)) _ _ interior (subtype.val) :=
{ choice := λ s hs, ⟨s, interior_eq_iff_open.mp $ le_antisymm interior_subset hs⟩,
gc := gc.dual,
le_l_u := λ _, interior_subset,
choice_eq := λ s hs, le_antisymm interior_subset hs }
@[simp] lemma gi_choice_val {s : order_dual (set α)} {hs} : (gi.choice s hs).val = s := rfl
instance : complete_lattice (opens α) :=
complete_lattice.copy
(@order_dual.lattice.complete_lattice _
(@galois_insertion.lift_complete_lattice
(order_dual (set α)) (order_dual (opens α)) _ interior (subtype.val : opens α → set α) _ gi))
/- le -/ (λ U V, U.1 ⊆ V.1) rfl
/- top -/ ⟨set.univ, _root_.is_open_univ⟩ (subtype.ext.mpr interior_univ.symm)
/- bot -/ ⟨∅, is_open_empty⟩ rfl
/- sup -/ (λ U V, ⟨U.1 ∪ V.1, _root_.is_open_union U.2 V.2⟩) rfl
/- inf -/ (λ U V, ⟨U.1 ∩ V.1, _root_.is_open_inter U.2 V.2⟩)
begin
funext,
apply subtype.ext.mpr,
symmetry,
apply interior_eq_of_open,
exact (_root_.is_open_inter U.2 V.2),
end
/- Sup -/ (λ Us, ⟨⋃₀ (subtype.val '' Us), _root_.is_open_sUnion $ λ U hU,
by { rcases hU with ⟨⟨V, hV⟩, h, h'⟩, dsimp at h', subst h', exact hV}⟩)
begin
funext,
apply subtype.ext.mpr,
simp [Sup_range],
refl,
end
/- Inf -/ _ rfl
instance : has_inter (opens α) := ⟨λ U V, U ⊓ V⟩
instance : has_union (opens α) := ⟨λ U V, U ⊔ V⟩
instance : has_emptyc (opens α) := ⟨⊥⟩
@[simp] lemma inter_eq (U V : opens α) : U ∩ V = U ⊓ V := rfl
@[simp] lemma union_eq (U V : opens α) : U ∪ V = U ⊔ V := rfl
@[simp] lemma empty_eq : (∅ : opens α) = ⊥ := rfl
@[simp] lemma Sup_s {Us : set (opens α)} : (Sup Us).val = ⋃₀ (subtype.val '' Us) :=
begin
rw [@galois_connection.l_Sup (opens α) (set α) _ _ (subtype.val : opens α → set α) interior gc Us, set.sUnion_image],
congr
end
def is_basis (B : set (opens α)) : Prop := is_topological_basis (subtype.val '' B)
lemma is_basis_iff_nbhd {B : set (opens α)} :
is_basis B ↔ ∀ {U : opens α} {x}, x ∈ U → ∃ U' ∈ B, x ∈ U' ∧ U' ⊆ U :=
begin
split; intro h,
{ rintros ⟨sU, hU⟩ x hx,
rcases (mem_nhds_of_is_topological_basis h).mp (mem_nhds_sets hU hx) with ⟨sV, ⟨⟨V, H₁, H₂⟩, hsV⟩⟩,
refine ⟨V, H₁, _⟩,
cases V, dsimp at H₂, subst H₂, exact hsV },
{ refine is_topological_basis_of_open_of_nhds _ _,
{ rintros sU ⟨U, ⟨H₁, H₂⟩⟩, subst H₂, exact U.property },
{ intros x sU hx hsU,
rcases @h (⟨sU, hsU⟩ : opens α) x hx with ⟨V, hV, H⟩,
exact ⟨V, ⟨V, hV, rfl⟩, H⟩ } }
end
lemma is_basis_iff_cover {B : set (opens α)} :
is_basis B ↔ ∀ U : opens α, ∃ Us ⊆ B, U = Sup Us :=
begin
split,
{ intros hB U,
rcases sUnion_basis_of_is_open hB U.property with ⟨sUs, H, hU⟩,
existsi {U : opens α | U ∈ B ∧ U.val ∈ sUs},
split,
{ intros U hU, exact hU.left },
{ apply ext,
rw [Sup_s, hU],
congr,
ext s; split; intro hs,
{ rcases H hs with ⟨V, hV⟩,
rw ← hV.right at hs,
refine ⟨V, ⟨⟨hV.left, hs⟩, hV.right⟩⟩ },
{ rcases hs with ⟨V, ⟨⟨H₁, H₂⟩, H₃⟩⟩,
subst H₃, exact H₂ } } },
{ intro h,
rw is_basis_iff_nbhd,
intros U x hx,
rcases h U with ⟨Us, hUs, H⟩,
replace H := congr_arg subtype.val H,
rw Sup_s at H,
change x ∈ U.val at hx,
rw H at hx,
rcases set.mem_sUnion.mp hx with ⟨sV, ⟨⟨V, H₁, H₂⟩, hsV⟩⟩,
refine ⟨V,hUs H₁,_⟩,
cases V with V hV,
dsimp at H₂, subst H₂,
refine ⟨hsV,_⟩,
change V ⊆ U.val, rw H,
exact set.subset_sUnion_of_mem ⟨⟨V, _⟩, ⟨H₁, rfl⟩⟩ }
end
end opens
end topological_space
namespace continuous
open topological_space
def comap {f : α → β} (hf : continuous f) (V : opens β) : opens α :=
⟨f ⁻¹' V.1, hf V.1 V.2⟩
@[simp] lemma comap_id (U : opens α) : (continuous_id).comap U = U := by { ext, refl }
lemma comap_mono {f : α → β} (hf : continuous f) {V W : opens β} (hVW : V ⊆ W) :
hf.comap V ⊆ hf.comap W :=
λ _ h, hVW h
end continuous
|
64306ece22322b4b534a13356e53e455aff392d1 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/field_theory/abel_ruffini.lean | e36d7378ab3d76f8270f0c4d91e1b7d1adcd447e | [
"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 | 16,435 | lean | /-
Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import group_theory.solvable
import field_theory.polynomial_galois_group
import ring_theory.roots_of_unity
/-!
# The Abel-Ruffini Theorem
This file proves one direction of the Abel-Ruffini theorem, namely that if an element is solvable
by radicals, then its minimal polynomial has solvable Galois group.
## Main definitions
* `SBF F E` : the intermediate field of solvable-by-radicals elements
## Main results
* `solvable_gal_of_solvable_by_rad` : the minimal polynomial of an element of `SBF F E` has
solvable Galois group
-/
noncomputable theory
open_locale classical
open polynomial intermediate_field
section abel_ruffini
variables {F : Type*} [field F] {E : Type*} [field E] [algebra F E]
lemma gal_zero_is_solvable : is_solvable (0 : polynomial F).gal :=
by apply_instance
lemma gal_one_is_solvable : is_solvable (1 : polynomial F).gal :=
by apply_instance
lemma gal_C_is_solvable (x : F) : is_solvable (C x).gal :=
by apply_instance
lemma gal_X_is_solvable : is_solvable (X : polynomial F).gal :=
by apply_instance
lemma gal_X_sub_C_is_solvable (x : F) : is_solvable (X - C x).gal :=
by apply_instance
lemma gal_X_pow_is_solvable (n : ℕ) : is_solvable (X ^ n : polynomial F).gal :=
by apply_instance
lemma gal_mul_is_solvable {p q : polynomial F}
(hp : is_solvable p.gal) (hq : is_solvable q.gal) : is_solvable (p * q).gal :=
solvable_of_solvable_injective (gal.restrict_prod_injective p q)
lemma gal_prod_is_solvable {s : multiset (polynomial F)}
(hs : ∀ p ∈ s, is_solvable (gal p)) : is_solvable s.prod.gal :=
begin
apply multiset.induction_on' s,
{ exact gal_one_is_solvable },
{ intros p t hps hts ht,
rw [multiset.insert_eq_cons, multiset.prod_cons],
exact gal_mul_is_solvable (hs p hps) ht },
end
lemma gal_is_solvable_of_splits {p q : polynomial F}
(hpq : fact (p.splits (algebra_map F q.splitting_field))) (hq : is_solvable q.gal) :
is_solvable p.gal :=
begin
haveI : is_solvable (q.splitting_field ≃ₐ[F] q.splitting_field) := hq,
exact solvable_of_surjective (alg_equiv.restrict_normal_hom_surjective q.splitting_field),
end
lemma gal_is_solvable_tower (p q : polynomial F)
(hpq : p.splits (algebra_map F q.splitting_field))
(hp : is_solvable p.gal)
(hq : is_solvable (q.map (algebra_map F p.splitting_field)).gal) :
is_solvable q.gal :=
begin
let K := p.splitting_field,
let L := q.splitting_field,
haveI : fact (p.splits (algebra_map F L)) := ⟨hpq⟩,
let ϕ : (L ≃ₐ[K] L) ≃* (q.map (algebra_map F K)).gal :=
(is_splitting_field.alg_equiv L (q.map (algebra_map F K))).aut_congr,
have ϕ_inj : function.injective ϕ.to_monoid_hom := ϕ.injective,
haveI : is_solvable (K ≃ₐ[F] K) := hp,
haveI : is_solvable (L ≃ₐ[K] L) := solvable_of_solvable_injective ϕ_inj,
exact is_solvable_of_is_scalar_tower F p.splitting_field q.splitting_field,
end
section gal_X_pow_sub_C
lemma gal_X_pow_sub_one_is_solvable (n : ℕ) : is_solvable (X ^ n - 1 : polynomial F).gal :=
begin
by_cases hn : n = 0,
{ rw [hn, pow_zero, sub_self],
exact gal_zero_is_solvable },
have hn' : 0 < n := pos_iff_ne_zero.mpr hn,
have hn'' : (X ^ n - 1 : polynomial F) ≠ 0 :=
λ h, one_ne_zero ((leading_coeff_X_pow_sub_one hn').symm.trans (congr_arg leading_coeff h)),
apply is_solvable_of_comm,
intros σ τ,
ext a ha,
rw [mem_root_set hn'', alg_hom.map_sub, aeval_X_pow, aeval_one, sub_eq_zero] at ha,
have key : ∀ σ : (X ^ n - 1 : polynomial F).gal, ∃ m : ℕ, σ a = a ^ m,
{ intro σ,
obtain ⟨m, hm⟩ := σ.to_alg_hom.to_ring_hom.map_root_of_unity_eq_pow_self
⟨is_unit.unit (is_unit_of_pow_eq_one a n ha hn'),
by { ext, rwa [units.coe_pow, is_unit.unit_spec, subtype.coe_mk n hn'] }⟩,
use m,
convert hm,
all_goals { exact (is_unit.unit_spec _).symm } },
obtain ⟨c, hc⟩ := key σ,
obtain ⟨d, hd⟩ := key τ,
rw [σ.mul_apply, τ.mul_apply, hc, τ.map_pow, hd, σ.map_pow, hc, ←pow_mul, pow_mul'],
end
lemma gal_X_pow_sub_C_is_solvable_aux (n : ℕ) (a : F)
(h : (X ^ n - 1 : polynomial F).splits (ring_hom.id F)) : is_solvable (X ^ n - C a).gal :=
begin
by_cases ha : a = 0,
{ rw [ha, C_0, sub_zero],
exact gal_X_pow_is_solvable n },
have ha' : algebra_map F (X ^ n - C a).splitting_field a ≠ 0 :=
mt ((ring_hom.injective_iff _).mp (ring_hom.injective _) a) ha,
by_cases hn : n = 0,
{ rw [hn, pow_zero, ←C_1, ←C_sub],
exact gal_C_is_solvable (1 - a) },
have hn' : 0 < n := pos_iff_ne_zero.mpr hn,
have hn'' : X ^ n - C a ≠ 0 :=
λ h, one_ne_zero ((leading_coeff_X_pow_sub_C hn').symm.trans (congr_arg leading_coeff h)),
have hn''' : (X ^ n - 1 : polynomial F) ≠ 0 :=
λ h, one_ne_zero ((leading_coeff_X_pow_sub_one hn').symm.trans (congr_arg leading_coeff h)),
have mem_range : ∀ {c}, c ^ n = 1 → ∃ d, algebra_map F (X ^ n - C a).splitting_field d = c :=
λ c hc, ring_hom.mem_range.mp (minpoly.mem_range_of_degree_eq_one F c (or.resolve_left h hn'''
(minpoly.irreducible ((splitting_field.normal (X ^ n - C a)).is_integral c)) (minpoly.dvd F c
(by rwa [map_id, alg_hom.map_sub, sub_eq_zero, aeval_X_pow, aeval_one])))),
apply is_solvable_of_comm,
intros σ τ,
ext b hb,
rw [mem_root_set hn'', alg_hom.map_sub, aeval_X_pow, aeval_C, sub_eq_zero] at hb,
have hb' : b ≠ 0,
{ intro hb',
rw [hb', zero_pow hn'] at hb,
exact ha' hb.symm },
have key : ∀ σ : (X ^ n - C a).gal, ∃ c, σ b = b * algebra_map F _ c,
{ intro σ,
have key : (σ b / b) ^ n = 1 := by rw [div_pow, ←σ.map_pow, hb, σ.commutes, div_self ha'],
obtain ⟨c, hc⟩ := mem_range key,
use c,
rw [hc, mul_div_cancel' (σ b) hb'] },
obtain ⟨c, hc⟩ := key σ,
obtain ⟨d, hd⟩ := key τ,
rw [σ.mul_apply, τ.mul_apply, hc, τ.map_mul, τ.commutes, hd, σ.map_mul, σ.commutes, hc],
rw [mul_assoc, mul_assoc, mul_right_inj' hb', mul_comm],
end
lemma splits_X_pow_sub_one_of_X_pow_sub_C {F : Type*} [field F] {E : Type*} [field E]
(i : F →+* E) (n : ℕ) {a : F} (ha : a ≠ 0) (h : (X ^ n - C a).splits i) : (X ^ n - 1).splits i :=
begin
have ha' : i a ≠ 0 := mt (i.injective_iff.mp (i.injective) a) ha,
by_cases hn : n = 0,
{ rw [hn, pow_zero, sub_self],
exact splits_zero i },
have hn' : 0 < n := pos_iff_ne_zero.mpr hn,
have hn'' : (X ^ n - C a).degree ≠ 0 :=
ne_of_eq_of_ne (degree_X_pow_sub_C hn' a) (mt with_bot.coe_eq_coe.mp hn),
obtain ⟨b, hb⟩ := exists_root_of_splits i h hn'',
rw [eval₂_sub, eval₂_X_pow, eval₂_C, sub_eq_zero] at hb,
have hb' : b ≠ 0,
{ intro hb',
rw [hb', zero_pow hn'] at hb,
exact ha' hb.symm },
let s := ((X ^ n - C a).map i).roots,
have hs : _ = _ * (s.map _).prod := eq_prod_roots_of_splits h,
rw [leading_coeff_X_pow_sub_C hn', ring_hom.map_one, C_1, one_mul] at hs,
have hs' : s.card = n := (nat_degree_eq_card_roots h).symm.trans nat_degree_X_pow_sub_C,
apply @splits_of_exists_multiset F E _ _ i (X ^ n - 1) (s.map (λ c : E, c / b)),
rw [leading_coeff_X_pow_sub_one hn', ring_hom.map_one, C_1, one_mul, multiset.map_map],
have C_mul_C : (C (i a⁻¹)) * (C (i a)) = 1,
{ rw [←C_mul, ←i.map_mul, inv_mul_cancel ha, i.map_one, C_1] },
have key1 : (X ^ n - 1).map i = C (i a⁻¹) * ((X ^ n - C a).map i).comp (C b * X),
{ rw [map_sub, map_sub, map_pow, map_X, map_C, map_one, sub_comp, pow_comp, X_comp, C_comp,
mul_pow, ←C_pow, hb, mul_sub, ←mul_assoc, C_mul_C, one_mul] },
have key2 : (λ q : polynomial E, q.comp (C b * X)) ∘ (λ c : E, X - C c) =
(λ c : E, C b * (X - C (c / b))),
{ ext1 c,
change (X - C c).comp (C b * X) = C b * (X - C (c / b)),
rw [sub_comp, X_comp, C_comp, mul_sub, ←C_mul, mul_div_cancel' c hb'] },
rw [key1, hs, prod_comp, multiset.map_map, key2, multiset.prod_map_mul, multiset.map_const,
multiset.prod_repeat, hs', ←C_pow, hb, ←mul_assoc, C_mul_C, one_mul],
all_goals { exact field.to_nontrivial F },
end
lemma gal_X_pow_sub_C_is_solvable (n : ℕ) (x : F) : is_solvable (X ^ n - C x).gal :=
begin
by_cases hx : x = 0,
{ rw [hx, C_0, sub_zero],
exact gal_X_pow_is_solvable n },
apply gal_is_solvable_tower (X ^ n - 1) (X ^ n - C x),
{ exact splits_X_pow_sub_one_of_X_pow_sub_C _ n hx (splitting_field.splits _) },
{ exact gal_X_pow_sub_one_is_solvable n },
{ rw [map_sub, map_pow, map_X, map_C],
apply gal_X_pow_sub_C_is_solvable_aux,
have key := splitting_field.splits (X ^ n - 1 : polynomial F),
rwa [←splits_id_iff_splits, map_sub, map_pow, map_X, map_one] at key },
end
end gal_X_pow_sub_C
variables (F)
/-- Inductive definition of solvable by radicals -/
inductive is_solvable_by_rad : E → Prop
| base (a : F) : is_solvable_by_rad (algebra_map F E a)
| add (a b : E) : is_solvable_by_rad a → is_solvable_by_rad b → is_solvable_by_rad (a + b)
| neg (α : E) : is_solvable_by_rad α → is_solvable_by_rad (-α)
| mul (α β : E) : is_solvable_by_rad α → is_solvable_by_rad β → is_solvable_by_rad (α * β)
| inv (α : E) : is_solvable_by_rad α → is_solvable_by_rad α⁻¹
| rad (α : E) (n : ℕ) (hn : n ≠ 0) : is_solvable_by_rad (α^n) → is_solvable_by_rad α
variables (E)
/-- The intermediate field of solvable-by-radicals elements -/
def solvable_by_rad : intermediate_field F E :=
{ carrier := is_solvable_by_rad F,
zero_mem' := by { convert is_solvable_by_rad.base (0 : F), rw ring_hom.map_zero },
add_mem' := is_solvable_by_rad.add,
neg_mem' := is_solvable_by_rad.neg,
one_mem' := by { convert is_solvable_by_rad.base (1 : F), rw ring_hom.map_one },
mul_mem' := is_solvable_by_rad.mul,
inv_mem' := is_solvable_by_rad.inv,
algebra_map_mem' := is_solvable_by_rad.base }
namespace solvable_by_rad
variables {F} {E} {α : E}
lemma induction (P : solvable_by_rad F E → Prop)
(base : ∀ α : F, P (algebra_map F (solvable_by_rad F E) α))
(add : ∀ α β : solvable_by_rad F E, P α → P β → P (α + β))
(neg : ∀ α : solvable_by_rad F E, P α → P (-α))
(mul : ∀ α β : solvable_by_rad F E, P α → P β → P (α * β))
(inv : ∀ α : solvable_by_rad F E, P α → P α⁻¹)
(rad : ∀ α : solvable_by_rad F E, ∀ n : ℕ, n ≠ 0 → P (α^n) → P α)
(α : solvable_by_rad F E) : P α :=
begin
revert α,
suffices : ∀ (α : E), is_solvable_by_rad F α → (∃ β : solvable_by_rad F E, ↑β = α ∧ P β),
{ intro α,
obtain ⟨α₀, hα₀, Pα⟩ := this α (subtype.mem α),
convert Pα,
exact subtype.ext hα₀.symm },
apply is_solvable_by_rad.rec,
{ exact λ α, ⟨algebra_map F (solvable_by_rad F E) α, rfl, base α⟩ },
{ intros α β hα hβ Pα Pβ,
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := ⟨Pα, Pβ⟩,
exact ⟨α₀ + β₀, by {rw [←hα₀, ←hβ₀], refl }, add α₀ β₀ Pα Pβ⟩ },
{ intros α hα Pα,
obtain ⟨α₀, hα₀, Pα⟩ := Pα,
exact ⟨-α₀, by {rw ←hα₀, refl }, neg α₀ Pα⟩ },
{ intros α β hα hβ Pα Pβ,
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := ⟨Pα, Pβ⟩,
exact ⟨α₀ * β₀, by {rw [←hα₀, ←hβ₀], refl }, mul α₀ β₀ Pα Pβ⟩ },
{ intros α hα Pα,
obtain ⟨α₀, hα₀, Pα⟩ := Pα,
exact ⟨α₀⁻¹, by {rw ←hα₀, refl }, inv α₀ Pα⟩ },
{ intros α n hn hα Pα,
obtain ⟨α₀, hα₀, Pα⟩ := Pα,
refine ⟨⟨α, is_solvable_by_rad.rad α n hn hα⟩, rfl, rad _ n hn _⟩,
convert Pα,
exact subtype.ext (eq.trans ((solvable_by_rad F E).coe_pow _ n) hα₀.symm) }
end
theorem is_integral (α : solvable_by_rad F E) : is_integral F α :=
begin
revert α,
apply solvable_by_rad.induction,
{ exact λ _, is_integral_algebra_map },
{ exact λ _ _, is_integral_add },
{ exact λ _, is_integral_neg },
{ exact λ _ _, is_integral_mul },
{ exact λ α hα, subalgebra.inv_mem_of_algebraic (integral_closure F (solvable_by_rad F E))
(show is_algebraic F ↑(⟨α, hα⟩ : integral_closure F (solvable_by_rad F E)),
by exact (is_algebraic_iff_is_integral F).mpr hα) },
{ intros α n hn hα,
obtain ⟨p, h1, h2⟩ := (is_algebraic_iff_is_integral F).mpr hα,
refine (is_algebraic_iff_is_integral F).mp ⟨p.comp (X ^ n),
⟨λ h, h1 (leading_coeff_eq_zero.mp _), by rw [aeval_comp, aeval_X_pow, h2]⟩⟩,
rwa [←leading_coeff_eq_zero, leading_coeff_comp, leading_coeff_X_pow, one_pow, mul_one] at h,
rwa nat_degree_X_pow }
end
/-- The statement to be proved inductively -/
def P (α : solvable_by_rad F E) : Prop := is_solvable (minpoly F α).gal
/-- An auxiliary induction lemma, which is generalized by `solvable_by_rad.is_solvable`. -/
lemma induction3 {α : solvable_by_rad F E} {n : ℕ} (hn : n ≠ 0) (hα : P (α ^ n)) : P α :=
begin
let p := minpoly F (α ^ n),
have hp : p.comp (X ^ n) ≠ 0,
{ intro h,
cases (comp_eq_zero_iff.mp h) with h' h',
{ exact minpoly.ne_zero (is_integral (α ^ n)) h' },
{ exact hn (by rw [←nat_degree_C _, ←h'.2, nat_degree_X_pow]) } },
apply gal_is_solvable_of_splits,
{ exact ⟨splits_of_splits_of_dvd _ hp (splitting_field.splits (p.comp (X ^ n)))
(minpoly.dvd F α (by rw [aeval_comp, aeval_X_pow, minpoly.aeval]))⟩ },
{ refine gal_is_solvable_tower p (p.comp (X ^ n)) _ hα _,
{ exact gal.splits_in_splitting_field_of_comp _ _ (by rwa [nat_degree_X_pow]) },
{ obtain ⟨s, hs⟩ := exists_multiset_of_splits _ (splitting_field.splits p),
rw [map_comp, map_pow, map_X, hs, mul_comp, C_comp],
apply gal_mul_is_solvable (gal_C_is_solvable _),
rw prod_comp,
apply gal_prod_is_solvable,
intros q hq,
rw multiset.mem_map at hq,
obtain ⟨q, hq, rfl⟩ := hq,
rw multiset.mem_map at hq,
obtain ⟨q, hq, rfl⟩ := hq,
rw [sub_comp, X_comp, C_comp],
exact gal_X_pow_sub_C_is_solvable n q } },
end
/-- An auxiliary induction lemma, which is generalized by `solvable_by_rad.is_solvable`. -/
lemma induction2 {α β γ : solvable_by_rad F E} (hγ : γ ∈ F⟮α, β⟯) (hα : P α) (hβ : P β) : P γ :=
begin
let p := (minpoly F α),
let q := (minpoly F β),
have hpq := polynomial.splits_of_splits_mul _ (mul_ne_zero (minpoly.ne_zero (is_integral α))
(minpoly.ne_zero (is_integral β))) (splitting_field.splits (p * q)),
let f : F⟮α, β⟯ →ₐ[F] (p * q).splitting_field := classical.choice (alg_hom_mk_adjoin_splits
begin
intros x hx,
cases hx,
rw hx,
exact ⟨is_integral α, hpq.1⟩,
cases hx,
exact ⟨is_integral β, hpq.2⟩,
end),
have key : minpoly F γ = minpoly F (f ⟨γ, hγ⟩) := minpoly.unique'
(minpoly.irreducible (is_integral γ)) begin
suffices : aeval (⟨γ, hγ⟩ : F ⟮α, β⟯) (minpoly F γ) = 0,
{ rw [aeval_alg_hom_apply, this, alg_hom.map_zero] },
apply (algebra_map F⟮α, β⟯ (solvable_by_rad F E)).injective,
rw [ring_hom.map_zero, is_scalar_tower.algebra_map_aeval],
exact minpoly.aeval F γ,
end (minpoly.monic (is_integral γ)),
rw [P, key],
exact gal_is_solvable_of_splits ⟨normal.splits (splitting_field.normal _) _⟩
(gal_mul_is_solvable hα hβ),
end
/-- An auxiliary induction lemma, which is generalized by `solvable_by_rad.is_solvable`. -/
lemma induction1 {α β : solvable_by_rad F E} (hβ : β ∈ F⟮α⟯) (hα : P α) : P β :=
induction2 (adjoin.mono F _ _ (ge_of_eq (set.pair_eq_singleton α)) hβ) hα hα
theorem is_solvable (α : solvable_by_rad F E) :
is_solvable (minpoly F α).gal :=
begin
revert α,
apply solvable_by_rad.induction,
{ exact λ α, by { rw minpoly.eq_X_sub_C, exact gal_X_sub_C_is_solvable α } },
{ exact λ α β, induction2 (add_mem _ (subset_adjoin F _ (set.mem_insert α _))
(subset_adjoin F _ (set.mem_insert_of_mem α (set.mem_singleton β)))) },
{ exact λ α, induction1 (neg_mem _ (mem_adjoin_simple_self F α)) },
{ exact λ α β, induction2 (mul_mem _ (subset_adjoin F _ (set.mem_insert α _))
(subset_adjoin F _ (set.mem_insert_of_mem α (set.mem_singleton β)))) },
{ exact λ α, induction1 (inv_mem _ (mem_adjoin_simple_self F α)) },
{ exact λ α n, induction3 },
end
end solvable_by_rad
end abel_ruffini
|
2e0c0004dabf2fe5617613403a48f9a531e5efa4 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/complex/re_im_topology.lean | 5410395907c29062bbf72a35503353c4b5401910 | [
"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 | 7,729 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.complex.basic
import topology.fiber_bundle.is_homeomorphic_trivial_bundle
/-!
# Closure, interior, and frontier of preimages under `re` and `im`
In this fact we use the fact that `ℂ` is naturally homeomorphic to `ℝ × ℝ` to deduce some
topological properties of `complex.re` and `complex.im`.
## Main statements
Each statement about `complex.re` listed below has a counterpart about `complex.im`.
* `complex.is_homeomorphic_trivial_fiber_bundle_re`: `complex.re` turns `ℂ` into a trivial
topological fiber bundle over `ℝ`;
* `complex.is_open_map_re`, `complex.quotient_map_re`: in particular, `complex.re` is an open map
and is a quotient map;
* `complex.interior_preimage_re`, `complex.closure_preimage_re`, `complex.frontier_preimage_re`:
formulas for `interior (complex.re ⁻¹' s)` etc;
* `complex.interior_set_of_re_le` etc: particular cases of the above formulas in the cases when `s`
is one of the infinite intervals `set.Ioi a`, `set.Ici a`, `set.Iio a`, and `set.Iic a`,
formulated as `interior {z : ℂ | z.re ≤ a} = {z | z.re < a}` etc.
## Tags
complex, real part, imaginary part, closure, interior, frontier
-/
open set
noncomputable theory
namespace complex
/-- `complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
lemma is_homeomorphic_trivial_fiber_bundle_re : is_homeomorphic_trivial_fiber_bundle ℝ re :=
⟨equiv_real_prod_clm.to_homeomorph, λ z, rfl⟩
/-- `complex.im` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
lemma is_homeomorphic_trivial_fiber_bundle_im : is_homeomorphic_trivial_fiber_bundle ℝ im :=
⟨equiv_real_prod_clm.to_homeomorph.trans (homeomorph.prod_comm ℝ ℝ), λ z, rfl⟩
lemma is_open_map_re : is_open_map re := is_homeomorphic_trivial_fiber_bundle_re.is_open_map_proj
lemma is_open_map_im : is_open_map im := is_homeomorphic_trivial_fiber_bundle_im.is_open_map_proj
lemma quotient_map_re : quotient_map re := is_homeomorphic_trivial_fiber_bundle_re.quotient_map_proj
lemma quotient_map_im : quotient_map im := is_homeomorphic_trivial_fiber_bundle_im.quotient_map_proj
lemma interior_preimage_re (s : set ℝ) : interior (re ⁻¹' s) = re ⁻¹' (interior s) :=
(is_open_map_re.preimage_interior_eq_interior_preimage continuous_re _).symm
lemma interior_preimage_im (s : set ℝ) : interior (im ⁻¹' s) = im ⁻¹' (interior s) :=
(is_open_map_im.preimage_interior_eq_interior_preimage continuous_im _).symm
lemma closure_preimage_re (s : set ℝ) : closure (re ⁻¹' s) = re ⁻¹' (closure s) :=
(is_open_map_re.preimage_closure_eq_closure_preimage continuous_re _).symm
lemma closure_preimage_im (s : set ℝ) : closure (im ⁻¹' s) = im ⁻¹' (closure s) :=
(is_open_map_im.preimage_closure_eq_closure_preimage continuous_im _).symm
lemma frontier_preimage_re (s : set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' (frontier s) :=
(is_open_map_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm
lemma frontier_preimage_im (s : set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' (frontier s) :=
(is_open_map_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm
@[simp] lemma interior_set_of_re_le (a : ℝ) : interior {z : ℂ | z.re ≤ a} = {z | z.re < a} :=
by simpa only [interior_Iic] using interior_preimage_re (Iic a)
@[simp] lemma interior_set_of_im_le (a : ℝ) : interior {z : ℂ | z.im ≤ a} = {z | z.im < a} :=
by simpa only [interior_Iic] using interior_preimage_im (Iic a)
@[simp] lemma interior_set_of_le_re (a : ℝ) : interior {z : ℂ | a ≤ z.re} = {z | a < z.re} :=
by simpa only [interior_Ici] using interior_preimage_re (Ici a)
@[simp] lemma interior_set_of_le_im (a : ℝ) : interior {z : ℂ | a ≤ z.im} = {z | a < z.im} :=
by simpa only [interior_Ici] using interior_preimage_im (Ici a)
@[simp] lemma closure_set_of_re_lt (a : ℝ) : closure {z : ℂ | z.re < a} = {z | z.re ≤ a} :=
by simpa only [closure_Iio] using closure_preimage_re (Iio a)
@[simp] lemma closure_set_of_im_lt (a : ℝ) : closure {z : ℂ | z.im < a} = {z | z.im ≤ a} :=
by simpa only [closure_Iio] using closure_preimage_im (Iio a)
@[simp] lemma closure_set_of_lt_re (a : ℝ) : closure {z : ℂ | a < z.re} = {z | a ≤ z.re} :=
by simpa only [closure_Ioi] using closure_preimage_re (Ioi a)
@[simp] lemma closure_set_of_lt_im (a : ℝ) : closure {z : ℂ | a < z.im} = {z | a ≤ z.im} :=
by simpa only [closure_Ioi] using closure_preimage_im (Ioi a)
@[simp] lemma frontier_set_of_re_le (a : ℝ) : frontier {z : ℂ | z.re ≤ a} = {z | z.re = a} :=
by simpa only [frontier_Iic] using frontier_preimage_re (Iic a)
@[simp] lemma frontier_set_of_im_le (a : ℝ) : frontier {z : ℂ | z.im ≤ a} = {z | z.im = a} :=
by simpa only [frontier_Iic] using frontier_preimage_im (Iic a)
@[simp] lemma frontier_set_of_le_re (a : ℝ) : frontier {z : ℂ | a ≤ z.re} = {z | z.re = a} :=
by simpa only [frontier_Ici] using frontier_preimage_re (Ici a)
@[simp] lemma frontier_set_of_le_im (a : ℝ) : frontier {z : ℂ | a ≤ z.im} = {z | z.im = a} :=
by simpa only [frontier_Ici] using frontier_preimage_im (Ici a)
@[simp] lemma frontier_set_of_re_lt (a : ℝ) : frontier {z : ℂ | z.re < a} = {z | z.re = a} :=
by simpa only [frontier_Iio] using frontier_preimage_re (Iio a)
@[simp] lemma frontier_set_of_im_lt (a : ℝ) : frontier {z : ℂ | z.im < a} = {z | z.im = a} :=
by simpa only [frontier_Iio] using frontier_preimage_im (Iio a)
@[simp] lemma frontier_set_of_lt_re (a : ℝ) : frontier {z : ℂ | a < z.re} = {z | z.re = a} :=
by simpa only [frontier_Ioi] using frontier_preimage_re (Ioi a)
@[simp] lemma frontier_set_of_lt_im (a : ℝ) : frontier {z : ℂ | a < z.im} = {z | z.im = a} :=
by simpa only [frontier_Ioi] using frontier_preimage_im (Ioi a)
lemma closure_re_prod_im (s t : set ℝ) : closure (s ×ℂ t) = closure s ×ℂ closure t :=
by simpa only [← preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective,
equiv_real_prod_clm.symm.to_homeomorph.preimage_closure]
using @closure_prod_eq _ _ _ _ s t
lemma interior_re_prod_im (s t : set ℝ) : interior (s ×ℂ t) = interior s ×ℂ interior t :=
by rw [re_prod_im, re_prod_im, interior_inter, interior_preimage_re, interior_preimage_im]
lemma frontier_re_prod_im (s t : set ℝ) :
frontier (s ×ℂ t) = (closure s ×ℂ frontier t) ∪ (frontier s ×ℂ closure t) :=
by simpa only [← preimage_eq_preimage equiv_real_prod_clm.symm.to_homeomorph.surjective,
equiv_real_prod_clm.symm.to_homeomorph.preimage_frontier]
using frontier_prod_eq s t
lemma frontier_set_of_le_re_and_le_im (a b : ℝ) :
frontier {z | a ≤ re z ∧ b ≤ im z} = {z | a ≤ re z ∧ im z = b ∨ re z = a ∧ b ≤ im z} :=
by simpa only [closure_Ici, frontier_Ici] using frontier_re_prod_im (Ici a) (Ici b)
lemma frontier_set_of_le_re_and_im_le (a b : ℝ) :
frontier {z | a ≤ re z ∧ im z ≤ b} = {z | a ≤ re z ∧ im z = b ∨ re z = a ∧ im z ≤ b} :=
by simpa only [closure_Ici, closure_Iic, frontier_Ici, frontier_Iic]
using frontier_re_prod_im (Ici a) (Iic b)
end complex
open complex metric
variables {s t : set ℝ}
lemma is_open.re_prod_im (hs : is_open s) (ht : is_open t) : is_open (s ×ℂ t) :=
(hs.preimage continuous_re).inter (ht.preimage continuous_im)
lemma is_closed.re_prod_im (hs : is_closed s) (ht : is_closed t) : is_closed (s ×ℂ t) :=
(hs.preimage continuous_re).inter (ht.preimage continuous_im)
lemma metric.bounded.re_prod_im (hs : bounded s) (ht : bounded t) : bounded (s ×ℂ t) :=
antilipschitz_equiv_real_prod.bounded_preimage (hs.prod ht)
|
c7ad738d5a1a209be10f7c39efc599c0f31315c8 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/data/rat/default.lean | 1c022cc0186240ebf82860aa053f4d8b52479a6c | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 300 | lean | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import data.rat.basic
import data.rat.order
import data.rat.cast
import data.rat.floor
/-!
# Default Imports to Work With Rational Numbers
-/
|
9936b91e3312ce1864b6a11387e7bcbc14c4b41d | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/topology/basic.lean | 85fb347b865b6857403d69c5ea3882246fbb3044 | [
"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 | 60,801 | 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, Jeremy Avigad
-/
import order.filter.ultrafilter
import order.filter.partial
import algebra.support
/-!
# Basic theory of topological spaces.
The main definition is the type class `topological space α` which endows a type `α` with a topology.
Then `set α` gets predicates `is_open`, `is_closed` and functions `interior`, `closure` and
`frontier`. Each point `x` of `α` gets a neighborhood filter `𝓝 x`. A filter `F` on `α` has
`x` as a cluster point if `cluster_pt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : ι → α` clusters at `x`
along `F : filter ι` if `map_cluster_pt x F f : cluster_pt x (map f F)`. In particular
the notion of cluster point of a sequence `u` is `map_cluster_pt x at_top u`.
This file also defines locally finite families of subsets of `α`.
For topological spaces `α` and `β`, a function `f : α → β` and a point `a : α`,
`continuous_at f a` means `f` is continuous at `a`, and global continuity is
`continuous f`. There is also a version of continuity `pcontinuous` for
partially defined functions.
## Notation
* `𝓝 x`: the filter of neighborhoods of a point `x`;
* `𝓟 s`: the principal filter of a set `s`;
* `𝓝[s] x`: the filter `nhds_within x s` of neighborhoods of a point `x` within a set `s`.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space, interior, closure, frontier, neighborhood, continuity, continuous function
-/
noncomputable theory
open set filter classical
open_locale classical filter
universes u v w
/-!
### Topological spaces
-/
/-- A topology on `α`. -/
@[protect_proj] structure topological_space (α : Type u) :=
(is_open : set α → Prop)
(is_open_univ : is_open univ)
(is_open_inter : ∀s t, is_open s → is_open t → is_open (s ∩ t))
(is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s))
attribute [class] topological_space
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def topological_space.of_closed {α : Type u} (T : set (set α))
(empty_mem : ∅ ∈ T) (sInter_mem : ∀ A ⊆ T, ⋂₀ A ∈ T) (union_mem : ∀ A B ∈ T, A ∪ B ∈ T) :
topological_space α :=
{ is_open := λ X, Xᶜ ∈ T,
is_open_univ := by simp [empty_mem],
is_open_inter := λ s t hs ht, by simpa [set.compl_inter] using union_mem sᶜ tᶜ hs ht,
is_open_sUnion := λ s hs,
by rw set.compl_sUnion; exact sInter_mem (set.compl '' s)
(λ z ⟨y, hy, hz⟩, by simpa [hz.symm] using hs y hy) }
section topological_space
variables {α : Type u} {β : Type v} {ι : Sort w} {a : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}
@[ext]
lemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g
| ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl
section
variables [t : topological_space α]
include t
/-- `is_open s` means that `s` is open in the ambient topological space on `α` -/
def is_open (s : set α) : Prop := topological_space.is_open t s
@[simp]
lemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t
lemma is_open.inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) :=
topological_space.is_open_inter t s₁ s₂ h₁ h₂
lemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) :=
topological_space.is_open_sUnion t s h
end
lemma topological_space_eq_iff {t t' : topological_space α} :
t = t' ↔ ∀ s, @is_open α t s ↔ @is_open α t' s :=
⟨λ h s, h ▸ iff.rfl, λ h, by { ext, exact h _ }⟩
lemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s :=
rfl
variables [topological_space α]
lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=
is_open_sUnion $ by rintro _ ⟨i, rfl⟩; exact h i
lemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) :
is_open (⋃i∈s, f i) :=
is_open_Union $ assume i, is_open_Union $ assume hi, h i hi
lemma is_open.union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=
by rw union_eq_Union; exact is_open_Union (bool.forall_bool.2 ⟨h₂, h₁⟩)
@[simp] lemma is_open_empty : is_open (∅ : set α) :=
by rw ← sUnion_empty; exact is_open_sUnion (assume a, false.elim)
lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=
finite.induction_on hs (λ _, by rw sInter_empty; exact is_open_univ) $
λ a s has hs ih h, by rw sInter_insert; exact
is_open.inter (h _ $ mem_insert _ _) (ih $ λ t, h t ∘ mem_insert_of_mem _)
lemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) :=
finite.induction_on hs
(λ _, by rw bInter_empty; exact is_open_univ)
(λ a s has hs ih h, by rw bInter_insert; exact
is_open.inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))
lemma is_open_Inter [fintype β] {s : β → set α}
(h : ∀ i, is_open (s i)) : is_open (⋂ i, s i) :=
suffices is_open (⋂ (i : β) (hi : i ∈ @univ β), s i), by simpa,
is_open_bInter finite_univ (λ i _, h i)
lemma is_open_Inter_prop {p : Prop} {s : p → set α}
(h : ∀ h : p, is_open (s h)) : is_open (Inter s) :=
by by_cases p; simp *
lemma is_open_const {p : Prop} : is_open {a : α | p} :=
by_cases
(assume : p, begin simp only [this]; exact is_open_univ end)
(assume : ¬ p, begin simp only [this]; exact is_open_empty end)
lemma is_open.and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} :=
is_open.inter
/-- A set is closed if its complement is open -/
class is_closed (s : set α) : Prop :=
(is_open_compl : is_open sᶜ)
@[simp] lemma is_open_compl_iff {s : set α} : is_open sᶜ ↔ is_closed s :=
⟨λ h, ⟨h⟩, λ h, h.is_open_compl⟩
@[simp] lemma is_closed_empty : is_closed (∅ : set α) :=
by { rw [← is_open_compl_iff, compl_empty], exact is_open_univ }
@[simp] lemma is_closed_univ : is_closed (univ : set α) :=
by { rw [← is_open_compl_iff, compl_univ], exact is_open_empty }
lemma is_closed.union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=
λ h₁ h₂, by { rw [← is_open_compl_iff] at *, rw compl_union, exact is_open.inter h₁ h₂ }
lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=
by simpa only [← is_open_compl_iff, compl_sInter, sUnion_image] using is_open_bUnion
lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=
is_closed_sInter $ assume t ⟨i, (heq : f i = t)⟩, heq ▸ h i
lemma is_closed_bInter {s : set β} {f : β → set α} (h : ∀ i ∈ s, is_closed (f i)) :
is_closed (⋂ i ∈ s, f i) :=
is_closed_Inter $ λ i, is_closed_Inter $ h i
@[simp] lemma is_closed_compl_iff {s : set α} : is_closed sᶜ ↔ is_open s :=
by rw [←is_open_compl_iff, compl_compl]
lemma is_open.is_closed_compl {s : set α} (hs : is_open s) : is_closed sᶜ :=
is_closed_compl_iff.2 hs
lemma is_open.sdiff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \ t) :=
is_open.inter h₁ $ is_open_compl_iff.mpr h₂
lemma is_closed.inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) :=
by { rw [← is_open_compl_iff] at *, rw compl_inter, exact is_open.union h₁ h₂ }
lemma is_closed.sdiff {s t : set α} (h₁ : is_closed s) (h₂ : is_open t) : is_closed (s \ t) :=
is_closed.inter h₁ (is_closed_compl_iff.mpr h₂)
lemma is_closed_bUnion {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=
finite.induction_on hs
(λ _, by rw bUnion_empty; exact is_closed_empty)
(λ a s has hs ih h, by rw bUnion_insert; exact
is_closed.union (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi))))
lemma is_closed_Union [fintype β] {s : β → set α}
(h : ∀ i, is_closed (s i)) : is_closed (Union s) :=
suffices is_closed (⋃ (i : β) (hi : i ∈ @univ β), s i),
by convert this; simp [set.ext_iff],
is_closed_bUnion finite_univ (λ i _, h i)
lemma is_closed_Union_prop {p : Prop} {s : p → set α}
(h : ∀ h : p, is_closed (s h)) : is_closed (Union s) :=
by by_cases p; simp *
lemma is_closed_imp {p q : α → Prop} (hp : is_open {x | p x})
(hq : is_closed {x | q x}) : is_closed {x | p x → q x} :=
have {x | p x → q x} = {x | p x}ᶜ ∪ {x | q x}, from set.ext $ λ x, imp_iff_not_or,
by rw [this]; exact is_closed.union (is_closed_compl_iff.mpr hp) hq
lemma is_closed.not : is_closed {a | p a} → is_open {a | ¬ p a} :=
is_open_compl_iff.mpr
/-!
### Interior of a set
-/
/-- The interior of a set `s` is the largest open subset of `s`. -/
def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s}
lemma mem_interior {s : set α} {x : α} :
x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by simp only [interior, mem_set_of_eq, exists_prop, and_assoc, and.left_comm]
@[simp] lemma is_open_interior {s : set α} : is_open (interior s) :=
is_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁
lemma interior_subset {s : set α} : interior s ⊆ s :=
sUnion_subset $ assume t ⟨h₁, h₂⟩, h₂
lemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s :=
subset_sUnion_of_mem ⟨h₂, h₁⟩
lemma is_open.interior_eq {s : set α} (h : is_open s) : interior s = s :=
subset.antisymm interior_subset (interior_maximal (subset.refl s) h)
lemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s :=
⟨assume h, h ▸ is_open_interior, is_open.interior_eq⟩
lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=
by simp only [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset, true_and]
lemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) :
s ⊆ interior t ↔ s ⊆ t :=
⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩
lemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t :=
interior_maximal (subset.trans interior_subset h) is_open_interior
@[simp] lemma interior_empty : interior (∅ : set α) = ∅ :=
is_open_empty.interior_eq
@[simp] lemma interior_univ : interior (univ : set α) = univ :=
is_open_univ.interior_eq
@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=
is_open_interior.interior_eq
@[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t :=
subset.antisymm
(subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t))
(interior_maximal (inter_subset_inter interior_subset interior_subset) $
is_open.inter is_open_interior is_open_interior)
lemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s)
(h₂ : interior t = ∅) :
interior (s ∪ t) = interior s :=
have interior (s ∪ t) ⊆ s, from
assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩,
classical.by_contradiction $ assume hx₂ : x ∉ s,
have u \ s ⊆ t,
from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂,
have u \ s ⊆ interior t,
by rwa subset_interior_iff_subset_of_open (is_open.sdiff hu₁ h₁),
have u \ s ⊆ ∅,
by rwa h₂ at this,
this ⟨hx₁, hx₂⟩,
subset.antisymm
(interior_maximal this is_open_interior)
(interior_mono $ subset_union_left _ _)
lemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t :=
by rw ← subset_interior_iff_open; simp only [subset_def, mem_interior]
/-!
### Closure of a set
-/
/-- The closure of `s` is the smallest closed set containing `s`. -/
def closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t}
@[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) :=
is_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁
lemma subset_closure {s : set α} : s ⊆ closure s :=
subset_sInter $ assume t ⟨h₁, h₂⟩, h₂
lemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t :=
sInter_subset_of_mem ⟨h₂, h₁⟩
lemma is_closed.closure_eq {s : set α} (h : is_closed s) : closure s = s :=
subset.antisymm (closure_minimal (subset.refl s) h) subset_closure
lemma is_closed.closure_subset {s : set α} (hs : is_closed s) : closure s ⊆ s :=
closure_minimal (subset.refl _) hs
lemma is_closed.closure_subset_iff {s t : set α} (h₁ : is_closed t) :
closure s ⊆ t ↔ s ⊆ t :=
⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩
@[mono] lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_minimal (subset.trans h subset_closure) is_closed_closure
lemma monotone_closure (α : Type*) [topological_space α] : monotone (@closure α _) :=
λ _ _, closure_mono
lemma diff_subset_closure_iff {s t : set α} :
s \ t ⊆ closure t ↔ s ⊆ closure t :=
by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure]
lemma closure_inter_subset_inter_closure (s t : set α) :
closure (s ∩ t) ⊆ closure s ∩ closure t :=
(monotone_closure α).map_inf_le s t
lemma is_closed_of_closure_subset {s : set α} (h : closure s ⊆ s) : is_closed s :=
by rw subset.antisymm subset_closure h; exact is_closed_closure
lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=
⟨assume h, h ▸ is_closed_closure, is_closed.closure_eq⟩
lemma closure_subset_iff_is_closed {s : set α} : closure s ⊆ s ↔ is_closed s :=
⟨is_closed_of_closure_subset, is_closed.closure_subset⟩
@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=
is_closed_empty.closure_eq
@[simp] lemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ :=
⟨subset_eq_empty subset_closure, λ h, h.symm ▸ closure_empty⟩
@[simp] lemma closure_nonempty_iff {s : set α} : (closure s).nonempty ↔ s.nonempty :=
by simp only [← ne_empty_iff_nonempty, ne.def, closure_empty_iff]
alias closure_nonempty_iff ↔ set.nonempty.of_closure set.nonempty.closure
@[simp] lemma closure_univ : closure (univ : set α) = univ :=
is_closed_univ.closure_eq
@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=
is_closed_closure.closure_eq
@[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t :=
subset.antisymm
(closure_minimal (union_subset_union subset_closure subset_closure) $
is_closed.union is_closed_closure is_closed_closure)
((monotone_closure α).le_map_sup s t)
lemma interior_subset_closure {s : set α} : interior s ⊆ closure s :=
subset.trans interior_subset subset_closure
lemma closure_eq_compl_interior_compl {s : set α} : closure s = (interior sᶜ)ᶜ :=
begin
rw [interior, closure, compl_sUnion, compl_image_set_of],
simp only [compl_subset_compl, is_open_compl_iff],
end
@[simp] lemma interior_compl {s : set α} : interior sᶜ = (closure s)ᶜ :=
by simp [closure_eq_compl_interior_compl]
@[simp] lemma closure_compl {s : set α} : closure sᶜ = (interior s)ᶜ :=
by simp [closure_eq_compl_interior_compl]
theorem mem_closure_iff {s : set α} {a : α} :
a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → (o ∩ s).nonempty :=
⟨λ h o oo ao, classical.by_contradiction $ λ os,
have s ⊆ oᶜ, from λ x xs xo, os ⟨x, xo, xs⟩,
closure_minimal this (is_closed_compl_iff.2 oo) h ao,
λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,
let ⟨x, hc, hs⟩ := (H _ h₁.is_open_compl nc) in hc (h₂ hs)⟩
/-- A set is dense in a topological space if every point belongs to its closure. -/
def dense (s : set α) : Prop := ∀ x, x ∈ closure s
lemma dense_iff_closure_eq {s : set α} : dense s ↔ closure s = univ :=
eq_univ_iff_forall.symm
lemma dense.closure_eq {s : set α} (h : dense s) : closure s = univ :=
dense_iff_closure_eq.mp h
lemma interior_eq_empty_iff_dense_compl {s : set α} : interior s = ∅ ↔ dense sᶜ :=
by rw [dense_iff_closure_eq, closure_compl, compl_univ_iff]
lemma dense.interior_compl {s : set α} (h : dense s) : interior sᶜ = ∅ :=
interior_eq_empty_iff_dense_compl.2 $ by rwa compl_compl
/-- The closure of a set `s` is dense if and only if `s` is dense. -/
@[simp] lemma dense_closure {s : set α} : dense (closure s) ↔ dense s :=
by rw [dense, dense, closure_closure]
alias dense_closure ↔ dense.of_closure dense.closure
@[simp] lemma dense_univ : dense (univ : set α) := λ x, subset_closure trivial
/-- A set is dense if and only if it has a nonempty intersection with each nonempty open set. -/
lemma dense_iff_inter_open {s : set α} :
dense s ↔ ∀ U, is_open U → U.nonempty → (U ∩ s).nonempty :=
begin
split ; intro h,
{ rintros U U_op ⟨x, x_in⟩,
exact mem_closure_iff.1 (by simp only [h.closure_eq]) U U_op x_in },
{ intro x,
rw mem_closure_iff,
intros U U_op x_in,
exact h U U_op ⟨_, x_in⟩ },
end
alias dense_iff_inter_open ↔ dense.inter_open_nonempty _
lemma dense.nonempty_iff {s : set α} (hs : dense s) :
s.nonempty ↔ nonempty α :=
⟨λ ⟨x, hx⟩, ⟨x⟩, λ ⟨x⟩,
let ⟨y, hy⟩ := hs.inter_open_nonempty _ is_open_univ ⟨x, trivial⟩ in ⟨y, hy.2⟩⟩
lemma dense.nonempty [h : nonempty α] {s : set α} (hs : dense s) : s.nonempty :=
hs.nonempty_iff.2 h
@[mono]
lemma dense.mono {s₁ s₂ : set α} (h : s₁ ⊆ s₂) (hd : dense s₁) : dense s₂ :=
λ x, closure_mono h (hd x)
/-- Complement to a singleton is dense if and only if the singleton is not an open set. -/
lemma dense_compl_singleton_iff_not_open {x : α} : dense ({x}ᶜ : set α) ↔ ¬is_open ({x} : set α) :=
begin
fsplit,
{ intros hd ho,
exact (hd.inter_open_nonempty _ ho (singleton_nonempty _)).ne_empty (inter_compl_self _) },
{ refine λ ho, dense_iff_inter_open.2 (λ U hU hne, inter_compl_nonempty_iff.2 $ λ hUx, _),
obtain rfl : U = {x}, from eq_singleton_iff_nonempty_unique_mem.2 ⟨hne, hUx⟩,
exact ho hU }
end
/-!
### Frontier of a set
-/
/-- The frontier of a set is the set of points between the closure and interior. -/
def frontier (s : set α) : set α := closure s \ interior s
lemma frontier_eq_closure_inter_closure {s : set α} :
frontier s = closure s ∩ closure sᶜ :=
by rw [closure_compl, frontier, diff_eq]
lemma frontier_subset_closure {s : set α} : frontier s ⊆ closure s := diff_subset _ _
/-- The complement of a set has the same frontier as the original set. -/
@[simp] lemma frontier_compl (s : set α) : frontier sᶜ = frontier s :=
by simp only [frontier_eq_closure_inter_closure, compl_compl, inter_comm]
@[simp] lemma frontier_univ : frontier (univ : set α) = ∅ := by simp [frontier]
@[simp] lemma frontier_empty : frontier (∅ : set α) = ∅ := by simp [frontier]
lemma frontier_inter_subset (s t : set α) :
frontier (s ∩ t) ⊆ (frontier s ∩ closure t) ∪ (closure s ∩ frontier t) :=
begin
simp only [frontier_eq_closure_inter_closure, compl_inter, closure_union],
convert inter_subset_inter_left _ (closure_inter_subset_inter_closure s t),
simp only [inter_distrib_left, inter_distrib_right, inter_assoc],
congr' 2,
apply inter_comm
end
lemma frontier_union_subset (s t : set α) :
frontier (s ∪ t) ⊆ (frontier s ∩ closure tᶜ) ∪ (closure sᶜ ∩ frontier t) :=
by simpa only [frontier_compl, ← compl_union]
using frontier_inter_subset sᶜ tᶜ
lemma is_closed.frontier_eq {s : set α} (hs : is_closed s) : frontier s = s \ interior s :=
by rw [frontier, hs.closure_eq]
lemma is_open.frontier_eq {s : set α} (hs : is_open s) : frontier s = closure s \ s :=
by rw [frontier, hs.interior_eq]
lemma is_open.inter_frontier_eq {s : set α} (hs : is_open s) : s ∩ frontier s = ∅ :=
by rw [hs.frontier_eq, inter_diff_self]
/-- The frontier of a set is closed. -/
lemma is_closed_frontier {s : set α} : is_closed (frontier s) :=
by rw frontier_eq_closure_inter_closure; exact is_closed.inter is_closed_closure is_closed_closure
/-- The frontier of a closed set has no interior point. -/
lemma interior_frontier {s : set α} (h : is_closed s) : interior (frontier s) = ∅ :=
begin
have A : frontier s = s \ interior s, from h.frontier_eq,
have B : interior (frontier s) ⊆ interior s, by rw A; exact interior_mono (diff_subset _ _),
have C : interior (frontier s) ⊆ frontier s := interior_subset,
have : interior (frontier s) ⊆ (interior s) ∩ (s \ interior s) :=
subset_inter B (by simpa [A] using C),
rwa [inter_diff_self, subset_empty_iff] at this,
end
lemma closure_eq_interior_union_frontier (s : set α) : closure s = interior s ∪ frontier s :=
(union_diff_cancel interior_subset_closure).symm
lemma closure_eq_self_union_frontier (s : set α) : closure s = s ∪ frontier s :=
(union_diff_cancel' interior_subset subset_closure).symm
lemma is_open.inter_frontier_eq_empty_of_disjoint {s t : set α} (ht : is_open t)
(hd : disjoint s t) :
t ∩ frontier s = ∅ :=
begin
rw [inter_comm, ← subset_compl_iff_disjoint],
exact subset.trans frontier_subset_closure (closure_minimal (λ _, disjoint_left.1 hd)
(is_closed_compl_iff.2 ht))
end
lemma frontier_eq_inter_compl_interior {s : set α} :
frontier s = (interior s)ᶜ ∩ (interior (sᶜ))ᶜ :=
by { rw [←frontier_compl, ←closure_compl], refl }
lemma compl_frontier_eq_union_interior {s : set α} :
(frontier s)ᶜ = interior s ∪ interior sᶜ :=
begin
rw frontier_eq_inter_compl_interior,
simp only [compl_inter, compl_compl],
end
/-!
### Neighborhoods
-/
/-- A set is called a neighborhood of `a` if it contains an open set around `a`. The set of all
neighborhoods of `a` forms a filter, the neighborhood filter at `a`, is here defined as the
infimum over the principal filters of all open sets containing `a`. -/
@[irreducible] def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 s)
localized "notation `𝓝` := nhds" in topological_space
/-- The "neighborhood within" filter. Elements of `𝓝[s] a` are sets containing the
intersection of `s` and a neighborhood of `a`. -/
def nhds_within (a : α) (s : set α) : filter α := 𝓝 a ⊓ 𝓟 s
localized "notation `𝓝[` s `] ` x:100 := nhds_within x s" in topological_space
lemma nhds_def (a : α) : 𝓝 a = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 s) := by rw nhds
/-- The open sets containing `a` are a basis for the neighborhood filter. See `nhds_basis_opens'`
for a variant using open neighborhoods instead. -/
lemma nhds_basis_opens (a : α) : (𝓝 a).has_basis (λ s : set α, a ∈ s ∧ is_open s) (λ x, x) :=
begin
rw nhds_def,
exact has_basis_binfi_principal
(λ s ⟨has, hs⟩ t ⟨hat, ht⟩, ⟨s ∩ t, ⟨⟨has, hat⟩, is_open.inter hs ht⟩,
⟨inter_subset_left _ _, inter_subset_right _ _⟩⟩)
⟨univ, ⟨mem_univ a, is_open_univ⟩⟩
end
/-- A filter lies below the neighborhood filter at `a` iff it contains every open set around `a`. -/
lemma le_nhds_iff {f a} : f ≤ 𝓝 a ↔ ∀ s : set α, a ∈ s → is_open s → s ∈ f :=
by simp [nhds_def]
/-- To show a filter is above the neighborhood filter at `a`, it suffices to show that it is above
the principal filter of some open set `s` containing `a`. -/
lemma nhds_le_of_le {f a} {s : set α} (h : a ∈ s) (o : is_open s) (sf : 𝓟 s ≤ f) : 𝓝 a ≤ f :=
by rw nhds_def; exact infi_le_of_le s (infi_le_of_le ⟨h, o⟩ sf)
lemma mem_nhds_iff {a : α} {s : set α} :
s ∈ 𝓝 a ↔ ∃t⊆s, is_open t ∧ a ∈ t :=
(nhds_basis_opens a).mem_iff.trans
⟨λ ⟨t, ⟨hat, ht⟩, hts⟩, ⟨t, hts, ht, hat⟩, λ ⟨t, hts, ht, hat⟩, ⟨t, ⟨hat, ht⟩, hts⟩⟩
/-- A predicate is true in a neighborhood of `a` iff it is true for all the points in an open set
containing `a`. -/
lemma eventually_nhds_iff {a : α} {p : α → Prop} :
(∀ᶠ x in 𝓝 a, p x) ↔ ∃ (t : set α), (∀ x ∈ t, p x) ∧ is_open t ∧ a ∈ t :=
mem_nhds_iff.trans $ by simp only [subset_def, exists_prop, mem_set_of_eq]
lemma map_nhds {a : α} {f : α → β} :
map f (𝓝 a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 (image f s)) :=
((nhds_basis_opens a).map f).eq_binfi
lemma mem_of_mem_nhds {a : α} {s : set α} : s ∈ 𝓝 a → a ∈ s :=
λ H, let ⟨t, ht, _, hs⟩ := mem_nhds_iff.1 H in ht hs
/-- If a predicate is true in a neighborhood of `a`, then it is true for `a`. -/
lemma filter.eventually.self_of_nhds {p : α → Prop} {a : α}
(h : ∀ᶠ y in 𝓝 a, p y) : p a :=
mem_of_mem_nhds h
lemma is_open.mem_nhds {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :
s ∈ 𝓝 a :=
mem_nhds_iff.2 ⟨s, subset.refl _, hs, ha⟩
lemma is_open.eventually_mem {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :
∀ᶠ x in 𝓝 a, x ∈ s :=
is_open.mem_nhds hs ha
/-- The open neighborhoods of `a` are a basis for the neighborhood filter. See `nhds_basis_opens`
for a variant using open sets around `a` instead. -/
lemma nhds_basis_opens' (a : α) : (𝓝 a).has_basis (λ s : set α, s ∈ 𝓝 a ∧ is_open s) (λ x, x) :=
begin
convert nhds_basis_opens a,
ext s,
split,
{ rintros ⟨s_in, s_op⟩,
exact ⟨mem_of_mem_nhds s_in, s_op⟩ },
{ rintros ⟨a_in, s_op⟩,
exact ⟨is_open.mem_nhds s_op a_in, s_op⟩ },
end
/-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of `s`:
it contains an open set containing `s`. -/
lemma exists_open_set_nhds {s U : set α} (h : ∀ x ∈ s, U ∈ 𝓝 x) :
∃ V : set α, s ⊆ V ∧ is_open V ∧ V ⊆ U :=
begin
have := λ x hx, (nhds_basis_opens x).mem_iff.1 (h x hx),
choose! Z hZ hZ' using this,
refine ⟨⋃ x ∈ s, Z x, _, _, bUnion_subset hZ'⟩,
{ intros x hx,
simp only [mem_Union],
exact ⟨x, hx, (hZ x hx).1⟩ },
{ apply is_open_Union,
intros x,
by_cases hx : x ∈ s ; simp [hx],
exact (hZ x hx).2 }
end
/-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of s:
it contains an open set containing `s`. -/
lemma exists_open_set_nhds' {s U : set α} (h : U ∈ ⨆ x ∈ s, 𝓝 x) :
∃ V : set α, s ⊆ V ∧ is_open V ∧ V ⊆ U :=
exists_open_set_nhds (by simpa using h)
/-- If a predicate is true in a neighbourhood of `a`, then for `y` sufficiently close
to `a` this predicate is true in a neighbourhood of `y`. -/
lemma filter.eventually.eventually_nhds {p : α → Prop} {a : α} (h : ∀ᶠ y in 𝓝 a, p y) :
∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝 y, p x :=
let ⟨t, htp, hto, ha⟩ := eventually_nhds_iff.1 h in
eventually_nhds_iff.2 ⟨t, λ x hx, eventually_nhds_iff.2 ⟨t, htp, hto, hx⟩, hto, ha⟩
@[simp] lemma eventually_eventually_nhds {p : α → Prop} {a : α} :
(∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝 y, p x) ↔ ∀ᶠ x in 𝓝 a, p x :=
⟨λ h, h.self_of_nhds, λ h, h.eventually_nhds⟩
@[simp] lemma nhds_bind_nhds : (𝓝 a).bind 𝓝 = 𝓝 a := filter.ext $ λ s, eventually_eventually_nhds
@[simp] lemma eventually_eventually_eq_nhds {f g : α → β} {a : α} :
(∀ᶠ y in 𝓝 a, f =ᶠ[𝓝 y] g) ↔ f =ᶠ[𝓝 a] g :=
eventually_eventually_nhds
lemma filter.eventually_eq.eq_of_nhds {f g : α → β} {a : α} (h : f =ᶠ[𝓝 a] g) : f a = g a :=
h.self_of_nhds
@[simp] lemma eventually_eventually_le_nhds [has_le β] {f g : α → β} {a : α} :
(∀ᶠ y in 𝓝 a, f ≤ᶠ[𝓝 y] g) ↔ f ≤ᶠ[𝓝 a] g :=
eventually_eventually_nhds
/-- If two functions are equal in a neighbourhood of `a`, then for `y` sufficiently close
to `a` these functions are equal in a neighbourhood of `y`. -/
lemma filter.eventually_eq.eventually_eq_nhds {f g : α → β} {a : α} (h : f =ᶠ[𝓝 a] g) :
∀ᶠ y in 𝓝 a, f =ᶠ[𝓝 y] g :=
h.eventually_nhds
/-- If `f x ≤ g x` in a neighbourhood of `a`, then for `y` sufficiently close to `a` we have
`f x ≤ g x` in a neighbourhood of `y`. -/
lemma filter.eventually_le.eventually_le_nhds [has_le β] {f g : α → β} {a : α} (h : f ≤ᶠ[𝓝 a] g) :
∀ᶠ y in 𝓝 a, f ≤ᶠ[𝓝 y] g :=
h.eventually_nhds
theorem all_mem_nhds (x : α) (P : set α → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) :
(∀ s ∈ 𝓝 x, P s) ↔ (∀ s, is_open s → x ∈ s → P s) :=
((nhds_basis_opens x).forall_iff hP).trans $ by simp only [and_comm (x ∈ _), and_imp]
theorem all_mem_nhds_filter (x : α) (f : set α → set β) (hf : ∀ s t, s ⊆ t → f s ⊆ f t)
(l : filter β) :
(∀ s ∈ 𝓝 x, f s ∈ l) ↔ (∀ s, is_open s → x ∈ s → f s ∈ l) :=
all_mem_nhds _ _ (λ s t ssubt h, mem_of_superset h (hf s t ssubt))
theorem rtendsto_nhds {r : rel β α} {l : filter β} {a : α} :
rtendsto r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.core s ∈ l) :=
all_mem_nhds_filter _ _ (λ s t, id) _
theorem rtendsto'_nhds {r : rel β α} {l : filter β} {a : α} :
rtendsto' r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.preimage s ∈ l) :=
by { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono }
theorem ptendsto_nhds {f : β →. α} {l : filter β} {a : α} :
ptendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.core s ∈ l) :=
rtendsto_nhds
theorem ptendsto'_nhds {f : β →. α} {l : filter β} {a : α} :
ptendsto' f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.preimage s ∈ l) :=
rtendsto'_nhds
theorem tendsto_nhds {f : β → α} {l : filter β} {a : α} :
tendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f ⁻¹' s ∈ l) :=
all_mem_nhds_filter _ _ (λ s t h, preimage_mono h) _
lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (𝓝 a) :=
tendsto_nhds.mpr $ assume s hs ha, univ_mem' $ assume _, ha
lemma tendsto_at_top_of_eventually_const {ι : Type*} [semilattice_sup ι] [nonempty ι]
{x : α} {u : ι → α} {i₀ : ι} (h : ∀ i ≥ i₀, u i = x) : tendsto u at_top (𝓝 x) :=
tendsto.congr' (eventually_eq.symm (eventually_at_top.mpr ⟨i₀, h⟩)) tendsto_const_nhds
lemma tendsto_at_bot_of_eventually_const {ι : Type*} [semilattice_inf ι] [nonempty ι]
{x : α} {u : ι → α} {i₀ : ι} (h : ∀ i ≤ i₀, u i = x) : tendsto u at_bot (𝓝 x) :=
tendsto.congr' (eventually_eq.symm (eventually_at_bot.mpr ⟨i₀, h⟩)) tendsto_const_nhds
lemma pure_le_nhds : pure ≤ (𝓝 : α → filter α) :=
assume a s hs, mem_pure.2 $ mem_of_mem_nhds hs
lemma tendsto_pure_nhds {α : Type*} [topological_space β] (f : α → β) (a : α) :
tendsto f (pure a) (𝓝 (f a)) :=
(tendsto_pure_pure f a).mono_right (pure_le_nhds _)
lemma order_top.tendsto_at_top_nhds {α : Type*} [order_top α] [topological_space β] (f : α → β) :
tendsto f at_top (𝓝 $ f ⊤) :=
(tendsto_at_top_pure f).mono_right (pure_le_nhds _)
@[simp] instance nhds_ne_bot {a : α} : ne_bot (𝓝 a) :=
ne_bot_of_le (pure_le_nhds a)
/-!
### Cluster points
In this section we define [cluster points](https://en.wikipedia.org/wiki/Limit_point)
(also known as limit points and accumulation points) of a filter and of a sequence.
-/
/-- A point `x` is a cluster point of a filter `F` if 𝓝 x ⊓ F ≠ ⊥. Also known as
an accumulation point or a limit point. -/
def cluster_pt (x : α) (F : filter α) : Prop := ne_bot (𝓝 x ⊓ F)
lemma cluster_pt.ne_bot {x : α} {F : filter α} (h : cluster_pt x F) : ne_bot (𝓝 x ⊓ F) := h
lemma filter.has_basis.cluster_pt_iff {ιa ιF} {pa : ιa → Prop} {sa : ιa → set α}
{pF : ιF → Prop} {sF : ιF → set α} {F : filter α}
(ha : (𝓝 a).has_basis pa sa) (hF : F.has_basis pF sF) :
cluster_pt a F ↔ ∀ ⦃i⦄ (hi : pa i) ⦃j⦄ (hj : pF j), (sa i ∩ sF j).nonempty :=
ha.inf_basis_ne_bot_iff hF
lemma cluster_pt_iff {x : α} {F : filter α} :
cluster_pt x F ↔ ∀ ⦃U : set α⦄ (hU : U ∈ 𝓝 x) ⦃V⦄ (hV : V ∈ F), (U ∩ V).nonempty :=
inf_ne_bot_iff
/-- `x` is a cluster point of a set `s` if every neighbourhood of `x` meets `s` on a nonempty
set. -/
lemma cluster_pt_principal_iff {x : α} {s : set α} :
cluster_pt x (𝓟 s) ↔ ∀ U ∈ 𝓝 x, (U ∩ s).nonempty :=
inf_principal_ne_bot_iff
lemma cluster_pt_principal_iff_frequently {x : α} {s : set α} :
cluster_pt x (𝓟 s) ↔ ∃ᶠ y in 𝓝 x, y ∈ s :=
by simp only [cluster_pt_principal_iff, frequently_iff, set.nonempty, exists_prop, mem_inter_iff]
lemma cluster_pt.of_le_nhds {x : α} {f : filter α} (H : f ≤ 𝓝 x) [ne_bot f] : cluster_pt x f :=
by rwa [cluster_pt, inf_eq_right.mpr H]
lemma cluster_pt.of_le_nhds' {x : α} {f : filter α} (H : f ≤ 𝓝 x) (hf : ne_bot f) :
cluster_pt x f :=
cluster_pt.of_le_nhds H
lemma cluster_pt.of_nhds_le {x : α} {f : filter α} (H : 𝓝 x ≤ f) : cluster_pt x f :=
by simp only [cluster_pt, inf_eq_left.mpr H, nhds_ne_bot]
lemma cluster_pt.mono {x : α} {f g : filter α} (H : cluster_pt x f) (h : f ≤ g) :
cluster_pt x g :=
⟨ne_bot_of_le_ne_bot H.ne $ inf_le_inf_left _ h⟩
lemma cluster_pt.of_inf_left {x : α} {f g : filter α} (H : cluster_pt x $ f ⊓ g) :
cluster_pt x f :=
H.mono inf_le_left
lemma cluster_pt.of_inf_right {x : α} {f g : filter α} (H : cluster_pt x $ f ⊓ g) :
cluster_pt x g :=
H.mono inf_le_right
lemma ultrafilter.cluster_pt_iff {x : α} {f : ultrafilter α} : cluster_pt x f ↔ ↑f ≤ 𝓝 x :=
⟨f.le_of_inf_ne_bot', λ h, cluster_pt.of_le_nhds h⟩
/-- A point `x` is a cluster point of a sequence `u` along a filter `F` if it is a cluster point
of `map u F`. -/
def map_cluster_pt {ι :Type*} (x : α) (F : filter ι) (u : ι → α) : Prop := cluster_pt x (map u F)
lemma map_cluster_pt_iff {ι :Type*} (x : α) (F : filter ι) (u : ι → α) :
map_cluster_pt x F u ↔ ∀ s ∈ 𝓝 x, ∃ᶠ a in F, u a ∈ s :=
by { simp_rw [map_cluster_pt, cluster_pt, inf_ne_bot_iff_frequently_left, frequently_map], refl }
lemma map_cluster_pt_of_comp {ι δ :Type*} {F : filter ι} {φ : δ → ι} {p : filter δ}
{x : α} {u : ι → α} [ne_bot p] (h : tendsto φ p F) (H : tendsto (u ∘ φ) p (𝓝 x)) :
map_cluster_pt x F u :=
begin
have := calc
map (u ∘ φ) p = map u (map φ p) : map_map
... ≤ map u F : map_mono h,
have : map (u ∘ φ) p ≤ 𝓝 x ⊓ map u F,
from le_inf H this,
exact ne_bot_of_le this
end
/-!
### Interior, closure and frontier in terms of neighborhoods
-/
lemma interior_eq_nhds' {s : set α} : interior s = {a | s ∈ 𝓝 a} :=
set.ext $ λ x, by simp only [mem_interior, mem_nhds_iff, mem_set_of_eq]
lemma interior_eq_nhds {s : set α} : interior s = {a | 𝓝 a ≤ 𝓟 s} :=
interior_eq_nhds'.trans $ by simp only [le_principal_iff]
lemma mem_interior_iff_mem_nhds {s : set α} {a : α} :
a ∈ interior s ↔ s ∈ 𝓝 a :=
by rw [interior_eq_nhds', mem_set_of_eq]
@[simp] lemma interior_mem_nhds {s : set α} {a : α} :
interior s ∈ 𝓝 a ↔ s ∈ 𝓝 a :=
⟨λ h, mem_of_superset h interior_subset,
λ h, is_open.mem_nhds is_open_interior (mem_interior_iff_mem_nhds.2 h)⟩
lemma interior_set_of_eq {p : α → Prop} :
interior {x | p x} = {x | ∀ᶠ y in 𝓝 x, p y} :=
interior_eq_nhds'
lemma is_open_set_of_eventually_nhds {p : α → Prop} :
is_open {x | ∀ᶠ y in 𝓝 x, p y} :=
by simp only [← interior_set_of_eq, is_open_interior]
lemma subset_interior_iff_nhds {s V : set α} : s ⊆ interior V ↔ ∀ x ∈ s, V ∈ 𝓝 x :=
show (∀ x, x ∈ s → x ∈ _) ↔ _, by simp_rw mem_interior_iff_mem_nhds
lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, 𝓝 a ≤ 𝓟 s :=
calc is_open s ↔ s ⊆ interior s : subset_interior_iff_open.symm
... ↔ (∀a∈s, 𝓝 a ≤ 𝓟 s) : by rw [interior_eq_nhds]; refl
lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ 𝓝 a :=
is_open_iff_nhds.trans $ forall_congr $ λ _, imp_congr_right $ λ _, le_principal_iff
theorem is_open_iff_ultrafilter {s : set α} :
is_open s ↔ (∀ (x ∈ s) (l : ultrafilter α), ↑l ≤ 𝓝 x → s ∈ l) :=
by simp_rw [is_open_iff_mem_nhds, ← mem_iff_ultrafilter]
lemma mem_closure_iff_frequently {s : set α} {a : α} : a ∈ closure s ↔ ∃ᶠ x in 𝓝 a, x ∈ s :=
by rw [filter.frequently, filter.eventually, ← mem_interior_iff_mem_nhds,
closure_eq_compl_interior_compl]; refl
alias mem_closure_iff_frequently ↔ _ filter.frequently.mem_closure
/-- The set of cluster points of a filter is closed. In particular, the set of limit points
of a sequence is closed. -/
lemma is_closed_set_of_cluster_pt {f : filter α} : is_closed {x | cluster_pt x f} :=
begin
simp only [cluster_pt, inf_ne_bot_iff_frequently_left, set_of_forall, imp_iff_not_or],
refine is_closed_Inter (λ p, is_closed.union _ _); apply is_closed_compl_iff.2,
exacts [is_open_set_of_eventually_nhds, is_open_const]
end
theorem mem_closure_iff_cluster_pt {s : set α} {a : α} : a ∈ closure s ↔ cluster_pt a (𝓟 s) :=
mem_closure_iff_frequently.trans cluster_pt_principal_iff_frequently.symm
lemma mem_closure_iff_nhds_ne_bot {s : set α} : a ∈ closure s ↔ 𝓝 a ⊓ 𝓟 s ≠ ⊥ :=
mem_closure_iff_cluster_pt.trans ne_bot_iff
lemma mem_closure_iff_nhds_within_ne_bot {s : set α} {x : α} :
x ∈ closure s ↔ ne_bot (𝓝[s] x) :=
mem_closure_iff_cluster_pt
/-- If `x` is not an isolated point of a topological space, then `{x}ᶜ` is dense in the whole
space. -/
lemma dense_compl_singleton (x : α) [ne_bot (𝓝[{x}ᶜ] x)] : dense ({x}ᶜ : set α) :=
begin
intro y,
unfreezingI { rcases eq_or_ne y x with rfl|hne },
{ rwa mem_closure_iff_nhds_within_ne_bot },
{ exact subset_closure hne }
end
/-- If `x` is not an isolated point of a topological space, then the closure of `{x}ᶜ` is the whole
space. -/
@[simp] lemma closure_compl_singleton (x : α) [ne_bot (𝓝[{x}ᶜ] x)] :
closure {x}ᶜ = (univ : set α) :=
(dense_compl_singleton x).closure_eq
/-- If `x` is not an isolated point of a topological space, then the interior of `{x}ᶜ` is empty. -/
@[simp] lemma interior_singleton (x : α) [ne_bot (𝓝[{x}ᶜ] x)] :
interior {x} = (∅ : set α) :=
interior_eq_empty_iff_dense_compl.2 (dense_compl_singleton x)
lemma closure_eq_cluster_pts {s : set α} : closure s = {a | cluster_pt a (𝓟 s)} :=
set.ext $ λ x, mem_closure_iff_cluster_pt
theorem mem_closure_iff_nhds {s : set α} {a : α} :
a ∈ closure s ↔ ∀ t ∈ 𝓝 a, (t ∩ s).nonempty :=
mem_closure_iff_cluster_pt.trans cluster_pt_principal_iff
theorem mem_closure_iff_nhds' {s : set α} {a : α} :
a ∈ closure s ↔ ∀ t ∈ 𝓝 a, ∃ y : s, ↑y ∈ t :=
by simp only [mem_closure_iff_nhds, set.nonempty_inter_iff_exists_right]
theorem mem_closure_iff_comap_ne_bot {A : set α} {x : α} :
x ∈ closure A ↔ ne_bot (comap (coe : A → α) (𝓝 x)) :=
by simp_rw [mem_closure_iff_nhds, comap_ne_bot_iff, set.nonempty_inter_iff_exists_right]
theorem mem_closure_iff_nhds_basis' {a : α} {p : β → Prop} {s : β → set α} (h : (𝓝 a).has_basis p s)
{t : set α} :
a ∈ closure t ↔ ∀ i, p i → (s i ∩ t).nonempty :=
mem_closure_iff_cluster_pt.trans $ (h.cluster_pt_iff (has_basis_principal _)).trans $
by simp only [exists_prop, forall_const]
theorem mem_closure_iff_nhds_basis {a : α} {p : β → Prop} {s : β → set α} (h : (𝓝 a).has_basis p s)
{t : set α} :
a ∈ closure t ↔ ∀ i, p i → ∃ y ∈ t, y ∈ s i :=
(mem_closure_iff_nhds_basis' h).trans $
by simp only [set.nonempty, mem_inter_eq, exists_prop, and_comm]
/-- `x` belongs to the closure of `s` if and only if some ultrafilter
supported on `s` converges to `x`. -/
lemma mem_closure_iff_ultrafilter {s : set α} {x : α} :
x ∈ closure s ↔ ∃ (u : ultrafilter α), s ∈ u ∧ ↑u ≤ 𝓝 x :=
by simp [closure_eq_cluster_pts, cluster_pt, ← exists_ultrafilter_iff, and.comm]
lemma is_closed_iff_cluster_pt {s : set α} : is_closed s ↔ ∀a, cluster_pt a (𝓟 s) → a ∈ s :=
calc is_closed s ↔ closure s ⊆ s : closure_subset_iff_is_closed.symm
... ↔ (∀a, cluster_pt a (𝓟 s) → a ∈ s) : by simp only [subset_def, mem_closure_iff_cluster_pt]
lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀ x, (∀ U ∈ 𝓝 x, (U ∩ s).nonempty) → x ∈ s :=
by simp_rw [is_closed_iff_cluster_pt, cluster_pt, inf_principal_ne_bot_iff]
lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=
begin
rintro a ⟨hs, ht⟩,
have : s ∈ 𝓝 a := is_open.mem_nhds h hs,
rw mem_closure_iff_nhds_ne_bot at ht ⊢,
rwa [← inf_principal, ← inf_assoc, inf_eq_left.2 (le_principal_iff.2 this)],
end
lemma closure_inter_open' {s t : set α} (h : is_open t) : closure s ∩ t ⊆ closure (s ∩ t) :=
by simpa only [inter_comm] using closure_inter_open h
lemma dense.open_subset_closure_inter {s t : set α} (hs : dense s) (ht : is_open t) :
t ⊆ closure (t ∩ s) :=
calc t = t ∩ closure s : by rw [hs.closure_eq, inter_univ]
... ⊆ closure (t ∩ s) : closure_inter_open ht
lemma mem_closure_of_mem_closure_union {s₁ s₂ : set α} {x : α} (h : x ∈ closure (s₁ ∪ s₂))
(h₁ : s₁ᶜ ∈ 𝓝 x) : x ∈ closure s₂ :=
begin
rw mem_closure_iff_nhds_ne_bot at *,
rwa ← calc
𝓝 x ⊓ principal (s₁ ∪ s₂) = 𝓝 x ⊓ (principal s₁ ⊔ principal s₂) : by rw sup_principal
... = (𝓝 x ⊓ principal s₁) ⊔ (𝓝 x ⊓ principal s₂) : inf_sup_left
... = ⊥ ⊔ 𝓝 x ⊓ principal s₂ : by rw inf_principal_eq_bot.mpr h₁
... = 𝓝 x ⊓ principal s₂ : bot_sup_eq
end
/-- The intersection of an open dense set with a dense set is a dense set. -/
lemma dense.inter_of_open_left {s t : set α} (hs : dense s) (ht : dense t) (hso : is_open s) :
dense (s ∩ t) :=
λ x, (closure_minimal (closure_inter_open hso) is_closed_closure) $
by simp [hs.closure_eq, ht.closure_eq]
/-- The intersection of a dense set with an open dense set is a dense set. -/
lemma dense.inter_of_open_right {s t : set α} (hs : dense s) (ht : dense t) (hto : is_open t) :
dense (s ∩ t) :=
inter_comm t s ▸ ht.inter_of_open_left hs hto
lemma dense.inter_nhds_nonempty {s t : set α} (hs : dense s) {x : α} (ht : t ∈ 𝓝 x) :
(s ∩ t).nonempty :=
let ⟨U, hsub, ho, hx⟩ := mem_nhds_iff.1 ht in
(hs.inter_open_nonempty U ho ⟨x, hx⟩).mono $ λ y hy, ⟨hy.2, hsub hy.1⟩
lemma closure_diff {s t : set α} : closure s \ closure t ⊆ closure (s \ t) :=
calc closure s \ closure t = (closure t)ᶜ ∩ closure s : by simp only [diff_eq, inter_comm]
... ⊆ closure ((closure t)ᶜ ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure
... = closure (s \ closure t) : by simp only [diff_eq, inter_comm]
... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure
lemma filter.frequently.mem_of_closed {a : α} {s : set α} (h : ∃ᶠ x in 𝓝 a, x ∈ s)
(hs : is_closed s) : a ∈ s :=
hs.closure_subset h.mem_closure
lemma is_closed.mem_of_frequently_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
(hs : is_closed s) (h : ∃ᶠ x in b, f x ∈ s) (hf : tendsto f b (𝓝 a)) : a ∈ s :=
(hf.frequently $ show ∃ᶠ x in b, (λ y, y ∈ s) (f x), from h).mem_of_closed hs
lemma is_closed.mem_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
[ne_bot b] (hs : is_closed s) (hf : tendsto f b (𝓝 a)) (h : ∀ᶠ x in b, f x ∈ s) : a ∈ s :=
hs.mem_of_frequently_of_tendsto h.frequently hf
lemma mem_closure_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
[ne_bot b] (hf : tendsto f b (𝓝 a)) (h : ∀ᶠ x in b, f x ∈ s) : a ∈ closure s :=
is_closed_closure.mem_of_tendsto hf $ h.mono (preimage_mono subset_closure)
/-- Suppose that `f` sends the complement to `s` to a single point `a`, and `l` is some filter.
Then `f` tends to `a` along `l` restricted to `s` if and only if it tends to `a` along `l`. -/
lemma tendsto_inf_principal_nhds_iff_of_forall_eq {f : β → α} {l : filter β} {s : set β}
{a : α} (h : ∀ x ∉ s, f x = a) :
tendsto f (l ⊓ 𝓟 s) (𝓝 a) ↔ tendsto f l (𝓝 a) :=
begin
rw [tendsto_iff_comap, tendsto_iff_comap],
replace h : 𝓟 sᶜ ≤ comap f (𝓝 a),
{ rintros U ⟨t, ht, htU⟩ x hx,
have : f x ∈ t, from (h x hx).symm ▸ mem_of_mem_nhds ht,
exact htU this },
refine ⟨λ h', _, le_trans inf_le_left⟩,
have := sup_le h' h,
rw [sup_inf_right, sup_principal, union_compl_self, principal_univ,
inf_top_eq, sup_le_iff] at this,
exact this.1
end
/-!
### Limits of filters in topological spaces
-/
section lim
/-- If `f` is a filter, then `Lim f` is a limit of the filter, if it exists. -/
noncomputable def Lim [nonempty α] (f : filter α) : α := epsilon $ λa, f ≤ 𝓝 a
/--
If `f` is a filter satisfying `ne_bot f`, then `Lim' f` is a limit of the filter, if it exists.
-/
def Lim' (f : filter α) [ne_bot f] : α := @Lim _ _ (nonempty_of_ne_bot f) f
/--
If `F` is an ultrafilter, then `filter.ultrafilter.Lim F` is a limit of the filter, if it exists.
Note that dot notation `F.Lim` can be used for `F : ultrafilter α`.
-/
def ultrafilter.Lim : ultrafilter α → α := λ F, Lim' F
/-- If `f` is a filter in `β` and `g : β → α` is a function, then `lim f` is a limit of `g` at `f`,
if it exists. -/
noncomputable def lim [nonempty α] (f : filter β) (g : β → α) : α :=
Lim (f.map g)
/-- If a filter `f` is majorated by some `𝓝 a`, then it is majorated by `𝓝 (Lim f)`. We formulate
this lemma with a `[nonempty α]` argument of `Lim` derived from `h` to make it useful for types
without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
lemma le_nhds_Lim {f : filter α} (h : ∃a, f ≤ 𝓝 a) : f ≤ 𝓝 (@Lim _ _ (nonempty_of_exists h) f) :=
epsilon_spec h
/-- If `g` tends to some `𝓝 a` along `f`, then it tends to `𝓝 (lim f g)`. We formulate
this lemma with a `[nonempty α]` argument of `lim` derived from `h` to make it useful for types
without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
lemma tendsto_nhds_lim {f : filter β} {g : β → α} (h : ∃ a, tendsto g f (𝓝 a)) :
tendsto g f (𝓝 $ @lim _ _ _ (nonempty_of_exists h) f g) :=
le_nhds_Lim h
end lim
/-!
### Locally finite families
-/
/- locally finite family [General Topology (Bourbaki, 1995)] -/
section locally_finite
/-- A family of sets in `set α` is locally finite if at every point `x:α`,
there is a neighborhood of `x` which meets only finitely many sets in the family -/
def locally_finite (f : β → set α) :=
∀x:α, ∃t ∈ 𝓝 x, finite {i | (f i ∩ t).nonempty }
lemma locally_finite.point_finite {f : β → set α} (hf : locally_finite f) (x : α) :
finite {b | x ∈ f b} :=
let ⟨t, hxt, ht⟩ := hf x in ht.subset $ λ b hb, ⟨x, hb, mem_of_mem_nhds hxt⟩
lemma locally_finite_of_fintype [fintype β] (f : β → set α) : locally_finite f :=
assume x, ⟨univ, univ_mem, finite.of_fintype _⟩
lemma locally_finite.subset
{f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ :=
assume a,
let ⟨t, ht₁, ht₂⟩ := hf₂ a in
⟨t, ht₁, ht₂.subset $ assume i hi, hi.mono $ inter_subset_inter (hf i) $ subset.refl _⟩
lemma locally_finite.comp_injective {ι} {f : β → set α} {g : ι → β} (hf : locally_finite f)
(hg : function.injective g) : locally_finite (f ∘ g) :=
λ x, let ⟨t, htx, htf⟩ := hf x in ⟨t, htx, htf.preimage (hg.inj_on _)⟩
lemma locally_finite.closure {f : β → set α} (hf : locally_finite f) :
locally_finite (λ i, closure (f i)) :=
begin
intro x,
rcases hf x with ⟨s, hsx, hsf⟩,
refine ⟨interior s, interior_mem_nhds.2 hsx, hsf.subset $ λ i hi, _⟩,
exact (hi.mono (closure_inter_open' is_open_interior)).of_closure.mono
(inter_subset_inter_right _ interior_subset)
end
lemma locally_finite.is_closed_Union {f : β → set α}
(h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=
begin
simp only [← is_open_compl_iff, compl_Union, is_open_iff_mem_nhds, mem_Inter],
intros a ha,
replace ha : ∀ i, (f i)ᶜ ∈ 𝓝 a := λ i, (h₂ i).is_open_compl.mem_nhds (ha i),
rcases h₁ a with ⟨t, h_nhds, h_fin⟩,
have : t ∩ (⋂ i ∈ {i | (f i ∩ t).nonempty}, (f i)ᶜ) ∈ 𝓝 a,
from inter_mem h_nhds ((bInter_mem h_fin).2 (λ i _, ha i)),
filter_upwards [this],
simp only [mem_inter_eq, mem_Inter],
rintros b ⟨hbt, hn⟩ i hfb,
exact hn i ⟨b, hfb, hbt⟩ hfb
end
lemma locally_finite.closure_Union {f : β → set α} (h : locally_finite f) :
closure (⋃ i, f i) = ⋃ i, closure (f i) :=
subset.antisymm
(closure_minimal (Union_subset_Union $ λ _, subset_closure) $
h.closure.is_closed_Union $ λ _, is_closed_closure)
(Union_subset $ λ i, closure_mono $ subset_Union _ _)
end locally_finite
end topological_space
/-!
### Continuity
-/
section continuous
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables [topological_space α] [topological_space β] [topological_space γ]
open_locale topological_space
/-- A function between topological spaces is continuous if the preimage
of every open set is open. Registered as a structure to make sure it is not unfolded by Lean. -/
structure continuous (f : α → β) : Prop :=
(is_open_preimage : ∀s, is_open s → is_open (f ⁻¹' s))
lemma continuous_def {f : α → β} : continuous f ↔ (∀s, is_open s → is_open (f ⁻¹' s)) :=
⟨λ hf s hs, hf.is_open_preimage s hs, λ h, ⟨h⟩⟩
lemma is_open.preimage {f : α → β} (hf : continuous f) {s : set β} (h : is_open s) :
is_open (f ⁻¹' s) :=
hf.is_open_preimage s h
/-- A function between topological spaces is continuous at a point `x₀`
if `f x` tends to `f x₀` when `x` tends to `x₀`. -/
def continuous_at (f : α → β) (x : α) := tendsto f (𝓝 x) (𝓝 (f x))
lemma continuous_at.tendsto {f : α → β} {x : α} (h : continuous_at f x) :
tendsto f (𝓝 x) (𝓝 (f x)) :=
h
lemma continuous_at_congr {f g : α → β} {x : α} (h : f =ᶠ[𝓝 x] g) :
continuous_at f x ↔ continuous_at g x :=
by simp only [continuous_at, tendsto_congr' h, h.eq_of_nhds]
lemma continuous_at.congr {f g : α → β} {x : α} (hf : continuous_at f x) (h : f =ᶠ[𝓝 x] g) :
continuous_at g x :=
(continuous_at_congr h).1 hf
lemma continuous_at.preimage_mem_nhds {f : α → β} {x : α} {t : set β} (h : continuous_at f x)
(ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝 x :=
h ht
lemma eventually_eq_zero_nhds {M₀} [has_zero M₀] {a : α} {f : α → M₀} :
f =ᶠ[𝓝 a] 0 ↔ a ∉ closure (function.support f) :=
by rw [← mem_compl_eq, ← interior_compl, mem_interior_iff_mem_nhds, function.compl_support]; refl
lemma cluster_pt.map {x : α} {la : filter α} {lb : filter β} (H : cluster_pt x la)
{f : α → β} (hfc : continuous_at f x) (hf : tendsto f la lb) :
cluster_pt (f x) lb :=
⟨ne_bot_of_le_ne_bot ((map_ne_bot_iff f).2 H).ne $ hfc.tendsto.inf hf⟩
lemma preimage_interior_subset_interior_preimage {f : α → β} {s : set β}
(hf : continuous f) : f⁻¹' (interior s) ⊆ interior (f⁻¹' s) :=
interior_maximal (preimage_mono interior_subset) (is_open_interior.preimage hf)
lemma continuous_id : continuous (id : α → α) :=
continuous_def.2 $ assume s h, h
lemma continuous.comp {g : β → γ} {f : α → β} (hg : continuous g) (hf : continuous f) :
continuous (g ∘ f) :=
continuous_def.2 $ assume s h, (h.preimage hg).preimage hf
lemma continuous.iterate {f : α → α} (h : continuous f) (n : ℕ) : continuous (f^[n]) :=
nat.rec_on n continuous_id (λ n ihn, ihn.comp h)
lemma continuous_at.comp {g : β → γ} {f : α → β} {x : α}
(hg : continuous_at g (f x)) (hf : continuous_at f x) :
continuous_at (g ∘ f) x :=
hg.comp hf
lemma continuous.tendsto {f : α → β} (hf : continuous f) (x) :
tendsto f (𝓝 x) (𝓝 (f x)) :=
((nhds_basis_opens x).tendsto_iff $ nhds_basis_opens $ f x).2 $
λ t ⟨hxt, ht⟩, ⟨f ⁻¹' t, ⟨hxt, ht.preimage hf⟩, subset.refl _⟩
/-- A version of `continuous.tendsto` that allows one to specify a simpler form of the limit.
E.g., one can write `continuous_exp.tendsto' 0 1 exp_zero`. -/
lemma continuous.tendsto' {f : α → β} (hf : continuous f) (x : α) (y : β) (h : f x = y) :
tendsto f (𝓝 x) (𝓝 y) :=
h ▸ hf.tendsto x
lemma continuous.continuous_at {f : α → β} {x : α} (h : continuous f) :
continuous_at f x :=
h.tendsto x
lemma continuous_iff_continuous_at {f : α → β} : continuous f ↔ ∀ x, continuous_at f x :=
⟨continuous.tendsto,
assume hf : ∀x, tendsto f (𝓝 x) (𝓝 (f x)),
continuous_def.2 $
assume s, assume hs : is_open s,
have ∀a, f a ∈ s → s ∈ 𝓝 (f a),
from λ a ha, is_open.mem_nhds hs ha,
show is_open (f ⁻¹' s),
from is_open_iff_nhds.2 $ λ a ha, le_principal_iff.2 $ hf _ (this a ha)⟩
lemma continuous_at_const {x : α} {b : β} : continuous_at (λ a:α, b) x :=
tendsto_const_nhds
lemma continuous_const {b : β} : continuous (λa:α, b) :=
continuous_iff_continuous_at.mpr $ assume a, continuous_at_const
lemma continuous_at_id {x : α} : continuous_at id x :=
continuous_id.continuous_at
lemma continuous_at.iterate {f : α → α} {x : α} (hf : continuous_at f x) (hx : f x = x) (n : ℕ) :
continuous_at (f^[n]) x :=
nat.rec_on n continuous_at_id $ λ n ihn,
show continuous_at (f^[n] ∘ f) x,
from continuous_at.comp (hx.symm ▸ ihn) hf
lemma continuous_iff_is_closed {f : α → β} :
continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) :=
⟨assume hf s hs, by simpa using (continuous_def.1 hf sᶜ hs.is_open_compl).is_closed_compl,
assume hf, continuous_def.2 $ assume s,
by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩
lemma is_closed.preimage {f : α → β} (hf : continuous f) {s : set β} (h : is_closed s) :
is_closed (f ⁻¹' s) :=
continuous_iff_is_closed.mp hf s h
lemma mem_closure_image {f : α → β} {x : α} {s : set α} (hf : continuous_at f x)
(hx : x ∈ closure s) : f x ∈ closure (f '' s) :=
begin
rw [mem_closure_iff_nhds_ne_bot] at hx ⊢,
rw ← bot_lt_iff_ne_bot,
haveI : ne_bot _ := ⟨hx⟩,
calc
⊥ < map f (𝓝 x ⊓ principal s) : bot_lt_iff_ne_bot.mpr ne_bot.ne'
... ≤ (map f $ 𝓝 x) ⊓ (map f $ principal s) : map_inf_le
... = (map f $ 𝓝 x) ⊓ (principal $ f '' s) : by rw map_principal
... ≤ 𝓝 (f x) ⊓ (principal $ f '' s) : inf_le_inf hf le_rfl
end
lemma continuous_at_iff_ultrafilter {f : α → β} {x} : continuous_at f x ↔
∀ g : ultrafilter α, ↑g ≤ 𝓝 x → tendsto f g (𝓝 (f x)) :=
tendsto_iff_ultrafilter f (𝓝 x) (𝓝 (f x))
lemma continuous_iff_ultrafilter {f : α → β} :
continuous f ↔ ∀ x (g : ultrafilter α), ↑g ≤ 𝓝 x → tendsto f g (𝓝 (f x)) :=
by simp only [continuous_iff_continuous_at, continuous_at_iff_ultrafilter]
lemma continuous.closure_preimage_subset {f : α → β}
(hf : continuous f) (t : set β) :
closure (f ⁻¹' t) ⊆ f ⁻¹' (closure t) :=
begin
rw ← (is_closed_closure.preimage hf).closure_eq,
exact closure_mono (preimage_mono subset_closure),
end
lemma continuous.frontier_preimage_subset
{f : α → β} (hf : continuous f) (t : set β) :
frontier (f ⁻¹' t) ⊆ f ⁻¹' (frontier t) :=
diff_subset_diff (hf.closure_preimage_subset t) (preimage_interior_subset_interior_preimage hf)
/-! ### Continuity and partial functions -/
/-- Continuity of a partial function -/
def pcontinuous (f : α →. β) := ∀ s, is_open s → is_open (f.preimage s)
lemma open_dom_of_pcontinuous {f : α →. β} (h : pcontinuous f) : is_open f.dom :=
by rw [←pfun.preimage_univ]; exact h _ is_open_univ
lemma pcontinuous_iff' {f : α →. β} :
pcontinuous f ↔ ∀ {x y} (h : y ∈ f x), ptendsto' f (𝓝 x) (𝓝 y) :=
begin
split,
{ intros h x y h',
simp only [ptendsto'_def, mem_nhds_iff],
rintros s ⟨t, tsubs, opent, yt⟩,
exact ⟨f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩ },
intros hf s os,
rw is_open_iff_nhds,
rintros x ⟨y, ys, fxy⟩ t,
rw [mem_principal],
assume h : f.preimage s ⊆ t,
change t ∈ 𝓝 x,
apply mem_of_superset _ h,
have h' : ∀ s ∈ 𝓝 y, f.preimage s ∈ 𝓝 x,
{ intros s hs,
have : ptendsto' f (𝓝 x) (𝓝 y) := hf fxy,
rw ptendsto'_def at this,
exact this s hs },
show f.preimage s ∈ 𝓝 x,
apply h', rw mem_nhds_iff, exact ⟨s, set.subset.refl _, os, ys⟩
end
/-- If a continuous map `f` maps `s` to `t`, then it maps `closure s` to `closure t`. -/
lemma set.maps_to.closure {s : set α} {t : set β} {f : α → β} (h : maps_to f s t)
(hc : continuous f) : maps_to f (closure s) (closure t) :=
begin
simp only [maps_to, mem_closure_iff_cluster_pt],
exact λ x hx, hx.map hc.continuous_at (tendsto_principal_principal.2 h)
end
lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) :
f '' closure s ⊆ closure (f '' s) :=
((maps_to_image f s).closure h).image_subset
lemma closure_subset_preimage_closure_image {f : α → β} {s : set α} (h : continuous f) :
closure s ⊆ f ⁻¹' (closure (f '' s)) :=
by { rw ← set.image_subset_iff, exact image_closure_subset_closure_image h }
lemma map_mem_closure {s : set α} {t : set β} {f : α → β} {a : α}
(hf : continuous f) (ha : a ∈ closure s) (ht : ∀a∈s, f a ∈ t) : f a ∈ closure t :=
set.maps_to.closure ht hf ha
/-!
### Function with dense range
-/
section dense_range
variables {κ ι : Type*} (f : κ → β) (g : β → γ)
/-- `f : ι → β` has dense range if its range (image) is a dense subset of β. -/
def dense_range := dense (range f)
variables {f}
/-- A surjective map has dense range. -/
lemma function.surjective.dense_range (hf : function.surjective f) : dense_range f :=
λ x, by simp [hf.range_eq]
lemma dense_range_iff_closure_range : dense_range f ↔ closure (range f) = univ :=
dense_iff_closure_eq
lemma dense_range.closure_range (h : dense_range f) : closure (range f) = univ :=
h.closure_eq
lemma continuous.range_subset_closure_image_dense {f : α → β} (hf : continuous f)
{s : set α} (hs : dense s) :
range f ⊆ closure (f '' s) :=
by { rw [← image_univ, ← hs.closure_eq], exact image_closure_subset_closure_image hf }
/-- The image of a dense set under a continuous map with dense range is a dense set. -/
lemma dense_range.dense_image {f : α → β} (hf' : dense_range f) (hf : continuous f)
{s : set α} (hs : dense s) :
dense (f '' s) :=
(hf'.mono $ hf.range_subset_closure_image_dense hs).of_closure
/-- If `f` has dense range and `s` is an open set in the codomain of `f`, then the image of the
preimage of `s` under `f` is dense in `s`. -/
lemma dense_range.subset_closure_image_preimage_of_is_open (hf : dense_range f) {s : set β}
(hs : is_open s) : s ⊆ closure (f '' (f ⁻¹' s)) :=
by { rw image_preimage_eq_inter_range, exact hf.open_subset_closure_inter hs }
/-- If a continuous map with dense range maps a dense set to a subset of `t`, then `t` is a dense
set. -/
lemma dense_range.dense_of_maps_to {f : α → β} (hf' : dense_range f) (hf : continuous f)
{s : set α} (hs : dense s) {t : set β} (ht : maps_to f s t) :
dense t :=
(hf'.dense_image hf hs).mono ht.image_subset
/-- Composition of a continuous map with dense range and a function with dense range has dense
range. -/
lemma dense_range.comp {g : β → γ} {f : κ → β} (hg : dense_range g) (hf : dense_range f)
(cg : continuous g) :
dense_range (g ∘ f) :=
by { rw [dense_range, range_comp], exact hg.dense_image cg hf }
lemma dense_range.nonempty_iff (hf : dense_range f) : nonempty κ ↔ nonempty β :=
range_nonempty_iff_nonempty.symm.trans hf.nonempty_iff
lemma dense_range.nonempty [h : nonempty β] (hf : dense_range f) : nonempty κ :=
hf.nonempty_iff.mpr h
/-- Given a function `f : α → β` with dense range and `b : β`, returns some `a : α`. -/
def dense_range.some (hf : dense_range f) (b : β) : κ :=
classical.choice $ hf.nonempty_iff.mpr ⟨b⟩
end dense_range
end continuous
|
f1b5a53e5ac6fdff35d6d1e191e39083eb831dea | a4673261e60b025e2c8c825dfa4ab9108246c32e | /stage0/src/Lean/Elab/Log.lean | 592d97722c51e5529f9d971872fee2c56071ac42 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,844 | 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.Elab.Util
import Lean.Elab.Exception
namespace Lean.Elab
class MonadLog (m : Type → Type) :=
(getRef : m Syntax)
(getFileMap : m FileMap)
(getFileName : m String)
(logMessage : Message → m Unit)
instance (m n) [MonadLog m] [MonadLift m n] : MonadLog n := {
getRef := liftM (MonadLog.getRef : m _),
getFileMap := liftM (MonadLog.getFileMap : m _),
getFileName := liftM (MonadLog.getFileName : m _),
logMessage := fun msg => liftM (MonadLog.logMessage msg : m _ )
}
export MonadLog (getFileMap getFileName logMessage)
variables {m : Type → Type} [Monad m] [MonadLog m] [AddMessageContext m]
def getRefPos : m String.Pos := do
let ref ← MonadLog.getRef
return ref.getPos.getD 0
def getRefPosition : m Position := do
let fileMap ← getFileMap
return fileMap.toPosition (← getRefPos)
def logAt (ref : Syntax) (msgData : MessageData) (severity : MessageSeverity := MessageSeverity.error): m Unit := do
let ref := replaceRef ref (← MonadLog.getRef)
let pos := ref.getPos.getD 0
let fileMap ← getFileMap
let msgData ← addMessageContext msgData
logMessage { fileName := (← getFileName), pos := fileMap.toPosition pos, data := msgData, severity := severity }
def logErrorAt (ref : Syntax) (msgData : MessageData) : m Unit :=
logAt ref msgData MessageSeverity.error
def logWarningAt (ref : Syntax) (msgData : MessageData) : m Unit :=
logAt ref msgData MessageSeverity.warning
def logInfoAt (ref : Syntax) (msgData : MessageData) : m Unit :=
logAt ref msgData MessageSeverity.information
def log (msgData : MessageData) (severity : MessageSeverity := MessageSeverity.error): m Unit := do
let ref ← MonadLog.getRef
logAt ref msgData severity
def logError (msgData : MessageData) : m Unit :=
log msgData MessageSeverity.error
def logWarning (msgData : MessageData) : m Unit :=
log msgData MessageSeverity.warning
def logInfo (msgData : MessageData) : m Unit :=
log msgData MessageSeverity.information
def logException [MonadLiftT IO m] (ex : Exception) : m Unit := do
match ex with
| Exception.error ref msg => logErrorAt ref msg
| Exception.internal id _ =>
unless id == abortExceptionId do
let name ← id.getName
logError ("internal exception: " ++ name)
def logTrace (cls : Name) (msgData : MessageData) : m Unit := do
logInfo (MessageData.tagged cls msgData)
@[inline] def trace [MonadOptions m] (cls : Name) (msg : Unit → MessageData) : m Unit := do
if checkTraceOption (← getOptions) cls then
logTrace cls (msg ())
def logDbgTrace [MonadOptions m] (msg : MessageData) : m Unit := do
trace `Elab.debug fun _ => msg
end Lean.Elab
|
e218dc6e88fc78b1b2e664c18d7c8919c6fe57bb | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/group_theory/coset.lean | db354293d1be9136a7434cccc975fca0deec91d3 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,544 | lean | /-
Copyright (c) 2018 Mitchell Rowett. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Rowett, Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.group_theory.subgroup
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-- The left coset `a*s` corresponding to an element `a : α` and a subset `s : set α` -/
def left_coset {α : Type u_1} [Mul α] (a : α) (s : set α) : set α :=
(fun (x : α) => a * x) '' s
/-- The right coset `s*a` corresponding to an element `a : α` and a subset `s : set α` -/
def right_coset {α : Type u_1} [Mul α] (s : set α) (a : α) : set α :=
(fun (x : α) => x * a) '' s
theorem mem_left_coset {α : Type u_1} [Mul α] {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ left_coset a s :=
set.mem_image_of_mem (fun (b : α) => a * b) hxS
theorem mem_right_coset {α : Type u_1} [Mul α] {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ right_coset s a :=
set.mem_image_of_mem (fun (b : α) => b * a) hxS
/-- Equality of two left cosets `a*s` and `b*s` -/
def left_coset_equiv {α : Type u_1} [Mul α] (s : set α) (a : α) (b : α) :=
left_coset a s = left_coset b s
theorem left_add_coset_equiv_rel {α : Type u_1} [Add α] (s : set α) : equivalence (left_add_coset_equiv s) :=
mk_equivalence (left_add_coset_equiv s) (fun (a : α) => rfl) (fun (a b : α) => Eq.symm) fun (a b c : α) => Eq.trans
@[simp] theorem left_coset_assoc {α : Type u_1} [semigroup α] (s : set α) (a : α) (b : α) : left_coset a (left_coset b s) = left_coset (a * b) s := sorry
@[simp] theorem left_add_coset_assoc {α : Type u_1} [add_semigroup α] (s : set α) (a : α) (b : α) : left_add_coset a (left_add_coset b s) = left_add_coset (a + b) s := sorry
@[simp] theorem right_coset_assoc {α : Type u_1} [semigroup α] (s : set α) (a : α) (b : α) : right_coset (right_coset s a) b = right_coset s (a * b) := sorry
@[simp] theorem right_add_coset_assoc {α : Type u_1} [add_semigroup α] (s : set α) (a : α) (b : α) : right_add_coset (right_add_coset s a) b = right_add_coset s (a + b) := sorry
theorem left_add_coset_right_add_coset {α : Type u_1} [add_semigroup α] (s : set α) (a : α) (b : α) : right_add_coset (left_add_coset a s) b = left_add_coset a (right_add_coset s b) := sorry
@[simp] theorem one_left_coset {α : Type u_1} [monoid α] (s : set α) : left_coset 1 s = s := sorry
@[simp] theorem zero_left_add_coset {α : Type u_1} [add_monoid α] (s : set α) : left_add_coset 0 s = s := sorry
@[simp] theorem right_coset_one {α : Type u_1} [monoid α] (s : set α) : right_coset s 1 = s := sorry
@[simp] theorem right_add_coset_zero {α : Type u_1} [add_monoid α] (s : set α) : right_add_coset s 0 = s := sorry
theorem mem_own_left_coset {α : Type u_1} [monoid α] (s : submonoid α) (a : α) : a ∈ left_coset a ↑s := sorry
theorem mem_own_right_add_coset {α : Type u_1} [add_monoid α] (s : add_submonoid α) (a : α) : a ∈ right_add_coset (↑s) a := sorry
theorem mem_left_coset_left_coset {α : Type u_1} [monoid α] (s : submonoid α) {a : α} (ha : left_coset a ↑s = ↑s) : a ∈ s :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∈ s)) (Eq.symm (propext submonoid.mem_coe))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a ∈ ↑s)) (Eq.symm ha))) (mem_own_left_coset s a))
theorem mem_right_add_coset_right_add_coset {α : Type u_1} [add_monoid α] (s : add_submonoid α) {a : α} (ha : right_add_coset (↑s) a = ↑s) : a ∈ s :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∈ s)) (Eq.symm (propext add_submonoid.mem_coe))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a ∈ ↑s)) (Eq.symm ha))) (mem_own_right_add_coset s a))
theorem mem_left_coset_iff {α : Type u_1} [group α] {s : set α} {x : α} (a : α) : x ∈ left_coset a s ↔ a⁻¹ * x ∈ s := sorry
theorem mem_right_coset_iff {α : Type u_1} [group α] {s : set α} {x : α} (a : α) : x ∈ right_coset s a ↔ x * (a⁻¹) ∈ s := sorry
theorem left_coset_mem_left_coset {α : Type u_1} [group α] (s : subgroup α) {a : α} (ha : a ∈ s) : left_coset a ↑s = ↑s := sorry
theorem right_add_coset_mem_right_add_coset {α : Type u_1} [add_group α] (s : add_subgroup α) {a : α} (ha : a ∈ s) : right_add_coset (↑s) a = ↑s := sorry
theorem normal_of_eq_cosets {α : Type u_1} [group α] (s : subgroup α) (N : subgroup.normal s) (g : α) : left_coset g ↑s = right_coset (↑s) g := sorry
theorem eq_cosets_of_normal {α : Type u_1} [group α] (s : subgroup α) (h : ∀ (g : α), left_coset g ↑s = right_coset (↑s) g) : subgroup.normal s := sorry
theorem normal_iff_eq_add_cosets {α : Type u_1} [add_group α] (s : add_subgroup α) : add_subgroup.normal s ↔ ∀ (g : α), left_add_coset g ↑s = right_add_coset (↑s) g :=
{ mp := normal_of_eq_add_cosets s, mpr := eq_add_cosets_of_normal s }
namespace quotient_group
/-- The equivalence relation corresponding to the partition of a group by left cosets
of a subgroup.-/
def Mathlib.quotient_add_group.left_rel {α : Type u_1} [add_group α] (s : add_subgroup α) : setoid α :=
setoid.mk (fun (x y : α) => -x + y ∈ s) sorry
protected instance left_rel_decidable {α : Type u_1} [group α] (s : subgroup α) [d : decidable_pred fun (a : α) => a ∈ s] : DecidableRel setoid.r :=
fun (_x _x_1 : α) => d (_x⁻¹ * _x_1)
/-- `quotient s` is the quotient type representing the left cosets of `s`.
If `s` is a normal subgroup, `quotient s` is a group -/
def quotient {α : Type u_1} [group α] (s : subgroup α) :=
quotient (left_rel s)
end quotient_group
namespace quotient_add_group
/-- `quotient s` is the quotient type representing the left cosets of `s`.
If `s` is a normal subgroup, `quotient s` is a group -/
def quotient {α : Type u_1} [add_group α] (s : add_subgroup α) :=
quotient (left_rel s)
end quotient_add_group
namespace quotient_group
protected instance Mathlib.quotient_add_group.fintype {α : Type u_1} [add_group α] [fintype α] (s : add_subgroup α) [DecidableRel setoid.r] : fintype (quotient_add_group.quotient s) :=
quotient.fintype (quotient_add_group.left_rel s)
/-- The canonical map from a group `α` to the quotient `α/s`. -/
def Mathlib.quotient_add_group.mk {α : Type u_1} [add_group α] {s : add_subgroup α} (a : α) : quotient_add_group.quotient s :=
quotient.mk' a
theorem induction_on {α : Type u_1} [group α] {s : subgroup α} {C : quotient s → Prop} (x : quotient s) (H : ∀ (z : α), C (mk z)) : C x :=
quotient.induction_on' x H
protected instance quotient.has_coe_t {α : Type u_1} [group α] {s : subgroup α} : has_coe_t α (quotient s) :=
has_coe_t.mk mk
theorem induction_on' {α : Type u_1} [group α] {s : subgroup α} {C : quotient s → Prop} (x : quotient s) (H : ∀ (z : α), C ↑z) : C x :=
quotient.induction_on' x H
protected instance quotient.inhabited {α : Type u_1} [group α] (s : subgroup α) : Inhabited (quotient s) :=
{ default := ↑1 }
protected theorem eq {α : Type u_1} [group α] {s : subgroup α} {a : α} {b : α} : ↑a = ↑b ↔ a⁻¹ * b ∈ s :=
quotient.eq'
theorem Mathlib.quotient_add_group.eq_class_eq_left_coset {α : Type u_1} [add_group α] (s : add_subgroup α) (g : α) : (set_of fun (x : α) => ↑x = ↑g) = left_add_coset g ↑s := sorry
theorem preimage_image_coe {α : Type u_1} [group α] (N : subgroup α) (s : set α) : coe ⁻¹' (coe '' s) = set.Union fun (x : ↥N) => (fun (y : α) => y * ↑x) '' s := sorry
end quotient_group
namespace subgroup
/-- The natural bijection between the cosets `g*s` and `s` -/
def Mathlib.add_subgroup.left_coset_equiv_add_subgroup {α : Type u_1} [add_group α] {s : add_subgroup α} (g : α) : ↥(left_add_coset g ↑s) ≃ ↥s :=
equiv.mk (fun (x : ↥(left_add_coset g ↑s)) => { val := -g + subtype.val x, property := sorry })
(fun (x : ↥s) => { val := g + subtype.val x, property := sorry }) sorry sorry
/-- A (non-canonical) bijection between a group `α` and the product `(α/s) × s` -/
def Mathlib.add_subgroup.add_group_equiv_quotient_times_add_subgroup {α : Type u_1} [add_group α] {s : add_subgroup α} : α ≃ quotient_add_group.quotient s × ↥s :=
equiv.trans
(equiv.trans
(equiv.trans (equiv.symm (equiv.sigma_preimage_equiv quotient_add_group.mk))
(equiv.sigma_congr_right
fun (L : quotient_add_group.quotient s) =>
eq.mpr sorry (id (eq.mpr sorry (equiv.refl (Subtype fun (x : α) => quotient.mk' x = L))))))
(equiv.sigma_congr_right
fun (L : quotient_add_group.quotient s) => add_subgroup.left_coset_equiv_add_subgroup (quotient.out' L)))
(equiv.sigma_equiv_prod (quotient_add_group.quotient s) ↥s)
end subgroup
namespace quotient_group
-- FIXME -- why is there no `to_additive`?
/-- If `s` is a subgroup of the group `α`, and `t` is a subset of `α/s`, then
there is a (typically non-canonical) bijection between the preimage of `t` in
`α` and the product `s × t`. -/
def preimage_mk_equiv_subgroup_times_set {α : Type u_1} [group α] (s : subgroup α) (t : set (quotient s)) : ↥(mk ⁻¹' t) ≃ ↥s × ↥t :=
(fun
(h :
∀ {x : quotient s} {a : α}, x ∈ t → a ∈ s → quotient.mk' (quotient.out' x * a) = quotient.mk' (quotient.out' x)) =>
equiv.mk (fun (_x : ↥(mk ⁻¹' t)) => sorry) (fun (_x : ↥s × ↥t) => sorry) sorry sorry)
sorry
end quotient_group
/--
We use the class `has_coe_t` instead of `has_coe` if the first argument is a variable,
|
7edd788480b15e4a72c1f04a817986738bcb0ff1 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/int/units.lean | 925c287d972faf5f5b991f8bd80d47e04b9ef6de | [
"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 | 3,672 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import data.nat.units
import data.int.basic
import algebra.ring.units
/-!
# Lemmas about units in `ℤ`.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/807
> Any changes to this file require a corresponding PR to mathlib4.
-/
namespace int
/-! ### units -/
@[simp] theorem units_nat_abs (u : ℤˣ) : nat_abs u = 1 :=
units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
by rw [← nat_abs_mul, units.mul_inv]; refl,
by rw [← nat_abs_mul, units.inv_mul]; refl⟩
theorem units_eq_one_or (u : ℤˣ) : u = 1 ∨ u = -1 :=
by simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u
lemma is_unit_eq_one_or {a : ℤ} : is_unit a → a = 1 ∨ a = -1
| ⟨x, hx⟩ := hx ▸ (units_eq_one_or _).imp (congr_arg coe) (congr_arg coe)
lemma is_unit_iff {a : ℤ} : is_unit a ↔ a = 1 ∨ a = -1 :=
begin
refine ⟨λ h, is_unit_eq_one_or h, λ h, _⟩,
rcases h with rfl | rfl,
{ exact is_unit_one },
{ exact is_unit_one.neg }
end
lemma is_unit_eq_or_eq_neg {a b : ℤ} (ha : is_unit a) (hb : is_unit b) : a = b ∨ a = -b :=
begin
rcases is_unit_eq_one_or hb with rfl | rfl,
{ exact is_unit_eq_one_or ha },
{ rwa [or_comm, neg_neg, ←is_unit_iff] },
end
lemma eq_one_or_neg_one_of_mul_eq_one {z w : ℤ} (h : z * w = 1) : z = 1 ∨ z = -1 :=
is_unit_iff.mp (is_unit_of_mul_eq_one z w h)
lemma eq_one_or_neg_one_of_mul_eq_one' {z w : ℤ} (h : z * w = 1) :
(z = 1 ∧ w = 1) ∨ (z = -1 ∧ w = -1) :=
begin
have h' : w * z = 1 := (mul_comm z w) ▸ h,
rcases eq_one_or_neg_one_of_mul_eq_one h with rfl | rfl;
rcases eq_one_or_neg_one_of_mul_eq_one h' with rfl | rfl;
tauto,
end
lemma mul_eq_one_iff_eq_one_or_neg_one {z w : ℤ} :
z * w = 1 ↔ z = 1 ∧ w = 1 ∨ z = -1 ∧ w = -1 :=
begin
refine ⟨eq_one_or_neg_one_of_mul_eq_one', λ h, or.elim h (λ H, _) (λ H, _)⟩;
rcases H with ⟨rfl, rfl⟩;
refl,
end
lemma eq_one_or_neg_one_of_mul_eq_neg_one' {z w : ℤ} (h : z * w = -1) :
z = 1 ∧ w = -1 ∨ z = -1 ∧ w = 1 :=
begin
rcases is_unit_eq_one_or (is_unit.mul_iff.mp (int.is_unit_iff.mpr (or.inr h))).1 with rfl | rfl,
{ exact or.inl ⟨rfl, one_mul w ▸ h⟩, },
{ exact or.inr ⟨rfl, neg_inj.mp (neg_one_mul w ▸ h)⟩, }
end
lemma mul_eq_neg_one_iff_eq_one_or_neg_one {z w : ℤ} :
z * w = -1 ↔ z = 1 ∧ w = -1 ∨ z = -1 ∧ w = 1 :=
begin
refine ⟨eq_one_or_neg_one_of_mul_eq_neg_one', λ h, or.elim h (λ H, _) (λ H, _)⟩;
rcases H with ⟨rfl, rfl⟩;
refl,
end
theorem is_unit_iff_nat_abs_eq {n : ℤ} : is_unit n ↔ n.nat_abs = 1 :=
by simp [nat_abs_eq_iff, is_unit_iff, nat.cast_zero]
alias is_unit_iff_nat_abs_eq ↔ is_unit.nat_abs_eq _
@[norm_cast]
lemma of_nat_is_unit {n : ℕ} : is_unit (n : ℤ) ↔ is_unit n :=
by rw [nat.is_unit_iff, is_unit_iff_nat_abs_eq, nat_abs_of_nat]
lemma is_unit_mul_self {a : ℤ} (ha : is_unit a) : a * a = 1 :=
(is_unit_eq_one_or ha).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
lemma is_unit_add_is_unit_eq_is_unit_add_is_unit {a b c d : ℤ}
(ha : is_unit a) (hb : is_unit b) (hc : is_unit c) (hd : is_unit d) :
a + b = c + d ↔ a = c ∧ b = d ∨ a = d ∧ b = c :=
begin
rw is_unit_iff at ha hb hc hd,
cases ha; cases hb; cases hc; cases hd;
subst ha; subst hb; subst hc; subst hd;
tidy,
end
lemma eq_one_or_neg_one_of_mul_eq_neg_one {z w : ℤ} (h : z * w = -1) : z = 1 ∨ z = -1 :=
or.elim (eq_one_or_neg_one_of_mul_eq_neg_one' h) (λ H, or.inl H.1) (λ H, or.inr H.1)
end int
|
a3700312b6a1921fc826c02cd9dbdeea0f7bb3b3 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/unif_issue.lean | 555c348e5a61a400d097b204ac6a7b1493f10ab4 | [
"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 | 1,406 | lean | import Lean
new_frontend
open Lean
#eval toString $
Unhygienic.run do
let a ← `(Nat.one);
let rhs_0 : _ := fun (a : Lean.Syntax) (b : Lean.Syntax) => pure Syntax.missing;
let rhs_1 : _ := fun (_a : _) => pure Lean.Syntax.missing;
let discr_2 : _ := a;
ite (Lean.Syntax.isOfKind discr_2 (Lean.mkNameStr (Lean.mkNameStr (Lean.mkNameStr (Lean.mkNameStr Lean.Name.anonymous "Lean") "Parser") "Term") "add"))
(let discr_3 : _ := Lean.Syntax.getArg discr_2 0;
let discr_4 : _ := Lean.Syntax.getArg discr_2 1;
let discr_5 : _ := Lean.Syntax.getArg discr_2 2;
rhs_0 discr_3 discr_5)
(let discr_7 : _ := a;
rhs_1 Unit.unit)
#check (pure 0 : Id Nat)
#check (let rhs := fun a => pure a; rhs 0 : Id Nat)
#check toString $
Unhygienic.run do
let a ← `(Nat.one);
let rhs_0 : _ := fun (a : Lean.Syntax) (b : Lean.Syntax) => pure Syntax.missing;
let rhs_1 : _ := fun (_a : _) => pure Lean.Syntax.missing;
let discr_2 : _ := a;
ite (Lean.Syntax.isOfKind discr_2 (Lean.mkNameStr (Lean.mkNameStr (Lean.mkNameStr (Lean.mkNameStr Lean.Name.anonymous "Lean") "Parser") "Term") "add"))
(let discr_3 : _ := Lean.Syntax.getArg discr_2 0;
let discr_4 : _ := Lean.Syntax.getArg discr_2 1;
let discr_5 : _ := Lean.Syntax.getArg discr_2 2;
rhs_0 discr_3 discr_5)
(let discr_7 : _ := a;
rhs_1 Unit.unit)
|
e1328c144519c96b4fc87bf8000ee9546ec9dac0 | 37da0369b6c03e380e057bf680d81e6c9fdf9219 | /hott/types/pointed2.hlean | 8e2d145d53e729ce25c09974748439b1f3ba0fcf | [
"Apache-2.0"
] | permissive | kodyvajjha/lean2 | 72b120d95c3a1d77f54433fa90c9810e14a931a4 | 227fcad22ab2bc27bb7471be7911075d101ba3f9 | refs/heads/master | 1,627,157,512,295 | 1,501,855,676,000 | 1,504,809,427,000 | 109,317,326 | 0 | 0 | null | 1,509,839,253,000 | 1,509,655,713,000 | C++ | UTF-8 | Lean | false | false | 47,240 | hlean | /-
Copyright (c) 2017 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
More results about pointed types.
Contains
- squares of pointed maps,
- equalities between pointed homotopies and
- squares between pointed homotopies
- pointed maps into and out of (ppmap A B), the pointed type of pointed maps from A to B
-/
import algebra.homotopy_group eq2
open pointed eq unit is_trunc trunc nat group is_equiv equiv sigma function bool
namespace pointed
variables {A B C : Type*} {P : A → Type} {p₀ : P pt} {k k' l m n : ppi P p₀}
section psquare
/-
Squares of pointed maps
We treat expressions of the form
psquare f g h k :≡ k ∘* f ~* g ∘* h
as squares, where f is the top, g is the bottom, h is the left face and k is the right face.
Then the following are operations on squares
-/
variables {A' A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ : Type*}
{f₁₀ f₁₀' : A₀₀ →* A₂₀} {f₃₀ : A₂₀ →* A₄₀}
{f₀₁ f₀₁' : A₀₀ →* A₀₂} {f₂₁ f₂₁' : A₂₀ →* A₂₂} {f₄₁ : A₄₀ →* A₄₂}
{f₁₂ f₁₂' : A₀₂ →* A₂₂} {f₃₂ : A₂₂ →* A₄₂}
{f₀₃ : A₀₂ →* A₀₄} {f₂₃ : A₂₂ →* A₂₄} {f₄₃ : A₄₂ →* A₄₄}
{f₁₄ : A₀₄ →* A₂₄} {f₃₄ : A₂₄ →* A₄₄}
definition psquare [reducible] (f₁₀ : A₀₀ →* A₂₀) (f₁₂ : A₀₂ →* A₂₂)
(f₀₁ : A₀₀ →* A₀₂) (f₂₁ : A₂₀ →* A₂₂) : Type :=
f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁
definition psquare_of_phomotopy (p : f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁) : psquare f₁₀ f₁₂ f₀₁ f₂₁ :=
p
definition phomotopy_of_psquare (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : f₂₁ ∘* f₁₀ ~* f₁₂ ∘* f₀₁ :=
p
definition phdeg_square {f f' : A →* A'} (p : f ~* f') : psquare !pid !pid f f' :=
!pcompose_pid ⬝* p⁻¹* ⬝* !pid_pcompose⁻¹*
definition pvdeg_square {f f' : A →* A'} (p : f ~* f') : psquare f f' !pid !pid :=
!pid_pcompose ⬝* p ⬝* !pcompose_pid⁻¹*
variables (f₀₁ f₁₀)
definition phrefl : psquare !pid !pid f₀₁ f₀₁ := phdeg_square phomotopy.rfl
definition pvrefl : psquare f₁₀ f₁₀ !pid !pid := pvdeg_square phomotopy.rfl
variables {f₀₁ f₁₀}
definition phrfl : psquare !pid !pid f₀₁ f₀₁ := phrefl f₀₁
definition pvrfl : psquare f₁₀ f₁₀ !pid !pid := pvrefl f₁₀
definition phconcat (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₃₀ f₃₂ f₂₁ f₄₁) :
psquare (f₃₀ ∘* f₁₀) (f₃₂ ∘* f₁₂) f₀₁ f₄₁ :=
!passoc⁻¹* ⬝* pwhisker_right f₁₀ q ⬝* !passoc ⬝* pwhisker_left f₃₂ p ⬝* !passoc⁻¹*
definition pvconcat (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₁₂ f₁₄ f₀₃ f₂₃) :
psquare f₁₀ f₁₄ (f₀₃ ∘* f₀₁) (f₂₃ ∘* f₂₁) :=
!passoc ⬝* pwhisker_left _ p ⬝* !passoc⁻¹* ⬝* pwhisker_right _ q ⬝* !passoc
definition phinverse {f₁₀ : A₀₀ ≃* A₂₀} {f₁₂ : A₀₂ ≃* A₂₂} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀⁻¹ᵉ* f₁₂⁻¹ᵉ* f₂₁ f₀₁ :=
!pid_pcompose⁻¹* ⬝* pwhisker_right _ (pleft_inv f₁₂)⁻¹* ⬝* !passoc ⬝*
pwhisker_left _
(!passoc⁻¹* ⬝* pwhisker_right _ p⁻¹* ⬝* !passoc ⬝* pwhisker_left _ !pright_inv ⬝* !pcompose_pid)
definition pvinverse {f₀₁ : A₀₀ ≃* A₀₂} {f₂₁ : A₂₀ ≃* A₂₂} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₂ f₁₀ f₀₁⁻¹ᵉ* f₂₁⁻¹ᵉ* :=
(phinverse p⁻¹*)⁻¹*
definition phomotopy_hconcat (q : f₀₁' ~* f₀₁) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀ f₁₂ f₀₁' f₂₁ :=
p ⬝* pwhisker_left f₁₂ q⁻¹*
definition hconcat_phomotopy (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : f₂₁' ~* f₂₁) :
psquare f₁₀ f₁₂ f₀₁ f₂₁' :=
pwhisker_right f₁₀ q ⬝* p
definition phomotopy_vconcat (q : f₁₀' ~* f₁₀) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare f₁₀' f₁₂ f₀₁ f₂₁ :=
pwhisker_left f₂₁ q ⬝* p
definition vconcat_phomotopy (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : f₁₂' ~* f₁₂) :
psquare f₁₀ f₁₂' f₀₁ f₂₁ :=
p ⬝* pwhisker_right f₀₁ q⁻¹*
infix ` ⬝h* `:73 := phconcat
infix ` ⬝v* `:73 := pvconcat
infixl ` ⬝hp* `:72 := hconcat_phomotopy
infixr ` ⬝ph* `:72 := phomotopy_hconcat
infixl ` ⬝vp* `:72 := vconcat_phomotopy
infixr ` ⬝pv* `:72 := phomotopy_vconcat
postfix `⁻¹ʰ*`:(max+1) := phinverse
postfix `⁻¹ᵛ*`:(max+1) := pvinverse
definition pwhisker_tl (f : A →* A₀₀) (q : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (f₁₀ ∘* f) f₁₂ (f₀₁ ∘* f) f₂₁ :=
!passoc⁻¹* ⬝* pwhisker_right f q ⬝* !passoc
definition ap1_psquare (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (Ω→ f₁₀) (Ω→ f₁₂) (Ω→ f₀₁) (Ω→ f₂₁) :=
!ap1_pcompose⁻¹* ⬝* ap1_phomotopy p ⬝* !ap1_pcompose
definition apn_psquare (n : ℕ) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (Ω→[n] f₁₀) (Ω→[n] f₁₂) (Ω→[n] f₀₁) (Ω→[n] f₂₁) :=
!apn_pcompose⁻¹* ⬝* apn_phomotopy n p ⬝* !apn_pcompose
definition ptrunc_functor_psquare (n : ℕ₋₂) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (ptrunc_functor n f₁₀) (ptrunc_functor n f₁₂)
(ptrunc_functor n f₀₁) (ptrunc_functor n f₂₁) :=
!ptrunc_functor_pcompose⁻¹* ⬝* ptrunc_functor_phomotopy n p ⬝* !ptrunc_functor_pcompose
definition homotopy_group_functor_psquare (n : ℕ) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (π→[n] f₁₀) (π→[n] f₁₂) (π→[n] f₀₁) (π→[n] f₂₁) :=
!homotopy_group_functor_compose⁻¹* ⬝* homotopy_group_functor_phomotopy n p ⬝*
!homotopy_group_functor_compose
definition homotopy_group_homomorphism_psquare (n : ℕ) [H : is_succ n]
(p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : hsquare (π→g[n] f₁₀) (π→g[n] f₁₂) (π→g[n] f₀₁) (π→g[n] f₂₁) :=
begin
induction H with n, exact to_homotopy (ptrunc_functor_psquare 0 (apn_psquare (succ n) p))
end
end psquare
definition punit_pmap_phomotopy [constructor] {A : Type*} (f : punit →* A) :
f ~* pconst punit A :=
!phomotopy_of_is_contr_dom
definition punit_ppi [constructor] (P : punit → Type*) (p₀ : P ⋆) : ppi P p₀ :=
begin
fapply ppi.mk, intro u, induction u, exact p₀,
reflexivity
end
definition punit_ppi_phomotopy [constructor] {P : punit → Type*} {p₀ : P ⋆} (f : ppi P p₀) :
f ~* punit_ppi P p₀ :=
!phomotopy_of_is_contr_dom
definition is_contr_punit_ppi (P : punit → Type*) (p₀ : P ⋆) : is_contr (ppi P p₀) :=
is_contr.mk (punit_ppi P p₀) (λf, eq_of_phomotopy (punit_ppi_phomotopy f)⁻¹*)
definition is_contr_punit_pmap (A : Type*) : is_contr (punit →* A) :=
!is_contr_punit_ppi
-- definition phomotopy_eq_equiv (h₁ h₂ : k ~* l) :
-- (h₁ = h₂) ≃ Σ(p : to_homotopy h₁ ~ to_homotopy h₂),
-- whisker_right (respect_pt l) (p pt) ⬝ to_homotopy_pt h₂ = to_homotopy_pt h₁ :=
-- begin
-- refine !ppi_eq_equiv ⬝e !phomotopy.sigma_char ⬝e sigma_equiv_sigma_right _,
-- intro p,
-- end
/- Short term TODO: generalize to dependent maps (use ppi_eq_equiv?)
Long term TODO: use homotopies between pointed homotopies, not equalities
-/
definition phomotopy_eq_equiv {A B : Type*} {f g : A →* B} (h k : f ~* g) :
(h = k) ≃ Σ(p : to_homotopy h ~ to_homotopy k),
whisker_right (respect_pt g) (p pt) ⬝ to_homotopy_pt k = to_homotopy_pt h :=
calc
h = k ≃ phomotopy.sigma_char _ _ h = phomotopy.sigma_char _ _ k
: eq_equiv_fn_eq (phomotopy.sigma_char f g) h k
... ≃ Σ(p : to_homotopy h = to_homotopy k),
pathover (λp, p pt ⬝ respect_pt g = respect_pt f) (to_homotopy_pt h) p (to_homotopy_pt k)
: sigma_eq_equiv _ _
... ≃ Σ(p : to_homotopy h = to_homotopy k),
to_homotopy_pt h = ap (λq, q pt ⬝ respect_pt g) p ⬝ to_homotopy_pt k
: sigma_equiv_sigma_right (λp, eq_pathover_equiv_Fl p (to_homotopy_pt h) (to_homotopy_pt k))
... ≃ Σ(p : to_homotopy h = to_homotopy k),
ap (λq, q pt ⬝ respect_pt g) p ⬝ to_homotopy_pt k = to_homotopy_pt h
: sigma_equiv_sigma_right (λp, eq_equiv_eq_symm _ _)
... ≃ Σ(p : to_homotopy h = to_homotopy k),
whisker_right (respect_pt g) (apd10 p pt) ⬝ to_homotopy_pt k = to_homotopy_pt h
: sigma_equiv_sigma_right (λp, equiv_eq_closed_left _ (whisker_right _ !whisker_right_ap⁻¹))
... ≃ Σ(p : to_homotopy h ~ to_homotopy k),
whisker_right (respect_pt g) (p pt) ⬝ to_homotopy_pt k = to_homotopy_pt h
: sigma_equiv_sigma_left' eq_equiv_homotopy
definition phomotopy_eq {A B : Type*} {f g : A →* B} {h k : f ~* g} (p : to_homotopy h ~ to_homotopy k)
(q : whisker_right (respect_pt g) (p pt) ⬝ to_homotopy_pt k = to_homotopy_pt h) : h = k :=
to_inv (phomotopy_eq_equiv h k) ⟨p, q⟩
definition phomotopy_eq' {A B : Type*} {f g : A →* B} {h k : f ~* g} (p : to_homotopy h ~ to_homotopy k)
(q : square (to_homotopy_pt h) (to_homotopy_pt k) (whisker_right (respect_pt g) (p pt)) idp) : h = k :=
phomotopy_eq p (eq_of_square q)⁻¹
definition trans_refl (p : k ~* l) : p ⬝* phomotopy.rfl = p :=
begin
induction A with A a₀,
induction k with k k₀, induction l with l l₀, induction p with p p₀', esimp at * ⊢,
induction l₀, induction p₀', reflexivity,
end
definition eq_of_phomotopy_trans {X Y : Type*} {f g h : X →* Y} (p : f ~* g) (q : g ~* h) :
eq_of_phomotopy (p ⬝* q) = eq_of_phomotopy p ⬝ eq_of_phomotopy q :=
begin
induction p using phomotopy_rec_idp, induction q using phomotopy_rec_idp,
exact ap eq_of_phomotopy !trans_refl ⬝ whisker_left _ !eq_of_phomotopy_refl⁻¹
end
definition refl_trans (p : k ~* l) : phomotopy.rfl ⬝* p = p :=
begin
induction p using phomotopy_rec_idp,
apply trans_refl
end
definition trans_assoc (p : k ~* l) (q : l ~* m) (r : m ~* n) : p ⬝* q ⬝* r = p ⬝* (q ⬝* r) :=
begin
induction r using phomotopy_rec_idp,
induction q using phomotopy_rec_idp,
induction p using phomotopy_rec_idp,
induction k with k k₀, induction k₀,
reflexivity
end
definition refl_symm : phomotopy.rfl⁻¹* = phomotopy.refl k :=
begin
induction k with k k₀, induction k₀,
reflexivity
end
definition symm_symm (p : k ~* l) : p⁻¹*⁻¹* = p :=
begin
induction p using phomotopy_rec_idp, induction k with k k₀, induction k₀, reflexivity
end
definition trans_right_inv (p : k ~* l) : p ⬝* p⁻¹* = phomotopy.rfl :=
begin
induction p using phomotopy_rec_idp, exact !refl_trans ⬝ !refl_symm
end
definition trans_left_inv (p : k ~* l) : p⁻¹* ⬝* p = phomotopy.rfl :=
begin
induction p using phomotopy_rec_idp, exact !trans_refl ⬝ !refl_symm
end
definition trans2 {p p' : k ~* l} {q q' : l ~* m} (r : p = p') (s : q = q') : p ⬝* q = p' ⬝* q' :=
ap011 phomotopy.trans r s
definition pcompose3 {A B C : Type*} {g g' : B →* C} {f f' : A →* B}
{p p' : g ~* g'} {q q' : f ~* f'} (r : p = p') (s : q = q') : p ◾* q = p' ◾* q' :=
ap011 pcompose2 r s
definition symm2 {p p' : k ~* l} (r : p = p') : p⁻¹* = p'⁻¹* :=
ap phomotopy.symm r
infixl ` ◾** `:80 := pointed.trans2
infixl ` ◽* `:81 := pointed.pcompose3
postfix `⁻²**`:(max+1) := pointed.symm2
definition trans_symm (p : k ~* l) (q : l ~* m) : (p ⬝* q)⁻¹* = q⁻¹* ⬝* p⁻¹* :=
begin
induction p using phomotopy_rec_idp, induction q using phomotopy_rec_idp,
exact !trans_refl⁻²** ⬝ !trans_refl⁻¹ ⬝ idp ◾** !refl_symm⁻¹
end
definition phwhisker_left (p : k ~* l) {q q' : l ~* m} (s : q = q') : p ⬝* q = p ⬝* q' :=
idp ◾** s
definition phwhisker_right {p p' : k ~* l} (q : l ~* m) (r : p = p') : p ⬝* q = p' ⬝* q :=
r ◾** idp
definition pwhisker_left_refl {A B C : Type*} (g : B →* C) (f : A →* B) :
pwhisker_left g (phomotopy.refl f) = phomotopy.refl (g ∘* f) :=
begin
induction A with A a₀, induction B with B b₀, induction C with C c₀,
induction f with f f₀, induction g with g g₀,
esimp at *, induction g₀, induction f₀, reflexivity
end
definition pwhisker_right_refl {A B C : Type*} (f : A →* B) (g : B →* C) :
pwhisker_right f (phomotopy.refl g) = phomotopy.refl (g ∘* f) :=
begin
induction A with A a₀, induction B with B b₀, induction C with C c₀,
induction f with f f₀, induction g with g g₀,
esimp at *, induction g₀, induction f₀, reflexivity
end
definition pcompose2_refl {A B C : Type*} (g : B →* C) (f : A →* B) :
phomotopy.refl g ◾* phomotopy.refl f = phomotopy.rfl :=
!pwhisker_right_refl ◾** !pwhisker_left_refl ⬝ !refl_trans
definition pcompose2_refl_left {A B C : Type*} (g : B →* C) {f f' : A →* B} (p : f ~* f') :
phomotopy.rfl ◾* p = pwhisker_left g p :=
!pwhisker_right_refl ◾** idp ⬝ !refl_trans
definition pcompose2_refl_right {A B C : Type*} {g g' : B →* C} (f : A →* B) (p : g ~* g') :
p ◾* phomotopy.rfl = pwhisker_right f p :=
idp ◾** !pwhisker_left_refl ⬝ !trans_refl
definition pwhisker_left_trans {A B C : Type*} (g : B →* C) {f₁ f₂ f₃ : A →* B}
(p : f₁ ~* f₂) (q : f₂ ~* f₃) :
pwhisker_left g (p ⬝* q) = pwhisker_left g p ⬝* pwhisker_left g q :=
begin
induction p using phomotopy_rec_idp,
induction q using phomotopy_rec_idp,
refine _ ⬝ !pwhisker_left_refl⁻¹ ◾** !pwhisker_left_refl⁻¹,
refine ap (pwhisker_left g) !trans_refl ⬝ !pwhisker_left_refl ⬝ !trans_refl⁻¹
end
definition pwhisker_right_trans {A B C : Type*} (f : A →* B) {g₁ g₂ g₃ : B →* C}
(p : g₁ ~* g₂) (q : g₂ ~* g₃) :
pwhisker_right f (p ⬝* q) = pwhisker_right f p ⬝* pwhisker_right f q :=
begin
induction p using phomotopy_rec_idp,
induction q using phomotopy_rec_idp,
refine _ ⬝ !pwhisker_right_refl⁻¹ ◾** !pwhisker_right_refl⁻¹,
refine ap (pwhisker_right f) !trans_refl ⬝ !pwhisker_right_refl ⬝ !trans_refl⁻¹
end
definition pwhisker_left_symm {A B C : Type*} (g : B →* C) {f₁ f₂ : A →* B} (p : f₁ ~* f₂) :
pwhisker_left g p⁻¹* = (pwhisker_left g p)⁻¹* :=
begin
induction p using phomotopy_rec_idp,
refine _ ⬝ ap phomotopy.symm !pwhisker_left_refl⁻¹,
refine ap (pwhisker_left g) !refl_symm ⬝ !pwhisker_left_refl ⬝ !refl_symm⁻¹
end
definition pwhisker_right_symm {A B C : Type*} (f : A →* B) {g₁ g₂ : B →* C} (p : g₁ ~* g₂) :
pwhisker_right f p⁻¹* = (pwhisker_right f p)⁻¹* :=
begin
induction p using phomotopy_rec_idp,
refine _ ⬝ ap phomotopy.symm !pwhisker_right_refl⁻¹,
refine ap (pwhisker_right f) !refl_symm ⬝ !pwhisker_right_refl ⬝ !refl_symm⁻¹
end
definition trans_eq_of_eq_symm_trans {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : q = p⁻¹* ⬝* r) :
p ⬝* q = r :=
idp ◾** s ⬝ !trans_assoc⁻¹ ⬝ trans_right_inv p ◾** idp ⬝ !refl_trans
definition eq_symm_trans_of_trans_eq {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : p ⬝* q = r) :
q = p⁻¹* ⬝* r :=
!refl_trans⁻¹ ⬝ !trans_left_inv⁻¹ ◾** idp ⬝ !trans_assoc ⬝ idp ◾** s
definition trans_eq_of_eq_trans_symm {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : p = r ⬝* q⁻¹*) :
p ⬝* q = r :=
s ◾** idp ⬝ !trans_assoc ⬝ idp ◾** trans_left_inv q ⬝ !trans_refl
definition eq_trans_symm_of_trans_eq {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : p ⬝* q = r) :
p = r ⬝* q⁻¹* :=
!trans_refl⁻¹ ⬝ idp ◾** !trans_right_inv⁻¹ ⬝ !trans_assoc⁻¹ ⬝ s ◾** idp
definition eq_trans_of_symm_trans_eq {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : p⁻¹* ⬝* r = q) :
r = p ⬝* q :=
!refl_trans⁻¹ ⬝ !trans_right_inv⁻¹ ◾** idp ⬝ !trans_assoc ⬝ idp ◾** s
definition symm_trans_eq_of_eq_trans {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : r = p ⬝* q) :
p⁻¹* ⬝* r = q :=
idp ◾** s ⬝ !trans_assoc⁻¹ ⬝ trans_left_inv p ◾** idp ⬝ !refl_trans
definition eq_trans_of_trans_symm_eq {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : r ⬝* q⁻¹* = p) :
r = p ⬝* q :=
!trans_refl⁻¹ ⬝ idp ◾** !trans_left_inv⁻¹ ⬝ !trans_assoc⁻¹ ⬝ s ◾** idp
definition trans_symm_eq_of_eq_trans {p : k ~* l} {q : l ~* m} {r : k ~* m} (s : r = p ⬝* q) :
r ⬝* q⁻¹* = p :=
s ◾** idp ⬝ !trans_assoc ⬝ idp ◾** trans_right_inv q ⬝ !trans_refl
section phsquare
/-
Squares of pointed homotopies
-/
variables {f f' f₀₀ f₂₀ f₄₀ f₀₂ f₂₂ f₄₂ f₀₄ f₂₄ f₄₄ : ppi P p₀}
{p₁₀ : f₀₀ ~* f₂₀} {p₃₀ : f₂₀ ~* f₄₀}
{p₀₁ : f₀₀ ~* f₀₂} {p₂₁ : f₂₀ ~* f₂₂} {p₄₁ : f₄₀ ~* f₄₂}
{p₁₂ : f₀₂ ~* f₂₂} {p₃₂ : f₂₂ ~* f₄₂}
{p₀₃ : f₀₂ ~* f₀₄} {p₂₃ : f₂₂ ~* f₂₄} {p₄₃ : f₄₂ ~* f₄₄}
{p₁₄ : f₀₄ ~* f₂₄} {p₃₄ : f₂₄ ~* f₄₄}
definition phsquare [reducible] (p₁₀ : f₀₀ ~* f₂₀) (p₁₂ : f₀₂ ~* f₂₂)
(p₀₁ : f₀₀ ~* f₀₂) (p₂₁ : f₂₀ ~* f₂₂) : Type :=
p₁₀ ⬝* p₂₁ = p₀₁ ⬝* p₁₂
definition phsquare_of_eq (p : p₁₀ ⬝* p₂₁ = p₀₁ ⬝* p₁₂) : phsquare p₁₀ p₁₂ p₀₁ p₂₁ := p
definition eq_of_phsquare (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) : p₁₀ ⬝* p₂₁ = p₀₁ ⬝* p₁₂ := p
-- definition phsquare.mk (p : Πx, square (p₁₀ x) (p₁₂ x) (p₀₁ x) (p₂₁ x))
-- (q : cube (square_of_eq (to_homotopy_pt p₁₀)) (square_of_eq (to_homotopy_pt p₁₂))
-- (square_of_eq (to_homotopy_pt p₀₁)) (square_of_eq (to_homotopy_pt p₂₁))
-- (p pt) ids) : phsquare p₁₀ p₁₂ p₀₁ p₂₁ :=
-- begin
-- fapply phomotopy_eq,
-- { intro x, apply eq_of_square (p x) },
-- { generalize p pt, intro r, exact sorry }
-- end
definition phhconcat (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) (q : phsquare p₃₀ p₃₂ p₂₁ p₄₁) :
phsquare (p₁₀ ⬝* p₃₀) (p₁₂ ⬝* p₃₂) p₀₁ p₄₁ :=
!trans_assoc ⬝ idp ◾** q ⬝ !trans_assoc⁻¹ ⬝ p ◾** idp ⬝ !trans_assoc
definition phvconcat (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) (q : phsquare p₁₂ p₁₄ p₀₃ p₂₃) :
phsquare p₁₀ p₁₄ (p₀₁ ⬝* p₀₃) (p₂₁ ⬝* p₂₃) :=
(phhconcat p⁻¹ q⁻¹)⁻¹
definition phhdeg_square {p₁ p₂ : f ~* f'} (q : p₁ = p₂) : phsquare phomotopy.rfl phomotopy.rfl p₁ p₂ :=
!refl_trans ⬝ q⁻¹ ⬝ !trans_refl⁻¹
definition phvdeg_square {p₁ p₂ : f ~* f'} (q : p₁ = p₂) : phsquare p₁ p₂ phomotopy.rfl phomotopy.rfl :=
!trans_refl ⬝ q ⬝ !refl_trans⁻¹
variables (p₀₁ p₁₀)
definition phhrefl : phsquare phomotopy.rfl phomotopy.rfl p₀₁ p₀₁ := phhdeg_square idp
definition phvrefl : phsquare p₁₀ p₁₀ phomotopy.rfl phomotopy.rfl := phvdeg_square idp
variables {p₀₁ p₁₀}
definition phhrfl : phsquare phomotopy.rfl phomotopy.rfl p₀₁ p₀₁ := phhrefl p₀₁
definition phvrfl : phsquare p₁₀ p₁₀ phomotopy.rfl phomotopy.rfl := phvrefl p₁₀
/-
The names are very baroque. The following stands for
"pointed homotopy path-horizontal composition" (i.e. composition on the left with a path)
The names are obtained by using the ones for squares, and putting "ph" in front of it.
In practice, use the notation ⬝ph** defined below, which might be easier to remember
-/
definition phphconcat {p₀₁'} (p : p₀₁' = p₀₁) (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare p₁₀ p₁₂ p₀₁' p₂₁ :=
by induction p; exact q
definition phhpconcat {p₂₁'} (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) (p : p₂₁ = p₂₁') :
phsquare p₁₀ p₁₂ p₀₁ p₂₁' :=
by induction p; exact q
definition phpvconcat {p₁₀'} (p : p₁₀' = p₁₀) (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare p₁₀' p₁₂ p₀₁ p₂₁ :=
by induction p; exact q
definition phvpconcat {p₁₂'} (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) (p : p₁₂ = p₁₂') :
phsquare p₁₀ p₁₂' p₀₁ p₂₁ :=
by induction p; exact q
definition phhinverse (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) : phsquare p₁₀⁻¹* p₁₂⁻¹* p₂₁ p₀₁ :=
begin
refine (eq_symm_trans_of_trans_eq _)⁻¹,
refine !trans_assoc⁻¹ ⬝ _,
refine (eq_trans_symm_of_trans_eq _)⁻¹,
exact (eq_of_phsquare p)⁻¹
end
definition phvinverse (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) : phsquare p₁₂ p₁₀ p₀₁⁻¹* p₂₁⁻¹* :=
(phhinverse p⁻¹)⁻¹
infix ` ⬝h** `:78 := phhconcat
infix ` ⬝v** `:78 := phvconcat
infixr ` ⬝ph** `:77 := phphconcat
infixl ` ⬝hp** `:77 := phhpconcat
infixr ` ⬝pv** `:77 := phpvconcat
infixl ` ⬝vp** `:77 := phvpconcat
postfix `⁻¹ʰ**`:(max+1) := phhinverse
postfix `⁻¹ᵛ**`:(max+1) := phvinverse
definition phwhisker_rt (p : f ~* f₂₀) (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare (p₁₀ ⬝* p⁻¹*) p₁₂ p₀₁ (p ⬝* p₂₁) :=
!trans_assoc ⬝ idp ◾** (!trans_assoc⁻¹ ⬝ !trans_left_inv ◾** idp ⬝ !refl_trans) ⬝ q
definition phwhisker_br (p : f₂₂ ~* f) (q : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare p₁₀ (p₁₂ ⬝* p) p₀₁ (p₂₁ ⬝* p) :=
!trans_assoc⁻¹ ⬝ q ◾** idp ⬝ !trans_assoc
definition phmove_top_of_left' {p₀₁ : f ~* f₀₂} (p : f₀₀ ~* f)
(q : phsquare p₁₀ p₁₂ (p ⬝* p₀₁) p₂₁) : phsquare (p⁻¹* ⬝* p₁₀) p₁₂ p₀₁ p₂₁ :=
!trans_assoc ⬝ (eq_symm_trans_of_trans_eq (q ⬝ !trans_assoc)⁻¹)⁻¹
definition phmove_bot_of_left {p₀₁ : f₀₀ ~* f} (p : f ~* f₀₂)
(q : phsquare p₁₀ p₁₂ (p₀₁ ⬝* p) p₂₁) : phsquare p₁₀ (p ⬝* p₁₂) p₀₁ p₂₁ :=
q ⬝ !trans_assoc
definition passoc_phomotopy_right {A B C D : Type*} (h : C →* D) (g : B →* C) {f f' : A →* B}
(p : f ~* f') : phsquare (passoc h g f) (passoc h g f')
(pwhisker_left (h ∘* g) p) (pwhisker_left h (pwhisker_left g p)) :=
begin
induction p using phomotopy_rec_idp,
refine idp ◾** (ap (pwhisker_left h) !pwhisker_left_refl ⬝ !pwhisker_left_refl) ⬝ _ ⬝
!pwhisker_left_refl⁻¹ ◾** idp,
exact !trans_refl ⬝ !refl_trans⁻¹
end
theorem passoc_phomotopy_middle {A B C D : Type*} (h : C →* D) {g g' : B →* C} (f : A →* B)
(p : g ~* g') : phsquare (passoc h g f) (passoc h g' f)
(pwhisker_right f (pwhisker_left h p)) (pwhisker_left h (pwhisker_right f p)) :=
begin
induction p using phomotopy_rec_idp,
rewrite [pwhisker_right_refl, pwhisker_left_refl],
rewrite [pwhisker_right_refl, pwhisker_left_refl],
exact phvrfl
end
definition pwhisker_right_pwhisker_left {A B C : Type*} {g g' : B →* C} {f f' : A →* B}
(p : g ~* g') (q : f ~* f') :
phsquare (pwhisker_right f p) (pwhisker_right f' p) (pwhisker_left g q) (pwhisker_left g' q) :=
begin
induction p using phomotopy_rec_idp,
induction q using phomotopy_rec_idp,
exact !pwhisker_right_refl ◾** !pwhisker_left_refl ⬝
!pwhisker_left_refl⁻¹ ◾** !pwhisker_right_refl⁻¹
end
end phsquare
section nondep_phsquare
variables {f f' f₀₀ f₂₀ f₀₂ f₂₂ : A →* B}
{p₁₀ : f₀₀ ~* f₂₀} {p₀₁ : f₀₀ ~* f₀₂} {p₂₁ : f₂₀ ~* f₂₂} {p₁₂ : f₀₂ ~* f₂₂}
definition pwhisker_left_phsquare (f : B →* C) (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare (pwhisker_left f p₁₀) (pwhisker_left f p₁₂)
(pwhisker_left f p₀₁) (pwhisker_left f p₂₁) :=
!pwhisker_left_trans⁻¹ ⬝ ap (pwhisker_left f) p ⬝ !pwhisker_left_trans
definition pwhisker_right_phsquare (f : C →* A) (p : phsquare p₁₀ p₁₂ p₀₁ p₂₁) :
phsquare (pwhisker_right f p₁₀) (pwhisker_right f p₁₂)
(pwhisker_right f p₀₁) (pwhisker_right f p₂₁) :=
!pwhisker_right_trans⁻¹ ⬝ ap (pwhisker_right f) p ⬝ !pwhisker_right_trans
end nondep_phsquare
definition phomotopy_of_eq_con (p : k = l) (q : l = m) :
phomotopy_of_eq (p ⬝ q) = phomotopy_of_eq p ⬝* phomotopy_of_eq q :=
begin induction q, induction p, exact !trans_refl⁻¹ end
definition pcompose_left_eq_of_phomotopy {A B C : Type*} (g : B →* C) {f f' : A →* B}
(H : f ~* f') : ap (λf, g ∘* f) (eq_of_phomotopy H) = eq_of_phomotopy (pwhisker_left g H) :=
begin
induction H using phomotopy_rec_idp,
refine ap02 _ !eq_of_phomotopy_refl ⬝ !eq_of_phomotopy_refl⁻¹ ⬝ ap eq_of_phomotopy _,
exact !pwhisker_left_refl⁻¹
end
definition pcompose_right_eq_of_phomotopy {A B C : Type*} {g g' : B →* C} (f : A →* B)
(H : g ~* g') : ap (λg, g ∘* f) (eq_of_phomotopy H) = eq_of_phomotopy (pwhisker_right f H) :=
begin
induction H using phomotopy_rec_idp,
refine ap02 _ !eq_of_phomotopy_refl ⬝ !eq_of_phomotopy_refl⁻¹ ⬝ ap eq_of_phomotopy _,
exact !pwhisker_right_refl⁻¹
end
definition phomotopy_of_eq_pcompose_left {A B C : Type*} (g : B →* C) {f f' : A →* B}
(p : f = f') : phomotopy_of_eq (ap (λf, g ∘* f) p) = pwhisker_left g (phomotopy_of_eq p) :=
begin
induction p, exact !pwhisker_left_refl⁻¹
end
definition phomotopy_of_eq_pcompose_right {A B C : Type*} {g g' : B →* C} (f : A →* B)
(p : g = g') : phomotopy_of_eq (ap (λg, g ∘* f) p) = pwhisker_right f (phomotopy_of_eq p) :=
begin
induction p, exact !pwhisker_right_refl⁻¹
end
definition phomotopy_mk_ppmap [constructor] {A B C : Type*} {f g : A →* ppmap B C} (p : Πa, f a ~* g a)
(q : p pt ⬝* phomotopy_of_eq (respect_pt g) = phomotopy_of_eq (respect_pt f))
: f ~* g :=
begin
apply phomotopy.mk (λa, eq_of_phomotopy (p a)),
apply eq_of_fn_eq_fn (pmap_eq_equiv _ _), esimp [pmap_eq_equiv],
refine !phomotopy_of_eq_con ⬝ _,
refine !phomotopy_of_eq_of_phomotopy ◾** idp ⬝ q,
end
/- properties of ppmap, the pointed type of pointed maps -/
definition pcompose_pconst [constructor] (f : B →* C) : f ∘* pconst A B ~* pconst A C :=
phomotopy.mk (λa, respect_pt f) (idp_con _)⁻¹
definition pconst_pcompose [constructor] (f : A →* B) : pconst B C ∘* f ~* pconst A C :=
phomotopy.mk (λa, rfl) !ap_constant⁻¹
definition ppcompose_left [constructor] (g : B →* C) : ppmap A B →* ppmap A C :=
pmap.mk (pcompose g) (eq_of_phomotopy (pcompose_pconst g))
definition ppcompose_right [constructor] (f : A →* B) : ppmap B C →* ppmap A C :=
pmap.mk (λg, g ∘* f) (eq_of_phomotopy (pconst_pcompose f))
/- TODO: give construction using pequiv.MK, which computes better (see comment for a start of the proof), rename to ppmap_pequiv_ppmap_right -/
definition pequiv_ppcompose_left [constructor] (g : B ≃* C) : ppmap A B ≃* ppmap A C :=
pequiv.MK' (ppcompose_left g) (ppcompose_left g⁻¹ᵉ*)
begin intro f, apply eq_of_phomotopy, apply pinv_pcompose_cancel_left end
begin intro f, apply eq_of_phomotopy, apply pcompose_pinv_cancel_left end
-- pequiv.MK (ppcompose_left g) (ppcompose_left g⁻¹ᵉ*)
-- abstract begin
-- apply phomotopy_mk_ppmap (pinv_pcompose_cancel_left g), esimp,
-- refine !trans_refl ⬝ _,
-- refine _ ⬝ (!phomotopy_of_eq_con ⬝ (!phomotopy_of_eq_pcompose_left ⬝
-- ap (pwhisker_left _) !phomotopy_of_eq_of_phomotopy) ◾** !phomotopy_of_eq_of_phomotopy)⁻¹,
-- end end
-- abstract begin
-- exact sorry
-- end end
definition pequiv_ppcompose_right [constructor] (f : A ≃* B) : ppmap B C ≃* ppmap A C :=
begin
fapply pequiv.MK',
{ exact ppcompose_right f },
{ exact ppcompose_right f⁻¹ᵉ* },
{ intro g, apply eq_of_phomotopy, apply pcompose_pinv_cancel_right },
{ intro g, apply eq_of_phomotopy, apply pinv_pcompose_cancel_right },
end
definition loop_ppmap_commute (A B : Type*) : Ω(ppmap A B) ≃* (ppmap A (Ω B)) :=
pequiv_of_equiv
(calc Ω(ppmap A B) ≃ (pconst A B ~* pconst A B) : pmap_eq_equiv _ _
... ≃ Σ(p : pconst A B ~ pconst A B), p pt ⬝ rfl = rfl : phomotopy.sigma_char
... ≃ (A →* Ω B) : pmap.sigma_char)
(by reflexivity)
definition papply [constructor] {A : Type*} (B : Type*) (a : A) : ppmap A B →* B :=
pmap.mk (λ(f : A →* B), f a) idp
definition papply_pcompose [constructor] {A : Type*} (B : Type*) (a : A) : ppmap A B →* B :=
pmap.mk (λ(f : A →* B), f a) idp
definition ppmap_pbool_pequiv [constructor] (B : Type*) : ppmap pbool B ≃* B :=
begin
fapply pequiv.MK',
{ exact papply B tt },
{ exact pbool_pmap },
{ intro f, fapply eq_of_phomotopy, fapply phomotopy.mk,
{ intro b, cases b, exact !respect_pt⁻¹, reflexivity },
{ exact !con.left_inv }},
{ intro b, reflexivity },
end
definition papn_pt [constructor] (n : ℕ) (A B : Type*) : ppmap A B →* ppmap (Ω[n] A) (Ω[n] B) :=
pmap.mk (λf, apn n f) (eq_of_phomotopy !apn_pconst)
definition papn_fun [constructor] {n : ℕ} {A : Type*} (B : Type*) (p : Ω[n] A) :
ppmap A B →* Ω[n] B :=
papply _ p ∘* papn_pt n A B
definition pconst_pcompose_pconst (A B C : Type*) :
pconst_pcompose (pconst A B) = pcompose_pconst (pconst B C) :=
idp
definition pconst_pcompose_phomotopy_pconst {A B C : Type*} {f : A →* B} (p : f ~* pconst A B) :
pconst_pcompose f = pwhisker_left (pconst B C) p ⬝* pcompose_pconst (pconst B C) :=
begin
assert H : Π(p : pconst A B ~* f),
pconst_pcompose f = pwhisker_left (pconst B C) p⁻¹* ⬝* pcompose_pconst (pconst B C),
{ intro p, induction p using phomotopy_rec_idp, reflexivity },
refine H p⁻¹* ⬝ ap (pwhisker_left _) !symm_symm ◾** idp,
end
definition passoc_pconst_right {A B C D : Type*} (h : C →* D) (g : B →* C) :
passoc h g (pconst A B) ⬝* (pwhisker_left h (pcompose_pconst g) ⬝* pcompose_pconst h) =
pcompose_pconst (h ∘* g) :=
begin
fapply phomotopy_eq,
{ intro a, exact !idp_con },
{ induction h with h h₀, induction g with g g₀, induction D with D d₀, induction C with C c₀,
esimp at *, induction g₀, induction h₀, reflexivity }
end
definition passoc_pconst_middle {A A' B B' : Type*} (g : B →* B') (f : A' →* A) :
passoc g (pconst A B) f ⬝* (pwhisker_left g (pconst_pcompose f) ⬝* pcompose_pconst g) =
pwhisker_right f (pcompose_pconst g) ⬝* pconst_pcompose f :=
begin
fapply phomotopy_eq,
{ intro a, exact !idp_con ⬝ !idp_con },
{ induction g with g g₀, induction f with f f₀, induction B' with D d₀, induction A with C c₀,
esimp at *, induction g₀, induction f₀, reflexivity }
end
definition passoc_pconst_left {A B C D : Type*} (g : B →* C) (f : A →* B) :
phsquare (passoc (pconst C D) g f) (pconst_pcompose f)
(pwhisker_right f (pconst_pcompose g)) (pconst_pcompose (g ∘* f)) :=
begin
fapply phomotopy_eq,
{ intro a, exact !idp_con },
{ induction g with g g₀, induction f with f f₀, induction C with C c₀, induction B with B b₀,
esimp at *, induction g₀, induction f₀, reflexivity }
end
definition ppcompose_left_pcompose [constructor] {A B C D : Type*} (h : C →* D) (g : B →* C) :
@ppcompose_left A _ _ (h ∘* g) ~* ppcompose_left h ∘* ppcompose_left g :=
begin
fapply phomotopy_mk_ppmap,
{ exact passoc h g },
{ refine idp ◾** (!phomotopy_of_eq_con ⬝
(ap phomotopy_of_eq !pcompose_left_eq_of_phomotopy ⬝ !phomotopy_of_eq_of_phomotopy) ◾**
!phomotopy_of_eq_of_phomotopy) ⬝ _ ⬝ !phomotopy_of_eq_of_phomotopy⁻¹,
exact passoc_pconst_right h g }
end
definition ppcompose_right_pcompose [constructor] {A B C D : Type*} (g : B →* C) (f : A →* B) :
@ppcompose_right _ _ D (g ∘* f) ~* ppcompose_right f ∘* ppcompose_right g :=
begin
symmetry,
fapply phomotopy_mk_ppmap,
{ intro h, exact passoc h g f },
{ refine idp ◾** !phomotopy_of_eq_of_phomotopy ⬝ _ ⬝ (!phomotopy_of_eq_con ⬝
(ap phomotopy_of_eq !pcompose_right_eq_of_phomotopy ⬝ !phomotopy_of_eq_of_phomotopy) ◾** !phomotopy_of_eq_of_phomotopy)⁻¹,
exact passoc_pconst_left g f }
end
definition ppcompose_left_ppcompose_right {A A' B B' : Type*} (g : B →* B') (f : A' →* A) :
psquare (ppcompose_left g) (ppcompose_left g) (ppcompose_right f) (ppcompose_right f) :=
begin
fapply phomotopy_mk_ppmap,
{ intro h, exact passoc g h f },
{ refine idp ◾** (!phomotopy_of_eq_con ⬝
(ap phomotopy_of_eq !pcompose_left_eq_of_phomotopy ⬝ !phomotopy_of_eq_of_phomotopy) ◾**
!phomotopy_of_eq_of_phomotopy) ⬝ _ ⬝ (!phomotopy_of_eq_con ⬝
(ap phomotopy_of_eq !pcompose_right_eq_of_phomotopy ⬝ !phomotopy_of_eq_of_phomotopy) ◾**
!phomotopy_of_eq_of_phomotopy)⁻¹,
apply passoc_pconst_middle }
end
definition pcompose_pconst_phomotopy {A B C : Type*} {f f' : B →* C} (p : f ~* f') :
pwhisker_right (pconst A B) p ⬝* pcompose_pconst f' = pcompose_pconst f :=
begin
fapply phomotopy_eq,
{ intro a, exact to_homotopy_pt p },
{ induction p using phomotopy_rec_idp, induction C with C c₀, induction f with f f₀,
esimp at *, induction f₀, reflexivity }
end
definition pid_pconst (A B : Type*) : pcompose_pconst (pid B) = pid_pcompose (pconst A B) :=
by reflexivity
definition pid_pconst_pcompose {A B C : Type*} (f : A →* B) :
phsquare (pid_pcompose (pconst B C ∘* f))
(pcompose_pconst (pid C))
(pwhisker_left (pid C) (pconst_pcompose f))
(pconst_pcompose f) :=
begin
fapply phomotopy_eq,
{ reflexivity },
{ induction f with f f₀, induction B with B b₀, esimp at *, induction f₀, reflexivity }
end
definition ppcompose_left_pconst [constructor] (A B C : Type*) :
@ppcompose_left A _ _ (pconst B C) ~* pconst (ppmap A B) (ppmap A C) :=
begin
fapply phomotopy_mk_ppmap,
{ exact pconst_pcompose },
{ refine idp ◾** !phomotopy_of_eq_idp ⬝ !phomotopy_of_eq_of_phomotopy⁻¹ }
end
definition ppcompose_left_phomotopy [constructor] {A B C : Type*} {g g' : B →* C} (p : g ~* g') :
@ppcompose_left A _ _ g ~* ppcompose_left g' :=
begin
induction p using phomotopy_rec_idp,
reflexivity
end
definition ppcompose_left_phomotopy_refl {A B C : Type*} (g : B →* C) :
ppcompose_left_phomotopy (phomotopy.refl g) = phomotopy.refl (@ppcompose_left A _ _ g) :=
!phomotopy_rec_idp_refl
/- a more explicit proof of ppcompose_left_phomotopy, which might be useful if we need to prove properties about it
-/
-- fapply phomotopy_mk_ppmap,
-- { intro f, exact pwhisker_right f p },
-- { refine ap (λx, _ ⬝* x) !phomotopy_of_eq_of_phomotopy ⬝ _ ⬝ !phomotopy_of_eq_of_phomotopy⁻¹,
-- exact pcompose_pconst_phomotopy p }
definition ppcompose_right_phomotopy [constructor] {A B C : Type*} {f f' : A →* B} (p : f ~* f') :
@ppcompose_right _ _ C f ~* ppcompose_right f' :=
begin
induction p using phomotopy_rec_idp,
reflexivity
end
definition pppcompose [constructor] (A B C : Type*) : ppmap B C →* ppmap (ppmap A B) (ppmap A C) :=
pmap.mk ppcompose_left (eq_of_phomotopy !ppcompose_left_pconst)
section psquare
variables {A' A₀₀ A₂₀ A₄₀ A₀₂ A₂₂ A₄₂ A₀₄ A₂₄ A₄₄ : Type*}
{f₁₀ f₁₀' : A₀₀ →* A₂₀} {f₃₀ : A₂₀ →* A₄₀}
{f₀₁ f₀₁' : A₀₀ →* A₀₂} {f₂₁ f₂₁' : A₂₀ →* A₂₂} {f₄₁ : A₄₀ →* A₄₂}
{f₁₂ f₁₂' : A₀₂ →* A₂₂} {f₃₂ : A₂₂ →* A₄₂}
{f₀₃ : A₀₂ →* A₀₄} {f₂₃ : A₂₂ →* A₂₄} {f₄₃ : A₄₂ →* A₄₄}
{f₁₄ : A₀₄ →* A₂₄} {f₃₄ : A₂₄ →* A₄₄}
definition ppcompose_left_psquare {A : Type*} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (@ppcompose_left A _ _ f₁₀) (ppcompose_left f₁₂)
(ppcompose_left f₀₁) (ppcompose_left f₂₁) :=
!ppcompose_left_pcompose⁻¹* ⬝* ppcompose_left_phomotopy p ⬝* !ppcompose_left_pcompose
definition ppcompose_right_psquare {A : Type*} (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
psquare (@ppcompose_right _ _ A f₁₂) (ppcompose_right f₁₀)
(ppcompose_right f₂₁) (ppcompose_right f₀₁) :=
!ppcompose_right_pcompose⁻¹* ⬝* ppcompose_right_phomotopy p⁻¹* ⬝* !ppcompose_right_pcompose
definition trans_phomotopy_hconcat {f₀₁' f₀₁''}
(q₂ : f₀₁'' ~* f₀₁') (q₁ : f₀₁' ~* f₀₁) (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) :
(q₂ ⬝* q₁) ⬝ph* p = q₂ ⬝ph* q₁ ⬝ph* p :=
idp ◾** (ap (pwhisker_left f₁₂) !trans_symm ⬝ !pwhisker_left_trans) ⬝ !trans_assoc⁻¹
definition symm_phomotopy_hconcat {f₀₁'} (q : f₀₁ ~* f₀₁')
(p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : q⁻¹* ⬝ph* p = p ⬝* pwhisker_left f₁₂ q :=
idp ◾** ap (pwhisker_left f₁₂) !symm_symm
definition refl_phomotopy_hconcat (p : psquare f₁₀ f₁₂ f₀₁ f₂₁) : phomotopy.rfl ⬝ph* p = p :=
idp ◾** (ap (pwhisker_left _) !refl_symm ⬝ !pwhisker_left_refl) ⬝ !trans_refl
local attribute phomotopy.rfl [reducible]
theorem pwhisker_left_phomotopy_hconcat {f₀₁'} (r : f₀₁' ~* f₀₁)
(p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₁₂ f₁₄ f₀₃ f₂₃) :
pwhisker_left f₀₃ r ⬝ph* (p ⬝v* q) = (r ⬝ph* p) ⬝v* q :=
by induction r using phomotopy_rec_idp; rewrite [pwhisker_left_refl, +refl_phomotopy_hconcat]
theorem pvcompose_pwhisker_left {f₀₁'} (r : f₀₁ ~* f₀₁')
(p : psquare f₁₀ f₁₂ f₀₁ f₂₁) (q : psquare f₁₂ f₁₄ f₀₃ f₂₃) :
(p ⬝v* q) ⬝* (pwhisker_left f₁₄ (pwhisker_left f₀₃ r)) = (p ⬝* pwhisker_left f₁₂ r) ⬝v* q :=
by induction r using phomotopy_rec_idp; rewrite [+pwhisker_left_refl, + trans_refl]
definition phconcat2 {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁} {q q' : psquare f₃₀ f₃₂ f₂₁ f₄₁}
(r : p = p') (s : q = q') : p ⬝h* q = p' ⬝h* q' :=
ap011 phconcat r s
definition pvconcat2 {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁} {q q' : psquare f₁₂ f₁₄ f₀₃ f₂₃}
(r : p = p') (s : q = q') : p ⬝v* q = p' ⬝v* q' :=
ap011 pvconcat r s
definition phinverse2 {f₁₀ : A₀₀ ≃* A₂₀} {f₁₂ : A₀₂ ≃* A₂₂} {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁}
(r : p = p') : p⁻¹ʰ* = p'⁻¹ʰ* :=
ap phinverse r
definition pvinverse2 {f₀₁ : A₀₀ ≃* A₀₂} {f₂₁ : A₂₀ ≃* A₂₂} {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁}
(r : p = p') : p⁻¹ᵛ* = p'⁻¹ᵛ* :=
ap pvinverse r
definition phomotopy_hconcat2 {q q' : f₀₁' ~* f₀₁} {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁}
(r : q = q') (s : p = p') : q ⬝ph* p = q' ⬝ph* p' :=
ap011 phomotopy_hconcat r s
definition hconcat_phomotopy2 {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁} {q q' : f₂₁' ~* f₂₁}
(r : p = p') (s : q = q') : p ⬝hp* q = p' ⬝hp* q' :=
ap011 hconcat_phomotopy r s
definition phomotopy_vconcat2 {q q' : f₁₀' ~* f₁₀} {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁}
(r : q = q') (s : p = p') : q ⬝pv* p = q' ⬝pv* p' :=
ap011 phomotopy_vconcat r s
definition vconcat_phomotopy2 {p p' : psquare f₁₀ f₁₂ f₀₁ f₂₁} {q q' : f₁₂' ~* f₁₂}
(r : p = p') (s : q = q') : p ⬝vp* q = p' ⬝vp* q' :=
ap011 vconcat_phomotopy r s
-- for consistency, should there be a second star here?
infix ` ◾h* `:79 := phconcat2
infix ` ◾v* `:79 := pvconcat2
infixl ` ◾hp* `:79 := hconcat_phomotopy2
infixr ` ◾ph* `:79 := phomotopy_hconcat2
infixl ` ◾vp* `:79 := vconcat_phomotopy2
infixr ` ◾pv* `:79 := phomotopy_vconcat2
postfix `⁻²ʰ*`:(max+1) := phinverse2
postfix `⁻²ᵛ*`:(max+1) := pvinverse2
end psquare
variables {X X' Y Y' Z : Type*}
definition pap1 [constructor] (X Y : Type*) : ppmap X Y →* ppmap (Ω X) (Ω Y) :=
pmap.mk ap1 (eq_of_phomotopy !ap1_pconst)
definition ap1_gen_const {A B : Type} {a₁ a₂ : A} (b : B) (p : a₁ = a₂) :
ap1_gen (const A b) idp idp p = idp :=
ap1_gen_idp_left (const A b) p ⬝ ap_constant p b
definition ap1_gen_compose_const_left
{A B C : Type} (c : C) (f : A → B) {a₁ a₂ : A} (p : a₁ = a₂) :
ap1_gen_compose (const B c) f idp idp idp idp p ⬝
ap1_gen_const c (ap1_gen f idp idp p) =
ap1_gen_const c p :=
begin induction p, reflexivity end
definition ap1_gen_compose_const_right
{A B C : Type} (g : B → C) (b : B) {a₁ a₂ : A} (p : a₁ = a₂) :
ap1_gen_compose g (const A b) idp idp idp idp p ⬝
ap (ap1_gen g idp idp) (ap1_gen_const b p) =
ap1_gen_const (g b) p :=
begin induction p, reflexivity end
definition ap1_pcompose_pconst_left {A B C : Type*} (f : A →* B) :
phsquare (ap1_pcompose (pconst B C) f)
(ap1_pconst A C)
(ap1_phomotopy (pconst_pcompose f))
(pwhisker_right (Ω→ f) (ap1_pconst B C) ⬝* pconst_pcompose (Ω→ f)) :=
begin
induction A with A a₀, induction B with B b₀, induction C with C c₀, induction f with f f₀,
esimp at *, induction f₀,
refine idp ◾** !trans_refl ⬝ _ ⬝ !refl_trans⁻¹ ⬝ !ap1_phomotopy_refl⁻¹ ◾** idp,
fapply phomotopy_eq,
{ exact ap1_gen_compose_const_left c₀ f },
{ reflexivity }
end
definition ap1_pcompose_pconst_right {A B C : Type*} (g : B →* C) :
phsquare (ap1_pcompose g (pconst A B))
(ap1_pconst A C)
(ap1_phomotopy (pcompose_pconst g))
(pwhisker_left (Ω→ g) (ap1_pconst A B) ⬝* pcompose_pconst (Ω→ g)) :=
begin
induction A with A a₀, induction B with B b₀, induction C with C c₀, induction g with g g₀,
esimp at *, induction g₀,
refine idp ◾** !trans_refl ⬝ _ ⬝ !refl_trans⁻¹ ⬝ !ap1_phomotopy_refl⁻¹ ◾** idp,
fapply phomotopy_eq,
{ exact ap1_gen_compose_const_right g b₀ },
{ reflexivity }
end
definition pap1_natural_left [constructor] (f : X' →* X) :
psquare (pap1 X Y) (pap1 X' Y) (ppcompose_right f) (ppcompose_right (Ω→ f)) :=
begin
fapply phomotopy_mk_ppmap,
{ intro g, exact !ap1_pcompose⁻¹* },
{ refine idp ◾** (ap phomotopy_of_eq (!ap1_eq_of_phomotopy ◾ idp ⬝ !eq_of_phomotopy_trans⁻¹) ⬝
!phomotopy_of_eq_of_phomotopy) ⬝ _ ⬝ (ap phomotopy_of_eq (!pcompose_right_eq_of_phomotopy ◾
idp ⬝ !eq_of_phomotopy_trans⁻¹) ⬝ !phomotopy_of_eq_of_phomotopy)⁻¹,
apply symm_trans_eq_of_eq_trans, exact (ap1_pcompose_pconst_left f)⁻¹ }
end
definition pap1_natural_right [constructor] (f : Y →* Y') :
psquare (pap1 X Y) (pap1 X Y') (ppcompose_left f) (ppcompose_left (Ω→ f)) :=
begin
fapply phomotopy_mk_ppmap,
{ intro g, exact !ap1_pcompose⁻¹* },
{ refine idp ◾** (ap phomotopy_of_eq (!ap1_eq_of_phomotopy ◾ idp ⬝ !eq_of_phomotopy_trans⁻¹) ⬝
!phomotopy_of_eq_of_phomotopy) ⬝ _ ⬝ (ap phomotopy_of_eq (!pcompose_left_eq_of_phomotopy ◾
idp ⬝ !eq_of_phomotopy_trans⁻¹) ⬝ !phomotopy_of_eq_of_phomotopy)⁻¹,
apply symm_trans_eq_of_eq_trans, exact (ap1_pcompose_pconst_right f)⁻¹ }
end
open sigma.ops prod
definition pequiv.sigma_char {A B : Type*} :
(A ≃* B) ≃ Σ(f : A →* B), (Σ(g : B →* A), f ∘* g ~* pid B) × (Σ(h : B →* A), h ∘* f ~* pid A) :=
begin
fapply equiv.MK,
{ intro f, exact ⟨f, (⟨pequiv.to_pinv1 f, pequiv.pright_inv f⟩,
⟨pequiv.to_pinv2 f, pequiv.pleft_inv f⟩)⟩, },
{ intro f, exact pequiv.mk' f.1 (pr1 f.2).1 (pr2 f.2).1 (pr1 f.2).2 (pr2 f.2).2 },
{ intro f, induction f with f v, induction v with hl hr, induction hl, induction hr,
reflexivity },
{ intro f, induction f, reflexivity }
end
definition is_contr_pright_inv (f : A ≃* B) : is_contr (Σ(g : B →* A), f ∘* g ~* pid B) :=
begin
fapply is_trunc_equiv_closed,
{ exact !fiber.sigma_char ⬝e sigma_equiv_sigma_right (λg, !pmap_eq_equiv) },
fapply is_contr_fiber_of_is_equiv,
exact pequiv.to_is_equiv (pequiv_ppcompose_left f)
end
definition is_contr_pleft_inv (f : A ≃* B) : is_contr (Σ(h : B →* A), h ∘* f ~* pid A) :=
begin
fapply is_trunc_equiv_closed,
{ exact !fiber.sigma_char ⬝e sigma_equiv_sigma_right (λg, !pmap_eq_equiv) },
fapply is_contr_fiber_of_is_equiv,
exact pequiv.to_is_equiv (pequiv_ppcompose_right f)
end
definition pequiv_eq_equiv (f g : A ≃* B) : (f = g) ≃ f ~* g :=
have Π(f : A →* B), is_prop ((Σ(g : B →* A), f ∘* g ~* pid B) × (Σ(h : B →* A), h ∘* f ~* pid A)),
begin
intro f, apply is_prop_of_imp_is_contr, intro v,
let f' := pequiv.sigma_char⁻¹ᵉ ⟨f, v⟩,
apply is_trunc_prod, exact is_contr_pright_inv f', exact is_contr_pleft_inv f'
end,
calc (f = g) ≃ (pequiv.sigma_char f = pequiv.sigma_char g)
: eq_equiv_fn_eq pequiv.sigma_char f g
... ≃ (f = g :> (A →* B)) : subtype_eq_equiv
... ≃ (f ~* g) : pmap_eq_equiv f g
definition pequiv_eq {f g : A ≃* B} (H : f ~* g) : f = g :=
(pequiv_eq_equiv f g)⁻¹ᵉ H
open algebra
definition pequiv_of_isomorphism_of_eq {G₁ G₂ : Group} (p : G₁ = G₂) :
pequiv_of_isomorphism (isomorphism_of_eq p) = pequiv_of_eq (ap pType_of_Group p) :=
begin
induction p,
apply pequiv_eq,
fapply phomotopy.mk,
{ intro g, reflexivity },
{ apply is_prop.elim }
end
end pointed
|
17f1048f4d14669c54b99532216b5c49132c0245 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/if_dollar_prec.lean | 5a07d154da3b938b57f71171fdd90119b50aab4f | [
"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 | 34 | lean | #check if tt then tt else id $ ff
|
cc3f6b3637e4c0e2cad956dfa66083cd45625f36 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/measure_theory/prod.lean | 9c011771168af9b9f248f166ecba88e1d1e9e0aa | [] | 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 | 45,481 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.measure_theory.giry_monad
import Mathlib.measure_theory.set_integral
import Mathlib.PostPort
universes u_1 u_3 u_2 u_6 u_5 u_7
namespace Mathlib
/-!
# The product measure
In this file we define and prove properties about the binary product measure. If `α` and `β` have
σ-finite measures `μ` resp. `ν` then `α × β` can be equipped with a σ-finite measure `μ.prod ν` that
satisfies `(μ.prod ν) s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`.
We also have `(μ.prod ν) (s.prod t) = μ s * ν t`, i.e. the measure of a rectangle is the product of
the measures of the sides.
We also prove Tonelli's theorem and Fubini's theorem.
## Main definition
* `measure_theory.measure.prod`: The product of two measures.
## Main results
* `measure_theory.measure.prod_apply` states `μ.prod ν s = ∫⁻ x, ν {y | (x, y) ∈ s} ∂μ`
for measurable `s`. `measure_theory.measure.prod_apply_symm` is the reversed version.
* `measure_theory.measure.prod_prod` states `μ.prod ν (s.prod t) = μ s * ν t` for measurable sets
`s` and `t`.
* `measure_theory.lintegral_prod`: Tonelli's theorem. It states that for a measurable function
`α × β → ennreal` we have `∫⁻ z, f z ∂(μ.prod ν) = ∫⁻ x, ∫⁻ y, f (x, y) ∂ν ∂μ`. The version
for functions `α → β → ennreal` is reversed, and called `lintegral_lintegral`. Both versions have
a variant with `_symm` appended, where the order of integration is reversed.
The lemma `measurable.lintegral_prod_right'` states that the inner integral of the right-hand side
is measurable.
* `measure_theory.integrable_prod_iff` states that a binary function is integrable iff both
* `y ↦ f (x, y)` is integrable for almost every `x`, and
* the function `x ↦ ∫ ∥f (x, y)∥ dy` is integrable.
* `measure_theory.integral_prod`: Fubini's theorem. It states that for a integrable function
`α × β → E` (where `E` is a second countable Banach space) we have
`∫ z, f z ∂(μ.prod ν) = ∫ x, ∫ y, f (x, y) ∂ν ∂μ`. This theorem has the same variants as
Tonelli's theorem. The lemma `measure_theory.integrable.integral_prod_right` states that the
inner integral of the right-hand side is integrable.
## Implementation Notes
Many results are proven twice, once for functions in curried form (`α → β → γ`) and one for
functions in uncurried form (`α × β → γ`). The former often has an assumption
`measurable (uncurry f)`, which could be inconvenient to discharge, but for the latter it is more
common that the function has to be given explicitly, since Lean cannot synthesize the function by
itself. We name the lemmas about the uncurried form with a prime.
Tonelli's theorem and Fubini's theorem have a different naming scheme, since the version for the
uncurried version is reversed.
## Tags
product measure, Fubini's theorem, Tonelli's theorem, Fubini-Tonelli theorem
-/
/-- Rectangles formed by π-systems form a π-system. -/
theorem is_pi_system.prod {α : Type u_1} {β : Type u_3} {C : set (set α)} {D : set (set β)} (hC : is_pi_system C) (hD : is_pi_system D) : is_pi_system (set.image2 set.prod C D) := sorry
/-- Rectangles of countably spanning sets are countably spanning. -/
theorem is_countably_spanning.prod {α : Type u_1} {β : Type u_3} {C : set (set α)} {D : set (set β)} (hC : is_countably_spanning C) (hD : is_countably_spanning D) : is_countably_spanning (set.image2 set.prod C D) := sorry
/-! ### Measurability
Before we define the product measure, we can talk about the measurability of operations on binary
functions. We show that if `f` is a binary measurable function, then the function that integrates
along one of the variables (using either the Lebesgue or Bochner integral) is measurable.
-/
/-- The product of generated σ-algebras is the one generated by rectangles, if both generating sets
are countably spanning. -/
theorem generate_from_prod_eq {α : Type u_1} {β : Type u_2} {C : set (set α)} {D : set (set β)} (hC : is_countably_spanning C) (hD : is_countably_spanning D) : prod.measurable_space = measurable_space.generate_from (set.image2 set.prod C D) := sorry
/-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D`
generate the σ-algebra on `α × β`. -/
theorem generate_from_eq_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {C : set (set α)} {D : set (set β)} (hC : measurable_space.generate_from C = _inst_1) (hD : measurable_space.generate_from D = _inst_3) (h2C : is_countably_spanning C) (h2D : is_countably_spanning D) : measurable_space.generate_from (set.image2 set.prod C D) = prod.measurable_space := sorry
/-- The product σ-algebra is generated from boxes, i.e. `s.prod t` for sets `s : set α` and
`t : set β`. -/
theorem generate_from_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] : measurable_space.generate_from
(set.image2 set.prod (set_of fun (s : set α) => is_measurable s) (set_of fun (t : set β) => is_measurable t)) =
prod.measurable_space :=
generate_from_eq_prod measurable_space.generate_from_is_measurable measurable_space.generate_from_is_measurable
is_countably_spanning_is_measurable is_countably_spanning_is_measurable
/-- Rectangles form a π-system. -/
theorem is_pi_system_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] : is_pi_system
(set.image2 set.prod (set_of fun (s : set α) => is_measurable s) (set_of fun (t : set β) => is_measurable t)) :=
is_pi_system.prod measurable_space.is_pi_system_is_measurable measurable_space.is_pi_system_is_measurable
/-- If `ν` is a finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is
a measurable function. `measurable_measure_prod_mk_left` is strictly more general. -/
theorem measurable_measure_prod_mk_left_finite {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [measure_theory.finite_measure ν] {s : set (α × β)} (hs : is_measurable s) : measurable fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s) := sorry
/-- If `ν` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `x ↦ ν { y | (x, y) ∈ s }` is
a measurable function. -/
theorem measurable_measure_prod_mk_left {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] {s : set (α × β)} (hs : is_measurable s) : measurable fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s) := sorry
/-- If `μ` is a σ-finite measure, and `s ⊆ α × β` is measurable, then `y ↦ μ { x | (x, y) ∈ s }` is
a measurable function. -/
theorem measurable_measure_prod_mk_right {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [measure_theory.sigma_finite μ] {s : set (α × β)} (hs : is_measurable s) : measurable fun (y : β) => coe_fn μ ((fun (x : α) => (x, y)) ⁻¹' s) :=
measurable_measure_prod_mk_left (iff.mpr is_measurable_swap_iff hs)
theorem measurable.map_prod_mk_left {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] : measurable fun (x : α) => coe_fn (measure_theory.measure.map (Prod.mk x)) ν := sorry
theorem measurable.map_prod_mk_right {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [measure_theory.sigma_finite μ] : measurable fun (y : β) => coe_fn (measure_theory.measure.map fun (x : α) => (x, y)) μ := sorry
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable. -/
theorem measurable.lintegral_prod_right' {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] {f : α × β → ennreal} (hf : measurable f) : measurable fun (x : α) => measure_theory.lintegral ν fun (y : β) => f (x, y) := sorry
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
theorem measurable.lintegral_prod_right {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] {f : α → β → ennreal} (hf : measurable (function.uncurry f)) : measurable fun (x : α) => measure_theory.lintegral ν fun (y : β) => f x y :=
measurable.lintegral_prod_right' hf
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable. -/
theorem measurable.lintegral_prod_left' {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [measure_theory.sigma_finite μ] {f : α × β → ennreal} (hf : measurable f) : measurable fun (y : β) => measure_theory.lintegral μ fun (x : α) => f (x, y) :=
measurable.lintegral_prod_right' (iff.mpr measurable_swap_iff hf)
/-- The Lebesgue integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Tonelli's theorem is measurable.
This version has the argument `f` in curried form. -/
theorem measurable.lintegral_prod_left {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [measure_theory.sigma_finite μ] {f : α → β → ennreal} (hf : measurable (function.uncurry f)) : measurable fun (y : β) => measure_theory.lintegral μ fun (x : α) => f x y :=
measurable.lintegral_prod_left' hf
theorem is_measurable_integrable {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [normed_group E] [measurable_space E] [measure_theory.sigma_finite ν] [opens_measurable_space E] {f : α → β → E} (hf : measurable (function.uncurry f)) : is_measurable (set_of fun (x : α) => measure_theory.integrable (f x)) := sorry
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable.
This version has `f` in curried form. -/
theorem measurable.integral_prod_right {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [normed_group E] [measurable_space E] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [measure_theory.sigma_finite ν] {f : α → β → E} (hf : measurable (function.uncurry f)) : measurable fun (x : α) => measure_theory.integral ν fun (y : β) => f x y := sorry
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable. -/
theorem measurable.integral_prod_right' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {ν : measure_theory.measure β} [normed_group E] [measurable_space E] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [measure_theory.sigma_finite ν] {f : α × β → E} (hf : measurable f) : measurable fun (x : α) => measure_theory.integral ν fun (y : β) => f (x, y) :=
measurable.integral_prod_right (eq.mp (Eq._oldrec (Eq.refl (measurable f)) (Eq.symm (function.uncurry_curry f))) hf)
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable.
This version has `f` in curried form. -/
theorem measurable.integral_prod_left {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [normed_group E] [measurable_space E] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [measure_theory.sigma_finite μ] {f : α → β → E} (hf : measurable (function.uncurry f)) : measurable fun (y : β) => measure_theory.integral μ fun (x : α) => f x y :=
measurable.integral_prod_right' (measurable.comp hf measurable_swap)
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
the symmetric version of Fubini's theorem is measurable. -/
theorem measurable.integral_prod_left' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} [normed_group E] [measurable_space E] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [measure_theory.sigma_finite μ] {f : α × β → E} (hf : measurable f) : measurable fun (y : β) => measure_theory.integral μ fun (x : α) => f (x, y) :=
measurable.integral_prod_right' (measurable.comp hf measurable_swap)
/-! ### The product measure -/
namespace measure_theory
namespace measure
/-- The binary product of measures. They are defined for arbitrary measures, but we basically
prove all properties under the assumption that at least one of them is σ-finite. -/
protected def prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] (μ : measure α) (ν : measure β) : measure (α × β) :=
bind μ fun (x : α) => coe_fn (map (Prod.mk x)) ν
protected instance prod.measure_space {α : Type u_1} {β : Type u_2} [measure_space α] [measure_space β] : measure_space (α × β) :=
measure_space.mk (measure.prod volume volume)
theorem prod_apply {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set (α × β)} (hs : is_measurable s) : coe_fn (measure.prod μ ν) s = lintegral μ fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s) := sorry
@[simp] theorem prod_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set α} {t : set β} (hs : is_measurable s) (ht : is_measurable t) : coe_fn (measure.prod μ ν) (set.prod s t) = coe_fn μ s * coe_fn ν t := sorry
/-- If we don't assume measurability of `s` and `t`, we can bound the measure of their product. -/
theorem prod_prod_le {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] (s : set α) (t : set β) : coe_fn (measure.prod μ ν) (set.prod s t) ≤ coe_fn μ s * coe_fn ν t := sorry
theorem ae_measure_lt_top {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set (α × β)} (hs : is_measurable s) (h2s : coe_fn (measure.prod μ ν) s < ⊤) : filter.eventually (fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s) < ⊤) (ae μ) := sorry
theorem integrable_measure_prod_mk_left {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set (α × β)} (hs : is_measurable s) (h2s : coe_fn (measure.prod μ ν) s < ⊤) : integrable fun (x : α) => ennreal.to_real (coe_fn ν (Prod.mk x ⁻¹' s)) := sorry
/-- Note: the assumption `hs` cannot be dropped. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
theorem measure_prod_null {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set (α × β)} (hs : is_measurable s) : coe_fn (measure.prod μ ν) s = 0 ↔ filter.eventually_eq (ae μ) (fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s)) 0 := sorry
/-- Note: the converse is not true without assuming that `s` is measurable. For a counterexample,
see Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
theorem measure_ae_null_of_prod_null {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {s : set (α × β)} (h : coe_fn (measure.prod μ ν) s = 0) : filter.eventually_eq (ae μ) (fun (x : α) => coe_fn ν (Prod.mk x ⁻¹' s)) 0 := sorry
/-- Note: the converse is not true. For a counterexample, see
Walter Rudin *Real and Complex Analysis*, example (c) in section 8.9. -/
theorem ae_ae_of_ae_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {p : α × β → Prop} (h : filter.eventually (fun (z : α × β) => p z) (ae (measure.prod μ ν))) : filter.eventually (fun (x : α) => filter.eventually (fun (y : β) => p (x, y)) (ae ν)) (ae μ) :=
measure_ae_null_of_prod_null h
/-- `μ.prod ν` has finite spanning sets in rectangles of finite spanning sets. -/
def finite_spanning_sets_in.prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} {C : set (set α)} {D : set (set β)} (hμ : finite_spanning_sets_in μ C) (hν : finite_spanning_sets_in ν D) (hC : ∀ (s : set α), s ∈ C → is_measurable s) (hD : ∀ (t : set β), t ∈ D → is_measurable t) : finite_spanning_sets_in (measure.prod μ ν) (set.image2 set.prod C D) :=
finite_spanning_sets_in.mk
(fun (n : ℕ) =>
set.prod (finite_spanning_sets_in.set hμ (prod.fst (nat.unpair n)))
(finite_spanning_sets_in.set hν (prod.snd (nat.unpair n))))
sorry sorry sorry
protected instance prod.sigma_finite {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] : sigma_finite (measure.prod μ ν) := sorry
/-- Measures on a product space are equal the product measure if they are equal on rectangles
with as sides sets that generate the corresponding σ-algebras. -/
theorem prod_eq_generate_from {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} {C : set (set α)} {D : set (set β)} (hC : measurable_space.generate_from C = _inst_1) (hD : measurable_space.generate_from D = _inst_3) (h2C : is_pi_system C) (h2D : is_pi_system D) (h3C : finite_spanning_sets_in μ C) (h3D : finite_spanning_sets_in ν D) {μν : measure (α × β)} (h₁ : ∀ (s : set α), s ∈ C → ∀ (t : set β), t ∈ D → coe_fn μν (set.prod s t) = coe_fn μ s * coe_fn ν t) : measure.prod μ ν = μν := sorry
/-- Measures on a product space are equal to the product measure if they are equal on rectangles. -/
theorem prod_eq {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] {μν : measure (α × β)} (h : ∀ (s : set α) (t : set β), is_measurable s → is_measurable t → coe_fn μν (set.prod s t) = coe_fn μ s * coe_fn ν t) : measure.prod μ ν = μν := sorry
theorem prod_swap {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] : coe_fn (map prod.swap) (measure.prod μ ν) = measure.prod ν μ := sorry
theorem prod_apply_symm {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] {s : set (α × β)} (hs : is_measurable s) : coe_fn (measure.prod μ ν) s = lintegral ν fun (y : β) => coe_fn μ ((fun (x : α) => (x, y)) ⁻¹' s) := sorry
theorem prod_assoc_prod {α : Type u_1} {β : Type u_3} {γ : Type u_5} [measurable_space α] [measurable_space β] [measurable_space γ] {μ : measure α} {ν : measure β} {τ : measure γ} [sigma_finite ν] [sigma_finite μ] [sigma_finite τ] : coe_fn (map ⇑measurable_equiv.prod_assoc) (measure.prod (measure.prod μ ν) τ) = measure.prod μ (measure.prod ν τ) := sorry
/-! ### The product of specific measures -/
theorem prod_restrict {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] {s : set α} {t : set β} (hs : is_measurable s) (ht : is_measurable t) : measure.prod (restrict μ s) (restrict ν t) = restrict (measure.prod μ ν) (set.prod s t) := sorry
theorem prod_dirac {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} [sigma_finite μ] (y : β) : measure.prod μ (dirac y) = coe_fn (map fun (x : α) => (x, y)) μ := sorry
theorem dirac_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure β} [sigma_finite ν] (x : α) : measure.prod (dirac x) ν = coe_fn (map (Prod.mk x)) ν := sorry
theorem dirac_prod_dirac {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {x : α} {y : β} : measure.prod (dirac x) (dirac y) = dirac (x, y) := sorry
theorem prod_sum {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} [sigma_finite μ] {ι : Type u_2} [fintype ι] (ν : ι → measure β) [∀ (i : ι), sigma_finite (ν i)] : measure.prod μ (sum ν) = sum fun (i : ι) => measure.prod μ (ν i) := sorry
theorem sum_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {ν : measure β} [sigma_finite ν] {ι : Type u_2} [fintype ι] (μ : ι → measure α) [∀ (i : ι), sigma_finite (μ i)] : measure.prod (sum μ) ν = sum fun (i : ι) => measure.prod (μ i) ν := sorry
theorem prod_add {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] (ν' : measure β) [sigma_finite ν'] : measure.prod μ (ν + ν') = measure.prod μ ν + measure.prod μ ν' := sorry
theorem add_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] (μ' : measure α) [sigma_finite μ'] : measure.prod (μ + μ') ν = measure.prod μ ν + measure.prod μ' ν := sorry
end measure
end measure_theory
theorem ae_measurable.prod_swap {α : Type u_1} {β : Type u_3} {γ : Type u_5} [measurable_space α] [measurable_space β] [measurable_space γ] {μ : measure_theory.measure α} {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] [measure_theory.sigma_finite μ] {f : α × β → γ} (hf : ae_measurable f) : ae_measurable fun (z : β × α) => f (prod.swap z) :=
ae_measurable.comp_measurable
(eq.mp (Eq._oldrec (Eq.refl (ae_measurable f)) (Eq.symm measure_theory.measure.prod_swap)) hf) measurable_swap
/-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of)
Fubini's theorem is measurable. -/
theorem ae_measurable.integral_prod_right' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure_theory.measure α} {ν : measure_theory.measure β} [normed_group E] [measurable_space E] [measure_theory.sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [borel_space E] [complete_space E] {f : α × β → E} (hf : ae_measurable f) : ae_measurable fun (x : α) => measure_theory.integral ν fun (y : β) => f (x, y) := sorry
theorem ae_measurable.prod_mk_left {α : Type u_1} {β : Type u_3} {γ : Type u_5} [measurable_space α] [measurable_space β] [measurable_space γ] {μ : measure_theory.measure α} {ν : measure_theory.measure β} [measure_theory.sigma_finite ν] {f : α × β → γ} (hf : ae_measurable f) : filter.eventually (fun (x : α) => ae_measurable fun (y : β) => f (x, y)) (measure_theory.measure.ae μ) := sorry
namespace measure_theory
/-! ### The Lebesgue integral on a product -/
theorem lintegral_prod_swap {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] (f : α × β → ennreal) (hf : ae_measurable f) : (lintegral (measure.prod ν μ) fun (z : β × α) => f (prod.swap z)) = lintegral (measure.prod μ ν) fun (z : α × β) => f z := sorry
/-- Tonelli's Theorem: For `ennreal`-valued measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
theorem lintegral_prod {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] (f : α × β → ennreal) (hf : measurable f) : (lintegral (measure.prod μ ν) fun (z : α × β) => f z) = lintegral μ fun (x : α) => lintegral ν fun (y : β) => f (x, y) := sorry
/-- Tonelli's Theorem: For `ennreal`-valued almost everywhere measurable functions on `α × β`,
the integral of `f` is equal to the iterated integral. -/
theorem lintegral_prod' {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] (f : α × β → ennreal) (hf : ae_measurable f) : (lintegral (measure.prod μ ν) fun (z : α × β) => f z) = lintegral μ fun (x : α) => lintegral ν fun (y : β) => f (x, y) := sorry
/-- The symmetric verion of Tonelli's Theorem: For `ennreal`-valued almost everywhere measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
theorem lintegral_prod_symm' {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] (f : α × β → ennreal) (hf : ae_measurable f) : (lintegral (measure.prod μ ν) fun (z : α × β) => f z) = lintegral ν fun (y : β) => lintegral μ fun (x : α) => f (x, y) := sorry
/-- The symmetric verion of Tonelli's Theorem: For `ennreal`-valued measurable
functions on `α × β`, the integral of `f` is equal to the iterated integral, in reverse order. -/
theorem lintegral_prod_symm {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] (f : α × β → ennreal) (hf : measurable f) : (lintegral (measure.prod μ ν) fun (z : α × β) => f z) = lintegral ν fun (y : β) => lintegral μ fun (x : α) => f (x, y) :=
lintegral_prod_symm' f (measurable.ae_measurable hf)
/-- The reversed version of Tonelli's Theorem. In this version `f` is in curried form, which makes
it easier for the elaborator to figure out `f` automatically. -/
theorem lintegral_lintegral {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {f : α → β → ennreal} (hf : measurable (function.uncurry f)) : (lintegral μ fun (x : α) => lintegral ν fun (y : β) => f x y) =
lintegral (measure.prod μ ν) fun (z : α × β) => f (prod.fst z) (prod.snd z) :=
Eq.symm (lintegral_prod (function.uncurry f) hf)
/-- The reversed version of Tonelli's Theorem (symmetric version). In this version `f` is in curried
form, which makes it easier for the elaborator to figure out `f` automatically. -/
theorem lintegral_lintegral_symm {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] {f : α → β → ennreal} (hf : measurable (function.uncurry f)) : (lintegral μ fun (x : α) => lintegral ν fun (y : β) => f x y) =
lintegral (measure.prod ν μ) fun (z : β × α) => f (prod.snd z) (prod.fst z) :=
Eq.symm (lintegral_prod_symm (function.uncurry f ∘ prod.swap) (measurable.comp hf measurable_swap))
/-- Change the order of Lebesgue integration. -/
theorem lintegral_lintegral_swap {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] [sigma_finite μ] {f : α → β → ennreal} (hf : measurable (function.uncurry f)) : (lintegral μ fun (x : α) => lintegral ν fun (y : β) => f x y) =
lintegral ν fun (y : β) => lintegral μ fun (x : α) => f x y :=
Eq.trans (lintegral_lintegral hf) (lintegral_prod_symm (fun (z : α × β) => f (prod.fst z) (prod.snd z)) hf)
theorem lintegral_prod_mul {α : Type u_1} {β : Type u_3} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [sigma_finite ν] {f : α → ennreal} {g : β → ennreal} (hf : measurable f) (hg : measurable g) : (lintegral (measure.prod μ ν) fun (z : α × β) => f (prod.fst z) * g (prod.snd z)) =
(lintegral μ fun (x : α) => f x) * lintegral ν fun (y : β) => g y := sorry
/-! ### Integrability on a product -/
theorem integrable.swap {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} (hf : integrable f) : integrable (f ∘ prod.swap) := sorry
theorem integrable_swap_iff {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} : integrable (f ∘ prod.swap) ↔ integrable f := sorry
theorem has_finite_integral_prod_iff {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] {f : α × β → E} (h1f : measurable f) : has_finite_integral f ↔
filter.eventually (fun (x : α) => has_finite_integral fun (y : β) => f (x, y)) (measure.ae μ) ∧
has_finite_integral fun (x : α) => integral ν fun (y : β) => norm (f (x, y)) := sorry
theorem has_finite_integral_prod_iff' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] {f : α × β → E} (h1f : ae_measurable f) : has_finite_integral f ↔
filter.eventually (fun (x : α) => has_finite_integral fun (y : β) => f (x, y)) (measure.ae μ) ∧
has_finite_integral fun (x : α) => integral ν fun (y : β) => norm (f (x, y)) := sorry
/-- A binary function is integrable if the function `y ↦ f (x, y)` is integrable for almost every
`x` and the function `x ↦ ∫ ∥f (x, y)∥ dy` is integrable. -/
theorem integrable_prod_iff {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] {f : α × β → E} (h1f : ae_measurable f) : integrable f ↔
filter.eventually (fun (x : α) => integrable fun (y : β) => f (x, y)) (measure.ae μ) ∧
integrable fun (x : α) => integral ν fun (y : β) => norm (f (x, y)) := sorry
/-- A binary function is integrable if the function `x ↦ f (x, y)` is integrable for almost every
`y` and the function `y ↦ ∫ ∥f (x, y)∥ dx` is integrable. -/
theorem integrable_prod_iff' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} (h1f : ae_measurable f) : integrable f ↔
filter.eventually (fun (y : β) => integrable fun (x : α) => f (x, y)) (measure.ae ν) ∧
integrable fun (y : β) => integral μ fun (x : α) => norm (f (x, y)) := sorry
theorem integrable.prod_left_ae {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} (hf : integrable f) : filter.eventually (fun (y : β) => integrable fun (x : α) => f (x, y)) (measure.ae ν) :=
and.left (iff.mp (integrable_prod_iff' (integrable.ae_measurable hf)) hf)
theorem integrable.prod_right_ae {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} (hf : integrable f) : filter.eventually (fun (x : α) => integrable fun (y : β) => f (x, y)) (measure.ae μ) :=
integrable.prod_left_ae (integrable.swap hf)
theorem integrable.integral_norm_prod_left {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] {f : α × β → E} (hf : integrable f) : integrable fun (x : α) => integral ν fun (y : β) => norm (f (x, y)) :=
and.right (iff.mp (integrable_prod_iff (integrable.ae_measurable hf)) hf)
theorem integrable.integral_norm_prod_right {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [opens_measurable_space E] [sigma_finite μ] {f : α × β → E} (hf : integrable f) : integrable fun (y : β) => integral μ fun (x : α) => norm (f (x, y)) :=
integrable.integral_norm_prod_left (integrable.swap hf)
theorem integrable.integral_prod_left {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] {f : α × β → E} (hf : integrable f) : integrable fun (x : α) => integral ν fun (y : β) => f (x, y) := sorry
theorem integrable.integral_prod_right {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} (hf : integrable f) : integrable fun (y : β) => integral μ fun (x : α) => f (x, y) :=
integrable.integral_prod_left (integrable.swap hf)
/-! ### The Bochner integral on a product -/
theorem integral_prod_swap {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] (f : α × β → E) (hf : ae_measurable f) : (integral (measure.prod ν μ) fun (z : β × α) => f (prod.swap z)) = integral (measure.prod μ ν) fun (z : α × β) => f z := sorry
/-! Some rules about the sum/difference of double integrals. They follow from `integral_add`, but
we separate them out as separate lemmas, because they involve quite some steps. -/
/-- Integrals commute with addition inside another integral. `F` can be any function. -/
theorem integral_fn_integral_add {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {E' : Type u_7} [measurable_space E'] [normed_group E'] [borel_space E'] [complete_space E'] [normed_space ℝ E'] [topological_space.second_countable_topology E'] {f : α × β → E} {g : α × β → E} (F : E → E') (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => F (integral ν fun (y : β) => f (x, y) + g (x, y))) =
integral μ fun (x : α) => F ((integral ν fun (y : β) => f (x, y)) + integral ν fun (y : β) => g (x, y)) := sorry
/-- Integrals commute with subtraction inside another integral.
`F` can be any measurable function. -/
theorem integral_fn_integral_sub {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {E' : Type u_7} [measurable_space E'] [normed_group E'] [borel_space E'] [complete_space E'] [normed_space ℝ E'] [topological_space.second_countable_topology E'] {f : α × β → E} {g : α × β → E} (F : E → E') (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => F (integral ν fun (y : β) => f (x, y) - g (x, y))) =
integral μ fun (x : α) => F ((integral ν fun (y : β) => f (x, y)) - integral ν fun (y : β) => g (x, y)) := sorry
/-- Integrals commute with subtraction inside a lower Lebesgue integral.
`F` can be any function. -/
theorem lintegral_fn_integral_sub {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} {g : α × β → E} (F : E → ennreal) (hf : integrable f) (hg : integrable g) : (lintegral μ fun (x : α) => F (integral ν fun (y : β) => f (x, y) - g (x, y))) =
lintegral μ fun (x : α) => F ((integral ν fun (y : β) => f (x, y)) - integral ν fun (y : β) => g (x, y)) := sorry
/-- Double integrals commute with addition. -/
theorem integral_integral_add {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} {g : α × β → E} (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => integral ν fun (y : β) => f (x, y) + g (x, y)) =
(integral μ fun (x : α) => integral ν fun (y : β) => f (x, y)) +
integral μ fun (x : α) => integral ν fun (y : β) => g (x, y) :=
Eq.trans (integral_fn_integral_add id hf hg)
(integral_add (integrable.integral_prod_left hf) (integrable.integral_prod_left hg))
/-- Double integrals commute with addition. This is the version with `(f + g) (x, y)`
(instead of `f (x, y) + g (x, y)`) in the LHS. -/
theorem integral_integral_add' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} {g : α × β → E} (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => integral ν fun (y : β) => Add.add f g (x, y)) =
(integral μ fun (x : α) => integral ν fun (y : β) => f (x, y)) +
integral μ fun (x : α) => integral ν fun (y : β) => g (x, y) :=
integral_integral_add hf hg
/-- Double integrals commute with subtraction. -/
theorem integral_integral_sub {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} {g : α × β → E} (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => integral ν fun (y : β) => f (x, y) - g (x, y)) =
(integral μ fun (x : α) => integral ν fun (y : β) => f (x, y)) -
integral μ fun (x : α) => integral ν fun (y : β) => g (x, y) :=
Eq.trans (integral_fn_integral_sub id hf hg)
(integral_sub (integrable.integral_prod_left hf) (integrable.integral_prod_left hg))
/-- Double integrals commute with subtraction. This is the version with `(f - g) (x, y)`
(instead of `f (x, y) - g (x, y)`) in the LHS. -/
theorem integral_integral_sub' {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α × β → E} {g : α × β → E} (hf : integrable f) (hg : integrable g) : (integral μ fun (x : α) => integral ν fun (y : β) => Sub.sub f g (x, y)) =
(integral μ fun (x : α) => integral ν fun (y : β) => f (x, y)) -
integral μ fun (x : α) => integral ν fun (y : β) => g (x, y) :=
integral_integral_sub hf hg
/-- The map that sends an L¹-function `f : α × β → E` to `∫∫f` is continuous. -/
theorem continuous_integral_integral {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] : continuous
fun (f : l1 (α × β) E (measure.prod μ ν)) => integral μ fun (x : α) => integral ν fun (y : β) => coe_fn f (x, y) := sorry
/-- Fubini's Theorem: For integrable functions on `α × β`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
`integrable_prod_iff` can be useful to show that the function in question in integrable.
`measure_theory.integrable.integral_prod_right` is useful to show that the inner integral
of the right-hand side is integrable. -/
theorem integral_prod {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] (f : α × β → E) (hf : integrable f) : (integral (measure.prod μ ν) fun (z : α × β) => f z) = integral μ fun (x : α) => integral ν fun (y : β) => f (x, y) := sorry
/-- Symmetric version of Fubini's Theorem: For integrable functions on `α × β`,
the Bochner integral of `f` is equal to the iterated Bochner integral.
This version has the integrals on the right-hand side in the other order. -/
theorem integral_prod_symm {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] (f : α × β → E) (hf : integrable f) : (integral (measure.prod μ ν) fun (z : α × β) => f z) = integral ν fun (y : β) => integral μ fun (x : α) => f (x, y) := sorry
/-- Reversed version of Fubini's Theorem. -/
theorem integral_integral {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α → β → E} (hf : integrable (function.uncurry f)) : (integral μ fun (x : α) => integral ν fun (y : β) => f x y) =
integral (measure.prod μ ν) fun (z : α × β) => f (prod.fst z) (prod.snd z) :=
Eq.symm (integral_prod (function.uncurry f) hf)
/-- Reversed version of Fubini's Theorem (symmetric version). -/
theorem integral_integral_symm {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α → β → E} (hf : integrable (function.uncurry f)) : (integral μ fun (x : α) => integral ν fun (y : β) => f x y) =
integral (measure.prod ν μ) fun (z : β × α) => f (prod.snd z) (prod.fst z) :=
Eq.symm (integral_prod_symm (function.uncurry f ∘ prod.swap) (integrable.swap hf))
/-- Change the order of Bochner integration. -/
theorem integral_integral_swap {α : Type u_1} {β : Type u_3} {E : Type u_6} [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β} [normed_group E] [measurable_space E] [sigma_finite ν] [topological_space.second_countable_topology E] [normed_space ℝ E] [complete_space E] [borel_space E] [sigma_finite μ] {f : α → β → E} (hf : integrable (function.uncurry f)) : (integral μ fun (x : α) => integral ν fun (y : β) => f x y) = integral ν fun (y : β) => integral μ fun (x : α) => f x y :=
Eq.trans (integral_integral hf) (integral_prod_symm (fun (z : α × β) => f (prod.fst z) (prod.snd z)) hf)
|
74a150b199aed6d99ee76a0f6c21d4ea0803f86d | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/tst13.lean | 56367f5836fb4608b1aaf44f6bd56bc96805b723 | [
"Apache-2.0"
] | permissive | codyroux/lean0.1 | 1ce92751d664aacff0529e139083304a7bbc8a71 | 0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef | refs/heads/master | 1,610,830,535,062 | 1,402,150,480,000 | 1,402,150,480,000 | 19,588,851 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 267 | lean | print fun x : Bool, (fun x : Bool, x).
print let x := true,
y := true
in (let z := x /\ y,
f := (fun x y : Bool, x /\ y =
y /\ x =
x \/ y \/ y)
in (f x y) \/ z)
|
555e3855a0e755510201598222aa1dd2a7a95d63 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0716.lean | 31a7a9bbfd999984d676a043ca01aa3e90047f3f | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 538 | lean | import data.list.basic
open list
universe u
variables {α : Type} (x y z : α) (xs ys zs : list α)
def mk_symm (xs : list α) := xs ++ reverse xs
theorem reverse_mk_symm (xs : list α) :
reverse (mk_symm xs) = mk_symm xs :=
by simp [mk_symm]
example (xs ys : list ℕ) :
reverse (xs ++ mk_symm ys) = mk_symm ys ++ reverse xs :=
by simp [reverse_mk_symm]
example (xs ys : list ℕ) (p : list ℕ → Prop) (h : p (reverse (xs ++ (mk_symm ys)))) :
p (mk_symm ys ++ reverse xs) :=
by simp [reverse_mk_symm] at h; assumption
|
47331266c718a2acec93c472b5cafea0768143e4 | 420f29e297b60897d18482fe0761beb846b855a3 | /src/demo.lean | d22dbc356eacf656ccaebe0e733b4e14a4b601fb | [] | no_license | robertylewis/simons | 73d577779f10179a5c15ff9bf5ce7d3d7576e93e | 3b49971f17470a0a28f889153c55caa9dbfe6986 | refs/heads/master | 1,692,960,422,913 | 1,636,199,246,000 | 1,636,208,322,000 | 424,988,327 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,817 | lean | import analysis.special_functions.trigonometric.arctan
import ring_theory.witt_vector.compare
noncomputable theory
local notation `ℤ/3ℤ` := zmod 3
open real
open_locale real
/-!
# Machine-Checked proofs in Lean
## Introduction
I'm Rob Lewis. Just joined the Brown CS department this fall.
My goal with this talk:
* Introduce you to the idea of proof assistants
* Show you (quickly!) what it's like to use a proof assistant
* Explain the structure and goals of Lean's library mathlib
## Following along
* Install Lean and its supporting tools:
<https://leanprover-community.github.io/get_started.html>
* `leanproject get robertylewis/simons`
* Open the `simons` *directory* in VSCode (File -> Open Folder...)
## What is a proof assistant?
A proof assistant provides a language (or languages) to:
* define kinds of objects
* define particular objects
* state properties of those objects
* prove that these properties hold
It also provides a tool to mechanically check these proofs,
down to logical axioms.
Ideally, we want all of this to be human-readable.
-/
#check ℕ
#check 0
#check ∀ n : ℕ, 0 ≤ n
lemma my_first_lemma : ∀ n : ℕ, 0 ≤ n :=
begin
intro n,
apply nat.zero_le,
end
/-!
Historically these tools have been applied with "objects" = "programs".
But nothing inherently computational about them.
Depending on our choice of languages,
we can talk about totally abstract things.
-/
#check category_theory.category
#check differentiable
#check fderiv
/-!
### Why formalize mathematics?
* Verified proofs are very very likely to be correct
* Full specifications, no ambiguity
* Age of data: machine-readable proofs are machine-processable
* Applications in AI
* Applications in education
* It's incredibly addictive
Big leaf node projects may be exciting,
but all of this requires *libraries*.
## A demo: complex numbers
-/
namespace demo
structure complex :=
(re : ℝ)
(im : ℝ)
def i : complex :=
{ re := 0,
im := 1 }
def add (c1 c2 : complex) : complex :=
{ re := c1.re + c2.re,
im := c1.im + c2.im }
def neg (c : complex) : complex :=
{ re := -c.re,
im := -c.im }
@[simp]
def mul (c1 c2 : complex) : complex :=
{ re := c1.re * c2.re - c1.im * c2.im,
im := c1.re * c2.im + c1.im * c2.re }
def inv (c : complex) : complex :=
let norm := (c.re^2 + c.im^2) in
{ re := c.re / norm,
im := - c.im / norm }
instance : field complex :=
{ add := add,
mul := mul,
zero := {re := 0, im := 0},
one := {re := 1, im := 0},
neg := neg,
inv := inv,
add_comm := sorry,
add_assoc := sorry,
zero_add := sorry,
add_zero := sorry,
add_left_neg := sorry,
mul_assoc := sorry,
one_mul := sorry,
mul_one := sorry,
left_distrib := sorry,
right_distrib := sorry,
mul_comm := sorry,
exists_pair_ne := sorry,
mul_inv_cancel := sorry,
inv_zero := sorry }
/--
`to_polar c` returns a pair of real numbers `(angle, radius)`.
-/
def to_polar (c : complex) : ℝ × ℝ :=
(arctan (c.im / c.re), sqrt (c.re^2 + c.im^2))
def from_polar (angle radius : ℝ) : complex :=
{ re := radius * cos angle,
im := radius * sin angle }
example (angle radius : ℝ) :
to_polar (from_polar angle radius) = (angle, radius) :=
begin
sorry
end
end demo
/-!
## Lean and mathlib
The Lean proof asssistant is relatively new,
relatively ergonomic,
and has a relatively large community of users interested in mathematics.
*mathlib* is the de facto standard library for Lean.
* <https://leanprover-community.github.io/>
* <https://github.com/leanprover-community/mathlib>
* <https://leanprover.zulipchat.com/>
* 700k lines of code, nearly 200 contributors
* Collaborative open-source project
* Lots of effort to make mathlib developments coherent, reusable
Overview of the library:
<https://leanprover-community.github.io/mathlib-overview.html>
Undergraduate math in mathlib:
<https://leanprover-community.github.io/undergrad.html>
People involved at all levels of mathematical maturity!
Formalization is a great way to get undergraduates involved.
### Noteworthy projects
A number of projects, some ongoing, have added to or built on the library.
#### Liquid tensor experiment
Peter Scholze, Dec 5, 2020:
I want to propose a challenge:
Formalize the proof of the following theorem.
**Theorem 1.1** (Clausen-Scholze).
Let 0 < p' < p ≤ 1 be real numbers,
let S be a profinite set,
and let V be a p-Banach space.
Let ℳₚ'(S) be the space of p'-measures on S.
Then Extⁱ_Cond(Ab)(ℳₚ'(S), V) = 0 for i ≥ 1.
...
I think this may be my most important theorem to date....
Better be sure it’s correct.
Peter Scholze, June 5, 2021:
Exactly half a year ago I wrote the Liquid Tensor
Experiment blog post...
I am excited to announce that the Experiment has verified
the entire part of the argument that I was unsure about.
I find it absolutely insane that interactive proof assistants
are now at the level that
within a very reasonable time span
they can formally verify difficult original research.
A collaborative effort led by Johan Commelin.
-/
/-!
#### Formalizing perfectoid spaces
A challenge in formalizing a very complex *definition*.
Kevin Buzzard, Johan Commelin, Patrick Massot (2020).
#### Formalizing the solution to the cap set problem
A *cap set* is a subset of ℤ₃ⁿ containing no arithmetic progression.
Theorem (Ellenberg and Gijswijt, 2017):
The largest possible size of a cap set is O(2.756^n).
Sander Dahmen, Johannes Hölzl, Robert Y. Lewis (2019):
-/
theorem cap_set_problem : ∃ B : ℝ,
∀ {n : ℕ} {A : finset (fin n → ℤ/3ℤ)},
(∀ x y z : fin n → ℤ/3ℤ,
x ∈ A → y ∈ A → z ∈ A → x + y + z = 0 → x = y ∧ x = z) →
↑A.card ≤
B * ((((3 : ℝ) / 8)^3 * (207 + 33*real.sqrt 33))^(1/3 : ℝ))^n :=
sorry
/-!
#### Formalizing the ring of Witt vectors
Johan Commelin and Robert Y. Lewis (2021).
Abstract strategies for verifying Witt vector identities
are very hard to formalize.
With the right abstractions and some metaprogramming,
formal arguments can follow the same path as informal arguments.
-/
#check witt_vector
#check witt_vector.equiv
/-!
### Current status
Plenty of ongoing projects:
* LTE
* Sphere eversion
* Transition from Lean 3 to Lean 4
* 8- and 24-dim sphere packings?
CMU recently received a $20m donation to found
the Hoskinson Center for Formal Mathematics.
Various events planned in the medium-term future:
* Lorentz Center in Leiden, March 2022 (ask me for details!)
* ICERM, summer 2022
* Lean Together 2022, ???
## Resources and references
Learning: <https://leanprover-community.github.io/learn.html>
* Tutorials project: <https://github.com/leanprover-community/tutorials>
* Lean for the Curious Mathematician: <https://leanprover-community.github.io/lftcm2020/>
* Theorem Proving in Lean: <https://leanprover.github.io/theorem_proving_in_lean/>
Papers: <https://leanprover-community.github.io/papers.html>
* de Moura, Kong, Avigad, van Doorn, von Raumer (2015).
*The Lean Theorem Prover (System Description)*.
<https://doi.org/10.1007/978-3-319-21401-6_26>
* The mathlib Community (2020). *The Lean mathematical library*.
<https://doi.org/10.1145/3372885.3373824>
* Lewis (2019). *A formal proof of Hensel's Lemma over the p-adic integers*.
<https://doi.org/10.1145/3293880.3294089>
* Dahmen, Hölzl, Lewis (2019). *Formalizing the solution to the cap set problem*.
<https://doi.org/10.4230/LIPIcs.ITP.2019.15>
* Buzzard, Commelin, Massot (2020). *Formalising perfectoid spaces*.
<https://doi.org/10.1145/3372885.3373830>
* Commelin, Lewis (2021). *Formalizing the ring of Witt vectors*.
<https://doi.org/10.1145/3437992.3439919>
-/ |
8cf226285611325d1809ca0d5b5bc1ea48bcafe3 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/linear_algebra/matrix/polynomial.lean | 3f3dec4c871b98386b034f01242156db1d8b96fc | [
"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 | 4,060 | lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import linear_algebra.matrix.determinant
import data.polynomial.eval
import data.polynomial.monic
import algebra.polynomial.big_operators
/-!
# Matrices of polynomials and polynomials of matrices
In this file, we prove results about matrices over a polynomial ring.
In particular, we give results about the polynomial given by
`det (t * I + A)`.
## References
* "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
## Tags
matrix determinant, polynomial
-/
open_locale matrix big_operators
variables {n α : Type*} [decidable_eq n] [fintype n] [comm_ring α]
open polynomial matrix equiv.perm
namespace polynomial
lemma nat_degree_det_X_add_C_le (A B : matrix n n α) :
nat_degree (det ((X : polynomial α) • A.map C + B.map C)) ≤ fintype.card n :=
begin
rw det_apply,
refine (nat_degree_sum_le _ _).trans _,
refine (multiset.max_nat_le_of_forall_le _ _ _),
simp only [forall_apply_eq_imp_iff', true_and, function.comp_app, multiset.map_map,
multiset.mem_map, exists_imp_distrib, finset.mem_univ_val],
intro g,
calc nat_degree (sign g • ∏ (i : n), (X • A.map C + B.map C) (g i) i)
≤ nat_degree (∏ (i : n), (X • A.map C + B.map C) (g i) i) : by {
cases int.units_eq_one_or (sign g) with sg sg,
{ rw [sg, one_smul] },
{ rw [sg, units.neg_smul, one_smul, nat_degree_neg] } }
... ≤ ∑ (i : n), nat_degree (((X : polynomial α) • A.map C + B.map C) (g i) i) :
nat_degree_prod_le (finset.univ : finset n) (λ (i : n), (X • A.map C + B.map C) (g i) i)
... ≤ finset.univ.card • 1 : finset.sum_le_of_forall_le _ _ 1 (λ (i : n) _, _)
... ≤ fintype.card n : by simpa,
calc nat_degree (((X : polynomial α) • A.map C + B.map C) (g i) i)
= nat_degree ((X : polynomial α) * C (A (g i) i) + C (B (g i) i)) : by simp
... ≤ max (nat_degree ((X : polynomial α) * C (A (g i) i))) (nat_degree (C (B (g i) i))) :
nat_degree_add_le _ _
... = nat_degree ((X : polynomial α) * C (A (g i) i)) :
max_eq_left ((nat_degree_C _).le.trans (zero_le _))
... ≤ nat_degree (X : polynomial α) : nat_degree_mul_C_le _ _
... ≤ 1 : nat_degree_X_le
end
lemma coeff_det_X_add_C_zero (A B : matrix n n α) :
coeff (det ((X : polynomial α) • A.map C + B.map C)) 0 = det B :=
begin
rw [det_apply, finset_sum_coeff, det_apply],
refine finset.sum_congr rfl _,
intros g hg,
convert coeff_smul (sign g) _ 0,
rw coeff_zero_prod,
refine finset.prod_congr rfl _,
simp
end
lemma coeff_det_X_add_C_card (A B : matrix n n α) :
coeff (det ((X : polynomial α) • A.map C + B.map C)) (fintype.card n) = det A :=
begin
rw [det_apply, det_apply, finset_sum_coeff],
refine finset.sum_congr rfl _,
simp only [algebra.id.smul_eq_mul, finset.mem_univ, ring_hom.map_matrix_apply, forall_true_left,
map_apply, dmatrix.add_apply, pi.smul_apply],
intros g,
convert coeff_smul (sign g) _ _,
rw ←mul_one (fintype.card n),
convert (coeff_prod_of_nat_degree_le _ _ _ _).symm,
{ ext,
simp [coeff_C] },
{ intros p hp,
refine (nat_degree_add_le _ _).trans _,
simpa using (nat_degree_mul_C_le _ _).trans nat_degree_X_le }
end
lemma leading_coeff_det_X_one_add_C (A : matrix n n α) :
leading_coeff (det ((X : polynomial α) • (1 : matrix n n (polynomial α)) + A.map C)) = 1 :=
begin
casesI (subsingleton_or_nontrivial α),
{ simp },
rw [←@det_one n, ←coeff_det_X_add_C_card _ A, leading_coeff],
simp only [matrix.map_one, C_eq_zero, ring_hom.map_one],
cases (nat_degree_det_X_add_C_le 1 A).eq_or_lt with h h,
{ simp only [ring_hom.map_one, matrix.map_one, C_eq_zero] at h,
rw h },
{ -- contradiction. we have a hypothesis that the degree is less than |n|
-- but we know that coeff _ n = 1
have H := coeff_eq_zero_of_nat_degree_lt h,
rw coeff_det_X_add_C_card at H,
simpa using H }
end
end polynomial
|
bc5110d0c0613029fd33011ce29cef2081af5b78 | df561f413cfe0a88b1056655515399c546ff32a5 | /5-advanced-proposition-world/l1.lean | ba0a2ef927833fff54b27e10d668ce56587575fc | [] | no_license | nicholaspun/natural-number-game-solutions | 31d5158415c6f582694680044c5c6469032c2a06 | 1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0 | refs/heads/main | 1,675,123,625,012 | 1,607,633,548,000 | 1,607,633,548,000 | 318,933,860 | 3 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 84 | lean | example (P Q : Prop) (p : P) (q : Q) : P ∧ Q :=
begin
split,
exact p,
exact q,
end |
fb3827709021ed443798178e453fee3450fa2788 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/set/constructions_auto.lean | 3bcb49dd0cd3bbbbf5dabd724cd742a20ebdac34 | [] | 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 | 2,355 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.default
import Mathlib.data.finset.basic
import Mathlib.PostPort
universes u_1 l
namespace Mathlib
/-!
# Constructions involving sets of sets.
## Finite Intersections
We define a structure `has_finite_inter` which asserts that a set `S` of subsets of `α` is
closed under finite intersections.
We define `finite_inter_closure` which, given a set `S` of subsets of `α`, is the smallest
set of subsets of `α` which is closed under finite intersections.
`finite_inter_closure S` is endowed with a term of type `has_finite_inter` using
`finite_inter_closure_has_finite_inter`.
-/
/-- A structure encapsulating the fact that a set of sets is closed under finite intersection. -/
structure has_finite_inter {α : Type u_1} (S : set (set α)) where
univ_mem : set.univ ∈ S
inter_mem : ∀ {s t : set α}, s ∈ S → t ∈ S → s ∩ t ∈ S
namespace has_finite_inter
-- Satisfying the inhabited linter...
protected instance inhabited {α : Type u_1} : Inhabited (has_finite_inter (singleton set.univ)) :=
{ default := mk sorry sorry }
/-- The smallest set of sets containing `S` which is closed under finite intersections. -/
inductive finite_inter_closure {α : Type u_1} (S : set (set α)) : set (set α) where
| basic : ∀ {s : set α}, s ∈ S → finite_inter_closure S s
| univ : finite_inter_closure S set.univ
| inter :
∀ {s t : set α},
finite_inter_closure S s → finite_inter_closure S t → finite_inter_closure S (s ∩ t)
/-- Defines `has_finite_inter` for `finite_inter_closure S`. -/
def finite_inter_closure_has_finite_inter {α : Type u_1} (S : set (set α)) :
has_finite_inter (finite_inter_closure S) :=
mk finite_inter_closure.univ sorry
theorem finite_inter_mem {α : Type u_1} {S : set (set α)} (cond : has_finite_inter S)
(F : finset (set α)) : ↑F ⊆ S → ⋂₀↑F ∈ S :=
sorry
theorem finite_inter_closure_insert {α : Type u_1} {S : set (set α)} {A : set α}
(cond : has_finite_inter S) (P : set α) (H : P ∈ finite_inter_closure (insert A S)) :
P ∈ S ∨ ∃ (Q : set α), ∃ (H : Q ∈ S), P = A ∩ Q :=
sorry
end Mathlib |
d33ac2eb18b046c0e5154e6b7eb0e0c15767a0c2 | 9e90bb7eb4d1bde1805f9eb6187c333fdf09588a | /src/lib/basic.lean | 15ed0755a80e002025ceadd1677c36523298c71d | [
"Apache-2.0"
] | permissive | alexjbest/stump-learnable | 6311d0c3a1a1a0e65ce83edcbb3b4b7cecabb851 | f8fd812fc646d2ece312ff6ffc2a19848ac76032 | refs/heads/master | 1,659,486,805,691 | 1,590,454,024,000 | 1,590,454,024,000 | 266,173,720 | 0 | 0 | Apache-2.0 | 1,590,169,884,000 | 1,590,169,883,000 | null | UTF-8 | Lean | false | false | 11,403 | lean | /-
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
-/
import lib.attributed.probability_theory
import lib.attributed.dvector lib.attributed.to_mathlib
import measure_theory.giry_monad
import measure_theory.measure_space
import data.complex.exponential
local attribute [instance] classical.prop_decidable
universes u v
open nnreal measure_theory nat list measure_theory.measure to_integration probability_measure set dfin lattice ennreal
variables {α : Type u} {β : Type u} {γ : Type v}[measurable_space α]
infixl ` >>=ₐ `:55 := measure.bind
infixl ` <$>ₐ `:55 := measure.map
local notation `doₐ` binders ` ←ₐ ` m ` ; ` t:(scoped p, m >>=ₐ p) := t
local notation `ret` := measure.dirac
lemma split_set {α β : Type u} (Pa : α → Prop) (Pb : β → Prop) : {m : α × β | Pa m.fst} = {x : α | Pa x}.prod univ := by ext1; cases x; dsimp at *; simp at *
instance has_zero_dfin {n} : has_zero $ dfin (n+1) := ⟨dfin.fz⟩
lemma vec.split_set {n : ℕ} (P : α → Prop) (μ : probability_measure α) :
{x : vec α (n+2)| P (kth_projn x 1)} = set.prod univ {x : vec α (n+1) | P (kth_projn x 0)} :=
begin
ext1, cases x, cases x_snd, dsimp at *, simp at *, refl,
end
lemma vec.prod_measure_univ' {n : ℕ} [nonempty α] [ne : ∀ n, nonempty (vec α n)](μ : probability_measure α) : (vec.prod_measure μ n : measure (vec α (n))) (univ) = 1
:=
by exact measure_univ _
noncomputable def vec.prob_measure (n : ℕ) [nonempty α] (μ : probability_measure α) : probability_measure (vec α n) :=
⟨ vec.prod_measure μ n , vec.prod_measure_univ' μ ⟩
lemma vec.prob_measure_apply (n : ℕ) [nonempty α] {μ : probability_measure α} {S : set (vec α n)} (hS : is_measurable S) : (vec.prob_measure n μ) S = ((vec.prod_measure μ n) S) := rfl
lemma measure_kth_projn' {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : is_measurable {x : vec α (n + 1) | P (kth_projn x 0)}) :
(vec.prod_measure μ (n+2) : probability_measure (vec α (n+2))) {x : vec α (n + 2) | P (kth_projn x 1)} = μ {x : α | P x} :=
begin
rw vec.split_set _ μ,
rw vec.prod_measure_eq,
rw prod.prob_measure_apply _ _ is_measurable.univ _, rw prob_univ,rw one_mul,
have h: {x : vec α (n + 1) | P (kth_projn x 0)} = {x : vec α (n + 1) | P (x.fst)}, {
ext1, cases x, refl,
},
rw h, clear h,
induction n with k ih, rw vec.prod_measure_eq,
have h₁: {x : vec α (0 + 1) | P (x.fst)} = set.prod {x:α | P(x)} univ,by ext1; cases x; dsimp at *;simp at *,
rw h₁, rw vec.prod_measure,rw prod.prob_measure_apply _ _ _ is_measurable.univ, rw prob_univ, rw mul_one, assumption,assumption, exact hP,
have h₂ : {x : vec α (succ k + 1) | P (x.fst)} = {x : vec α (k + 2) | P (x.fst)},by refl,
rw h₂, clear h₂,
have h₃ : {x : vec α (k + 2) | P (x.fst)} = set.prod {x : α | P(x)} univ, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₃, rw vec.prod_measure_eq,rw prod.prob_measure_apply _ _ _ is_measurable.univ, rw prob_univ, rw mul_one, assumption, apply nonempty.vec, exact hP, assumption, apply nonempty.vec, assumption,
end
@[simp] lemma measure_kth_projn {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n i, is_measurable {x : vec α n | P (kth_projn x i)}) : ∀ (i : dfin (n+1)),
(vec.prod_measure μ n : probability_measure (vec α n)) {x : vec α n | P (kth_projn x i)} = μ {x : α | P x} :=
begin
intros i,
induction n with n b dk ih, rw vec.prod_measure,
have g : {x : vec α 0 | P (kth_projn x i)} = {x | P x}, by tidy, rw g, refl,
have h: {x : vec α (n + 1) | P (kth_projn x fz)} = {x : vec α (n + 1) | P (x.fst)}, {
ext1, cases x, refl,
},
cases i,
rw h, clear h,
have h₃ : {x : vec α (n + 1) | P (x.fst)} = set.prod {x : α | P(x)} univ, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₃, rw vec.prod_measure_eq, rw prod.prob_measure_apply _ _ hP is_measurable.univ, rw prob_univ, rw mul_one, exact (nonempty.vec n), rw vec.prod_measure_eq,
have h₄ : {x : vec α (succ n) | P (kth_projn x (fs i_a))} = set.prod univ {x : vec α n | P (kth_projn x i_a)}, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₄, rw prod.prob_measure_apply _ _ is_measurable.univ _, rw prob_univ, rw one_mul, rw b,
assumption, exact (nonempty.vec n),
apply hp',
end
lemma dfin_succ_prop_iff_fst_and_rst {α : Type u} (P : α → Prop) {k : ℕ} (x : vec α (succ k)) : (∀ (i : dfin (succ k + 1)), P (kth_projn x i)) ↔ P (x.fst) ∧ ∀ (i : dfin (succ k)), P (kth_projn (x.snd) i) :=
begin
fsplit,
intros h, split, have := h fz, have : kth_projn x 0 = x.fst, cases x, refl, rw ←this, assumption,
intro i₀, cases x, have := h (fs i₀), rwa kth_projn at this,
intros g i₁, cases g with l r, cases i₁ with ifz ifs, have : kth_projn x fz = x.fst, cases x, refl, rw this, assumption,
cases x, rw kth_projn, exact r i₁_a,
end
lemma independence {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n, is_measurable {x : vec α n | ∀ i, P (kth_projn x i)}) :
(vec.prod_measure μ n : probability_measure (vec α n)) {x : vec α n | ∀ (i : dfin (n + 1)), P (kth_projn x i)} = μ {x : α | P x} ^ (n+1) :=
begin
induction n with k ih,
simp only [nat.pow_zero, nat_zero_eq_zero],
have g : {x : vec α 0 | ∀ i : dfin 1, P (kth_projn x i)} = {x | P x}, {
ext1, dsimp at *, fsplit, intros a, exact (a fz), intros a i, assumption,
},
rw g, simp, refl,
have h₂ : {x : vec α (succ k) | ∀ (i : dfin (succ k + 1)), P (kth_projn x i)} = set.prod {x | P x} {x : vec α k | ∀ (i : dfin (succ k)), P (kth_projn x i)},{
ext1, apply dfin_succ_prop_iff_fst_and_rst,
},
rw [h₂],
rw vec.prod_measure_eq, rw vec.prod_measure_apply _ _ hP (hp' k),rw ih,refl,
end
@[simp] lemma prob_independence {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n, is_measurable {x : vec α n | ∀ i, P (kth_projn x i)}) :
(vec.prob_measure n μ : probability_measure (vec α n)) {x : vec α n | ∀ (i : dfin (succ n)), P (kth_projn x i)} = (μ {x : α | P x}) ^ (n+1) :=
begin
induction n with k ih,
simp only [nat.pow_zero, nat_zero_eq_zero],
have g : {x : vec α 0 | ∀ i : dfin 1, P (kth_projn x i)} = {x | P x}, {
ext1, dsimp at *, fsplit, intros a, exact (a fz), intros a i, assumption,
},
rw g, rw vec.prob_measure, simp, refl,
have h₂ : {x : vec α (succ k) | ∀ (i : dfin (succ (succ k))), P (kth_projn x i)} = set.prod {x | P x} {x : vec α k | ∀ (i : dfin (succ k)), P (kth_projn x i)},{
ext1, apply dfin_succ_prop_iff_fst_and_rst,
},
rw h₂,
rw vec.prob_measure_apply _ _,
rw [vec.prod_measure_eq], rw vec.prod_measure_apply _ _ hP, rw pow_succ', rw ←ih, rw mul_comm, rw vec.prob_measure_apply, exact hp' k, exact hp' k, exact is_measurable.prod hP (hp' k),
end
noncomputable def point_indicators {f h: α → bool} {n : ℕ} (hf : measurable f) (hh : measurable h) (i : dfin (succ n)) := χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧
lemma integral_point_indicators {f h: α → bool} {n : ℕ} [ne : nonempty (vec α n)] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (μ : measure (vec α n)) :
∀ i : dfin (succ n),
(∫ χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧ ðμ) = μ ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}) := assume i, integral_char_fun μ (hA n i)
lemma finally {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) : let η := (vec.prod_measure μ n).to_measure in
∀ i, (∫ (χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧) ðη) = μ.to_measure {x : α | h x ≠ f x} :=
begin
intros η i₀,
rw [integral_point_indicators hf hh hA (vec.prod_measure μ n).to_measure i₀], rw ←coe_eq_to_measure, rw ←coe_eq_to_measure,
rw measure_kth_projn μ hB,
intro n₀, apply hA,
end
lemma integral_char_fun_finset_sum {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) (m : finset(dfin (succ n))):
(∫finset.sum m (λ (i : dfin (succ n)), ⇑χ⟦{x : vec α n | h (kth_projn x i) ≠ f (kth_projn x i)}⟧)ð((vec.prod_measure μ n).to_measure)) = m.sum (λ i, ((vec.prod_measure μ n)) ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) :=
begin
rw integral,
refine finset.induction_on m _ _,
{ simp, erw lintegral_zero },
{ assume a s has ih, simp [has], erw [lintegral_add],
erw simple_func.lintegral_eq_integral,unfold char_fun,
erw simple_func.restrict_const_integral, dsimp, rw ←ih, rw one_mul, rw coe_eq_to_measure, refl, exact(hA n a),
exact measurable.comp (simple_func.measurable _) measurable_id,
refine measurable.comp _ measurable_id,
refine finset.induction_on s _ _,
{simp, exact simple_func.measurable 0,},
{intros a b c d, simp [c], apply measurable.add, exact simple_func.measurable _, exact d,}
},
end
lemma integral_sum_dfin {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) (m : finset(dfin (succ n))) : let η := (vec.prod_measure μ n) in
(∫ m.sum (λ i, χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧) ðη.to_measure )= m.sum (λ i, (μ.to_measure : measure α) {x : α | h x ≠ f x}) :=
begin
intros η,
rw [integral_char_fun_finset_sum hf hh hA hB],
congr, funext, rw measure_kth_projn μ hB hA, rw coe_eq_to_measure,
end
lemma measure_sum_const {f h : α → bool} {n : ℕ} (hf : measurable f) (hh : measurable h) (m : finset (fin n)) (μ : probability_measure α) :
m.sum (λ i, (μ : measure α) {x : α | h x ≠ f x}) = (m.card : ℕ) * ((μ : measure α) {x : α | h x ≠ f x}) :=
begin
apply finset.induction_on m, simp,
intros a b c d,
simp [c], rw add_monoid.add_smul, rw [add_monoid.smul],
simp [monoid.pow], rw right_distrib, rw monoid.one_mul, rw ←d,
simp,
refl,
end
namespace hoeffding
open complex real
noncomputable def exp_fun (f : α → ennreal) : α → ℝ := λ x, exp $ (f x).to_real
local notation `∫` f `𝒹`m := integral m.to_measure f
lemma integral_char_rect [measurable_space α] [measurable_space β] [n₁ : nonempty α] [n₂ : nonempty β](μ : probability_measure α) (ν : probability_measure β) {A : set α} {B : set β} (hA : is_measurable A) (hB : is_measurable B) :
(∫ χ ⟦ A.prod B ⟧ 𝒹(μ ⊗ₚ ν)) = (μ A) * (ν B) :=
begin
haveI := (nonempty_prod.2 (and.intro n₁ n₂)),
rw [integral_char_fun _ (is_measurable.prod hA hB),←coe_eq_to_measure,
(prod.prob_measure_apply _ _ hA hB)], simp,
end
end hoeffding
|
452e4722f9ce61df34c1babddf60fb149cd59578 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/normed_space/star/exponential.lean | 1a23c9643dee91ceb2236343236d64decb305961 | [
"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 | 2,416 | lean | /-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import analysis.normed_space.star.basic
import algebra.star.module
import analysis.special_functions.exponential
/-! # The exponential map from selfadjoint to unitary
In this file, we establish various propreties related to the map `λ a, exp ℂ A (I • a)` between the
subtypes `self_adjoint A` and `unitary A`.
## TODO
* Show that any exponential unitary is path-connected in `unitary A` to `1 : unitary A`.
* Prove any unitary whose distance to `1 : unitary A` is less than `1` can be expressed as an
exponential unitary.
* A unitary is in the path component of `1` if and only if it is a finite product of exponential
unitaries.
-/
section star
variables {A : Type*}
[normed_ring A] [normed_algebra ℂ A] [star_ring A] [has_continuous_star A] [complete_space A]
[star_module ℂ A]
open complex
lemma is_self_adjoint.exp_i_smul_unitary {a : A} (ha : is_self_adjoint a) :
exp ℂ (I • a) ∈ unitary A :=
begin
rw [unitary.mem_iff, star_exp],
simp only [star_smul, is_R_or_C.star_def, self_adjoint.mem_iff.mp ha, conj_I, neg_smul],
rw ←@exp_add_of_commute ℂ A _ _ _ _ _ _ ((commute.refl (I • a)).neg_left),
rw ←@exp_add_of_commute ℂ A _ _ _ _ _ _ ((commute.refl (I • a)).neg_right),
simpa only [add_right_neg, add_left_neg, and_self] using (exp_zero : exp ℂ (0 : A) = 1),
end
/-- The map from the selfadjoint real subspace to the unitary group. This map only makes sense
over ℂ. -/
@[simps]
noncomputable def self_adjoint.exp_unitary (a : self_adjoint A) : unitary A :=
⟨exp ℂ (I • a), a.prop.exp_i_smul_unitary⟩
open self_adjoint
lemma commute.exp_unitary_add {a b : self_adjoint A} (h : commute (a : A) (b : A)) :
exp_unitary (a + b) = exp_unitary a * exp_unitary b :=
begin
ext,
have hcomm : commute (I • (a : A)) (I • (b : A)),
calc _ = _ : by simp only [h.eq, algebra.smul_mul_assoc, algebra.mul_smul_comm],
simpa only [exp_unitary_coe, add_subgroup.coe_add, smul_add] using exp_add_of_commute hcomm,
end
lemma commute.exp_unitary {a b : self_adjoint A} (h : commute (a : A) (b : A)) :
commute (exp_unitary a) (exp_unitary b) :=
calc (exp_unitary a) * (exp_unitary b) = (exp_unitary b) * (exp_unitary a)
: by rw [←h.exp_unitary_add, ←h.symm.exp_unitary_add, add_comm]
end star
|
ca471743796211eca2c32c7029e4aba3af215622 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebraic_geometry/presheafed_space_auto.lean | fe0e7b75e4f215f0ff9b89a8183c7fee908d68e4 | [] | 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 | 13,612 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.sheaves.presheaf
import Mathlib.PostPort
universes v u l
namespace Mathlib
/-!
# Presheafed spaces
Introduces the category of topological spaces equipped with a presheaf (taking values in an
arbitrary target category `C`.)
We further describe how to apply functors and natural transformations to the values of the
presheaves.
-/
namespace algebraic_geometry
/-- A `PresheafedSpace C` is a topological space equipped with a presheaf of `C`s. -/
structure PresheafedSpace (C : Type u) [category_theory.category C] where
carrier : Top
presheaf : Top.presheaf C carrier
namespace PresheafedSpace
protected instance coe_carrier {C : Type u} [category_theory.category C] :
has_coe (PresheafedSpace C) Top :=
has_coe.mk fun (X : PresheafedSpace C) => carrier X
@[simp] theorem as_coe {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
carrier X = ↑X :=
rfl
@[simp] theorem mk_coe {C : Type u} [category_theory.category C] (carrier : Top)
(presheaf : Top.presheaf C carrier) : ↑(mk carrier presheaf) = carrier :=
rfl
protected instance topological_space {C : Type u} [category_theory.category C]
(X : PresheafedSpace C) : topological_space ↥X :=
category_theory.bundled.str (carrier X)
/-- The constant presheaf on `X` with value `Z`. -/
def const {C : Type u} [category_theory.category C] (X : Top) (Z : C) : PresheafedSpace C :=
mk X
(category_theory.functor.mk (fun (U : topological_space.opens ↥Xᵒᵖ) => Z)
fun (U V : topological_space.opens ↥Xᵒᵖ) (f : U ⟶ V) => 𝟙)
protected instance inhabited {C : Type u} [category_theory.category C] [Inhabited C] :
Inhabited (PresheafedSpace C) :=
{ default := const (Top.of pempty) Inhabited.default }
/-- A morphism between presheafed spaces `X` and `Y` consists of a continuous map
`f` between the underlying topological spaces, and a (notice contravariant!) map
from the presheaf on `Y` to the pushforward of the presheaf on `X` via `f`. -/
structure hom {C : Type u} [category_theory.category C] (X : PresheafedSpace C)
(Y : PresheafedSpace C)
where
base : ↑X ⟶ ↑Y
c : PresheafedSpace.presheaf Y ⟶ base _* PresheafedSpace.presheaf X
theorem ext {C : Type u} [category_theory.category C] {X : PresheafedSpace C}
{Y : PresheafedSpace C} (α : hom X Y) (β : hom X Y) (w : hom.base α = hom.base β)
(h :
hom.c α ≫
category_theory.whisker_right
(category_theory.nat_trans.op
(category_theory.iso.inv
(topological_space.opens.map_iso (hom.base α) (hom.base β) w)))
(PresheafedSpace.presheaf X) =
hom.c β) :
α = β :=
sorry
/-- The identity morphism of a `PresheafedSpace`. -/
def id {C : Type u} [category_theory.category C] (X : PresheafedSpace C) : hom X X :=
hom.mk 𝟙
(category_theory.iso.inv (category_theory.functor.left_unitor (PresheafedSpace.presheaf X)) ≫
category_theory.whisker_right
(category_theory.nat_trans.op
(category_theory.iso.hom (topological_space.opens.map_id (carrier X))))
(PresheafedSpace.presheaf X))
protected instance hom_inhabited {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
Inhabited (hom X X) :=
{ default := id X }
/-- Composition of morphisms of `PresheafedSpace`s. -/
def comp {C : Type u} [category_theory.category C] {X : PresheafedSpace C} {Y : PresheafedSpace C}
{Z : PresheafedSpace C} (α : hom X Y) (β : hom Y Z) : hom X Z :=
hom.mk (hom.base α ≫ hom.base β)
(hom.c β ≫
category_theory.whisker_left
(category_theory.functor.op (topological_space.opens.map (hom.base β))) (hom.c α) ≫
category_theory.iso.inv
(Top.presheaf.pushforward.comp (PresheafedSpace.presheaf X) (hom.base α) (hom.base β)))
/- The proofs below can be done by `tidy`, but it is too slow,
and we don't have a tactic caching mechanism. -/
/-- The category of PresheafedSpaces. Morphisms are pairs, a continuous map and a presheaf map
from the presheaf on the target to the pushforward of the presheaf on the source. -/
protected instance category_of_PresheafedSpaces (C : Type u) [category_theory.category C] :
category_theory.category (PresheafedSpace C) :=
category_theory.category.mk
@[simp] theorem id_base {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
hom.base 𝟙 = 𝟙 :=
rfl
theorem id_c {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
hom.c 𝟙 =
category_theory.iso.inv (category_theory.functor.left_unitor (PresheafedSpace.presheaf X)) ≫
category_theory.whisker_right
(category_theory.nat_trans.op
(category_theory.iso.hom (topological_space.opens.map_id (carrier X))))
(PresheafedSpace.presheaf X) :=
rfl
@[simp] theorem id_c_app {C : Type u} [category_theory.category C] (X : PresheafedSpace C)
(U : topological_space.opens ↥(carrier X)ᵒᵖ) :
category_theory.nat_trans.app (hom.c 𝟙) U =
category_theory.eq_to_hom
(opposite.op_induction
(fun (U : topological_space.opens ↥(carrier X)) =>
subtype.cases_on U
fun (U_val : set ↥(carrier X)) (U_property : is_open U_val) =>
Eq.refl
(category_theory.functor.obj (PresheafedSpace.presheaf X)
(opposite.op { val := U_val, property := U_property })))
U) :=
sorry
@[simp] theorem comp_base {C : Type u} [category_theory.category C] {X : PresheafedSpace C}
{Y : PresheafedSpace C} {Z : PresheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) :
hom.base (f ≫ g) = hom.base f ≫ hom.base g :=
rfl
@[simp] theorem comp_c_app {C : Type u} [category_theory.category C] {X : PresheafedSpace C}
{Y : PresheafedSpace C} {Z : PresheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z)
(U : topological_space.opens ↥(carrier Z)ᵒᵖ) :
category_theory.nat_trans.app (hom.c (α ≫ β)) U =
category_theory.nat_trans.app (hom.c β) U ≫
category_theory.nat_trans.app (hom.c α)
(opposite.op
(category_theory.functor.obj (topological_space.opens.map (hom.base β))
(opposite.unop U))) ≫
category_theory.nat_trans.app
(category_theory.iso.inv
(Top.presheaf.pushforward.comp (PresheafedSpace.presheaf X) (hom.base α)
(hom.base β)))
U :=
rfl
theorem congr_app {C : Type u} [category_theory.category C] {X : PresheafedSpace C}
{Y : PresheafedSpace C} {α : X ⟶ Y} {β : X ⟶ Y} (h : α = β)
(U : topological_space.opens ↥(carrier Y)ᵒᵖ) :
category_theory.nat_trans.app (hom.c α) U =
category_theory.nat_trans.app (hom.c β) U ≫
category_theory.functor.map (PresheafedSpace.presheaf X)
(category_theory.eq_to_hom
(Eq._oldrec
(Eq.refl
(category_theory.functor.obj
(category_theory.functor.op (topological_space.opens.map (hom.base α))) U))
h)) :=
sorry
/-- The forgetful functor from `PresheafedSpace` to `Top`. -/
def forget (C : Type u) [category_theory.category C] : PresheafedSpace C ⥤ Top :=
category_theory.functor.mk (fun (X : PresheafedSpace C) => ↑X)
fun (X Y : PresheafedSpace C) (f : X ⟶ Y) => hom.base f
/--
The restriction of a presheafed space along an open embedding into the space.
-/
@[simp] theorem restrict_carrier {C : Type u} [category_theory.category C] {U : Top}
(X : PresheafedSpace C) (f : U ⟶ ↑X) (h : open_embedding ⇑f) : carrier (restrict X f h) = U :=
Eq.refl (carrier (restrict X f h))
/--
The map from the restriction of a presheafed space.
-/
@[simp] theorem of_restrict_c_app {C : Type u} [category_theory.category C] (U : Top)
(X : PresheafedSpace C) (f : U ⟶ ↑X) (h : open_embedding ⇑f)
(V : topological_space.opens ↥(carrier X)ᵒᵖ) :
category_theory.nat_trans.app (hom.c (of_restrict U X f h)) V =
category_theory.functor.map (PresheafedSpace.presheaf X)
(category_theory.has_hom.hom.op
(coe_fn
(equiv.symm
(category_theory.adjunction.hom_equiv
(is_open_map.adjunction (of_restrict._proof_2 U X f h))
(category_theory.functor.obj (topological_space.opens.map f) (opposite.unop V))
(opposite.unop V)))
𝟙)) :=
Eq.refl (category_theory.nat_trans.app (hom.c (of_restrict U X f h)) V)
/--
The map to the restriction of a presheafed space along the canonical inclusion from the top
subspace.
-/
@[simp] theorem to_restrict_top_base_to_fun_coe {C : Type u} [category_theory.category C]
(X : PresheafedSpace C) (x : ↥↑X) : ↑(coe_fn (hom.base (to_restrict_top X)) x) = x :=
Eq.refl ↑(coe_fn (hom.base (to_restrict_top X)) x)
/--
The isomorphism from the restriction to the top subspace.
-/
def restrict_top_iso {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
restrict X (topological_space.opens.inclusion ⊤) (restrict_top_iso._proof_1 X) ≅ X :=
category_theory.iso.mk
(of_restrict (category_theory.functor.obj (topological_space.opens.to_Top ↑X) ⊤) X
(topological_space.opens.inclusion ⊤) sorry)
(to_restrict_top X)
/--
The global sections, notated Gamma.
-/
@[simp] theorem Γ_obj {C : Type u} [category_theory.category C] (X : PresheafedSpace Cᵒᵖ) :
category_theory.functor.obj Γ X =
category_theory.functor.obj (PresheafedSpace.presheaf (opposite.unop X)) (opposite.op ⊤) :=
Eq.refl (category_theory.functor.obj Γ X)
theorem Γ_obj_op {C : Type u} [category_theory.category C] (X : PresheafedSpace C) :
category_theory.functor.obj Γ (opposite.op X) =
category_theory.functor.obj (PresheafedSpace.presheaf X) (opposite.op ⊤) :=
rfl
theorem Γ_map_op {C : Type u} [category_theory.category C] {X : PresheafedSpace C}
{Y : PresheafedSpace C} (f : X ⟶ Y) :
category_theory.functor.map Γ (category_theory.has_hom.hom.op f) =
category_theory.nat_trans.app (hom.c f) (opposite.op ⊤) ≫
category_theory.functor.map (PresheafedSpace.presheaf X)
(category_theory.has_hom.hom.op (topological_space.opens.le_map_top (hom.base f) ⊤)) :=
rfl
end PresheafedSpace
end algebraic_geometry
namespace category_theory
namespace functor
/-- We can apply a functor `F : C ⥤ D` to the values of the presheaf in any `PresheafedSpace C`,
giving a functor `PresheafedSpace C ⥤ PresheafedSpace D` -/
def map_presheaf {C : Type u} [category C] {D : Type u} [category D] (F : C ⥤ D) :
algebraic_geometry.PresheafedSpace C ⥤ algebraic_geometry.PresheafedSpace D :=
mk
(fun (X : algebraic_geometry.PresheafedSpace C) =>
algebraic_geometry.PresheafedSpace.mk (algebraic_geometry.PresheafedSpace.carrier X)
(algebraic_geometry.PresheafedSpace.presheaf X ⋙ F))
fun (X Y : algebraic_geometry.PresheafedSpace C) (f : X ⟶ Y) =>
algebraic_geometry.PresheafedSpace.hom.mk (algebraic_geometry.PresheafedSpace.hom.base f)
(whisker_right (algebraic_geometry.PresheafedSpace.hom.c f) F)
@[simp] theorem map_presheaf_obj_X {C : Type u} [category C] {D : Type u} [category D] (F : C ⥤ D)
(X : algebraic_geometry.PresheafedSpace C) : ↑(obj (map_presheaf F) X) = ↑X :=
rfl
@[simp] theorem map_presheaf_obj_presheaf {C : Type u} [category C] {D : Type u} [category D]
(F : C ⥤ D) (X : algebraic_geometry.PresheafedSpace C) :
algebraic_geometry.PresheafedSpace.presheaf (obj (map_presheaf F) X) =
algebraic_geometry.PresheafedSpace.presheaf X ⋙ F :=
rfl
@[simp] theorem map_presheaf_map_f {C : Type u} [category C] {D : Type u} [category D] (F : C ⥤ D)
{X : algebraic_geometry.PresheafedSpace C} {Y : algebraic_geometry.PresheafedSpace C}
(f : X ⟶ Y) :
algebraic_geometry.PresheafedSpace.hom.base (map (map_presheaf F) f) =
algebraic_geometry.PresheafedSpace.hom.base f :=
rfl
@[simp] theorem map_presheaf_map_c {C : Type u} [category C] {D : Type u} [category D] (F : C ⥤ D)
{X : algebraic_geometry.PresheafedSpace C} {Y : algebraic_geometry.PresheafedSpace C}
(f : X ⟶ Y) :
algebraic_geometry.PresheafedSpace.hom.c (map (map_presheaf F) f) =
whisker_right (algebraic_geometry.PresheafedSpace.hom.c f) F :=
rfl
end functor
namespace nat_trans
/--
A natural transformation induces a natural transformation between the `map_presheaf` functors.
-/
def on_presheaf {C : Type u} [category C] {D : Type u} [category D] {F : C ⥤ D} {G : C ⥤ D}
(α : F ⟶ G) : functor.map_presheaf G ⟶ functor.map_presheaf F :=
mk
fun (X : algebraic_geometry.PresheafedSpace C) =>
algebraic_geometry.PresheafedSpace.hom.mk 𝟙
(whisker_left (algebraic_geometry.PresheafedSpace.presheaf X) α ≫
iso.inv (functor.left_unitor (algebraic_geometry.PresheafedSpace.presheaf X ⋙ G)) ≫
whisker_right
(nat_trans.op
(iso.hom
(topological_space.opens.map_id (algebraic_geometry.PresheafedSpace.carrier X))))
(algebraic_geometry.PresheafedSpace.presheaf X ⋙ G))
end Mathlib |
62ccda64dbf7d0834a770c4223a59b303eb26e7a | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /stage0/src/Lean/Data/SMap.lean | 4714b5654177a48f1e50942702260686635ad733 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,196 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Std.Data.HashMap
import Std.Data.PersistentHashMap
universes u v w w'
namespace Lean
open Std (HashMap PHashMap)
/- Staged map for implementing the Environment. The idea is to store
imported entries into a hashtable and local entries into a persistent hashtable.
Hypotheses:
- The number of entries (i.e., declarations) coming from imported files is much bigger than
the number of entries in the current file.
- HashMap is faster than PersistentHashMap.
- When we are reading imported files, we have exclusive access to the map, and efficient
destructive updates are performed.
Remarks:
- We never remove declarations from the Environment. In principle, we could support
deletion by using `(PHashMap α (Option β))` where the value `none` would indicate
that an entry was "removed" from the hashtable.
- We do not need additional bookkeeping for extracting the local entries.
-/
structure SMap (α : Type u) (β : Type v) [BEq α] [Hashable α] where
stage₁ : Bool := true
map₁ : HashMap α β := {}
map₂ : PHashMap α β := {}
namespace SMap
variables {α : Type u} {β : Type v} [BEq α] [Hashable α]
instance : Inhabited (SMap α β) := ⟨{}⟩
def empty : SMap α β := {}
@[specialize] def insert : SMap α β → α → β → SMap α β
| ⟨true, m₁, m₂⟩, k, v => ⟨true, m₁.insert k v, m₂⟩
| ⟨false, m₁, m₂⟩, k, v => ⟨false, m₁, m₂.insert k v⟩
@[specialize] def find? : SMap α β → α → Option β
| ⟨true, m₁, _⟩, k => m₁.find? k
| ⟨false, m₁, m₂⟩, k => (m₂.find? k).orElse (m₁.find? k)
@[inline] def findD (m : SMap α β) (a : α) (b₀ : β) : β :=
(m.find? a).getD b₀
@[inline] def find! [Inhabited β] (m : SMap α β) (a : α) : β :=
match m.find? a with
| some b => b
| none => panic! "key is not in the map"
@[specialize] def contains : SMap α β → α → Bool
| ⟨true, m₁, _⟩, k => m₁.contains k
| ⟨false, m₁, m₂⟩, k => m₁.contains k || m₂.contains k
/- Similar to `find?`, but searches for result in the hashmap first.
So, the result is correct only if we never "overwrite" `map₁` entries using `map₂`. -/
@[specialize] def find?' : SMap α β → α → Option β
| ⟨true, m₁, _⟩, k => m₁.find? k
| ⟨false, m₁, m₂⟩, k => (m₁.find? k).orElse (m₂.find? k)
/- Move from stage 1 into stage 2. -/
def switch (m : SMap α β) : SMap α β :=
if m.stage₁ then { m with stage₁ := false } else m
@[inline] def foldStage2 {σ : Type w} (f : σ → α → β → σ) (s : σ) (m : SMap α β) : σ :=
m.map₂.foldl f s
def fold {σ : Type w} (f : σ → α → β → σ) (s : σ) (m : SMap α β) : σ :=
m.map₂.foldl f $ m.map₁.fold f s
def size (m : SMap α β) : Nat :=
m.map₁.size + m.map₂.size
def stageSizes (m : SMap α β) : Nat × Nat :=
(m.map₁.size, m.map₂.size)
def numBuckets (m : SMap α β) : Nat :=
m.map₁.numBuckets
end SMap
end Lean
|
123dcf448bf5e8ce0a0ca162dc0f054b5986652e | 6b10c15e653d49d146378acda9f3692e9b5b1950 | /examples/basic_skills/unnamed_399.lean | 186c042cd8243b7dd1a7b0aa612acad1c23b1d8e | [] | no_license | gebner/mathematics_in_lean | 3cf7f18767208ea6c3307ec3a67c7ac266d8514d | 6d1462bba46d66a9b948fc1aef2714fd265cde0b | refs/heads/master | 1,655,301,945,565 | 1,588,697,505,000 | 1,588,697,505,000 | 261,523,603 | 0 | 0 | null | 1,588,695,611,000 | 1,588,695,610,000 | null | UTF-8 | Lean | false | false | 280 | lean | import data.real.basic
variables a b c d : ℝ
-- BEGIN
example (a b c d : ℝ) (hyp : c = d * a + b) (hyp' : b = a * d) :
c = 2 * a * d :=
begin
rw hyp' at hyp,
rw mul_comm d a at hyp,
rw ← two_mul (a*d) at hyp,
rw ← mul_assoc 2 a d at hyp,
exact hyp
end
-- END |
71dd71ba5370b6c7d136fabd80a21b2a43dd7100 | 367134ba5a65885e863bdc4507601606690974c1 | /src/linear_algebra/prod.lean | 67ce80059f119364f049df48140e7b0f53f2fa89 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 15,093 | 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, Kevin Buzzard, Yury Kudryashov, Eric Wieser
-/
import linear_algebra.basic
/-! ### Products of semimodules
This file defines constructors for linear maps whose domains or codomains are products.
It contains theorems relating these to each other, as well as to `submodule.prod`, `submodule.map`,
`submodule.comap`, `linear_map.range`, and `linear_map.ker`.
## Main definitions
- products in the domain:
- `linear_map.fst`
- `linear_map.snd`
- `linear_map.coprod`
- `linear_map.prod_ext`
- products in the codomain:
- `linear_map.inl`
- `linear_map.inr`
- `linear_map.prod`
- products in both domain and codomain:
- `linear_map.prod_map`
- `linear_equiv.prod_map`
- `linear_equiv.skew_prod`
-/
universes u v w x y z u' v' w' y'
variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'}
variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x}
section prod
namespace linear_map
variables (S : Type*) [semiring R] [semiring S]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
variables (f : M →ₗ[R] M₂)
section
variables (R M M₂)
/-- The first projection of a product is a linear map. -/
def fst : M × M₂ →ₗ[R] M := ⟨prod.fst, λ x y, rfl, λ x y, rfl⟩
/-- The second projection of a product is a linear map. -/
def snd : M × M₂ →ₗ[R] M₂ := ⟨prod.snd, λ x y, rfl, λ x y, rfl⟩
end
@[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl
@[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl
/-- The prod of two linear maps is a linear map. -/
@[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (M →ₗ[R] M₂ × M₃) :=
{ to_fun := λ x, (f x, g x),
map_add' := λ x y, by simp only [prod.mk_add_mk, map_add],
map_smul' := λ c x, by simp only [prod.smul_mk, map_smul] }
@[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(fst R M₂ M₃).comp (prod f g) = f := by ext; refl
@[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(snd R M₂ M₃).comp (prod f g) = g := by ext; refl
@[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = linear_map.id :=
by ext; refl
/-- Taking the product of two maps with the same domain is equivalent to taking the product of
their codomains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps] def prod_equiv
[semimodule S M₂] [semimodule S M₃] [smul_comm_class R S M₂] [smul_comm_class R S M₃] :
((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] (M →ₗ[R] M₂ × M₃) :=
{ to_fun := λ f, f.1.prod f.2,
inv_fun := λ f, ((fst _ _ _).comp f, (snd _ _ _).comp f),
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl,
map_add' := λ a b, rfl,
map_smul' := λ r a, rfl }
section
variables (R M M₂)
/-- The left injection into a product is a linear map. -/
def inl : M →ₗ[R] M × M₂ := prod linear_map.id 0
/-- The right injection into a product is a linear map. -/
def inr : M₂ →ₗ[R] M × M₂ := prod 0 linear_map.id
end
@[simp] theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl
@[simp] theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl
theorem inl_eq_prod : inl R M M₂ = prod linear_map.id 0 := rfl
theorem inr_eq_prod : inr R M M₂ = prod 0 linear_map.id := rfl
theorem inl_injective : function.injective (inl R M M₂) :=
λ _, by simp
theorem inr_injective : function.injective (inr R M M₂) :=
λ _, by simp
/-- The coprod function `λ x : M × M₂, f.1 x.1 + f.2 x.2` is a linear map. -/
def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ :=
f.comp (fst _ _ _) + g.comp (snd _ _ _)
@[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) :
coprod f g x = f x.1 + g x.2 := rfl
@[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(coprod f g).comp (inl R M M₂) = f :=
by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply]
@[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(coprod f g).comp (inr R M M₂) = g :=
by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply]
@[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = linear_map.id :=
by ext; simp only [prod.mk_add_mk, add_zero, id_apply, coprod_apply,
inl_apply, inr_apply, zero_add]
theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) :
f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) :=
ext $ λ x, f.map_add (g₁ x.1) (g₂ x.2)
theorem fst_eq_coprod : fst R M M₂ = coprod linear_map.id 0 := by ext; simp
theorem snd_eq_coprod : snd R M M₂ = coprod 0 linear_map.id := by ext; simp
@[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄)
(f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) :
(f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' :=
rfl
/-- Taking the product of two maps with the same codomain is equivalent to taking the product of
their domains.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps] def coprod_equiv [semimodule S M₃] [smul_comm_class R S M₃] :
((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] (M × M₂ →ₗ[R] M₃) :=
{ to_fun := λ f, f.1.coprod f.2,
inv_fun := λ f, (f.comp (inl _ _ _), f.comp (inr _ _ _)),
left_inv := λ f, by simp only [prod.mk.eta, coprod_inl, coprod_inr],
right_inv := λ f, by simp only [←comp_coprod, comp_id, coprod_inl_inr],
map_add' := λ a b,
by { ext, simp only [prod.snd_add, add_apply, coprod_apply, prod.fst_add], ac_refl },
map_smul' := λ r a,
by { ext, simp only [smul_add, smul_apply, prod.smul_snd, prod.smul_fst, coprod_apply] } }
theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} :
f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) :=
(coprod_equiv ℕ).symm.injective.eq_iff.symm.trans prod.ext_iff
/--
Split equality of linear maps from a product into linear maps over each component, to allow `ext`
to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`.
See note [partially-applied ext lemmas]. -/
@[ext] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃}
(hl : f.comp (inl _ _ _) = g.comp (inl _ _ _))
(hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) :
f = g :=
prod_ext_iff.2 ⟨hl, hr⟩
/-- `prod.map` of two linear maps. -/
def prod_map (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : (M × M₂) →ₗ[R] (M₃ × M₄) :=
(f.comp (fst R M M₂)).prod (g.comp (snd R M M₂))
@[simp] theorem prod_map_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) :
f.prod_map g x = (f x.1, g x.2) := rfl
end linear_map
end prod
namespace linear_map
open submodule
variables [semiring R]
[add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
[semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄]
lemma range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(f.coprod g).range = f.range ⊔ g.range :=
submodule.ext $ λ x, by simp [mem_sup]
lemma is_compl_range_inl_inr : is_compl (inl R M M₂).range (inr R M M₂).range :=
begin
split,
{ rintros ⟨_, _⟩ ⟨⟨x, -, hx⟩, ⟨y, -, hy⟩⟩,
simp only [prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢,
exact ⟨hy.1.symm, hx.2.symm⟩ },
{ rintros ⟨x, y⟩ -,
simp only [mem_sup, mem_range, exists_prop],
refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, _⟩,
simp }
end
lemma sup_range_inl_inr : (inl R M M₂).range ⊔ (inr R M M₂).range = ⊤ :=
is_compl_range_inl_inr.sup_eq_top
lemma disjoint_inl_inr : disjoint (inl R M M₂).range (inr R M M₂).range :=
by simp [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] {contextual := tt}; intros; refl
theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃)
(p : submodule R M) (q : submodule R M₂) :
map (coprod f g) (p.prod q) = map f p ⊔ map g q :=
begin
refine le_antisymm _ (sup_le (map_le_iff_le_comap.2 _) (map_le_iff_le_comap.2 _)),
{ rw le_def', rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩,
exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ },
{ exact λ x hx, ⟨(x, 0), by simp [hx]⟩ },
{ exact λ x hx, ⟨(0, x), by simp [hx]⟩ }
end
theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃)
(p : submodule R M₂) (q : submodule R M₃) :
comap (prod f g) (p.prod q) = comap f p ⊓ comap g q :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_inf_comap (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.comap (linear_map.fst R M M₂) ⊓ q.comap (linear_map.snd R M M₂) :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_sup_map (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.map (linear_map.inl R M M₂) ⊔ q.map (linear_map.inr R M M₂) :=
by rw [← map_coprod_prod, coprod_inl_inr, map_id]
lemma span_inl_union_inr {s : set M} {t : set M₂} :
span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) :=
by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image]
@[simp] lemma ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
ker (prod f g) = ker f ⊓ ker g :=
by rw [ker, ← prod_bot, comap_prod_prod]; refl
lemma range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
range (prod f g) ≤ (range f).prod (range g) :=
begin
simp only [le_def', prod_apply, mem_range, mem_coe, mem_prod, exists_imp_distrib],
rintro _ x rfl,
exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩
end
end linear_map
namespace submodule
open linear_map
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid M₂]
variables [semimodule R M] [semimodule R M₂]
lemma sup_eq_range (p q : submodule R M) : p ⊔ q = (p.subtype.coprod q.subtype).range :=
submodule.ext $ λ x, by simp [submodule.mem_sup, submodule.exists]
variables (p : submodule R M) (q : submodule R M₂)
@[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ :=
by { ext ⟨x, y⟩, simp only [and.left_comm, eq_comm, mem_map, prod.mk.inj_iff, inl_apply, mem_bot,
exists_eq_left', mem_prod] }
@[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q :=
by ext ⟨x, y⟩; simp [and.left_comm, eq_comm]
@[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ :=
by ext ⟨x, y⟩; simp
@[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q :=
by ext ⟨x, y⟩; simp
@[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp
@[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp
@[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)]
@[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)]
@[simp] theorem ker_inl : (inl R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inl]
@[simp] theorem ker_inr : (inr R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inr]
@[simp] theorem range_fst : (fst R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_fst]
@[simp] theorem range_snd : (snd R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_snd]
end submodule
namespace linear_equiv
section
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables {semimodule_M₃ : semimodule R M₃} {semimodule_M₄ : semimodule R M₄}
variables (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
/-- Product of linear equivalences; the maps come from `equiv.prod_congr`. -/
protected def prod :
(M × M₃) ≃ₗ[R] (M₂ × M₄) :=
{ map_add' := λ x y, prod.ext (e₁.map_add _ _) (e₂.map_add _ _),
map_smul' := λ c x, prod.ext (e₁.map_smul c _) (e₂.map_smul c _),
.. equiv.prod_congr e₁.to_equiv e₂.to_equiv }
lemma prod_symm : (e₁.prod e₂).symm = e₁.symm.prod e₂.symm := rfl
@[simp] lemma prod_apply (p) :
e₁.prod e₂ p = (e₁ p.1, e₂ p.2) := rfl
@[simp, norm_cast] lemma coe_prod :
(e₁.prod e₂ : (M × M₃) →ₗ[R] (M₂ × M₄)) = (e₁ : M →ₗ[R] M₂).prod_map (e₂ : M₃ →ₗ[R] M₄) := rfl
end
section
variables [semiring R]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_group M₄]
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables {semimodule_M₃ : semimodule R M₃} {semimodule_M₄ : semimodule R M₄}
variables (e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄)
/-- Equivalence given by a block lower diagonal matrix. `e₁` and `e₂` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
protected def skew_prod (f : M →ₗ[R] M₄) :
(M × M₃) ≃ₗ[R] M₂ × M₄ :=
{ inv_fun := λ p : M₂ × M₄, (e₁.symm p.1, e₂.symm (p.2 - f (e₁.symm p.1))),
left_inv := λ p, by simp,
right_inv := λ p, by simp,
.. ((e₁ : M →ₗ[R] M₂).comp (linear_map.fst R M M₃)).prod
((e₂ : M₃ →ₗ[R] M₄).comp (linear_map.snd R M M₃) +
f.comp (linear_map.fst R M M₃)) }
@[simp] lemma skew_prod_apply (f : M →ₗ[R] M₄) (x) :
e₁.skew_prod e₂ f x = (e₁ x.1, e₂ x.2 + f x.1) := rfl
@[simp] lemma skew_prod_symm_apply (f : M →ₗ[R] M₄) (x) :
(e₁.skew_prod e₂ f).symm x = (e₁.symm x.1, e₂.symm (x.2 - f (e₁.symm x.1))) := rfl
end
end linear_equiv
namespace linear_map
open submodule
variables [ring R]
variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [semimodule R M] [semimodule R M₂] [semimodule R M₃]
/-- If the union of the kernels `ker f` and `ker g` spans the domain, then the range of
`prod f g` is equal to the product of `range f` and `range g`. -/
lemma range_prod_eq {f : M →ₗ[R] M₂} {g : M →ₗ[R] M₃} (h : ker f ⊔ ker g = ⊤) :
range (prod f g) = (range f).prod (range g) :=
begin
refine le_antisymm (f.range_prod_le g) _,
simp only [le_def', prod_apply, mem_range, mem_coe, mem_prod, exists_imp_distrib, and_imp,
prod.forall],
rintros _ _ x rfl y rfl,
simp only [prod.mk.inj_iff, ← sub_mem_ker_iff],
have : y - x ∈ ker f ⊔ ker g, { simp only [h, mem_top] },
rcases mem_sup.1 this with ⟨x', hx', y', hy', H⟩,
refine ⟨x' + x, _, _⟩,
{ rwa add_sub_cancel },
{ rwa [← eq_sub_iff_add_eq.1 H, add_sub_add_right_eq_sub, ← neg_mem_iff, neg_sub,
add_sub_cancel'] }
end
end linear_map
|
6f7c078edac4bff41c8c37d0ce90ef6abdfa689f | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/448.lean | 404a08d322d75e5de12c2c6b44cbe700b3d93cab | [
"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 | 905 | lean | namespace TryCatchWithAutolift
structure M (α : Type) where
σ : ExceptT String IO α
instance : Monad M where
pure x := { σ := pure x }
bind x f := { σ := do (f (← x.σ)).σ }
map f x := { σ := return f (← x.σ) }
instance : MonadLiftT IO M where
monadLift {α : Type} (act : IO α) : M α :=
{ σ := monadLift act }
instance : MonadFinally M where
tryFinally' := fun x h => M.mk do
tryFinally' x.σ fun e => (h e).σ
def t : M Unit := do
liftM $ IO.println "bad"
try do pure () -- Error
catch ex : IO.Error => do pure ()
finally do pure ()
instance : MonadExceptOf IO.Error M where
throw e := { σ := throwThe IO.Error e }
tryCatch x handle := { σ := tryCatchThe IO.Error x.σ fun e => handle e |>.σ }
def t2 : M Unit := do
liftM $ IO.println "bad"
try do pure ()
catch ex : IO.Error => do pure ()
finally do pure ()
end TryCatchWithAutolift
|
2bab630ebb6de816c4e70ec06091f7b3098284e2 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/linear_algebra/pi_tensor_product.lean | 6652b11e06b4af714888236743760167281a7b07 | [
"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 | 21,341 | lean | /-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Eric Wieser
-/
import group_theory.congruence
import linear_algebra.multilinear
/-!
# Tensor product of an indexed family of modules over commutative semirings
We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative
semirings. We denote this space by `⨂[R] i, s i` and define it as `free_add_monoid (R × Π i, s i)`
quotiented by the appropriate equivalence relation. The treatment follows very closely that of the
binary tensor product in `linear_algebra/tensor_product.lean`.
## Main definitions
* `pi_tensor_product R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product
of all the `s i`'s. This is denoted by `⨂[R] i, s i`.
* `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`.
This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`.
* `lift_add_hom` constructs an `add_monoid_hom` from `(⨂[R] i, s i)` to some space `F` from a
function `φ : (R × Π i, s i) → F` with the appropriate properties.
* `lift φ` with `φ : multilinear_map R s E` is the corresponding linear map
`(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence.
* `pi_tensor_product.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`.
* `pi_tensor_product.tmul_equiv` equivalence between a `tensor_product` of `pi_tensor_product`s and
a single `pi_tensor_product`.
## Notations
* `⨂[R] i, s i` is defined as localized notation in locale `tensor_product`
* `⨂ₜ[R] i, f i` with `f : Π i, f i` is defined globally as the tensor product of all the `f i`'s.
## Implementation notes
* We define it via `free_add_monoid (R × Π i, s i)` with the `R` representing a "hidden" tensor
factor, rather than `free_add_monoid (Π i, s i)` to ensure that, if `ι` is an empty type,
the space is isomorphic to the base ring `R`.
* We have not restricted the index type `ι` to be a `fintype`, as nothing we do here strictly
requires it. However, problems may arise in the case where `ι` is infinite; use at your own
caution.
## TODO
* Define tensor powers, symmetric subspace, etc.
* API for the various ways `ι` can be split into subsets; connect this with the binary
tensor product.
* Include connection with holors.
* Port more of the API from the binary tensor product over to this case.
## Tags
multilinear, tensor, tensor product
-/
open function
section semiring
variables {ι ι₂ ι₃ : Type*} [decidable_eq ι] [decidable_eq ι₂] [decidable_eq ι₃]
variables {R : Type*} [comm_semiring R]
variables {R' : Type*} [comm_semiring R'] [algebra R' R]
variables {s : ι → Type*} [∀ i, add_comm_monoid (s i)] [∀ i, module R (s i)]
variables {M : Type*} [add_comm_monoid M] [module R M]
variables {E : Type*} [add_comm_monoid E] [module R E]
variables {F : Type*} [add_comm_monoid F]
namespace pi_tensor_product
include R
variables (R) (s)
/-- The relation on `free_add_monoid (R × Π i, s i)` that generates a congruence whose quotient is
the tensor product. -/
inductive eqv : free_add_monoid (R × Π i, s i) → free_add_monoid (R × Π i, s i) → Prop
| of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (hf : f i = 0), eqv (free_add_monoid.of (r, f)) 0
| of_zero_scalar : ∀ (f : Π i, s i), eqv (free_add_monoid.of (0, f)) 0
| of_add : ∀ (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i), eqv
(free_add_monoid.of (r, update f i m₁) + free_add_monoid.of (r, update f i m₂))
(free_add_monoid.of (r, update f i (m₁ + m₂)))
| of_add_scalar : ∀ (r r' : R) (f : Π i, s i), eqv
(free_add_monoid.of (r, f) + free_add_monoid.of (r', f))
(free_add_monoid.of (r + r', f))
| of_smul : ∀ (r : R) (f : Π i, s i) (i : ι) (r' : R), eqv
(free_add_monoid.of (r, update f i (r' • (f i))))
(free_add_monoid.of (r' * r, f))
| add_comm : ∀ x y, eqv (x + y) (y + x)
end pi_tensor_product
variables (R) (s)
/-- `pi_tensor_product R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor
product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/
def pi_tensor_product : Type* :=
(add_con_gen (pi_tensor_product.eqv R s)).quotient
variables {R}
/- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product, given `s : ι → Type*`. -/
localized "notation `⨂[`:100 R `] ` binders `, ` r:(scoped:67 f, pi_tensor_product R f) := r"
in tensor_product
open_locale tensor_product
namespace pi_tensor_product
section module
instance : add_comm_monoid (⨂[R] i, s i) :=
{ add_comm := λ x y, add_con.induction_on₂ x y $ λ x y, quotient.sound' $
add_con_gen.rel.of _ _ $ eqv.add_comm _ _,
.. (add_con_gen (pi_tensor_product.eqv R s)).add_monoid }
instance : inhabited (⨂[R] i, s i) := ⟨0⟩
variables (R) {s}
/-- `tprod_coeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i`
over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary
definition for this file alone, and that one should use `tprod` defined below for most purposes. -/
def tprod_coeff (r : R) (f : Π i, s i) : ⨂[R] i, s i := add_con.mk' _ $ free_add_monoid.of (r, f)
variables {R}
lemma zero_tprod_coeff (f : Π i, s i) : tprod_coeff R 0 f = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero_scalar _
lemma zero_tprod_coeff' (z : R) (f : Π i, s i) (i : ι) (hf: f i = 0) : tprod_coeff R z f = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero _ _ i hf
lemma add_tprod_coeff (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) :
tprod_coeff R z (update f i m₁) + tprod_coeff R z (update f i m₂) =
tprod_coeff R z (update f i (m₁ + m₂)) :=
quotient.sound' $ add_con_gen.rel.of _ _ (eqv.of_add z f i m₁ m₂)
lemma add_tprod_coeff' (z₁ z₂ : R) (f : Π i, s i) :
tprod_coeff R z₁ f + tprod_coeff R z₂ f = tprod_coeff R (z₁ + z₂) f :=
quotient.sound' $ add_con_gen.rel.of _ _ (eqv.of_add_scalar z₁ z₂ f)
lemma smul_tprod_coeff_aux (z : R) (f : Π i, s i) (i : ι) (r : R) :
tprod_coeff R z (update f i (r • f i)) = tprod_coeff R (r * z) f :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_smul _ _ _ _
lemma smul_tprod_coeff (z : R) (f : Π i, s i) (i : ι) (r : R')
[module R' (s i)] [is_scalar_tower R' R (s i)] :
tprod_coeff R z (update f i (r • f i)) = tprod_coeff R (r • z) f :=
begin
have h₁ : r • z = (r • (1 : R)) * z := by simp,
have h₂ : r • (f i) = (r • (1 : R)) • f i := by simp,
rw [h₁, h₂],
exact smul_tprod_coeff_aux z f i _,
end
/-- Construct an `add_monoid_hom` from `(⨂[R] i, s i)` to some space `F` from a function
`φ : (R × Π i, s i) → F` with the appropriate properties. -/
def lift_add_hom (φ : (R × Π i, s i) → F)
(C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (hf : f i = 0), φ (r, f) = 0)
(C0' : ∀ (f : Π i, s i), φ (0, f) = 0)
(C_add : ∀ (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂)))
(C_add_scalar : ∀ (r r' : R) (f : Π i, s i),
φ (r , f) + φ (r', f) = φ (r + r', f))
(C_smul : ∀ (r : R) (f : Π i, s i) (i : ι) (r' : R),
φ (r, update f i (r' • (f i))) = φ (r' * r, f))
: (⨂[R] i, s i) →+ F :=
(add_con_gen (pi_tensor_product.eqv R s)).lift (free_add_monoid.lift φ) $ add_con.add_con_gen_le $
λ x y hxy, match x, y, hxy with
| _, _, (eqv.of_zero r' f i hf) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C0 r' f i hf]
| _, _, (eqv.of_zero_scalar f) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C0']
| _, _, (eqv.of_add z f i m₁ m₂) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C_add]
| _, _, (eqv.of_add_scalar z₁ z₂ f) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C_add_scalar]
| _, _, (eqv.of_smul z f i r') := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C_smul]
| _, _, (eqv.add_comm x y) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, add_comm]
end
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance has_scalar' : has_scalar R' (⨂[R] i, s i) :=
⟨λ r, lift_add_hom (λ f : R × Π i, s i, tprod_coeff R (r • f.1) f.2)
(λ r' f i hf, by simp_rw [zero_tprod_coeff' _ f i hf])
(λ f, by simp [zero_tprod_coeff])
(λ r' f i m₁ m₂, by simp [add_tprod_coeff])
(λ r' r'' f, by simp [add_tprod_coeff', mul_add])
(λ z f i r', by simp [smul_tprod_coeff])⟩
instance : has_scalar R (⨂[R] i, s i) := pi_tensor_product.has_scalar'
lemma smul_tprod_coeff' (r : R') (z : R) (f : Π i, s i) :
r • (tprod_coeff R z f) = tprod_coeff R (r • z) f := rfl
protected theorem smul_add (r : R') (x y : ⨂[R] i, s i) :
r • (x + y) = r • x + r • y :=
add_monoid_hom.map_add _ _ _
@[elab_as_eliminator]
protected theorem induction_on'
{C : (⨂[R] i, s i) → Prop}
(z : ⨂[R] i, s i)
(C1 : ∀ {r : R} {f : Π i, s i}, C (tprod_coeff R r f))
(Cp : ∀ {x y}, C x → C y → C (x + y)) : C z :=
begin
have C0 : C 0,
{ have h₁ := @C1 0 0,
rwa [zero_tprod_coeff] at h₁ },
refine add_con.induction_on z (λ x, free_add_monoid.rec_on x C0 _),
simp_rw add_con.coe_add,
refine λ f y ih, Cp _ ih,
convert @C1 f.1 f.2,
simp only [prod.mk.eta],
end
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance module' : module R' (⨂[R] i, s i) :=
{ smul := (•),
smul_add := λ r x y, pi_tensor_product.smul_add r x y,
mul_smul := λ r r' x,
begin
refine pi_tensor_product.induction_on' x _ _,
{ intros r'' f,
simp [smul_tprod_coeff', smul_smul] },
{ intros x y ihx ihy,
simp [pi_tensor_product.smul_add, ihx, ihy] }
end,
one_smul := λ x, pi_tensor_product.induction_on' x
(λ f, by simp [smul_tprod_coeff' _ _])
(λ z y ihz ihy, by simp_rw [pi_tensor_product.smul_add, ihz, ihy]),
add_smul := λ r r' x,
begin
refine pi_tensor_product.induction_on' x _ _,
{ intros r f,
simp [smul_tprod_coeff' _ _, add_smul, add_tprod_coeff'] },
{ intros x y ihx ihy,
simp [pi_tensor_product.smul_add, ihx, ihy, add_add_add_comm] }
end,
smul_zero := λ r, add_monoid_hom.map_zero _,
zero_smul := λ x,
begin
refine pi_tensor_product.induction_on' x _ _,
{ intros r f,
simp_rw [smul_tprod_coeff' _ _, zero_smul],
exact zero_tprod_coeff _ },
{ intros x y ihx ihy,
rw [pi_tensor_product.smul_add, ihx, ihy, add_zero] },
end }
instance : module R' (⨂[R] i, s i) := pi_tensor_product.module'
variables {R}
variables (R)
/-- The canonical `multilinear_map R s (⨂[R] i, s i)`. -/
def tprod : multilinear_map R s (⨂[R] i, s i) :=
{ to_fun := tprod_coeff R 1,
map_add' := λ f i x y, (add_tprod_coeff (1 : R) f i x y).symm,
map_smul' := λ f i r x,
by simp_rw [smul_tprod_coeff', ←smul_tprod_coeff (1 : R) _ i, update_idem, update_same] }
variables {R}
notation `⨂ₜ[`:100 R`] ` binders `, ` r:(scoped:67 f, tprod R f) := r
@[simp]
lemma tprod_coeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprod_coeff R z f = z • tprod R f :=
begin
have : z = z • (1 : R) := by simp only [mul_one, algebra.id.smul_eq_mul],
conv_lhs { rw this },
rw ←smul_tprod_coeff',
refl,
end
@[elab_as_eliminator]
protected theorem induction_on
{C : (⨂[R] i, s i) → Prop}
(z : ⨂[R] i, s i)
(C1 : ∀ {r : R} {f : Π i, s i}, C (r • (tprod R f)))
(Cp : ∀ {x y}, C x → C y → C (x + y)) : C z :=
begin
simp_rw ←tprod_coeff_eq_smul_tprod at C1,
exact pi_tensor_product.induction_on' z @C1 @Cp,
end
@[ext]
theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E}
(H : φ₁.comp_multilinear_map (tprod R) = φ₂.comp_multilinear_map (tprod R)) : φ₁ = φ₂ :=
begin
refine linear_map.ext _,
refine λ z,
(pi_tensor_product.induction_on' z _ (λ x y hx hy, by rw [φ₁.map_add, φ₂.map_add, hx, hy])),
{ intros r f,
rw [tprod_coeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul],
apply _root_.congr_arg,
exact multilinear_map.congr_fun H f }
end
end module
section multilinear
open multilinear_map
variables {s}
/-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a
`multilinear map R s E` with the property that its composition with the canonical
`multilinear_map R s (⨂[R] i, s i)` is the given multilinear map. -/
def lift_aux (φ : multilinear_map R s E) : (⨂[R] i, s i) →+ E :=
lift_add_hom (λ (p : R × Π i, s i), p.1 • (φ p.2))
(λ z f i hf, by rw [map_coord_zero φ i hf, smul_zero])
(λ f, by rw [zero_smul])
(λ z f i m₁ m₂, by rw [←smul_add, φ.map_add])
(λ z₁ z₂ f, by rw [←add_smul])
(λ z f i r, by simp [φ.map_smul, smul_smul, mul_comm])
lemma lift_aux_tprod (φ : multilinear_map R s E) (f : Π i, s i) : lift_aux φ (tprod R f) = φ f :=
by simp only [lift_aux, lift_add_hom, tprod, multilinear_map.coe_mk, tprod_coeff,
free_add_monoid.lift_eval_of, one_smul, add_con.lift_mk']
lemma lift_aux_tprod_coeff (φ : multilinear_map R s E) (z : R) (f : Π i, s i) :
lift_aux φ (tprod_coeff R z f) = z • φ f :=
by simp [lift_aux, lift_add_hom, tprod_coeff, free_add_monoid.lift_eval_of]
lemma lift_aux.smul {φ : multilinear_map R s E} (r : R) (x : ⨂[R] i, s i) :
lift_aux φ (r • x) = r • lift_aux φ x :=
begin
refine pi_tensor_product.induction_on' x _ _,
{ intros z f,
rw [smul_tprod_coeff' r z f, lift_aux_tprod_coeff, lift_aux_tprod_coeff, smul_assoc] },
{ intros z y ihz ihy,
rw [smul_add, (lift_aux φ).map_add, ihz, ihy, (lift_aux φ).map_add, smul_add] }
end
/-- Constructing a linear map `(⨂[R] i, s i) → E` given a `multilinear_map R s E` with the
property that its composition with the canonical `multilinear_map R s E` is
the given multilinear map `φ`. -/
def lift : (multilinear_map R s E) ≃ₗ[R] ((⨂[R] i, s i) →ₗ[R] E) :=
{ to_fun := λ φ, { map_smul' := lift_aux.smul, .. lift_aux φ },
inv_fun := λ φ', φ'.comp_multilinear_map (tprod R),
left_inv := λ φ, by { ext, simp [lift_aux_tprod, linear_map.comp_multilinear_map] },
right_inv := λ φ, by { ext, simp [lift_aux_tprod] },
map_add' := λ φ₁ φ₂, by { ext, simp [lift_aux_tprod] },
map_smul' := λ r φ₂, by { ext, simp [lift_aux_tprod] } }
variables {φ : multilinear_map R s E}
@[simp] lemma lift.tprod (f : Π i, s i) : lift φ (tprod R f) = φ f := lift_aux_tprod φ f
theorem lift.unique' {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : φ'.comp_multilinear_map (tprod R) = φ) :
φ' = lift φ :=
ext $ H.symm ▸ (lift.symm_apply_apply φ).symm
theorem lift.unique {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : ∀ f, φ' (tprod R f) = φ f) :
φ' = lift φ :=
lift.unique' (multilinear_map.ext H)
@[simp]
theorem lift_symm (φ' : (⨂[R] i, s i) →ₗ[R] E) : lift.symm φ' = φ'.comp_multilinear_map (tprod R) :=
rfl
@[simp]
theorem lift_tprod : lift (tprod R : multilinear_map R s _) = linear_map.id :=
eq.symm $ lift.unique' rfl
section
variables (R M)
/-- Re-index the components of the tensor power by `e`.
For simplicity, this is defined only for homogeneously- (rather than dependently-) typed components.
-/
def reindex (e : ι ≃ ι₂) : ⨂[R] i : ι, M ≃ₗ[R] ⨂[R] i : ι₂, M :=
linear_equiv.of_linear
((lift.symm.trans $
multilinear_map.dom_dom_congr_linear_equiv M (⨂[R] i : ι₂, M) R R e.symm).trans
lift (linear_map.id))
((lift.symm.trans $
multilinear_map.dom_dom_congr_linear_equiv M (⨂[R] i : ι, M) R R e).trans
lift (linear_map.id))
(by { ext, simp })
(by { ext, simp })
end
@[simp] lemma reindex_tprod (e : ι ≃ ι₂) (f : Π i, M) :
reindex R M e (tprod R f) = tprod R (λ i, f (e.symm i)) :=
lift.tprod f
@[simp] lemma reindex_comp_tprod (e : ι ≃ ι₂) :
(reindex R M e : ⨂[R] i : ι, M →ₗ[R] ⨂[R] i : ι₂, M).comp_multilinear_map (tprod R) =
(tprod R : multilinear_map R (λ i, M) _).dom_dom_congr e.symm :=
multilinear_map.ext $ reindex_tprod e
@[simp] lemma lift_comp_reindex (e : ι ≃ ι₂) (φ : multilinear_map R (λ _ : ι₂, M) E) :
(lift φ).comp ↑(reindex R M e) = lift (φ.dom_dom_congr e.symm) :=
by { ext, simp, }
@[simp]
lemma lift_reindex (e : ι ≃ ι₂) (φ : multilinear_map R (λ _, M) E) (x : ⨂[R] i, M) :
lift φ (reindex R M e x) = lift (φ.dom_dom_congr e.symm) x :=
linear_map.congr_fun (lift_comp_reindex e φ) x
@[simp] lemma reindex_trans (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) :
(reindex R M e).trans (reindex R M e') = reindex R M (e.trans e') :=
begin
apply linear_equiv.to_linear_map_injective,
ext f,
simp only [linear_equiv.trans_apply, linear_equiv.coe_coe, reindex_tprod,
linear_map.coe_comp_multilinear_map, function.comp_app, multilinear_map.dom_dom_congr_apply,
reindex_comp_tprod],
congr,
end
@[simp] lemma reindex_symm (e : ι ≃ ι₂) :
(reindex R M e).symm = reindex R M e.symm := rfl
@[simp] lemma reindex_refl : reindex R M (equiv.refl ι) = linear_equiv.refl R _ :=
begin
apply linear_equiv.to_linear_map_injective,
ext1,
rw [reindex_comp_tprod, linear_equiv.refl_to_linear_map, equiv.refl_symm],
refl,
end
/-- The tensor product over an empty set of indices is isomorphic to the base ring -/
def pempty_equiv : ⨂[R] i : pempty, M ≃ₗ[R] R :=
{ to_fun := lift ⟨λ (_ : pempty → M), (1 : R), λ v, pempty.elim, λ v, pempty.elim⟩,
inv_fun := λ r, r • tprod R (λ v, pempty.elim v),
left_inv := λ x, by {
apply x.induction_on,
{ intros r f,
have : f = (λ i, pempty.elim i) := funext (λ i, pempty.elim i),
simp [this], },
{ simp only,
intros x y hx hy,
simp [add_smul, hx, hy] }},
right_inv := λ t, by simp only [mul_one, algebra.id.smul_eq_mul, multilinear_map.coe_mk,
linear_map.map_smul, pi_tensor_product.lift.tprod],
map_add' := linear_map.map_add _,
map_smul' := linear_map.map_smul _, }
section tmul
/-- Collapse a `tensor_product` of `pi_tensor_product`s. -/
private def tmul : (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) →ₗ[R] ⨂[R] i : ι ⊕ ι₂, M :=
tensor_product.lift
{ to_fun := λ a, pi_tensor_product.lift $ pi_tensor_product.lift
(multilinear_map.curry_sum_equiv R _ _ M _ (tprod R)) a,
map_add' := λ a b, by simp only [linear_equiv.map_add, linear_map.map_add],
map_smul' := λ r a, by simp only [linear_equiv.map_smul, linear_map.map_smul], }
private lemma tmul_apply (a : ι → M) (b : ι₂ → M) :
tmul ((⨂ₜ[R] i, a i) ⊗ₜ[R] (⨂ₜ[R] i, b i)) = ⨂ₜ[R] i, sum.elim a b i :=
begin
erw [tensor_product.lift.tmul, pi_tensor_product.lift.tprod, pi_tensor_product.lift.tprod],
refl
end
/-- Expand `pi_tensor_product` into a `tensor_product` of two factors. -/
private def tmul_symm : ⨂[R] i : ι ⊕ ι₂, M →ₗ[R] (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) :=
-- by using tactic mode, we avoid the need for a lot of `@`s and `_`s
pi_tensor_product.lift $ by apply multilinear_map.dom_coprod; [exact tprod R, exact tprod R]
private lemma tmul_symm_apply (a : ι ⊕ ι₂ → M) :
tmul_symm (⨂ₜ[R] i, a i) = (⨂ₜ[R] i, a (sum.inl i)) ⊗ₜ[R] (⨂ₜ[R] i, a (sum.inr i)) :=
pi_tensor_product.lift.tprod _
variables (R M)
/-- Equivalence between a `tensor_product` of `pi_tensor_product`s and a single
`pi_tensor_product` indexed by a `sum` type.
For simplicity, this is defined only for homogeneously- (rather than dependently-) typed components.
-/
def tmul_equiv : (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) ≃ₗ[R] ⨂[R] i : ι ⊕ ι₂, M :=
linear_equiv.of_linear tmul tmul_symm
(by { ext x,
show tmul (tmul_symm (tprod R x)) = tprod R x, -- Speed up the call to `simp`.
simp only [tmul_symm_apply, tmul_apply, sum.elim_comp_inl_inr], })
(by { ext x y,
show tmul_symm (tmul (tprod R x ⊗ₜ[R] tprod R y)) = tprod R x ⊗ₜ[R] tprod R y,
simp only [tmul_apply, tmul_symm_apply, sum.elim_inl, sum.elim_inr], })
@[simp] lemma tmul_equiv_apply (a : ι → M) (b : ι₂ → M) :
tmul_equiv R M ((⨂ₜ[R] i, a i) ⊗ₜ[R] (⨂ₜ[R] i, b i)) = ⨂ₜ[R] i, sum.elim a b i :=
tmul_apply a b
@[simp] lemma tmul_equiv_symm_apply (a : ι ⊕ ι₂ → M) :
(tmul_equiv R M).symm (⨂ₜ[R] i, a i) = (⨂ₜ[R] i, a (sum.inl i)) ⊗ₜ[R] (⨂ₜ[R] i, a (sum.inr i)) :=
tmul_symm_apply a
end tmul
end multilinear
end pi_tensor_product
end semiring
section ring
namespace pi_tensor_product
open pi_tensor_product
open_locale tensor_product
variables {ι : Type*} [decidable_eq ι] {R : Type*} [comm_ring R]
variables {s : ι → Type*} [∀ i, add_comm_group (s i)] [∀ i, module R (s i)]
/- Unlike for the binary tensor product, we require `R` to be a `comm_ring` here, otherwise
this is false in the case where `ι` is empty. -/
instance : add_comm_group (⨂[R] i, s i) := module.add_comm_monoid_to_add_comm_group R
end pi_tensor_product
end ring
|
fe1bef2526dbe295038d55d7a1d57a6123369035 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/order/ring/lemmas.lean | 6427b131a1b0a6db33c83cf2730fcc76a470a2ca | [
"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 | 38,001 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Yuyang Zhao
-/
import algebra.covariant_and_contravariant
import algebra.group_with_zero.defs
/-!
# Multiplication by ·positive· elements is monotonic
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/482
> Any changes to this file require a corresponding PR to mathlib4.
Let `α` be a type with `<` and `0`. We use the type `{x : α // 0 < x}` of positive elements of `α`
to prove results about monotonicity of multiplication. We also introduce the local notation `α>0`
for the subtype `{x : α // 0 < x}`:
If the type `α` also has a multiplication, then we combine this with (`contravariant_`)
`covariant_class`es to assume that multiplication by positive elements is (strictly) monotone on a
`mul_zero_class`, `monoid_with_zero`,...
More specifically, we use extensively the following typeclasses:
* monotone left
* * `covariant_class α>0 α (λ x y, x * y) (≤)`, abbreviated `pos_mul_mono α`,
expressing that multiplication by positive elements on the left is monotone;
* * `covariant_class α>0 α (λ x y, x * y) (<)`, abbreviated `pos_mul_strict_mono α`,
expressing that multiplication by positive elements on the left is strictly monotone;
* monotone right
* * `covariant_class α>0 α (λ x y, y * x) (≤)`, abbreviated `mul_pos_mono α`,
expressing that multiplication by positive elements on the right is monotone;
* * `covariant_class α>0 α (λ x y, y * x) (<)`, abbreviated `mul_pos_strict_mono α`,
expressing that multiplication by positive elements on the right is strictly monotone.
* reverse monotone left
* * `contravariant_class α>0 α (λ x y, x * y) (≤)`, abbreviated `pos_mul_mono_rev α`,
expressing that multiplication by positive elements on the left is reverse monotone;
* * `contravariant_class α>0 α (λ x y, x * y) (<)`, abbreviated `pos_mul_reflect_lt α`,
expressing that multiplication by positive elements on the left is strictly reverse monotone;
* reverse reverse monotone right
* * `contravariant_class α>0 α (λ x y, y * x) (≤)`, abbreviated `mul_pos_mono_rev α`,
expressing that multiplication by positive elements on the right is reverse monotone;
* * `contravariant_class α>0 α (λ x y, y * x) (<)`, abbreviated `mul_pos_reflect_lt α`,
expressing that multiplication by positive elements on the right is strictly reverse monotone.
## Notation
The following is local notation in this file:
* `α≥0`: `{x : α // 0 ≤ x}`
* `α>0`: `{x : α // 0 < x}`
-/
variable (α : Type*)
/- Notations for nonnegative and positive elements
https://
leanprover.zulipchat.com/#narrow/stream/113488-general/topic/notation.20for.20positive.20elements
-/
local notation `α≥0` := {x : α // 0 ≤ x}
local notation `α>0` := {x : α // 0 < x}
section abbreviations
variables [has_mul α] [has_zero α] [preorder α]
/-- `pos_mul_mono α` is an abbreviation for `covariant_class α≥0 α (λ x y, x * y) (≤)`,
expressing that multiplication by nonnegative elements on the left is monotone. -/
abbreviation pos_mul_mono : Prop := covariant_class α≥0 α (λ x y, x * y) (≤)
/-- `mul_pos_mono α` is an abbreviation for `covariant_class α≥0 α (λ x y, y * x) (≤)`,
expressing that multiplication by nonnegative elements on the right is monotone. -/
abbreviation mul_pos_mono : Prop := covariant_class α≥0 α (λ x y, y * x) (≤)
/-- `pos_mul_strict_mono α` is an abbreviation for `covariant_class α>0 α (λ x y, x * y) (<)`,
expressing that multiplication by positive elements on the left is strictly monotone. -/
abbreviation pos_mul_strict_mono : Prop := covariant_class α>0 α (λ x y, x * y) (<)
/-- `mul_pos_strict_mono α` is an abbreviation for `covariant_class α>0 α (λ x y, y * x) (<)`,
expressing that multiplication by positive elements on the right is strictly monotone. -/
abbreviation mul_pos_strict_mono : Prop := covariant_class α>0 α (λ x y, y * x) (<)
/-- `pos_mul_reflect_lt α` is an abbreviation for `contravariant_class α≥0 α (λ x y, x * y) (<)`,
expressing that multiplication by nonnegative elements on the left is strictly reverse monotone. -/
abbreviation pos_mul_reflect_lt : Prop := contravariant_class α≥0 α (λ x y, x * y) (<)
/-- `mul_pos_reflect_lt α` is an abbreviation for `contravariant_class α≥0 α (λ x y, y * x) (<)`,
expressing that multiplication by nonnegative elements on the right is strictly reverse monotone. -/
abbreviation mul_pos_reflect_lt : Prop := contravariant_class α≥0 α (λ x y, y * x) (<)
/-- `pos_mul_mono_rev α` is an abbreviation for `contravariant_class α>0 α (λ x y, x * y) (≤)`,
expressing that multiplication by positive elements on the left is reverse monotone. -/
abbreviation pos_mul_mono_rev : Prop := contravariant_class α>0 α (λ x y, x * y) (≤)
/-- `mul_pos_mono_rev α` is an abbreviation for `contravariant_class α>0 α (λ x y, y * x) (≤)`,
expressing that multiplication by positive elements on the right is reverse monotone. -/
abbreviation mul_pos_mono_rev : Prop := contravariant_class α>0 α (λ x y, y * x) (≤)
end abbreviations
variables {α} {a b c d : α}
section has_mul_zero
variables [has_mul α] [has_zero α]
section preorder
variables [preorder α]
instance pos_mul_mono.to_covariant_class_pos_mul_le [pos_mul_mono α] :
covariant_class α>0 α (λ x y, x * y) (≤) :=
⟨λ a b c bc, @covariant_class.elim α≥0 α (λ x y, x * y) (≤) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance mul_pos_mono.to_covariant_class_pos_mul_le [mul_pos_mono α] :
covariant_class α>0 α (λ x y, y * x) (≤) :=
⟨λ a b c bc, @covariant_class.elim α≥0 α (λ x y, y * x) (≤) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance pos_mul_reflect_lt.to_contravariant_class_pos_mul_lt [pos_mul_reflect_lt α] :
contravariant_class α>0 α (λ x y, x * y) (<) :=
⟨λ a b c bc, @contravariant_class.elim α≥0 α (λ x y, x * y) (<) _ ⟨_, a.2.le⟩ _ _ bc⟩
instance mul_pos_reflect_lt.to_contravariant_class_pos_mul_lt [mul_pos_reflect_lt α] :
contravariant_class α>0 α (λ x y, y * x) (<) :=
⟨λ a b c bc, @contravariant_class.elim α≥0 α (λ x y, y * x) (<) _ ⟨_, a.2.le⟩ _ _ bc⟩
lemma mul_le_mul_of_nonneg_left [pos_mul_mono α] (h : b ≤ c) (a0 : 0 ≤ a) : a * b ≤ a * c :=
@covariant_class.elim α≥0 α (λ x y, x * y) (≤) _ ⟨a, a0⟩ _ _ h
lemma mul_le_mul_of_nonneg_right [mul_pos_mono α] (h : b ≤ c) (a0 : 0 ≤ a) : b * a ≤ c * a :=
@covariant_class.elim α≥0 α (λ x y, y * x) (≤) _ ⟨a, a0⟩ _ _ h
lemma mul_lt_mul_of_pos_left [pos_mul_strict_mono α] (bc : b < c) (a0 : 0 < a) : a * b < a * c :=
@covariant_class.elim α>0 α (λ x y, x * y) (<) _ ⟨a, a0⟩ _ _ bc
lemma mul_lt_mul_of_pos_right [mul_pos_strict_mono α] (bc : b < c) (a0 : 0 < a) : b * a < c * a :=
@covariant_class.elim α>0 α (λ x y, y * x) (<) _ ⟨a, a0⟩ _ _ bc
lemma lt_of_mul_lt_mul_left [pos_mul_reflect_lt α] (h : a * b < a * c) (a0 : 0 ≤ a) : b < c :=
@contravariant_class.elim α≥0 α (λ x y, x * y) (<) _ ⟨a, a0⟩ _ _ h
lemma lt_of_mul_lt_mul_right [mul_pos_reflect_lt α] (h : b * a < c * a) (a0 : 0 ≤ a) : b < c :=
@contravariant_class.elim α≥0 α (λ x y, y * x) (<) _ ⟨a, a0⟩ _ _ h
lemma le_of_mul_le_mul_left [pos_mul_mono_rev α] (bc : a * b ≤ a * c) (a0 : 0 < a) : b ≤ c :=
@contravariant_class.elim α>0 α (λ x y, x * y) (≤) _ ⟨a, a0⟩ _ _ bc
lemma le_of_mul_le_mul_right [mul_pos_mono_rev α] (bc : b * a ≤ c * a) (a0 : 0 < a) : b ≤ c :=
@contravariant_class.elim α>0 α (λ x y, y * x) (≤) _ ⟨a, a0⟩ _ _ bc
alias lt_of_mul_lt_mul_left ← lt_of_mul_lt_mul_of_nonneg_left
alias lt_of_mul_lt_mul_right ← lt_of_mul_lt_mul_of_nonneg_right
alias le_of_mul_le_mul_left ← le_of_mul_le_mul_of_pos_left
alias le_of_mul_le_mul_right ← le_of_mul_le_mul_of_pos_right
@[simp] lemma mul_lt_mul_left [pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a * b < a * c ↔ b < c :=
@rel_iff_cov α>0 α (λ x y, x * y) (<) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_lt_mul_right [mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(a0 : 0 < a) :
b * a < c * a ↔ b < c :=
@rel_iff_cov α>0 α (λ x y, y * x) (<) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_le_mul_left [pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a * b ≤ a * c ↔ b ≤ c :=
@rel_iff_cov α>0 α (λ x y, x * y) (≤) _ _ ⟨a, a0⟩ _ _
@[simp] lemma mul_le_mul_right [mul_pos_mono α] [mul_pos_mono_rev α]
(a0 : 0 < a) :
b * a ≤ c * a ↔ b ≤ c :=
@rel_iff_cov α>0 α (λ x y, y * x) (≤) _ _ ⟨a, a0⟩ _ _
lemma mul_lt_mul_of_pos_of_nonneg [pos_mul_strict_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 ≤ d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans_le (mul_le_mul_of_nonneg_right h₁ d0)
lemma mul_lt_mul_of_le_of_le' [pos_mul_strict_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c < d) (b0 : 0 < b) (c0 : 0 ≤ c) : a * c < b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans_lt (mul_lt_mul_of_pos_left h₂ b0)
lemma mul_lt_mul_of_nonneg_of_pos [pos_mul_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 < d) : a * c < b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans_lt (mul_lt_mul_of_pos_right h₁ d0)
lemma mul_lt_mul_of_le_of_lt' [pos_mul_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c ≤ d) (b0 : 0 ≤ b) (c0 : 0 < c) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans_le (mul_le_mul_of_nonneg_left h₂ b0)
lemma mul_lt_mul_of_pos_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c < d) (a0 : 0 < a) (d0 : 0 < d) : a * c < b * d :=
(mul_lt_mul_of_pos_left h₂ a0).trans (mul_lt_mul_of_pos_right h₁ d0)
lemma mul_lt_mul_of_lt_of_lt' [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(h₁ : a < b) (h₂ : c < d) (b0 : 0 < b) (c0 : 0 < c) : a * c < b * d :=
(mul_lt_mul_of_pos_right h₁ c0).trans (mul_lt_mul_of_pos_left h₂ b0)
lemma mul_lt_of_mul_lt_of_nonneg_left [pos_mul_mono α] (h : a * b < c) (hdb : d ≤ b) (ha : 0 ≤ a) :
a * d < c :=
(mul_le_mul_of_nonneg_left hdb ha).trans_lt h
lemma lt_mul_of_lt_mul_of_nonneg_left [pos_mul_mono α] (h : a < b * c) (hcd : c ≤ d) (hb : 0 ≤ b) :
a < b * d :=
h.trans_le $ mul_le_mul_of_nonneg_left hcd hb
lemma mul_lt_of_mul_lt_of_nonneg_right [mul_pos_mono α] (h : a * b < c) (hda : d ≤ a) (hb : 0 ≤ b) :
d * b < c :=
(mul_le_mul_of_nonneg_right hda hb).trans_lt h
lemma lt_mul_of_lt_mul_of_nonneg_right [mul_pos_mono α] (h : a < b * c) (hbd : b ≤ d) (hc : 0 ≤ c) :
a < d * c :=
h.trans_le $ mul_le_mul_of_nonneg_right hbd hc
end preorder
section linear_order
variables [linear_order α]
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_strict_mono.to_pos_mul_mono_rev [pos_mul_strict_mono α] : pos_mul_mono_rev α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ mul_lt_mul_of_pos_left h' x.prop⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_strict_mono.to_mul_pos_mono_rev [mul_pos_strict_mono α] : mul_pos_mono_rev α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ mul_lt_mul_of_pos_right h' x.prop⟩
lemma pos_mul_mono_rev.to_pos_mul_strict_mono [pos_mul_mono_rev α] : pos_mul_strict_mono α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ le_of_mul_le_mul_of_pos_left h' x.prop⟩
lemma mul_pos_mono_rev.to_mul_pos_strict_mono [mul_pos_mono_rev α] : mul_pos_strict_mono α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ le_of_mul_le_mul_of_pos_right h' x.prop⟩
lemma pos_mul_strict_mono_iff_pos_mul_mono_rev : pos_mul_strict_mono α ↔ pos_mul_mono_rev α :=
⟨@pos_mul_strict_mono.to_pos_mul_mono_rev _ _ _ _, @pos_mul_mono_rev.to_pos_mul_strict_mono _ _ _ _⟩
lemma mul_pos_strict_mono_iff_mul_pos_mono_rev : mul_pos_strict_mono α ↔ mul_pos_mono_rev α :=
⟨@mul_pos_strict_mono.to_mul_pos_mono_rev _ _ _ _, @mul_pos_mono_rev.to_mul_pos_strict_mono _ _ _ _⟩
lemma pos_mul_reflect_lt.to_pos_mul_mono [pos_mul_reflect_lt α] : pos_mul_mono α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ lt_of_mul_lt_mul_left h' x.prop⟩
lemma mul_pos_reflect_lt.to_mul_pos_mono [mul_pos_reflect_lt α] : mul_pos_mono α :=
⟨λ x a b h, le_of_not_lt $ λ h', h.not_lt $ lt_of_mul_lt_mul_right h' x.prop⟩
lemma pos_mul_mono.to_pos_mul_reflect_lt [pos_mul_mono α] : pos_mul_reflect_lt α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ mul_le_mul_of_nonneg_left h' x.prop⟩
lemma mul_pos_mono.to_mul_pos_reflect_lt [mul_pos_mono α] : mul_pos_reflect_lt α :=
⟨λ x a b h, lt_of_not_le $ λ h', h.not_le $ mul_le_mul_of_nonneg_right h' x.prop⟩
lemma pos_mul_mono_iff_pos_mul_reflect_lt : pos_mul_mono α ↔ pos_mul_reflect_lt α :=
⟨@pos_mul_mono.to_pos_mul_reflect_lt _ _ _ _, @pos_mul_reflect_lt.to_pos_mul_mono _ _ _ _⟩
lemma mul_pos_mono_iff_mul_pos_reflect_lt : mul_pos_mono α ↔ mul_pos_reflect_lt α :=
⟨@mul_pos_mono.to_mul_pos_reflect_lt _ _ _ _, @mul_pos_reflect_lt.to_mul_pos_mono _ _ _ _⟩
end linear_order
end has_mul_zero
section mul_zero_class
variables [mul_zero_class α]
section preorder
variables [preorder α]
/-- Assumes left covariance. -/
lemma left.mul_pos [pos_mul_strict_mono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
by simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
alias left.mul_pos ← mul_pos
lemma mul_neg_of_pos_of_neg [pos_mul_strict_mono α] (ha : 0 < a) (hb : b < 0) : a * b < 0 :=
by simpa only [mul_zero] using mul_lt_mul_of_pos_left hb ha
@[simp] lemma zero_lt_mul_left [pos_mul_strict_mono α] [pos_mul_reflect_lt α] (h : 0 < c) :
0 < c * b ↔ 0 < b :=
by { convert mul_lt_mul_left h, simp }
/-- Assumes right covariance. -/
lemma right.mul_pos [mul_pos_strict_mono α] (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
by simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
lemma mul_neg_of_neg_of_pos [mul_pos_strict_mono α] (ha : a < 0) (hb : 0 < b) : a * b < 0 :=
by simpa only [zero_mul] using mul_lt_mul_of_pos_right ha hb
@[simp] lemma zero_lt_mul_right [mul_pos_strict_mono α] [mul_pos_reflect_lt α] (h : 0 < c) :
0 < b * c ↔ 0 < b :=
by { convert mul_lt_mul_right h, simp }
/-- Assumes left covariance. -/
lemma left.mul_nonneg [pos_mul_mono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
by simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
alias left.mul_nonneg ← mul_nonneg
lemma mul_nonpos_of_nonneg_of_nonpos [pos_mul_mono α] (ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 :=
by simpa only [mul_zero] using mul_le_mul_of_nonneg_left hb ha
/-- Assumes right covariance. -/
lemma right.mul_nonneg [mul_pos_mono α] (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
by simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
lemma mul_nonpos_of_nonpos_of_nonneg [mul_pos_mono α] (ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 :=
by simpa only [zero_mul] using mul_le_mul_of_nonneg_right ha hb
lemma pos_of_mul_pos_right [pos_mul_reflect_lt α] (h : 0 < a * b) (ha : 0 ≤ a) : 0 < b :=
lt_of_mul_lt_mul_left ((mul_zero a).symm ▸ h : a * 0 < a * b) ha
lemma pos_of_mul_pos_left [mul_pos_reflect_lt α] (h : 0 < a * b) (hb : 0 ≤ b) : 0 < a :=
lt_of_mul_lt_mul_right ((zero_mul b).symm ▸ h : 0 * b < a * b) hb
lemma pos_iff_pos_of_mul_pos [pos_mul_reflect_lt α] [mul_pos_reflect_lt α] (hab : 0 < a * b) :
0 < a ↔ 0 < b :=
⟨pos_of_mul_pos_right hab ∘ le_of_lt, pos_of_mul_pos_left hab ∘ le_of_lt⟩
lemma mul_le_mul_of_le_of_le [pos_mul_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (a0 : 0 ≤ a) (d0 : 0 ≤ d) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_left h₂ a0).trans $ mul_le_mul_of_nonneg_right h₁ d0
lemma mul_le_mul [pos_mul_mono α] [mul_pos_mono α]
(h₁ : a ≤ b) (h₂ : c ≤ d) (c0 : 0 ≤ c) (b0 : 0 ≤ b) : a * c ≤ b * d :=
(mul_le_mul_of_nonneg_right h₁ c0).trans $ mul_le_mul_of_nonneg_left h₂ b0
lemma mul_self_le_mul_self [pos_mul_mono α] [mul_pos_mono α] (ha : 0 ≤ a) (hab : a ≤ b) :
a * a ≤ b * b :=
mul_le_mul hab hab ha $ ha.trans hab
lemma mul_le_of_mul_le_of_nonneg_left [pos_mul_mono α] (h : a * b ≤ c) (hle : d ≤ b) (a0 : 0 ≤ a) :
a * d ≤ c :=
(mul_le_mul_of_nonneg_left hle a0).trans h
lemma le_mul_of_le_mul_of_nonneg_left [pos_mul_mono α] (h : a ≤ b * c) (hle : c ≤ d) (b0 : 0 ≤ b) :
a ≤ b * d :=
h.trans (mul_le_mul_of_nonneg_left hle b0)
lemma mul_le_of_mul_le_of_nonneg_right [mul_pos_mono α] (h : a * b ≤ c) (hle : d ≤ a) (b0 : 0 ≤ b) :
d * b ≤ c :=
(mul_le_mul_of_nonneg_right hle b0).trans h
lemma le_mul_of_le_mul_of_nonneg_right [mul_pos_mono α] (h : a ≤ b * c) (hle : b ≤ d) (c0 : 0 ≤ c) :
a ≤ d * c :=
h.trans (mul_le_mul_of_nonneg_right hle c0)
end preorder
section partial_order
variables [partial_order α]
lemma pos_mul_mono_iff_covariant_pos : pos_mul_mono α ↔ covariant_class α>0 α (λ x y, x * y) (≤) :=
⟨@pos_mul_mono.to_covariant_class_pos_mul_le _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simp only [ha, zero_mul] },
{ exactI @covariant_class.elim α>0 α (λ x y, x * y) (≤) _ ⟨_, ha⟩ _ _ h }
end⟩⟩
lemma mul_pos_mono_iff_covariant_pos : mul_pos_mono α ↔ covariant_class α>0 α (λ x y, y * x) (≤) :=
⟨@mul_pos_mono.to_covariant_class_pos_mul_le _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simp only [ha, mul_zero] },
{ exactI @covariant_class.elim α>0 α (λ x y, y * x) (≤) _ ⟨_, ha⟩ _ _ h }
end⟩⟩
lemma pos_mul_reflect_lt_iff_contravariant_pos :
pos_mul_reflect_lt α ↔ contravariant_class α>0 α (λ x y, x * y) (<) :=
⟨@pos_mul_reflect_lt.to_contravariant_class_pos_mul_lt _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simpa [ha] using h },
{ exactI (@contravariant_class.elim α>0 α (λ x y, x * y) (<) _ ⟨_, ha⟩ _ _ h) }
end⟩⟩
lemma mul_pos_reflect_lt_iff_contravariant_pos :
mul_pos_reflect_lt α ↔ contravariant_class α>0 α (λ x y, y * x) (<) :=
⟨@mul_pos_reflect_lt.to_contravariant_class_pos_mul_lt _ _ _ _, λ h, ⟨λ a b c h, begin
obtain ha | ha := a.prop.eq_or_gt,
{ simpa [ha] using h },
{ exactI (@contravariant_class.elim α>0 α (λ x y, y * x) (<) _ ⟨_, ha⟩ _ _ h) }
end⟩⟩
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_strict_mono.to_pos_mul_mono [pos_mul_strict_mono α] : pos_mul_mono α :=
pos_mul_mono_iff_covariant_pos.2 $ ⟨λ a, strict_mono.monotone $ @covariant_class.elim _ _ _ _ _ _⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_strict_mono.to_mul_pos_mono [mul_pos_strict_mono α] : mul_pos_mono α :=
mul_pos_mono_iff_covariant_pos.2 $ ⟨λ a, strict_mono.monotone $ @covariant_class.elim _ _ _ _ _ _⟩
@[priority 100] -- see Note [lower instance priority]
instance pos_mul_mono_rev.to_pos_mul_reflect_lt [pos_mul_mono_rev α] : pos_mul_reflect_lt α :=
pos_mul_reflect_lt_iff_contravariant_pos.2
⟨λ a b c h, (le_of_mul_le_mul_of_pos_left h.le a.2).lt_of_ne $ by { rintro rfl, simpa using h }⟩
@[priority 100] -- see Note [lower instance priority]
instance mul_pos_mono_rev.to_mul_pos_reflect_lt [mul_pos_mono_rev α] : mul_pos_reflect_lt α :=
mul_pos_reflect_lt_iff_contravariant_pos.2
⟨λ a b c h, (le_of_mul_le_mul_of_pos_right h.le a.2).lt_of_ne $ by { rintro rfl, simpa using h }⟩
lemma mul_left_cancel_iff_of_pos [pos_mul_mono_rev α] (a0 : 0 < a) : a * b = a * c ↔ b = c :=
⟨λ h, (le_of_mul_le_mul_of_pos_left h.le a0).antisymm $ le_of_mul_le_mul_of_pos_left h.ge a0,
congr_arg _⟩
lemma mul_right_cancel_iff_of_pos [mul_pos_mono_rev α] (b0 : 0 < b) : a * b = c * b ↔ a = c :=
⟨λ h, (le_of_mul_le_mul_of_pos_right h.le b0).antisymm $ le_of_mul_le_mul_of_pos_right h.ge b0,
congr_arg _⟩
lemma mul_eq_mul_iff_eq_and_eq_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
[pos_mul_mono_rev α] [mul_pos_mono_rev α]
(hac : a ≤ b) (hbd : c ≤ d) (a0 : 0 < a) (d0 : 0 < d) :
a * c = b * d ↔ a = b ∧ c = d :=
begin
refine ⟨λ h, _, λ h, congr_arg2 (*) h.1 h.2⟩,
rcases hac.eq_or_lt with rfl | hac,
{ exact ⟨rfl, (mul_left_cancel_iff_of_pos a0).mp h⟩ },
rcases eq_or_lt_of_le hbd with rfl | hbd,
{ exact ⟨(mul_right_cancel_iff_of_pos d0).mp h, rfl⟩ },
exact ((mul_lt_mul_of_pos_of_pos hac hbd a0 d0).ne h).elim,
end
lemma mul_eq_mul_iff_eq_and_eq_of_pos' [pos_mul_strict_mono α] [mul_pos_strict_mono α]
[pos_mul_mono_rev α] [mul_pos_mono_rev α]
(hac : a ≤ b) (hbd : c ≤ d) (b0 : 0 < b) (c0 : 0 < c) :
a * c = b * d ↔ a = b ∧ c = d :=
begin
refine ⟨λ h, _, λ h, congr_arg2 (*) h.1 h.2⟩,
rcases hac.eq_or_lt with rfl | hac,
{ exact ⟨rfl, (mul_left_cancel_iff_of_pos b0).mp h⟩ },
rcases eq_or_lt_of_le hbd with rfl | hbd,
{ exact ⟨(mul_right_cancel_iff_of_pos c0).mp h, rfl⟩ },
exact ((mul_lt_mul_of_lt_of_lt' hac hbd b0 c0).ne h).elim,
end
end partial_order
section linear_order
variables [linear_order α]
lemma pos_and_pos_or_neg_and_neg_of_mul_pos [pos_mul_mono α] [mul_pos_mono α]
(hab : 0 < a * b) :
(0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0) :=
begin
rcases lt_trichotomy 0 a with ha | rfl | ha,
{ refine or.inl ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact mul_nonpos_of_nonneg_of_nonpos ha.le hb },
{ rw [zero_mul] at hab, exact hab.false.elim },
{ refine or.inr ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
exact mul_nonpos_of_nonpos_of_nonneg ha.le hb }
end
lemma neg_of_mul_pos_right [pos_mul_mono α] [mul_pos_mono α]
(h : 0 < a * b) (ha : a ≤ 0) :
b < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ λ h, h.1.not_le ha).2
lemma neg_of_mul_pos_left [pos_mul_mono α] [mul_pos_mono α]
(h : 0 < a * b) (ha : b ≤ 0) :
a < 0 :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_left $ λ h, h.2.not_le ha).1
lemma neg_iff_neg_of_mul_pos [pos_mul_mono α] [mul_pos_mono α]
(hab : 0 < a * b) :
a < 0 ↔ b < 0 :=
⟨neg_of_mul_pos_right hab ∘ le_of_lt, neg_of_mul_pos_left hab ∘ le_of_lt⟩
lemma left.neg_of_mul_neg_left [pos_mul_mono α]
(h : a * b < 0) (h1 : 0 ≤ a) :
b < 0 :=
lt_of_not_ge (assume h2 : b ≥ 0, (left.mul_nonneg h1 h2).not_lt h)
lemma right.neg_of_mul_neg_left [mul_pos_mono α]
(h : a * b < 0) (h1 : 0 ≤ a) :
b < 0 :=
lt_of_not_ge (assume h2 : b ≥ 0, (right.mul_nonneg h1 h2).not_lt h)
lemma left.neg_of_mul_neg_right [pos_mul_mono α]
(h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge (assume h2 : a ≥ 0, (left.mul_nonneg h2 h1).not_lt h)
lemma right.neg_of_mul_neg_right [mul_pos_mono α]
(h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge (assume h2 : a ≥ 0, (right.mul_nonneg h2 h1).not_lt h)
end linear_order
end mul_zero_class
section mul_one_class
variables [mul_one_class α] [has_zero α]
section preorder
variables [preorder α]
/-! Lemmas of the form `a ≤ a * b ↔ 1 ≤ b` and `a * b ≤ a ↔ b ≤ 1`,
which assume left covariance. -/
@[simp]
lemma le_mul_iff_one_le_right
[pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a ≤ a * b ↔ 1 ≤ b :=
iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
lemma lt_mul_iff_one_lt_right
[pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a < a * b ↔ 1 < b :=
iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
@[simp]
lemma mul_le_iff_le_one_right
[pos_mul_mono α] [pos_mul_mono_rev α]
(a0 : 0 < a) :
a * b ≤ a ↔ b ≤ 1 :=
iff.trans (by rw [mul_one]) (mul_le_mul_left a0)
@[simp]
lemma mul_lt_iff_lt_one_right
[pos_mul_strict_mono α] [pos_mul_reflect_lt α]
(a0 : 0 < a) :
a * b < a ↔ b < 1 :=
iff.trans (by rw [mul_one]) (mul_lt_mul_left a0)
/-! Lemmas of the form `a ≤ b * a ↔ 1 ≤ b` and `a * b ≤ b ↔ a ≤ 1`,
which assume right covariance. -/
@[simp]
lemma le_mul_iff_one_le_left
[mul_pos_mono α] [mul_pos_mono_rev α]
(a0 : 0 < a) :
a ≤ b * a ↔ 1 ≤ b :=
iff.trans (by rw [one_mul]) (mul_le_mul_right a0)
@[simp]
lemma lt_mul_iff_one_lt_left
[mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(a0 : 0 < a) :
a < b * a ↔ 1 < b :=
iff.trans (by rw [one_mul]) (mul_lt_mul_right a0)
@[simp]
lemma mul_le_iff_le_one_left
[mul_pos_mono α] [mul_pos_mono_rev α]
(b0 : 0 < b) :
a * b ≤ b ↔ a ≤ 1 :=
iff.trans (by rw [one_mul]) (mul_le_mul_right b0)
@[simp]
lemma mul_lt_iff_lt_one_left
[mul_pos_strict_mono α] [mul_pos_reflect_lt α]
(b0 : 0 < b) :
a * b < b ↔ a < 1 :=
iff.trans (by rw [one_mul]) (mul_lt_mul_right b0)
/-! Lemmas of the form `1 ≤ b → a ≤ a * b`. -/
lemma mul_le_of_le_one_left [mul_pos_mono α] (hb : 0 ≤ b) (h : a ≤ 1) : a * b ≤ b :=
by simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
lemma le_mul_of_one_le_left [mul_pos_mono α] (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a * b :=
by simpa only [one_mul] using mul_le_mul_of_nonneg_right h hb
lemma mul_le_of_le_one_right [pos_mul_mono α] (ha : 0 ≤ a) (h : b ≤ 1) : a * b ≤ a :=
by simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
lemma le_mul_of_one_le_right [pos_mul_mono α] (ha : 0 ≤ a) (h : 1 ≤ b) : a ≤ a * b :=
by simpa only [mul_one] using mul_le_mul_of_nonneg_left h ha
lemma mul_lt_of_lt_one_left [mul_pos_strict_mono α] (hb : 0 < b) (h : a < 1) : a * b < b :=
by simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
lemma lt_mul_of_one_lt_left [mul_pos_strict_mono α] (hb : 0 < b) (h : 1 < a) : b < a * b :=
by simpa only [one_mul] using mul_lt_mul_of_pos_right h hb
lemma mul_lt_of_lt_one_right [pos_mul_strict_mono α] (ha : 0 < a) (h : b < 1) : a * b < a :=
by simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
lemma lt_mul_of_one_lt_right [pos_mul_strict_mono α] (ha : 0 < a) (h : 1 < b) : a < a * b :=
by simpa only [mul_one] using mul_lt_mul_of_pos_left h ha
/-! Lemmas of the form `b ≤ c → a ≤ 1 → b * a ≤ c`. -/
/- Yaël: What's the point of these lemmas? They just chain an existing lemma with an assumption in
all possible ways, thereby artificially inflating the API and making the truly relevant lemmas hard
to find -/
lemma mul_le_of_le_of_le_one_of_nonneg [pos_mul_mono α] (h : b ≤ c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a ≤ c :=
(mul_le_of_le_one_right hb ha).trans h
lemma mul_lt_of_le_of_lt_one_of_pos [pos_mul_strict_mono α] (bc : b ≤ c) (ha : a < 1) (b0 : 0 < b) :
b * a < c :=
(mul_lt_of_lt_one_right b0 ha).trans_le bc
lemma mul_lt_of_lt_of_le_one_of_nonneg [pos_mul_mono α] (h : b < c) (ha : a ≤ 1) (hb : 0 ≤ b) :
b * a < c :=
(mul_le_of_le_one_right hb ha).trans_lt h
/-- Assumes left covariance. -/
lemma left.mul_le_one_of_le_of_le [pos_mul_mono α] (ha : a ≤ 1) (hb : b ≤ 1) (a0 : 0 ≤ a) :
a * b ≤ 1 :=
mul_le_of_le_of_le_one_of_nonneg ha hb a0
/-- Assumes left covariance. -/
lemma left.mul_lt_of_le_of_lt_one_of_pos [pos_mul_strict_mono α]
(ha : a ≤ 1) (hb : b < 1) (a0 : 0 < a) : a * b < 1 :=
mul_lt_of_le_of_lt_one_of_pos ha hb a0
/-- Assumes left covariance. -/
lemma left.mul_lt_of_lt_of_le_one_of_nonneg [pos_mul_mono α]
(ha : a < 1) (hb : b ≤ 1) (a0 : 0 ≤ a) : a * b < 1 :=
mul_lt_of_lt_of_le_one_of_nonneg ha hb a0
lemma mul_le_of_le_of_le_one' [pos_mul_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : a ≤ 1) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : b * a ≤ c :=
(mul_le_mul_of_nonneg_right bc a0).trans $ mul_le_of_le_one_right c0 ha
lemma mul_lt_of_lt_of_le_one' [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : a ≤ 1) (a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le $ mul_le_of_le_one_right c0 ha
lemma mul_lt_of_le_of_lt_one' [pos_mul_strict_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : a < 1) (a0 : 0 ≤ a) (c0 : 0 < c) : b * a < c :=
(mul_le_mul_of_nonneg_right bc a0).trans_lt $ mul_lt_of_lt_one_right c0 ha
lemma mul_lt_of_lt_of_lt_one_of_pos [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : a ≤ 1) (a0 : 0 < a) (c0 : 0 ≤ c) : b * a < c :=
(mul_lt_mul_of_pos_right bc a0).trans_le $ mul_le_of_le_one_right c0 ha
/-! Lemmas of the form `b ≤ c → 1 ≤ a → b ≤ c * a`. -/
lemma le_mul_of_le_of_one_le_of_nonneg [pos_mul_mono α] (h : b ≤ c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b ≤ c * a :=
h.trans $ le_mul_of_one_le_right hc ha
lemma lt_mul_of_le_of_one_lt_of_pos [pos_mul_strict_mono α] (bc : b ≤ c) (ha : 1 < a) (c0 : 0 < c) :
b < c * a :=
bc.trans_lt $ lt_mul_of_one_lt_right c0 ha
lemma lt_mul_of_lt_of_one_le_of_nonneg [pos_mul_mono α] (h : b < c) (ha : 1 ≤ a) (hc : 0 ≤ c) :
b < c * a :=
h.trans_le $ le_mul_of_one_le_right hc ha
/-- Assumes left covariance. -/
lemma left.one_le_mul_of_le_of_le [pos_mul_mono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (a0 : 0 ≤ a) :
1 ≤ a * b :=
le_mul_of_le_of_one_le_of_nonneg ha hb a0
/-- Assumes left covariance. -/
lemma left.one_lt_mul_of_le_of_lt_of_pos [pos_mul_strict_mono α]
(ha : 1 ≤ a) (hb : 1 < b) (a0 : 0 < a) : 1 < a * b :=
lt_mul_of_le_of_one_lt_of_pos ha hb a0
/-- Assumes left covariance. -/
lemma left.lt_mul_of_lt_of_one_le_of_nonneg [pos_mul_mono α]
(ha : 1 < a) (hb : 1 ≤ b) (a0 : 0 ≤ a) : 1 < a * b :=
lt_mul_of_lt_of_one_le_of_nonneg ha hb a0
lemma le_mul_of_le_of_one_le' [pos_mul_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : 1 ≤ a) (a0 : 0 ≤ a) (b0 : 0 ≤ b) : b ≤ c * a :=
(le_mul_of_one_le_right b0 ha).trans $ mul_le_mul_of_nonneg_right bc a0
lemma lt_mul_of_le_of_one_lt' [pos_mul_strict_mono α] [mul_pos_mono α]
(bc : b ≤ c) (ha : 1 < a) (a0 : 0 ≤ a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans_le $ mul_le_mul_of_nonneg_right bc a0
lemma lt_mul_of_lt_of_one_le' [pos_mul_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : 1 ≤ a) (a0 : 0 < a) (b0 : 0 ≤ b) : b < c * a :=
(le_mul_of_one_le_right b0 ha).trans_lt $ mul_lt_mul_of_pos_right bc a0
lemma lt_mul_of_lt_of_one_lt_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(bc : b < c) (ha : 1 < a) (a0 : 0 < a) (b0 : 0 < b) : b < c * a :=
(lt_mul_of_one_lt_right b0 ha).trans $ mul_lt_mul_of_pos_right bc a0
/-! Lemmas of the form `a ≤ 1 → b ≤ c → a * b ≤ c`. -/
lemma mul_le_of_le_one_of_le_of_nonneg [mul_pos_mono α] (ha : a ≤ 1) (h : b ≤ c) (hb : 0 ≤ b) :
a * b ≤ c :=
(mul_le_of_le_one_left hb ha).trans h
lemma mul_lt_of_lt_one_of_le_of_pos [mul_pos_strict_mono α] (ha : a < 1) (h : b ≤ c) (hb : 0 < b) :
a * b < c :=
(mul_lt_of_lt_one_left hb ha).trans_le h
lemma mul_lt_of_le_one_of_lt_of_nonneg [mul_pos_mono α] (ha : a ≤ 1) (h : b < c) (hb : 0 ≤ b) :
a * b < c :=
(mul_le_of_le_one_left hb ha).trans_lt h
/-- Assumes right covariance. -/
lemma right.mul_lt_one_of_lt_of_le_of_pos [mul_pos_strict_mono α]
(ha : a < 1) (hb : b ≤ 1) (b0 : 0 < b) : a * b < 1 :=
mul_lt_of_lt_one_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
lemma right.mul_lt_one_of_le_of_lt_of_nonneg [mul_pos_mono α]
(ha : a ≤ 1) (hb : b < 1) (b0 : 0 ≤ b) : a * b < 1 :=
mul_lt_of_le_one_of_lt_of_nonneg ha hb b0
lemma mul_lt_of_lt_one_of_lt_of_pos [pos_mul_strict_mono α] [mul_pos_strict_mono α]
(ha : a < 1) (bc : b < c) (a0 : 0 < a) (c0 : 0 < c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans $ mul_lt_of_lt_one_left c0 ha
/-- Assumes right covariance. -/
lemma right.mul_le_one_of_le_of_le [mul_pos_mono α]
(ha : a ≤ 1) (hb : b ≤ 1) (b0 : 0 ≤ b) : a * b ≤ 1 :=
mul_le_of_le_one_of_le_of_nonneg ha hb b0
lemma mul_le_of_le_one_of_le' [pos_mul_mono α] [mul_pos_mono α]
(ha : a ≤ 1) (bc : b ≤ c) (a0 : 0 ≤ a) (c0 : 0 ≤ c) : a * b ≤ c :=
(mul_le_mul_of_nonneg_left bc a0).trans $ mul_le_of_le_one_left c0 ha
lemma mul_lt_of_lt_one_of_le' [pos_mul_mono α] [mul_pos_strict_mono α]
(ha : a < 1) (bc : b ≤ c) (a0 : 0 ≤ a) (c0 : 0 < c) : a * b < c :=
(mul_le_mul_of_nonneg_left bc a0).trans_lt $ mul_lt_of_lt_one_left c0 ha
lemma mul_lt_of_le_one_of_lt' [pos_mul_strict_mono α] [mul_pos_mono α]
(ha : a ≤ 1) (bc : b < c) (a0 : 0 < a) (c0 : 0 ≤ c) : a * b < c :=
(mul_lt_mul_of_pos_left bc a0).trans_le $ mul_le_of_le_one_left c0 ha
/-! Lemmas of the form `1 ≤ a → b ≤ c → b ≤ a * c`. -/
lemma lt_mul_of_one_lt_of_le_of_pos [mul_pos_strict_mono α] (ha : 1 < a) (h : b ≤ c) (hc : 0 < c) :
b < a * c :=
h.trans_lt $ lt_mul_of_one_lt_left hc ha
lemma lt_mul_of_one_le_of_lt_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le $ le_mul_of_one_le_left hc ha
lemma lt_mul_of_one_lt_of_lt_of_pos [mul_pos_strict_mono α] (ha : 1 < a) (h : b < c) (hc : 0 < c) :
b < a * c :=
h.trans $ lt_mul_of_one_lt_left hc ha
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_lt_of_le_of_pos [mul_pos_strict_mono α]
(ha : 1 < a) (hb : 1 ≤ b) (b0 : 0 < b) : 1 < a * b :=
lt_mul_of_one_lt_of_le_of_pos ha hb b0
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_le_of_lt_of_nonneg [mul_pos_mono α]
(ha : 1 ≤ a) (hb : 1 < b) (b0 : 0 ≤ b) : 1 < a * b :=
lt_mul_of_one_le_of_lt_of_nonneg ha hb b0
/-- Assumes right covariance. -/
lemma right.one_lt_mul_of_lt_of_lt [mul_pos_strict_mono α]
(ha : 1 < a) (hb : 1 < b) (b0 : 0 < b) : 1 < a * b :=
lt_mul_of_one_lt_of_lt_of_pos ha hb b0
lemma lt_mul_of_one_lt_of_lt_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (h : b < c) (hc : 0 ≤ c) :
b < a * c :=
h.trans_le $ le_mul_of_one_le_left hc ha
lemma lt_of_mul_lt_of_one_le_of_nonneg_left [pos_mul_mono α] (h : a * b < c) (hle : 1 ≤ b)
(ha : 0 ≤ a) :
a < c :=
(le_mul_of_one_le_right ha hle).trans_lt h
lemma lt_of_lt_mul_of_le_one_of_nonneg_left [pos_mul_mono α] (h : a < b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) :
a < b :=
h.trans_le $ mul_le_of_le_one_right hb hc
lemma lt_of_lt_mul_of_le_one_of_nonneg_right [mul_pos_mono α] (h : a < b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) :
a < c :=
h.trans_le $ mul_le_of_le_one_left hc hb
lemma le_mul_of_one_le_of_le_of_nonneg [mul_pos_mono α] (ha : 1 ≤ a) (bc : b ≤ c) (c0 : 0 ≤ c) :
b ≤ a * c :=
bc.trans $ le_mul_of_one_le_left c0 ha
/-- Assumes right covariance. -/
lemma right.one_le_mul_of_le_of_le [mul_pos_mono α] (ha : 1 ≤ a) (hb : 1 ≤ b) (b0 : 0 ≤ b) :
1 ≤ a * b :=
le_mul_of_one_le_of_le_of_nonneg ha hb b0
lemma le_of_mul_le_of_one_le_of_nonneg_left [pos_mul_mono α] (h : a * b ≤ c) (hb : 1 ≤ b)
(ha : 0 ≤ a) :
a ≤ c :=
(le_mul_of_one_le_right ha hb).trans h
lemma le_of_le_mul_of_le_one_of_nonneg_left [pos_mul_mono α] (h : a ≤ b * c) (hc : c ≤ 1)
(hb : 0 ≤ b) :
a ≤ b :=
h.trans $ mul_le_of_le_one_right hb hc
lemma le_of_mul_le_of_one_le_nonneg_right [mul_pos_mono α] (h : a * b ≤ c) (ha : 1 ≤ a)
(hb : 0 ≤ b) :
b ≤ c :=
(le_mul_of_one_le_left hb ha).trans h
lemma le_of_le_mul_of_le_one_of_nonneg_right [mul_pos_mono α] (h : a ≤ b * c) (hb : b ≤ 1)
(hc : 0 ≤ c) :
a ≤ c :=
h.trans $ mul_le_of_le_one_left hc hb
end preorder
section linear_order
variables [linear_order α]
-- Yaël: What's the point of this lemma? If we have `0 * 0 = 0`, then we can just take `b = 0`.
-- proven with `a0 : 0 ≤ a` as `exists_square_le`
lemma exists_square_le' [pos_mul_strict_mono α] (a0 : 0 < a) : ∃ (b : α), b * b ≤ a :=
begin
obtain ha | ha := lt_or_le a 1,
{ exact ⟨a, (mul_lt_of_lt_one_right a0 ha).le⟩ },
{ exact ⟨1, by rwa mul_one⟩ }
end
end linear_order
end mul_one_class
section cancel_monoid_with_zero
variables [cancel_monoid_with_zero α]
section partial_order
variables [partial_order α]
lemma pos_mul_mono.to_pos_mul_strict_mono [pos_mul_mono α] : pos_mul_strict_mono α :=
⟨λ x a b h, (mul_le_mul_of_nonneg_left h.le x.2.le).lt_of_ne (h.ne ∘ mul_left_cancel₀ x.2.ne')⟩
lemma pos_mul_mono_iff_pos_mul_strict_mono : pos_mul_mono α ↔ pos_mul_strict_mono α :=
⟨@pos_mul_mono.to_pos_mul_strict_mono α _ _, @pos_mul_strict_mono.to_pos_mul_mono α _ _⟩
lemma mul_pos_mono.to_mul_pos_strict_mono [mul_pos_mono α] : mul_pos_strict_mono α :=
⟨λ x a b h, (mul_le_mul_of_nonneg_right h.le x.2.le).lt_of_ne (h.ne ∘ mul_right_cancel₀ x.2.ne')⟩
lemma mul_pos_mono_iff_mul_pos_strict_mono : mul_pos_mono α ↔ mul_pos_strict_mono α :=
⟨@mul_pos_mono.to_mul_pos_strict_mono α _ _, @mul_pos_strict_mono.to_mul_pos_mono α _ _⟩
lemma pos_mul_reflect_lt.to_pos_mul_mono_rev [pos_mul_reflect_lt α] : pos_mul_mono_rev α :=
⟨λ x a b h, h.eq_or_lt.elim (le_of_eq ∘ mul_left_cancel₀ x.2.ne.symm)
(λ h', (lt_of_mul_lt_mul_left h' x.2.le).le)⟩
lemma pos_mul_mono_rev_iff_pos_mul_reflect_lt : pos_mul_mono_rev α ↔ pos_mul_reflect_lt α :=
⟨@pos_mul_mono_rev.to_pos_mul_reflect_lt α _ _, @pos_mul_reflect_lt.to_pos_mul_mono_rev α _ _⟩
lemma mul_pos_reflect_lt.to_mul_pos_mono_rev [mul_pos_reflect_lt α] : mul_pos_mono_rev α :=
⟨λ x a b h, h.eq_or_lt.elim (le_of_eq ∘ mul_right_cancel₀ x.2.ne.symm)
(λ h', (lt_of_mul_lt_mul_right h' x.2.le).le)⟩
lemma mul_pos_mono_rev_iff_mul_pos_reflect_lt : mul_pos_mono_rev α ↔ mul_pos_reflect_lt α :=
⟨@mul_pos_mono_rev.to_mul_pos_reflect_lt α _ _, @mul_pos_reflect_lt.to_mul_pos_mono_rev α _ _⟩
end partial_order
end cancel_monoid_with_zero
section comm_semigroup_has_zero
variables [comm_semigroup α] [has_zero α] [preorder α]
lemma pos_mul_strict_mono_iff_mul_pos_strict_mono :
pos_mul_strict_mono α ↔ mul_pos_strict_mono α :=
by simp ! only [mul_comm]
lemma pos_mul_reflect_lt_iff_mul_pos_reflect_lt :
pos_mul_reflect_lt α ↔ mul_pos_reflect_lt α :=
by simp ! only [mul_comm]
lemma pos_mul_mono_iff_mul_pos_mono :
pos_mul_mono α ↔ mul_pos_mono α :=
by simp ! only [mul_comm]
lemma pos_mul_mono_rev_iff_mul_pos_mono_rev :
pos_mul_mono_rev α ↔ mul_pos_mono_rev α :=
by simp ! only [mul_comm]
end comm_semigroup_has_zero
|
4aca4c2540c275239b97736eb2f8ce9624af60ef | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/ring_theory/int/basic.lean | 63eb8f83119ffbad844bef1768e47b937f20866a | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,418 | 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, Jens Wagemaker, Aaron Anderson
-/
import ring_theory.coprime.basic
import ring_theory.unique_factorization_domain
/-!
# Divisibility over ℕ and ℤ
This file collects results for the integers and natural numbers that use abstract algebra in
their proofs or cases of ℕ and ℤ being examples of structures in abstract algebra.
## Main statements
* `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`
* `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime
* `nat.factors_eq`: the multiset of elements of `nat.factors` is equal to the factors
given by the `unique_factorization_monoid` instance
* ℤ is a `normalization_monoid`
* ℤ is a `gcd_monoid`
## Tags
prime, irreducible, natural numbers, integers, normalization monoid, gcd monoid,
greatest common divisor, prime factorization, prime factors, unique factorization,
unique factors
-/
theorem nat.prime_iff {p : ℕ} : p.prime ↔ prime p :=
begin
split; intro h,
{ refine ⟨h.ne_zero, ⟨_, λ a b, _⟩⟩,
{ rw nat.is_unit_iff, apply h.ne_one },
{ apply h.dvd_mul.1 } },
{ refine ⟨_, λ m hm, _⟩,
{ cases p, { exfalso, apply h.ne_zero rfl },
cases p, { exfalso, apply h.ne_one rfl },
exact (add_le_add_right (zero_le p) 2 : _ ) },
{ cases hm with n hn,
cases h.2.2 m n (hn ▸ dvd_rfl) with hpm hpn,
{ right, apply nat.dvd_antisymm (dvd.intro _ hn.symm) hpm },
{ left,
cases n, { exfalso, rw [hn, mul_zero] at h, apply h.ne_zero rfl },
apply nat.eq_of_mul_eq_mul_right (nat.succ_pos _),
rw [← hn, one_mul],
apply nat.dvd_antisymm hpn (dvd.intro m _),
rw [mul_comm, hn], }, } }
end
theorem nat.irreducible_iff_prime {p : ℕ} : irreducible p ↔ prime p :=
begin
refine ⟨λ h, _, prime.irreducible⟩,
rw ← nat.prime_iff,
refine ⟨_, λ m hm, _⟩,
{ cases p, { exfalso, apply h.ne_zero rfl },
cases p, { exfalso, apply h.not_unit is_unit_one, },
exact (add_le_add_right (zero_le p) 2 : _ ) },
{ cases hm with n hn,
cases h.is_unit_or_is_unit hn with um un,
{ left, rw nat.is_unit_iff.1 um, },
{ right, rw [hn, nat.is_unit_iff.1 un, mul_one], } }
end
namespace nat
instance : wf_dvd_monoid ℕ :=
⟨begin
apply rel_hom.well_founded _ (with_top.well_founded_lt nat.lt_wf),
refine ⟨λ x, if x = 0 then ⊤ else x, _⟩,
intros a b h,
cases a,
{ exfalso, revert h, simp [dvd_not_unit] },
cases b,
{simp [succ_ne_zero, with_top.coe_lt_top]},
cases dvd_and_not_dvd_iff.2 h with h1 h2,
simp only [succ_ne_zero, with_top.coe_lt_coe, if_false],
apply lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h1) (λ con, h2 _),
rw con,
end⟩
instance : unique_factorization_monoid ℕ :=
⟨λ _, nat.irreducible_iff_prime⟩
end nat
/-- `ℕ` is a gcd_monoid. -/
instance : gcd_monoid ℕ :=
{ gcd := nat.gcd,
lcm := nat.lcm,
gcd_dvd_left := nat.gcd_dvd_left ,
gcd_dvd_right := nat.gcd_dvd_right,
dvd_gcd := λ a b c, nat.dvd_gcd,
normalize_gcd := λ a b, normalize_eq _,
gcd_mul_lcm := λ a b, by rw [normalize_eq _, nat.gcd_mul_lcm],
lcm_zero_left := nat.lcm_zero_left,
lcm_zero_right := nat.lcm_zero_right,
.. (infer_instance : normalization_monoid ℕ) }
lemma gcd_eq_nat_gcd (m n : ℕ) : gcd m n = nat.gcd m n := rfl
lemma lcm_eq_nat_lcm (m n : ℕ) : lcm m n = nat.lcm m n := rfl
namespace int
section normalization_monoid
instance : normalization_monoid ℤ :=
{ norm_unit := λa:ℤ, if 0 ≤ a then 1 else -1,
norm_unit_zero := if_pos (le_refl _),
norm_unit_mul := assume a b hna hnb,
begin
cases hna.lt_or_lt with ha ha; cases hnb.lt_or_lt with hb hb;
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
end,
norm_unit_coe_units := assume u, (units_eq_one_or u).elim
(assume eq, eq.symm ▸ if_pos zero_le_one)
(assume eq, eq.symm ▸ if_neg (not_le_of_gt $ show (-1:ℤ) < 0, by dec_trivial)), }
lemma normalize_of_nonneg {z : ℤ} (h : 0 ≤ z) : normalize z = z :=
show z * ↑(ite _ _ _) = z, by rw [if_pos h, units.coe_one, mul_one]
lemma normalize_of_neg {z : ℤ} (h : z < 0) : normalize z = -z :=
show z * ↑(ite _ _ _) = -z,
by rw [if_neg (not_le_of_gt h), units.coe_neg, units.coe_one, mul_neg_one]
lemma normalize_coe_nat (n : ℕ) : normalize (n : ℤ) = n :=
normalize_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n)
theorem coe_nat_abs_eq_normalize (z : ℤ) : (z.nat_abs : ℤ) = normalize z :=
begin
by_cases 0 ≤ z,
{ simp [nat_abs_of_nonneg h, normalize_of_nonneg h] },
{ simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), normalize_of_neg (lt_of_not_ge h)] }
end
end normalization_monoid
section gcd_monoid
instance : gcd_monoid ℤ :=
{ gcd := λa b, int.gcd a b,
lcm := λa b, int.lcm a b,
gcd_dvd_left := assume a b, int.gcd_dvd_left _ _,
gcd_dvd_right := assume a b, int.gcd_dvd_right _ _,
dvd_gcd := assume a b c, dvd_gcd,
normalize_gcd := assume a b, normalize_coe_nat _,
gcd_mul_lcm := by intros; rw [← int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_normalize],
lcm_zero_left := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_left _,
lcm_zero_right := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_right _,
.. int.normalization_monoid }
lemma coe_gcd (i j : ℤ) : ↑(int.gcd i j) = gcd_monoid.gcd i j := rfl
lemma coe_lcm (i j : ℤ) : ↑(int.lcm i j) = gcd_monoid.lcm i j := rfl
lemma nat_abs_gcd (i j : ℤ) : nat_abs (gcd_monoid.gcd i j) = int.gcd i j := rfl
lemma nat_abs_lcm (i j : ℤ) : nat_abs (gcd_monoid.lcm i j) = int.lcm i j := rfl
end gcd_monoid
lemma exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (h : is_unit u), (int.nat_abs a : ℤ) = u * a :=
begin
cases (nat_abs_eq a) with h,
{ use [1, is_unit_one], rw [← h, one_mul], },
{ use [-1, is_unit_one.neg], rw [ ← neg_eq_iff_neg_eq.mp (eq.symm h)],
simp only [neg_mul_eq_neg_mul_symm, one_mul] }
end
lemma gcd_eq_nat_abs {a b : ℤ} : int.gcd a b = nat.gcd a.nat_abs b.nat_abs := rfl
lemma gcd_eq_one_iff_coprime {a b : ℤ} : int.gcd a b = 1 ↔ is_coprime a b :=
begin
split,
{ intro hg,
obtain ⟨ua, hua, ha⟩ := exists_unit_of_abs a,
obtain ⟨ub, hub, hb⟩ := exists_unit_of_abs b,
use [(nat.gcd_a (int.nat_abs a) (int.nat_abs b)) * ua,
(nat.gcd_b (int.nat_abs a) (int.nat_abs b)) * ub],
rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (int.nat_abs b : ℤ),
← nat.gcd_eq_gcd_ab, ←gcd_eq_nat_abs, hg, int.coe_nat_one] },
{ rintro ⟨r, s, h⟩,
by_contradiction hg,
obtain ⟨p, ⟨hp, ha, hb⟩⟩ := nat.prime.not_coprime_iff_dvd.mp hg,
apply nat.prime.not_dvd_one hp,
rw [←coe_nat_dvd, int.coe_nat_one, ← h],
exact dvd_add ((coe_nat_dvd_left.mpr ha).mul_left _)
((coe_nat_dvd_left.mpr hb).mul_left _) }
end
lemma coprime_iff_nat_coprime {a b : ℤ} : is_coprime a b ↔ nat.coprime a.nat_abs b.nat_abs :=
by rw [←gcd_eq_one_iff_coprime, nat.coprime_iff_gcd_eq_one, gcd_eq_nat_abs]
lemma sq_of_gcd_eq_one {a b c : ℤ} (h : int.gcd a b = 1) (heq : a * b = c ^ 2) :
∃ (a0 : ℤ), a = a0 ^ 2 ∨ a = - (a0 ^ 2) :=
begin
have h' : gcd_monoid.gcd a b = 1, { rw [← coe_gcd, h], dec_trivial },
obtain ⟨d, ⟨u, hu⟩⟩ := exists_associated_pow_of_mul_eq_pow h' heq,
use d,
rw ← hu,
cases int.units_eq_one_or u with hu' hu'; { rw hu', simp }
end
lemma sq_of_coprime {a b c : ℤ} (h : is_coprime a b) (heq : a * b = c ^ 2) :
∃ (a0 : ℤ), a = a0 ^ 2 ∨ a = - (a0 ^ 2) := sq_of_gcd_eq_one (gcd_eq_one_iff_coprime.mpr h) heq
lemma nat_abs_euclidean_domain_gcd (a b : ℤ) :
int.nat_abs (euclidean_domain.gcd a b) = int.gcd a b :=
begin
apply nat.dvd_antisymm; rw ← int.coe_nat_dvd,
{ rw int.nat_abs_dvd,
exact int.dvd_gcd (euclidean_domain.gcd_dvd_left _ _) (euclidean_domain.gcd_dvd_right _ _) },
{ rw int.dvd_nat_abs,
exact euclidean_domain.dvd_gcd (int.gcd_dvd_left _ _) (int.gcd_dvd_right _ _) }
end
end int
theorem irreducible_iff_nat_prime : ∀(a : ℕ), irreducible a ↔ nat.prime a
| 0 := by simp [nat.not_prime_zero]
| 1 := by simp [nat.prime, one_lt_two]
| (n + 2) :=
have h₁ : ¬n + 2 = 1, from dec_trivial,
begin
simp [h₁, nat.prime, irreducible_iff, (≥), nat.le_add_left 2 n, (∣)],
refine forall_congr (assume a, forall_congr $ assume b, forall_congr $ assume hab, _),
by_cases a = 1; simp [h],
split,
{ assume hb, simpa [hb] using hab.symm },
{ assume ha, subst ha,
have : n + 2 > 0, from dec_trivial,
refine nat.eq_of_mul_eq_mul_left this _,
rw [← hab, mul_one] }
end
lemma nat.prime_iff_prime_int {p : ℕ} : p.prime ↔ _root_.prime (p : ℤ) :=
⟨λ hp, ⟨int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,
λ a b h, by rw [← int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;
rwa [← int.dvd_nat_abs, int.coe_nat_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd]⟩,
λ hp, nat.prime_iff.2 ⟨int.coe_nat_ne_zero.1 hp.1,
mt nat.is_unit_iff.1 $ λ h, by simpa [h, not_prime_one] using hp,
λ a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b⟩⟩
/-- Maps an associate class of integers consisting of `-n, n` to `n : ℕ` -/
def associates_int_equiv_nat : associates ℤ ≃ ℕ :=
begin
refine ⟨λz, z.out.nat_abs, λn, associates.mk n, _, _⟩,
{ refine (assume a, quotient.induction_on' a $ assume a,
associates.mk_eq_mk_iff_associated.2 $ associated.symm $ ⟨norm_unit a, _⟩),
show normalize a = int.nat_abs (normalize a),
rw [int.coe_nat_abs_eq_normalize, normalize_idem] },
{ intro n, dsimp, rw [associates.out_mk ↑n,
← int.coe_nat_abs_eq_normalize, int.nat_abs_of_nat, int.nat_abs_of_nat] }
end
lemma int.prime.dvd_mul {m n : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ m * n) : p ∣ m.nat_abs ∨ p ∣ n.nat_abs :=
begin
apply (nat.prime.dvd_mul hp).mp,
rw ← int.nat_abs_mul,
exact int.coe_nat_dvd_left.mp h
end
lemma int.prime.dvd_mul' {m n : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ m * n) : (p : ℤ) ∣ m ∨ (p : ℤ) ∣ n :=
begin
rw [int.coe_nat_dvd_left, int.coe_nat_dvd_left],
exact int.prime.dvd_mul hp h
end
lemma int.prime.dvd_pow {n : ℤ} {k p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ n ^ k) : p ∣ n.nat_abs :=
begin
apply @nat.prime.dvd_of_dvd_pow _ _ k hp,
rw ← int.nat_abs_pow,
exact int.coe_nat_dvd_left.mp h
end
lemma int.prime.dvd_pow' {n : ℤ} {k p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ n ^ k) : (p : ℤ) ∣ n :=
begin
rw int.coe_nat_dvd_left,
exact int.prime.dvd_pow hp h
end
lemma prime_two_or_dvd_of_dvd_two_mul_pow_self_two {m : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ 2 * m ^ 2) : p = 2 ∨ p ∣ int.nat_abs m :=
begin
cases int.prime.dvd_mul hp h with hp2 hpp,
{ apply or.intro_left,
exact le_antisymm (nat.le_of_dvd zero_lt_two hp2) (nat.prime.two_le hp) },
{ apply or.intro_right,
rw [sq, int.nat_abs_mul] at hpp,
exact (or_self _).mp ((nat.prime.dvd_mul hp).mp hpp)}
end
open unique_factorization_monoid
theorem nat.factors_eq {n : ℕ} : normalized_factors n = n.factors :=
begin
cases n, { simp },
rw [← multiset.rel_eq, ← associated_eq_eq],
apply factors_unique (irreducible_of_normalized_factor) _,
{ rw [multiset.coe_prod, nat.prod_factors (nat.succ_pos _)],
apply normalized_factors_prod (nat.succ_ne_zero _) },
{ apply_instance },
{ intros x hx,
rw [nat.irreducible_iff_prime, ← nat.prime_iff],
exact nat.prime_of_mem_factors hx }
end
lemma nat.factors_multiset_prod_of_irreducible
{s : multiset ℕ} (h : ∀ (x : ℕ), x ∈ s → irreducible x) :
normalized_factors (s.prod) = s :=
begin
rw [← multiset.rel_eq, ← associated_eq_eq],
apply unique_factorization_monoid.factors_unique irreducible_of_normalized_factor h
(normalized_factors_prod _),
rw [ne.def, multiset.prod_eq_zero_iff],
intro con,
exact not_irreducible_zero (h 0 con),
end
namespace multiplicity
lemma finite_int_iff_nat_abs_finite {a b : ℤ} : finite a b ↔ finite a.nat_abs b.nat_abs :=
by simp only [finite_def, ← int.nat_abs_dvd_abs_iff, int.nat_abs_pow]
lemma finite_int_iff {a b : ℤ} : finite a b ↔ (a.nat_abs ≠ 1 ∧ b ≠ 0) :=
by rw [finite_int_iff_nat_abs_finite, finite_nat_iff, pos_iff_ne_zero, int.nat_abs_ne_zero]
instance decidable_nat : decidable_rel (λ a b : ℕ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_nat_iff.symm
instance decidable_int : decidable_rel (λ a b : ℤ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_int_iff.symm
end multiplicity
lemma induction_on_primes {P : ℕ → Prop} (h₀ : P 0) (h₁ : P 1)
(h : ∀ p a : ℕ, p.prime → P a → P (p * a)) (n : ℕ) : P n :=
begin
apply unique_factorization_monoid.induction_on_prime,
exact h₀,
{ intros n h,
rw nat.is_unit_iff.1 h,
exact h₁, },
{ intros a p _ hp ha,
exact h p a (nat.prime_iff.2 hp) ha, },
end
lemma int.associated_nat_abs (k : ℤ) : associated k k.nat_abs :=
associated_of_dvd_dvd (int.coe_nat_dvd_right.mpr dvd_rfl) (int.nat_abs_dvd.mpr dvd_rfl)
lemma int.prime_iff_nat_abs_prime {k : ℤ} : prime k ↔ nat.prime k.nat_abs :=
(int.associated_nat_abs k).prime_iff.trans nat.prime_iff_prime_int.symm
theorem int.associated_iff_nat_abs {a b : ℤ} : associated a b ↔ a.nat_abs = b.nat_abs :=
begin
rw [←dvd_dvd_iff_associated, ←int.nat_abs_dvd_abs_iff, ←int.nat_abs_dvd_abs_iff,
dvd_dvd_iff_associated],
exact associated_iff_eq,
end
lemma int.associated_iff {a b : ℤ} : associated a b ↔ (a = b ∨ a = -b) :=
begin
rw int.associated_iff_nat_abs,
exact int.nat_abs_eq_nat_abs_iff,
end
namespace int
lemma gmultiples_nat_abs (a : ℤ) :
add_subgroup.gmultiples (a.nat_abs : ℤ) = add_subgroup.gmultiples a :=
le_antisymm
(add_subgroup.gmultiples_subset (mem_gmultiples_iff.mpr (dvd_nat_abs.mpr (dvd_refl a))))
(add_subgroup.gmultiples_subset (mem_gmultiples_iff.mpr (nat_abs_dvd.mpr (dvd_refl a))))
lemma span_nat_abs (a : ℤ) : ideal.span ({a.nat_abs} : set ℤ) = ideal.span {a} :=
by { rw ideal.span_singleton_eq_span_singleton, exact (associated_nat_abs _).symm }
end int
|
3e4258ac707482fe7a55ef3e73382cdbd43e90fa | 3863d2564418bccb1859e057bf5a4ef240e75fd7 | /hott/init/trunc.hlean | 3c53f2794594782cdeab1a6e2fb1731f177dc126 | [
"Apache-2.0"
] | permissive | JacobGross/lean | 118bbb067ff4d4af48a266face2c7eb9868fa91c | eb26087df940c54337cb807b4bc6d345d1fc1085 | refs/heads/master | 1,582,735,011,532 | 1,462,557,826,000 | 1,462,557,826,000 | 46,451,196 | 0 | 0 | null | 1,462,557,826,000 | 1,447,885,161,000 | C++ | UTF-8 | Lean | false | false | 12,498 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Floris van Doorn
Definition of is_trunc (n-truncatedness)
Ported from Coq HoTT.
-/
prelude
import .nat .logic .equiv .pathover
open eq nat sigma unit sigma.ops
--set_option class.force_new true
/- Truncation levels -/
inductive trunc_index : Type₀ :=
| minus_two : trunc_index
| succ : trunc_index → trunc_index
open trunc_index
/-
notation for trunc_index is -2, -1, 0, 1, ...
from 0 and up this comes from the way numerals are parsed in Lean.
Any structure with a 0, a 1, and a + have numerals defined in them.
-/
notation `ℕ₋₂` := trunc_index -- input using \N-2
definition has_zero_trunc_index [instance] [priority 2000] : has_zero ℕ₋₂ :=
has_zero.mk (succ (succ minus_two))
definition has_one_trunc_index [instance] [priority 2000] : has_one ℕ₋₂ :=
has_one.mk (succ (succ (succ minus_two)))
namespace trunc_index
notation `-1` := trunc_index.succ trunc_index.minus_two -- ISSUE: -1 gets printed as -2.+1?
notation `-2` := trunc_index.minus_two
postfix `.+1`:(max+1) := trunc_index.succ
postfix `.+2`:(max+1) := λn, (n .+1 .+1)
--addition, where we add two to the result
definition add_plus_two [reducible] (n m : ℕ₋₂) : ℕ₋₂ :=
trunc_index.rec_on m n (λ k l, l .+1)
infix ` +2+ `:65 := trunc_index.add_plus_two
-- addition of trunc_indices, where results smaller than -2 are changed to -2
protected definition add (n m : ℕ₋₂) : ℕ₋₂ :=
trunc_index.cases_on m
(trunc_index.cases_on n -2 (λn', (trunc_index.cases_on n' -2 id)))
(λm', trunc_index.cases_on m'
(trunc_index.cases_on n -2 id)
(add_plus_two n))
/- we give a weird name to the reflexivity step to avoid overloading le.refl
(which can be used if types.trunc is imported) -/
inductive le (a : ℕ₋₂) : ℕ₋₂ → Type :=
| tr_refl : le a a
| step : Π {b}, le a b → le a (b.+1)
end trunc_index
definition has_le_trunc_index [instance] [priority 2000] : has_le ℕ₋₂ :=
has_le.mk trunc_index.le
attribute trunc_index.add [reducible]
definition has_add_trunc_index [instance] [priority 2000] : has_add ℕ₋₂ :=
has_add.mk trunc_index.add
namespace trunc_index
definition sub_two [reducible] (n : ℕ) : ℕ₋₂ :=
nat.rec_on n -2 (λ n k, k.+1)
definition add_two [reducible] (n : ℕ₋₂) : ℕ :=
trunc_index.rec_on n nat.zero (λ n k, nat.succ k)
postfix `.-2`:(max+1) := sub_two
postfix `.-1`:(max+1) := λn, (n .-2 .+1)
definition of_nat [coercion] [reducible] (n : ℕ) : ℕ₋₂ :=
n.-2.+2
definition succ_le_succ {n m : ℕ₋₂} (H : n ≤ m) : n.+1 ≤ m.+1 :=
by induction H with m H IH; apply le.tr_refl; exact le.step IH
definition minus_two_le (n : ℕ₋₂) : -2 ≤ n :=
by induction n with n IH; apply le.tr_refl; exact le.step IH
end trunc_index open trunc_index
namespace is_trunc
export [notation] [coercion] trunc_index
/- truncated types -/
/-
Just as in Coq HoTT we define an internal version of contractibility and is_trunc, but we only
use `is_trunc` and `is_contr`
-/
structure contr_internal (A : Type) :=
(center : A)
(center_eq : Π(a : A), center = a)
definition is_trunc_internal (n : ℕ₋₂) : Type → Type :=
trunc_index.rec_on n
(λA, contr_internal A)
(λn trunc_n A, (Π(x y : A), trunc_n (x = y)))
end is_trunc open is_trunc
structure is_trunc [class] (n : ℕ₋₂) (A : Type) :=
(to_internal : is_trunc_internal n A)
open nat num trunc_index
namespace is_trunc
abbreviation is_contr := is_trunc -2
abbreviation is_prop := is_trunc -1
abbreviation is_set := is_trunc 0
variables {A B : Type}
definition is_trunc_succ_intro (A : Type) (n : ℕ₋₂) [H : ∀x y : A, is_trunc n (x = y)]
: is_trunc n.+1 A :=
is_trunc.mk (λ x y, !is_trunc.to_internal)
definition is_trunc_eq [instance] [priority 1200]
(n : ℕ₋₂) [H : is_trunc (n.+1) A] (x y : A) : is_trunc n (x = y) :=
is_trunc.mk (is_trunc.to_internal (n.+1) A x y)
/- contractibility -/
definition is_contr.mk (center : A) (center_eq : Π(a : A), center = a) : is_contr A :=
is_trunc.mk (contr_internal.mk center center_eq)
definition center (A : Type) [H : is_contr A] : A :=
contr_internal.center (is_trunc.to_internal -2 A)
definition center_eq [H : is_contr A] (a : A) : !center = a :=
contr_internal.center_eq (is_trunc.to_internal -2 A) a
definition eq_of_is_contr [H : is_contr A] (x y : A) : x = y :=
(center_eq x)⁻¹ ⬝ (center_eq y)
definition prop_eq_of_is_contr {A : Type} [H : is_contr A] {x y : A} (p q : x = y) : p = q :=
have K : ∀ (r : x = y), eq_of_is_contr x y = r, from (λ r, eq.rec_on r !con.left_inv),
(K p)⁻¹ ⬝ K q
theorem is_contr_eq {A : Type} [H : is_contr A] (x y : A) : is_contr (x = y) :=
is_contr.mk !eq_of_is_contr (λ p, !prop_eq_of_is_contr)
local attribute is_contr_eq [instance]
/- truncation is upward close -/
-- n-types are also (n+1)-types
theorem is_trunc_succ [instance] [priority 900] (A : Type) (n : ℕ₋₂)
[H : is_trunc n A] : is_trunc (n.+1) A :=
trunc_index.rec_on n
(λ A (H : is_contr A), !is_trunc_succ_intro)
(λ n IH A (H : is_trunc (n.+1) A), @is_trunc_succ_intro _ _ (λ x y, IH _ _))
A H
--in the proof the type of H is given explicitly to make it available for class inference
theorem is_trunc_of_le.{l} (A : Type.{l}) {n m : ℕ₋₂} (Hnm : n ≤ m)
[Hn : is_trunc n A] : is_trunc m A :=
begin
induction Hnm with m Hnm IH,
{ exact Hn},
{ exact _}
end
definition is_trunc_of_imp_is_trunc {n : ℕ₋₂} (H : A → is_trunc (n.+1) A)
: is_trunc (n.+1) A :=
@is_trunc_succ_intro _ _ (λx y, @is_trunc_eq _ _ (H x) x y)
definition is_trunc_of_imp_is_trunc_of_le {n : ℕ₋₂} (Hn : -1 ≤ n) (H : A → is_trunc n A)
: is_trunc n A :=
begin
cases Hn with n' Hn': apply is_trunc_of_imp_is_trunc H
end
-- these must be definitions, because we need them to compute sometimes
definition is_trunc_of_is_contr (A : Type) (n : ℕ₋₂) [H : is_contr A] : is_trunc n A :=
trunc_index.rec_on n H (λn H, _)
definition is_trunc_succ_of_is_prop (A : Type) (n : ℕ₋₂) [H : is_prop A]
: is_trunc (n.+1) A :=
is_trunc_of_le A (show -1 ≤ n.+1, from succ_le_succ (minus_two_le n))
definition is_trunc_succ_succ_of_is_set (A : Type) (n : ℕ₋₂) [H : is_set A]
: is_trunc (n.+2) A :=
is_trunc_of_le A (show 0 ≤ n.+2, from succ_le_succ (succ_le_succ (minus_two_le n)))
/- props -/
definition is_prop.elim [H : is_prop A] (x y : A) : x = y :=
!center
definition is_contr_of_inhabited_prop {A : Type} [H : is_prop A] (x : A) : is_contr A :=
is_contr.mk x (λy, !is_prop.elim)
theorem is_prop_of_imp_is_contr {A : Type} (H : A → is_contr A) : is_prop A :=
@is_trunc_succ_intro A -2
(λx y,
have H2 : is_contr A, from H x,
!is_contr_eq)
theorem is_prop.mk {A : Type} (H : ∀x y : A, x = y) : is_prop A :=
is_prop_of_imp_is_contr (λ x, is_contr.mk x (H x))
theorem is_prop_elim_self {A : Type} {H : is_prop A} (x : A) : is_prop.elim x x = idp :=
!is_prop.elim
/- sets -/
theorem is_set.mk (A : Type) (H : ∀(x y : A) (p q : x = y), p = q) : is_set A :=
@is_trunc_succ_intro _ _ (λ x y, is_prop.mk (H x y))
definition is_set.elim [H : is_set A] ⦃x y : A⦄ (p q : x = y) : p = q :=
!is_prop.elim
/- instances -/
definition is_contr_sigma_eq [instance] [priority 800] {A : Type} (a : A)
: is_contr (Σ(x : A), a = x) :=
is_contr.mk (sigma.mk a idp) (λp, sigma.rec_on p (λ b q, eq.rec_on q idp))
definition is_contr_sigma_eq' [instance] [priority 800] {A : Type} (a : A)
: is_contr (Σ(x : A), x = a) :=
is_contr.mk (sigma.mk a idp) (λp, sigma.rec_on p (λ b q, eq.rec_on q idp))
definition ap_pr1_center_eq_sigma_eq {A : Type} {a x : A} (p : a = x)
: ap pr₁ (center_eq ⟨x, p⟩) = p :=
by induction p; reflexivity
definition ap_pr1_center_eq_sigma_eq' {A : Type} {a x : A} (p : x = a)
: ap pr₁ (center_eq ⟨x, p⟩) = p⁻¹ :=
by induction p; reflexivity
definition is_contr_unit : is_contr unit :=
is_contr.mk star (λp, unit.rec_on p idp)
definition is_prop_empty : is_prop empty :=
is_prop.mk (λx, !empty.elim x)
local attribute is_contr_unit is_prop_empty [instance]
definition is_trunc_unit [instance] (n : ℕ₋₂) : is_trunc n unit :=
!is_trunc_of_is_contr
definition is_trunc_empty [instance] (n : ℕ₋₂) : is_trunc (n.+1) empty :=
!is_trunc_succ_of_is_prop
/- interaction with equivalences -/
section
open is_equiv equiv
definition is_contr_is_equiv_closed (f : A → B) [Hf : is_equiv f] [HA: is_contr A]
: (is_contr B) :=
is_contr.mk (f (center A)) (λp, eq_of_eq_inv !center_eq)
definition is_contr_equiv_closed (H : A ≃ B) [HA: is_contr A] : is_contr B :=
is_contr_is_equiv_closed (to_fun H)
definition equiv_of_is_contr_of_is_contr [HA : is_contr A] [HB : is_contr B] : A ≃ B :=
equiv.mk
(λa, center B)
(is_equiv.adjointify (λa, center B) (λb, center A) center_eq center_eq)
theorem is_trunc_is_equiv_closed (n : ℕ₋₂) (f : A → B) [H : is_equiv f]
[HA : is_trunc n A] : is_trunc n B :=
begin
revert A HA B f H, induction n with n IH: intros,
{ exact is_contr_is_equiv_closed f},
{ apply is_trunc_succ_intro, intro x y,
exact IH (f⁻¹ x = f⁻¹ y) _ (x = y) (ap f⁻¹)⁻¹ !is_equiv_inv}
end
definition is_trunc_is_equiv_closed_rev (n : ℕ₋₂) (f : A → B) [H : is_equiv f]
[HA : is_trunc n B] : is_trunc n A :=
is_trunc_is_equiv_closed n f⁻¹
definition is_trunc_equiv_closed (n : ℕ₋₂) (f : A ≃ B) [HA : is_trunc n A]
: is_trunc n B :=
is_trunc_is_equiv_closed n (to_fun f)
definition is_trunc_equiv_closed_rev (n : ℕ₋₂) (f : A ≃ B) [HA : is_trunc n B]
: is_trunc n A :=
is_trunc_is_equiv_closed n (to_inv f)
definition is_equiv_of_is_prop [constructor] [HA : is_prop A] [HB : is_prop B]
(f : A → B) (g : B → A) : is_equiv f :=
is_equiv.mk f g (λb, !is_prop.elim) (λa, !is_prop.elim) (λa, !is_set.elim)
definition equiv_of_is_prop [constructor] [HA : is_prop A] [HB : is_prop B]
(f : A → B) (g : B → A) : A ≃ B :=
equiv.mk f (is_equiv_of_is_prop f g)
definition equiv_of_iff_of_is_prop [unfold 5] [HA : is_prop A] [HB : is_prop B] (H : A ↔ B) : A ≃ B :=
equiv_of_is_prop (iff.elim_left H) (iff.elim_right H)
/- truncatedness of lift -/
definition is_trunc_lift [instance] [priority 1450] (A : Type) (n : ℕ₋₂)
[H : is_trunc n A] : is_trunc n (lift A) :=
is_trunc_equiv_closed _ !equiv_lift
end
/- interaction with the Unit type -/
open equiv
/- A contractible type is equivalent to unit. -/
variable (A)
definition equiv_unit_of_is_contr [H : is_contr A] : A ≃ unit :=
equiv.MK (λ (x : A), ⋆)
(λ (u : unit), center A)
(λ (u : unit), unit.rec_on u idp)
(λ (x : A), center_eq x)
/- interaction with pathovers -/
variable {A}
variables {C : A → Type}
{a a₂ : A} (p : a = a₂)
(c : C a) (c₂ : C a₂)
definition is_prop.elimo [H : is_prop (C a)] : c =[p] c₂ :=
pathover_of_eq_tr !is_prop.elim
definition is_trunc_pathover [instance]
(n : ℕ₋₂) [H : is_trunc (n.+1) (C a)] : is_trunc n (c =[p] c₂) :=
is_trunc_equiv_closed_rev n !pathover_equiv_eq_tr
variables {p c c₂}
theorem is_set.elimo (q q' : c =[p] c₂) [H : is_set (C a)] : q = q' :=
!is_prop.elim
-- TODO: port "Truncated morphisms"
/- truncated universe -/
end is_trunc
structure trunctype (n : ℕ₋₂) :=
(carrier : Type)
(struct : is_trunc n carrier)
notation n `-Type` := trunctype n
abbreviation Prop := -1-Type
abbreviation Set := 0-Type
attribute trunctype.carrier [coercion]
attribute trunctype.struct [instance] [priority 1400]
protected abbreviation Prop.mk := @trunctype.mk -1
protected abbreviation Set.mk := @trunctype.mk (-1.+1)
protected definition trunctype.mk' [constructor] (n : ℕ₋₂) (A : Type) [H : is_trunc n A]
: n-Type :=
trunctype.mk A H
namespace is_trunc
definition tlift.{u v} [constructor] {n : ℕ₋₂} (A : trunctype.{u} n)
: trunctype.{max u v} n :=
trunctype.mk (lift A) !is_trunc_lift
end is_trunc
|
54218ddd6d596f9c4323afa0a91eecdc56433afa | 4950bf76e5ae40ba9f8491647d0b6f228ddce173 | /src/algebra/group/pi.lean | ade5c063af191549ec118a628b919580ae15bd41 | [
"Apache-2.0"
] | permissive | ntzwq/mathlib | ca50b21079b0a7c6781c34b62199a396dd00cee2 | 36eec1a98f22df82eaccd354a758ef8576af2a7f | refs/heads/master | 1,675,193,391,478 | 1,607,822,996,000 | 1,607,822,996,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,788 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import data.pi
import tactic.pi_instances
import algebra.group.defs
import algebra.group.hom
/-!
# Pi instances for groups and monoids
This file defines instances for group, monoid, semigroup and related structures on Pi types.
-/
universes u v w
variable {I : Type u} -- The indexing type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
namespace pi
@[to_additive]
instance semigroup [∀ i, semigroup $ f i] : semigroup (Π i : I, f i) :=
by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field
@[to_additive]
instance comm_semigroup [∀ i, comm_semigroup $ f i] : comm_semigroup (Π i : I, f i) :=
by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field
@[to_additive]
instance monoid [∀ i, monoid $ f i] : monoid (Π i : I, f i) :=
by refine_struct { one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field
@[to_additive]
instance comm_monoid [∀ i, comm_monoid $ f i] : comm_monoid (Π i : I, f i) :=
by refine_struct { one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field
@[to_additive]
instance group [∀ i, group $ f i] : group (Π i : I, f i) :=
by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, .. };
tactic.pi_instance_derive_field
-- TODO: derive this from `@[to_additive] pi.div_apply`,
-- when the `add_group -> has_sub` diamond is fixed
@[simp] lemma sub_apply [∀ i, add_group $ f i] (x y : Π i : I, f i) (i : I) :
(x - y) i = x i - y i := rfl
@[to_additive]
instance comm_group [∀ i, comm_group $ f i] : comm_group (Π i : I, f i) :=
by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, .. };
tactic.pi_instance_derive_field
@[to_additive add_left_cancel_semigroup]
instance left_cancel_semigroup [∀ i, left_cancel_semigroup $ f i] :
left_cancel_semigroup (Π i : I, f i) :=
by refine_struct { mul := (*) }; tactic.pi_instance_derive_field
@[to_additive add_right_cancel_semigroup]
instance right_cancel_semigroup [∀ i, right_cancel_semigroup $ f i] :
right_cancel_semigroup (Π i : I, f i) :=
by refine_struct { mul := (*) }; tactic.pi_instance_derive_field
instance mul_zero_class [∀ i, mul_zero_class $ f i] :
mul_zero_class (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field
instance comm_monoid_with_zero [∀ i, comm_monoid_with_zero $ f i] :
comm_monoid_with_zero (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := (1 : Π i, f i), mul := (*), .. };
tactic.pi_instance_derive_field
section instance_lemmas
open function
variables {α β γ : Type*}
@[simp, to_additive] lemma const_one [has_one β] : const α (1 : β) = 1 := rfl
@[simp, to_additive] lemma comp_one [has_one β] {f : β → γ} : f ∘ 1 = const α (f 1) := rfl
@[simp, to_additive] lemma one_comp [has_one γ] {f : α → β} : (1 : β → γ) ∘ f = 1 := rfl
end instance_lemmas
end pi
section monoid_hom
variables (f) [Π i, monoid (f i)]
/-- Evaluation of functions into an indexed collection of monoids at a point is a monoid
homomorphism. -/
@[to_additive "Evaluation of functions into an indexed collection of additive monoids at a point
is an additive monoid homomorphism."]
def monoid_hom.apply (i : I) : (Π i, f i) →* f i :=
{ to_fun := λ g, g i,
map_one' := rfl,
map_mul' := λ x y, rfl, }
@[simp, to_additive]
lemma monoid_hom.apply_apply (i : I) (g : Π i, f i) :
(monoid_hom.apply f i) g = g i := rfl
end monoid_hom
section add_monoid_single
variables [decidable_eq I] (f) [Π i, add_monoid (f i)]
open pi
/-- The additive monoid homomorphism including a single additive monoid
into a dependent family of additive monoids, as functions supported at a point. -/
def add_monoid_hom.single (i : I) : f i →+ Π i, f i :=
{ to_fun := λ x, single i x,
map_zero' :=
begin
ext i', by_cases h : i' = i,
{ subst h, simp only [single_eq_same], refl, },
{ simp only [h, single_eq_of_ne, ne.def, not_false_iff], refl, },
end,
map_add' := λ x y,
begin
ext i', by_cases h : i' = i,
-- FIXME in the next two `simp only`s,
-- it would be really nice to not have to provide the arguments to `add_apply`.
{ subst h, simp only [single_eq_same, add_apply (single i' x) (single i' y) i'], },
{ simp only [h, add_zero, single_eq_of_ne,
add_apply (single i x) (single i y) i', ne.def, not_false_iff], },
end, }
@[simp]
lemma add_monoid_hom.single_apply {i : I} (x : f i) :
(add_monoid_hom.single f i) x = single i x := rfl
end add_monoid_single
|
a5d0fcb28c72e95b50ebf56f9869808376c4abaa | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /test/print_sorry.lean | 790b9f0f4da294ad3c369da4c809322a682414c4 | [
"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 | 867 | lean | import tactic.print_sorry
axiom my_sorry : false -- we avoid using noisy code in the test folder, so we use an axiom instead
def foo1 : false := my_sorry
def foo2 : false ∧ false := ⟨my_sorry, foo1⟩
def foo3 : false ∧ false := ⟨foo2.1, my_sorry⟩
def foo4 : true := trivial
def foo5 : true ∧ false := ⟨foo4, foo3.2⟩
meta def metafoo : ℕ → empty := metafoo
open tactic
#eval show tactic unit, from do
env ← get_env,
data ← find_all_exprs env (λ e, e.const_name = `my_sorry) (λ _, ff) `foo5,
guard $ data.map (λ x, x.1) = [`foo5, `foo3, `foo2, `foo1],
guard $ data.map (λ x, x.2.1) = [ff, tt, tt, tt],
guard $ data.map (λ x, x.2.2.to_list) = [[`foo3], [`foo2], [`foo1], []],
-- make sure it doesn't loop on self-referencing meta expressions
find_all_exprs env (λ e, e.const_name = `my_sorry) (λ _, ff) `metafoo,
skip
|
7e650a7dfb4b5c12849ccdab7fd702f09f3b16b2 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/algebra/group_with_zero.lean | 237ef16ec4407612bbe8ace0b4a7a18fa3c97550 | [
"Apache-2.0"
] | permissive | Lix0120/mathlib | 0020745240315ed0e517cbf32e738d8f9811dd80 | e14c37827456fc6707f31b4d1d16f1f3a3205e91 | refs/heads/master | 1,673,102,855,024 | 1,604,151,044,000 | 1,604,151,044,000 | 308,930,245 | 0 | 0 | Apache-2.0 | 1,604,164,710,000 | 1,604,163,547,000 | null | UTF-8 | Lean | false | false | 38,346 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import logic.nontrivial
import algebra.group.units_hom
import algebra.group.inj_surj
/-!
# Groups with an adjoined zero element
This file describes structures that are not usually studied on their own right in mathematics,
namely a special sort of monoid: apart from a distinguished “zero element” they form a group,
or in other words, they are groups with an adjoined zero element.
Examples are:
* division rings;
* the value monoid of a multiplicative valuation;
* in particular, the non-negative real numbers.
## Main definitions
* `group_with_zero`
* `comm_group_with_zero`
## Implementation details
As is usual in mathlib, we extend the inverse function to the zero element,
and require `0⁻¹ = 0`.
-/
set_option old_structure_cmd true
open_locale classical
open function
variables {M₀ G₀ M₀' G₀' : Type*}
mk_simp_attribute field_simps "The simpset `field_simps` is used by the tactic `field_simp` to
reduce an expression in a field to an expression of the form `n / d` where `n` and `d` are
division-free."
section
/-- Typeclass for expressing that a type `M₀` with multiplication and a zero satisfies
`0 * a = 0` and `a * 0 = 0` for all `a : M₀`. -/
@[protect_proj, ancestor has_mul has_zero]
class mul_zero_class (M₀ : Type*) extends has_mul M₀, has_zero M₀ :=
(zero_mul : ∀ a : M₀, 0 * a = 0)
(mul_zero : ∀ a : M₀, a * 0 = 0)
section mul_zero_class
variables [mul_zero_class M₀] {a b : M₀}
@[ematch, simp] lemma zero_mul (a : M₀) : 0 * a = 0 :=
mul_zero_class.zero_mul a
@[ematch, simp] lemma mul_zero (a : M₀) : a * 0 = 0 :=
mul_zero_class.mul_zero a
/-- Pullback a `mul_zero_class` instance along an injective function. -/
protected def function.injective.mul_zero_class [has_mul M₀'] [has_zero M₀'] (f : M₀' → M₀)
(hf : injective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) :
mul_zero_class M₀' :=
{ mul := (*),
zero := 0,
zero_mul := λ a, hf $ by simp only [mul, zero, zero_mul],
mul_zero := λ a, hf $ by simp only [mul, zero, mul_zero] }
/-- Pushforward a `mul_zero_class` instance along an surjective function. -/
protected def function.surjective.mul_zero_class [has_mul M₀'] [has_zero M₀'] (f : M₀ → M₀')
(hf : surjective f) (zero : f 0 = 0) (mul : ∀ a b, f (a * b) = f a * f b) :
mul_zero_class M₀' :=
{ mul := (*),
zero := 0,
mul_zero := hf.forall.2 $ λ x, by simp only [← zero, ← mul, mul_zero],
zero_mul := hf.forall.2 $ λ x, by simp only [← zero, ← mul, zero_mul] }
lemma mul_eq_zero_of_left (h : a = 0) (b : M₀) : a * b = 0 := h.symm ▸ zero_mul b
lemma mul_eq_zero_of_right (a : M₀) (h : b = 0) : a * b = 0 := h.symm ▸ mul_zero a
lemma left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 := mt (λ h, mul_eq_zero_of_left h b)
lemma right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 := mt (mul_eq_zero_of_right a)
lemma ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩
lemma mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) :
a * b = 0 :=
if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero]
end mul_zero_class
/-- Predicate typeclass for expressing that `a * b = 0` implies `a = 0` or `b = 0`
for all `a` and `b` of type `G₀`. -/
class no_zero_divisors (M₀ : Type*) [has_mul M₀] [has_zero M₀] : Prop :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : M₀}, a * b = 0 → a = 0 ∨ b = 0)
export no_zero_divisors (eq_zero_or_eq_zero_of_mul_eq_zero)
/-- Pushforward a `no_zero_divisors` instance along an injective function. -/
protected lemma function.injective.no_zero_divisors [has_mul M₀] [has_zero M₀]
[has_mul M₀'] [has_zero M₀'] [no_zero_divisors M₀']
(f : M₀ → M₀') (hf : injective f) (zero : f 0 = 0) (mul : ∀ x y, f (x * y) = f x * f y) :
no_zero_divisors M₀ :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ x y H,
have f x * f y = 0, by rw [← mul, H, zero],
(eq_zero_or_eq_zero_of_mul_eq_zero this).imp (λ H, hf $ by rwa zero) (λ H, hf $ by rwa zero) }
lemma eq_zero_of_mul_self_eq_zero [has_mul M₀] [has_zero M₀] [no_zero_divisors M₀]
{a : M₀} (h : a * a = 0) :
a = 0 :=
(eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id
section
variables [mul_zero_class M₀] [no_zero_divisors M₀] {a b : M₀}
/-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them
equals zero. -/
@[simp] theorem mul_eq_zero : a * b = 0 ↔ a = 0 ∨ b = 0 :=
⟨eq_zero_or_eq_zero_of_mul_eq_zero,
λo, o.elim (λ h, mul_eq_zero_of_left h b) (mul_eq_zero_of_right a)⟩
/-- If `α` has no zero divisors, then the product of two elements equals zero iff one of them
equals zero. -/
@[simp] theorem zero_eq_mul : 0 = a * b ↔ a = 0 ∨ b = 0 :=
by rw [eq_comm, mul_eq_zero]
/-- If `α` has no zero divisors, then the product of two elements is nonzero iff both of them
are nonzero. -/
theorem mul_ne_zero_iff : a * b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 :=
(not_congr mul_eq_zero).trans not_or_distrib
theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 :=
mul_ne_zero_iff.2 ⟨ha, hb⟩
/-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` equals zero iff so is
`b * a`. -/
theorem mul_eq_zero_comm : a * b = 0 ↔ b * a = 0 :=
mul_eq_zero.trans $ (or_comm _ _).trans mul_eq_zero.symm
/-- If `α` has no zero divisors, then for elements `a, b : α`, `a * b` is nonzero iff so is
`b * a`. -/
theorem mul_ne_zero_comm : a * b ≠ 0 ↔ b * a ≠ 0 :=
not_congr mul_eq_zero_comm
lemma mul_self_eq_zero : a * a = 0 ↔ a = 0 := by simp
lemma zero_eq_mul_self : 0 = a * a ↔ a = 0 := by simp
end
end
/-- A type `M` is a “monoid with zero” if it is a monoid with zero element, and `0` is left
and right absorbing. -/
@[protect_proj] class monoid_with_zero (M₀ : Type*) extends monoid M₀, mul_zero_class M₀.
/-- A type `M` is a `cancel_monoid_with_zero` if it is a monoid with zero element, `0` is left
and right absorbing, and left/right multiplication by a non-zero element is injective. -/
@[protect_proj] class cancel_monoid_with_zero (M₀ : Type*) extends monoid_with_zero M₀ :=
(mul_left_cancel_of_ne_zero : ∀ {a b c : M₀}, a ≠ 0 → a * b = a * c → b = c)
(mul_right_cancel_of_ne_zero : ∀ {a b c : M₀}, b ≠ 0 → a * b = c * b → a = c)
section
variables [monoid_with_zero M₀] [nontrivial M₀] {a b : M₀}
/-- In a nontrivial monoid with zero, zero and one are different. -/
@[simp] lemma zero_ne_one : 0 ≠ (1:M₀) :=
begin
assume h,
rcases exists_pair_ne M₀ with ⟨x, y, hx⟩,
apply hx,
calc x = 1 * x : by rw [one_mul]
... = 0 : by rw [← h, zero_mul]
... = 1 * y : by rw [← h, zero_mul]
... = y : by rw [one_mul]
end
@[simp] lemma one_ne_zero : (1:M₀) ≠ 0 :=
zero_ne_one.symm
lemma ne_zero_of_eq_one {a : M₀} (h : a = 1) : a ≠ 0 :=
calc a = 1 : h
... ≠ 0 : one_ne_zero
lemma left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 :=
left_ne_zero_of_mul $ ne_zero_of_eq_one h
lemma right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 :=
right_ne_zero_of_mul $ ne_zero_of_eq_one h
/-- Pullback a `nontrivial` instance along a function sending `0` to `0` and `1` to `1`. -/
protected lemma pullback_nonzero [has_zero M₀'] [has_one M₀']
(f : M₀' → M₀) (zero : f 0 = 0) (one : f 1 = 1) : nontrivial M₀' :=
⟨⟨0, 1, mt (congr_arg f) $ by { rw [zero, one], exact zero_ne_one }⟩⟩
end
/-- A type `M` is a commutative “monoid with zero” if it is a commutative monoid with zero
element, and `0` is left and right absorbing. -/
@[protect_proj]
class comm_monoid_with_zero (M₀ : Type*) extends comm_monoid M₀, monoid_with_zero M₀.
/-- A type `M` is a `comm_cancel_monoid_with_zero` if it is a commutative monoid with zero element,
`0` is left and right absorbing,
and left/right multiplication by a non-zero element is injective. -/
@[protect_proj] class comm_cancel_monoid_with_zero (M₀ : Type*) extends
comm_monoid_with_zero M₀, cancel_monoid_with_zero M₀.
/-- A type `G₀` is a “group with zero” if it is a monoid with zero element (distinct from `1`)
such that every nonzero element is invertible.
The type is required to come with an “inverse” function, and the inverse of `0` must be `0`.
Examples include division rings and the ordered monoids that are the
target of valuations in general valuation theory.-/
class group_with_zero (G₀ : Type*) extends monoid_with_zero G₀, has_inv G₀, nontrivial G₀ :=
(inv_zero : (0 : G₀)⁻¹ = 0)
(mul_inv_cancel : ∀ a:G₀, a ≠ 0 → a * a⁻¹ = 1)
/-- A type `G₀` is a commutative “group with zero”
if it is a commutative monoid with zero element (distinct from `1`)
such that every nonzero element is invertible.
The type is required to come with an “inverse” function, and the inverse of `0` must be `0`. -/
class comm_group_with_zero (G₀ : Type*) extends comm_monoid_with_zero G₀, group_with_zero G₀.
/-- The division operation on a group with zero element. -/
@[priority 100] -- see Note [lower instance priority]
instance group_with_zero.has_div {G₀ : Type*} [group_with_zero G₀] :
has_div G₀ := ⟨λ g h, g * h⁻¹⟩
section monoid_with_zero
/-- Pullback a `monoid_with_zero` class along an injective function. -/
protected def function.injective.monoid_with_zero [has_zero M₀'] [has_mul M₀'] [has_one M₀']
[monoid_with_zero M₀]
(f : M₀' → M₀) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) :
monoid_with_zero M₀' :=
{ .. hf.monoid f one mul, .. hf.mul_zero_class f zero mul }
/-- Pushforward a `monoid_with_zero` class along a surjective function. -/
protected def function.surjective.monoid_with_zero [has_zero M₀'] [has_mul M₀'] [has_one M₀']
[monoid_with_zero M₀]
(f : M₀ → M₀') (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) :
monoid_with_zero M₀' :=
{ .. hf.monoid f one mul, .. hf.mul_zero_class f zero mul }
/-- Pullback a `monoid_with_zero` class along an injective function. -/
protected def function.injective.comm_monoid_with_zero [has_zero M₀'] [has_mul M₀'] [has_one M₀']
[comm_monoid_with_zero M₀]
(f : M₀' → M₀) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_monoid_with_zero M₀' :=
{ .. hf.comm_monoid f one mul, .. hf.mul_zero_class f zero mul }
/-- Pushforward a `monoid_with_zero` class along a surjective function. -/
protected def function.surjective.comm_monoid_with_zero [has_zero M₀'] [has_mul M₀'] [has_one M₀']
[comm_monoid_with_zero M₀]
(f : M₀ → M₀') (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_monoid_with_zero M₀' :=
{ .. hf.comm_monoid f one mul, .. hf.mul_zero_class f zero mul }
variables [monoid_with_zero M₀]
namespace units
/-- An element of the unit group of a nonzero monoid with zero represented as an element
of the monoid is nonzero. -/
@[simp] lemma ne_zero [nontrivial M₀] (u : units M₀) :
(u : M₀) ≠ 0 :=
left_ne_zero_of_mul_eq_one u.mul_inv
-- We can't use `mul_eq_zero` + `units.ne_zero` in the next two lemmas because we don't assume
-- `nonzero M₀`.
@[simp] lemma mul_left_eq_zero (u : units M₀) {a : M₀} : a * u = 0 ↔ a = 0 :=
⟨λ h, by simpa using mul_eq_zero_of_left h ↑u⁻¹, λ h, mul_eq_zero_of_left h u⟩
@[simp] lemma mul_right_eq_zero (u : units M₀) {a : M₀} : ↑u * a = 0 ↔ a = 0 :=
⟨λ h, by simpa using mul_eq_zero_of_right ↑u⁻¹ h, mul_eq_zero_of_right u⟩
end units
namespace is_unit
lemma ne_zero [nontrivial M₀] {a : M₀} (ha : is_unit a) : a ≠ 0 := let ⟨u, hu⟩ := ha in hu ▸ u.ne_zero
lemma mul_right_eq_zero {a b : M₀} (ha : is_unit a) : a * b = 0 ↔ b = 0 :=
let ⟨u, hu⟩ := ha in hu ▸ u.mul_right_eq_zero
lemma mul_left_eq_zero {a b : M₀} (hb : is_unit b) : a * b = 0 ↔ a = 0 :=
let ⟨u, hu⟩ := hb in hu ▸ u.mul_left_eq_zero
end is_unit
/-- In a monoid with zero, if zero equals one, then zero is the only element. -/
lemma eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 :=
by rw [← mul_one a, ← h, mul_zero]
/-- In a monoid with zero, if zero equals one, then zero is the unique element.
Somewhat arbitrarily, we define the default element to be `0`.
All other elements will be provably equal to it, but not necessarily definitionally equal. -/
def unique_of_zero_eq_one (h : (0 : M₀) = 1) : unique M₀ :=
{ default := 0, uniq := eq_zero_of_zero_eq_one h }
/-- In a monoid with zero, zero equals one if and only if all elements of that semiring are equal. -/
theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ subsingleton M₀ :=
⟨λ h, @unique.subsingleton _ (unique_of_zero_eq_one h), λ h, @subsingleton.elim _ h _ _⟩
alias subsingleton_iff_zero_eq_one ↔ subsingleton_of_zero_eq_one _
lemma eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b :=
@subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b
@[simp] theorem is_unit_zero_iff : is_unit (0 : M₀) ↔ (0:M₀) = 1 :=
⟨λ ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩, by rwa zero_mul at a0,
λ h, @is_unit_of_subsingleton _ _ (subsingleton_of_zero_eq_one h) 0⟩
@[simp] theorem not_is_unit_zero [nontrivial M₀] : ¬ is_unit (0 : M₀) :=
mt is_unit_zero_iff.1 zero_ne_one
variable (M₀)
/-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/
lemma zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ (∀a:M₀, a = 0) :=
not_or_of_imp eq_zero_of_zero_eq_one
end monoid_with_zero
section cancel_monoid_with_zero
variables [cancel_monoid_with_zero M₀] {a b c : M₀}
@[priority 10] -- see Note [lower instance priority]
instance comm_cancel_monoid_with_zero.no_zero_divisors : no_zero_divisors M₀ :=
⟨λ a b ab0, by { by_cases a = 0, { left, exact h }, right,
apply cancel_monoid_with_zero.mul_left_cancel_of_ne_zero h, rw [ab0, mul_zero], }⟩
lemma mul_left_cancel' (ha : a ≠ 0) (h : a * b = a * c) : b = c :=
cancel_monoid_with_zero.mul_left_cancel_of_ne_zero ha h
lemma mul_right_cancel' (hb : b ≠ 0) (h : a * b = c * b) : a = c :=
cancel_monoid_with_zero.mul_right_cancel_of_ne_zero hb h
lemma mul_left_inj' (hc : c ≠ 0) : a * c = b * c ↔ a = b := ⟨mul_right_cancel' hc, λ h, h ▸ rfl⟩
lemma mul_right_inj' (ha : a ≠ 0) : a * b = a * c ↔ b = c := ⟨mul_left_cancel' ha, λ h, h ▸ rfl⟩
@[simp] lemma mul_eq_mul_right_iff : a * c = b * c ↔ a = b ∨ c = 0 :=
by by_cases hc : c = 0; [simp [hc], simp [mul_left_inj', hc]]
@[simp] lemma mul_eq_mul_left_iff : a * b = a * c ↔ b = c ∨ a = 0 :=
by by_cases ha : a = 0; [simp [ha], simp [mul_right_inj', ha]]
/-- Pullback a `monoid_with_zero` class along an injective function. -/
protected def function.injective.cancel_monoid_with_zero [has_zero M₀'] [has_mul M₀'] [has_one M₀']
(f : M₀' → M₀) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) :
cancel_monoid_with_zero M₀' :=
{ mul_left_cancel_of_ne_zero := λ x y z hx H, hf $ mul_left_cancel' ((hf.ne_iff' zero).2 hx) $
by erw [← mul, ← mul, H]; refl,
mul_right_cancel_of_ne_zero := λ x y z hx H, hf $ mul_right_cancel' ((hf.ne_iff' zero).2 hx) $
by erw [← mul, ← mul, H]; refl,
.. hf.monoid f one mul, .. hf.mul_zero_class f zero mul }
/-- An element of a `cancel_monoid_with_zero` fixed by right multiplication by an element other
than one must be zero. -/
theorem eq_zero_of_mul_eq_self_right (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 :=
classical.by_contradiction $ λ ha, h₁ $ mul_left_cancel' ha $ h₂.symm ▸ (mul_one a).symm
/-- An element of a `cancel_monoid_with_zero` fixed by left multiplication by an element other
than one must be zero. -/
theorem eq_zero_of_mul_eq_self_left (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 :=
classical.by_contradiction $ λ ha, h₁ $ mul_right_cancel' ha $ h₂.symm ▸ (one_mul a).symm
end cancel_monoid_with_zero
section group_with_zero
variables [group_with_zero G₀]
lemma div_eq_mul_inv {a b : G₀} : a / b = a * b⁻¹ := rfl
alias div_eq_mul_inv ← division_def
@[simp] lemma inv_zero : (0 : G₀)⁻¹ = 0 :=
group_with_zero.inv_zero
@[simp] lemma mul_inv_cancel {a : G₀} (h : a ≠ 0) : a * a⁻¹ = 1 :=
group_with_zero.mul_inv_cancel a h
/-- Pullback a `group_with_zero` class along an injective function. -/
protected def function.injective.group_with_zero [has_zero G₀'] [has_mul G₀'] [has_one G₀']
[has_inv G₀'] (f : G₀' → G₀) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
group_with_zero G₀' :=
{ inv := has_inv.inv,
inv_zero := hf $ by erw [inv, zero, inv_zero],
mul_inv_cancel := λ x hx, hf $ by erw [one, mul, inv, mul_inv_cancel ((hf.ne_iff' zero).2 hx)],
.. hf.monoid_with_zero f zero one mul,
.. pullback_nonzero f zero one }
/-- Pushforward a `group_with_zero` class along an surjective function. -/
protected def function.surjective.group_with_zero [has_zero G₀'] [has_mul G₀'] [has_one G₀']
[has_inv G₀'] (h01 : (0:G₀') ≠ 1)
(f : G₀ → G₀') (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
group_with_zero G₀' :=
{ inv := has_inv.inv,
inv_zero := by erw [← zero, ← inv, inv_zero],
mul_inv_cancel := hf.forall.2 $ λ x hx,
by erw [← inv, ← mul, mul_inv_cancel (mt (congr_arg f) $ trans_rel_left ne hx zero.symm)];
exact one,
exists_pair_ne := ⟨0, 1, h01⟩,
.. hf.monoid_with_zero f zero one mul }
@[simp] lemma mul_inv_cancel_right' {b : G₀} (h : b ≠ 0) (a : G₀) :
(a * b) * b⁻¹ = a :=
calc (a * b) * b⁻¹ = a * (b * b⁻¹) : mul_assoc _ _ _
... = a : by simp [h]
@[simp] lemma mul_inv_cancel_left' {a : G₀} (h : a ≠ 0) (b : G₀) :
a * (a⁻¹ * b) = b :=
calc a * (a⁻¹ * b) = (a * a⁻¹) * b : (mul_assoc _ _ _).symm
... = b : by simp [h]
lemma inv_ne_zero {a : G₀} (h : a ≠ 0) : a⁻¹ ≠ 0 :=
assume a_eq_0, by simpa [a_eq_0] using mul_inv_cancel h
@[simp] lemma inv_mul_cancel {a : G₀} (h : a ≠ 0) : a⁻¹ * a = 1 :=
calc a⁻¹ * a = (a⁻¹ * a) * a⁻¹ * a⁻¹⁻¹ : by simp [inv_ne_zero h]
... = a⁻¹ * a⁻¹⁻¹ : by simp [h]
... = 1 : by simp [inv_ne_zero h]
@[simp] lemma inv_mul_cancel_right' {b : G₀} (h : b ≠ 0) (a : G₀) :
(a * b⁻¹) * b = a :=
calc (a * b⁻¹) * b = a * (b⁻¹ * b) : mul_assoc _ _ _
... = a : by simp [h]
@[simp] lemma inv_mul_cancel_left' {a : G₀} (h : a ≠ 0) (b : G₀) :
a⁻¹ * (a * b) = b :=
calc a⁻¹ * (a * b) = (a⁻¹ * a) * b : (mul_assoc _ _ _).symm
... = b : by simp [h]
@[simp] lemma inv_one : 1⁻¹ = (1:G₀) :=
calc 1⁻¹ = 1 * 1⁻¹ : by rw [one_mul]
... = (1:G₀) : by simp
@[simp] lemma inv_inv' (a : G₀) : a⁻¹⁻¹ = a :=
begin
classical,
by_cases h : a = 0, { simp [h] },
calc a⁻¹⁻¹ = a * (a⁻¹ * a⁻¹⁻¹) : by simp [h]
... = a : by simp [inv_ne_zero h]
end
/-- Multiplying `a` by itself and then by its inverse results in `a`
(whether or not `a` is zero). -/
@[simp] lemma mul_self_mul_inv (a : G₀) : a * a * a⁻¹ = a :=
begin
classical,
by_cases h : a = 0,
{ rw [h, inv_zero, mul_zero] },
{ rw [mul_assoc, mul_inv_cancel h, mul_one] }
end
/-- Multiplying `a` by its inverse and then by itself results in `a`
(whether or not `a` is zero). -/
@[simp] lemma mul_inv_mul_self (a : G₀) : a * a⁻¹ * a = a :=
begin
classical,
by_cases h : a = 0,
{ rw [h, inv_zero, mul_zero] },
{ rw [mul_inv_cancel h, one_mul] }
end
/-- Multiplying `a⁻¹` by `a` twice results in `a` (whether or not `a`
is zero). -/
@[simp] lemma inv_mul_mul_self (a : G₀) : a⁻¹ * a * a = a :=
begin
classical,
by_cases h : a = 0,
{ rw [h, inv_zero, mul_zero] },
{ rw [inv_mul_cancel h, one_mul] }
end
/-- Multiplying `a` by itself and then dividing by itself results in
`a` (whether or not `a` is zero). -/
@[simp] lemma mul_self_div_self (a : G₀) : a * a / a = a :=
mul_self_mul_inv a
/-- Dividing `a` by itself and then multiplying by itself results in
`a` (whether or not `a` is zero). -/
@[simp] lemma div_self_mul_self (a : G₀) : a / a * a = a :=
mul_inv_mul_self a
lemma inv_involutive' : function.involutive (has_inv.inv : G₀ → G₀) :=
inv_inv'
lemma eq_inv_of_mul_right_eq_one {a b : G₀} (h : a * b = 1) :
b = a⁻¹ :=
by rw [← inv_mul_cancel_left' (left_ne_zero_of_mul_eq_one h) b, h, mul_one]
lemma eq_inv_of_mul_left_eq_one {a b : G₀} (h : a * b = 1) :
a = b⁻¹ :=
by rw [← mul_inv_cancel_right' (right_ne_zero_of_mul_eq_one h) a, h, one_mul]
lemma inv_injective' : function.injective (@has_inv.inv G₀ _) :=
inv_involutive'.injective
@[simp] lemma inv_inj' {g h : G₀} : g⁻¹ = h⁻¹ ↔ g = h := inv_injective'.eq_iff
lemma inv_eq_iff {g h : G₀} : g⁻¹ = h ↔ h⁻¹ = g :=
by rw [← inv_inj', eq_comm, inv_inv']
@[simp] lemma inv_eq_one' {g : G₀} : g⁻¹ = 1 ↔ g = 1 :=
by rw [inv_eq_iff, inv_one, eq_comm]
end group_with_zero
namespace units
variables [group_with_zero G₀]
variables {a b : G₀}
/-- Embed a non-zero element of a `group_with_zero` into the unit group.
By combining this function with the operations on units,
or the `/ₚ` operation, it is possible to write a division
as a partial function with three arguments. -/
def mk0 (a : G₀) (ha : a ≠ 0) : units G₀ :=
⟨a, a⁻¹, mul_inv_cancel ha, inv_mul_cancel ha⟩
@[simp] lemma coe_mk0 {a : G₀} (h : a ≠ 0) : (mk0 a h : G₀) = a := rfl
@[simp] lemma mk0_coe (u : units G₀) (h : (u : G₀) ≠ 0) : mk0 (u : G₀) h = u :=
units.ext rfl
@[simp, norm_cast] lemma coe_inv' (u : units G₀) : ((u⁻¹ : units G₀) : G₀) = u⁻¹ :=
eq_inv_of_mul_left_eq_one u.inv_mul
@[simp] lemma mul_inv' (u : units G₀) : (u : G₀) * u⁻¹ = 1 := mul_inv_cancel u.ne_zero
@[simp] lemma inv_mul' (u : units G₀) : (u⁻¹ : G₀) * u = 1 := inv_mul_cancel u.ne_zero
@[simp] lemma mk0_inj {a b : G₀} (ha : a ≠ 0) (hb : b ≠ 0) :
units.mk0 a ha = units.mk0 b hb ↔ a = b :=
⟨λ h, by injection h, λ h, units.ext h⟩
@[simp] lemma exists_iff_ne_zero {x : G₀} : (∃ u : units G₀, ↑u = x) ↔ x ≠ 0 :=
⟨λ ⟨u, hu⟩, hu ▸ u.ne_zero, assume hx, ⟨mk0 x hx, rfl⟩⟩
end units
section group_with_zero
variables [group_with_zero G₀]
lemma is_unit.mk0 (x : G₀) (hx : x ≠ 0) : is_unit x := is_unit_unit (units.mk0 x hx)
lemma is_unit_iff_ne_zero {x : G₀} : is_unit x ↔ x ≠ 0 :=
units.exists_iff_ne_zero
@[priority 10] -- see Note [lower instance priority]
instance group_with_zero.no_zero_divisors : no_zero_divisors G₀ :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h,
begin
classical, contrapose! h,
exact ((units.mk0 a h.1) * (units.mk0 b h.2)).ne_zero
end,
.. (‹_› : group_with_zero G₀) }
@[priority 10] -- see Note [lower instance priority]
instance group_with_zero.cancel_monoid_with_zero : cancel_monoid_with_zero G₀ :=
{ mul_left_cancel_of_ne_zero := λ x y z hx h,
by rw [← inv_mul_cancel_left' hx y, h, inv_mul_cancel_left' hx z],
mul_right_cancel_of_ne_zero := λ x y z hy h,
by rw [← mul_inv_cancel_right' hy x, h, mul_inv_cancel_right' hy z],
.. (‹_› : group_with_zero G₀) }
lemma mul_inv_rev' (x y : G₀) : (x * y)⁻¹ = y⁻¹ * x⁻¹ :=
begin
classical,
by_cases hx : x = 0, { simp [hx] },
by_cases hy : y = 0, { simp [hy] },
symmetry,
apply eq_inv_of_mul_left_eq_one,
simp [mul_assoc, hx, hy]
end
@[simp] lemma div_self {a : G₀} (h : a ≠ 0) : a / a = 1 := mul_inv_cancel h
@[simp] lemma div_one (a : G₀) : a / 1 = a := by simp [div_eq_mul_inv]
@[simp] lemma one_div (a : G₀) : 1 / a = a⁻¹ := one_mul _
@[simp] lemma zero_div (a : G₀) : 0 / a = 0 := zero_mul _
@[simp] lemma div_zero (a : G₀) : a / 0 = 0 :=
show a * 0⁻¹ = 0, by rw [inv_zero, mul_zero]
@[simp] lemma div_mul_cancel (a : G₀) {b : G₀} (h : b ≠ 0) : a / b * b = a :=
inv_mul_cancel_right' h a
lemma div_mul_cancel_of_imp {a b : G₀} (h : b = 0 → a = 0) : a / b * b = a :=
classical.by_cases (λ hb : b = 0, by simp [*]) (div_mul_cancel a)
@[simp] lemma mul_div_cancel (a : G₀) {b : G₀} (h : b ≠ 0) : a * b / b = a :=
mul_inv_cancel_right' h a
lemma mul_div_cancel_of_imp {a b : G₀} (h : b = 0 → a = 0) : a * b / b = a :=
classical.by_cases (λ hb : b = 0, by simp [*]) (mul_div_cancel a)
lemma mul_div_assoc {a b c : G₀} : a * b / c = a * (b / c) :=
mul_assoc _ _ _
local attribute [simp] div_eq_mul_inv mul_comm mul_assoc mul_left_comm
lemma div_eq_mul_one_div (a b : G₀) : a / b = a * (1 / b) :=
by simp
lemma mul_one_div_cancel {a : G₀} (h : a ≠ 0) : a * (1 / a) = 1 :=
by simp [h]
lemma one_div_mul_cancel {a : G₀} (h : a ≠ 0) : (1 / a) * a = 1 :=
by simp [h]
lemma one_div_one : 1 / 1 = (1:G₀) :=
div_self (ne.symm zero_ne_one)
lemma one_div_ne_zero {a : G₀} (h : a ≠ 0) : 1 / a ≠ 0 :=
by simpa only [one_div] using inv_ne_zero h
lemma eq_one_div_of_mul_eq_one {a b : G₀} (h : a * b = 1) : b = 1 / a :=
by simpa only [one_div] using eq_inv_of_mul_right_eq_one h
lemma eq_one_div_of_mul_eq_one_left {a b : G₀} (h : b * a = 1) : b = 1 / a :=
by simpa only [one_div] using eq_inv_of_mul_left_eq_one h
@[simp] lemma one_div_div (a b : G₀) : 1 / (a / b) = b / a :=
by rw [one_div, div_eq_mul_inv, mul_inv_rev', inv_inv', div_eq_mul_inv]
lemma one_div_one_div (a : G₀) : 1 / (1 / a) = a :=
by simp
lemma eq_of_one_div_eq_one_div {a b : G₀} (h : 1 / a = 1 / b) : a = b :=
by rw [← one_div_one_div a, h, one_div_one_div]
variables {a b c : G₀}
@[simp] lemma inv_eq_zero {a : G₀} : a⁻¹ = 0 ↔ a = 0 :=
by rw [inv_eq_iff, inv_zero, eq_comm]
@[simp] lemma zero_eq_inv {a : G₀} : 0 = a⁻¹ ↔ 0 = a :=
eq_comm.trans $ inv_eq_zero.trans eq_comm
lemma one_div_mul_one_div_rev (a b : G₀) : (1 / a) * (1 / b) = 1 / (b * a) :=
by simp only [div_eq_mul_inv, one_mul, mul_inv_rev']
theorem divp_eq_div (a : G₀) (u : units G₀) : a /ₚ u = a / u :=
congr_arg _ $ u.coe_inv'
@[simp] theorem divp_mk0 (a : G₀) {b : G₀} (hb : b ≠ 0) :
a /ₚ units.mk0 b hb = a / b :=
divp_eq_div _ _
lemma inv_div : (a / b)⁻¹ = b / a :=
(mul_inv_rev' _ _).trans (by rw inv_inv'; refl)
lemma inv_div_left : a⁻¹ / b = (b * a)⁻¹ :=
(mul_inv_rev' _ _).symm
lemma div_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a / b ≠ 0 :=
mul_ne_zero ha (inv_ne_zero hb)
@[simp] lemma div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = 0:=
by simp [div_eq_mul_inv]
lemma div_ne_zero_iff : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 :=
(not_congr div_eq_zero_iff).trans not_or_distrib
lemma div_left_inj' (hc : c ≠ 0) : a / c = b / c ↔ a = b :=
by rw [← divp_mk0 _ hc, ← divp_mk0 _ hc, divp_left_inj]
lemma div_eq_iff_mul_eq (hb : b ≠ 0) : a / b = c ↔ c * b = a :=
⟨λ h, by rw [← h, div_mul_cancel _ hb],
λ h, by rw [← h, mul_div_cancel _ hb]⟩
lemma eq_div_iff_mul_eq (hc : c ≠ 0) : a = b / c ↔ a * c = b :=
by rw [eq_comm, div_eq_iff_mul_eq hc]
lemma div_eq_of_eq_mul {x : G₀} (hx : x ≠ 0) {y z : G₀} (h : y = z * x) : y / x = z :=
(div_eq_iff_mul_eq hx).2 h.symm
lemma eq_div_of_mul_eq {x : G₀} (hx : x ≠ 0) {y z : G₀} (h : z * x = y) : z = y / x :=
eq.symm $ div_eq_of_eq_mul hx h.symm
lemma eq_of_div_eq_one (h : a / b = 1) : a = b :=
begin
classical,
by_cases hb : b = 0,
{ rw [hb, div_zero] at h,
exact eq_of_zero_eq_one h a b },
{ rwa [div_eq_iff_mul_eq hb, one_mul, eq_comm] at h }
end
lemma div_eq_one_iff_eq (hb : b ≠ 0) : a / b = 1 ↔ a = b :=
⟨eq_of_div_eq_one, λ h, h.symm ▸ div_self hb⟩
lemma div_mul_left {a b : G₀} (hb : b ≠ 0) : b / (a * b) = 1 / a :=
by simp only [div_eq_mul_inv, mul_inv_rev', mul_inv_cancel_left' hb, one_mul]
lemma mul_div_mul_right (a b : G₀) {c : G₀} (hc : c ≠ 0) :
(a * c) / (b * c) = a / b :=
by simp only [div_eq_mul_inv, mul_inv_rev', mul_assoc, mul_inv_cancel_left' hc]
lemma mul_mul_div (a : G₀) {b : G₀} (hb : b ≠ 0) : a = a * b * (1 / b) :=
by simp [hb]
end group_with_zero
section comm_group_with_zero -- comm
variables [comm_group_with_zero G₀] {a b c : G₀}
@[priority 10] -- see Note [lower instance priority]
instance comm_group_with_zero.comm_cancel_monoid_with_zero : comm_cancel_monoid_with_zero G₀ :=
{ ..group_with_zero.cancel_monoid_with_zero, ..comm_group_with_zero.to_comm_monoid_with_zero G₀ }
/-- Pullback a `comm_group_with_zero` class along an injective function. -/
protected def function.injective.comm_group_with_zero [has_zero G₀'] [has_mul G₀'] [has_one G₀']
[has_inv G₀'] (f : G₀' → G₀) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
comm_group_with_zero G₀' :=
{ .. hf.group_with_zero f zero one mul inv, .. hf.comm_semigroup f mul }
/-- Pushforward a `comm_group_with_zero` class along an surjective function. -/
protected def function.surjective.comm_group_with_zero [has_zero G₀'] [has_mul G₀'] [has_one G₀']
[has_inv G₀'] (h01 : (0:G₀') ≠ 1)
(f : G₀ → G₀') (hf : surjective f) (zero : f 0 = 0) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹) :
comm_group_with_zero G₀' :=
{ .. hf.group_with_zero h01 f zero one mul inv, .. hf.comm_semigroup f mul }
lemma mul_inv' : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
by rw [mul_inv_rev', mul_comm]
lemma one_div_mul_one_div (a b : G₀) : (1 / a) * (1 / b) = 1 / (a * b) :=
by rw [one_div_mul_one_div_rev, mul_comm b]
lemma div_mul_right {a : G₀} (b : G₀) (ha : a ≠ 0) : a / (a * b) = 1 / b :=
by rw [mul_comm, div_mul_left ha]
lemma mul_div_cancel_left_of_imp {a b : G₀} (h : a = 0 → b = 0) : a * b / a = b :=
by rw [mul_comm, mul_div_cancel_of_imp h]
lemma mul_div_cancel_left {a : G₀} (b : G₀) (ha : a ≠ 0) : a * b / a = b :=
mul_div_cancel_left_of_imp $ λ h, (ha h).elim
lemma mul_div_cancel_of_imp' {a b : G₀} (h : b = 0 → a = 0) : b * (a / b) = a :=
by rw [mul_comm, div_mul_cancel_of_imp h]
lemma mul_div_cancel' (a : G₀) {b : G₀} (hb : b ≠ 0) : b * (a / b) = a :=
by rw [mul_comm, (div_mul_cancel _ hb)]
local attribute [simp] mul_assoc mul_comm mul_left_comm
lemma div_mul_div (a b c d : G₀) :
(a / b) * (c / d) = (a * c) / (b * d) :=
by simp [div_eq_mul_inv, mul_inv']
lemma mul_div_mul_left (a b : G₀) {c : G₀} (hc : c ≠ 0) :
(c * a) / (c * b) = a / b :=
by rw [mul_comm c, mul_comm c, mul_div_mul_right _ _ hc]
@[field_simps] lemma div_mul_eq_mul_div (a b c : G₀) : (b / c) * a = (b * a) / c :=
by simp [div_eq_mul_inv]
lemma div_mul_eq_mul_div_comm (a b c : G₀) :
(b / c) * a = b * (a / c) :=
by rw [div_mul_eq_mul_div, ← one_mul c, ← div_mul_div, div_one, one_mul]
lemma mul_eq_mul_of_div_eq_div (a : G₀) {b : G₀} (c : G₀) {d : G₀} (hb : b ≠ 0)
(hd : d ≠ 0) (h : a / b = c / d) : a * d = c * b :=
by rw [← mul_one (a*d), mul_assoc, mul_comm d, ← mul_assoc, ← div_self hb,
← div_mul_eq_mul_div_comm, h, div_mul_eq_mul_div, div_mul_cancel _ hd]
@[field_simps] lemma div_div_eq_mul_div (a b c : G₀) :
a / (b / c) = (a * c) / b :=
by rw [div_eq_mul_one_div, one_div_div, ← mul_div_assoc]
@[field_simps] lemma div_div_eq_div_mul (a b c : G₀) :
(a / b) / c = a / (b * c) :=
by rw [div_eq_mul_one_div, div_mul_div, mul_one]
lemma div_div_div_div_eq (a : G₀) {b c d : G₀} :
(a / b) / (c / d) = (a * d) / (b * c) :=
by rw [div_div_eq_mul_div, div_mul_eq_mul_div, div_div_eq_div_mul]
lemma div_mul_eq_div_mul_one_div (a b c : G₀) :
a / (b * c) = (a / b) * (1 / c) :=
by rw [← div_div_eq_div_mul, ← div_eq_mul_one_div]
/-- Dividing `a` by the result of dividing `a` by itself results in
`a` (whether or not `a` is zero). -/
@[simp] lemma div_div_self (a : G₀) : a / (a / a) = a :=
begin
rw div_div_eq_mul_div,
exact mul_self_div_self a
end
lemma ne_zero_of_one_div_ne_zero {a : G₀} (h : 1 / a ≠ 0) : a ≠ 0 :=
assume ha : a = 0, begin rw [ha, div_zero] at h, contradiction end
lemma eq_zero_of_one_div_eq_zero {a : G₀} (h : 1 / a = 0) : a = 0 :=
classical.by_cases
(assume ha, ha)
(assume ha, ((one_div_ne_zero ha) h).elim)
lemma div_helper {a : G₀} (b : G₀) (h : a ≠ 0) : (1 / (a * b)) * a = 1 / b :=
by rw [div_mul_eq_mul_div, one_mul, div_mul_right _ h]
end comm_group_with_zero
section comm_group_with_zero
variables [comm_group_with_zero G₀] {a b c d : G₀}
lemma div_eq_inv_mul : a / b = b⁻¹ * a := mul_comm _ _
lemma mul_div_right_comm (a b c : G₀) : (a * b) / c = (a / c) * b :=
by rw [div_eq_mul_inv, mul_assoc, mul_comm b, ← mul_assoc]; refl
lemma mul_comm_div' (a b c : G₀) : (a / b) * c = a * (c / b) :=
by rw [← mul_div_assoc, mul_div_right_comm]
lemma div_mul_comm' (a b c : G₀) : (a / b) * c = (c / b) * a :=
by rw [div_mul_eq_mul_div, mul_comm, mul_div_right_comm]
lemma mul_div_comm (a b c : G₀) : a * (b / c) = b * (a / c) :=
by rw [← mul_div_assoc, mul_comm, mul_div_assoc]
lemma div_right_comm (a : G₀) : (a / b) / c = (a / c) / b :=
by rw [div_div_eq_div_mul, div_div_eq_div_mul, mul_comm]
lemma div_div_div_cancel_right (a : G₀) (hc : c ≠ 0) : (a / c) / (b / c) = a / b :=
by rw [div_div_eq_mul_div, div_mul_cancel _ hc]
lemma div_mul_div_cancel (a : G₀) (hc : c ≠ 0) : (a / c) * (c / b) = a / b :=
by rw [← mul_div_assoc, div_mul_cancel _ hc]
@[field_simps] lemma div_eq_div_iff (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b :=
calc a / b = c / d ↔ a / b * (b * d) = c / d * (b * d) :
by rw [mul_left_inj' (mul_ne_zero hb hd)]
... ↔ a * d = c * b :
by rw [← mul_assoc, div_mul_cancel _ hb,
← mul_assoc, mul_right_comm, div_mul_cancel _ hd]
@[field_simps] lemma div_eq_iff (hb : b ≠ 0) : a / b = c ↔ a = c * b :=
by simpa using @div_eq_div_iff _ _ a b c 1 hb one_ne_zero
@[field_simps] lemma eq_div_iff (hb : b ≠ 0) : c = a / b ↔ c * b = a :=
by simpa using @div_eq_div_iff _ _ c 1 a b one_ne_zero hb
lemma div_div_cancel' (ha : a ≠ 0) : a / (a / b) = b :=
by rw [div_eq_mul_inv, inv_div, mul_div_cancel' _ ha]
end comm_group_with_zero
namespace semiconj_by
@[simp] lemma zero_right [mul_zero_class G₀] (a : G₀) : semiconj_by a 0 0 :=
by simp only [semiconj_by, mul_zero, zero_mul]
@[simp] lemma zero_left [mul_zero_class G₀] (x y : G₀) : semiconj_by 0 x y :=
by simp only [semiconj_by, mul_zero, zero_mul]
variables [group_with_zero G₀] {a x y x' y' : G₀}
@[simp] lemma inv_symm_left_iff' : semiconj_by a⁻¹ x y ↔ semiconj_by a y x :=
classical.by_cases
(λ ha : a = 0, by simp only [ha, inv_zero, semiconj_by.zero_left])
(λ ha, @units_inv_symm_left_iff _ _ (units.mk0 a ha) _ _)
lemma inv_symm_left' (h : semiconj_by a x y) : semiconj_by a⁻¹ y x :=
semiconj_by.inv_symm_left_iff'.2 h
lemma inv_right' (h : semiconj_by a x y) : semiconj_by a x⁻¹ y⁻¹ :=
begin
classical,
by_cases ha : a = 0,
{ simp only [ha, zero_left] },
by_cases hx : x = 0,
{ subst x,
simp only [semiconj_by, mul_zero, @eq_comm _ _ (y * a), mul_eq_zero] at h,
simp [h.resolve_right ha] },
{ have := mul_ne_zero ha hx,
rw [h.eq, mul_ne_zero_iff] at this,
exact @units_inv_right _ _ _ (units.mk0 x hx) (units.mk0 y this.1) h },
end
@[simp] lemma inv_right_iff' : semiconj_by a x⁻¹ y⁻¹ ↔ semiconj_by a x y :=
⟨λ h, inv_inv' x ▸ inv_inv' y ▸ h.inv_right', inv_right'⟩
lemma div_right (h : semiconj_by a x y) (h' : semiconj_by a x' y') :
semiconj_by a (x / x') (y / y') :=
h.mul_right h'.inv_right'
end semiconj_by
namespace commute
@[simp] theorem zero_right [mul_zero_class G₀] (a : G₀) :commute a 0 := semiconj_by.zero_right a
@[simp] theorem zero_left [mul_zero_class G₀] (a : G₀) : commute 0 a := semiconj_by.zero_left a a
variables [group_with_zero G₀] {a b c : G₀}
@[simp] theorem inv_left_iff' : commute a⁻¹ b ↔ commute a b :=
semiconj_by.inv_symm_left_iff'
theorem inv_left' (h : commute a b) : commute a⁻¹ b := inv_left_iff'.2 h
@[simp] theorem inv_right_iff' : commute a b⁻¹ ↔ commute a b :=
semiconj_by.inv_right_iff'
theorem inv_right' (h : commute a b) : commute a b⁻¹ := inv_right_iff'.2 h
theorem inv_inv' (h : commute a b) : commute a⁻¹ b⁻¹ := h.inv_left'.inv_right'
@[simp] theorem div_right (hab : commute a b) (hac : commute a c) :
commute a (b / c) :=
hab.div_right hac
@[simp] theorem div_left (hac : commute a c) (hbc : commute b c) :
commute (a / b) c :=
hac.mul_left hbc.inv_left'
end commute
namespace monoid_hom
variables [group_with_zero G₀] [group_with_zero G₀'] [monoid_with_zero M₀] [nontrivial M₀]
section monoid_with_zero
variables (f : G₀ →* M₀) (h0 : f 0 = 0) {a : G₀}
include h0
lemma map_ne_zero : f a ≠ 0 ↔ a ≠ 0 :=
⟨λ hfa ha, hfa $ ha.symm ▸ h0, λ ha, ((is_unit.mk0 a ha).map f).ne_zero⟩
lemma map_eq_zero : f a = 0 ↔ a = 0 :=
by { classical, exact not_iff_not.1 (f.map_ne_zero h0) }
end monoid_with_zero
section group_with_zero
variables (f : G₀ →* G₀') (h0 : f 0 = 0) (a b : G₀)
include h0
/-- A monoid homomorphism between groups with zeros sending `0` to `0` sends `a⁻¹` to `(f a)⁻¹`. -/
lemma map_inv' : f a⁻¹ = (f a)⁻¹ :=
begin
classical, by_cases h : a = 0, by simp [h, h0],
apply eq_inv_of_mul_left_eq_one,
rw [← f.map_mul, inv_mul_cancel h, f.map_one]
end
lemma map_div : f (a / b) = f a / f b :=
(f.map_mul _ _).trans $ _root_.congr_arg _ $ f.map_inv' h0 b
omit h0
@[simp] lemma map_units_inv {M G₀ : Type*} [monoid M] [group_with_zero G₀]
(f : M →* G₀) (u : units M) : f ↑u⁻¹ = (f u)⁻¹ :=
by rw [← units.coe_map, ← units.coe_map, ← units.coe_inv', map_inv]
end group_with_zero
end monoid_hom
|
e497e5c9983e30a7517734d1c986d741908f7527 | 29cc89d6158dd3b90acbdbcab4d2c7eb9a7dbf0f | /3.2/x32_library.lean | ef36e4b3c1818d1d1744750c2a55aade73f71686 | [] | no_license | KjellZijlemaker/Logical_Verification_VU | ced0ba95316a30e3c94ba8eebd58ea004fa6f53b | 4578b93bf1615466996157bb333c84122b201d99 | refs/heads/master | 1,585,966,086,108 | 1,549,187,704,000 | 1,549,187,704,000 | 155,690,284 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,628 | lean | /- Library 3.2: Program Semantics — Hoare Logic -/
/- This file contains some basic material for the Hoare logic lecture, exercise, and homework.
This file contains the following concepts:
* `state`: representing the state space of an imperative program (defined as `string → ℕ`)
* `∅` is the empty state; mapping every variable to `0`
* `s.update n v` or `s & n ::= v`: replace the name `n` in the state `s` by value `v`
* `s n` variable `n` of state `s`
* `program` syntax for WHILE programs over `state` as state space.
This is a slight modification of the lecture 3.1. Instead of over an arbitrary state space `σ` we
are now fixed on `state`; and also `assign` only allows changing one variable.
* `(p, s) ⟹ t`: big-step semantics over `program`
It is all under the `lecture` namespace. -/
meta def tactic.dec_trivial := `[exact dec_trivial]
@[simp] lemma not_not_iff (p : Prop) [decidable p] : ¬ (¬ p) ↔ p :=
by by_cases p; simp [h]
@[simp] lemma and_imp (p q r : Prop) : ((p ∧ q) → r) ↔ (p → q → r) :=
iff.intro
(assume h hp hq, h ⟨hp, hq⟩)
(assume h ⟨hp, hq⟩, h hp hq)
namespace lecture
/- `state` to represent state spaces -/
def state := string → ℕ
def state.update (name : string) (val : ℕ) (s : state) : state :=
λn, if n = name then val else s n
notation s ` & ` n ` ::= ` v := state.update n v s
namespace state
instance : has_emptyc state := ⟨λ_, 0⟩
@[simp] lemma update_apply (name : string) (val : ℕ) (s : state) :
(s & name ::= val) name = val :=
if_pos rfl
@[simp] lemma update_apply_ne (name name' : string) (val : ℕ) (s : state)
(h : name' ≠ name . tactic.dec_trivial):
(s & name ::= val) name' = s name' :=
if_neg h
@[simp] lemma update_override (name : string) (val₁ val₂ : ℕ) (s : state) :
(s & name ::= val₂ & name ::= val₁) = (s & name ::= val₁) :=
by funext name'; by_cases name' = name; simp [h]
@[simp] lemma update_swap
(name₁ name₂ : string) (val₁ val₂ : ℕ) (s : state) (h : name₁ ≠ name₂ . tactic.dec_trivial):
(s & name₂ ::= val₂ & name₁ ::= val₁) = (s & name₁ ::= val₁ & name₂ ::= val₂) :=
by funext name'; by_cases h₁ : name' = name₁; by_cases h₂ : name' = name₂; simp * at *
end state
example (s : state) : (s & "a" ::= 0 & "a" ::= 2) = (s & "a" ::= 2) :=
by simp
example (s : state) : (s & "a" ::= 0 & "b" ::= 2) = (s & "b" ::= 2 & "a" ::= 0) :=
by simp
/- A WHILE programming language -/
inductive program : Type
| skip {} : program
| assign : string → (state → ℕ) → program
| seq : program → program → program
| ite : (state → Prop) → program → program → program
| while : (state → Prop) → program → program
infixr ` ;; `:90 := program.seq
open program
/- We use the **big step** semantics -/
inductive big_step : (program × state) → state → Prop
| skip {s} :
big_step (skip, s) s
| assign {n f s} :
big_step (assign n f, s) (s.update n (f s))
| seq {p₁ p₂ s u} (t) (h₁ : big_step (p₁, s) t) (h₂ : big_step (p₂, t) u) :
big_step (seq p₁ p₂, s) u
| ite_true {c : state → Prop} {p₁ p₀ s t} (hs : c s) (h : big_step (p₁, s) t) :
big_step (ite c p₁ p₀, s) t
| ite_false {c : state → Prop} {p₁ p₀ s t} (hs : ¬ c s) (h : big_step (p₀, s) t) :
big_step (ite c p₁ p₀, s) t
| while_true {c : state → Prop} {p s u} (t) (hs : c s) (hp : big_step (p, s) t)
(hw : big_step (while c p, t) u) :
big_step (while c p, s) u
| while_false {c : state → Prop} {p s} (hs : ¬ c s) : big_step (while c p, s) s
infix ` ⟹ `:110 := big_step
end lecture
|
00a1d56fbf5239f2d506ae34e4565dc4a1d1460e | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/analysis/normed_space/units.lean | 3a2d725f11e76dfeea5a427e4e378fdf85feed2d | [
"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 | 12,220 | lean | /-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.specific_limits
/-!
# The group of units of a complete normed ring
This file contains the basic theory for the group of units (invertible elements) of a complete
normed ring (Banach algebras being a notable special case).
## Main results
The constructions `one_sub`, `add` and `unit_of_nearby` state, in varying forms, that perturbations
of a unit are units. The latter two are not stated in their optimal form; more precise versions
would use the spectral radius.
The first main result is `is_open`: the group of units of a complete normed ring is an open subset
of the ring.
The function `inverse` (defined in `algebra.ring`), for a ring `R`, sends `a : R` to `a⁻¹` if `a` is
a unit and 0 if not. The other major results of this file (notably `inverse_add`,
`inverse_add_norm` and `inverse_add_norm_diff_nth_order`) cover the asymptotic properties of
`inverse (x + t)` as `t → 0`.
-/
noncomputable theory
open_locale topological_space
variables {R : Type*} [normed_ring R] [complete_space R]
namespace units
/-- In a complete normed ring, a perturbation of `1` by an element `t` of distance less than `1`
from `1` is a unit. Here we construct its `units` structure. -/
@[simps coe]
def one_sub (t : R) (h : ∥t∥ < 1) : units R :=
{ val := 1 - t,
inv := ∑' n : ℕ, t ^ n,
val_inv := mul_neg_geom_series t h,
inv_val := geom_series_mul_neg t h }
/-- In a complete normed ring, a perturbation of a unit `x` by an element `t` of distance less than
`∥x⁻¹∥⁻¹` from `x` is a unit. Here we construct its `units` structure. -/
@[simps coe]
def add (x : units R) (t : R) (h : ∥t∥ < ∥(↑x⁻¹ : R)∥⁻¹) : units R :=
units.copy -- to make `coe_add` true definitionally, for convenience
(x * (units.one_sub (-(↑x⁻¹ * t)) begin
nontriviality R using [zero_lt_one],
have hpos : 0 < ∥(↑x⁻¹ : R)∥ := units.norm_pos x⁻¹,
calc ∥-(↑x⁻¹ * t)∥
= ∥↑x⁻¹ * t∥ : by { rw norm_neg }
... ≤ ∥(↑x⁻¹ : R)∥ * ∥t∥ : norm_mul_le ↑x⁻¹ _
... < ∥(↑x⁻¹ : R)∥ * ∥(↑x⁻¹ : R)∥⁻¹ : by nlinarith only [h, hpos]
... = 1 : mul_inv_cancel (ne_of_gt hpos)
end))
(x + t) (by simp [mul_add]) _ rfl
/-- In a complete normed ring, an element `y` of distance less than `∥x⁻¹∥⁻¹` from `x` is a unit.
Here we construct its `units` structure. -/
@[simps coe]
def unit_of_nearby (x : units R) (y : R) (h : ∥y - x∥ < ∥(↑x⁻¹ : R)∥⁻¹) : units R :=
units.copy (x.add (y - x : R) h) y (by simp) _ rfl
/-- The group of units of a complete normed ring is an open subset of the ring. -/
protected lemma is_open : is_open {x : R | is_unit x} :=
begin
nontriviality R,
apply metric.is_open_iff.mpr,
rintros x' ⟨x, rfl⟩,
refine ⟨∥(↑x⁻¹ : R)∥⁻¹, inv_pos.mpr (units.norm_pos x⁻¹), _⟩,
intros y hy,
rw [metric.mem_ball, dist_eq_norm] at hy,
exact (x.unit_of_nearby y hy).is_unit
end
protected lemma nhds (x : units R) : {x : R | is_unit x} ∈ 𝓝 (x : R) :=
is_open.mem_nhds units.is_open x.is_unit
end units
namespace normed_ring
open_locale classical big_operators
open asymptotics filter metric finset ring
lemma inverse_one_sub (t : R) (h : ∥t∥ < 1) : inverse (1 - t) = ↑(units.one_sub t h)⁻¹ :=
by rw [← inverse_unit (units.one_sub t h), units.coe_one_sub]
/-- The formula `inverse (x + t) = inverse (1 + x⁻¹ * t) * x⁻¹` holds for `t` sufficiently small. -/
lemma inverse_add (x : units R) :
∀ᶠ t in (𝓝 0), inverse ((x : R) + t) = inverse (1 + ↑x⁻¹ * t) * ↑x⁻¹ :=
begin
nontriviality R,
rw [eventually_iff, metric.mem_nhds_iff],
have hinv : 0 < ∥(↑x⁻¹ : R)∥⁻¹, by cancel_denoms,
use [∥(↑x⁻¹ : R)∥⁻¹, hinv],
intros t ht,
simp only [mem_ball, dist_zero_right] at ht,
have ht' : ∥-↑x⁻¹ * t∥ < 1,
{ refine lt_of_le_of_lt (norm_mul_le _ _) _,
rw norm_neg,
refine lt_of_lt_of_le (mul_lt_mul_of_pos_left ht x⁻¹.norm_pos) _,
cancel_denoms },
have hright := inverse_one_sub (-↑x⁻¹ * t) ht',
have hleft := inverse_unit (x.add t ht),
simp only [← neg_mul_eq_neg_mul, sub_neg_eq_add] at hright,
simp only [units.coe_add] at hleft,
simp [hleft, hright, units.add]
end
lemma inverse_one_sub_nth_order (n : ℕ) :
∀ᶠ t in (𝓝 0), inverse ((1:R) - t) = (∑ i in range n, t ^ i) + (t ^ n) * inverse (1 - t) :=
begin
simp only [eventually_iff, metric.mem_nhds_iff],
use [1, by norm_num],
intros t ht,
simp only [mem_ball, dist_zero_right] at ht,
simp only [inverse_one_sub t ht, set.mem_set_of_eq],
have h : 1 = ((range n).sum (λ i, t ^ i)) * (units.one_sub t ht) + t ^ n,
{ simp only [units.coe_one_sub],
rw [← geom_sum, geom_sum_mul_neg],
simp },
rw [← one_mul ↑(units.one_sub t ht)⁻¹, h, add_mul],
congr,
{ rw [mul_assoc, (units.one_sub t ht).mul_inv],
simp },
{ simp only [units.coe_one_sub],
rw [← add_mul, ← geom_sum, geom_sum_mul_neg],
simp }
end
/-- The formula
`inverse (x + t) = (∑ i in range n, (- x⁻¹ * t) ^ i) * x⁻¹ + (- x⁻¹ * t) ^ n * inverse (x + t)`
holds for `t` sufficiently small. -/
lemma inverse_add_nth_order (x : units R) (n : ℕ) :
∀ᶠ t in (𝓝 0), inverse ((x : R) + t)
= (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹ + (- ↑x⁻¹ * t) ^ n * inverse (x + t) :=
begin
refine (inverse_add x).mp _,
have hzero : tendsto (λ (t : R), - ↑x⁻¹ * t) (𝓝 0) (𝓝 0),
{ convert ((mul_left_continuous (- (↑x⁻¹ : R))).tendsto 0).comp tendsto_id,
simp },
refine (hzero.eventually (inverse_one_sub_nth_order n)).mp (eventually_of_forall _),
simp only [neg_mul_eq_neg_mul_symm, sub_neg_eq_add],
intros t h1 h2,
have h := congr_arg (λ (a : R), a * ↑x⁻¹) h1,
dsimp at h,
convert h,
rw [add_mul, mul_assoc],
simp [h2.symm]
end
lemma inverse_one_sub_norm : is_O (λ t, inverse ((1:R) - t)) (λ t, (1:ℝ)) (𝓝 (0:R)) :=
begin
simp only [is_O, is_O_with, eventually_iff, metric.mem_nhds_iff],
refine ⟨∥(1:R)∥ + 1, (2:ℝ)⁻¹, by norm_num, _⟩,
intros t ht,
simp only [ball, dist_zero_right, set.mem_set_of_eq] at ht,
have ht' : ∥t∥ < 1,
{ have : (2:ℝ)⁻¹ < 1 := by cancel_denoms,
linarith },
simp only [inverse_one_sub t ht', norm_one, mul_one, set.mem_set_of_eq],
change ∥∑' n : ℕ, t ^ n∥ ≤ _,
have := normed_ring.tsum_geometric_of_norm_lt_1 t ht',
have : (1 - ∥t∥)⁻¹ ≤ 2,
{ rw ← inv_inv' (2:ℝ),
refine inv_le_inv_of_le (by norm_num) _,
have : (2:ℝ)⁻¹ + (2:ℝ)⁻¹ = 1 := by ring,
linarith },
linarith
end
/-- The function `λ t, inverse (x + t)` is O(1) as `t → 0`. -/
lemma inverse_add_norm (x : units R) : is_O (λ t, inverse (↑x + t)) (λ t, (1:ℝ)) (𝓝 (0:R)) :=
begin
nontriviality R,
simp only [is_O_iff, norm_one, mul_one],
cases is_O_iff.mp (@inverse_one_sub_norm R _ _) with C hC,
use C * ∥((x⁻¹:units R):R)∥,
have hzero : tendsto (λ t, - (↑x⁻¹ : R) * t) (𝓝 0) (𝓝 0),
{ convert ((mul_left_continuous (-↑x⁻¹ : R)).tendsto 0).comp tendsto_id,
simp },
refine (inverse_add x).mp ((hzero.eventually hC).mp (eventually_of_forall _)),
intros t bound iden,
rw iden,
simp at bound,
have hmul := norm_mul_le (inverse (1 + ↑x⁻¹ * t)) ↑x⁻¹,
nlinarith [norm_nonneg (↑x⁻¹ : R)]
end
/-- The function
`λ t, inverse (x + t) - (∑ i in range n, (- x⁻¹ * t) ^ i) * x⁻¹`
is `O(t ^ n)` as `t → 0`. -/
lemma inverse_add_norm_diff_nth_order (x : units R) (n : ℕ) :
is_O (λ (t : R), inverse (↑x + t) - (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹)
(λ t, ∥t∥ ^ n) (𝓝 (0:R)) :=
begin
by_cases h : n = 0,
{ simpa [h] using inverse_add_norm x },
have hn : 0 < n := nat.pos_of_ne_zero h,
simp [is_O_iff],
cases (is_O_iff.mp (inverse_add_norm x)) with C hC,
use C * ∥(1:ℝ)∥ * ∥(↑x⁻¹ : R)∥ ^ n,
have h : eventually_eq (𝓝 (0:R))
(λ t, inverse (↑x + t) - (∑ i in range n, (- ↑x⁻¹ * t) ^ i) * ↑x⁻¹)
(λ t, ((- ↑x⁻¹ * t) ^ n) * inverse (x + t)),
{ refine (inverse_add_nth_order x n).mp (eventually_of_forall _),
intros t ht,
convert congr_arg (λ a, a - (range n).sum (pow (-↑x⁻¹ * t)) * ↑x⁻¹) ht,
simp },
refine h.mp (hC.mp (eventually_of_forall _)),
intros t _ hLHS,
simp only [neg_mul_eq_neg_mul_symm] at hLHS,
rw hLHS,
refine le_trans (norm_mul_le _ _ ) _,
have h' : ∥(-(↑x⁻¹ * t)) ^ n∥ ≤ ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n,
{ calc ∥(-(↑x⁻¹ * t)) ^ n∥ ≤ ∥(-(↑x⁻¹ * t))∥ ^ n : norm_pow_le' _ hn
... = ∥↑x⁻¹ * t∥ ^ n : by rw norm_neg
... ≤ (∥(↑x⁻¹ : R)∥ * ∥t∥) ^ n : _
... = ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n : mul_pow _ _ n,
exact pow_le_pow_of_le_left (norm_nonneg _) (norm_mul_le ↑x⁻¹ t) n },
have h'' : 0 ≤ ∥(↑x⁻¹ : R)∥ ^ n * ∥t∥ ^ n,
{ refine mul_nonneg _ _;
exact pow_nonneg (norm_nonneg _) n },
nlinarith [norm_nonneg (inverse (↑x + t))],
end
/-- The function `λ t, inverse (x + t) - x⁻¹` is `O(t)` as `t → 0`. -/
lemma inverse_add_norm_diff_first_order (x : units R) :
is_O (λ t, inverse (↑x + t) - ↑x⁻¹) (λ t, ∥t∥) (𝓝 (0:R)) :=
by { convert inverse_add_norm_diff_nth_order x 1; simp }
/-- The function
`λ t, inverse (x + t) - x⁻¹ + x⁻¹ * t * x⁻¹`
is `O(t ^ 2)` as `t → 0`. -/
lemma inverse_add_norm_diff_second_order (x : units R) :
is_O (λ t, inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) (λ t, ∥t∥ ^ 2) (𝓝 (0:R)) :=
begin
convert inverse_add_norm_diff_nth_order x 2,
ext t,
simp only [range_succ, range_one, sum_insert, mem_singleton, sum_singleton, not_false_iff,
one_ne_zero, pow_zero, add_mul, pow_one, one_mul, neg_mul_eq_neg_mul_symm,
sub_add_eq_sub_sub_swap, sub_neg_eq_add],
end
/-- The function `inverse` is continuous at each unit of `R`. -/
lemma inverse_continuous_at (x : units R) : continuous_at inverse (x : R) :=
begin
have h_is_o : is_o (λ (t : R), ∥inverse (↑x + t) - ↑x⁻¹∥) (λ (t : R), (1:ℝ)) (𝓝 0),
{ refine is_o_norm_left.mpr ((inverse_add_norm_diff_first_order x).trans_is_o _),
exact is_o_norm_left.mpr (is_o_id_const one_ne_zero) },
have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0),
{ refine tendsto_zero_iff_norm_tendsto_zero.mpr _,
exact tendsto_iff_norm_tendsto_zero.mp tendsto_id },
simp only [continuous_at],
rw [tendsto_iff_norm_tendsto_zero, inverse_unit],
convert h_is_o.tendsto_0.comp h_lim,
ext, simp
end
end normed_ring
namespace units
open opposite filter normed_ring
/-- In a normed ring, the coercion from `units R` (equipped with the induced topology from the
embedding in `R × R`) to `R` is an open map. -/
lemma is_open_map_coe : is_open_map (coe : units R → R) :=
begin
rw is_open_map_iff_nhds_le,
intros x s,
rw [mem_map, mem_nhds_induced],
rintros ⟨t, ht, hts⟩,
obtain ⟨u, hu, v, hv, huvt⟩ :
∃ (u : set R), u ∈ 𝓝 ↑x ∧ ∃ (v : set Rᵒᵖ), v ∈ 𝓝 (opposite.op ↑x⁻¹) ∧ u.prod v ⊆ t,
{ simpa [embed_product, mem_nhds_prod_iff] using ht },
have : u ∩ (op ∘ ring.inverse) ⁻¹' v ∩ (set.range (coe : units R → R)) ∈ 𝓝 ↑x,
{ refine inter_mem_sets (inter_mem_sets hu _) (units.nhds x),
refine (continuous_op.continuous_at.comp (inverse_continuous_at x)).preimage_mem_nhds _,
simpa using hv },
refine mem_sets_of_superset this _,
rintros _ ⟨⟨huy, hvy⟩, ⟨y, rfl⟩⟩,
have : embed_product R y ∈ u.prod v := ⟨huy, by simpa using hvy⟩,
simpa using hts (huvt this)
end
/-- In a normed ring, the coercion from `units R` (equipped with the induced topology from the
embedding in `R × R`) to `R` is an open embedding. -/
lemma open_embedding_coe : open_embedding (coe : units R → R) :=
open_embedding_of_continuous_injective_open continuous_coe ext is_open_map_coe
end units
|
7ea8a7d210aac34ea60d177fdc71d883748bc9cb | b2c4bd81ed12cc14c20704365f094339d4c894a2 | /src/graph_theory/subgraph.lean | 3f300c256dbfe5ddb387b55475be5163439f658d | [] | no_license | agusakov/graph_theory_2020 | 711639d9d9b25fd83899620da11ae1753d11d48b | 83a8afc31aa28dbec39a768d6042d3cb515f7a16 | refs/heads/master | 1,669,901,277,114 | 1,596,931,643,000 | 1,596,931,643,000 | 285,154,458 | 5 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,726 | lean | /-
Copyright (c) 2020 Alena Gusakov, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Alena Gusakov, Jalex Stark.
-/
import .basic
noncomputable theory
open_locale classical
universes u
variables {V : Type u}
namespace simple_graph
-- define map from graph to subgraph, use `is_subgraph` property from graph_induction.lean
def is_subgraph (H : simple_graph V) (G : simple_graph V) : Prop :=
∀ u v, H.adj u v → G.adj u v
variables (G : simple_graph V)
include G
@[refl] lemma is_subgraph_self : G.is_subgraph G := by tidy
lemma empty_is_subgraph : empty.is_subgraph G := by tidy
def subgraph := {H : simple_graph V // H.is_subgraph G}
namespace subgraph
-- CR-soon jstark: bundle these together
variables {G} (H : simple_graph V) (hG : H.is_subgraph G)
include hG
def edge_inclusion : H.E → G.E :=
begin
intro e,
set u := e.some,
have hu := e.some_spec,
set v := e.other hu,
have hv := e.other_mem hu,
suffices : G.adj u v, { apply G.edge_of_adj this },
apply hG, apply e.other_adj,
end
-- properties of `inclusion`: it's an injective homomorphism
end subgraph
def induced_subgraph (G : simple_graph V) (S : set V) : simple_graph S :=
{
adj := λ a b, G.adj a b,
sym := λ a b h, G.sym h,
loopless := λ x h, G.loopless x h
}
variables (s : set V) (S : simple_graph s)
-- two ideas:
-- `induced_subgraph.to_supergraph`
-- `simple_graph.to_induced_subgraph`
/-def induced_subgraph.to_supergraph {S : simple_graph s} {G : simple_graph V} : S.E → G.E
| -/
def path_inclusion.to_supergraph {V : Type u} : T.path → S.path
| [] := ∅
| (h::t) := {h} ∪ list.to_set t
end simple_graph
|
83fd93ff95dafb668e711f0b6d59c92da84d6252 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/topology/metric_space/emetric_paracompact.lean | 5048b2434f82d6924a4b7cbe65078869b760cc3b | [
"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 | 8,367 | lean | /-
Copyright (c) 202 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import set_theory.ordinal.basic
import topology.metric_space.emetric_space
import topology.paracompact
/-!
# (Extended) metric spaces are paracompact
In this file we provide two instances:
* `emetric.paracompact_space`: a `pseudo_emetric_space` is paracompact; formalization is based
on [MR0236876];
* `emetric.normal_of_metric`: an `emetric_space` is a normal topological space.
## Tags
metric space, paracompact space, normal space
-/
variable {α : Type*}
open_locale ennreal topological_space
open set
namespace emetric
/-- A `pseudo_emetric_space` is always a paracompact space. Formalization is based
on [MR0236876]. -/
@[priority 100] -- See note [lower instance priority]
instance [pseudo_emetric_space α] : paracompact_space α :=
begin
classical,
/- We start with trivial observations about `1 / 2 ^ k`. Here and below we use `1 / 2 ^ k` in
the comments and `2⁻¹ ^ k` in the code. -/
have pow_pos : ∀ k : ℕ, (0 : ℝ≥0∞) < 2⁻¹ ^ k,
from λ k, ennreal.pow_pos (ennreal.inv_pos.2 ennreal.two_ne_top) _,
have hpow_le : ∀ {m n : ℕ}, m ≤ n → (2⁻¹ : ℝ≥0∞) ^ n ≤ 2⁻¹ ^ m,
from λ m n h, ennreal.pow_le_pow_of_le_one (ennreal.inv_le_one.2 ennreal.one_lt_two.le) h,
have h2pow : ∀ n : ℕ, 2 * (2⁻¹ : ℝ≥0∞) ^ (n + 1) = 2⁻¹ ^ n,
by { intro n, simp [pow_succ, ← mul_assoc, ennreal.mul_inv_cancel] },
-- Consider an open covering `S : set (set α)`
refine ⟨λ ι s ho hcov, _⟩,
simp only [Union_eq_univ_iff] at hcov,
-- choose a well founded order on `S`
letI : linear_order ι := linear_order_of_STO' well_ordering_rel,
have wf : well_founded ((<) : ι → ι → Prop) := @is_well_founded.wf ι well_ordering_rel _,
-- Let `ind x` be the minimal index `s : S` such that `x ∈ s`.
set ind : α → ι := λ x, wf.min {i : ι | x ∈ s i} (hcov x),
have mem_ind : ∀ x, x ∈ s (ind x), from λ x, wf.min_mem _ (hcov x),
have nmem_of_lt_ind : ∀ {x i}, i < (ind x) → x ∉ s i,
from λ x i hlt hxi, wf.not_lt_min _ (hcov x) hxi hlt,
/- The refinement `D : ℕ → ι → set α` is defined recursively. For each `n` and `i`, `D n i`
is the union of balls `ball x (1 / 2 ^ n)` over all points `x` such that
* `ind x = i`;
* `x` does not belong to any `D m j`, `m < n`;
* `ball x (3 / 2 ^ n) ⊆ s i`;
We define this sequence using `nat.strong_rec_on'`, then restate it as `Dn` and `memD`.
-/
set D : ℕ → ι → set α :=
λ n, nat.strong_rec_on' n (λ n D' i,
⋃ (x : α) (hxs : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D' m ‹_› j), ball x (2⁻¹ ^ n)),
have Dn : ∀ n i, D n i = ⋃ (x : α) (hxs : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D m j), ball x (2⁻¹ ^ n),
from λ n s, by { simp only [D], rw nat.strong_rec_on_beta' },
have memD : ∀ {n i y}, y ∈ D n i ↔ ∃ x (hi : ind x = i) (hb : ball x (3 * 2⁻¹ ^ n) ⊆ s i)
(hlt : ∀ (m < n) (j : ι), x ∉ D m j), edist y x < 2⁻¹ ^ n,
{ intros n i y, rw [Dn n i], simp only [mem_Union, mem_ball] },
-- The sets `D n i` cover the whole space. Indeed, for each `x` we can choose `n` such that
-- `ball x (3 / 2 ^ n) ⊆ s (ind x)`, then either `x ∈ D n i`, or `x ∈ D m i` for some `m < n`.
have Dcov : ∀ x, ∃ n i, x ∈ D n i,
{ intro x,
obtain ⟨n, hn⟩ : ∃ n : ℕ, ball x (3 * 2⁻¹ ^ n) ⊆ s (ind x),
{ -- This proof takes 5 lines because we can't import `specific_limits` here
rcases is_open_iff.1 (ho $ ind x) x (mem_ind x) with ⟨ε, ε0, hε⟩,
have : 0 < ε / 3 := ennreal.div_pos_iff.2 ⟨ε0.lt.ne', ennreal.coe_ne_top⟩,
rcases ennreal.exists_inv_two_pow_lt this.ne' with ⟨n, hn⟩,
refine ⟨n, subset.trans (ball_subset_ball _) hε⟩,
simpa only [div_eq_mul_inv, mul_comm] using (ennreal.mul_lt_of_lt_div hn).le },
by_contra' h,
apply h n (ind x),
exact memD.2 ⟨x, rfl, hn, λ _ _ _, h _ _, mem_ball_self (pow_pos _)⟩ },
-- Each `D n i` is a union of open balls, hence it is an open set
have Dopen : ∀ n i, is_open (D n i),
{ intros n i,
rw Dn,
iterate 4 { refine is_open_Union (λ _, _) },
exact is_open_ball },
-- the covering `D n i` is a refinement of the original covering: `D n i ⊆ s i`
have HDS : ∀ n i, D n i ⊆ s i,
{ intros n s x,
rw memD,
rintro ⟨y, rfl, hsub, -, hyx⟩,
refine hsub (lt_of_lt_of_le hyx _),
calc 2⁻¹ ^ n = 1 * 2⁻¹ ^ n : (one_mul _).symm
... ≤ 3 * 2⁻¹ ^ n : ennreal.mul_le_mul _ le_rfl,
-- TODO: use `norm_num`
have : ((1 : ℕ) : ℝ≥0∞) ≤ (3 : ℕ), from ennreal.coe_nat_le_coe_nat.2 (by norm_num1),
exact_mod_cast this },
-- Let us show the rest of the properties. Since the definition expects a family indexed
-- by a single parameter, we use `ℕ × ι` as the domain.
refine ⟨ℕ × ι, λ ni, D ni.1 ni.2, λ _, Dopen _ _, _, _, λ ni, ⟨ni.2, HDS _ _⟩⟩,
-- The sets `D n i` cover the whole space as we proved earlier
{ refine Union_eq_univ_iff.2 (λ x, _),
rcases Dcov x with ⟨n, i, h⟩,
exact ⟨⟨n, i⟩, h⟩ },
{ /- Let us prove that the covering `D n i` is locally finite. Take a point `x` and choose
`n`, `i` so that `x ∈ D n i`. Since `D n i` is an open set, we can choose `k` so that
`B = ball x (1 / 2 ^ (n + k + 1)) ⊆ D n i`. -/
intro x,
rcases Dcov x with ⟨n, i, hn⟩,
have : D n i ∈ 𝓝 x, from is_open.mem_nhds (Dopen _ _) hn,
rcases (nhds_basis_uniformity uniformity_basis_edist_inv_two_pow).mem_iff.1 this
with ⟨k, -, hsub : ball x (2⁻¹ ^ k) ⊆ D n i⟩,
set B := ball x (2⁻¹ ^ (n + k + 1)),
refine ⟨B, ball_mem_nhds _ (pow_pos _), _⟩,
-- The sets `D m i`, `m > n + k`, are disjoint with `B`
have Hgt : ∀ (m ≥ n + k + 1) (i : ι), disjoint (D m i) B,
{ rintros m hm i y ⟨hym, hyx⟩,
rcases memD.1 hym with ⟨z, rfl, hzi, H, hz⟩,
have : z ∉ ball x (2⁻¹ ^ k), from λ hz, H n (by linarith) i (hsub hz), apply this,
calc edist z x ≤ edist y z + edist y x : edist_triangle_left _ _ _
... < (2⁻¹ ^ m) + (2⁻¹ ^ (n + k + 1)) : ennreal.add_lt_add hz hyx
... ≤ (2⁻¹ ^ (k + 1)) + (2⁻¹ ^ (k + 1)) :
add_le_add (hpow_le $ by linarith) (hpow_le $ by linarith)
... = (2⁻¹ ^ k) : by rw [← two_mul, h2pow] },
-- For each `m ≤ n + k` there is at most one `j` such that `D m j ∩ B` is nonempty.
have Hle : ∀ m ≤ n + k, set.subsingleton {j | (D m j ∩ B).nonempty},
{ rintros m hm j₁ ⟨y, hyD, hyB⟩ j₂ ⟨z, hzD, hzB⟩,
by_contra h,
wlog h : j₁ < j₂ := ne.lt_or_lt h using [j₁ j₂ y z, j₂ j₁ z y],
rcases memD.1 hyD with ⟨y', rfl, hsuby, -, hdisty⟩,
rcases memD.1 hzD with ⟨z', rfl, -, -, hdistz⟩,
suffices : edist z' y' < 3 * 2⁻¹ ^ m, from nmem_of_lt_ind h (hsuby this),
calc edist z' y' ≤ edist z' x + edist x y' : edist_triangle _ _ _
... ≤ (edist z z' + edist z x) + (edist y x + edist y y') :
add_le_add (edist_triangle_left _ _ _) (edist_triangle_left _ _ _)
... < (2⁻¹ ^ m + 2⁻¹ ^ (n + k + 1)) + (2⁻¹ ^ (n + k + 1) + 2⁻¹ ^ m) :
by apply_rules [ennreal.add_lt_add]
... = 2 * (2⁻¹ ^ m + 2⁻¹ ^ (n + k + 1)) : by simp only [two_mul, add_comm]
... ≤ 2 * (2⁻¹ ^ m + 2⁻¹ ^ (m + 1)) :
ennreal.mul_le_mul le_rfl $ add_le_add le_rfl $ hpow_le (add_le_add hm le_rfl)
... = 3 * 2⁻¹ ^ m : by rw [mul_add, h2pow, bit1, add_mul, one_mul] },
-- Finally, we glue `Hgt` and `Hle`
have : (⋃ (m ≤ n + k) (i ∈ {i : ι | (D m i ∩ B).nonempty}), {(m, i)}).finite :=
(finite_le_nat _).bUnion' (λ i hi, (Hle i hi).finite.bUnion' (λ _ _, finite_singleton _)),
refine this.subset (λ I hI, _), simp only [mem_Union],
refine ⟨I.1, _, I.2, hI, prod.mk.eta.symm⟩,
exact not_lt.1 (λ hlt, Hgt I.1 hlt I.2 hI.some_spec) }
end
@[priority 100] -- see Note [lower instance priority]
instance normal_of_emetric [emetric_space α] : normal_space α := normal_of_paracompact_t2
end emetric
|
f6e01fe4342dfca9356bbf698c71978cb92a6ed9 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /hott/init/types.hlean | 708092271808d2fa4e8ba7f09da60ce5f3361d03 | [
"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 | 2,263 | hlean | /-
Copyright (c) 2014-2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn, Jakob von Raumer
-/
prelude
import init.num init.relation
open iff
-- Empty type
-- ----------
protected definition empty.has_decidable_eq [instance] : decidable_eq empty :=
take (a b : empty), decidable.inl (!empty.elim a)
-- Unit type
-- ---------
namespace unit
notation `⋆` := star
end unit
-- Sigma type
-- ----------
notation `Σ` binders `, ` r:(scoped P, sigma P) := r
abbreviation dpair [constructor] := @sigma.mk
namespace sigma
notation `⟨`:max t:(foldr `, ` (e r, mk e r)) `⟩`:0 := t --input ⟨ ⟩ as \< \>
namespace ops
postfix `.1`:(max+1) := pr1
postfix `.2`:(max+1) := pr2
abbreviation pr₁ := @pr1
abbreviation pr₂ := @pr2
end ops
end sigma
-- Sum type
-- --------
namespace sum
infixr + := sum
namespace low_precedence_plus
reserve infixr ` + `:25 -- conflicts with notation for addition
infixr ` + ` := sum
end low_precedence_plus
variables {a b c d : Type}
definition sum_of_sum_of_imp_of_imp (H₁ : a ⊎ b) (H₂ : a → c) (H₃ : b → d) : c ⊎ d :=
sum.rec_on H₁
(assume Ha : a, sum.inl (H₂ Ha))
(assume Hb : b, sum.inr (H₃ Hb))
definition sum_of_sum_of_imp_left (H₁ : a ⊎ c) (H : a → b) : b ⊎ c :=
sum.rec_on H₁
(assume H₂ : a, sum.inl (H H₂))
(assume H₂ : c, sum.inr H₂)
definition sum_of_sum_of_imp_right (H₁ : c ⊎ a) (H : a → b) : c ⊎ b :=
sum.rec_on H₁
(assume H₂ : c, sum.inl H₂)
(assume H₂ : a, sum.inr (H H₂))
end sum
-- Product type
-- ------------
namespace prod
-- notation for n-ary tuples
notation `(` h `, ` t:(foldl `,` (e r, prod.mk r e) h) `)` := t
namespace ops
postfix `.1`:(max+1) := pr1
postfix `.2`:(max+1) := pr2
abbreviation pr₁ := @pr1
abbreviation pr₂ := @pr2
end ops
namespace low_precedence_times
reserve infixr ` * `:30 -- conflicts with notation for multiplication
infixr ` * ` := prod
end low_precedence_times
open prod.ops
definition flip [unfold 3] {A B : Type} (a : A × B) : B × A := pair (pr2 a) (pr1 a)
end prod
|
632eaa875de715d2ca2bc64ad81548c480e72a42 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/keyword_tactics.lean | 0e3b549cfcf6a578b7de87d3a1e30372dee8ba49 | [
"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 | 641 | lean | example : ℕ → ℕ → ℕ :=
begin
assume n m,
apply n
end
example : ℕ → ℕ → ℕ :=
begin
assume (n m : ℕ),
apply n
end
example : ¬false :=
begin
assume contr,
apply contr
end
example : Π α : Type, α → α :=
begin
assume α,
assume a : α,
apply a
end
example : ℕ → ℕ → ℕ :=
begin
assume n m : bool,
apply n
end
example : ℕ → ℕ → ℕ :=
begin
have : _ → ℕ,
{ assume m : ℕ,
have: ℕ := m,
have: ℕ, from m,
have: ℕ, by apply m,
apply this },
{ assume n, apply this },
end
example (f : ℕ → ℕ) : bool :=
begin
have : ℕ, by apply f,
end
|
a8c5c88bf806f568a1df038faca961d8271aad98 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/field_theory/finite/polynomial.lean | 2728230cb2c792c375b76596b8451eacd7d7e767 | [
"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,552 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import field_theory.finite.basic
import field_theory.mv_polynomial
import data.mv_polynomial.expand
import linear_algebra.basic
import linear_algebra.finite_dimensional
/-!
## Polynomials over finite fields
-/
namespace mv_polynomial
variables {σ : Type*}
/-- A polynomial over the integers is divisible by `n : ℕ`
if and only if it is zero over `zmod n`. -/
lemma C_dvd_iff_zmod (n : ℕ) (φ : mv_polynomial σ ℤ) :
C (n:ℤ) ∣ φ ↔ map (int.cast_ring_hom (zmod n)) φ = 0 :=
C_dvd_iff_map_hom_eq_zero _ _ (char_p.int_cast_eq_zero_iff (zmod n) n) _
section frobenius
variables {p : ℕ} [fact p.prime]
lemma frobenius_zmod (f : mv_polynomial σ (zmod p)) :
frobenius _ p f = expand p f :=
begin
apply induction_on f,
{ intro a, rw [expand_C, frobenius_def, ← C_pow, zmod.pow_card], },
{ simp only [alg_hom.map_add, ring_hom.map_add], intros _ _ hf hg, rw [hf, hg] },
{ simp only [expand_X, ring_hom.map_mul, alg_hom.map_mul],
intros _ _ hf, rw [hf, frobenius_def], },
end
lemma expand_zmod (f : mv_polynomial σ (zmod p)) :
expand p f = f ^ p :=
(frobenius_zmod _).symm
end frobenius
end mv_polynomial
namespace mv_polynomial
noncomputable theory
open_locale big_operators classical
open set linear_map submodule
variables {K : Type*} {σ : Type*}
variables [field K] [fintype K] [fintype σ]
def indicator (a : σ → K) : mv_polynomial σ K :=
∏ n, (1 - (X n - C (a n))^(fintype.card K - 1))
lemma eval_indicator_apply_eq_one (a : σ → K) :
eval a (indicator a) = 1 :=
have 0 < fintype.card K - 1,
begin
rw [← fintype.card_units, fintype.card_pos_iff],
exact ⟨1⟩
end,
by { simp only [indicator, (eval a).map_prod, ring_hom.map_sub,
(eval a).map_one, (eval a).map_pow, eval_X, eval_C,
sub_self, zero_pow this, sub_zero, finset.prod_const_one] }
lemma eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) :
eval a (indicator b) = 0 :=
have ∃i, a i ≠ b i, by rwa [(≠), function.funext_iff, not_forall] at h,
begin
rcases this with ⟨i, hi⟩,
simp only [indicator, (eval a).map_prod, ring_hom.map_sub,
(eval a).map_one, (eval a).map_pow, eval_X, eval_C,
sub_self, finset.prod_eq_zero_iff],
refine ⟨i, finset.mem_univ _, _⟩,
rw [finite_field.pow_card_sub_one_eq_one, sub_self],
rwa [(≠), sub_eq_zero],
end
lemma degrees_indicator (c : σ → K) :
degrees (indicator c) ≤ ∑ s : σ, (fintype.card K - 1) • {s} :=
begin
rw [indicator],
refine le_trans (degrees_prod _ _) (finset.sum_le_sum $ assume s hs, _),
refine le_trans (degrees_sub _ _) _,
rw [degrees_one, ← bot_eq_zero, bot_sup_eq],
refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_of_le_right _ _),
refine le_trans (degrees_sub _ _) _,
rw [degrees_C, ← bot_eq_zero, sup_bot_eq],
exact degrees_X' _
end
lemma indicator_mem_restrict_degree (c : σ → K) :
indicator c ∈ restrict_degree σ K (fintype.card K - 1) :=
begin
rw [mem_restrict_degree_iff_sup, indicator],
assume n,
refine le_trans (multiset.count_le_of_le _ $ degrees_indicator _) (le_of_eq _),
simp_rw [ ← multiset.coe_count_add_monoid_hom, (multiset.count_add_monoid_hom n).map_sum,
add_monoid_hom.map_nsmul, multiset.coe_count_add_monoid_hom, nsmul_eq_mul, nat.cast_id],
transitivity,
refine finset.sum_eq_single n _ _,
{ assume b hb ne, rw [multiset.count_singleton, if_neg ne.symm, mul_zero] },
{ assume h, exact (h $ finset.mem_univ _).elim },
{ rw [multiset.count_singleton_self, mul_one] }
end
section
variables (K σ)
def evalₗ : mv_polynomial σ K →ₗ[K] (σ → K) → K :=
{ to_fun := λ p e, eval e p,
map_add' := λ p q, by { ext x, rw ring_hom.map_add, refl, },
map_smul' := λ a p, by { ext e, rw [smul_eq_C_mul, ring_hom.map_mul, eval_C], refl } }
end
lemma evalₗ_apply (p : mv_polynomial σ K) (e : σ → K) : evalₗ K σ p e = eval e p :=
rfl
lemma map_restrict_dom_evalₗ : (restrict_degree σ K (fintype.card K - 1)).map (evalₗ K σ) = ⊤ :=
begin
refine top_unique (set_like.le_def.2 $ assume e _, mem_map.2 _),
refine ⟨∑ n : σ → K, e n • indicator n, _, _⟩,
{ exact sum_mem _ (assume c _, smul_mem _ _ (indicator_mem_restrict_degree _)) },
{ ext n,
simp only [linear_map.map_sum, @finset.sum_apply (σ → K) (λ_, K) _ _ _ _ _,
pi.smul_apply, linear_map.map_smul],
simp only [evalₗ_apply],
transitivity,
refine finset.sum_eq_single n _ _,
{ assume b _ h,
rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero] },
{ assume h, exact (h $ finset.mem_univ n).elim },
{ rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one] } }
end
end mv_polynomial
namespace mv_polynomial
open_locale classical cardinal
open linear_map submodule
universe u
variables (σ : Type u) (K : Type u) [fintype σ] [field K] [fintype K]
@[derive [add_comm_group, module K, inhabited]]
def R : Type u := restrict_degree σ K (fintype.card K - 1)
noncomputable instance decidable_restrict_degree (m : ℕ) :
decidable_pred (∈ {n : σ →₀ ℕ | ∀i, n i ≤ m }) :=
by simp only [set.mem_set_of_eq]; apply_instance
lemma dim_R : module.rank K (R σ K) = fintype.card (σ → K) :=
calc module.rank K (R σ K) =
module.rank K (↥{s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card K - 1} →₀ K) :
linear_equiv.dim_eq
(finsupp.supported_equiv_finsupp {s : σ →₀ ℕ | ∀n:σ, s n ≤ fintype.card K - 1 })
... = #{s : σ →₀ ℕ | ∀ (n : σ), s n ≤ fintype.card K - 1} :
by rw [finsupp.dim_eq, dim_self, mul_one]
... = #{s : σ → ℕ | ∀ (n : σ), s n < fintype.card K } :
begin
refine quotient.sound ⟨equiv.subtype_equiv finsupp.equiv_fun_on_fintype $ assume f, _⟩,
refine forall_congr (assume n, le_tsub_iff_right _),
exact fintype.card_pos_iff.2 ⟨0⟩
end
... = #(σ → {n // n < fintype.card K}) :
(@equiv.subtype_pi_equiv_pi σ (λ_, ℕ) (λs n, n < fintype.card K)).cardinal_eq
... = #(σ → fin (fintype.card K)) :
(equiv.arrow_congr (equiv.refl σ) (equiv.fin_equiv_subtype _).symm).cardinal_eq
... = #(σ → K) :
(equiv.arrow_congr (equiv.refl σ) (fintype.equiv_fin K).symm).cardinal_eq
... = fintype.card (σ → K) : cardinal.mk_fintype _
instance : finite_dimensional K (R σ K) :=
is_noetherian.iff_fg.1 $ is_noetherian.iff_dim_lt_omega.mpr
(by simpa only [dim_R] using cardinal.nat_lt_omega (fintype.card (σ → K)))
lemma finrank_R : finite_dimensional.finrank K (R σ K) = fintype.card (σ → K) :=
finite_dimensional.finrank_eq_of_dim_eq (dim_R σ K)
def evalᵢ : R σ K →ₗ[K] (σ → K) → K :=
((evalₗ K σ).comp (restrict_degree σ K (fintype.card K - 1)).subtype)
lemma range_evalᵢ : (evalᵢ σ K).range = ⊤ :=
begin
rw [evalᵢ, linear_map.range_comp, range_subtype],
exact map_restrict_dom_evalₗ
end
lemma ker_evalₗ : (evalᵢ σ K).ker = ⊥ :=
begin
refine (ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank _).mpr (range_evalᵢ _ _),
rw [finite_dimensional.finrank_fintype_fun_eq_card, finrank_R]
end
lemma eq_zero_of_eval_eq_zero (p : mv_polynomial σ K)
(h : ∀v:σ → K, eval v p = 0) (hp : p ∈ restrict_degree σ K (fintype.card K - 1)) :
p = 0 :=
let p' : R σ K := ⟨p, hp⟩ in
have p' ∈ (evalᵢ σ K).ker := by { rw [mem_ker], ext v, exact h v },
show p'.1 = (0 : R σ K).1,
begin
rw [ker_evalₗ, mem_bot] at this,
rw [this]
end
end mv_polynomial
|
33741f121de5d2b9a66c2604b45cd2cb47284220 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/field_theory/minpoly.lean | 3a001cd5372969b2a8b202b4b9e883a62e64fffe | [
"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 | 17,608 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johan Commelin
-/
import data.polynomial.field_division
import ring_theory.integral_closure
import ring_theory.polynomial.gauss_lemma
/-!
# Minimal polynomials
This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,
under the assumption that x is integral over `A`.
After stating the defining property we specialize to the setting of field extensions
and derive some well-known properties, amongst which the fact that minimal polynomials
are irreducible, and uniquely determined by their defining property.
-/
open_locale classical
open polynomial set function
variables {A B : Type*}
section min_poly_def
variables (A) [comm_ring A] [ring B] [algebra A B]
/--
Suppose `x : B`, where `B` is an `A`-algebra.
The minimal polynomial `minpoly A x` of `x`
is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,
if such exists (`is_integral A x`) or zero otherwise.
For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then
the minimal polynomial of `f` is `minpoly 𝕜 f`.
-/
noncomputable def minpoly (x : B) : polynomial A :=
if hx : is_integral A x then well_founded.min degree_lt_wf _ hx else 0
end min_poly_def
namespace minpoly
section ring
variables [comm_ring A] [ring B] [algebra A B]
variables {x : B}
/-- A minimal polynomial is monic. -/
lemma monic (hx : is_integral A x) : monic (minpoly A x) :=
by { delta minpoly, rw dif_pos hx, exact (well_founded.min_mem degree_lt_wf _ hx).1 }
/-- A minimal polynomial is nonzero. -/
lemma ne_zero [nontrivial A] (hx : is_integral A x) : minpoly A x ≠ 0 :=
ne_zero_of_monic (monic hx)
lemma eq_zero (hx : ¬ is_integral A x) : minpoly A x = 0 :=
dif_neg hx
variables (A x)
/-- An element is a root of its minimal polynomial. -/
@[simp] lemma aeval : aeval x (minpoly A x) = 0 :=
begin
delta minpoly, split_ifs with hx,
{ exact (well_founded.min_mem degree_lt_wf _ hx).2 },
{ exact aeval_zero _ }
end
/-- A minimal polynomial is not `1`. -/
lemma ne_one [nontrivial B] : minpoly A x ≠ 1 :=
begin
intro h,
refine (one_ne_zero : (1 : B) ≠ 0) _,
simpa using congr_arg (polynomial.aeval x) h
end
lemma map_ne_one [nontrivial B] {R : Type*} [semiring R] [nontrivial R] (f : A →+* R) :
(minpoly A x).map f ≠ 1 :=
begin
by_cases hx : is_integral A x,
{ exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x) },
{ rw [eq_zero hx, polynomial.map_zero], exact zero_ne_one },
end
/-- A minimal polynomial is not a unit. -/
lemma not_is_unit [nontrivial B] : ¬ is_unit (minpoly A x) :=
begin
haveI : nontrivial A := (algebra_map A B).domain_nontrivial,
by_cases hx : is_integral A x,
{ exact mt (eq_one_of_is_unit_of_monic (monic hx)) (ne_one A x) },
{ rw [eq_zero hx], exact not_is_unit_zero }
end
lemma mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x ∈ (algebra_map A B).range :=
begin
have h : is_integral A x,
{ by_contra h,
rw [eq_zero h, degree_zero, ←with_bot.coe_one] at hx,
exact (ne_of_lt (show ⊥ < ↑1, from with_bot.bot_lt_coe 1) hx) },
have key := minpoly.aeval A x,
rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leading_coeff, C_1, one_mul, aeval_add,
aeval_C, aeval_X, ←eq_neg_iff_add_eq_zero, ←ring_hom.map_neg] at key,
exact ⟨-(minpoly A x).coeff 0, key.symm⟩,
end
/-- The defining property of the minimal polynomial of an element `x`:
it is the monic polynomial with smallest degree that has `x` as its root. -/
lemma min {p : polynomial A} (pmonic : p.monic) (hp : polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
begin
delta minpoly, split_ifs with hx,
{ exact le_of_not_lt (well_founded.not_lt_min degree_lt_wf _ hx ⟨pmonic, hp⟩) },
{ simp only [degree_zero, bot_le] }
end
end ring
section integral_domain
variables [comm_ring A]
section ring
variables [ring B] [algebra A B] [nontrivial B]
variables {x : B}
/-- The degree of a minimal polynomial, as a natural number, is positive. -/
lemma nat_degree_pos (hx : is_integral A x) : 0 < nat_degree (minpoly A x) :=
begin
rw pos_iff_ne_zero,
intro ndeg_eq_zero,
have eq_one : minpoly A x = 1,
{ rw eq_C_of_nat_degree_eq_zero ndeg_eq_zero, convert C_1,
simpa only [ndeg_eq_zero.symm] using (monic hx).leading_coeff },
simpa only [eq_one, alg_hom.map_one, one_ne_zero] using aeval A x
end
/-- The degree of a minimal polynomial is positive. -/
lemma degree_pos (hx : is_integral A x) : 0 < degree (minpoly A x) :=
nat_degree_pos_iff_degree_pos.mp (nat_degree_pos hx)
/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,
then the minimal polynomial of `algebra_map A B a` is `X - C a`. -/
lemma eq_X_sub_C_of_algebra_map_inj [nontrivial A]
(a : A) (hf : function.injective (algebra_map A B)) :
minpoly A (algebra_map A B a) = X - C a :=
begin
have hdegle : (minpoly A (algebra_map A B a)).nat_degree ≤ 1,
{ apply with_bot.coe_le_coe.1,
rw [←degree_eq_nat_degree (ne_zero (@is_integral_algebra_map A B _ _ _ a)),
with_top.coe_one, ←degree_X_sub_C a],
refine min A (algebra_map A B a) (monic_X_sub_C a) _,
simp only [aeval_C, aeval_X, alg_hom.map_sub, sub_self] },
have hdeg : (minpoly A (algebra_map A B a)).degree = 1,
{ apply (degree_eq_iff_nat_degree_eq (ne_zero (@is_integral_algebra_map A B _ _ _ a))).2,
apply le_antisymm hdegle (nat_degree_pos (@is_integral_algebra_map A B _ _ _ a)) },
have hrw := eq_X_add_C_of_degree_eq_one hdeg,
simp only [monic (@is_integral_algebra_map A B _ _ _ a), one_mul,
monic.leading_coeff, ring_hom.map_one] at hrw,
have h0 : (minpoly A (algebra_map A B a)).coeff 0 = -a,
{ have hroot := aeval A (algebra_map A B a),
rw [hrw, add_comm] at hroot,
simp only [aeval_C, aeval_X, aeval_add] at hroot,
replace hroot := eq_neg_of_add_eq_zero hroot,
rw [←ring_hom.map_neg _ a] at hroot,
exact (hf hroot) },
rw hrw,
simp only [h0, ring_hom.map_neg, sub_eq_add_neg],
end
end ring
section domain
variables [integral_domain A] [ring B] [algebra A B]
variables {x : B}
/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/
lemma aeval_ne_zero_of_dvd_not_unit_minpoly {a : polynomial A} (hx : is_integral A x)
(hamonic : a.monic) (hdvd : dvd_not_unit a (minpoly A x)) :
polynomial.aeval x a ≠ 0 :=
begin
intro ha,
refine not_lt_of_ge (minpoly.min A x hamonic ha) _,
obtain ⟨hzeroa, b, hb_nunit, prod⟩ := hdvd,
have hbmonic : b.monic,
{ rw monic.def,
have := monic hx,
rwa [monic.def, prod, leading_coeff_mul, monic.def.mp hamonic, one_mul] at this },
have hzerob : b ≠ 0 := hbmonic.ne_zero,
have degbzero : 0 < b.nat_degree,
{ apply nat.pos_of_ne_zero,
intro h,
have h₁ := eq_C_of_nat_degree_eq_zero h,
rw [←h, ←leading_coeff, monic.def.1 hbmonic, C_1] at h₁,
rw h₁ at hb_nunit,
have := is_unit_one,
contradiction },
rw [prod, degree_mul, degree_eq_nat_degree hzeroa, degree_eq_nat_degree hzerob],
exact_mod_cast lt_add_of_pos_right _ degbzero,
end
variables [domain B]
/-- A minimal polynomial is irreducible. -/
lemma irreducible (hx : is_integral A x) : irreducible (minpoly A x) :=
begin
cases irreducible_or_factor (minpoly A x) (not_is_unit A x) with hirr hred,
{ exact hirr },
exfalso,
obtain ⟨a, b, ha_nunit, hb_nunit, hab_eq⟩ := hred,
have coeff_prod : a.leading_coeff * b.leading_coeff = 1,
{ rw [←monic.def.1 (monic hx), ←hab_eq],
simp only [leading_coeff_mul] },
have hamonic : (a * C b.leading_coeff).monic,
{ rw monic.def,
simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },
have hbmonic : (b * C a.leading_coeff).monic,
{ rw [monic.def, mul_comm],
simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },
have prod : minpoly A x = (a * C b.leading_coeff) * (b * C a.leading_coeff),
{ symmetry,
calc a * C b.leading_coeff * (b * C a.leading_coeff)
= a * b * (C a.leading_coeff * C b.leading_coeff) : by ring
... = a * b * (C (a.leading_coeff * b.leading_coeff)) : by simp only [ring_hom.map_mul]
... = a * b : by rw [coeff_prod, C_1, mul_one]
... = minpoly A x : hab_eq },
have hzero := aeval A x,
rw [prod, aeval_mul, mul_eq_zero] at hzero,
cases hzero,
{ refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hamonic _ hzero,
exact ⟨hamonic.ne_zero, _, mt is_unit_of_mul_is_unit_left hb_nunit, prod⟩ },
{ refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hbmonic _ hzero,
rw mul_comm at prod,
exact ⟨hbmonic.ne_zero, _, mt is_unit_of_mul_is_unit_left ha_nunit, prod⟩ },
end
end domain
end integral_domain
section field
variables [field A]
section ring
variables [ring B] [algebra A B]
variables {x : B}
variables (A x)
/-- If an element `x` is a root of a nonzero polynomial `p`,
then the degree of `p` is at least the degree of the minimal polynomial of `x`. -/
lemma degree_le_of_ne_zero
{p : polynomial A} (pnz : p ≠ 0) (hp : polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
calc degree (minpoly A x) ≤ degree (p * C (leading_coeff p)⁻¹) :
min A x (monic_mul_leading_coeff_inv pnz) (by simp [hp])
... = degree p : degree_mul_leading_coeff_inv p pnz
/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:
if there is another monic polynomial of minimal degree that has `x` as a root,
then this polynomial is equal to the minimal polynomial of `x`. -/
lemma unique {p : polynomial A}
(pmonic : p.monic) (hp : polynomial.aeval x p = 0)
(pmin : ∀ q : polynomial A, q.monic → polynomial.aeval x q = 0 → degree p ≤ degree q) :
p = minpoly A x :=
begin
have hx : is_integral A x := ⟨p, pmonic, hp⟩,
symmetry, apply eq_of_sub_eq_zero,
by_contra hnz,
have := degree_le_of_ne_zero A x hnz (by simp [hp]),
contrapose! this,
apply degree_sub_lt _ (ne_zero hx),
{ rw [(monic hx).leading_coeff, pmonic.leading_coeff] },
{ exact le_antisymm (min A x pmonic hp)
(pmin (minpoly A x) (monic hx) (aeval A x)) }
end
/-- If an element `x` is a root of a polynomial `p`,
then the minimal polynomial of `x` divides `p`. -/
lemma dvd {p : polynomial A} (hp : polynomial.aeval x p = 0) : minpoly A x ∣ p :=
begin
by_cases hp0 : p = 0,
{ simp only [hp0, dvd_zero] },
have hx : is_integral A x,
{ rw ← is_algebraic_iff_is_integral, exact ⟨p, hp0, hp⟩ },
rw ← dvd_iff_mod_by_monic_eq_zero (monic hx),
by_contra hnz,
have := degree_le_of_ne_zero A x hnz _,
{ contrapose! this,
exact degree_mod_by_monic_lt _ (monic hx) },
{ rw ← mod_by_monic_add_div p (monic hx) at hp,
simpa using hp }
end
lemma dvd_map_of_is_scalar_tower (A K : Type*) {R : Type*} [comm_ring A] [field K] [comm_ring R]
[algebra A K] [algebra A R] [algebra K R] [is_scalar_tower A K R] (x : R) :
minpoly K x ∣ (minpoly A x).map (algebra_map A K) :=
by { refine minpoly.dvd K x _, rw [← is_scalar_tower.aeval_apply, minpoly.aeval] }
/-- If `y` is a conjugate of `x` over a field `K`, then it is a conjugate over a subring `R`. -/
lemma aeval_of_is_scalar_tower (R : Type*) {K T U : Type*} [comm_ring R] [field K] [comm_ring T]
[algebra R K] [algebra K T] [algebra R T] [is_scalar_tower R K T]
[comm_semiring U] [algebra K U] [algebra R U] [is_scalar_tower R K U]
(x : T) (y : U)
(hy : polynomial.aeval y (minpoly K x) = 0) : polynomial.aeval y (minpoly R x) = 0 :=
by { rw is_scalar_tower.aeval_apply R K,
exact eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (algebra_map K U) y
(minpoly.dvd_map_of_is_scalar_tower R K x) hy }
variables {A x}
theorem unique' [nontrivial B] {p : polynomial A} (hp1 : _root_.irreducible p)
(hp2 : polynomial.aeval x p = 0) (hp3 : p.monic) : p = minpoly A x :=
let ⟨q, hq⟩ := dvd A x hp2 in
eq_of_monic_of_associated hp3 (monic ⟨p, ⟨hp3, hp2⟩⟩) $
mul_one (minpoly A x) ▸ hq.symm ▸ associated.mul_left _ $
associated_one_iff_is_unit.2 $ (hp1.is_unit_or_is_unit hq).resolve_left $ not_is_unit A x
lemma unique'' [nontrivial B] {p : polynomial A}
(hp1 : _root_.irreducible p) (hp2 : polynomial.aeval x p = 0) :
p * C p.leading_coeff⁻¹ = minpoly A x :=
begin
have : p.leading_coeff ≠ 0 := leading_coeff_ne_zero.mpr hp1.ne_zero,
apply unique',
{ exact associated.irreducible ⟨⟨C p.leading_coeff⁻¹, C p.leading_coeff,
by rwa [←C_mul, inv_mul_cancel, C_1], by rwa [←C_mul, mul_inv_cancel, C_1]⟩, rfl⟩ hp1 },
{ rw [aeval_mul, hp2, zero_mul] },
{ rwa [polynomial.monic, leading_coeff_mul, leading_coeff_C, mul_inv_cancel] },
end
/-- If `y` is the image of `x` in an extension, their minimal polynomials coincide.
We take `h : y = algebra_map L T x` as an argument because `rw h` typically fails
since `is_integral R y` depends on y.
-/
lemma eq_of_algebra_map_eq {K S T : Type*} [field K] [comm_ring S] [comm_ring T]
[algebra K S] [algebra K T] [algebra S T]
[is_scalar_tower K S T] (hST : function.injective (algebra_map S T))
{x : S} {y : T} (hx : is_integral K x) (h : y = algebra_map S T x) :
minpoly K x = minpoly K y :=
minpoly.unique _ _ (minpoly.monic hx)
(by rw [h, ← is_scalar_tower.algebra_map_aeval, minpoly.aeval, ring_hom.map_zero])
(λ q q_monic root_q, minpoly.min _ _ q_monic
(is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero K S T hST
(h ▸ root_q : polynomial.aeval (algebra_map S T x) q = 0)))
section gcd_domain
/-- For GCD domains, the minimal polynomial over the ring is the same as the minimal polynomial
over the fraction field. -/
lemma gcd_domain_eq_field_fractions {A R : Type*} (K : Type*) [comm_ring A] [integral_domain A]
[normalized_gcd_monoid A] [field K]
[comm_ring R] [integral_domain R] [algebra A K] [is_fraction_ring A K]
[algebra K R] [algebra A R] [is_scalar_tower A K R] {x : R} (hx : is_integral A x) :
minpoly K x = (minpoly A x).map (algebra_map A K) :=
begin
symmetry,
refine unique' _ _ _,
{ exact (polynomial.is_primitive.irreducible_iff_irreducible_map_fraction_map
(polynomial.monic.is_primitive (monic hx))).1 (irreducible hx) },
{ have htower := is_scalar_tower.aeval_apply A K R x (minpoly A x),
rwa [aeval, eq_comm] at htower },
{ exact monic_map _ (monic hx) }
end
/-- For GCD domains, the minimal polynomial divides any primitive polynomial that has the integral
element as root. -/
lemma gcd_domain_dvd {A R : Type*} (K : Type*)
[comm_ring A] [integral_domain A] [normalized_gcd_monoid A] [field K]
[comm_ring R] [integral_domain R] [algebra A K]
[is_fraction_ring A K] [algebra K R] [algebra A R] [is_scalar_tower A K R]
{x : R} (hx : is_integral A x)
{P : polynomial A} (hprim : is_primitive P) (hroot : polynomial.aeval x P = 0) :
minpoly A x ∣ P :=
begin
apply (is_primitive.dvd_iff_fraction_map_dvd_fraction_map K
(monic.is_primitive (monic hx)) hprim).2,
rw ← gcd_domain_eq_field_fractions K hx,
refine dvd _ _ _,
rwa ← is_scalar_tower.aeval_apply
end
end gcd_domain
variables (B) [nontrivial B]
/-- If `B/K` is a nontrivial algebra over a field, and `x` is an element of `K`,
then the minimal polynomial of `algebra_map K B x` is `X - C x`. -/
lemma eq_X_sub_C (a : A) : minpoly A (algebra_map A B a) = X - C a :=
eq_X_sub_C_of_algebra_map_inj a (algebra_map A B).injective
lemma eq_X_sub_C' (a : A) : minpoly A a = X - C a := eq_X_sub_C A a
variables (A)
/-- The minimal polynomial of `0` is `X`. -/
@[simp] lemma zero : minpoly A (0:B) = X :=
by simpa only [add_zero, C_0, sub_eq_add_neg, neg_zero, ring_hom.map_zero]
using eq_X_sub_C B (0:A)
/-- The minimal polynomial of `1` is `X - 1`. -/
@[simp] lemma one : minpoly A (1:B) = X - 1 :=
by simpa only [ring_hom.map_one, C_1, sub_eq_add_neg] using eq_X_sub_C B (1:A)
end ring
section domain
variables [ring B] [domain B] [algebra A B]
variables {x : B}
/-- A minimal polynomial is prime. -/
lemma prime (hx : is_integral A x) : prime (minpoly A x) :=
begin
refine ⟨ne_zero hx, not_is_unit A x, _⟩,
rintros p q ⟨d, h⟩,
have : polynomial.aeval x (p*q) = 0 := by simp [h, aeval A x],
replace : polynomial.aeval x p = 0 ∨ polynomial.aeval x q = 0 := by simpa,
exact or.imp (dvd A x) (dvd A x) this
end
/-- If `L/K` is a field extension and an element `y` of `K` is a root of the minimal polynomial
of an element `x ∈ L`, then `y` maps to `x` under the field embedding. -/
lemma root {x : B} (hx : is_integral A x) {y : A} (h : is_root (minpoly A x) y) :
algebra_map A B y = x :=
have key : minpoly A x = X - C y :=
eq_of_monic_of_associated (monic hx) (monic_X_sub_C y) (associated_of_dvd_dvd
((irreducible_X_sub_C y).dvd_symm (irreducible hx) (dvd_iff_is_root.2 h))
(dvd_iff_is_root.2 h)),
by { have := aeval A x, rwa [key, alg_hom.map_sub, aeval_X, aeval_C, sub_eq_zero, eq_comm] at this }
/-- The constant coefficient of the minimal polynomial of `x` is `0` if and only if `x = 0`. -/
@[simp] lemma coeff_zero_eq_zero (hx : is_integral A x) : coeff (minpoly A x) 0 = 0 ↔ x = 0 :=
begin
split,
{ intro h,
have zero_root := zero_is_root_of_coeff_zero_eq_zero h,
rw ← root hx zero_root,
exact ring_hom.map_zero _ },
{ rintro rfl, simp }
end
/-- The minimal polynomial of a nonzero element has nonzero constant coefficient. -/
lemma coeff_zero_ne_zero (hx : is_integral A x) (h : x ≠ 0) : coeff (minpoly A x) 0 ≠ 0 :=
by { contrapose! h, simpa only [hx, coeff_zero_eq_zero] using h }
end domain
end field
end minpoly
|
12f9b01770f2fe516848dd392b823ad33cab92fd | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /library/standard/piext.lean | a8f4411a61e6ce02c75b6dae617501b08b7e414a | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,295 | lean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
import logic cast
-- Pi extensionality
axiom piext {A : Type} {B B' : A → Type} {H : inhabited (Π x, B x)} : (Π x, B x) = (Π x, B' x) → B = B'
theorem cast_app {A : Type} {B B' : A → Type} (H : (Π x, B x) = (Π x, B' x)) (f : Π x, B x) (a : A) : cast H f a == f a
:= have Hi [fact] : inhabited (Π x, B x), from inhabited_intro f,
have Hb : B = B', from piext H,
cast_app' Hb f a
theorem hcongr1 {A : Type} {B B' : A → Type} {f : Π x, B x} {f' : Π x, B' x} (a : A) (H : f == f') : f a == f' a
:= have Hi [fact] : inhabited (Π x, B x), from inhabited_intro f,
have Hb : B = B', from piext (type_eq H),
hcongr1' a H Hb
theorem hcongr {A A' : Type} {B : A → Type} {B' : A' → Type} {f : Π x, B x} {f' : Π x, B' x} {a : A} {a' : A'}
(Hff' : f == f') (Haa' : a == a') : f a == f' a'
:= have H1 : ∀ (B B' : A → Type) (f : Π x, B x) (f' : Π x, B' x), f == f' → f a == f' a, from
take B B' f f' e, hcongr1 a e,
have H2 : ∀ (B : A → Type) (B' : A' → Type) (f : Π x, B x) (f' : Π x, B' x), f == f' → f a == f' a', from
hsubst Haa' H1,
H2 B B' f f' Hff'
|
dd32874302f845f181b3017a3bd09f1ba7b07913 | 4fa161becb8ce7378a709f5992a594764699e268 | /src/topology/metric_space/completion.lean | e5dae51338c9ba4d2d9abc3fb4e978a7fd2486f4 | [
"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 | 8,709 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sébastien Gouëzel
-/
import topology.uniform_space.completion
import topology.metric_space.isometry
/-!
# The completion of a metric space
Completion of uniform spaces are already defined in `topology.uniform_space.completion`. We show
here that the uniform space completion of a metric space inherits a metric space structure,
by extending the distance to the completion and checking that it is indeed a distance, and that
it defines the same uniformity as the already defined uniform structure on the completion
-/
open set filter uniform_space uniform_space.completion
noncomputable theory
universes u
variables {α : Type u} [metric_space α]
namespace metric
/-- The distance on the completion is obtained by extending the distance on the original space,
by uniform continuity. -/
instance : has_dist (completion α) :=
⟨completion.extension₂ dist⟩
/-- The new distance is uniformly continuous. -/
protected lemma completion.uniform_continuous_dist :
uniform_continuous (λp:completion α × completion α, dist p.1 p.2) :=
uniform_continuous_extension₂ dist
/-- The new distance is an extension of the original distance. -/
protected lemma completion.dist_eq (x y : α) : dist (x : completion α) y = dist x y :=
completion.extension₂_coe_coe uniform_continuous_dist' _ _
/- Let us check that the new distance satisfies the axioms of a distance, by starting from the
properties on α and extending them to `completion α` by continuity. -/
protected lemma completion.dist_self (x : completion α) : dist x x = 0 :=
begin
apply induction_on x,
{ refine is_closed_eq _ continuous_const,
exact (completion.uniform_continuous_dist.continuous.comp
(continuous.prod_mk continuous_id continuous_id) : _) },
{ assume a,
rw [completion.dist_eq, dist_self] }
end
protected lemma completion.dist_comm (x y : completion α) : dist x y = dist y x :=
begin
apply induction_on₂ x y,
{ refine is_closed_eq completion.uniform_continuous_dist.continuous _,
exact (completion.uniform_continuous_dist.continuous.comp continuous_swap : _) },
{ assume a b,
rw [completion.dist_eq, completion.dist_eq, dist_comm] }
end
protected lemma completion.dist_triangle (x y z : completion α) : dist x z ≤ dist x y + dist y z :=
begin
apply induction_on₃ x y z,
{ refine is_closed_le _ (continuous.add _ _),
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.2)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_snd),
exact (completion.uniform_continuous_dist.continuous.comp this : _) },
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.1)) :=
continuous.prod_mk continuous_fst (continuous_fst.comp continuous_snd),
exact (completion.uniform_continuous_dist.continuous.comp this : _) },
{ have : continuous (λp : completion α × completion α × completion α, (p.2.1, p.2.2)) :=
continuous.prod_mk (continuous_fst.comp continuous_snd)
(continuous.comp continuous_snd continuous_snd),
exact (continuous.comp completion.uniform_continuous_dist.continuous this : _) } },
{ assume a b c,
rw [completion.dist_eq, completion.dist_eq, completion.dist_eq],
exact dist_triangle a b c }
end
/-- Elements of the uniformity (defined generally for completions) can be characterized in terms
of the distance. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma completion.mem_uniformity_dist (s : set (completion α × completion α)) :
s ∈ uniformity (completion α) ↔ (∃ε>0, ∀{a b}, dist a b < ε → (a, b) ∈ s) :=
begin
split,
{ /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in α is an
entourage, so it contains an ε-neighborhood of the diagonal by definition of the entourages
in metric spaces. Then `t` contains an ε-neighborhood of the diagonal in `completion α`, as
closed properties pass to the completion. -/
assume hs,
rcases mem_uniformity_is_closed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩,
have A : {x : α × α | (coe (x.1), coe (x.2)) ∈ t} ∈ uniformity α :=
uniform_continuous_def.1 (uniform_continuous_coe α) t ht,
rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩,
refine ⟨ε, εpos, λx y hxy, _⟩,
have : ε ≤ dist x y ∨ (x, y) ∈ t,
{ apply induction_on₂ x y,
{ have : {x : completion α × completion α | ε ≤ dist (x.fst) (x.snd) ∨ (x.fst, x.snd) ∈ t}
= {p : completion α × completion α | ε ≤ dist p.1 p.2} ∪ t, by ext; simp,
rw this,
apply is_closed_union _ tclosed,
exact is_closed_le continuous_const completion.uniform_continuous_dist.continuous },
{ assume x y,
rw completion.dist_eq,
by_cases h : ε ≤ dist x y,
{ exact or.inl h },
{ have Z := hε (not_le.1 h),
simp only [set.mem_set_of_eq] at Z,
exact or.inr Z }}},
simp only [not_le.mpr hxy, false_or, not_le] at this,
exact ts this },
{ /- Start from a set `s` containing an ε-neighborhood of the diagonal in `completion α`. To show
that it is an entourage, we use the fact that `dist` is uniformly continuous on
`completion α × completion α` (this is a general property of the extension of uniformly
continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ
is an entourage in `completion α × completion α`. Massaging this property, it follows that
the ε-neighborhood of the diagonal is an entourage in `completion α`, and therefore this is
also the case of `s`. -/
rintros ⟨ε, εpos, hε⟩,
let r : set (ℝ × ℝ) := {p | dist p.1 p.2 < ε},
have : r ∈ uniformity ℝ := metric.dist_mem_uniformity εpos,
have T := uniform_continuous_def.1 (@completion.uniform_continuous_dist α _) r this,
simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop,
filter.mem_map, set.mem_set_of_eq] at T,
rcases T with ⟨t1, ht1, t2, ht2, ht⟩,
refine mem_sets_of_superset ht1 _,
have A : ∀a b : completion α, (a, b) ∈ t1 → dist a b < ε,
{ assume a b hab,
have : ((a, b), (a, a)) ∈ set.prod t1 t2 := ⟨hab, refl_mem_uniformity ht2⟩,
have I := ht this,
simp [completion.dist_self, real.dist_eq, completion.dist_comm] at I,
exact lt_of_le_of_lt (le_abs_self _) I },
show t1 ⊆ s,
{ rintros ⟨a, b⟩ hp,
have : dist a b < ε := A a b hp,
exact hε this }}
end
/-- If two points are at distance 0, then they coincide. -/
protected lemma completion.eq_of_dist_eq_zero (x y : completion α) (h : dist x y = 0) : x = y :=
begin
/- This follows from the separation of `completion α` and from the description of
entourages in terms of the distance. -/
have : separated (completion α) := by apply_instance,
refine separated_def.1 this x y (λs hs, _),
rcases (completion.mem_uniformity_dist s).1 hs with ⟨ε, εpos, hε⟩,
rw ← h at εpos,
exact hε εpos
end
/- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition
of the metric space structure. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma completion.uniformity_dist' :
uniformity (completion α) = (⨅ε:{ε:ℝ // ε>0}, principal {p | dist p.1 p.2 < ε.val}) :=
begin
ext s, rw mem_infi,
{ simp [completion.mem_uniformity_dist, subset_def] },
{ rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩,
simp [lt_min_iff, (≥)] {contextual := tt} },
{ exact ⟨⟨1, zero_lt_one⟩⟩ }
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
protected lemma completion.uniformity_dist :
uniformity (completion α) = (⨅ ε>0, principal {p | dist p.1 p.2 < ε}) :=
by simpa [infi_subtype] using @completion.uniformity_dist' α _
/-- Metric space structure on the completion of a metric space. -/
instance completion.metric_space : metric_space (completion α) :=
{ dist_self := completion.dist_self,
eq_of_dist_eq_zero := completion.eq_of_dist_eq_zero,
dist_comm := completion.dist_comm,
dist_triangle := completion.dist_triangle,
to_uniform_space := by apply_instance,
uniformity_dist := completion.uniformity_dist }
/-- The embedding of a metric space in its completion is an isometry. -/
lemma completion.coe_isometry : isometry (coe : α → completion α) :=
isometry_emetric_iff_metric.2 completion.dist_eq
end metric
|
b55939c758d1e9e22fde8679b69c8f669e12e1cb | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/continuous_function/compact.lean | fbf02f9ec680bfd17717e8fd08f01362f8ee017f | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 18,928 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.continuous_function.bounded
import topology.uniform_space.compact
import topology.compact_open
import topology.sets.compacts
/-!
# Continuous functions on a compact space
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Continuous functions `C(α, β)` from a compact space `α` to a metric space `β`
are automatically bounded, and so acquire various structures inherited from `α →ᵇ β`.
This file transfers these structures, and restates some lemmas
characterising these structures.
If you need a lemma which is proved about `α →ᵇ β` but not for `C(α, β)` when `α` is compact,
you should restate it here. You can also use
`bounded_continuous_function.equiv_continuous_map_of_compact` to move functions back and forth.
-/
noncomputable theory
open_locale topology classical nnreal bounded_continuous_function big_operators
open set filter metric
open bounded_continuous_function
namespace continuous_map
variables {α β E : Type*} [topological_space α] [compact_space α] [metric_space β]
[normed_add_comm_group E]
section
variables (α β)
/--
When `α` is compact, the bounded continuous maps `α →ᵇ β` are
equivalent to `C(α, β)`.
-/
@[simps { fully_applied := ff }]
def equiv_bounded_of_compact : C(α, β) ≃ (α →ᵇ β) :=
⟨mk_of_compact, bounded_continuous_function.to_continuous_map,
λ f, by { ext, refl, }, λ f, by { ext, refl, }⟩
lemma uniform_inducing_equiv_bounded_of_compact :
uniform_inducing (equiv_bounded_of_compact α β) :=
uniform_inducing.mk'
begin
simp only [has_basis_compact_convergence_uniformity.mem_iff, uniformity_basis_dist_le.mem_iff],
exact λ s, ⟨λ ⟨⟨a, b⟩, ⟨ha, ⟨ε, hε, hb⟩⟩, hs⟩, ⟨{p | ∀ x, (p.1 x, p.2 x) ∈ b},
⟨ε, hε, λ _ h x, hb (by exact (dist_le hε.le).mp h x)⟩, λ f g h, hs (by exact λ x hx, h x)⟩,
λ ⟨t, ⟨ε, hε, ht⟩, hs⟩, ⟨⟨set.univ, {p | dist p.1 p.2 ≤ ε}⟩,
⟨is_compact_univ, ⟨ε, hε, λ _ h, h⟩⟩,
λ ⟨f, g⟩ h, hs _ _ (ht (by exact (dist_le hε.le).mpr (λ x, h x (mem_univ x))))⟩⟩,
end
lemma uniform_embedding_equiv_bounded_of_compact :
uniform_embedding (equiv_bounded_of_compact α β) :=
{ inj := (equiv_bounded_of_compact α β).injective,
.. uniform_inducing_equiv_bounded_of_compact α β }
/--
When `α` is compact, the bounded continuous maps `α →ᵇ 𝕜` are
additively equivalent to `C(α, 𝕜)`.
-/
@[simps apply symm_apply { fully_applied := ff }]
def add_equiv_bounded_of_compact [add_monoid β] [has_lipschitz_add β] :
C(α, β) ≃+ (α →ᵇ β) :=
({ .. to_continuous_map_add_hom α β,
.. (equiv_bounded_of_compact α β).symm, } : (α →ᵇ β) ≃+ C(α, β)).symm
instance : metric_space C(α, β) :=
(uniform_embedding_equiv_bounded_of_compact α β).comap_metric_space _
/--
When `α` is compact, and `β` is a metric space, the bounded continuous maps `α →ᵇ β` are
isometric to `C(α, β)`.
-/
@[simps to_equiv apply symm_apply { fully_applied := ff }]
def isometry_equiv_bounded_of_compact :
C(α, β) ≃ᵢ (α →ᵇ β) :=
{ isometry_to_fun := λ x y, rfl,
to_equiv := equiv_bounded_of_compact α β }
end
@[simp] lemma _root_.bounded_continuous_function.dist_mk_of_compact (f g : C(α, β)) :
dist (mk_of_compact f) (mk_of_compact g) = dist f g := rfl
@[simp] lemma _root_.bounded_continuous_function.dist_to_continuous_map (f g : α →ᵇ β) :
dist (f.to_continuous_map) (g.to_continuous_map) = dist f g := rfl
open bounded_continuous_function
section
variables {α β} {f g : C(α, β)} {C : ℝ}
/-- The pointwise distance is controlled by the distance between functions, by definition. -/
lemma dist_apply_le_dist (x : α) : dist (f x) (g x) ≤ dist f g :=
by simp only [← dist_mk_of_compact, dist_coe_le_dist, ← mk_of_compact_apply]
/-- The distance between two functions is controlled by the supremum of the pointwise distances -/
lemma dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀x:α, dist (f x) (g x) ≤ C :=
by simp only [← dist_mk_of_compact, dist_le C0, mk_of_compact_apply]
lemma dist_le_iff_of_nonempty [nonempty α] :
dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C :=
by simp only [← dist_mk_of_compact, dist_le_iff_of_nonempty, mk_of_compact_apply]
lemma dist_lt_iff_of_nonempty [nonempty α] :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
by simp only [← dist_mk_of_compact, dist_lt_iff_of_nonempty_compact, mk_of_compact_apply]
lemma dist_lt_of_nonempty [nonempty α] (w : ∀x:α, dist (f x) (g x) < C) : dist f g < C :=
(dist_lt_iff_of_nonempty).2 w
lemma dist_lt_iff (C0 : (0 : ℝ) < C) :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
by simp only [← dist_mk_of_compact, dist_lt_iff_of_compact C0, mk_of_compact_apply]
end
instance [complete_space β] : complete_space (C(α, β)) :=
(isometry_equiv_bounded_of_compact α β).complete_space
/-- See also `continuous_map.continuous_eval'` -/
@[continuity] lemma continuous_eval : continuous (λ p : C(α, β) × α, p.1 p.2) :=
continuous_eval.comp ((isometry_equiv_bounded_of_compact α β).continuous.prod_map continuous_id)
/-- See also `continuous_map.continuous_eval_const` -/
@[continuity] lemma continuous_eval_const (x : α) : continuous (λ f : C(α, β), f x) :=
continuous_eval.comp (continuous_id.prod_mk continuous_const)
/-- See also `continuous_map.continuous_coe'` -/
lemma continuous_coe : @continuous (C(α, β)) (α → β) _ _ coe_fn :=
continuous_pi continuous_eval_const
-- TODO at some point we will need lemmas characterising this norm!
-- At the moment the only way to reason about it is to transfer `f : C(α,E)` back to `α →ᵇ E`.
instance : has_norm C(α, E) :=
{ norm := λ x, dist x 0 }
@[simp] lemma _root_.bounded_continuous_function.norm_mk_of_compact (f : C(α, E)) :
‖mk_of_compact f‖ = ‖f‖ := rfl
@[simp] lemma _root_.bounded_continuous_function.norm_to_continuous_map_eq (f : α →ᵇ E) :
‖f.to_continuous_map‖ = ‖f‖ :=
rfl
open bounded_continuous_function
instance : normed_add_comm_group C(α, E) :=
{ dist_eq := λ x y, by
rw [← norm_mk_of_compact, ← dist_mk_of_compact, dist_eq_norm, mk_of_compact_sub],
dist := dist, norm := norm, .. continuous_map.metric_space _ _, .. continuous_map.add_comm_group }
instance [nonempty α] [has_one E] [norm_one_class E] : norm_one_class C(α, E) :=
{ norm_one := by simp only [←norm_mk_of_compact, mk_of_compact_one, norm_one] }
section
variables (f : C(α, E))
-- The corresponding lemmas for `bounded_continuous_function` are stated with `{f}`,
-- and so can not be used in dot notation.
lemma norm_coe_le_norm (x : α) : ‖f x‖ ≤ ‖f‖ :=
(mk_of_compact f).norm_coe_le_norm x
/-- Distance between the images of any two points is at most twice the norm of the function. -/
lemma dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ‖f‖ :=
(mk_of_compact f).dist_le_two_norm x y
/-- The norm of a function is controlled by the supremum of the pointwise norms -/
lemma norm_le {C : ℝ} (C0 : (0 : ℝ) ≤ C) : ‖f‖ ≤ C ↔ ∀x:α, ‖f x‖ ≤ C :=
@bounded_continuous_function.norm_le _ _ _ _
(mk_of_compact f) _ C0
lemma norm_le_of_nonempty [nonempty α] {M : ℝ} : ‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M :=
@bounded_continuous_function.norm_le_of_nonempty _ _ _ _ _ (mk_of_compact f) _
lemma norm_lt_iff {M : ℝ} (M0 : 0 < M) : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
@bounded_continuous_function.norm_lt_iff_of_compact _ _ _ _ _ (mk_of_compact f) _ M0
theorem nnnorm_lt_iff {M : ℝ≥0} (M0 : 0 < M) : ‖f‖₊ < M ↔ ∀ (x : α), ‖f x‖₊ < M :=
f.norm_lt_iff M0
lemma norm_lt_iff_of_nonempty [nonempty α] {M : ℝ} :
‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
@bounded_continuous_function.norm_lt_iff_of_nonempty_compact _ _ _ _ _ _ (mk_of_compact f) _
lemma nnnorm_lt_iff_of_nonempty [nonempty α] {M : ℝ≥0} :
‖f‖₊ < M ↔ ∀ x, ‖f x‖₊ < M :=
f.norm_lt_iff_of_nonempty
lemma apply_le_norm (f : C(α, ℝ)) (x : α) : f x ≤ ‖f‖ :=
le_trans (le_abs.mpr (or.inl (le_refl (f x)))) (f.norm_coe_le_norm x)
lemma neg_norm_le_apply (f : C(α, ℝ)) (x : α) : -‖f‖ ≤ f x :=
le_trans (neg_le_neg (f.norm_coe_le_norm x)) (neg_le.mp (neg_le_abs_self (f x)))
lemma norm_eq_supr_norm : ‖f‖ = ⨆ x : α, ‖f x‖ :=
(mk_of_compact f).norm_eq_supr_norm
lemma norm_restrict_mono_set {X : Type*} [topological_space X]
(f : C(X, E)) {K L : topological_space.compacts X} (hKL : K ≤ L) :
‖f.restrict K‖ ≤ ‖f.restrict L‖ :=
(norm_le _ (norm_nonneg _)).mpr (λ x, norm_coe_le_norm (f.restrict L) $ set.inclusion hKL x)
end
section
variables {R : Type*} [normed_ring R]
instance : normed_ring C(α,R) :=
{ norm_mul := λ f g, norm_mul_le (mk_of_compact f) (mk_of_compact g),
..(infer_instance : normed_add_comm_group C(α,R)),
.. continuous_map.ring }
end
section
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E]
instance : normed_space 𝕜 C(α,E) :=
{ norm_smul_le := λ c f, (norm_smul_le c (mk_of_compact f) : _) }
section
variables (α 𝕜 E)
/--
When `α` is compact and `𝕜` is a normed field,
the `𝕜`-algebra of bounded continuous maps `α →ᵇ β` is
`𝕜`-linearly isometric to `C(α, β)`.
-/
def linear_isometry_bounded_of_compact :
C(α, E) ≃ₗᵢ[𝕜] (α →ᵇ E) :=
{ map_smul' := λ c f, by { ext, simp, },
norm_map' := λ f, rfl,
.. add_equiv_bounded_of_compact α E }
variables {α E} -- to match bounded_continuous_function.eval_clm
/-- The evaluation at a point, as a continuous linear map from `C(α, 𝕜)` to `𝕜`. -/
def eval_clm (x : α) : C(α, E) →L[𝕜] E :=
(eval_clm 𝕜 x).comp
((linear_isometry_bounded_of_compact α E 𝕜).to_linear_isometry).to_continuous_linear_map
end
-- this lemma and the next are the analogues of those autogenerated by `@[simps]` for
-- `equiv_bounded_of_compact`, `add_equiv_bounded_of_compact`
@[simp] lemma linear_isometry_bounded_of_compact_symm_apply (f : α →ᵇ E) :
(linear_isometry_bounded_of_compact α E 𝕜).symm f = f.to_continuous_map :=
rfl
@[simp] lemma linear_isometry_bounded_of_compact_apply_apply (f : C(α, E)) (a : α) :
(linear_isometry_bounded_of_compact α E 𝕜 f) a = f a :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_to_isometry_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_isometry_equiv =
(isometry_equiv_bounded_of_compact α E) :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_to_add_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_equiv.to_add_equiv =
(add_equiv_bounded_of_compact α E) :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_of_compact_to_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_equiv.to_equiv =
(equiv_bounded_of_compact α E) :=
rfl
end
section
variables {𝕜 : Type*} {γ : Type*} [normed_field 𝕜] [normed_ring γ] [normed_algebra 𝕜 γ]
instance : normed_algebra 𝕜 C(α, γ) :=
{ ..continuous_map.normed_space }
end
end continuous_map
namespace continuous_map
section uniform_continuity
variables {α β : Type*}
variables [metric_space α] [compact_space α] [metric_space β]
/-!
We now set up some declarations making it convenient to use uniform continuity.
-/
lemma uniform_continuity
(f : C(α, β)) (ε : ℝ) (h : 0 < ε) :
∃ δ > 0, ∀ {x y}, dist x y < δ → dist (f x) (f y) < ε :=
metric.uniform_continuous_iff.mp
(compact_space.uniform_continuous_of_continuous f.continuous) ε h
/--
An arbitrarily chosen modulus of uniform continuity for a given function `f` and `ε > 0`.
-/
-- This definition allows us to separate the choice of some `δ`,
-- and the corresponding use of `dist a b < δ → dist (f a) (f b) < ε`,
-- even across different declarations.
def modulus (f : C(α, β)) (ε : ℝ) (h : 0 < ε) : ℝ :=
classical.some (uniform_continuity f ε h)
lemma modulus_pos (f : C(α, β)) {ε : ℝ} {h : 0 < ε} : 0 < f.modulus ε h :=
(classical.some_spec (uniform_continuity f ε h)).fst
lemma dist_lt_of_dist_lt_modulus
(f : C(α, β)) (ε : ℝ) (h : 0 < ε) {a b : α} (w : dist a b < f.modulus ε h) :
dist (f a) (f b) < ε :=
(classical.some_spec (uniform_continuity f ε h)).snd w
end uniform_continuity
end continuous_map
section comp_left
variables (X : Type*) {𝕜 β γ : Type*} [topological_space X] [compact_space X]
[nontrivially_normed_field 𝕜]
variables [normed_add_comm_group β] [normed_space 𝕜 β] [normed_add_comm_group γ] [normed_space 𝕜 γ]
open continuous_map
/--
Postcomposition of continuous functions into a normed module by a continuous linear map is a
continuous linear map.
Transferred version of `continuous_linear_map.comp_left_continuous_bounded`,
upgraded version of `continuous_linear_map.comp_left_continuous`,
similar to `linear_map.comp_left`. -/
protected def continuous_linear_map.comp_left_continuous_compact (g : β →L[𝕜] γ) :
C(X, β) →L[𝕜] C(X, γ) :=
(linear_isometry_bounded_of_compact X γ 𝕜).symm.to_linear_isometry.to_continuous_linear_map.comp $
(g.comp_left_continuous_bounded X).comp $
(linear_isometry_bounded_of_compact X β 𝕜).to_linear_isometry.to_continuous_linear_map
@[simp] lemma continuous_linear_map.to_linear_comp_left_continuous_compact (g : β →L[𝕜] γ) :
(g.comp_left_continuous_compact X : C(X, β) →ₗ[𝕜] C(X, γ)) = g.comp_left_continuous 𝕜 X :=
by { ext f, refl }
@[simp] lemma continuous_linear_map.comp_left_continuous_compact_apply (g : β →L[𝕜] γ)
(f : C(X, β)) (x : X) :
g.comp_left_continuous_compact X f x = g (f x) :=
rfl
end comp_left
namespace continuous_map
/-!
We now setup variations on `comp_right_* f`, where `f : C(X, Y)`
(that is, precomposition by a continuous map),
as a morphism `C(Y, T) → C(X, T)`, respecting various types of structure.
In particular:
* `comp_right_continuous_map`, the bundled continuous map (for this we need `X Y` compact).
* `comp_right_homeomorph`, when we precompose by a homeomorphism.
* `comp_right_alg_hom`, when `T = R` is a topological ring.
-/
section comp_right
/--
Precomposition by a continuous map is itself a continuous map between spaces of continuous maps.
-/
def comp_right_continuous_map {X Y : Type*} (T : Type*) [topological_space X] [compact_space X]
[topological_space Y] [compact_space Y] [metric_space T]
(f : C(X, Y)) : C(C(Y, T), C(X, T)) :=
{ to_fun := λ g, g.comp f,
continuous_to_fun :=
begin
refine metric.continuous_iff.mpr _,
intros g ε ε_pos,
refine ⟨ε, ε_pos, λ g' h, _⟩,
rw continuous_map.dist_lt_iff ε_pos at h ⊢,
{ exact λ x, h (f x), },
end }
@[simp] lemma comp_right_continuous_map_apply {X Y : Type*} (T : Type*) [topological_space X]
[compact_space X] [topological_space Y] [compact_space Y] [metric_space T]
(f : C(X, Y)) (g : C(Y, T)) :
(comp_right_continuous_map T f) g = g.comp f :=
rfl
/--
Precomposition by a homeomorphism is itself a homeomorphism between spaces of continuous maps.
-/
def comp_right_homeomorph {X Y : Type*} (T : Type*) [topological_space X] [compact_space X]
[topological_space Y] [compact_space Y] [metric_space T]
(f : X ≃ₜ Y) : C(Y, T) ≃ₜ C(X, T) :=
{ to_fun := comp_right_continuous_map T f.to_continuous_map,
inv_fun := comp_right_continuous_map T f.symm.to_continuous_map,
left_inv := λ g, ext $ λ _, congr_arg g (f.apply_symm_apply _),
right_inv := λ g, ext $ λ _, congr_arg g (f.symm_apply_apply _) }
lemma comp_right_alg_hom_continuous {X Y : Type*} (R A : Type*)
[topological_space X] [compact_space X] [topological_space Y] [compact_space Y] [comm_semiring R]
[semiring A] [metric_space A] [topological_semiring A] [algebra R A] (f : C(X, Y)) :
continuous (comp_right_alg_hom R A f) :=
map_continuous (comp_right_continuous_map A f)
end comp_right
section local_normal_convergence
/-! ### Local normal convergence
A sum of continuous functions (on a locally compact space) is "locally normally convergent" if the
sum of its sup-norms on any compact subset is summable. This implies convergence in the topology
of `C(X, E)` (i.e. locally uniform convergence). -/
open topological_space
variables {X : Type*} [topological_space X] [t2_space X] [locally_compact_space X]
variables {E : Type*} [normed_add_comm_group E] [complete_space E]
lemma summable_of_locally_summable_norm {ι : Type*} {F : ι → C(X, E)}
(hF : ∀ K : compacts X, summable (λ i, ‖(F i).restrict K‖)) :
summable F :=
begin
refine (continuous_map.exists_tendsto_compact_open_iff_forall _).2 (λ K hK, _),
lift K to compacts X using hK,
have A : ∀ s : finset ι, restrict ↑K (∑ i in s, F i) = ∑ i in s, restrict K (F i),
{ intro s, ext1 x, simp },
simpa only [has_sum, A] using summable_of_summable_norm (hF K)
end
end local_normal_convergence
/-!
### Star structures
In this section, if `β` is a normed ⋆-group, then so is the space of
continuous functions from `α` to `β`, by using the star operation pointwise.
Furthermore, if `α` is compact and `β` is a C⋆-ring, then `C(α, β)` is a C⋆-ring. -/
section normed_space
variables {α : Type*} {β : Type*}
variables [topological_space α] [normed_add_comm_group β] [star_add_monoid β] [normed_star_group β]
lemma _root_.bounded_continuous_function.mk_of_compact_star [compact_space α] (f : C(α, β)) :
mk_of_compact (star f) = star (mk_of_compact f) := rfl
instance [compact_space α] : normed_star_group C(α, β) :=
{ norm_star := λ f, by rw [←bounded_continuous_function.norm_mk_of_compact,
bounded_continuous_function.mk_of_compact_star, norm_star,
bounded_continuous_function.norm_mk_of_compact] }
end normed_space
section cstar_ring
variables {α : Type*} {β : Type*}
variables [topological_space α] [normed_ring β] [star_ring β]
instance [compact_space α] [cstar_ring β] : cstar_ring C(α, β) :=
{ norm_star_mul_self :=
begin
intros f,
refine le_antisymm _ _,
{ rw [←sq, continuous_map.norm_le _ (sq_nonneg _)],
intro x,
simp only [continuous_map.coe_mul, coe_star, pi.mul_apply, pi.star_apply,
cstar_ring.norm_star_mul_self, ←sq],
refine sq_le_sq' _ _,
{ linarith [norm_nonneg (f x), norm_nonneg f] },
{ exact continuous_map.norm_coe_le_norm f x }, },
{ rw [←sq, ←real.le_sqrt (norm_nonneg _) (norm_nonneg _),
continuous_map.norm_le _ (real.sqrt_nonneg _)],
intro x,
rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ←cstar_ring.norm_star_mul_self],
exact continuous_map.norm_coe_le_norm (star f * f) x },
end }
end cstar_ring
end continuous_map
|
2f48a00f081b1f2dde7ada82267462bfafa8c7d9 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/sequences.lean | 1ec0d97328d2ac13528aa3479ca698c42c62491f | [
"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 | 16,569 | lean | /-
Copyright (c) 2018 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Patrick Massot
-/
import topology.subset_properties
import topology.metric_space.basic
/-!
# Sequences in topological spaces
In this file we define sequences in topological spaces and show how they are related to
filters and the topology. In particular, we
* define the sequential closure of a set and prove that it's contained in the closure,
* define a type class "sequential_space" in which closure and sequential closure agree,
* define sequential continuity and show that it coincides with continuity in sequential spaces,
* provide an instance that shows that every first-countable (and in particular metric) space is
a sequential space.
* define sequential compactness, prove that compactness implies sequential compactness in first
countable spaces, and prove they are equivalent for uniform spaces having a countable uniformity
basis (in particular metric spaces).
-/
open set function filter
open_locale topological_space
variables {X Y : Type*}
local notation x ` ⟶ ` a := tendsto x at_top (𝓝 a)
/-! ### Sequential closures, sequential continuity, and sequential spaces. -/
section topological_space
variables [topological_space X] [topological_space Y]
/-- The sequential closure of a set `s : set X` in a topological space `X` is
the set of all `a : X` which arise as limit of sequences in `s`. -/
def seq_closure (s : set X) : set X :=
{a | ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ (x ⟶ a)}
lemma subset_seq_closure (s : set X) : s ⊆ seq_closure s :=
λ a ha, ⟨const ℕ a, λ n, ha, tendsto_const_nhds⟩
/-- A set `s` is sequentially closed if for any converging sequence `x n` of elements of `s`,
the limit belongs to `s` as well. -/
def is_seq_closed (s : set X) : Prop := s = seq_closure s
/-- A convenience lemma for showing that a set is sequentially closed. -/
lemma is_seq_closed_of_def {s : set X}
(h : ∀ (x : ℕ → X) (a : X), (∀ n : ℕ, x n ∈ s) → (x ⟶ a) → a ∈ s) : is_seq_closed s :=
show s = seq_closure s, from subset.antisymm
(subset_seq_closure s)
(show ∀ a, a ∈ seq_closure s → a ∈ s, from
(assume a ⟨x, _, _⟩, show a ∈ s, from h x a ‹∀ n : ℕ, ((x n) ∈ s)› ‹(x ⟶ a)›))
/-- The sequential closure of a set is contained in the closure of that set.
The converse is not true. -/
lemma seq_closure_subset_closure (s : set X) : seq_closure s ⊆ closure s :=
assume a ⟨x, xM, xa⟩,
mem_closure_of_tendsto xa (eventually_of_forall xM)
/-- A set is sequentially closed if it is closed. -/
lemma is_closed.is_seq_closed {s : set X} (hs : is_closed s) : is_seq_closed s :=
suffices seq_closure s ⊆ s, from (subset_seq_closure s).antisymm this,
calc seq_closure s ⊆ closure s : seq_closure_subset_closure s
... = s : hs.closure_eq
/-- The limit of a convergent sequence in a sequentially closed set is in that set.-/
lemma is_seq_closed.mem_of_tendsto {s : set X} (hs : is_seq_closed s) {x : ℕ → X}
(hmem : ∀ n, x n ∈ s) {a : X} (ha : (x ⟶ a)) : a ∈ s :=
have a ∈ seq_closure s, from
show ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ (x ⟶ a), from ⟨x, ‹∀ n, x n ∈ s›, ‹(x ⟶ a)›⟩,
eq.subst (eq.symm ‹is_seq_closed s›) ‹a ∈ seq_closure s›
/-- A sequential space is a space in which 'sequences are enough to probe the topology'. This can be
formalised by demanding that the sequential closure and the closure coincide. The following
statements show that other topological properties can be deduced from sequences in sequential
spaces. -/
class sequential_space (X : Type*) [topological_space X] : Prop :=
(seq_closure_eq_closure : ∀ s : set X, seq_closure s = closure s)
/-- In a sequential space, a set is closed iff it's sequentially closed. -/
lemma is_seq_closed_iff_is_closed [sequential_space X] {s : set X} :
is_seq_closed s ↔ is_closed s :=
iff.intro
(assume _, closure_eq_iff_is_closed.mp (eq.symm
(calc s = seq_closure s : by assumption
... = closure s : sequential_space.seq_closure_eq_closure s)))
is_closed.is_seq_closed
alias is_seq_closed_iff_is_closed ↔ is_seq_closed.is_closed _
/-- In a sequential space, a point belongs to the closure of a set iff it is a limit of a sequence
taking values in this set. -/
lemma mem_closure_iff_seq_limit [sequential_space X] {s : set X} {a : X} :
a ∈ closure s ↔ ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ (x ⟶ a) :=
by { rw ← sequential_space.seq_closure_eq_closure, exact iff.rfl }
/-- A function between topological spaces is sequentially continuous if it commutes with limit of
convergent sequences. -/
def seq_continuous (f : X → Y) : Prop :=
∀ (x : ℕ → X), ∀ {a : X}, (x ⟶ a) → (f ∘ x ⟶ f a)
/- A continuous function is sequentially continuous. -/
protected lemma continuous.seq_continuous {f : X → Y} (hf : continuous f) : seq_continuous f :=
assume x a (_ : x ⟶ a),
have tendsto f (𝓝 a) (𝓝 (f a)), from continuous.tendsto ‹continuous f› a,
show (f ∘ x) ⟶ (f a), from tendsto.comp this ‹(x ⟶ a)›
/-- In a sequential space, continuity and sequential continuity coincide. -/
lemma continuous_iff_seq_continuous {f : X → Y} [sequential_space X] :
continuous f ↔ seq_continuous f :=
iff.intro
continuous.seq_continuous
(assume : seq_continuous f, show continuous f, from
suffices h : ∀ {s : set Y}, is_closed s → is_seq_closed (f ⁻¹' s), from
continuous_iff_is_closed.mpr (assume s _, is_seq_closed_iff_is_closed.mp $ h ‹is_closed s›),
assume s (_ : is_closed s),
is_seq_closed_of_def $
assume (x : ℕ → X) a (_ : ∀ n, f (x n) ∈ s) (_ : x ⟶ a),
have (f ∘ x) ⟶ (f a), from ‹seq_continuous f› x ‹(x ⟶ a)›,
show f a ∈ s,
from ‹is_closed s›.is_seq_closed.mem_of_tendsto ‹∀ n, f (x n) ∈ s› ‹(f∘x ⟶ f a)›)
alias continuous_iff_seq_continuous ↔ _ seq_continuous.continuous
end topological_space
namespace topological_space
namespace first_countable_topology
variables [topological_space X] [first_countable_topology X]
/-- Every first-countable space is sequential. -/
@[priority 100] -- see Note [lower instance priority]
instance : sequential_space X :=
⟨show ∀ s, seq_closure s = closure s, from assume s,
suffices closure s ⊆ seq_closure s,
from set.subset.antisymm (seq_closure_subset_closure s) this,
-- For every a ∈ closure s, we need to construct a sequence `x` in `s` that converges to `a`:
assume (a : X) (ha : a ∈ closure s),
-- Since we are in a first-countable space, the neighborhood filter around `a` has a decreasing
-- basis `U` indexed by `ℕ`.
let ⟨U, hU⟩ := (𝓝 a).exists_antitone_basis in
-- Since `p ∈ closure M`, there is an element in each `M ∩ U i`
have ha : ∀ (i : ℕ), ∃ (y : X), y ∈ s ∧ y ∈ U i,
by simpa using (mem_closure_iff_nhds_basis hU.1).mp ha,
begin
-- The axiom of (countable) choice builds our sequence from the later fact
choose u hu using ha,
rw forall_and_distrib at hu,
-- It clearly takes values in `M`
use [u, hu.1],
-- and converges to `p` because the basis is decreasing.
apply hU.tendsto hu.2,
end⟩
end first_countable_topology
end topological_space
section seq_compact
open topological_space topological_space.first_countable_topology
variables [topological_space X]
/-- A set `s` is sequentially compact if every sequence taking values in `s` has a
converging subsequence. -/
def is_seq_compact (s : set X) :=
∀ ⦃x : ℕ → X⦄, (∀ n, x n ∈ s) → ∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a)
/-- A space `X` is sequentially compact if every sequence in `X` has a
converging subsequence. -/
class seq_compact_space (X : Type*) [topological_space X] : Prop :=
(seq_compact_univ : is_seq_compact (univ : set X))
lemma is_seq_compact.subseq_of_frequently_in {s : set X} (hs : is_seq_compact s) {x : ℕ → X}
(hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a) :=
let ⟨ψ, hψ, huψ⟩ := extraction_of_frequently_at_top hx, ⟨a, a_in, φ, hφ, h⟩ := hs huψ in
⟨a, a_in, ψ ∘ φ, hψ.comp hφ, h⟩
lemma seq_compact_space.tendsto_subseq [seq_compact_space X] (x : ℕ → X) :
∃ a (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a) :=
let ⟨a, _, φ, mono, h⟩ := seq_compact_space.seq_compact_univ (λ n, mem_univ (x n)) in
⟨a, φ, mono, h⟩
section first_countable_topology
variables [first_countable_topology X]
open topological_space.first_countable_topology
lemma is_compact.is_seq_compact {s : set X} (hs : is_compact s) : is_seq_compact s :=
λ x x_in,
let ⟨a, a_in, ha⟩ := @hs (map x at_top) _
(le_principal_iff.mpr (univ_mem' x_in : _)) in ⟨a, a_in, tendsto_subseq ha⟩
lemma is_compact.tendsto_subseq' {s : set X} {x : ℕ → X} (hs : is_compact s)
(hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a) :=
hs.is_seq_compact.subseq_of_frequently_in hx
lemma is_compact.tendsto_subseq {s : set X} {x : ℕ → X} (hs : is_compact s) (hx : ∀ n, x n ∈ s) :
∃ (a ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a) :=
hs.is_seq_compact hx
@[priority 100] -- see Note [lower instance priority]
instance first_countable_topology.seq_compact_of_compact [compact_space X] : seq_compact_space X :=
⟨compact_univ.is_seq_compact⟩
lemma compact_space.tendsto_subseq [compact_space X] (x : ℕ → X) :
∃ a (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ a) :=
seq_compact_space.tendsto_subseq x
end first_countable_topology
end seq_compact
section uniform_space_seq_compact
open_locale uniformity
open uniform_space prod
variables [uniform_space X] {s : set X}
lemma lebesgue_number_lemma_seq {ι : Type*} [is_countably_generated (𝓤 X)] {c : ι → set X}
(hs : is_seq_compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ V ∈ 𝓤 X, symmetric_rel V ∧ ∀ x ∈ s, ∃ i, ball x V ⊆ c i :=
begin
classical,
obtain ⟨V, hV, Vsymm⟩ :
∃ V : ℕ → set (X × X), (𝓤 X).has_antitone_basis V ∧ ∀ n, swap ⁻¹' V n = V n,
from uniform_space.has_seq_basis X,
suffices : ∃ n, ∀ x ∈ s, ∃ i, ball x (V n) ⊆ c i,
{ cases this with n hn,
exact ⟨V n, hV.to_has_basis.mem_of_mem trivial, Vsymm n, hn⟩ },
by_contradiction H,
obtain ⟨x, x_in, hx⟩ : ∃ x : ℕ → X, (∀ n, x n ∈ s) ∧ ∀ n i, ¬ ball (x n) (V n) ⊆ c i,
{ push_neg at H,
choose x hx using H,
exact ⟨x, forall_and_distrib.mp hx⟩ }, clear H,
obtain ⟨x₀, x₀_in, φ, φ_mono, hlim⟩ : ∃ (x₀ ∈ s) (φ : ℕ → ℕ), strict_mono φ ∧ (x ∘ φ ⟶ x₀),
from hs x_in, clear hs,
obtain ⟨i₀, x₀_in⟩ : ∃ i₀, x₀ ∈ c i₀,
{ rcases hc₂ x₀_in with ⟨_, ⟨i₀, rfl⟩, x₀_in_c⟩,
exact ⟨i₀, x₀_in_c⟩ }, clear hc₂,
obtain ⟨n₀, hn₀⟩ : ∃ n₀, ball x₀ (V n₀) ⊆ c i₀,
{ rcases (nhds_basis_uniformity hV.to_has_basis).mem_iff.mp
(is_open_iff_mem_nhds.mp (hc₁ i₀) _ x₀_in) with ⟨n₀, _, h⟩,
use n₀,
rwa ← ball_eq_of_symmetry (Vsymm n₀) at h }, clear hc₁,
obtain ⟨W, W_in, hWW⟩ : ∃ W ∈ 𝓤 X, W ○ W ⊆ V n₀,
from comp_mem_uniformity_sets (hV.to_has_basis.mem_of_mem trivial),
obtain ⟨N, x_φ_N_in, hVNW⟩ : ∃ N, x (φ N) ∈ ball x₀ W ∧ V (φ N) ⊆ W,
{ obtain ⟨N₁, h₁⟩ : ∃ N₁, ∀ n ≥ N₁, x (φ n) ∈ ball x₀ W,
from tendsto_at_top'.mp hlim _ (mem_nhds_left x₀ W_in),
obtain ⟨N₂, h₂⟩ : ∃ N₂, V (φ N₂) ⊆ W,
{ rcases hV.to_has_basis.mem_iff.mp W_in with ⟨N, _, hN⟩,
use N,
exact subset.trans (hV.antitone $ φ_mono.id_le _) hN },
have : φ N₂ ≤ φ (max N₁ N₂),
from φ_mono.le_iff_le.mpr (le_max_right _ _),
exact ⟨max N₁ N₂, h₁ _ (le_max_left _ _), trans (hV.antitone this) h₂⟩ },
suffices : ball (x (φ N)) (V (φ N)) ⊆ c i₀,
from hx (φ N) i₀ this,
calc
ball (x $ φ N) (V $ φ N) ⊆ ball (x $ φ N) W : preimage_mono hVNW
... ⊆ ball x₀ (V n₀) : ball_subset_of_comp_subset x_φ_N_in hWW
... ⊆ c i₀ : hn₀,
end
lemma is_seq_compact.totally_bounded (h : is_seq_compact s) : totally_bounded s :=
begin
classical,
apply totally_bounded_of_forall_symm,
unfold is_seq_compact at h,
contrapose! h,
rcases h with ⟨V, V_in, V_symm, h⟩,
simp_rw [not_subset] at h,
have : ∀ (t : set X), t.finite → ∃ a, a ∈ s ∧ a ∉ ⋃ y ∈ t, ball y V,
{ intros t ht,
obtain ⟨a, a_in, H⟩ : ∃ a ∈ s, ∀ x ∈ t, (x, a) ∉ V,
by simpa [ht] using h t,
use [a, a_in],
intro H',
obtain ⟨x, x_in, hx⟩ := mem_Union₂.mp H',
exact H x x_in hx },
cases seq_of_forall_finite_exists this with u hu, clear h this,
simp [forall_and_distrib] at hu,
cases hu with u_in hu,
use [u, u_in], clear u_in,
intros x x_in φ,
intros hφ huφ,
obtain ⟨N, hN⟩ : ∃ N, ∀ p q, p ≥ N → q ≥ N → (u (φ p), u (φ q)) ∈ V,
from huφ.cauchy_seq.mem_entourage V_in,
specialize hN N (N+1) (le_refl N) (nat.le_succ N),
specialize hu (φ $ N+1) (φ N) (hφ $ lt_add_one N),
exact hu hN,
end
protected lemma is_seq_compact.is_compact [is_countably_generated $ 𝓤 X] (hs : is_seq_compact s) :
is_compact s :=
begin
classical,
rw is_compact_iff_finite_subcover,
intros ι U Uop s_sub,
rcases lebesgue_number_lemma_seq hs Uop s_sub with ⟨V, V_in, Vsymm, H⟩,
rcases totally_bounded_iff_subset.mp hs.totally_bounded V V_in with ⟨t,t_sub, tfin, ht⟩,
have : ∀ x : t, ∃ (i : ι), ball x.val V ⊆ U i,
{ rintros ⟨x, x_in⟩,
exact H x (t_sub x_in) },
choose i hi using this,
haveI : fintype t := tfin.fintype,
use finset.image i finset.univ,
transitivity ⋃ y ∈ t, ball y V,
{ intros x x_in,
specialize ht x_in,
rw mem_Union₂ at *,
simp_rw ball_eq_of_symmetry Vsymm,
exact ht },
{ refine Union₂_mono' (λ x x_in, _),
exact ⟨i ⟨x, x_in⟩, finset.mem_image_of_mem _ (finset.mem_univ _), hi ⟨x, x_in⟩⟩ },
end
/-- A version of Bolzano-Weistrass: in a uniform space with countably generated uniformity filter
(e.g., in a metric space), a set is compact if and only if it is sequentially compact. -/
protected lemma uniform_space.compact_iff_seq_compact [is_countably_generated $ 𝓤 X] :
is_compact s ↔ is_seq_compact s :=
⟨λ H, H.is_seq_compact, λ H, H.is_compact⟩
lemma uniform_space.compact_space_iff_seq_compact_space [is_countably_generated $ 𝓤 X] :
compact_space X ↔ seq_compact_space X :=
have key : is_compact (univ : set X) ↔ is_seq_compact univ := uniform_space.compact_iff_seq_compact,
⟨λ ⟨h⟩, ⟨key.mp h⟩, λ ⟨h⟩, ⟨key.mpr h⟩⟩
end uniform_space_seq_compact
section metric_seq_compact
variables [pseudo_metric_space X]
open metric
lemma seq_compact.lebesgue_number_lemma_of_metric {ι : Sort*} {c : ι → set X}
{s : set X} (hs : is_seq_compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ a ∈ s, ∃ i, ball a δ ⊆ c i :=
lebesgue_number_lemma_of_metric hs.is_compact hc₁ hc₂
variables [proper_space X] {s : set X}
/-- A version of **Bolzano-Weistrass**: in a proper metric space (eg. $ℝ^n$),
every bounded sequence has a converging subsequence. This version assumes only
that the sequence is frequently in some bounded set. -/
lemma tendsto_subseq_of_frequently_bounded (hs : bounded s)
{x : ℕ → X} (hx : ∃ᶠ n in at_top, x n ∈ s) :
∃ a ∈ closure s, ∃ φ : ℕ → ℕ, strict_mono φ ∧ (x ∘ φ ⟶ a) :=
have hcs : is_seq_compact (closure s), from hs.is_compact_closure.is_seq_compact,
have hu' : ∃ᶠ n in at_top, x n ∈ closure s, from hx.mono (λ n hn, subset_closure hn),
hcs.subseq_of_frequently_in hu'
/-- A version of Bolzano-Weistrass: in a proper metric space (eg. $ℝ^n$),
every bounded sequence has a converging subsequence. -/
lemma tendsto_subseq_of_bounded (hs : bounded s) {x : ℕ → X} (hx : ∀ n, x n ∈ s) :
∃ a ∈ closure s, ∃ φ : ℕ → ℕ, strict_mono φ ∧ (x ∘ φ ⟶ a) :=
tendsto_subseq_of_frequently_bounded hs $ frequently_of_forall hx
end metric_seq_compact
|
9c9e8810cc695f14139d006efaab01456c4a0f29 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/algebra/ordered_group.lean | 7b9ce868d27e79c943968fce2bd6c07d8b55c989 | [
"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 | 44,953 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import algebra.ordered_monoid
import order.rel_iso
import order.order_dual
/-!
# Ordered groups
This file develops the basics of ordered groups.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
set_option old_structure_cmd true
universe u
variable {α : Type u}
@[to_additive]
instance group.covariant_class_le.to_contravariant_class_le
[group α] [has_le α] [covariant_class α α (*) (≤)] : contravariant_class α α (*) (≤) :=
{ elim := λ a b c bc, calc b = a⁻¹ * (a * b) : eq_inv_mul_of_mul_eq rfl
... ≤ a⁻¹ * (a * c) : mul_le_mul_left' bc a⁻¹
... = c : inv_mul_cancel_left a c }
@[to_additive]
instance group.swap.covariant_class_le.to_contravariant_class_le [group α] [has_le α]
[covariant_class α α (function.swap (*)) (≤)] : contravariant_class α α (function.swap (*)) (≤) :=
{ elim := λ a b c bc, calc b = b * a * a⁻¹ : eq_mul_inv_of_mul_eq rfl
... ≤ c * a * a⁻¹ : mul_le_mul_right' bc a⁻¹
... = c : mul_inv_eq_of_eq_mul rfl }
@[to_additive]
instance group.covariant_class_lt.to_contravariant_class_lt
[group α] [has_lt α] [covariant_class α α (*) (<)] : contravariant_class α α (*) (<) :=
{ elim := λ a b c bc, calc b = a⁻¹ * (a * b) : eq_inv_mul_of_mul_eq rfl
... < a⁻¹ * (a * c) : mul_lt_mul_left' bc a⁻¹
... = c : inv_mul_cancel_left a c }
@[to_additive]
instance group.swap.covariant_class_lt.to_contravariant_class_lt [group α] [has_lt α]
[covariant_class α α (function.swap (*)) (<)] : contravariant_class α α (function.swap (*)) (<) :=
{ elim := λ a b c bc, calc b = b * a * a⁻¹ : eq_mul_inv_of_mul_eq rfl
... < c * a * a⁻¹ : mul_lt_mul_right' bc a⁻¹
... = c : mul_inv_eq_of_eq_mul rfl }
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
@[protect_proj, ancestor add_comm_group partial_order]
class ordered_add_comm_group (α : Type u) extends add_comm_group α, partial_order α :=
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b)
/-- An ordered commutative group is an commutative group
with a partial order in which multiplication is strictly monotone. -/
@[protect_proj, ancestor comm_group partial_order]
class ordered_comm_group (α : Type u) extends comm_group α, partial_order α :=
(mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b)
attribute [to_additive] ordered_comm_group
@[to_additive]
instance ordered_comm_group.to_covariant_class_left_le (α : Type u) [ordered_comm_group α] :
covariant_class α α (*) (≤) :=
{ elim := λ a b c bc, ordered_comm_group.mul_le_mul_left b c bc a }
/--The units of an ordered commutative monoid form an ordered commutative group. -/
@[to_additive]
instance units.ordered_comm_group [ordered_comm_monoid α] : ordered_comm_group (units α) :=
{ mul_le_mul_left := λ a b h c, (mul_le_mul_left' (h : (a : α) ≤ b) _ : (c : α) * a ≤ c * b),
.. units.partial_order,
.. (infer_instance : comm_group (units α)) }
@[priority 100, to_additive] -- see Note [lower instance priority]
instance ordered_comm_group.to_ordered_cancel_comm_monoid (α : Type u)
[s : ordered_comm_group α] :
ordered_cancel_comm_monoid α :=
{ mul_left_cancel := λ a b c, (mul_right_inj a).mp,
le_of_mul_le_mul_left := λ a b c, (mul_le_mul_iff_left a).mp,
..s }
@[priority 100, to_additive]
instance ordered_comm_group.has_exists_mul_of_le (α : Type u)
[ordered_comm_group α] :
has_exists_mul_of_le α :=
⟨λ a b hab, ⟨b * a⁻¹, (mul_inv_cancel_comm_assoc a b).symm⟩⟩
section group
variables [group α]
section typeclasses_left_le
variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α}
/-- Uses `left` co(ntra)variant. -/
@[simp, to_additive left.neg_nonpos_iff]
lemma left.inv_le_one_iff :
a⁻¹ ≤ 1 ↔ 1 ≤ a :=
by { rw [← mul_le_mul_iff_left a], simp }
/-- Uses `left` co(ntra)variant. -/
@[simp, to_additive left.nonneg_neg_iff]
lemma left.one_le_inv_iff :
1 ≤ a⁻¹ ↔ a ≤ 1 :=
by { rw [← mul_le_mul_iff_left a], simp }
@[simp, to_additive]
lemma le_inv_mul_iff_mul_le : b ≤ a⁻¹ * c ↔ a * b ≤ c :=
by { rw ← mul_le_mul_iff_left a, simp }
@[simp, to_additive]
lemma inv_mul_le_iff_le_mul : b⁻¹ * a ≤ c ↔ a ≤ b * c :=
by rw [← mul_le_mul_iff_left b, mul_inv_cancel_left]
@[to_additive neg_le_iff_add_nonneg']
lemma inv_le_iff_one_le_mul' : a⁻¹ ≤ b ↔ 1 ≤ a * b :=
(mul_le_mul_iff_left a).symm.trans $ by rw mul_inv_self
@[to_additive]
lemma le_inv_iff_mul_le_one_left : a ≤ b⁻¹ ↔ b * a ≤ 1 :=
(mul_le_mul_iff_left b).symm.trans $ by rw mul_inv_self
@[to_additive]
lemma le_inv_mul_iff_le : 1 ≤ b⁻¹ * a ↔ b ≤ a :=
by rw [← mul_le_mul_iff_left b, mul_one, mul_inv_cancel_left]
@[to_additive]
lemma inv_mul_le_one_iff : a⁻¹ * b ≤ 1 ↔ b ≤ a :=
trans (inv_mul_le_iff_le_mul) $ by rw mul_one
end typeclasses_left_le
section typeclasses_left_lt
variables [has_lt α] [covariant_class α α (*) (<)] {a b c : α}
/-- Uses `left` co(ntra)variant. -/
@[simp, to_additive left.neg_pos_iff]
lemma left.one_lt_inv_iff :
1 < a⁻¹ ↔ a < 1 :=
by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one]
/-- Uses `left` co(ntra)variant. -/
@[simp, to_additive left.neg_neg_iff]
lemma left.inv_lt_one_iff :
a⁻¹ < 1 ↔ 1 < a :=
by rw [← mul_lt_mul_iff_left a, mul_inv_self, mul_one]
@[simp, to_additive]
lemma lt_inv_mul_iff_mul_lt : b < a⁻¹ * c ↔ a * b < c :=
by { rw [← mul_lt_mul_iff_left a], simp }
@[simp, to_additive]
lemma inv_mul_lt_iff_lt_mul : b⁻¹ * a < c ↔ a < b * c :=
by rw [← mul_lt_mul_iff_left b, mul_inv_cancel_left]
@[to_additive]
lemma inv_lt_iff_one_lt_mul' : a⁻¹ < b ↔ 1 < a * b :=
(mul_lt_mul_iff_left a).symm.trans $ by rw mul_inv_self
@[to_additive]
lemma lt_inv_iff_mul_lt_one' : a < b⁻¹ ↔ b * a < 1 :=
(mul_lt_mul_iff_left b).symm.trans $ by rw mul_inv_self
@[to_additive]
lemma lt_inv_mul_iff_lt : 1 < b⁻¹ * a ↔ b < a :=
by rw [← mul_lt_mul_iff_left b, mul_one, mul_inv_cancel_left]
@[to_additive]
lemma inv_mul_lt_one_iff : a⁻¹ * b < 1 ↔ b < a :=
trans (inv_mul_lt_iff_lt_mul) $ by rw mul_one
end typeclasses_left_lt
section typeclasses_right_le
variables [has_le α] [covariant_class α α (function.swap (*)) (≤)] {a b c : α}
/-- Uses `right` co(ntra)variant. -/
@[simp, to_additive right.neg_nonpos_iff]
lemma right.inv_le_one_iff :
a⁻¹ ≤ 1 ↔ 1 ≤ a :=
by { rw [← mul_le_mul_iff_right a], simp }
/-- Uses `right` co(ntra)variant. -/
@[simp, to_additive right.nonneg_neg_iff]
lemma right.one_le_inv_iff :
1 ≤ a⁻¹ ↔ a ≤ 1 :=
by { rw [← mul_le_mul_iff_right a], simp }
@[to_additive neg_le_iff_add_nonneg]
lemma inv_le_iff_one_le_mul : a⁻¹ ≤ b ↔ 1 ≤ b * a :=
(mul_le_mul_iff_right a).symm.trans $ by rw inv_mul_self
@[to_additive]
lemma le_inv_iff_mul_le_one_right : a ≤ b⁻¹ ↔ a * b ≤ 1 :=
(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_self
@[simp, to_additive]
lemma mul_inv_le_iff_le_mul : a * b⁻¹ ≤ c ↔ a ≤ c * b :=
(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right
@[simp, to_additive]
lemma le_mul_inv_iff_mul_le : c ≤ a * b⁻¹ ↔ c * b ≤ a :=
(mul_le_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right
@[simp, to_additive]
lemma mul_inv_le_one_iff_le : a * b⁻¹ ≤ 1 ↔ a ≤ b :=
mul_inv_le_iff_le_mul.trans $ by rw one_mul
@[to_additive]
lemma le_mul_inv_iff_le : 1 ≤ a * b⁻¹ ↔ b ≤ a :=
by rw [← mul_le_mul_iff_right b, one_mul, inv_mul_cancel_right]
@[to_additive]
lemma mul_inv_le_one_iff : b * a⁻¹ ≤ 1 ↔ b ≤ a :=
trans (mul_inv_le_iff_le_mul) $ by rw one_mul
end typeclasses_right_le
section typeclasses_right_lt
variables [has_lt α] [covariant_class α α (function.swap (*)) (<)] {a b c : α}
/-- Uses `right` co(ntra)variant. -/
@[simp, to_additive right.neg_neg_iff]
lemma right.inv_lt_one_iff :
a⁻¹ < 1 ↔ 1 < a :=
by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul]
/-- Uses `right` co(ntra)variant. -/
@[simp, to_additive right.neg_pos_iff]
lemma right.one_lt_inv_iff :
1 < a⁻¹ ↔ a < 1 :=
by rw [← mul_lt_mul_iff_right a, inv_mul_self, one_mul]
@[to_additive]
lemma inv_lt_iff_one_lt_mul : a⁻¹ < b ↔ 1 < b * a :=
(mul_lt_mul_iff_right a).symm.trans $ by rw inv_mul_self
@[to_additive]
lemma lt_inv_iff_mul_lt_one : a < b⁻¹ ↔ a * b < 1 :=
(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_self
@[simp, to_additive]
lemma mul_inv_lt_iff_lt_mul : a * b⁻¹ < c ↔ a < c * b :=
by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right]
@[simp, to_additive]
lemma lt_mul_inv_iff_mul_lt : c < a * b⁻¹ ↔ c * b < a :=
(mul_lt_mul_iff_right b).symm.trans $ by rw inv_mul_cancel_right
@[simp, to_additive]
lemma inv_mul_lt_one_iff_lt : a * b⁻¹ < 1 ↔ a < b :=
by rw [← mul_lt_mul_iff_right b, inv_mul_cancel_right, one_mul]
@[to_additive]
lemma lt_mul_inv_iff_lt : 1 < a * b⁻¹ ↔ b < a :=
by rw [← mul_lt_mul_iff_right b, one_mul, inv_mul_cancel_right]
@[to_additive]
lemma mul_inv_lt_one_iff : b * a⁻¹ < 1 ↔ b < a :=
trans (mul_inv_lt_iff_lt_mul) $ by rw one_mul
end typeclasses_right_lt
section typeclasses_left_right_le
variables [has_le α] [covariant_class α α (*) (≤)] [covariant_class α α (function.swap (*)) (≤)]
{a b c d : α}
@[simp, to_additive]
lemma inv_le_inv_iff : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
by { rw [← mul_le_mul_iff_left a, ← mul_le_mul_iff_right b], simp }
alias neg_le_neg_iff ↔ le_of_neg_le_neg _
/-- `x ↦ x⁻¹` as an order-reversing equivalence. -/
@[to_additive "`x ↦ -x` as an order-reversing equivalence.", simps]
def order_iso.inv : α ≃o order_dual α :=
{ to_equiv := (equiv.inv α).trans order_dual.to_dual,
map_rel_iff' := λ a b, @inv_le_inv_iff α _ _ _ _ _ _ }
@[to_additive neg_le]
lemma inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
order_iso.inv.symm_apply_le
alias inv_le' ↔ inv_le_of_inv_le _
attribute [to_additive] inv_le_of_inv_le
@[to_additive le_neg]
lemma le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
order_iso.inv.le_symm_apply
@[to_additive]
lemma mul_inv_le_inv_mul_iff : a * b⁻¹ ≤ d⁻¹ * c ↔ d * a ≤ c * b :=
by rw [← mul_le_mul_iff_left d, ← mul_le_mul_iff_right b, mul_inv_cancel_left, mul_assoc,
inv_mul_cancel_right]
@[simp, to_additive] lemma div_le_self_iff (a : α) {b : α} : a / b ≤ a ↔ 1 ≤ b :=
by simp [div_eq_mul_inv]
alias sub_le_self_iff ↔ _ sub_le_self
end typeclasses_left_right_le
section typeclasses_left_right_lt
variables [has_lt α] [covariant_class α α (*) (<)] [covariant_class α α (function.swap (*)) (<)]
{a b c d : α}
@[simp, to_additive]
lemma inv_lt_inv_iff : a⁻¹ < b⁻¹ ↔ b < a :=
by { rw [← mul_lt_mul_iff_left a, ← mul_lt_mul_iff_right b], simp }
@[to_additive neg_lt]
lemma inv_lt' : a⁻¹ < b ↔ b⁻¹ < a :=
by rw [← inv_lt_inv_iff, inv_inv]
@[to_additive lt_neg]
lemma lt_inv' : a < b⁻¹ ↔ b < a⁻¹ :=
by rw [← inv_lt_inv_iff, inv_inv]
alias lt_inv' ↔ lt_inv_of_lt_inv _
attribute [to_additive] lt_inv_of_lt_inv
alias inv_lt' ↔ inv_lt_of_inv_lt _
attribute [to_additive] inv_lt_of_inv_lt
@[to_additive]
lemma mul_inv_lt_inv_mul_iff : a * b⁻¹ < d⁻¹ * c ↔ d * a < c * b :=
by rw [← mul_lt_mul_iff_left d, ← mul_lt_mul_iff_right b, mul_inv_cancel_left, mul_assoc,
inv_mul_cancel_right]
@[simp, to_additive] lemma div_lt_self_iff (a : α) {b : α} : a / b < a ↔ 1 < b :=
by simp [div_eq_mul_inv]
alias sub_lt_self_iff ↔ _ sub_lt_self
end typeclasses_left_right_lt
section pre_order
variable [preorder α]
section left_le
variables [covariant_class α α (*) (≤)] {a : α}
@[to_additive]
lemma left.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a :=
le_trans (left.inv_le_one_iff.mpr h) h
alias left.neg_le_self ← neg_le_self
@[to_additive]
lemma left.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ :=
le_trans h (left.one_le_inv_iff.mpr h)
end left_le
section left_lt
variables [covariant_class α α (*) (<)] {a : α}
@[to_additive]
lemma left.inv_lt_self (h : 1 < a) : a⁻¹ < a :=
(left.inv_lt_one_iff.mpr h).trans h
alias left.neg_lt_self ← neg_lt_self
@[to_additive]
lemma left.self_lt_inv (h : a < 1) : a < a⁻¹ :=
lt_trans h (left.one_lt_inv_iff.mpr h)
end left_lt
section right_le
variables [covariant_class α α (function.swap (*)) (≤)] {a : α}
@[to_additive]
lemma right.inv_le_self (h : 1 ≤ a) : a⁻¹ ≤ a :=
le_trans (right.inv_le_one_iff.mpr h) h
@[to_additive]
lemma right.self_le_inv (h : a ≤ 1) : a ≤ a⁻¹ :=
le_trans h (right.one_le_inv_iff.mpr h)
end right_le
section right_lt
variables [covariant_class α α (function.swap (*)) (<)] {a : α}
@[to_additive]
lemma right.inv_lt_self (h : 1 < a) : a⁻¹ < a :=
(right.inv_lt_one_iff.mpr h).trans h
@[to_additive]
lemma right.self_lt_inv (h : a < 1) : a < a⁻¹ :=
lt_trans h (right.one_lt_inv_iff.mpr h)
end right_lt
end pre_order
end group
section comm_group
variables [comm_group α]
section has_le
variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α}
@[to_additive]
lemma inv_mul_le_iff_le_mul' : c⁻¹ * a ≤ b ↔ a ≤ b * c :=
by rw [inv_mul_le_iff_le_mul, mul_comm]
@[simp, to_additive]
lemma mul_inv_le_iff_le_mul' : a * b⁻¹ ≤ c ↔ a ≤ b * c :=
by rw [← inv_mul_le_iff_le_mul, mul_comm]
@[to_additive add_neg_le_add_neg_iff]
lemma mul_inv_le_mul_inv_iff' : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b :=
by rw [mul_comm c, mul_inv_le_inv_mul_iff, mul_comm]
end has_le
section has_lt
variables [has_lt α] [covariant_class α α (*) (<)] {a b c d : α}
@[to_additive]
lemma inv_mul_lt_iff_lt_mul' : c⁻¹ * a < b ↔ a < b * c :=
by rw [inv_mul_lt_iff_lt_mul, mul_comm]
@[simp, to_additive]
lemma mul_inv_lt_iff_le_mul' : a * b⁻¹ < c ↔ a < b * c :=
by rw [← inv_mul_lt_iff_lt_mul, mul_comm]
@[to_additive add_neg_lt_add_neg_iff]
lemma mul_inv_lt_mul_inv_iff' : a * b⁻¹ < c * d⁻¹ ↔ a * d < c * b :=
by rw [mul_comm c, mul_inv_lt_inv_mul_iff, mul_comm]
end has_lt
end comm_group
alias le_inv' ↔ le_inv_of_le_inv _
attribute [to_additive] le_inv_of_le_inv
alias left.inv_le_one_iff ↔ one_le_of_inv_le_one _
attribute [to_additive] one_le_of_inv_le_one
alias left.one_le_inv_iff ↔ le_one_of_one_le_inv _
attribute [to_additive nonpos_of_neg_nonneg] le_one_of_one_le_inv
alias inv_lt_inv_iff ↔ lt_of_inv_lt_inv _
attribute [to_additive] lt_of_inv_lt_inv
alias left.inv_lt_one_iff ↔ one_lt_of_inv_lt_one _
attribute [to_additive] one_lt_of_inv_lt_one
alias left.inv_lt_one_iff ← inv_lt_one_iff_one_lt
attribute [to_additive] inv_lt_one_iff_one_lt
alias left.inv_lt_one_iff ← inv_lt_one'
attribute [to_additive neg_lt_zero] inv_lt_one'
alias left.one_lt_inv_iff ↔ inv_of_one_lt_inv _
attribute [to_additive neg_of_neg_pos] inv_of_one_lt_inv
alias left.one_lt_inv_iff ↔ _ one_lt_inv_of_inv
attribute [to_additive neg_pos_of_neg] one_lt_inv_of_inv
alias le_inv_mul_iff_mul_le ↔ mul_le_of_le_inv_mul _
attribute [to_additive] mul_le_of_le_inv_mul
alias le_inv_mul_iff_mul_le ↔ _ le_inv_mul_of_mul_le
attribute [to_additive] le_inv_mul_of_mul_le
alias inv_mul_le_iff_le_mul ↔ _ inv_mul_le_of_le_mul
attribute [to_additive] inv_mul_le_iff_le_mul
alias lt_inv_mul_iff_mul_lt ↔ mul_lt_of_lt_inv_mul _
attribute [to_additive] mul_lt_of_lt_inv_mul
alias lt_inv_mul_iff_mul_lt ↔ _ lt_inv_mul_of_mul_lt
attribute [to_additive] lt_inv_mul_of_mul_lt
alias inv_mul_lt_iff_lt_mul ↔ lt_mul_of_inv_mul_lt inv_mul_lt_of_lt_mul
attribute [to_additive] lt_mul_of_inv_mul_lt
attribute [to_additive] inv_mul_lt_of_lt_mul
alias lt_mul_of_inv_mul_lt ← lt_mul_of_inv_mul_lt_left
attribute [to_additive] lt_mul_of_inv_mul_lt_left
alias left.inv_le_one_iff ← inv_le_one'
attribute [to_additive neg_nonpos] inv_le_one'
alias left.one_le_inv_iff ← one_le_inv'
attribute [to_additive neg_nonneg] one_le_inv'
alias left.one_lt_inv_iff ← one_lt_inv'
attribute [to_additive neg_pos] one_lt_inv'
alias mul_lt_mul_left' ← ordered_comm_group.mul_lt_mul_left'
attribute [to_additive ordered_add_comm_group.add_lt_add_left] ordered_comm_group.mul_lt_mul_left'
alias le_of_mul_le_mul_left' ← ordered_comm_group.le_of_mul_le_mul_left
attribute [to_additive ordered_add_comm_group.le_of_add_le_add_left]
ordered_comm_group.le_of_mul_le_mul_left
alias lt_of_mul_lt_mul_left' ← ordered_comm_group.lt_of_mul_lt_mul_left
attribute [to_additive ordered_add_comm_group.lt_of_add_lt_add_left]
ordered_comm_group.lt_of_mul_lt_mul_left
/-- Pullback an `ordered_comm_group` under an injective map.
See note [reducible non-instances]. -/
@[reducible, to_additive function.injective.ordered_add_comm_group
"Pullback an `ordered_add_comm_group` under an injective map."]
def function.injective.ordered_comm_group [ordered_comm_group α] {β : Type*}
[has_one β] [has_mul β] [has_inv β] [has_div β]
(f : β → α) (hf : function.injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
ordered_comm_group β :=
{ ..partial_order.lift f hf,
..hf.ordered_comm_monoid f one mul,
..hf.comm_group f one mul inv div }
/- Most of the lemmas that are primed in this section appear in ordered_field. -/
/- I (DT) did not try to minimise the assumptions. -/
section group
variables [group α] [has_le α]
section right
variables [covariant_class α α (function.swap (*)) (≤)] {a b c d : α}
@[simp, to_additive]
lemma div_le_div_iff_right (c : α) : a / c ≤ b / c ↔ a ≤ b :=
by simpa only [div_eq_mul_inv] using mul_le_mul_iff_right _
@[to_additive sub_le_sub_right]
lemma div_le_div_right' (h : a ≤ b) (c : α) : a / c ≤ b / c :=
(div_le_div_iff_right c).2 h
@[simp, to_additive sub_nonneg]
lemma one_le_div' : 1 ≤ a / b ↔ b ≤ a :=
by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias sub_nonneg ↔ le_of_sub_nonneg sub_nonneg_of_le
@[simp, to_additive sub_nonpos]
lemma div_le_one' : a / b ≤ 1 ↔ a ≤ b :=
by rw [← mul_le_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias sub_nonpos ↔ le_of_sub_nonpos sub_nonpos_of_le
@[to_additive]
lemma le_div_iff_mul_le : a ≤ c / b ↔ a * b ≤ c :=
by rw [← mul_le_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]
alias le_sub_iff_add_le ↔ add_le_of_le_sub_right le_sub_right_of_add_le
@[to_additive]
lemma div_le_iff_le_mul : a / c ≤ b ↔ a ≤ b * c :=
by rw [← mul_le_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]
/-- `equiv.mul_right` as an `order_iso`. -/
@[to_additive "`equiv.add_right` as an `order_iso`.", simps to_equiv apply {simp_rhs := tt}]
def order_iso.mul_right (a : α) : α ≃o α :=
{ map_rel_iff' := λ _ _, mul_le_mul_iff_right a, to_equiv := equiv.mul_right a }
@[simp, to_additive] lemma order_iso.mul_right_symm (a : α) :
(order_iso.mul_right a).symm = order_iso.mul_right a⁻¹ :=
by { ext x, refl }
end right
section left
variables [covariant_class α α (*) (≤)]
/-- `equiv.mul_left` as an `order_iso`. -/
@[to_additive "`equiv.add_left` as an `order_iso`.", simps to_equiv apply {simp_rhs := tt}]
def order_iso.mul_left (a : α) : α ≃o α :=
{ map_rel_iff' := λ _ _, mul_le_mul_iff_left a, to_equiv := equiv.mul_left a }
@[simp, to_additive] lemma order_iso.mul_left_symm (a : α) :
(order_iso.mul_left a).symm = order_iso.mul_left a⁻¹ :=
by { ext x, refl }
variables [covariant_class α α (function.swap (*)) (≤)] {a b c : α}
@[simp, to_additive]
lemma div_le_div_iff_left (a : α) : a / b ≤ a / c ↔ c ≤ b :=
by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_le_mul_iff_left a⁻¹, inv_mul_cancel_left,
inv_mul_cancel_left, inv_le_inv_iff]
@[to_additive sub_le_sub_left]
lemma div_le_div_left' (h : a ≤ b) (c : α) : c / b ≤ c / a :=
(div_le_div_iff_left c).2 h
end left
end group
section comm_group
variables [comm_group α]
section has_le
variables [has_le α] [covariant_class α α (*) (≤)] {a b c d : α}
@[to_additive sub_le_sub_iff]
lemma div_le_div_iff' : a / b ≤ c / d ↔ a * d ≤ c * b :=
by simpa only [div_eq_mul_inv] using mul_inv_le_mul_inv_iff'
@[to_additive]
lemma le_div_iff_mul_le' : b ≤ c / a ↔ a * b ≤ c :=
by rw [le_div_iff_mul_le, mul_comm]
alias le_sub_iff_add_le' ↔ add_le_of_le_sub_left le_sub_left_of_add_le
@[to_additive]
lemma div_le_iff_le_mul' : a / b ≤ c ↔ a ≤ b * c :=
by rw [div_le_iff_le_mul, mul_comm]
alias sub_le_iff_le_add' ↔ le_add_of_sub_left_le sub_left_le_of_le_add
@[simp, to_additive]
lemma inv_le_div_iff_le_mul : b⁻¹ ≤ a / c ↔ c ≤ a * b :=
le_div_iff_mul_le.trans inv_mul_le_iff_le_mul'
@[to_additive]
lemma inv_le_div_iff_le_mul' : a⁻¹ ≤ b / c ↔ c ≤ a * b :=
by rw [inv_le_div_iff_le_mul, mul_comm]
@[to_additive sub_le]
lemma div_le'' : a / b ≤ c ↔ a / c ≤ b :=
div_le_iff_le_mul'.trans div_le_iff_le_mul.symm
@[to_additive le_sub]
lemma le_div'' : a ≤ b / c ↔ c ≤ b / a :=
le_div_iff_mul_le'.trans le_div_iff_mul_le.symm
end has_le
section preorder
variables [preorder α] [covariant_class α α (*) (≤)] {a b c d : α}
@[to_additive sub_le_sub]
lemma div_le_div'' (hab : a ≤ b) (hcd : c ≤ d) :
a / d ≤ b / c :=
begin
rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_le_inv_mul_iff, mul_comm],
exact mul_le_mul' hab hcd
end
end preorder
end comm_group
/- Most of the lemmas that are primed in this section appear in ordered_field. -/
/- I (DT) did not try to minimise the assumptions. -/
section group
variables [group α] [has_lt α]
section right
variables [covariant_class α α (function.swap (*)) (<)] {a b c d : α}
@[simp, to_additive]
lemma div_lt_div_iff_right (c : α) : a / c < b / c ↔ a < b :=
by simpa only [div_eq_mul_inv] using mul_lt_mul_iff_right _
@[to_additive sub_lt_sub_right]
lemma div_lt_div_right' (h : a < b) (c : α) : a / c < b / c :=
(div_lt_div_iff_right c).2 h
@[simp, to_additive sub_pos]
lemma one_lt_div' : 1 < a / b ↔ b < a :=
by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias sub_pos ↔ lt_of_sub_pos sub_pos_of_lt
@[simp, to_additive sub_neg]
lemma div_lt_one' : a / b < 1 ↔ a < b :=
by rw [← mul_lt_mul_iff_right b, one_mul, div_eq_mul_inv, inv_mul_cancel_right]
alias sub_neg ↔ lt_of_sub_neg sub_neg_of_lt
alias sub_neg ← sub_lt_zero
@[to_additive]
lemma lt_div_iff_mul_lt : a < c / b ↔ a * b < c :=
by rw [← mul_lt_mul_iff_right b, div_eq_mul_inv, inv_mul_cancel_right]
alias lt_sub_iff_add_lt ↔ add_lt_of_lt_sub_right lt_sub_right_of_add_lt
@[to_additive]
lemma div_lt_iff_lt_mul : a / c < b ↔ a < b * c :=
by rw [← mul_lt_mul_iff_right c, div_eq_mul_inv, inv_mul_cancel_right]
alias sub_lt_iff_lt_add ↔ lt_add_of_sub_right_lt sub_right_lt_of_lt_add
end right
section left
variables [covariant_class α α (*) (<)] [covariant_class α α (function.swap (*)) (<)] {a b c : α}
@[simp, to_additive]
lemma div_lt_div_iff_left (a : α) : a / b < a / c ↔ c < b :=
by rw [div_eq_mul_inv, div_eq_mul_inv, ← mul_lt_mul_iff_left a⁻¹, inv_mul_cancel_left,
inv_mul_cancel_left, inv_lt_inv_iff]
@[simp, to_additive]
lemma inv_lt_div_iff_lt_mul : a⁻¹ < b / c ↔ c < a * b :=
by rw [div_eq_mul_inv, lt_mul_inv_iff_mul_lt, inv_mul_lt_iff_lt_mul]
@[to_additive sub_lt_sub_left]
lemma div_lt_div_left' (h : a < b) (c : α) : c / b < c / a :=
(div_lt_div_iff_left c).2 h
end left
end group
section comm_group
variables [comm_group α]
section has_lt
variables [has_lt α] [covariant_class α α (*) (<)] {a b c d : α}
@[to_additive sub_lt_sub_iff]
lemma div_lt_div_iff' : a / b < c / d ↔ a * d < c * b :=
by simpa only [div_eq_mul_inv] using mul_inv_lt_mul_inv_iff'
@[to_additive]
lemma lt_div_iff_mul_lt' : b < c / a ↔ a * b < c :=
by rw [lt_div_iff_mul_lt, mul_comm]
alias lt_sub_iff_add_lt' ↔ add_lt_of_lt_sub_left lt_sub_left_of_add_lt
@[to_additive]
lemma div_lt_iff_lt_mul' : a / b < c ↔ a < b * c :=
by rw [div_lt_iff_lt_mul, mul_comm]
alias sub_lt_iff_lt_add' ↔ lt_add_of_sub_left_lt sub_left_lt_of_lt_add
@[to_additive]
lemma inv_lt_div_iff_lt_mul' : b⁻¹ < a / c ↔ c < a * b :=
lt_div_iff_mul_lt.trans inv_mul_lt_iff_lt_mul'
@[to_additive sub_lt]
lemma div_lt'' : a / b < c ↔ a / c < b :=
div_lt_iff_lt_mul'.trans div_lt_iff_lt_mul.symm
@[to_additive lt_sub]
lemma lt_div'' : a < b / c ↔ c < b / a :=
lt_div_iff_mul_lt'.trans lt_div_iff_mul_lt.symm
end has_lt
section preorder
variables [preorder α] [covariant_class α α (*) (<)] {a b c d : α}
@[to_additive sub_lt_sub]
lemma div_lt_div'' (hab : a < b) (hcd : c < d) :
a / d < b / c :=
begin
rw [div_eq_mul_inv, div_eq_mul_inv, mul_comm b, mul_inv_lt_inv_mul_iff, mul_comm],
exact mul_lt_mul_of_lt_of_lt hab hcd
end
end preorder
end comm_group
section linear_order
variables [group α] [linear_order α] [covariant_class α α (*) (≤)]
section variable_names
variables {a b c : α}
@[to_additive]
lemma le_of_forall_one_lt_lt_mul (h : ∀ ε : α, 1 < ε → a < b * ε) : a ≤ b :=
le_of_not_lt (λ h₁, lt_irrefl a (by simpa using (h _ (lt_inv_mul_iff_lt.mpr h₁))))
@[to_additive]
lemma le_iff_forall_one_lt_lt_mul : a ≤ b ↔ ∀ ε, 1 < ε → a < b * ε :=
⟨λ h ε, lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul⟩
/- I (DT) introduced this lemma to prove (the additive version `sub_le_sub_flip` of)
`div_le_div_flip` below. Now I wonder what is the point of either of these lemmas... -/
@[to_additive]
lemma div_le_inv_mul_iff [covariant_class α α (function.swap (*)) (≤)] :
a / b ≤ a⁻¹ * b ↔ a ≤ b :=
begin
rw [div_eq_mul_inv, mul_inv_le_inv_mul_iff],
exact ⟨λ h, not_lt.mp (λ k, not_lt.mpr h (mul_lt_mul''' k k)), λ h, mul_le_mul' h h⟩,
end
/- What is the point of this lemma? See comment about `div_le_inv_mul_iff` above. -/
@[simp, to_additive]
lemma div_le_div_flip {α : Type*} [comm_group α] [linear_order α] [covariant_class α α (*) (≤)]
{a b : α}:
a / b ≤ b / a ↔ a ≤ b :=
begin
rw [div_eq_mul_inv b, mul_comm],
exact div_le_inv_mul_iff,
end
@[simp, to_additive] lemma max_one_div_max_inv_one_eq_self (a : α) :
max a 1 / max a⁻¹ 1 = a :=
by { rcases le_total a 1 with h|h; simp [h] }
alias max_zero_sub_max_neg_zero_eq_self ← max_zero_sub_eq_self
end variable_names
section densely_ordered
variables [densely_ordered α] {a b c : α}
@[to_additive]
lemma le_of_forall_one_lt_le_mul (h : ∀ ε : α, 1 < ε → a ≤ b * ε) : a ≤ b :=
le_of_forall_le_of_dense $ λ c hc,
calc a ≤ b * (b⁻¹ * c) : h _ (lt_inv_mul_iff_lt.mpr hc)
... = c : mul_inv_cancel_left b c
@[to_additive]
lemma le_iff_forall_one_lt_le_mul : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε :=
⟨λ h ε ε_pos, le_mul_of_le_of_one_le h ε_pos.le, le_of_forall_one_lt_le_mul⟩
end densely_ordered
end linear_order
/-!
### Linearly ordered commutative groups
-/
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
@[protect_proj, ancestor ordered_add_comm_group linear_order]
class linear_ordered_add_comm_group (α : Type u) extends ordered_add_comm_group α, linear_order α
/-- A linearly ordered commutative monoid with an additively absorbing `⊤` element.
Instances should include number systems with an infinite element adjoined.` -/
@[protect_proj, ancestor linear_ordered_add_comm_monoid_with_top sub_neg_monoid nontrivial]
class linear_ordered_add_comm_group_with_top (α : Type*)
extends linear_ordered_add_comm_monoid_with_top α, sub_neg_monoid α, nontrivial α :=
(neg_top : - (⊤ : α) = ⊤)
(add_neg_cancel : ∀ a:α, a ≠ ⊤ → a + (- a) = 0)
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[protect_proj, ancestor ordered_comm_group linear_order, to_additive]
class linear_ordered_comm_group (α : Type u) extends ordered_comm_group α, linear_order α
section linear_ordered_comm_group
variables [linear_ordered_comm_group α] {a b c : α}
@[priority 100, to_additive] -- see Note [lower instance priority]
instance linear_ordered_comm_group.to_linear_ordered_cancel_comm_monoid :
linear_ordered_cancel_comm_monoid α :=
{ le_of_mul_le_mul_left := λ x y z, le_of_mul_le_mul_left',
mul_left_cancel := λ x y z, mul_left_cancel,
..‹linear_ordered_comm_group α› }
/-- Pullback a `linear_ordered_comm_group` under an injective map.
See note [reducible non-instances]. -/
@[reducible, to_additive function.injective.linear_ordered_add_comm_group
"Pullback a `linear_ordered_add_comm_group` under an injective map."]
def function.injective.linear_ordered_comm_group {β : Type*}
[has_one β] [has_mul β] [has_inv β] [has_div β]
(f : β → α) (hf : function.injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
linear_ordered_comm_group β :=
{ ..linear_order.lift f hf,
..hf.ordered_comm_group f one mul inv div }
@[to_additive linear_ordered_add_comm_group.add_lt_add_left]
lemma linear_ordered_comm_group.mul_lt_mul_left'
(a b : α) (h : a < b) (c : α) : c * a < c * b :=
mul_lt_mul_left' h c
@[to_additive min_neg_neg]
lemma min_inv_inv' (a b : α) : min (a⁻¹) (b⁻¹) = (max a b)⁻¹ :=
eq.symm $ @monotone.map_max α (order_dual α) _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr
@[to_additive max_neg_neg]
lemma max_inv_inv' (a b : α) : max (a⁻¹) (b⁻¹) = (min a b)⁻¹ :=
eq.symm $ @monotone.map_min α (order_dual α) _ _ has_inv.inv a b $ λ a b, inv_le_inv_iff.mpr
@[to_additive min_sub_sub_right]
lemma min_div_div_right' (a b c : α) : min (a / c) (b / c) = min a b / c :=
by simpa only [div_eq_mul_inv] using min_mul_mul_right a b (c⁻¹)
@[to_additive max_sub_sub_right]
lemma max_div_div_right' (a b c : α) : max (a / c) (b / c) = max a b / c :=
by simpa only [div_eq_mul_inv] using max_mul_mul_right a b (c⁻¹)
@[to_additive min_sub_sub_left]
lemma min_div_div_left' (a b c : α) : min (a / b) (a / c) = a / max b c :=
by simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']
@[to_additive max_sub_sub_left]
lemma max_div_div_left' (a b c : α) : max (a / b) (a / c) = a / min b c :=
by simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']
@[to_additive eq_zero_of_neg_eq]
lemma eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 :=
match lt_trichotomy a 1 with
| or.inl h₁ :=
have 1 < a, from h ▸ one_lt_inv_of_inv h₁,
absurd h₁ this.asymm
| or.inr (or.inl h₁) := h₁
| or.inr (or.inr h₁) :=
have a < 1, from h ▸ inv_lt_one'.mpr h₁,
absurd h₁ this.asymm
end
@[to_additive exists_zero_lt]
lemma exists_one_lt' [nontrivial α] : ∃ (a:α), 1 < a :=
begin
obtain ⟨y, hy⟩ := decidable.exists_ne (1 : α),
cases hy.lt_or_lt,
{ exact ⟨y⁻¹, one_lt_inv'.mpr h⟩ },
{ exact ⟨y, h⟩ }
end
@[priority 100, to_additive] -- see Note [lower instance priority]
instance linear_ordered_comm_group.to_no_top_order [nontrivial α] :
no_top_order α :=
⟨ begin
obtain ⟨y, hy⟩ : ∃ (a:α), 1 < a := exists_one_lt',
exact λ a, ⟨a * y, lt_mul_of_one_lt_right' a hy⟩
end ⟩
@[priority 100, to_additive] -- see Note [lower instance priority]
instance linear_ordered_comm_group.to_no_bot_order [nontrivial α] : no_bot_order α :=
⟨ begin
obtain ⟨y, hy⟩ : ∃ (a:α), 1 < a := exists_one_lt',
exact λ a, ⟨a / y, (div_lt_self_iff a).mpr hy⟩
end ⟩
end linear_ordered_comm_group
section covariant_add_le
section has_neg
variables [has_neg α] [linear_order α] {a b: α}
/-- `abs a` is the absolute value of `a`. -/
def abs {α : Type*} [has_neg α] [linear_order α] (a : α) : α := max a (-a)
lemma abs_choice (x : α) : abs x = x ∨ abs x = -x := max_choice _ _
lemma abs_le' : abs a ≤ b ↔ a ≤ b ∧ -a ≤ b := max_le_iff
lemma le_abs : a ≤ abs b ↔ a ≤ b ∨ a ≤ -b := le_max_iff
lemma le_abs_self (a : α) : a ≤ abs a := le_max_left _ _
lemma neg_le_abs_self (a : α) : -a ≤ abs a := le_max_right _ _
lemma lt_abs : a < abs b ↔ a < b ∨ a < -b := lt_max_iff
theorem abs_le_abs (h₀ : a ≤ b) (h₁ : -a ≤ b) : abs a ≤ abs b :=
(abs_le'.2 ⟨h₀, h₁⟩).trans (le_abs_self b)
lemma abs_by_cases (P : α → Prop) {a : α} (h1 : P a) (h2 : P (-a)) : P (abs a) :=
sup_ind _ _ h1 h2
end has_neg
section add_group
variables [add_group α] [linear_order α]
@[simp] lemma abs_neg (a : α) : abs (-a) = abs a :=
begin unfold abs, rw [max_comm, neg_neg] end
lemma eq_or_eq_neg_of_abs_eq {a b : α} (h : abs a = b) : a = b ∨ a = -b :=
by simpa only [← h, eq_comm, eq_neg_iff_eq_neg] using abs_choice a
lemma abs_eq_abs {a b : α} : abs a = abs b ↔ a = b ∨ a = -b :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ obtain rfl | rfl := eq_or_eq_neg_of_abs_eq h;
simpa only [neg_eq_iff_neg_eq, neg_inj, or.comm, @eq_comm _ (-b)] using abs_choice b },
{ cases h; simp only [h, abs_neg] },
end
lemma abs_sub_comm (a b : α) : abs (a - b) = abs (b - a) :=
calc abs (a - b) = abs (- (b - a)) : congr_arg _ (neg_sub b a).symm
... = abs (b - a) : abs_neg (b - a)
variables [covariant_class α α (+) (≤)] {a b c : α}
lemma abs_of_nonneg (h : 0 ≤ a) : abs a = a :=
max_eq_left $ (neg_nonpos.2 h).trans h
lemma abs_of_pos (h : 0 < a) : abs a = a :=
abs_of_nonneg h.le
lemma abs_of_nonpos (h : a ≤ 0) : abs a = -a :=
max_eq_right $ h.trans (neg_nonneg.2 h)
lemma abs_of_neg (h : a < 0) : abs a = -a :=
abs_of_nonpos h.le
@[simp] lemma abs_zero : abs 0 = (0:α) :=
abs_of_nonneg le_rfl
@[simp] lemma abs_pos : 0 < abs a ↔ a ≠ 0 :=
begin
rcases lt_trichotomy a 0 with (ha|rfl|ha),
{ simp [abs_of_neg ha, neg_pos, ha.ne, ha] },
{ simp },
{ simp [abs_of_pos ha, ha, ha.ne.symm] }
end
lemma abs_pos_of_pos (h : 0 < a) : 0 < abs a := abs_pos.2 h.ne.symm
lemma abs_pos_of_neg (h : a < 0) : 0 < abs a := abs_pos.2 h.ne
lemma neg_abs_le_self (a : α) : -abs a ≤ a :=
begin
cases le_total 0 a with h h,
{ calc -abs a = - a : congr_arg (has_neg.neg) (abs_of_nonneg h)
... ≤ 0 : neg_nonpos.mpr h
... ≤ a : h },
{ calc -abs a = - - a : congr_arg (has_neg.neg) (abs_of_nonpos h)
... ≤ a : (neg_neg a).le }
end
lemma abs_nonneg (a : α) : 0 ≤ abs a :=
(le_total 0 a).elim (λ h, h.trans (le_abs_self a)) (λ h, (neg_nonneg.2 h).trans $ neg_le_abs_self a)
@[simp] lemma abs_abs (a : α) : abs (abs a) = abs a :=
abs_of_nonneg $ abs_nonneg a
@[simp] lemma abs_eq_zero : abs a = 0 ↔ a = 0 :=
decidable.not_iff_not.1 $ ne_comm.trans $ (abs_nonneg a).lt_iff_ne.symm.trans abs_pos
@[simp] lemma abs_nonpos_iff {a : α} : abs a ≤ 0 ↔ a = 0 :=
(abs_nonneg a).le_iff_eq.trans abs_eq_zero
variable [covariant_class α α (function.swap (+)) (≤)]
lemma abs_lt : abs a < b ↔ - b < a ∧ a < b :=
max_lt_iff.trans $ and.comm.trans $ by rw [neg_lt]
lemma neg_lt_of_abs_lt (h : abs a < b) : -b < a := (abs_lt.mp h).1
lemma lt_of_abs_lt (h : abs a < b) : a < b := (abs_lt.mp h).2
lemma max_sub_min_eq_abs' (a b : α) : max a b - min a b = abs (a - b) :=
begin
cases le_total a b with ab ba,
{ rw [max_eq_right ab, min_eq_left ab, abs_of_nonpos, neg_sub], rwa sub_nonpos },
{ rw [max_eq_left ba, min_eq_right ba, abs_of_nonneg], rwa sub_nonneg }
end
lemma max_sub_min_eq_abs (a b : α) : max a b - min a b = abs (b - a) :=
by { rw abs_sub_comm, exact max_sub_min_eq_abs' _ _ }
end add_group
section add_comm_group
variables [add_comm_group α] [linear_order α] [covariant_class α α (+) (≤)] {a b c d : α}
lemma abs_le : abs a ≤ b ↔ - b ≤ a ∧ a ≤ b :=
by rw [abs_le', and.comm, neg_le]
lemma neg_le_of_abs_le (h : abs a ≤ b) : -b ≤ a := (abs_le.mp h).1
lemma le_of_abs_le (h : abs a ≤ b) : a ≤ b := (abs_le.mp h).2
/--
The **triangle inequality** in `linear_ordered_add_comm_group`s.
-/
lemma abs_add (a b : α) : abs (a + b) ≤ abs a + abs b :=
abs_le.2 ⟨(neg_add (abs a) (abs b)).symm ▸
add_le_add (neg_le.2 $ neg_le_abs_self _) (neg_le.2 $ neg_le_abs_self _),
add_le_add (le_abs_self _) (le_abs_self _)⟩
theorem abs_sub (a b : α) :
abs (a - b) ≤ abs a + abs b :=
by { rw [sub_eq_add_neg, ←abs_neg b], exact abs_add a _ }
lemma abs_sub_le_iff : abs (a - b) ≤ c ↔ a - b ≤ c ∧ b - a ≤ c :=
by rw [abs_le, neg_le_sub_iff_le_add, sub_le_iff_le_add', and_comm, sub_le_iff_le_add']
lemma abs_sub_lt_iff : abs (a - b) < c ↔ a - b < c ∧ b - a < c :=
by rw [abs_lt, neg_lt_sub_iff_lt_add', sub_lt_iff_lt_add', and_comm, sub_lt_iff_lt_add']
lemma sub_le_of_abs_sub_le_left (h : abs (a - b) ≤ c) : b - c ≤ a :=
sub_le.1 $ (abs_sub_le_iff.1 h).2
lemma sub_le_of_abs_sub_le_right (h : abs (a - b) ≤ c) : a - c ≤ b :=
sub_le_of_abs_sub_le_left (abs_sub_comm a b ▸ h)
lemma sub_lt_of_abs_sub_lt_left (h : abs (a - b) < c) : b - c < a :=
sub_lt.1 $ (abs_sub_lt_iff.1 h).2
lemma sub_lt_of_abs_sub_lt_right (h : abs (a - b) < c) : a - c < b :=
sub_lt_of_abs_sub_lt_left (abs_sub_comm a b ▸ h)
lemma abs_sub_abs_le_abs_sub (a b : α) : abs a - abs b ≤ abs (a - b) :=
sub_le_iff_le_add.2 $
calc abs a = abs (a - b + b) : by rw [sub_add_cancel]
... ≤ abs (a - b) + abs b : abs_add _ _
lemma abs_abs_sub_abs_le_abs_sub (a b : α) : abs (abs a - abs b) ≤ abs (a - b) :=
abs_sub_le_iff.2 ⟨abs_sub_abs_le_abs_sub _ _, by rw abs_sub_comm; apply abs_sub_abs_le_abs_sub⟩
lemma abs_eq (hb : 0 ≤ b) : abs a = b ↔ a = b ∨ a = -b :=
begin
refine ⟨eq_or_eq_neg_of_abs_eq, _⟩,
rintro (rfl|rfl); simp only [abs_neg, abs_of_nonneg hb]
end
lemma abs_le_max_abs_abs (hab : a ≤ b) (hbc : b ≤ c) : abs b ≤ max (abs a) (abs c) :=
abs_le'.2
⟨by simp [hbc.trans (le_abs_self c)],
by simp [(neg_le_neg_iff.mpr hab).trans (neg_le_abs_self a)]⟩
lemma eq_of_abs_sub_eq_zero {a b : α} (h : abs (a - b) = 0) : a = b :=
sub_eq_zero.1 $ abs_eq_zero.1 h
lemma abs_sub_le (a b c : α) : abs (a - c) ≤ abs (a - b) + abs (b - c) :=
calc
abs (a - c) = abs (a - b + (b - c)) : by rw [sub_add_sub_cancel]
... ≤ abs (a - b) + abs (b - c) : abs_add _ _
lemma abs_add_three (a b c : α) : abs (a + b + c) ≤ abs a + abs b + abs c :=
(abs_add _ _).trans (add_le_add_right (abs_add _ _) _)
lemma dist_bdd_within_interval {a b lb ub : α} (hal : lb ≤ a) (hau : a ≤ ub)
(hbl : lb ≤ b) (hbu : b ≤ ub) : abs (a - b) ≤ ub - lb :=
abs_sub_le_iff.2 ⟨sub_le_sub hau hbl, sub_le_sub hbu hal⟩
lemma eq_of_abs_sub_nonpos (h : abs (a - b) ≤ 0) : a = b :=
eq_of_abs_sub_eq_zero (le_antisymm h (abs_nonneg (a - b)))
lemma abs_max_sub_max_le_abs (a b c : α) : abs (max a c - max b c) ≤ abs (a - b) :=
begin
simp_rw [abs_le, le_sub_iff_add_le, sub_le_iff_le_add, ← max_add_add_left],
split; apply max_le_max; simp only [← le_sub_iff_add_le, ← sub_le_iff_le_add, sub_self, neg_le,
neg_le_abs_self, neg_zero, abs_nonneg, le_abs_self]
end
end add_comm_group
end covariant_add_le
section linear_ordered_add_comm_group
variable [linear_ordered_add_comm_group α]
instance with_top.linear_ordered_add_comm_group_with_top :
linear_ordered_add_comm_group_with_top (with_top α) :=
{ neg := option.map (λ a : α, -a),
neg_top := @option.map_none _ _ (λ a : α, -a),
add_neg_cancel := begin
rintro (a | a) ha,
{ exact (ha rfl).elim },
{ exact with_top.coe_add.symm.trans (with_top.coe_eq_coe.2 (add_neg_self a)) }
end,
.. with_top.linear_ordered_add_comm_monoid_with_top,
.. option.nontrivial }
end linear_ordered_add_comm_group
/-- This is not so much a new structure as a construction mechanism
for ordered groups, by specifying only the "positive cone" of the group. -/
class nonneg_add_comm_group (α : Type*) extends add_comm_group α :=
(nonneg : α → Prop)
(pos : α → Prop := λ a, nonneg a ∧ ¬ nonneg (neg a))
(pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬ nonneg (-a) . order_laws_tac)
(zero_nonneg : nonneg 0)
(add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b))
(nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0)
namespace nonneg_add_comm_group
variable [s : nonneg_add_comm_group α]
include s
@[reducible, priority 100] -- see Note [lower instance priority]
instance to_ordered_add_comm_group : ordered_add_comm_group α :=
{ le := λ a b, nonneg (b - a),
lt := λ a b, pos (b - a),
lt_iff_le_not_le := λ a b, by simp; rw [pos_iff]; simp,
le_refl := λ a, by simp [zero_nonneg],
le_trans := λ a b c nab nbc, by simp [-sub_eq_add_neg];
rw ← sub_add_sub_cancel; exact add_nonneg nbc nab,
le_antisymm := λ a b nab nba, eq_of_sub_eq_zero $
nonneg_antisymm nba (by rw neg_sub; exact nab),
add_le_add_left := λ a b nab c, by simpa [(≤), preorder.le] using nab,
..s }
theorem nonneg_def {a : α} : nonneg a ↔ 0 ≤ a :=
show _ ↔ nonneg _, by simp
theorem pos_def {a : α} : pos a ↔ 0 < a :=
show _ ↔ pos _, by simp
theorem not_zero_pos : ¬ pos (0 : α) :=
mt pos_def.1 (lt_irrefl _)
theorem zero_lt_iff_nonneg_nonneg {a : α} :
0 < a ↔ nonneg a ∧ ¬ nonneg (-a) :=
pos_def.symm.trans (pos_iff _)
theorem nonneg_total_iff :
(∀ a : α, nonneg a ∨ nonneg (-a)) ↔
(∀ a b : α, a ≤ b ∨ b ≤ a) :=
⟨λ h a b, by have := h (b - a); rwa [neg_sub] at this,
λ h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h⟩
/--
A `nonneg_add_comm_group` is a `linear_ordered_add_comm_group`
if `nonneg` is total and decidable.
-/
def to_linear_ordered_add_comm_group
[decidable_pred (@nonneg α _)]
(nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a))
: linear_ordered_add_comm_group α :=
{ le := (≤),
lt := (<),
le_total := nonneg_total_iff.1 nonneg_total,
decidable_le := by apply_instance,
decidable_lt := by apply_instance,
..@nonneg_add_comm_group.to_ordered_add_comm_group _ s }
end nonneg_add_comm_group
namespace order_dual
instance [ordered_add_comm_group α] : ordered_add_comm_group (order_dual α) :=
{ add_left_neg := λ a : α, add_left_neg a,
sub := λ a b, (a - b : α),
..order_dual.ordered_add_comm_monoid,
..show add_comm_group α, by apply_instance }
instance [linear_ordered_add_comm_group α] :
linear_ordered_add_comm_group (order_dual α) :=
{ add_le_add_left := λ a b h c, by exact add_le_add_left h _,
..order_dual.linear_order α,
..show add_comm_group α, by apply_instance }
end order_dual
namespace prod
variables {G H : Type*}
@[to_additive]
instance [ordered_comm_group G] [ordered_comm_group H] :
ordered_comm_group (G × H) :=
{ .. prod.comm_group, .. prod.partial_order G H, .. prod.ordered_cancel_comm_monoid }
end prod
section type_tags
instance [ordered_add_comm_group α] : ordered_comm_group (multiplicative α) :=
{ ..multiplicative.comm_group,
..multiplicative.ordered_comm_monoid }
instance [ordered_comm_group α] : ordered_add_comm_group (additive α) :=
{ ..additive.add_comm_group,
..additive.ordered_add_comm_monoid }
instance [linear_ordered_add_comm_group α] : linear_ordered_comm_group (multiplicative α) :=
{ ..multiplicative.linear_order,
..multiplicative.ordered_comm_group }
instance [linear_ordered_comm_group α] : linear_ordered_add_comm_group (additive α) :=
{ ..additive.linear_order,
..additive.ordered_add_comm_group }
end type_tags
section norm_num_lemmas
/- The following lemmas are stated so that the `norm_num` tactic can use them with the
expected signatures. -/
variables [ordered_comm_group α] {a b : α}
@[to_additive neg_le_neg]
lemma inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ :=
inv_le_inv_iff.mpr
@[to_additive neg_lt_neg]
lemma inv_lt_inv' : a < b → b⁻¹ < a⁻¹ :=
inv_lt_inv_iff.mpr
/- The additive version is also a `linarith` lemma. -/
@[to_additive]
theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 :=
inv_lt_one_iff_one_lt.mpr
/- The additive version is also a `linarith` lemma. -/
@[to_additive]
lemma inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 :=
inv_le_one'.mpr
@[to_additive neg_nonneg_of_nonpos]
lemma one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ :=
one_le_inv'.mpr
end norm_num_lemmas
|
70a2ee7b55dd7ac6ce0ba5200acefe8ff778deb2 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /src/Lean/Parser/Command.lean | 8284902f6ef173d523e233824f0164784b237104 | [
"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 | 9,660 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.Parser.Term
import Lean.Parser.Do
namespace Lean
namespace Parser
/--
Syntax quotation for terms and (lists of) commands. We prefer terms, so ambiguous quotations like
`($x $y) will be parsed as an application, not two commands. Use `($x:command $y:command) instead.
Multiple command will be put in a `null node, but a single command will not (so that you can directly
match against a quotation in a command kind's elaborator). -/
-- TODO: use two separate quotation parsers with parser priorities instead
@[builtinTermParser] def Term.quot := leading_parser "`(" >> incQuotDepth (termParser <|> many1Unbox commandParser) >> ")"
@[builtinTermParser] def Term.precheckedQuot := leading_parser "`" >> Term.quot
namespace Command
def namedPrio := leading_parser (atomic ("(" >> nonReservedSymbol "priority") >> " := " >> priorityParser >> ")")
def optNamedPrio := optional namedPrio
def «private» := leading_parser "private "
def «protected» := leading_parser "protected "
def visibility := «private» <|> «protected»
def «noncomputable» := leading_parser "noncomputable "
def «unsafe» := leading_parser "unsafe "
def «partial» := leading_parser "partial "
def declModifiers (inline : Bool) := leading_parser optional docComment >> optional (Term.«attributes» >> if inline then skip else ppDedent ppLine) >> optional visibility >> optional «noncomputable» >> optional «unsafe» >> optional «partial»
def declId := leading_parser ident >> optional (".{" >> sepBy1 ident ", " >> "}")
def declSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.typeSpec
def optDeclSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.optType
def declValSimple := leading_parser " :=\n" >> termParser >> optional Term.whereDecls
def declValEqns := leading_parser Term.matchAltsWhereDecls
def declVal := declValSimple <|> declValEqns <|> Term.whereDecls
def «abbrev» := leading_parser "abbrev " >> declId >> optDeclSig >> declVal
def «def» := leading_parser "def " >> declId >> optDeclSig >> declVal
def «theorem» := leading_parser "theorem " >> declId >> declSig >> declVal
def «constant» := leading_parser "constant " >> declId >> declSig >> optional declValSimple
def «instance» := leading_parser Term.attrKind >> "instance " >> optNamedPrio >> optional declId >> declSig >> declVal
def «axiom» := leading_parser "axiom " >> declId >> declSig
def «example» := leading_parser "example " >> declSig >> declVal
def inferMod := leading_parser atomic (symbol "{" >> "}")
def ctor := leading_parser "\n| " >> declModifiers true >> ident >> optional inferMod >> optDeclSig
def optDeriving := leading_parser optional (atomic ("deriving " >> notSymbol "instance") >> sepBy1 ident ", ")
def «inductive» := leading_parser "inductive " >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving
def classInductive := leading_parser atomic (group (symbol "class " >> "inductive ")) >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving
def structExplicitBinder := leading_parser atomic (declModifiers true >> "(") >> many1 ident >> optional inferMod >> optDeclSig >> optional Term.binderDefault >> ")"
def structImplicitBinder := leading_parser atomic (declModifiers true >> "{") >> many1 ident >> optional inferMod >> declSig >> "}"
def structInstBinder := leading_parser atomic (declModifiers true >> "[") >> many1 ident >> optional inferMod >> declSig >> "]"
def structSimpleBinder := leading_parser atomic (declModifiers true >> ident) >> optional inferMod >> optDeclSig >> optional Term.binderDefault
def structFields := leading_parser manyIndent (ppLine >> checkColGe >>(structExplicitBinder <|> structImplicitBinder <|> structInstBinder <|> structSimpleBinder))
def structCtor := leading_parser atomic (declModifiers true >> ident >> optional inferMod >> " :: ")
def structureTk := leading_parser "structure "
def classTk := leading_parser "class "
def «extends» := leading_parser " extends " >> sepBy1 termParser ", "
def «structure» := leading_parser
(structureTk <|> classTk) >> declId >> many Term.bracketedBinder >> optional «extends» >> Term.optType
>> optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields)
>> optDeriving
@[builtinCommandParser] def declaration := leading_parser
declModifiers false >> («abbrev» <|> «def» <|> «theorem» <|> «constant» <|> «instance» <|> «axiom» <|> «example» <|> «inductive» <|> classInductive <|> «structure»)
@[builtinCommandParser] def «deriving» := leading_parser "deriving " >> "instance " >> sepBy1 ident ", " >> " for " >> sepBy1 ident ", "
@[builtinCommandParser] def «section» := leading_parser "section " >> optional ident
@[builtinCommandParser] def «namespace» := leading_parser "namespace " >> ident
@[builtinCommandParser] def «end» := leading_parser "end " >> optional ident
@[builtinCommandParser] def «variable» := leading_parser "variable" >> many1 Term.bracketedBinder
@[builtinCommandParser] def «universe» := leading_parser "universe " >> many1 ident
@[builtinCommandParser] def check := leading_parser "#check " >> termParser
@[builtinCommandParser] def check_failure := leading_parser "#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check
@[builtinCommandParser] def reduce := leading_parser "#reduce " >> termParser
@[builtinCommandParser] def eval := leading_parser "#eval " >> termParser
@[builtinCommandParser] def synth := leading_parser "#synth " >> termParser
@[builtinCommandParser] def exit := leading_parser "#exit"
@[builtinCommandParser] def print := leading_parser "#print " >> (ident <|> strLit)
@[builtinCommandParser] def printAxioms := leading_parser "#print " >> nonReservedSymbol "axioms " >> ident
@[builtinCommandParser] def «resolve_name» := leading_parser "#resolve_name " >> ident
@[builtinCommandParser] def «init_quot» := leading_parser "init_quot"
def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit
@[builtinCommandParser] def «set_option» := leading_parser "set_option " >> ident >> ppSpace >> optionValue
def eraseAttr := leading_parser "-" >> ident
@[builtinCommandParser] def «attribute» := leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "] " >> many1 ident
@[builtinCommandParser] def «export» := leading_parser "export " >> ident >> "(" >> many1 ident >> ")"
def openHiding := leading_parser atomic (ident >> "hiding") >> many1 ident
def openRenamingItem := leading_parser ident >> unicodeSymbol "→" "->" >> ident
def openRenaming := leading_parser atomic (ident >> "renaming") >> sepBy1 openRenamingItem ", "
def openOnly := leading_parser atomic (ident >> "(") >> many1 ident >> ")"
def openSimple := leading_parser many1 ident
def openDecl := openHiding <|> openRenaming <|> openOnly <|> openSimple
@[builtinCommandParser] def «open» := leading_parser "open " >> openDecl
@[builtinCommandParser] def «mutual» := leading_parser "mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >> ppDedent (ppLine >> "end")
@[builtinCommandParser] def «initialize» := leading_parser "initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq
@[builtinCommandParser] def «builtin_initialize» := leading_parser "builtin_initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq
@[builtinCommandParser] def «in» := trailing_parser " in " >> commandParser
/-
This is an auxiliary command for generation constructor injectivity theorems for inductive types defined at `Prelude.lean`.
It is meant for bootstrapping purposes only. -/
@[builtinCommandParser] def genInjectiveTheorems := leading_parser "gen_injective_theorems% " >> ident
@[runBuiltinParserAttributeHooks] abbrev declModifiersF := declModifiers false
@[runBuiltinParserAttributeHooks] abbrev declModifiersT := declModifiers true
builtin_initialize
register_parser_alias "declModifiers" declModifiersF
register_parser_alias "nestedDeclModifiers" declModifiersT
register_parser_alias "declId" declId
register_parser_alias "declSig" declSig
register_parser_alias "declVal" declVal
register_parser_alias "optDeclSig" optDeclSig
register_parser_alias "openDecl" openDecl
end Command
namespace Term
@[builtinTermParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> " in " >> termParser
@[builtinTermParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> termParser
end Term
namespace Tactic
@[builtinTacticParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> " in " >> tacticSeq
@[builtinTacticParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> tacticSeq
end Tactic
end Parser
end Lean
|
d60343616bff4596c9cc9f10aeba891deb396de2 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/data/support.lean | 70b944fef407a5275422f3a76a14049e728e07ba | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 5,293 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import order.conditionally_complete_lattice
import algebra.big_operators.basic
import algebra.group.prod
/-!
# Support of a function
In this file we define `function.support f = {x | f x ≠ 0}` and prove its basic properties.
-/
universes u v w x y
open set
open_locale big_operators
namespace function
variables {α : Type u} {β : Type v} {ι : Sort w} {A : Type x} {B : Type y}
/-- `support` of a function is the set of points `x` such that `f x ≠ 0`. -/
def support [has_zero A] (f : α → A) : set α := {x | f x ≠ 0}
lemma nmem_support [has_zero A] {f : α → A} {x : α} :
x ∉ support f ↔ f x = 0 :=
classical.not_not
lemma mem_support [has_zero A] {f : α → A} {x : α} :
x ∈ support f ↔ f x ≠ 0 :=
iff.rfl
lemma support_subset_iff [has_zero A] {f : α → A} {s : set α} :
support f ⊆ s ↔ ∀ x, f x ≠ 0 → x ∈ s :=
iff.rfl
lemma support_subset_iff' [has_zero A] {f : α → A} {s : set α} :
support f ⊆ s ↔ ∀ x ∉ s, f x = 0 :=
forall_congr $ λ x, by classical; exact not_imp_comm
lemma support_binop_subset [has_zero A] (op : A → A → A) (op0 : op 0 0 = 0) (f g : α → A) :
support (λ x, op (f x) (g x)) ⊆ support f ∪ support g :=
λ x hx, classical.by_cases
(λ hf : f x = 0, or.inr $ λ hg, hx $ by simp only [hf, hg, op0])
or.inl
lemma support_add [add_monoid A] (f g : α → A) :
support (λ x, f x + g x) ⊆ support f ∪ support g :=
support_binop_subset (+) (zero_add _) f g
@[simp] lemma support_neg [add_group A] (f : α → A) :
support (λ x, -f x) = support f :=
set.ext $ λ x, not_congr neg_eq_zero
lemma support_sub [add_group A] (f g : α → A) :
support (λ x, f x - g x) ⊆ support f ∪ support g :=
support_binop_subset (has_sub.sub) (sub_self _) f g
@[simp] lemma support_mul [mul_zero_class A] [no_zero_divisors A] (f g : α → A) :
support (λ x, f x * g x) = support f ∩ support g :=
set.ext $ λ x, by simp only [support, ne.def, mul_eq_zero, mem_set_of_eq,
mem_inter_iff, not_or_distrib]
@[simp] lemma support_inv [division_ring A] (f : α → A) :
support (λ x, (f x)⁻¹) = support f :=
set.ext $ λ x, not_congr inv_eq_zero
@[simp] lemma support_div [division_ring A] (f g : α → A) :
support (λ x, f x / g x) = support f ∩ support g :=
by simp [div_eq_mul_inv]
lemma support_sup [has_zero A] [semilattice_sup A] (f g : α → A) :
support (λ x, (f x) ⊔ (g x)) ⊆ support f ∪ support g :=
support_binop_subset (⊔) sup_idem f g
lemma support_inf [has_zero A] [semilattice_inf A] (f g : α → A) :
support (λ x, (f x) ⊓ (g x)) ⊆ support f ∪ support g :=
support_binop_subset (⊓) inf_idem f g
lemma support_max [has_zero A] [decidable_linear_order A] (f g : α → A) :
support (λ x, max (f x) (g x)) ⊆ support f ∪ support g :=
support_sup f g
lemma support_min [has_zero A] [decidable_linear_order A] (f g : α → A) :
support (λ x, min (f x) (g x)) ⊆ support f ∪ support g :=
support_inf f g
lemma support_supr [has_zero A] [conditionally_complete_lattice A] [nonempty ι] (f : ι → α → A) :
support (λ x, ⨆ i, f i x) ⊆ ⋃ i, support (f i) :=
begin
intros x hx,
classical,
contrapose hx,
simp only [mem_Union, not_exists, nmem_support] at hx ⊢,
simp only [hx, csupr_const]
end
lemma support_infi [has_zero A] [conditionally_complete_lattice A] [nonempty ι] (f : ι → α → A) :
support (λ x, ⨅ i, f i x) ⊆ ⋃ i, support (f i) :=
@support_supr _ _ (order_dual A) ⟨(0:A)⟩ _ _ f
lemma support_sum [add_comm_monoid A] (s : finset α) (f : α → β → A) :
support (λ x, ∑ i in s, f i x) ⊆ ⋃ i ∈ s, support (f i) :=
begin
intros x hx,
classical,
contrapose hx,
simp only [mem_Union, not_exists, nmem_support] at hx ⊢,
exact finset.sum_eq_zero hx
end
lemma support_prod_subset [comm_monoid_with_zero A] (s : finset α) (f : α → β → A) :
support (λ x, ∏ i in s, f i x) ⊆ ⋂ i ∈ s, support (f i) :=
λ x hx, mem_bInter_iff.2 $ λ i hi H, hx $ finset.prod_eq_zero hi H
lemma support_prod [comm_monoid_with_zero A] [no_zero_divisors A] [nontrivial A]
(s : finset α) (f : α → β → A) :
support (λ x, ∏ i in s, f i x) = ⋂ i ∈ s, support (f i) :=
set.ext $ λ x, by
simp only [support, ne.def, finset.prod_eq_zero_iff, mem_set_of_eq, set.mem_Inter, not_exists]
lemma support_comp_subset [has_zero A] [has_zero B] {g : A → B} (hg : g 0 = 0) (f : α → A) :
support (g ∘ f) ⊆ support f :=
λ x, mt $ λ h, by simp [(∘), *]
lemma support_subset_comp [has_zero A] [has_zero B] {g : A → B} (hg : ∀ {x}, g x = 0 → x = 0)
(f : α → A) :
support f ⊆ support (g ∘ f) :=
λ x, mt hg
lemma support_comp_eq [has_zero A] [has_zero B] (g : A → B) (hg : ∀ {x}, g x = 0 ↔ x = 0)
(f : α → A) :
support (g ∘ f) = support f :=
set.ext $ λ x, not_congr hg
lemma support_prod_mk [has_zero A] [has_zero B] (f : α → A) (g : α → B) :
support (λ x, (f x, g x)) = support f ∪ support g :=
set.ext $ λ x, by simp only [support, classical.not_and_distrib, mem_union_eq, mem_set_of_eq,
prod.mk_eq_zero, ne.def]
end function
|
f112c2838e24a8c259c18dcc6abdfa3277e9b7df | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/renameI.lean | 70173877f6716453a6c18b43f0b0159e5cb212d6 | [
"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 | 284 | lean | example : (m n : Nat) → m = n := by
intro y y
rename_i x
trace_state
admit
example : (m n : Nat) → m = n := by
intro a.b a.b
rename_i x
trace_state
admit
example : (m o p n: Nat) → m + p = n + o := by
intro a.b _ _ a.b
rename_i x _ y
trace_state
admit
|
3a0862c7f5b46422a9550ff0bcd8665340f8b4a9 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/transfer_auto.lean | 62c1f10edffa30033eb0a57283246812bc8bec0e | [] | 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,367 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl (CMU)
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.meta.tactic
import Mathlib.Lean3Lib.init.meta.match_tactic
import Mathlib.Lean3Lib.init.meta.mk_dec_eq_instance
import Mathlib.Lean3Lib.init.data.list.instances
import Mathlib.logic.relator
import Mathlib.PostPort
namespace Mathlib
namespace transfer
/- Transfer rules are of the shape:
rel_t : {u} Πx, R t₁ t₂
where `u` is a list of universe parameters, `x` is a list of dependent variables, and `R` is a
relation. Then this rule will translate `t₁` (depending on `u` and `x`) into `t₂`. `u` and `x`
will be called parameters. When `R` is a relation on functions lifted from `S` and `R` the variables
bound by `S` are called arguments. `R` is generally constructed using `⇒` (i.e. `relator.lift_fun`).
As example:
rel_eq : (R ⇒ R ⇒ iff) eq t
transfer will match this rule when it sees:
(@eq α a b) and transfer it to (t a b)
Here `α` is a parameter and `a` and `b` are arguments.
TODO: add trace statements
TODO: currently the used relation must be fixed by the matched rule or through type class
inference. Maybe we want to replace this by type inference similar to Isabelle's transfer.
-/
end Mathlib |
d1ce1d054e44aaf6e02b6ea44989c17faff99def | b3fced0f3ff82d577384fe81653e47df68bb2fa1 | /src/measure_theory/ae_eq_fun.lean | b4994b0c8f054c5394b2ba78058af082b8db99e9 | [
"Apache-2.0"
] | permissive | ratmice/mathlib | 93b251ef5df08b6fd55074650ff47fdcc41a4c75 | 3a948a6a4cd5968d60e15ed914b1ad2f4423af8d | refs/heads/master | 1,599,240,104,318 | 1,572,981,183,000 | 1,572,981,183,000 | 219,830,178 | 0 | 0 | Apache-2.0 | 1,572,980,897,000 | 1,572,980,896,000 | null | UTF-8 | Lean | false | false | 12,511 | lean | /-
Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Zhouhang Zhou
We define almost everywhere equal functions, and show that
• they form a vector space if the codomain is a vector space
• they form an emetric space under L¹ metric if the codomain is a metric space
-/
import measure_theory.integration
noncomputable theory
open_locale classical
namespace measure_theory
open set lattice filter topological_space
universes u v
variables {α : Type u} {β : Type v} [measure_space α]
section measurable_space
variables [measurable_space β]
variables (α β)
instance ae_eq_fun.setoid : setoid { f : α → β // measurable f } :=
⟨ λf g, ∀ₘ a, f.1 a = g.1 a,
assume ⟨f, hf⟩, by filter_upwards [] assume a, rfl,
assume ⟨f, hf⟩ ⟨g, hg⟩ hfg, by filter_upwards [hfg] assume a, eq.symm,
assume ⟨f, hf⟩ ⟨g, hg⟩ ⟨h, hh⟩ hfg hgh, by filter_upwards [hfg, hgh] assume a, eq.trans ⟩
def ae_eq_fun : Type (max u v) := quotient (ae_eq_fun.setoid α β)
variables {α β}
infixr ` →ₘ `:25 := ae_eq_fun
end measurable_space
namespace ae_eq_fun
variables [measurable_space β]
def mk (f : α → β) (hf : measurable f) : α →ₘ β := quotient.mk ⟨f, hf⟩
@[simp] lemma quot_mk_eq_mk (f : {f : α → β // measurable f}) : quot.mk setoid.r f = mk f.1 f.2 :=
by cases f; refl
@[simp] lemma mk_eq_mk (f g : α → β) (hf hg) :
mk f hf = mk g hg ↔ (∀ₘ a, f a = g a) :=
⟨quotient.exact, assume h, quotient.sound h⟩
def comp {γ : Type*} [measurable_space γ] (g : β → γ) (hg : measurable g) (f : α →ₘ β) : α →ₘ γ :=
quotient.lift_on f (λf, mk (g ∘ f.1) (measurable.comp hg f.2)) $ assume f₁ f₂ eq,
by refine quotient.sound _; filter_upwards [eq] assume a, congr_arg g
def comp₂ {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (λp:β×γ, g p.1 p.2)) (f₁ : α →ₘ β) (f₂ : α →ₘ γ) : α →ₘ δ :=
begin
refine quotient.lift_on₂ f₁ f₂ (λf₁ f₂, mk (λa, g (f₁.1 a) (f₂.1 a)) $ _) _,
{ exact measurable.comp hg (measurable_prod_mk f₁.2 f₂.2) },
{ rintros ⟨f₁, hf₁⟩ ⟨f₂, hf₂⟩ ⟨g₁, hg₁⟩ ⟨g₂, hg₂⟩ h₁ h₂,
refine quotient.sound _,
filter_upwards [h₁, h₂],
simp {contextual := tt} }
end
@[simp] lemma comp₂_mk_mk {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (λp:β×γ, g p.1 p.2)) (f₁ : α → β) (f₂ : α → γ) (hf₁ hf₂) :
comp₂ g hg (mk f₁ hf₁) (mk f₂ hf₂) =
mk (λa, g (f₁ a) (f₂ a)) (measurable.comp hg (measurable_prod_mk hf₁ hf₂)) :=
rfl
def lift_pred (p : β → Prop) (f : α →ₘ β) : Prop :=
quotient.lift_on f (λf, ∀ₘ a, p (f.1 a))
begin
assume f g h, dsimp, refine propext (all_ae_congr _),
filter_upwards [h], simp {contextual := tt}
end
def lift_rel {γ : Type*} [measurable_space γ] (r : β → γ → Prop) (f : α →ₘ β) (g : α →ₘ γ) : Prop :=
lift_pred (λp:β×γ, r p.1 p.2)
(comp₂ prod.mk (measurable_prod_mk
(measurable_fst measurable_id) (measurable_snd measurable_id)) f g)
lemma lift_rel_mk_mk {γ : Type*} [measurable_space γ] (r : β → γ → Prop)
(f : α → β) (g : α → γ) (hf hg) : lift_rel r (mk f hf) (mk g hg) ↔ ∀ₘ a, r (f a) (g a) :=
iff.rfl
section order
instance [preorder β] : preorder (α →ₘ β) :=
{ le := lift_rel (≤),
le_refl := by rintros ⟨⟨f, hf⟩⟩; exact univ_mem_sets' (assume a, le_refl _),
le_trans :=
begin
rintros ⟨⟨f, hf⟩⟩ ⟨⟨g, hg⟩⟩ ⟨⟨h, hh⟩⟩ hfg hgh,
filter_upwards [hfg, hgh] assume a, le_trans
end }
lemma mk_le_mk [preorder β] {f g : α → β} (hf hg) : mk f hf ≤ mk g hg ↔ ∀ₘ a, f a ≤ g a :=
iff.rfl
instance [partial_order β] : partial_order (α →ₘ β) :=
{ le_antisymm :=
begin
rintros ⟨⟨f, hf⟩⟩ ⟨⟨g, hg⟩⟩ hfg hgf,
refine quotient.sound _,
filter_upwards [hfg, hgf] assume a, le_antisymm
end,
.. measure_theory.ae_eq_fun.preorder }
end order
variable (α)
def const (b : β) : α →ₘ β := mk (λa:α, b) measurable_const
variable {α}
instance [has_zero β] : has_zero (α →ₘ β) := ⟨const α 0⟩
lemma zero_def [has_zero β] : (0 : α →ₘ β) = mk (λa:α, 0) measurable_const := rfl
instance [has_one β] : has_one (α →ₘ β) := ⟨const α 1⟩
lemma one_def [has_one β] : (1 : α →ₘ β) = mk (λa:α, 1) measurable_const := rfl
section add_monoid
variables {γ : Type*}
[topological_space γ] [second_countable_topology γ] [add_monoid γ] [topological_add_monoid γ]
protected def add : (α →ₘ γ) → (α →ₘ γ) → (α →ₘ γ) :=
comp₂ (+) (measurable_add (measurable_fst measurable_id) (measurable_snd measurable_id))
instance : has_add (α →ₘ γ) := ⟨ae_eq_fun.add⟩
@[simp] lemma mk_add_mk (f g : α → γ) (hf hg) : (mk f hf) + (mk g hg) =
mk (λa, (f a) + (g a)) (measurable_add hf hg) := rfl
instance : add_monoid (α →ₘ γ) :=
{ zero := 0,
add := ae_eq_fun.add,
add_zero := by rintros ⟨a⟩; exact quotient.sound (univ_mem_sets' $ assume a, add_zero _),
zero_add := by rintros ⟨a⟩; exact quotient.sound (univ_mem_sets' $ assume a, zero_add _),
add_assoc :=
by rintros ⟨a⟩ ⟨b⟩ ⟨c⟩; exact quotient.sound (univ_mem_sets' $ assume a, add_assoc _ _ _) }
end add_monoid
section add_comm_monoid
variables {γ : Type*}
[topological_space γ] [second_countable_topology γ] [add_comm_monoid γ] [topological_add_monoid γ]
instance : add_comm_monoid (α →ₘ γ) :=
{ add_comm := by rintros ⟨a⟩ ⟨b⟩; exact quotient.sound (univ_mem_sets' $ assume a, add_comm _ _),
.. ae_eq_fun.add_monoid }
end add_comm_monoid
section add_group
variables {γ : Type*} [topological_space γ] [add_group γ] [topological_add_group γ]
protected def neg : (α →ₘ γ) → (α →ₘ γ) := comp has_neg.neg (measurable_neg measurable_id)
instance : has_neg (α →ₘ γ) := ⟨ae_eq_fun.neg⟩
@[simp] lemma neg_mk (f : α → γ) (hf) : -(mk f hf) = mk (-f) (measurable_neg hf) := rfl
instance [second_countable_topology γ] : add_group (α →ₘ γ) :=
{ neg := ae_eq_fun.neg,
add_left_neg := by rintros ⟨a⟩; exact quotient.sound (univ_mem_sets' $ assume a, add_left_neg _),
.. ae_eq_fun.add_monoid
}
end add_group
section add_comm_group
variables {γ : Type*}
[topological_space γ] [second_countable_topology γ] [add_comm_group γ] [topological_add_group γ]
instance : add_comm_group (α →ₘ γ) :=
{ add_comm := ae_eq_fun.add_comm_monoid.add_comm
.. ae_eq_fun.add_group
}
end add_comm_group
section semimodule
variables {K : Type*} [semiring K] [topological_space K]
variables {γ : Type*} [topological_space γ]
[add_comm_monoid γ] [semimodule K γ] [topological_semimodule K γ]
protected def smul : K → (α →ₘ γ) → (α →ₘ γ) :=
λ c f, comp (has_scalar.smul c) (measurable_smul measurable_id) f
instance : has_scalar K (α →ₘ γ) := ⟨ae_eq_fun.smul⟩
@[simp] lemma smul_mk (c : K) (f : α → γ) (hf) : c • (mk f hf) = mk (c • f) (measurable_smul hf) :=
rfl
variables [second_countable_topology γ] [topological_add_monoid γ]
instance : semimodule K (α →ₘ γ) :=
{ one_smul := by { rintros ⟨f, hf⟩, simp only [quot_mk_eq_mk, smul_mk, one_smul] },
mul_smul :=
by { rintros x y ⟨f, hf⟩, simp only [quot_mk_eq_mk, smul_mk, mul_action.mul_smul x y f], refl },
smul_add :=
begin
rintros x ⟨f, hf⟩ ⟨g, hg⟩, simp only [quot_mk_eq_mk, smul_mk, mk_add_mk],
congr, exact smul_add x f g
end,
smul_zero := by { intro x, simp only [zero_def, smul_mk], congr, exact smul_zero x },
add_smul :=
begin
intros x y, rintro ⟨f, hf⟩, simp only [quot_mk_eq_mk, smul_mk, mk_add_mk], congr,
exact add_smul x y f
end,
zero_smul :=
by { rintro ⟨f, hf⟩, simp only [quot_mk_eq_mk, smul_mk, zero_def], congr, exact zero_smul K f }}
end semimodule
section vector_space
variables {K : Type*} [discrete_field K] [topological_space K]
variables {γ : Type*} [topological_space γ] [second_countable_topology γ] [add_comm_group γ]
[topological_add_group γ] [vector_space K γ] [topological_semimodule K γ]
instance : vector_space K (α →ₘ γ) := { .. ae_eq_fun.semimodule }
end vector_space
open ennreal
-- integral on ae_eq_fun
def eintegral (f : α →ₘ ennreal) : ennreal :=
quotient.lift_on f (λf, lintegral f.1) (assume ⟨f, hf⟩ ⟨g, hg⟩ eq, lintegral_congr_ae eq)
@[simp] lemma eintegral_mk (f : α → ennreal) (hf) : eintegral (mk f hf) = lintegral f := rfl
@[simp] lemma eintegral_zero : eintegral (0 : α →ₘ ennreal) = 0 := lintegral_zero
@[simp] lemma eintegral_eq_zero_iff (f : α →ₘ ennreal) : eintegral f = 0 ↔ f = 0 :=
begin
rcases f with ⟨f, hf⟩,
refine iff.trans (lintegral_eq_zero_iff hf) ⟨_, _⟩,
{ assume h, exact quotient.sound h },
{ assume h, exact quotient.exact h }
end
lemma eintegral_add : ∀(f g : α →ₘ ennreal), eintegral (f + g) = eintegral f + eintegral g :=
by rintros ⟨f⟩ ⟨g⟩; simp only [quot_mk_eq_mk, mk_add_mk, eintegral_mk, lintegral_add f.2 g.2]
lemma eintegral_le_eintegral {f g : α →ₘ ennreal} (h : f ≤ g) : eintegral f ≤ eintegral g :=
begin
rcases f with ⟨f, hf⟩, rcases g with ⟨g, hg⟩,
simp only [quot_mk_eq_mk, eintegral_mk, mk_le_mk] at *,
refine lintegral_le_lintegral_ae _,
filter_upwards [h], simp
end
section
variables {γ : Type*} [emetric_space γ] [second_countable_topology γ]
def comp_edist (f g : α →ₘ γ) : α →ₘ ennreal := comp₂ edist measurable_edist' f g
lemma comp_edist_self : ∀ (f : α →ₘ γ), comp_edist f f = 0 :=
by rintro ⟨f⟩; refine quotient.sound _; simp only [edist_self]
instance : emetric_space (α →ₘ γ) :=
{ edist := λf g, eintegral (comp_edist f g),
edist_self := assume f, (eintegral_eq_zero_iff _).2 (comp_edist_self _),
edist_comm :=
by rintros ⟨f⟩ ⟨g⟩; simp only [comp_edist, quot_mk_eq_mk, comp₂_mk_mk, edist_comm],
edist_triangle :=
begin
rintros ⟨f⟩ ⟨g⟩ ⟨h⟩,
simp only [comp_edist, quot_mk_eq_mk, comp₂_mk_mk, (eintegral_add _ _).symm],
exact lintegral_le_lintegral _ _ (assume a, edist_triangle _ _ _)
end,
eq_of_edist_eq_zero :=
begin
rintros ⟨f⟩ ⟨g⟩,
simp only [edist, comp_edist, quot_mk_eq_mk, comp₂_mk_mk, eintegral_eq_zero_iff],
simp only [zero_def, mk_eq_mk, edist_eq_zero],
assume h, assumption
end }
lemma edist_mk_mk {f g : α → γ} (hf hg) : edist (mk f hf) (mk g hg) = ∫⁻ x, edist (f x) (g x) := rfl
end
section metric
variables {γ : Type*} [metric_space γ] [second_countable_topology γ]
lemma edist_mk_mk' {f g : α → γ} (hf hg) :
edist (mk f hf) (mk g hg) = ∫⁻ x, nndist (f x) (g x) :=
show (∫⁻ x, edist (f x) (g x)) = ∫⁻ x, nndist (f x) (g x), from
lintegral_congr_ae $all_ae_of_all $ assume a, edist_nndist _ _
end metric
section normed_group
variables {γ : Type*} [normed_group γ] [second_countable_topology γ]
lemma edist_eq_add_add : ∀ {f g h : α →ₘ γ}, edist f g = edist (f + h) (g + h) :=
begin
rintros ⟨f⟩ ⟨g⟩ ⟨h⟩,
simp only [quot_mk_eq_mk, mk_add_mk, edist_mk_mk'],
apply lintegral_congr_ae,
filter_upwards [], simp [nndist_eq_nnnorm]
end
end normed_group
section normed_space
set_option class.instance_max_depth 100
variables {K : Type*} [normed_field K]
variables {γ : Type*} [normed_group γ] [second_countable_topology γ] [normed_space K γ]
lemma edist_smul (x : K) : ∀ f : α →ₘ γ, edist (x • f) 0 = (ennreal.of_real ∥x∥) * edist f 0 :=
begin
rintros ⟨f, hf⟩, simp only [zero_def, edist_mk_mk', quot_mk_eq_mk, smul_mk],
exact calc
(∫⁻ (a : α), nndist (x • f a) 0) = (∫⁻ (a : α), (nnnorm x) * nnnorm (f a)) :
lintegral_congr_ae $ by { filter_upwards [], assume a, simp [nndist_eq_nnnorm, nnnorm_smul] }
... = _ : lintegral_const_mul _ (measurable_coe_nnnorm hf)
... = _ :
begin
convert rfl,
{ rw ← coe_nnnorm, rw [ennreal.of_real], congr, exact nnreal.of_real_coe },
{ funext, simp [nndist_eq_nnnorm] }
end,
end
end normed_space
end ae_eq_fun
end measure_theory
|
a26e7d02c956119483257b32a37dc94f6e6a7aab | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/641.lean | 51101a5d35ad8083a21fd3d9ef74fc0288d227f6 | [
"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 | 66 | lean | example : true := by do tactic.set_goals [`(true)] >> tactic.triv
|
7ecd1e7173398408ede85f2a3fcbf49b3d5579de | c777c32c8e484e195053731103c5e52af26a25d1 | /src/measure_theory/function/egorov.lean | 63bfb80eb9b2c0be245b9fdec9c7523d6e0d9d98 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 10,810 | lean | /-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import measure_theory.function.strongly_measurable.basic
/-!
# Egorov theorem
This file contains the Egorov theorem which states that an almost everywhere convergent
sequence on a finite measure space converges uniformly except on an arbitrarily small set.
This theorem is useful for the Vitali convergence theorem as well as theorems regarding
convergence in measure.
## Main results
* `measure_theory.egorov`: Egorov's theorem which shows that a sequence of almost everywhere
convergent functions converges uniformly except on an arbitrarily small set.
-/
noncomputable theory
open_locale classical measure_theory nnreal ennreal topology
namespace measure_theory
open set filter topological_space
variables {α β ι : Type*} {m : measurable_space α} [metric_space β] {μ : measure α}
namespace egorov
/-- Given a sequence of functions `f` and a function `g`, `not_convergent_seq f g n j` is the
set of elements such that `f k x` and `g x` are separated by at least `1 / (n + 1)` for some
`k ≥ j`.
This definition is useful for Egorov's theorem. -/
def not_convergent_seq [preorder ι] (f : ι → α → β) (g : α → β) (n : ℕ) (j : ι) : set α :=
⋃ k (hk : j ≤ k), {x | (1 / (n + 1 : ℝ)) < dist (f k x) (g x)}
variables {n : ℕ} {i j : ι} {s : set α} {ε : ℝ} {f : ι → α → β} {g : α → β}
lemma mem_not_convergent_seq_iff [preorder ι] {x : α} : x ∈ not_convergent_seq f g n j ↔
∃ k (hk : j ≤ k), (1 / (n + 1 : ℝ)) < dist (f k x) (g x) :=
by { simp_rw [not_convergent_seq, mem_Union], refl }
lemma not_convergent_seq_antitone [preorder ι] :
antitone (not_convergent_seq f g n) :=
λ j k hjk, Union₂_mono' $ λ l hl, ⟨l, le_trans hjk hl, subset.rfl⟩
lemma measure_inter_not_convergent_seq_eq_zero [semilattice_sup ι] [nonempty ι]
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) (n : ℕ) :
μ (s ∩ ⋂ j, not_convergent_seq f g n j) = 0 :=
begin
simp_rw [metric.tendsto_at_top, ae_iff] at hfg,
rw [← nonpos_iff_eq_zero, ← hfg],
refine measure_mono (λ x, _),
simp only [mem_inter_iff, mem_Inter, ge_iff_le, mem_not_convergent_seq_iff],
push_neg,
rintro ⟨hmem, hx⟩,
refine ⟨hmem, 1 / (n + 1 : ℝ), nat.one_div_pos_of_nat, λ N, _⟩,
obtain ⟨n, hn₁, hn₂⟩ := hx N,
exact ⟨n, hn₁, hn₂.le⟩
end
lemma not_convergent_seq_measurable_set [preorder ι] [countable ι]
(hf : ∀ n, strongly_measurable[m] (f n)) (hg : strongly_measurable g) :
measurable_set (not_convergent_seq f g n j) :=
measurable_set.Union (λ k, measurable_set.Union $ λ hk,
strongly_measurable.measurable_set_lt strongly_measurable_const $ (hf k).dist hg)
lemma measure_not_convergent_seq_tendsto_zero [semilattice_sup ι] [countable ι]
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) (n : ℕ) :
tendsto (λ j, μ (s ∩ not_convergent_seq f g n j)) at_top (𝓝 0) :=
begin
casesI is_empty_or_nonempty ι,
{ have : (λ j, μ (s ∩ not_convergent_seq f g n j)) = λ j, 0,
by simp only [eq_iff_true_of_subsingleton],
rw this,
exact tendsto_const_nhds, },
rw [← measure_inter_not_convergent_seq_eq_zero hfg n, inter_Inter],
refine tendsto_measure_Inter (λ n, hsm.inter $ not_convergent_seq_measurable_set hf hg)
(λ k l hkl, inter_subset_inter_right _ $ not_convergent_seq_antitone hkl)
⟨h.some, (lt_of_le_of_lt (measure_mono $ inter_subset_left _ _) (lt_top_iff_ne_top.2 hs)).ne⟩,
end
variables [semilattice_sup ι] [nonempty ι] [countable ι]
lemma exists_not_convergent_seq_lt (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) (n : ℕ) :
∃ j : ι, μ (s ∩ not_convergent_seq f g n j) ≤ ennreal.of_real (ε * 2⁻¹ ^ n) :=
begin
obtain ⟨N, hN⟩ := (ennreal.tendsto_at_top ennreal.zero_ne_top).1
(measure_not_convergent_seq_tendsto_zero hf hg hsm hs hfg n)
(ennreal.of_real (ε * 2⁻¹ ^ n)) _,
{ rw zero_add at hN,
exact ⟨N, (hN N le_rfl).2⟩ },
{ rw [gt_iff_lt, ennreal.of_real_pos],
exact mul_pos hε (pow_pos (by norm_num) n), }
end
/-- Given some `ε > 0`, `not_convergent_seq_lt_index` provides the index such that
`not_convergent_seq` (intersected with a set of finite measure) has measure less than
`ε * 2⁻¹ ^ n`.
This definition is useful for Egorov's theorem. -/
def not_convergent_seq_lt_index (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) (n : ℕ) : ι :=
classical.some $ exists_not_convergent_seq_lt hε hf hg hsm hs hfg n
lemma not_convergent_seq_lt_index_spec (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) (n : ℕ) :
μ (s ∩ not_convergent_seq f g n (not_convergent_seq_lt_index hε hf hg hsm hs hfg n)) ≤
ennreal.of_real (ε * 2⁻¹ ^ n) :=
classical.some_spec $ exists_not_convergent_seq_lt hε hf hg hsm hs hfg n
/-- Given some `ε > 0`, `Union_not_convergent_seq` is the union of `not_convergent_seq` with
specific indicies such that `Union_not_convergent_seq` has measure less equal than `ε`.
This definition is useful for Egorov's theorem. -/
def Union_not_convergent_seq (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) : set α :=
⋃ n, s ∩ not_convergent_seq f g n (not_convergent_seq_lt_index (half_pos hε) hf hg hsm hs hfg n)
lemma Union_not_convergent_seq_measurable_set (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) :
measurable_set $ Union_not_convergent_seq hε hf hg hsm hs hfg :=
measurable_set.Union (λ n, hsm.inter $ not_convergent_seq_measurable_set hf hg)
lemma measure_Union_not_convergent_seq (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) :
μ (Union_not_convergent_seq hε hf hg hsm hs hfg) ≤ ennreal.of_real ε :=
begin
refine le_trans (measure_Union_le _)
(le_trans (ennreal.tsum_le_tsum $ not_convergent_seq_lt_index_spec
(half_pos hε) hf hg hsm hs hfg) _),
simp_rw [ennreal.of_real_mul (half_pos hε).le],
rw [ennreal.tsum_mul_left, ← ennreal.of_real_tsum_of_nonneg, inv_eq_one_div,
tsum_geometric_two, ← ennreal.of_real_mul (half_pos hε).le, div_mul_cancel ε two_ne_zero],
{ exact le_rfl },
{ exact λ n, pow_nonneg (by norm_num) _ },
{ rw [inv_eq_one_div],
exact summable_geometric_two },
end
lemma Union_not_convergent_seq_subset (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) :
Union_not_convergent_seq hε hf hg hsm hs hfg ⊆ s :=
begin
rw [Union_not_convergent_seq, ← inter_Union],
exact inter_subset_left _ _,
end
lemma tendsto_uniformly_on_diff_Union_not_convergent_seq (hε : 0 < ε)
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) :
tendsto_uniformly_on f g at_top (s \ egorov.Union_not_convergent_seq hε hf hg hsm hs hfg) :=
begin
rw metric.tendsto_uniformly_on_iff,
intros δ hδ,
obtain ⟨N, hN⟩ := exists_nat_one_div_lt hδ,
rw eventually_at_top,
refine ⟨egorov.not_convergent_seq_lt_index (half_pos hε) hf hg hsm hs hfg N, λ n hn x hx, _⟩,
simp only [mem_diff, egorov.Union_not_convergent_seq, not_exists, mem_Union, mem_inter_iff,
not_and, exists_and_distrib_left] at hx,
obtain ⟨hxs, hx⟩ := hx,
specialize hx hxs N,
rw egorov.mem_not_convergent_seq_iff at hx,
push_neg at hx,
rw dist_comm,
exact lt_of_le_of_lt (hx n hn) hN,
end
end egorov
variables [semilattice_sup ι] [nonempty ι] [countable ι]
{γ : Type*} [topological_space γ]
{f : ι → α → β} {g : α → β} {s : set α}
/-- **Egorov's theorem**: If `f : ι → α → β` is a sequence of strongly measurable functions that
converges to `g : α → β` almost everywhere on a measurable set `s` of finite measure,
then for all `ε > 0`, there exists a subset `t ⊆ s` such that `μ t ≤ ε` and `f` converges to `g`
uniformly on `s \ t`. We require the index type `ι` to be countable, and usually `ι = ℕ`.
In other words, a sequence of almost everywhere convergent functions converges uniformly except on
an arbitrarily small set. -/
theorem tendsto_uniformly_on_of_ae_tendsto
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hsm : measurable_set s) (hs : μ s ≠ ∞)
(hfg : ∀ᵐ x ∂μ, x ∈ s → tendsto (λ n, f n x) at_top (𝓝 (g x))) {ε : ℝ} (hε : 0 < ε) :
∃ t ⊆ s, measurable_set t ∧ μ t ≤ ennreal.of_real ε ∧ tendsto_uniformly_on f g at_top (s \ t) :=
⟨egorov.Union_not_convergent_seq hε hf hg hsm hs hfg,
egorov.Union_not_convergent_seq_subset hε hf hg hsm hs hfg,
egorov.Union_not_convergent_seq_measurable_set hε hf hg hsm hs hfg,
egorov.measure_Union_not_convergent_seq hε hf hg hsm hs hfg,
egorov.tendsto_uniformly_on_diff_Union_not_convergent_seq hε hf hg hsm hs hfg⟩
/-- Egorov's theorem for finite measure spaces. -/
lemma tendsto_uniformly_on_of_ae_tendsto' [is_finite_measure μ]
(hf : ∀ n, strongly_measurable (f n)) (hg : strongly_measurable g)
(hfg : ∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (𝓝 (g x))) {ε : ℝ} (hε : 0 < ε) :
∃ t, measurable_set t ∧ μ t ≤ ennreal.of_real ε ∧ tendsto_uniformly_on f g at_top tᶜ :=
begin
obtain ⟨t, _, ht, htendsto⟩ :=
tendsto_uniformly_on_of_ae_tendsto hf hg measurable_set.univ (measure_ne_top μ univ) _ hε,
{ refine ⟨_, ht, _⟩,
rwa compl_eq_univ_diff },
{ filter_upwards [hfg] with _ htendsto _ using htendsto, },
end
end measure_theory
|
c4aefb66d0d12b62e13b30c270f86acf7be7f38e | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /src/Lean/Elab/BuiltinTerm.lean | 344b4f5c1657677fac35090fd08e4515dc755489 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 13,595 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Open
import Lean.Elab.SetOption
import Lean.Elab.Eval
namespace Lean.Elab.Term
open Meta
@[builtinTermElab «prop»] def elabProp : TermElab := fun _ _ =>
return mkSort levelZero
private def elabOptLevel (stx : Syntax) : TermElabM Level :=
if stx.isNone then
pure levelZero
else
elabLevel stx[0]
@[builtinTermElab «sort»] def elabSort : TermElab := fun stx _ =>
return mkSort (← elabOptLevel stx[1])
@[builtinTermElab «type»] def elabTypeStx : TermElab := fun stx _ =>
return mkSort (mkLevelSucc (← elabOptLevel stx[1]))
/-!
the method `resolveName` adds a completion point for it using the given
expected type. Thus, we propagate the expected type if `stx[0]` is an identifier.
It doesn't "hurt" if the identifier can be resolved because the expected type is not used in this case.
Recall that if the name resolution fails a synthetic sorry is returned.-/
@[builtinTermElab «pipeCompletion»] def elabPipeCompletion : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[0] none
unless e.isSorry do
addDotCompletionInfo stx e expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
@[builtinTermElab «completion»] def elabCompletion : TermElab := fun stx expectedType? => do
/- `ident.` is ambiguous in Lean, we may try to be completing a declaration name or access a "field". -/
if stx[0].isIdent then
/- If we can elaborate the identifier successfully, we assume it is a dot-completion. Otherwise, we treat it as
identifier completion with a dangling `.`.
Recall that the server falls back to identifier completion when dot-completion fails. -/
let s ← saveState
try
let e ← elabTerm stx[0] none
addDotCompletionInfo stx e expectedType?
catch _ =>
s.restore
addCompletionInfo <| CompletionInfo.id stx stx[0].getId (danglingDot := true) (← getLCtx) expectedType?
throwErrorAt stx[1] "invalid field notation, identifier or numeral expected"
else
elabPipeCompletion stx expectedType?
@[builtinTermElab «hole»] def elabHole : TermElab := fun stx expectedType? => do
let mvar ← mkFreshExprMVar expectedType?
registerMVarErrorHoleInfo mvar.mvarId! stx
pure mvar
@[builtinTermElab «syntheticHole»] def elabSyntheticHole : TermElab := fun stx expectedType? => do
let arg := stx[1]
let userName := if arg.isIdent then arg.getId else Name.anonymous
let mkNewHole : Unit → TermElabM Expr := fun _ => do
let kind := if (← read).inPattern then MetavarKind.natural else MetavarKind.syntheticOpaque
let mvar ← mkFreshExprMVar expectedType? kind userName
registerMVarErrorHoleInfo mvar.mvarId! stx
return mvar
if userName.isAnonymous || (← read).inPattern then
mkNewHole ()
else
match (← getMCtx).findUserName? userName with
| none => mkNewHole ()
| some mvarId =>
let mvar := mkMVar mvarId
let mvarDecl ← getMVarDecl mvarId
let lctx ← getLCtx
if mvarDecl.lctx.isSubPrefixOf lctx then
return mvar
else match (← getExprMVarAssignment? mvarId) with
| some val =>
let val ← instantiateMVars val
if (← MetavarContext.isWellFormed lctx val) then
return val
else
withLCtx mvarDecl.lctx mvarDecl.localInstances do
throwError "synthetic hole has already been defined and assigned to value incompatible with the current context{indentExpr val}"
| none =>
if (← mvarId.isDelayedAssigned) then
-- We can try to improve this case if needed.
throwError "synthetic hole has already beend defined and delayed assigned with an incompatible local context"
else if lctx.isSubPrefixOf mvarDecl.lctx then
let mvarNew ← mkNewHole ()
mvarId.assign mvarNew
return mvarNew
else
throwError "synthetic hole has already been defined with an incompatible local context"
@[builtinTermElab «letMVar»] def elabLetMVar : TermElab := fun stx expectedType? => do
match stx with
| `(let_mvar% ? $n := $e; $b) =>
match (← getMCtx).findUserName? n.getId with
| some _ => throwError "invalid 'let_mvar%', metavariable '?{n.getId}' has already been used"
| none =>
let e ← elabTerm e none
let mvar ← mkFreshExprMVar (← inferType e) MetavarKind.syntheticOpaque n.getId
mvar.mvarId!.assign e
-- We use `mkSaveInfoAnnotation` to make sure the info trees for `e` are saved even if `b` is a metavariable.
return mkSaveInfoAnnotation (← elabTerm b expectedType?)
| _ => throwUnsupportedSyntax
private def getMVarFromUserName (ident : Syntax) : MetaM Expr := do
match (← getMCtx).findUserName? ident.getId with
| none => throwError "unknown metavariable '?{ident.getId}'"
| some mvarId => instantiateMVars (mkMVar mvarId)
@[builtinTermElab «waitIfTypeMVar»] def elabWaitIfTypeMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_mvar% ? $n; $b) =>
tryPostponeIfMVar (← inferType (← getMVarFromUserName n))
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtinTermElab «waitIfTypeContainsMVar»] def elabWaitIfTypeContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_type_contains_mvar% ? $n; $b) =>
if (← instantiateMVars (← inferType (← getMVarFromUserName n))).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
@[builtinTermElab «waitIfContainsMVar»] def elabWaitIfContainsMVar : TermElab := fun stx expectedType? => do
match stx with
| `(wait_if_contains_mvar% ? $n; $b) =>
if (← getMVarFromUserName n).hasExprMVar then
tryPostpone
elabTerm b expectedType?
| _ => throwUnsupportedSyntax
private def mkTacticMVar (type : Expr) (tacticCode : Syntax) : TermElabM Expr := do
let mvar ← mkFreshExprMVar type MetavarKind.syntheticOpaque
let mvarId := mvar.mvarId!
let ref ← getRef
registerSyntheticMVar ref mvarId <| SyntheticMVarKind.tactic tacticCode (← saveContext)
return mvar
@[builtinTermElab byTactic] def elabByTactic : TermElab := fun stx expectedType? => do
match expectedType? with
| some expectedType => mkTacticMVar expectedType stx
| none =>
tryPostpone
throwError ("invalid 'by' tactic, expected type has not been provided")
@[builtinTermElab noImplicitLambda] def elabNoImplicitLambda : TermElab := fun stx expectedType? =>
elabTerm stx[1] (mkNoImplicitLambdaAnnotation <$> expectedType?)
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun _ _ =>
throwError "invalid occurrence of `·` notation, it must be surrounded by parentheses (e.g. `(· + 1)`)"
@[builtinTermElab str] def elabStrLit : TermElab := fun stx _ => do
match stx.isStrLit? with
| some val => pure $ mkStrLit val
| none => throwIllFormedSyntax
private def mkFreshTypeMVarFor (expectedType? : Option Expr) : TermElabM Expr := do
let typeMVar ← mkFreshTypeMVar MetavarKind.synthetic
match expectedType? with
| some expectedType => discard <| isDefEq expectedType typeMVar
| _ => pure ()
return typeMVar
@[builtinTermElab num] def elabNumLit : TermElab := fun stx expectedType? => do
let val ← match stx.isNatLit? with
| some val => pure val
| none => throwIllFormedSyntax
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp2 (Lean.mkConst ``OfNat [u]) typeMVar (mkRawNatLit val))
let r := mkApp3 (Lean.mkConst ``OfNat.ofNat [u]) typeMVar (mkRawNatLit val) mvar
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtinTermElab rawNatLit] def elabRawNatLit : TermElab := fun stx _ => do
match stx[1].isNatLit? with
| some val => return mkRawNatLit val
| none => throwIllFormedSyntax
@[builtinTermElab scientific]
def elabScientificLit : TermElab := fun stx expectedType? => do
match stx.isScientificLit? with
| none => throwIllFormedSyntax
| some (m, sign, e) =>
let typeMVar ← mkFreshTypeMVarFor expectedType?
let u ← getDecLevel typeMVar
let mvar ← mkInstMVar (mkApp (Lean.mkConst ``OfScientific [u]) typeMVar)
let r := mkApp5 (Lean.mkConst ``OfScientific.ofScientific [u]) typeMVar mvar (mkRawNatLit m) (toExpr sign) (mkRawNatLit e)
registerMVarErrorImplicitArgInfo mvar.mvarId! stx r
return r
@[builtinTermElab char] def elabCharLit : TermElab := fun stx _ => do
match stx.isCharLit? with
| some val => return mkApp (Lean.mkConst ``Char.ofNat) (mkRawNatLit val.toNat)
| none => throwIllFormedSyntax
@[builtinTermElab quotedName] def elabQuotedName : TermElab := fun stx _ =>
match stx[0].isNameLit? with
| some val => pure $ toExpr val
| none => throwIllFormedSyntax
@[builtinTermElab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ =>
return toExpr (← resolveGlobalConstNoOverloadWithInfo stx[2])
@[builtinTermElab declName] def elabDeclName : TermElab := adaptExpander fun _ => do
let some declName ← getDeclName?
| throwError "invalid `decl_name%` macro, the declaration name is not available"
return (quote declName : Term)
@[builtinTermElab Parser.Term.withDeclName] def elabWithDeclName : TermElab := fun stx expectedType? => do
let id := stx[2].getId
let id := if stx[1].isNone then id else (← getCurrNamespace) ++ id
let e := stx[3]
withMacroExpansion stx e <| withDeclName id <| elabTerm e expectedType?
@[builtinTermElab typeOf] def elabTypeOf : TermElab := fun stx _ => do
inferType (← elabTerm stx[1] none)
/--
Recall that `mkTermInfo` does not create an `ofTermInfo` node in the info tree
if `e` corresponds to a hole that is going to be filled "later" by executing a tactic or resuming elaboration.
This behavior is problematic for auxiliary elaboration steps that are "almost" no-ops.
For example, consider the elaborator for
```
ensure_type_of% s msg e
```
It elaborates `s`, infers its type `t`, and then elaborates `e` ensuring the resulting type is `t`.
If the elaboration of `e` is postponed, then the result is just a metavariable, and an `ofTermInfo` would not be created.
This happens because `ensure_type_of%` is almost a no-op. The elaboration of `s` does not directly contribute to the
final result, just its type.
To make sure, we don't miss any information in the `InfoTree`, we can just create a "silent" annotation to force
`mTermInfo` to create a node for the `ensure_type_of% s msg e` even if `e` has been postponed.
Another possible solution is to elaborate `ensure_type_of% s msg e` as `ensureType s e` where `ensureType` has type
```
ensureType (s e : α) := e
```
We decided to use the silent notation because `ensure_type_of%` is heavily used in the `Do` elaborator, and the extra
overhead could be significant.
-/
private def mkSilentAnnotationIfHole (e : Expr) : TermElabM Expr := do
if (← isTacticOrPostponedHole? e).isSome then
return mkAnnotation `_silent e
else
return e
@[builtinTermElab ensureTypeOf] def elabEnsureTypeOf : TermElab := fun stx _ =>
match stx[2].isStrLit? with
| none => throwIllFormedSyntax
| some msg => do
let refTerm ← elabTerm stx[1] none
let refTermType ← inferType refTerm
-- See comment at `mkSilentAnnotationIfHole`
mkSilentAnnotationIfHole (← elabTermEnsuringType stx[3] refTermType (errorMsgHeader? := msg))
@[builtinTermElab ensureExpectedType] def elabEnsureExpectedType : TermElab := fun stx expectedType? =>
match stx[1].isStrLit? with
| none => throwIllFormedSyntax
| some msg => elabTermEnsuringType stx[2] expectedType? (errorMsgHeader? := msg)
@[builtinTermElab «open»] def elabOpen : TermElab := fun stx expectedType? => do
let `(open $decl in $e) := stx | throwUnsupportedSyntax
try
pushScope
let openDecls ← elabOpenDecl decl
withTheReader Core.Context (fun ctx => { ctx with openDecls := openDecls }) do
elabTerm e expectedType?
finally
popScope
@[builtinTermElab «set_option»] def elabSetOption : TermElab := fun stx expectedType? => do
let options ← Elab.elabSetOption stx[1] stx[2]
withTheReader Core.Context (fun ctx => { ctx with maxRecDepth := maxRecDepth.get options, options := options }) do
elabTerm stx[4] expectedType?
@[builtinTermElab withAnnotateTerm] def elabWithAnnotateTerm : TermElab := fun stx expectedType? => do
match stx with
| `(with_annotate_term $stx $e) =>
withInfoContext' stx (elabTerm e expectedType?) (mkTermInfo .anonymous (expectedType? := expectedType?) stx)
| _ => throwUnsupportedSyntax
private unsafe def evalFilePathUnsafe (stx : Syntax) : TermElabM System.FilePath :=
evalTerm System.FilePath (Lean.mkConst ``System.FilePath) stx
@[implementedBy evalFilePathUnsafe]
private opaque evalFilePath (stx : Syntax) : TermElabM System.FilePath
@[builtinTermElab includeStr] def elabIncludeStr : TermElab
| `(include_str $path:term), _ => do
let path ← evalFilePath path
let ctx ← readThe Lean.Core.Context
let srcPath := System.FilePath.mk ctx.fileName
let some srcDir := srcPath.parent
| throwError "cannot compute parent directory of '{srcPath}'"
let path := srcDir / path
mkStrLit <$> IO.FS.readFile path
| _, _ => throwUnsupportedSyntax
end Lean.Elab.Term
|
28f4aef251cf306543a35f63d2965ce8a10f521b | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/logic/unnamed_891.lean | e28516b30d8db61a399473c8c1e1eedc5a99c86e | [] | 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 | 367 | lean | import tactic
variables {α : Type*} [comm_ring α]
def sum_of_squares (x : α) := ∃ a b, x = a^2 + b^2
-- BEGIN
theorem sum_of_squares_mul {x y : α}
(sosx : sum_of_squares x) (sosy : sum_of_squares y) :
sum_of_squares (x * y) :=
begin
rcases sosx with ⟨a, b, rfl⟩,
rcases sosy with ⟨c, d, rfl⟩,
use [a*c - b*d, a*d + b*c],
ring
end
-- END |
c8b0afdbaf711ffaf33abd8c25e91b3aafc0887c | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/analysis/normed_space/operator_norm.lean | 91744d66af6fc77ea9f89e3f0b3384b4fae8d797 | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 37,059 | 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
-/
import linear_algebra.finite_dimensional
import analysis.normed_space.riesz_lemma
import analysis.asymptotics
/-!
# 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.
-/
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] },
{ 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 [nontrivial E] : ∥id 𝕜 E∥ = 1 :=
le_antisymm norm_id_le $ let ⟨x, hx⟩ := exists_ne (0 : E) 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
@[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) } ⟩)
/-- Continuous linear maps form a normed ring with respect to the operator norm. -/
instance to_normed_ring : normed_ring (E →L[𝕜] E) :=
{ norm_mul := op_norm_comp_le,
.. continuous_linear_map.to_normed_group }
/-- For a nonzero normed space `E`, continuous linear endomorphisms form a normed algebra with
respect to the operator norm. -/
instance to_normed_algebra [nontrivial E] : normed_algebra 𝕜 (E →L[𝕜] E) :=
{ norm_algebra_map_eq := λ c, show ∥c • id 𝕜 E∥ = ∥c∥,
by {rw [norm_smul, norm_id], simp},
.. continuous_linear_map.algebra }
/-- 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 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 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 (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 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 h_dense.induction_on₂ _ _,
{ exact is_closed_eq (cont.comp continuous_add)
((cont.comp continuous_fst).add (cont.comp continuous_snd)) },
{ assume x y, simp only [eq, ← e.map_add], exact f.map_add _ _ },
end,
map_smul' := λk,
begin
refine (λ b, h_dense.induction_on b _ _),
{ exact is_closed_eq (cont.comp (continuous_const.smul continuous_id))
((continuous_const.smul continuous_id).comp cont) },
{ assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ },
end,
cont := cont
}
lemma extend_unique (g : G →L[𝕜] F) (H : g.comp e = f) : extend f e h_dense h_e = g :=
continuous_linear_map.coe_injective' $
uniformly_extend_unique h_e h_dense (continuous_linear_map.ext_iff.1 H) g.continuous
@[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 :=
extend_unique _ _ _ _ _ (zero_comp _)
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
/-- Left-multiplication in a normed algebra, considered as a continuous linear map. -/
def lmul_left (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜] [normed_ring 𝕜']
[h : normed_algebra 𝕜 𝕜'] : 𝕜' → (𝕜' →L[𝕜] 𝕜') :=
λ x, (algebra.lmul_left 𝕜 𝕜' x).mk_continuous ∥x∥
(λ y, by {rw algebra.lmul_left_apply, exact norm_mul_le x y})
@[simp] lemma lmul_left_apply {𝕜 : Type*} (𝕜' : Type*) [normed_field 𝕜]
[normed_ring 𝕜'] [h : normed_algebra 𝕜 𝕜'] (x y : 𝕜') :
lmul_left 𝕜 𝕜' x y = x * y := rfl
/-- Right-multiplication in a normed algebra, considered as a continuous linear map. -/
def lmul_right (𝕜 : Type*) (𝕜' : Type*) [normed_field 𝕜]
[normed_ring 𝕜'] [h : normed_algebra 𝕜 𝕜'] : 𝕜' → (𝕜' →L[𝕜] 𝕜') :=
λ x, (algebra.lmul_right 𝕜 𝕜' x).mk_continuous ∥x∥
(λ y, by {rw [algebra.lmul_right_apply, mul_comm], exact norm_mul_le y x})
@[simp] lemma lmul_right_apply {𝕜 : Type*} (𝕜' : Type*) [normed_field 𝕜]
[normed_ring 𝕜'] [h : normed_algebra 𝕜 𝕜'] (x y : 𝕜') :
lmul_right 𝕜 𝕜' x y = y * x := rfl
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
variables {ι : Type*}
/-- Applying a continuous linear map commutes with taking an (infinite) sum. -/
lemma continuous_linear_map.has_sum {f : ι → E} (φ : E →L[𝕜] F) {x : E} (hf : has_sum f x) :
has_sum (λ (b:ι), φ (f b)) (φ x) :=
begin
unfold has_sum,
convert φ.continuous.continuous_at.tendsto.comp hf,
ext s, rw [function.comp_app, finset.sum_hom s φ],
end
lemma continuous_linear_map.has_sum_of_summable {f : ι → E} (φ : E →L[𝕜] F) (hf : summable f) :
has_sum (λ (b:ι), φ (f b)) (φ (∑'b, f b)) :=
continuous_linear_map.has_sum φ hf.has_sum
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 [nontrivial E] :
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]
end
lemma norm_pos [nontrivial E] : 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) (norm_nonneg _)
lemma norm_symm_pos [nontrivial E] : 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) (norm_nonneg _)
lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ :=
begin
rcases subsingleton_or_nontrivial E with _i|_i; resetI,
{ left, apply_instance },
{ right, exact e.norm_symm_pos }
end
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
variable (E)
/-- The continuous linear equivalences from `E` to itself form a group under composition. -/
instance automorphism_group : group (E ≃L[𝕜] E) :=
{ mul := λ f g, g.trans f,
one := continuous_linear_equiv.refl 𝕜 E,
inv := λ f, f.symm,
mul_assoc := λ f g h, by {ext, refl},
mul_one := λ f, by {ext, refl},
one_mul := λ f, by {ext, refl},
mul_left_inv := λ f, by {ext, exact f.left_inv x} }
variables {𝕜 E}
/-- An invertible continuous linear map `f` determines a continuous equivalence from `E` to itself.
-/
def of_unit (f : units (E →L[𝕜] E)) : (E ≃L[𝕜] E) :=
{ to_linear_equiv :=
{ to_fun := f.val,
map_add' := by simp,
map_smul' := by simp,
inv_fun := f.inv,
left_inv := λ x, show (f.inv * f.val) x = x, by {rw f.inv_val, simp},
right_inv := λ x, show (f.val * f.inv) x = x, by {rw f.val_inv, simp}, },
continuous_to_fun := f.val.continuous,
continuous_inv_fun := f.inv.continuous }
/-- A continuous equivalence from `E` to itself determines an invertible continuous linear map. -/
def to_unit (f : (E ≃L[𝕜] E)) : units (E →L[𝕜] E) :=
{ val := f,
inv := f.symm,
val_inv := by {ext, simp},
inv_val := by {ext, simp} }
variables (𝕜 E)
/-- The units of the algebra of continuous `𝕜`-linear endomorphisms of `E` is multiplicatively
equivalent to the type of continuous linear equivalences between `E` and itself. -/
def units_equiv : units (E →L[𝕜] E) ≃* (E ≃L[𝕜] E) :=
{ to_fun := of_unit,
inv_fun := to_unit,
left_inv := λ f, by {ext, refl},
right_inv := λ f, by {ext, refl},
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma units_equiv_to_continuous_linear_map
(f : units (E →L[𝕜] E)) :
(units_equiv 𝕜 E f : E →L[𝕜] E) = f := by {ext, refl}
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
|
f18cf704b4cdef996b9b2b69def1c442c2767c90 | 1446f520c1db37e157b631385707cc28a17a595e | /stage0/src/Init/Data/String.lean | 88da4da7080b51ac0893bb666121b5cd0daf0af6 | [
"Apache-2.0"
] | permissive | bdbabiak/lean4 | cab06b8a2606d99a168dd279efdd404edb4e825a | 3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac | refs/heads/master | 1,615,045,275,530 | 1,583,793,696,000 | 1,583,793,696,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 202 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.String.Basic
|
d6df3966c55b7f517d8cc90f9e3772cb346ea6d8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/number_field/class_number.lean | 4958f37408dfee0e113345b42c6c203adaefd735 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 1,787 | lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import number_theory.class_number.admissible_abs
import number_theory.class_number.finite
import number_theory.number_field.basic
/-!
# Class numbers of number fields
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the class number of a number field as the (finite) cardinality of
the class group of its ring of integers. It also proves some elementary results
on the class number.
## Main definitions
- `number_field.class_number`: the class number of a number field is the (finite)
cardinality of the class group of its ring of integers
-/
namespace number_field
variables (K : Type*) [field K] [number_field K]
namespace ring_of_integers
noncomputable instance : fintype (class_group (ring_of_integers K)) :=
class_group.fintype_of_admissible_of_finite ℚ K absolute_value.abs_is_admissible
end ring_of_integers
/-- The class number of a number field is the (finite) cardinality of the class group. -/
noncomputable def class_number : ℕ := fintype.card (class_group (ring_of_integers K))
variables {K}
/-- The class number of a number field is `1` iff the ring of integers is a PID. -/
theorem class_number_eq_one_iff :
class_number K = 1 ↔ is_principal_ideal_ring (ring_of_integers K) :=
card_class_group_eq_one_iff
end number_field
namespace rat
open number_field
theorem class_number_eq : number_field.class_number ℚ = 1 :=
class_number_eq_one_iff.mpr $ by convert is_principal_ideal_ring.of_surjective
(rat.ring_of_integers_equiv.symm : ℤ →+* ring_of_integers ℚ)
(rat.ring_of_integers_equiv.symm.surjective)
end rat
|
ccf71f1171b0d8befe384445d8342aef9acf03b3 | ed2fefcfa8b4fe534e01e6245f2696fd7c890d95 | /2019-02-25_aula1.lean | 28fe7fde63c8e1621751960110dca407db55cb54 | [] | no_license | Bpalkmim/EstOrientadoLean | 2036194e2211badb8ae18c1440edfe557b8e11d2 | 05a11f20cb5d0da612c9767fd97d0dbf698a405a | refs/heads/master | 1,588,562,078,354 | 1,557,777,940,000 | 1,557,777,940,000 | 178,943,165 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,200 | lean | -- Matéria de estudo orientado de L∃∀N com o Hermann
-- 2019.1
-- autor: Bernardo Alkmim
-- Objetivo geral: implementação de provas formais para NP=PSPACE
-- Discussão: futuro do L∃∀N indo mais para linguagem de programação e
-- saindo um pouco da característica de provador,
-- comparação com outros provadores como Agda, Coq etc.
-- Discussão teórica: diferenças entre cálculo de construções e ITT interativa?
-- Teoria dos tipos simples × teoria dos tipos.
-- Simples é o primeiro nível da hierarquia: tipos básicos, funcionais, produtos, coprodutos finitos. Nat se bá. Mas quantidade finita de interação. Church - tentativa de fundamentar a matemática ocmo reação ao paradoxo de Russell.
-- A teoria dos tipos (não simples) envolve abstração sobre os tipos simples.
-- λ cube? Sabores de λ calculus?
-- λ calculus. Modelo de computação assim como funções recursivas, máquinas de Turing etc.
-- Operador de ponto fixo Y ≡ λf.((λx. f (x x))(λx. f (x x))) para realizar recursão primitiva e geral.
-- Independência do Y para o tipo de dado utilizado → não tem tipo (versão não tipada).
-- λ calculus tipado: paradoxo de Russell e teorema de Gödel. Não podemos fazer (x x) poiso primeiro deve ter um tipo funcional sobre o segundo, mas os tipos devem ser o mesmo (pois é o mesmo cara). Aí perde a graça pois Y não pode ser realizado. Temos apenas recursão primitiva, e só funções totais.
-- Obs.: λ calculus não é extensional.
-- Outro modelo computacional: lógica combinatória (Haskell Curry).
-- K : A → (B → A)
-- S : (A → (B → C)) → ((A → B) → (A → C))
-- Dupla Neg : ¬¬A → A
-- Efq : A → (¬A → B)
-- Modus ponens : α, α → β ⊢ β
-- Substituição : α ⊢ σ[x/y] α
-- Schoenfinkel : aplicação associativa à esquerda
-- K a b ▷ a
-- S a b c ▷ a c (b c)
-- I ≡ SKK (ou SKS, ou SK batatinha). I a ▷ a
-- Não há substituição pois não há variáveis!!!! (Curry não gostava de substituição de variáveis no nível lógico)
-- Relação entre o que é demonstrado por K S + modus ponens e substituição (lógica intuicionista minimal) e o que pode ser feito com combinadores. Toda prova em IPL (minimal) corresponde a um combinador (e vice-versa).
-- À época não havia tipos, e o isomorfismo Curry-Howard é tipado (tipos são fórmulas). Howard: types as formulas.
-- Codificar λ calculus em combinadores
-- [x] v = I, se x = v, e K v, se x != v
-- [x] (e e') = ([x] e) ([x] e') = S ([x] e) ([x] e')
-- [x] (λy. e) = [x]([y] M)
-- e e' ▷* L ⇔ e* e'* ▷* L* (via Church-Rosser)
-- Paralelos de normalização de provas em Dedução Natural (para M→) e normalização de λ calculus tipado.
-- Normalização forte: todo termo converge i.e. toda computação para.
-- λ calculus tipado apresenta normalização forte.
-- Ter recursão (primitiva) para o λ calculus tipado, nos moldes do Y.
-- É necessário criar um combinador de recursão para cada tipo.
-- Objetivo: alguém que seja Y M ≡ M (Y M).
-- Recursão primitiva:
-- f(x,0) = g(x)
-- f(x,s(y)) = h(x, y, f(x,y))
-- Como colocar no λ calculus?
-- Tipo "formador de f"
-- g : A → A
-- h : A → Nat → A → A
-- f : A → Nat → A
-- Operador de recursão para A.
-- Rec^{A}: (A → A) → Nat → (A → Nat → A → A) → (A → Nat → A)
-- Rec^{A}(g, n, h) = g, se n = 0
-- = h(g, k, Rec^{A}(g, h, k)), se n = s(k)
-- Resultado do Gödel no teorema da incompletude: toda prova na aritmética com indução corresponde a uma função computável definida por recursão primitiva.
-- Como faz para colocar Ackermann? Coloca a recursão em dois valores: novo construtor de recursão.
-- Tem hierarquia de funções totais, precisa de um construtor para funções (ainda totais) superiores a Ackermann.
-- Sistema T de tipos transfinitos.
-- Rec0, Rec1, Rec2 etc. para cada tipo. RecListas (de primeira ordem). RecParesDeListas. RecListasDeListas etc. cada uma pra um tipo e cada operador pra cada função de cada tipo. Isso engloba todas as funções computáveis totais (Gödel). ω elevado a ω etc. (aquelas brincadeiras do Hermann) aka ε0. |
8556c68017c5d611fcabdefdad15853b4c2eba67 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/control/functor/multivariate.lean | 18394bd93ff122c9ad1104f6a44d4e0ab8033765 | [
"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 | 6,714 | lean | /-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Simon Hudon
-/
import data.fin2
import data.typevec
import logic.function.basic
import tactic.basic
/-!
Functors between the category of tuples of types, and the category Type
Features:
`mvfunctor n` : the type class of multivariate functors
`f <$$> x` : notation for map
-/
universes u v w
open_locale mvfunctor
/-- multivariate functors, i.e. functor between the category of type vectors
and the category of Type -/
class mvfunctor {n : ℕ} (F : typevec n → Type*) :=
(map : Π {α β : typevec n}, (α ⟹ β) → (F α → F β))
localized "infixr ` <$$> `:100 := mvfunctor.map" in mvfunctor
variables {n : ℕ}
namespace mvfunctor
variables {α β γ : typevec.{u} n} {F : typevec.{u} n → Type v} [mvfunctor F]
/-- predicate lifting over multivariate functors -/
def liftp {α : typevec n} (p : Π i, α i → Prop) (x : F α) : Prop :=
∃ u : F (λ i, subtype (p i)), (λ i, @subtype.val _ (p i)) <$$> u = x
/-- relational lifting over multivariate functors -/
def liftr {α : typevec n} (r : Π {i}, α i → α i → Prop) (x y : F α) : Prop :=
∃ u : F (λ i, {p : α i × α i // r p.fst p.snd}),
(λ i (t : {p : α i × α i // r p.fst p.snd}), t.val.fst) <$$> u = x ∧
(λ i (t : {p : α i × α i // r p.fst p.snd}), t.val.snd) <$$> u = y
/-- given `x : F α` and a projection `i` of type vector `α`, `supp x i` is the set
of `α.i` contained in `x` -/
def supp {α : typevec n} (x : F α) (i : fin2 n) : set (α i) :=
{ y : α i | ∀ ⦃p⦄, liftp p x → p i y }
theorem of_mem_supp {α : typevec n} {x : F α} {p : Π ⦃i⦄, α i → Prop} (h : liftp p x) (i : fin2 n):
∀ y ∈ supp x i, p y :=
λ y hy, hy h
end mvfunctor
/-- laws for `mvfunctor` -/
class is_lawful_mvfunctor {n : ℕ} (F : typevec n → Type*) [mvfunctor F] : Prop :=
(id_map : ∀ {α : typevec n} (x : F α), typevec.id <$$> x = x)
(comp_map : ∀ {α β γ : typevec n} (g : α ⟹ β) (h : β ⟹ γ) (x : F α),
(h ⊚ g) <$$> x = h <$$> g <$$> x)
open nat typevec
namespace mvfunctor
export is_lawful_mvfunctor (comp_map)
open is_lawful_mvfunctor
variables {α β γ : typevec.{u} n}
variables {F : typevec.{u} n → Type v} [mvfunctor F]
variables (p : α ⟹ repeat n Prop) (r : α ⊗ α ⟹ repeat n Prop)
/-- adapt `mvfunctor.liftp` to accept predicates as arrows -/
def liftp' : F α → Prop :=
mvfunctor.liftp $ λ i x, of_repeat $ p i x
/-- adapt `mvfunctor.liftp` to accept relations as arrows -/
def liftr' : F α → F α → Prop :=
mvfunctor.liftr $ λ i x y, of_repeat $ r i $ typevec.prod.mk _ x y
variables [is_lawful_mvfunctor F]
@[simp]
lemma id_map (x : F α) :
typevec.id <$$> x = x :=
id_map x
@[simp]
lemma id_map' (x : F α) :
(λ i a, a) <$$> x = x :=
id_map x
lemma map_map (g : α ⟹ β) (h : β ⟹ γ) (x : F α) :
h <$$> g <$$> x = (h ⊚ g) <$$> x :=
eq.symm $ comp_map _ _ _
section liftp'
variables (F)
lemma exists_iff_exists_of_mono {p : F α → Prop} {q : F β → Prop} (f : α ⟹ β) (g : β ⟹ α)
(h₀ : f ⊚ g = id)
(h₁ : ∀ u : F α, p u ↔ q (f <$$> u)) :
(∃ u : F α, p u) ↔ (∃ u : F β, q u) :=
begin
split; rintro ⟨u,h₂⟩; [ use f <$$> u, use g <$$> u ],
{ apply (h₁ u).mp h₂ },
{ apply (h₁ _).mpr _,
simp only [mvfunctor.map_map,h₀,is_lawful_mvfunctor.id_map,h₂] },
end
variables {F}
lemma liftp_def (x : F α) : liftp' p x ↔ ∃ u : F (subtype_ p), subtype_val p <$$> u = x :=
exists_iff_exists_of_mono F _ _ (to_subtype_of_subtype p) (by simp [mvfunctor.map_map])
lemma liftr_def (x y : F α) :
liftr' r x y ↔
∃ u : F (subtype_ r), (typevec.prod.fst ⊚ subtype_val r) <$$> u = x ∧
(typevec.prod.snd ⊚ subtype_val r) <$$> u = y :=
exists_iff_exists_of_mono _ _ _ (to_subtype'_of_subtype' r)
(by simp only [map_map, comp_assoc, subtype_val_to_subtype']; simp [comp])
end liftp'
end mvfunctor
open nat
namespace mvfunctor
open typevec
section liftp_last_pred_iff
variables {F : typevec.{u} (n+1) → Type*} [mvfunctor F] [is_lawful_mvfunctor F]
{α : typevec.{u} n}
variables (p : α ⟹ repeat n Prop)
(r : α ⊗ α ⟹ repeat n Prop)
open mvfunctor
variables {β : Type u}
variables (pp : β → Prop)
private def f : Π (n α), (λ (i : fin2 (n + 1)), {p_1 // of_repeat (pred_last' α pp i p_1)}) ⟹
λ (i : fin2 (n + 1)), {p_1 : (α ::: β) i // pred_last α pp p_1}
| _ α (fin2.fs i) x := ⟨ x.val, cast (by simp only [pred_last]; erw const_iff_true) x.property ⟩
| _ α fin2.fz x := ⟨ x.val, x.property ⟩
private def g : Π (n α), (λ (i : fin2 (n + 1)), {p_1 : (α ::: β) i // pred_last α pp p_1}) ⟹
(λ (i : fin2 (n + 1)), {p_1 // of_repeat (pred_last' α pp i p_1)})
| _ α (fin2.fs i) x := ⟨ x.val, cast (by simp only [pred_last]; erw const_iff_true) x.property ⟩
| _ α fin2.fz x := ⟨ x.val, x.property ⟩
lemma liftp_last_pred_iff {β} (p : β → Prop) (x : F (α ::: β)) :
liftp' (pred_last' _ p) x ↔ liftp (pred_last _ p) x :=
begin
dsimp only [liftp,liftp'],
apply exists_iff_exists_of_mono F (f _ n α) (g _ n α),
{ clear x _inst_2 _inst_1 F, ext i ⟨x,_⟩, cases i; refl },
{ intros, rw [mvfunctor.map_map,(⊚)],
congr'; ext i ⟨x,_⟩; cases i; refl }
end
open function
variables (rr : β → β → Prop)
private def f :
Π (n α),
(λ (i : fin2 (n + 1)),
{p_1 : _ × _ // of_repeat (rel_last' α rr i (typevec.prod.mk _ p_1.fst p_1.snd))}) ⟹
λ (i : fin2 (n + 1)), {p_1 : (α ::: β) i × _ // rel_last α rr (p_1.fst) (p_1.snd)}
| _ α (fin2.fs i) x := ⟨ x.val, cast (by simp only [rel_last]; erw repeat_eq_iff_eq) x.property ⟩
| _ α fin2.fz x := ⟨ x.val, x.property ⟩
private def g :
Π (n α), (λ (i : fin2 (n + 1)), {p_1 : (α ::: β) i × _ // rel_last α rr (p_1.fst) (p_1.snd)}) ⟹
(λ (i : fin2 (n + 1)),
{p_1 : _ × _ // of_repeat (rel_last' α rr i (typevec.prod.mk _ p_1.1 p_1.2))})
| _ α (fin2.fs i) x := ⟨ x.val, cast (by simp only [rel_last]; erw repeat_eq_iff_eq) x.property ⟩
| _ α fin2.fz x := ⟨ x.val, x.property ⟩
lemma liftr_last_rel_iff (x y : F (α ::: β)) :
liftr' (rel_last' _ rr) x y ↔ liftr (rel_last _ rr) x y :=
begin
dsimp only [liftr,liftr'],
apply exists_iff_exists_of_mono F (f rr _ _) (g rr _ _),
{ clear x y _inst_2 _inst_1 F, ext i ⟨x,_⟩ : 2, cases i; refl, },
{ intros, rw [mvfunctor.map_map,mvfunctor.map_map,(⊚),(⊚)],
congr'; ext i ⟨x,_⟩; cases i; refl }
end
end liftp_last_pred_iff
end mvfunctor
|
ac59f02f117fd9b5d8ba2a7d4d45b5551c7a75ff | 94e33a31faa76775069b071adea97e86e218a8ee | /src/set_theory/zfc.lean | 9dc531408f980a60c7fe4c3ae398a719623256a0 | [
"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 | 35,238 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.set.lattice
/-!
# A model of ZFC
In this file, we model Zermelo-Fraenkel set theory (+ Choice) using Lean's underlying type theory.
We do this in four main steps:
* Define pre-sets inductively.
* Define extensional equivalence on pre-sets and give it a `setoid` instance.
* Define ZFC sets by quotienting pre-sets by extensional equivalence.
* Define classes as sets of ZFC sets.
Then the rest is usual set theory.
## The model
* `pSet`: Pre-set. A pre-set is inductively defined by its indexing type and its members, which are
themselves pre-sets.
* `Set`: ZFC set. Defined as `pSet` quotiented by `pSet.equiv`, the extensional equivalence.
* `Class`: Class. Defined as `set Set`.
* `Set.choice`: Axiom of choice. Proved from Lean's axiom of choice.
## Other definitions
* `arity α n`: `n`-ary function `α → α → ... → α`. Defined inductively.
* `arity.const a n`: `n`-ary constant function equal to `a`.
* `pSet.type`: Underlying type of a pre-set.
* `pSet.func`: Underlying family of pre-sets of a pre-set.
* `pSet.equiv`: Extensional equivalence of pre-sets. Defined inductively.
* `pSet.omega`, `Set.omega`: The von Neumann ordinal `ω` as a `pSet`, as a `Set`.
* `pSet.arity.equiv`: Extensional equivalence of `n`-ary `pSet`-valued functions. Extension of
`pSet.equiv`.
* `pSet.resp`: Collection of `n`-ary `pSet`-valued functions that respect extensional equivalence.
* `pSet.eval`: Turns a `pSet`-valued function that respect extensional equivalence into a
`Set`-valued function.
* `classical.all_definable`: All functions are classically definable.
* `Set.is_func` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC
function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of
`y`.
* `Set.funs`: ZFC set of ZFC functions `x → y`.
* `Class.iota`: Definite description operator.
## Notes
To avoid confusion between the Lean `set` and the ZFC `Set`, docstrings in this file refer to them
respectively as "`set`" and "ZFC set".
## TODO
Prove `Set.map_definable_aux` computably.
-/
universes u v
/-- The type of `n`-ary functions `α → α → ... → α`. -/
def arity (α : Type u) : ℕ → Type u
| 0 := α
| (n+1) := α → arity n
@[simp] theorem arity_zero (α : Type u) : arity α 0 = α := rfl
@[simp] theorem arity_succ (α : Type u) (n : ℕ) : arity α n.succ = (α → arity α n) := rfl
namespace arity
/-- Constant `n`-ary function with value `a`. -/
def const {α : Type u} (a : α) : ∀ n, arity α n
| 0 := a
| (n+1) := λ _, const n
@[simp] theorem const_zero {α : Type u} (a : α) : const a 0 = a := rfl
@[simp] theorem const_succ {α : Type u} (a : α) (n : ℕ) : const a n.succ = λ _, const a n := rfl
theorem const_succ_apply {α : Type u} (a : α) (n : ℕ) (x : α) : const a n.succ x = const a n := rfl
instance arity.inhabited {α n} [inhabited α] : inhabited (arity α n) := ⟨const default _⟩
end arity
/-- The type of pre-sets in universe `u`. A pre-set
is a family of pre-sets indexed by a type in `Type u`.
The ZFC universe is defined as a quotient of this
to ensure extensionality. -/
inductive pSet : Type (u+1)
| mk (α : Type u) (A : α → pSet) : pSet
namespace pSet
/-- The underlying type of a pre-set -/
@[nolint has_inhabited_instance] def type : pSet → Type u
| ⟨α, A⟩ := α
/-- The underlying pre-set family of a pre-set -/
def func : Π (x : pSet), x.type → pSet
| ⟨α, A⟩ := A
@[simp] theorem eta : Π (x : pSet), mk x.type x.func = x
| ⟨α, A⟩ := rfl
/-- Two pre-sets are extensionally equivalent if every element of the first family is extensionally
equivalent to some element of the second family and vice-versa. -/
def equiv (x y : pSet) : Prop :=
pSet.rec (λ α z m ⟨β, B⟩, (∀ a, ∃ b, m a (B b)) ∧ (∀ b, ∃ a, m a (B b))) x y
theorem exists_equiv_left : Π {x y : pSet} (h : equiv x y) (i : x.type),
∃ j, equiv (x.func i) (y.func j)
| ⟨α, A⟩ ⟨β, B⟩ h := h.1
theorem exists_equiv_right : Π {x y : pSet} (h : equiv x y) (j : y.type),
∃ i, equiv (x.func i) (y.func j)
| ⟨α, A⟩ ⟨β, B⟩ h := h.2
protected theorem equiv.refl (x) : equiv x x :=
pSet.rec_on x $ λ α A IH, ⟨λ a, ⟨a, IH a⟩, λ a, ⟨a, IH a⟩⟩
protected theorem equiv.rfl : ∀ {x}, equiv x x := equiv.refl
protected theorem equiv.euc {x} : Π {y z}, equiv x y → equiv z y → equiv x z :=
pSet.rec_on x $ λ α A IH y, pSet.cases_on y $ λ β B ⟨γ, Γ⟩ ⟨αβ, βα⟩ ⟨γβ, βγ⟩,
⟨λ a, let ⟨b, ab⟩ := αβ a, ⟨c, bc⟩ := βγ b in ⟨c, IH a ab bc⟩,
λ c, let ⟨b, cb⟩ := γβ c, ⟨a, ba⟩ := βα b in ⟨a, IH a ba cb⟩⟩
protected theorem equiv.symm {x y} : equiv x y → equiv y x :=
(equiv.refl y).euc
protected theorem equiv.trans {x y z} (h1 : equiv x y) (h2 : equiv y z) : equiv x z :=
h1.euc h2.symm
instance setoid : setoid pSet :=
⟨pSet.equiv, equiv.refl, λ x y, equiv.symm, λ x y z, equiv.trans⟩
/-- A pre-set is a subset of another pre-set if every element of the first family is extensionally
equivalent to some element of the second family.-/
protected def subset : pSet → pSet → Prop
| ⟨α, A⟩ ⟨β, B⟩ := ∀ a, ∃ b, equiv (A a) (B b)
instance : has_subset pSet := ⟨pSet.subset⟩
theorem equiv.ext : Π (x y : pSet), equiv x y ↔ (x ⊆ y ∧ y ⊆ x)
| ⟨α, A⟩ ⟨β, B⟩ :=
⟨λ ⟨αβ, βα⟩, ⟨αβ, λ b, let ⟨a, h⟩ := βα b in ⟨a, equiv.symm h⟩⟩,
λ ⟨αβ, βα⟩, ⟨αβ, λ b, let ⟨a, h⟩ := βα b in ⟨a, equiv.symm h⟩⟩⟩
theorem subset.congr_left : Π {x y z : pSet}, equiv x y → (x ⊆ z ↔ y ⊆ z)
| ⟨α, A⟩ ⟨β, B⟩ ⟨γ, Γ⟩ ⟨αβ, βα⟩ :=
⟨λ αγ b, let ⟨a, ba⟩ := βα b, ⟨c, ac⟩ := αγ a in ⟨c, (equiv.symm ba).trans ac⟩,
λ βγ a, let ⟨b, ab⟩ := αβ a, ⟨c, bc⟩ := βγ b in ⟨c, equiv.trans ab bc⟩⟩
theorem subset.congr_right : Π {x y z : pSet}, equiv x y → (z ⊆ x ↔ z ⊆ y)
| ⟨α, A⟩ ⟨β, B⟩ ⟨γ, Γ⟩ ⟨αβ, βα⟩ :=
⟨λ γα c, let ⟨a, ca⟩ := γα c, ⟨b, ab⟩ := αβ a in ⟨b, ca.trans ab⟩,
λ γβ c, let ⟨b, cb⟩ := γβ c, ⟨a, ab⟩ := βα b in ⟨a, cb.trans (equiv.symm ab)⟩⟩
/-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member of the family `y`. -/
def mem : pSet → pSet → Prop
| x ⟨β, B⟩ := ∃ b, equiv x (B b)
instance : has_mem pSet.{u} pSet.{u} := ⟨mem⟩
theorem mem.mk {α : Type u} (A : α → pSet) (a : α) : A a ∈ mk α A :=
⟨a, equiv.refl (A a)⟩
theorem mem.ext : Π {x y : pSet.{u}}, (∀ w : pSet.{u}, w ∈ x ↔ w ∈ y) → equiv x y
| ⟨α, A⟩ ⟨β, B⟩ h := ⟨λ a, (h (A a)).1 (mem.mk A a),
λ b, let ⟨a, ha⟩ := (h (B b)).2 (mem.mk B b) in ⟨a, ha.symm⟩⟩
theorem mem.congr_right : Π {x y : pSet.{u}}, equiv x y → (∀ {w : pSet.{u}}, w ∈ x ↔ w ∈ y)
| ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ w :=
⟨λ ⟨a, ha⟩, let ⟨b, hb⟩ := αβ a in ⟨b, ha.trans hb⟩,
λ ⟨b, hb⟩, let ⟨a, ha⟩ := βα b in ⟨a, hb.euc ha⟩⟩
theorem equiv_iff_mem {x y : pSet.{u}} : equiv x y ↔ (∀ {w : pSet.{u}}, w ∈ x ↔ w ∈ y) :=
⟨mem.congr_right, match x, y with
| ⟨α, A⟩, ⟨β, B⟩, h := ⟨λ a, h.1 (mem.mk A a), λ b,
let ⟨a, h⟩ := h.2 (mem.mk B b) in ⟨a, h.symm⟩⟩
end⟩
theorem mem.congr_left : Π {x y : pSet.{u}}, equiv x y → (∀ {w : pSet.{u}}, x ∈ w ↔ y ∈ w)
| x y h ⟨α, A⟩ := ⟨λ ⟨a, ha⟩, ⟨a, h.symm.trans ha⟩, λ ⟨a, ha⟩, ⟨a, h.trans ha⟩⟩
/-- Convert a pre-set to a `set` of pre-sets. -/
def to_set (u : pSet.{u}) : set pSet.{u} := {x | x ∈ u}
/-- Two pre-sets are equivalent iff they have the same members. -/
theorem equiv.eq {x y : pSet} : equiv x y ↔ to_set x = to_set y :=
equiv_iff_mem.trans set.ext_iff.symm
instance : has_coe pSet (set pSet) := ⟨to_set⟩
/-- The empty pre-set -/
protected def empty : pSet := ⟨_, pempty.elim⟩
instance : has_emptyc pSet := ⟨pSet.empty⟩
instance : inhabited pSet := ⟨∅⟩
@[simp] theorem mem_empty (x : pSet.{u}) : x ∉ (∅ : pSet.{u}) := is_empty.exists_iff.1
/-- Insert an element into a pre-set -/
protected def insert : pSet → pSet → pSet
| u ⟨α, A⟩ := ⟨option α, λ o, option.rec u A o⟩
instance : has_insert pSet pSet := ⟨pSet.insert⟩
instance : has_singleton pSet pSet := ⟨λ s, insert s ∅⟩
instance : is_lawful_singleton pSet pSet := ⟨λ _, rfl⟩
/-- The n-th von Neumann ordinal -/
def of_nat : ℕ → pSet
| 0 := ∅
| (n+1) := pSet.insert (of_nat n) (of_nat n)
/-- The von Neumann ordinal ω -/
def omega : pSet := ⟨ulift ℕ, λ n, of_nat n.down⟩
/-- The pre-set separation operation `{x ∈ a | p x}` -/
protected def sep (p : set pSet) : pSet → pSet
| ⟨α, A⟩ := ⟨{a // p (A a)}, λ x, A x.1⟩
instance : has_sep pSet pSet := ⟨pSet.sep⟩
/-- The pre-set powerset operator -/
def powerset : pSet → pSet
| ⟨α, A⟩ := ⟨set α, λ p, ⟨{a // p a}, λ x, A x.1⟩⟩
@[simp] theorem mem_powerset : Π {x y : pSet}, y ∈ powerset x ↔ y ⊆ x
| ⟨α, A⟩ ⟨β, B⟩ := ⟨λ ⟨p, e⟩, (subset.congr_left e).2 $ λ ⟨a, pa⟩, ⟨a, equiv.refl (A a)⟩,
λ βα, ⟨{a | ∃ b, equiv (B b) (A a)}, λ b, let ⟨a, ba⟩ := βα b in ⟨⟨a, b, ba⟩, ba⟩,
λ ⟨a, b, ba⟩, ⟨b, ba⟩⟩⟩
/-- The pre-set union operator -/
def Union : pSet → pSet
| ⟨α, A⟩ := ⟨Σ x, (A x).type, λ ⟨x, y⟩, (A x).func y⟩
@[simp] theorem mem_Union : Π {x y : pSet.{u}}, y ∈ Union x ↔ ∃ z ∈ x, y ∈ z
| ⟨α, A⟩ y :=
⟨λ ⟨⟨a, c⟩, (e : equiv y ((A a).func c))⟩,
have func (A a) c ∈ mk (A a).type (A a).func, from mem.mk (A a).func c,
⟨_, mem.mk _ _, (mem.congr_left e).2 (by rwa eta at this)⟩,
λ ⟨⟨β, B⟩, ⟨a, (e : equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩,
by { rw ←(eta (A a)) at e, exact
let ⟨βt, tβ⟩ := e, ⟨c, bc⟩ := βt b in ⟨⟨a, c⟩, yb.trans bc⟩ }⟩
/-- The image of a function from pre-sets to pre-sets. -/
def image (f : pSet.{u} → pSet.{u}) : pSet.{u} → pSet
| ⟨α, A⟩ := ⟨α, f ∘ A⟩
theorem mem_image {f : pSet.{u} → pSet.{u}} (H : ∀ {x y}, equiv x y → equiv (f x) (f y)) :
Π {x y : pSet.{u}}, y ∈ image f x ↔ ∃ z ∈ x, equiv y (f z)
| ⟨α, A⟩ y := ⟨λ ⟨a, ya⟩, ⟨A a, mem.mk A a, ya⟩, λ ⟨z, ⟨a, za⟩, yz⟩, ⟨a, yz.trans (H za)⟩⟩
/-- Universe lift operation -/
protected def lift : pSet.{u} → pSet.{max u v}
| ⟨α, A⟩ := ⟨ulift α, λ ⟨x⟩, lift (A x)⟩
/-- Embedding of one universe in another -/
@[nolint check_univs] -- intended to be used with explicit universe parameters
def embed : pSet.{max (u+1) v} := ⟨ulift.{v u+1} pSet, λ ⟨x⟩, pSet.lift.{u (max (u+1) v)} x⟩
theorem lift_mem_embed : Π (x : pSet.{u}), pSet.lift.{u (max (u+1) v)} x ∈ embed.{u v} :=
λ x, ⟨⟨x⟩, equiv.rfl⟩
/-- Function equivalence is defined so that `f ~ g` iff `∀ x y, x ~ y → f x ~ g y`. This extends to
equivalence of `n`-ary functions. -/
def arity.equiv : Π {n}, arity pSet.{u} n → arity pSet.{u} n → Prop
| 0 a b := equiv a b
| (n+1) a b := ∀ x y, equiv x y → arity.equiv (a x) (b y)
lemma arity.equiv_const {a : pSet.{u}} : ∀ n, arity.equiv (arity.const a n) (arity.const a n)
| 0 := equiv.rfl
| (n+1) := λ x y h, arity.equiv_const _
/-- `resp n` is the collection of n-ary functions on `pSet` that respect
equivalence, i.e. when the inputs are equivalent the output is as well. -/
def resp (n) := {x : arity pSet.{u} n // arity.equiv x x}
instance resp.inhabited {n} : inhabited (resp n) :=
⟨⟨arity.const default _, arity.equiv_const _⟩⟩
/-- The `n`-ary image of a `(n + 1)`-ary function respecting equivalence as a function respecting
equivalence. -/
def resp.f {n} (f : resp (n+1)) (x : pSet) : resp n :=
⟨f.1 x, f.2 _ _ $ equiv.refl x⟩
/-- Function equivalence for functions respecting equivalence. See `pSet.arity.equiv`. -/
def resp.equiv {n} (a b : resp n) : Prop := arity.equiv a.1 b.1
protected theorem resp.equiv.refl {n} (a : resp n) : resp.equiv a a := a.2
protected theorem resp.equiv.euc : Π {n} {a b c : resp n},
resp.equiv a b → resp.equiv c b → resp.equiv a c
| 0 a b c hab hcb := equiv.euc hab hcb
| (n+1) a b c hab hcb := λ x y h,
@resp.equiv.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ $ equiv.refl y)
protected theorem resp.equiv.symm {n} {a b : resp n} : resp.equiv a b → resp.equiv b a :=
(resp.equiv.refl b).euc
protected theorem resp.equiv.trans {n} {x y z : resp n}
(h1 : resp.equiv x y) (h2 : resp.equiv y z) : resp.equiv x z :=
h1.euc h2.symm
instance resp.setoid {n} : setoid (resp n) :=
⟨resp.equiv, resp.equiv.refl, λ x y, resp.equiv.symm, λ x y z, resp.equiv.trans⟩
end pSet
/-- The ZFC universe of sets consists of the type of pre-sets,
quotiented by extensional equivalence. -/
def Set : Type (u+1) := quotient pSet.setoid.{u}
namespace pSet
namespace resp
/-- Helper function for `pSet.eval`. -/
def eval_aux : Π {n}, {f : resp n → arity Set.{u} n // ∀ (a b : resp n), resp.equiv a b → f a = f b}
| 0 := ⟨λ a, ⟦a.1⟧, λ a b h, quotient.sound h⟩
| (n+1) := let F : resp (n + 1) → arity Set (n + 1) := λ a, @quotient.lift _ _ pSet.setoid
(λ x, eval_aux.1 (a.f x)) (λ b c h, eval_aux.2 _ _ (a.2 _ _ h)) in
⟨F, λ b c h, funext $ @quotient.ind _ _ (λ q, F b q = F c q) $ λ z,
eval_aux.2 (resp.f b z) (resp.f c z) (h _ _ (pSet.equiv.refl z))⟩
/-- An equivalence-respecting function yields an n-ary ZFC set function. -/
def eval (n) : resp n → arity Set.{u} n := eval_aux.1
theorem eval_val {n f x} : (@eval (n+1) f : Set → arity Set n) ⟦x⟧ = eval n (resp.f f x) := rfl
end resp
/-- A set function is "definable" if it is the image of some n-ary pre-set
function. This isn't exactly definability, but is useful as a sufficient
condition for functions that have a computable image. -/
class inductive definable (n) : arity Set.{u} n → Type (u+1)
| mk (f) : definable (resp.eval n f)
attribute [instance] definable.mk
/-- The evaluation of a function respecting equivalence is definable, by that same function. -/
def definable.eq_mk {n} (f) : Π {s : arity Set.{u} n} (H : resp.eval _ f = s), definable n s
| ._ rfl := ⟨f⟩
/-- Turns a definable function into a function that respects equivalence. -/
def definable.resp {n} : Π (s : arity Set.{u} n) [definable n s], resp n
| ._ ⟨f⟩ := f
theorem definable.eq {n} :
Π (s : arity Set.{u} n) [H : definable n s], (@definable.resp n s H).eval _ = s
| ._ ⟨f⟩ := rfl
end pSet
namespace classical
open pSet
/-- All functions are classically definable. -/
noncomputable def all_definable : Π {n} (F : arity Set.{u} n), definable n F
| 0 F := let p := @quotient.exists_rep pSet _ F in
definable.eq_mk ⟨some p, equiv.rfl⟩ (some_spec p)
| (n+1) (F : arity Set.{u} (n + 1)) := begin
have I := λ x, (all_definable (F x)),
refine definable.eq_mk ⟨λ x : pSet, (@definable.resp _ _ (I ⟦x⟧)).1, _⟩ _,
{ dsimp [arity.equiv],
introsI x y h,
rw @quotient.sound pSet _ _ _ h,
exact (definable.resp (F ⟦y⟧)).2 },
refine funext (λ q, quotient.induction_on q $ λ x, _),
simp_rw [resp.eval_val, resp.f, subtype.val_eq_coe, subtype.coe_eta],
exact @definable.eq _ (F ⟦x⟧) (I ⟦x⟧),
end
end classical
namespace Set
open pSet
/-- Turns a pre-set into a ZFC set. -/
def mk : pSet → Set := quotient.mk
@[simp] theorem mk_eq (x : pSet) : @eq Set ⟦x⟧ (mk x) := rfl
@[simp] theorem mk_out : ∀ x : Set, mk x.out = x := quotient.out_eq
theorem eq {x y : pSet} : mk x = mk y ↔ equiv x y := quotient.eq
theorem sound {x y : pSet} (h : pSet.equiv x y) : mk x = mk y := quotient.sound h
theorem exact {x y : pSet} : mk x = mk y → pSet.equiv x y := quotient.exact
@[simp] lemma eval_mk {n f x} :
(@resp.eval (n+1) f : Set → arity Set n) (mk x) = resp.eval n (resp.f f x) :=
rfl
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
def mem : Set → Set → Prop :=
quotient.lift₂ pSet.mem
(λ x y x' y' hx hy, propext ((mem.congr_left hx).trans (mem.congr_right hy)))
instance : has_mem Set Set := ⟨mem⟩
/-- Convert a ZFC set into a `set` of ZFC sets -/
def to_set (u : Set.{u}) : set Set.{u} := {x | x ∈ u}
/-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/
protected def subset (x y : Set.{u}) :=
∀ ⦃z⦄, z ∈ x → z ∈ y
instance has_subset : has_subset Set :=
⟨Set.subset⟩
lemma subset_def {x y : Set.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y := iff.rfl
@[simp] theorem subset_iff : Π (x y : pSet), mk x ⊆ mk y ↔ x ⊆ y
| ⟨α, A⟩ ⟨β, B⟩ := ⟨λ h a, @h ⟦A a⟧ (mem.mk A a),
λ h z, quotient.induction_on z (λ z ⟨a, za⟩, let ⟨b, ab⟩ := h a in ⟨b, za.trans ab⟩)⟩
theorem ext {x y : Set.{u}} : (∀ z : Set.{u}, z ∈ x ↔ z ∈ y) → x = y :=
quotient.induction_on₂ x y (λ u v h, quotient.sound (mem.ext (λ w, h ⟦w⟧)))
theorem ext_iff {x y : Set.{u}} : (∀ z : Set.{u}, z ∈ x ↔ z ∈ y) ↔ x = y :=
⟨ext, λ h, by simp [h]⟩
/-- The empty ZFC set -/
def empty : Set := mk ∅
instance : has_emptyc Set := ⟨empty⟩
instance : inhabited Set := ⟨∅⟩
@[simp] theorem mem_empty (x) : x ∉ (∅ : Set.{u}) :=
quotient.induction_on x pSet.mem_empty
theorem eq_empty (x : Set.{u}) : x = ∅ ↔ ∀ y : Set.{u}, y ∉ x :=
⟨λ h y, (h.symm ▸ mem_empty y),
λ h, ext (λ y, ⟨λ yx, absurd yx (h y), λ y0, absurd y0 (mem_empty _)⟩)⟩
/-- `insert x y` is the set `{x} ∪ y` -/
protected def insert : Set → Set → Set :=
resp.eval 2 ⟨pSet.insert, λ u v uv ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λ o, match o with
| some a := let ⟨b, hb⟩ := αβ a in ⟨some b, hb⟩
| none := ⟨none, uv⟩
end, λ o, match o with
| some b := let ⟨a, ha⟩ := βα b in ⟨some a, ha⟩
| none := ⟨none, uv⟩
end⟩⟩
instance : has_insert Set Set := ⟨Set.insert⟩
instance : has_singleton Set Set := ⟨λ x, insert x ∅⟩
instance : is_lawful_singleton Set Set := ⟨λ x, rfl⟩
@[simp] theorem mem_insert {x y z : Set.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z :=
quotient.induction_on₃ x y z
(λ x y ⟨α, A⟩, show x ∈ pSet.mk (option α) (λ o, option.rec y A o) ↔
mk x = mk y ∨ x ∈ pSet.mk α A, from
⟨λ m, match m with
| ⟨some a, ha⟩ := or.inr ⟨a, ha⟩
| ⟨none, h⟩ := or.inl (quotient.sound h)
end, λ m, match m with
| or.inr ⟨a, ha⟩ := ⟨some a, ha⟩
| or.inl h := ⟨none, quotient.exact h⟩
end⟩)
@[simp] theorem mem_singleton {x y : Set.{u}} : x ∈ @singleton Set.{u} Set.{u} _ y ↔ x = y :=
iff.trans mem_insert ⟨λ o, or.rec (λ h, h) (λ n, absurd n (mem_empty _)) o, or.inl⟩
@[simp] theorem mem_pair {x y z : Set.{u}} : x ∈ ({y, z} : Set) ↔ x = y ∨ x = z :=
iff.trans mem_insert $ or_congr iff.rfl mem_singleton
/-- `omega` is the first infinite von Neumann ordinal -/
def omega : Set := mk omega
@[simp] theorem omega_zero : ∅ ∈ omega :=
⟨⟨0⟩, equiv.rfl⟩
@[simp] theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} :=
quotient.induction_on n (λ x ⟨⟨n⟩, h⟩, ⟨⟨n+1⟩,
have Set.insert ⟦x⟧ ⟦x⟧ = Set.insert ⟦of_nat n⟧ ⟦of_nat n⟧, by rw (@quotient.sound pSet _ _ _ h),
quotient.exact this⟩)
/-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/
protected def sep (p : Set → Prop) : Set → Set :=
resp.eval 1 ⟨pSet.sep (λ y, p ⟦y⟧), λ ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λ ⟨a, pa⟩, let ⟨b, hb⟩ := αβ a in ⟨⟨b, by rwa ←(@quotient.sound pSet _ _ _ hb)⟩, hb⟩,
λ ⟨b, pb⟩, let ⟨a, ha⟩ := βα b in ⟨⟨a, by rwa (@quotient.sound pSet _ _ _ ha)⟩, ha⟩⟩⟩
instance : has_sep Set Set := ⟨Set.sep⟩
@[simp] theorem mem_sep {p : Set.{u} → Prop} {x y : Set.{u}} : y ∈ {y ∈ x | p y} ↔ y ∈ x ∧ p y :=
quotient.induction_on₂ x y (λ ⟨α, A⟩ y,
⟨λ ⟨⟨a, pa⟩, h⟩, ⟨⟨a, h⟩, by { rw (@quotient.sound pSet _ _ _ h), exact pa }⟩,
λ ⟨⟨a, h⟩, pa⟩, ⟨⟨a, by { rw ←(@quotient.sound pSet _ _ _ h), exact pa }⟩, h⟩⟩)
/-- The powerset operation, the collection of subsets of a ZFC set -/
def powerset : Set → Set :=
resp.eval 1 ⟨powerset, λ ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λ p, ⟨{b | ∃ a, p a ∧ equiv (A a) (B b)},
λ ⟨a, pa⟩, let ⟨b, ab⟩ := αβ a in ⟨⟨b, a, pa, ab⟩, ab⟩,
λ ⟨b, a, pa, ab⟩, ⟨⟨a, pa⟩, ab⟩⟩,
λ q, ⟨{a | ∃ b, q b ∧ equiv (A a) (B b)},
λ ⟨a, b, qb, ab⟩, ⟨⟨b, qb⟩, ab⟩,
λ ⟨b, qb⟩, let ⟨a, ab⟩ := βα b in ⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩
@[simp] theorem mem_powerset {x y : Set.{u}} : y ∈ powerset x ↔ y ⊆ x :=
quotient.induction_on₂ x y ( λ ⟨α, A⟩ ⟨β, B⟩,
show (⟨β, B⟩ : pSet.{u}) ∈ (pSet.powerset.{u} ⟨α, A⟩) ↔ _,
by simp [mem_powerset, subset_iff])
theorem Union_lem {α β : Type u} (A : α → pSet) (B : β → pSet) (αβ : ∀ a, ∃ b, equiv (A a) (B b)) :
∀ a, ∃ b, (equiv ((Union ⟨α, A⟩).func a) ((Union ⟨β, B⟩).func b))
| ⟨a, c⟩ := let ⟨b, hb⟩ := αβ a in
begin
induction ea : A a with γ Γ,
induction eb : B b with δ Δ,
rw [ea, eb] at hb,
cases hb with γδ δγ,
exact
let c : type (A a) := c, ⟨d, hd⟩ := γδ (by rwa ea at c) in
have pSet.equiv ((A a).func c) ((B b).func (eq.rec d (eq.symm eb))), from
match A a, B b, ea, eb, c, d, hd with ._, ._, rfl, rfl, x, y, hd := hd end,
⟨⟨b, eq.rec d (eq.symm eb)⟩, this⟩
end
/-- The union operator, the collection of elements of elements of a ZFC set -/
def Union : Set → Set :=
resp.eval 1 ⟨pSet.Union, λ ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨Union_lem A B αβ, λ a, exists.elim (Union_lem B A (λ b,
exists.elim (βα b) (λ c hc, ⟨c, pSet.equiv.symm hc⟩)) a) (λ b hb, ⟨b, pSet.equiv.symm hb⟩)⟩⟩
notation `⋃` := Union
@[simp] theorem mem_Union {x y : Set.{u}} : y ∈ Union x ↔ ∃ z ∈ x, y ∈ z :=
quotient.induction_on₂ x y (λ x y, iff.trans mem_Union
⟨λ ⟨z, h⟩, ⟨⟦z⟧, h⟩, λ ⟨z, h⟩, quotient.induction_on z (λ z h, ⟨z, h⟩) h⟩)
@[simp] theorem Union_singleton {x : Set.{u}} : Union {x} = x :=
ext $ λ y, by simp_rw [mem_Union, exists_prop, mem_singleton, exists_eq_left]
theorem singleton_inj {x y : Set.{u}} (H : ({x} : Set) = {y}) : x = y :=
let this := congr_arg Union H in by rwa [Union_singleton, Union_singleton] at this
/-- The binary union operation -/
protected def union (x y : Set.{u}) : Set.{u} := ⋃ {x, y}
/-- The binary intersection operation -/
protected def inter (x y : Set.{u}) : Set.{u} := {z ∈ x | z ∈ y}
/-- The set difference operation -/
protected def diff (x y : Set.{u}) : Set.{u} := {z ∈ x | z ∉ y}
instance : has_union Set := ⟨Set.union⟩
instance : has_inter Set := ⟨Set.inter⟩
instance : has_sdiff Set := ⟨Set.diff⟩
@[simp] theorem mem_union {x y z : Set.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y :=
iff.trans mem_Union
⟨λ ⟨w, wxy, zw⟩, match mem_pair.1 wxy with
| or.inl wx := or.inl (by rwa ←wx)
| or.inr wy := or.inr (by rwa ←wy)
end, λ zxy, match zxy with
| or.inl zx := ⟨x, mem_pair.2 (or.inl rfl), zx⟩
| or.inr zy := ⟨y, mem_pair.2 (or.inr rfl), zy⟩
end⟩
@[simp] theorem mem_inter {x y z : Set.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y :=
@@mem_sep (λ z : Set.{u}, z ∈ y)
@[simp] theorem mem_diff {x y z : Set.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y :=
@@mem_sep (λ z : Set.{u}, z ∉ y)
theorem induction_on {p : Set → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x :=
quotient.induction_on x $ λ u, pSet.rec_on u $ λ α A IH, h _ $ λ y,
show @has_mem.mem _ _ Set.has_mem y ⟦⟨α, A⟩⟧ → p y, from
quotient.induction_on y (λ v ⟨a, ha⟩, by { rw (@quotient.sound pSet _ _ _ ha), exact IH a })
theorem regularity (x : Set.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ :=
classical.by_contradiction $ λ ne, h $ (eq_empty x).2 $ λ y,
induction_on y $ λ z (IH : ∀ w : Set.{u}, w ∈ z → w ∉ x), show z ∉ x, from λ zx,
ne ⟨z, zx, (eq_empty _).2 (λ w wxz, let ⟨wx, wz⟩ := mem_inter.1 wxz in IH w wz wx)⟩
/-- The image of a (definable) ZFC set function -/
def image (f : Set → Set) [H : definable 1 f] : Set → Set :=
let r := @definable.resp 1 f _ in
resp.eval 1 ⟨image r.1, λ x y e, mem.ext $ λ z,
iff.trans (mem_image r.2) $ iff.trans (by exact
⟨λ ⟨w, h1, h2⟩, ⟨w, (mem.congr_right e).1 h1, h2⟩,
λ ⟨w, h1, h2⟩, ⟨w, (mem.congr_right e).2 h1, h2⟩⟩) $
iff.symm (mem_image r.2)⟩
theorem image.mk :
Π (f : Set.{u} → Set.{u}) [H : definable 1 f] (x) {y} (h : y ∈ x), f y ∈ @image f H x
| ._ ⟨F⟩ x y := quotient.induction_on₂ x y $ λ ⟨α, A⟩ y ⟨a, ya⟩, ⟨a, F.2 _ _ ya⟩
@[simp] theorem mem_image : Π {f : Set.{u} → Set.{u}} [H : definable 1 f] {x y : Set.{u}},
y ∈ @image f H x ↔ ∃ z ∈ x, f z = y
| ._ ⟨F⟩ x y := quotient.induction_on₂ x y $ λ ⟨α, A⟩ y,
⟨λ ⟨a, ya⟩, ⟨⟦A a⟧, mem.mk A a, eq.symm $ quotient.sound ya⟩,
λ ⟨z, hz, e⟩, e ▸ image.mk _ _ hz⟩
/-- Kuratowski ordered pair -/
def pair (x y : Set.{u}) : Set.{u} := {{x}, {x, y}}
/-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/
def pair_sep (p : Set.{u} → Set.{u} → Prop) (x y : Set.{u}) : Set.{u} :=
{z ∈ powerset (powerset (x ∪ y)) | ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b}
@[simp] theorem mem_pair_sep {p} {x y z : Set.{u}} :
z ∈ pair_sep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b :=
begin
refine mem_sep.trans ⟨and.right, λ e, ⟨_, e⟩⟩,
rcases e with ⟨a, ax, b, bY, rfl, pab⟩,
simp only [mem_powerset, subset_def, mem_union, pair, mem_pair],
rintros u (rfl|rfl) v; simp only [mem_singleton, mem_pair],
{ rintro rfl, exact or.inl ax },
{ rintro (rfl|rfl); [left, right]; assumption }
end
theorem pair_inj {x y x' y' : Set.{u}} (H : pair x y = pair x' y') : x = x' ∧ y = y' :=
begin
have ae := ext_iff.2 H,
simp only [pair, mem_pair] at ae,
obtain rfl : x = x',
{ cases (ae {x}).1 (by simp) with h h,
{ exact singleton_inj h },
{ have m : x' ∈ ({x} : Set),
{ simp [h] },
rw mem_singleton.mp m } },
have he : x = y → y = y',
{ rintro rfl,
cases (ae {x, y'}).2 (by simp only [eq_self_iff_true, or_true]) with xy'x xy'xx,
{ rw [eq_comm, ←mem_singleton, ←xy'x, mem_pair],
exact or.inr rfl },
{ simpa [eq_comm] using (ext_iff.2 xy'xx y').1 (by simp) } },
obtain xyx | xyy' := (ae {x, y}).1 (by simp),
{ obtain rfl := mem_singleton.mp ((ext_iff.2 xyx y).1 $ by simp),
simp [he rfl] },
{ obtain rfl | yy' := mem_pair.mp ((ext_iff.2 xyy' y).1 $ by simp),
{ simp [he rfl] },
{ simp [yy'] } }
end
/-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/
def prod : Set.{u} → Set.{u} → Set.{u} := pair_sep (λ a b, true)
@[simp] theorem mem_prod {x y z : Set.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b :=
by simp [prod]
@[simp] theorem pair_mem_prod {x y a b : Set.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y :=
⟨λ h, let ⟨a', a'x, b', b'y, e⟩ := mem_prod.1 h in
match a', b', pair_inj e, a'x, b'y with ._, ._, ⟨rfl, rfl⟩, ax, bY := ⟨ax, bY⟩ end,
λ ⟨ax, bY⟩, mem_prod.2 ⟨a, ax, b, bY, rfl⟩⟩
/-- `is_func x y f` is the assertion that `f` is a subset of `x × y` which relates to each element
of `x` a unique element of `y`, so that we can consider `f`as a ZFC function `x → y`. -/
def is_func (x y f : Set.{u}) : Prop :=
f ⊆ prod x y ∧ ∀ z : Set.{u}, z ∈ x → ∃! w, pair z w ∈ f
/-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/
def funs (x y : Set.{u}) : Set.{u} :=
{f ∈ powerset (prod x y) | is_func x y f}
@[simp] theorem mem_funs {x y f : Set.{u}} : f ∈ funs x y ↔ is_func x y f :=
by simp [funs, is_func]
-- TODO(Mario): Prove this computably
noncomputable instance map_definable_aux (f : Set → Set) [H : definable 1 f] :
definable 1 (λ y, pair y (f y)) :=
@classical.all_definable 1 _
/-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/
noncomputable def map (f : Set → Set) [H : definable 1 f] : Set → Set :=
image (λ y, pair y (f y))
@[simp] theorem mem_map {f : Set → Set} [H : definable 1 f] {x y : Set} :
y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y :=
mem_image
theorem map_unique {f : Set.{u} → Set.{u}} [H : definable 1 f] {x z : Set.{u}} (zx : z ∈ x) :
∃! w, pair z w ∈ map f x :=
⟨f z, image.mk _ _ zx, λ y yx, let ⟨w, wx, we⟩ := mem_image.1 yx, ⟨wz, fy⟩ := pair_inj we in
by rw[←fy, wz]⟩
@[simp] theorem map_is_func {f : Set → Set} [H : definable 1 f] {x y : Set} :
is_func x y (map f x) ↔ ∀ z ∈ x, f z ∈ y :=
⟨λ ⟨ss, h⟩ z zx, let ⟨t, t1, t2⟩ := h z zx in
(t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right,
λ h, ⟨λ y yx, let ⟨z, zx, ze⟩ := mem_image.1 yx in ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩,
λ z, map_unique⟩⟩
end Set
/-- The collection of all classes. A class is defined as a `set` of ZFC sets. -/
@[derive [has_subset, has_sep Set, has_emptyc, inhabited, has_insert Set, has_union, has_inter,
has_compl, has_sdiff]]
def Class := set Set
namespace Class
/-- Coerce a ZFC set into a class -/
def of_Set (x : Set.{u}) : Class.{u} := {y | y ∈ x}
instance : has_coe Set Class := ⟨of_Set⟩
/-- The universal class -/
def univ : Class := set.univ
/-- Assert that `A` is a ZFC set satisfying `p` -/
def to_Set (p : Set.{u} → Prop) (A : Class.{u}) : Prop := ∃ x, ↑x = A ∧ p x
/-- `A ∈ B` if `A` is a ZFC set which is a member of `B` -/
protected def mem (A B : Class.{u}) : Prop := to_Set.{u} B A
instance : has_mem Class Class := ⟨Class.mem⟩
theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : Set.{u}, ↑x = A :=
exists_congr $ λ x, and_true _
/-- Convert a conglomerate (a collection of classes) into a class -/
def Cong_to_Class (x : set Class.{u}) : Class.{u} := {y | ↑y ∈ x}
/-- Convert a class into a conglomerate (a collection of classes) -/
def Class_to_Cong (x : Class.{u}) : set Class.{u} := {y | y ∈ x}
/-- The power class of a class is the class of all subclasses that are ZFC sets -/
def powerset (x : Class) : Class := Cong_to_Class (set.powerset x)
/-- The union of a class is the class of all members of ZFC sets in the class -/
def Union (x : Class) : Class := set.sUnion (Class_to_Cong x)
notation `⋃` := Union
theorem of_Set.inj {x y : Set.{u}} (h : (x : Class.{u}) = y) : x = y :=
Set.ext $ λ z, by { change (x : Class.{u}) z ↔ (y : Class.{u}) z, rw h }
@[simp] theorem to_Set_of_Set (p : Set.{u} → Prop) (x : Set.{u}) : to_Set p x ↔ p x :=
⟨λ ⟨y, yx, py⟩, by rwa of_Set.inj yx at py, λ px, ⟨x, rfl, px⟩⟩
@[simp] theorem mem_hom_left (x : Set.{u}) (A : Class.{u}) : (x : Class.{u}) ∈ A ↔ A x :=
to_Set_of_Set _ _
@[simp] theorem mem_hom_right (x y : Set.{u}) : (y : Class.{u}) x ↔ x ∈ y := iff.rfl
@[simp] theorem subset_hom (x y : Set.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y := iff.rfl
@[simp] theorem sep_hom (p : Set.{u} → Prop) (x : Set.{u}) :
(↑{y ∈ x | p y} : Class.{u}) = {y ∈ x | p y} :=
set.ext $ λ y, Set.mem_sep
@[simp] theorem empty_hom : ↑(∅ : Set.{u}) = (∅ : Class.{u}) :=
set.ext $ λ y, (iff_false _).2 (Set.mem_empty y)
@[simp] theorem insert_hom (x y : Set.{u}) : (@insert Set.{u} Class.{u} _ x y) = ↑(insert x y) :=
set.ext $ λ z, iff.symm Set.mem_insert
@[simp] theorem union_hom (x y : Set.{u}) : (x : Class.{u}) ∪ y = (x ∪ y : Set.{u}) :=
set.ext $ λ z, iff.symm Set.mem_union
@[simp] theorem inter_hom (x y : Set.{u}) : (x : Class.{u}) ∩ y = (x ∩ y : Set.{u}) :=
set.ext $ λ z, iff.symm Set.mem_inter
@[simp] theorem diff_hom (x y : Set.{u}) : (x : Class.{u}) \ y = (x \ y : Set.{u}) :=
set.ext $ λ z, iff.symm Set.mem_diff
@[simp] theorem powerset_hom (x : Set.{u}) : powerset.{u} x = Set.powerset x :=
set.ext $ λ z, iff.symm Set.mem_powerset
@[simp] theorem Union_hom (x : Set.{u}) : Union.{u} x = Set.Union x :=
set.ext $ λ z, by { refine iff.trans _ Set.mem_Union.symm, exact
⟨λ ⟨._, ⟨a, rfl, ax⟩, za⟩, ⟨a, ax, za⟩, λ ⟨a, ax, za⟩, ⟨_, ⟨a, rfl, ax⟩, za⟩⟩ }
/-- The definite description operator, which is `{x}` if `{a | p a} = {x}` and `∅` otherwise. -/
def iota (p : Set → Prop) : Class := Union {x | ∀ y, p y ↔ y = x}
theorem iota_val (p : Set → Prop) (x : Set) (H : ∀ y, p y ↔ y = x) : iota p = ↑x :=
set.ext $ λ y, ⟨λ ⟨._, ⟨x', rfl, h⟩, yx'⟩, by rwa ←((H x').1 $ (h x').2 rfl),
λ yx, ⟨_, ⟨x, rfl, H⟩, yx⟩⟩
/-- Unlike the other set constructors, the `iota` definite descriptor
is a set for any set input, but not constructively so, so there is no
associated `(Set → Prop) → Set` function. -/
theorem iota_ex (p) : iota.{u} p ∈ univ.{u} :=
mem_univ.2 $ or.elim (classical.em $ ∃ x, ∀ y, p y ↔ y = x)
(λ ⟨x, h⟩, ⟨x, eq.symm $ iota_val p x h⟩)
(λ hn, ⟨∅, set.ext (λ z, empty_hom.symm ▸ ⟨false.rec _, λ ⟨._, ⟨x, rfl, H⟩, zA⟩, hn ⟨x, H⟩⟩)⟩)
/-- Function value -/
def fval (F A : Class.{u}) : Class.{u} := iota (λ y, to_Set (λ x, F (Set.pair x y)) A)
infixl `′`:100 := fval
theorem fval_ex (F A : Class.{u}) : F ′ A ∈ univ.{u} := iota_ex _
end Class
namespace Set
@[simp] theorem map_fval {f : Set.{u} → Set.{u}} [H : pSet.definable 1 f]
{x y : Set.{u}} (h : y ∈ x) :
(Set.map f x ′ y : Class.{u}) = f y :=
Class.iota_val _ _ (λ z, by { rw [Class.to_Set_of_Set, Class.mem_hom_right, mem_map], exact
⟨λ ⟨w, wz, pr⟩, let ⟨wy, fw⟩ := Set.pair_inj pr in by rw[←fw, wy],
λ e, by { subst e, exact ⟨_, h, rfl⟩ }⟩ })
variables (x : Set.{u}) (h : ∅ ∉ x)
/-- A choice function on the class of nonempty ZFC sets. -/
noncomputable def choice : Set :=
@map (λ y, classical.epsilon (λ z, z ∈ y)) (classical.all_definable _) x
include h
theorem choice_mem_aux (y : Set.{u}) (yx : y ∈ x) : classical.epsilon (λ z : Set.{u}, z ∈ y) ∈ y :=
@classical.epsilon_spec _ (λ z : Set.{u}, z ∈ y) $ classical.by_contradiction $ λ n, h $
by rwa ←((eq_empty y).2 $ λ z zx, n ⟨z, zx⟩)
theorem choice_is_func : is_func x (Union x) (choice x) :=
(@map_is_func _ (classical.all_definable _) _ _).2 $
λ y yx, mem_Union.2 ⟨y, yx, choice_mem_aux x h y yx⟩
theorem choice_mem (y : Set.{u}) (yx : y ∈ x) : (choice x ′ y : Class.{u}) ∈ (y : Class.{u}) :=
begin
delta choice,
rw [map_fval yx, Class.mem_hom_left, Class.mem_hom_right],
exact choice_mem_aux x h y yx
end
end Set
|
61cdd127762f19b0f2dcb4ce87abe4349cf93fc2 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/tactic/monotonicity/basic.lean | e91824f2995abcbc6b19af661957719d7eb60024 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,761 | lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import algebra.ordered_ring
import order.bounded_lattice
namespace tactic.interactive
open tactic list
open lean lean.parser interactive
open interactive.types
@[derive inhabited]
structure mono_cfg :=
(unify := ff)
@[derive [decidable_eq, has_reflect, inhabited]]
inductive mono_selection : Type
| left : mono_selection
| right : mono_selection
| both : mono_selection
declare_trace mono.relation
section compare
parameter opt : mono_cfg
meta def compare (e₀ e₁ : expr) : tactic unit := do
if opt.unify then do
guard (¬ e₀.is_mvar ∧ ¬ e₁.is_mvar),
unify e₀ e₁
else is_def_eq e₀ e₁
meta def find_one_difference
: list expr → list expr → tactic (list expr × expr × expr × list expr)
| (x :: xs) (y :: ys) :=
do c ← try_core (compare x y),
if c.is_some
then prod.map (cons x) id <$> find_one_difference xs ys
else do
guard (xs.length = ys.length),
mzip_with' compare xs ys,
return ([],x,y,xs)
| xs ys := fail format!"find_one_difference: {xs}, {ys}"
end compare
def last_two {α : Type*} (l : list α) : option (α × α) :=
match l.reverse with
| (x₁ :: x₀ :: _) := some (x₀, x₁)
| _ := none
end
meta def match_imp : expr → tactic (expr × expr)
| `(%%e₀ → %%e₁) :=
do guard (¬ e₁.has_var),
return (e₀,e₁)
| _ := failed
open expr
meta def same_operator : expr → expr → bool
| (app e₀ _) (app e₁ _) :=
let fn₀ := e₀.get_app_fn,
fn₁ := e₁.get_app_fn in
fn₀.is_constant ∧ fn₀.const_name = fn₁.const_name
| (pi _ _ _ _) (pi _ _ _ _) := tt
| _ _ := ff
meta def get_operator (e : expr) : option name :=
guard (¬ e.is_pi) >> pure e.get_app_fn.const_name
meta def monotonicity.check_rel (l r : expr) : tactic (option name) :=
do guard (same_operator l r) <|>
do { fail format!"{l} and {r} should be the f x and f y for some f" },
if l.is_pi then pure none
else pure r.get_app_fn.const_name
@[reducible]
def mono_key := (with_bot name × with_bot name)
open nat
meta def mono_head_candidates : ℕ → list expr → expr → tactic mono_key
| 0 _ h := fail!"Cannot find relation in {h}"
| (succ n) xs h :=
do { (rel,l,r) ← if h.is_arrow
then pure (none,h.binding_domain,h.binding_body)
else guard h.get_app_fn.is_constant >>
prod.mk (some h.get_app_fn.const_name) <$> last_two h.get_app_args,
prod.mk <$> monotonicity.check_rel l r <*> pure rel } <|>
match xs with
| [] := fail format!"oh? {h}"
| (x::xs) := mono_head_candidates n xs (h.pis [x])
end
meta def monotonicity.check (lm_n : name) : tactic mono_key :=
do lm ← mk_const lm_n,
lm_t ← infer_type lm >>= instantiate_mvars,
when_tracing `mono.relation trace!"[mono] Looking for relation in {lm_t}",
s ← simp_lemmas.mk.add_simp ``monotone,
lm_t ← s.dsimplify [] lm_t { fail_if_unchanged := ff },
when_tracing `mono.relation trace!"[mono] Looking for relation in {lm_t} (after unfolding)",
(xs,h) ← open_pis lm_t,
mono_head_candidates 3 xs.reverse h
meta instance : has_to_format mono_selection :=
⟨ λ x, match x with
| mono_selection.left := "left"
| mono_selection.right := "right"
| mono_selection.both := "both"
end ⟩
meta def side : lean.parser mono_selection :=
with_desc "expecting 'left', 'right' or 'both' (default)" $
do some n ← optional ident | pure mono_selection.both,
if n = `left then pure $ mono_selection.left
else if n = `right then pure $ mono_selection.right
else if n = `both then pure $ mono_selection.both
else fail format!"invalid argument: {n}, expecting 'left', 'right' or 'both' (default)"
open function
@[user_attribute]
meta def monotonicity.attr : user_attribute
(native.rb_lmap mono_key (name))
(option mono_key × mono_selection) :=
{ name := `mono
, descr := "monotonicity of function `f` wrt relations `R₀` and `R₁`: R₀ x y → R₁ (f x) (f y)"
, cache_cfg :=
{ dependencies := [],
mk_cache := λ ls,
do ps ← ls.mmap monotonicity.attr.get_param,
let ps := ps.filter_map prod.fst,
pure $ (ps.zip ls).foldl
(flip $ uncurry (λ k n m, m.insert k n))
(native.rb_lmap.mk mono_key _) }
, after_set := some $ λ n prio p,
do { (none,v) ← monotonicity.attr.get_param n | pure (),
k ← monotonicity.check n,
monotonicity.attr.set n (some k,v) p }
, parser := prod.mk none <$> side }
meta def filter_instances (e : mono_selection) (ns : list name) : tactic (list name) :=
ns.mfilter $ λ n,
do d ← user_attribute.get_param_untyped monotonicity.attr n,
(_,d) ← to_expr ``(id %%d) >>= eval_expr (option mono_key × mono_selection),
return (e = d : bool)
meta def get_monotonicity_lemmas (k : expr) (e : mono_selection) : tactic (list name) :=
do ns ← monotonicity.attr.get_cache,
k' ← if k.is_pi
then pure (get_operator k.binding_domain,none)
else do { (x₀,x₁) ← last_two k.get_app_args,
pure (get_operator x₀,some k.get_app_fn.const_name) },
let ns := ns.find_def [] k',
ns' ← filter_instances e ns,
if e ≠ mono_selection.both then (++) ns' <$> filter_instances mono_selection.both ns
else pure ns'
end tactic.interactive
attribute [mono] add_le_add mul_le_mul neg_le_neg
mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right
imp_imp_imp le_implies_le_of_le_of_le
sub_le_sub abs_le_abs sup_le_sup
inf_le_inf
attribute [mono left] add_lt_add_of_le_of_lt mul_lt_mul'
attribute [mono right] add_lt_add_of_lt_of_le mul_lt_mul
|
5e8d2e821f148167e591ab068b3195780d231a83 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/adjunction/over.lean | 9d74adc21d6ea63526764f349705e7fed5c255f3 | [
"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 | 1,688 | lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.over
import category_theory.limits.preserves.basic
import category_theory.limits.creates
import category_theory.limits.shapes.binary_products
import category_theory.monad.products
/-!
# Adjunctions related to the over category
Construct the left adjoint `star X` to `over.forget X : over X ⥤ C`.
## TODO
Show `star X` itself has a left adjoint provided `C` is locally cartesian closed.
-/
noncomputable theory
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
open category limits comonad
variables {C : Type u} [category.{v} C] (X : C)
/--
The functor from `C` to `over X` which sends `Y : C` to `π₁ : X ⨯ Y ⟶ X`, sometimes denoted `X*`.
-/
@[simps]
def star [has_binary_products C] : C ⥤ over X :=
cofree _ ⋙ coalgebra_to_over X
/--
The functor `over.forget X : over X ⥤ C` has a right adjoint given by `star X`.
Note that the binary products assumption is necessary: the existence of a right adjoint to
`over.forget X` is equivalent to the existence of each binary product `X ⨯ -`.
-/
def forget_adj_star [has_binary_products C] : over.forget X ⊣ star X :=
(coalgebra_equiv_over X).symm.to_adjunction.comp _ _ (adj _)
/--
Note that the binary products assumption is necessary: the existence of a right adjoint to
`over.forget X` is equivalent to the existence of each binary product `X ⨯ -`.
-/
instance [has_binary_products C] : is_left_adjoint (over.forget X) := ⟨_, forget_adj_star X⟩
end category_theory
|
21f55598592681be1991d48db1cd52149ce5cb4a | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/algebra/group.lean | 8f55d804365902fab45a694898e1dad67c7b7d8b | [
"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 | 60,262 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import group_theory.group_action.conj_act
import group_theory.quotient_group
import order.filter.pointwise
import topology.algebra.monoid
import topology.compact_open
import topology.sets.compacts
import topology.algebra.constructions
/-!
# Topological groups
This file defines the following typeclasses:
* `topological_group`, `topological_add_group`: multiplicative and additive topological groups,
i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`;
* `has_continuous_sub G` means that `G` has a continuous subtraction operation.
There is an instance deducing `has_continuous_sub` from `topological_group` but we use a separate
typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups.
We also define `homeomorph` versions of several `equiv`s: `homeomorph.mul_left`,
`homeomorph.mul_right`, `homeomorph.inv`, and prove a few facts about neighbourhood filters in
groups.
## Tags
topological space, group, topological group
-/
open classical set filter topological_space function
open_locale classical topological_space filter pointwise
universes u v w x
variables {α : Type u} {β : Type v} {G : Type w} {H : Type x}
section continuous_mul_group
/-!
### Groups with continuous multiplication
In this section we prove a few statements about groups with continuous `(*)`.
-/
variables [topological_space G] [group G] [has_continuous_mul G]
/-- Multiplication from the left in a topological group as a homeomorphism. -/
@[to_additive "Addition from the left in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_left (a : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[simp, to_additive]
lemma homeomorph.coe_mul_left (a : G) : ⇑(homeomorph.mul_left a) = (*) a := rfl
@[to_additive]
lemma homeomorph.mul_left_symm (a : G) : (homeomorph.mul_left a).symm = homeomorph.mul_left a⁻¹ :=
by { ext, refl }
@[to_additive]
lemma is_open_map_mul_left (a : G) : is_open_map (λ x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive is_open.left_add_coset]
lemma is_open.left_coset {U : set G} (h : is_open U) (x : G) : is_open (left_coset x U) :=
is_open_map_mul_left x _ h
@[to_additive]
lemma is_closed_map_mul_left (a : G) : is_closed_map (λ x, a * x) :=
(homeomorph.mul_left a).is_closed_map
@[to_additive is_closed.left_add_coset]
lemma is_closed.left_coset {U : set G} (h : is_closed U) (x : G) : is_closed (left_coset x U) :=
is_closed_map_mul_left x _ h
/-- Multiplication from the right in a topological group as a homeomorphism. -/
@[to_additive "Addition from the right in a topological additive group as a homeomorphism."]
protected def homeomorph.mul_right (a : G) :
G ≃ₜ G :=
{ continuous_to_fun := continuous_id.mul continuous_const,
continuous_inv_fun := continuous_id.mul continuous_const,
.. equiv.mul_right a }
@[simp, to_additive]
lemma homeomorph.coe_mul_right (a : G) : ⇑(homeomorph.mul_right a) = λ g, g * a := rfl
@[to_additive]
lemma homeomorph.mul_right_symm (a : G) :
(homeomorph.mul_right a).symm = homeomorph.mul_right a⁻¹ :=
by { ext, refl }
@[to_additive]
lemma is_open_map_mul_right (a : G) : is_open_map (λ x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive is_open.right_add_coset]
lemma is_open.right_coset {U : set G} (h : is_open U) (x : G) : is_open (right_coset U x) :=
is_open_map_mul_right x _ h
@[to_additive]
lemma is_closed_map_mul_right (a : G) : is_closed_map (λ x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive is_closed.right_add_coset]
lemma is_closed.right_coset {U : set G} (h : is_closed U) (x : G) : is_closed (right_coset U x) :=
is_closed_map_mul_right x _ h
@[to_additive]
lemma discrete_topology_of_open_singleton_one (h : is_open ({1} : set G)) : discrete_topology G :=
begin
rw ← singletons_open_iff_discrete,
intro g,
suffices : {g} = (λ (x : G), g⁻¹ * x) ⁻¹' {1},
{ rw this, exact (continuous_mul_left (g⁻¹)).is_open_preimage _ h, },
simp only [mul_one, set.preimage_mul_left_singleton, eq_self_iff_true,
inv_inv, set.singleton_eq_singleton_iff],
end
@[to_additive]
lemma discrete_topology_iff_open_singleton_one : discrete_topology G ↔ is_open ({1} : set G) :=
⟨λ h, forall_open_iff_discrete.mpr h {1}, discrete_topology_of_open_singleton_one⟩
end continuous_mul_group
/-!
### `has_continuous_inv` and `has_continuous_neg`
-/
/-- Basic hypothesis to talk about a topological additive group. A topological additive group
over `M`, for example, is obtained by requiring the instances `add_group M` and
`has_continuous_add M` and `has_continuous_neg M`. -/
class has_continuous_neg (G : Type u) [topological_space G] [has_neg G] : Prop :=
(continuous_neg : continuous (λ a : G, -a))
/-- Basic hypothesis to talk about a topological group. A topological group over `M`, for example,
is obtained by requiring the instances `group M` and `has_continuous_mul M` and
`has_continuous_inv M`. -/
@[to_additive]
class has_continuous_inv (G : Type u) [topological_space G] [has_inv G] : Prop :=
(continuous_inv : continuous (λ a : G, a⁻¹))
export has_continuous_inv (continuous_inv)
export has_continuous_neg (continuous_neg)
section continuous_inv
variables [topological_space G] [has_inv G] [has_continuous_inv G]
@[to_additive]
lemma continuous_on_inv {s : set G} : continuous_on has_inv.inv s :=
continuous_inv.continuous_on
@[to_additive]
lemma continuous_within_at_inv {s : set G} {x : G} : continuous_within_at has_inv.inv s x :=
continuous_inv.continuous_within_at
@[to_additive]
lemma continuous_at_inv {x : G} : continuous_at has_inv.inv x :=
continuous_inv.continuous_at
@[to_additive]
lemma tendsto_inv (a : G) : tendsto has_inv.inv (𝓝 a) (𝓝 (a⁻¹)) :=
continuous_at_inv
/-- If a function converges to a value in a multiplicative topological group, then its inverse
converges to the inverse of this value. For the version in normed fields assuming additionally
that the limit is nonzero, use `tendsto.inv'`. -/
@[to_additive]
lemma filter.tendsto.inv {f : α → G} {l : filter α} {y : G} (h : tendsto f l (𝓝 y)) :
tendsto (λ x, (f x)⁻¹) l (𝓝 y⁻¹) :=
(continuous_inv.tendsto y).comp h
variables [topological_space α] {f : α → G} {s : set α} {x : α}
@[continuity, to_additive]
lemma continuous.inv (hf : continuous f) : continuous (λx, (f x)⁻¹) :=
continuous_inv.comp hf
@[to_additive]
lemma continuous_at.inv (hf : continuous_at f x) : continuous_at (λ x, (f x)⁻¹) x :=
continuous_at_inv.comp hf
@[to_additive]
lemma continuous_on.inv (hf : continuous_on f s) : continuous_on (λx, (f x)⁻¹) s :=
continuous_inv.comp_continuous_on hf
@[to_additive]
lemma continuous_within_at.inv (hf : continuous_within_at f s x) :
continuous_within_at (λ x, (f x)⁻¹) s x :=
hf.inv
@[to_additive]
instance [topological_space H] [has_inv H] [has_continuous_inv H] : has_continuous_inv (G × H) :=
⟨(continuous_inv.comp continuous_fst).prod_mk (continuous_inv.comp continuous_snd)⟩
variable {ι : Type*}
@[to_additive]
instance pi.has_continuous_inv {C : ι → Type*} [∀ i, topological_space (C i)]
[∀ i, has_inv (C i)] [∀ i, has_continuous_inv (C i)] : has_continuous_inv (Π i, C i) :=
{ continuous_inv := continuous_pi (λ i, continuous.inv (continuous_apply i)) }
/-- A version of `pi.has_continuous_inv` for non-dependent functions. It is needed because sometimes
Lean fails to use `pi.has_continuous_inv` for non-dependent functions. -/
@[to_additive "A version of `pi.has_continuous_neg` for non-dependent functions. It is needed
because sometimes Lean fails to use `pi.has_continuous_neg` for non-dependent functions."]
instance pi.has_continuous_inv' : has_continuous_inv (ι → G) :=
pi.has_continuous_inv
@[priority 100, to_additive]
instance has_continuous_inv_of_discrete_topology [topological_space H]
[has_inv H] [discrete_topology H] : has_continuous_inv H :=
⟨continuous_of_discrete_topology⟩
section pointwise_limits
variables (G₁ G₂ : Type*) [topological_space G₂] [t2_space G₂]
@[to_additive] lemma is_closed_set_of_map_inv [has_inv G₁] [has_inv G₂] [has_continuous_inv G₂] :
is_closed {f : G₁ → G₂ | ∀ x, f x⁻¹ = (f x)⁻¹ } :=
begin
simp only [set_of_forall],
refine is_closed_Inter (λ i, is_closed_eq (continuous_apply _) (continuous_apply _).inv),
end
end pointwise_limits
instance additive.has_continuous_neg [h : topological_space H] [has_inv H]
[has_continuous_inv H] : @has_continuous_neg (additive H) h _ :=
{ continuous_neg := @continuous_inv H _ _ _ }
instance multiplicative.has_continuous_inv [h : topological_space H] [has_neg H]
[has_continuous_neg H] : @has_continuous_inv (multiplicative H) h _ :=
{ continuous_inv := @continuous_neg H _ _ _ }
end continuous_inv
section continuous_involutive_inv
variables [topological_space G] [has_involutive_inv G] [has_continuous_inv G] {s : set G}
@[to_additive] lemma is_compact.inv (hs : is_compact s) : is_compact s⁻¹ :=
by { rw [← image_inv], exact hs.image continuous_inv }
variables (G)
/-- Inversion in a topological group as a homeomorphism. -/
@[to_additive "Negation in a topological group as a homeomorphism."]
protected def homeomorph.inv (G : Type*) [topological_space G] [has_involutive_inv G]
[has_continuous_inv G] : G ≃ₜ G :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv G }
@[to_additive] lemma is_open_map_inv : is_open_map (has_inv.inv : G → G) :=
(homeomorph.inv _).is_open_map
@[to_additive] lemma is_closed_map_inv : is_closed_map (has_inv.inv : G → G) :=
(homeomorph.inv _).is_closed_map
variables {G}
@[to_additive] lemma is_open.inv (hs : is_open s) : is_open s⁻¹ := hs.preimage continuous_inv
@[to_additive] lemma is_closed.inv (hs : is_closed s) : is_closed s⁻¹ := hs.preimage continuous_inv
@[to_additive] lemma inv_closure : ∀ s : set G, (closure s)⁻¹ = closure s⁻¹ :=
(homeomorph.inv G).preimage_closure
end continuous_involutive_inv
section lattice_ops
variables {ι' : Sort*} [has_inv G] [has_inv H] {ts : set (topological_space G)}
(h : Π t ∈ ts, @has_continuous_inv G t _) {ts' : ι' → topological_space G}
(h' : Π i, @has_continuous_inv G (ts' i) _) {t₁ t₂ : topological_space G}
(h₁ : @has_continuous_inv G t₁ _) (h₂ : @has_continuous_inv G t₂ _)
{t : topological_space H} [has_continuous_inv H]
@[to_additive] lemma has_continuous_inv_Inf :
@has_continuous_inv G (Inf ts) _ :=
{ continuous_inv := continuous_Inf_rng (λ t ht, continuous_Inf_dom ht
(@has_continuous_inv.continuous_inv G t _ (h t ht))) }
include h'
@[to_additive] lemma has_continuous_inv_infi :
@has_continuous_inv G (⨅ i, ts' i) _ :=
by {rw ← Inf_range, exact has_continuous_inv_Inf (set.forall_range_iff.mpr h')}
omit h'
include h₁ h₂
@[to_additive] lemma has_continuous_inv_inf :
@has_continuous_inv G (t₁ ⊓ t₂) _ :=
by {rw inf_eq_infi, refine has_continuous_inv_infi (λ b, _), cases b; assumption}
end lattice_ops
section topological_group
/-!
### Topological groups
A topological group is a group in which the multiplication and inversion operations are
continuous. Topological additive groups are defined in the same way. Equivalently, we can require
that the division operation `λ x y, x * y⁻¹` (resp., subtraction) is continuous.
-/
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (G : Type u) [topological_space G] [add_group G]
extends has_continuous_add G, has_continuous_neg G : Prop
/-- A topological group is a group in which the multiplication and inversion operations are
continuous.
When you declare an instance that does not already have a `uniform_space` instance,
you should also provide an instance of `uniform_space` and `uniform_group` using
`topological_group.to_uniform_space` and `topological_group_is_uniform`. -/
@[to_additive]
class topological_group (G : Type*) [topological_space G] [group G]
extends has_continuous_mul G, has_continuous_inv G : Prop
section conj
instance conj_act.units_has_continuous_const_smul {M} [monoid M] [topological_space M]
[has_continuous_mul M] :
has_continuous_const_smul (conj_act Mˣ) M :=
⟨λ m, (continuous_const.mul continuous_id).mul continuous_const⟩
/-- we slightly weaken the type class assumptions here so that it will also apply to `ennreal`, but
we nevertheless leave it in the `topological_group` namespace. -/
variables [topological_space G] [has_inv G] [has_mul G] [has_continuous_mul G]
/-- Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are continuous. -/
@[to_additive "Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are
continuous."]
lemma topological_group.continuous_conj_prod [has_continuous_inv G] :
continuous (λ g : G × G, g.fst * g.snd * g.fst⁻¹) :=
continuous_mul.mul (continuous_inv.comp continuous_fst)
/-- Conjugation by a fixed element is continuous when `mul` is continuous. -/
@[to_additive "Conjugation by a fixed element is continuous when `add` is continuous."]
lemma topological_group.continuous_conj (g : G) : continuous (λ (h : G), g * h * g⁻¹) :=
(continuous_mul_right g⁻¹).comp (continuous_mul_left g)
/-- Conjugation acting on fixed element of the group is continuous when both `mul` and
`inv` are continuous. -/
@[to_additive "Conjugation acting on fixed element of the additive group is continuous when both
`add` and `neg` are continuous."]
lemma topological_group.continuous_conj' [has_continuous_inv G]
(h : G) : continuous (λ (g : G), g * h * g⁻¹) :=
(continuous_mul_right h).mul continuous_inv
end conj
variables [topological_space G] [group G] [topological_group G]
[topological_space α] {f : α → G} {s : set α} {x : α}
section zpow
@[continuity, to_additive]
lemma continuous_zpow : ∀ z : ℤ, continuous (λ a : G, a ^ z)
| (int.of_nat n) := by simpa using continuous_pow n
| -[1+n] := by simpa using (continuous_pow (n + 1)).inv
instance add_group.has_continuous_const_smul_int {A} [add_group A] [topological_space A]
[topological_add_group A] : has_continuous_const_smul ℤ A := ⟨continuous_zsmul⟩
instance add_group.has_continuous_smul_int {A} [add_group A] [topological_space A]
[topological_add_group A] : has_continuous_smul ℤ A :=
⟨continuous_uncurry_of_discrete_topology continuous_zsmul⟩
@[continuity, to_additive]
lemma continuous.zpow {f : α → G} (h : continuous f) (z : ℤ) :
continuous (λ b, (f b) ^ z) :=
(continuous_zpow z).comp h
@[to_additive]
lemma continuous_on_zpow {s : set G} (z : ℤ) : continuous_on (λ x, x ^ z) s :=
(continuous_zpow z).continuous_on
@[to_additive]
lemma continuous_at_zpow (x : G) (z : ℤ) : continuous_at (λ x, x ^ z) x :=
(continuous_zpow z).continuous_at
@[to_additive]
lemma filter.tendsto.zpow {α} {l : filter α} {f : α → G} {x : G} (hf : tendsto f l (𝓝 x)) (z : ℤ) :
tendsto (λ x, f x ^ z) l (𝓝 (x ^ z)) :=
(continuous_at_zpow _ _).tendsto.comp hf
@[to_additive]
lemma continuous_within_at.zpow {f : α → G} {x : α} {s : set α} (hf : continuous_within_at f s x)
(z : ℤ) : continuous_within_at (λ x, f x ^ z) s x :=
hf.zpow z
@[to_additive]
lemma continuous_at.zpow {f : α → G} {x : α} (hf : continuous_at f x) (z : ℤ) :
continuous_at (λ x, f x ^ z) x :=
hf.zpow z
@[to_additive continuous_on.zsmul]
lemma continuous_on.zpow {f : α → G} {s : set α} (hf : continuous_on f s) (z : ℤ) :
continuous_on (λ x, f x ^ z) s :=
λ x hx, (hf x hx).zpow z
end zpow
section ordered_comm_group
variables [topological_space H] [ordered_comm_group H] [topological_group H]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi {a : H} :
tendsto has_inv.inv (𝓝[>] a) (𝓝[<] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iio {a : H} :
tendsto has_inv.inv (𝓝[<] a) (𝓝[>] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv {a : H} :
tendsto has_inv.inv (𝓝[>] (a⁻¹)) (𝓝[<] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iio_inv {a : H} :
tendsto has_inv.inv (𝓝[<] (a⁻¹)) (𝓝[>] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Ici {a : H} :
tendsto has_inv.inv (𝓝[≥] a) (𝓝[≤] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iic {a : H} :
tendsto has_inv.inv (𝓝[≤] a) (𝓝[≥] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ici_inv {a : H} :
tendsto has_inv.inv (𝓝[≥] (a⁻¹)) (𝓝[≤] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iic_inv {a : H} :
tendsto has_inv.inv (𝓝[≤] (a⁻¹)) (𝓝[≥] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹)
end ordered_comm_group
@[instance, to_additive]
instance [topological_space H] [group H] [topological_group H] :
topological_group (G × H) :=
{ continuous_inv := continuous_inv.prod_map continuous_inv }
@[to_additive]
instance pi.topological_group {C : β → Type*} [∀ b, topological_space (C b)]
[∀ b, group (C b)] [∀ b, topological_group (C b)] : topological_group (Π b, C b) :=
{ continuous_inv := continuous_pi (λ i, (continuous_apply i).inv) }
open mul_opposite
@[to_additive]
instance [group α] [has_continuous_inv α] : has_continuous_inv αᵐᵒᵖ :=
{ continuous_inv := continuous_induced_rng $ (@continuous_inv α _ _ _).comp continuous_unop }
/-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/
@[to_additive "If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`."]
instance [group α] [topological_group α] :
topological_group αᵐᵒᵖ := { }
variable (G)
@[to_additive]
lemma nhds_one_symm : comap has_inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) :=
((homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one)
/-- The map `(x, y) ↦ (x, xy)` as a homeomorphism. This is a shear mapping. -/
@[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism.
This is a shear mapping."]
protected def homeomorph.shear_mul_right : G × G ≃ₜ G × G :=
{ continuous_to_fun := continuous_fst.prod_mk continuous_mul,
continuous_inv_fun := continuous_fst.prod_mk $ continuous_fst.inv.mul continuous_snd,
.. equiv.prod_shear (equiv.refl _) equiv.mul_left }
@[simp, to_additive]
lemma homeomorph.shear_mul_right_coe :
⇑(homeomorph.shear_mul_right G) = λ z : G × G, (z.1, z.1 * z.2) :=
rfl
@[simp, to_additive]
lemma homeomorph.shear_mul_right_symm_coe :
⇑(homeomorph.shear_mul_right G).symm = λ z : G × G, (z.1, z.1⁻¹ * z.2) :=
rfl
variables {G}
namespace subgroup
@[to_additive] instance (S : subgroup G) :
topological_group S :=
{ continuous_inv :=
begin
rw embedding_subtype_coe.to_inducing.continuous_iff,
exact continuous_subtype_coe.inv
end,
..S.to_submonoid.has_continuous_mul }
end subgroup
/-- The (topological-space) closure of a subgroup of a space `M` with `has_continuous_mul` is
itself a subgroup. -/
@[to_additive "The (topological-space) closure of an additive subgroup of a space `M` with
`has_continuous_add` is itself an additive subgroup."]
def subgroup.topological_closure (s : subgroup G) : subgroup G :=
{ carrier := closure (s : set G),
inv_mem' := λ g m, by simpa [←set.mem_inv, inv_closure] using m,
..s.to_submonoid.topological_closure }
@[simp, to_additive] lemma subgroup.topological_closure_coe {s : subgroup G} :
(s.topological_closure : set G) = closure s :=
rfl
@[to_additive]
instance subgroup.topological_closure_topological_group (s : subgroup G) :
topological_group (s.topological_closure) :=
{ continuous_inv :=
begin
apply continuous_induced_rng,
change continuous (λ p : s.topological_closure, (p : G)⁻¹),
continuity,
end
..s.to_submonoid.topological_closure_has_continuous_mul}
@[to_additive] lemma subgroup.subgroup_topological_closure (s : subgroup G) :
s ≤ s.topological_closure :=
subset_closure
@[to_additive] lemma subgroup.is_closed_topological_closure (s : subgroup G) :
is_closed (s.topological_closure : set G) :=
by convert is_closed_closure
@[to_additive] lemma subgroup.topological_closure_minimal
(s : subgroup G) {t : subgroup G} (h : s ≤ t) (ht : is_closed (t : set G)) :
s.topological_closure ≤ t :=
closure_minimal h ht
@[to_additive] lemma dense_range.topological_closure_map_subgroup [group H] [topological_space H]
[topological_group H] {f : G →* H} (hf : continuous f) (hf' : dense_range f) {s : subgroup G}
(hs : s.topological_closure = ⊤) :
(s.map f).topological_closure = ⊤ :=
begin
rw set_like.ext'_iff at hs ⊢,
simp only [subgroup.topological_closure_coe, subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢,
exact hf'.dense_image hf hs
end
/-- The topological closure of a normal subgroup is normal.-/
@[to_additive "The topological closure of a normal additive subgroup is normal."]
lemma subgroup.is_normal_topological_closure {G : Type*} [topological_space G] [group G]
[topological_group G] (N : subgroup G) [N.normal] :
(subgroup.topological_closure N).normal :=
{ conj_mem := λ n hn g,
begin
apply mem_closure_of_continuous (topological_group.continuous_conj g) hn,
intros m hm,
exact subset_closure (subgroup.normal.conj_mem infer_instance m hm g),
end }
@[to_additive] lemma mul_mem_connected_component_one {G : Type*} [topological_space G]
[mul_one_class G] [has_continuous_mul G] {g h : G} (hg : g ∈ connected_component (1 : G))
(hh : h ∈ connected_component (1 : G)) : g * h ∈ connected_component (1 : G) :=
begin
rw connected_component_eq hg,
have hmul: g ∈ connected_component (g*h),
{ apply continuous.image_connected_component_subset (continuous_mul_left g),
rw ← connected_component_eq hh,
exact ⟨(1 : G), mem_connected_component, by simp only [mul_one]⟩ },
simpa [← connected_component_eq hmul] using (mem_connected_component)
end
@[to_additive] lemma inv_mem_connected_component_one {G : Type*} [topological_space G] [group G]
[topological_group G] {g : G} (hg : g ∈ connected_component (1 : G)) :
g⁻¹ ∈ connected_component (1 : G) :=
begin
rw ← inv_one,
exact continuous.image_connected_component_subset continuous_inv _
((set.mem_image _ _ _).mp ⟨g, hg, rfl⟩)
end
/-- The connected component of 1 is a subgroup of `G`. -/
@[to_additive "The connected component of 0 is a subgroup of `G`."]
def subgroup.connected_component_of_one (G : Type*) [topological_space G] [group G]
[topological_group G] : subgroup G :=
{ carrier := connected_component (1 : G),
one_mem' := mem_connected_component,
mul_mem' := λ g h hg hh, mul_mem_connected_component_one hg hh,
inv_mem' := λ g hg, inv_mem_connected_component_one hg }
/-- If a subgroup of a topological group is commutative, then so is its topological closure. -/
@[to_additive "If a subgroup of an additive topological group is commutative, then so is its
topological closure."]
def subgroup.comm_group_topological_closure [t2_space G] (s : subgroup G)
(hs : ∀ (x y : s), x * y = y * x) : comm_group s.topological_closure :=
{ ..s.topological_closure.to_group,
..s.to_submonoid.comm_monoid_topological_closure hs }
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv {s : set G} (hs : s ∈ 𝓝 (1 : G)) :
∃ V ∈ 𝓝 (1 : G), ∀ (v ∈ V) (w ∈ V), v / w ∈ s :=
have ((λp : G × G, p.1 * p.2⁻¹) ⁻¹' s) ∈ 𝓝 ((1, 1) : G × G),
from continuous_at_fst.mul continuous_at_snd.inv (by simpa),
by simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage]
using this
@[to_additive]
lemma nhds_translation_mul_inv (x : G) : comap (λ y : G, y * x⁻¹) (𝓝 1) = 𝓝 x :=
((homeomorph.mul_right x⁻¹).comap_nhds_eq 1).trans $ show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x, by simp
@[simp, to_additive] lemma map_mul_left_nhds (x y : G) : map ((*) x) (𝓝 y) = 𝓝 (x * y) :=
(homeomorph.mul_left x).map_nhds_eq y
@[to_additive] lemma map_mul_left_nhds_one (x : G) : map ((*) x) (𝓝 1) = 𝓝 x := by simp
@[to_additive]
lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G}
(tg : @topological_group G t _) (tg' : @topological_group G t' _)
(h : @nhds G t 1 = @nhds G t' 1) : t = t' :=
eq_of_nhds_eq_nhds $ λ x, by
rw [← @nhds_translation_mul_inv G t _ _ x , ← @nhds_translation_mul_inv G t' _ _ x , ← h]
@[to_additive]
lemma topological_group.of_nhds_aux {G : Type*} [group G] [topological_space G]
(hinv : tendsto (λ (x : G), x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ (x₀ : G), 𝓝 x₀ = map (λ (x : G), x₀ * x) (𝓝 1))
(hconj : ∀ (x₀ : G), map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) ≤ 𝓝 1) : continuous (λ x : G, x⁻¹) :=
begin
rw continuous_iff_continuous_at,
rintros x₀,
have key : (λ x, (x₀*x)⁻¹) = (λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹) ∘ (λ x, x⁻¹),
by {ext ; simp[mul_assoc] },
calc map (λ x, x⁻¹) (𝓝 x₀)
= map (λ x, x⁻¹) (map (λ x, x₀*x) $ 𝓝 1) : by rw hleft
... = map (λ x, (x₀*x)⁻¹) (𝓝 1) : by rw filter.map_map
... = map (((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) ∘ (λ x, x⁻¹)) (𝓝 1) : by rw key
... = map ((λ x, x₀⁻¹*x) ∘ (λ x, x₀*x*x₀⁻¹)) _ : by rw ← filter.map_map
... ≤ map ((λ x, x₀⁻¹ * x) ∘ λ x, x₀ * x * x₀⁻¹) (𝓝 1) : map_mono hinv
... = map (λ x, x₀⁻¹ * x) (map (λ x, x₀ * x * x₀⁻¹) (𝓝 1)) : filter.map_map
... ≤ map (λ x, x₀⁻¹ * x) (𝓝 1) : map_mono (hconj x₀)
... = 𝓝 x₀⁻¹ : (hleft _).symm
end
@[to_additive]
lemma topological_group.of_nhds_one' {G : Type u} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hright : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x*x₀) (𝓝 1)) : topological_group G :=
begin
refine { continuous_mul := (has_continuous_mul.of_nhds_one hmul hleft hright).continuous_mul,
continuous_inv := topological_group.of_nhds_aux hinv hleft _ },
intros x₀,
suffices : map (λ (x : G), x₀ * x * x₀⁻¹) (𝓝 1) = 𝓝 1, by simp [this, le_refl],
rw [show (λ x, x₀ * x * x₀⁻¹) = (λ x, x₀ * x) ∘ λ x, x*x₀⁻¹, by {ext, simp [mul_assoc] },
← filter.map_map, ← hright, hleft x₀⁻¹, filter.map_map],
convert map_id,
ext,
simp
end
@[to_additive]
lemma topological_group.of_nhds_one {G : Type u} [group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1))
(hconj : ∀ x₀ : G, tendsto (λ x, x₀*x*x₀⁻¹) (𝓝 1) (𝓝 1)) : topological_group G :=
{ continuous_mul := begin
rw continuous_iff_continuous_at,
rintros ⟨x₀, y₀⟩,
have key : (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) =
((λ x, x₀*y₀*x) ∘ (uncurry (*)) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id)),
by { ext, simp [uncurry, prod.map, mul_assoc] },
specialize hconj y₀⁻¹, rw inv_inv at hconj,
calc map (λ (p : G × G), p.1 * p.2) (𝓝 (x₀, y₀))
= map (λ (p : G × G), p.1 * p.2) ((𝓝 x₀) ×ᶠ 𝓝 y₀)
: by rw nhds_prod_eq
... = map (λ (p : G × G), x₀ * p.1 * (y₀ * p.2)) ((𝓝 1) ×ᶠ (𝓝 1))
: by rw [hleft x₀, hleft y₀, prod_map_map_eq, filter.map_map]
... = map (((λ x, x₀*y₀*x) ∘ (uncurry (*))) ∘ (prod.map (λ x, y₀⁻¹*x*y₀) id))((𝓝 1) ×ᶠ (𝓝 1))
: by rw key
... = map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((map (λ x, y₀⁻¹*x*y₀) $ 𝓝 1) ×ᶠ (𝓝 1))
: by rw [← filter.map_map, ← prod_map_map_eq', map_id]
... ≤ map ((λ x, x₀*y₀*x) ∘ (uncurry (*))) ((𝓝 1) ×ᶠ (𝓝 1))
: map_mono (filter.prod_mono hconj $ le_rfl)
... = map (λ x, x₀*y₀*x) (map (uncurry (*)) ((𝓝 1) ×ᶠ (𝓝 1))) : by rw filter.map_map
... ≤ map (λ x, x₀*y₀*x) (𝓝 1) : map_mono hmul
... = 𝓝 (x₀*y₀) : (hleft _).symm
end,
continuous_inv := topological_group.of_nhds_aux hinv hleft hconj}
@[to_additive]
lemma topological_group.of_comm_of_nhds_one {G : Type u} [comm_group G] [topological_space G]
(hmul : tendsto (uncurry ((*) : G → G → G)) ((𝓝 1) ×ᶠ 𝓝 1) (𝓝 1))
(hinv : tendsto (λ x : G, x⁻¹) (𝓝 1) (𝓝 1))
(hleft : ∀ x₀ : G, 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1)) : topological_group G :=
topological_group.of_nhds_one hmul hinv hleft (by simpa using tendsto_id)
end topological_group
section quotient_topological_group
variables [topological_space G] [group G] [topological_group G] (N : subgroup G) (n : N.normal)
@[to_additive]
instance quotient_group.quotient.topological_space {G : Type*} [group G] [topological_space G]
(N : subgroup G) : topological_space (G ⧸ N) :=
quotient.topological_space
open quotient_group
@[to_additive]
lemma quotient_group.is_open_map_coe : is_open_map (coe : G → G ⧸ N) :=
begin
intros s s_op,
change is_open ((coe : G → G ⧸ N) ⁻¹' (coe '' s)),
rw quotient_group.preimage_image_coe N s,
exact is_open_Union (λ n, (continuous_mul_right _).is_open_preimage s s_op)
end
@[to_additive]
instance topological_group_quotient [N.normal] : topological_group (G ⧸ N) :=
{ continuous_mul := begin
have cont : continuous ((coe : G → G ⧸ N) ∘ (λ (p : G × G), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
have quot : quotient_map (λ p : G × G, ((p.1 : G ⧸ N), (p.2 : G ⧸ N))),
{ apply is_open_map.to_quotient_map,
{ exact (quotient_group.is_open_map_coe N).prod (quotient_group.is_open_map_coe N) },
{ exact continuous_quot_mk.prod_map continuous_quot_mk },
{ exact (surjective_quot_mk _).prod_map (surjective_quot_mk _) } },
exact (quotient_map.continuous_iff quot).2 cont,
end,
continuous_inv := begin
have : continuous ((coe : G → G ⧸ N) ∘ (λ (a : G), a⁻¹)) :=
continuous_quot_mk.comp continuous_inv,
convert continuous_quotient_lift _ this,
end }
end quotient_topological_group
/-- A typeclass saying that `λ p : G × G, p.1 - p.2` is a continuous function. This property
automatically holds for topological additive groups but it also holds, e.g., for `ℝ≥0`. -/
class has_continuous_sub (G : Type*) [topological_space G] [has_sub G] : Prop :=
(continuous_sub : continuous (λ p : G × G, p.1 - p.2))
/-- A typeclass saying that `λ p : G × G, p.1 / p.2` is a continuous function. This property
automatically holds for topological groups. Lemmas using this class have primes.
The unprimed version is for `group_with_zero`. -/
@[to_additive]
class has_continuous_div (G : Type*) [topological_space G] [has_div G] : Prop :=
(continuous_div' : continuous (λ p : G × G, p.1 / p.2))
@[priority 100, to_additive] -- see Note [lower instance priority]
instance topological_group.to_has_continuous_div [topological_space G] [group G]
[topological_group G] : has_continuous_div G :=
⟨by { simp only [div_eq_mul_inv], exact continuous_fst.mul continuous_snd.inv }⟩
export has_continuous_sub (continuous_sub)
export has_continuous_div (continuous_div')
section has_continuous_div
variables [topological_space G] [has_div G] [has_continuous_div G]
@[to_additive sub]
lemma filter.tendsto.div' {f g : α → G} {l : filter α} {a b : G} (hf : tendsto f l (𝓝 a))
(hg : tendsto g l (𝓝 b)) : tendsto (λ x, f x / g x) l (𝓝 (a / b)) :=
(continuous_div'.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
@[to_additive const_sub]
lemma filter.tendsto.const_div' (b : G) {c : G} {f : α → G} {l : filter α}
(h : tendsto f l (𝓝 c)) : tendsto (λ k : α, b / f k) l (𝓝 (b / c)) :=
tendsto_const_nhds.div' h
@[to_additive sub_const]
lemma filter.tendsto.div_const' (b : G) {c : G} {f : α → G} {l : filter α}
(h : tendsto f l (𝓝 c)) : tendsto (λ k : α, f k / b) l (𝓝 (c / b)) :=
h.div' tendsto_const_nhds
variables [topological_space α] {f g : α → G} {s : set α} {x : α}
@[continuity, to_additive sub] lemma continuous.div' (hf : continuous f) (hg : continuous g) :
continuous (λ x, f x / g x) :=
continuous_div'.comp (hf.prod_mk hg : _)
@[to_additive continuous_sub_left]
lemma continuous_div_left' (a : G) : continuous (λ b : G, a / b) :=
continuous_const.div' continuous_id
@[to_additive continuous_sub_right]
lemma continuous_div_right' (a : G) : continuous (λ b : G, b / a) :=
continuous_id.div' continuous_const
@[to_additive sub]
lemma continuous_at.div' {f g : α → G} {x : α} (hf : continuous_at f x) (hg : continuous_at g x) :
continuous_at (λx, f x / g x) x :=
hf.div' hg
@[to_additive sub]
lemma continuous_within_at.div' (hf : continuous_within_at f s x)
(hg : continuous_within_at g s x) :
continuous_within_at (λ x, f x / g x) s x :=
hf.div' hg
@[to_additive sub]
lemma continuous_on.div' (hf : continuous_on f s) (hg : continuous_on g s) :
continuous_on (λx, f x / g x) s :=
λ x hx, (hf x hx).div' (hg x hx)
end has_continuous_div
section div_in_topological_group
variables [group G] [topological_space G] [topological_group G]
/-- A version of `homeomorph.mul_left a b⁻¹` that is defeq to `a / b`. -/
@[to_additive /-" A version of `homeomorph.add_left a (-b)` that is defeq to `a - b`. "-/,
simps {simp_rhs := tt}]
def homeomorph.div_left (x : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_const.div' continuous_id,
continuous_inv_fun := continuous_inv.mul continuous_const,
.. equiv.div_left x }
@[to_additive] lemma is_open_map_div_left (a : G) : is_open_map ((/) a) :=
(homeomorph.div_left _).is_open_map
@[to_additive] lemma is_closed_map_div_left (a : G) : is_closed_map ((/) a) :=
(homeomorph.div_left _).is_closed_map
/-- A version of `homeomorph.mul_right a⁻¹ b` that is defeq to `b / a`. -/
@[to_additive /-" A version of `homeomorph.add_right (-a) b` that is defeq to `b - a`. "-/,
simps {simp_rhs := tt}]
def homeomorph.div_right (x : G) : G ≃ₜ G :=
{ continuous_to_fun := continuous_id.div' continuous_const,
continuous_inv_fun := continuous_id.mul continuous_const,
.. equiv.div_right x }
@[to_additive]
lemma is_open_map_div_right (a : G) : is_open_map (λ x, x / a) :=
(homeomorph.div_right a).is_open_map
@[to_additive]
lemma is_closed_map_div_right (a : G) : is_closed_map (λ x, x / a) :=
(homeomorph.div_right a).is_closed_map
@[to_additive]
lemma tendsto_div_nhds_one_iff
{α : Type*} {l : filter α} {x : G} {u : α → G} :
tendsto (λ n, u n / x) l (𝓝 1) ↔ tendsto u l (𝓝 x) :=
begin
have A : tendsto (λ (n : α), x) l (𝓝 x) := tendsto_const_nhds,
exact ⟨λ h, by simpa using h.mul A, λ h, by simpa using h.div' A⟩
end
@[to_additive] lemma nhds_translation_div (x : G) : comap (/ x) (𝓝 1) = 𝓝 x :=
by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x
end div_in_topological_group
/-!
### Topological operations on pointwise sums and products
A few results about interior and closure of the pointwise addition/multiplication of sets in groups
with continuous addition/multiplication. See also `submonoid.top_closure_mul_self_eq` in
`topology.algebra.monoid`.
-/
section has_continuous_mul
variables [topological_space α] [group α] [has_continuous_mul α] {s t : set α}
@[to_additive] lemma is_open.mul_left (ht : is_open t) : is_open (s * t) :=
by { rw ←Union_mul_left_image, exact is_open_bUnion (λ a ha, is_open_map_mul_left a t ht) }
@[to_additive] lemma is_open.mul_right (hs : is_open s) : is_open (s * t) :=
by { rw ←Union_mul_right_image, exact is_open_bUnion (λ a ha, is_open_map_mul_right a s hs) }
@[to_additive] lemma subset_interior_mul_left : interior s * t ⊆ interior (s * t) :=
interior_maximal (set.mul_subset_mul_right interior_subset) is_open_interior.mul_right
@[to_additive] lemma subset_interior_mul_right : s * interior t ⊆ interior (s * t) :=
interior_maximal (set.mul_subset_mul_left interior_subset) is_open_interior.mul_left
@[to_additive] lemma subset_interior_mul : interior s * interior t ⊆ interior (s * t) :=
(set.mul_subset_mul_left interior_subset).trans subset_interior_mul_left
end has_continuous_mul
section topological_group
variables [topological_space α] [group α] [topological_group α] {s t : set α}
@[to_additive] lemma is_open.div_left (ht : is_open t) : is_open (s / t) :=
by { rw ←Union_div_left_image, exact is_open_bUnion (λ a ha, is_open_map_div_left a t ht) }
@[to_additive] lemma is_open.div_right (hs : is_open s) : is_open (s / t) :=
by { rw ←Union_div_right_image, exact is_open_bUnion (λ a ha, is_open_map_div_right a s hs) }
@[to_additive] lemma subset_interior_div_left : interior s / t ⊆ interior (s / t) :=
interior_maximal (div_subset_div_right interior_subset) is_open_interior.div_right
@[to_additive] lemma subset_interior_div_right : s / interior t ⊆ interior (s / t) :=
interior_maximal (div_subset_div_left interior_subset) is_open_interior.div_left
@[to_additive] lemma subset_interior_div : interior s / interior t ⊆ interior (s / t) :=
(div_subset_div_left interior_subset).trans subset_interior_div_left
@[to_additive] lemma is_open.mul_closure (hs : is_open s) (t : set α) : s * closure t = s * t :=
begin
refine (mul_subset_iff.2 $ λ a ha b hb, _).antisymm (mul_subset_mul_left subset_closure),
rw mem_closure_iff at hb,
have hbU : b ∈ s⁻¹ * {a * b} := ⟨a⁻¹, a * b, set.inv_mem_inv.2 ha, rfl, inv_mul_cancel_left _ _⟩,
obtain ⟨_, ⟨c, d, hc, (rfl : d = _), rfl⟩, hcs⟩ := hb _ hs.inv.mul_right hbU,
exact ⟨c⁻¹, _, hc, hcs, inv_mul_cancel_left _ _⟩,
end
@[to_additive] lemma is_open.closure_mul (ht : is_open t) (s : set α) : closure s * t = s * t :=
by rw [←inv_inv (closure s * t), set.mul_inv_rev, inv_closure, ht.inv.mul_closure, set.mul_inv_rev,
inv_inv, inv_inv]
@[to_additive] lemma is_open.div_closure (hs : is_open s) (t : set α) : s / closure t = s / t :=
by simp_rw [div_eq_mul_inv, inv_closure, hs.mul_closure]
@[to_additive] lemma is_open.closure_div (ht : is_open t) (s : set α) : closure s / t = s / t :=
by simp_rw [div_eq_mul_inv, ht.inv.closure_mul]
end topological_group
/-- additive group with a neighbourhood around 0.
Only used to construct a topology and uniform space.
This is currently only available for commutative groups, but it can be extended to
non-commutative groups too.
-/
class add_group_with_zero_nhd (G : Type u) extends add_comm_group G :=
(Z [] : filter G)
(zero_Z : pure 0 ≤ Z)
(sub_Z : tendsto (λp:G×G, p.1 - p.2) (Z ×ᶠ Z) Z)
section filter_mul
section
variables (G) [topological_space G] [group G] [topological_group G]
@[to_additive]
lemma topological_group.t1_space (h : @is_closed G _ {1}) : t1_space G :=
⟨assume x, by { convert is_closed_map_mul_right x _ h, simp }⟩
@[to_additive]
lemma topological_group.regular_space [t1_space G] : regular_space G :=
⟨assume s a hs ha,
let f := λ p : G × G, p.1 * (p.2)⁻¹ in
have hf : continuous f := continuous_fst.mul continuous_snd.inv,
-- a ∈ -s implies f (a, 1) ∈ -s, and so (a, 1) ∈ f⁻¹' (-s);
-- and so can find t₁ t₂ open such that a ∈ t₁ × t₂ ⊆ f⁻¹' (-s)
let ⟨t₁, t₂, ht₁, ht₂, a_mem_t₁, one_mem_t₂, t_subset⟩ :=
is_open_prod_iff.1 ((is_open_compl_iff.2 hs).preimage hf) a (1:G) (by simpa [f]) in
begin
use [s * t₂, ht₂.mul_left, λ x hx, ⟨x, 1, hx, one_mem_t₂, mul_one _⟩],
rw [nhds_within, inf_principal_eq_bot, mem_nhds_iff],
refine ⟨t₁, _, ht₁, a_mem_t₁⟩,
rintros x hx ⟨y, z, hy, hz, yz⟩,
have : x * z⁻¹ ∈ sᶜ := (prod_subset_iff.1 t_subset) x hx z hz,
have : x * z⁻¹ ∈ s, rw ← yz, simpa,
contradiction
end⟩
@[to_additive]
lemma topological_group.t2_space [t1_space G] : t2_space G :=
@regular_space.t2_space G _ (topological_group.regular_space G)
variables {G} (S : subgroup G) [subgroup.normal S] [is_closed (S : set G)]
@[to_additive]
instance subgroup.regular_quotient_of_is_closed
(S : subgroup G) [subgroup.normal S] [is_closed (S : set G)] : regular_space (G ⧸ S) :=
begin
suffices : t1_space (G ⧸ S), { exact @topological_group.regular_space _ _ _ _ this, },
have hS : is_closed (S : set G) := infer_instance,
rw ← quotient_group.ker_mk S at hS,
exact topological_group.t1_space (G ⧸ S) ((quotient_map_quotient_mk.is_closed_preimage).mp hS),
end
end
section
/-! Some results about an open set containing the product of two sets in a topological group. -/
variables [topological_space G] [group G] [topological_group G]
/-- Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `1`
such that `K * V ⊆ U`. -/
@[to_additive "Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of
`0` such that `K + V ⊆ U`."]
lemma compact_open_separated_mul_right {K U : set G} (hK : is_compact K) (hU : is_open U)
(hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), K * V ⊆ U :=
begin
apply hK.induction_on,
{ exact ⟨univ, by simp⟩ },
{ rintros s t hst ⟨V, hV, hV'⟩,
exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ },
{ rintros s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩,
use [V ∩ W, inter_mem V_in W_in],
rw union_mul,
exact union_subset ((mul_subset_mul_left (V.inter_subset_left W)).trans hV')
((mul_subset_mul_left (V.inter_subset_right W)).trans hW') },
{ intros x hx,
have := tendsto_mul (show U ∈ 𝓝 (x * 1), by simpa using hU.mem_nhds (hKU hx)),
rw [nhds_prod_eq, mem_map, mem_prod_iff] at this,
rcases this with ⟨t, ht, s, hs, h⟩,
rw [← image_subset_iff, image_mul_prod] at h,
exact ⟨t, mem_nhds_within_of_mem_nhds ht, s, hs, h⟩ }
end
open mul_opposite
/-- Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of `1`
such that `V * K ⊆ U`. -/
@[to_additive "Given a compact set `K` inside an open set `U`, there is a open neighborhood `V` of
`0` such that `V + K ⊆ U`."]
lemma compact_open_separated_mul_left {K U : set G} (hK : is_compact K) (hU : is_open U)
(hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), V * K ⊆ U :=
begin
rcases compact_open_separated_mul_right (hK.image continuous_op) (op_homeomorph.is_open_map U hU)
(image_subset op hKU) with ⟨V, (hV : V ∈ 𝓝 (op (1 : G))), hV' : op '' K * V ⊆ op '' U⟩,
refine ⟨op ⁻¹' V, continuous_op.continuous_at hV, _⟩,
rwa [← image_preimage_eq V op_surjective, ← image_op_mul, image_subset_iff,
preimage_image_eq _ op_injective] at hV'
end
/-- A compact set is covered by finitely many left multiplicative translates of a set
with non-empty interior. -/
@[to_additive "A compact set is covered by finitely many left additive translates of a set
with non-empty interior."]
lemma compact_covered_by_mul_left_translates {K V : set G} (hK : is_compact K)
(hV : (interior V).nonempty) : ∃ t : finset G, K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V :=
begin
obtain ⟨t, ht⟩ : ∃ t : finset G, K ⊆ ⋃ x ∈ t, interior (((*) x) ⁻¹' V),
{ refine hK.elim_finite_subcover (λ x, interior $ ((*) x) ⁻¹' V) (λ x, is_open_interior) _,
cases hV with g₀ hg₀,
refine λ g hg, mem_Union.2 ⟨g₀ * g⁻¹, _⟩,
refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) _,
rwa [mem_preimage, inv_mul_cancel_right] },
exact ⟨t, subset.trans ht $ Union₂_mono $ λ g hg, interior_subset⟩
end
/-- Every locally compact separable topological group is σ-compact.
Note: this is not true if we drop the topological group hypothesis. -/
@[priority 100, to_additive separable_locally_compact_add_group.sigma_compact_space]
instance separable_locally_compact_group.sigma_compact_space
[separable_space G] [locally_compact_space G] : sigma_compact_space G :=
begin
obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G),
refine ⟨⟨λ n, (λ x, x * dense_seq G n) ⁻¹' L, _, _⟩⟩,
{ intro n, exact (homeomorph.mul_right _).compact_preimage.mpr hLc },
{ refine Union_eq_univ_iff.2 (λ x, _),
obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (dense_seq G) ∩ (λ y, x * y) ⁻¹' L).nonempty,
{ rw [← (homeomorph.mul_left x).apply_symm_apply 1] at hL1,
exact (dense_range_dense_seq G).inter_nhds_nonempty
((homeomorph.mul_left x).continuous.continuous_at $ hL1) },
exact ⟨n, hn⟩ }
end
/-- Every separated topological group in which there exists a compact set with nonempty interior
is locally compact. -/
@[to_additive] lemma topological_space.positive_compacts.locally_compact_space_of_group
[t2_space G] (K : positive_compacts G) :
locally_compact_space G :=
begin
refine locally_compact_of_compact_nhds (λ x, _),
obtain ⟨y, hy⟩ := K.interior_nonempty,
let F := homeomorph.mul_left (x * y⁻¹),
refine ⟨F '' K, _, K.compact.image F.continuous⟩,
suffices : F.symm ⁻¹' K ∈ 𝓝 x, by { convert this, apply equiv.image_eq_preimage },
apply continuous_at.preimage_mem_nhds F.symm.continuous.continuous_at,
have : F.symm x = y, by simp [F, homeomorph.mul_left_symm],
rw this,
exact mem_interior_iff_mem_nhds.1 hy
end
end
section
variables [topological_space G] [comm_group G] [topological_group G]
@[to_additive]
lemma nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y :=
filter_eq $ set.ext $ assume s,
begin
rw [← nhds_translation_mul_inv x, ← nhds_translation_mul_inv y, ← nhds_translation_mul_inv (x*y)],
split,
{ rintros ⟨t, ht, ts⟩,
rcases exists_nhds_one_split ht with ⟨V, V1, h⟩,
refine ⟨(λa, a * x⁻¹) ⁻¹' V, (λa, a * y⁻¹) ⁻¹' V,
⟨V, V1, subset.refl _⟩, ⟨V, V1, subset.refl _⟩, _⟩,
rintros a ⟨v, w, v_mem, w_mem, rfl⟩,
apply ts,
simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * x⁻¹) v_mem (w * y⁻¹) w_mem },
{ rintros ⟨a, c, ⟨b, hb, ba⟩, ⟨d, hd, dc⟩, ac⟩,
refine ⟨b ∩ d, inter_mem hb hd, assume v, _⟩,
simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *,
rintros ⟨vb, vd⟩,
refine ac ⟨v * y⁻¹, y, _, _, _⟩,
{ rw ← mul_assoc _ _ _ at vb, exact ba _ vb },
{ apply dc y, rw mul_right_inv, exact mem_of_mem_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
/-- On a topological group, `𝓝 : G → filter G` can be promoted to a `mul_hom`. -/
@[to_additive "On an additive topological group, `𝓝 : G → filter G` can be promoted to an
`add_hom`.", simps]
def nhds_mul_hom : G →ₙ* (filter G) :=
{ to_fun := 𝓝,
map_mul' := λ_ _, nhds_mul _ _ }
end
end filter_mul
instance additive.topological_add_group {G} [h : topological_space G]
[group G] [topological_group G] : @topological_add_group (additive G) h _ :=
{ continuous_neg := @continuous_inv G _ _ _ }
instance multiplicative.topological_group {G} [h : topological_space G]
[add_group G] [topological_add_group G] : @topological_group (multiplicative G) h _ :=
{ continuous_inv := @continuous_neg G _ _ _ }
section quotient
variables [group G] [topological_space G] [topological_group G] {Γ : subgroup G}
@[to_additive]
instance quotient_group.has_continuous_const_smul : has_continuous_const_smul G (G ⧸ Γ) :=
{ continuous_const_smul := λ g₀, begin
apply continuous_coinduced_dom,
change continuous (λ g : G, quotient_group.mk (g₀ * g)),
exact continuous_coinduced_rng.comp (continuous_mul_left g₀),
end }
@[to_additive]
lemma quotient_group.continuous_smul₁ (x : G ⧸ Γ) : continuous (λ g : G, g • x) :=
begin
obtain ⟨g₀, rfl⟩ : ∃ g₀, quotient_group.mk g₀ = x,
{ exact @quotient.exists_rep _ (quotient_group.left_rel Γ) x },
change continuous (λ g, quotient_group.mk (g * g₀)),
exact continuous_coinduced_rng.comp (continuous_mul_right g₀)
end
@[to_additive]
instance quotient_group.has_continuous_smul [locally_compact_space G] :
has_continuous_smul G (G ⧸ Γ) :=
{ continuous_smul := begin
let F : G × G ⧸ Γ → G ⧸ Γ := λ p, p.1 • p.2,
change continuous F,
have H : continuous (F ∘ (λ p : G × G, (p.1, quotient_group.mk p.2))),
{ change continuous (λ p : G × G, quotient_group.mk (p.1 * p.2)),
refine continuous_coinduced_rng.comp continuous_mul },
exact quotient_map.continuous_lift_prod_right quotient_map_quotient_mk H,
end }
end quotient
namespace units
open mul_opposite (continuous_op continuous_unop)
variables [monoid α] [topological_space α] [has_continuous_mul α] [monoid β] [topological_space β]
[has_continuous_mul β]
@[to_additive] instance : topological_group αˣ :=
{ continuous_inv := continuous_induced_rng ((continuous_unop.comp
(@continuous_embed_product α _ _).snd).prod_mk (continuous_op.comp continuous_coe)) }
/-- The topological group isomorphism between the units of a product of two monoids, and the product
of the units of each monoid. -/
def homeomorph.prod_units : homeomorph (α × β)ˣ (αˣ × βˣ) :=
{ continuous_to_fun :=
begin
show continuous (λ i : (α × β)ˣ, (map (monoid_hom.fst α β) i, map (monoid_hom.snd α β) i)),
refine continuous.prod_mk _ _,
{ refine continuous_induced_rng ((continuous_fst.comp units.continuous_coe).prod_mk _),
refine mul_opposite.continuous_op.comp (continuous_fst.comp _),
simp_rw units.inv_eq_coe_inv,
exact units.continuous_coe.comp continuous_inv, },
{ refine continuous_induced_rng ((continuous_snd.comp units.continuous_coe).prod_mk _),
simp_rw units.coe_map_inv,
exact continuous_op.comp (continuous_snd.comp (units.continuous_coe.comp continuous_inv)), }
end,
continuous_inv_fun :=
begin
refine continuous_induced_rng (continuous.prod_mk _ _),
{ exact (units.continuous_coe.comp continuous_fst).prod_mk
(units.continuous_coe.comp continuous_snd), },
{ refine continuous_op.comp
(units.continuous_coe.comp $ continuous_induced_rng $ continuous.prod_mk _ _),
{ exact (units.continuous_coe.comp (continuous_inv.comp continuous_fst)).prod_mk
(units.continuous_coe.comp (continuous_inv.comp continuous_snd)) },
{ exact continuous_op.comp ((units.continuous_coe.comp continuous_fst).prod_mk
(units.continuous_coe.comp continuous_snd)) }}
end,
..mul_equiv.prod_units }
end units
section lattice_ops
variables {ι : Sort*} [group G] [group H] {ts : set (topological_space G)}
(h : ∀ t ∈ ts, @topological_group G t _) {ts' : ι → topological_space G}
(h' : ∀ i, @topological_group G (ts' i) _) {t₁ t₂ : topological_space G}
(h₁ : @topological_group G t₁ _) (h₂ : @topological_group G t₂ _)
{t : topological_space H} [topological_group H] {F : Type*}
[monoid_hom_class F G H] (f : F)
@[to_additive] lemma topological_group_Inf :
@topological_group G (Inf ts) _ :=
{ continuous_inv := @has_continuous_inv.continuous_inv G (Inf ts) _
(@has_continuous_inv_Inf _ _ _
(λ t ht, @topological_group.to_has_continuous_inv G t _ (h t ht))),
continuous_mul := @has_continuous_mul.continuous_mul G (Inf ts) _
(@has_continuous_mul_Inf _ _ _
(λ t ht, @topological_group.to_has_continuous_mul G t _ (h t ht))) }
include h'
@[to_additive] lemma topological_group_infi :
@topological_group G (⨅ i, ts' i) _ :=
by {rw ← Inf_range, exact topological_group_Inf (set.forall_range_iff.mpr h')}
omit h'
include h₁ h₂
@[to_additive] lemma topological_group_inf :
@topological_group G (t₁ ⊓ t₂) _ :=
by {rw inf_eq_infi, refine topological_group_infi (λ b, _), cases b; assumption}
omit h₁ h₂
@[to_additive] lemma topological_group_induced :
@topological_group G (t.induced f) _ :=
{ continuous_inv :=
begin
letI : topological_space G := t.induced f,
refine continuous_induced_rng _,
simp_rw [function.comp, map_inv],
exact continuous_inv.comp (continuous_induced_dom : continuous f)
end,
continuous_mul := @has_continuous_mul.continuous_mul G (t.induced f) _
(@has_continuous_mul_induced G H _ _ t _ _ _ f) }
end lattice_ops
/-!
### Lattice of group topologies
We define a type class `group_topology α` which endows a group `α` with a topology such that all
group operations are continuous.
Group topologies on a fixed group `α` are ordered, by reverse inclusion. They form a complete
lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology.
Any function `f : α → β` induces `coinduced f : topological_space α → group_topology β`.
The additive version `add_group_topology α` and corresponding results are provided as well.
-/
/-- A group topology on a group `α` is a topology for which multiplication and inversion
are continuous. -/
structure group_topology (α : Type u) [group α]
extends topological_space α, topological_group α : Type u
/-- An additive group topology on an additive group `α` is a topology for which addition and
negation are continuous. -/
structure add_group_topology (α : Type u) [add_group α]
extends topological_space α, topological_add_group α : Type u
attribute [to_additive] group_topology
namespace group_topology
variables [group α]
/-- A version of the global `continuous_mul` suitable for dot notation. -/
@[to_additive]
lemma continuous_mul' (g : group_topology α) :
by haveI := g.to_topological_space; exact continuous (λ p : α × α, p.1 * p.2) :=
begin
letI := g.to_topological_space,
haveI := g.to_topological_group,
exact continuous_mul,
end
/-- A version of the global `continuous_inv` suitable for dot notation. -/
@[to_additive]
lemma continuous_inv' (g : group_topology α) :
by haveI := g.to_topological_space; exact continuous (has_inv.inv : α → α) :=
begin
letI := g.to_topological_space,
haveI := g.to_topological_group,
exact continuous_inv,
end
@[to_additive]
lemma to_topological_space_injective :
function.injective (to_topological_space : group_topology α → topological_space α):=
λ f g h, by { cases f, cases g, congr' }
@[ext, to_additive]
lemma ext' {f g : group_topology α} (h : f.is_open = g.is_open) : f = g :=
to_topological_space_injective $ topological_space_eq h
/-- The ordering on group topologies on the group `γ`.
`t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/
@[to_additive]
instance : partial_order (group_topology α) :=
partial_order.lift to_topological_space to_topological_space_injective
@[simp, to_additive] lemma to_topological_space_le {x y : group_topology α} :
x.to_topological_space ≤ y.to_topological_space ↔ x ≤ y := iff.rfl
@[to_additive]
instance : has_top (group_topology α) :=
⟨{to_topological_space := ⊤,
continuous_mul := continuous_top,
continuous_inv := continuous_top}⟩
@[simp, to_additive] lemma to_topological_space_top :
(⊤ : group_topology α).to_topological_space = ⊤ := rfl
@[to_additive]
instance : has_bot (group_topology α) :=
⟨{to_topological_space := ⊥,
continuous_mul := by continuity,
continuous_inv := continuous_bot}⟩
@[simp, to_additive] lemma to_topological_space_bot :
(⊥ : group_topology α).to_topological_space = ⊥ := rfl
@[to_additive]
instance : bounded_order (group_topology α) :=
{ top := ⊤,
le_top := λ x, show x.to_topological_space ≤ ⊤, from le_top,
bot := ⊥,
bot_le := λ x, show ⊥ ≤ x.to_topological_space, from bot_le }
@[to_additive]
instance : has_inf (group_topology α) :=
{ inf := λ x y,
{ to_topological_space := x.to_topological_space ⊓ y.to_topological_space,
continuous_mul := continuous_inf_rng
(continuous_inf_dom_left₂ x.continuous_mul') (continuous_inf_dom_right₂ y.continuous_mul'),
continuous_inv := continuous_inf_rng
(continuous_inf_dom_left x.continuous_inv') (continuous_inf_dom_right y.continuous_inv') } }
@[simp, to_additive]
lemma to_topological_space_inf (x y : group_topology α) :
(x ⊓ y).to_topological_space = x.to_topological_space ⊓ y.to_topological_space := rfl
@[to_additive]
instance : semilattice_inf (group_topology α) :=
to_topological_space_injective.semilattice_inf _ to_topological_space_inf
@[to_additive]
instance : inhabited (group_topology α) := ⟨⊤⟩
local notation `cont` := @continuous _ _
@[to_additive "Infimum of a collection of additive group topologies"]
instance : has_Inf (group_topology α) :=
{ Inf := λ S,
{ to_topological_space := Inf (to_topological_space '' S),
continuous_mul := continuous_Inf_rng begin
rintros _ ⟨⟨t, tr⟩, haS, rfl⟩, resetI,
exact continuous_Inf_dom₂
(set.mem_image_of_mem to_topological_space haS)
(set.mem_image_of_mem to_topological_space haS) continuous_mul,
end,
continuous_inv := continuous_Inf_rng begin
rintros _ ⟨⟨t, tr⟩, haS, rfl⟩, resetI,
exact continuous_Inf_dom (set.mem_image_of_mem to_topological_space haS) continuous_inv,
end, } }
@[simp, to_additive]
lemma to_topological_space_Inf (s : set (group_topology α)) :
(Inf s).to_topological_space = Inf (to_topological_space '' s) := rfl
@[simp, to_additive]
lemma to_topological_space_infi {ι} (s : ι → group_topology α) :
(⨅ i, s i).to_topological_space = ⨅ i, (s i).to_topological_space :=
congr_arg Inf (range_comp _ _).symm
/-- Group topologies on `γ` form a complete lattice, with `⊥` the discrete topology and `⊤` the
indiscrete topology.
The infimum of a collection of group topologies is the topology generated by all their open sets
(which is a group topology).
The supremum of two group topologies `s` and `t` is the infimum of the family of all group
topologies contained in the intersection of `s` and `t`. -/
@[to_additive]
instance : complete_semilattice_Inf (group_topology α) :=
{ Inf_le := λ S a haS, to_topological_space_le.1 $ Inf_le ⟨a, haS, rfl⟩,
le_Inf :=
begin
intros S a hab,
apply topological_space.complete_lattice.le_Inf,
rintros _ ⟨b, hbS, rfl⟩,
exact hab b hbS,
end,
..group_topology.has_Inf,
..group_topology.partial_order }
@[to_additive]
instance : complete_lattice (group_topology α) :=
{ inf := (⊓),
top := ⊤,
bot := ⊥,
..group_topology.bounded_order,
..group_topology.semilattice_inf,
..complete_lattice_of_complete_semilattice_Inf _ }
/-- Given `f : α → β` and a topology on `α`, the coinduced group topology on `β` is the finest
topology such that `f` is continuous and `β` is a topological group. -/
@[to_additive "Given `f : α → β` and a topology on `α`, the coinduced additive group topology on `β`
is the finest topology such that `f` is continuous and `β` is a topological additive group."]
def coinduced {α β : Type*} [t : topological_space α] [group β] (f : α → β) :
group_topology β :=
Inf {b : group_topology β | (topological_space.coinduced f t) ≤ b.to_topological_space}
@[to_additive]
lemma coinduced_continuous {α β : Type*} [t : topological_space α] [group β]
(f : α → β) : cont t (coinduced f).to_topological_space f :=
begin
rw continuous_iff_coinduced_le,
refine le_Inf _,
rintros _ ⟨t', ht', rfl⟩,
exact ht',
end
end group_topology
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.