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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6c04fd6c38664a69bf1c6ed23821de0daf5d2315 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/hash_map.lean | 048ef0bdd822ff1a062cdb8f860db5db5a0eec80 | [
"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 | 29,571 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import data.pnat.basic
import data.list.range
import data.array.lemmas
/-!
# Hash maps
Defines a hash map data structure, representing a finite key-value map
with a value type that may depend on the key type. The structure
requires a `nat`-valued hash function to associate keys to buckets.
## Main definitions
* `hash_map`: constructed with `mk_hash_map`.
## Implementation details
A hash map with key type `α` and (dependent) value type `β : α → Type*`
consists of an array of *buckets*, which are lists containing
key/value pairs for that bucket. The hash function is taken modulo `n`
to assign keys to their respective bucket. Because of this, some care
should be put into the hash function to ensure it evenly distributes
keys.
The bucket array is an `array`. These have special VM support for
in-place modification if there is only ever one reference to them. If
one takes special care to never keep references to old versions of a
hash map alive after updating it, then the hash map will be modified
in-place. In this documentation, when we say a hash map is modified
in-place, we are assuming the API is being used in this manner.
When inserting (`hash_map.insert`), if the number of stored pairs (the
*size*) is going to exceed the number of buckets, then a new hash map
is first created with double the number of buckets and everything in
the old hash map is reinserted along with the new key/value pair.
Otherwise, the bucket array is modified in-place. The amortized
running time of inserting $$n$$ elements into a hash map is $$O(n)$$.
When removing (`hash_map.erase`), the hash map is modified in-place.
The implementation does not reduce the number of buckets in the hash
map if the size gets too low.
## Tags
hash map
-/
universes u v w
/-- `bucket_array α β` is the underlying data type for `hash_map α β`,
an array of linked lists of key-value pairs. -/
def bucket_array (α : Type u) (β : α → Type v) (n : ℕ+) :=
array n (list Σ a, β a)
/-- Make a hash_map index from a `nat` hash value and a (positive) buffer size -/
def hash_map.mk_idx (n : ℕ+) (i : nat) : fin n :=
⟨i % n, nat.mod_lt _ n.2⟩
namespace bucket_array
section
parameters {α : Type u} {β : α → Type v} (hash_fn : α → nat)
variables {n : ℕ+} (data : bucket_array α β n)
instance : inhabited (bucket_array α β n) :=
⟨mk_array _ []⟩
/-- Read the bucket corresponding to an element -/
def read (a : α) : list Σ a, β a :=
let bidx := hash_map.mk_idx n (hash_fn a) in
data.read bidx
/-- Write the bucket corresponding to an element -/
def write (a : α) (l : list Σ a, β a) : bucket_array α β n :=
let bidx := hash_map.mk_idx n (hash_fn a) in
data.write bidx l
/-- Modify (read, apply `f`, and write) the bucket corresponding to an element -/
def modify (a : α) (f : list (Σ a, β a) → list (Σ a, β a)) : bucket_array α β n :=
let bidx := hash_map.mk_idx n (hash_fn a) in
array.write data bidx (f (array.read data bidx))
/-- The list of all key-value pairs in the bucket list -/
def as_list : list Σ a, β a := data.to_list.join
theorem mem_as_list {a : Σ a, β a} : a ∈ data.as_list ↔ ∃i, a ∈ array.read data i :=
have (∃ (l : list (Σ (a : α), β a)) (i : fin (n.val)), a ∈ l ∧ array.read data i = l) ↔
∃ (i : fin (n.val)), a ∈ array.read data i,
by rw exists_swap; exact exists_congr (λ i, by simp),
by simp [as_list]; simpa [array.mem.def, and_comm]
/-- Fold a function `f` over the key-value pairs in the bucket list -/
def foldl {δ : Type w} (d : δ) (f : δ → Π a, β a → δ) : δ :=
data.foldl d (λ b d, b.foldl (λ r a, f r a.1 a.2) d)
theorem foldl_eq {δ : Type w} (d : δ) (f : δ → Π a, β a → δ) :
data.foldl d f = data.as_list.foldl (λ r a, f r a.1 a.2) d :=
by rw [foldl, as_list, list.foldl_join, ← array.to_list_foldl]
end
end bucket_array
namespace hash_map
section
parameters {α : Type u} {β : α → Type v} (hash_fn : α → nat)
/-- Insert the pair `⟨a, b⟩` into the correct location in the bucket array
(without checking for duplication) -/
def reinsert_aux {n} (data : bucket_array α β n) (a : α) (b : β a) : bucket_array α β n :=
data.modify hash_fn a (λl, ⟨a, b⟩ :: l)
theorem mk_as_list (n : ℕ+) : bucket_array.as_list (mk_array n [] : bucket_array α β n) = [] :=
list.eq_nil_iff_forall_not_mem.mpr $ λ x m,
let ⟨i, h⟩ := (bucket_array.mem_as_list _).1 m in h
parameter [decidable_eq α]
/-- Search a bucket for a key `a` and return the value -/
def find_aux (a : α) : list (Σ a, β a) → option (β a)
| [] := none
| (⟨a',b⟩::t) := if h : a' = a then some (eq.rec_on h b) else find_aux t
theorem find_aux_iff {a : α} {b : β a} :
Π {l : list Σ a, β a}, (l.map sigma.fst).nodup → (find_aux a l = some b ↔ sigma.mk a b ∈ l)
| [] nd := ⟨λn, by injection n, false.elim⟩
| (⟨a',b'⟩::t) nd := begin
by_cases a' = a,
{ clear find_aux_iff, subst h,
suffices : b' = b ↔ b' = b ∨ sigma.mk a' b ∈ t, {simpa [find_aux, eq_comm]},
refine (or_iff_left_of_imp (λ m, _)).symm,
have : a' ∉ t.map sigma.fst, from list.not_mem_of_nodup_cons nd,
exact this.elim (list.mem_map_of_mem sigma.fst m) },
{ have : sigma.mk a b ≠ ⟨a', b'⟩,
{ intro e, injection e with e, exact h e.symm },
simp at nd, simp [find_aux, h, ne.symm h, find_aux_iff, nd] }
end
/-- Returns `tt` if the bucket `l` contains the key `a` -/
def contains_aux (a : α) (l : list Σ a, β a) : bool :=
(find_aux a l).is_some
theorem contains_aux_iff {a : α} {l : list Σ a, β a} (nd : (l.map sigma.fst).nodup) :
contains_aux a l ↔ a ∈ l.map sigma.fst :=
begin
unfold contains_aux,
cases h : find_aux a l with b; simp,
{ assume (b : β a) (m : sigma.mk a b ∈ l),
rw (find_aux_iff nd).2 m at h,
contradiction },
{ show ∃ (b : β a), sigma.mk a b ∈ l,
exact ⟨_, (find_aux_iff nd).1 h⟩ },
end
/-- Modify a bucket to replace a value in the list. Leaves the list
unchanged if the key is not found. -/
def replace_aux (a : α) (b : β a) : list (Σ a, β a) → list (Σ a, β a)
| [] := []
| (⟨a', b'⟩::t) := if a' = a then ⟨a, b⟩::t else ⟨a', b'⟩ :: replace_aux t
/-- Modify a bucket to remove a key, if it exists. -/
def erase_aux (a : α) : list (Σ a, β a) → list (Σ a, β a)
| [] := []
| (⟨a', b'⟩::t) := if a' = a then t else ⟨a', b'⟩ :: erase_aux t
/-- The predicate `valid bkts sz` means that `bkts` satisfies the `hash_map`
invariants: There are exactly `sz` elements in it, every pair is in the
bucket determined by its key and the hash function, and no key appears
multiple times in the list. -/
structure valid {n} (bkts : bucket_array α β n) (sz : nat) : Prop :=
(len : bkts.as_list.length = sz)
(idx : ∀ {i} {a : Σ a, β a}, a ∈ array.read bkts i →
mk_idx n (hash_fn a.1) = i)
(nodup : ∀i, ((array.read bkts i).map sigma.fst).nodup)
theorem valid.idx_enum {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
{i l} (he : (i, l) ∈ bkts.to_list.enum) {a} {b : β a} (hl : sigma.mk a b ∈ l) :
∃ h, mk_idx n (hash_fn a) = ⟨i, h⟩ :=
(array.mem_to_list_enum.mp he).imp (λ h e, by subst e; exact v.idx hl)
theorem valid.idx_enum_1 {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
{i l} (he : (i, l) ∈ bkts.to_list.enum) {a} {b : β a} (hl : sigma.mk a b ∈ l) :
(mk_idx n (hash_fn a)).1 = i :=
let ⟨h, e⟩ := v.idx_enum _ he hl in by rw e; refl
theorem valid.as_list_nodup {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz) :
(bkts.as_list.map sigma.fst).nodup :=
begin
suffices : (bkts.to_list.map (list.map sigma.fst)).pairwise list.disjoint,
{ suffices : ∀ l, array.mem l bkts → (l.map sigma.fst).nodup,
by simpa [bucket_array.as_list, list.nodup_join, *],
rintros l ⟨i, rfl⟩,
apply v.nodup },
rw [← list.enum_map_snd bkts.to_list, list.pairwise_map, list.pairwise_map],
have : (bkts.to_list.enum.map prod.fst).nodup := by simp [list.nodup_range],
refine list.pairwise.imp_of_mem _ ((list.pairwise_map _).1 this),
rw prod.forall, intros i l₁,
rw prod.forall, intros j l₂ me₁ me₂ ij,
simp [list.disjoint], intros a b ml₁ b' ml₂,
apply ij, rwa [← v.idx_enum_1 _ me₁ ml₁, ← v.idx_enum_1 _ me₂ ml₂]
end
theorem mk_valid (n : ℕ+) : @valid n (mk_array n []) 0 :=
⟨by simp [mk_as_list], λ i a h, by cases h, λ i, list.nodup_nil⟩
theorem valid.find_aux_iff {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz) {a : α}
{b : β a} :
find_aux a (bkts.read hash_fn a) = some b ↔ sigma.mk a b ∈ bkts.as_list :=
(find_aux_iff (v.nodup _)).trans $
by rw bkts.mem_as_list; exact ⟨λ h, ⟨_, h⟩, λ ⟨i, h⟩, (v.idx h).symm ▸ h⟩
theorem valid.contains_aux_iff {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
(a : α) :
contains_aux a (bkts.read hash_fn a) ↔ a ∈ bkts.as_list.map sigma.fst :=
by simp [contains_aux, option.is_some_iff_exists, v.find_aux_iff hash_fn]
section
parameters {n : ℕ+} {bkts : bucket_array α β n}
{bidx : fin n} {f : list (Σ a, β a) → list (Σ a, β a)}
(u v1 v2 w : list Σ a, β a)
local notation `L` := array.read bkts bidx
private def bkts' : bucket_array α β n := array.write bkts bidx (f L)
variables (hl : L = u ++ v1 ++ w)
(hfl : f L = u ++ v2 ++ w)
include hl hfl
theorem append_of_modify :
∃ u' w', bkts.as_list = u' ++ v1 ++ w' ∧ bkts'.as_list = u' ++ v2 ++ w' :=
begin
unfold bucket_array.as_list,
have h : (bidx : ℕ) < bkts.to_list.length, { simp only [bidx.is_lt, array.to_list_length] },
refine ⟨(bkts.to_list.take bidx).join ++ u, w ++ (bkts.to_list.drop (bidx+1)).join, _, _⟩,
{ conv { to_lhs,
rw [← list.take_append_drop bidx bkts.to_list, list.drop_eq_nth_le_cons h],
simp [hl] }, simp },
{ conv { to_lhs,
rw [bkts', array.write_to_list, list.update_nth_eq_take_cons_drop _ h],
simp [hfl] }, simp }
end
variables (hvnd : (v2.map sigma.fst).nodup)
(hal : ∀ (a : Σ a, β a), a ∈ v2 → mk_idx n (hash_fn a.1) = bidx)
(djuv : (u.map sigma.fst).disjoint (v2.map sigma.fst))
(djwv : (w.map sigma.fst).disjoint (v2.map sigma.fst))
include hvnd hal djuv djwv
theorem valid.modify {sz : ℕ} (v : valid bkts sz) :
v1.length ≤ sz + v2.length ∧ valid bkts' (sz + v2.length - v1.length) :=
begin
rcases append_of_modify u v1 v2 w hl hfl with ⟨u', w', e₁, e₂⟩,
rw [← v.len, e₁],
suffices : valid bkts' (u' ++ v2 ++ w').length,
{ simpa [ge, add_comm, add_left_comm, nat.le_add_right, nat.add_sub_cancel_left] },
refine ⟨congr_arg _ e₂, λ i a, _, λ i, _⟩,
{ by_cases bidx = i,
{ subst i, rw [bkts', array.read_write, hfl],
have := @valid.idx _ _ _ v bidx a,
simp only [hl, list.mem_append, or_imp_distrib, forall_and_distrib] at this ⊢,
exact ⟨⟨this.1.1, hal _⟩, this.2⟩ },
{ rw [bkts', array.read_write_of_ne _ _ h], apply v.idx } },
{ by_cases bidx = i,
{ subst i, rw [bkts', array.read_write, hfl],
have := @valid.nodup _ _ _ v bidx,
simp [hl, list.nodup_append] at this,
simp [list.nodup_append, this, hvnd, djuv, djwv.symm] },
{ rw [bkts', array.read_write_of_ne _ _ h], apply v.nodup } }
end
end
theorem valid.replace_aux (a : α) (b : β a) : Π (l : list (Σ a, β a)), a ∈ l.map sigma.fst →
∃ (u w : list Σ a, β a) b', l = u ++ [⟨a, b'⟩] ++ w ∧ replace_aux a b l = u ++ [⟨a, b⟩] ++ w
| [] := false.elim
| (⟨a', b'⟩::t) := begin
by_cases e : a' = a,
{ subst a',
suffices : ∃ (u w : list Σ a, β a) (b'' : β a),
(sigma.mk a b') :: t = u ++ ⟨a, b''⟩ :: w ∧
replace_aux a b (⟨a, b'⟩ :: t) = u ++ ⟨a, b⟩ :: w, {simpa},
refine ⟨[], t, b', _⟩, simp [replace_aux] },
{ suffices : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (b'' : β a),
(sigma.mk a' b') :: t = u ++ ⟨a, b''⟩ :: w ∧
(sigma.mk a' b') :: (replace_aux a b t) = u ++ ⟨a, b⟩ :: w,
{ simpa [replace_aux, ne.symm e, e] },
intros x m,
have IH : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (b'' : β a),
t = u ++ ⟨a, b''⟩ :: w ∧ replace_aux a b t = u ++ ⟨a, b⟩ :: w,
{ simpa using valid.replace_aux t },
rcases IH x m with ⟨u, w, b'', hl, hfl⟩,
exact ⟨⟨a', b'⟩ :: u, w, b'', by simp [hl, hfl.symm, ne.symm e]⟩ }
end
theorem valid.replace {n : ℕ+}
{bkts : bucket_array α β n} {sz : ℕ} (a : α) (b : β a)
(Hc : contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (bkts.modify hash_fn a (replace_aux a b)) sz :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases hash_map.valid.replace_aux a b (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u, w, b', hl, hfl⟩,
simp [hl, list.nodup_append] at nd,
refine (v.modify hash_fn
u [⟨a, b'⟩] [⟨a, b⟩] w hl hfl (list.nodup_singleton _)
(λa' e, by simp at e; rw e)
(λa' e1 e2, _)
(λa' e1 e2, _)).2;
{ revert e1, simp [-sigma.exists] at e2, subst a', simp [nd] }
end
theorem valid.insert {n : ℕ+}
{bkts : bucket_array α β n} {sz : ℕ} (a : α) (b : β a)
(Hnc : ¬ contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (reinsert_aux bkts a b) (sz+1) :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
refine (v.modify hash_fn
[] [] [⟨a, b⟩] (bkts.read hash_fn a) rfl rfl (list.nodup_singleton _)
(λa' e, by simp at e; rw e)
(λa', false.elim)
(λa' e1 e2, _)).2,
simp [-sigma.exists] at e2, subst a',
exact Hnc ((contains_aux_iff nd).2 e1)
end
theorem valid.erase_aux (a : α) : Π (l : list (Σ a, β a)), a ∈ l.map sigma.fst →
∃ (u w : list Σ a, β a) b, l = u ++ [⟨a, b⟩] ++ w ∧ erase_aux a l = u ++ [] ++ w
| [] := false.elim
| (⟨a', b'⟩::t) := begin
by_cases e : a' = a,
{ subst a',
simpa [erase_aux, and_comm] using show ∃ u w (x : β a),
t = u ++ w ∧ (sigma.mk a b') :: t = u ++ ⟨a, x⟩ :: w,
from ⟨[], t, b', by simp⟩ },
{ simp [erase_aux, e, ne.symm e],
suffices : ∀ (b : β a) (_ : sigma.mk a b ∈ t), ∃ u w (x : β a),
(sigma.mk a' b') :: t = u ++ ⟨a, x⟩ :: w ∧
(sigma.mk a' b') :: (erase_aux a t) = u ++ w,
{ simpa [replace_aux, ne.symm e, e] },
intros b m,
have IH : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (x : β a),
t = u ++ ⟨a, x⟩ :: w ∧ erase_aux a t = u ++ w,
{ simpa using valid.erase_aux t },
rcases IH b m with ⟨u, w, b'', hl, hfl⟩,
exact ⟨⟨a', b'⟩ :: u, w, b'', by simp [hl, hfl.symm]⟩ }
end
theorem valid.erase {n} {bkts : bucket_array α β n} {sz}
(a : α) (Hc : contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (bkts.modify hash_fn a (erase_aux a)) (sz-1) :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases hash_map.valid.erase_aux a (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u, w, b, hl, hfl⟩,
refine (v.modify hash_fn u [⟨a, b⟩] [] w hl hfl list.nodup_nil _ _ _).2;
simp
end
end
end hash_map
/-- A hash map data structure, representing a finite key-value map
with key type `α` and value type `β` (which may depend on `α`). -/
structure hash_map (α : Type u) [decidable_eq α] (β : α → Type v) :=
(hash_fn : α → nat)
(size : ℕ)
(nbuckets : ℕ+)
(buckets : bucket_array α β nbuckets)
(is_valid : hash_map.valid hash_fn buckets size)
/-- Construct an empty hash map with buffer size `nbuckets` (default 8). -/
def mk_hash_map {α : Type u} [decidable_eq α] {β : α → Type v} (hash_fn : α → nat) (nbuckets := 8) :
hash_map α β :=
let n := if nbuckets = 0 then 8 else nbuckets in
let nz : n > 0 := by abstract { cases nbuckets; simp [if_pos, nat.succ_ne_zero] } in
{ hash_fn := hash_fn,
size := 0,
nbuckets := ⟨n, nz⟩,
buckets := mk_array n [],
is_valid := hash_map.mk_valid _ _ }
namespace hash_map
variables {α : Type u} {β : α → Type v} [decidable_eq α]
/-- Return the value corresponding to a key, or `none` if not found -/
def find (m : hash_map α β) (a : α) : option (β a) :=
find_aux a (m.buckets.read m.hash_fn a)
/-- Return `tt` if the key exists in the map -/
def contains (m : hash_map α β) (a : α) : bool :=
(m.find a).is_some
instance : has_mem α (hash_map α β) := ⟨λa m, m.contains a⟩
/-- Fold a function over the key-value pairs in the map -/
def fold {δ : Type w} (m : hash_map α β) (d : δ) (f : δ → Π a, β a → δ) : δ :=
m.buckets.foldl d f
/-- The list of key-value pairs in the map -/
def entries (m : hash_map α β) : list Σ a, β a :=
m.buckets.as_list
/-- The list of keys in the map -/
def keys (m : hash_map α β) : list α :=
m.entries.map sigma.fst
theorem find_iff (m : hash_map α β) (a : α) (b : β a) :
m.find a = some b ↔ sigma.mk a b ∈ m.entries :=
m.is_valid.find_aux_iff _
theorem contains_iff (m : hash_map α β) (a : α) :
m.contains a ↔ a ∈ m.keys :=
m.is_valid.contains_aux_iff _ _
theorem entries_empty (hash_fn : α → nat) (n) :
(@mk_hash_map α _ β hash_fn n).entries = [] :=
mk_as_list _
theorem keys_empty (hash_fn : α → nat) (n) :
(@mk_hash_map α _ β hash_fn n).keys = [] :=
by dsimp [keys]; rw entries_empty; refl
theorem find_empty (hash_fn : α → nat) (n a) :
(@mk_hash_map α _ β hash_fn n).find a = none :=
by induction h : (@mk_hash_map α _ β hash_fn n).find a; [refl,
{ have := (find_iff _ _ _).1 h, rw entries_empty at this, contradiction }]
theorem not_contains_empty (hash_fn : α → nat) (n a) :
¬ (@mk_hash_map α _ β hash_fn n).contains a :=
by apply bool_iff_false.2; dsimp [contains]; rw [find_empty]; refl
theorem insert_lemma (hash_fn : α → nat) {n n'}
{bkts : bucket_array α β n} {sz} (v : valid hash_fn bkts sz) :
valid hash_fn (bkts.foldl (mk_array _ [] : bucket_array α β n') (reinsert_aux hash_fn)) sz :=
begin
suffices : ∀ (l : list Σ a, β a) (t : bucket_array α β n') sz,
valid hash_fn t sz → ((l ++ t.as_list).map sigma.fst).nodup →
valid hash_fn (l.foldl (λr (a : Σ a, β a), reinsert_aux hash_fn r a.1 a.2) t) (sz + l.length),
{ have p := this bkts.as_list _ _ (mk_valid _ _),
rw [mk_as_list, list.append_nil, zero_add, v.len] at p,
rw bucket_array.foldl_eq,
exact p (v.as_list_nodup _) },
intro l, induction l with c l IH; intros t sz v nd, {exact v},
rw show sz + (c :: l).length = sz + 1 + l.length, by simp [add_comm, add_assoc],
rcases (show (l.map sigma.fst).nodup ∧
((bucket_array.as_list t).map sigma.fst).nodup ∧
c.fst ∉ l.map sigma.fst ∧
c.fst ∉ (bucket_array.as_list t).map sigma.fst ∧
(l.map sigma.fst).disjoint ((bucket_array.as_list t).map sigma.fst),
by simpa [list.nodup_append, not_or_distrib, and_comm, and.left_comm] using nd)
with ⟨nd1, nd2, nm1, nm2, dj⟩,
have v' := v.insert _ _ c.2 (λHc, nm2 $ (v.contains_aux_iff _ c.1).1 Hc),
apply IH _ _ v',
suffices : ∀ ⦃a : α⦄ (b : β a), sigma.mk a b ∈ l →
∀ (b' : β a), sigma.mk a b' ∈ (reinsert_aux hash_fn t c.1 c.2).as_list → false,
{ simpa [list.nodup_append, nd1, v'.as_list_nodup _, list.disjoint] },
intros a b m1 b' m2,
rcases (reinsert_aux hash_fn t c.1 c.2).mem_as_list.1 m2 with ⟨i, im⟩,
have : sigma.mk a b' ∉ array.read t i,
{ intro m3,
have : a ∈ list.map sigma.fst t.as_list :=
list.mem_map_of_mem sigma.fst (t.mem_as_list.2 ⟨_, m3⟩),
exact dj (list.mem_map_of_mem sigma.fst m1) this },
by_cases h : mk_idx n' (hash_fn c.1) = i,
{ subst h,
have e : sigma.mk a b' = ⟨c.1, c.2⟩,
{ simpa [reinsert_aux, bucket_array.modify, array.read_write, this] using im },
injection e with e, subst a,
exact nm1.elim (@list.mem_map_of_mem _ _ sigma.fst _ _ m1) },
{ apply this,
simpa [reinsert_aux, bucket_array.modify, array.read_write_of_ne _ _ h] using im }
end
/-- Insert a key-value pair into the map. (Modifies `m` in-place when applicable) -/
def insert : Π (m : hash_map α β) (a : α) (b : β a), hash_map α β
| ⟨hash_fn, size, n, buckets, v⟩ a b :=
let bkt := buckets.read hash_fn a in
if hc : contains_aux a bkt then
{ hash_fn := hash_fn,
size := size,
nbuckets := n,
buckets := buckets.modify hash_fn a (replace_aux a b),
is_valid := v.replace _ a b hc }
else
let size' := size + 1,
buckets' := buckets.modify hash_fn a (λl, ⟨a, b⟩::l),
valid' := v.insert _ a b hc in
if size' ≤ n then
{ hash_fn := hash_fn,
size := size',
nbuckets := n,
buckets := buckets',
is_valid := valid' }
else
let n' : ℕ+ := ⟨n * 2, mul_pos n.2 dec_trivial⟩,
buckets'' : bucket_array α β n' :=
buckets'.foldl (mk_array _ []) (reinsert_aux hash_fn) in
{ hash_fn := hash_fn,
size := size',
nbuckets := n',
buckets := buckets'',
is_valid := insert_lemma _ valid' }
theorem mem_insert : Π (m : hash_map α β) (a b a' b'),
(sigma.mk a' b' : sigma β) ∈ (m.insert a b).entries ↔
if a = a' then b == b' else sigma.mk a' b' ∈ m.entries
| ⟨hash_fn, size, n, bkts, v⟩ a b a' b' := begin
let bkt := bkts.read hash_fn a,
have nd : (bkt.map sigma.fst).nodup := v.nodup (mk_idx n (hash_fn a)),
have lem : Π (bkts' : bucket_array α β n) (v1 u w)
(hl : bucket_array.as_list bkts = u ++ v1 ++ w)
(hfl : bucket_array.as_list bkts' = u ++ [⟨a, b⟩] ++ w)
(veq : (v1 = [] ∧ ¬ contains_aux a bkt) ∨ ∃b'', v1 = [⟨a, b''⟩]),
sigma.mk a' b' ∈ bkts'.as_list ↔
if a = a' then b == b' else sigma.mk a' b' ∈ bkts.as_list,
{ intros bkts' v1 u w hl hfl veq,
rw [hl, hfl],
by_cases h : a = a',
{ subst a',
suffices : b = b' ∨ sigma.mk a b' ∈ u ∨ sigma.mk a b' ∈ w ↔ b = b',
{ simpa [eq_comm, or.left_comm] },
refine or_iff_left_of_imp (not.elim $ not_or_distrib.2 _),
rcases veq with ⟨rfl, Hnc⟩ | ⟨b'', rfl⟩,
{ have na := (not_iff_not_of_iff $ v.contains_aux_iff _ _).1 Hnc,
simp [hl, not_or_distrib] at na, simp [na] },
{ have nd' := v.as_list_nodup _,
simp [hl, list.nodup_append] at nd', simp [nd'] } },
{ suffices : sigma.mk a' b' ∉ v1, {simp [h, ne.symm h, this]},
rcases veq with ⟨rfl, Hnc⟩ | ⟨b'', rfl⟩; simp [ne.symm h] } },
by_cases Hc : (contains_aux a bkt : Prop),
{ rcases hash_map.valid.replace_aux a b (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u', w', b'', hl', hfl'⟩,
rcases (append_of_modify u' [⟨a, b''⟩] [⟨a, b⟩] w' hl' hfl') with ⟨u, w, hl, hfl⟩,
simpa [insert, @dif_pos (contains_aux a bkt) _ Hc]
using lem _ _ u w hl hfl (or.inr ⟨b'', rfl⟩) },
{ let size' := size + 1,
let bkts' := bkts.modify hash_fn a (λl, ⟨a, b⟩::l),
have mi : sigma.mk a' b' ∈ bkts'.as_list ↔
if a = a' then b == b' else sigma.mk a' b' ∈ bkts.as_list :=
let ⟨u, w, hl, hfl⟩ := append_of_modify [] [] [⟨a, b⟩] _ rfl rfl in
lem bkts' _ u w hl hfl $ or.inl ⟨rfl, Hc⟩,
simp [insert, @dif_neg (contains_aux a bkt) _ Hc],
by_cases h : size' ≤ n,
{ simpa [show size' ≤ n, from h] using mi },
{ let n' : ℕ+ := ⟨n * 2, mul_pos n.2 dec_trivial⟩,
let bkts'' : bucket_array α β n' := bkts'.foldl (mk_array _ []) (reinsert_aux hash_fn),
suffices : sigma.mk a' b' ∈ bkts''.as_list ↔ sigma.mk a' b' ∈ bkts'.as_list.reverse,
{ simpa [show ¬ size' ≤ n, from h, mi] },
rw [show bkts'' = bkts'.as_list.foldl _ _, from bkts'.foldl_eq _ _,
← list.foldr_reverse],
induction bkts'.as_list.reverse with a l IH,
{ simp [mk_as_list] },
{ cases a with a'' b'',
let B := l.foldr (λ (y : sigma β) (x : bucket_array α β n'),
reinsert_aux hash_fn x y.1 y.2) (mk_array n' []),
rcases append_of_modify [] [] [⟨a'', b''⟩] _ rfl rfl with ⟨u, w, hl, hfl⟩,
simp [IH.symm, or.left_comm, show B.as_list = _, from hl,
show (reinsert_aux hash_fn B a'' b'').as_list = _, from hfl] } } }
end
theorem find_insert_eq (m : hash_map α β) (a : α) (b : β a) : (m.insert a b).find a = some b :=
(find_iff (m.insert a b) a b).2 $ (mem_insert m a b a b).2 $ by rw if_pos rfl
theorem find_insert_ne (m : hash_map α β) (a a' : α) (b : β a) (h : a ≠ a') :
(m.insert a b).find a' = m.find a' :=
option.eq_of_eq_some $ λb',
let t := mem_insert m a b a' b' in
(find_iff _ _ _).trans $ iff.trans (by rwa if_neg h at t) (find_iff _ _ _).symm
theorem find_insert (m : hash_map α β) (a' a : α) (b : β a) :
(m.insert a b).find a' = if h : a = a' then some (eq.rec_on h b) else m.find a' :=
if h : a = a' then by rw dif_pos h; exact
match a', h with ._, rfl := find_insert_eq m a b end
else by rw dif_neg h; exact find_insert_ne m a a' b h
/-- Insert a list of key-value pairs into the map. (Modifies `m` in-place when applicable) -/
def insert_all (l : list (Σ a, β a)) (m : hash_map α β) : hash_map α β :=
l.foldl (λ m ⟨a, b⟩, insert m a b) m
/-- Construct a hash map from a list of key-value pairs. -/
def of_list (l : list (Σ a, β a)) (hash_fn) : hash_map α β :=
insert_all l (mk_hash_map hash_fn (2 * l.length))
/-- Remove a key from the map. (Modifies `m` in-place when applicable) -/
def erase (m : hash_map α β) (a : α) : hash_map α β :=
match m with ⟨hash_fn, size, n, buckets, v⟩ :=
if hc : contains_aux a (buckets.read hash_fn a) then
{ hash_fn := hash_fn,
size := size - 1,
nbuckets := n,
buckets := buckets.modify hash_fn a (erase_aux a),
is_valid := v.erase _ a hc }
else m
end
theorem mem_erase : Π (m : hash_map α β) (a a' b'),
(sigma.mk a' b' : sigma β) ∈ (m.erase a).entries ↔
a ≠ a' ∧ sigma.mk a' b' ∈ m.entries
| ⟨hash_fn, size, n, bkts, v⟩ a a' b' := begin
let bkt := bkts.read hash_fn a,
by_cases Hc : (contains_aux a bkt : Prop),
{ let bkts' := bkts.modify hash_fn a (erase_aux a),
suffices : sigma.mk a' b' ∈ bkts'.as_list ↔ a ≠ a' ∧ sigma.mk a' b' ∈ bkts.as_list,
{ simpa [erase, @dif_pos (contains_aux a bkt) _ Hc] },
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases valid.erase_aux a bkt ((contains_aux_iff nd).1 Hc) with ⟨u', w', b, hl', hfl'⟩,
rcases append_of_modify u' [⟨a, b⟩] [] _ hl' hfl' with ⟨u, w, hl, hfl⟩,
suffices : ∀_:sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w, a ≠ a',
{ have : sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w ↔ (¬a = a' ∧ a' = a) ∧ b' == b ∨
¬a = a' ∧ (sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w),
{ simp [eq_comm, not_and_self_iff, and_iff_right_of_imp this] },
simpa [hl, show bkts'.as_list = _, from hfl, and_or_distrib_left,
and_comm, and.left_comm, or.left_comm] },
intros m e, subst a', revert m, apply not_or_distrib.2,
have nd' := v.as_list_nodup _,
simp [hl, list.nodup_append] at nd', simp [nd'] },
{ suffices : ∀_:sigma.mk a' b' ∈ bucket_array.as_list bkts, a ≠ a',
{ simp [erase, @dif_neg (contains_aux a bkt) _ Hc, entries, and_iff_right_of_imp this] },
intros m e, subst a',
exact Hc ((v.contains_aux_iff _ _).2 (list.mem_map_of_mem sigma.fst m)) }
end
theorem find_erase_eq (m : hash_map α β) (a : α) : (m.erase a).find a = none :=
begin
cases h : (m.erase a).find a with b, {refl},
exact absurd rfl ((mem_erase m a a b).1 ((find_iff (m.erase a) a b).1 h)).left
end
theorem find_erase_ne (m : hash_map α β) (a a' : α) (h : a ≠ a') :
(m.erase a).find a' = m.find a' :=
option.eq_of_eq_some $ λb',
(find_iff _ _ _).trans $ (mem_erase m a a' b').trans $
(and_iff_right h).trans (find_iff _ _ _).symm
theorem find_erase (m : hash_map α β) (a' a : α) :
(m.erase a).find a' = if a = a' then none else m.find a' :=
if h : a = a' then by subst a'; simp [find_erase_eq m a]
else by rw if_neg h; exact find_erase_ne m a a' h
section string
variables [has_to_string α] [∀ a, has_to_string (β a)]
open prod
private def key_data_to_string (a : α) (b : β a) (first : bool) : string :=
(if first then "" else ", ") ++ sformat!"{a} ← {b}"
private def to_string (m : hash_map α β) : string :=
"⟨" ++ (fst (fold m ("", tt) (λ p a b, (fst p ++ key_data_to_string a b (snd p), ff)))) ++ "⟩"
instance : has_to_string (hash_map α β) :=
⟨to_string⟩
end string
section format
open format prod
variables [has_to_format α] [∀ a, has_to_format (β a)]
private meta def format_key_data (a : α) (b : β a) (first : bool) : format :=
(if first then to_fmt "" else to_fmt "," ++ line) ++
to_fmt a ++ space ++ to_fmt "←" ++ space ++ to_fmt b
private meta def to_format (m : hash_map α β) : format :=
group $ to_fmt "⟨" ++
nest 1 (fst (fold m (to_fmt "", tt) (λ p a b, (fst p ++ format_key_data a b (snd p), ff)))) ++
to_fmt "⟩"
meta instance : has_to_format (hash_map α β) :=
⟨to_format⟩
end format
/-- `hash_map` with key type `nat` and value type that may vary. -/
instance {β : ℕ → Type*} : inhabited (hash_map ℕ β) := ⟨mk_hash_map id⟩
end hash_map
|
c4fb66cbd33ce722506b326eb16e7a92b7bc73c0 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /test/tactics.lean | bf37e81f2112e0b495f38cf220dc656982939c1e | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 12,762 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Scott Morrison
-/
import tactic.interactive tactic.finish tactic.ext tactic.lift tactic.apply
tactic.reassoc_axiom tactic.tfae tactic.elide tactic.ring_exp
example (m n p q : nat) (h : m + n = p) : true :=
begin
have : m + n = q,
{ generalize_hyp h' : m + n = x at h,
guard_hyp h' := m + n = x,
guard_hyp h := x = p,
guard_target m + n = q,
admit },
have : m + n = q,
{ generalize_hyp h' : m + n = x at h ⊢,
guard_hyp h' := m + n = x,
guard_hyp h := x = p,
guard_target x = q,
admit },
trivial
end
example (α : Sort*) (L₁ L₂ L₃ : list α)
(H : L₁ ++ L₂ = L₃) : true :=
begin
have : L₁ ++ L₂ = L₂,
{ generalize_hyp h : L₁ ++ L₂ = L at H,
induction L with hd tl ih,
case list.nil
{ tactic.cleanup,
change list.nil = L₃ at H,
admit },
case list.cons
{ change list.cons hd tl = L₃ at H,
admit } },
trivial
end
example (x y : ℕ) (p q : Prop) (h : x = y) (h' : p ↔ q) : true :=
begin
symmetry' at h,
guard_hyp' h := y = x,
guard_hyp' h' := p ↔ q,
symmetry' at *,
guard_hyp' h := x = y,
guard_hyp' h' := q ↔ p,
trivial
end
section apply_rules
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules [add_le_add, mul_le_mul_of_nonneg_right]
@[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
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules [mono_rules]
example {a b c d e : nat} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
by apply_rules mono_rules
end apply_rules
section h_generalize
variables {α β γ φ ψ : Type} (f : α → α → α → φ → γ)
(x y : α) (a b : β) (z : φ)
(h₀ : β = α) (h₁ : β = α) (h₂ : φ = β)
(hx : x == a) (hy : y == b) (hz : z == a)
include f x y z a b hx hy hz
example : f x y x z = f (eq.rec_on h₀ a) (cast h₀ b) (eq.mpr h₁.symm a) (eq.mpr h₂ a) :=
begin
guard_hyp_nums 16,
h_generalize hp : a == p with hh,
guard_hyp_nums 19,
guard_hyp' hh := β = α,
guard_target f x y x z = f p (cast h₀ b) p (eq.mpr h₂ a),
h_generalize hq : _ == q,
guard_hyp_nums 21,
guard_target f x y x z = f p q p (eq.mpr h₂ a),
h_generalize _ : _ == r,
guard_hyp_nums 23,
guard_target f x y x z = f p q p r,
casesm* [_ == _, _ = _], refl
end
end h_generalize
section h_generalize
variables {α β γ φ ψ : Type} (f : list α → list α → γ)
(x : list α) (a : list β) (z : φ)
(h₀ : β = α) (h₁ : list β = list α)
(hx : x == a)
include f x z a hx h₀ h₁
example : true :=
begin
have : f x x = f (eq.rec_on h₀ a) (cast h₁ a),
{ guard_hyp_nums 11,
h_generalize : a == p with _,
guard_hyp_nums 13,
guard_hyp' h := β = α,
guard_target f x x = f p (cast h₁ a),
h_generalize! : a == q ,
guard_hyp_nums 13,
guard_target ∀ q, f x x = f p q,
casesm* [_ == _, _ = _],
success_if_fail { refl },
admit },
trivial
end
end h_generalize
section tfae
example (p q r s : Prop)
(h₀ : p ↔ q)
(h₁ : q ↔ r)
(h₂ : r ↔ s) :
p ↔ s :=
begin
scc,
end
example (p' p q r r' s s' : Prop)
(h₀ : p' → p)
(h₀ : p → q)
(h₁ : q → r)
(h₁ : r' → r)
(h₂ : r ↔ s)
(h₂ : s → p)
(h₂ : s → s') :
p ↔ s :=
begin
scc,
end
example (p' p q r r' s s' : Prop)
(h₀ : p' → p)
(h₀ : p → q)
(h₁ : q → r)
(h₁ : r' → r)
(h₂ : r ↔ s)
(h₂ : s → p)
(h₂ : s → s') :
p ↔ s :=
begin
scc',
assumption
end
example : tfae [true, ∀ n : ℕ, 0 ≤ n * n, true, true] := begin
tfae_have : 3 → 1, { intro h, constructor },
tfae_have : 2 → 3, { intro h, constructor },
tfae_have : 2 ← 1, { intros h n, apply nat.zero_le },
tfae_have : 4 ↔ 2, { tauto },
tfae_finish,
end
example : tfae [] := begin
tfae_finish,
end
variables P Q R : Prop
example : tfae [P, Q, R] :=
begin
have : P → Q := sorry, have : Q → R := sorry, have : R → P := sorry,
--have : R → Q := sorry, -- uncommenting this makes the proof fail
tfae_finish
end
example : tfae [P, Q, R] :=
begin
have : P → Q := sorry, have : Q → R := sorry, have : R → P := sorry,
have : R → Q := sorry, -- uncommenting this makes the proof fail
tfae_finish
end
example : tfae [P, Q, R] :=
begin
have : P ↔ Q := sorry, have : Q ↔ R := sorry,
tfae_finish -- the success or failure of this tactic is nondeterministic!
end
end tfae
section clear_aux_decl
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
end clear_aux_decl
section congr
example (c : Prop → Prop → Prop → Prop) (x x' y z z' : Prop)
(h₀ : x ↔ x')
(h₁ : z ↔ z') :
c x y z ↔ c x' y z' :=
begin
congr',
{ guard_target x = x', ext, assumption },
{ guard_target z = z', ext, assumption },
end
end congr
section convert_to
example {a b c d : ℕ} (H : a = c) (H' : b = d) : a + b = d + c :=
by {convert_to c + d = _ using 2, from H, from H', rw[add_comm]}
example {a b c d : ℕ} (H : a = c) (H' : b = d) : a + b = d + c :=
by {convert_to c + d = _ using 0, congr' 2, from H, from H', rw[add_comm]}
example (a b c d e f g N : ℕ) : (a + b) + (c + d) + (e + f) + g ≤ a + d + e + f + c + g + b :=
by {ac_change a + d + e + f + c + g + b ≤ _, refl}
end convert_to
section swap
example {α₁ α₂ α₃ : Type} : true :=
by {have : α₁, have : α₂, have : α₃, swap, swap,
rotate, rotate, rotate, rotate 2, rotate 2, triv, recover}
end swap
section lift
example (n m k x z u : ℤ) (hn : 0 < n) (hk : 0 ≤ k + n) (hu : 0 ≤ u) (h : k + n = 2 + x) :
k + n = m + x :=
begin
lift n to ℕ using le_of_lt hn,
guard_target (k + ↑n = m + x), guard_hyp hn := (0 : ℤ) < ↑n,
lift m to ℕ,
guard_target (k + ↑n = ↑m + x), tactic.swap, guard_target (0 ≤ m), tactic.swap,
tactic.num_goals >>= λ n, guard (n = 2),
lift (k + n) to ℕ using hk with l hl,
guard_hyp l := ℕ, guard_hyp hl := ↑l = k + ↑n, guard_target (↑l = ↑m + x),
tactic.success_if_fail (tactic.get_local `hk),
lift x to ℕ with y hy,
guard_hyp y := ℕ, guard_hyp hy := ↑y = x, guard_target (↑l = ↑m + x),
lift z to ℕ with w,
guard_hyp w := ℕ, tactic.success_if_fail (tactic.get_local `z),
lift u to ℕ using hu with u rfl hu,
guard_hyp hu := (0 : ℤ) ≤ ↑u,
all_goals { admit }
end
-- test lift of functions
example (α : Type*) (f : α → ℤ) (hf : ∀ a, 0 ≤ f a) (hf' : ∀ a, f a < 1) (a : α) : 0 ≤ 2 * f a :=
begin
lift f to α → ℕ using hf,
guard_target ((0:ℤ) ≤ 2 * (λ i : α, (f i : ℤ)) a),
guard_hyp hf' := ∀ a, ((λ i : α, (f i:ℤ)) a) < 1,
trivial
end
instance can_lift_unit : can_lift unit unit :=
⟨id, λ x, true, λ x _, ⟨x, rfl⟩⟩
/- test whether new instances of `can_lift` are added as simp lemmas -/
run_cmd do l ← can_lift_attr.get_cache, guard (`can_lift_unit ∈ l)
/- test error messages -/
example (n : ℤ) (hn : 0 < n) : true :=
begin
success_if_fail_with_msg {lift n to ℕ using hn} "lift tactic failed. The type of\n hn\nis
0 < n\nbut it is expected to be\n 0 ≤ n",
success_if_fail_with_msg {lift (n : option ℤ) to ℕ}
"Failed to find a lift from option ℤ to ℕ. Provide an instance of\n can_lift (option ℤ) ℕ",
trivial
end
example (n : ℤ) : ℕ :=
begin
success_if_fail_with_msg {lift n to ℕ}
"lift tactic failed. Tactic is only applicable when the target is a proposition.",
exact 0
end
end lift
private meta def get_exception_message (t : lean.parser unit) : lean.parser string
| s := match t s with
| result.success a s' := result.success "No exception" s
| result.exception none pos s' := result.success "Exception no msg" s
| result.exception (some msg) pos s' := result.success (msg ()).to_string s
end
@[user_command] meta def test_parser1_fail_cmd
(_ : interactive.parse (lean.parser.tk "test_parser1")) : lean.parser unit :=
do
let msg := "oh, no!",
let t : lean.parser unit := tactic.fail msg,
s ← get_exception_message t,
if s = msg then tactic.skip
else interaction_monad.fail "Message was corrupted while being passed through `lean.parser.of_tactic`"
.
-- Due to `lean.parser.of_tactic'` priority, the following *should not* fail with
-- a VM check error, and instead catch the error gracefully and just
-- run and succeed silently.
test_parser1
section category_theory
open category_theory
variables {C : Type} [category.{1} C]
example (X Y Z W : C) (x : X ⟶ Y) (y : Y ⟶ Z) (z z' : Z ⟶ W) (w : X ⟶ Z)
(h : x ≫ y = w)
(h' : y ≫ z = y ≫ z') :
x ≫ y ≫ z = w ≫ z' :=
begin
rw [h',reassoc_of h],
end
end category_theory
section is_eta_expansion
/- test the is_eta_expansion tactic -/
open function tactic
structure my_equiv (α : Sort*) (β : Sort*) :=
(to_fun : α → β)
(inv_fun : β → α)
(left_inv : left_inverse inv_fun to_fun)
(right_inv : right_inverse inv_fun to_fun)
infix ` my≃ `:25 := my_equiv
protected def my_rfl {α} : α my≃ α :=
⟨id, λ x, x, λ x, rfl, λ x, rfl⟩
def eta_expansion_test : ℕ × ℕ := ((1,0).1,(1,0).2)
run_cmd do e ← get_env, x ← e.get `eta_expansion_test,
let v := (x.value.get_app_args).drop 2,
let nms := [`prod.fst, `prod.snd],
guard $ expr.is_eta_expansion_test (nms.zip v) = some `((1, 0))
def eta_expansion_test2 : ℕ my≃ ℕ :=
⟨my_rfl.to_fun, my_rfl.inv_fun, λ x, rfl, λ x, rfl⟩
run_cmd do e ← get_env, x ← e.get `eta_expansion_test2,
let v := (x.value.get_app_args).drop 2,
projs ← e.structure_fields_full `my_equiv,
b ← expr.is_eta_expansion_aux x.value (projs.zip v),
guard $ b = some `(@my_rfl ℕ)
run_cmd do e ← get_env, x1 ← e.get `eta_expansion_test, x2 ← e.get `eta_expansion_test2,
b1 ← expr.is_eta_expansion x1.value,
b2 ← expr.is_eta_expansion x2.value,
guard $ b1 = some `((1, 0)) ∧ b2 = some `(@my_rfl ℕ)
structure my_str (n : ℕ) := (x y : ℕ)
def dummy : my_str 3 := ⟨3, 1, 1⟩
def wrong_param : my_str 2 := ⟨2, dummy.1, dummy.2⟩
def right_param : my_str 3 := ⟨3, dummy.1, dummy.2⟩
run_cmd do e ← get_env,
x ← e.get `wrong_param, o ← x.value.is_eta_expansion,
guard o.is_none,
x ← e.get `right_param, o ← x.value.is_eta_expansion,
guard $ o = some `(dummy)
end is_eta_expansion
section elide
variables {x y z w : ℕ}
variables (h : x + y + z ≤ w)
(h' : x ≤ y + z + w)
include h h'
example : x + y + z ≤ w :=
begin
elide 0 at h,
elide 2 at h',
guard_hyp h := @hidden _ (x + y + z ≤ w),
guard_hyp h' := x ≤ @has_add.add (@hidden Type nat) (@hidden (has_add nat) nat.has_add)
(@hidden ℕ (y + z)) (@hidden ℕ w),
unelide at h,
unelide at h',
guard_hyp h' := x ≤ y + z + w,
exact h, -- there was a universe problem in `elide`. `exact h` lets the kernel check
-- the consistency of the universes
end
end elide
section struct_eq
@[ext]
structure foo (α : Type*) :=
(x y : ℕ)
(z : {z // z < x})
(k : α)
(h : x < y)
example {α : Type*} : Π (x y : foo α), x.x = y.x → x.y = y.y → x.z == y.z → x.k = y.k → x = y :=
foo.ext
example {α : Type*} : Π (x y : foo α), x = y ↔ x.x = y.x ∧ x.y = y.y ∧ x.z == y.z ∧ x.k = y.k :=
foo.ext_iff
example {α} (x y : foo α) (h : x = y) : y = x :=
begin
ext,
{ guard_target' y.x = x.x, rw h },
{ guard_target' y.y = x.y, rw h },
{ guard_target' y.z == x.z, rw h },
{ guard_target' y.k = x.k, rw h },
end
end struct_eq
section ring_exp
example (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) = (a^2 + 2 * a * b + b^2) * (a + b)^n := by ring_exp
end ring_exp
|
226af82ee33af2c8ab53900c285b9da3ee8de0cc | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/category_theory/preadditive/biproducts.lean | 431ef9e6be087163d52c3d1ddded0bb42d574985 | [
"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 | 11,601 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import tactic.abel
import category_theory.limits.shapes.biproducts
import category_theory.preadditive
/-!
# Basic facts about morphisms between biproducts in preadditive categories.
* In any category (with zero morphisms), if `biprod.map f g` is an isomorphism,
then both `f` and `g` are isomorphisms.
The remaining lemmas hold in any preadditive category.
* If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
* As a corollary of the previous two facts,
if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
we can construct an isomorphism `X₂ ≅ Y₂`.
* If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`,
or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero.
* If `f : ⨁ S ⟶ ⨁ T` is an isomorphism,
then every column (corresponding to a nonzero summand in the domain)
has some nonzero matrix entry.
-/
open category_theory
open category_theory.preadditive
open category_theory.limits
universes v u
namespace category_theory
variables {C : Type u} [category.{v} C]
section
variables [has_zero_morphisms.{v} C] [has_binary_biproducts.{v} C]
/--
If
```
(f 0)
(0 g)
```
is invertible, then `f` is invertible.
-/
def is_iso_left_of_is_iso_biprod_map
{W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [is_iso (biprod.map f g)] : is_iso f :=
{ inv := biprod.inl ≫ inv (biprod.map f g) ≫ biprod.fst,
hom_inv_id' :=
begin
have t := congr_arg (λ p : W ⊞ X ⟶ W ⊞ X, biprod.inl ≫ p ≫ biprod.fst)
(is_iso.hom_inv_id (biprod.map f g)),
simp only [category.id_comp, category.assoc, biprod.inl_map_assoc] at t,
simp [t],
end,
inv_hom_id' :=
begin
have t := congr_arg (λ p : Y ⊞ Z ⟶ Y ⊞ Z, biprod.inl ≫ p ≫ biprod.fst)
(is_iso.inv_hom_id (biprod.map f g)),
simp only [category.id_comp, category.assoc, biprod.map_fst] at t,
simp only [category.assoc],
simp [t],
end }
/--
If
```
(f 0)
(0 g)
```
is invertible, then `g` is invertible.
-/
def is_iso_right_of_is_iso_biprod_map
{W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [is_iso (biprod.map f g)] : is_iso g :=
begin
letI : is_iso (biprod.map g f) := by
{ rw [←biprod.braiding_map_braiding],
apply_instance, },
exact is_iso_left_of_is_iso_biprod_map g f,
end
end
section
variables [preadditive.{v} C] [has_binary_biproducts.{v} C]
variables {X₁ X₂ Y₁ Y₂ : C}
variables (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂)
/--
The "matrix" morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` with specified components.
-/
def biprod.of_components : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂ :=
biprod.fst ≫ f₁₁ ≫ biprod.inl +
biprod.fst ≫ f₁₂ ≫ biprod.inr +
biprod.snd ≫ f₂₁ ≫ biprod.inl +
biprod.snd ≫ f₂₂ ≫ biprod.inr
@[simp]
lemma biprod.inl_of_components :
biprod.inl ≫ biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂ =
f₁₁ ≫ biprod.inl + f₁₂ ≫ biprod.inr :=
by simp [biprod.of_components]
@[simp]
lemma biprod.inr_of_components :
biprod.inr ≫ biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂ =
f₂₁ ≫ biprod.inl + f₂₂ ≫ biprod.inr :=
by simp [biprod.of_components]
@[simp]
lemma biprod.of_components_fst :
biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.fst =
biprod.fst ≫ f₁₁ + biprod.snd ≫ f₂₁ :=
by simp [biprod.of_components]
@[simp]
lemma biprod.of_components_snd :
biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.snd =
biprod.fst ≫ f₁₂ + biprod.snd ≫ f₂₂ :=
by simp [biprod.of_components]
@[simp]
lemma biprod.of_components_eq (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) :
biprod.of_components (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd)
(biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd) = f :=
begin
ext; simp,
end
@[simp]
lemma biprod.of_components_comp {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C}
(f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂)
(g₁₁ : Y₁ ⟶ Z₁) (g₁₂ : Y₁ ⟶ Z₂) (g₂₁ : Y₂ ⟶ Z₁) (g₂₂ : Y₂ ⟶ Z₂) :
biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.of_components g₁₁ g₁₂ g₂₁ g₂₂ =
biprod.of_components
(f₁₁ ≫ g₁₁ + f₁₂ ≫ g₂₁) (f₁₁ ≫ g₁₂ + f₁₂ ≫ g₂₂)
(f₂₁ ≫ g₁₁ + f₂₂ ≫ g₂₁) (f₂₁ ≫ g₁₂ + f₂₂ ≫ g₂₂) :=
begin
dsimp [biprod.of_components],
apply biprod.hom_ext; apply biprod.hom_ext';
simp only [add_comp, comp_add, add_comp_assoc, add_zero, zero_add,
biprod.inl_fst, biprod.inl_snd, biprod.inr_fst, biprod.inr_snd,
biprod.inl_fst_assoc, biprod.inl_snd_assoc, biprod.inr_fst_assoc, biprod.inr_snd_assoc,
has_zero_morphisms.comp_zero, has_zero_morphisms.zero_comp, has_zero_morphisms.zero_comp_assoc,
category.comp_id, category.assoc],
end
/--
The unipotent upper triangular matrix
```
(1 r)
(0 1)
```
as an isomorphism.
-/
@[simps]
def biprod.unipotent_upper {X₁ X₂ : C} (r : X₁ ⟶ X₂) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ :=
{ hom := biprod.of_components (𝟙 _) r 0 (𝟙 _),
inv := biprod.of_components (𝟙 _) (-r) 0 (𝟙 _), }
/--
The unipotent lower triangular matrix
```
(1 0)
(r 1)
```
as an isomorphism.
-/
@[simps]
def biprod.unipotent_lower {X₁ X₂ : C} (r : X₂ ⟶ X₁) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ :=
{ hom := biprod.of_components (𝟙 _) 0 r (𝟙 _),
inv := biprod.of_components (𝟙 _) 0 (-r) (𝟙 _), }
/--
If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
(This is the version of `biprod.gaussian` written in terms of components.)
-/
def biprod.gaussian' [is_iso f₁₁] :
Σ' (L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂) (R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂) (g₂₂ : X₂ ⟶ Y₂),
L.hom ≫ (biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂) ≫ R.hom = biprod.map f₁₁ g₂₂ :=
⟨biprod.unipotent_lower (-(f₂₁ ≫ inv f₁₁)),
biprod.unipotent_upper (-(inv f₁₁ ≫ f₁₂)),
f₂₂ - f₂₁ ≫ (inv f₁₁) ≫ f₁₂,
by ext; simp; abel⟩
/--
If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂`
so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`),
via Gaussian elimination.
-/
def biprod.gaussian (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) [is_iso (biprod.inl ≫ f ≫ biprod.fst)] :
Σ' (L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂) (R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂) (g₂₂ : X₂ ⟶ Y₂),
L.hom ≫ f ≫ R.hom = biprod.map (biprod.inl ≫ f ≫ biprod.fst) g₂₂ :=
begin
let := biprod.gaussian'
(biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd)
(biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd),
simpa [biprod.of_components_eq],
end
/--
If `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` via a two-by-two matrix whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct an isomorphism `X₂ ≅ Y₂`, via Gaussian elimination.
-/
def biprod.iso_elim' [is_iso f₁₁] [is_iso (biprod.of_components f₁₁ f₁₂ f₂₁ f₂₂)] : X₂ ≅ Y₂ :=
begin
obtain ⟨L, R, g, w⟩ := biprod.gaussian' f₁₁ f₁₂ f₂₁ f₂₂,
letI : is_iso (biprod.map f₁₁ g) := by { rw ←w, apply_instance, },
letI : is_iso g := (is_iso_right_of_is_iso_biprod_map f₁₁ g),
exact as_iso g,
end
/--
If `f` is an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism,
then we can construct an isomorphism `X₂ ≅ Y₂`, via Gaussian elimination.
-/
def biprod.iso_elim (f : X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂) [is_iso (biprod.inl ≫ f.hom ≫ biprod.fst)] : X₂ ≅ Y₂ :=
begin
letI : is_iso (biprod.of_components
(biprod.inl ≫ f.hom ≫ biprod.fst)
(biprod.inl ≫ f.hom ≫ biprod.snd)
(biprod.inr ≫ f.hom ≫ biprod.fst)
(biprod.inr ≫ f.hom ≫ biprod.snd)) :=
by { simp only [biprod.of_components_eq], apply_instance, },
exact biprod.iso_elim'
(biprod.inl ≫ f.hom ≫ biprod.fst)
(biprod.inl ≫ f.hom ≫ biprod.snd)
(biprod.inr ≫ f.hom ≫ biprod.fst)
(biprod.inr ≫ f.hom ≫ biprod.snd)
end
lemma biprod.column_nonzero_of_iso {W X Y Z : C}
(f : W ⊞ X ⟶ Y ⊞ Z) [is_iso f] :
𝟙 W = 0 ∨ biprod.inl ≫ f ≫ biprod.fst ≠ 0 ∨ biprod.inl ≫ f ≫ biprod.snd ≠ 0 :=
begin
classical,
by_contradiction,
rw [not_or_distrib, not_or_distrib, classical.not_not, classical.not_not] at a,
rcases a with ⟨nz, a₁, a₂⟩,
set x := biprod.inl ≫ f ≫ inv f ≫ biprod.fst,
have h₁ : x = 𝟙 W, by simp [x],
have h₀ : x = 0,
{ dsimp [x],
rw [←category.id_comp (inv f), category.assoc, ←biprod.total],
conv_lhs { slice 2 3, rw [comp_add], },
simp only [category.assoc],
rw [comp_add_assoc, add_comp],
conv_lhs { congr, skip, slice 1 3, rw a₂, },
simp only [has_zero_morphisms.zero_comp, add_zero],
conv_lhs { slice 1 3, rw a₁, },
simp only [has_zero_morphisms.zero_comp], },
exact nz (h₁.symm.trans h₀),
end
end
variables [preadditive.{v} C]
lemma biproduct.column_nonzero_of_iso'
{σ τ : Type v} [decidable_eq σ] [decidable_eq τ] [fintype τ]
{S : σ → C} [has_biproduct.{v} S] {T : τ → C} [has_biproduct.{v} T]
(s : σ) (f : ⨁ S ⟶ ⨁ T) [is_iso f] :
(∀ t : τ, biproduct.ι S s ≫ f ≫ biproduct.π T t = 0) → 𝟙 (S s) = 0 :=
begin
intro z,
set x := biproduct.ι S s ≫ f ≫ inv f ≫ biproduct.π S s,
have h₁ : x = 𝟙 (S s), by simp [x],
have h₀ : x = 0,
{ dsimp [x],
rw [←category.id_comp (inv f), category.assoc, ←biproduct.total],
simp only [comp_sum_assoc],
conv_lhs { congr, apply_congr, skip, simp only [reassoc_of z], },
simp, },
exact h₁.symm.trans h₀,
end
/--
If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, and `s` is a non-trivial summand of the source,
then there is some `t` in the target so that the `s, t` matrix entry of `f` is nonzero.
-/
def biproduct.column_nonzero_of_iso
{σ τ : Type v} [decidable_eq σ] [decidable_eq τ] [fintype τ]
{S : σ → C} [has_biproduct.{v} S] {T : τ → C} [has_biproduct.{v} T]
(s : σ) (nz : 𝟙 (S s) ≠ 0)
[∀ t, decidable_eq (S s ⟶ T t)]
(f : ⨁ S ⟶ ⨁ T) [is_iso f] :
trunc (Σ' t : τ, biproduct.ι S s ≫ f ≫ biproduct.π T t ≠ 0) :=
begin
apply trunc_sigma_of_exists,
-- Do this before we run `classical`, so we get the right `decidable_eq` instances.
have t := biproduct.column_nonzero_of_iso'.{v} s f,
classical,
by_contradiction,
simp only [classical.not_exists_not] at a,
exact nz (t a)
end
end category_theory
|
30bf683f97aeef09f7e7ff7b57e5f016b9b28693 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/linear_algebra/basic.lean | 94c9ca5c8599084ad07b0a347f87eb63a2e830e4 | [
"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 | 84,479 | 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, Frédéric Dupuis,
Heather Macbeth
-/
import algebra.big_operators.pi
import algebra.module.hom
import algebra.module.prod
import algebra.module.submodule.lattice
import data.dfinsupp.basic
import data.finsupp.basic
import order.compactly_generated
/-!
# Linear algebra
This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of
modules over a ring, submodules, and linear maps.
Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in
`src/algebra/module`.
## Main definitions
* Many constructors for (semi)linear maps
* The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain
respectively.
* The general linear group is defined to be the group of invertible linear maps from `M` to itself.
See `linear_algebra.span` for the span of a set (as a submodule),
and `linear_algebra.quotient` for quotients by submodules.
## Main theorems
See `linear_algebra.isomorphisms` for Noether's three isomorphism theorems for modules.
## Notations
* We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear
(resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`).
## Implementation notes
We note that, when constructing linear maps, it is convenient to use operations defined on bundled
maps (`linear_map.prod`, `linear_map.coprod`, arithmetic operations like `+`) instead of defining a
function and proving it is linear.
## TODO
* Parts of this file have not yet been generalized to semilinear maps
## Tags
linear algebra, vector space, module
-/
open function
open_locale big_operators pointwise
variables {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} {R₄ : Type*}
variables {S : Type*}
variables {K : Type*} {K₂ : Type*}
variables {M : Type*} {M' : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*} {M₄ : Type*}
variables {N : Type*} {N₂ : Type*}
variables {ι : Type*}
variables {V : Type*} {V₂ : Type*}
namespace finsupp
lemma smul_sum {α : Type*} {β : Type*} {R : Type*} {M : Type*}
[has_zero β] [monoid R] [add_comm_monoid M] [distrib_mul_action R M]
{v : α →₀ β} {c : R} {h : α → β → M} :
c • (v.sum h) = v.sum (λa b, c • h a b) :=
finset.smul_sum
@[simp]
lemma sum_smul_index_linear_map' {α : Type*} {R : Type*} {M : Type*} {M₂ : Type*}
[semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂]
{v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} :
(c • v).sum (λ a, h a) = c • (v.sum (λ a, h a)) :=
begin
rw [finsupp.sum_smul_index', finsupp.smul_sum],
{ simp only [map_smul], },
{ intro i, exact (h i).map_zero },
end
variables (α : Type*) [fintype α]
variables (R M) [add_comm_monoid M] [semiring R] [module R M]
/-- Given `fintype α`, `linear_equiv_fun_on_fintype R` is the natural `R`-linear equivalence between
`α →₀ β` and `α → β`. -/
@[simps apply] noncomputable def linear_equiv_fun_on_fintype :
(α →₀ M) ≃ₗ[R] (α → M) :=
{ to_fun := coe_fn,
map_add' := λ f g, by { ext, refl },
map_smul' := λ c f, by { ext, refl },
.. equiv_fun_on_fintype }
@[simp] lemma linear_equiv_fun_on_fintype_single [decidable_eq α] (x : α) (m : M) :
(linear_equiv_fun_on_fintype R M α) (single x m) = pi.single x m :=
begin
ext a,
change (equiv_fun_on_fintype (single x m)) a = _,
convert _root_.congr_fun (equiv_fun_on_fintype_single x m) a,
end
@[simp] lemma linear_equiv_fun_on_fintype_symm_single [decidable_eq α]
(x : α) (m : M) : (linear_equiv_fun_on_fintype R M α).symm (pi.single x m) = single x m :=
begin
ext a,
change (equiv_fun_on_fintype.symm (pi.single x m)) a = _,
convert congr_fun (equiv_fun_on_fintype_symm_single x m) a,
end
@[simp] lemma linear_equiv_fun_on_fintype_symm_coe (f : α →₀ M) :
(linear_equiv_fun_on_fintype R M α).symm f = f :=
by { ext, simp [linear_equiv_fun_on_fintype], }
/-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is
`R`-linearly equivalent to `M`. -/
noncomputable def linear_equiv.finsupp_unique (α : Type*) [unique α] : (α →₀ M) ≃ₗ[R] M :=
{ map_add' := λ x y, rfl,
map_smul' := λ r x, rfl,
..finsupp.equiv_fun_on_fintype.trans (equiv.fun_unique α M) }
variables {R M α}
@[simp] lemma linear_equiv.finsupp_unique_apply (α : Type*) [unique α] (f : α →₀ M) :
linear_equiv.finsupp_unique R M α f = f default := rfl
@[simp] lemma linear_equiv.finsupp_unique_symm_apply {α : Type*} [unique α] (m : M) :
(linear_equiv.finsupp_unique R M α).symm m = finsupp.single default m :=
by ext; simp [linear_equiv.finsupp_unique]
end finsupp
/-- decomposing `x : ι → R` as a sum along the canonical basis -/
lemma pi_eq_sum_univ {ι : Type*} [fintype ι] [decidable_eq ι] {R : Type*} [semiring R] (x : ι → R) :
x = ∑ i, x i • (λj, if i = j then 1 else 0) :=
by { ext, simp }
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂]
variables [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [module R M] [module R M₁] [module R₂ M₂] [module R₃ M₃] [module R₄ M₄]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₃₄ : R₃ →+* R₄}
variables {σ₁₃ : R →+* R₃} {σ₂₄ : R₂ →+* R₄} {σ₁₄ : R →+* R₄}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃] [ring_hom_comp_triple σ₂₃ σ₃₄ σ₂₄]
variables [ring_hom_comp_triple σ₁₃ σ₃₄ σ₁₄] [ring_hom_comp_triple σ₁₂ σ₂₄ σ₁₄]
variables (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
include R R₂
theorem comp_assoc (h : M₃ →ₛₗ[σ₃₄] M₄) :
((h.comp g : M₂ →ₛₗ[σ₂₄] M₄).comp f : M →ₛₗ[σ₁₄] M₄)
= h.comp (g.comp f : M →ₛₗ[σ₁₃] M₃) := rfl
omit R R₂
/-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map
`p → M₂`. -/
def dom_restrict (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) : p →ₛₗ[σ₁₂] M₂ := f.comp p.subtype
@[simp] lemma dom_restrict_apply (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) (x : p) :
f.dom_restrict p x = f x := rfl
/-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a
linear map M₂ → p. -/
def cod_restrict (p : submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) (h : ∀c, f c ∈ p) : M →ₛₗ[σ₁₂] p :=
by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp
@[simp] theorem cod_restrict_apply (p : submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) {h} (x : M) :
(cod_restrict p f h x : M₂) = f x := rfl
@[simp] lemma comp_cod_restrict (p : submodule R₃ M₃) (h : ∀b, g b ∈ p) :
((cod_restrict p g h).comp f : M →ₛₗ[σ₁₃] p) = cod_restrict p (g.comp f) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (p : submodule R₂ M₂) (h : ∀b, f b ∈ p) :
p.subtype.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- Restrict domain and codomain of an endomorphism. -/
def restrict (f : M →ₗ[R] M) {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : p →ₗ[R] p :=
(f.dom_restrict p).cod_restrict p $ set_like.forall.2 hf
lemma restrict_apply
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) (x : p) :
f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl
lemma subtype_comp_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
p.subtype.comp (f.restrict hf) = f.dom_restrict p := rfl
lemma restrict_eq_cod_restrict_dom_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) :
f.restrict hf = (f.dom_restrict p).cod_restrict p (λ x, hf x.1 x.2) := rfl
lemma restrict_eq_dom_restrict_cod_restrict
{f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x, f x ∈ p) :
f.restrict (λ x _, hf x) = (f.cod_restrict p hf).dom_restrict p := rfl
instance unique_of_left [subsingleton M] : unique (M →ₛₗ[σ₁₂] M₂) :=
{ uniq := λ f, ext $ λ x, by rw [subsingleton.elim x 0, map_zero, map_zero],
.. linear_map.inhabited }
instance unique_of_right [subsingleton M₂] : unique (M →ₛₗ[σ₁₂] M₂) :=
coe_injective.unique
/-- Evaluation of a `σ₁₂`-linear map at a fixed `a`, as an `add_monoid_hom`. -/
def eval_add_monoid_hom (a : M) : (M →ₛₗ[σ₁₂] M₂) →+ M₂ :=
{ to_fun := λ f, f a,
map_add' := λ f g, linear_map.add_apply f g a,
map_zero' := rfl }
/-- `linear_map.to_add_monoid_hom` promoted to an `add_monoid_hom` -/
def to_add_monoid_hom' : (M →ₛₗ[σ₁₂] M₂) →+ (M →+ M₂) :=
{ to_fun := to_add_monoid_hom,
map_zero' := by ext; refl,
map_add' := by intros; ext; refl }
lemma sum_apply (t : finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) (b : M) :
(∑ d in t, f d) b = ∑ d in t, f d b :=
add_monoid_hom.map_sum ((add_monoid_hom.eval b).comp to_add_monoid_hom') f _
section smul_right
variables [semiring S] [module R S] [module S M] [is_scalar_tower R S M]
/-- When `f` is an `R`-linear map taking values in `S`, then `λb, f b • x` is an `R`-linear map. -/
def smul_right (f : M₁ →ₗ[R] S) (x : M) : M₁ →ₗ[R] M :=
{ to_fun := λb, f b • x,
map_add' := λ x y, by rw [f.map_add, add_smul],
map_smul' := λ b y, by dsimp; rw [map_smul, smul_assoc] }
@[simp] theorem coe_smul_right (f : M₁ →ₗ[R] S) (x : M) :
(smul_right f x : M₁ → M) = λ c, f c • x := rfl
theorem smul_right_apply (f : M₁ →ₗ[R] S) (x : M) (c : M₁) :
smul_right f x c = f c • x := rfl
end smul_right
instance [nontrivial M] : nontrivial (module.End R M) :=
begin
obtain ⟨m, ne⟩ := (nontrivial_iff_exists_ne (0 : M)).mp infer_instance,
exact nontrivial_of_ne 1 0 (λ p, ne (linear_map.congr_fun p m)),
end
@[simp, norm_cast] lemma coe_fn_sum {ι : Type*} (t : finset ι) (f : ι → M →ₛₗ[σ₁₂] M₂) :
⇑(∑ i in t, f i) = ∑ i in t, (f i : M → M₂) :=
add_monoid_hom.map_sum ⟨@to_fun R R₂ _ _ σ₁₂ M M₂ _ _ _ _, rfl, λ x y, rfl⟩ _ _
@[simp] lemma pow_apply (f : M →ₗ[R] M) (n : ℕ) (m : M) :
(f^n) m = (f^[n] m) :=
begin
induction n with n ih,
{ refl, },
{ simp only [function.comp_app, function.iterate_succ, linear_map.mul_apply, pow_succ, ih],
exact (function.commute.iterate_self _ _ m).symm, },
end
lemma pow_map_zero_of_le
{f : module.End R M} {m : M} {k l : ℕ} (hk : k ≤ l) (hm : (f^k) m = 0) : (f^l) m = 0 :=
by rw [← tsub_add_cancel_of_le hk, pow_add, mul_apply, hm, map_zero]
lemma commute_pow_left_of_commute
{f : M →ₛₗ[σ₁₂] M₂} {g : module.End R M} {g₂ : module.End R₂ M₂}
(h : g₂.comp f = f.comp g) (k : ℕ) : (g₂^k).comp f = f.comp (g^k) :=
begin
induction k with k ih,
{ simpa only [pow_zero], },
{ rw [pow_succ, pow_succ, linear_map.mul_eq_comp, linear_map.comp_assoc, ih,
← linear_map.comp_assoc, h, linear_map.comp_assoc, linear_map.mul_eq_comp], },
end
lemma submodule_pow_eq_zero_of_pow_eq_zero {N : submodule R M}
{g : module.End R N} {G : module.End R M} (h : G.comp N.subtype = N.subtype.comp g)
{k : ℕ} (hG : G^k = 0) : g^k = 0 :=
begin
ext m,
have hg : N.subtype.comp (g^k) m = 0,
{ rw [← commute_pow_left_of_commute h, hG, zero_comp, zero_apply], },
simp only [submodule.subtype_apply, comp_app, submodule.coe_eq_zero, coe_comp] at hg,
rw [hg, linear_map.zero_apply],
end
lemma coe_pow (f : M →ₗ[R] M) (n : ℕ) : ⇑(f^n) = (f^[n]) :=
by { ext m, apply pow_apply, }
@[simp] lemma id_pow (n : ℕ) : (id : M →ₗ[R] M)^n = id := one_pow n
section
variables {f' : M →ₗ[R] M}
lemma iterate_succ (n : ℕ) : (f' ^ (n + 1)) = comp (f' ^ n) f' :=
by rw [pow_succ', mul_eq_comp]
lemma iterate_surjective (h : surjective f') : ∀ n : ℕ, surjective ⇑(f' ^ n)
| 0 := surjective_id
| (n + 1) := by { rw [iterate_succ], exact surjective.comp (iterate_surjective n) h, }
lemma iterate_injective (h : injective f') : ∀ n : ℕ, injective ⇑(f' ^ n)
| 0 := injective_id
| (n + 1) := by { rw [iterate_succ], exact injective.comp (iterate_injective n) h, }
lemma iterate_bijective (h : bijective f') : ∀ n : ℕ, bijective ⇑(f' ^ n)
| 0 := bijective_id
| (n + 1) := by { rw [iterate_succ], exact bijective.comp (iterate_bijective n) h, }
lemma injective_of_iterate_injective {n : ℕ} (hn : n ≠ 0) (h : injective ⇑(f' ^ n)) :
injective f' :=
begin
rw [← nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr hn), iterate_succ, coe_comp] at h,
exact injective.of_comp h,
end
lemma surjective_of_iterate_surjective {n : ℕ} (hn : n ≠ 0) (h : surjective ⇑(f' ^ n)) :
surjective f' :=
begin
rw [← nat.succ_pred_eq_of_pos (pos_iff_ne_zero.mpr hn),
nat.succ_eq_add_one, add_comm, pow_add] at h,
exact surjective.of_comp h,
end
lemma pow_apply_mem_of_forall_mem {p : submodule R M}
(n : ℕ) (h : ∀ x ∈ p, f' x ∈ p) (x : M) (hx : x ∈ p) :
(f'^n) x ∈ p :=
begin
induction n with n ih generalizing x, { simpa, },
simpa only [iterate_succ, coe_comp, function.comp_app, restrict_apply] using ih _ (h _ hx),
end
lemma pow_restrict {p : submodule R M} (n : ℕ)
(h : ∀ x ∈ p, f' x ∈ p) (h' := pow_apply_mem_of_forall_mem n h) :
(f'.restrict h)^n = (f'^n).restrict h' :=
begin
induction n with n ih;
ext,
{ simp [restrict_apply], },
{ simp [restrict_apply, linear_map.iterate_succ, -linear_map.pow_apply, ih], },
end
end
/-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements
of the canonical basis. -/
lemma pi_apply_eq_sum_univ [fintype ι] [decidable_eq ι] (f : (ι → R) →ₗ[R] M) (x : ι → R) :
f x = ∑ i, x i • (f (λj, if i = j then 1 else 0)) :=
begin
conv_lhs { rw [pi_eq_sum_univ x, f.map_sum] },
apply finset.sum_congr rfl (λl hl, _),
rw map_smul
end
end add_comm_monoid
section module
variables [semiring R] [semiring S]
[add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
[module R M] [module R M₂] [module R M₃]
[module S M₂] [module S M₃] [smul_comm_class R S M₂] [smul_comm_class R S M₃]
(f : M →ₗ[R] M₂)
variable (S)
/-- Applying a linear map at `v : M`, seen as `S`-linear map from `M →ₗ[R] M₂` to `M₂`.
See `linear_map.applyₗ` for a version where `S = R`. -/
@[simps]
def applyₗ' : M →+ (M →ₗ[R] M₂) →ₗ[S] M₂ :=
{ to_fun := λ v,
{ to_fun := λ f, f v,
map_add' := λ f g, f.add_apply g v,
map_smul' := λ x f, f.smul_apply x v },
map_zero' := linear_map.ext $ λ f, f.map_zero,
map_add' := λ x y, linear_map.ext $ λ f, f.map_add _ _ }
section
variables (R M)
/--
The equivalence between R-linear maps from `R` to `M`, and points of `M` itself.
This says that the forgetful functor from `R`-modules to types is representable, by `R`.
This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`.
When `R` is commutative, we can take this to be the usual action with `S = R`.
Otherwise, `S = ℕ` shows that the equivalence is additive.
See note [bundled maps over different rings].
-/
@[simps]
def ring_lmap_equiv_self [module S M] [smul_comm_class R S M] : (R →ₗ[R] M) ≃ₗ[S] M :=
{ to_fun := λ f, f 1,
inv_fun := smul_right (1 : R →ₗ[R] R),
left_inv := λ f, by { ext, simp },
right_inv := λ x, by simp,
.. applyₗ' S (1 : R) }
end
end module
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (f g : M →ₗ[R] M₂)
include R
/-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂`
to the space of linear maps `M₂ → M₃`. -/
def comp_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) :=
{ to_fun := f.comp,
map_add' := λ _ _, linear_map.ext $ λ _, map_add f _ _,
map_smul' := λ _ _, linear_map.ext $ λ _, map_smul f _ _ }
@[simp]
lemma comp_right_apply (f : M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂) :
comp_right f g = f.comp g := rfl
/-- Applying a linear map at `v : M`, seen as a linear map from `M →ₗ[R] M₂` to `M₂`.
See also `linear_map.applyₗ'` for a version that works with two different semirings.
This is the `linear_map` version of `add_monoid_hom.eval`. -/
@[simps]
def applyₗ : M →ₗ[R] (M →ₗ[R] M₂) →ₗ[R] M₂ :=
{ to_fun := λ v, { to_fun := λ f, f v, ..applyₗ' R v },
map_smul' := λ x y, linear_map.ext $ λ f, map_smul f _ _,
..applyₗ' R }
/-- Alternative version of `dom_restrict` as a linear map. -/
def dom_restrict'
(p : submodule R M) : (M →ₗ[R] M₂) →ₗ[R] (p →ₗ[R] M₂) :=
{ to_fun := λ φ, φ.dom_restrict p,
map_add' := by simp [linear_map.ext_iff],
map_smul' := by simp [linear_map.ext_iff] }
@[simp] lemma dom_restrict'_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) :
dom_restrict' p f x = f x := rfl
/--
The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`.
-/
def smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M :=
{ to_fun := λ f,
{ to_fun := linear_map.smul_right f,
map_add' := λ m m', by { ext, apply smul_add, },
map_smul' := λ c m, by { ext, apply smul_comm, } },
map_add' := λ f f', by { ext, apply add_smul, },
map_smul' := λ c f, by { ext, apply mul_smul, } }
@[simp] lemma smul_rightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
(smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M) f x c = (f c) • x := rfl
end comm_semiring
end linear_map
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℕ`-linear morphisms `A →ₗ[ℕ] B`.
-/
@[simps]
def add_monoid_hom_lequiv_nat {A B : Type*} (R : Type*)
[semiring R] [add_comm_monoid A] [add_comm_monoid B] [module R B] :
(A →+ B) ≃ₗ[R] (A →ₗ[ℕ] B) :=
{ to_fun := add_monoid_hom.to_nat_linear_map,
inv_fun := linear_map.to_add_monoid_hom,
map_add' := by { intros, ext, refl },
map_smul' := by { intros, ext, refl },
left_inv := by { intros f, ext, refl },
right_inv := by { intros f, ext, refl } }
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℤ`-linear morphisms `A →ₗ[ℤ] B`.
-/
@[simps]
def add_monoid_hom_lequiv_int {A B : Type*} (R : Type*)
[semiring R] [add_comm_group A] [add_comm_group B] [module R B] :
(A →+ B) ≃ₗ[R] (A →ₗ[ℤ] B) :=
{ to_fun := add_monoid_hom.to_int_linear_map,
inv_fun := linear_map.to_add_monoid_hom,
map_add' := by { intros, ext, refl },
map_smul' := by { intros, ext, refl },
left_inv := by { intros f, ext, refl },
right_inv := by { intros f, ext, refl } }
/-! ### Properties of submodules -/
namespace submodule
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M']
variables [module R M] [module R M'] [module R₂ M₂] [module R₃ M₃]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variables {σ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables (p p' : submodule R M) (q q' : submodule R₂ M₂)
variables (q₁ q₁' : submodule R M')
variables {r : R} {x y : M}
open set
variables {p p'}
/-- If two submodules `p` and `p'` satisfy `p ⊆ p'`, then `of_le p p'` is the linear map version of
this inclusion. -/
def of_le (h : p ≤ p') : p →ₗ[R] p' :=
p.subtype.cod_restrict p' $ λ ⟨x, hx⟩, h hx
@[simp] theorem coe_of_le (h : p ≤ p') (x : p) :
(of_le h x : M) = x := rfl
theorem of_le_apply (h : p ≤ p') (x : p) : of_le h x = ⟨x, h x.2⟩ := rfl
theorem of_le_injective (h : p ≤ p') : function.injective (of_le h) :=
λ x y h, subtype.val_injective (subtype.mk.inj h)
variables (p p')
lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) :
q.subtype.comp (of_le h) = p.subtype :=
by { ext ⟨b, hb⟩, refl }
variables (R)
@[simp] lemma subsingleton_iff : subsingleton (submodule R M) ↔ subsingleton M :=
have h : subsingleton (submodule R M) ↔ subsingleton (add_submonoid M),
{ rw [←subsingleton_iff_bot_eq_top, ←subsingleton_iff_bot_eq_top],
convert to_add_submonoid_eq.symm; refl, },
h.trans add_submonoid.subsingleton_iff
@[simp] lemma nontrivial_iff : nontrivial (submodule R M) ↔ nontrivial M :=
not_iff_not.mp (
(not_nontrivial_iff_subsingleton.trans $ subsingleton_iff R).trans
not_nontrivial_iff_subsingleton.symm)
variables {R}
instance [subsingleton M] : unique (submodule R M) :=
⟨⟨⊥⟩, λ a, @subsingleton.elim _ ((subsingleton_iff R).mpr ‹_›) a _⟩
instance unique' [subsingleton R] : unique (submodule R M) :=
by haveI := module.subsingleton R M; apply_instance
instance [nontrivial M] : nontrivial (submodule R M) := (nontrivial_iff R).mpr ‹_›
theorem mem_right_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p} :
(x:M) ∈ p' ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x x.2 hx, λ h, h.symm ▸ p'.zero_mem⟩
theorem mem_left_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p'} :
(x:M) ∈ p ↔ x = 0 :=
⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x hx x.2, λ h, h.symm ▸ p.zero_mem⟩
section
variables [ring_hom_surjective σ₁₂]
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) : submodule R₂ M₂ :=
{ carrier := f '' p,
smul_mem' :=
begin
rintro c x ⟨y, hy, rfl⟩,
obtain ⟨a, rfl⟩ := σ₁₂.is_surjective c,
exact ⟨_, p.smul_mem a hy, map_smulₛₗ f _ _⟩,
end,
.. p.to_add_submonoid.map f.to_add_monoid_hom }
@[simp] lemma map_coe (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(map f p : set M₂) = f '' p := rfl
lemma map_to_add_submonoid (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(p.map f).to_add_submonoid = p.to_add_submonoid.map (f : M →+ M₂) :=
set_like.coe_injective rfl
lemma map_to_add_submonoid' (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
(p.map f).to_add_submonoid = p.to_add_submonoid.map f :=
set_like.coe_injective rfl
@[simp] lemma mem_map {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {x : M₂} :
x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl
theorem mem_map_of_mem {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {r} (h : r ∈ p) :
f r ∈ map f p := set.mem_image_of_mem _ h
lemma apply_coe_mem_map (f : M →ₛₗ[σ₁₂] M₂) {p : submodule R M} (r : p) :
f r ∈ map f p := mem_map_of_mem r.prop
@[simp] lemma map_id : map (linear_map.id : M →ₗ[R] M) p = p :=
submodule.ext $ λ a, by simp
lemma map_comp [ring_hom_surjective σ₂₃] [ring_hom_surjective σ₁₃]
(f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
(p : submodule R M) : map (g.comp f : M →ₛₗ[σ₁₃] M₃) p = map g (map f p) :=
set_like.coe_injective $ by simp [map_coe]; rw ← image_comp
lemma map_mono {f : M →ₛₗ[σ₁₂] M₂} {p p' : submodule R M} :
p ≤ p' → map f p ≤ map f p' := image_subset _
@[simp] lemma map_zero : map (0 : M →ₛₗ[σ₁₂] M₂) p = ⊥ :=
have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩,
ext $ by simp [this, eq_comm]
lemma map_add_le (f g : M →ₛₗ[σ₁₂] M₂) : map (f + g) p ≤ map f p ⊔ map g p :=
begin
rintros x ⟨m, hm, rfl⟩,
exact add_mem_sup (mem_map_of_mem hm) (mem_map_of_mem hm),
end
lemma range_map_nonempty (N : submodule R M) :
(set.range (λ ϕ, submodule.map ϕ N : (M →ₛₗ[σ₁₂] M₂) → submodule R₂ M₂)).nonempty :=
⟨_, set.mem_range.mpr ⟨0, rfl⟩⟩
end
include σ₂₁
/-- The pushforward of a submodule by an injective linear map is
linearly equivalent to the original submodule. See also `linear_equiv.submodule_map` for a
computable version when `f` has an explicit inverse. -/
noncomputable def equiv_map_of_injective (f : M →ₛₗ[σ₁₂] M₂) (i : injective f)
(p : submodule R M) : p ≃ₛₗ[σ₁₂] p.map f :=
{ map_add' := by { intros, simp, refl },
map_smul' := by { intros, simp, refl },
..(equiv.set.image f p i) }
@[simp] lemma coe_equiv_map_of_injective_apply (f : M →ₛₗ[σ₁₂] M₂) (i : injective f)
(p : submodule R M) (x : p) :
(equiv_map_of_injective f i p x : M₂) = f x := rfl
omit σ₂₁
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R₂ M₂) : submodule R M :=
{ carrier := f ⁻¹' p,
smul_mem' := λ a x h, by simp [p.smul_mem _ h],
.. p.to_add_submonoid.comap f.to_add_monoid_hom }
@[simp] lemma comap_coe (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R₂ M₂) :
(comap f p : set M) = f ⁻¹' p := rfl
@[simp] lemma mem_comap {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R₂ M₂} :
x ∈ comap f p ↔ f x ∈ p := iff.rfl
@[simp] lemma comap_id : comap linear_map.id p = p :=
set_like.coe_injective rfl
lemma comap_comp (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
(p : submodule R₃ M₃) : comap (g.comp f : M →ₛₗ[σ₁₃] M₃) p = comap f (comap g p) :=
rfl
lemma comap_mono {f : M →ₛₗ[σ₁₂] M₂} {q q' : submodule R₂ M₂} :
q ≤ q' → comap f q ≤ comap f q' := preimage_mono
lemma le_comap_pow_of_le_comap (p : submodule R M) {f : M →ₗ[R] M} (h : p ≤ p.comap f) (k : ℕ) :
p ≤ p.comap (f^k) :=
begin
induction k with k ih,
{ simp [linear_map.one_eq_id], },
{ simp [linear_map.iterate_succ, comap_comp, h.trans (comap_mono ih)], },
end
section
variables [ring_hom_surjective σ₁₂]
lemma map_le_iff_le_comap {f : M →ₛₗ[σ₁₂] M₂} {p : submodule R M} {q : submodule R₂ M₂} :
map f p ≤ q ↔ p ≤ comap f q := image_subset_iff
lemma gc_map_comap (f : M →ₛₗ[σ₁₂] M₂) : galois_connection (map f) (comap f)
| p q := map_le_iff_le_comap
@[simp] lemma map_bot (f : M →ₛₗ[σ₁₂] M₂) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma map_sup (f : M →ₛₗ[σ₁₂] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f).l_sup
@[simp] lemma map_supr {ι : Sort*} (f : M →ₛₗ[σ₁₂] M₂) (p : ι → submodule R M) :
map f (⨆i, p i) = (⨆i, map f (p i)) :=
(gc_map_comap f).l_supr
end
@[simp] lemma comap_top (f : M →ₛₗ[σ₁₂] M₂) : comap f ⊤ = ⊤ := rfl
@[simp] lemma comap_inf (f : M →ₛₗ[σ₁₂] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl
@[simp] lemma comap_infi [ring_hom_surjective σ₁₂] {ι : Sort*} (f : M →ₛₗ[σ₁₂] M₂)
(p : ι → submodule R₂ M₂) :
comap f (⨅i, p i) = (⨅i, comap f (p i)) :=
(gc_map_comap f).u_infi
@[simp] lemma comap_zero : comap (0 : M →ₛₗ[σ₁₂] M₂) q = ⊤ :=
ext $ by simp
lemma map_comap_le [ring_hom_surjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) (q : submodule R₂ M₂) :
map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
lemma le_comap_map [ring_hom_surjective σ₁₂] (f : M →ₛₗ[σ₁₂] M₂) (p : submodule R M) :
p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
section galois_insertion
variables {f : M →ₛₗ[σ₁₂] M₂} (hf : surjective f)
variables [ring_hom_surjective σ₁₂]
include hf
/-- `map f` and `comap f` form a `galois_insertion` when `f` is surjective. -/
def gi_map_comap : galois_insertion (map f) (comap f) :=
(gc_map_comap f).to_galois_insertion
(λ S x hx, begin
rcases hf x with ⟨y, rfl⟩,
simp only [mem_map, mem_comap],
exact ⟨y, hx, rfl⟩
end)
lemma map_comap_eq_of_surjective (p : submodule R₂ M₂) : (p.comap f).map f = p :=
(gi_map_comap hf).l_u_eq _
lemma map_surjective_of_surjective : function.surjective (map f) :=
(gi_map_comap hf).l_surjective
lemma comap_injective_of_surjective : function.injective (comap f) :=
(gi_map_comap hf).u_injective
lemma map_sup_comap_of_surjective (p q : submodule R₂ M₂) :
(p.comap f ⊔ q.comap f).map f = p ⊔ q :=
(gi_map_comap hf).l_sup_u _ _
lemma map_supr_comap_of_sujective {ι : Sort*} (S : ι → submodule R₂ M₂) :
(⨆ i, (S i).comap f).map f = supr S :=
(gi_map_comap hf).l_supr_u _
lemma map_inf_comap_of_surjective (p q : submodule R₂ M₂) :
(p.comap f ⊓ q.comap f).map f = p ⊓ q :=
(gi_map_comap hf).l_inf_u _ _
lemma map_infi_comap_of_surjective {ι : Sort*} (S : ι → submodule R₂ M₂) :
(⨅ i, (S i).comap f).map f = infi S :=
(gi_map_comap hf).l_infi_u _
lemma comap_le_comap_iff_of_surjective (p q : submodule R₂ M₂) :
p.comap f ≤ q.comap f ↔ p ≤ q :=
(gi_map_comap hf).u_le_u_iff
lemma comap_strict_mono_of_surjective : strict_mono (comap f) :=
(gi_map_comap hf).strict_mono_u
end galois_insertion
section galois_coinsertion
variables [ring_hom_surjective σ₁₂] {f : M →ₛₗ[σ₁₂] M₂} (hf : injective f)
include hf
/-- `map f` and `comap f` form a `galois_coinsertion` when `f` is injective. -/
def gci_map_comap : galois_coinsertion (map f) (comap f) :=
(gc_map_comap f).to_galois_coinsertion
(λ S x, by simp [mem_comap, mem_map, hf.eq_iff])
lemma comap_map_eq_of_injective (p : submodule R M) : (p.map f).comap f = p :=
(gci_map_comap hf).u_l_eq _
lemma comap_surjective_of_injective : function.surjective (comap f) :=
(gci_map_comap hf).u_surjective
lemma map_injective_of_injective : function.injective (map f) :=
(gci_map_comap hf).l_injective
lemma comap_inf_map_of_injective (p q : submodule R M) : (p.map f ⊓ q.map f).comap f = p ⊓ q :=
(gci_map_comap hf).u_inf_l _ _
lemma comap_infi_map_of_injective {ι : Sort*} (S : ι → submodule R M) :
(⨅ i, (S i).map f).comap f = infi S :=
(gci_map_comap hf).u_infi_l _
lemma comap_sup_map_of_injective (p q : submodule R M) : (p.map f ⊔ q.map f).comap f = p ⊔ q :=
(gci_map_comap hf).u_sup_l _ _
lemma comap_supr_map_of_injective {ι : Sort*} (S : ι → submodule R M) :
(⨆ i, (S i).map f).comap f = supr S :=
(gci_map_comap hf).u_supr_l _
lemma map_le_map_iff_of_injective (p q : submodule R M) : p.map f ≤ q.map f ↔ p ≤ q :=
(gci_map_comap hf).l_le_l_iff
lemma map_strict_mono_of_injective : strict_mono (map f) :=
(gci_map_comap hf).strict_mono_l
end galois_coinsertion
--TODO(Mario): is there a way to prove this from order properties?
lemma map_inf_eq_map_inf_comap [ring_hom_surjective σ₁₂] {f : M →ₛₗ[σ₁₂] M₂}
{p : submodule R M} {p' : submodule R₂ M₂} :
map f p ⊓ p' = map f (p ⊓ comap f p') :=
le_antisymm
(by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩)
(le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right))
lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' :=
ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩
lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0
| ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb
/-- The infimum of a family of invariant submodule of an endomorphism is also an invariant
submodule. -/
lemma _root_.linear_map.infi_invariant {σ : R →+* R} [ring_hom_surjective σ] {ι : Sort*}
(f : M →ₛₗ[σ] M) {p : ι → submodule R M} (hf : ∀ i, ∀ v ∈ (p i), f v ∈ p i) :
∀ v ∈ infi p, f v ∈ infi p :=
begin
have : ∀ i, (p i).map f ≤ p i,
{ rintros i - ⟨v, hv, rfl⟩,
exact hf i v hv },
suffices : (infi p).map f ≤ infi p,
{ exact λ v hv, this ⟨v, hv, rfl⟩, },
exact le_infi (λ i, (submodule.map_mono (infi_le p i)).trans (this i)),
end
end add_comm_monoid
section add_comm_group
variables [ring R] [add_comm_group M] [module R M] (p : submodule R M)
variables [add_comm_group M₂] [module R M₂]
@[simp] lemma neg_coe : -(p : set M) = p := set.ext $ λ x, p.neg_mem_iff
@[simp] protected lemma map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p :=
ext $ λ y, ⟨λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, show -x ∈ p, from neg_mem hx, map_neg f x⟩,
λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, show -x ∈ p, from neg_mem hx, (map_neg (-f) _).trans (neg_neg (f x))⟩⟩
end add_comm_group
end submodule
namespace submodule
variables [field K]
variables [add_comm_group V] [module K V]
variables [add_comm_group V₂] [module K V₂]
lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) :
p.comap (a • f) = p.comap f :=
by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply]
lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) :
p.map (a • f) = p.map f :=
le_antisymm
begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_rfl end
begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_rfl end
lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) :
p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) :=
by classical; by_cases a = 0; simp [h, comap_smul]
lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) :
p.map (a • f) = (⨆ h : a ≠ 0, p.map f) :=
by classical; by_cases a = 0; simp [h, map_smul]
end submodule
/-! ### Properties of linear maps -/
namespace linear_map
section add_comm_monoid
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
include R
open submodule
section finsupp
variables {γ : Type*} [has_zero γ]
@[simp] lemma map_finsupp_sum (f : M →ₛₗ[σ₁₂] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum
lemma coe_finsupp_sum (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _
@[simp] lemma finsupp_sum_apply (t : ι →₀ γ) (g : ι → γ → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _
end finsupp
section dfinsupp
open dfinsupp
variables {γ : ι → Type*} [decidable_eq ι]
section sum
variables [Π i, has_zero (γ i)] [Π i (x : γ i), decidable (x ≠ 0)]
@[simp] lemma map_dfinsupp_sum (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : Π i, γ i → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum
lemma coe_dfinsupp_sum (t : Π₀ i, γ i) (g : Π i, γ i → M →ₛₗ[σ₁₂] M₂) :
⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _
@[simp] lemma dfinsupp_sum_apply (t : Π₀ i, γ i) (g : Π i, γ i → M →ₛₗ[σ₁₂] M₂) (b : M) :
(t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _
end sum
section sum_add_hom
variables [Π i, add_zero_class (γ i)]
@[simp] lemma map_dfinsupp_sum_add_hom (f : M →ₛₗ[σ₁₂] M₂) {t : Π₀ i, γ i} {g : Π i, γ i →+ M} :
f (sum_add_hom g t) = sum_add_hom (λ i, f.to_add_monoid_hom.comp (g i)) t :=
f.to_add_monoid_hom.map_dfinsupp_sum_add_hom _ _
end sum_add_hom
end dfinsupp
variables {σ₂₁ : R₂ →+* R} {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
theorem map_cod_restrict [ring_hom_surjective σ₂₁] (p : submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (h p') :
submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) :=
submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.ext_iff_val]
theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₛₗ[σ₂₁] M) (hf p') :
submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') :=
submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩
section
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`.
See Note [range copy pattern]. -/
def range [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : submodule R₂ M₂ :=
(map f ⊤).copy (set.range f) set.image_univ.symm
theorem range_coe [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(range f : set M₂) = set.range f := rfl
lemma range_to_add_submonoid [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.to_add_submonoid = f.to_add_monoid_hom.mrange := rfl
@[simp] theorem mem_range [ring_hom_surjective τ₁₂]
{f : M →ₛₗ[τ₁₂] M₂} {x} : x ∈ range f ↔ ∃ y, f y = x :=
iff.rfl
lemma range_eq_map [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) : f.range = map f ⊤ :=
by { ext, simp }
theorem mem_range_self [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) (x : M) : f x ∈ f.range := ⟨x, rfl⟩
@[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ :=
set_like.coe_injective set.range_id
theorem range_comp [ring_hom_surjective τ₁₂] [ring_hom_surjective τ₂₃] [ring_hom_surjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) :=
set_like.coe_injective (set.range_comp g f)
theorem range_comp_le_range [ring_hom_surjective τ₂₃] [ring_hom_surjective τ₁₃]
(f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g :=
set_like.coe_mono (set.range_comp_subset_range f g)
theorem range_eq_top [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} :
range f = ⊤ ↔ surjective f :=
by rw [set_like.ext'_iff, range_coe, top_coe, set.range_iff_surjective]
lemma range_le_iff_comap [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R₂ M₂} :
range f ≤ p ↔ comap f p = ⊤ :=
by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
map f p ≤ range f :=
set_like.coe_mono (set.image_subset_range f p)
@[simp] lemma range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*}
[semiring R] [ring R₂] [add_comm_monoid M] [add_comm_group M₂] [module R M] [module R₂ M₂]
{τ₁₂ : R →+* R₂} [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
(-f).range = f.range :=
begin
change ((-linear_map.id : M₂ →ₗ[R₂] M₂).comp f).range = _,
rw [range_comp, submodule.map_neg, submodule.map_id],
end
end
/--
The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map.
-/
@[simps]
def iterate_range (f : M →ₗ[R] M) : ℕ →o (submodule R M)ᵒᵈ :=
⟨λ n, (f ^ n).range, λ n m w x h, begin
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp w,
rw linear_map.mem_range at h,
obtain ⟨m, rfl⟩ := h,
rw linear_map.mem_range,
use (f ^ c) m,
rw [pow_add, linear_map.mul_apply],
end⟩
/-- Restrict the codomain of a linear map `f` to `f.range`.
This is the bundled version of `set.range_factorization`. -/
@[reducible] def range_restrict [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
M →ₛₗ[τ₁₂] f.range := f.cod_restrict f.range f.mem_range_self
/-- The range of a linear map is finite if the domain is finite.
Note: this instance can form a diamond with `subtype.fintype` in the
presence of `fintype M₂`. -/
instance fintype_range [fintype M] [decidable_eq M₂] [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) : fintype (range f) :=
set.fintype_range f
/-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the
set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/
def ker (f : M →ₛₗ[τ₁₂] M₂) : submodule R M := comap f ⊥
@[simp] theorem mem_ker {f : M →ₛₗ[τ₁₂] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R₂
@[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl
@[simp] theorem map_coe_ker (f : M →ₛₗ[τ₁₂] M₂) (x : ker f) : f x = 0 := mem_ker.1 x.2
lemma ker_to_add_submonoid (f : M →ₛₗ[τ₁₂] M₂) :
f.ker.to_add_submonoid = f.to_add_monoid_hom.mker := rfl
lemma comp_ker_subtype (f : M →ₛₗ[τ₁₂] M₂) : f.comp f.ker.subtype = 0 :=
linear_map.ext $ λ x, suffices f x = 0, by simp [this], mem_ker.1 x.2
theorem ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = comap f (ker g) := rfl
theorem ker_le_ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker f ≤ ker (g.comp f : M →ₛₗ[τ₁₃] M₃) :=
by rw ker_comp; exact comap_mono bot_le
theorem disjoint_ker {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 :=
by simp [disjoint_def]
theorem ker_eq_bot' {f : M →ₛₗ[τ₁₂] M₂} :
ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) :=
by simpa [disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ _ _ _ f ⊤
theorem ker_eq_bot_of_inverse {τ₂₁ : R₂ →+* R} [ring_hom_inv_pair τ₁₂ τ₂₁]
{f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₁] M} (h : (g.comp f : M →ₗ[R] M) = id) :
ker f = ⊥ :=
ker_eq_bot'.2 $ λ m hm, by rw [← id_apply m, ← h, comp_apply, hm, g.map_zero]
lemma le_ker_iff_map [ring_hom_surjective τ₁₂] {f : M →ₛₗ[τ₁₂] M₂} {p : submodule R M} :
p ≤ ker f ↔ map f p = ⊥ :=
by rw [ker, eq_bot_iff, map_le_iff_le_comap]
lemma ker_cod_restrict {τ₂₁ : R₂ →+* R} (p : submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) :
ker (cod_restrict p f hf) = ker f :=
by rw [ker, comap_cod_restrict, map_bot]; refl
lemma range_cod_restrict {τ₂₁ : R₂ →+* R} [ring_hom_surjective τ₂₁] (p : submodule R M)
(f : M₂ →ₛₗ[τ₂₁] M) (hf) :
range (cod_restrict p f hf) = comap p.subtype f.range :=
by simpa only [range_eq_map] using map_cod_restrict _ _ _ _
lemma ker_restrict {p : submodule R M} {f : M →ₗ[R] M} (hf : ∀ x : M, x ∈ p → f x ∈ p) :
ker (f.restrict hf) = (f.dom_restrict p).ker :=
by rw [restrict_eq_cod_restrict_dom_restrict, ker_cod_restrict]
lemma _root_.submodule.map_comap_eq [ring_hom_surjective τ₁₂]
(f : M →ₛₗ[τ₁₂] M₂) (q : submodule R₂ M₂) : map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf map_le_range (map_comap_le _ _)) $
by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
lemma _root_.submodule.map_comap_eq_self [ring_hom_surjective τ₁₂]
{f : M →ₛₗ[τ₁₂] M₂} {q : submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q :=
by rwa [submodule.map_comap_eq, inf_eq_right]
@[simp] theorem ker_zero : ker (0 : M →ₛₗ[τ₁₂] M₂) = ⊤ :=
eq_top_iff'.2 $ λ x, by simp
@[simp] theorem range_zero [ring_hom_surjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ :=
by simpa only [range_eq_map] using submodule.map_zero _
theorem ker_eq_top {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊤ ↔ f = 0 :=
⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩
section
variables [ring_hom_surjective τ₁₂]
lemma range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 :=
by rw [range_le_iff_comap]; exact ker_eq_top
theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 :=
by rw [← range_le_bot_iff, le_bot_iff]
lemma range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} :
range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 :=
⟨λ h, ker_eq_top.1 $ eq_top_iff'.2 $ λ x, h $ ⟨_, rfl⟩,
λ h x hx, mem_ker.2 $ exists.elim hx $ λ y hy, by rw [←hy, ←comp_apply, h, zero_apply]⟩
theorem comap_le_comap_iff {f : M →ₛₗ[τ₁₂] M₂} (hf : range f = ⊤) {p p'} :
comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
theorem comap_injective {f : M →ₛₗ[τ₁₂] M₂} (hf : range f = ⊤) : injective (comap f) :=
λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h))
((comap_le_comap_iff hf).1 (ge_of_eq h))
end
theorem ker_eq_bot_of_injective {f : M →ₛₗ[τ₁₂] M₂} (hf : injective f) : ker f = ⊥ :=
begin
have : disjoint ⊤ f.ker, by { rw [disjoint_ker, ← map_zero f], exact λ x hx H, hf H },
simpa [disjoint]
end
/--
The increasing sequence of submodules consisting of the kernels of the iterates of a linear map.
-/
@[simps]
def iterate_ker (f : M →ₗ[R] M) : ℕ →o submodule R M :=
⟨λ n, (f ^ n).ker, λ n m w x h, begin
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp w,
rw linear_map.mem_ker at h,
rw [linear_map.mem_ker, add_comm, pow_add, linear_map.mul_apply, h, linear_map.map_zero],
end⟩
end add_comm_monoid
section ring
variables [ring R] [ring R₂] [ring R₃]
variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
variables {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
variables {f : M →ₛₗ[τ₁₂] M₂}
include R
open submodule
lemma range_to_add_subgroup [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) :
f.range.to_add_subgroup = f.to_add_monoid_hom.range := rfl
lemma ker_to_add_subgroup (f : M →ₛₗ[τ₁₂] M₂) :
f.ker.to_add_subgroup = f.to_add_monoid_hom.ker := rfl
theorem sub_mem_ker_iff {x y} : x - y ∈ f.ker ↔ f x = f y :=
by rw [mem_ker, map_sub, sub_eq_zero]
theorem disjoint_ker' {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y :=
disjoint_ker.trans
⟨λ H x hx y hy h, eq_of_sub_eq_zero $ H _ (sub_mem hx hy) (by simp [h]),
λ H x h₁ h₂, H x h₁ 0 (zero_mem _) (by simpa using h₂)⟩
theorem inj_of_disjoint_ker {p : submodule R M}
{s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) :
∀ x y ∈ s, f x = f y → x = y :=
λ x hx y hy, disjoint_ker'.1 hd _ (h hx) _ (h hy)
theorem ker_eq_bot : ker f = ⊥ ↔ injective f :=
by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ _ _ _ f ⊤
lemma ker_le_iff [ring_hom_surjective τ₁₂] {p : submodule R M} :
ker f ≤ p ↔ ∃ (y ∈ range f), f ⁻¹' {y} ⊆ p :=
begin
split,
{ intros h, use 0, rw [← set_like.mem_coe, f.range_coe], exact ⟨⟨0, map_zero f⟩, h⟩, },
{ rintros ⟨y, h₁, h₂⟩,
rw set_like.le_def, intros z hz, simp only [mem_ker, set_like.mem_coe] at hz,
rw [← set_like.mem_coe, f.range_coe, set.mem_range] at h₁, obtain ⟨x, hx⟩ := h₁,
have hx' : x ∈ p, { exact h₂ hx, },
have hxz : z + x ∈ p, { apply h₂, simp [hx, hz], },
suffices : z + x - x ∈ p, { simpa only [this, add_sub_cancel], },
exact p.sub_mem hxz hx', },
end
end ring
section field
variables [field K] [field K₂]
variables [add_comm_group V] [module K V]
variables [add_comm_group V₂] [module K V₂]
lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f :=
submodule.comap_smul f _ a h
lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f :=
submodule.comap_smul' f _ a
lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f :=
by simpa only [range_eq_map] using submodule.map_smul f _ a h
lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f :=
by simpa only [range_eq_map] using submodule.map_smul' f _ a
end field
end linear_map
namespace is_linear_map
lemma is_linear_map_add [semiring R] [add_comm_monoid M] [module R M] :
is_linear_map R (λ (x : M × M), x.1 + x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp, cc },
{ intros x y,
simp [smul_add] }
end
lemma is_linear_map_sub {R M : Type*} [semiring R] [add_comm_group M] [module R M]:
is_linear_map R (λ (x : M × M), x.1 - x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp [add_comm, add_left_comm, sub_eq_add_neg] },
{ intros x y,
simp [smul_sub] }
end
end is_linear_map
namespace submodule
section add_comm_monoid
variables [semiring R] [semiring R₂] [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂]
variables (p p' : submodule R M) (q : submodule R₂ M₂)
variables {τ₁₂ : R →+* R₂}
open linear_map
@[simp] theorem map_top [ring_hom_surjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : map f ⊤ = range f :=
f.range_eq_map.symm
@[simp] theorem comap_bot (f : M →ₛₗ[τ₁₂] M₂) : comap f ⊥ = ker f := rfl
@[simp] theorem ker_subtype : p.subtype.ker = ⊥ :=
ker_eq_bot_of_injective $ λ x y, subtype.ext_val
@[simp] theorem range_subtype : p.subtype.range = p :=
by simpa using map_comap_subtype p ⊤
lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p :=
by simpa using (map_le_range : map p.subtype p' ≤ p.subtype.range)
/-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the
maximal submodule of `p` is just `p `. -/
@[simp] lemma map_subtype_top : map p.subtype (⊤ : submodule R p) = p :=
by simp
@[simp] lemma comap_subtype_eq_top {p p' : submodule R M} :
comap p.subtype p' = ⊤ ↔ p ≤ p' :=
eq_top_iff.trans $ map_le_iff_le_comap.symm.trans $ by rw [map_subtype_top]
@[simp] lemma comap_subtype_self : comap p.subtype p = ⊤ :=
comap_subtype_eq_top.2 le_rfl
@[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ :=
by rw [of_le, ker_cod_restrict, ker_subtype]
lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p :=
by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype]
@[simp] lemma map_subtype_range_of_le {p p' : submodule R M} (h : p ≤ p') :
map p'.subtype (of_le h).range = p :=
by simp [range_of_le, map_comap_eq, h]
lemma disjoint_iff_comap_eq_bot {p q : submodule R M} :
disjoint p q ↔ comap p.subtype q = ⊥ :=
by rw [←(map_injective_of_injective (show injective p.subtype, from subtype.coe_injective)).eq_iff,
map_comap_subtype, map_bot, disjoint_iff]
/-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N` -/
def map_subtype.rel_iso : submodule R p ≃o {p' : submodule R M // p' ≤ p} :=
{ to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩,
inv_fun := λ q, comap p.subtype q,
left_inv := λ p', comap_map_eq_of_injective subtype.coe_injective p',
right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simp [map_comap_subtype p, inf_of_le_right hq],
map_rel_iff' := λ p₁ p₂, subtype.coe_le_coe.symm.trans begin
dsimp,
rw [map_le_iff_le_comap,
comap_map_eq_of_injective (show injective p.subtype, from subtype.coe_injective) p₂],
end }
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of `M`. -/
def map_subtype.order_embedding : submodule R p ↪o submodule R M :=
(rel_iso.to_rel_embedding $ map_subtype.rel_iso p).trans (subtype.rel_embedding _ _)
@[simp] lemma map_subtype_embedding_eq (p' : submodule R p) :
map_subtype.order_embedding p p' = map p.subtype p' := rfl
end add_comm_monoid
end submodule
namespace linear_map
section semiring
variables [semiring R] [semiring R₂] [semiring R₃]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R₂ M₂] [module R₃ M₃]
variables {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variables [ring_hom_comp_triple τ₁₂ τ₂₃ τ₁₃]
/-- A monomorphism is injective. -/
lemma ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂}
(h : ∀ (u v : f.ker →ₗ[R] M), f.comp u = f.comp v → u = v) : f.ker = ⊥ :=
begin
have h₁ : f.comp (0 : f.ker →ₗ[R] M) = 0 := comp_zero _,
rw [←submodule.range_subtype f.ker, ←h 0 f.ker.subtype (eq.trans h₁ (comp_ker_subtype f).symm)],
exact range_zero
end
lemma range_comp_of_range_eq_top [ring_hom_surjective τ₁₂] [ring_hom_surjective τ₂₃]
[ring_hom_surjective τ₁₃]
{f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) :
range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g :=
by rw [range_comp, hf, submodule.map_top]
lemma ker_comp_of_ker_eq_bot (f : M →ₛₗ[τ₁₂] M₂) {g : M₂ →ₛₗ[τ₂₃] M₃}
(hg : ker g = ⊥) : ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = ker f :=
by rw [ker_comp, hg, submodule.comap_bot]
section image
/-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map,
then `(ϕ : O →ₗ M').submodule_image N` is `ϕ(N)` as a submodule of `M'` -/
def submodule_image {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) : submodule R M' :=
(N.comap O.subtype).map ϕ
@[simp] lemma mem_submodule_image {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yO : y ∈ O) (yN : y ∈ N), ϕ ⟨y, yO⟩ = x :=
begin
refine submodule.mem_map.trans ⟨_, _⟩; simp_rw submodule.mem_comap,
{ rintro ⟨⟨y, yO⟩, (yN : y ∈ N), h⟩,
exact ⟨y, yO, yN, h⟩ },
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨⟨y, yO⟩, yN, h⟩ }
end
lemma mem_submodule_image_of_le {M' : Type*} [add_comm_monoid M'] [module R M']
{O : submodule R M} {ϕ : O →ₗ[R] M'} {N : submodule R M} (hNO : N ≤ O) {x : M'} :
x ∈ ϕ.submodule_image N ↔ ∃ y (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x :=
begin
refine mem_submodule_image.trans ⟨_, _⟩,
{ rintro ⟨y, yO, yN, h⟩,
exact ⟨y, yN, h⟩ },
{ rintro ⟨y, yN, h⟩,
exact ⟨y, hNO yN, yN, h⟩ }
end
lemma submodule_image_apply_of_le {M' : Type*} [add_comm_group M'] [module R M']
{O : submodule R M} (ϕ : O →ₗ[R] M') (N : submodule R M) (hNO : N ≤ O) :
ϕ.submodule_image N = (ϕ.comp (submodule.of_le hNO)).range :=
by rw [submodule_image, range_comp, submodule.range_of_le]
end image
end semiring
end linear_map
@[simp] lemma linear_map.range_range_restrict [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[module R M] [module R M₂] (f : M →ₗ[R] M₂) :
f.range_restrict.range = ⊤ :=
by simp [f.range_cod_restrict _]
/-! ### Linear equivalences -/
namespace linear_equiv
section add_comm_monoid
section subsingleton
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables [module R M] [module R₂ M₂]
variables [subsingleton M] [subsingleton M₂]
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
include σ₂₁
/-- Between two zero modules, the zero map is an equivalence. -/
instance : has_zero (M ≃ₛₗ[σ₁₂] M₂) :=
⟨{ to_fun := 0,
inv_fun := 0,
right_inv := λ x, subsingleton.elim _ _,
left_inv := λ x, subsingleton.elim _ _,
..(0 : M →ₛₗ[σ₁₂] M₂)}⟩
omit σ₂₁
-- Even though these are implied by `subsingleton.elim` via the `unique` instance below, they're
-- nice to have as `rfl`-lemmas for `dsimp`.
include σ₂₁
@[simp] lemma zero_symm : (0 : M ≃ₛₗ[σ₁₂] M₂).symm = 0 := rfl
@[simp] lemma coe_zero : ⇑(0 : M ≃ₛₗ[σ₁₂] M₂) = 0 := rfl
lemma zero_apply (x : M) : (0 : M ≃ₛₗ[σ₁₂] M₂) x = 0 := rfl
/-- Between two zero modules, the zero map is the only equivalence. -/
instance : unique (M ≃ₛₗ[σ₁₂] M₂) :=
{ uniq := λ f, to_linear_map_injective (subsingleton.elim _ _),
default := 0 }
omit σ₂₁
end subsingleton
section
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂}
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables (e e' : M ≃ₛₗ[σ₁₂] M₂)
lemma map_eq_comap {p : submodule R M} :
(p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂) = p.comap (e.symm : M₂ →ₛₗ[σ₂₁] M) :=
set_like.coe_injective $ by simp [e.image_eq_preimage]
/-- A linear equivalence of two modules restricts to a linear equivalence from any submodule
`p` of the domain onto the image of that submodule.
This is the linear version of `add_equiv.submonoid_map` and `add_equiv.subgroup_map`.
This is `linear_equiv.of_submodule'` but with `map` on the right instead of `comap` on the left. -/
def submodule_map (p : submodule R M) :
p ≃ₛₗ[σ₁₂] ↥(p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂) :=
{ inv_fun := λ y, ⟨(e.symm : M₂ →ₛₗ[σ₂₁] M) y, by
{ rcases y with ⟨y', hy⟩, rw submodule.mem_map at hy, rcases hy with ⟨x, hx, hxy⟩, subst hxy,
simp only [symm_apply_apply, submodule.coe_mk, coe_coe, hx], }⟩,
left_inv := λ x, by simp only [linear_map.dom_restrict_apply, linear_map.cod_restrict_apply,
linear_map.to_fun_eq_coe, linear_equiv.coe_coe, linear_equiv.symm_apply_apply, set_like.eta],
right_inv := λ y, by { apply set_coe.ext, simp only [linear_map.dom_restrict_apply,
linear_map.cod_restrict_apply, linear_map.to_fun_eq_coe, linear_equiv.coe_coe, set_like.coe_mk,
linear_equiv.apply_symm_apply] },
..((e : M →ₛₗ[σ₁₂] M₂).dom_restrict p).cod_restrict (p.map (e : M →ₛₗ[σ₁₂] M₂))
(λ x, ⟨x, by simp only [linear_map.dom_restrict_apply, eq_self_iff_true, and_true,
set_like.coe_mem, set_like.mem_coe]⟩) }
include σ₂₁
@[simp] lemma submodule_map_apply (p : submodule R M) (x : p) :
↑(e.submodule_map p x) = e x := rfl
@[simp] lemma submodule_map_symm_apply (p : submodule R M)
(x : (p.map (e : M →ₛₗ[σ₁₂] M₂) : submodule R₂ M₂)) :
↑((e.submodule_map p).symm x) = e.symm x :=
rfl
omit σ₂₁
end
section finsupp
variables {γ : Type*}
variables [semiring R] [semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂] [has_zero γ]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
include τ₂₁
@[simp] lemma map_finsupp_sum (f : M ≃ₛₗ[τ₁₂] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum _
omit τ₂₁
end finsupp
section dfinsupp
open dfinsupp
variables [semiring R] [semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂]
variables [module R M] [module R₂ M₂]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
variables {γ : ι → Type*} [decidable_eq ι]
include τ₂₁
@[simp] lemma map_dfinsupp_sum [Π i, has_zero (γ i)] [Π i (x : γ i), decidable (x ≠ 0)]
(f : M ≃ₛₗ[τ₁₂] M₂) (t : Π₀ i, γ i) (g : Π i, γ i → M) :
f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum _
@[simp] lemma map_dfinsupp_sum_add_hom [Π i, add_zero_class (γ i)] (f : M ≃ₛₗ[τ₁₂] M₂)
(t : Π₀ i, γ i) (g : Π i, γ i →+ M) :
f (sum_add_hom g t) = sum_add_hom (λ i, f.to_add_equiv.to_add_monoid_hom.comp (g i)) t :=
f.to_add_equiv.map_dfinsupp_sum_add_hom _ _
end dfinsupp
section uncurry
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables (V V₂ R)
/-- Linear equivalence between a curried and uncurried function.
Differs from `tensor_product.curry`. -/
protected def curry :
(V × V₂ → R) ≃ₗ[R] (V → V₂ → R) :=
{ map_add' := λ _ _, by { ext, refl },
map_smul' := λ _ _, by { ext, refl },
.. equiv.curry _ _ _ }
@[simp] lemma coe_curry : ⇑(linear_equiv.curry R V V₂) = curry := rfl
@[simp] lemma coe_curry_symm : ⇑(linear_equiv.curry R V V₂).symm = uncurry := rfl
end uncurry
section
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂} {module_M₃ : module R₃ M₃}
variables {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variables {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [ring_hom_comp_triple σ₁₂ σ₂₃ σ₁₃]
variables {σ₃₂ : R₃ →+* R₂}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables {re₂₃ : ring_hom_inv_pair σ₂₃ σ₃₂} {re₃₂ : ring_hom_inv_pair σ₃₂ σ₂₃}
variables (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M) (e : M ≃ₛₗ[σ₁₂] M₂) (h : M₂ →ₛₗ[σ₂₃] M₃)
variables (e'' : M₂ ≃ₛₗ[σ₂₃] M₃)
variables (p q : submodule R M)
/-- Linear equivalence between two equal submodules. -/
def of_eq (h : p = q) : p ≃ₗ[R] q :=
{ map_smul' := λ _ _, rfl, map_add' := λ _ _, rfl, .. equiv.set.of_eq (congr_arg _ h) }
variables {p q}
@[simp] lemma coe_of_eq_apply (h : p = q) (x : p) : (of_eq p q h x : M) = x := rfl
@[simp] lemma of_eq_symm (h : p = q) : (of_eq p q h).symm = of_eq q p h.symm := rfl
@[simp] lemma of_eq_rfl : of_eq p p rfl = linear_equiv.refl R p := by ext; refl
include σ₂₁
/-- A linear equivalence which maps a submodule of one module onto another, restricts to a linear
equivalence of the two submodules. -/
def of_submodules (p : submodule R M) (q : submodule R₂ M₂) (h : p.map (e : M →ₛₗ[σ₁₂] M₂) = q) :
p ≃ₛₗ[σ₁₂] q := (e.submodule_map p).trans (linear_equiv.of_eq _ _ h)
@[simp] lemma of_submodules_apply {p : submodule R M} {q : submodule R₂ M₂}
(h : p.map ↑e = q) (x : p) : ↑(e.of_submodules p q h x) = e x := rfl
@[simp] lemma of_submodules_symm_apply {p : submodule R M} {q : submodule R₂ M₂}
(h : p.map ↑e = q) (x : q) : ↑((e.of_submodules p q h).symm x) = e.symm x := rfl
include re₁₂ re₂₁
/-- A linear equivalence of two modules restricts to a linear equivalence from the preimage of any
submodule to that submodule.
This is `linear_equiv.of_submodule` but with `comap` on the left instead of `map` on the right. -/
def of_submodule' [module R M] [module R₂ M₂] (f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) :
U.comap (f : M →ₛₗ[σ₁₂] M₂) ≃ₛₗ[σ₁₂] U :=
(f.symm.of_submodules _ _ f.symm.map_eq_comap).symm
lemma of_submodule'_to_linear_map [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) :
(f.of_submodule' U).to_linear_map =
(f.to_linear_map.dom_restrict _).cod_restrict _ subtype.prop :=
by { ext, refl }
@[simp]
lemma of_submodule'_apply [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) (x : U.comap (f : M →ₛₗ[σ₁₂] M₂)) :
(f.of_submodule' U x : M₂) = f (x : M) := rfl
@[simp]
lemma of_submodule'_symm_apply [module R M] [module R₂ M₂]
(f : M ≃ₛₗ[σ₁₂] M₂) (U : submodule R₂ M₂) (x : U) :
((f.of_submodule' U).symm x : M) = f.symm (x : M₂) := rfl
variable (p)
omit σ₂₁ re₁₂ re₂₁
/-- The top submodule of `M` is linearly equivalent to `M`. -/
def of_top (h : p = ⊤) : p ≃ₗ[R] M :=
{ inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩,
left_inv := λ ⟨x, h⟩, rfl,
right_inv := λ x, rfl,
.. p.subtype }
@[simp] theorem of_top_apply {h} (x : p) : of_top p h x = x := rfl
@[simp] theorem coe_of_top_symm_apply {h} (x : M) : ((of_top p h).symm x : M) = x := rfl
theorem of_top_symm_apply {h} (x : M) : (of_top p h).symm x = ⟨x, h.symm ▸ trivial⟩ := rfl
include σ₂₁ re₁₂ re₂₁
/-- If a linear map has an inverse, it is a linear equivalence. -/
def of_linear (h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) :
M ≃ₛₗ[σ₁₂] M₂ :=
{ inv_fun := g,
left_inv := linear_map.ext_iff.1 h₂,
right_inv := linear_map.ext_iff.1 h₁,
..f }
omit σ₂₁ re₁₂ re₂₁
include σ₂₁ re₁₂ re₂₁
@[simp] theorem of_linear_apply {h₁ h₂} (x : M) : of_linear f g h₁ h₂ x = f x := rfl
omit σ₂₁ re₁₂ re₂₁
include σ₂₁ re₁₂ re₂₁
@[simp] theorem of_linear_symm_apply {h₁ h₂} (x : M₂) : (of_linear f g h₁ h₂).symm x = g x :=
rfl
omit σ₂₁ re₁₂ re₂₁
@[simp] protected theorem range : (e : M →ₛₗ[σ₁₂] M₂).range = ⊤ :=
linear_map.range_eq_top.2 e.to_equiv.surjective
include σ₂₁ re₁₂ re₂₁
lemma eq_bot_of_equiv [module R₂ M₂] (e : p ≃ₛₗ[σ₁₂] (⊥ : submodule R₂ M₂)) : p = ⊥ :=
begin
refine bot_unique (set_like.le_def.2 $ assume b hb, (submodule.mem_bot R).2 _),
rw [← p.mk_eq_zero hb, ← e.map_eq_zero_iff],
apply submodule.eq_zero_of_bot_submodule
end
omit σ₂₁ re₁₂ re₂₁
@[simp] protected theorem ker : (e : M →ₛₗ[σ₁₂] M₂).ker = ⊥ :=
linear_map.ker_eq_bot_of_injective e.to_equiv.injective
@[simp] theorem range_comp [ring_hom_surjective σ₁₂] [ring_hom_surjective σ₂₃]
[ring_hom_surjective σ₁₃] :
(h.comp (e : M →ₛₗ[σ₁₂] M₂) : M →ₛₗ[σ₁₃] M₃).range = h.range :=
linear_map.range_comp_of_range_eq_top _ e.range
include module_M
@[simp] theorem ker_comp (l : M →ₛₗ[σ₁₂] M₂) :
(((e'' : M₂ →ₛₗ[σ₂₃] M₃).comp l : M →ₛₗ[σ₁₃] M₃) : M →ₛₗ[σ₁₃] M₃).ker = l.ker :=
linear_map.ker_comp_of_ker_eq_bot _ e''.ker
omit module_M
variables {f g}
include σ₂₁
/-- An linear map `f : M →ₗ[R] M₂` with a left-inverse `g : M₂ →ₗ[R] M` defines a linear
equivalence between `M` and `f.range`.
This is a computable alternative to `linear_equiv.of_injective`, and a bidirectional version of
`linear_map.range_restrict`. -/
def of_left_inverse [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{g : M₂ → M} (h : function.left_inverse g f) : M ≃ₛₗ[σ₁₂] f.range :=
{ to_fun := f.range_restrict,
inv_fun := g ∘ f.range.subtype,
left_inv := h,
right_inv := λ x, subtype.ext $
let ⟨x', hx'⟩ := linear_map.mem_range.mp x.prop in
show f (g x) = x, by rw [←hx', h x'],
.. f.range_restrict }
omit σ₂₁
@[simp] lemma of_left_inverse_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(h : function.left_inverse g f) (x : M) :
↑(of_left_inverse h x) = f x := rfl
include σ₂₁
@[simp] lemma of_left_inverse_symm_apply [ring_hom_inv_pair σ₁₂ σ₂₁]
[ring_hom_inv_pair σ₂₁ σ₁₂] (h : function.left_inverse g f) (x : f.range) :
(of_left_inverse h).symm x = g x := rfl
omit σ₂₁
variables (f)
/-- An `injective` linear map `f : M →ₗ[R] M₂` defines a linear equivalence
between `M` and `f.range`. See also `linear_map.of_left_inverse`. -/
noncomputable def of_injective [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(h : injective f) : M ≃ₛₗ[σ₁₂] f.range :=
of_left_inverse $ classical.some_spec h.has_left_inverse
@[simp] theorem of_injective_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{h : injective f} (x : M) : ↑(of_injective f h x) = f x := rfl
/-- A bijective linear map is a linear equivalence. -/
noncomputable def of_bijective [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
(hf₁ : injective f) (hf₂ : surjective f) : M ≃ₛₗ[σ₁₂] M₂ :=
(of_injective f hf₁).trans (of_top _ $ linear_map.range_eq_top.2 hf₂)
@[simp] theorem of_bijective_apply [ring_hom_inv_pair σ₁₂ σ₂₁] [ring_hom_inv_pair σ₂₁ σ₁₂]
{hf₁ hf₂} (x : M) : of_bijective f hf₁ hf₂ x = f x := rfl
end
end add_comm_monoid
section add_comm_group
variables [semiring R] [semiring R₂] [semiring R₃] [semiring R₄]
variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄]
variables {module_M : module R M} {module_M₂ : module R₂ M₂}
variables {module_M₃ : module R₃ M₃} {module_M₄ : module R₄ M₄}
variables {σ₁₂ : R →+* R₂} {σ₃₄ : R₃ →+* R₄}
variables {σ₂₁ : R₂ →+* R} {σ₄₃ : R₄ →+* R₃}
variables {re₁₂ : ring_hom_inv_pair σ₁₂ σ₂₁} {re₂₁ : ring_hom_inv_pair σ₂₁ σ₁₂}
variables {re₃₄ : ring_hom_inv_pair σ₃₄ σ₄₃} {re₄₃ : ring_hom_inv_pair σ₄₃ σ₃₄}
variables (e e₁ : M ≃ₛₗ[σ₁₂] M₂) (e₂ : M₃ ≃ₛₗ[σ₃₄] M₄)
@[simp] theorem map_neg (a : M) : e (-a) = -e a := e.to_linear_map.map_neg a
@[simp] theorem map_sub (a b : M) : e (a - b) = e a - e b :=
e.to_linear_map.map_sub a b
end add_comm_group
section neg
variables (R) [semiring R] [add_comm_group M] [module R M]
/-- `x ↦ -x` as a `linear_equiv` -/
def neg : M ≃ₗ[R] M := { .. equiv.neg M, .. (-linear_map.id : M →ₗ[R] M) }
variable {R}
@[simp] lemma coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl
lemma neg_apply (x : M) : neg R x = -x := by simp
@[simp] lemma symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl
end neg
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
variables [module R M] [module R M₂] [module R M₃]
open _root_.linear_map
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smul_of_unit (a : Rˣ) : M ≃ₗ[R] M :=
distrib_mul_action.to_linear_equiv R M a
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a
linear isomorphism between the two function spaces. -/
def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) :
(M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) :=
{ to_fun := λ f : M₁ →ₗ[R] M₂₁, (e₂ : M₂₁ →ₗ[R] M₂₂).comp $ f.comp (e₁.symm : M₂ →ₗ[R] M₁),
inv_fun := λ f, (e₂.symm : M₂₂ →ₗ[R] M₂₁).comp $ f.comp (e₁ : M₁ →ₗ[R] M₂),
left_inv := λ f, by { ext x, simp only [symm_apply_apply, comp_app, coe_comp, coe_coe]},
right_inv := λ f, by { ext x, simp only [comp_app, apply_symm_apply, coe_comp, coe_coe]},
map_add' := λ f g, by { ext x, simp only [map_add, add_apply, comp_app, coe_comp, coe_coe]},
map_smul' := λ c f, by { ext x, simp only [smul_apply, comp_app, coe_comp, map_smulₛₗ e₂,
coe_coe]} }
@[simp] lemma arrow_congr_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₁ →ₗ[R] M₂₁) (x : M₂) :
arrow_congr e₁ e₂ f x = e₂ (f (e₁.symm x)) :=
rfl
@[simp] lemma arrow_congr_symm_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_semiring R]
[add_comm_monoid M₁] [add_comm_monoid M₂] [add_comm_monoid M₂₁] [add_comm_monoid M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₂ →ₗ[R] M₂₂) (x : M₁) :
(arrow_congr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) :=
rfl
lemma arrow_congr_comp {N N₂ N₃ : Sort*}
[add_comm_monoid N] [add_comm_monoid N₂] [add_comm_monoid N₃]
[module R N] [module R N₂] [module R N₃]
(e₁ : M ≃ₗ[R] N) (e₂ : M₂ ≃ₗ[R] N₂) (e₃ : M₃ ≃ₗ[R] N₃) (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) :
arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) :=
by { ext, simp only [symm_apply_apply, arrow_congr_apply, linear_map.comp_apply], }
lemma arrow_congr_trans {M₁ M₂ M₃ N₁ N₂ N₃ : Sort*}
[add_comm_monoid M₁] [module R M₁] [add_comm_monoid M₂] [module R M₂]
[add_comm_monoid M₃] [module R M₃] [add_comm_monoid N₁] [module R N₁]
[add_comm_monoid N₂] [module R N₂] [add_comm_monoid N₃] [module R N₃]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : N₁ ≃ₗ[R] N₂) (e₃ : M₂ ≃ₗ[R] M₃) (e₄ : N₂ ≃ₗ[R] N₃) :
(arrow_congr e₁ e₂).trans (arrow_congr e₃ e₄) = arrow_congr (e₁.trans e₃) (e₂.trans e₄) :=
rfl
/-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂`
and `M` into `M₃` are linearly isomorphic. -/
def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ[R] (M →ₗ[R] M₃) :=
arrow_congr (linear_equiv.refl R M) f
/-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to
themselves are linearly isomorphic. -/
def conj (e : M ≃ₗ[R] M₂) : (module.End R M) ≃ₗ[R] (module.End R M₂) := arrow_congr e e
lemma conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M) :
e.conj f = ((↑e : M →ₗ[R] M₂).comp f).comp (e.symm : M₂ →ₗ[R] M) := rfl
lemma symm_conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M₂) :
e.symm.conj f = ((↑e.symm : M₂ →ₗ[R] M).comp f).comp (e : M →ₗ[R] M₂) := rfl
lemma conj_comp (e : M ≃ₗ[R] M₂) (f g : module.End R M) :
e.conj (g.comp f) = (e.conj g).comp (e.conj f) :=
arrow_congr_comp e e e f g
lemma conj_trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) :
e₁.conj.trans e₂.conj = (e₁.trans e₂).conj :=
by { ext f x, refl, }
@[simp] lemma conj_id (e : M ≃ₗ[R] M₂) : e.conj linear_map.id = linear_map.id :=
by { ext, simp [conj_apply], }
end comm_semiring
section field
variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module K M] [module K M₂] [module K M₃]
variables (K) (M)
open _root_.linear_map
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
@[simps] def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M :=
smul_of_unit $ units.mk0 a ha
end field
end linear_equiv
namespace submodule
section module
variables [semiring R] [add_comm_monoid M] [module R M]
/-- Given `p` a submodule of the module `M` and `q` a submodule of `p`, `p.equiv_subtype_map q`
is the natural `linear_equiv` between `q` and `q.map p.subtype`. -/
def equiv_subtype_map (p : submodule R M) (q : submodule R p) :
q ≃ₗ[R] q.map p.subtype :=
{ inv_fun :=
begin
rintro ⟨x, hx⟩,
refine ⟨⟨x, _⟩, _⟩;
rcases hx with ⟨⟨_, h⟩, _, rfl⟩;
assumption
end,
left_inv := λ ⟨⟨_, _⟩, _⟩, rfl,
right_inv := λ ⟨x, ⟨_, h⟩, _, rfl⟩, rfl,
.. (p.subtype.dom_restrict q).cod_restrict _
begin
rintro ⟨x, hx⟩,
refine ⟨x, hx, rfl⟩,
end }
@[simp]
lemma equiv_subtype_map_apply {p : submodule R M} {q : submodule R p} (x : q) :
(p.equiv_subtype_map q x : M) = p.subtype.dom_restrict q x :=
rfl
@[simp]
lemma equiv_subtype_map_symm_apply {p : submodule R M} {q : submodule R p} (x : q.map p.subtype) :
((p.equiv_subtype_map q).symm x : M) = x :=
by { cases x, refl }
/-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap
of `t.subtype`. -/
@[simps]
def comap_subtype_equiv_of_le {p q : submodule R M} (hpq : p ≤ q) :
comap q.subtype p ≃ₗ[R] p :=
{ to_fun := λ x, ⟨x, x.2⟩,
inv_fun := λ x, ⟨⟨x, hpq x.2⟩, x.2⟩,
left_inv := λ x, by simp only [coe_mk, set_like.eta, coe_coe],
right_inv := λ x, by simp only [subtype.coe_mk, set_like.eta, coe_coe],
map_add' := λ x y, rfl,
map_smul' := λ c x, rfl }
end module
end submodule
namespace submodule
variables [comm_semiring R] [comm_semiring R₂]
variables [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R₂ M₂]
variables [add_comm_monoid N] [add_comm_monoid N₂] [module R N] [module R N₂]
variables {τ₁₂ : R →+* R₂} {τ₂₁ : R₂ →+* R}
variables [ring_hom_inv_pair τ₁₂ τ₂₁] [ring_hom_inv_pair τ₂₁ τ₁₂]
variables (p : submodule R M) (q : submodule R₂ M₂)
variables (pₗ : submodule R N) (qₗ : submodule R N₂)
include τ₂₁
@[simp] lemma mem_map_equiv {e : M ≃ₛₗ[τ₁₂] M₂} {x : M₂} : x ∈ p.map (e : M →ₛₗ[τ₁₂] M₂) ↔
e.symm x ∈ p :=
begin
rw submodule.mem_map, split,
{ rintros ⟨y, hy, hx⟩, simp [←hx, hy], },
{ intros hx, refine ⟨e.symm x, hx, by simp⟩, },
end
omit τ₂₁
lemma map_equiv_eq_comap_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : submodule R M) :
K.map (e : M →ₛₗ[τ₁₂] M₂) = K.comap (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
submodule.ext (λ _, by rw [mem_map_equiv, mem_comap, linear_equiv.coe_coe])
lemma comap_equiv_eq_map_symm (e : M ≃ₛₗ[τ₁₂] M₂) (K : submodule R₂ M₂) :
K.comap (e : M →ₛₗ[τ₁₂] M₂) = K.map (e.symm : M₂ →ₛₗ[τ₂₁] M) :=
(map_equiv_eq_comap_symm e.symm K).symm
lemma comap_le_comap_smul (fₗ : N →ₗ[R] N₂) (c : R) :
comap fₗ qₗ ≤ comap (c • fₗ) qₗ :=
begin
rw set_like.le_def,
intros m h,
change c • (fₗ m) ∈ qₗ,
change fₗ m ∈ qₗ at h,
apply qₗ.smul_mem _ h,
end
lemma inf_comap_le_comap_add (f₁ f₂ : M →ₛₗ[τ₁₂] M₂) :
comap f₁ q ⊓ comap f₂ q ≤ comap (f₁ + f₂) q :=
begin
rw set_like.le_def,
intros m h,
change f₁ m + f₂ m ∈ q,
change f₁ m ∈ q ∧ f₂ m ∈ q at h,
apply q.add_mem h.1 h.2,
end
/-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`,
the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/
def compatible_maps : submodule R (N →ₗ[R] N₂) :=
{ carrier := {fₗ | pₗ ≤ comap fₗ qₗ},
zero_mem' := by { change pₗ ≤ comap 0 qₗ, rw comap_zero, refine le_top, },
add_mem' := λ f₁ f₂ h₁ h₂, by { apply le_trans _ (inf_comap_le_comap_add qₗ f₁ f₂),
rw le_inf_iff, exact ⟨h₁, h₂⟩, },
smul_mem' := λ c fₗ h, le_trans h (comap_le_comap_smul qₗ fₗ c), }
end submodule
namespace equiv
variables [semiring R] [add_comm_monoid M] [module R M] [add_comm_monoid M₂] [module R M₂]
/-- An equivalence whose underlying function is linear is a linear equivalence. -/
def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ :=
{ .. e, .. h.mk' e}
end equiv
section fun_left
variables (R M) [semiring R] [add_comm_monoid M] [module R M]
variables {m n p : Type*}
namespace linear_map
/-- Given an `R`-module `M` and a function `m → n` between arbitrary types,
construct a linear map `(n → M) →ₗ[R] (m → M)` -/
def fun_left (f : m → n) : (n → M) →ₗ[R] (m → M) :=
{ to_fun := (∘ f), map_add' := λ _ _, rfl, map_smul' := λ _ _, rfl }
@[simp] theorem fun_left_apply (f : m → n) (g : n → M) (i : m) : fun_left R M f g i = g (f i) :=
rfl
@[simp] theorem fun_left_id (g : n → M) : fun_left R M _root_.id g = g :=
rfl
theorem fun_left_comp (f₁ : n → p) (f₂ : m → n) :
fun_left R M (f₁ ∘ f₂) = (fun_left R M f₂).comp (fun_left R M f₁) :=
rfl
theorem fun_left_surjective_of_injective (f : m → n) (hf : injective f) :
surjective (fun_left R M f) :=
begin
classical,
intro g,
refine ⟨λ x, if h : ∃ y, f y = x then g h.some else 0, _⟩,
{ ext,
dsimp only [fun_left_apply],
split_ifs with w,
{ congr,
exact hf w.some_spec, },
{ simpa only [not_true, exists_apply_eq_apply] using w } },
end
theorem fun_left_injective_of_surjective (f : m → n) (hf : surjective f) :
injective (fun_left R M f) :=
begin
obtain ⟨g, hg⟩ := hf.has_right_inverse,
suffices : left_inverse (fun_left R M g) (fun_left R M f),
{ exact this.injective },
intro x,
rw [←linear_map.comp_apply, ← fun_left_comp, hg.id, fun_left_id],
end
end linear_map
namespace linear_equiv
open _root_.linear_map
/-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types,
construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/
def fun_congr_left (e : m ≃ n) : (n → M) ≃ₗ[R] (m → M) :=
linear_equiv.of_linear (fun_left R M e) (fun_left R M e.symm)
(linear_map.ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.symm_comp_self, fun_left_id])
(linear_map.ext $ λ x, funext $ λ i,
by rw [id_apply, ← fun_left_comp, equiv.self_comp_symm, fun_left_id])
@[simp] theorem fun_congr_left_apply (e : m ≃ n) (x : n → M) :
fun_congr_left R M e x = fun_left R M e x :=
rfl
@[simp] theorem fun_congr_left_id :
fun_congr_left R M (equiv.refl n) = linear_equiv.refl R (n → M) :=
rfl
@[simp] theorem fun_congr_left_comp (e₁ : m ≃ n) (e₂ : n ≃ p) :
fun_congr_left R M (equiv.trans e₁ e₂) =
linear_equiv.trans (fun_congr_left R M e₂) (fun_congr_left R M e₁) :=
rfl
@[simp] lemma fun_congr_left_symm (e : m ≃ n) :
(fun_congr_left R M e).symm = fun_congr_left R M e.symm :=
rfl
end linear_equiv
end fun_left
namespace linear_map
variables [semiring R] [add_comm_monoid M] [module R M]
variables (R M)
/-- The group of invertible linear maps from `M` to itself -/
@[reducible] def general_linear_group := (M →ₗ[R] M)ˣ
namespace general_linear_group
variables {R M}
instance : has_coe_to_fun (general_linear_group R M) (λ _, M → M) := by apply_instance
/-- An invertible linear map `f` determines an equivalence from `M` to itself. -/
def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) :=
{ inv_fun := f.inv.to_fun,
left_inv := λ m, show (f.inv * f.val) m = m,
by erw f.inv_val; simp,
right_inv := λ m, show (f.val * f.inv) m = m,
by erw f.val_inv; simp,
..f.val }
/-- An equivalence from `M` to itself determines an invertible linear map. -/
def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M :=
{ val := f,
inv := (f.symm : M →ₗ[R] M),
val_inv := linear_map.ext $ λ _, f.apply_symm_apply _,
inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ }
variables (R M)
/-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear
equivalences between `M` and itself. -/
def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) :=
{ to_fun := to_linear_equiv,
inv_fun := of_linear_equiv,
left_inv := λ f, by { ext, refl },
right_inv := λ f, by { ext, refl },
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) :
(general_linear_equiv R M f : M →ₗ[R] M) = f :=
by {ext, refl}
@[simp] lemma coe_fn_general_linear_equiv (f : general_linear_group R M) :
⇑(general_linear_equiv R M f) = (f : M → M) :=
rfl
end general_linear_group
end linear_map
|
a4458193888c1b58016a6720aef6551ce9e2193a | f4bff2062c030df03d65e8b69c88f79b63a359d8 | /src/game/order/level07.lean | 2d51627571aa5de94e5481187e0ad416033bc82f | [
"Apache-2.0"
] | permissive | adastra7470/real-number-game | 776606961f52db0eb824555ed2f8e16f92216ea3 | f9dcb7d9255a79b57e62038228a23346c2dc301b | refs/heads/master | 1,669,221,575,893 | 1,594,669,800,000 | 1,594,669,800,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 932 | lean | import game.order.level06
import data.real.irrational
open real
namespace xena -- hide
/-
# Chapter 2 : Order
## Level 7
Prove by example that there exist pairs of real numbers
$a$ and $b$ such that $a \in \mathbb{R} \setminus \mathbb{Q}$,
$b \in \mathbb{R} \setminus \mathbb{Q}$,
but their sum $a + b$ is a rational number, $(a+b) \in \mathbb{Q}$.
You may use this result in the Lean mathlib library:
`irrational_sqrt_two : irrational (sqrt 2)`
-/
/- Axiom : irrational_sqrt_two : irrational (sqrt 2)
-/
/- Lemma
Not true that for any $a$, $b$, irrational numbers, the sum is
also an irrational number.
-/
theorem not_sum_irrational :
¬ ( ∀ (a b : ℝ), irrational a → irrational b → irrational (a+b) ) :=
begin
intro H,
have H2 := H (sqrt 2) (-sqrt 2),
have H3 := H2 irrational_sqrt_two (irrational_neg_iff.2 irrational_sqrt_two),
apply H3,
existsi (0 : ℚ),
simp, done
end
end xena -- hide
|
eb0b3387553825153b0d942a1eaf9b69655084aa | 42c01158c2730cc6ac3e058c1339c18cb90366e2 | /group_projects/Ellen_Arlt_solutions.lean | ac0dd2b0a912dc85ee9cf69146b901bd33c7a58a | [] | no_license | ChrisHughes24/xena | c80d94355d0c2ae8deddda9d01e6d31bc21c30ae | 337a0d7c9f0e255e08d6d0a383e303c080c6ec0c | refs/heads/master | 1,631,059,898,392 | 1,511,200,551,000 | 1,511,200,551,000 | 111,468,589 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,086 | lean | namespace xena
inductive xnat
| zero : xnat
| succ : xnat → xnat
open xnat
open classical
--#check @succ.inj
definition one := succ zero
definition two := succ one
definition add : xnat → xnat → xnat
| n zero := n
| n (succ p) := succ (add n p)
notation a + b := add a b
theorem one_add_one_equals_two : one + one = two :=
begin
unfold two,
unfold one,
unfold add,
end
theorem add_zero (n : xnat) : n + zero = n :=
begin
unfold add
end
theorem zero_add (n : xnat) : zero + n = n :=
begin
induction n with t Ht,
refl,
unfold add,
rewrite [Ht],
end
theorem add_assoc (a b c : xnat) : (a + b) + c = a + (b + c) :=
begin
induction c with t Ht,
refl,
unfold add,
rewrite [Ht]
end
theorem zero_add_eq_add_zero (n : xnat) : zero + n = n + zero :=
begin
rewrite [zero_add],
unfold add
end
theorem one_add_eq_succ (n : xnat) : one + n = succ n :=
begin
unfold one,
induction n with t Ht,
refl,
unfold add,
rewrite [Ht]
end
theorem add_comm (a b : xnat) : a + b = b + a :=
begin
induction b with t Ht,
rw [←zero_add_eq_add_zero],
unfold add,
rewrite [Ht],
rewrite [←one_add_eq_succ],
rewrite [← add_assoc],
rw [one_add_eq_succ]
end
theorem eq_iff_succ_eq_succ (a b : xnat) : succ a = succ b ↔ a = b :=
begin
split,
exact succ.inj,
assume H : a = b,
rw [H]
end
theorem add_cancel_right (a b t : xnat) : a = b ↔ a+t = b+t :=
begin
split,
assume H : a = b,
rw [H],
assume P : a+t = b+t,
induction t with s Qs,
have h3: a = a + zero, by exact add_zero a,
have h4: b = b+ zero, by exact add_zero b,
rw [h3, h4], assumption,
rw [Qs],
unfold add at P,
rw [eq_iff_succ_eq_succ] at P,assumption
end
definition mul : xnat → xnat → xnat
| n zero := zero
| n (succ p) := n + (mul n p)
notation a * b := mul a b
example : one * one = one :=
begin
refl
end
theorem mul_zero (a : xnat) : a * zero = zero :=
begin
unfold mul
end
theorem zero_mul (a : xnat) : zero * a = zero :=
begin
induction a with t Ht,
refl,
unfold mul,
rewrite [Ht],
refl
end
theorem mul_one (a : xnat) : a * one = a :=
begin
unfold one,
unfold mul,
rewrite [add_zero]
end
theorem one_mul (a : xnat) : one * a = a :=
begin
induction a with t Ht,
refl,
unfold mul,
rewrite [Ht],
rewrite [one_add_eq_succ]
end
theorem zero_sum : zero + zero = zero :=
begin
unfold add,
end
theorem right_distrib (a b c : xnat) : a * (b + c) = a* b + a * c :=
begin
induction c with t Ht,
rw [add_zero],
rw [mul_zero],
rw [add_zero],
unfold add,
unfold mul,
rewrite [Ht],
rw [← add_assoc],
rw [← add_assoc],
rw [← add_cancel_right],
rw [add_comm]
end
theorem add_one_eq_succ (n : xnat) : n + one = succ n :=
begin
unfold one,
unfold add,
end
theorem left_distrib (a b c : xnat) : (a + b) * c = a * c + b * c :=
begin
induction c with n Hn,
unfold mul,
refl,
rw [←add_one_eq_succ,right_distrib,Hn,right_distrib,right_distrib],
rw [mul_one,mul_one,mul_one],
rw [add_assoc,←add_assoc (b*n),add_comm (b*n),←add_assoc,←add_assoc,←add_assoc],
end
theorem mul_assoc (a b c : xnat) : (a * b) * c = a * (b * c) :=
begin
induction c with n Hn,
refl,
unfold mul,
rw [Hn,right_distrib],
end
theorem mul_comm (a b : xnat) : a * b = b * a :=
begin
induction b with n Hn,
rw [mul_zero,zero_mul],
rw[← one_add_eq_succ,right_distrib,left_distrib,Hn,one_mul,mul_one]
end
definition lt : xnat → xnat → Prop
| zero zero := false
| (succ m) zero := false
| zero (succ p) := true
| (succ m) (succ p) := lt m p
definition gt : xnat → xnat → Prop
| zero zero := false
| (succ m) zero := true
| zero (succ p) := false
| (succ m) (succ p) := gt m p
notation a < b := lt a b
notation b > a := gt a b
theorem inequality_A1 (a b t : xnat) : a < b → a + t < b + t :=
begin
intro H,
induction t with n Hn,
rw [add_zero,add_zero],assumption,
rw [← add_one_eq_succ,← add_assoc,← add_assoc],
rw [add_one_eq_succ,add_one_eq_succ],
unfold lt, assumption
end
end xena
|
c114b5eef5b680bf2a2bca19340a24929becf2e4 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/order/partial_sups.lean | 8ca66aa100f0c05742c056d1fa1c9c1547681efb | [
"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 | 5,784 | 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 data.finset.lattice
import data.set.pairwise
import order.preorder_hom
/-!
# The monotone sequence of partial supremums of a sequence
We define `partial_sups : (ℕ → α) → ℕ →ₘ α` inductively. For `f : ℕ → α`, `partial_sups f` is
the sequence `f 0 `, `f 0 ⊔ f 1`, `f 0 ⊔ f 1 ⊔ f 2`, ... The point of this definition is that
* it doesn't need a `⨆`, as opposed to `⨆ (i ≤ n), f i`.
* it doesn't need a `⊥`, as opposed to `(finset.range (n + 1)).sup f`.
* it avoids needing to prove that `finset.range (n + 1)` is nonempty to use `finset.sup'`.
Equivalence with those definitions is shown by `partial_sups_eq_bsupr`, `partial_sups_eq_sup_range`,
`partial_sups_eq_sup'_range` and respectively.
## Notes
One might dispute whether this sequence should start at `f 0` or `⊥`. We choose the former because :
* Starting at `⊥` requires... having a bottom element.
* `λ f n, (finset.range n).sup f` is already effectively the sequence starting at `⊥`.
* If we started at `⊥` we wouldn't have the Galois insertion. See `partial_sups.gi`.
## TODO
One could generalize `partial_sups` to any locally finite bot preorder domain, in place of `ℕ`.
-/
variables {α : Type*}
section semilattice_sup
variables [semilattice_sup α]
/-- The monotone sequence whose value at `n` is the supremum of the `f m` where `m ≤ n`. -/
def partial_sups (f : ℕ → α) : ℕ →ₘ α :=
⟨@nat.rec (λ _, α) (f 0) (λ (n : ℕ) (a : α), a ⊔ f (n + 1)),
monotone_of_monotone_nat (λ n, le_sup_left)⟩
@[simp] lemma partial_sups_zero (f : ℕ → α) : partial_sups f 0 = f 0 := rfl
@[simp] lemma partial_sups_succ (f : ℕ → α) (n : ℕ) :
partial_sups f (n + 1) = partial_sups f n ⊔ f (n + 1) := rfl
lemma le_partial_sups_of_le (f : ℕ → α) {m n : ℕ} (h : m ≤ n) :
f m ≤ partial_sups f n :=
begin
induction n with n ih,
{ cases h, apply le_refl, },
{ cases h with h h,
{ exact le_sup_right, },
{ exact (ih h).trans le_sup_left, } },
end
lemma le_partial_sups (f : ℕ → α) :
f ≤ partial_sups f :=
λ n, le_partial_sups_of_le f le_rfl
lemma partial_sups_le (f : ℕ → α) (n : ℕ)
(a : α) (w : ∀ m, m ≤ n → f m ≤ a) : partial_sups f n ≤ a :=
begin
induction n with n ih,
{ apply w 0 le_rfl, },
{ exact sup_le (ih (λ m p, w m (nat.le_succ_of_le p))) (w (n + 1) le_rfl) }
end
lemma monotone.partial_sups_eq {f : ℕ → α} (hf : monotone f) :
(partial_sups f : ℕ → α) = f :=
begin
ext n,
induction n with n ih,
{ refl },
{ rw [partial_sups_succ, ih, sup_eq_right.2 (hf (nat.le_succ _))] }
end
lemma partial_sups_mono : monotone (partial_sups : (ℕ → α) → ℕ →ₘ α) :=
begin
rintro f g h n,
induction n with n ih,
{ exact h 0 },
{ exact sup_le_sup ih (h _) }
end
/-- `partial_sups` forms a Galois insertion with the coercion from monotone functions to functions.
-/
def partial_sups.gi : galois_insertion (partial_sups : (ℕ → α) → ℕ →ₘ α) coe_fn :=
{ choice := λ f h, ⟨f, begin
convert (partial_sups f).monotone,
exact (le_partial_sups f).antisymm h,
end⟩,
gc := λ f g, begin
refine ⟨(le_partial_sups f).trans, λ h, _⟩,
convert partial_sups_mono h,
exact preorder_hom.ext _ _ g.monotone.partial_sups_eq.symm,
end,
le_l_u := λ f, le_partial_sups f,
choice_eq := λ f h, preorder_hom.ext _ _ ((le_partial_sups f).antisymm h) }
lemma partial_sups_eq_sup'_range (f : ℕ → α) (n : ℕ) :
partial_sups f n = (finset.range (n + 1)).sup' ⟨n, finset.self_mem_range_succ n⟩ f :=
begin
induction n with n ih,
{ simp },
{ dsimp [partial_sups] at ih ⊢,
simp_rw @finset.range_succ n.succ,
rw [ih, finset.sup'_insert, sup_comm] }
end
end semilattice_sup
lemma partial_sups_eq_sup_range [semilattice_sup_bot α] (f : ℕ → α) (n : ℕ) :
partial_sups f n = (finset.range (n + 1)).sup f :=
begin
induction n with n ih,
{ simp },
{ dsimp [partial_sups] at ih ⊢,
rw [finset.range_succ, finset.sup_insert, sup_comm, ih] }
end
/- Note this lemma requires a distributive lattice, so is not useful (or true) in situations such as
submodules.
Can be generalized to (the yet inexistent) `distrib_lattice_bot`. -/
lemma partial_sups_disjoint_of_disjoint [bounded_distrib_lattice α]
(f : ℕ → α) (h : pairwise (disjoint on f)) {m n : ℕ} (hmn : m < n) :
disjoint (partial_sups f m) (f n) :=
begin
induction m with m ih,
{ exact h 0 n hmn.ne, },
{ rw [partial_sups_succ, disjoint_sup_left],
exact ⟨ih (nat.lt_of_succ_lt hmn), h (m + 1) n hmn.ne⟩ }
end
section complete_lattice
variables [complete_lattice α]
lemma partial_sups_eq_bsupr (f : ℕ → α) (n : ℕ) :
partial_sups f n = ⨆ (i ≤ n), f i :=
begin
rw [partial_sups_eq_sup_range, finset.sup_eq_supr],
congr,
ext a,
exact supr_congr_Prop (by rw [finset.mem_range, nat.lt_succ_iff]) (λ _, rfl),
end
@[simp] lemma supr_partial_sups_eq (f : ℕ → α) :
(⨆ n, partial_sups f n) = ⨆ n, f n :=
begin
refine (supr_le $ λ n, _).antisymm (supr_le_supr $ le_partial_sups f),
rw partial_sups_eq_bsupr,
exact bsupr_le_supr _ _,
end
lemma supr_le_supr_of_partial_sups_le_partial_sups {f g : ℕ → α}
(h : partial_sups f ≤ partial_sups g) :
(⨆ n, f n) ≤ ⨆ n, g n :=
begin
rw [←supr_partial_sups_eq f, ←supr_partial_sups_eq g],
exact supr_le_supr h,
end
lemma supr_eq_supr_of_partial_sups_eq_partial_sups {f g : ℕ → α}
(h : partial_sups f = partial_sups g) :
(⨆ n, f n) = ⨆ n, g n :=
by simp_rw [←supr_partial_sups_eq f, ←supr_partial_sups_eq g, h]
end complete_lattice
|
350f49cd24db6cd31c04245cf10433906c1e8925 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/set_theory/cardinal/finite.lean | 8014e39334561f10c0a02978737821b6cbe45816 | [
"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 | 2,913 | lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import set_theory.cardinal.basic
/-!
# Finite Cardinality Functions
## Main Definitions
* `nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `nat.card α = 0`.
* `part_enat.card α` is the cardinality of `α` as an extended natural number
(`part ℕ` implementation). If `α` is infinite, `part_enat.card α = ⊤`.
-/
open cardinal
noncomputable theory
variables {α β : Type*}
namespace nat
/-- `nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `nat.card α = 0`. -/
protected def card (α : Type*) : ℕ := (mk α).to_nat
@[simp]
lemma card_eq_fintype_card [fintype α] : nat.card α = fintype.card α := mk_to_nat_eq_card
@[simp]
lemma card_eq_zero_of_infinite [infinite α] : nat.card α = 0 := mk_to_nat_of_infinite
lemma card_congr (f : α ≃ β) : nat.card α = nat.card β :=
cardinal.to_nat_congr f
lemma card_eq_of_bijective (f : α → β) (hf : function.bijective f) : nat.card α = nat.card β :=
card_congr (equiv.of_bijective f hf)
lemma card_eq_of_equiv_fin {α : Type*} {n : ℕ}
(f : α ≃ fin n) : nat.card α = n :=
by simpa using card_congr f
/-- If the cardinality is positive, that means it is a finite type, so there is
an equivalence between `α` and `fin (nat.card α)`. See also `finite.equiv_fin`. -/
def equiv_fin_of_card_pos {α : Type*} (h : nat.card α ≠ 0) :
α ≃ fin (nat.card α) :=
begin
casesI fintype_or_infinite α,
{ simpa using fintype.equiv_fin α },
{ simpa using h },
end
lemma card_of_subsingleton (a : α) [subsingleton α] : nat.card α = 1 :=
begin
rw [card_eq_fintype_card],
convert fintype.card_of_subsingleton a,
end
@[simp] lemma card_unique [unique α] : nat.card α = 1 :=
card_of_subsingleton default
lemma card_eq_one_iff_unique : nat.card α = 1 ↔ subsingleton α ∧ nonempty α :=
cardinal.to_nat_eq_one_iff_unique
theorem card_of_is_empty [is_empty α] : nat.card α = 0 := by simp
@[simp] lemma card_prod (α β : Type*) : nat.card (α × β) = nat.card α * nat.card β :=
by simp only [nat.card, mk_prod, to_nat_mul, to_nat_lift]
@[simp] lemma card_ulift (α : Type*) : nat.card (ulift α) = nat.card α :=
card_congr equiv.ulift
@[simp] lemma card_plift (α : Type*) : nat.card (plift α) = nat.card α :=
card_congr equiv.plift
end nat
namespace part_enat
/-- `part_enat.card α` is the cardinality of `α` as an extended natural number.
If `α` is infinite, `part_enat.card α = ⊤`. -/
def card (α : Type*) : part_enat := (mk α).to_part_enat
@[simp]
lemma card_eq_coe_fintype_card [fintype α] : card α = fintype.card α := mk_to_part_enat_eq_coe_card
@[simp]
lemma card_eq_top_of_infinite [infinite α] : card α = ⊤ := mk_to_part_enat_of_infinite
end part_enat
|
2e52952fcf3b003dda218110a2a1877f46d5432d | ad0c7d243dc1bd563419e2767ed42fb323d7beea | /data/real/cau_seq.lean | d7d4310c112fce4b6e14c0128b39ed40b0b4487c | [
"Apache-2.0"
] | permissive | sebzim4500/mathlib | e0b5a63b1655f910dee30badf09bd7e191d3cf30 | 6997cafbd3a7325af5cb318561768c316ceb7757 | refs/heads/master | 1,585,549,958,618 | 1,538,221,723,000 | 1,538,221,723,000 | 150,869,076 | 0 | 0 | Apache-2.0 | 1,538,229,323,000 | 1,538,229,323,000 | null | UTF-8 | Lean | false | false | 22,353 | 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 basic theory of Cauchy sequences, used in the construction of the reals.
Where applicable, lemmas that will be reused in other contexts have
been stated in extra generality.
-/
import algebra.big_operators algebra.ordered_field
class is_absolute_value {α} [discrete_linear_ordered_field α]
{β} [ring β] (f : β → α) : Prop :=
(abv_nonneg : ∀ x, 0 ≤ f x)
(abv_eq_zero : ∀ {x}, f x = 0 ↔ x = 0)
(abv_add : ∀ x y, f (x + y) ≤ f x + f y)
(abv_mul : ∀ x y, f (x * y) = f x * f y)
namespace is_absolute_value
variables {α : Type*} [discrete_linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) [is_absolute_value abv]
theorem abv_zero : abv 0 = 0 := (abv_eq_zero abv).2 rfl
theorem abv_one' (h : (1:β) ≠ 0) : abv 1 = 1 :=
(domain.mul_left_inj $ mt (abv_eq_zero abv).1 h).1 $
by rw [← abv_mul abv, mul_one, mul_one]
theorem abv_one
{β : Type*} [domain β] (abv : β → α) [is_absolute_value abv] :
abv 1 = 1 := abv_one' abv one_ne_zero
theorem abv_pos {a : β} : 0 < abv a ↔ a ≠ 0 :=
by rw [lt_iff_le_and_ne, ne, eq_comm]; simp [abv_eq_zero abv, abv_nonneg abv]
theorem abv_neg (a : β) : abv (-a) = abv a :=
by rw [← mul_self_inj_of_nonneg (abv_nonneg abv _) (abv_nonneg abv _),
← abv_mul abv, ← abv_mul abv]; simp
theorem abv_sub (a b : β) : abv (a - b) = abv (b - a) :=
by rw [← neg_sub, abv_neg abv]
theorem abv_inv
{β : Type*} [discrete_field β] (abv : β → α) [is_absolute_value abv]
(a : β) : abv a⁻¹ = (abv a)⁻¹ :=
classical.by_cases
(λ h : a = 0, by simp [h, abv_zero abv])
(λ h, (domain.mul_left_inj (mt (abv_eq_zero abv).1 h)).1 $
by rw [← abv_mul abv]; simp [h, mt (abv_eq_zero abv).1 h, abv_one abv])
theorem abv_div
{β : Type*} [discrete_field β] (abv : β → α) [is_absolute_value abv]
(a b : β) : abv (a / b) = abv a / abv b :=
by rw [division_def, abv_mul abv, abv_inv abv]; refl
lemma abv_sub_le (a b c : β) : abv (a - c) ≤ abv (a - b) + abv (b - c) :=
by simpa using abv_add abv (a - b) (b - c)
lemma sub_abv_le_abv_sub (a b : β) : abv a - abv b ≤ abv (a - b) :=
sub_le_iff_le_add.2 $ by simpa using abv_add abv (a - b) b
lemma abs_abv_sub_le_abv_sub (a b : β) :
abs (abv a - abv b) ≤ abv (a - b) :=
abs_sub_le_iff.2 ⟨sub_abv_le_abv_sub abv _ _,
by rw abv_sub abv; apply sub_abv_le_abv_sub abv⟩
end is_absolute_value
instance abs_is_absolute_value {α} [discrete_linear_ordered_field α] :
is_absolute_value (abs : α → α) :=
{ abv_nonneg := abs_nonneg,
abv_eq_zero := λ _, abs_eq_zero,
abv_add := abs_add,
abv_mul := abs_mul }
open is_absolute_value
theorem exists_forall_ge_and {α} [linear_order α] {P Q : α → Prop} :
(∃ i, ∀ j ≥ i, P j) → (∃ i, ∀ j ≥ i, Q j) →
∃ i, ∀ j ≥ i, P j ∧ Q j
| ⟨a, h₁⟩ ⟨b, h₂⟩ := let ⟨c, ac, bc⟩ := exists_ge_of_linear a b in
⟨c, λ j hj, ⟨h₁ _ (le_trans ac hj), h₂ _ (le_trans bc hj)⟩⟩
section
variables {α : Type*} [discrete_linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) [is_absolute_value abv]
theorem rat_add_continuous_lemma
{ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β},
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, λ a₁ a₂ b₁ b₂ h₁ h₂,
by simpa [add_halves] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma
{ε K₁ K₂ : α} (ε0 : 0 < ε) (K₁0 : 0 < K₁) (K₂0 : 0 < K₂) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ →
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε :=
begin
have K0 := lt_of_lt_of_le K₁0 (le_max_left _ K₂),
have εK := div_pos (half_pos ε0) K0,
refine ⟨_, εK, λ a₁ a₂ b₁ b₂ ha₁ hb₂ h₁ h₂, _⟩,
replace ha₁ := lt_of_lt_of_le ha₁ (le_max_left _ K₂),
replace hb₂ := lt_of_lt_of_le hb₂ (le_max_right K₁ _),
have := add_lt_add
(mul_lt_mul' (le_of_lt h₁) hb₂ (abv_nonneg abv _) εK)
(mul_lt_mul' (le_of_lt h₂) ha₁ (abv_nonneg abv _) εK),
rw [← abv_mul abv, mul_comm, div_mul_cancel _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this,
simpa [mul_add, add_mul] using lt_of_le_of_lt (abv_add abv _ _) this
end
theorem rat_inv_continuous_lemma
{β : Type*} [discrete_field β] (abv : β → α) [is_absolute_value abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b →
abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε :=
begin
have KK := mul_pos K0 K0,
have εK := mul_pos ε0 KK,
refine ⟨_, εK, λ a b ha hb h, _⟩,
have a0 := lt_of_lt_of_le K0 ha,
have b0 := lt_of_lt_of_le K0 hb,
rw [inv_sub_inv ((abv_pos abv).1 a0) ((abv_pos abv).1 b0),
abv_div abv, abv_mul abv, mul_comm, abv_sub abv,
← mul_div_cancel ε (ne_of_gt KK)],
exact div_lt_div h
(mul_le_mul hb ha (le_of_lt K0) (abv_nonneg abv _))
(le_of_lt $ mul_pos ε0 KK) KK
end
end
def is_cau_seq {α : Type*} [discrete_linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) [is_absolute_value abv] (f : ℕ → β) :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace is_cau_seq
variables {α : Type*} [discrete_linear_ordered_field α]
{β : Type*} [ring β] {abv : β → α} [is_absolute_value abv] {f : ℕ → β}
theorem cauchy₂ (hf : is_cau_seq abv f) {ε:α} (ε0 : ε > 0) :
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε :=
begin
refine (hf _ (half_pos ε0)).imp (λ i hi j k ij ik, _),
rw ← add_halves ε,
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) _),
rw abv_sub abv, exact hi _ ik
end
theorem cauchy₃ (hf : is_cau_seq abv f) {ε:α} (ε0 : ε > 0) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0 in ⟨i, λ j ij k jk, H _ _ (le_trans ij jk) ij⟩
end is_cau_seq
def cau_seq {α : Type*} [discrete_linear_ordered_field α]
(β : Type*) [ring β] (abv : β → α) [is_absolute_value abv] :=
{f : ℕ → β // is_cau_seq abv f}
namespace cau_seq
variables {α : Type*} [discrete_linear_ordered_field α]
section ring
variables {β : Type*} [ring β] {abv : β → α} [is_absolute_value abv]
instance : has_coe_to_fun (cau_seq β abv) := ⟨_, subtype.val⟩
@[simp] theorem mk_to_fun (f) (hf : is_cau_seq abv f) :
@coe_fn (cau_seq β abv) _ ⟨f, hf⟩ = f := rfl
theorem ext {f g : cau_seq β abv} (h : ∀ i, f i = g i) : f = g :=
subtype.eq (funext h)
theorem is_cau (f : cau_seq β abv) : is_cau_seq abv f := f.2
theorem cauchy (f : cau_seq β abv) :
∀ {ε}, ε > 0 → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := f.2
theorem cauchy₂ (f : cau_seq β abv) {ε:α} : ε > 0 →
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂
theorem cauchy₃ (f : cau_seq β abv) {ε:α} : ε > 0 →
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃
theorem bounded (f : cau_seq β abv) : ∃ r, ∀ i, abv (f i) < r :=
begin
cases f.cauchy zero_lt_one with i h,
let R := (finset.range (i+1)).sum (λ j, abv (f j)),
have : ∀ j ≤ i, abv (f j) ≤ R,
{ intros j ij, change (λ j, abv (f j)) j ≤ R,
apply finset.single_le_sum,
{ intros, apply abv_nonneg abv },
{ rwa [finset.mem_range, nat.lt_succ_iff] } },
refine ⟨R + 1, λ j, _⟩,
cases lt_or_le j i with ij ij,
{ exact lt_of_le_of_lt (this _ (le_of_lt ij)) (lt_add_one _) },
{ have := lt_of_le_of_lt (abv_add abv _ _)
(add_lt_add_of_le_of_lt (this _ (le_refl _)) (h _ ij)),
rw [add_sub, add_comm] at this, simpa }
end
theorem bounded' (f : cau_seq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := f.bounded in
⟨max r (x+1), lt_of_lt_of_le (lt_add_one _) (le_max_right _ _),
λ i, lt_of_lt_of_le (h i) (le_max_left _ _)⟩
def of_eq (f : cau_seq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : cau_seq β abv :=
⟨g, λ ε, by rw [show g = f, from (funext e).symm]; exact f.cauchy⟩
instance : has_add (cau_seq β abv) :=
⟨λ f g, ⟨λ i, (f i + g i : β), λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0,
⟨i, H⟩ := exists_forall_ge_and (f.cauchy₃ δ0) (g.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ (le_refl _) in Hδ (H₁ _ ij) (H₂ _ ij)⟩⟩⟩
@[simp] theorem add_apply (f g : cau_seq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl
variable (abv)
def const (x : β) : cau_seq β abv :=
⟨λ i, x, λ ε ε0, ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩⟩
variable {abv}
local notation `const` := const abv
@[simp] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl
theorem const_inj {x y : β} : (const x : cau_seq β abv) = const y ↔ x = y :=
⟨λ h, congr_arg (λ f:cau_seq β abv, (f:ℕ→β) 0) h, congr_arg _⟩
instance : has_zero (cau_seq β abv) := ⟨const 0⟩
instance : has_one (cau_seq β abv) := ⟨const 1⟩
@[simp] theorem zero_apply (i) : (0 : cau_seq β abv) i = 0 := rfl
@[simp] theorem one_apply (i) : (1 : cau_seq β abv) i = 1 := rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
ext $ λ i, rfl
instance : has_mul (cau_seq β abv) :=
⟨λ f g, ⟨λ i, (f i * g i : β), λ ε ε0,
let ⟨F, F0, hF⟩ := f.bounded' 0, ⟨G, G0, hG⟩ := g.bounded' 0,
⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0 F0 G0,
⟨i, H⟩ := exists_forall_ge_and (f.cauchy₃ δ0) (g.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ (le_refl _) in
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩⟩⟩
@[simp] theorem mul_apply (f g : cau_seq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y :=
ext $ λ i, rfl
instance : has_neg (cau_seq β abv) :=
⟨λ f, of_eq (const (-1) * f) (λ x, -f x) (λ i, by simp)⟩
@[simp] theorem neg_apply (f : cau_seq β abv) (i) : (-f) i = -f i := rfl
theorem const_neg (x : β) : const (-x) = -const x :=
ext $ λ i, rfl
instance : ring (cau_seq β abv) :=
by refine {neg := has_neg.neg, add := (+), zero := 0, mul := (*), one := 1, ..};
{ intros, apply ext, simp [mul_add, mul_assoc, add_mul] }
instance {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv] : comm_ring (cau_seq β abv) :=
{ mul_comm := by intros; apply ext; simp [mul_left_comm, mul_comm],
..cau_seq.ring }
theorem const_sub (x y : β) : const (x - y) = const x - const y :=
by rw [sub_eq_add_neg, const_add, const_neg, sub_eq_add_neg]
@[simp] theorem sub_apply (f g : cau_seq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl
def lim_zero (f : cau_seq β abv) := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f + g)
| ε ε0 := (exists_forall_ge_and
(hf _ $ half_pos ε0) (hg _ $ half_pos ε0)).imp $
λ i H j ij, let ⟨H₁, H₂⟩ := H _ ij in
by simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_lim_zero (f : cau_seq β abv) {g}
(hg : lim_zero g) : lim_zero (f * g)
| ε ε0 := let ⟨F, F0, hF⟩ := f.bounded' 0 in
(hg _ $ div_pos ε0 F0).imp $ λ i H j ij,
by have := mul_lt_mul' (le_of_lt $ hF j) (H _ ij) (abv_nonneg abv _) F0;
rwa [mul_comm F, div_mul_cancel _ (ne_of_gt F0), ← abv_mul abv] at this
theorem neg_lim_zero {f : cau_seq β abv} (hf : lim_zero f) : lim_zero (-f) :=
by rw ← neg_one_mul; exact mul_lim_zero _ hf
theorem sub_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f - g) :=
add_lim_zero hf (neg_lim_zero hg)
theorem zero_lim_zero : lim_zero (0 : cau_seq β abv)
| ε ε0 := ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩
theorem const_lim_zero {x : β} : lim_zero (const x) ↔ x = 0 :=
⟨λ H, (abv_eq_zero abv).1 $
eq_of_le_of_forall_le_of_dense (abv_nonneg abv _) $
λ ε ε0, let ⟨i, hi⟩ := H _ ε0 in le_of_lt $ hi _ (le_refl _),
λ e, e.symm ▸ zero_lim_zero⟩
instance equiv : setoid (cau_seq β abv) :=
⟨λ f g, lim_zero (f - g),
⟨λ f, by simp [zero_lim_zero],
λ f g h, by simpa using neg_lim_zero h,
λ f g h fg gh, by simpa using add_lim_zero fg gh⟩⟩
theorem equiv_def₃ {f g : cau_seq β abv} (h : f ≈ g) {ε:α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ $ half_pos ε0) (f.cauchy₃ $ half_pos ε0)).imp $
λ i H j ij k jk, let ⟨h₁, h₂⟩ := H _ ij in
by have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk));
rwa [sub_add_sub_cancel', add_halves] at this
theorem lim_zero_congr {f g : cau_seq β abv} (h : f ≈ g) : lim_zero f ↔ lim_zero g :=
⟨λ l, by simpa using add_lim_zero (setoid.symm h) l,
λ l, by simpa using add_lim_zero h l⟩
theorem abv_pos_of_not_lim_zero {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) :=
begin
haveI := classical.prop_decidable,
by_contra nk,
refine hf (λ ε ε0, _),
simp [not_forall] at nk,
cases f.cauchy₃ (half_pos ε0) with i hi,
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩,
refine ⟨j, λ k jk, _⟩,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj),
rwa [sub_add_cancel, add_halves] at this
end
theorem of_near (f : ℕ → β) (g : cau_seq β abv)
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) : is_cau_seq abv f
| ε ε0 :=
let ⟨i, hi⟩ := exists_forall_ge_and
(h _ (half_pos $ half_pos ε0)) (g.cauchy₃ $ half_pos ε0) in
⟨i, λ j ij, begin
cases hi _ (le_refl _) with h₁ h₂, rw abv_sub abv at h₁,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁),
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij)),
rwa [add_halves, add_halves, add_right_comm,
sub_add_sub_cancel, sub_add_sub_cancel] at this
end⟩
lemma not_lim_zero_of_not_congr_zero {f : cau_seq _ abv} (hf : ¬ f ≈ 0) : ¬ lim_zero f :=
assume : lim_zero f,
have lim_zero (f - 0), by simpa,
hf this
lemma mul_equiv_zero (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : g * f ≈ 0 :=
have lim_zero (f - 0), from hf,
have lim_zero (g*f), from mul_lim_zero _ $ by simpa,
show lim_zero (g*f - 0), by simpa
lemma mul_not_equiv_zero {f g : cau_seq _ abv} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) : ¬ (f * g) ≈ 0 :=
assume : lim_zero (f*g - 0),
have hlz : lim_zero (f*g), by simpa,
have hf' : ¬ lim_zero f, by simpa using (show ¬ lim_zero (f - 0), from hf),
have hg' : ¬ lim_zero g, by simpa using (show ¬ lim_zero (g - 0), from hg),
begin
rcases abv_pos_of_not_lim_zero hf' with ⟨a1, ha1, N1, hN1⟩,
rcases abv_pos_of_not_lim_zero hg' with ⟨a2, ha2, N2, hN2⟩,
have : a1 * a2 > 0, from mul_pos ha1 ha2,
cases hlz _ this with N hN,
let i := max N (max N1 N2),
have hN' := hN i (le_max_left _ _),
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _)),
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _)),
apply not_le_of_lt hN',
change _ ≤ abv (_ * _),
rw is_absolute_value.abv_mul abv,
apply mul_le_mul; try { assumption },
{ apply le_of_lt ha2 },
{ apply is_absolute_value.abv_nonneg abv }
end
end ring
section comm_ring
variables {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv]
lemma mul_equiv_zero' (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : f * g ≈ 0 :=
by rw mul_comm; apply mul_equiv_zero _ hf
end comm_ring
section integral_domain
variables {β : Type*} [integral_domain β] (abv : β → α) [is_absolute_value abv]
lemma one_not_equiv_zero : ¬ (const abv 1) ≈ (const abv 0) :=
assume h,
have ∀ ε > 0, ∃ i, ∀ k, k ≥ i → abv (1 - 0) < ε, from h,
have h1 : abv 1 ≤ 0, from le_of_not_gt $
assume h2 : abv 1 > 0,
exists.elim (this _ h2) $ λ i hi,
lt_irrefl (abv 1) $ by simpa using hi _ (le_refl _),
have h2 : abv 1 ≥ 0, from is_absolute_value.abv_nonneg _ _,
have abv 1 = 0, from le_antisymm h1 h2,
have (1 : β) = 0, from (is_absolute_value.abv_eq_zero abv).1 this,
absurd this one_ne_zero
end integral_domain
section discrete_field
variables {β : Type*} [discrete_field β] {abv : β → α} [is_absolute_value abv]
theorem inv_aux {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε | ε ε0 :=
let ⟨K, K0, HK⟩ := abv_pos_of_not_lim_zero hf,
⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0,
⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨iK, H'⟩ := H _ (le_refl _) in Hδ (H _ ij).1 iK (H' _ ij)⟩
def inv (f) (hf : ¬ lim_zero f) : cau_seq β abv := ⟨_, inv_aux hf⟩
@[simp] theorem inv_apply {f : cau_seq β abv} (hf i) : inv f hf i = (f i)⁻¹ := rfl
theorem inv_mul_cancel {f : cau_seq β abv} (hf) : inv f hf * f ≈ 1 :=
λ ε ε0, let ⟨K, K0, i, H⟩ := abv_pos_of_not_lim_zero hf in
⟨i, λ j ij,
by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)),
abv_zero abv] using ε0⟩
theorem const_inv {x : β} (hx : x ≠ 0) : const abv (x⁻¹) = inv (const abv x) (by rwa const_lim_zero) :=
ext (assume n, by simp[inv_apply, const_apply])
end discrete_field
section abs
local notation `const` := const abs
def pos (f : cau_seq α abs) : Prop := ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j
theorem not_lim_zero_of_pos {f : cau_seq α abs} : pos f → ¬ lim_zero f
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ F0),
⟨h₁, h₂⟩ := h _ (le_refl _) in
not_lt_of_le h₁ (abs_lt.1 h₂).2
theorem const_pos {x : α} : pos (const x) ↔ 0 < x :=
⟨λ ⟨K, K0, i, h⟩, lt_of_lt_of_le K0 (h _ (le_refl _)),
λ h, ⟨x, h, 0, λ j _, le_refl _⟩⟩
theorem add_pos {f g : cau_seq α abs} : pos f → pos g → pos (f + g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.add_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in add_le_add h₁ h₂⟩
theorem pos_add_lim_zero {f g : cau_seq α abs} : pos f → lim_zero g → pos (f + g)
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0)) in
⟨_, half_pos F0, i, λ j ij, begin
cases h j ij with h₁ h₂,
have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1),
rwa [← sub_eq_add_neg, sub_self_div_two] at this
end⟩
theorem mul_pos {f g : cau_seq α abs} : pos f → pos g → pos (f * g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.mul_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in
mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩
theorem trichotomy (f : cau_seq α abs) : pos f ∨ lim_zero f ∨ pos (-f) :=
begin
cases classical.em (lim_zero f); simp *,
rcases abv_pos_of_not_lim_zero h with ⟨K, K0, hK⟩,
rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩,
refine (le_total 0 (f i)).imp _ _;
refine (λ h, ⟨K, K0, i, λ j ij, _⟩);
have := (hi _ ij).1;
cases hi _ (le_refl _) with h₁ h₂,
{ rwa abs_of_nonneg at this,
rw abs_of_nonneg h at h₁,
exact (le_add_iff_nonneg_right _).1
(le_trans h₁ $ neg_le_sub_iff_le_add'.1 $
le_of_lt (abs_lt.1 $ h₂ _ ij).1) },
{ rwa abs_of_nonpos at this,
rw abs_of_nonpos h at h₁,
rw [← sub_le_sub_iff_right, zero_sub],
exact le_trans (le_of_lt (abs_lt.1 $ h₂ _ ij).2) h₁ }
end
instance : has_lt (cau_seq α abs) := ⟨λ f g, pos (g - f)⟩
instance : has_le (cau_seq α abs) := ⟨λ f g, f < g ∨ f ≈ g⟩
theorem lt_of_lt_of_eq {f g h : cau_seq α abs}
(fg : f < g) (gh : g ≈ h) : f < h :=
by simpa using pos_add_lim_zero fg (neg_lim_zero gh)
theorem lt_of_eq_of_lt {f g h : cau_seq α abs}
(fg : f ≈ g) (gh : g < h) : f < h :=
by have := pos_add_lim_zero gh (neg_lim_zero fg);
rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : cau_seq α abs} (fg : f < g) (gh : g < h) : f < h :=
by simpa using add_pos fg gh
theorem lt_irrefl {f : cau_seq α abs} : ¬ f < f
| h := not_lim_zero_of_pos h (by simp [zero_lim_zero])
instance : preorder (cau_seq α abs) :=
{ lt := (<),
le := λ f g, f < g ∨ f ≈ g,
le_refl := λ f, or.inr (setoid.refl _),
le_trans := λ f g h fg, match fg with
| or.inl fg, or.inl gh := or.inl $ lt_trans fg gh
| or.inl fg, or.inr gh := or.inl $ lt_of_lt_of_eq fg gh
| or.inr fg, or.inl gh := or.inl $ lt_of_eq_of_lt fg gh
| or.inr fg, or.inr gh := or.inr $ setoid.trans fg gh
end,
lt_iff_le_not_le := λ f g,
⟨λ h, ⟨or.inl h,
not_or (mt (lt_trans h) lt_irrefl) (not_lim_zero_of_pos h)⟩,
λ ⟨h₁, h₂⟩, h₁.resolve_right
(mt (λ h, or.inr (setoid.symm h)) h₂)⟩ }
theorem le_antisymm {f g : cau_seq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : cau_seq α abs) : f < g ∨ f ≈ g ∨ g < f :=
(trichotomy (g - f)).imp_right
(λ h, h.imp (λ h, setoid.symm h) (λ h, by rwa neg_sub at h))
theorem le_total (f g : cau_seq α abs) : f ≤ g ∨ g ≤ f :=
(or.assoc.2 (lt_total f g)).imp_right or.inl
theorem const_lt {x y : α} : const x < const y ↔ x < y :=
show pos _ ↔ _, by rw [← const_sub, const_pos, sub_pos]
theorem const_equiv {x y : α} : const x ≈ const y ↔ x = y :=
show lim_zero _ ↔ _, by rw [← const_sub, const_lim_zero, sub_eq_zero]
theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y :=
by rw le_iff_lt_or_eq; exact or_congr const_lt const_equiv
theorem exists_gt (f : cau_seq α abs) : ∃ a : α, f < const a :=
let ⟨K, H⟩ := f.bounded in
⟨K + 1, 1, zero_lt_one, 0, λ i _, begin
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right],
exact le_of_lt (abs_lt.1 (H _)).2
end⟩
theorem exists_lt (f : cau_seq α abs) : ∃ a : α, const a < f :=
let ⟨a, h⟩ := (-f).exists_gt in ⟨-a, show pos _,
by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩
end abs
end cau_seq
|
16a34b31e304685f2d3d5b4b99f9dbccb86cb67c | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/sites/surjective.lean | 93c68c5866ca0c454bf59fcd8327210898dd7ef6 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,191 | lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import category_theory.sites.subsheaf
import category_theory.sites.compatible_sheafification
/-!
# Locally surjective morphisms
## Main definitions
- `is_locally_surjective` : A morphism of presheaves valued in a concrete category is locally
surjective with respect to a grothendieck topology if every section in the target is locally
in the set-theoretic image, i.e. the image sheaf coincides with the target.
## Main results
- `to_sheafify_is_locally_surjective` : `to_sheafify` is locally surjective.
-/
universes v u w v' u' w'
open opposite category_theory category_theory.grothendieck_topology
namespace category_theory
variables {C : Type u} [category.{v} C] (J : grothendieck_topology C)
local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun
variables {A : Type u'} [category.{v'} A] [concrete_category.{w'} A]
/-- Given `f : F ⟶ G`, a morphism between presieves, and `s : G.obj (op U)`, this is the sieve
of `U` consisting of the `i : V ⟶ U` such that `s` restricted along `i` is in the image of `f`. -/
@[simps (lemmas_only)]
def image_sieve {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : G.obj (op U)) : sieve U :=
{ arrows := λ V i, ∃ t : F.obj (op V), f.app _ t = G.map i.op s,
downward_closed' := begin
rintros V W i ⟨t, ht⟩ j,
refine ⟨F.map j.op t, _⟩,
rw [op_comp, G.map_comp, comp_apply, ← ht, elementwise_of f.naturality],
end }
lemma image_sieve_eq_sieve_of_section {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : G.obj (op U)) :
image_sieve f s = (image_presheaf (whisker_right f (forget A))).sieve_of_section s := rfl
lemma image_sieve_whisker_forget {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : G.obj (op U)) :
image_sieve (whisker_right f (forget A)) s = image_sieve f s := rfl
lemma image_sieve_app {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) {U : C} (s : F.obj (op U)) :
image_sieve f (f.app _ s) = ⊤ :=
begin
ext V i,
simp only [sieve.top_apply, iff_true, image_sieve_apply],
have := elementwise_of (f.naturality i.op),
exact ⟨F.map i.op s, this s⟩,
end
/-- A morphism of presheaves `f : F ⟶ G` is locally surjective with respect to a grothendieck
topology if every section of `G` is locally in the image of `f`. -/
def is_locally_surjective {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) : Prop :=
∀ (U : C) (s : G.obj (op U)), image_sieve f s ∈ J U
lemma is_locally_surjective_iff_image_presheaf_sheafify_eq_top {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) :
is_locally_surjective J f ↔ (image_presheaf (whisker_right f (forget A))).sheafify J = ⊤ :=
begin
simp only [subpresheaf.ext_iff, function.funext_iff, set.ext_iff, top_subpresheaf_obj,
set.top_eq_univ, set.mem_univ, iff_true],
exact ⟨λ H U, H (unop U), λ H U, H (op U)⟩
end
lemma is_locally_surjective_iff_image_presheaf_sheafify_eq_top'
{F G : Cᵒᵖ ⥤ (Type w)} (f : F ⟶ G) :
is_locally_surjective J f ↔ (image_presheaf f).sheafify J = ⊤ :=
begin
simp only [subpresheaf.ext_iff, function.funext_iff, set.ext_iff, top_subpresheaf_obj,
set.top_eq_univ, set.mem_univ, iff_true],
exact ⟨λ H U, H (unop U), λ H U, H (op U)⟩
end
lemma is_locally_surjective_iff_is_iso
{F G : Sheaf J (Type w)} (f : F ⟶ G) :
is_locally_surjective J f.1 ↔ is_iso (image_sheaf_ι f) :=
begin
rw [image_sheaf_ι, is_locally_surjective_iff_image_presheaf_sheafify_eq_top',
subpresheaf.eq_top_iff_is_iso],
exact ⟨λ h, @@is_iso_of_reflects_iso _ _ (image_sheaf_ι f) (Sheaf_to_presheaf J _) h _,
λ h, @@functor.map_is_iso _ _ (Sheaf_to_presheaf J _) _ h⟩,
end
lemma is_locally_surjective_iff_whisker_forget {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) :
is_locally_surjective J f ↔ is_locally_surjective J (whisker_right f (forget A)) :=
begin
simpa only [is_locally_surjective_iff_image_presheaf_sheafify_eq_top]
end
lemma is_locally_surjective_of_surjective {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G)
(H : ∀ U, function.surjective (f.app U)) : is_locally_surjective J f :=
begin
intros U s,
obtain ⟨t, rfl⟩ := H _ s,
rw image_sieve_app,
exact J.top_mem _
end
lemma is_locally_surjective_of_iso {F G : Cᵒᵖ ⥤ A} (f : F ⟶ G) [is_iso f] :
is_locally_surjective J f :=
begin
apply is_locally_surjective_of_surjective,
intro U,
apply function.bijective.surjective,
rw ← is_iso_iff_bijective,
apply_instance
end
lemma is_locally_surjective.comp {F₁ F₂ F₃ : Cᵒᵖ ⥤ A} {f₁ : F₁ ⟶ F₂} {f₂ : F₂ ⟶ F₃}
(h₁ : is_locally_surjective J f₁) (h₂ : is_locally_surjective J f₂) :
is_locally_surjective J (f₁ ≫ f₂) :=
begin
intros U s,
have : sieve.bind (image_sieve f₂ s) (λ _ _ h, image_sieve f₁ h.some) ≤ image_sieve (f₁ ≫ f₂) s,
{ rintros V i ⟨W, i, j, H, ⟨t', ht'⟩, rfl⟩,
refine ⟨t', _⟩,
rw [op_comp, F₃.map_comp, nat_trans.comp_app, comp_apply, comp_apply, ht',
elementwise_of f₂.naturality, H.some_spec] },
apply J.superset_covering this,
apply J.bind_covering,
{ apply h₂ },
{ intros, apply h₁ }
end
section
variables (F : Cᵒᵖ ⥤ Type (max u v))
/-- The image of `F` in `J.sheafify F` is isomorphic to the sheafification. -/
noncomputable
def sheafification_iso_image_presheaf :
J.sheafify F ≅ ((image_presheaf (J.to_sheafify F)).sheafify J).to_presheaf :=
{ hom := J.sheafify_lift (to_image_presheaf_sheafify J _)
((is_sheaf_iff_is_sheaf_of_type J _).mpr $ subpresheaf.sheafify_is_sheaf _ $
(is_sheaf_iff_is_sheaf_of_type J _).mp $ sheafify_is_sheaf J _),
inv := subpresheaf.ι _,
hom_inv_id' := J.sheafify_hom_ext _ _ (J.sheafify_is_sheaf _)
(by simp [to_image_presheaf_sheafify]),
inv_hom_id' := begin
rw [← cancel_mono (subpresheaf.ι _), category.id_comp, category.assoc],
refine eq.trans _ (category.comp_id _),
congr' 1,
exact J.sheafify_hom_ext _ _ (J.sheafify_is_sheaf _) (by simp [to_image_presheaf_sheafify]),
apply_instance
end }
-- We need to sheafify
variables {B : Type w} [category.{max u v} B]
[concrete_category.{max u v} B]
[∀ (X : C), limits.has_colimits_of_shape (J.cover X)ᵒᵖ B]
[∀ (P : Cᵒᵖ ⥤ B) (X : C) (S : J.cover X), limits.has_multiequalizer (S.index P)]
[Π (X : C) (W : J.cover X) (P : Cᵒᵖ ⥤ B),
limits.preserves_limit (W.index P).multicospan (forget B)]
[Π (X : C), limits.preserves_colimits_of_shape (J.cover X)ᵒᵖ (forget B)]
[∀ (α β : Type (max u v)) (fst snd : β → α),
limits.has_limits_of_shape (limits.walking_multicospan fst snd) B]
lemma to_sheafify_is_locally_surjective (F : Cᵒᵖ ⥤ B) :
is_locally_surjective J (J.to_sheafify F) :=
begin
rw [is_locally_surjective_iff_whisker_forget, ← to_sheafify_comp_sheafify_comp_iso_inv],
apply is_locally_surjective.comp,
{ rw [is_locally_surjective_iff_image_presheaf_sheafify_eq_top, subpresheaf.eq_top_iff_is_iso],
exact is_iso.of_iso_inv (sheafification_iso_image_presheaf J (F ⋙ forget B)) },
{ exact is_locally_surjective_of_iso _ _ }
end
end
end category_theory
|
919aa39f17ade8cd3a09ad08903554ec9e3b2ceb | e37bb385769d6f4ac9931236fd07b708397e086b | /src/exercises/src_37_completeness_axiom.lean | 71951f963f6da6d9caeba3b93813a2b0b9d7742f | [] | no_license | gihanmarasingha/ems_reals | 5f5d5b9d9dfb5a10da465046336d74995132dff6 | 9df527742db69d0a389add44b506538fdb4d0800 | refs/heads/master | 1,675,327,747,064 | 1,608,036,820,000 | 1,608,036,820,000 | 315,825,726 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,622 | lean | import ..library.src_real_field
import ..library.src_ordered_field_lemmas
import data.set.basic
import tactic
namespace mth1001
namespace myreal
open myreal_field classical myordered_field
open_locale classical
variables {R : Type} [myreal_field R]
def has_upper_bound (S : set R) := ∃ u : R, upper_bound u S
lemma sup_is_sup {S : set R} (h₁ : has_upper_bound S) (h₂ : S ≠ ∅) : is_sup (sup S) S :=
begin
have h₃ : ∃ x : R, is_sup x S, from completeness h₂ h₁,
have h₄ : sup S = some h₃, from dif_pos h₃,
rw h₄,
exact some_spec h₃,
end
-- Exercise 071:
theorem sup_monotone (S T : set R) (h₁ : has_upper_bound S) (h₂ : has_upper_bound T)
(h₃ : S ≠ ∅) (h₄ : T ≠ ∅) : S ⊆ T → sup S ≤ sup T :=
begin
have h₅ : ∀ (v : R), upper_bound v S → sup S ≤ v, from (sup_is_sup h₁ h₃).right,
have h₆ : upper_bound (sup T) T, from (sup_is_sup h₂ h₄).left,
intro k,
sorry
end
-- Exercise 072:
-- The exercise below is rather challenging.
theorem archimedean : ∀ x : R, ∃ n : ℕ, x < n :=
begin
by_contra h,
push_neg at h,
cases h with x hx,
let S := {m : R | ∃ n : ℕ, (m = n) ∧ (x ≥ n)},
have h₁ : ↑1 ∈ S, from ⟨1, rfl, hx 1⟩,
have h₂ : S ≠ ∅,
{ intro h, rw h at h₁, exact h₁, },
have h₃ : has_upper_bound S,
{ use x, rintros _ ⟨_, rfl, xgen⟩, exact xgen, },
have h₄ : is_sup (sup S) S, from sup_is_sup h₃ h₂,
sorry
end
-- Exercise 073:
-- Use `archimedean` and other results (such as `inv_pos` and `inv_lt_inv`) to prove:
theorem inv_lt_of_pos (ε : R) (h : 0 < ε) : ∃ n : ℕ, n ≠ 0 ∧ (↑n)⁻¹ < ε :=
begin
sorry
end
-- Exercise 074:
theorem bounded_iff_abs_lt (S : set R) : bounded S ↔ ∃ m : ℕ, ∀ s ∈ S, abs s < ↑m :=
begin
split,
{ rintro ⟨⟨ub, hub⟩, lb, hlb⟩,
rcases archimedean (max (abs ub) (abs lb)) with ⟨n, hn⟩,
use n,
intros s hs,
unfold abs,
cases max_choice s (-s) with hms hmns,
{ sorry, },
{ rw hmns,
have h₂ : -s ≤ -lb, from neg_le_neg_iff.mpr (hlb s hs),
have h₃ : -lb ≤ abs lb, from neg_le_abs lb,
have h₄ : abs lb ≤ max (abs ub) (abs lb), from le_max_right _ _,
apply lt_of_le_of_lt,
{ exact le_trans _ _ _ h₂ (le_trans _ _ _ h₃ h₄) },
{ exact hn, }, }, },
{ rintro ⟨m, hm⟩,
split,
{ sorry, },
{ use (-m),
intros s hs,
rw [←neg_le_neg_iff, neg_neg],
apply le_trans,
{ exact neg_le_abs s, },
{ exact le_iff_lt_or_eq.mpr (or.inl (hm s hs)), }, }, },
end
end myreal
end mth1001
|
e3cd956b760b44dd5601dfe561712ea77bcda0cf | 1446f520c1db37e157b631385707cc28a17a595e | /src/Init/Lean/Parser/Term.lean | 1c2cf0f467a421dfd13f5bdcec0c73876067a6c4 | [
"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 | 12,845 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Lean.Parser.Parser
import Init.Lean.Parser.Level
namespace Lean
namespace Parser
@[init] def regBuiltinTacticParserAttr : IO Unit :=
let leadingIdentAsSymbol := true;
registerBuiltinParserAttribute `builtinTacticParser `tactic leadingIdentAsSymbol
@[init] def regTacticParserAttribute : IO Unit :=
registerBuiltinDynamicParserAttribute `tacticParser `tactic
@[inline] def tacticParser (rbp : Nat := 0) : Parser :=
categoryParser `tactic rbp
def Tactic.seq : Parser := node `Lean.Parser.Tactic.seq $ sepBy tacticParser "; " true
def Tactic.nonEmptySeq : Parser := node `Lean.Parser.Tactic.seq $ sepBy1 tacticParser "; " true
def darrow : Parser := unicodeSymbol "⇒" "=>"
namespace Term
/- Helper functions for defining simple parsers -/
def unicodeInfixR (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser :=
unicodeSymbol sym asciiSym lbp >> termParser (lbp - 1)
def infixR (sym : String) (lbp : Nat) : TrailingParser :=
symbol sym lbp >> termParser (lbp - 1)
def unicodeInfixL (sym : String) (asciiSym : String) (lbp : Nat) : TrailingParser :=
unicodeSymbol sym asciiSym lbp >> termParser lbp
def infixL (sym : String) (lbp : Nat) : TrailingParser :=
symbol sym lbp >> termParser lbp
def leadPrec := appPrec - 1
/- Built-in parsers -/
-- NOTE: `checkNoWsBefore` should be used *before* `parser!` so that it is also applied to the generated
-- antiquotation.
def explicitUniv := checkNoWsBefore "no space before '.{'" >> parser! ".{" >> sepBy1 levelParser ", " >> "}"
def namedPattern := checkNoWsBefore "no space before '@'" >> parser! "@" >> termParser appPrec
@[builtinTermParser] def id := parser! ident >> optional (explicitUniv <|> namedPattern)
@[builtinTermParser] def num : Parser := parser! numLit
@[builtinTermParser] def str : Parser := parser! strLit
@[builtinTermParser] def char : Parser := parser! charLit
@[builtinTermParser] def type := parser! symbol "Type" appPrec
@[builtinTermParser] def sort := parser! symbol "Sort" appPrec
@[builtinTermParser] def prop := parser! symbol "Prop" appPrec
@[builtinTermParser] def hole := parser! symbol "_" appPrec
@[builtinTermParser] def namedHole := parser! symbol "?" appPrec >> ident
@[builtinTermParser] def «sorry» := parser! symbol "sorry" appPrec
@[builtinTermParser] def cdot := parser! symbol "·" appPrec
@[builtinTermParser] def emptyC := parser! symbol "∅" appPrec
def typeAscription := parser! " : " >> termParser
def tupleTail := parser! ", " >> sepBy1 termParser ", "
def parenSpecial : Parser := optional (tupleTail <|> typeAscription)
@[builtinTermParser] def paren := parser! symbol "(" appPrec >> optional (termParser >> parenSpecial) >> ")"
@[builtinTermParser] def anonymousCtor := parser! symbol "⟨" appPrec >> sepBy termParser ", " >> "⟩"
def optIdent : Parser := optional (try (ident >> " : "))
@[builtinTermParser] def «if» := parser! symbol "if " leadPrec >> optIdent >> termParser >> " then " >> termParser >> " else " >> termParser
def fromTerm := parser! " from " >> termParser
def haveAssign := parser! " := " >> termParser
@[builtinTermParser] def «have» := parser! symbol "have " leadPrec >> optIdent >> termParser >> (haveAssign <|> fromTerm) >> "; " >> termParser
@[builtinTermParser] def «suffices» := parser! symbol "suffices " leadPrec >> optIdent >> termParser >> fromTerm >> "; " >> termParser
@[builtinTermParser] def «show» := parser! symbol "show " leadPrec >> termParser >> fromTerm
def structInstArrayRef := parser! "[" >> termParser >>"]"
def structInstLVal := (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef)
def structInstField := parser! structInstLVal >> " := " >> termParser
def structInstSource := parser! ".." >> optional termParser
@[builtinTermParser] def structInst := parser! symbol "{" appPrec >> optional (try (ident >> checkWsBefore "expected space '.'" >> " . ")) >> sepBy (structInstField <|> structInstSource) ", " true >> "}"
def typeSpec := parser! " : " >> termParser
def optType : Parser := optional typeSpec
@[builtinTermParser] def subtype := parser! "{" >> ident >> optType >> " // " >> termParser >> "}"
@[builtinTermParser] def listLit := parser! symbol "[" appPrec >> sepBy termParser "," true >> "]"
@[builtinTermParser] def arrayLit := parser! symbol "#[" appPrec >> sepBy termParser "," true >> "]"
@[builtinTermParser] def explicit := parser! symbol "@" appPrec >> termParser appPrec
@[builtinTermParser] def inaccessible := parser! symbol ".(" appPrec >> termParser >> ")"
def binderIdent : Parser := ident <|> hole
def binderType (requireType := false) : Parser := if requireType then group (" : " >> termParser) else optional (" : " >> termParser)
def binderTactic := parser! try (" := " >> " by ") >> Tactic.nonEmptySeq
def binderDefault := parser! " := " >> termParser
def explicitBinder (requireType := false) := parser! "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")"
def implicitBinder (requireType := false) := parser! "{" >> many1 binderIdent >> binderType requireType >> "}"
def instBinder := parser! "[" >> optIdent >> termParser >> "]"
def bracktedBinder (requireType := false) := explicitBinder requireType <|> implicitBinder requireType <|> instBinder
@[builtinTermParser] def depArrow := parser! bracktedBinder true >> checkRBPGreater 25 "expected parentheses around dependent arrow" >> unicodeSymbol " → " " -> " >> termParser
def simpleBinder := parser! many1 binderIdent
@[builtinTermParser] def «forall» := parser! unicodeSymbol "∀" "forall" leadPrec >> many1 (simpleBinder <|> bracktedBinder) >> ", " >> termParser
def funBinder : Parser := implicitBinder <|> instBinder <|> termParser appPrec
@[builtinTermParser] def «fun» := parser! unicodeSymbol "λ" "fun" leadPrec >> many1 funBinder >> darrow >> termParser
def matchAlt : Parser :=
nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $
sepBy1 termParser ", " >> darrow >> termParser
def matchAlts (optionalFirstBar := true) : Parser :=
withPosition $ fun pos =>
(if optionalFirstBar then optional "|" else "|") >>
sepBy1 matchAlt (checkColGe pos.column "alternatives must be indented" >> "|")
@[builtinTermParser] def «match» := parser! symbol "match " leadPrec >> sepBy1 termParser ", " >> optType >> " with " >> matchAlts
@[builtinTermParser] def «nomatch» := parser! symbol "nomatch " leadPrec >> termParser
@[builtinTermParser] def «parser!» := parser! symbol "parser! " leadPrec >> termParser
@[builtinTermParser] def «tparser!» := parser! symbol "tparser! " leadPrec >> termParser
@[builtinTermParser] def borrowed := parser! symbol "@&" appPrec >> termParser (appPrec - 1)
@[builtinTermParser] def quotedName := parser! nameLit
-- NOTE: syntax quotations are defined in Init.Lean.Parser.Command
@[builtinTermParser] def «match_syntax» := parser! symbol "match_syntax" leadPrec >> termParser >> " with " >> matchAlts
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many bracktedBinder >> optType
def letIdDecl : Parser := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl $ try (letIdLhs >> " := ") >> termParser
def letPatDecl : Parser := node `Lean.Parser.Term.letDecl $ try (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl : Parser := node `Lean.Parser.Term.letDecl $ letIdLhs >> matchAlts false
def letDecl := letIdDecl <|> letPatDecl <|> letEqnsDecl
@[builtinTermParser] def «let» := parser! symbol "let " leadPrec >> letDecl >> "; " >> termParser
@[builtinTermParser] def «let!» := parser! symbol "let! " leadPrec >> letDecl >> "; " >> termParser
def leftArrow : Parser := unicodeSymbol " ← " " <- "
def doLet := parser! "let " >> letDecl
def doId := parser! try (ident >> optType >> leftArrow) >> termParser
def doPat := parser! try (termParser >> leftArrow) >> termParser >> optional (" | " >> termParser)
def doExpr := parser! termParser
def doElem := doLet <|> doId <|> doPat <|> doExpr
def doSeq := sepBy1 doElem "; "
def bracketedDoSeq := parser! "{" >> doSeq >> "}"
@[builtinTermParser] def liftMethod := parser! leftArrow >> termParser
@[builtinTermParser] def «do» := parser! symbol "do " leadPrec >> (bracketedDoSeq <|> doSeq)
@[builtinTermParser] def not := parser! symbol "¬" appPrec >> termParser 40
@[builtinTermParser] def bnot := parser! symbol "!" appPrec >> termParser 40
@[builtinTermParser] def uminus := parser! "-" >> termParser 100
def namedArgument := parser! try ("(" >> ident >> " := ") >> termParser >> ")"
@[builtinTermParser] def app := tparser! many1 (namedArgument <|> termParser appPrec)
def checkIsSort := checkStackTop (fun stx => stx.isOfKind `Lean.Parser.Term.type || stx.isOfKind `Lean.Parser.Term.sort)
@[builtinTermParser] def sortApp := tparser! checkIsSort >> levelParser appPrec
@[builtinTermParser] def proj := tparser! symbolNoWs "." (appPrec+1) >> (fieldIdx <|> ident)
@[builtinTermParser] def arrow := tparser! unicodeInfixR " → " " -> " 25
@[builtinTermParser] def arrayRef := tparser! symbolNoWs "[" (appPrec+1) >> termParser >>"]"
@[builtinTermParser] def dollar := tparser! try (dollarSymbol >> checkWsBefore "space expected") >> termParser 0
@[builtinTermParser] def dollarProj := tparser! symbol "$." 1 >> (fieldIdx <|> ident)
@[builtinTermParser] def «where» := tparser! symbol " where " 1 >> sepBy1 letDecl (group ("; " >> " where "))
@[builtinTermParser] def fcomp := tparser! infixR " ∘ " 90
@[builtinTermParser] def prod := tparser! infixR " × " 35
@[builtinTermParser] def add := tparser! infixL " + " 65
@[builtinTermParser] def sub := tparser! infixL " - " 65
@[builtinTermParser] def mul := tparser! infixL " * " 70
@[builtinTermParser] def div := tparser! infixL " / " 70
@[builtinTermParser] def mod := tparser! infixL " % " 70
@[builtinTermParser] def modN := tparser! infixL " %ₙ " 70
@[builtinTermParser] def pow := tparser! infixR " ^ " 80
@[builtinTermParser] def le := tparser! unicodeInfixL " ≤ " " <= " 50
@[builtinTermParser] def ge := tparser! unicodeInfixL " ≥ " " >= " 50
@[builtinTermParser] def lt := tparser! infixL " < " 50
@[builtinTermParser] def gt := tparser! infixL " > " 50
@[builtinTermParser] def eq := tparser! infixL " = " 50
@[builtinTermParser] def ne := tparser! infixL " ≠ " 50
@[builtinTermParser] def beq := tparser! infixL " == " 50
@[builtinTermParser] def bne := tparser! infixL " != " 50
@[builtinTermParser] def heq := tparser! unicodeInfixL " ≅ " " ~= " 50
@[builtinTermParser] def equiv := tparser! infixL " ≈ " 50
@[builtinTermParser] def subst := tparser! symbol " ▸ " 75 >> sepBy1 (termParser 75) " ▸ "
@[builtinTermParser] def and := tparser! unicodeInfixR " ∧ " " /\\ " 35
@[builtinTermParser] def or := tparser! unicodeInfixR " ∨ " " \\/ " 30
@[builtinTermParser] def iff := tparser! unicodeInfixL " ↔ " " <-> " 20
@[builtinTermParser] def band := tparser! infixL " && " 35
@[builtinTermParser] def bor := tparser! infixL " || " 30
@[builtinTermParser] def append := tparser! infixL " ++ " 65
@[builtinTermParser] def cons := tparser! infixR " :: " 67
@[builtinTermParser] def orelse := tparser! infixR " <|> " 2
@[builtinTermParser] def orM := tparser! infixR " <||> " 30
@[builtinTermParser] def andM := tparser! infixR " <&&> " 35
@[builtinTermParser] def andthen := tparser! infixR " >> " 60
@[builtinTermParser] def bindOp := tparser! infixR " >>= " 55
@[builtinTermParser] def mapRev := tparser! infixR " <&> " 100
@[builtinTermParser] def seq := tparser! infixL " <*> " 60
@[builtinTermParser] def seqLeft := tparser! infixL " <* " 60
@[builtinTermParser] def seqRight := tparser! infixR " *> " 60
@[builtinTermParser] def map := tparser! infixR " <$> " 100
@[builtinTermParser] def mapConst := tparser! infixR " <$ " 100
@[builtinTermParser] def mapConstRev := tparser! infixR " $> " 100
@[builtinTermParser] def tacticBlock := parser! symbol "begin " appPrec >> Tactic.seq >> "end"
@[builtinTermParser] def byTactic := parser! symbol "by " leadPrec >> Tactic.nonEmptySeq
-- Use `unboxSingleton` trick similar to the one used at Command.lean for `Term.stxQuot`
@[builtinTermParser] def tacticStxQuot : Parser := node `Lean.Parser.Term.stxQuot $ symbol "`(tactic|" appPrec >> sepBy1 tacticParser "; " true true >> ")"
end Term
end Parser
end Lean
|
148984e762c2c9a42502bb00dfe49ca0c426c25e | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/tactic/tidy.lean | 0898314626bffa963933c58894030f9ae8308ed3 | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 4,435 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import tactic.ext
import tactic.auto_cases
import tactic.chain
import tactic.solve_by_elim
import tactic.norm_cast
import tactic.hint
import tactic.interactive
namespace tactic
namespace tidy
/-- Tag interactive tactics (locally) with `[tidy]` to add them to the list of default tactics
called by `tidy`. -/
meta def tidy_attribute : user_attribute := {
name := `tidy,
descr := "A tactic that should be called by `tidy`."
}
add_tactic_doc
{ name := "tidy",
category := doc_category.attr,
decl_names := [`tactic.tidy.tidy_attribute],
tags := ["search"] }
run_cmd attribute.register ``tidy_attribute
meta def run_tactics : tactic string :=
do names ← attribute.get_instances `tidy,
first (names.map name_to_tactic) <|> fail "no @[tidy] tactics succeeded"
@[hint_tactic]
meta def ext1_wrapper : tactic string :=
do ng ← num_goals,
ext1 [] {apply_cfg . new_goals := new_goals.all},
ng' ← num_goals,
return $ if ng' > ng then
"tactic.ext1 [] {new_goals := tactic.new_goals.all}"
else "ext1"
meta def default_tactics : list (tactic string) :=
[ reflexivity >> pure "refl",
`[exact dec_trivial] >> pure "exact dec_trivial",
propositional_goal >> assumption >> pure "assumption",
intros1 >>= λ ns, pure ("intros " ++ (" ".intercalate (ns.map (λ e, e.to_string)))),
auto_cases,
`[apply_auto_param] >> pure "apply_auto_param",
`[dsimp at *] >> pure "dsimp at *",
`[simp at *] >> pure "simp at *",
ext1_wrapper,
fsplit >> pure "fsplit",
injections_and_clear >> pure "injections_and_clear",
propositional_goal >> (`[solve_by_elim]) >> pure "solve_by_elim",
`[norm_cast] >> pure "norm_cast",
`[unfold_coes] >> pure "unfold_coes",
`[unfold_aux] >> pure "unfold_aux",
tidy.run_tactics ]
meta structure cfg :=
(trace_result : bool := ff)
(trace_result_prefix : string := "Try this: ")
(tactics : list (tactic string) := default_tactics)
declare_trace tidy
meta def core (cfg : cfg := {}) : tactic (list string) :=
do
results ← chain cfg.tactics,
when (cfg.trace_result) $
trace (cfg.trace_result_prefix ++ (", ".intercalate results)),
return results
end tidy
meta def tidy (cfg : tidy.cfg := {}) := tactic.tidy.core cfg >> skip
namespace interactive
open lean.parser interactive
/-- Use a variety of conservative tactics to solve goals.
`tidy?` reports back the tactic script it found. As an example
```lean
example : ∀ x : unit, x = unit.star :=
begin
tidy? -- Prints the trace message: "Try this: intros x, exact dec_trivial"
end
```
The default list of tactics is stored in `tactic.tidy.default_tidy_tactics`.
This list can be overridden using `tidy { tactics := ... }`.
(The list must be a `list` of `tactic string`, so that `tidy?`
can report a usable tactic script.)
Tactics can also be added to the list by tagging them (locally) with the
`[tidy]` attribute. -/
meta def tidy (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :=
tactic.tidy { trace_result := trace.is_some, ..cfg }
end interactive
add_tactic_doc
{ name := "tidy",
category := doc_category.tactic,
decl_names := [`tactic.interactive.tidy],
tags := ["search", "Try this", "finishing"] }
/-- Invoking the hole command `tidy` ("Use `tidy` to complete the goal") runs the tactic of
the same name, replacing the hole with the tactic script `tidy` produces.
-/
@[hole_command] meta def tidy_hole_cmd : hole_command :=
{ name := "tidy",
descr := "Use `tidy` to complete the goal.",
action := λ _, do script ← tidy.core,
return [("begin " ++ (", ".intercalate script) ++ " end", "by tidy")] }
add_tactic_doc
{ name := "tidy",
category := doc_category.hole_cmd,
decl_names := [`tactic.tidy_hole_cmd],
tags := ["search"] }
end tactic
|
c07a90c7a1efbe3152c19475a1ba07a4dd477d56 | 90bd8c2a52dbaaba588bdab57b155a7ec1532de0 | /src/homotopy/lift.lean | 8baf95083c070e3d24a7877c5e852508d0b7bef2 | [
"Apache-2.0"
] | permissive | shingtaklam1324/alg-top | fd434f1478925a232af45f18f370ee3a22811c54 | 4c88e28df6f0a329f26eab32bae023789193990e | refs/heads/master | 1,689,447,024,947 | 1,630,073,400,000 | 1,630,073,400,000 | 381,528,689 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 345 | lean | import homotopy.basic
import covering_space.lift
variables {X X' Y : Type _} [topological_space X] [topological_space X'] [topological_space Y]
open_locale unit_interval
example (p : C(X', X)) (hp : is_covering_map p) (f₀ f₁ : C(Y, X)) (H : homotopy f₀ f₁) (f₀' : C(Y, X'))
(hf₀' : p.comp f₀' = f₀) : C(Y × I, X) :=
sorry
|
78b923f076a2fc027e74034a2b7ab3d62b07a1ff | f68c8823d8ddc719de8a4513815174aa7408ac4a | /lean_resolutions/PUZ134_2.lean | 2eb8b5d6bf624606dfd5ff29eee7e8425d577b60 | [] | no_license | FredsoNerd/tptp-lean-puzzles | e7ea66a0de9aa3cb7cc7480299f01adf885440a6 | 43d4d77524e797a4ac7a62b2cfaf8df08b409815 | refs/heads/master | 1,606,359,611,765 | 1,576,824,274,000 | 1,576,824,274,000 | 228,945,807 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,217 | lean | ------------------------------------------------------------------------------
-- File : PUZ134_2 : TPTP v7.3.0. Released v5.1.0.
-- Domain : Puzzles
-- Problem : The Knowheyan Job Puzzle - Ages
-- Version : Especial.
-- English : Five Knowheyans, A, B, C, D, and E, work in Metropolisas Airfoil
-- Technician, Communications Consultant, Space Planner, Lunar Energy
-- Engineer, and Synthetic Food Nutrionist. No two of them are the
-- same age. The Knowheyan interpreter explains about the jobs and
-- ages of these five inhabitants, as follows:
-- 1. The Communications Consultant is not younger than any of the
-- other four.
-- 2. D is not as old as A and not as young as B, who is not as old
-- as the Lunar Energy Engineer, but not as young as C.
-- 3. The Airfoil Technician is not younger than the Space Planner,
-- who is not younger than the Synthetic Food Nutrionist.
-- 4. C is not the yougest of the five.
-- What is the age order of the five Knowheyans?
-- Refs : [WS+06] Willis et al. (2006), The World's Biggest Book of Brai
-- Source : [TPTP]
--------------------------------------------------------------------------------
variable knowheyan: Type
variable job: Type
variable age: Type
variable age_of: knowheyan → age
variable job_of: knowheyan → job
variable greater: age × age → Prop
variable a: knowheyan
variable b: knowheyan
variable c: knowheyan
variable d: knowheyan
variable e: knowheyan
-- axioms
variable a_not_b : a ≠ b
variable a_not_c : a ≠ c
variable a_not_d : a ≠ d
variable a_not_e : a ≠ e
variable b_not_c : b ≠ c
variable b_not_d : b ≠ d
variable b_not_e : b ≠ e
variable c_not_d : c ≠ d
variable c_not_e : c ≠ e
variable d_not_e : d ≠ e
variable airfoil_technician: job
variable communications_consultant: job
variable space_planner: job
variable lunar_energy_engineer: job
variable synthetic_food_nutitionist: job
variable airfoil_technician_not_communications_consultant:
airfoil_technician ≠ communications_consultant
variable airfoil_technician_not_space_planner:
airfoil_technician ≠ space_planner
variable airfoil_technician_not_lunar_energy_engineer:
airfoil_technician ≠ lunar_energy_engineer
variable airfoil_technician_not_synthetic_food_nutitionist:
airfoil_technician ≠ synthetic_food_nutitionist
variable communications_consultant_not_space_planner:
communications_consultant ≠ space_planner
variable communications_consultant_not_lunar_energy_engineer:
communications_consultant ≠ lunar_energy_engineer
variable communications_consultant_not_synthetic_food_nutitionist:
communications_consultant ≠ synthetic_food_nutitionist
variable space_planner_not_lunar_energy_engineer:
space_planner ≠ lunar_energy_engineer
variable space_planner_not_synthetic_food_nutitionist:
space_planner ≠ synthetic_food_nutitionist
variable lunar_energy_engineer_not_synthetic_food_nutitionist:
lunar_energy_engineer ≠ synthetic_food_nutitionist
variable only_knowheyans:
∀ (X: knowheyan) ,
( X = a
∨ X = b
∨ X = c
∨ X = d
∨ X = e )
variable only_jobs:
∀ (X: job) ,
( X = airfoil_technician
∨ X = communications_consultant
∨ X = space_planner
∨ X = lunar_energy_engineer
∨ X = synthetic_food_nutitionist )
variable unique_ages:
∀ (X: knowheyan) (Y: knowheyan) ,
( X ≠ Y
→ age_of(X) ≠ age_of(Y) )
variable unique_jobs:
∀ (X: knowheyan) (Y: knowheyan) ,
( X ≠ Y
→ job_of(X) ≠ job_of(Y) )
variable age_transitive:
∀ (X: age) (Y: age) (Z: age) ,
( ( greater(X,Y)
∧ greater(Y,Z) )
→ greater(X,Z) )
variable age_irreflexive:
∀ (X: age)(Y: age) ,
¬ ( greater(X,Y)
∧ greater(Y,X) )
variable age_greater:
∀ (X: age)(Y: age) ,
( X ≠ Y
↔ ( greater(X,Y)
∨ greater(Y,X) ) )
variable communications_consultant_not_younger:
∀ (X: knowheyan) ,
( job_of(X) = communications_consultant
→ ¬ ∃ (Y: knowheyan) , greater(age_of(Y),age_of(X)) )
variable age_info1:
greater(age_of(a),age_of(d))
variable age_info2:
greater(age_of(d),age_of(b))
variable age_info3:
∀ (X: knowheyan) ,
( job_of(X) = lunar_energy_engineer
→ greater(age_of(X),age_of(b)) )
variable age_info4:
greater(age_of(b),age_of(c))
variable age_job1:
∀ (X: knowheyan) (Y: knowheyan) ,
( ( job_of(X) = airfoil_technician
∧ job_of(Y) = space_planner )
→ greater(age_of(X),age_of(Y)) )
variable age_job2:
∀ (X: knowheyan) (Y: knowheyan) ,
( ( job_of(X) = space_planner
∧ job_of(Y) = synthetic_food_nutitionist )
∧ greater(age_of(X),age_of(Y)) )
variable c_not_youngest:
∃ (X: knowheyan) , greater(age_of(c),age_of(X))
-- conjecture : age_order
theorem age_order :
( greater(age_of(a),age_of(d))
∧ greater(age_of(d),age_of(b))
∧ greater(age_of(b),age_of(c))
∧ greater(age_of(c),age_of(e)) ) := sorry
|
51f01e33fdeeae1f81820b4e1ee4c6f8cc05224d | 8f209eb34c0c4b9b6be5e518ebfc767a38bed79c | /code/src/internal/result.lean | 2f50d6f6ce79b10ac80c02b59fb084cd719eee86 | [] | no_license | hediet/masters-thesis | 13e3bcacb6227f25f7ec4691fb78cb0363f2dfb5 | dc40c14cc4ed073673615412f36b4e386ee7aac9 | refs/heads/master | 1,680,591,056,302 | 1,617,710,887,000 | 1,617,710,887,000 | 311,762,038 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 730 | lean | import tactic
import data.bool
import ..definitions
import .internal_definitions
variable [GuardModule]
open GuardModule
@[simp]
lemma Result.is_match_tt_neq_no_match { α: Type } (r: Result α): r.is_match = tt ↔ r ≠ Result.no_match :=
by cases r; simp [Result.is_match]
@[simp]
lemma Result.is_match_ff_neq_no_match { α: Type } (r: Result α): r.is_match = ff ↔ r = Result.no_match :=
by cases r; simp [Result.is_match]
@[simp]
lemma Result.is_match_neq_no_match { α: Type } (r: Result α): r.is_match ↔ r ≠ Result.no_match :=
by cases r; simp [Result.is_match]
@[simp]
lemma Result.not_is_match_eq_no_match { α: Type } (r: Result α): !r.is_match ↔ r = Result.no_match :=
by cases r; simp [Result.is_match]
|
fa86b04f58f94509cec367ecd8637be80f3d680d | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/measure_theory/lattice.lean | 46576ba07dbdf39fd7ede6e896ca91850a0ddd30 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 7,878 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import measure_theory.measure.ae_measurable
/-!
# Typeclasses for measurability of lattice operations
In this file we define classes `has_measurable_sup` and `has_measurable_inf` and prove dot-style
lemmas (`measurable.sup`, `ae_measurable.sup` etc). For binary operations we define two typeclasses:
- `has_measurable_sup` says that both left and right sup are measurable;
- `has_measurable_sup₂` says that `λ p : α × α, p.1 ⊔ p.2` is measurable,
and similarly for other binary operations. The reason for introducing these classes is that in case
of topological space `α` equipped with the Borel `σ`-algebra, instances for `has_measurable_sup₂`
etc require `α` to have a second countable topology.
For instances relating, e.g., `has_continuous_sup` to `has_measurable_sup` see file
`measure_theory.borel_space`.
## Tags
measurable function, lattice operation
-/
open measure_theory
/-- We say that a type `has_measurable_sup` if `((⊔) c)` and `(⊔ c)` are measurable functions.
For a typeclass assuming measurability of `uncurry (⊔)` see `has_measurable_sup₂`. -/
class has_measurable_sup (M : Type*) [measurable_space M] [has_sup M] : Prop :=
(measurable_const_sup : ∀ c : M, measurable ((⊔) c))
(measurable_sup_const : ∀ c : M, measurable (⊔ c))
/-- We say that a type `has_measurable_sup₂` if `uncurry (⊔)` is a measurable functions.
For a typeclass assuming measurability of `((⊔) c)` and `(⊔ c)` see `has_measurable_sup`. -/
class has_measurable_sup₂ (M : Type*) [measurable_space M] [has_sup M] : Prop :=
(measurable_sup : measurable (λ p : M × M, p.1 ⊔ p.2))
export has_measurable_sup₂ (measurable_sup)
has_measurable_sup (measurable_const_sup measurable_sup_const)
/-- We say that a type `has_measurable_inf` if `((⊓) c)` and `(⊓ c)` are measurable functions.
For a typeclass assuming measurability of `uncurry (⊓)` see `has_measurable_inf₂`. -/
class has_measurable_inf (M : Type*) [measurable_space M] [has_inf M] : Prop :=
(measurable_const_inf : ∀ c : M, measurable ((⊓) c))
(measurable_inf_const : ∀ c : M, measurable (⊓ c))
/-- We say that a type `has_measurable_inf₂` if `uncurry (⊔)` is a measurable functions.
For a typeclass assuming measurability of `((⊔) c)` and `(⊔ c)` see `has_measurable_inf`. -/
class has_measurable_inf₂ (M : Type*) [measurable_space M] [has_inf M] : Prop :=
(measurable_inf : measurable (λ p : M × M, p.1 ⊓ p.2))
export has_measurable_inf₂ (measurable_inf)
has_measurable_inf (measurable_const_inf measurable_inf_const)
variables {M : Type*} [measurable_space M]
section order_dual
@[priority 100]
instance [has_inf M] [has_measurable_inf M] : has_measurable_sup Mᵒᵈ :=
⟨@measurable_const_inf M _ _ _, @measurable_inf_const M _ _ _⟩
@[priority 100]
instance [has_sup M] [has_measurable_sup M] : has_measurable_inf Mᵒᵈ :=
⟨@measurable_const_sup M _ _ _, @measurable_sup_const M _ _ _⟩
@[priority 100]
instance [has_inf M] [has_measurable_inf₂ M] : has_measurable_sup₂ Mᵒᵈ :=
⟨@measurable_inf M _ _ _⟩
@[priority 100]
instance [has_sup M] [has_measurable_sup₂ M] : has_measurable_inf₂ Mᵒᵈ :=
⟨@measurable_sup M _ _ _⟩
end order_dual
variables {α : Type*} {m : measurable_space α} {μ : measure α} {f g : α → M}
include m
section sup
variables [has_sup M]
section measurable_sup
variables [has_measurable_sup M]
@[measurability]
lemma measurable.const_sup (hf : measurable f) (c : M) : measurable (λ x, c ⊔ f x) :=
(measurable_const_sup c).comp hf
@[measurability]
lemma ae_measurable.const_sup (hf : ae_measurable f μ) (c : M) : ae_measurable (λ x, c ⊔ f x) μ :=
(has_measurable_sup.measurable_const_sup c).comp_ae_measurable hf
@[measurability]
lemma measurable.sup_const (hf : measurable f) (c : M) : measurable (λ x, f x ⊔ c) :=
(measurable_sup_const c).comp hf
@[measurability]
lemma ae_measurable.sup_const (hf : ae_measurable f μ) (c : M) :
ae_measurable (λ x, f x ⊔ c) μ :=
(measurable_sup_const c).comp_ae_measurable hf
end measurable_sup
section measurable_sup₂
variables [has_measurable_sup₂ M]
@[measurability]
lemma measurable.sup' (hf : measurable f) (hg : measurable g) : measurable (f ⊔ g) :=
measurable_sup.comp (hf.prod_mk hg)
@[measurability]
lemma measurable.sup (hf : measurable f) (hg : measurable g) : measurable (λ a, f a ⊔ g a) :=
measurable_sup.comp (hf.prod_mk hg)
@[measurability]
lemma ae_measurable.sup' (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (f ⊔ g) μ :=
measurable_sup.comp_ae_measurable (hf.prod_mk hg)
@[measurability]
lemma ae_measurable.sup (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (λ a, f a ⊔ g a) μ :=
measurable_sup.comp_ae_measurable (hf.prod_mk hg)
omit m
@[priority 100]
instance has_measurable_sup₂.to_has_measurable_sup : has_measurable_sup M :=
⟨λ c, measurable_const.sup measurable_id, λ c, measurable_id.sup measurable_const⟩
include m
end measurable_sup₂
end sup
section inf
variables [has_inf M]
section measurable_inf
variables [has_measurable_inf M]
@[measurability]
lemma measurable.const_inf (hf : measurable f) (c : M) :
measurable (λ x, c ⊓ f x) :=
(measurable_const_inf c).comp hf
@[measurability]
lemma ae_measurable.const_inf (hf : ae_measurable f μ) (c : M) :
ae_measurable (λ x, c ⊓ f x) μ :=
(has_measurable_inf.measurable_const_inf c).comp_ae_measurable hf
@[measurability]
lemma measurable.inf_const (hf : measurable f) (c : M) :
measurable (λ x, f x ⊓ c) :=
(measurable_inf_const c).comp hf
@[measurability]
lemma ae_measurable.inf_const (hf : ae_measurable f μ) (c : M) :
ae_measurable (λ x, f x ⊓ c) μ :=
(measurable_inf_const c).comp_ae_measurable hf
end measurable_inf
section measurable_inf₂
variables [has_measurable_inf₂ M]
@[measurability]
lemma measurable.inf' (hf : measurable f) (hg : measurable g) : measurable (f ⊓ g) :=
measurable_inf.comp (hf.prod_mk hg)
@[measurability]
lemma measurable.inf (hf : measurable f) (hg : measurable g) : measurable (λ a, f a ⊓ g a) :=
measurable_inf.comp (hf.prod_mk hg)
@[measurability]
lemma ae_measurable.inf' (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (f ⊓ g) μ :=
measurable_inf.comp_ae_measurable (hf.prod_mk hg)
@[measurability]
lemma ae_measurable.inf (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (λ a, f a ⊓ g a) μ :=
measurable_inf.comp_ae_measurable (hf.prod_mk hg)
omit m
@[priority 100]
instance has_measurable_inf₂.to_has_measurable_inf : has_measurable_inf M :=
⟨λ c, measurable_const.inf measurable_id, λ c, measurable_id.inf measurable_const⟩
include m
end measurable_inf₂
end inf
section semilattice_sup
open finset
variables {δ : Type*} [measurable_space δ] [semilattice_sup α] [has_measurable_sup₂ α]
@[measurability] lemma finset.measurable_sup' {ι : Type*} {s : finset ι} (hs : s.nonempty)
{f : ι → δ → α} (hf : ∀ n ∈ s, measurable (f n)) :
measurable (s.sup' hs f) :=
finset.sup'_induction hs _ (λ f hf g hg, hf.sup hg) (λ n hn, hf n hn)
@[measurability] lemma finset.measurable_range_sup'
{f : ℕ → δ → α} {n : ℕ} (hf : ∀ k ≤ n, measurable (f k)) :
measurable ((range (n + 1)).sup' nonempty_range_succ f) :=
begin
simp_rw ← nat.lt_succ_iff at hf,
refine finset.measurable_sup' _ _,
simpa [finset.mem_range],
end
@[measurability] lemma finset.measurable_range_sup''
{f : ℕ → δ → α} {n : ℕ} (hf : ∀ k ≤ n, measurable (f k)) :
measurable (λ x, (range (n + 1)).sup' nonempty_range_succ (λ k, f k x)) :=
begin
convert finset.measurable_range_sup' hf,
ext x,
simp,
end
end semilattice_sup
|
1f6f35c34fdc5a3bfea2009f2ef2ae542ffcb56d | bb31430994044506fa42fd667e2d556327e18dfe | /src/data/finset/sups.lean | 97f93b29855e2f66491b1161fc50b3b51a8c412d | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 12,969 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.n_ary
/-!
# Set family operations
This file defines a few binary operations on `finset α` for use in set family combinatorics.
## Main declarations
* `finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`.
* `finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`.
* `finset.disj_sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a`
and `b` are disjoint.
## Notation
We define the following notation in locale `finset_family`:
* `s ⊻ t` for `finset.sups s t`
* `s ⊼ t` for `finset.infs s t`
* `s ○ t` for `finset.disj_sups s t`
## References
[B. Bollobás, *Combinatorics*][bollobas1986]
-/
open function
variables {α : Type*} [decidable_eq α]
namespace finset
section sups
variables [semilattice_sup α] (s s₁ s₂ t t₁ t₂ u : finset α)
/-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/
def sups (s t : finset α) : finset α := image₂ (⊔) s t
localized "infix (name := finset.sups) ` ⊻ `:74 := finset.sups" in finset_family
variables {s t} {a b c : α}
@[simp] lemma mem_sups : c ∈ s ⊻ t ↔ ∃ (a ∈ s) (b ∈ t), a ⊔ b = c := by simp [sups]
variables (s t)
@[simp, norm_cast] lemma coe_sups : (s ⊻ t : set α) = set.image2 (⊔) s t := coe_image₂ _ _ _
lemma card_sups_le : (s ⊻ t).card ≤ s.card * t.card := card_image₂_le _ _ _
lemma card_sups_iff :
(s ⊻ t).card = s.card * t.card ↔ (s ×ˢ t : set (α × α)).inj_on (λ x, x.1 ⊔ x.2) :=
card_image₂_iff
variables {s s₁ s₂ t t₁ t₂ u}
lemma sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t := mem_image₂_of_mem
lemma sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ := image₂_subset
lemma sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ := image₂_subset_left
lemma sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t := image₂_subset_right
lemma image_subset_sups_left : b ∈ t → (λ a, a ⊔ b) '' s ⊆ s ⊻ t := image_subset_image₂_left
lemma image_subset_sups_right : a ∈ s → (⊔) a '' t ⊆ s ⊻ t := image_subset_image₂_right
lemma forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ (a ∈ s) (b ∈ t), p (a ⊔ b) :=
forall_image₂_iff
@[simp] lemma sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ (a ∈ s) (b ∈ t), a ⊔ b ∈ u := image₂_subset_iff
@[simp] lemma sups_nonempty_iff : (s ⊻ t).nonempty ↔ s.nonempty ∧ t.nonempty := image₂_nonempty_iff
lemma nonempty.sups : s.nonempty → t.nonempty → (s ⊻ t).nonempty := nonempty.image₂
lemma nonempty.of_sups_left : (s ⊻ t).nonempty → s.nonempty := nonempty.of_image₂_left
lemma nonempty.of_sups_right : (s ⊻ t).nonempty → t.nonempty := nonempty.of_image₂_right
@[simp] lemma sups_empty_left : ∅ ⊻ t = ∅ := image₂_empty_left
@[simp] lemma sups_empty_right : s ⊻ ∅ = ∅ := image₂_empty_right
@[simp] lemma sups_eq_empty_iff : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff
@[simp] lemma sups_singleton_left : {a} ⊻ t = t.image (λ b, a ⊔ b) := image₂_singleton_left
@[simp] lemma sups_singleton_right : s ⊻ {b} = s.image (λ a, a ⊔ b) := image₂_singleton_right
lemma sups_singleton_left' : {a} ⊻ t = t.image ((⊔) a) := image₂_singleton_left'
lemma sups_singleton : ({a} ⊻ {b} : finset α) = {a ⊔ b} := image₂_singleton
lemma sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t := image₂_union_left
lemma sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ := image₂_union_right
lemma sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t := image₂_inter_subset_left
lemma sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ := image₂_inter_subset_right
lemma subset_sups {s t : set α} :
↑u ⊆ set.image2 (⊔) s t → ∃ s' t' : finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' :=
subset_image₂
variables (s t u)
lemma bUnion_image_sup_left : s.bUnion (λ a, t.image $ (⊔) a) = s ⊻ t := bUnion_image_left
lemma bUnion_image_sup_right : t.bUnion (λ b, s.image $ λ a, a ⊔ b) = s ⊻ t := bUnion_image_right
@[simp] lemma image_sup_product (s t : finset α) : (s ×ˢ t).image (uncurry (⊔)) = s ⊻ t :=
image_uncurry_product _ _ _
lemma sups_assoc : (s ⊻ t) ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc $ λ _ _ _, sup_assoc
lemma sups_comm : s ⊻ t = t ⊻ s := image₂_comm $ λ _ _, sup_comm
lemma sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := image₂_left_comm sup_left_comm
lemma sups_right_comm : (s ⊻ t) ⊻ u = (s ⊻ u) ⊻ t := image₂_right_comm sup_right_comm
end sups
section infs
variables [semilattice_inf α] (s s₁ s₂ t t₁ t₂ u : finset α)
/-- The finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/
def infs (s t : finset α) : finset α := image₂ (⊓) s t
localized "infix (name := finset.infs) ` ⊼ `:74 := finset.infs" in finset_family
variables {s t} {a b c : α}
@[simp] lemma mem_infs : c ∈ s ⊼ t ↔ ∃ (a ∈ s) (b ∈ t), a ⊓ b = c := by simp [infs]
variables (s t)
@[simp, norm_cast] lemma coe_infs : (s ⊼ t : set α) = set.image2 (⊓) s t := coe_image₂ _ _ _
lemma card_infs_le : (s ⊼ t).card ≤ s.card * t.card := card_image₂_le _ _ _
lemma card_infs_iff :
(s ⊼ t).card = s.card * t.card ↔ (s ×ˢ t : set (α × α)).inj_on (λ x, x.1 ⊓ x.2) :=
card_image₂_iff
variables {s s₁ s₂ t t₁ t₂ u}
lemma inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t := mem_image₂_of_mem
lemma infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ := image₂_subset
lemma infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ := image₂_subset_left
lemma infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t := image₂_subset_right
lemma image_subset_infs_left : b ∈ t → (λ a, a ⊓ b) '' s ⊆ s ⊼ t := image_subset_image₂_left
lemma image_subset_infs_right : a ∈ s → (⊓) a '' t ⊆ s ⊼ t := image_subset_image₂_right
lemma forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ (a ∈ s) (b ∈ t), p (a ⊓ b) :=
forall_image₂_iff
@[simp] lemma infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ (a ∈ s) (b ∈ t), a ⊓ b ∈ u := image₂_subset_iff
@[simp] lemma infs_nonempty_iff : (s ⊼ t).nonempty ↔ s.nonempty ∧ t.nonempty := image₂_nonempty_iff
lemma nonempty.infs : s.nonempty → t.nonempty → (s ⊼ t).nonempty := nonempty.image₂
lemma nonempty.of_infs_left : (s ⊼ t).nonempty → s.nonempty := nonempty.of_image₂_left
lemma nonempty.of_infs_right : (s ⊼ t).nonempty → t.nonempty := nonempty.of_image₂_right
@[simp] lemma infs_empty_left : ∅ ⊼ t = ∅ := image₂_empty_left
@[simp] lemma infs_empty_right : s ⊼ ∅ = ∅ := image₂_empty_right
@[simp] lemma infs_eq_empty_iff : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ := image₂_eq_empty_iff
@[simp] lemma infs_singleton_left : {a} ⊼ t = t.image (λ b, a ⊓ b) := image₂_singleton_left
@[simp] lemma infs_singleton_right : s ⊼ {b} = s.image (λ a, a ⊓ b) := image₂_singleton_right
lemma infs_singleton_left' : {a} ⊼ t = t.image ((⊓) a) := image₂_singleton_left'
lemma infs_singleton : ({a} ⊼ {b} : finset α) = {a ⊓ b} := image₂_singleton
lemma infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t := image₂_union_left
lemma infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ := image₂_union_right
lemma infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t := image₂_inter_subset_left
lemma infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ := image₂_inter_subset_right
lemma subset_infs {s t : set α} :
↑u ⊆ set.image2 (⊓) s t → ∃ s' t' : finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊼ t' :=
subset_image₂
variables (s t u)
lemma bUnion_image_inf_left : s.bUnion (λ a, t.image $ (⊓) a) = s ⊼ t := bUnion_image_left
lemma bUnion_image_inf_right : t.bUnion (λ b, s.image $ λ a, a ⊓ b) = s ⊼ t := bUnion_image_right
@[simp] lemma image_inf_product (s t : finset α) : (s ×ˢ t).image (uncurry (⊓)) = s ⊼ t :=
image_uncurry_product _ _ _
lemma infs_assoc : (s ⊼ t) ⊼ u = s ⊼ (t ⊼ u) := image₂_assoc $ λ _ _ _, inf_assoc
lemma infs_comm : s ⊼ t = t ⊼ s := image₂_comm $ λ _ _, inf_comm
lemma infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) := image₂_left_comm inf_left_comm
lemma infs_right_comm : (s ⊼ t) ⊼ u = (s ⊼ u) ⊼ t := image₂_right_comm inf_right_comm
end infs
open_locale finset_family
section disj_sups
variables [semilattice_sup α] [order_bot α] [@decidable_rel α disjoint]
(s s₁ s₂ t t₁ t₂ u : finset α)
/-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint.
-/
def disj_sups : finset α :=
((s ×ˢ t).filter $ λ ab : α × α, disjoint ab.1 ab.2).image $ λ ab, ab.1 ⊔ ab.2
localized "infix (name := finset.disj_sups) ` ○ `:74 := finset.disj_sups" in finset_family
variables {s t u} {a b c : α}
@[simp] lemma mem_disj_sups : c ∈ s ○ t ↔ ∃ (a ∈ s) (b ∈ t), disjoint a b ∧ a ⊔ b = c :=
by simp [disj_sups, and_assoc]
lemma disj_sups_subset_sups : s ○ t ⊆ s ⊻ t :=
begin
simp_rw [subset_iff, mem_sups, mem_disj_sups],
exact λ c ⟨a, b, ha, hb, h, hc⟩, ⟨a, b, ha, hb, hc⟩,
end
variables (s t)
lemma card_disj_sups_le : (s ○ t).card ≤ s.card * t.card :=
(card_le_of_subset disj_sups_subset_sups).trans $ card_sups_le _ _
variables {s s₁ s₂ t t₁ t₂ u}
lemma disj_sups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ :=
image_subset_image $ filter_subset_filter _ $ product_subset_product hs ht
lemma disj_sups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ := disj_sups_subset subset.rfl ht
lemma disj_sups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t := disj_sups_subset hs subset.rfl
lemma forall_disj_sups_iff {p : α → Prop} :
(∀ c ∈ s ○ t, p c) ↔ ∀ (a ∈ s) (b ∈ t), disjoint a b → p (a ⊔ b) :=
begin
simp_rw mem_disj_sups,
refine ⟨λ h a ha b hb hab, h _ ⟨_, ha, _, hb, hab, rfl⟩, _⟩,
rintro h _ ⟨a, ha, b, hb, hab, rfl⟩,
exact h _ ha _ hb hab,
end
@[simp] lemma disj_sups_subset_iff : s ○ t ⊆ u ↔ ∀ (a ∈ s) (b ∈ t), disjoint a b → a ⊔ b ∈ u :=
forall_disj_sups_iff
lemma nonempty.of_disj_sups_left : (s ○ t).nonempty → s.nonempty :=
by { simp_rw [finset.nonempty, mem_disj_sups], exact λ ⟨_, a, ha, _⟩, ⟨a, ha⟩ }
lemma nonempty.of_disj_sups_right : (s ○ t).nonempty → t.nonempty :=
by { simp_rw [finset.nonempty, mem_disj_sups], exact λ ⟨_, _, _, b, hb, _⟩, ⟨b, hb⟩ }
@[simp] lemma disj_sups_empty_left : ∅ ○ t = ∅ := by simp [disj_sups]
@[simp] lemma disj_sups_empty_right : s ○ ∅ = ∅ := by simp [disj_sups]
lemma disj_sups_singleton : ({a} ○ {b} : finset α) = if disjoint a b then {a ⊔ b} else ∅ :=
by split_ifs; simp [disj_sups, filter_singleton, h]
lemma disj_sups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t :=
by simp [disj_sups, filter_union, image_union]
lemma disj_sups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ :=
by simp [disj_sups, filter_union, image_union]
lemma disj_sups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t :=
by simpa only [disj_sups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _
lemma disj_sups_inter_subset_right : s ○ (t₁ ∩ t₂) ⊆ s ○ t₁ ∩ s ○ t₂ :=
by simpa only [disj_sups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _
variables (s t)
lemma disj_sups_comm : s ○ t = t ○ s :=
by { ext, rw [mem_disj_sups, exists₂_comm], simp [sup_comm, disjoint.comm] }
end disj_sups
open_locale finset_family
section distrib_lattice
variables [distrib_lattice α] [order_bot α] [@decidable_rel α disjoint] (s t u : finset α)
lemma disj_sups_assoc : ∀ s t u : finset α, (s ○ t) ○ u = s ○ (t ○ u) :=
begin
refine associative_of_commutative_of_le disj_sups_comm _,
simp only [le_eq_subset, disj_sups_subset_iff, mem_disj_sups],
rintro s t u _ ⟨a, ha, b, hb, hab, rfl⟩ c hc habc,
rw disjoint_sup_left at habc,
exact ⟨a, ha, _, ⟨b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, sup_assoc.symm⟩,
end
lemma disj_sups_left_comm : s ○ (t ○ u) = t ○ (s ○ u) :=
by simp_rw [←disj_sups_assoc, disj_sups_comm s]
lemma disj_sups_right_comm : (s ○ t) ○ u = (s ○ u) ○ t :=
by simp_rw [disj_sups_assoc, disj_sups_comm]
end distrib_lattice
end finset
|
4ad0a5459b0c816bbc3d75c7167e32e4e3acfaec | b328e8ebb2ba923140e5137c83f09fa59516b793 | /src/Lean/Meta/Tactic/Intro.lean | 36930ce3086034b74be3e83f42a7c9a9fa7ddaa9 | [
"Apache-2.0"
] | permissive | DrMaxis/lean4 | a781bcc095511687c56ab060e816fd948553e162 | 5a02c4facc0658aad627cfdcc3db203eac0cb544 | refs/heads/master | 1,677,051,517,055 | 1,611,876,226,000 | 1,611,876,226,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,581 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Util
namespace Lean.Meta
@[inline] private partial def introNImp {σ} (mvarId : MVarId) (n : Nat) (mkName : LocalContext → Name → σ → MetaM (Name × σ)) (s : σ)
: MetaM (Array FVarId × MVarId) := withMVarContext mvarId do
checkNotAssigned mvarId `introN
let mvarType ← getMVarType mvarId
let lctx ← getLCtx
let rec @[specialize] loop : Nat → LocalContext → Array Expr → Nat → σ → Expr → MetaM (Array Expr × MVarId)
| 0, lctx, fvars, j, _, type =>
let type := type.instantiateRevRange j fvars.size fvars
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstances fvars j do
let tag ← getMVarTag mvarId
let type := type.headBeta
let newMVar ← mkFreshExprSyntheticOpaqueMVar type tag
let lctx ← getLCtx
let newVal ← mkLambdaFVars fvars newMVar
assignExprMVar mvarId newVal
pure $ (fvars, newMVar.mvarId!)
| (i+1), lctx, fvars, j, s, Expr.letE n type val body _ => do
let type := type.instantiateRevRange j fvars.size fvars
let type := type.headBeta
let val := val.instantiateRevRange j fvars.size fvars
let fvarId ← mkFreshId
let (n, s) ← mkName lctx n s
let lctx := lctx.mkLetDecl fvarId n type val
let fvar := mkFVar fvarId
let fvars := fvars.push fvar
loop i lctx fvars j s body
| (i+1), lctx, fvars, j, s, Expr.forallE n type body c => do
let type := type.instantiateRevRange j fvars.size fvars
let type := type.headBeta
let fvarId ← mkFreshId
let (n, s) ← mkName lctx n s
let lctx := lctx.mkLocalDecl fvarId n type c.binderInfo
let fvar := mkFVar fvarId
let fvars := fvars.push fvar
loop i lctx fvars j s body
| (i+1), lctx, fvars, j, s, type =>
let type := type.instantiateRevRange j fvars.size fvars
withReader (fun ctx => { ctx with lctx := lctx }) do
withNewLocalInstances fvars j do
let newType ← whnf type
if newType.isForall then
loop (i+1) lctx fvars fvars.size s newType
else
throwTacticEx `introN mvarId "insufficient number of binders"
let (fvars, mvarId) ← loop n lctx #[] 0 s mvarType
pure (fvars.map Expr.fvarId!, mvarId)
register_builtin_option hygienicIntro : Bool := {
defValue := true
group := "tactic"
descr := "make sure 'intro'-like tactics are hygienic"
}
def getHygienicIntro : MetaM Bool := do
return hygienicIntro.get (← getOptions)
private def mkAuxNameImp (preserveBinderNames : Bool) (hygienic : Bool) (lctx : LocalContext) (binderName : Name) : List Name → MetaM (Name × List Name)
| [] => do
if preserveBinderNames then
pure (binderName, [])
else if hygienic then do
let binderName ← mkFreshUserName binderName;
pure (binderName, [])
else
pure (lctx.getUnusedName binderName, [])
| n :: rest => do
if n != Name.mkSimple "_" then
pure (n, rest)
else if preserveBinderNames then
pure (binderName, rest)
else if hygienic then
let binderName ← mkFreshUserName binderName
pure (binderName, rest)
else
pure (lctx.getUnusedName binderName, rest)
def introNCore (mvarId : MVarId) (n : Nat) (givenNames : List Name) (preserveBinderNames : Bool) : MetaM (Array FVarId × MVarId) := do
let hygienic ← getHygienicIntro
if n == 0 then
pure (#[], mvarId)
else
introNImp mvarId n (mkAuxNameImp preserveBinderNames hygienic) givenNames
abbrev introN (mvarId : MVarId) (n : Nat) (givenNames : List Name := []) : MetaM (Array FVarId × MVarId) :=
introNCore mvarId n givenNames false
abbrev introNP (mvarId : MVarId) (n : Nat) : MetaM (Array FVarId × MVarId) :=
introNCore mvarId n [] true
def intro (mvarId : MVarId) (name : Name) : MetaM (FVarId × MVarId) := do
let (fvarIds, mvarId) ← introN mvarId 1 [name]
pure (fvarIds.get! 0, mvarId)
def intro1Core (mvarId : MVarId) (preserveBinderNames : Bool) : MetaM (FVarId × MVarId) := do
let (fvarIds, mvarId) ← introNCore mvarId 1 [] preserveBinderNames
pure (fvarIds.get! 0, mvarId)
abbrev intro1 (mvarId : MVarId) : MetaM (FVarId × MVarId) :=
intro1Core mvarId false
abbrev intro1P (mvarId : MVarId) : MetaM (FVarId × MVarId) :=
intro1Core mvarId true
end Lean.Meta
|
2667872c67d774c148cc3e99e139b573883a2bad | 367134ba5a65885e863bdc4507601606690974c1 | /src/order/directed.lean | 80f421af889084f5964cfa4a60e163b13dd7d099 | [
"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 | 3,053 | 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
-/
import order.lattice
import data.set.basic
universes u v w
variables {α : Type u} {β : Type v} {ι : Sort w} (r : α → α → Prop)
local infix ` ≼ ` : 50 := r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def directed (f : ι → α) := ∀x y, ∃z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃z ∈ s, x ≼ z ∧ y ≼ z
variables {r}
theorem directed_on_iff_directed {s} : @directed_on α r s ↔ directed r (coe : s → α) :=
by simp [directed, directed_on]; refine ball_congr (λ x hx, by simp; refl)
alias directed_on_iff_directed ↔ directed_on.directed_coe _
theorem directed_on_image {s} {f : β → α} :
directed_on r (f '' s) ↔ directed_on (f ⁻¹'o r) s :=
by simp only [directed_on, set.ball_image_iff, set.bex_image_iff, order.preimage]
theorem directed_on.mono {s : set α} (h : directed_on r s)
{r' : α → α → Prop} (H : ∀ {a b}, r a b → r' a b) :
directed_on r' s :=
λ x hx y hy, let ⟨z, zs, xz, yz⟩ := h x hx y hy in ⟨z, zs, H xz, H yz⟩
theorem directed_comp {ι} {f : ι → β} {g : β → α} :
directed r (g ∘ f) ↔ directed (g ⁻¹'o r) f := iff.rfl
theorem directed.mono {s : α → α → Prop} {ι} {f : ι → α}
(H : ∀ a b, r a b → s a b) (h : directed r f) : directed s f :=
λ a b, let ⟨c, h₁, h₂⟩ := h a b in ⟨c, H _ _ h₁, H _ _ h₂⟩
theorem directed.mono_comp {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α}
(hg : ∀ ⦃x y⦄, x ≼ y → rb (g x) (g y)) (hf : directed r f) :
directed rb (g ∘ f) :=
directed_comp.2 $ hf.mono hg
/-- A monotone function on a sup-semilattice is directed. -/
lemma directed_of_sup [semilattice_sup α] {f : α → β} {r : β → β → Prop}
(H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : directed r f :=
λ a b, ⟨a ⊔ b, H le_sup_left, H le_sup_right⟩
/-- An antimonotone function on an inf-semilattice is directed. -/
lemma directed_of_inf [semilattice_inf α] {r : β → β → Prop} {f : α → β}
(hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : directed r f :=
assume x y, ⟨x ⊓ y, hf _ _ inf_le_left, hf _ _ inf_le_right⟩
/-- A `preorder` is a `directed_order` if for any two elements `i`, `j`
there is an element `k` such that `i ≤ k` and `j ≤ k`. -/
class directed_order (α : Type u) extends preorder α :=
(directed : ∀ i j : α, ∃ k, i ≤ k ∧ j ≤ k)
@[priority 100] -- see Note [lower instance priority]
instance linear_order.to_directed_order (α) [linear_order α] : directed_order α :=
⟨λ i j, or.cases_on (le_total i j) (λ hij, ⟨j, hij, le_refl j⟩) (λ hji, ⟨i, le_refl i, hji⟩)⟩
|
3c29f5580c6f7440ebe623e7454b092b2f198ab6 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/data/finset/card.lean | 78cff73e3b338975e46a33683007e3426e19967b | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,450 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Cardinality calculations for finite sets.
-/
import .to_set .bigops data.set.function data.nat.power data.nat.bigops
open nat nat.finset eq.ops
namespace finset
variables {A B : Type}
variables [deceqA : decidable_eq A] [deceqB : decidable_eq B]
include deceqA
theorem card_add_card (s₁ s₂ : finset A) : card s₁ + card s₂ = card (s₁ ∪ s₂) + card (s₁ ∩ s₂) :=
begin
induction s₂ with a s₂ ans2 IH,
show card s₁ + card (∅:finset A) = card (s₁ ∪ ∅) + card (s₁ ∩ ∅),
by rewrite [union_empty, card_empty, inter_empty],
show card s₁ + card (insert a s₂) = card (s₁ ∪ (insert a s₂)) + card (s₁ ∩ (insert a s₂)),
from decidable.by_cases
(assume as1 : a ∈ s₁,
assert H : a ∉ s₁ ∩ s₂, from assume H', ans2 (mem_of_mem_inter_right H'),
begin
rewrite [card_insert_of_not_mem ans2, union.comm, -insert_union, union.comm],
rewrite [insert_union, insert_eq_of_mem as1, insert_eq, inter.distrib_left, inter.comm],
rewrite [singleton_inter_of_mem as1, -insert_eq, card_insert_of_not_mem H, -*add.assoc],
rewrite IH
end)
(assume ans1 : a ∉ s₁,
assert H : a ∉ s₁ ∪ s₂, from assume H',
or.elim (mem_or_mem_of_mem_union H') (assume as1, ans1 as1) (assume as2, ans2 as2),
begin
rewrite [card_insert_of_not_mem ans2, union.comm, -insert_union, union.comm],
rewrite [card_insert_of_not_mem H, insert_eq, inter.distrib_left, inter.comm],
rewrite [singleton_inter_of_not_mem ans1, empty_union, add.right_comm],
rewrite [-add.assoc, IH]
end)
end
theorem card_union (s₁ s₂ : finset A) : card (s₁ ∪ s₂) = card s₁ + card s₂ - card (s₁ ∩ s₂) :=
calc
card (s₁ ∪ s₂) = card (s₁ ∪ s₂) + card (s₁ ∩ s₂) - card (s₁ ∩ s₂) : add_sub_cancel
... = card s₁ + card s₂ - card (s₁ ∩ s₂) : card_add_card
theorem card_union_of_disjoint {s₁ s₂ : finset A} (H : s₁ ∩ s₂ = ∅) :
card (s₁ ∪ s₂) = card s₁ + card s₂ :=
by rewrite [card_union, H]
theorem card_eq_card_add_card_diff {s₁ s₂ : finset A} (H : s₁ ⊆ s₂) :
card s₂ = card s₁ + card (s₂ \ s₁) :=
have H1 : s₁ ∩ (s₂ \ s₁) = ∅,
from inter_eq_empty (take x, assume H1 H2, not_mem_of_mem_diff H2 H1),
calc
card s₂ = card (s₁ ∪ (s₂ \ s₁)) : union_diff_cancel H
... = card s₁ + card (s₂ \ s₁) : card_union_of_disjoint H1
theorem card_le_card_of_subset {s₁ s₂ : finset A} (H : s₁ ⊆ s₂) : card s₁ ≤ card s₂ :=
calc
card s₂ = card s₁ + card (s₂ \ s₁) : card_eq_card_add_card_diff H
... ≥ card s₁ : le_add_right
section card_image
open set
include deceqB
theorem card_image_eq_of_inj_on {f : A → B} {s : finset A} (H1 : inj_on f (ts s)) :
card (image f s) = card s :=
begin
induction s with a t H IH,
{ rewrite [card_empty] },
{ have H2 : ts t ⊆ ts (insert a t), by rewrite [-subset_eq_to_set_subset]; apply subset_insert,
have H3 : card (image f t) = card t, from IH (inj_on_of_inj_on_of_subset H1 H2),
have H4 : f a ∉ image f t,
proof
assume H5 : f a ∈ image f t,
obtain x (H6l : x ∈ t) (H6r : f x = f a), from exists_of_mem_image H5,
have H7 : x = a, from H1 (mem_insert_of_mem _ H6l) !mem_insert H6r,
show false, from H (H7 ▸ H6l)
qed,
calc
card (image f (insert a t)) = card (insert (f a) (image f t)) : image_insert
... = card (image f t) + 1 : card_insert_of_not_mem H4
... = card t + 1 : H3
... = card (insert a t) : card_insert_of_not_mem H
}
end
lemma card_le_of_inj_on (a : finset A) (b : finset B)
(Pex : ∃ f : A → B, set.inj_on f (ts a) ∧ (image f a ⊆ b)):
card a ≤ card b :=
obtain f Pinj, from Pex,
assert Psub : _, from and.right Pinj,
assert Ple : card (image f a) ≤ card b, from card_le_card_of_subset Psub,
by rewrite [(card_image_eq_of_inj_on (and.left Pinj))⁻¹]; exact Ple
theorem card_image_le (f : A → B) (s : finset A) : card (image f s) ≤ card s :=
finset.induction_on s
(by rewrite finset.image_empty)
(take a s',
assume Ha : a ∉ s',
assume IH : card (image f s') ≤ card s',
begin
rewrite [image_insert, card_insert_of_not_mem Ha],
apply le.trans !card_insert_le,
apply add_le_add_right IH
end)
theorem inj_on_of_card_image_eq {f : A → B} {s : finset A} :
card (image f s) = card s → inj_on f (ts s) :=
finset.induction_on s
(by intro H; rewrite to_set_empty; apply inj_on_empty)
(begin
intro a s' Ha IH,
rewrite [image_insert, card_insert_of_not_mem Ha, to_set_insert],
assume H1 : card (insert (f a) (image f s')) = card s' + 1,
show inj_on f (set.insert a (ts s')), from
decidable.by_cases
(assume Hfa : f a ∈ image f s',
have H2 : card (image f s') = card s' + 1,
by rewrite [card_insert_of_mem Hfa at H1]; assumption,
absurd
(calc
card (image f s') ≤ card s' : !card_image_le
... < card s' + 1 : lt_succ_self
... = card (image f s') : H2)
!lt.irrefl)
(assume Hnfa : f a ∉ image f s',
have H2 : card (image f s') + 1 = card s' + 1,
by rewrite [card_insert_of_not_mem Hnfa at H1]; assumption,
have H3 : card (image f s') = card s', from add.cancel_right H2,
have injf : inj_on f (ts s'), from IH H3,
show inj_on f (set.insert a (ts s')), from
take x1 x2,
assume Hx1 : x1 ∈ set.insert a (ts s'),
assume Hx2 : x2 ∈ set.insert a (ts s'),
assume feq : f x1 = f x2,
or.elim Hx1
(assume Hx1' : x1 = a,
or.elim Hx2
(assume Hx2' : x2 = a, by rewrite [Hx1', Hx2'])
(assume Hx2' : x2 ∈ ts s',
have Hfa : f a ∈ image f s',
by rewrite [-Hx1', feq]; apply mem_image_of_mem f Hx2',
absurd Hfa Hnfa))
(assume Hx1' : x1 ∈ ts s',
or.elim Hx2
(assume Hx2' : x2 = a,
have Hfa : f a ∈ image f s',
by rewrite [-Hx2', -feq]; apply mem_image_of_mem f Hx1',
absurd Hfa Hnfa)
(assume Hx2' : x2 ∈ ts s', injf Hx1' Hx2' feq)))
end)
end card_image
theorem card_pos_of_mem {a : A} {s : finset A} (H : a ∈ s) : card s > 0 :=
begin
induction s with a s' H1 IH,
{ contradiction },
{ rewrite (card_insert_of_not_mem H1), apply succ_pos }
end
theorem eq_of_card_eq_of_subset {s₁ s₂ : finset A} (Hcard : card s₁ = card s₂) (Hsub : s₁ ⊆ s₂) :
s₁ = s₂ :=
have H : card s₁ + 0 = card s₁ + card (s₂ \ s₁),
by rewrite [Hcard at {1}, card_eq_card_add_card_diff Hsub],
assert H1 : s₂ \ s₁ = ∅, from eq_empty_of_card_eq_zero (add.left_cancel H)⁻¹,
by rewrite [-union_diff_cancel Hsub, H1, union_empty]
lemma exists_two_of_card_gt_one {s : finset A} : 1 < card s → ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b :=
begin
intro h,
induction s with a s nain ih₁,
{exact absurd h dec_trivial},
{induction s with b s nbin ih₂,
{exact absurd h dec_trivial},
clear ih₁ ih₂,
existsi a, existsi b, split,
{apply mem_insert},
split,
{apply mem_insert_of_mem _ !mem_insert},
{intro aeqb, subst a, exact absurd !mem_insert nain}}
end
theorem Sum_const_eq_card_mul (s : finset A) (n : nat) : (∑ x ∈ s, n) = card s * n :=
begin
induction s with a s' H IH,
rewrite [Sum_empty, card_empty, zero_mul],
rewrite [Sum_insert_of_not_mem _ H, IH, card_insert_of_not_mem H, add.comm,
mul.right_distrib, one_mul]
end
theorem Sum_one_eq_card (s : finset A) : (∑ x ∈ s, (1 : nat)) = card s :=
eq.trans !Sum_const_eq_card_mul !mul_one
section deceqB
include deceqB
theorem card_Union_of_disjoint (s : finset A) (f : A → finset B) :
(∀{a₁ a₂}, a₁ ∈ s → a₂ ∈ s → a₁ ≠ a₂ → f a₁ ∩ f a₂ = ∅) →
card (⋃ x ∈ s, f x) = ∑ x ∈ s, card (f x) :=
finset.induction_on s
(assume H, by rewrite [Union_empty, Sum_empty, card_empty])
(take a s', assume H : a ∉ s',
assume IH,
assume H1 : ∀ {a₁ a₂ : A}, a₁ ∈ insert a s' → a₂ ∈ insert a s' → a₁ ≠ a₂ → f a₁ ∩ f a₂ = ∅,
have H2 : ∀ a₁ a₂ : A, a₁ ∈ s' → a₂ ∈ s' → a₁ ≠ a₂ → f a₁ ∩ f a₂ = ∅, from
take a₁ a₂, assume H3 H4 H5,
H1 (!mem_insert_of_mem H3) (!mem_insert_of_mem H4) H5,
assert H6 : card (⋃ (x : A) ∈ s', f x) = ∑ (x : A) ∈ s', card (f x), from IH H2,
assert H7 : ∀ x, x ∈ s' → f a ∩ f x = ∅, from
take x, assume xs',
have anex : a ≠ x, from assume aex, (eq.subst aex H) xs',
H1 !mem_insert (!mem_insert_of_mem xs') anex,
assert H8 : f a ∩ (⋃ (x : A) ∈ s', f x) = ∅, from
calc
f a ∩ (⋃ (x : A) ∈ s', f x) = (⋃ (x : A) ∈ s', f a ∩ f x) : by rewrite inter_Union
... = (⋃ (x : A) ∈ s', ∅) : by rewrite [Union_ext H7]
... = ∅ : by rewrite Union_empty',
by rewrite [Union_insert, Sum_insert_of_not_mem _ H,
card_union_of_disjoint H8, H6])
end deceqB
lemma dvd_Sum_of_dvd (f : A → nat) (n : nat) (s : finset A) : (∀ a, a ∈ s → n ∣ f a) → n ∣ Sum s f :=
begin
induction s with a s nain ih,
{intros, rewrite [Sum_empty], apply dvd_zero},
{intro h,
have h₁ : ∀ a, a ∈ s → n ∣ f a, from
take a, assume ains, h a (mem_insert_of_mem _ ains),
have h₂ : n ∣ Sum s f, from ih h₁,
have h₃ : n ∣ f a, from h a !mem_insert,
rewrite [Sum_insert_of_not_mem f nain],
apply dvd_add h₃ h₂}
end
end finset
|
ec8b93e4895b2e575abd140ed2673d2f62d3a087 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/ODE/gronwall.lean | a68f9966e0bf3407e8dbd918941295ee84d61f67 | [
"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 | 13,199 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.special_functions.exp_deriv
/-!
# Grönwall's inequality
The main technical result of this file is the Grönwall-like inequality
`norm_le_gronwall_bound_of_norm_deriv_right_le`. It states that if `f : ℝ → E` satisfies `∥f a∥ ≤ δ`
and `∀ x ∈ [a, b), ∥f' x∥ ≤ K * ∥f x∥ + ε`, then for all `x ∈ [a, b]` we have `∥f x∥ ≤ δ * exp (K *
x) + (ε / K) * (exp (K * x) - 1)`.
Then we use this inequality to prove some estimates on the possible rate of growth of the distance
between two approximate or exact solutions of an ordinary differential equation.
The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*,
Sec. 4.5][HubbardWest-ode], where `norm_le_gronwall_bound_of_norm_deriv_right_le` is called
“Fundamental Inequality”.
## TODO
- Once we have FTC, prove an inequality for a function satisfying `∥f' x∥ ≤ K x * ∥f x∥ + ε`,
or more generally `liminf_{y→x+0} (f y - f x)/(y - x) ≤ K x * f x + ε` with any sign
of `K x` and `f x`.
-/
variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E]
{F : Type*} [normed_add_comm_group F] [normed_space ℝ F]
open metric set asymptotics filter real
open_locale classical topological_space nnreal
/-! ### Technical lemmas about `gronwall_bound` -/
/-- Upper bound used in several Grönwall-like inequalities. -/
noncomputable def gronwall_bound (δ K ε x : ℝ) : ℝ :=
if K = 0 then δ + ε * x else δ * exp (K * x) + (ε / K) * (exp (K * x) - 1)
lemma gronwall_bound_K0 (δ ε : ℝ) : gronwall_bound δ 0 ε = λ x, δ + ε * x :=
funext $ λ x, if_pos rfl
lemma gronwall_bound_of_K_ne_0 {δ K ε : ℝ} (hK : K ≠ 0) :
gronwall_bound δ K ε = λ x, δ * exp (K * x) + (ε / K) * (exp (K * x) - 1) :=
funext $ λ x, if_neg hK
lemma has_deriv_at_gronwall_bound (δ K ε x : ℝ) :
has_deriv_at (gronwall_bound δ K ε) (K * (gronwall_bound δ K ε x) + ε) x :=
begin
by_cases hK : K = 0,
{ subst K,
simp only [gronwall_bound_K0, zero_mul, zero_add],
convert ((has_deriv_at_id x).const_mul ε).const_add δ,
rw [mul_one] },
{ simp only [gronwall_bound_of_K_ne_0 hK],
convert (((has_deriv_at_id x).const_mul K).exp.const_mul δ).add
((((has_deriv_at_id x).const_mul K).exp.sub_const 1).const_mul (ε / K)) using 1,
simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel' _ hK],
ring }
end
lemma has_deriv_at_gronwall_bound_shift (δ K ε x a : ℝ) :
has_deriv_at (λ y, gronwall_bound δ K ε (y - a)) (K * (gronwall_bound δ K ε (x - a)) + ε) x :=
begin
convert (has_deriv_at_gronwall_bound δ K ε _).comp x ((has_deriv_at_id x).sub_const a),
rw [id, mul_one]
end
lemma gronwall_bound_x0 (δ K ε : ℝ) : gronwall_bound δ K ε 0 = δ :=
begin
by_cases hK : K = 0,
{ simp only [gronwall_bound, if_pos hK, mul_zero, add_zero] },
{ simp only [gronwall_bound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] }
end
lemma gronwall_bound_ε0 (δ K x : ℝ) : gronwall_bound δ K 0 x = δ * exp (K * x) :=
begin
by_cases hK : K = 0,
{ simp only [gronwall_bound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] },
{ simp only [gronwall_bound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] }
end
lemma gronwall_bound_ε0_δ0 (K x : ℝ) : gronwall_bound 0 K 0 x = 0 :=
by simp only [gronwall_bound_ε0, zero_mul]
lemma gronwall_bound_continuous_ε (δ K x : ℝ) : continuous (λ ε, gronwall_bound δ K ε x) :=
begin
by_cases hK : K = 0,
{ simp only [gronwall_bound_K0, hK],
exact continuous_const.add (continuous_id.mul continuous_const) },
{ simp only [gronwall_bound_of_K_ne_0 hK],
exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) }
end
/-! ### Inequality and corollaries -/
/-- A Grönwall-like inequality: if `f : ℝ → ℝ` is continuous on `[a, b]` and satisfies
the inequalities `f a ≤ δ` and
`∀ x ∈ [a, b), liminf_{z→x+0} (f z - f x)/(z - x) ≤ K * (f x) + ε`, then `f x`
is bounded by `gronwall_bound δ K ε (x - a)` on `[a, b]`.
See also `norm_le_gronwall_bound_of_norm_deriv_right_le` for a version bounding `∥f x∥`,
`f : ℝ → E`. -/
theorem le_gronwall_bound_of_liminf_deriv_right_le {f f' : ℝ → ℝ} {δ K ε : ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r →
∃ᶠ z in 𝓝[>] x, (z - x)⁻¹ * (f z - f x) < r)
(ha : f a ≤ δ) (bound : ∀ x ∈ Ico a b, f' x ≤ K * f x + ε) :
∀ x ∈ Icc a b, f x ≤ gronwall_bound δ K ε (x - a) :=
begin
have H : ∀ x ∈ Icc a b, ∀ ε' ∈ Ioi ε, f x ≤ gronwall_bound δ K ε' (x - a),
{ assume x hx ε' hε',
apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf',
{ rwa [sub_self, gronwall_bound_x0] },
{ exact λ x, has_deriv_at_gronwall_bound_shift δ K ε' x a },
{ assume x hx hfB,
rw [← hfB],
apply lt_of_le_of_lt (bound x hx),
exact add_lt_add_left hε' _ },
{ exact hx } },
assume x hx,
change f x ≤ (λ ε', gronwall_bound δ K ε' (x - a)) ε,
convert continuous_within_at_const.closure_le _ _ (H x hx),
{ simp only [closure_Ioi, left_mem_Ici] },
exact (gronwall_bound_continuous_ε δ K (x - a)).continuous_within_at
end
/-- A Grönwall-like inequality: if `f : ℝ → E` is continuous on `[a, b]`, has right derivative
`f' x` at every point `x ∈ [a, b)`, and satisfies the inequalities `∥f a∥ ≤ δ`,
`∀ x ∈ [a, b), ∥f' x∥ ≤ K * ∥f x∥ + ε`, then `∥f x∥` is bounded by `gronwall_bound δ K ε (x - a)`
on `[a, b]`. -/
theorem norm_le_gronwall_bound_of_norm_deriv_right_le {f f' : ℝ → E} {δ K ε : ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b)) (hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
(ha : ∥f a∥ ≤ δ) (bound : ∀ x ∈ Ico a b, ∥f' x∥ ≤ K * ∥f x∥ + ε) :
∀ x ∈ Icc a b, ∥f x∥ ≤ gronwall_bound δ K ε (x - a) :=
le_gronwall_bound_of_liminf_deriv_right_le (continuous_norm.comp_continuous_on hf)
(λ x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha bound
/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them
can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some
people call this Grönwall's inequality too.
This version assumes all inequalities to be true in some time-dependent set `s t`,
and assumes that the solutions never leave this set. -/
theorem dist_le_of_approx_trajectories_ODE_of_mem_set {v : ℝ → E → E} {s : ℝ → set E}
{K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y)
{f g f' g' : ℝ → E} {a b : ℝ} {εf εg δ : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (f' t) (Ici t) t)
(f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf)
(hfs : ∀ t ∈ Ico a b, f t ∈ s t)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (g' t) (Ici t) t)
(g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg)
(hgs : ∀ t ∈ Ico a b, g t ∈ s t)
(ha : dist (f a) (g a) ≤ δ) :
∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwall_bound δ K (εf + εg) (t - a) :=
begin
simp only [dist_eq_norm] at ha ⊢,
have h_deriv : ∀ t ∈ Ico a b, has_deriv_within_at (λ t, f t - g t) (f' t - g' t) (Ici t) t,
from λ t ht, (hf' t ht).sub (hg' t ht),
apply norm_le_gronwall_bound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha,
assume t ht,
have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)),
rw [dist_eq_norm] at this,
refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht))
(hv t (f t) (hfs t ht) (g t) (hgs t ht))).trans _),
rw [dist_eq_norm, add_comm]
end
/-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them
can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some
people call this Grönwall's inequality too.
This version assumes all inequalities to be true in the whole space. -/
theorem dist_le_of_approx_trajectories_ODE {v : ℝ → E → E}
{K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t))
{f g f' g' : ℝ → E} {a b : ℝ} {εf εg δ : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (f' t) (Ici t) t)
(f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (g' t) (Ici t) t)
(g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg)
(ha : dist (f a) (g a) ≤ δ) :
∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwall_bound δ K (εf + εg) (t - a) :=
have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial,
dist_le_of_approx_trajectories_ODE_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y)
hf hf' f_bound hfs hg hg' g_bound (λ t ht, trivial) ha
/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them
can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some
people call this Grönwall's inequality too.
This version assumes all inequalities to be true in some time-dependent set `s t`,
and assumes that the solutions never leave this set. -/
theorem dist_le_of_trajectories_ODE_of_mem_set {v : ℝ → E → E} {s : ℝ → set E}
{K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y)
{f g : ℝ → E} {a b : ℝ} {δ : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)
(hfs : ∀ t ∈ Ico a b, f t ∈ s t)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)
(hgs : ∀ t ∈ Ico a b, g t ∈ s t)
(ha : dist (f a) (g a) ≤ δ) :
∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) :=
begin
have f_bound : ∀ t ∈ Ico a b, dist (v t (f t)) (v t (f t)) ≤ 0,
by { intros, rw [dist_self] },
have g_bound : ∀ t ∈ Ico a b, dist (v t (g t)) (v t (g t)) ≤ 0,
by { intros, rw [dist_self] },
assume t ht,
have := dist_le_of_approx_trajectories_ODE_of_mem_set hv hf hf' f_bound hfs hg hg' g_bound
hgs ha t ht,
rwa [zero_add, gronwall_bound_ε0] at this,
end
/-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them
can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some
people call this Grönwall's inequality too.
This version assumes all inequalities to be true in the whole space. -/
theorem dist_le_of_trajectories_ODE {v : ℝ → E → E}
{K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t))
{f g : ℝ → E} {a b : ℝ} {δ : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)
(ha : dist (f a) (g a) ≤ δ) :
∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) :=
have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial,
dist_le_of_trajectories_ODE_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y)
hf hf' hfs hg hg' (λ t ht, trivial) ha
/-- There exists only one solution of an ODE \(\dot x=v(t, x)\) in a set `s ⊆ ℝ × E` with
a given initial value provided that RHS is Lipschitz continuous in `x` within `s`,
and we consider only solutions included in `s`. -/
theorem ODE_solution_unique_of_mem_set {v : ℝ → E → E} {s : ℝ → set E}
{K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y)
{f g : ℝ → E} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)
(hfs : ∀ t ∈ Ico a b, f t ∈ s t)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)
(hgs : ∀ t ∈ Ico a b, g t ∈ s t)
(ha : f a = g a) :
∀ t ∈ Icc a b, f t = g t :=
begin
assume t ht,
have := dist_le_of_trajectories_ODE_of_mem_set hv hf hf' hfs hg hg' hgs
(dist_le_zero.2 ha) t ht,
rwa [zero_mul, dist_le_zero] at this
end
/-- There exists only one solution of an ODE \(\dot x=v(t, x)\) with
a given initial value provided that RHS is Lipschitz continuous in `x`. -/
theorem ODE_solution_unique {v : ℝ → E → E}
{K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t))
{f g : ℝ → E} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t)
(hg : continuous_on g (Icc a b))
(hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t)
(ha : f a = g a) :
∀ t ∈ Icc a b, f t = g t :=
have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial,
ODE_solution_unique_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y)
hf hf' hfs hg hg' (λ t ht, trivial) ha
|
76827ee8195eb481b99451469ffadd735f903d73 | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_propositional/prop_18.lean | 5a648ff3712cdfaf7a906754d5c535547c5416b9 | [
"CC0-1.0"
] | permissive | tomasz-lisowski/lean-logic-examples | 84e612466776be0a16c23a0439ff8ef6114ddbe1 | 2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d | refs/heads/master | 1,683,334,199,431 | 1,621,938,305,000 | 1,621,938,305,000 | 365,041,573 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 590 | lean | namespace prop_18
variables P Q : Prop
theorem prop_18 : ¬ (P ∧ Q) → ¬¬ (¬ P ∨ ¬ Q) :=
assume h1: ¬ (P ∧ Q),
assume h2: ¬(¬P ∨ ¬Q),
have h3: ¬ P ∨ ¬ Q, from or.elim
(classical.em P)
(assume h4: P,
have h5: Q, from (classical.by_contradiction
(assume h6: ¬ Q,
h2 (or.inr h6))),
have h7: P ∧ Q, from and.intro h4 h5,
have h8: false, from h1 h7, classical.by_contradiction
(assume h9: ¬(¬P ∨ ¬Q),
h8))
(assume h10: ¬ P,
or.inl h10),
show false, from h2 h3
-- end namespace
end prop_18 |
171e27c7ff6c1ba7c660095fe337fb550c801cab | f57570f33b51ef0271f8c366142363d5ae8fff45 | /src/analysis_course.lean | 50ed4f68987fc296ff5e92d0072d8b182d1c6c1b | [] | no_license | maxd13/lean-logic | 4083cb3fbb45b423befca7fda7268b8ba85ff3a6 | ddcab46b77adca91b120a5f37afbd48794da8b52 | refs/heads/master | 1,692,257,681,488 | 1,631,740,832,000 | 1,631,740,832,000 | 246,324,437 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,309 | lean | --Thu Aug 22 08:26:12 -03 2019
-- Luiz Carlos R. Viana
import data.set.basic algebra.big_operators
data.nat.basic data.real.basic
tactic.tidy
-- We formalize the curriculum of a basic analysis course from scratch in Lean
-- (even though this is already part of the standard library).
-- The goal here however is the readability and simplicity of proofs, so that this material may
-- be used to teach undergraduate students about sets and proofs in the future.
-- For details about the language itself, the reader should refer to the guide "Theorem Proving in Lean", which can be
-- found at https://Leanprover.github.io/theorem_proving_in_Lean/index.html (access date = date of this document).
-- On a more technical note, since interactive theorem provers use type theory instead of set theory as a foundation
-- for mathematics, in order to develop the usual (material, pure) set theoretic foundation of analysis within
-- this type theory, we would need to consider an internal model of set theory within type theory.
-- This was already accomplished in the standard library in the module set_theory.zfc, but the approach used there
-- is unnecessarily technical for our purposes, as it would be hard to teach using the foundations there outlined.
-- Instead the approach used here is simply to declare a type of base things a set can be composed of and then prove
-- results in a similar fashion as is done in the standard library, such as in data.set.basic. This gives us a more
-- canonical way of writing this material without having to concern ourselves all that much with complex constructions involving
-- types. As an inevitable result of this, when we go up the hierarchy of sets we will notice that ∈ is unavoidably
-- type theoretical, since x ∈ y is not defined for arbitrary sets x and y.
-- We begin with the primitive notion of a Type. A Type is a kind of thing, and each thing has a single type.
-- For instance, there is a Type ℕ of numbers, and the things of Type ℕ are called natural numbers. We write n : ℕ
-- to indicate that n is an instance of Type ℕ, i.e. that n is a natural number.
-- One thing that is important to notice about the declaration "n : ℕ" is that it is not a proposition, as it
-- makes little sense to ask wether it is true or false. Rather the typing declaration of n is a presupposition of
-- any proposition we make involving n, without which it would not make sense. For instance, we can say
-- "the number 2 is walking in the street", and one interpretation of this expression would say that it is a proposition
-- that is false; but certainly there is something else going on here. If the expression is false, it doesn't appear to be
-- false in the exact same sense in which we say that "2 = 3" is false, but rather it would appear to us that the expression
-- itself is nonsensical. "Walking in the street" simply is not an operation that is defined for natural numbers, so the
-- expression itself, though it may pose as a proposition, is ill-formed. Rather, we must presuppose that we know the types
-- of things that we are talking about so as to understand the possible ways we can form propositions involving them.
-- In type theory we consider that both propositions and typing declarations are different forms of judgement.
open set
namespace hidden
-- Where do Types live in? We can define an universe of discourse which will include all Types relevant to the development
-- of our theory, and this universe will be the collection of all our Types.
universe u
-- All that is needed to develop set theory from type theory is a single Type of things we wish
-- to talk about, so let α be a Type in the universe u
variable α : Type u
-- A set X of α's can be identified with a function which takes x : α and constructs a proposition "x is an element of X".
-- This is already defined in Lean's standard library, so we simply reproduce that definition here.
-- def set (α : Type u) := α → Prop
-- We can give a few examples of sets of different Types, for instance instead of α we could use natural numbers:
example : set ℕ := {x : ℕ | x > 0} -- this is the set of all natural numbers greater than 0.
example : set ℕ := {1, 2, 3}
-- If X is a set, the symbol ∈ is used as notation for membership in X, so if x : α, the proposition x ∈ X is the
-- one we get by applying X over x as a function.
-- We now start to define important notions involving sets. The first of them is set inclusion:
-- This definition says that s₁ is a subset of s₂ if and only if every element of s₁ is an element of s₂
def subset (s₁ s₂ : set α) := ∀ ⦃a⦄, a ∈ s₁ → a ∈ s₂
-- in order to be able to use the notation ⊆ for sets we need to tell Lean's elaborator that the type set α is
-- one of those types for which this notation is defined. We do this with the following command.
instance : has_subset (set α) :=
⟨set.subset⟩
-- 2 sets X and Y are said to be equal if and only if they have exactly the same elements, i.e. X ⊆ Y and Y ⊆ X.
-- This is called the principle of extensionality for sets. Since Lean treats equality as a primitive concept,
-- we don't really have to define it, rather it is possible to prove from certain axioms within Lean that 2 sets
-- are equal if and only if they have the same elements. The important theorem of the standard library that does this
-- is declared as:
-- theorem ext {a b : set α} (h : ∀ x, x ∈ a ↔ x ∈ b) : a = b
-- We need to keep in mind only that to prove equality between 2 sets X and Y, all we need to do is take
-- an element of X and prove that it is in Y, and then take an element of Y and prove that it is in X.
-- This is equivalent to proving both X ⊆ Y and Y ⊆ X.
-- To aid such proofs there is also a theorem in the standard library:
-- theorem eq_of_subset_of_subset {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b
-- For instance, here is a proof that every set is equal to itself.
--#check or.elim
example : ∀ s : set α, s = s :=
assume s : set α,
have s ⊆ s, from
(assume x : α,
assume h : x ∈ s,
show x ∈ s, from h
),
show s = s, from eq_of_subset_of_subset this this -- notice "this" refers to the last theorem proved using "have".
-- This proof, although very simple, is much more complicated than it needs to be.
-- We already have a standard method of proving equality for any given Type without the need to go
-- into details about the Type in question.
example : ∀ s : set α, s = s := assume s : set α, rfl
-- We can then define the notions of union and intersection of sets and their respective notations,
-- and prove theorems about them.
def union (s₁ s₂ : set α) : set α := {a | a ∈ s₁ ∨ a ∈ s₂}
-- We use ∪ for union.
instance : has_union (set α) := ⟨set.union⟩
def inter (s₁ s₂ : set α) : set α := {a | a ∈ s₁ ∧ a ∈ s₂}
-- We use ∩ for intersection.
instance : has_inter (set α) := ⟨set.inter⟩
-- here is a result a little bit harder than the previous one.
lemma distributivity₁ : ∀ {A B C : set α}, (A ∩ B) ∪ C = (A ∪ C) ∩ (B ∪ C) :=
assume A B C : set α, -- let A, B, C be sets.
-- we prove the side (⊆) first.
have c₀ : (A ∩ B) ∪ C ⊆ (A ∪ C) ∩ (B ∪ C), from
(assume x : α, -- suppose x is an α.
assume h : x ∈ (A ∩ B) ∪ C, -- suppose x is an element of the left hand side.
have c₀ : x ∈ (A ∩ B) ∨ x ∈ C, from h, -- by the definition of ∪, obtain that x is in (A ∩ B) OR x is in C.
-- lets prove that x ∈ A ∪ C.
-- We give a proof by cases, assuming in one case that x ∈ (A ∩ B), and in the other that x ∈ C.
-- The logical rule that allows us to do this is known as or-elimination.
have c₁ : x ∈ (A ∪ C), from or.elim c₀
(-- since we know c₀, assume in the fist case x ∈ (A ∩ B)
assume h : x ∈ (A ∩ B),-- notice this replaces the 'h' defined above.
-- We won't need that 'h' anymore so we can reuse the name.
-- the logical rule that allows us to infer that x ∈ A from the fact that both x ∈ A and x ∈ B is called
-- and-elimination.
have x ∈ A, from and.elim_left h,
-- since x ∈ A, x ∈ (A ∪ C). The rule that allows us to infer this is called or-introduction.
show x ∈ (A ∪ C), from or.inl this
-- this concludes the proof for the case x ∈ (A ∩ B)
)
(-- We then need to show the this works out in the other case as well.
assume h : x ∈ C,
-- likewise, we prove the desired result using or-introduction.
-- Can you tell the difference between the rules or.inl and or.inr? Hint: (l)eft vs (r)ight.
show x ∈ (A ∪ C), from or.inr h
),
-- next we must prove x ∈ (B ∪ C). The proof is very similar to the previous one.
have c₂ : x ∈ (B ∪ C), from or.elim c₀
(assume h : x ∈ (A ∩ B),
have x ∈ B, from and.elim_right h,
show x ∈ (B ∪ C), from or.inl this
)
(assume h: x ∈ C,
show x ∈ (B ∪ C), from or.inr h
),
-- to conclude the proof we put both results together.
show x ∈ (A ∪ C) ∩ (B ∪ C), from ⟨c₁, c₂⟩ -- the ⟨⟩ forms a notation for the rule of and-introduction.
),
-- next we prove the other side.
-- We we show here that we can write a proof of this sort more efficiently by using a few tricks.
have c₁ : (A ∪ C) ∩ (B ∪ C) ⊆ (A ∩ B) ∪ C, from
(assume x : α,
assume h₀ : x ∈ (A ∪ C) ∩ (B ∪ C),
match h₀.left with
| (or.inl h₁) :=
match h₀.right with
| (or.inl h₂) := or.inl ⟨h₁, h₂⟩
| (or.inr h₂) := or.inr h₂
end
| (or.inr h₁) := or.inr h₁
end
),
-- finally we put the 2 results together to prove the equality.
show (A ∩ B) ∪ C = (A ∪ C) ∩ (B ∪ C), from eq_of_subset_of_subset c₀ c₁
-- When you learn to do these kinds of proof more or less in your head,
-- this is good evidence that you have a decent proficiency with proofs.
-- There is an even shorter way of writing proofs in Lean using tactics. We will show this style
-- of writing in the next theorem.
lemma distributivity₂ : ∀ {A B C : set α}, (A ∪ B) ∩ C = (A ∩ C) ∪ (B ∩ C) :=
begin
intros A B C,
apply eq_of_subset_of_subset,
intros x h,
cases h.left with c₁ c₂,
exact or.inl ⟨c₁, h.right⟩,
exact or.inr ⟨c₂, h.right⟩,
intros x h,
cases h with c₁ c₂,
exact ⟨or.inl c₁.left, c₁.right⟩,
exact ⟨or.inr c₂.left, c₂.right⟩,
end
-- By using tactics we tell Lean in a more abstract manner what to do to generate a proof of our theorem.
-- We can ask Lean to show the proof it generated using the print command
set_option pp.beta true
set_option pp.notation true
--#print distributivity₂
-- Here is the generated proof:
-- theorem hidden.distributivity₂ : ∀ (α : Type u) {A B C : set α}, (A ∪ B) ∩ C = A ∩ C ∪ B ∩ C :=
-- λ (α : Type u) (A B C : set α),
-- eq_of_subset_of_subset
-- (id
-- (λ (x : α) (h : x ∈ (A ∪ B) ∩ C),
-- or.dcases_on (h.left) (λ (c₁ : x ∈ A), or.inl ⟨c₁, h.right⟩)
-- (λ (c₂ : x ∈ B), or.inr ⟨c₂, h.right⟩)))
-- (id
-- (λ (x : α) (h : x ∈ A ∩ C ∪ B ∩ C),
-- or.dcases_on h (λ (c₁ : x ∈ A ∩ C), ⟨or.inl (c₁.left), c₁.right⟩)
-- (λ (c₂ : x ∈ B ∩ C), ⟨or.inr (c₂.left), c₂.right⟩)))
-- Moving on we prove other basic results:
lemma union_commutative : ∀ {A B : set α}, A ∪ B = B ∪ A :=
begin
intros A B, -- let A, B be sets.
apply eq_of_subset_of_subset, -- proceed to prove the equality by showing the inclusions on both sides.
intros x h, -- to prove the first goal (⊆) assume x : α, h : x ∈ A ∪ B
cases h, -- proceed to prove x ∈ B ∪ A by cases
exact or.inr h, -- in case x ∈ A, we have x ∈ B ∪ A by applying or.inr
exact or.inl h, -- in case x ∈ B, by or.inl
-- Note: h was renamed to h : x ∈ A and h : x ∈ B, in each case respectively.
-- this way it is unecessary to declare names c₁, c₂ with the "with" statement, as above.
intros x h, -- now we prove the second goal, with h : x ∈ B ∪ A
cases h, -- proceed to prove x ∈ A ∪ B by cases
exact or.inr h, -- in case x ∈ B, we have x ∈ A ∪ B by applying or.inr
exact or.inl h, -- in case x ∈ A, by or.inl
-- Notice the proof of the second goal is symmetric to that of the first!!!
end
lemma union_associative : ∀ {A B C: set α}, (A ∪ B) ∪ C = A ∪ (B ∪ C) :=
begin
intros A B C,
apply eq_of_subset_of_subset,
intros x h,
cases h with c₁ c₂,
cases c₁ with c₁₁ c₁₂, -- here we have to case c₁ : x ∈ A ∪ B
exact or.inl c₁₁,
exact or.inr (or.inl c₁₂),
exact or.inr (or.inr c₂),
intros x h,
cases h with c₁ c₂,
exact or.inl (or.inl c₁),
cases c₂ with c₂₁ c₂₂,
exact or.inl (or.inr c₂₁),
exact or.inr c₂₂
end
lemma intersection_commutative : ∀ {A B : set α}, A ∩ B = B ∩ A :=
by intros; apply eq_of_subset_of_subset; intros x h; exact ⟨h.2, h.1⟩
-- This reads:
-- 1. Introduce assumptions.
-- 2. Prove the equality by eq_of_subset_of_subset.
-- 3. Assume an x belonging to the respective left hand side of the inclusion.
-- 4. If ⟨h₁, h₂⟩ is a proof of x ∈ X ∩ Y, with h₁ : x ∈ X and h₂ : x ∈ Y, then
--- the proof that x ∈ Y ∩ X is given exactly by ⟨h₂, h₁⟩
lemma intersection_associative : ∀ {A B C: set α}, (A ∩ B) ∩ C = A ∩ (B ∩ C) :=
begin
intros,
apply eq_of_subset_of_subset,
intros x h,
exact ⟨h.1.1, ⟨h.1.2, h.2⟩⟩,
intros x h,
exact ⟨⟨h.1, h.2.1⟩, h.2.2⟩
end
def relative_complement {B : set α} (A : set α) := {x ∈ B | x ∉ A}
instance set_complement : has_neg (set α) := ⟨@relative_complement α univ⟩
lemma set_pnc : ∀ {A : set α}, A ∩ - A = ∅ :=
by intros; tidy
#print set_pnc
#check ext
lemma complement_distrib : ∀ {A B : set α}, (A ∪ B) ∩ - A = B ∩ - A :=
by intros A B; rw [@distributivity₂ α A B (-A), set_pnc]; simp
section induction
-- The natural numbers are defined as:
-- inductive nat
-- | zero : nat
-- | succ (n : nat) : nat
-- Inductive types have recursors, which allow us to perform induction in these types.
-- The principle of mathematical induction for natural numbers is stated as follows:
#check nat.rec
open finset
-- example : ∀ n : ℕ, n > 1 → (finset.range n).prod (λi, 1 - 1 / i) = 1 / n :=
-- begin
-- intro n,
-- induction n with n₀ ih,
-- exfalso,
-- exact nat.not_succ_le_zero 1 h,
-- unfold finset.prod at *,
-- simp at *,
-- by_cases n₀ > 1,
-- rewrite ih h,
-- dsimp,
-- end
open nat
#check nat.add_div_left
example : ∀ n : ℕ, sum (range n) (λk, (k+1) / 2^(k+1)) = (2^(n+1) - n - 2) / 2^n :=
begin
intro n,
induction n with n₀ ih,
simp,
simp [range_succ, ih, nat.pow_succ 2 n₀],
admit
--rewrite nat.pow_succ 2 n₀,
-- induction n₀ with n₁ ih₂,
-- simp,
-- rewrite range_succ,
-- simp,
-- rewrite ih,
-- have h : (n₀ + 1) / 2 ^ (n₀ + 1) + (2 ^ (n₀ + 1) - n₀ - 2) / 2 ^ n₀
-- = ((n₀ + 1) + 2*(2 ^ (n₀ + 1) - n₀ - 2) )/ 2 ^ (n₀ + 1), from rfl,
end
open real lattice
#check real.of_near --set.range of_rat
#check set.exists_mem_of_ne_empty
variables (A B : set real)
variables (bddA₁ : bdd_above A) (bddB₁ : bdd_above B)
variables (bddA₂ : bdd_below A) (bddB₂ : bdd_below B)
variables (ne₁ : A ≠ ∅) (ne₂ : B ≠ ∅)
variables (h₁ : A ⊆ set.range of_rat) (h₂ : B ⊆ set.range of_rat)
lemma aux : ∀ ε : ℝ, ε > 0 → ∃ a ∈ A, real.Sup A < a + ε :=
begin
intros ε a,
simp at *,
fsplit;
--work_on_goal 1 { simp at *, fsplit };
admit
end
lemma aux₂ : ∀ ε : ℝ, ε > 0 → ∃ a ∈ B, real.Inf B > a - ε :=
sorry
include bddA₁ bddA₂ bddB₁ bddB₂ ne₁ ne₂ h₁ h₂
theorem ex3 : real.Sup A = real.Inf B ↔ (∀ (a ∈ A) (b ∈ B), a ≤ b) ∧ (∀ ε : ℝ, ε > 0 → ∃ (a ∈ A) (b ∈ B), a + ε > b) :=
begin
constructor; intro h,
-- ⟶ side
constructor, -- prova o lado esquerdo do and.
intros a a_in_A b b_in_B,
have c₀ : a ≤ real.Sup A, from le_cSup bddA₁ a_in_A,
have c₁ : real.Inf B ≤ b, from cInf_le bddB₂ b_in_B,
rewrite h at c₀,
exact le_trans c₀ c₁,
intros ε ε_pos,
obtain ⟨a, a_in_A, c₀⟩ := aux A (ε/2) (mul_pos ε_pos _),
work_on_goal 1 {ring, exact one_half_pos},
obtain ⟨b, b_in_B, c₁⟩ := aux₂ B (ε/2) (mul_pos ε_pos _),
work_on_goal 1 {ring, exact one_half_pos},
-- cases (aux A (ε/2) (mul_pos ε_pos sorry)) with a c₀,
-- cases c₀ with a_in_A c₀,
-- cases (aux₂ B (ε/2) (mul_pos ε_pos sorry)) with b c₁,
-- cases c₁ with b_in_B c₁,
suffices c : a + ε > b, from ⟨a, a_in_A, b, b_in_B, c⟩,
rewrite ←h at *, simp * at *,
have c, from lt_trans c₁ c₀,
replace c, from add_lt_add_left c (ε/2),
rw [add_comm, add_assoc, add_left_neg, add_zero] at c,
simp at c, exact c,
-- ⟵ side
cases h with c₁ c₂,
have c₀ : ∀ a ∈ A, a ≤ real.Sup A,
intros a a_in_A,
exact le_cSup bddA₁ a_in_A,
have c₃ : ∀ b ∈ B, ∀ a ∈ A, a ≤ b,
intros b b_in_B x x_in_A,
exact c₁ x x_in_A b b_in_B,
have c₄ : ∀ b ∈ B, real.Sup A ≤ b ,
intros b b_in_B,
exact cSup_le ne₁ (c₃ b b_in_B),
have c₅ : real.Sup A ≤ real.Inf B, from le_cInf ne₂ c₄,
have c₆ : ∀ a ∈ A, real.Inf A ≤ a,
intros a a_in_A,
exact cInf_le bddA₂ a_in_A,
have c₇ : real.Inf A ≤ real.Sup A,
cases (set.exists_mem_of_ne_empty ne₁) with a a_in_A,
apply le_trans,
exact c₆ a a_in_A,
exact c₀ a a_in_A,
replace c₇ : real.Inf A + -real.Inf A ≤ real.Sup A - real.Inf A,
from add_le_add_right c₇ (-real.Inf A),
simp at c₇,
let ε := real.Sup A - real.Inf A,
-- have c : 0 ≠ ε, from sorry,
replace c₇, from lt_of_le_of_ne c₇ sorry,
obtain ⟨a, a_in_A, b, b_in_B, c⟩ := (c₂ ε c₇),
-- replace c, from (c₂ ε c₇),
-- rcases c with ⟨a, a_in_A, b, b_in_B, c⟩,
-- cases c with a c,
-- cases c with a_in_A c,
-- cases c with b c,
-- cases c with b_in_B c,
-- cases (set.exists_mem_of_ne_empty ne₁) with a a_in_A,
-- cases (set.exists_mem_of_ne_empty ne₂) with b b_in_B,
-- repeat{fsplit},
-- exact a,
-- exact a_in_A,
-- exact b,
-- exact b_in_B,
-- clarify, simp at a_1,
-- simp * at *,
--cases (a (real.Sup A)),
end
-- example : ∀ n m : ℕ, m * n = n * m :=
-- begin
-- intros n m,
-- induction m with m ihm,
-- simp,
-- induction n with l ihn,
-- simp,
-- rewrite nat.mul_succ (n + 1) m,
-- rewrite nat.mul_succ (m+1) n,
-- rewrite ←ihm,
-- rewrite nat.mul_succ,
-- rewrite nat.add_assoc,
-- end
end induction
end hidden
-- Instead the approach used here is to construct the von Neumann hierarchy from the unit type,
-- the type with a single instance which is here to be considered as the empty set,
-- and we will define that a set we begin by considering the |
e9a39d80ca03ce41d31b973fad8606a896cdc562 | b815abf92ce063fe0d1fabf5b42da483552aa3e8 | /library/init/data/nat/lemmas.lean | dcd8da0d05d6d293930d3666109054479f0ef206 | [
"Apache-2.0"
] | permissive | yodalee/lean | a368d842df12c63e9f79414ed7bbee805b9001ef | 317989bf9ef6ae1dec7488c2363dbfcdc16e0756 | refs/heads/master | 1,610,551,176,860 | 1,481,430,138,000 | 1,481,646,441,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 22,375 | 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.nat.basic init.meta init.algebra
namespace nat
protected lemma zero_add : ∀ n : ℕ, 0 + n = n
| 0 := rfl
| (n+1) := congr_arg succ (zero_add n)
lemma succ_add : ∀ n m : ℕ, (succ n) + m = succ (n + m)
| n 0 := rfl
| n (m+1) := congr_arg succ (succ_add n m)
lemma add_succ : ∀ n m : ℕ, n + succ m = succ (n + m) :=
λ n m, rfl
lemma add_zero : ∀ n : ℕ, n + 0 = n :=
λ n, rfl
lemma add_one_eq_succ : ∀ n : ℕ, n + 1 = succ n :=
λ n, rfl
protected lemma add_comm : ∀ n m : ℕ, n + m = m + n
| n 0 := eq.symm (nat.zero_add n)
| n (m+1) :=
suffices succ (n + m) = succ (m + n), from
eq.symm (succ_add m n) ▸ this,
congr_arg succ (add_comm n m)
protected lemma add_assoc : ∀ n m k : ℕ, (n + m) + k = n + (m + k)
| n m 0 := rfl
| n m (succ k) := by simp [add_succ, add_assoc n m k]
protected lemma add_left_comm : ∀ (n m k : ℕ), n + (m + k) = m + (n + k) :=
left_comm nat.add nat.add_comm nat.add_assoc
protected lemma add_left_cancel : ∀ {n m k : ℕ}, n + m = n + k → m = k
| 0 m k := by ctx_simp [nat.zero_add]
| (succ n) m k := λ h,
have n+m = n+k, begin simp [succ_add] at h, injection h, assumption end,
add_left_cancel this
protected lemma add_right_cancel {n m k : ℕ} (h : n + m = k + m) : n = k :=
have m + n = m + k, begin rw [nat.add_comm n m, nat.add_comm k m] at h, assumption end,
nat.add_left_cancel this
lemma succ_ne_zero (n : ℕ) : succ n ≠ 0 :=
assume h, nat.no_confusion h
lemma succ_ne_self : ∀ n : ℕ, succ n ≠ n
| 0 h := absurd h (nat.succ_ne_zero 0)
| (n+1) h := succ_ne_self n (nat.no_confusion h (λ h, h))
protected lemma one_ne_zero : 1 ≠ (0 : ℕ) :=
assume h, nat.no_confusion h
protected lemma zero_ne_one : 0 ≠ (1 : ℕ) :=
assume h, nat.no_confusion h
lemma eq_zero_of_add_eq_zero_right : ∀ {n m : ℕ}, n + m = 0 → n = 0
| 0 m := by ctx_simp [nat.zero_add]
| (n+1) m := λ h,
begin
exfalso,
rw [add_one_eq_succ, succ_add] at h,
apply succ_ne_zero _ h
end
lemma eq_zero_of_add_eq_zero_left {n m : ℕ} (h : n + m = 0) : m = 0 :=
@eq_zero_of_add_eq_zero_right m n (nat.add_comm n m ▸ h)
lemma pred_zero : pred 0 = 0 :=
rfl
lemma pred_succ (n : ℕ) : pred (succ n) = n :=
rfl
protected lemma mul_zero (n : ℕ) : n * 0 = 0 :=
rfl
lemma mul_succ (n m : ℕ) : n * succ m = n * m + n :=
rfl
protected theorem zero_mul : ∀ (n : ℕ), 0 * n = 0
| 0 := rfl
| (succ n) := by rw [mul_succ, zero_mul]
private meta def sort_add :=
`[simp [nat.add_assoc, nat.add_comm, nat.add_left_comm]]
lemma succ_mul : ∀ (n m : ℕ), (succ n) * m = (n * m) + m
| n 0 := rfl
| n (succ m) :=
begin
simp [mul_succ, add_succ, succ_mul n m],
sort_add
end
protected lemma right_distrib : ∀ (n m k : ℕ), (n + m) * k = n * k + m * k
| n m 0 := rfl
| n m (succ k) :=
begin simp [mul_succ, right_distrib n m k], sort_add end
protected lemma left_distrib : ∀ (n m k : ℕ), n * (m + k) = n * m + n * k
| 0 m k := by simp [nat.zero_mul]
| (succ n) m k :=
begin simp [succ_mul, left_distrib n m k], sort_add end
protected lemma mul_comm : ∀ (n m : ℕ), n * m = m * n
| n 0 := by rw [nat.zero_mul, nat.mul_zero]
| n (succ m) := by simp [mul_succ, succ_mul, mul_comm n m]
protected lemma mul_assoc : ∀ (n m k : ℕ), (n * m) * k = n * (m * k)
| n m 0 := rfl
| n m (succ k) := by simp [mul_succ, nat.left_distrib, mul_assoc n m k]
protected lemma mul_one : ∀ (n : ℕ), n * 1 = n
| 0 := rfl
| (succ n) := by simp [succ_mul, mul_one n, add_one_eq_succ]
protected lemma one_mul (n : ℕ) : 1 * n = n :=
by rw [nat.mul_comm, nat.mul_one]
lemma eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {n m : ℕ}, n * m = 0 → n = 0 ∨ m = 0
| 0 m := λ h, or.inl rfl
| (succ n) m :=
begin
rw succ_mul, intro h,
exact or.inr (eq_zero_of_add_eq_zero_left h)
end
instance : comm_semiring nat :=
{add := nat.add,
add_assoc := nat.add_assoc,
zero := nat.zero,
zero_add := nat.zero_add,
add_zero := nat.add_zero,
add_comm := nat.add_comm,
mul := nat.mul,
mul_assoc := nat.mul_assoc,
one := nat.succ nat.zero,
one_mul := nat.one_mul,
mul_one := nat.mul_one,
left_distrib := nat.left_distrib,
right_distrib := nat.right_distrib,
zero_mul := nat.zero_mul,
mul_zero := nat.mul_zero,
mul_comm := nat.mul_comm}
/- properties of inequality -/
protected lemma le_of_eq {n m : ℕ} (p : n = m) : n ≤ m :=
p ▸ less_than.refl n
lemma le_succ_iff_true (n : ℕ) : n ≤ succ n ↔ true :=
iff_true_intro (le_succ n)
lemma pred_le_iff_true (n : ℕ) : pred n ≤ n ↔ true :=
iff_true_intro (pred_le n)
lemma le_succ_of_le {n m : ℕ} (h : n ≤ m) : n ≤ succ m :=
nat.le_trans h (le_succ m)
lemma le_of_succ_le {n m : ℕ} (h : succ n ≤ m) : n ≤ m :=
nat.le_trans (le_succ n) h
protected lemma le_of_lt {n m : ℕ} (h : n < m) : n ≤ m :=
le_of_succ_le h
lemma le_succ_of_pred_le {n m : ℕ} : pred n ≤ m → n ≤ succ m :=
nat.cases_on n less_than.step (λ a, succ_le_succ)
lemma succ_le_zero_iff_false (n : ℕ) : succ n ≤ 0 ↔ false :=
iff_false_intro (not_succ_le_zero n)
lemma succ_le_self_iff_false (n : ℕ) : succ n ≤ n ↔ false :=
iff_false_intro (not_succ_le_self n)
lemma zero_le_iff_true (n : ℕ) : 0 ≤ n ↔ true :=
iff_true_intro (zero_le n)
def lt.step {n m : ℕ} : n < m → n < succ m := less_than.step
lemma zero_lt_succ_iff_true (n : ℕ) : 0 < succ n ↔ true :=
iff_true_intro (zero_lt_succ n)
def succ_pos_iff_true := zero_lt_succ_iff_true
protected lemma lt_trans {n m k : ℕ} (h₁ : n < m) : m < k → n < k :=
nat.le_trans (less_than.step h₁)
protected lemma lt_of_le_of_lt {n m k : ℕ} (h₁ : n ≤ m) : m < k → n < k :=
nat.le_trans (succ_le_succ h₁)
lemma lt_self_iff_false (n : ℕ) : n < n ↔ false :=
iff_false_intro (λ h, absurd h (nat.lt_irrefl n))
lemma self_lt_succ (n : ℕ) : n < succ n := nat.le_refl (succ n)
def lt_succ_self := @self_lt_succ
lemma self_lt_succ_iff_true (n : ℕ) : n < succ n ↔ true :=
iff_true_intro (self_lt_succ n)
def lt_succ_self_iff_true := @self_lt_succ_iff_true
def lt.base (n : ℕ) : n < succ n := nat.le_refl (succ n)
lemma le_lt_antisymm {n m : ℕ} (h₁ : n ≤ m) (h₂ : m < n) : false :=
nat.lt_irrefl n (nat.lt_of_le_of_lt h₁ h₂)
protected lemma le_antisymm {n m : ℕ} (h₁ : n ≤ m) : m ≤ n → n = m :=
less_than.cases_on h₁ (λ a, rfl) (λ a b c, absurd (nat.lt_of_le_of_lt b c) (nat.lt_irrefl n))
instance : weak_order ℕ :=
⟨@nat.less_than, @nat.le_refl, @nat.le_trans, @nat.le_antisymm⟩
lemma lt_le_antisymm {n m : ℕ} (h₁ : n < m) (h₂ : m ≤ n) : false :=
le_lt_antisymm h₂ h₁
protected lemma nat.lt_asymm {n m : ℕ} (h₁ : n < m) : ¬ m < n :=
le_lt_antisymm (nat.le_of_lt h₁)
lemma lt_zero_iff_false (a : ℕ) : a < 0 ↔ false :=
iff_false_intro (not_lt_zero a)
protected lemma le_of_eq_or_lt {a b : ℕ} (h : a = b ∨ a < b) : a ≤ b :=
or.elim h nat.le_of_eq nat.le_of_lt
lemma succ_lt_succ {a b : ℕ} : a < b → succ a < succ b :=
succ_le_succ
lemma lt_of_succ_lt {a b : ℕ} : succ a < b → a < b :=
le_of_succ_le
lemma lt_of_succ_lt_succ {a b : ℕ} : succ a < succ b → a < b :=
le_of_succ_le_succ
protected lemma lt_or_ge : ∀ (a b : ℕ), a < b ∨ a ≥ b
| a 0 := or.inr (zero_le a)
| a (b+1) :=
match lt_or_ge a b with
| or.inl h := or.inl (le_succ_of_le h)
| or.inr h :=
match nat.eq_or_lt_of_le h with
| or.inl h1 := or.inl (h1 ▸ self_lt_succ b)
| or.inr h1 := or.inr h1
end
end
protected def {u} lt_ge_by_cases {a b : ℕ} {C : Type u} (h₁ : a < b → C) (h₂ : a ≥ b → C) : C :=
decidable.by_cases h₁ (λ h, h₂ (or.elim (nat.lt_or_ge a b) (λ a, absurd a h) (λ a, a)))
protected def {u} lt_by_cases {a b : ℕ} {C : Type u} (h₁ : a < b → C) (h₂ : a = b → C)
(h₃ : b < a → C) : C :=
nat.lt_ge_by_cases h₁ (λ h₁,
nat.lt_ge_by_cases h₃ (λ h, h₂ (nat.le_antisymm h h₁)))
protected lemma lt_trichotomy (a b : ℕ) : a < b ∨ a = b ∨ b < a :=
nat.lt_by_cases (λ h, or.inl h) (λ h, or.inr (or.inl h)) (λ h, or.inr (or.inr h))
protected lemma eq_or_lt_of_not_lt {a b : ℕ} (hnlt : ¬ a < b) : a = b ∨ b < a :=
or.elim (nat.lt_trichotomy a b)
(λ hlt, absurd hlt hnlt)
(λ h, h)
lemma lt_of_succ_le {a b : ℕ} (h : succ a ≤ b) : a < b := h
lemma succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b := h
lemma le_add_right : ∀ (n k : ℕ), n ≤ n + k
| n 0 := nat.le_refl n
| n (k+1) := le_succ_of_le (le_add_right n k)
lemma le_add_left (n m : ℕ): n ≤ m + n :=
nat.add_comm n m ▸ le_add_right n m
lemma le.dest : ∀ {n m : ℕ}, n ≤ m → ∃ k, n + k = m
| n .n (less_than.refl .n) := ⟨0, rfl⟩
| n .(succ m) (@less_than.step .n m h) :=
match le.dest h with
| ⟨w, hw⟩ := ⟨succ w, hw ▸ add_succ n w⟩
end
lemma le.intro {n m k : ℕ} (h : n + k = m) : n ≤ m :=
h ▸ le_add_right n k
protected lemma add_le_add_left {n m : ℕ} (h : n ≤ m) (k : ℕ) : k + n ≤ k + m :=
match le.dest h with
| ⟨w, hw⟩ := @le.intro _ _ w begin rw [nat.add_assoc, hw] end
end
protected lemma add_le_add_right {n m : ℕ} (h : n ≤ m) (k : ℕ) : n + k ≤ m + k :=
begin rw [nat.add_comm n k, nat.add_comm m k], apply nat.add_le_add_left h end
protected lemma le_of_add_le_add_left {k n m : ℕ} (h : k + n ≤ k + m) : n ≤ m :=
match le.dest h with
| ⟨w, hw⟩ := @le.intro _ _ w
begin
dsimp at hw,
rw [nat.add_assoc] at hw,
apply nat.add_left_cancel hw
end
end
protected lemma lt_of_le_and_ne {m n : ℕ} (h1 : m ≤ n) : m ≠ n → m < n :=
or.resolve_right (or.swap (nat.eq_or_lt_of_le h1))
protected theorem lt_of_add_lt_add_left {k n m : ℕ} (h : k + n < k + m) : n < m :=
let h' := nat.le_of_lt h in
nat.lt_of_le_and_ne
(nat.le_of_add_le_add_left h')
(λ heq, nat.lt_irrefl (k + m) begin rw heq at h, assumption end)
protected lemma add_lt_add_left {n m : ℕ} (h : n < m) (k : ℕ) : k + n < k + m :=
lt_of_succ_le (add_succ k n ▸ nat.add_le_add_left (succ_le_of_lt h) k)
protected lemma add_lt_add_right {n m : ℕ} (h : n < m) (k : ℕ) : n + k < m + k :=
nat.add_comm k m ▸ nat.add_comm k n ▸ nat.add_lt_add_left h k
protected lemma lt_add_of_pos_right {n k : ℕ} (h : k > 0) : n < n + k :=
nat.add_lt_add_left h n
protected lemma zero_lt_one : 0 < (1:nat) :=
zero_lt_succ 0
protected lemma le_total {m n : ℕ} : m ≤ n ∨ n ≤ m :=
or.imp_left nat.le_of_lt (nat.lt_or_ge m n)
protected lemma le_of_lt_or_eq {m n : ℕ} (h : m < n ∨ m = n) : m ≤ n :=
nat.le_of_eq_or_lt (or.swap h)
protected lemma lt_or_eq_of_le {m n : ℕ} (h : m ≤ n) : m < n ∨ m = n :=
or.swap (nat.eq_or_lt_of_le h)
protected lemma le_iff_lt_or_eq (m n : ℕ) : m ≤ n ↔ m < n ∨ m = n :=
iff.intro nat.lt_or_eq_of_le nat.le_of_lt_or_eq
lemma mul_le_mul_left {n m : ℕ} (k : ℕ) (h : n ≤ m) : k * n ≤ k * m :=
match le.dest h with
| ⟨l, hl⟩ :=
have k * n + k * l = k * m, by rw [-left_distrib, hl],
le.intro this
end
lemma mul_le_mul_right {n m : ℕ} (k : ℕ) (h : n ≤ m) : n * k ≤ m * k :=
mul_comm k m ▸ mul_comm k n ▸ mul_le_mul_left k h
protected lemma mul_lt_mul_of_pos_left {n m k : ℕ} (h : n < m) (hk : k > 0) : k * n < k * m :=
nat.lt_of_lt_of_le (nat.lt_add_of_pos_right hk) (mul_succ k n ▸ nat.mul_le_mul_left k (succ_le_of_lt h))
protected lemma mul_lt_mul_of_pos_right {n m k : ℕ} (h : n < m) (hk : k > 0) : n * k < m * k :=
mul_comm k m ▸ mul_comm k n ▸ nat.mul_lt_mul_of_pos_left h hk
instance : decidable_linear_ordered_semiring nat :=
{ nat.comm_semiring with
add_left_cancel := @nat.add_left_cancel,
add_right_cancel := @nat.add_right_cancel,
lt := nat.lt,
le := nat.le,
le_refl := nat.le_refl,
le_trans := @nat.le_trans,
le_antisymm := @nat.le_antisymm,
le_total := @nat.le_total,
le_iff_lt_or_eq := @nat.le_iff_lt_or_eq,
le_of_lt := @nat.le_of_lt,
lt_irrefl := @nat.lt_irrefl,
lt_of_lt_of_le := @nat.lt_of_lt_of_le,
lt_of_le_of_lt := @nat.lt_of_le_of_lt,
lt_of_add_lt_add_left := @nat.lt_of_add_lt_add_left,
add_lt_add_left := @nat.add_lt_add_left,
add_le_add_left := @nat.add_le_add_left,
le_of_add_le_add_left := @nat.le_of_add_le_add_left,
zero_lt_one := zero_lt_succ 0,
mul_le_mul_of_nonneg_left := (take a b c h₁ h₂, nat.mul_le_mul_left c h₁),
mul_le_mul_of_nonneg_right := (take a b c h₁ h₂, nat.mul_le_mul_right c h₁),
mul_lt_mul_of_pos_left := @nat.mul_lt_mul_of_pos_left,
mul_lt_mul_of_pos_right := @nat.mul_lt_mul_of_pos_right,
decidable_lt := nat.decidable_lt }
lemma le_of_lt_succ {m n : nat} : m < succ n → m ≤ n :=
le_of_succ_le_succ
/- sub properties -/
lemma sub_eq_succ_sub_succ (a b : ℕ) : a - b = succ a - succ b :=
eq.symm (succ_sub_succ_eq_sub a b)
lemma zero_sub_eq_zero : ∀ a : ℕ, 0 - a = 0
| 0 := rfl
| (a+1) := congr_arg pred (zero_sub_eq_zero a)
lemma zero_eq_zero_sub (a : ℕ) : 0 = 0 - a :=
eq.symm (zero_sub_eq_zero a)
lemma sub_le_iff_true (a b : ℕ) : a - b ≤ a ↔ true :=
iff_true_intro (sub_le a b)
lemma sub_lt_succ (a b : ℕ) : a - b < succ a :=
lt_succ_of_le (sub_le a b)
lemma sub_lt_succ_iff_true (a b : ℕ) : a - b < succ a ↔ true :=
iff_true_intro (sub_lt_succ a b)
/- bit0/bit1 properties -/
protected lemma bit0_succ_eq (n : ℕ) : bit0 (succ n) = succ (succ (bit0 n)) :=
show succ (succ n + n) = succ (succ (n + n)), from
congr_arg succ (succ_add n n)
protected lemma bit1_eq_succ_bit0 (n : ℕ) : bit1 n = succ (bit0 n) :=
rfl
protected lemma bit1_succ_eq (n : ℕ) : bit1 (succ n) = succ (succ (bit1 n)) :=
eq.trans (nat.bit1_eq_succ_bit0 (succ n)) (congr_arg succ (nat.bit0_succ_eq n))
protected lemma bit0_ne_zero : ∀ {n : ℕ}, n ≠ 0 → bit0 n ≠ 0
| 0 h := absurd rfl h
| (n+1) h := succ_ne_zero _
protected lemma bit1_ne_zero (n : ℕ) : bit1 n ≠ 0 :=
show succ (n + n) ≠ 0, from
succ_ne_zero (n + n)
protected lemma bit1_ne_one : ∀ {n : ℕ}, n ≠ 0 → bit1 n ≠ 1
| 0 h h1 := absurd rfl h
| (n+1) h h1 := nat.no_confusion h1 (λ h2, absurd h2 (succ_ne_zero _))
protected lemma bit0_ne_one : ∀ n : ℕ, bit0 n ≠ 1
| 0 h := absurd h (ne.symm nat.one_ne_zero)
| (n+1) h :=
have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h,
nat.no_confusion h1
(λ h2, absurd h2 (succ_ne_zero (n + n)))
protected lemma add_self_ne_one : ∀ (n : ℕ), n + n ≠ 1
| 0 h := nat.no_confusion h
| (n+1) h :=
have h1 : succ (succ (n + n)) = 1, from succ_add n n ▸ h,
nat.no_confusion h1 (λ h2, absurd h2 (nat.succ_ne_zero (n + n)))
protected lemma bit1_ne_bit0 : ∀ (n m : ℕ), bit1 n ≠ bit0 m
| 0 m h := absurd h (ne.symm (nat.add_self_ne_one m))
| (n+1) 0 h :=
have h1 : succ (bit0 (succ n)) = 0, from h,
absurd h1 (nat.succ_ne_zero _)
| (n+1) (m+1) h :=
have h1 : succ (succ (bit1 n)) = succ (succ (bit0 m)), from
nat.bit0_succ_eq m ▸ nat.bit1_succ_eq n ▸ h,
have h2 : bit1 n = bit0 m, from
nat.no_confusion h1 (λ h2', nat.no_confusion h2' (λ h2'', h2'')),
absurd h2 (bit1_ne_bit0 n m)
protected lemma bit0_ne_bit1 : ∀ (n m : ℕ), bit0 n ≠ bit1 m :=
λ n m : nat, ne.symm (nat.bit1_ne_bit0 m n)
protected lemma bit0_inj : ∀ {n m : ℕ}, bit0 n = bit0 m → n = m
| 0 0 h := rfl
| 0 (m+1) h := by contradiction
| (n+1) 0 h := by contradiction
| (n+1) (m+1) h :=
have succ (succ (n + n)) = succ (succ (m + m)),
begin unfold bit0 at h, simp [add_one_eq_succ, add_succ, succ_add] at h, exact h end,
have n + n = m + m, begin repeat {injection this with this}, assumption end,
have n = m, from bit0_inj this,
by rw this
protected lemma bit1_inj : ∀ {n m : ℕ}, bit1 n = bit1 m → n = m :=
λ n m h,
have succ (bit0 n) = succ (bit0 m), begin simp [nat.bit1_eq_succ_bit0] at h, assumption end,
have bit0 n = bit0 m, from begin injection this, assumption end,
nat.bit0_inj this
protected lemma bit0_ne {n m : ℕ} : n ≠ m → bit0 n ≠ bit0 m :=
λ h₁ h₂, absurd (nat.bit0_inj h₂) h₁
protected lemma bit1_ne {n m : ℕ} : n ≠ m → bit1 n ≠ bit1 m :=
λ h₁ h₂, absurd (nat.bit1_inj h₂) h₁
protected lemma zero_ne_bit0 {n : ℕ} : n ≠ 0 → 0 ≠ bit0 n :=
λ h, ne.symm (nat.bit0_ne_zero h)
protected lemma zero_ne_bit1 (n : ℕ) : 0 ≠ bit1 n :=
ne.symm (nat.bit1_ne_zero n)
protected lemma one_ne_bit0 (n : ℕ) : 1 ≠ bit0 n :=
ne.symm (nat.bit0_ne_one n)
protected lemma one_ne_bit1 {n : ℕ} : n ≠ 0 → 1 ≠ bit1 n :=
λ h, ne.symm (nat.bit1_ne_one h)
protected lemma zero_lt_bit1 (n : nat) : 0 < bit1 n :=
zero_lt_succ _
protected lemma zero_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 0 < bit0 n
| 0 h := by contradiction
| (succ n) h :=
begin
rw nat.bit0_succ_eq,
apply zero_lt_succ
end
protected lemma one_lt_bit1 : ∀ {n : nat}, n ≠ 0 → 1 < bit1 n
| 0 h := by contradiction
| (succ n) h :=
begin
rw nat.bit1_succ_eq,
apply succ_lt_succ,
apply zero_lt_succ
end
protected lemma one_lt_bit0 : ∀ {n : nat}, n ≠ 0 → 1 < bit0 n
| 0 h := by contradiction
| (succ n) h :=
begin
rw nat.bit0_succ_eq,
apply succ_lt_succ,
apply zero_lt_succ
end
protected lemma bit0_lt {n m : nat} (h : n < m) : bit0 n < bit0 m :=
add_lt_add h h
protected lemma bit1_lt {n m : nat} (h : n < m) : bit1 n < bit1 m :=
succ_lt_succ (add_lt_add h h)
protected lemma bit0_lt_bit1 {n m : nat} (h : n ≤ m) : bit0 n < bit1 m :=
lt_succ_of_le (add_le_add h h)
protected lemma bit1_lt_bit0 : ∀ {n m : nat}, n < m → bit1 n < bit0 m
| n 0 h := absurd h (not_lt_zero _)
| n (succ m) h :=
have n ≤ m, from le_of_lt_succ h,
have succ (n + n) ≤ succ (m + m), from succ_le_succ (add_le_add this this),
have succ (n + n) ≤ succ m + m, {rw succ_add, assumption},
show succ (n + n) < succ (succ m + m), from lt_succ_of_le this
protected lemma one_le_bit1 (n : ℕ) : 1 ≤ bit1 n :=
show 1 ≤ succ (bit0 n), from
succ_le_succ (zero_le (bit0 n))
protected lemma one_le_bit0 : ∀ (n : ℕ), n ≠ 0 → 1 ≤ bit0 n
| 0 h := absurd rfl h
| (n+1) h :=
suffices 1 ≤ succ (succ (bit0 n)), from
eq.symm (nat.bit0_succ_eq n) ▸ this,
succ_le_succ (zero_le (succ (bit0 n)))
/- Extra instances to short-circuit type class resolution -/
instance : add_comm_monoid nat := by apply_instance
instance : add_monoid nat := by apply_instance
instance : monoid nat := by apply_instance
instance : comm_monoid nat := by apply_instance
instance : comm_semigroup nat := by apply_instance
instance : semigroup nat := by apply_instance
instance : add_comm_semigroup nat := by apply_instance
instance : add_semigroup nat := by apply_instance
/- subtraction -/
protected theorem sub_zero (n : ℕ) : n - 0 = n :=
rfl
theorem sub_succ (n m : ℕ) : n - succ m = pred (n - m) :=
rfl
protected theorem zero_sub : ∀ (n : ℕ), 0 - n = 0
| 0 := by rw nat.sub_zero
| (succ n) := by rw [nat.sub_succ, zero_sub n, pred_zero]
theorem succ_sub_succ (n m : ℕ) : succ n - succ m = n - m :=
succ_sub_succ_eq_sub n m
protected theorem sub_self : ∀ (n : ℕ), n - n = 0
| 0 := by rw nat.sub_zero
| (succ n) := by rw [succ_sub_succ, sub_self n]
protected theorem add_sub_add_right : ∀ (n k m : ℕ), (n + k) - (m + k) = n - m
| n 0 m := by rw [add_zero, add_zero]
| n (succ k) m := by rw [add_succ, add_succ, succ_sub_succ, add_sub_add_right n k m]
protected theorem add_sub_add_left (k n m : ℕ) : (k + n) - (k + m) = n - m :=
by rw [add_comm k n, add_comm k m, nat.add_sub_add_right]
protected theorem add_sub_cancel (n m : ℕ) : n + m - m = n :=
suffices n + m - (0 + m) = n, from
by rwa [zero_add] at this,
by rw [nat.add_sub_add_right, nat.sub_zero]
protected theorem add_sub_cancel_left (n m : ℕ) : n + m - n = m :=
show n + m - (n + 0) = m, from
by rw [nat.add_sub_add_left, nat.sub_zero]
protected theorem sub_sub : ∀ (n m k : ℕ), n - m - k = n - (m + k)
| n m 0 := by rw [add_zero, nat.sub_zero]
| n m (succ k) := by rw [add_succ, nat.sub_succ, nat.sub_succ, sub_sub n m k]
theorem succ_sub_sub_succ (n m k : ℕ) : succ n - m - succ k = n - m - k :=
by rw [nat.sub_sub, nat.sub_sub, add_succ, succ_sub_succ]
theorem sub_self_add (n m : ℕ) : n - (n + m) = 0 :=
show (n + 0) - (n + m) = 0, from
by rw [nat.add_sub_add_left, nat.zero_sub]
protected theorem sub.right_comm (m n k : ℕ) : m - n - k = m - k - n :=
by rw [nat.sub_sub, nat.sub_sub, add_comm]
theorem sub_one (n : ℕ) : n - 1 = pred n :=
rfl
theorem succ_sub_one (n : ℕ) : succ n - 1 = n :=
rfl
theorem succ_pred_eq_of_pos : ∀ {n : ℕ}, n > 0 → succ (pred n) = n
| 0 h := absurd h (lt_irrefl 0)
| (succ k) h := rfl
theorem mul_pred_left : ∀ (n m : ℕ), pred n * m = n * m - m
| 0 m := by simp [nat.zero_sub, pred_zero, zero_mul]
| (succ n) m := by rw [pred_succ, succ_mul, nat.add_sub_cancel]
theorem mul_pred_right (n m : ℕ) : n * pred m = n * m - n :=
by rw [mul_comm, mul_pred_left, mul_comm]
protected theorem mul_sub_right_distrib : ∀ (n m k : ℕ), (n - m) * k = n * k - m * k
| n 0 k := by simp [nat.sub_zero]
| n (succ m) k := by rw [nat.sub_succ, mul_pred_left, mul_sub_right_distrib, succ_mul, nat.sub_sub]
protected theorem mul_sub_left_distrib (n m k : ℕ) : n * (m - k) = n * m - n * k :=
by rw [mul_comm, nat.mul_sub_right_distrib, mul_comm m n, mul_comm n k]
protected theorem mul_self_sub_mul_self_eq (a b : nat) : a * a - b * b = (a + b) * (a - b) :=
by rw [nat.mul_sub_left_distrib, right_distrib, right_distrib, mul_comm b a, add_comm (a*a) (a*b),
nat.add_sub_add_left]
theorem succ_mul_succ_eq (a : nat) : succ a * succ a = a*a + a + a + 1 :=
begin rw [-add_one_eq_succ], simp [right_distrib, left_distrib] end
/- TODO(Leo): sub + inequalities -/
end nat
|
0b37ba05d48e1d46716950030de555a13932146a | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/run/gcd.lean | 917626a10cd3adde8d44e4b54c34c28f7854ceaf | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,663 | lean | import data.nat data.prod
open nat well_founded decidable prod eq.ops
namespace playground
-- Setup
definition pair_nat.lt := lex lt lt
definition pair_nat.lt.wf [instance] : well_founded pair_nat.lt :=
intro_k (prod.lex.wf lt.wf lt.wf) 20 -- the '20' is for being able to execute the examples... it means 20 recursive call without proof computation
infixl `≺`:50 := pair_nat.lt
-- Lemma for justifying recursive call
private lemma lt₁ (x₁ y₁ : nat) : (x₁ - y₁, succ y₁) ≺ (succ x₁, succ y₁) :=
!lex.left (lt_succ_of_le (sub_le x₁ y₁))
-- Lemma for justifying recursive call
private lemma lt₂ (x₁ y₁ : nat) : (succ x₁, y₁ - x₁) ≺ (succ x₁, succ y₁) :=
!lex.right (lt_succ_of_le (sub_le y₁ x₁))
definition gcd.F (p₁ : nat × nat) : (Π p₂ : nat × nat, p₂ ≺ p₁ → nat) → nat :=
prod.cases_on p₁ (λ (x y : nat),
nat.cases_on x
(λ f, y) -- x = 0
(λ x₁, nat.cases_on y
(λ f, succ x₁) -- y = 0
(λ y₁ (f : (Π p₂ : nat × nat, p₂ ≺ (succ x₁, succ y₁) → nat)),
if y₁ ≤ x₁ then f (x₁ - y₁, succ y₁) !lt₁
else f (succ x₁, y₁ - x₁) !lt₂)))
definition gcd (x y : nat) :=
fix gcd.F (pair x y)
theorem gcd_def_z_y (y : nat) : gcd 0 y = y :=
well_founded.fix_eq gcd.F (0, y)
theorem gcd_def_sx_z (x : nat) : gcd (x+1) 0 = x+1 :=
well_founded.fix_eq gcd.F (x+1, 0)
theorem gcd_def_sx_sy (x y : nat) : gcd (x+1) (y+1) = if y ≤ x then gcd (x-y) (y+1) else gcd (x+1) (y-x) :=
well_founded.fix_eq gcd.F (x+1, y+1)
example : gcd 4 6 = 2 :=
rfl
example : gcd 15 6 = 3 :=
rfl
example : gcd 0 2 = 2 :=
rfl
end playground
|
84c26eb15e18c3389125d14c9dec8331c89e2f29 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/category/Group/basic.lean | 17a1980b15b3d6f3462683743ce074b500f7d318 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 10,135 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.category.Mon.basic
import category_theory.endomorphism
/-!
# Category instances for group, add_group, comm_group, and add_comm_group.
We introduce the bundled categories:
* `Group`
* `AddGroup`
* `CommGroup`
* `AddCommGroup`
along with the relevant forgetful functors between them, and to the bundled monoid categories.
-/
universes u v
open category_theory
/-- The category of groups and group morphisms. -/
@[to_additive AddGroup]
def Group : Type (u+1) := bundled group
/-- The category of additive groups and group morphisms -/
add_decl_doc AddGroup
namespace Group
@[to_additive]
instance : bundled_hom.parent_projection group.to_monoid := ⟨⟩
attribute [derive [large_category, concrete_category]] Group
attribute [to_additive] Group.large_category Group.concrete_category
@[to_additive] instance : has_coe_to_sort Group Type* := bundled.has_coe_to_sort
/-- Construct a bundled `Group` from the underlying type and typeclass. -/
@[to_additive] def of (X : Type u) [group X] : Group := bundled.of X
/-- Construct a bundled `AddGroup` from the underlying type and typeclass. -/
add_decl_doc AddGroup.of
/-- Typecheck a `monoid_hom` as a morphism in `Group`. -/
@[to_additive] def of_hom {X Y : Type u} [group X] [group Y] (f : X →* Y) : of X ⟶ of Y := f
/-- Typecheck a `add_monoid_hom` as a morphism in `AddGroup`. -/
add_decl_doc AddGroup.of_hom
@[simp, to_additive] lemma of_hom_apply {X Y : Type*} [group X] [group Y] (f : X →* Y) (x : X) :
of_hom f x = f x := rfl
@[to_additive]
instance (G : Group) : group G := G.str
@[simp, to_additive] lemma coe_of (R : Type u) [group R] : (Group.of R : Type u) = R := rfl
@[to_additive]
instance : inhabited Group := ⟨Group.of punit⟩
@[to_additive]
instance of_unique (G : Type*) [group G] [i : unique G] : unique (Group.of G) := i
@[simp, to_additive]
lemma one_apply (G H : Group) (g : G) : (1 : G ⟶ H) g = 1 := rfl
@[ext, to_additive]
lemma ext (G H : Group) (f₁ f₂ : G ⟶ H) (w : ∀ x, f₁ x = f₂ x) : f₁ = f₂ :=
by { ext1, apply w }
@[to_additive has_forget_to_AddMon]
instance has_forget_to_Mon : has_forget₂ Group Mon := bundled_hom.forget₂ _ _
@[to_additive] instance : has_coe Group.{u} Mon.{u} :=
{ coe := (forget₂ Group Mon).obj, }
end Group
/-- The category of commutative groups and group morphisms. -/
@[to_additive AddCommGroup]
def CommGroup : Type (u+1) := bundled comm_group
/-- The category of additive commutative groups and group morphisms. -/
add_decl_doc AddCommGroup
/-- `Ab` is an abbreviation for `AddCommGroup`, for the sake of mathematicians' sanity. -/
abbreviation Ab := AddCommGroup
namespace CommGroup
@[to_additive]
instance : bundled_hom.parent_projection comm_group.to_group := ⟨⟩
attribute [derive [large_category, concrete_category]] CommGroup
attribute [to_additive] CommGroup.large_category CommGroup.concrete_category
@[to_additive] instance : has_coe_to_sort CommGroup Type* := bundled.has_coe_to_sort
/-- Construct a bundled `CommGroup` from the underlying type and typeclass. -/
@[to_additive] def of (G : Type u) [comm_group G] : CommGroup := bundled.of G
/-- Construct a bundled `AddCommGroup` from the underlying type and typeclass. -/
add_decl_doc AddCommGroup.of
/-- Typecheck a `monoid_hom` as a morphism in `CommGroup`. -/
@[to_additive] def of_hom {X Y : Type u} [comm_group X] [comm_group Y] (f : X →* Y) :
of X ⟶ of Y := f
/-- Typecheck a `add_monoid_hom` as a morphism in `AddCommGroup`. -/
add_decl_doc AddCommGroup.of_hom
@[simp, to_additive] lemma of_hom_apply {X Y : Type*} [comm_group X] [comm_group Y] (f : X →* Y)
(x : X) : of_hom f x = f x := rfl
@[to_additive]
instance comm_group_instance (G : CommGroup) : comm_group G := G.str
@[simp, to_additive] lemma coe_of (R : Type u) [comm_group R] : (CommGroup.of R : Type u) = R := rfl
@[to_additive]
instance : inhabited CommGroup := ⟨CommGroup.of punit⟩
@[to_additive]
instance of_unique (G : Type*) [comm_group G] [i : unique G] : unique (CommGroup.of G) := i
@[simp, to_additive]
lemma one_apply (G H : CommGroup) (g : G) : (1 : G ⟶ H) g = 1 := rfl
@[ext, to_additive]
lemma ext (G H : CommGroup) (f₁ f₂ : G ⟶ H) (w : ∀ x, f₁ x = f₂ x) : f₁ = f₂ :=
by { ext1, apply w }
@[to_additive has_forget_to_AddGroup]
instance has_forget_to_Group : has_forget₂ CommGroup Group := bundled_hom.forget₂ _ _
@[to_additive] instance : has_coe CommGroup.{u} Group.{u} :=
{ coe := (forget₂ CommGroup Group).obj, }
@[to_additive has_forget_to_AddCommMon]
instance has_forget_to_CommMon : has_forget₂ CommGroup CommMon :=
induced_category.has_forget₂ (λ G : CommGroup, CommMon.of G)
@[to_additive] instance : has_coe CommGroup.{u} CommMon.{u} :=
{ coe := (forget₂ CommGroup CommMon).obj, }
end CommGroup
-- This example verifies an improvement possible in Lean 3.8.
-- Before that, to have `monoid_hom.map_map` usable by `simp` here,
-- we had to mark all the concrete category `has_coe_to_sort` instances reducible.
-- Now, it just works.
@[to_additive]
example {R S : CommGroup} (i : R ⟶ S) (r : R) (h : r = 1) : i r = 1 :=
by simp [h]
namespace AddCommGroup
/-- Any element of an abelian group gives a unique morphism from `ℤ` sending
`1` to that element. -/
-- Note that because `ℤ : Type 0`, this forces `G : AddCommGroup.{0}`,
-- so we write this explicitly to be clear.
-- TODO generalize this, requiring a `ulift_instances.lean` file
def as_hom {G : AddCommGroup.{0}} (g : G) : (AddCommGroup.of ℤ) ⟶ G :=
zmultiples_hom G g
@[simp]
lemma as_hom_apply {G : AddCommGroup.{0}} (g : G) (i : ℤ) : (as_hom g) i = i • g := rfl
lemma as_hom_injective {G : AddCommGroup.{0}} : function.injective (@as_hom G) :=
λ h k w, by convert congr_arg (λ k : (AddCommGroup.of ℤ) ⟶ G, (k : ℤ → G) (1 : ℤ)) w; simp
@[ext]
lemma int_hom_ext
{G : AddCommGroup.{0}} (f g : (AddCommGroup.of ℤ) ⟶ G) (w : f (1 : ℤ) = g (1 : ℤ)) : f = g :=
add_monoid_hom.ext_int w
-- TODO: this argument should be generalised to the situation where
-- the forgetful functor is representable.
lemma injective_of_mono {G H : AddCommGroup.{0}} (f : G ⟶ H) [mono f] : function.injective f :=
λ g₁ g₂ h,
begin
have t0 : as_hom g₁ ≫ f = as_hom g₂ ≫ f :=
begin
ext,
simpa [as_hom_apply] using h,
end,
have t1 : as_hom g₁ = as_hom g₂ := (cancel_mono _).1 t0,
apply as_hom_injective t1,
end
end AddCommGroup
/-- Build an isomorphism in the category `Group` from a `mul_equiv` between `group`s. -/
@[to_additive add_equiv.to_AddGroup_iso, simps]
def mul_equiv.to_Group_iso {X Y : Group} (e : X ≃* Y) : X ≅ Y :=
{ hom := e.to_monoid_hom,
inv := e.symm.to_monoid_hom }
/-- Build an isomorphism in the category `AddGroup` from an `add_equiv` between `add_group`s. -/
add_decl_doc add_equiv.to_AddGroup_iso
/-- Build an isomorphism in the category `CommGroup` from a `mul_equiv` between `comm_group`s. -/
@[to_additive add_equiv.to_AddCommGroup_iso, simps]
def mul_equiv.to_CommGroup_iso {X Y : CommGroup} (e : X ≃* Y) : X ≅ Y :=
{ hom := e.to_monoid_hom,
inv := e.symm.to_monoid_hom }
/-- Build an isomorphism in the category `AddCommGroup` from a `add_equiv` between
`add_comm_group`s. -/
add_decl_doc add_equiv.to_AddCommGroup_iso
namespace category_theory.iso
/-- Build a `mul_equiv` from an isomorphism in the category `Group`. -/
@[to_additive AddGroup_iso_to_add_equiv "Build an `add_equiv` from an isomorphism in the category
`AddGroup`.", simps]
def Group_iso_to_mul_equiv {X Y : Group} (i : X ≅ Y) : X ≃* Y :=
i.hom.to_mul_equiv i.inv i.hom_inv_id i.inv_hom_id
/-- Build a `mul_equiv` from an isomorphism in the category `CommGroup`. -/
@[to_additive AddCommGroup_iso_to_add_equiv "Build an `add_equiv` from an isomorphism
in the category `AddCommGroup`.", simps]
def CommGroup_iso_to_mul_equiv {X Y : CommGroup} (i : X ≅ Y) : X ≃* Y :=
i.hom.to_mul_equiv i.inv i.hom_inv_id i.inv_hom_id
end category_theory.iso
/-- multiplicative equivalences between `group`s are the same as (isomorphic to) isomorphisms
in `Group` -/
@[to_additive add_equiv_iso_AddGroup_iso "additive equivalences between `add_group`s are the same
as (isomorphic to) isomorphisms in `AddGroup`"]
def mul_equiv_iso_Group_iso {X Y : Group.{u}} : (X ≃* Y) ≅ (X ≅ Y) :=
{ hom := λ e, e.to_Group_iso,
inv := λ i, i.Group_iso_to_mul_equiv, }
/-- multiplicative equivalences between `comm_group`s are the same as (isomorphic to) isomorphisms
in `CommGroup` -/
@[to_additive add_equiv_iso_AddCommGroup_iso "additive equivalences between `add_comm_group`s are
the same as (isomorphic to) isomorphisms in `AddCommGroup`"]
def mul_equiv_iso_CommGroup_iso {X Y : CommGroup.{u}} : X ≃* Y ≅ (X ≅ Y) :=
{ hom := λ e, e.to_CommGroup_iso,
inv := λ i, i.CommGroup_iso_to_mul_equiv, }
namespace category_theory.Aut
/-- The (bundled) group of automorphisms of a type is isomorphic to the (bundled) group
of permutations. -/
def iso_perm {α : Type u} : Group.of (Aut α) ≅ Group.of (equiv.perm α) :=
{ hom := ⟨λ g, g.to_equiv, (by tidy), (by tidy)⟩,
inv := ⟨λ g, g.to_iso, (by tidy), (by tidy)⟩ }
/-- The (unbundled) group of automorphisms of a type is `mul_equiv` to the (unbundled) group
of permutations. -/
def mul_equiv_perm {α : Type u} : Aut α ≃* equiv.perm α :=
iso_perm.Group_iso_to_mul_equiv
end category_theory.Aut
@[to_additive]
instance Group.forget_reflects_isos : reflects_isomorphisms (forget Group.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget Group).map f),
let e : X ≃* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_Group_iso).1⟩,
end }
@[to_additive]
instance CommGroup.forget_reflects_isos : reflects_isomorphisms (forget CommGroup.{u}) :=
{ reflects := λ X Y f _,
begin
resetI,
let i := as_iso ((forget CommGroup).map f),
let e : X ≃* Y := { ..f, ..i.to_equiv },
exact ⟨(is_iso.of_iso e.to_CommGroup_iso).1⟩,
end }
|
fb7df9a2c506575beafa2f1e052aa07b93eadcc7 | 97c8e5d8aca4afeebb5b335f26a492c53680efc8 | /ground_zero/structures.lean | bc65ef6bbc26005507e7a6fe64eea6e3e90ad011 | [] | no_license | jfrancese/lean | cf32f0d8d5520b6f0e9d3987deb95841c553c53c | 06e7efaecce4093d97fb5ecc75479df2ef1dbbdb | refs/heads/master | 1,587,915,151,351 | 1,551,012,140,000 | 1,551,012,140,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,394 | lean | import ground_zero.types.unit ground_zero.types.coproduct
open ground_zero.types.unit
hott theory
namespace ground_zero
namespace structures
universes u v
def prop (α : Sort u) :=
Π (a b : α), a = b :> α
def hset (α : Sort u) :=
Π {a b : α} (p q : a = b :> α), p = q :> a = b :> α
structure contr (α : Sort u) :=
(point : α) (intro : Π (a : α), point = a :> α)
-- or we can write `idfun ~ λ _, point`
def LEM := Π (α : Type u), prop α → (α + ¬α)
def law_of_double_negation :=
Π (α : Type u), prop α → (¬¬α → α)
def LEM_inf := Π (α : Type u), α + ¬α
notation `LEM∞` := LEM_inf
inductive homotopy_level
| minus_two
| succ : homotopy_level → homotopy_level
notation `−2` := homotopy_level.minus_two
notation `−1` := homotopy_level.succ −2
instance : has_zero homotopy_level := ⟨homotopy_level.succ −1⟩
def level_to_n : homotopy_level → ℕ
| homotopy_level.minus_two := 0
| (homotopy_level.succ n) := level_to_n n + 1
def n_to_level : ℕ → homotopy_level
| 0 := homotopy_level.minus_two
| (n + 1) := homotopy_level.succ (n_to_level n)
def is_n_type : Sort u → homotopy_level → Sort (max 1 u)
| α homotopy_level.minus_two := contr α
| α (homotopy_level.succ n) := Π (x y : α),
is_n_type (x = y :> α) n
def n_type (n : homotopy_level) :=
Σ' (α : Sort u), is_n_type α n
notation n `-Type` := n_type n
def contr_impl_prop {α : Sort u} (h : contr α) : prop α :=
λ a b, (h.intro a)⁻¹ ⬝ (h.intro b)
def empty_is_prop : prop empty :=
begin intros x, induction x end
def unit_is_prop : prop types.unit :=
begin intros x y, induction x, induction y, trivial end
def prop_impl_prop {α : Prop} : prop α :=
begin intros x y, trivial end
section
open types.equiv types.eq
def prop_is_set {α : Sort u} (r : prop α) : hset α := begin
intros x y p q, have g := r x,
transitivity, symmetry, apply rewrite_comp,
exact (apd g p)⁻¹ ⬝ transport_composition p (g x),
induction q, apply inv_comp
end
-- unsafe postulate, but it computes
def function_extensionality {α : Sort u} {β : α → Sort v}
{f g : Π x, β x} (h : f ~ g) : f = g :> Π x, β x :=
support.inclusion $ funext (λ x, support.truncation (h x))
def contr_is_prop {α : Sort u} : prop (contr α) := begin
intros x y, cases x with x u, cases y with y v,
have p := u y, induction p, apply types.eq.map,
apply function_extensionality, intro a,
apply prop_is_set (contr_impl_prop ⟨x, u⟩)
end
def prop_is_prop {α : Sort u} : prop (prop α) := begin
intros f g,
have p := λ a b, (prop_is_set f) (f a b) (g a b),
apply function_extensionality, intro a,
apply function_extensionality, intro b,
exact p a b
end
end
inductive squash (α : Sort u) : Prop
| elem : α → squash
def squash.uniq {α : Sort u} (a b : squash α) : a = b :> squash α :=
types.eq.rfl
def K (α : Sort u) :=
Π (a : α) (p : a = a :> α), p = types.eq.refl a :> a = a :> α
theorem K_iff_set (α : Sort u) : K α ↔ hset α := begin
split,
{ intro h, intros x y p q,
induction q, apply h },
{ intro h, unfold K,
intros, apply h }
end
def lem_prop {α : Sort u} (h : α → prop α) : prop α :=
λ a, h a a
def lem_contr {α : Sort u} (h : α → contr α) : prop α :=
λ a, contr_impl_prop (h a) a
def is_contr_fiber {α : Sort u} {β : Sort v} (f : α → β) :=
Π (y : β), contr (types.fib f y)
end structures
-- http://www.cs.bham.ac.uk/~mhe/truncation-and-extensionality/tiny-library.html
-- http://www.cs.bham.ac.uk/~mhe/truncation-and-extensionality/hsetfunext.html
structure {u} singl {α : Sort u} (a : α) :=
(point : α) (intro : a = point :> α)
namespace singl
universe u
def trivial_loop {α : Sort u} (a : α) : singl a :=
⟨a, by reflexivity⟩
def path_from_trivial_loop {α : Sort u} {a b : α}
(r : a = b :> α) : (trivial_loop a) = ⟨b, r⟩ :> singl a :=
begin induction r, trivial end
def singl.eq {α : Sort u} {a : α} (t : singl a) :
{ point := t.point, intro := t.intro } = t :> singl a :=
begin induction t, simp end
def signl_contr {α : Sort u} (a : α) : structures.contr (singl a) :=
{ point := trivial_loop a,
intro := λ t, path_from_trivial_loop t.intro ⬝ singl.eq t }
def singl_prop {α : Sort u} (a : α) : structures.prop (singl a) :=
structures.contr_impl_prop (signl_contr a)
end singl
end ground_zero |
67ffafed0c3b53ee09916182a722d7d31f9d1ec0 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/group_theory/general_commutator.lean | 59cef90c874b1805a0c3978d728462a91f11071f | [
"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 | 4,387 | lean | /-
Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jordan Brown, Thomas Browning, Patrick Lutz
-/
import data.bracket
import group_theory.subgroup
import tactic.group
/-!
# General commutators.
If `G` is a group and `H₁ H₂ : subgroup G` then the general commutator `⁅H₁, H₂⁆ : subgroup G`
is the subgroup of `G` generated by the commutators `h₁ * h₂ * h₁⁻¹ * h₂⁻¹`.
## Main definitions
* `general_commutator H₁ H₂` : the commutator of the subgroups `H₁` and `H₂`
-/
open subgroup
variables {G G' : Type*} [group G] [group G'] {f : G →* G'}
/-- The commutator of two subgroups `H₁` and `H₂`. -/
instance general_commutator : has_bracket (subgroup G) (subgroup G) :=
⟨λ H₁ H₂, closure {x | ∃ (p ∈ H₁) (q ∈ H₂), p * q * p⁻¹ * q⁻¹ = x}⟩
lemma general_commutator_def (H₁ H₂ : subgroup G) :
⁅H₁, H₂⁆ = closure {x | ∃ (p ∈ H₁) (q ∈ H₂), p * q * p⁻¹ * q⁻¹ = x} := rfl
instance general_commutator_normal (H₁ H₂ : subgroup G) [h₁ : H₁.normal]
[h₂ : H₂.normal] : normal ⁅H₁, H₂⁆ :=
begin
let base : set G := {x | ∃ (p ∈ H₁) (q ∈ H₂), p * q * p⁻¹ * q⁻¹ = x},
suffices h_base : base = group.conjugates_of_set base,
{ dsimp only [general_commutator_def, ←base],
rw h_base,
exact subgroup.normal_closure_normal },
apply set.subset.antisymm group.subset_conjugates_of_set,
intros a h,
simp_rw [group.mem_conjugates_of_set_iff, is_conj_iff] at h,
rcases h with ⟨b, ⟨c, hc, e, he, rfl⟩, d, rfl⟩,
exact ⟨d * c * d⁻¹, h₁.conj_mem c hc d, d * e * d⁻¹, h₂.conj_mem e he d, by group⟩,
end
lemma general_commutator_mono {H₁ H₂ K₁ K₂ : subgroup G} (h₁ : H₁ ≤ K₁) (h₂ : H₂ ≤ K₂) :
⁅H₁, H₂⁆ ≤ ⁅K₁, K₂⁆ :=
begin
apply closure_mono,
rintros x ⟨p, hp, q, hq, rfl⟩,
exact ⟨p, h₁ hp, q, h₂ hq, rfl⟩,
end
lemma general_commutator_def' (H₁ H₂ : subgroup G) [H₁.normal] [H₂.normal] :
⁅H₁, H₂⁆ = normal_closure {x | ∃ (p ∈ H₁) (q ∈ H₂), p * q * p⁻¹ * q⁻¹ = x} :=
by rw [← normal_closure_eq_self ⁅H₁, H₂⁆, general_commutator_def,
normal_closure_closure_eq_normal_closure]
lemma general_commutator_le (H₁ H₂ : subgroup G) (K : subgroup G) :
⁅H₁, H₂⁆ ≤ K ↔ ∀ (p ∈ H₁) (q ∈ H₂), p * q * p⁻¹ * q⁻¹ ∈ K :=
begin
rw [general_commutator, closure_le],
split,
{ intros h p hp q hq,
exact h ⟨p, hp, q, hq, rfl⟩, },
{ rintros h x ⟨p, hp, q, hq, rfl⟩,
exact h p hp q hq, }
end
lemma general_commutator_containment (H₁ H₂ : subgroup G) {p q : G} (hp : p ∈ H₁) (hq : q ∈ H₂) :
p * q * p⁻¹ * q⁻¹ ∈ ⁅H₁, H₂⁆ :=
(general_commutator_le H₁ H₂ ⁅H₁, H₂⁆).mp (le_refl ⁅H₁, H₂⁆) p hp q hq
lemma general_commutator_comm (H₁ H₂ : subgroup G) : ⁅H₁, H₂⁆ = ⁅H₂, H₁⁆ :=
begin
suffices : ∀ H₁ H₂ : subgroup G, ⁅H₁, H₂⁆ ≤ ⁅H₂, H₁⁆, { exact le_antisymm (this _ _) (this _ _) },
intros H₁ H₂,
rw general_commutator_le,
intros p hp q hq,
have h : (p * q * p⁻¹ * q⁻¹)⁻¹ ∈ ⁅H₂, H₁⁆ := subset_closure ⟨q, hq, p, hp, by group⟩,
convert inv_mem ⁅H₂, H₁⁆ h,
group,
end
lemma general_commutator_le_right (H₁ H₂ : subgroup G) [h : normal H₂] :
⁅H₁, H₂⁆ ≤ H₂ :=
begin
rw general_commutator_le,
intros p hp q hq,
exact mul_mem H₂ (h.conj_mem q hq p) (inv_mem H₂ hq),
end
lemma general_commutator_le_left (H₁ H₂ : subgroup G) [h : normal H₁] :
⁅H₁, H₂⁆ ≤ H₁ :=
begin
rw general_commutator_comm,
exact general_commutator_le_right H₂ H₁,
end
@[simp] lemma general_commutator_bot (H : subgroup G) : ⁅H, ⊥⁆ = (⊥ : subgroup G) :=
by { rw eq_bot_iff, exact general_commutator_le_right H ⊥ }
@[simp] lemma bot_general_commutator (H : subgroup G) : ⁅(⊥ : subgroup G), H⁆ = (⊥ : subgroup G) :=
by { rw eq_bot_iff, exact general_commutator_le_left ⊥ H }
lemma general_commutator_le_inf (H₁ H₂ : subgroup G) [normal H₁] [normal H₂] :
⁅H₁, H₂⁆ ≤ H₁ ⊓ H₂ :=
by simp only [general_commutator_le_left, general_commutator_le_right, le_inf_iff, and_self]
|
aeb2bffd296471d494d5d0b7763ae211b379e030 | 97f752b44fd85ec3f635078a2dd125ddae7a82b6 | /library/theories/analysis/real_limit.lean | 28fb9800d97f13d7a7f4fc8b652e5707ef8f34cb | [
"Apache-2.0"
] | permissive | tectronics/lean | ab977ba6be0fcd46047ddbb3c8e16e7c26710701 | f38af35e0616f89c6e9d7e3eb1d48e47ee666efe | refs/heads/master | 1,532,358,526,384 | 1,456,276,623,000 | 1,456,276,623,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,508 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
Instantiates the reals as a Banach space.
-/
import .metric_space data.real.complete data.set .normed_space
open real classical analysis nat
noncomputable theory
/- sup and inf -/
-- Expresses completeness, sup, and inf in a manner that is less constructive, but more convenient,
-- than the way it is done in data.real.complete.
-- Issue: real.sup and real.inf conflict with sup and inf in lattice.
-- Perhaps put algebra sup and inf into a namespace?
namespace real
open set
private definition exists_is_sup {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) :
∃ y, is_sup X y :=
let x := some (and.left H), b := some (and.right H) in
exists_is_sup_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H))
private definition sup_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) :=
some (exists_is_sup H)
private definition sup_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) :
is_sup X (sup_aux H) :=
some_spec (exists_is_sup H)
definition sup (X : set ℝ) : ℝ :=
if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b) then sup_aux H else 0
proposition le_sup {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) :
x ≤ sup X :=
have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b),
from and.intro (exists.intro x Hx) (exists.intro b Hb),
by+ rewrite [↑sup, dif_pos H]; exact and.left (sup_aux_spec H) x Hx
proposition sup_le {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) :
sup X ≤ b :=
have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b),
from and.intro HX (exists.intro b Hb),
by+ rewrite [↑sup, dif_pos H]; exact and.right (sup_aux_spec H) b Hb
proposition exists_mem_and_lt_of_lt_sup {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : b < sup X) :
∃ x, x ∈ X ∧ b < x :=
have ¬ ∀ x, x ∈ X → x ≤ b, from assume H, not_le_of_gt Hb (sup_le HX H),
obtain x (Hx : ¬ (x ∈ X → x ≤ b)), from exists_not_of_not_forall this,
exists.intro x
(have x ∈ X ∧ ¬ x ≤ b, by rewrite [-not_implies_iff_and_not]; apply Hx,
and.intro (and.left this) (lt_of_not_ge (and.right this)))
private definition exists_is_inf {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) :
∃ y, is_inf X y :=
let x := some (and.left H), b := some (and.right H) in
exists_is_inf_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H))
private definition inf_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) :=
some (exists_is_inf H)
private definition inf_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) :
is_inf X (inf_aux H) :=
some_spec (exists_is_inf H)
definition inf (X : set ℝ) : ℝ :=
if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x) then inf_aux H else 0
proposition inf_le {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) :
inf X ≤ x :=
have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x),
from and.intro (exists.intro x Hx) (exists.intro b Hb),
by+ rewrite [↑inf, dif_pos H]; exact and.left (inf_aux_spec H) x Hx
proposition le_inf {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) :
b ≤ inf X :=
have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x),
from and.intro HX (exists.intro b Hb),
by+ rewrite [↑inf, dif_pos H]; exact and.right (inf_aux_spec H) b Hb
proposition exists_mem_and_lt_of_inf_lt {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : inf X < b) :
∃ x, x ∈ X ∧ x < b :=
have ¬ ∀ x, x ∈ X → b ≤ x, from assume H, not_le_of_gt Hb (le_inf HX H),
obtain x (Hx : ¬ (x ∈ X → b ≤ x)), from exists_not_of_not_forall this,
exists.intro x
(have x ∈ X ∧ ¬ b ≤ x, by rewrite [-not_implies_iff_and_not]; apply Hx,
and.intro (and.left this) (lt_of_not_ge (and.right this)))
section
local attribute mem [quasireducible]
-- TODO: is there a better place to put this?
proposition image_neg_eq (X : set ℝ) : (λ x, -x) ' X = {x | -x ∈ X} :=
set.ext (take x, iff.intro
(assume H, obtain y [(Hy₁ : y ∈ X) (Hy₂ : -y = x)], from H,
show -x ∈ X, by rewrite [-Hy₂, neg_neg]; exact Hy₁)
(assume H : -x ∈ X, exists.intro (-x) (and.intro H !neg_neg)))
proposition sup_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) :
sup {x | -x ∈ X} = - inf X :=
let negX := {x | -x ∈ X} in
have nonempty_negX : ∃ x, x ∈ negX, from
obtain x Hx, from nonempty_X,
have -(-x) ∈ X,
by rewrite neg_neg; apply Hx,
exists.intro (-x) this,
have H₁ : ∀ x, x ∈ negX → x ≤ - inf X, from
take x,
assume H,
have inf X ≤ -x,
from inf_le H Hb,
show x ≤ - inf X,
from le_neg_of_le_neg this,
have H₂ : ∀ x, x ∈ X → -sup negX ≤ x, from
take x,
assume H,
have -(-x) ∈ X, by rewrite neg_neg; apply H,
have -x ≤ sup negX, from le_sup this H₁,
show -sup negX ≤ x,
from !neg_le_of_neg_le this,
eq_of_le_of_ge
(show sup negX ≤ - inf X,
from sup_le nonempty_negX H₁)
(show -inf X ≤ sup negX,
from !neg_le_of_neg_le (le_inf nonempty_X H₂))
proposition inf_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) :
inf {x | -x ∈ X} = - sup X :=
let negX := {x | -x ∈ X} in
have nonempty_negX : ∃ x, x ∈ negX, from
obtain x Hx, from nonempty_X,
have -(-x) ∈ X,
by rewrite neg_neg; apply Hx,
exists.intro (-x) this,
have Hb' : ∀ x, x ∈ negX → -b ≤ x,
from take x, assume H, !neg_le_of_neg_le (Hb _ H),
have HX : X = {x | -x ∈ negX},
from set.ext (take x, by rewrite [↑set_of, ↑mem, +neg_neg]),
show inf {x | -x ∈ X} = - sup X,
using HX Hb' nonempty_negX, by rewrite [HX at {2}, sup_neg nonempty_negX Hb', neg_neg]
end
end real
/- the reals form a complete metric space -/
namespace analysis
theorem dist_eq_abs (x y : real) : dist x y = abs (x - y) := rfl
proposition converges_to_seq_real_intro {X : ℕ → ℝ} {y : ℝ}
(H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε) :
(X ⟶ y in ℕ) := H
proposition converges_to_seq_real_elim {X : ℕ → ℝ} {y : ℝ} (H : X ⟶ y in ℕ) :
∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε := H
proposition converges_to_seq_real_intro' {X : ℕ → ℝ} {y : ℝ}
(H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) ≤ ε) :
converges_to_seq X y :=
converges_to_seq.intro H
open pnat subtype
local postfix ⁻¹ := pnat.inv
private definition pnat.succ (n : ℕ) : ℕ+ := tag (succ n) !succ_pos
private definition r_seq_of (X : ℕ → ℝ) : r_seq := λ n, X (elt_of n)
private lemma rate_of_cauchy_aux {X : ℕ → ℝ} (H : cauchy X) :
∀ k : ℕ+, ∃ N : ℕ+, ∀ m n : ℕ+,
m ≥ N → n ≥ N → abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹ :=
take k : ℕ+,
have H1 : (k⁻¹ >[rat] (rat.of_num 0)), from !pnat.inv_pos,
have H2 : (of_rat k⁻¹ > of_rat (rat.of_num 0)), from !of_rat_lt_of_rat_of_lt H1,
obtain (N : ℕ) (H : ∀ m n, m ≥ N → n ≥ N → abs (X m - X n) < of_rat k⁻¹), from H _ H2,
exists.intro (pnat.succ N)
(take m n : ℕ+,
assume Hm : m ≥ (pnat.succ N),
assume Hn : n ≥ (pnat.succ N),
have Hm' : elt_of m ≥ N, begin apply le.trans, apply le_succ, apply Hm end,
have Hn' : elt_of n ≥ N, begin apply le.trans, apply le_succ, apply Hn end,
show abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹, from le_of_lt (H _ _ Hm' Hn'))
private definition rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) (k : ℕ+) : ℕ+ :=
some (rate_of_cauchy_aux H k)
private lemma cauchy_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) :
cauchy_with_rate (r_seq_of X) (rate_of_cauchy H) :=
take k : ℕ+,
some_spec (rate_of_cauchy_aux H k)
private lemma converges_to_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) :
∃ l Nb, converges_to_with_rate (r_seq_of X) l Nb :=
begin
apply exists.intro,
apply exists.intro,
apply converges_to_with_rate_of_cauchy_with_rate,
exact cauchy_with_rate_of_cauchy H
end
theorem converges_seq_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : converges_seq X :=
obtain l Nb (conv : converges_to_with_rate (r_seq_of X) l Nb),
from converges_to_with_rate_of_cauchy H,
exists.intro l
(take ε : ℝ,
suppose ε > 0,
obtain (k' : ℕ) (Hn : 1 / succ k' < ε), from archimedean_small `ε > 0`,
let k : ℕ+ := tag (succ k') !succ_pos,
N : ℕ+ := Nb k in
have Hk : real.of_rat k⁻¹ < ε,
by rewrite [↑pnat.inv, of_rat_divide]; exact Hn,
exists.intro (elt_of N)
(take n : ℕ,
assume Hn : n ≥ elt_of N,
let n' : ℕ+ := tag n (nat.lt_of_lt_of_le (has_property N) Hn) in
have abs (X n - l) ≤ real.of_rat k⁻¹, by apply conv k n' Hn,
show abs (X n - l) < ε, from lt_of_le_of_lt this Hk))
end analysis
definition complete_metric_space_real [reducible] [trans_instance] :
complete_metric_space ℝ :=
⦃complete_metric_space, metric_space_real,
complete := @analysis.converges_seq_of_cauchy
⦄
/- the real numbers can be viewed as a banach space -/
definition real_vector_space_real : real_vector_space ℝ :=
⦃ real_vector_space, real.discrete_linear_ordered_field,
smul := mul,
smul_left_distrib := left_distrib,
smul_right_distrib := right_distrib,
mul_smul := mul.assoc,
one_smul := one_mul
⦄
definition banach_space_real [trans_instance] [reducible] : banach_space ℝ :=
⦃ banach_space, real_vector_space_real,
norm := abs,
norm_zero := abs_zero,
eq_zero_of_norm_eq_zero := λ a H, eq_zero_of_abs_eq_zero H,
norm_triangle := abs_add_le_abs_add_abs,
norm_smul := abs_mul,
complete := λ X H, analysis.complete ℝ H
⦄
/- limits under pointwise operations -/
section limit_operations
variables {X Y : ℕ → ℝ}
variables {x y : ℝ}
proposition mul_left_converges_to_seq (c : ℝ) (HX : X ⟶ x in ℕ) :
(λ n, c * X n) ⟶ c * x in ℕ :=
smul_converges_to_seq c HX
proposition mul_right_converges_to_seq (c : ℝ) (HX : X ⟶ x in ℕ) :
(λ n, X n * c) ⟶ x * c in ℕ :=
have (λ n, X n * c) = (λ n, c * X n), from funext (take x, !mul.comm),
by+ rewrite [this, mul.comm]; apply mul_left_converges_to_seq c HX
theorem converges_to_seq_squeeze (HX : X ⟶ x in ℕ) (HY : Y ⟶ x in ℕ) {Z : ℕ → ℝ} (HZX : ∀ n, X n ≤ Z n)
(HZY : ∀ n, Z n ≤ Y n) : Z ⟶ x in ℕ :=
begin
intros ε Hε,
have Hε4 : ε / 4 > 0, from div_pos_of_pos_of_pos Hε four_pos,
cases HX Hε4 with N1 HN1,
cases HY Hε4 with N2 HN2,
existsi max N1 N2,
intro n Hn,
have HXY : abs (Y n - X n) < ε / 2, begin
apply lt_of_le_of_lt,
apply abs_sub_le _ x,
have Hε24 : ε / 2 = ε / 4 + ε / 4, from eq.symm !add_quarters,
rewrite Hε24,
apply add_lt_add,
apply HN2,
apply ge.trans Hn !le_max_right,
rewrite abs_sub,
apply HN1,
apply ge.trans Hn !le_max_left
end,
have HZX : abs (Z n - X n) < ε / 2, begin
have HZXnp : Z n - X n ≥ 0, from sub_nonneg_of_le !HZX,
have HXYnp : Y n - X n ≥ 0, from sub_nonneg_of_le (le.trans !HZX !HZY),
rewrite [abs_of_nonneg HZXnp, abs_of_nonneg HXYnp at HXY],
note Hgt := lt_add_of_sub_lt_right HXY,
have Hlt : Z n < ε / 2 + X n, from calc
Z n ≤ Y n : HZY
... < ε / 2 + X n : Hgt,
apply sub_lt_right_of_lt_add Hlt
end,
have H : abs (Z n - x) < ε, begin
apply lt_of_le_of_lt,
apply abs_sub_le _ (X n),
apply lt.trans,
apply add_lt_add,
apply HZX,
apply HN1,
apply ge.trans Hn !le_max_left,
apply div_two_add_div_four_lt Hε
end,
exact H
end
proposition converges_to_seq_of_abs_sub_converges_to_seq (Habs : (λ n, abs (X n - x)) ⟶ 0 in ℕ) :
X ⟶ x in ℕ :=
begin
intros ε Hε,
cases Habs Hε with N HN,
existsi N,
intro n Hn,
have Hn' : abs (abs (X n - x) - 0) < ε, from HN Hn,
rewrite [sub_zero at Hn', abs_abs at Hn'],
exact Hn'
end
proposition abs_sub_converges_to_seq_of_converges_to_seq (HX : X ⟶ x in ℕ) :
(λ n, abs (X n - x)) ⟶ 0 in ℕ :=
begin
intros ε Hε,
cases HX Hε with N HN,
existsi N,
intro n Hn,
have Hn' : abs (abs (X n - x) - 0) < ε, by rewrite [sub_zero, abs_abs]; apply HN Hn,
exact Hn'
end
proposition mul_converges_to_seq (HX : X ⟶ x in ℕ) (HY : Y ⟶ y in ℕ) :
(λ n, X n * Y n) ⟶ x * y in ℕ :=
have Hbd : ∃ K : ℝ, ∀ n : ℕ, abs (X n) ≤ K, begin
cases bounded_of_converges_seq HX with K HK,
existsi K + abs x,
intro n,
note Habs := le.trans (abs_abs_sub_abs_le_abs_sub (X n) x) !HK,
apply le_add_of_sub_right_le,
apply le.trans,
apply le_abs_self,
assumption
end,
obtain K HK, from Hbd,
have Habsle [visible] : ∀ n, abs (X n * Y n - x * y) ≤ K * abs (Y n - y) + abs y * abs (X n - x), begin
intro,
have Heq : X n * Y n - x * y = (X n * Y n - X n * y) + (X n * y - x * y), by
rewrite [-sub_add_cancel (X n * Y n) (X n * y) at {1}, sub_eq_add_neg, *add.assoc],
apply le.trans,
rewrite Heq,
apply abs_add_le_abs_add_abs,
apply add_le_add,
rewrite [-mul_sub_left_distrib, abs_mul],
apply mul_le_mul_of_nonneg_right,
apply HK,
apply abs_nonneg,
rewrite [-mul_sub_right_distrib, abs_mul, mul.comm],
apply le.refl
end,
have Hdifflim [visible] : (λ n, abs (X n * Y n - x * y)) ⟶ 0 in ℕ, begin
apply converges_to_seq_squeeze,
rotate 2,
intro, apply abs_nonneg,
apply Habsle,
apply converges_to_seq_constant,
rewrite -{0}zero_add,
apply add_converges_to_seq,
krewrite -(mul_zero K),
apply mul_left_converges_to_seq,
apply abs_sub_converges_to_seq_of_converges_to_seq,
exact HY,
krewrite -(mul_zero (abs y)),
apply mul_left_converges_to_seq,
apply abs_sub_converges_to_seq_of_converges_to_seq,
exact HX
end,
converges_to_seq_of_abs_sub_converges_to_seq Hdifflim
-- TODO: converges_to_seq_div, converges_to_seq_mul_left_iff, etc.
proposition abs_converges_to_seq_zero (HX : X ⟶ 0 in ℕ) : (λ n, abs (X n)) ⟶ 0 in ℕ :=
norm_converges_to_seq_zero HX
proposition converges_to_seq_zero_of_abs_converges_to_seq_zero (HX : (λ n, abs (X n)) ⟶ 0 in ℕ) :
X ⟶ 0 in ℕ :=
converges_to_seq_zero_of_norm_converges_to_seq_zero HX
proposition abs_converges_to_seq_zero_iff (X : ℕ → ℝ) :
((λ n, abs (X n)) ⟶ 0 in ℕ) ↔ (X ⟶ 0 in ℕ) :=
iff.intro converges_to_seq_zero_of_abs_converges_to_seq_zero abs_converges_to_seq_zero
-- TODO: products of two sequences, converges_seq, limit_seq
end limit_operations
/- properties of converges_to_at -/
section limit_operations_continuous
variables {f g : ℝ → ℝ}
variables {a b x y : ℝ}
theorem mul_converges_to_at (Hf : f ⟶ a at x) (Hg : g ⟶ b at x) : (λ z, f z * g z) ⟶ a * b at x :=
begin
apply converges_to_at_of_all_conv_seqs,
intro X HX,
apply mul_converges_to_seq,
note Hfc := all_conv_seqs_of_converges_to_at Hf,
apply Hfc _ HX,
note Hgb := all_conv_seqs_of_converges_to_at Hg,
apply Hgb _ HX
end
end limit_operations_continuous
/- monotone sequences -/
section monotone_sequences
open real set
variable {X : ℕ → ℝ}
definition nondecreasing (X : ℕ → ℝ) : Prop := ∀ ⦃i j⦄, i ≤ j → X i ≤ X j
proposition nondecreasing_of_forall_le_succ (H : ∀ i, X i ≤ X (succ i)) : nondecreasing X :=
take i j, suppose i ≤ j,
have ∀ n, X i ≤ X (i + n), from
take n, nat.induction_on n
(by rewrite nat.add_zero; apply le.refl)
(take n, assume ih, le.trans ih (H (i + n))),
have X i ≤ X (i + (j - i)), from !this,
by+ rewrite [add_sub_of_le `i ≤ j` at this]; exact this
proposition converges_to_seq_sup_of_nondecreasing (nondecX : nondecreasing X) {b : ℝ}
(Hb : ∀ i, X i ≤ b) : X ⟶ sup (X ' univ) in ℕ :=
let sX := sup (X ' univ) in
have Xle : ∀ i, X i ≤ sX, from
take i,
have ∀ x, x ∈ X ' univ → x ≤ b, from
(take x, assume H,
obtain i [H' (Hi : X i = x)], from H,
by rewrite -Hi; exact Hb i),
show X i ≤ sX, from le_sup (mem_image_of_mem X !mem_univ) this,
have exX : ∃ x, x ∈ X ' univ,
from exists.intro (X 0) (mem_image_of_mem X !mem_univ),
take ε, assume epos : ε > 0,
have sX - ε < sX, from !sub_lt_of_pos epos,
obtain x' [(H₁x' : x' ∈ X ' univ) (H₂x' : sX - ε < x')],
from exists_mem_and_lt_of_lt_sup exX this,
obtain i [H' (Hi : X i = x')], from H₁x',
have Hi' : ∀ j, j ≥ i → sX - ε < X j, from
take j, assume Hj, lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj),
exists.intro i
(take j, assume Hj : j ≥ i,
have X j - sX ≤ 0, from sub_nonpos_of_le (Xle j),
have eq₁ : abs (X j - sX) = sX - X j, using this, by rewrite [abs_of_nonpos this, neg_sub],
have sX - ε < X j, from lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj),
have sX < X j + ε, from lt_add_of_sub_lt_right this,
have sX - X j < ε, from sub_lt_left_of_lt_add this,
show (abs (X j - sX)) < ε, using eq₁ this, by rewrite eq₁; exact this)
definition nonincreasing (X : ℕ → ℝ) : Prop := ∀ ⦃i j⦄, i ≤ j → X i ≥ X j
proposition nodecreasing_of_nonincreasing_neg (nonincX : nonincreasing (λ n, - X n)) :
nondecreasing (λ n, X n) :=
take i j, suppose i ≤ j,
show X i ≤ X j, from le_of_neg_le_neg (nonincX this)
proposition noincreasing_neg_of_nondecreasing (nondecX : nondecreasing X) :
nonincreasing (λ n, - X n) :=
take i j, suppose i ≤ j,
show - X i ≥ - X j, from neg_le_neg (nondecX this)
proposition nonincreasing_neg_iff (X : ℕ → ℝ) : nonincreasing (λ n, - X n) ↔ nondecreasing X :=
iff.intro nodecreasing_of_nonincreasing_neg noincreasing_neg_of_nondecreasing
proposition nonincreasing_of_nondecreasing_neg (nondecX : nondecreasing (λ n, - X n)) :
nonincreasing (λ n, X n) :=
take i j, suppose i ≤ j,
show X i ≥ X j, from le_of_neg_le_neg (nondecX this)
proposition nodecreasing_neg_of_nonincreasing (nonincX : nonincreasing X) :
nondecreasing (λ n, - X n) :=
take i j, suppose i ≤ j,
show - X i ≤ - X j, from neg_le_neg (nonincX this)
proposition nondecreasing_neg_iff (X : ℕ → ℝ) : nondecreasing (λ n, - X n) ↔ nonincreasing X :=
iff.intro nonincreasing_of_nondecreasing_neg nodecreasing_neg_of_nonincreasing
proposition nonincreasing_of_forall_succ_le (H : ∀ i, X (succ i) ≤ X i) : nonincreasing X :=
begin
rewrite -nondecreasing_neg_iff,
show nondecreasing (λ n : ℕ, - X n), from
nondecreasing_of_forall_le_succ (take i, neg_le_neg (H i))
end
proposition converges_to_seq_inf_of_nonincreasing (nonincX : nonincreasing X) {b : ℝ}
(Hb : ∀ i, b ≤ X i) : X ⟶ inf (X ' univ) in ℕ :=
have H₁ : ∃ x, x ∈ X ' univ, from exists.intro (X 0) (mem_image_of_mem X !mem_univ),
have H₂ : ∀ x, x ∈ X ' univ → b ≤ x, from
(take x, assume H,
obtain i [Hi₁ (Hi₂ : X i = x)], from H,
show b ≤ x, by rewrite -Hi₂; apply Hb i),
have H₃ : {x : ℝ | -x ∈ X ' univ} = {x : ℝ | x ∈ (λ n, -X n) ' univ}, from calc
{x : ℝ | -x ∈ X ' univ} = (λ y, -y) ' (X ' univ) : by rewrite image_neg_eq
... = {x : ℝ | x ∈ (λ n, -X n) ' univ} : image_comp,
have H₄ : ∀ i, - X i ≤ - b, from take i, neg_le_neg (Hb i),
begin+
-- need krewrite here
krewrite [-neg_converges_to_seq_iff, -sup_neg H₁ H₂, H₃, -nondecreasing_neg_iff at nonincX],
apply converges_to_seq_sup_of_nondecreasing nonincX H₄
end
end monotone_sequences
/- x^n converges to 0 if abs x < 1 -/
section xn
open nat set
theorem pow_converges_to_seq_zero {x : ℝ} (H : abs x < 1) :
(λ n, x^n) ⟶ 0 in ℕ :=
suffices H' : (λ n, (abs x)^n) ⟶ 0 in ℕ, from
have (λ n, (abs x)^n) = (λ n, abs (x^n)), from funext (take n, eq.symm !abs_pow),
using this,
by rewrite this at H'; exact converges_to_seq_zero_of_abs_converges_to_seq_zero H',
let aX := (λ n, (abs x)^n),
iaX := real.inf (aX ' univ),
asX := (λ n, (abs x)^(succ n)) in
have noninc_aX : nonincreasing aX, from
nonincreasing_of_forall_succ_le
(take i,
assert (abs x) * (abs x)^i ≤ 1 * (abs x)^i,
from mul_le_mul_of_nonneg_right (le_of_lt H) (!pow_nonneg_of_nonneg !abs_nonneg),
assert (abs x) * (abs x)^i ≤ (abs x)^i, by krewrite one_mul at this; exact this,
show (abs x) ^ (succ i) ≤ (abs x)^i, by rewrite pow_succ; apply this),
have bdd_aX : ∀ i, 0 ≤ aX i, from take i, !pow_nonneg_of_nonneg !abs_nonneg,
assert aXconv : aX ⟶ iaX in ℕ, proof converges_to_seq_inf_of_nonincreasing noninc_aX bdd_aX qed,
have asXconv : asX ⟶ iaX in ℕ, from converges_to_seq_offset_succ aXconv,
have asXconv' : asX ⟶ (abs x) * iaX in ℕ, from mul_left_converges_to_seq (abs x) aXconv,
have iaX = (abs x) * iaX, from converges_to_seq_unique asXconv asXconv',
assert iaX = 0, from eq_zero_of_mul_eq_self_left (ne_of_lt H) (eq.symm this),
show aX ⟶ 0 in ℕ, begin rewrite -this, exact aXconv end --from this ▸ aXconv
end xn
/- continuity on the reals -/
section continuous
theorem continuous_real_elim {f : ℝ → ℝ} (H : continuous f) :
∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ,
abs (x' - x) < δ → abs (f x' - f x) < ε :=
take x, continuous_at_elim (H x)
theorem continuous_real_intro {f : ℝ → ℝ}
(H : ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ,
abs (x' - x) < δ → abs (f x' - f x) < ε) :
continuous f :=
take x, continuous_at_intro (H x)
theorem pos_on_nbhd_of_cts_of_pos {f : ℝ → ℝ} (Hf : continuous f) {b : ℝ} (Hb : f b > 0) :
∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (y - b) < δ → f y > 0 :=
begin
let Hcont := continuous_real_elim Hf b Hb,
cases Hcont with δ Hδ,
existsi δ,
split,
exact and.left Hδ,
intro y Hy,
let Hy' := and.right Hδ y Hy,
note Hlt := sub_lt_of_abs_sub_lt_left Hy',
rewrite sub_self at Hlt,
assumption
end
theorem neg_on_nbhd_of_cts_of_neg {f : ℝ → ℝ} (Hf : continuous f) {b : ℝ} (Hb : f b < 0) :
∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (y - b) < δ → f y < 0 :=
begin
let Hcont := continuous_real_elim Hf b (neg_pos_of_neg Hb),
cases Hcont with δ Hδ,
existsi δ,
split,
exact and.left Hδ,
intro y Hy,
let Hy' := and.right Hδ y Hy,
let Hlt := sub_lt_of_abs_sub_lt_right Hy',
note Hlt' := lt_add_of_sub_lt_left Hlt,
rewrite [add.comm at Hlt', -sub_eq_add_neg at Hlt', sub_self at Hlt'],
assumption
end
theorem continuous_neg_of_continuous {f : ℝ → ℝ} (Hcon : continuous f) : continuous (λ x, - f x) :=
begin
apply continuous_real_intro,
intros x ε Hε,
cases continuous_real_elim Hcon x Hε with δ Hδ,
cases Hδ with Hδ₁ Hδ₂,
existsi δ,
split,
assumption,
intros x' Hx',
let HD := Hδ₂ x' Hx',
rewrite [-abs_neg, neg_neg_sub_neg],
exact HD
end
theorem continuous_offset_of_continuous {f : ℝ → ℝ} (Hcon : continuous f) (a : ℝ) :
continuous (λ x, (f x) + a) :=
begin
apply continuous_real_intro,
intros x ε Hε,
cases continuous_real_elim Hcon x Hε with δ Hδ,
cases Hδ with Hδ₁ Hδ₂,
existsi δ,
split,
assumption,
intros x' Hx',
rewrite [add_sub_comm, sub_self, add_zero],
apply Hδ₂,
assumption
end
theorem continuous_mul_of_continuous {f g : ℝ → ℝ} (Hconf : continuous f) (Hcong : continuous g) :
continuous (λ x, f x * g x) :=
begin
intro x,
apply continuous_at_of_converges_to_at,
apply mul_converges_to_at,
all_goals apply converges_to_at_of_continuous_at,
apply Hconf,
apply Hcong
end
end continuous
|
3e0077fcfac7e3eee1fc84b73db8378729a0e4a1 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /tests/lean/run/e18.lean | a9f55a97ac34d9b92560f852f4c3f72d92994e94 | [
"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 | 494 | lean | prelude
inductive nat : Type :=
zero : nat,
succ : nat → nat
inductive list (A : Type) : Type :=
nil {} : list A,
cons : A → list A → list A
inductive int : Type :=
of_nat : nat → int,
neg : nat → int
attribute int.of_nat [coercion]
constants n m : nat
constants i j : int
constant l : list nat
namespace list end list open list
check cons i (cons i nil)
check cons n (cons n nil)
check cons i (cons n nil)
check cons n (cons i nil)
check cons n (cons i (cons m (cons j nil)))
|
d45a4d5224fd7ce1b8382189a936521c6fd5bc5c | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/lean/diamond3.lean | 637cb84982f4c4abe5af1ffa16dea25e4d64f36e | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 254 | lean | structure A where
x : Nat := 0
y : Nat := 0
f : Nat → Nat := (. + 10)
structure B extends A where
z : Nat
structure C extends A where
w : Nat
set_option structureDiamondWarning false
structure D extends B, C where
a : Nat
#print D.toC
|
a44f7fb462b800037a63c56d10a3d82778575be8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/whiskering.lean | 60bed39c4592b7475c0d2e1e2023004fab64f4d4 | [
"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 | 8,699 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.isomorphism
import category_theory.functor.category
import category_theory.functor.fully_faithful
/-!
# Whiskering
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Given a functor `F : C ⥤ D` and functors `G H : D ⥤ E` and a natural transformation `α : G ⟶ H`,
we can construct a new natural transformation `F ⋙ G ⟶ F ⋙ H`,
called `whisker_left F α`. This is the same as the horizontal composition of `𝟙 F` with `α`.
This operation is functorial in `F`, and we package this as `whiskering_left`. Here
`(whiskering_left.obj F).obj G` is `F ⋙ G`, and
`(whiskering_left.obj F).map α` is `whisker_left F α`.
(That is, we might have alternatively named this as the "left composition functor".)
We also provide analogues for composition on the right, and for these operations on isomorphisms.
At the end of the file, we provide the left and right unitors, and the associator,
for functor composition.
(In fact functor composition is definitionally associative, but very often relying on this causes
extremely slow elaboration, so it is better to insert it explicitly.)
We also show these natural isomorphisms satisfy the triangle and pentagon identities.
-/
namespace category_theory
universes u₁ v₁ u₂ v₂ u₃ v₃ u₄ v₄
section
variables {C : Type u₁} [category.{v₁} C]
{D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
/--
If `α : G ⟶ H` then
`whisker_left F α : (F ⋙ G) ⟶ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
@[simps] def whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) : (F ⋙ G) ⟶ (F ⋙ H) :=
{ app := λ X, α.app (F.obj X),
naturality' := λ X Y f, by rw [functor.comp_map, functor.comp_map, α.naturality] }
/--
If `α : G ⟶ H` then
`whisker_right α F : (G ⋙ F) ⟶ (G ⋙ F)` has components `F.map (α.app X)`.
-/
@[simps] def whisker_right {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) : (G ⋙ F) ⟶ (H ⋙ F) :=
{ app := λ X, F.map (α.app X),
naturality' := λ X Y f,
by rw [functor.comp_map, functor.comp_map, ←F.map_comp, ←F.map_comp, α.naturality] }
variables (C D E)
/--
Left-composition gives a functor `(C ⥤ D) ⥤ ((D ⥤ E) ⥤ (C ⥤ E))`.
`(whiskering_left.obj F).obj G` is `F ⋙ G`, and
`(whiskering_left.obj F).map α` is `whisker_left F α`.
-/
@[simps] def whiskering_left : (C ⥤ D) ⥤ ((D ⥤ E) ⥤ (C ⥤ E)) :=
{ obj := λ F,
{ obj := λ G, F ⋙ G,
map := λ G H α, whisker_left F α },
map := λ F G τ,
{ app := λ H,
{ app := λ c, H.map (τ.app c),
naturality' := λ X Y f, begin dsimp, rw [←H.map_comp, ←H.map_comp, ←τ.naturality] end },
naturality' := λ X Y f, begin ext, dsimp, rw [f.naturality] end } }
/--
Right-composition gives a functor `(D ⥤ E) ⥤ ((C ⥤ D) ⥤ (C ⥤ E))`.
`(whiskering_right.obj H).obj F` is `F ⋙ H`, and
`(whiskering_right.obj H).map α` is `whisker_right α H`.
-/
@[simps] def whiskering_right : (D ⥤ E) ⥤ ((C ⥤ D) ⥤ (C ⥤ E)) :=
{ obj := λ H,
{ obj := λ F, F ⋙ H,
map := λ _ _ α, whisker_right α H },
map := λ G H τ,
{ app := λ F,
{ app := λ c, τ.app (F.obj c),
naturality' := λ X Y f, begin dsimp, rw [τ.naturality] end },
naturality' := λ X Y f, begin ext, dsimp, rw [←nat_trans.naturality] end } }
variables {C} {D} {E}
instance faithful_whiskering_right_obj {F : D ⥤ E} [faithful F] :
faithful ((whiskering_right C D E).obj F) :=
{ map_injective' := λ G H α β hαβ, nat_trans.ext _ _ $ funext $ λ X,
functor.map_injective _ $ congr_fun (congr_arg nat_trans.app hαβ) X }
@[simp] lemma whisker_left_id (F : C ⥤ D) {G : D ⥤ E} :
whisker_left F (nat_trans.id G) = nat_trans.id (F.comp G) :=
rfl
@[simp] lemma whisker_left_id' (F : C ⥤ D) {G : D ⥤ E} :
whisker_left F (𝟙 G) = 𝟙 (F.comp G) :=
rfl
@[simp] lemma whisker_right_id {G : C ⥤ D} (F : D ⥤ E) :
whisker_right (nat_trans.id G) F = nat_trans.id (G.comp F) :=
((whiskering_right C D E).obj F).map_id _
@[simp] lemma whisker_right_id' {G : C ⥤ D} (F : D ⥤ E) :
whisker_right (𝟙 G) F = 𝟙 (G.comp F) :=
((whiskering_right C D E).obj F).map_id _
@[simp] lemma whisker_left_comp (F : C ⥤ D) {G H K : D ⥤ E} (α : G ⟶ H) (β : H ⟶ K) :
whisker_left F (α ≫ β) = (whisker_left F α) ≫ (whisker_left F β) :=
rfl
@[simp] lemma whisker_right_comp {G H K : C ⥤ D} (α : G ⟶ H) (β : H ⟶ K) (F : D ⥤ E) :
whisker_right (α ≫ β) F = (whisker_right α F) ≫ (whisker_right β F) :=
((whiskering_right C D E).obj F).map_comp α β
/--
If `α : G ≅ H` is a natural isomorphism then
`iso_whisker_left F α : (F ⋙ G) ≅ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
def iso_whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) : (F ⋙ G) ≅ (F ⋙ H) :=
((whiskering_left C D E).obj F).map_iso α
@[simp] lemma iso_whisker_left_hom (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(iso_whisker_left F α).hom = whisker_left F α.hom :=
rfl
@[simp] lemma iso_whisker_left_inv (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(iso_whisker_left F α).inv = whisker_left F α.inv :=
rfl
/--
If `α : G ≅ H` then
`iso_whisker_right α F : (G ⋙ F) ≅ (H ⋙ F)` has components `F.map_iso (α.app X)`.
-/
def iso_whisker_right {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) : (G ⋙ F) ≅ (H ⋙ F) :=
((whiskering_right C D E).obj F).map_iso α
@[simp] lemma iso_whisker_right_hom {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(iso_whisker_right α F).hom = whisker_right α.hom F :=
rfl
@[simp] lemma iso_whisker_right_inv {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(iso_whisker_right α F).inv = whisker_right α.inv F :=
rfl
instance is_iso_whisker_left (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) [is_iso α] :
is_iso (whisker_left F α) :=
is_iso.of_iso (iso_whisker_left F (as_iso α))
instance is_iso_whisker_right {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) [is_iso α] :
is_iso (whisker_right α F) :=
is_iso.of_iso (iso_whisker_right (as_iso α) F)
variables {B : Type u₄} [category.{v₄} B]
local attribute [elab_simple] whisker_left whisker_right
@[simp] lemma whisker_left_twice (F : B ⥤ C) (G : C ⥤ D) {H K : D ⥤ E} (α : H ⟶ K) :
whisker_left F (whisker_left G α) = whisker_left (F ⋙ G) α :=
rfl
@[simp] lemma whisker_right_twice {H K : B ⥤ C} (F : C ⥤ D) (G : D ⥤ E) (α : H ⟶ K) :
whisker_right (whisker_right α F) G = whisker_right α (F ⋙ G) :=
rfl
lemma whisker_right_left (F : B ⥤ C) {G H : C ⥤ D} (α : G ⟶ H) (K : D ⥤ E) :
whisker_right (whisker_left F α) K = whisker_left F (whisker_right α K) :=
rfl
end
namespace functor
universes u₅ v₅
variables {A : Type u₁} [category.{v₁} A]
variables {B : Type u₂} [category.{v₂} B]
/--
The left unitor, a natural isomorphism `((𝟭 _) ⋙ F) ≅ F`.
-/
@[simps] def left_unitor (F : A ⥤ B) : ((𝟭 A) ⋙ F) ≅ F :=
{ hom := { app := λ X, 𝟙 (F.obj X) },
inv := { app := λ X, 𝟙 (F.obj X) } }
/--
The right unitor, a natural isomorphism `(F ⋙ (𝟭 B)) ≅ F`.
-/
@[simps] def right_unitor (F : A ⥤ B) : (F ⋙ (𝟭 B)) ≅ F :=
{ hom := { app := λ X, 𝟙 (F.obj X) },
inv := { app := λ X, 𝟙 (F.obj X) } }
variables {C : Type u₃} [category.{v₃} C]
variables {D : Type u₄} [category.{v₄} D]
/--
The associator for functors, a natural isomorphism `((F ⋙ G) ⋙ H) ≅ (F ⋙ (G ⋙ H))`.
(In fact, `iso.refl _` will work here, but it tends to make Lean slow later,
and it's usually best to insert explicit associators.)
-/
@[simps] def associator (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) : ((F ⋙ G) ⋙ H) ≅ (F ⋙ (G ⋙ H)) :=
{ hom := { app := λ _, 𝟙 _ },
inv := { app := λ _, 𝟙 _ } }
@[protected]
lemma assoc (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) : ((F ⋙ G) ⋙ H) = (F ⋙ (G ⋙ H)) := rfl
lemma triangle (F : A ⥤ B) (G : B ⥤ C) :
(associator F (𝟭 B) G).hom ≫ (whisker_left F (left_unitor G).hom) =
(whisker_right (right_unitor F).hom G) :=
by { ext, dsimp, simp } -- See note [dsimp, simp].
variables {E : Type u₅} [category.{v₅} E]
variables (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) (K : D ⥤ E)
lemma pentagon :
(whisker_right (associator F G H).hom K) ≫
(associator F (G ⋙ H) K).hom ≫
(whisker_left F (associator G H K).hom) =
((associator (F ⋙ G) H K).hom ≫ (associator F G (H ⋙ K)).hom) :=
by { ext, dsimp, simp }
end functor
end category_theory
|
55fd8d1f3dccd1c7dec271039ba196f42d36d39f | dce2ec26258c35f21c8a5318a7a2ed297ddba7c6 | /src/Problems/1_2.lean | 7022d8a6b6120a1934ac4fe005bd80438b358c1d | [] | no_license | nedsu/lean-category-theory-pr | c151c4f95d58a2d3b33e8f38ff7734d85d82e5ee | 8d72f4645d83c72d15afaee7a2df781b952417e9 | refs/heads/master | 1,625,444,569,743 | 1,597,056,476,000 | 1,597,056,476,000 | 145,738,350 | 0 | 0 | null | 1,534,957,201,000 | 1,534,957,201,000 | null | UTF-8 | Lean | false | false | 3,942 | lean | import ncategory_theory.CatGroups
import category_theory.natural_transformation
import data.equiv.basic
open category_theory category_theory.isomorphism category_theory.functor category_theory.CatGroup category_theory.nat_trans
--delaration of universes and variables
universes u v u₀ v₀ u₁ v₁ u₂ v₂
lemma t {C : Type u} [𝒞 : CatGroup C] : ∀ X Y : C,((𝒞.obj ⟶ 𝒞.obj) = ((functor.id C).obj X ⟶ (functor.id C).obj Y)) :=
begin
intros,
exact calc
(𝒞.obj ⟶ 𝒞.obj) = (((functor.id C).obj (𝒞.obj)) ⟶ 𝒞.obj) : by simp
... = ((functor.id C).obj 𝒞.obj ⟶ (functor.id C).obj 𝒞.obj) : by simp
... = ((functor.id C).obj X ⟶ (functor.id C).obj 𝒞.obj) : by rw CatGroup.uniqueobj X
... = ((functor.id C).obj X ⟶ (functor.id C).obj Y) : by rw CatGroup.uniqueobj Y
end
section
--#print eq.rec
variables (C : Type u) [𝒞 : CatGroup C] (a : 𝒞.obj ⟶ 𝒞.obj) (X : C)
--#check (eq.rec a (eq.symm(CatGroup.uniqueobj X)) : 𝒞.obj ⟶ X)
--#check @congr_arg
--#print eq.rec.congr_arg
--#print prefix eq.rec
end
--2 Let G be a group viewed as a one-object category.
--Show that the natural transformations α : functor.id G ⟹ Identity Functor G
-- correspond to elements in the centre of the group.
definition Grp_id_nat_trans_center (C : Type u) [𝒞 : CatGroup C] :
{ a : 𝒞.obj ⟶ 𝒞.obj // ∀ x : 𝒞.obj ⟶ 𝒞.obj, a ≫ x = x ≫ a} ≃ (functor.id C ⟹ functor.id C) :=
{ to_fun := λ ⟨a , ha⟩,
⟨ (λ X, (𝟙X : (functor.id C).obj X ⟶ X) ≫ (𝟙 𝒞.obj : X ⟶ 𝒞.obj) ≫ a ≫ (𝟙 𝒞.obj : 𝒞.obj ⟶ X) ≫ (𝟙X : X ⟶ (functor.id C).obj X) ) , _ ⟩,
inv_fun := λ α, ⟨(𝟙 𝒞.obj : 𝒞.obj ⟶ ((functor.id C).obj 𝒞.obj)) ≫ α 𝒞.obj ≫
(𝟙 (𝒞.obj) : ((functor.id C).obj 𝒞.obj) ⟶ 𝒞.obj),λ x,
begin
rw [category.id_comp,←category.assoc],
rw @category.comp_id _ _ _ 𝒞.obj _,
-- it's such a struggle to rewrite!
rw @category.comp_id _ _ _ 𝒞.obj _,
have H : α 𝒞.obj ≫ ((functor.id C).map x) = ((functor.id C).map x) ≫ α 𝒞.obj, from by rw nat_trans.naturality,
rw functor.id_map x at H,
assumption
end⟩,
left_inv := sorry,
right_inv := sorry
}
theorem Grp_id_nat_trans_center' (C : Type u) [𝒞 : CatGroup C] (a : 𝒞.obj ⟶ 𝒞.obj) :
(∀ x : 𝒞.obj ⟶ 𝒞.obj, a ≫ x = x ≫ a) ↔ (∃ α : functor.id C ⟹ functor.id C, α 𝒞.obj = a) :=
begin
apply iff.intro,
intro hc,
exact exists.intro
(
⟨
(λ X , cast (t X X) a),
begin
apply_auto_param,
have Hy : Y = 𝒞.obj, from CatGroup.uniqueobj Y,
have Hx : X = 𝒞.obj, from CatGroup.uniqueobj X,
rw Hx at f,
rw Hy at f,
convert (hc f).symm,
repeat {sorry},
end
⟩ : functor.id C ⟹ functor.id C)
(
begin
simp,
exact cast_eq _ a
end
),
intro hn,
cases (classical.indefinite_description _ hn) with α ha,
intro,
exact calc
a ≫ x = (α 𝒞.obj) ≫ x : by rw ha
... = (α 𝒞.obj) ≫ ((functor.id C).map x) : by simp
... = ((functor.id C).map x) ≫ (α 𝒞.obj) : by rw nat_trans.naturality
... = x ≫ (α 𝒞.obj) : by simp
... = x ≫ a : by rw ha
end |
91d04449a6d4e22a4ed608dbfb9216e334128170 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/algebra/archimedean.lean | 00f518fe2d943a1cc910a3484cdbdead896e8282 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 10,315 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Archimedean groups and fields.
-/
import algebra.field_power
import data.rat
variables {α : Type*}
/-- An ordered additive commutative monoid is called `archimedean` if for any two elements `x`, `y`
such that `0 < y` there exists a natural number `n` such that `x ≤ n •ℕ y`. -/
class archimedean (α) [ordered_add_comm_monoid α] : Prop :=
(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n •ℕ y)
theorem exists_nat_gt [linear_ordered_semiring α] [archimedean α]
(x : α) : ∃ n : ℕ, x < n :=
let ⟨n, h⟩ := archimedean.arch x zero_lt_one in
⟨n+1, lt_of_le_of_lt (by rwa ← nsmul_one)
(nat.cast_lt.2 (nat.lt_succ_self _))⟩
lemma add_one_pow_unbounded_of_pos [linear_ordered_semiring α] [archimedean α] (x : α) {y : α}
(hy : 0 < y) :
∃ n : ℕ, x < (y + 1) ^ n :=
let ⟨n, h⟩ := archimedean.arch x hy in
⟨n, calc x ≤ n •ℕ y : h
... < 1 + n •ℕ y : lt_one_add _
... ≤ (1 + y) ^ n : one_add_mul_le_pow' (mul_nonneg (le_of_lt hy) (le_of_lt hy))
(le_of_lt $ lt_trans hy (lt_one_add y)) _
... = (y + 1) ^ n : by rw [add_comm]⟩
section linear_ordered_ring
variables [linear_ordered_ring α] [archimedean α]
lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) :
∃ n : ℕ, x < y ^ n :=
sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1)
/-- Every x greater than or equal to 1 is between two successive
natural-number powers of every y greater than one. -/
lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) :
∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) :=
have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy,
by classical; exact let n := nat.find h in
have hn : x < y ^ n, from nat.find_spec h,
have hnp : 0 < n, from nat.pos_iff_ne_zero.2 (λ hn0,
by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)),
have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp,
have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp),
⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩
theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa ← coe_coe⟩
theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x :=
let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by rw int.cast_neg; exact neg_lt.1 h⟩
theorem exists_floor (x : α) :
∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x :=
begin
haveI := classical.prop_decidable,
have : ∃ (ub : ℤ), (ub:α) ≤ x ∧ ∀ (z : ℤ), (z:α) ≤ x → z ≤ ub :=
int.exists_greatest_of_bdd
(let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h',
int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩)
(let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩),
refine this.imp (λ fl h z, _),
cases h with h₁ h₂,
exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩,
end
end linear_ordered_ring
section linear_ordered_field
/-- Every positive x is between two successive integer powers of
another y greater than one. This is the same as `exists_int_pow_near'`,
but with ≤ and < the other way around. -/
lemma exists_int_pow_near [discrete_linear_ordered_field α] [archimedean α]
{x : α} {y : α} (hx : 0 < x) (hy : 1 < y) :
∃ n : ℤ, y ^ n ≤ x ∧ x < y ^ (n + 1) :=
by classical; exact
let ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy in
have he: ∃ m : ℤ, y ^ m ≤ x, from
⟨-N, le_of_lt (by rw [(fpow_neg y (↑N))];
exact (inv_lt hx (lt_trans (inv_pos.2 hx) hN)).1 hN)⟩,
let ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy in
have hb: ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b, from
⟨M, λ m hm, le_of_not_lt (λ hlt, not_lt_of_ge
(fpow_le_of_le (le_of_lt hy) (le_of_lt hlt)) (lt_of_le_of_lt hm hM))⟩,
let ⟨n, hn₁, hn₂⟩ := int.exists_greatest_of_bdd hb he in
⟨n, hn₁, lt_of_not_ge (λ hge, not_le_of_gt (int.lt_succ _) (hn₂ _ hge))⟩
/-- Every positive x is between two successive integer powers of
another y greater than one. This is the same as `exists_int_pow_near`,
but with ≤ and < the other way around. -/
lemma exists_int_pow_near' [discrete_linear_ordered_field α] [archimedean α]
{x : α} {y : α} (hx : 0 < x) (hy : 1 < y) :
∃ n : ℤ, y ^ n < x ∧ x ≤ y ^ (n + 1) :=
let ⟨m, hle, hlt⟩ := exists_int_pow_near (inv_pos.2 hx) hy in
have hyp : 0 < y, from lt_trans zero_lt_one hy,
⟨-(m+1),
by rwa [fpow_neg, inv_lt (fpow_pos_of_pos hyp _) hx],
by rwa [neg_add, neg_add_cancel_right, fpow_neg,
le_inv hx (fpow_pos_of_pos hyp _)]⟩
variables [linear_ordered_field α] [floor_ring α]
lemma sub_floor_div_mul_nonneg (x : α) {y : α} (hy : 0 < y) :
0 ≤ x - ⌊x / y⌋ * y :=
begin
conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm},
rw ← sub_mul,
exact mul_nonneg (sub_nonneg.2 (floor_le _)) (le_of_lt hy)
end
lemma sub_floor_div_mul_lt (x : α) {y : α} (hy : 0 < y) :
x - ⌊x / y⌋ * y < y :=
sub_lt_iff_lt_add.2 begin
conv in y {rw ← one_mul y},
conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm},
rw ← add_mul,
exact (mul_lt_mul_right hy).2 (by rw add_comm; exact lt_floor_add_one _),
end
end linear_ordered_field
instance : archimedean ℕ :=
⟨λ n m m0, ⟨n, by simpa only [mul_one, nat.nsmul_eq_mul] using nat.mul_le_mul_left n m0⟩⟩
instance : archimedean ℤ :=
⟨λ n m m0, ⟨n.to_nat, le_trans (int.le_to_nat _) $
by simpa only [nsmul_eq_mul, int.nat_cast_eq_coe_nat, zero_add, mul_one] using mul_le_mul_of_nonneg_left
(int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat)⟩⟩
/-- A linear ordered archimedean ring is a floor ring. This is not an `instance` because in some
cases we have a computable `floor` function. -/
noncomputable def archimedean.floor_ring (α)
[linear_ordered_ring α] [archimedean α] : floor_ring α :=
{ floor := λ x, classical.some (exists_floor x),
le_floor := λ z x, classical.some_spec (exists_floor x) z }
section linear_ordered_field
variables [linear_ordered_field α]
theorem archimedean_iff_nat_lt :
archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n :=
⟨@exists_nat_gt α _, λ H, ⟨λ x y y0,
(H (x / y)).imp $ λ n h, le_of_lt $
by rwa [div_lt_iff y0, ← nsmul_eq_mul] at h⟩⟩
theorem archimedean_iff_nat_le :
archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n :=
archimedean_iff_nat_lt.trans
⟨λ H x, (H x).imp $ λ _, le_of_lt,
λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩
theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q :=
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa rat.cast_coe_nat⟩
theorem archimedean_iff_rat_lt :
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q :=
⟨@exists_rat_gt α _,
λ H, archimedean_iff_nat_lt.2 $ λ x,
let ⟨q, h⟩ := H x in
⟨nat_ceil q, lt_of_lt_of_le h $
by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (le_nat_ceil _)⟩⟩
theorem archimedean_iff_rat_le :
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q :=
archimedean_iff_rat_lt.trans
⟨λ H x, (H x).imp $ λ _, le_of_lt,
λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
lt_of_le_of_lt h (rat.cast_lt.2 (lt_add_one _))⟩⟩
variable [archimedean α]
theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x :=
let ⟨n, h⟩ := exists_int_lt x in ⟨n, by rwa rat.cast_coe_int⟩
theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y :=
begin
cases exists_nat_gt (y - x)⁻¹ with n nh,
cases exists_floor (x * n) with z zh,
refine ⟨(z + 1 : ℤ) / n, _⟩,
have n0 := nat.cast_pos.1 (lt_trans (inv_pos.2 (sub_pos.2 h)) nh),
have n0' := (@nat.cast_pos α _ _).2 n0,
rw [rat.cast_div_of_ne_zero, rat.cast_coe_nat, rat.cast_coe_int, div_lt_iff n0'],
refine ⟨(lt_div_iff n0').2 $
(lt_iff_lt_of_le_iff_le (zh _)).1 (lt_add_one _), _⟩,
rw [int.cast_add, int.cast_one],
refine lt_of_le_of_lt (add_le_add_right ((zh _).1 (le_refl _)) _) _,
rwa [← lt_sub_iff_add_lt', ← sub_mul,
← div_lt_iff' (sub_pos.2 h), one_div],
{ rw [rat.coe_int_denom, nat.cast_one], exact one_ne_zero },
{ intro H, rw [rat.coe_nat_num, ← coe_coe, nat.cast_eq_zero] at H, subst H, cases n0 },
{ rw [rat.coe_nat_denom, nat.cast_one], exact one_ne_zero }
end
theorem exists_nat_one_div_lt {ε : α} (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1: α) < ε :=
begin
cases exists_nat_gt (1/ε) with n hn,
use n,
rw [div_lt_iff, ← div_lt_iff' hε],
{ apply hn.trans,
simp [zero_lt_one] },
{ exact n.cast_add_one_pos }
end
theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x :=
by simpa only [rat.cast_pos] using exists_rat_btwn x0
include α
@[simp] theorem rat.cast_floor (x : ℚ) :
by haveI := archimedean.floor_ring α; exact ⌊(x:α)⌋ = ⌊x⌋ :=
begin
haveI := archimedean.floor_ring α,
apply le_antisymm,
{ rw [le_floor, ← @rat.cast_le α, rat.cast_coe_int],
apply floor_le },
{ rw [le_floor, ← rat.cast_coe_int, rat.cast_le],
apply floor_le }
end
end linear_ordered_field
section
variables [discrete_linear_ordered_field α]
/-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/
def round [floor_ring α] (x : α) : ℤ := ⌊x + 1 / 2⌋
lemma abs_sub_round [floor_ring α] (x : α) : abs (x - round x) ≤ 1 / 2 :=
begin
rw [round, abs_sub_le_iff],
have := floor_le (x + 1 / 2),
have := lt_floor_add_one (x + 1 / 2),
split; linarith
end
variable [archimedean α]
theorem exists_rat_near (x : α) {ε : α} (ε0 : 0 < ε) :
∃ q : ℚ, abs (x - q) < ε :=
let ⟨q, h₁, h₂⟩ := exists_rat_btwn $
lt_trans ((sub_lt_self_iff x).2 ε0) ((lt_add_iff_pos_left x).2 ε0) in
⟨q, abs_sub_lt_iff.2 ⟨sub_lt.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩
instance : archimedean ℚ :=
archimedean_iff_rat_le.2 $ λ q, ⟨q, by rw rat.cast_id⟩
@[simp] theorem rat.cast_round (x : ℚ) : by haveI := archimedean.floor_ring α;
exact round (x:α) = round x :=
have ((x + (1 : ℚ) / (2 : ℚ) : ℚ) : α) = x + 1 / 2, by simp,
by rw [round, round, ← this, rat.cast_floor]
end
|
6a7571f7501d91e9eb3c6e46bff9f4cb8b89842e | f0f12a5b81106a798deda31dca238c11997a605e | /Playlean4/Order.lean | 45aa4689899f2f3509579b0131795db4f9104a91 | [
"MIT"
] | permissive | thejohncrafter/playlean4 | fe7119d492aab07048f78333eeda9862f6471740 | 81df180a71b8d84d0f45bc98db367aad203cf5df | refs/heads/master | 1,683,152,783,765 | 1,621,879,382,000 | 1,621,879,382,000 | 366,563,501 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 216 | lean |
class Order {α : Type} where
rel : α → α → Prop
reflexivity : ∀ x : α, rel x x
transitivity : ∀ x y z : α, rel x y → rel y z → rel x z
antisymettricity : ∀ x y : α, rel x y → ¬rel y x
|
71a932024eeae2eb8a8e38ed12cc3d605602bd0f | aa101d73b1a3173c7ec56de02b96baa8ca64c42e | /src/my_exercises/02_iff_if_and.lean | 8e21ace515eaaa538e4b2897284c1a5e6ab3332f | [
"Apache-2.0"
] | permissive | gihanmarasingha/tutorials | b554d4d53866c493c4341dc13e914b01444e95a6 | 56617114ef0f9f7b808476faffd11e22e4380918 | refs/heads/master | 1,671,141,758,153 | 1,599,173,318,000 | 1,599,173,318,000 | 282,405,870 | 0 | 0 | Apache-2.0 | 1,595,666,751,000 | 1,595,666,750,000 | null | UTF-8 | Lean | false | false | 15,473 | lean | import data.real.basic
/-
In the previous file, we saw how to rewrite using equalities.
The analogue operation with mathematical statements is rewriting using
equivalences. This is also done using the `rw` tactic.
Lean uses ↔ to denote equivalence instead of ⇔.
In the following exercises we will use the lemma:
sub_nonneg {x y : ℝ} : 0 ≤ y - x ↔ x ≤ y
The curly braces around x and y instead of parentheses mean Lean will always try to figure out what
x and y are from context, unless we really insist on telling it (we'll see how to insist much later).
Let's not worry about that for now.
In order to announce an intermediate statement we use:
have my_name : my statement,
This triggers the apparition of a new goal: proving the statement. After this is done,
the statement becomes available under the name `my_name`.
We can focus on the current goal by typing tactics between curly braces.
-/
example {a b c : ℝ} (hab : a ≤ b) : c + a ≤ c + b :=
begin
rw ← sub_nonneg,
have key : (c + b) - (c + a) = b - a, -- Here we introduce an intermediate statement named key
{ ring, }, -- and prove it between curly braces
rw key, -- we can now use the key statement
rw sub_nonneg,
exact hab,
end
/-
Of course the previous lemma is already in the core library, named `add_le_add_left`, so we can use it below.
Let's prove a variation (without invoking commutativity of addition since this would spoil our fun).
-/
-- 0009
example {a b : ℝ} (hab : a ≤ b) (c : ℝ) : a + c ≤ b + c :=
begin
rw ← sub_nonneg,
ring,
rw sub_nonneg,
exact hab,
end
/-
Let's see how we could use this lemma. It is already in the core library, under the name `add_le_add_right`:
add_le_add_right {a b : ℝ} (hab : a ≤ b) (c : ℝ) : a + c ≤ b + c
This can be read as: "add_le_add_right is a function that will take as input real numbers a and b, an
assumption `hab` claiming a ≤ b and a real number c, and will output a proof of a + c ≤ b + c".
In addition, recall that curly braces around a b mean Lean will figure out those arguments unless we
insist to help. This is because they can be deduced from the next argument `hab`.
So it will be sufficient to feed `hab` and c to this function.
-/
example {a b : ℝ} (ha : 0 ≤ a) : b ≤ a + b :=
begin
calc b = 0 + b : by ring
... ≤ a + b : by exact add_le_add_right ha b,
end
/-
In the second line of the above proof, we need to prove 0 + b ≤ a + b.
The proof after the colon says: this is exactly lemma `add_le_add_right` applied to ha and b.
Actually the `calc` block expects proof terms, and the `by` keyword is used to tell Lean we will use tactics
to build such a proof term. But since the only tactic used in this block is `exact`, we can skip
tactics entirely, and write:
-/
example (a b : ℝ) (ha : 0 ≤ a) : b ≤ a + b :=
begin
calc b = 0 + b : by ring
... ≤ a + b : add_le_add_right ha b,
end
/- Let's do a variant. -/
-- 0010
example (a b : ℝ) (hb : 0 ≤ b) : a ≤ a + b :=
begin
calc a = a + 0 : by ring
... ≤ a + b : add_le_add_left hb a
end
/-
The two preceding examples are in the core library :
le_add_of_nonneg_left {a b : ℝ} (ha : 0 ≤ a) : b ≤ a + b
le_add_of_nonneg_right {a b : ℝ} (hb : 0 ≤ b) : a ≤ a + b
Again, there won't be any need to memorize those names, we will
soon see how to get rid of such goals automatically.
But we can already try to understand how their names are built:
"le_add" describe the conclusion "less or equal than some addition"
It comes first because we are focussed on proving stuff, and
auto-completion works by looking at the beginning of words.
"of" introduces assumptions. "nonneg" is Lean's abbreviation for non-negative.
"left" or "right" disambiguates between the two variations.
Let's use those lemmas by hand for now.
-/
-- 0011
example (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
begin
calc 0 = 0 + 0 : by ring
... ≤ 0 + b : add_le_add_left hb 0
... ≤ a + b : add_le_add_right ha b
end
/- And let's combine with our earlier lemmas. -/
-- 0012
example (a b c d : ℝ) (hab : a ≤ b) (hcd : c ≤ d) : a + c ≤ b + d :=
begin
calc a + c ≤ a + d : add_le_add_left hcd a
... ≤ b + d : add_le_add_right hab d
end
/-
In the above examples, we prepared proofs of assumptions of our lemmas beforehand, so
that we could feed them to the lemmas. This is called forward reasonning.
The `calc` proofs also belong to this category.
We can also announce the use of a lemma, and provide proofs after the fact, using
the `apply` tactic. This is called backward reasonning because we get the conclusion
first, and provide proofs later. Using `rw` on the goal (rather than on an assumption
from the local context) is also backward reasonning.
Let's do that using the lemma
mul_nonneg {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : 0 ≤ x*y
-/
example (a b c : ℝ) (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=
begin
rw ← sub_nonneg,
have key : b*c - a*c = (b - a)*c,
{ ring },
rw key,
apply mul_nonneg, -- Here we don't provide proofs for the lemma's assumptions
-- Now we need to provide the proofs.
{ rw sub_nonneg,
exact hab },
{ exact hc },
end
/-
Let's prove the same statement using only forward reasonning: announcing stuff,
proving it by working with known facts, moving forward.
-/
example (a b c : ℝ) (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=
begin
have hab' : 0 ≤ b - a,
{ rw ← sub_nonneg at hab,
exact hab, },
have h₁ : 0 ≤ (b - a)*c,
{ exact mul_nonneg hab' hc },
have h₂ : (b - a)*c = b*c - a*c,
{ ring, },
have h₃ : 0 ≤ b*c - a*c,
{ rw h₂ at h₁,
exact h₁, },
rw sub_nonneg at h₃,
exact h₃,
end
/-
One reason why the backward reasoning proof is shorter is because Lean can
infer of lot of things by comparing the goal and the lemma statement. Indeed
in the `apply mul_nonneg` line, we didn't need to tell Lean that x = b - a
and y = c in the lemma. It was infered by "unification" between the lemma
statement and the goal.
To be fair to the forward reasoning version, we should introduce a convenient
variation on `rw`. The `rwa` tactic performs rewrite and then looks for an
assumption matching the goal. We can use it to rewrite our latest proof as:
-/
example (a b c : ℝ) (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=
begin
have hab' : 0 ≤ b - a,
{ rwa ← sub_nonneg at hab, },
have h₁ : 0 ≤ (b - a)*c,
{ exact mul_nonneg hab' hc },
have h₂ : (b - a)*c = b*c - a*c,
{ ring, },
have h₃ : 0 ≤ b*c - a*c,
{ rwa h₂ at h₁, },
rwa sub_nonneg at h₃,
end
/-
Let's now combine forward and backward reasonning, to get our most
efficient proof of this statement. Note in particular how unification is used
to know what to prove inside the parentheses in the `mul_nonneg` arguments.
-/
example (a b c : ℝ) (hc : 0 ≤ c) (hab : a ≤ b) : a*c ≤ b*c :=
begin
rw ← sub_nonneg,
calc 0 ≤ (b - a)*c : mul_nonneg (by rwa sub_nonneg) hc
... = b*c - a*c : by ring,
end
/-
Let's now practice all three styles using:
mul_nonneg_of_nonpos_of_nonpos {a b : α} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b
sub_nonpos {a b : α} : a - b ≤ 0 ↔ a ≤ b
-/
/- First using mostly backward reasonning -/
-- 0013
example (a b c : ℝ) (hc : c ≤ 0) (hab : a ≤ b) : b*c ≤ a*c :=
begin
rw ← sub_nonneg,
have key : a*c - b*c = (a-b)*c,
{ring},
rw key,
apply mul_nonneg_of_nonpos_of_nonpos,
{ rwa sub_nonpos },
{ exact hc },
end
/- Using forward reasonning -/
-- 0014
example (a b c : ℝ) (hc : c ≤ 0) (hab : a ≤ b) : b*c ≤ a*c :=
begin
have hab' : a - b ≤ 0,
{rwa sub_nonpos},
have h₁ : 0 ≤ (a-b)*c,
{ exact mul_nonneg_of_nonpos_of_nonpos hab' hc },
have h₂ : (a-b)*c = a*c - b*c,
{ ring },
rw h₂ at h₁,
rwa ←sub_nonneg,
end
/-- Using a combination of both, with a `calc` block -/
-- 0015
example (a b c : ℝ) (hc : c ≤ 0) (hab : a ≤ b) : b*c ≤ a*c :=
begin
rw ← sub_nonneg,
calc 0 ≤ (a-b)*c : mul_nonneg_of_nonpos_of_nonpos (by rwa sub_nonpos) hc
... = a*c - b*c : by ring,
end
/-
Let's now move to proving implications. Lean denotes implications using
a simple arrow →, the same it uses for functions (say denoting the type of functions
from ℕ to ℕ by ℕ → ℕ). This is because it sees a proof of P ⇒ Q as a function turning
a proof of P into a proof Q.
Many of the examples that we already met are implications under the hood. For instance we proved
le_add_of_nonneg_left (a b : ℝ) (ha : 0 ≤ a) : b ≤ a + b
But this can be rephrased as
le_add_of_nonneg_left (a b : ℝ) : 0 ≤ a → b ≤ a + b
In order to prove P → Q, we use the tactic `intros`, followed by an assumption name.
This creates an assumption with that name asserting that P holds, and turns the goal into Q.
Let's check we can go from our old version of `le_add_of_nonneg_left` to the new one.
-/
example (a b : ℝ): 0 ≤ a → b ≤ a + b :=
begin
intros ha,
exact le_add_of_nonneg_left ha,
end
/-
Actually Lean doesn't make any difference between those two versions. It is also happy with
-/
example (a b : ℝ): 0 ≤ a → b ≤ a + b :=
le_add_of_nonneg_left
/- No tactic state is shown in the above line because we don't even need to enter
tactic mode using `begin` or `by`.
Let's practise using `intros`. -/
-- 0016
example (a b : ℝ): 0 ≤ b → a ≤ a + b :=
begin
intros hb,
exact le_add_of_nonneg_right hb
end
/-
What about lemmas having more than one assumption? For instance:
add_nonneg {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b
A natural idea is to use the conjunction operator (logical AND), which Lean denotes
by ∧. Assumptions built using this operator can be decomposed using the `cases` tactic,
which is a very general assumption-decomposing tactic.
-/
example {a b : ℝ} : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b :=
begin
intros hyp,
cases hyp with ha hb,
exact add_nonneg ha hb,
end
/-
Needing that intermediate line invoking `cases` shows this formulation is not what is used by
Lean. It rather sees `add_nonneg` as two nested implications:
if a is non-negative then if b is non-negative then a+b is non-negative.
It reads funny, but it is much more convenient to use in practice.
-/
example {a b : ℝ} : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=
add_nonneg
/-
The above pattern is so common that implications are defined as right-associative operators,
hence parentheses are not needed above.
Let's prove that the naive conjunction version implies the funny Lean version. For this we need
to know how to prove a conjunction. The `split` tactic creates two goals from a conjunction goal.
It can also be used to create two implication goals from an equivalence goal.
-/
example {a b : ℝ} (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=
begin
intros ha,
intros hb,
apply H,
split,
exact ha,
exact hb,
end
/-
Let's practice `cases` and `split`. In the next exercise, P, Q and R denote
unspecified mathematical statements.
-/
-- 0017
example (P Q R : Prop) : P ∧ Q → Q ∧ P :=
begin
intro hpq,
cases hpq with hp hq,
split,
exact hq,
exact hp,
end
/-
Of course using `split` only to be able to use `exact` twice in a row feels silly. One can
also use the anonymous constructor syntax: ⟨ ⟩
Beware those are not parentheses but angle brackets. This is a generic way of providing
compound objects to Lean when Lean already has a very clear idea of what it is waiting for.
So we could have replaced the last three lines by:
exact ⟨hQ, hP⟩
We can also combine the `intros` steps. We can now compress our earlier proof to:
-/
example {a b : ℝ} (H : (0 ≤ a ∧ 0 ≤ b) → 0 ≤ a + b) : 0 ≤ a → (0 ≤ b → 0 ≤ a + b) :=
begin
intros ha hb,
exact H ⟨ha, hb⟩,
end
/-
The anonymous contructor trick actually also works in `intros` provided we use
its recursive version `rintros`. So we can replace
intro h,
cases h with h₁ h₂
by
rintros ⟨h₁, h₂⟩,
Now redo the previous exercise using all those compressing techniques, in exactly two lines. -/
-- 0018
example (P Q R : Prop): P ∧ Q → Q ∧ P :=
begin
rintros ⟨hp,hq⟩,
exact ⟨hq, hp⟩,
end
/-
We are ready to come back to the equivalence between the different formulations of
lemmas having two assumptions. Remember the `split` tactic can be used to split
an equivalence into two implications.
-/
-- 0019
example (P Q R : Prop) : (P ∧ Q → R) ↔ (P → (Q → R)) :=
begin
split, {
intros hpqr hp hq,
exact hpqr ⟨hp,hq⟩
}, {
rintros hpqr ⟨hp, hq⟩,
exact hpqr hp hq
}
end
/-
If you used more than five lines in the above exercise then try to compress things
(without simply removing line ends).
One last compression technique: given a proof h of a conjunction P ∧ Q, one can get
a proof of P using h.left and a proof of Q using h.right, without using cases.
One can also use the more generic (but less legible) names h.1 and h.2.
Similarly, given a proof h of P ↔ Q, one can get a proof of P → Q using h.mp
and a proof of Q → P using h.mpr (or the generic h.1 and h.2 that are even less legible
in this case).
Before the final exercise in this file, let's make sure we'll be able to leave
without learning 10 lemma names. The `linarith` tactic will prove any equality or
inequality or contradiction that follows by linear combinations of assumptions from the
context (with constant coefficients).
-/
example (a b : ℝ) (hb : 0 ≤ b) : a ≤ a + b :=
begin
linarith,
end
/-
Now let's enjoy this for a while.
-/
-- 0020
example (a b : ℝ) (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
begin
linarith,
end
/- And let's combine with our earlier lemmas. -/
-- 0021
example (a b c d : ℝ) (hab : a ≤ b) (hcd : c ≤ d) : a + c ≤ b + d :=
begin
linarith,
end
/-
Final exercise
In the last exercise of this file, we will use the divisibility relation on ℕ,
denoted by ∣ (beware this is a unicode divisibility bar, not the ASCII pipe character),
and the gcd function.
The definitions are the usual ones, but our goal is to avoid using these definitions and
only use the following three lemmas:
dvd_refl (a : ℕ) : a ∣ a
dvd_antisymm {a b : ℕ} : a ∣ b → b ∣ a → a = b :=
dvd_gcd_iff {a b c : ℕ} : c ∣ gcd a b ↔ c ∣ a ∧ c ∣ b
-/
-- All functions and lemmas below are about natural numbers.
open nat
-- 0022
/- Here are two solutions. The first is based on Massot's.#check
The second is entirely mine, but less efficient!-/
example (a b : ℕ) : a ∣ b ↔ gcd a b = a :=
begin
-- sorry
have h : gcd a b ∣ a ∧ gcd a b ∣ b,
rw ←dvd_gcd_iff,
split, {
intro hab,
apply dvd_antisymm, {
exact h.1,
}, {
rw dvd_gcd_iff,
exact ⟨dvd_refl a, hab⟩
}
}, {
intro hab,
rw hab at h,
exact h.2,
}
end
example (a b : ℕ) : a ∣ b ↔ gcd a b = a :=
begin
have h : (gcd a b) ∣ a,
exact (dvd_gcd_iff.1 (dvd_refl (gcd a b))).1,
split, {
intro hab,
apply dvd_antisymm, {
exact h,
}, {
rw dvd_gcd_iff,
exact ⟨dvd_refl a, hab⟩,
}
}, {
intro hab,
suffices : a ∣ a ∧ a ∣ b, {
exact this.2,
}, {
apply dvd_gcd_iff.1,
rw hab,
}
}
end
|
974805070464d92d897dbc145fa2b3e2369e0915 | de4548698671d50981659ecc9f4910de15969d3d | /lakefile.lean | 7e027c93acb7f899011f4ae9c539854757eb9449 | [] | no_license | digama0/mm-lean4 | 7ad17c81853816c6cd4bb97b8abe4bea0fd35ff6 | 6a427edecb851cec04818848a755c0145a5f2e98 | refs/heads/master | 1,688,934,520,262 | 1,687,937,043,000 | 1,687,937,043,000 | 365,257,017 | 15 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 346 | lean | import Lake
open Lake DSL
package «mm-lean4»
require std from git "https://github.com/leanprover/std4" @ "main"
@[default_target]
lean_lib Metamath where
roots := #[`Metamath.Verify]
@[default_target]
lean_lib MetamathExperimental where
roots := #[`Metamath.Translate]
@[default_target]
lean_exe «mm-lean4» where
root := `Metamath
|
659267277fae9ba59669aa308503a53923d91cfd | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/measure_theory/constructions/pi.lean | fcd29e3840ae41c5358e7be6bb621597bcde32af | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 32,287 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.constructions.prod
/-!
# Product measures
In this file we define and prove properties about finite products of measures
(and at some point, countable products of measures).
## Main definition
* `measure_theory.measure.pi`: The product of finitely many σ-finite measures.
Given `μ : Π i : ι, measure (α i)` for `[fintype ι]` it has type `measure (Π i : ι, α i)`.
To apply Fubini along some subset of the variables, use
`measure_theory.measure.map_pi_equiv_pi_subtype_prod` to reduce to the situation of a product
of two measures: this lemma states that the bijection `equiv.pi_equiv_pi_subtype_prod p α`
between `(Π i : ι, α i)` and `(Π i : {i // p i}, α i) × (Π i : {i // ¬ p i}, α i)` maps a product
measure to a direct product of product measures, to which one can apply the usual Fubini for
direct product of measures.
## Implementation Notes
We define `measure_theory.outer_measure.pi`, the product of finitely many outer measures, as the
maximal outer measure `n` with the property that `n (pi univ s) ≤ ∏ i, m i (s i)`,
where `pi univ s` is the product of the sets `{s i | i : ι}`.
We then show that this induces a product of measures, called `measure_theory.measure.pi`.
For a collection of σ-finite measures `μ` and a collection of measurable sets `s` we show that
`measure.pi μ (pi univ s) = ∏ i, m i (s i)`. To do this, we follow the following steps:
* We know that there is some ordering on `ι`, given by an element of `[encodable ι]`.
* Using this, we have an equivalence `measurable_equiv.pi_measurable_equiv_tprod` between
`Π ι, α i` and an iterated product of `α i`, called `list.tprod α l` for some list `l`.
* On this iterated product we can easily define a product measure `measure_theory.measure.tprod`
by iterating `measure_theory.measure.prod`
* Using the previous two steps we construct `measure_theory.measure.pi'` on `Π ι, α i` for encodable
`ι`.
* We know that `measure_theory.measure.pi'` sends products of sets to products of measures, and
since `measure_theory.measure.pi` is the maximal such measure (or at least, it comes from an outer
measure which is the maximal such outer measure), we get the same rule for
`measure_theory.measure.pi`.
## Tags
finitary product measure
-/
noncomputable theory
open function set measure_theory.outer_measure filter measurable_space encodable
open_locale classical big_operators topological_space ennreal
variables {ι ι' : Type*} {α : ι → Type*}
/-! We start with some measurability properties -/
/-- Boxes formed by π-systems form a π-system. -/
lemma is_pi_system.pi {C : Π i, set (set (α i))} (hC : ∀ i, is_pi_system (C i)) :
is_pi_system (pi univ '' pi univ C) :=
begin
rintro _ _ ⟨s₁, hs₁, rfl⟩ ⟨s₂, hs₂, rfl⟩ hst,
rw [← pi_inter_distrib] at hst ⊢, rw [univ_pi_nonempty_iff] at hst,
exact mem_image_of_mem _ (λ i _, hC i _ _ (hs₁ i (mem_univ i)) (hs₂ i (mem_univ i)) (hst i))
end
/-- Boxes form a π-system. -/
lemma is_pi_system_pi [Π i, measurable_space (α i)] :
is_pi_system (pi univ '' pi univ (λ i, {s : set (α i) | measurable_set s})) :=
is_pi_system.pi (λ i, is_pi_system_measurable_set)
variables [fintype ι] [fintype ι']
/-- Boxes of countably spanning sets are countably spanning. -/
lemma is_countably_spanning.pi {C : Π i, set (set (α i))}
(hC : ∀ i, is_countably_spanning (C i)) :
is_countably_spanning (pi univ '' pi univ C) :=
begin
choose s h1s h2s using hC,
haveI := fintype.encodable ι,
let e : ℕ → (ι → ℕ) := λ n, (decode (ι → ℕ) n).iget,
refine ⟨λ n, pi univ (λ i, s i (e n i)), λ n, mem_image_of_mem _ (λ i _, h1s i _), _⟩,
simp_rw [(surjective_decode_iget (ι → ℕ)).Union_comp (λ x, pi univ (λ i, s i (x i))),
Union_univ_pi s, h2s, pi_univ]
end
/-- The product of generated σ-algebras is the one generated by boxes, if both generating sets
are countably spanning. -/
lemma generate_from_pi_eq {C : Π i, set (set (α i))}
(hC : ∀ i, is_countably_spanning (C i)) :
@measurable_space.pi _ _ (λ i, generate_from (C i)) = generate_from (pi univ '' pi univ C) :=
begin
haveI := fintype.encodable ι,
apply le_antisymm,
{ refine supr_le _, intro i, rw [comap_generate_from],
apply generate_from_le, rintro _ ⟨s, hs, rfl⟩, dsimp,
choose t h1t h2t using hC,
simp_rw [eval_preimage, ← h2t],
rw [← @Union_const _ ℕ _ s],
have : (pi univ (update (λ (i' : ι), Union (t i')) i (⋃ (i' : ℕ), s))) =
(pi univ (λ k, ⋃ j : ℕ, @update ι (λ i', set (α i')) _ (λ i', t i' j) i s k)),
{ ext, simp_rw [mem_univ_pi], apply forall_congr, intro i',
by_cases (i' = i), { subst h, simp }, { rw [← ne.def] at h, simp [h] }},
rw [this, ← Union_univ_pi],
apply measurable_set.Union,
intro n, apply measurable_set_generate_from,
apply mem_image_of_mem, intros j _, dsimp only,
by_cases h: j = i, subst h, rwa [update_same], rw [update_noteq h], apply h1t },
{ apply generate_from_le, rintro _ ⟨s, hs, rfl⟩,
rw [univ_pi_eq_Inter], apply measurable_set.Inter, intro i, apply measurable_pi_apply,
exact measurable_set_generate_from (hs i (mem_univ i)) }
end
/-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D`
generate the σ-algebra on `α × β`. -/
lemma generate_from_eq_pi [h : Π i, measurable_space (α i)]
{C : Π i, set (set (α i))} (hC : ∀ i, generate_from (C i) = h i)
(h2C : ∀ i, is_countably_spanning (C i)) :
generate_from (pi univ '' pi univ C) = measurable_space.pi :=
by rw [← funext hC, generate_from_pi_eq h2C]
/-- The product σ-algebra is generated from boxes, i.e. `s.prod t` for sets `s : set α` and
`t : set β`. -/
lemma generate_from_pi [Π i, measurable_space (α i)] :
generate_from (pi univ '' pi univ (λ i, { s : set (α i) | measurable_set s})) =
measurable_space.pi :=
generate_from_eq_pi (λ i, generate_from_measurable_set) (λ i, is_countably_spanning_measurable_set)
namespace measure_theory
variables {m : Π i, outer_measure (α i)}
/-- An upper bound for the measure in a finite product space.
It is defined to by taking the image of the set under all projections, and taking the product
of the measures of these images.
For measurable boxes it is equal to the correct measure. -/
@[simp] def pi_premeasure (m : Π i, outer_measure (α i)) (s : set (Π i, α i)) : ℝ≥0∞ :=
∏ i, m i (eval i '' s)
lemma pi_premeasure_pi {s : Π i, set (α i)} (hs : (pi univ s).nonempty) :
pi_premeasure m (pi univ s) = ∏ i, m i (s i) :=
by simp [hs]
lemma pi_premeasure_pi' [nonempty ι] {s : Π i, set (α i)} :
pi_premeasure m (pi univ s) = ∏ i, m i (s i) :=
begin
cases (pi univ s).eq_empty_or_nonempty with h h,
{ rcases univ_pi_eq_empty_iff.mp h with ⟨i, hi⟩,
have : ∃ i, m i (s i) = 0 := ⟨i, by simp [hi]⟩,
simpa [h, finset.card_univ, zero_pow (fintype.card_pos_iff.mpr ‹_›),
@eq_comm _ (0 : ℝ≥0∞), finset.prod_eq_zero_iff] },
{ simp [h] }
end
lemma pi_premeasure_pi_mono {s t : set (Π i, α i)} (h : s ⊆ t) :
pi_premeasure m s ≤ pi_premeasure m t :=
finset.prod_le_prod' (λ i _, (m i).mono' (image_subset _ h))
lemma pi_premeasure_pi_eval [nonempty ι] {s : set (Π i, α i)} :
pi_premeasure m (pi univ (λ i, eval i '' s)) = pi_premeasure m s :=
by simp [pi_premeasure_pi']
namespace outer_measure
/-- `outer_measure.pi m` is the finite product of the outer measures `{m i | i : ι}`.
It is defined to be the maximal outer measure `n` with the property that
`n (pi univ s) ≤ ∏ i, m i (s i)`, where `pi univ s` is the product of the sets
`{s i | i : ι}`. -/
protected def pi (m : Π i, outer_measure (α i)) : outer_measure (Π i, α i) :=
bounded_by (pi_premeasure m)
lemma pi_pi_le (m : Π i, outer_measure (α i)) (s : Π i, set (α i)) :
outer_measure.pi m (pi univ s) ≤ ∏ i, m i (s i) :=
by { cases (pi univ s).eq_empty_or_nonempty with h h, simp [h],
exact (bounded_by_le _).trans_eq (pi_premeasure_pi h) }
lemma le_pi {m : Π i, outer_measure (α i)} {n : outer_measure (Π i, α i)} :
n ≤ outer_measure.pi m ↔ ∀ (s : Π i, set (α i)), (pi univ s).nonempty →
n (pi univ s) ≤ ∏ i, m i (s i) :=
begin
rw [outer_measure.pi, le_bounded_by'], split,
{ intros h s hs, refine (h _ hs).trans_eq (pi_premeasure_pi hs) },
{ intros h s hs, refine le_trans (n.mono $ subset_pi_eval_image univ s) (h _ _),
simp [univ_pi_nonempty_iff, hs] }
end
end outer_measure
namespace measure
variables [Π i, measurable_space (α i)] (μ : Π i, measure (α i))
section tprod
open list
variables {δ : Type*} {π : δ → Type*} [∀ x, measurable_space (π x)]
/-- A product of measures in `tprod α l`. -/
-- for some reason the equation compiler doesn't like this definition
protected def tprod (l : list δ) (μ : Π i, measure (π i)) : measure (tprod π l) :=
by { induction l with i l ih, exact dirac punit.star, exact (μ i).prod ih }
@[simp] lemma tprod_nil (μ : Π i, measure (π i)) : measure.tprod [] μ = dirac punit.star := rfl
@[simp] lemma tprod_cons (i : δ) (l : list δ) (μ : Π i, measure (π i)) :
measure.tprod (i :: l) μ = (μ i).prod (measure.tprod l μ) := rfl
instance sigma_finite_tprod (l : list δ) (μ : Π i, measure (π i)) [∀ i, sigma_finite (μ i)] :
sigma_finite (measure.tprod l μ) :=
begin
induction l with i l ih,
{ rw [tprod_nil], apply_instance },
{ rw [tprod_cons], resetI, apply_instance }
end
lemma tprod_tprod (l : list δ) (μ : Π i, measure (π i)) [∀ i, sigma_finite (μ i)]
(s : Π i, set (π i)) :
measure.tprod l μ (set.tprod l s) = (l.map (λ i, (μ i) (s i))).prod :=
begin
induction l with i l ih, { simp },
rw [tprod_cons, set.tprod, prod_prod, map_cons, prod_cons, ih]
end
end tprod
section encodable
open list measurable_equiv
variables [encodable ι]
/-- The product measure on an encodable finite type, defined by mapping `measure.tprod` along the
equivalence `measurable_equiv.pi_measurable_equiv_tprod`.
The definition `measure_theory.measure.pi` should be used instead of this one. -/
def pi' : measure (Π i, α i) :=
measure.map (tprod.elim' mem_sorted_univ) (measure.tprod (sorted_univ ι) μ)
lemma pi'_pi [∀ i, sigma_finite (μ i)] (s : Π i, set (α i)) : pi' μ (pi univ s) = ∏ i, μ i (s i) :=
by rw [pi', ← measurable_equiv.pi_measurable_equiv_tprod_symm_apply, measurable_equiv.map_apply,
measurable_equiv.pi_measurable_equiv_tprod_symm_apply, elim_preimage_pi, tprod_tprod _ μ,
← list.prod_to_finset, sorted_univ_to_finset]; exact sorted_univ_nodup ι
end encodable
lemma pi_caratheodory :
measurable_space.pi ≤ (outer_measure.pi (λ i, (μ i).to_outer_measure)).caratheodory :=
begin
refine supr_le _,
intros i s hs,
rw [measurable_space.comap] at hs,
rcases hs with ⟨s, hs, rfl⟩,
apply bounded_by_caratheodory,
intro t,
simp_rw [pi_premeasure],
refine finset.prod_add_prod_le' (finset.mem_univ i) _ _ _,
{ simp [image_inter_preimage, image_diff_preimage, measure_inter_add_diff _ hs, le_refl] },
{ rintro j - hj, apply mono', apply image_subset, apply inter_subset_left },
{ rintro j - hj, apply mono', apply image_subset, apply diff_subset }
end
/-- `measure.pi μ` is the finite product of the measures `{μ i | i : ι}`.
It is defined to be measure corresponding to `measure_theory.outer_measure.pi`. -/
@[irreducible] protected def pi : measure (Π i, α i) :=
to_measure (outer_measure.pi (λ i, (μ i).to_outer_measure)) (pi_caratheodory μ)
lemma pi_pi_aux [∀ i, sigma_finite (μ i)] (s : Π i, set (α i)) (hs : ∀ i, measurable_set (s i)) :
measure.pi μ (pi univ s) = ∏ i, μ i (s i) :=
begin
refine le_antisymm _ _,
{ rw [measure.pi, to_measure_apply _ _ (measurable_set.pi_fintype (λ i _, hs i))],
apply outer_measure.pi_pi_le },
{ haveI : encodable ι := fintype.encodable ι,
rw [← pi'_pi μ s],
simp_rw [← pi'_pi μ s, measure.pi,
to_measure_apply _ _ (measurable_set.pi_fintype (λ i _, hs i)), ← to_outer_measure_apply],
suffices : (pi' μ).to_outer_measure ≤ outer_measure.pi (λ i, (μ i).to_outer_measure),
{ exact this _ },
clear hs s,
rw [outer_measure.le_pi],
intros s hs,
simp_rw [to_outer_measure_apply],
exact (pi'_pi μ s).le }
end
variable {μ}
/-- `measure.pi μ` has finite spanning sets in rectangles of finite spanning sets. -/
def finite_spanning_sets_in.pi {C : Π i, set (set (α i))}
(hμ : ∀ i, (μ i).finite_spanning_sets_in (C i)) :
(measure.pi μ).finite_spanning_sets_in (pi univ '' pi univ C) :=
begin
haveI := λ i, (hμ i).sigma_finite,
haveI := fintype.encodable ι,
let e : ℕ → (ι → ℕ) := λ n, (decode (ι → ℕ) n).iget,
refine ⟨λ n, pi univ (λ i, (hμ i).set (e n i)), λ n, _, λ n, _, _⟩,
{ refine mem_image_of_mem _ (λ i _, (hμ i).set_mem _) },
{ calc measure.pi μ (pi univ (λ i, (hμ i).set (e n i)))
≤ measure.pi μ (pi univ (λ i, to_measurable (μ i) ((hμ i).set (e n i)))) :
measure_mono (pi_mono $ λ i hi, subset_to_measurable _ _)
... = ∏ i, μ i (to_measurable (μ i) ((hμ i).set (e n i))) :
pi_pi_aux μ _ (λ i, measurable_set_to_measurable _ _)
... = ∏ i, μ i ((hμ i).set (e n i)) :
by simp only [measure_to_measurable]
... < ∞ : ennreal.prod_lt_top (λ i hi, ((hμ i).finite _).ne) },
{ simp_rw [(surjective_decode_iget (ι → ℕ)).Union_comp (λ x, pi univ (λ i, (hμ i).set (x i))),
Union_univ_pi (λ i, (hμ i).set), (hμ _).spanning, set.pi_univ] }
end
/-- A measure on a finite product space equals the product measure if they are equal on rectangles
with as sides sets that generate the corresponding σ-algebras. -/
lemma pi_eq_generate_from {C : Π i, set (set (α i))}
(hC : ∀ i, generate_from (C i) = _inst_3 i)
(h2C : ∀ i, is_pi_system (C i))
(h3C : ∀ i, (μ i).finite_spanning_sets_in (C i))
{μν : measure (Π i, α i)}
(h₁ : ∀ s : Π i, set (α i), (∀ i, s i ∈ C i) → μν (pi univ s) = ∏ i, μ i (s i)) :
measure.pi μ = μν :=
begin
have h4C : ∀ i (s : set (α i)), s ∈ C i → measurable_set s,
{ intros i s hs, rw [← hC], exact measurable_set_generate_from hs },
refine (finite_spanning_sets_in.pi h3C).ext
(generate_from_eq_pi hC (λ i, (h3C i).is_countably_spanning)).symm
(is_pi_system.pi h2C) _,
rintro _ ⟨s, hs, rfl⟩,
rw [mem_univ_pi] at hs,
haveI := λ i, (h3C i).sigma_finite,
simp_rw [h₁ s hs, pi_pi_aux μ s (λ i, h4C i _ (hs i))]
end
variables [∀ i, sigma_finite (μ i)]
/-- A measure on a finite product space equals the product measure if they are equal on
rectangles. -/
lemma pi_eq {μ' : measure (Π i, α i)}
(h : ∀ s : Π i, set (α i), (∀ i, measurable_set (s i)) → μ' (pi univ s) = ∏ i, μ i (s i)) :
measure.pi μ = μ' :=
pi_eq_generate_from (λ i, generate_from_measurable_set)
(λ i, is_pi_system_measurable_set)
(λ i, (μ i).to_finite_spanning_sets_in) h
variables (μ)
lemma pi'_eq_pi [encodable ι] : pi' μ = measure.pi μ :=
eq.symm $ pi_eq $ λ s hs, pi'_pi μ s
@[simp] lemma pi_pi (s : Π i, set (α i)) : measure.pi μ (pi univ s) = ∏ i, μ i (s i) :=
begin
haveI : encodable ι := fintype.encodable ι,
rw [← pi'_eq_pi, pi'_pi]
end
lemma pi_univ : measure.pi μ univ = ∏ i, μ i univ := by rw [← pi_univ, pi_pi μ]
lemma pi_ball [∀ i, metric_space (α i)] (x : Π i, α i) {r : ℝ}
(hr : 0 < r) :
measure.pi μ (metric.ball x r) = ∏ i, μ i (metric.ball (x i) r) :=
by rw [ball_pi _ hr, pi_pi]
lemma pi_closed_ball [∀ i, metric_space (α i)] (x : Π i, α i) {r : ℝ}
(hr : 0 ≤ r) :
measure.pi μ (metric.closed_ball x r) = ∏ i, μ i (metric.closed_ball (x i) r) :=
by rw [closed_ball_pi _ hr, pi_pi]
lemma pi_unique_eq_map {β : Type*} {m : measurable_space β} (μ : measure β) (α : Type*) [unique α] :
measure.pi (λ a : α, μ) = map (measurable_equiv.fun_unique α β).symm μ :=
begin
set e := measurable_equiv.fun_unique α β,
have : pi_premeasure (λ _ : α, μ.to_outer_measure) = map e.symm μ,
{ ext1 s,
rw [pi_premeasure, fintype.prod_unique, to_outer_measure_apply, e.symm.map_apply],
congr' 1, exact e.to_equiv.image_eq_preimage s },
simp only [measure.pi, outer_measure.pi, this, bounded_by_measure, to_outer_measure_to_measure],
end
lemma map_fun_unique {α β : Type*} [unique α] {m : measurable_space β} (μ : measure β) :
map (measurable_equiv.fun_unique α β) (measure.pi $ λ _, μ) = μ :=
(measurable_equiv.fun_unique α β).map_apply_eq_iff_map_symm_apply_eq.2 (pi_unique_eq_map μ _).symm
instance pi.sigma_finite : sigma_finite (measure.pi μ) :=
(finite_spanning_sets_in.pi (λ i, (μ i).to_finite_spanning_sets_in)).sigma_finite
lemma pi_of_empty {α : Type*} [is_empty α] {β : α → Type*} {m : Π a, measurable_space (β a)}
(μ : Π a : α, measure (β a)) (x : Π a, β a := is_empty_elim) :
measure.pi μ = dirac x :=
begin
haveI : ∀ a, sigma_finite (μ a) := is_empty_elim,
refine pi_eq (λ s hs, _),
rw [fintype.prod_empty, dirac_apply_of_mem],
exact is_empty_elim
end
lemma {u} pi_fin_two_eq_map {α : fin 2 → Type u} {m : Π i, measurable_space (α i)}
(μ : Π i, measure (α i)) [∀ i, sigma_finite (μ i)] :
measure.pi μ = map (measurable_equiv.pi_fin_two α).symm ((μ 0).prod (μ 1)) :=
begin
refine pi_eq (λ s hs, _),
rw [measurable_equiv.map_apply, fin.prod_univ_succ, fin.prod_univ_succ, fin.prod_univ_zero,
mul_one, ← measure.prod_prod],
congr' 1,
ext ⟨a, b⟩,
simp [fin.forall_fin_succ, is_empty.forall_iff]
end
lemma {u} map_pi_fin_two {α : fin 2 → Type u} {m : Π i, measurable_space (α i)}
(μ : Π i, measure (α i)) [∀ i, sigma_finite (μ i)] :
map (measurable_equiv.pi_fin_two α) (measure.pi μ) = ((μ 0).prod (μ 1)) :=
(measurable_equiv.pi_fin_two α).map_apply_eq_iff_map_symm_apply_eq.2 (pi_fin_two_eq_map μ).symm
lemma prod_eq_map_fin_two_arrow {α : Type*} {m : measurable_space α} (μ ν : measure α)
[sigma_finite μ] [sigma_finite ν] :
μ.prod ν = map measurable_equiv.fin_two_arrow (measure.pi ![μ, ν]) :=
begin
haveI : ∀ i, sigma_finite (![μ, ν] i) := fin.forall_fin_two.2 ⟨‹_›, ‹_›⟩,
exact (map_pi_fin_two ![μ, ν]).symm
end
lemma prod_eq_map_fin_two_arrow_same {α : Type*} {m : measurable_space α} (μ : measure α)
[sigma_finite μ] :
μ.prod μ = map measurable_equiv.fin_two_arrow (measure.pi $ λ _, μ) :=
by rw [prod_eq_map_fin_two_arrow, matrix.vec_single_eq_const, matrix.vec_cons_const]
lemma pi_eval_preimage_null {i : ι} {s : set (α i)} (hs : μ i s = 0) :
measure.pi μ (eval i ⁻¹' s) = 0 :=
begin
/- WLOG, `s` is measurable -/
rcases exists_measurable_superset_of_null hs with ⟨t, hst, htm, hμt⟩,
suffices : measure.pi μ (eval i ⁻¹' t) = 0,
from measure_mono_null (preimage_mono hst) this,
clear_dependent s,
/- Now rewrite it as `set.pi`, and apply `pi_pi` -/
rw [← univ_pi_update_univ, pi_pi],
apply finset.prod_eq_zero (finset.mem_univ i),
simp [hμt]
end
lemma pi_hyperplane (i : ι) [has_no_atoms (μ i)] (x : α i) :
measure.pi μ {f : Π i, α i | f i = x} = 0 :=
show measure.pi μ (eval i ⁻¹' {x}) = 0,
from pi_eval_preimage_null _ (measure_singleton x)
lemma ae_eval_ne (i : ι) [has_no_atoms (μ i)] (x : α i) :
∀ᵐ y : Π i, α i ∂measure.pi μ, y i ≠ x :=
compl_mem_ae_iff.2 (pi_hyperplane μ i x)
variable {μ}
lemma tendsto_eval_ae_ae {i : ι} : tendsto (eval i) (measure.pi μ).ae (μ i).ae :=
λ s hs, pi_eval_preimage_null μ hs
-- TODO: should we introduce `filter.pi` and prove some basic facts about it?
-- The same combinator appears here and in `nhds_pi`
lemma ae_pi_le_infi_comap : (measure.pi μ).ae ≤ ⨅ i, filter.comap (eval i) (μ i).ae :=
le_infi $ λ i, tendsto_eval_ae_ae.le_comap
lemma ae_eq_pi {β : ι → Type*} {f f' : Π i, α i → β i} (h : ∀ i, f i =ᵐ[μ i] f' i) :
(λ (x : Π i, α i) i, f i (x i)) =ᵐ[measure.pi μ] (λ x i, f' i (x i)) :=
(eventually_all.2 (λ i, tendsto_eval_ae_ae.eventually (h i))).mono $ λ x hx, funext hx
lemma ae_le_pi {β : ι → Type*} [Π i, preorder (β i)] {f f' : Π i, α i → β i}
(h : ∀ i, f i ≤ᵐ[μ i] f' i) :
(λ (x : Π i, α i) i, f i (x i)) ≤ᵐ[measure.pi μ] (λ x i, f' i (x i)) :=
(eventually_all.2 (λ i, tendsto_eval_ae_ae.eventually (h i))).mono $ λ x hx, hx
lemma ae_le_set_pi {I : set ι} {s t : Π i, set (α i)} (h : ∀ i ∈ I, s i ≤ᵐ[μ i] t i) :
(set.pi I s) ≤ᵐ[measure.pi μ] (set.pi I t) :=
((eventually_all_finite (finite.of_fintype I)).2
(λ i hi, tendsto_eval_ae_ae.eventually (h i hi))).mono $
λ x hst hx i hi, hst i hi $ hx i hi
lemma ae_eq_set_pi {I : set ι} {s t : Π i, set (α i)} (h : ∀ i ∈ I, s i =ᵐ[μ i] t i) :
(set.pi I s) =ᵐ[measure.pi μ] (set.pi I t) :=
(ae_le_set_pi (λ i hi, (h i hi).le)).antisymm (ae_le_set_pi (λ i hi, (h i hi).symm.le))
section intervals
variables {μ} [Π i, partial_order (α i)] [∀ i, has_no_atoms (μ i)]
lemma pi_Iio_ae_eq_pi_Iic {s : set ι} {f : Π i, α i} :
pi s (λ i, Iio (f i)) =ᵐ[measure.pi μ] pi s (λ i, Iic (f i)) :=
ae_eq_set_pi $ λ i hi, Iio_ae_eq_Iic
lemma pi_Ioi_ae_eq_pi_Ici {s : set ι} {f : Π i, α i} :
pi s (λ i, Ioi (f i)) =ᵐ[measure.pi μ] pi s (λ i, Ici (f i)) :=
ae_eq_set_pi $ λ i hi, Ioi_ae_eq_Ici
lemma univ_pi_Iio_ae_eq_Iic {f : Π i, α i} :
pi univ (λ i, Iio (f i)) =ᵐ[measure.pi μ] Iic f :=
by { rw ← pi_univ_Iic, exact pi_Iio_ae_eq_pi_Iic }
lemma univ_pi_Ioi_ae_eq_Ici {f : Π i, α i} :
pi univ (λ i, Ioi (f i)) =ᵐ[measure.pi μ] Ici f :=
by { rw ← pi_univ_Ici, exact pi_Ioi_ae_eq_pi_Ici }
lemma pi_Ioo_ae_eq_pi_Icc {s : set ι} {f g : Π i, α i} :
pi s (λ i, Ioo (f i) (g i)) =ᵐ[measure.pi μ] pi s (λ i, Icc (f i) (g i)) :=
ae_eq_set_pi $ λ i hi, Ioo_ae_eq_Icc
lemma univ_pi_Ioo_ae_eq_Icc {f g : Π i, α i} :
pi univ (λ i, Ioo (f i) (g i)) =ᵐ[measure.pi μ] Icc f g :=
by { rw ← pi_univ_Icc, exact pi_Ioo_ae_eq_pi_Icc }
lemma pi_Ioc_ae_eq_pi_Icc {s : set ι} {f g : Π i, α i} :
pi s (λ i, Ioc (f i) (g i)) =ᵐ[measure.pi μ] pi s (λ i, Icc (f i) (g i)) :=
ae_eq_set_pi $ λ i hi, Ioc_ae_eq_Icc
lemma univ_pi_Ioc_ae_eq_Icc {f g : Π i, α i} :
pi univ (λ i, Ioc (f i) (g i)) =ᵐ[measure.pi μ] Icc f g :=
by { rw ← pi_univ_Icc, exact pi_Ioc_ae_eq_pi_Icc }
lemma pi_Ico_ae_eq_pi_Icc {s : set ι} {f g : Π i, α i} :
pi s (λ i, Ico (f i) (g i)) =ᵐ[measure.pi μ] pi s (λ i, Icc (f i) (g i)) :=
ae_eq_set_pi $ λ i hi, Ico_ae_eq_Icc
lemma univ_pi_Ico_ae_eq_Icc {f g : Π i, α i} :
pi univ (λ i, Ico (f i) (g i)) =ᵐ[measure.pi μ] Icc f g :=
by { rw ← pi_univ_Icc, exact pi_Ico_ae_eq_pi_Icc }
end intervals
/-- If one of the measures `μ i` has no atoms, them `measure.pi µ`
has no atoms. The instance below assumes that all `μ i` have no atoms. -/
lemma pi_has_no_atoms (i : ι) [has_no_atoms (μ i)] :
has_no_atoms (measure.pi μ) :=
⟨λ x, flip measure_mono_null (pi_hyperplane μ i (x i)) (singleton_subset_iff.2 rfl)⟩
instance [h : nonempty ι] [∀ i, has_no_atoms (μ i)] : has_no_atoms (measure.pi μ) :=
h.elim $ λ i, pi_has_no_atoms i
instance [Π i, topological_space (α i)] [∀ i, is_locally_finite_measure (μ i)] :
is_locally_finite_measure (measure.pi μ) :=
begin
refine ⟨λ x, _⟩,
choose s hxs ho hμ using λ i, (μ i).exists_is_open_measure_lt_top (x i),
refine ⟨pi univ s, set_pi_mem_nhds finite_univ (λ i hi, is_open.mem_nhds (ho i) (hxs i)), _⟩,
rw [pi_pi],
exact ennreal.prod_lt_top (λ i _, (hμ i).ne)
end
variable (μ)
/-- Separating the indices into those that satisfy a predicate `p` and those that don't maps
a product measure to a product of product measures. This is useful to apply Fubini to some subset
of the variables. The converse is `measure_theory.measure.map_pi_equiv_pi_subtype_prod`. -/
lemma map_pi_equiv_pi_subtype_prod_symm (p : ι → Prop) [decidable_pred p] :
map (equiv.pi_equiv_pi_subtype_prod p α).symm
(measure.prod (measure.pi (λ i, μ i)) (measure.pi (λ i, μ i))) = measure.pi μ :=
begin
refine (measure.pi_eq (λ s hs, _)).symm,
have A : (equiv.pi_equiv_pi_subtype_prod p α).symm ⁻¹' (set.pi set.univ (λ (i : ι), s i)) =
set.prod (set.pi set.univ (λ i, s i)) (set.pi set.univ (λ i, s i)),
{ ext x,
simp only [equiv.pi_equiv_pi_subtype_prod_symm_apply, mem_prod, mem_univ_pi, mem_preimage,
subtype.forall],
split,
{ exact λ h, ⟨λ i hi, by simpa [dif_pos hi] using h i,
λ i hi, by simpa [dif_neg hi] using h i⟩ },
{ assume h i,
by_cases hi : p i,
{ simpa only [dif_pos hi] using h.1 i hi },
{simpa only [dif_neg hi] using h.2 i hi } } },
rw [measure.map_apply (measurable_pi_equiv_pi_subtype_prod_symm _ p)
(measurable_set.univ_pi_fintype hs), A,
measure.prod_prod, pi_pi, pi_pi, ← fintype.prod_subtype_mul_prod_subtype p (λ i, μ i (s i))],
end
lemma map_pi_equiv_pi_subtype_prod (p : ι → Prop) [decidable_pred p] :
map (equiv.pi_equiv_pi_subtype_prod p α) (measure.pi μ) =
measure.prod (measure.pi (λ i, μ i)) (measure.pi (λ i, μ i)) :=
begin
rw [← map_pi_equiv_pi_subtype_prod_symm μ p, measure.map_map
(measurable_pi_equiv_pi_subtype_prod _ p) (measurable_pi_equiv_pi_subtype_prod_symm _ p)],
simp only [equiv.self_comp_symm, map_id]
end
end measure
instance measure_space.pi [Π i, measure_space (α i)] : measure_space (Π i, α i) :=
⟨measure.pi (λ i, volume)⟩
lemma volume_pi [Π i, measure_space (α i)] :
(volume : measure (Π i, α i)) = measure.pi (λ i, volume) :=
rfl
lemma volume_pi_pi [Π i, measure_space (α i)] [∀ i, sigma_finite (volume : measure (α i))]
(s : Π i, set (α i)) :
volume (pi univ s) = ∏ i, volume (s i) :=
measure.pi_pi (λ i, volume) s
lemma volume_pi_ball [Π i, measure_space (α i)] [∀ i, sigma_finite (volume : measure (α i))]
[∀ i, metric_space (α i)] (x : Π i, α i) {r : ℝ} (hr : 0 < r) :
volume (metric.ball x r) = ∏ i, volume (metric.ball (x i) r) :=
measure.pi_ball _ _ hr
lemma volume_pi_closed_ball [Π i, measure_space (α i)] [∀ i, sigma_finite (volume : measure (α i))]
[∀ i, metric_space (α i)] (x : Π i, α i) {r : ℝ} (hr : 0 ≤ r) :
volume (metric.closed_ball x r) = ∏ i, volume (metric.closed_ball (x i) r) :=
measure.pi_closed_ball _ _ hr
section fun_unique
/-!
### Integral over `ι → α` with `[unique ι]`
In this section we prove some lemmas that relate integrals over `ι → β`, where `ι` is a type with
unique element (e.g., `unit` or `fin 1`) and integrals over `β`.
-/
variables {β E : Type*} [normed_group E] [normed_space ℝ E] [measurable_space E]
[topological_space.second_countable_topology E] [borel_space E] [complete_space E]
lemma integral_fun_unique_pi (ι) [unique ι] {m : measurable_space β} (μ : measure β)
(f : (ι → β) → E) :
∫ y, f y ∂(measure.pi (λ _, μ)) = ∫ x, f (λ _, x) ∂μ :=
by rw [measure.pi_unique_eq_map μ ι, integral_map_equiv]; refl
lemma integral_fun_unique_pi' (ι : Type*) [unique ι] {m : measurable_space β} (μ : measure β)
(f : β → E) :
∫ y : ι → β, f (y (default ι)) ∂(measure.pi (λ _, μ)) = ∫ x, f x ∂μ :=
integral_fun_unique_pi ι μ _
lemma integral_fun_unique (ι : Type*) [unique ι] [measure_space β] (f : (ι → β) → E) :
∫ y, f y = ∫ x, f (λ _, x) :=
integral_fun_unique_pi ι volume f
lemma integral_fun_unique' (ι : Type*) [unique ι] [measure_space β] (f : β → E) :
∫ y : ι → β, f (y (default ι)) = ∫ x, f x :=
integral_fun_unique_pi' ι volume f
lemma set_integral_fun_unique_pi (ι : Type*) [unique ι] {m : measurable_space β} (μ : measure β)
(f : (ι → β) → E) (s : set (ι → β)) :
∫ y in s, f y ∂(measure.pi (λ _, μ)) = ∫ x in const ι ⁻¹' s, f (λ _, x) ∂μ :=
by rw [measure.pi_unique_eq_map μ ι, set_integral_map_equiv]; refl
lemma set_integral_fun_unique_pi' (ι : Type*) [unique ι] {m : measurable_space β} (μ : measure β)
(f : β → E) (s : set β) :
∫ y : ι → β in function.eval (default ι) ⁻¹' s, f (y (default ι)) ∂(measure.pi (λ _, μ)) =
∫ x in s, f x ∂μ :=
by erw [set_integral_fun_unique_pi, (equiv.fun_unique ι β).symm_preimage_preimage]
lemma set_integral_fun_unique (ι : Type*) [unique ι] [measure_space β] (f : (ι → β) → E)
(s : set (ι → β)) :
∫ y in s, f y = ∫ x in const ι ⁻¹' s, f (λ _, x) :=
by convert set_integral_fun_unique_pi ι volume f s
lemma set_integral_fun_unique' (ι : Type*) [unique ι] [measure_space β] (f : β → E) (s : set β) :
∫ y : ι → β in @function.eval ι (λ _, β) (default ι) ⁻¹' s, f (y (default ι)) = ∫ x in s, f x :=
by convert set_integral_fun_unique_pi' ι volume f s
end fun_unique
section fin_two_arrow
variables {β E : Type*} [normed_group E] [normed_space ℝ E] [measurable_space E]
[topological_space.second_countable_topology E] [borel_space E] [complete_space E]
lemma integral_fin_two_arrow_pi {m : measurable_space β} (μ ν : measure β)
[sigma_finite μ] [sigma_finite ν] (f : (fin 2 → β) → E) :
∫ y, f y ∂(measure.pi ![μ, ν]) = ∫ x, f ![x.1, x.2] ∂(μ.prod ν) :=
begin
haveI : ∀ i, sigma_finite (![μ, ν] i) := fin.forall_fin_two.2 ⟨‹_›, ‹_›⟩,
rw [measure.pi_fin_two_eq_map, integral_map_equiv], refl
end
lemma integral_fin_two_arrow_pi' {m : measurable_space β} (μ ν : measure β) [sigma_finite μ]
[sigma_finite ν] (f : β × β → E) :
∫ y : fin 2 → β, f (y 0, y 1) ∂(measure.pi ![μ, ν]) = ∫ x, f x ∂(μ.prod ν) :=
by { rw [measure.prod_eq_map_fin_two_arrow, integral_map_equiv], refl }
lemma integral_fin_two_arrow [measure_space β] [sigma_finite (volume : measure β)]
(f : (fin 2 → β) → E) :
∫ y, f y = ∫ x : β × β, f ![x.1, x.2] :=
by rw [volume_pi, measure.volume_eq_prod, ← integral_fin_two_arrow_pi, matrix.vec_single_eq_const,
matrix.vec_cons_const]
lemma integral_fin_two_arrow' [measure_space β] [sigma_finite (volume : measure β)]
(f : β × β → E) :
∫ y : fin 2 → β, f (y 0, y 1) = ∫ x, f x :=
by rw [volume_pi, measure.volume_eq_prod, ← integral_fin_two_arrow_pi', matrix.vec_single_eq_const,
matrix.vec_cons_const]
lemma set_integral_fin_two_arrow_pi {m : measurable_space β} (μ ν : measure β)
[sigma_finite μ] [sigma_finite ν] (f : (fin 2 → β) → E) (s : set (fin 2 → β)) :
∫ y in s, f y ∂(measure.pi ![μ, ν]) =
∫ x : β × β in (fin_two_arrow_equiv β).symm ⁻¹' s, f ![x.1, x.2] ∂(μ.prod ν) :=
begin
haveI : ∀ i, sigma_finite (![μ, ν] i) := fin.forall_fin_two.2 ⟨‹_›, ‹_›⟩,
rw [measure.pi_fin_two_eq_map, set_integral_map_equiv], refl
end
lemma set_integral_fin_two_arrow_pi' {m : measurable_space β} (μ ν : measure β)
[sigma_finite μ] [sigma_finite ν] (f : β × β → E) (s : set (β × β)) :
∫ y : fin 2 → β in fin_two_arrow_equiv β ⁻¹' s, f (y 0, y 1) ∂(measure.pi ![μ, ν]) =
∫ x in s, f x ∂(μ.prod ν) :=
by { rw [set_integral_fin_two_arrow_pi, equiv.symm_preimage_preimage], simp }
lemma set_integral_fin_two_arrow [measure_space β] [sigma_finite (volume : measure β)]
(f : (fin 2 → β) → E) (s : set (fin 2 → β)) :
∫ y in s, f y = ∫ x in (fin_two_arrow_equiv β).symm ⁻¹' s, f ![x.1, x.2] :=
by rw [measure.volume_eq_prod, ← set_integral_fin_two_arrow_pi, volume_pi,
matrix.vec_single_eq_const, matrix.vec_cons_const]
lemma set_integral_fin_two_arrow' [measure_space β] [sigma_finite (volume : measure β)]
(f : β × β → E) (s : set (β × β)) :
∫ y : fin 2 → β in fin_two_arrow_equiv β ⁻¹' s, f (y 0, y 1) = ∫ x in s, f x :=
by rw [measure.volume_eq_prod, ← set_integral_fin_two_arrow_pi', volume_pi,
matrix.vec_single_eq_const, matrix.vec_cons_const]
end fin_two_arrow
end measure_theory
|
a95baf9a8085d74d8312c681d18f1c15f6332386 | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /src/Lean/Meta/Check.lean | a10e0d7ff558ffc23e1a193ba8c779d3a94ef11d | [
"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 | 6,191 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.InferType
import Lean.Meta.LevelDefEq
/-
This is not the Kernel type checker, but an auxiliary method for checking
whether terms produced by tactics and `isDefEq` are type correct.
-/
namespace Lean.Meta
private def ensureType (e : Expr) : MetaM Unit := do
discard <| getLevel e
def throwLetTypeMismatchMessage {α} (fvarId : FVarId) : MetaM α := do
let lctx ← getLCtx
match lctx.find? fvarId with
| some (LocalDecl.ldecl _ _ n t v _) => do
let vType ← inferType v
throwError! "invalid let declaration, term{indentExpr v}\nhas type{indentExpr vType}\nbut is expected to have type{indentExpr t}"
| _ => unreachable!
private def checkConstant (constName : Name) (us : List Level) : MetaM Unit := do
let cinfo ← getConstInfo constName
unless us.length == cinfo.lparams.length do
throwIncorrectNumberOfLevels constName us
private def getFunctionDomain (f : Expr) : MetaM (Expr × BinderInfo) := do
let fType ← inferType f
let fType ← whnfD fType
match fType with
| Expr.forallE _ d _ c => return (d, c.binderInfo)
| _ => throwFunctionExpected f
/-
Given to expressions `a` and `b`, this method tries to annotate terms with `pp.explicit := true` to
expose "implicit" differences. For example, suppose `a` and `b` are of the form
```lean
@HashMap Nat Nat eqInst hasInst1
@HashMap Nat Nat eqInst hasInst2
```
By default, the pretty printer formats both of them as `HashMap Nat Nat`.
So, counterintuitive error messages such as
```lean
error: application type mismatch
HashMap.insert m
argument
m
has type
HashMap Nat Nat
but is expected to have type
HashMap Nat Nat
```
would be produced.
By adding `pp.explicit := true`, we can generate the more informative error
```lean
error: application type mismatch
HashMap.insert m
argument
m
has type
@HashMap Nat Nat eqInst hasInst1
but is expected to have type
@HashMap Nat Nat eqInst hasInst2
```
Remark: this method implements a simple heuristic, we should extend it as we find other counterintuitive
error messages.
-/
partial def addPPExplicitToExposeDiff (a b : Expr) : MetaM (Expr × Expr) := do
if (← getOptions).getBool `pp.all false || (← getOptions).getBool `pp.explicit false then
return (a, b)
else
visit a b
where
visit (a b : Expr) : MetaM (Expr × Expr) := do
try
if !a.isApp || !b.isApp then
return (a, b)
else if a.getAppNumArgs != b.getAppNumArgs then
return (a, b)
else if not (← isDefEq a.getAppFn b.getAppFn) then
return (a, b)
else
let fType ← inferType a.getAppFn
forallBoundedTelescope fType a.getAppNumArgs fun xs _ => do
let mut as := a.getAppArgs
let mut bs := b.getAppArgs
if (← hasExplicitDiff xs as bs) then
return (a, b)
else
for i in [:as.size] do
let (ai, bi) ← visit as[i] bs[i]
as := as.set! i ai
bs := bs.set! i bi
let a := mkAppN a.getAppFn as
let b := mkAppN b.getAppFn bs
return (a.setAppPPExplicit, b.setAppPPExplicit)
catch _ =>
return (a, b)
hasExplicitDiff (xs as bs : Array Expr) : MetaM Bool := do
for i in [:xs.size] do
let localDecl ← getLocalDecl xs[i].fvarId!
if localDecl.binderInfo.isExplicit then
if not (← isDefEq as[i] bs[i]) then
return true
return false
/-
Return error message "has type{givenType}\nbut is expected to have type{expectedType}"
-/
def mkHasTypeButIsExpectedMsg (givenType expectedType : Expr) : MetaM MessageData := do
let (givenType, expectedType) ← addPPExplicitToExposeDiff givenType expectedType
m!"has type{indentExpr givenType}\nbut is expected to have type{indentExpr expectedType}"
def throwAppTypeMismatch {α} (f a : Expr) (extraMsg : MessageData := Format.nil) : MetaM α := do
let (expectedType, binfo) ← getFunctionDomain f
let mut e := mkApp f a
unless binfo.isExplicit do
e := e.setAppPPExplicit
let aType ← inferType a
throwError! "application type mismatch{indentExpr e}\nargument{indentExpr a}\n{← mkHasTypeButIsExpectedMsg aType expectedType}"
def checkApp (f a : Expr) : MetaM Unit := do
let fType ← inferType f
let fType ← whnf fType
match fType with
| Expr.forallE _ d _ _ =>
let aType ← inferType a
unless (← isDefEq d aType) do
throwAppTypeMismatch f a
| _ => throwFunctionExpected (mkApp f a)
private partial def checkAux : Expr → MetaM Unit
| e@(Expr.forallE ..) => checkForall e
| e@(Expr.lam ..) => checkLambdaLet e
| e@(Expr.letE ..) => checkLambdaLet e
| Expr.const c lvls _ => checkConstant c lvls
| Expr.app f a _ => do checkAux f; checkAux a; checkApp f a
| Expr.mdata _ e _ => checkAux e
| Expr.proj _ _ e _ => checkAux e
| _ => pure ()
where
checkLambdaLet (e : Expr) : MetaM Unit :=
lambdaLetTelescope e fun xs b => do
xs.forM fun x => do
let xDecl ← getFVarLocalDecl x;
match xDecl with
| LocalDecl.cdecl _ _ _ t _ =>
ensureType t
checkAux t
| LocalDecl.ldecl _ _ _ t v _ =>
ensureType t
checkAux t
let vType ← inferType v
unless (← isDefEq t vType) do throwLetTypeMismatchMessage x.fvarId!
checkAux v
checkAux b
checkForall (e : Expr) : MetaM Unit :=
forallTelescope e fun xs b => do
xs.forM fun x => do
let xDecl ← getFVarLocalDecl x
ensureType xDecl.type
checkAux xDecl.type
ensureType b
checkAux b
def check (e : Expr) : MetaM Unit :=
traceCtx `Meta.check do
withTransparency TransparencyMode.all $ checkAux e
def isTypeCorrect (e : Expr) : MetaM Bool := do
try
check e
pure true
catch ex =>
trace[Meta.typeError]! ex.toMessageData
pure false
builtin_initialize
registerTraceClass `Meta.check
registerTraceClass `Meta.typeError
end Lean.Meta
|
367d9204128223024882970fb374b1e42a46cf21 | f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58 | /data/int/gcd.lean | 40e2aa81d5171e3e338615a6b345ca01b5c04b0c | [
"Apache-2.0"
] | permissive | semorrison/mathlib | 1be6f11086e0d24180fec4b9696d3ec58b439d10 | 20b4143976dad48e664c4847b75a85237dca0a89 | refs/heads/master | 1,583,799,212,170 | 1,535,634,130,000 | 1,535,730,505,000 | 129,076,205 | 0 | 0 | Apache-2.0 | 1,551,697,998,000 | 1,523,442,265,000 | Lean | UTF-8 | Lean | false | false | 11,961 | lean | /-
Copyright (c) 2018 Guy Leroy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl
Greatest common divisor (gcd) and least common multiple (lcm) for integers.
This sets up ℤ to be a GCD domain, and introduces rules about `int.gcd`, as well as `int.lcm`.
NOTE: If you add rules to this theory, check that the corresponding rules are available for
`gcd_domain`.
-/
import data.int.basic data.nat.prime algebra.gcd_domain
/- Extended Euclidean algorithm -/
namespace nat
def xgcd_aux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ
| 0 s t r' s' t' := (r', s', t')
| r@(succ _) s t r' s' t' :=
have r' % r < r, from mod_lt _ $ succ_pos _,
let q := r' / r in xgcd_aux (r' % r) (s' - q * s) (t' - q * t) r s t
@[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcd_aux 0 s t r' s' t' = (r', s', t') :=
by simp [xgcd_aux]
@[simp] theorem xgcd_aux_rec {r s t r' s' t'} (h : 0 < r) : xgcd_aux r s t r' s' t' = xgcd_aux (r' % r) (s' - (r' / r) * s) (t' - (r' / r) * t) r s t :=
by cases r; [exact absurd h (lt_irrefl _), {simp only [xgcd_aux], refl}]
/-- Use the extended GCD algorithm to generate the `a` and `b` values
satisfying `gcd x y = x * a + y * b`. -/
def xgcd (x y : ℕ) : ℤ × ℤ := (xgcd_aux x 1 0 y 0 1).2
/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/
def gcd_a (x y : ℕ) : ℤ := (xgcd x y).1
/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/
def gcd_b (x y : ℕ) : ℤ := (xgcd x y).2
@[simp] theorem xgcd_aux_fst (x y) : ∀ s t s' t',
(xgcd_aux x s t y s' t').1 = gcd x y :=
gcd.induction x y (by simp) (λ x y h IH s t s' t', by simp [h, IH]; rw ← gcd_rec)
theorem xgcd_aux_val (x y) : xgcd_aux x 1 0 y 0 1 = (gcd x y, xgcd x y) :=
by rw [xgcd, ← xgcd_aux_fst x y 1 0 0 1]; cases xgcd_aux x 1 0 y 0 1; refl
theorem xgcd_val (x y) : xgcd x y = (gcd_a x y, gcd_b x y) :=
by unfold gcd_a gcd_b; cases xgcd x y; refl
section
parameters (a b : ℕ)
private def P : ℕ × ℤ × ℤ → Prop | (r, s, t) := (r : ℤ) = a * s + b * t
theorem xgcd_aux_P {r r'} : ∀ {s t s' t'}, P (r, s, t) → P (r', s', t') → P (xgcd_aux r s t r' s' t') :=
gcd.induction r r' (by simp) $ λ x y h IH s t s' t' p p', begin
rw [xgcd_aux_rec h], refine IH _ p, dsimp [P] at *,
rw [int.mod_def], generalize : (y / x : ℤ) = k,
rw [p, p'], simp [mul_add, mul_comm, mul_left_comm]
end
theorem gcd_eq_gcd_ab : (gcd a b : ℤ) = a * gcd_a a b + b * gcd_b a b :=
by have := @xgcd_aux_P a b a b 1 0 0 1 (by simp [P]) (by simp [P]);
rwa [xgcd_aux_val, xgcd_val] at this
end
end nat
namespace int
theorem nat_abs_div (a b : ℤ) (H : b ∣ a) : nat_abs (a / b) = (nat_abs a) / (nat_abs b) :=
begin
cases (nat.eq_zero_or_pos (nat_abs b)),
rw eq_zero_of_nat_abs_eq_zero h,
simp,
calc
nat_abs (a / b) = nat_abs (a / b) * 1 : by rw mul_one
... = nat_abs (a / b) * (nat_abs b / nat_abs b) : by rw nat.div_self h
... = nat_abs (a / b) * nat_abs b / nat_abs b : by rw (nat.mul_div_assoc _ (dvd_refl _))
... = nat_abs (a / b * b) / nat_abs b : by rw (nat_abs_mul (a / b) b)
... = nat_abs a / nat_abs b : by rw int.div_mul_cancel H,
end
theorem nat_abs_dvd_abs_iff {i j : ℤ} : i.nat_abs ∣ j.nat_abs ↔ i ∣ j :=
⟨assume (H : i.nat_abs ∣ j.nat_abs), dvd_nat_abs.mp (nat_abs_dvd.mp (coe_nat_dvd.mpr H)),
assume H : (i ∣ j), coe_nat_dvd.mp (dvd_nat_abs.mpr (nat_abs_dvd.mpr H))⟩
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : ℕ} (p_prime : nat.prime p) {m n : ℤ} {k l : ℕ}
(hpm : ↑(p ^ k) ∣ m)
(hpn : ↑(p ^ l) ∣ n) (hpmn : ↑(p ^ (k+l+1)) ∣ m*n) : ↑(p ^ (k+1)) ∣ m ∨ ↑(p ^ (l+1)) ∣ n :=
have hpm' : p ^ k ∣ m.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpm,
have hpn' : p ^ l ∣ n.nat_abs, from int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpn,
have hpmn' : (p ^ (k+l+1)) ∣ m.nat_abs*n.nat_abs,
by rw ←int.nat_abs_mul; apply (int.coe_nat_dvd.1 $ int.dvd_nat_abs.2 hpmn),
let hsd := nat.succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul p_prime hpm' hpn' hpmn' in
hsd.elim
(λ hsd1, or.inl begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd1 end)
(λ hsd2, or.inr begin apply int.dvd_nat_abs.1, apply int.coe_nat_dvd.2 hsd2 end)
theorem dvd_of_mul_dvd_mul_left {i j k : ℤ} (k_non_zero : k ≠ 0) (H : k * i ∣ k * j) : i ∣ j :=
dvd.elim H (λl H1, by rw mul_assoc at H1; exact ⟨_, eq_of_mul_eq_mul_left k_non_zero H1⟩)
theorem dvd_of_mul_dvd_mul_right {i j k : ℤ} (k_non_zero : k ≠ 0) (H : i * k ∣ j * k) : i ∣ j :=
by rw [mul_comm i k, mul_comm j k] at H; exact dvd_of_mul_dvd_mul_left k_non_zero H
section normalization_domain
instance : normalization_domain ℤ :=
{ 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
by_cases ha : 0 ≤ a; by_cases hb : 0 ≤ b; simp [ha, hb],
exact if_pos (mul_nonneg ha hb),
exact if_neg (assume h, hb $ nonneg_of_mul_nonneg_left h $ lt_of_le_of_ne ha hna.symm),
exact if_neg (assume h, ha $ nonneg_of_mul_nonneg_right h $ lt_of_le_of_ne hb hnb.symm),
exact if_pos (mul_nonneg_of_nonpos_of_nonpos (le_of_not_ge ha) (le_of_not_ge hb))
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 simpa [@neg_lt ℤ _ 1 0])),
.. (infer_instance : integral_domain ℤ) }
lemma norm_unit_of_nonneg {z : ℤ} (h : 0 ≤ z) : norm_unit z = 1 :=
by unfold norm_unit; exact if_pos h
lemma norm_unit_of_neg {z : ℤ} (h : z < 0) : norm_unit z = -1 :=
by unfold norm_unit; exact if_neg (not_le_of_gt h)
lemma norm_unit_nat_coe (n : ℕ) : norm_unit (n : ℤ) = 1 :=
norm_unit_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n)
theorem coe_nat_abs_eq_mul_norm_unit {z : ℤ} : (z.nat_abs : ℤ) = z * norm_unit z :=
begin
by_cases 0 ≤ z,
{ simp [nat_abs_of_nonneg h, norm_unit_of_nonneg h] },
{ simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), norm_unit_of_neg (lt_of_not_ge h)] }
end
end normalization_domain
/-- ℤ specific version of least common multiple. -/
def lcm (i j : ℤ) : ℕ := nat.lcm (nat_abs i) (nat_abs j)
theorem lcm_def (i j : ℤ) : lcm i j = nat.lcm (nat_abs i) (nat_abs j) := rfl
section gcd_domain
theorem gcd_dvd_left (i j : ℤ) : (gcd i j : ℤ) ∣ i :=
dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_left _ _
theorem gcd_dvd_right (i j : ℤ) : (gcd i j : ℤ) ∣ j :=
dvd_nat_abs.mp $ coe_nat_dvd.mpr $ nat.gcd_dvd_right _ _
theorem dvd_gcd {i j k : ℤ} (h1 : k ∣ i) (h2 : k ∣ j) : k ∣ gcd i j :=
nat_abs_dvd.1 $ coe_nat_dvd.2 $ nat.dvd_gcd (nat_abs_dvd_abs_iff.2 h1) (nat_abs_dvd_abs_iff.2 h2)
theorem gcd_mul_lcm (i j : ℤ) : gcd i j * lcm i j = nat_abs (i * j) :=
by rw [int.gcd, int.lcm, nat.gcd_mul_lcm, nat_abs_mul]
instance : gcd_domain ℤ :=
{ 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,
norm_unit_gcd := assume a b, norm_unit_nat_coe _,
gcd_mul_lcm := by intros; rw [← int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_mul_norm_unit],
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_domain }
lemma coe_gcd (i j : ℤ) : ↑(int.gcd i j) = gcd_domain.gcd i j := rfl
lemma coe_lcm (i j : ℤ) : ↑(int.lcm i j) = gcd_domain.lcm i j := rfl
lemma nat_abs_gcd (i j : ℤ) : nat_abs (gcd_domain.gcd i j) = int.gcd i j := rfl
lemma nat_abs_lcm (i j : ℤ) : nat_abs (gcd_domain.lcm i j) = int.lcm i j := rfl
end gcd_domain
theorem gcd_comm (i j : ℤ) : gcd i j = gcd j i := nat.gcd_comm _ _
theorem gcd_assoc (i j k : ℤ) : gcd (gcd i j) k = gcd i (gcd j k) := nat.gcd_assoc _ _ _
@[simp] theorem gcd_self (i : ℤ) : gcd i i = nat_abs i := by simp [gcd]
@[simp] theorem gcd_zero_left (i : ℤ) : gcd 0 i = nat_abs i := by simp [gcd]
@[simp] theorem gcd_zero_right (i : ℤ) : gcd i 0 = nat_abs i := by simp [gcd]
@[simp] theorem gcd_one_left (i : ℤ) : gcd 1 i = 1 := nat.gcd_one_left _
@[simp] theorem gcd_one_right (i : ℤ) : gcd i 1 = 1 := nat.gcd_one_right _
theorem gcd_mul_left (i j k : ℤ) : gcd (i * j) (i * k) = nat_abs i * gcd j k :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit]
theorem gcd_mul_right (i j k : ℤ) : gcd (i * j) (k * j) = gcd i k * nat_abs j :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_gcd, coe_nat_abs_eq_mul_norm_unit]
theorem gcd_pos_of_non_zero_left {i : ℤ} (j : ℤ) (i_non_zero : i ≠ 0) : gcd i j > 0 :=
nat.gcd_pos_of_pos_left (nat_abs j) (nat_abs_pos_of_ne_zero i_non_zero)
theorem gcd_pos_of_non_zero_right (i : ℤ) {j : ℤ} (j_non_zero : j ≠ 0) : gcd i j > 0 :=
nat.gcd_pos_of_pos_right (nat_abs i) (nat_abs_pos_of_ne_zero j_non_zero)
theorem gcd_eq_zero_iff {i j : ℤ} : gcd i j = 0 ↔ i = 0 ∧ j = 0 :=
by rw [← int.coe_nat_eq_coe_nat_iff, int.coe_nat_zero, coe_gcd, gcd_eq_zero_iff]
theorem gcd_div {i j k : ℤ} (H1 : k ∣ i) (H2 : k ∣ j) :
gcd (i / k) (j / k) = gcd i j / nat_abs k :=
by rw [gcd, nat_abs_div i k H1, nat_abs_div j k H2];
exact nat.gcd_div (nat_abs_dvd_abs_iff.mpr H1) (nat_abs_dvd_abs_iff.mpr H2)
theorem gcd_dvd_gcd_of_dvd_left {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd i j ∣ gcd k j :=
int.coe_nat_dvd.1 $ dvd_gcd (dvd.trans (gcd_dvd_left i j) H) (gcd_dvd_right i j)
theorem gcd_dvd_gcd_of_dvd_right {i k : ℤ} (j : ℤ) (H : i ∣ k) : gcd j i ∣ gcd j k :=
int.coe_nat_dvd.1 $ dvd_gcd (gcd_dvd_left j i) (dvd.trans (gcd_dvd_right j i) H)
theorem gcd_dvd_gcd_mul_left (i j k : ℤ) : gcd i j ∣ gcd (k * i) j :=
gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right (i j k : ℤ) : gcd i j ∣ gcd (i * k) j :=
gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _)
theorem gcd_dvd_gcd_mul_left_right (i j k : ℤ) : gcd i j ∣ gcd i (k * j) :=
gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _)
theorem gcd_dvd_gcd_mul_right_right (i j k : ℤ) : gcd i j ∣ gcd i (j * k) :=
gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _)
theorem gcd_eq_left {i j : ℤ} (H : i ∣ j) : gcd i j = nat_abs i :=
nat.dvd_antisymm (by unfold gcd; exact nat.gcd_dvd_left _ _)
(by unfold gcd; exact nat.dvd_gcd (dvd_refl _) (nat_abs_dvd_abs_iff.mpr H))
theorem gcd_eq_right {i j : ℤ} (H : j ∣ i) : gcd i j = nat_abs j :=
by rw [gcd_comm, gcd_eq_left H]
/- lcm -/
theorem lcm_comm (i j : ℤ) : lcm i j = lcm j i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_comm]
theorem lcm_assoc (i j k : ℤ) : lcm (lcm i j) k = lcm i (lcm j k) :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, lcm_assoc]
@[simp] theorem lcm_zero_left (i : ℤ) : lcm 0 i = 0 :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm]
@[simp] theorem lcm_zero_right (i : ℤ) : lcm i 0 = 0 :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm]
@[simp] theorem lcm_one_left (i : ℤ) : lcm 1 i = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
@[simp] theorem lcm_one_right (i : ℤ) : lcm i 1 = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
@[simp] theorem lcm_self (i : ℤ) : lcm i i = nat_abs i :=
by simp [(int.coe_nat_eq_coe_nat_iff _ _).symm, coe_lcm, coe_nat_abs_eq_mul_norm_unit]
theorem dvd_lcm_left (i j : ℤ) : i ∣ lcm i j :=
by rw [coe_lcm]; exact dvd_lcm_left _ _
theorem dvd_lcm_right (i j : ℤ) : j ∣ lcm i j :=
by rw [coe_lcm]; exact dvd_lcm_right _ _
theorem lcm_dvd {i j k : ℤ} : i ∣ k → j ∣ k → (lcm i j : ℤ) ∣ k :=
by rw [coe_lcm]; exact lcm_dvd
end int
|
7ec7827afee9995f0baf00e384dccfd58aafaaa7 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/complex/locally_uniform_limit.lean | cc91ebd185d1fb1fec84a3dd01dcb04f296ea787 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 10,428 | lean | /-
Copyright (c) 2022 Vincent Beffara. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Vincent Beffara
-/
import analysis.complex.removable_singularity
import analysis.calculus.series
/-!
# Locally uniform limits of holomorphic functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file gathers some results about locally uniform limits of holomorphic functions on an open
subset of the complex plane.
## Main results
* `tendsto_locally_uniformly_on.differentiable_on`: A locally uniform limit of holomorphic functions
is holomorphic.
* `tendsto_locally_uniformly_on.deriv`: Locally uniform convergence implies locally uniform
convergence of the derivatives to the derivative of the limit.
-/
open set metric measure_theory filter complex interval_integral
open_locale real topology
variables {E ι : Type*} [normed_add_comm_group E] [normed_space ℂ E] [complete_space E]
{U K : set ℂ} {z : ℂ} {M r δ : ℝ} {φ : filter ι} {F : ι → ℂ → E} {f g : ℂ → E}
namespace complex
section cderiv
/-- A circle integral which coincides with `deriv f z` whenever one can apply the Cauchy formula for
the derivative. It is useful in the proof that locally uniform limits of holomorphic functions are
holomorphic, because it depends continuously on `f` for the uniform topology. -/
noncomputable def cderiv (r : ℝ) (f : ℂ → E) (z : ℂ) : E :=
(2 * π * I : ℂ)⁻¹ • ∮ w in C(z, r), ((w - z) ^ 2)⁻¹ • f w
lemma cderiv_eq_deriv (hU : is_open U) (hf : differentiable_on ℂ f U) (hr : 0 < r)
(hzr : closed_ball z r ⊆ U) :
cderiv r f z = deriv f z :=
two_pi_I_inv_smul_circle_integral_sub_sq_inv_smul_of_differentiable hU hzr hf (mem_ball_self hr)
lemma norm_cderiv_le (hr : 0 < r) (hf : ∀ w ∈ sphere z r, ‖f w‖ ≤ M) :
‖cderiv r f z‖ ≤ M / r :=
begin
have hM : 0 ≤ M,
{ obtain ⟨w, hw⟩ : (sphere z r).nonempty := normed_space.sphere_nonempty.mpr hr.le,
exact (norm_nonneg _).trans (hf w hw) },
have h1 : ∀ w ∈ sphere z r, ‖((w - z) ^ 2)⁻¹ • f w‖ ≤ M / r ^ 2,
{ intros w hw,
simp only [mem_sphere_iff_norm, norm_eq_abs] at hw,
simp only [norm_smul, inv_mul_eq_div, hw, norm_eq_abs, map_inv₀, complex.abs_pow],
exact div_le_div hM (hf w hw) (sq_pos_of_pos hr) le_rfl },
have h2 := circle_integral.norm_integral_le_of_norm_le_const hr.le h1,
simp only [cderiv, norm_smul],
refine (mul_le_mul le_rfl h2 (norm_nonneg _) (norm_nonneg _)).trans (le_of_eq _),
field_simp [_root_.abs_of_nonneg real.pi_pos.le, real.pi_pos.ne.symm, hr.ne.symm],
ring
end
lemma cderiv_sub (hr : 0 < r) (hf : continuous_on f (sphere z r))
(hg : continuous_on g (sphere z r)) :
cderiv r (f - g) z = cderiv r f z - cderiv r g z :=
begin
have h1 : continuous_on (λ (w : ℂ), ((w - z) ^ 2)⁻¹) (sphere z r),
{ refine ((continuous_id'.sub continuous_const).pow 2).continuous_on.inv₀ (λ w hw h, hr.ne _),
rwa [mem_sphere_iff_norm, sq_eq_zero_iff.mp h, norm_zero] at hw },
simp_rw [cderiv, ← smul_sub],
congr' 1,
simpa only [pi.sub_apply, smul_sub] using circle_integral.integral_sub
((h1.smul hf).circle_integrable hr.le) ((h1.smul hg).circle_integrable hr.le)
end
lemma norm_cderiv_lt (hr : 0 < r) (hfM : ∀ w ∈ sphere z r, ‖f w‖ < M)
(hf : continuous_on f (sphere z r)) :
‖cderiv r f z‖ < M / r :=
begin
obtain ⟨L, hL1, hL2⟩ : ∃ L < M, ∀ w ∈ sphere z r, ‖f w‖ ≤ L,
{ have e1 : (sphere z r).nonempty := normed_space.sphere_nonempty.mpr hr.le,
have e2 : continuous_on (λ w, ‖f w‖) (sphere z r),
from continuous_norm.comp_continuous_on hf,
obtain ⟨x, hx, hx'⟩ := (is_compact_sphere z r).exists_forall_ge e1 e2,
exact ⟨‖f x‖, hfM x hx, hx'⟩ },
exact (norm_cderiv_le hr hL2).trans_lt ((div_lt_div_right hr).mpr hL1)
end
lemma norm_cderiv_sub_lt (hr : 0 < r) (hfg : ∀ w ∈ sphere z r, ‖f w - g w‖ < M)
(hf : continuous_on f (sphere z r)) (hg : continuous_on g (sphere z r)) :
‖cderiv r f z - cderiv r g z‖ < M / r :=
cderiv_sub hr hf hg ▸ norm_cderiv_lt hr hfg (hf.sub hg)
lemma tendsto_uniformly_on.cderiv (hF : tendsto_uniformly_on F f φ (cthickening δ K)) (hδ : 0 < δ)
(hFn : ∀ᶠ n in φ, continuous_on (F n) (cthickening δ K)) :
tendsto_uniformly_on (cderiv δ ∘ F) (cderiv δ f) φ K :=
begin
by_cases φ = ⊥,
{ simp only [h, tendsto_uniformly_on, eventually_bot, implies_true_iff]},
haveI : φ.ne_bot := ne_bot_iff.2 h,
have e1 : continuous_on f (cthickening δ K) := tendsto_uniformly_on.continuous_on hF hFn,
rw [tendsto_uniformly_on_iff] at hF ⊢,
rintro ε hε,
filter_upwards [hF (ε * δ) (mul_pos hε hδ), hFn] with n h h' z hz,
simp_rw [dist_eq_norm] at h ⊢,
have e2 : ∀ w ∈ sphere z δ, ‖f w - F n w‖ < ε * δ,
from λ w hw1, h w (closed_ball_subset_cthickening hz δ (sphere_subset_closed_ball hw1)),
have e3 := sphere_subset_closed_ball.trans (closed_ball_subset_cthickening hz δ),
have hf : continuous_on f (sphere z δ),
from e1.mono (sphere_subset_closed_ball.trans (closed_ball_subset_cthickening hz δ)),
simpa only [mul_div_cancel _ hδ.ne.symm] using norm_cderiv_sub_lt hδ e2 hf (h'.mono e3)
end
end cderiv
section weierstrass
lemma tendsto_uniformly_on_deriv_of_cthickening_subset (hf : tendsto_locally_uniformly_on F f φ U)
(hF : ∀ᶠ n in φ, differentiable_on ℂ (F n) U) {δ : ℝ} (hδ: 0 < δ) (hK : is_compact K)
(hU : is_open U) (hKU : cthickening δ K ⊆ U) :
tendsto_uniformly_on (deriv ∘ F) (cderiv δ f) φ K :=
begin
have h1 : ∀ᶠ n in φ, continuous_on (F n) (cthickening δ K),
by filter_upwards [hF] with n h using h.continuous_on.mono hKU,
have h2 : is_compact (cthickening δ K),
from is_compact_of_is_closed_bounded is_closed_cthickening hK.bounded.cthickening,
have h3 : tendsto_uniformly_on F f φ (cthickening δ K),
from (tendsto_locally_uniformly_on_iff_forall_is_compact hU).mp hf (cthickening δ K) hKU h2,
apply (h3.cderiv hδ h1).congr,
filter_upwards [hF] with n h z hz,
exact cderiv_eq_deriv hU h hδ ((closed_ball_subset_cthickening hz δ).trans hKU)
end
lemma exists_cthickening_tendsto_uniformly_on (hf : tendsto_locally_uniformly_on F f φ U)
(hF : ∀ᶠ n in φ, differentiable_on ℂ (F n) U) (hK : is_compact K) (hU : is_open U) (hKU : K ⊆ U) :
∃ δ > 0, cthickening δ K ⊆ U ∧ tendsto_uniformly_on (deriv ∘ F) (cderiv δ f) φ K :=
begin
obtain ⟨δ, hδ, hKδ⟩ := hK.exists_cthickening_subset_open hU hKU,
exact ⟨δ, hδ, hKδ, tendsto_uniformly_on_deriv_of_cthickening_subset hf hF hδ hK hU hKδ⟩
end
/-- A locally uniform limit of holomorphic functions on an open domain of the complex plane is
holomorphic (the derivatives converge locally uniformly to that of the limit, which is proved
as `tendsto_locally_uniformly_on.deriv`). -/
theorem _root_.tendsto_locally_uniformly_on.differentiable_on [φ.ne_bot]
(hf : tendsto_locally_uniformly_on F f φ U) (hF : ∀ᶠ n in φ, differentiable_on ℂ (F n) U)
(hU : is_open U) :
differentiable_on ℂ f U :=
begin
rintro x hx,
obtain ⟨K, ⟨hKx, hK⟩, hKU⟩ := (compact_basis_nhds x).mem_iff.mp (hU.mem_nhds hx),
obtain ⟨δ, hδ, -, h1⟩ := exists_cthickening_tendsto_uniformly_on hf hF hK hU hKU,
have h2 : interior K ⊆ U := interior_subset.trans hKU,
have h3 : ∀ᶠ n in φ, differentiable_on ℂ (F n) (interior K),
filter_upwards [hF] with n h using h.mono h2,
have h4 : tendsto_locally_uniformly_on F f φ (interior K) := hf.mono h2,
have h5 : tendsto_locally_uniformly_on (deriv ∘ F) (cderiv δ f) φ (interior K),
from h1.tendsto_locally_uniformly_on.mono interior_subset,
have h6 : ∀ x ∈ interior K, has_deriv_at f (cderiv δ f x) x,
from λ x h, has_deriv_at_of_tendsto_locally_uniformly_on'
is_open_interior h5 h3 (λ _, h4.tendsto_at) h,
have h7 : differentiable_on ℂ f (interior K),
from λ x hx, (h6 x hx).differentiable_at.differentiable_within_at,
exact (h7.differentiable_at (interior_mem_nhds.mpr hKx)).differentiable_within_at
end
lemma _root_.tendsto_locally_uniformly_on.deriv (hf : tendsto_locally_uniformly_on F f φ U)
(hF : ∀ᶠ n in φ, differentiable_on ℂ (F n) U) (hU : is_open U) :
tendsto_locally_uniformly_on (deriv ∘ F) (deriv f) φ U :=
begin
rw [tendsto_locally_uniformly_on_iff_forall_is_compact hU],
by_cases φ = ⊥,
{ simp only [h, tendsto_uniformly_on, eventually_bot, implies_true_iff] },
haveI : φ.ne_bot := ne_bot_iff.2 h,
rintro K hKU hK,
obtain ⟨δ, hδ, hK4, h⟩ := exists_cthickening_tendsto_uniformly_on hf hF hK hU hKU,
refine h.congr_right (λ z hz, cderiv_eq_deriv hU (hf.differentiable_on hF hU) hδ _),
exact (closed_ball_subset_cthickening hz δ).trans hK4,
end
end weierstrass
section tsums
/-- If the terms in the sum `∑' (i : ι), F i` are uniformly bounded on `U` by a
summable function, and each term in the sum is differentiable on `U`, then so is the sum. -/
lemma differentiable_on_tsum_of_summable_norm {u : ι → ℝ}
(hu : summable u) (hf : ∀ (i : ι), differentiable_on ℂ (F i) U) (hU : is_open U)
(hF_le : ∀ (i : ι) (w : ℂ), w ∈ U → ‖F i w‖ ≤ u i) :
differentiable_on ℂ (λ w : ℂ, ∑' (i : ι), F i w) U :=
begin
classical,
have hc := (tendsto_uniformly_on_tsum hu hF_le).tendsto_locally_uniformly_on,
refine hc.differentiable_on (eventually_of_forall $ λ s, _) hU,
exact differentiable_on.sum (λ i hi, hf i),
end
/-- If the terms in the sum `∑' (i : ι), F i` are uniformly bounded on `U` by a
summable function, then the sum of `deriv F i` at a point in `U` is the derivative of the
sum. -/
lemma has_sum_deriv_of_summable_norm {u : ι → ℝ}
(hu : summable u) (hf : ∀ (i : ι), differentiable_on ℂ (F i) U) (hU : is_open U)
(hF_le : ∀ (i : ι) (w : ℂ), w ∈ U → ‖F i w‖ ≤ u i) (hz : z ∈ U) :
has_sum (λ (i : ι), deriv (F i) z) (deriv (λ w : ℂ, ∑' (i : ι), F i w) z) :=
begin
rw has_sum,
have hc := (tendsto_uniformly_on_tsum hu hF_le).tendsto_locally_uniformly_on,
convert (hc.deriv (eventually_of_forall $ λ s, differentiable_on.sum
(λ i hi, hf i)) hU).tendsto_at hz using 1,
ext1 s,
exact (deriv_sum (λ i hi, (hf i).differentiable_at (hU.mem_nhds hz))).symm,
end
end tsums
end complex
|
9a36cd4dea925a0df06e5e17434acaa4164d1b29 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/data/int/order_auto.lean | 6c1df57e5b8a8ee9ce7e60e276f9745448e75351 | [] | 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 | 35,793 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The order relation on the integers.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.int.basic
import Mathlib.Lean3Lib.init.data.ordering.basic
namespace Mathlib
namespace int
def nonneg (a : ℤ) := int.cases_on a (fun (n : ℕ) => True) fun (n : ℕ) => False
protected def le (a : ℤ) (b : ℤ) := nonneg (b - a)
protected instance has_le : HasLessEq ℤ := { LessEq := int.le }
protected def lt (a : ℤ) (b : ℤ) := a + 1 ≤ b
protected instance has_lt : HasLess ℤ := { Less := int.lt }
def decidable_nonneg (a : ℤ) : Decidable (nonneg a) :=
int.cases_on a (fun (a : ℕ) => decidable.true) fun (a : ℕ) => decidable.false
protected instance decidable_le (a : ℤ) (b : ℤ) : Decidable (a ≤ b) := decidable_nonneg (b - a)
protected instance decidable_lt (a : ℤ) (b : ℤ) : Decidable (a < b) :=
decidable_nonneg (b - (a + 1))
theorem lt_iff_add_one_le (a : ℤ) (b : ℤ) : a < b ↔ a + 1 ≤ b := iff.refl (a < b)
theorem nonneg.elim {a : ℤ} : nonneg a → ∃ (n : ℕ), a = ↑n :=
int.cases_on a (fun (n : ℕ) (H : nonneg (Int.ofNat n)) => exists.intro n rfl)
fun (n' : ℕ) => false.elim
theorem nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) :=
int.cases_on a (fun (n : ℕ) => Or.inl trivial) fun (n : ℕ) => Or.inr trivial
theorem le.intro_sub {a : ℤ} {b : ℤ} {n : ℕ} (h : b - a = ↑n) : a ≤ b :=
(fun (this : nonneg (b - a)) => this)
(eq.mpr (id (Eq._oldrec (Eq.refl (nonneg (b - a))) h)) trivial)
theorem le.intro {a : ℤ} {b : ℤ} {n : ℕ} (h : a + ↑n = b) : a ≤ b := sorry
theorem le.dest_sub {a : ℤ} {b : ℤ} (h : a ≤ b) : ∃ (n : ℕ), b - a = ↑n := nonneg.elim h
theorem le.dest {a : ℤ} {b : ℤ} (h : a ≤ b) : ∃ (n : ℕ), a + ↑n = b := sorry
theorem le.elim {a : ℤ} {b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ (n : ℕ), a + ↑n = b → P) : P :=
exists.elim (le.dest h) h'
protected theorem le_total (a : ℤ) (b : ℤ) : a ≤ b ∨ b ≤ a := sorry
theorem coe_nat_le_coe_nat_of_le {m : ℕ} {n : ℕ} (h : m ≤ n) : ↑m ≤ ↑n := sorry
theorem le_of_coe_nat_le_coe_nat {m : ℕ} {n : ℕ} (h : ↑m ≤ ↑n) : m ≤ n :=
le.elim h
fun (k : ℕ) (hk : ↑m + ↑k = ↑n) =>
(fun (this : m + k = n) => nat.le.intro this)
(int.coe_nat_inj (Eq.trans (int.coe_nat_add m k) hk))
theorem coe_nat_le_coe_nat_iff (m : ℕ) (n : ℕ) : ↑m ≤ ↑n ↔ m ≤ n :=
{ mp := le_of_coe_nat_le_coe_nat, mpr := coe_nat_le_coe_nat_of_le }
theorem coe_zero_le (n : ℕ) : 0 ≤ ↑n := coe_nat_le_coe_nat_of_le (nat.zero_le n)
theorem eq_coe_of_zero_le {a : ℤ} (h : 0 ≤ a) : ∃ (n : ℕ), a = ↑n := sorry
theorem eq_succ_of_zero_lt {a : ℤ} (h : 0 < a) : ∃ (n : ℕ), a = ↑(Nat.succ n) := sorry
theorem lt_add_succ (a : ℤ) (n : ℕ) : a < a + ↑(Nat.succ n) := sorry
theorem lt.intro {a : ℤ} {b : ℤ} {n : ℕ} (h : a + ↑(Nat.succ n) = b) : a < b := h ▸ lt_add_succ a n
theorem lt.dest {a : ℤ} {b : ℤ} (h : a < b) : ∃ (n : ℕ), a + ↑(Nat.succ n) = b := sorry
theorem lt.elim {a : ℤ} {b : ℤ} (h : a < b) {P : Prop} (h' : ∀ (n : ℕ), a + ↑(Nat.succ n) = b → P) :
P :=
exists.elim (lt.dest h) h'
theorem coe_nat_lt_coe_nat_iff (n : ℕ) (m : ℕ) : ↑n < ↑m ↔ n < m := sorry
theorem lt_of_coe_nat_lt_coe_nat {m : ℕ} {n : ℕ} (h : ↑m < ↑n) : m < n :=
iff.mp (coe_nat_lt_coe_nat_iff m n) h
theorem coe_nat_lt_coe_nat_of_lt {m : ℕ} {n : ℕ} (h : m < n) : ↑m < ↑n :=
iff.mpr (coe_nat_lt_coe_nat_iff m n) h
/- show that the integers form an ordered additive group -/
protected theorem le_refl (a : ℤ) : a ≤ a := le.intro (int.add_zero a)
protected theorem le_trans {a : ℤ} {b : ℤ} {c : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c := sorry
protected theorem le_antisymm {a : ℤ} {b : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ a) : a = b := sorry
protected theorem lt_irrefl (a : ℤ) : ¬a < a := sorry
protected theorem ne_of_lt {a : ℤ} {b : ℤ} (h : a < b) : a ≠ b :=
fun (this : a = b) => absurd (eq.mp (Eq._oldrec (Eq.refl (a < b)) this) h) (int.lt_irrefl b)
theorem le_of_lt {a : ℤ} {b : ℤ} (h : a < b) : a ≤ b :=
lt.elim h fun (n : ℕ) (hn : a + ↑(Nat.succ n) = b) => le.intro hn
protected theorem lt_iff_le_and_ne (a : ℤ) (b : ℤ) : a < b ↔ a ≤ b ∧ a ≠ b := sorry
theorem lt_succ (a : ℤ) : a < a + 1 := int.le_refl (a + 1)
protected theorem add_le_add_left {a : ℤ} {b : ℤ} (h : a ≤ b) (c : ℤ) : c + a ≤ c + b := sorry
protected theorem add_lt_add_left {a : ℤ} {b : ℤ} (h : a < b) (c : ℤ) : c + a < c + b := sorry
protected theorem mul_nonneg {a : ℤ} {b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := sorry
protected theorem mul_pos {a : ℤ} {b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b := sorry
protected theorem zero_lt_one : 0 < 1 := trivial
protected theorem lt_iff_le_not_le {a : ℤ} {b : ℤ} : a < b ↔ a ≤ b ∧ ¬b ≤ a := sorry
protected instance linear_order : linear_order ℤ :=
linear_order.mk int.le int.lt int.le_refl int.le_trans int.le_antisymm int.le_total
int.decidable_le int.decidable_eq int.decidable_lt
theorem eq_nat_abs_of_zero_le {a : ℤ} (h : 0 ≤ a) : a = ↑(nat_abs a) := sorry
theorem le_nat_abs {a : ℤ} : a ≤ ↑(nat_abs a) := sorry
theorem neg_succ_lt_zero (n : ℕ) : Int.negSucc n < 0 := sorry
theorem eq_neg_succ_of_lt_zero {a : ℤ} : a < 0 → ∃ (n : ℕ), a = Int.negSucc n := sorry
/- int is an ordered add comm group -/
protected theorem eq_neg_of_eq_neg {a : ℤ} {b : ℤ} (h : a = -b) : b = -a :=
eq.mpr (id (Eq._oldrec (Eq.refl (b = -a)) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (b = --b)) (int.neg_neg b))) (Eq.refl b))
protected theorem neg_add_cancel_left (a : ℤ) (b : ℤ) : -a + (a + b) = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (-a + (a + b) = b)) (Eq.symm (int.add_assoc (-a) a b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (-a + a + b = b)) (int.add_left_neg a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (int.zero_add b))) (Eq.refl b)))
protected theorem add_neg_cancel_left (a : ℤ) (b : ℤ) : a + (-a + b) = b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + (-a + b) = b)) (Eq.symm (int.add_assoc a (-a) b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + -a + b = b)) (int.add_right_neg a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 + b = b)) (int.zero_add b))) (Eq.refl b)))
protected theorem add_neg_cancel_right (a : ℤ) (b : ℤ) : a + b + -b = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + b + -b = a)) (int.add_assoc a b (-b))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + (b + -b) = a)) (int.add_right_neg b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (int.add_zero a))) (Eq.refl a)))
protected theorem neg_add_cancel_right (a : ℤ) (b : ℤ) : a + -b + b = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + -b + b = a)) (int.add_assoc a (-b) b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + (-b + b) = a)) (int.add_left_neg b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (int.add_zero a))) (Eq.refl a)))
protected theorem sub_self (a : ℤ) : a - a = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (a - a = 0)) int.sub_eq_add_neg))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + -a = 0)) (int.add_right_neg a))) (Eq.refl 0))
protected theorem sub_eq_zero_of_eq {a : ℤ} {b : ℤ} (h : a = b) : a - b = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (a - b = 0)) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (b - b = 0)) (int.sub_self b))) (Eq.refl 0))
protected theorem eq_of_sub_eq_zero {a : ℤ} {b : ℤ} (h : a - b = 0) : a = b := sorry
protected theorem sub_eq_zero_iff_eq {a : ℤ} {b : ℤ} : a - b = 0 ↔ a = b :=
{ mp := int.eq_of_sub_eq_zero, mpr := int.sub_eq_zero_of_eq }
@[simp] protected theorem neg_eq_of_add_eq_zero {a : ℤ} {b : ℤ} (h : a + b = 0) : -a = b := sorry
protected theorem neg_mul_eq_neg_mul (a : ℤ) (b : ℤ) : -(a * b) = -a * b := sorry
protected theorem neg_mul_eq_mul_neg (a : ℤ) (b : ℤ) : -(a * b) = a * -b := sorry
@[simp] theorem neg_mul_eq_neg_mul_symm (a : ℤ) (b : ℤ) : -a * b = -(a * b) :=
Eq.symm (int.neg_mul_eq_neg_mul a b)
@[simp] theorem mul_neg_eq_neg_mul_symm (a : ℤ) (b : ℤ) : a * -b = -(a * b) :=
Eq.symm (int.neg_mul_eq_mul_neg a b)
protected theorem neg_mul_neg (a : ℤ) (b : ℤ) : -a * -b = a * b := sorry
protected theorem neg_mul_comm (a : ℤ) (b : ℤ) : -a * b = a * -b := sorry
protected theorem mul_sub (a : ℤ) (b : ℤ) (c : ℤ) : a * (b - c) = a * b - a * c := sorry
protected theorem sub_mul (a : ℤ) (b : ℤ) (c : ℤ) : (a - b) * c = a * c - b * c := sorry
protected theorem le_of_add_le_add_left {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b ≤ a + c) : b ≤ c := sorry
protected theorem lt_of_add_lt_add_left {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b < a + c) : b < c := sorry
protected theorem add_le_add_right {a : ℤ} {b : ℤ} (h : a ≤ b) (c : ℤ) : a + c ≤ b + c :=
int.add_comm c a ▸ int.add_comm c b ▸ int.add_le_add_left h c
protected theorem add_lt_add_right {a : ℤ} {b : ℤ} (h : a < b) (c : ℤ) : a + c < b + c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + c < b + c)) (int.add_comm a c)))
(eq.mpr (id (Eq._oldrec (Eq.refl (c + a < b + c)) (int.add_comm b c)))
(int.add_lt_add_left h c))
protected theorem add_le_add {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a + c ≤ b + d :=
le_trans (int.add_le_add_right h₁ c) (int.add_le_add_left h₂ b)
protected theorem le_add_of_nonneg_right {a : ℤ} {b : ℤ} (h : b ≥ 0) : a ≤ a + b :=
(fun (this : a + b ≥ a + 0) => eq.mp (Eq._oldrec (Eq.refl (a + b ≥ a + 0)) (int.add_zero a)) this)
(int.add_le_add_left h a)
protected theorem le_add_of_nonneg_left {a : ℤ} {b : ℤ} (h : b ≥ 0) : a ≤ b + a :=
(fun (this : 0 + a ≤ b + a) => eq.mp (Eq._oldrec (Eq.refl (0 + a ≤ b + a)) (int.zero_add a)) this)
(int.add_le_add_right h a)
protected theorem add_lt_add {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (h₁ : a < b) (h₂ : c < d) :
a + c < b + d :=
lt_trans (int.add_lt_add_right h₁ c) (int.add_lt_add_left h₂ b)
protected theorem add_lt_add_of_le_of_lt {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (h₁ : a ≤ b) (h₂ : c < d) :
a + c < b + d :=
lt_of_le_of_lt (int.add_le_add_right h₁ c) (int.add_lt_add_left h₂ b)
protected theorem add_lt_add_of_lt_of_le {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (h₁ : a < b) (h₂ : c ≤ d) :
a + c < b + d :=
lt_of_lt_of_le (int.add_lt_add_right h₁ c) (int.add_le_add_left h₂ b)
protected theorem lt_add_of_pos_right (a : ℤ) {b : ℤ} (h : b > 0) : a < a + b :=
(fun (this : a + 0 < a + b) => eq.mp (Eq._oldrec (Eq.refl (a + 0 < a + b)) (int.add_zero a)) this)
(int.add_lt_add_left h a)
protected theorem lt_add_of_pos_left (a : ℤ) {b : ℤ} (h : b > 0) : a < b + a :=
(fun (this : 0 + a < b + a) => eq.mp (Eq._oldrec (Eq.refl (0 + a < b + a)) (int.zero_add a)) this)
(int.add_lt_add_right h a)
protected theorem le_of_add_le_add_right {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b ≤ c + b) : a ≤ c :=
sorry
protected theorem lt_of_add_lt_add_right {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b < c + b) : a < c :=
sorry
-- here we start using properties of zero.
protected theorem add_nonneg {a : ℤ} {b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
int.zero_add 0 ▸ int.add_le_add ha hb
protected theorem add_pos {a : ℤ} {b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
int.zero_add 0 ▸ int.add_lt_add ha hb
protected theorem add_pos_of_pos_of_nonneg {a : ℤ} {b : ℤ} (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b :=
int.zero_add 0 ▸ int.add_lt_add_of_lt_of_le ha hb
protected theorem add_pos_of_nonneg_of_pos {a : ℤ} {b : ℤ} (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b :=
int.zero_add 0 ▸ int.add_lt_add_of_le_of_lt ha hb
protected theorem add_nonpos {a : ℤ} {b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 :=
int.zero_add 0 ▸ int.add_le_add ha hb
protected theorem add_neg {a : ℤ} {b : ℤ} (ha : a < 0) (hb : b < 0) : a + b < 0 :=
int.zero_add 0 ▸ int.add_lt_add ha hb
protected theorem add_neg_of_neg_of_nonpos {a : ℤ} {b : ℤ} (ha : a < 0) (hb : b ≤ 0) : a + b < 0 :=
int.zero_add 0 ▸ int.add_lt_add_of_lt_of_le ha hb
protected theorem add_neg_of_nonpos_of_neg {a : ℤ} {b : ℤ} (ha : a ≤ 0) (hb : b < 0) : a + b < 0 :=
int.zero_add 0 ▸ int.add_lt_add_of_le_of_lt ha hb
protected theorem lt_add_of_le_of_pos {a : ℤ} {b : ℤ} {c : ℤ} (hbc : b ≤ c) (ha : 0 < a) :
b < c + a :=
int.add_zero b ▸ int.add_lt_add_of_le_of_lt hbc ha
protected theorem sub_add_cancel (a : ℤ) (b : ℤ) : a - b + b = a := int.neg_add_cancel_right a b
protected theorem add_sub_cancel (a : ℤ) (b : ℤ) : a + b - b = a := int.add_neg_cancel_right a b
protected theorem add_sub_assoc (a : ℤ) (b : ℤ) (c : ℤ) : a + b - c = a + (b - c) := sorry
protected theorem neg_le_neg {a : ℤ} {b : ℤ} (h : a ≤ b) : -b ≤ -a := sorry
protected theorem le_of_neg_le_neg {a : ℤ} {b : ℤ} (h : -b ≤ -a) : a ≤ b := sorry
protected theorem nonneg_of_neg_nonpos {a : ℤ} (h : -a ≤ 0) : 0 ≤ a :=
(fun (this : -a ≤ -0) => int.le_of_neg_le_neg this)
(eq.mpr (id (Eq._oldrec (Eq.refl (-a ≤ -0)) int.neg_zero)) h)
protected theorem neg_nonpos_of_nonneg {a : ℤ} (h : 0 ≤ a) : -a ≤ 0 :=
(fun (this : -a ≤ -0) => eq.mp (Eq._oldrec (Eq.refl (-a ≤ -0)) int.neg_zero) this)
(int.neg_le_neg h)
protected theorem nonpos_of_neg_nonneg {a : ℤ} (h : 0 ≤ -a) : a ≤ 0 :=
(fun (this : -0 ≤ -a) => int.le_of_neg_le_neg this)
(eq.mpr (id (Eq._oldrec (Eq.refl (-0 ≤ -a)) int.neg_zero)) h)
protected theorem neg_nonneg_of_nonpos {a : ℤ} (h : a ≤ 0) : 0 ≤ -a :=
(fun (this : -0 ≤ -a) => eq.mp (Eq._oldrec (Eq.refl (-0 ≤ -a)) int.neg_zero) this)
(int.neg_le_neg h)
protected theorem neg_lt_neg {a : ℤ} {b : ℤ} (h : a < b) : -b < -a := sorry
protected theorem lt_of_neg_lt_neg {a : ℤ} {b : ℤ} (h : -b < -a) : a < b :=
int.neg_neg a ▸ int.neg_neg b ▸ int.neg_lt_neg h
protected theorem pos_of_neg_neg {a : ℤ} (h : -a < 0) : 0 < a :=
(fun (this : -a < -0) => int.lt_of_neg_lt_neg this)
(eq.mpr (id (Eq._oldrec (Eq.refl (-a < -0)) int.neg_zero)) h)
protected theorem neg_neg_of_pos {a : ℤ} (h : 0 < a) : -a < 0 :=
(fun (this : -a < -0) => eq.mp (Eq._oldrec (Eq.refl (-a < -0)) int.neg_zero) this)
(int.neg_lt_neg h)
protected theorem neg_of_neg_pos {a : ℤ} (h : 0 < -a) : a < 0 :=
(fun (this : -0 < -a) => int.lt_of_neg_lt_neg this)
(eq.mpr (id (Eq._oldrec (Eq.refl (-0 < -a)) int.neg_zero)) h)
protected theorem neg_pos_of_neg {a : ℤ} (h : a < 0) : 0 < -a :=
(fun (this : -0 < -a) => eq.mp (Eq._oldrec (Eq.refl (-0 < -a)) int.neg_zero) this)
(int.neg_lt_neg h)
protected theorem le_neg_of_le_neg {a : ℤ} {b : ℤ} (h : a ≤ -b) : b ≤ -a :=
eq.mp (Eq._oldrec (Eq.refl ( --b ≤ -a)) (int.neg_neg b)) (int.neg_le_neg h)
protected theorem neg_le_of_neg_le {a : ℤ} {b : ℤ} (h : -a ≤ b) : -b ≤ a :=
eq.mp (Eq._oldrec (Eq.refl (-b ≤ --a)) (int.neg_neg a)) (int.neg_le_neg h)
protected theorem lt_neg_of_lt_neg {a : ℤ} {b : ℤ} (h : a < -b) : b < -a :=
eq.mp (Eq._oldrec (Eq.refl ( --b < -a)) (int.neg_neg b)) (int.neg_lt_neg h)
protected theorem neg_lt_of_neg_lt {a : ℤ} {b : ℤ} (h : -a < b) : -b < a :=
eq.mp (Eq._oldrec (Eq.refl (-b < --a)) (int.neg_neg a)) (int.neg_lt_neg h)
protected theorem sub_nonneg_of_le {a : ℤ} {b : ℤ} (h : b ≤ a) : 0 ≤ a - b :=
eq.mp (Eq._oldrec (Eq.refl (b + -b ≤ a + -b)) (int.add_right_neg b)) (int.add_le_add_right h (-b))
protected theorem le_of_sub_nonneg {a : ℤ} {b : ℤ} (h : 0 ≤ a - b) : b ≤ a :=
eq.mp (Eq._oldrec (Eq.refl (0 + b ≤ a)) (int.zero_add b))
(eq.mp (Eq._oldrec (Eq.refl (0 + b ≤ a - b + b)) (int.sub_add_cancel a b))
(int.add_le_add_right h b))
protected theorem sub_nonpos_of_le {a : ℤ} {b : ℤ} (h : a ≤ b) : a - b ≤ 0 :=
eq.mp (Eq._oldrec (Eq.refl (a + -b ≤ b + -b)) (int.add_right_neg b)) (int.add_le_add_right h (-b))
protected theorem le_of_sub_nonpos {a : ℤ} {b : ℤ} (h : a - b ≤ 0) : a ≤ b :=
eq.mp (Eq._oldrec (Eq.refl (a ≤ 0 + b)) (int.zero_add b))
(eq.mp (Eq._oldrec (Eq.refl (a - b + b ≤ 0 + b)) (int.sub_add_cancel a b))
(int.add_le_add_right h b))
protected theorem sub_pos_of_lt {a : ℤ} {b : ℤ} (h : b < a) : 0 < a - b :=
eq.mp (Eq._oldrec (Eq.refl (b + -b < a + -b)) (int.add_right_neg b)) (int.add_lt_add_right h (-b))
protected theorem lt_of_sub_pos {a : ℤ} {b : ℤ} (h : 0 < a - b) : b < a :=
eq.mp (Eq._oldrec (Eq.refl (0 + b < a)) (int.zero_add b))
(eq.mp (Eq._oldrec (Eq.refl (0 + b < a - b + b)) (int.sub_add_cancel a b))
(int.add_lt_add_right h b))
protected theorem sub_neg_of_lt {a : ℤ} {b : ℤ} (h : a < b) : a - b < 0 :=
eq.mp (Eq._oldrec (Eq.refl (a + -b < b + -b)) (int.add_right_neg b)) (int.add_lt_add_right h (-b))
protected theorem lt_of_sub_neg {a : ℤ} {b : ℤ} (h : a - b < 0) : a < b :=
eq.mp (Eq._oldrec (Eq.refl (a < 0 + b)) (int.zero_add b))
(eq.mp (Eq._oldrec (Eq.refl (a - b + b < 0 + b)) (int.sub_add_cancel a b))
(int.add_lt_add_right h b))
protected theorem add_le_of_le_neg_add {a : ℤ} {b : ℤ} {c : ℤ} (h : b ≤ -a + c) : a + b ≤ c :=
eq.mp (Eq._oldrec (Eq.refl (a + b ≤ a + (-a + c))) (int.add_neg_cancel_left a c))
(int.add_le_add_left h a)
protected theorem le_neg_add_of_add_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b ≤ c) : b ≤ -a + c :=
eq.mp (Eq._oldrec (Eq.refl (-a + (a + b) ≤ -a + c)) (int.neg_add_cancel_left a b))
(int.add_le_add_left h (-a))
protected theorem add_le_of_le_sub_left {a : ℤ} {b : ℤ} {c : ℤ} (h : b ≤ c - a) : a + b ≤ c :=
eq.mp (Eq._oldrec (Eq.refl (a + b ≤ c + a - a)) (int.add_sub_cancel c a))
(eq.mp (Eq._oldrec (Eq.refl (a + b ≤ a + c - a)) (int.add_comm a c))
(eq.mp (Eq._oldrec (Eq.refl (a + b ≤ a + (c - a))) (Eq.symm (int.add_sub_assoc a c a)))
(int.add_le_add_left h a)))
protected theorem le_sub_left_of_add_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b ≤ c) : b ≤ c - a :=
eq.mp (Eq._oldrec (Eq.refl (b + a + -a ≤ c + -a)) (int.add_neg_cancel_right b a))
(eq.mp (Eq._oldrec (Eq.refl (a + b + -a ≤ c + -a)) (int.add_comm a b))
(int.add_le_add_right h (-a)))
protected theorem add_le_of_le_sub_right {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ c - b) : a + b ≤ c :=
eq.mp (Eq._oldrec (Eq.refl (a + b ≤ c - b + b)) (int.sub_add_cancel c b))
(int.add_le_add_right h b)
protected theorem le_sub_right_of_add_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b ≤ c) : a ≤ c - b :=
eq.mp (Eq._oldrec (Eq.refl (a + b + -b ≤ c + -b)) (int.add_neg_cancel_right a b))
(int.add_le_add_right h (-b))
protected theorem le_add_of_neg_add_le {a : ℤ} {b : ℤ} {c : ℤ} (h : -b + a ≤ c) : a ≤ b + c :=
eq.mp (Eq._oldrec (Eq.refl (b + (-b + a) ≤ b + c)) (int.add_neg_cancel_left b a))
(int.add_le_add_left h b)
protected theorem neg_add_le_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ b + c) : -b + a ≤ c :=
eq.mp (Eq._oldrec (Eq.refl (-b + a ≤ -b + (b + c))) (int.neg_add_cancel_left b c))
(int.add_le_add_left h (-b))
protected theorem le_add_of_sub_left_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a - b ≤ c) : a ≤ b + c :=
eq.mp (Eq._oldrec (Eq.refl (a ≤ c + b)) (int.add_comm c b))
(eq.mp (Eq._oldrec (Eq.refl (a - b + b ≤ c + b)) (int.sub_add_cancel a b))
(int.add_le_add_right h b))
protected theorem sub_left_le_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ b + c) : a - b ≤ c :=
eq.mp (Eq._oldrec (Eq.refl (a + -b ≤ c + b + -b)) (int.add_neg_cancel_right c b))
(eq.mp (Eq._oldrec (Eq.refl (a + -b ≤ b + c + -b)) (int.add_comm b c))
(int.add_le_add_right h (-b)))
protected theorem le_add_of_sub_right_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a - c ≤ b) : a ≤ b + c :=
eq.mp (Eq._oldrec (Eq.refl (a - c + c ≤ b + c)) (int.sub_add_cancel a c))
(int.add_le_add_right h c)
protected theorem sub_right_le_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ b + c) : a - c ≤ b :=
eq.mp (Eq._oldrec (Eq.refl (a + -c ≤ b + c + -c)) (int.add_neg_cancel_right b c))
(int.add_le_add_right h (-c))
protected theorem le_add_of_neg_add_le_left {a : ℤ} {b : ℤ} {c : ℤ} (h : -b + a ≤ c) : a ≤ b + c :=
int.le_add_of_sub_left_le (eq.mp (Eq._oldrec (Eq.refl (-b + a ≤ c)) (int.add_comm (-b) a)) h)
protected theorem neg_add_le_left_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ b + c) : -b + a ≤ c :=
eq.mpr (id (Eq._oldrec (Eq.refl (-b + a ≤ c)) (int.add_comm (-b) a)))
(int.sub_left_le_of_le_add h)
protected theorem le_add_of_neg_add_le_right {a : ℤ} {b : ℤ} {c : ℤ} (h : -c + a ≤ b) : a ≤ b + c :=
int.le_add_of_sub_right_le (eq.mp (Eq._oldrec (Eq.refl (-c + a ≤ b)) (int.add_comm (-c) a)) h)
protected theorem neg_add_le_right_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a ≤ b + c) : -c + a ≤ b :=
int.neg_add_le_left_of_le_add (eq.mp (Eq._oldrec (Eq.refl (a ≤ b + c)) (int.add_comm b c)) h)
protected theorem le_add_of_neg_le_sub_left {a : ℤ} {b : ℤ} {c : ℤ} (h : -a ≤ b - c) : c ≤ a + b :=
int.le_add_of_neg_add_le_left (int.add_le_of_le_sub_right h)
protected theorem neg_le_sub_left_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : c ≤ a + b) : -a ≤ b - c :=
eq.mp (Eq._oldrec (Eq.refl (-a ≤ -c + b)) (int.add_comm (-c) b))
(int.le_neg_add_of_add_le (int.sub_left_le_of_le_add h))
protected theorem le_add_of_neg_le_sub_right {a : ℤ} {b : ℤ} {c : ℤ} (h : -b ≤ a - c) : c ≤ a + b :=
int.le_add_of_sub_right_le (int.add_le_of_le_sub_left h)
protected theorem neg_le_sub_right_of_le_add {a : ℤ} {b : ℤ} {c : ℤ} (h : c ≤ a + b) : -b ≤ a - c :=
int.le_sub_left_of_add_le (int.sub_right_le_of_le_add h)
protected theorem sub_le_of_sub_le {a : ℤ} {b : ℤ} {c : ℤ} (h : a - b ≤ c) : a - c ≤ b :=
int.sub_left_le_of_le_add (int.le_add_of_sub_right_le h)
protected theorem sub_le_sub_left {a : ℤ} {b : ℤ} (h : a ≤ b) (c : ℤ) : c - b ≤ c - a :=
int.add_le_add_left (int.neg_le_neg h) c
protected theorem sub_le_sub_right {a : ℤ} {b : ℤ} (h : a ≤ b) (c : ℤ) : a - c ≤ b - c :=
int.add_le_add_right h (-c)
protected theorem sub_le_sub {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hab : a ≤ b) (hcd : c ≤ d) :
a - d ≤ b - c :=
int.add_le_add hab (int.neg_le_neg hcd)
protected theorem add_lt_of_lt_neg_add {a : ℤ} {b : ℤ} {c : ℤ} (h : b < -a + c) : a + b < c :=
eq.mp (Eq._oldrec (Eq.refl (a + b < a + (-a + c))) (int.add_neg_cancel_left a c))
(int.add_lt_add_left h a)
protected theorem lt_neg_add_of_add_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b < c) : b < -a + c :=
eq.mp (Eq._oldrec (Eq.refl (-a + (a + b) < -a + c)) (int.neg_add_cancel_left a b))
(int.add_lt_add_left h (-a))
protected theorem add_lt_of_lt_sub_left {a : ℤ} {b : ℤ} {c : ℤ} (h : b < c - a) : a + b < c :=
eq.mp (Eq._oldrec (Eq.refl (a + b < c + a - a)) (int.add_sub_cancel c a))
(eq.mp (Eq._oldrec (Eq.refl (a + b < a + c - a)) (int.add_comm a c))
(eq.mp (Eq._oldrec (Eq.refl (a + b < a + (c - a))) (Eq.symm (int.add_sub_assoc a c a)))
(int.add_lt_add_left h a)))
protected theorem lt_sub_left_of_add_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b < c) : b < c - a :=
eq.mp (Eq._oldrec (Eq.refl (b + a + -a < c + -a)) (int.add_neg_cancel_right b a))
(eq.mp (Eq._oldrec (Eq.refl (a + b + -a < c + -a)) (int.add_comm a b))
(int.add_lt_add_right h (-a)))
protected theorem add_lt_of_lt_sub_right {a : ℤ} {b : ℤ} {c : ℤ} (h : a < c - b) : a + b < c :=
eq.mp (Eq._oldrec (Eq.refl (a + b < c - b + b)) (int.sub_add_cancel c b))
(int.add_lt_add_right h b)
protected theorem lt_sub_right_of_add_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a + b < c) : a < c - b :=
eq.mp (Eq._oldrec (Eq.refl (a + b + -b < c + -b)) (int.add_neg_cancel_right a b))
(int.add_lt_add_right h (-b))
protected theorem lt_add_of_neg_add_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : -b + a < c) : a < b + c :=
eq.mp (Eq._oldrec (Eq.refl (b + (-b + a) < b + c)) (int.add_neg_cancel_left b a))
(int.add_lt_add_left h b)
protected theorem neg_add_lt_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a < b + c) : -b + a < c :=
eq.mp (Eq._oldrec (Eq.refl (-b + a < -b + (b + c))) (int.neg_add_cancel_left b c))
(int.add_lt_add_left h (-b))
protected theorem lt_add_of_sub_left_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a - b < c) : a < b + c :=
eq.mp (Eq._oldrec (Eq.refl (a < c + b)) (int.add_comm c b))
(eq.mp (Eq._oldrec (Eq.refl (a - b + b < c + b)) (int.sub_add_cancel a b))
(int.add_lt_add_right h b))
protected theorem sub_left_lt_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a < b + c) : a - b < c :=
eq.mp (Eq._oldrec (Eq.refl (a + -b < c + b + -b)) (int.add_neg_cancel_right c b))
(eq.mp (Eq._oldrec (Eq.refl (a + -b < b + c + -b)) (int.add_comm b c))
(int.add_lt_add_right h (-b)))
protected theorem lt_add_of_sub_right_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a - c < b) : a < b + c :=
eq.mp (Eq._oldrec (Eq.refl (a - c + c < b + c)) (int.sub_add_cancel a c))
(int.add_lt_add_right h c)
protected theorem sub_right_lt_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a < b + c) : a - c < b :=
eq.mp (Eq._oldrec (Eq.refl (a + -c < b + c + -c)) (int.add_neg_cancel_right b c))
(int.add_lt_add_right h (-c))
protected theorem lt_add_of_neg_add_lt_left {a : ℤ} {b : ℤ} {c : ℤ} (h : -b + a < c) : a < b + c :=
int.lt_add_of_sub_left_lt (eq.mp (Eq._oldrec (Eq.refl (-b + a < c)) (int.add_comm (-b) a)) h)
protected theorem neg_add_lt_left_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a < b + c) : -b + a < c :=
eq.mpr (id (Eq._oldrec (Eq.refl (-b + a < c)) (int.add_comm (-b) a)))
(int.sub_left_lt_of_lt_add h)
protected theorem lt_add_of_neg_add_lt_right {a : ℤ} {b : ℤ} {c : ℤ} (h : -c + a < b) : a < b + c :=
int.lt_add_of_sub_right_lt (eq.mp (Eq._oldrec (Eq.refl (-c + a < b)) (int.add_comm (-c) a)) h)
protected theorem neg_add_lt_right_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : a < b + c) : -c + a < b :=
int.neg_add_lt_left_of_lt_add (eq.mp (Eq._oldrec (Eq.refl (a < b + c)) (int.add_comm b c)) h)
protected theorem lt_add_of_neg_lt_sub_left {a : ℤ} {b : ℤ} {c : ℤ} (h : -a < b - c) : c < a + b :=
int.lt_add_of_neg_add_lt_left (int.add_lt_of_lt_sub_right h)
protected theorem neg_lt_sub_left_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : c < a + b) : -a < b - c :=
eq.mp (Eq._oldrec (Eq.refl (-a < -c + b)) (int.add_comm (-c) b))
(int.lt_neg_add_of_add_lt (int.sub_left_lt_of_lt_add h))
protected theorem lt_add_of_neg_lt_sub_right {a : ℤ} {b : ℤ} {c : ℤ} (h : -b < a - c) : c < a + b :=
int.lt_add_of_sub_right_lt (int.add_lt_of_lt_sub_left h)
protected theorem neg_lt_sub_right_of_lt_add {a : ℤ} {b : ℤ} {c : ℤ} (h : c < a + b) : -b < a - c :=
int.lt_sub_left_of_add_lt (int.sub_right_lt_of_lt_add h)
protected theorem sub_lt_of_sub_lt {a : ℤ} {b : ℤ} {c : ℤ} (h : a - b < c) : a - c < b :=
int.sub_left_lt_of_lt_add (int.lt_add_of_sub_right_lt h)
protected theorem sub_lt_sub_left {a : ℤ} {b : ℤ} (h : a < b) (c : ℤ) : c - b < c - a :=
int.add_lt_add_left (int.neg_lt_neg h) c
protected theorem sub_lt_sub_right {a : ℤ} {b : ℤ} (h : a < b) (c : ℤ) : a - c < b - c :=
int.add_lt_add_right h (-c)
protected theorem sub_lt_sub {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hab : a < b) (hcd : c < d) :
a - d < b - c :=
int.add_lt_add hab (int.neg_lt_neg hcd)
protected theorem sub_lt_sub_of_le_of_lt {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hab : a ≤ b)
(hcd : c < d) : a - d < b - c :=
int.add_lt_add_of_le_of_lt hab (int.neg_lt_neg hcd)
protected theorem sub_lt_sub_of_lt_of_le {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hab : a < b)
(hcd : c ≤ d) : a - d < b - c :=
int.add_lt_add_of_lt_of_le hab (int.neg_le_neg hcd)
protected theorem sub_le_self (a : ℤ) {b : ℤ} (h : b ≥ 0) : a - b ≤ a :=
trans_rel_left LessEq
(trans_rel_right LessEq rfl (int.add_le_add_left (int.neg_nonpos_of_nonneg h) a))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (int.add_zero a))) (Eq.refl a))
protected theorem sub_lt_self (a : ℤ) {b : ℤ} (h : b > 0) : a - b < a :=
trans_rel_left Less (trans_rel_right Less rfl (int.add_lt_add_left (int.neg_neg_of_pos h) a))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + 0 = a)) (int.add_zero a))) (Eq.refl a))
protected theorem add_le_add_three {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} {e : ℤ} {f : ℤ} (h₁ : a ≤ d)
(h₂ : b ≤ e) (h₃ : c ≤ f) : a + b + c ≤ d + e + f :=
le_trans (int.add_le_add (int.add_le_add h₁ h₂) h₃) (le_refl (d + e + f))
/- missing facts -/
protected theorem mul_lt_mul_of_pos_left {a : ℤ} {b : ℤ} {c : ℤ} (h₁ : a < b) (h₂ : 0 < c) :
c * a < c * b :=
sorry
protected theorem mul_lt_mul_of_pos_right {a : ℤ} {b : ℤ} {c : ℤ} (h₁ : a < b) (h₂ : 0 < c) :
a * c < b * c :=
sorry
protected theorem mul_le_mul_of_nonneg_left {a : ℤ} {b : ℤ} {c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) :
c * a ≤ c * b :=
sorry
protected theorem mul_le_mul_of_nonneg_right {a : ℤ} {b : ℤ} {c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) :
a * c ≤ b * c :=
sorry
-- TODO: there are four variations, depending on which variables we assume to be nonneg
protected theorem mul_le_mul {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hac : a ≤ c) (hbd : b ≤ d)
(nn_b : 0 ≤ b) (nn_c : 0 ≤ c) : a * b ≤ c * d :=
le_trans (int.mul_le_mul_of_nonneg_right hac nn_b) (int.mul_le_mul_of_nonneg_left hbd nn_c)
protected theorem mul_nonpos_of_nonneg_of_nonpos {a : ℤ} {b : ℤ} (ha : a ≥ 0) (hb : b ≤ 0) :
a * b ≤ 0 :=
(fun (h : a * b ≤ a * 0) => eq.mp (Eq._oldrec (Eq.refl (a * b ≤ a * 0)) (int.mul_zero a)) h)
(int.mul_le_mul_of_nonneg_left hb ha)
protected theorem mul_nonpos_of_nonpos_of_nonneg {a : ℤ} {b : ℤ} (ha : a ≤ 0) (hb : b ≥ 0) :
a * b ≤ 0 :=
(fun (h : a * b ≤ 0 * b) => eq.mp (Eq._oldrec (Eq.refl (a * b ≤ 0 * b)) (int.zero_mul b)) h)
(int.mul_le_mul_of_nonneg_right ha hb)
protected theorem mul_lt_mul {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (hac : a < c) (hbd : b ≤ d)
(pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d :=
lt_of_lt_of_le (int.mul_lt_mul_of_pos_right hac pos_b) (int.mul_le_mul_of_nonneg_left hbd nn_c)
protected theorem mul_lt_mul' {a : ℤ} {b : ℤ} {c : ℤ} {d : ℤ} (h1 : a ≤ c) (h2 : b < d) (h3 : b ≥ 0)
(h4 : c > 0) : a * b < c * d :=
lt_of_le_of_lt (int.mul_le_mul_of_nonneg_right h1 h3) (int.mul_lt_mul_of_pos_left h2 h4)
protected theorem mul_neg_of_pos_of_neg {a : ℤ} {b : ℤ} (ha : a > 0) (hb : b < 0) : a * b < 0 :=
(fun (h : a * b < a * 0) => eq.mp (Eq._oldrec (Eq.refl (a * b < a * 0)) (int.mul_zero a)) h)
(int.mul_lt_mul_of_pos_left hb ha)
protected theorem mul_neg_of_neg_of_pos {a : ℤ} {b : ℤ} (ha : a < 0) (hb : b > 0) : a * b < 0 :=
(fun (h : a * b < 0 * b) => eq.mp (Eq._oldrec (Eq.refl (a * b < 0 * b)) (int.zero_mul b)) h)
(int.mul_lt_mul_of_pos_right ha hb)
protected theorem mul_le_mul_of_nonpos_right {a : ℤ} {b : ℤ} {c : ℤ} (h : b ≤ a) (hc : c ≤ 0) :
a * c ≤ b * c :=
sorry
protected theorem mul_nonneg_of_nonpos_of_nonpos {a : ℤ} {b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) :
0 ≤ a * b :=
(fun (this : 0 * b ≤ a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b ≤ a * b)) (int.zero_mul b)) this)
(int.mul_le_mul_of_nonpos_right ha hb)
protected theorem mul_lt_mul_of_neg_left {a : ℤ} {b : ℤ} {c : ℤ} (h : b < a) (hc : c < 0) :
c * a < c * b :=
sorry
protected theorem mul_lt_mul_of_neg_right {a : ℤ} {b : ℤ} {c : ℤ} (h : b < a) (hc : c < 0) :
a * c < b * c :=
sorry
protected theorem mul_pos_of_neg_of_neg {a : ℤ} {b : ℤ} (ha : a < 0) (hb : b < 0) : 0 < a * b :=
(fun (this : 0 * b < a * b) => eq.mp (Eq._oldrec (Eq.refl (0 * b < a * b)) (int.zero_mul b)) this)
(int.mul_lt_mul_of_neg_right ha hb)
protected theorem mul_self_le_mul_self {a : ℤ} {b : ℤ} (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b :=
int.mul_le_mul h2 h2 h1 (le_trans h1 h2)
protected theorem mul_self_lt_mul_self {a : ℤ} {b : ℤ} (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2)
/- more facts specific to int -/
theorem of_nat_nonneg (n : ℕ) : 0 ≤ Int.ofNat n := trivial
theorem coe_succ_pos (n : ℕ) : ↑(Nat.succ n) > 0 := coe_nat_lt_coe_nat_of_lt (nat.succ_pos n)
theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃ (n : ℕ), a = -↑n := sorry
theorem nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : ↑(nat_abs a) = a := sorry
theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : ↑(nat_abs a) = -a :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑(nat_abs a) = -a)) (Eq.symm (nat_abs_neg a))))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (↑(nat_abs (-a)) = -a))
(nat_abs_of_nonneg (int.neg_nonneg_of_nonpos H))))
(Eq.refl (-a)))
theorem lt_of_add_one_le {a : ℤ} {b : ℤ} (H : a + 1 ≤ b) : a < b := H
theorem add_one_le_of_lt {a : ℤ} {b : ℤ} (H : a < b) : a + 1 ≤ b := H
theorem lt_add_one_of_le {a : ℤ} {b : ℤ} (H : a ≤ b) : a < b + 1 := int.add_le_add_right H 1
theorem le_of_lt_add_one {a : ℤ} {b : ℤ} (H : a < b + 1) : a ≤ b := int.le_of_add_le_add_right H
theorem sub_one_le_of_lt {a : ℤ} {b : ℤ} (H : a ≤ b) : a - 1 < b :=
int.sub_right_lt_of_lt_add (lt_add_one_of_le H)
theorem lt_of_sub_one_le {a : ℤ} {b : ℤ} (H : a - 1 < b) : a ≤ b :=
le_of_lt_add_one (int.lt_add_of_sub_right_lt H)
theorem le_sub_one_of_lt {a : ℤ} {b : ℤ} (H : a < b) : a ≤ b - 1 := int.le_sub_right_of_add_le H
theorem lt_of_le_sub_one {a : ℤ} {b : ℤ} (H : a ≤ b - 1) : a < b := int.add_le_of_le_sub_right H
theorem sign_of_succ (n : ℕ) : sign ↑(Nat.succ n) = 1 := rfl
theorem sign_eq_one_of_pos {a : ℤ} (h : 0 < a) : sign a = 1 := sorry
theorem sign_eq_neg_one_of_neg {a : ℤ} (h : a < 0) : sign a = -1 := sorry
theorem eq_zero_of_sign_eq_zero {a : ℤ} : sign a = 0 → a = 0 := sorry
theorem pos_of_sign_eq_one {a : ℤ} : sign a = 1 → 0 < a := sorry
theorem neg_of_sign_eq_neg_one {a : ℤ} : sign a = -1 → a < 0 := sorry
theorem sign_eq_one_iff_pos (a : ℤ) : sign a = 1 ↔ 0 < a :=
{ mp := pos_of_sign_eq_one, mpr := sign_eq_one_of_pos }
theorem sign_eq_neg_one_iff_neg (a : ℤ) : sign a = -1 ↔ a < 0 :=
{ mp := neg_of_sign_eq_neg_one, mpr := sign_eq_neg_one_of_neg }
theorem sign_eq_zero_iff_zero (a : ℤ) : sign a = 0 ↔ a = 0 := sorry
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {a : ℤ} {b : ℤ} (h : a * b = 0) :
a = 0 ∨ b = 0 :=
sorry
protected theorem eq_of_mul_eq_mul_right {a : ℤ} {b : ℤ} {c : ℤ} (ha : a ≠ 0) (h : b * a = c * a) :
b = c :=
sorry
protected theorem eq_of_mul_eq_mul_left {a : ℤ} {b : ℤ} {c : ℤ} (ha : a ≠ 0) (h : a * b = a * c) :
b = c :=
sorry
theorem eq_one_of_mul_eq_self_left {a : ℤ} {b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 :=
int.eq_of_mul_eq_mul_right Hpos
(eq.mpr (id (Eq._oldrec (Eq.refl (b * a = 1 * a)) (int.one_mul a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (b * a = a)) H)) (Eq.refl a)))
theorem eq_one_of_mul_eq_self_right {a : ℤ} {b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 :=
int.eq_of_mul_eq_mul_left Hpos
(eq.mpr (id (Eq._oldrec (Eq.refl (b * a = b * 1)) (int.mul_one b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (b * a = b)) H)) (Eq.refl b)))
end Mathlib |
99a2b4a4621ead32503f08ff69a75d3df80f4574 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/tactic/squeeze.lean | 12b05b94eb7e44f2c463be32e67659186ae5de76 | [
"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 | 12,110 | lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
-/
import category.traversable.basic
import tactic.simpa
open interactive interactive.types lean.parser
private meta def loc.to_string_aux : option name → string
| none := "⊢"
| (some x) := to_string x
/-- pretty print a `loc` -/
meta def loc.to_string : loc → string
| (loc.ns []) := ""
| (loc.ns [none]) := ""
| (loc.ns ls) := string.join $ list.intersperse " " (" at" :: ls.map loc.to_string_aux)
| loc.wildcard := " at *"
/-- shift `pos` `n` columns to the left -/
meta def pos.move_left (p : pos) (n : ℕ) : pos :=
{ line := p.line, column := p.column - n }
namespace tactic
/--
`erase_simp_args hs s` removes from `s` each name `n` such that `const n` is an element of `hs`
-/
meta def erase_simp_args (hs : list simp_arg_type) (s : name_set) : tactic name_set :=
do
-- TODO: when Lean 3.4 support is dropped, use `decode_simp_arg_list_with_symm` on the next line:
(hs, _, _) ← decode_simp_arg_list hs,
pure $ hs.foldr (λ (h : pexpr) (s : name_set),
match h.get_app_fn h with
| (expr.const n _) := s.erase n
| _ := s
end) s
open list
/-- parse structure instance of the shape `{ field1 := value1, .. , field2 := value2 }` -/
meta def struct_inst : lean.parser pexpr :=
do tk "{",
ls ← sep_by (skip_info (tk ","))
( sum.inl <$> (tk ".." *> texpr) <|>
sum.inr <$> (prod.mk <$> ident <* tk ":=" <*> texpr)),
tk "}",
let (srcs,fields) := partition_map id ls,
let (names,values) := unzip fields,
pure $ pexpr.mk_structure_instance
{ field_names := names,
field_values := values,
sources := srcs }
/-- pretty print structure instance -/
meta def struct.to_tactic_format (e : pexpr) : tactic format :=
do r ← e.get_structure_instance_info,
fs ← mzip_with (λ n v,
do v ← to_expr v >>= pp,
pure $ format!"{n} := {v}" )
r.field_names r.field_values,
let ss := r.sources.map (λ s, format!" .. {s}"),
let x : format := format.join $ list.intersperse ", " (fs ++ ss),
pure format!" {{{x}}"
/-- Attribute containing a table that accumulates multiple `squeeze_simp` suggestions -/
@[user_attribute]
private meta def squeeze_loc_attr : user_attribute unit (option (list (pos × string × list simp_arg_type × string))) :=
{ name := `_squeeze_loc,
parser := fail "this attribute should not be used",
descr := "table to accumulate multiple `squeeze_simp` suggestions" }
/-- dummy declaration used as target of `squeeze_loc` attribute -/
def squeeze_loc_attr_carrier := ()
run_cmd squeeze_loc_attr.set ``squeeze_loc_attr_carrier none tt
/-- Emit a suggestion to the user. If inside a `squeeze_scope` block,
the suggestions emitted through `mk_suggestion` will be aggregated so that
every tactic that makes a suggestion can consider multiple execution of the
same invocation. -/
meta def mk_suggestion (p : pos) (pre post : string) (args : list simp_arg_type) : tactic unit :=
do xs ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier,
match xs with
| none := do
args ← to_line_wrap_format <$> args.mmap pp,
@scope_trace _ p.line p.column $ λ _, _root_.trace sformat!"{pre}{args}{post}" (pure () : tactic unit)
| some xs := do
squeeze_loc_attr.set ``squeeze_loc_attr_carrier ((p,pre,args,post) :: xs) ff
end
local postfix `?`:9001 := optional
/-- translate a `pexpr` into a `simp` configuration -/
meta def parse_config : option pexpr → tactic (simp_config_ext × format)
| none := pure ({}, "")
| (some cfg) :=
do e ← to_expr ``(%%cfg : simp_config_ext),
fmt ← has_to_tactic_format.to_tactic_format cfg,
prod.mk <$> eval_expr simp_config_ext e
<*> struct.to_tactic_format cfg
/-- `same_result proof tac` runs tactic `tac` and checks if the proof
produced by `tac` is equivalent to `proof`. -/
meta def same_result (pr : proof_state) (tac : tactic unit) : tactic bool :=
do s ← get_proof_state_after tac,
pure $ some pr = s
private meta def filter_simp_set_aux
(tac : bool → list simp_arg_type → tactic unit)
(args : list simp_arg_type) (pr : proof_state) :
list simp_arg_type → list simp_arg_type →
list simp_arg_type → tactic (list simp_arg_type × list simp_arg_type)
| [] ys ds := pure (ys.reverse, ds.reverse)
| (x :: xs) ys ds :=
do b ← same_result pr (tac tt (args ++ xs ++ ys)),
if b
then filter_simp_set_aux xs ys (x:: ds)
else filter_simp_set_aux xs (x :: ys) ds
declare_trace squeeze.deleted
/--
`filter_simp_set g call_simp user_args simp_args` returns `args'` such that, when calling
`call_simp tt /- only -/ args'` on the goal `g` (`g` is a meta var) we end up in the same
state as if we had called `call_simp ff (user_args ++ simp_args)` and removing any one
element of `args'` changes the resulting proof.
-/
meta def filter_simp_set
(tac : bool → list simp_arg_type → tactic unit)
(user_args simp_args : list simp_arg_type) : tactic (list simp_arg_type) :=
do some s ← get_proof_state_after (tac ff (user_args ++ simp_args)),
(simp_args', _) ← filter_simp_set_aux tac user_args s simp_args [] [],
(user_args', ds) ← filter_simp_set_aux tac simp_args' s user_args [] [],
when (is_trace_enabled_for `squeeze.deleted = tt ∧ ¬ ds.empty)
trace!"deleting provided arguments {ds}",
pure (user_args' ++ simp_args')
/-- make a `simp_arg_type` that references the name given as an argument -/
meta def name.to_simp_args (n : name) : tactic simp_arg_type :=
do e ← resolve_name' n, pure $ simp_arg_type.expr e
/-- tactic combinator to create a `simp`-like tactic that minimizes its
argument list.
* `no_dflt`: did the user use the `only` keyword?
* `args`: list of `simp` arguments
* `tac`: how to invoke the underlying `simp` tactic
-/
meta def squeeze_simp_core
(no_dflt : bool) (args : list simp_arg_type)
(tac : Π (no_dflt : bool) (args : list simp_arg_type), tactic unit)
(mk_suggestion : list simp_arg_type → tactic unit) : tactic unit :=
do v ← target >>= mk_meta_var,
g ← retrieve $ do
{ g ← main_goal,
tac no_dflt args,
instantiate_mvars g },
let vs := g.list_constant,
vs ← vs.mfilter is_simp_lemma,
vs ← vs.mmap strip_prefix,
vs ← erase_simp_args args vs,
vs ← vs.to_list.mmap name.to_simp_args,
with_local_goals' [v] (filter_simp_set tac args vs)
>>= mk_suggestion,
tac no_dflt args
namespace interactive
attribute [derive decidable_eq] simp_arg_type
/-- combinator meant to aggregate the suggestions issued by multiple calls
of `squeeze_simp` (due, for instance, to `;`).
Can be used as:
```lean
example {α β} (xs ys : list α) (f : α → β) :
(xs ++ ys.tail).map f = xs.map f ∧ (xs.tail.map f).length = xs.length :=
begin
have : xs = ys, admit,
squeeze_scope
{ split; squeeze_simp, -- `squeeze_simp` is run twice, the first one requires
-- `list.map_append` and the second one `[list.length_map, list.length_tail]`
-- prints only one message and combine the suggestions:
-- > Try this: simp only [list.length_map, list.length_tail, list.map_append]
squeeze_simp [this] -- `squeeze_simp` is run only once
-- prints:
-- > Try this: simp only [this]
},
end
```
-/
meta def squeeze_scope (tac : itactic) : tactic unit :=
do none ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier | pure (),
squeeze_loc_attr.set ``squeeze_loc_attr_carrier (some []) ff,
finally tac $ do
some xs ← squeeze_loc_attr.get_param ``squeeze_loc_attr_carrier | fail "invalid state",
let m := native.rb_lmap.of_list xs,
squeeze_loc_attr.set ``squeeze_loc_attr_carrier none ff,
m.to_list.reverse.mmap' $ λ ⟨p,suggs⟩, do
{ let ⟨pre,_,post⟩ := suggs.head,
let suggs : list (list simp_arg_type) := suggs.map $ prod.fst ∘ prod.snd,
mk_suggestion p pre post (suggs.foldl list.union []), pure () }
/--
`squeeze_simp` and `squeeze_simpa` perform the same task with
the difference that `squeeze_simp` relates to `simp` while
`squeeze_simpa` relates to `simpa`. The following applies to both
`squeeze_simp` and `squeeze_simpa`.
`squeeze_simp` behaves like `simp` (including all its arguments)
and prints a `simp only` invokation to skip the search through the
`simp` lemma list.
For instance, the following is easily solved with `simp`:
```lean
example : 0 + 1 = 1 + 0 := by simp
```
To guide the proof search and speed it up, we may replace `simp`
with `squeeze_simp`:
```lean
example : 0 + 1 = 1 + 0 := by squeeze_simp
-- prints:
-- Try this: simp only [add_zero, eq_self_iff_true, zero_add]
```
`squeeze_simp` suggests a replacement which we can use instead of
`squeeze_simp`.
```lean
example : 0 + 1 = 1 + 0 := by simp only [add_zero, eq_self_iff_true, zero_add]
```
`squeeze_simp only` prints nothing as it already skips the `simp` list.
This tactic is useful for speeding up the compilation of a complete file.
Steps:
1. search and replace ` simp` with ` squeeze_simp` (the space helps avoid the
replacement of `simp` in `@[simp]`) throughout the file.
2. Starting at the beginning of the file, go to each printout in turn, copy
the suggestion in place of `squeeze_simp`.
3. after all the suggestions were applied, search and replace `squeeze_simp` with
`simp` to remove the occurrences of `squeeze_simp` that did not produce a suggestion.
Known limitation(s):
* in cases where `squeeze_simp` is used after a `;` (e.g. `cases x; squeeze_simp`),
`squeeze_simp` will produce as many suggestions as the number of goals it is applied to.
It is likely that none of the suggestion is a good replacement but they can all be
combined by concatenating their list of lemmas. `squeeze_scope` can be used to
combine the suggestions: `by squeeze_scope { cases x; squeeze_simp }`
-/
meta def squeeze_simp
(key : parse cur_pos)
(use_iota_eqn : parse (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list)
(attr_names : parse with_ident_list) (locat : parse location)
(cfg : parse struct_inst?) : tactic unit :=
do (cfg',c) ← parse_config cfg,
squeeze_simp_core no_dflt hs
(λ l_no_dft l_args, simp use_iota_eqn l_no_dft l_args attr_names locat cfg')
(λ args,
let use_iota_eqn := if use_iota_eqn.is_some then "!" else "",
attrs := if attr_names.empty then "" else string.join (list.intersperse " " (" with" :: attr_names.map to_string)),
loc := loc.to_string locat in
mk_suggestion (key.move_left 1)
sformat!"Try this: simp{use_iota_eqn} only "
sformat!"{attrs}{loc}{c}" args)
/-- see `squeeze_simp` -/
meta def squeeze_simpa
(key : parse cur_pos)
(use_iota_eqn : parse (tk "!")?) (no_dflt : parse only_flag) (hs : parse simp_arg_list)
(attr_names : parse with_ident_list) (tgt : parse (tk "using" *> texpr)?)
(cfg : parse struct_inst?) : tactic unit :=
do (cfg',c) ← parse_config cfg,
tgt' ← traverse (λ t, do t ← to_expr t >>= pp,
pure format!" using {t}") tgt,
squeeze_simp_core no_dflt hs
(λ l_no_dft l_args, simpa use_iota_eqn l_no_dft l_args attr_names tgt cfg')
(λ args,
let use_iota_eqn := if use_iota_eqn.is_some then "!" else "",
attrs := if attr_names.empty then "" else string.join (list.intersperse " " (" with" :: attr_names.map to_string)),
tgt' := tgt'.get_or_else "" in
mk_suggestion (key.move_left 1)
sformat!"Try this: simpa{use_iota_eqn} only "
sformat!"{attrs}{tgt'}{c}" args)
end interactive
end tactic
open tactic.interactive
add_tactic_doc
{ name := "squeeze_simp / squeeze_simpa / squeeze_scope",
category := doc_category.tactic,
decl_names :=
[``squeeze_simp,
``squeeze_simpa,
``squeeze_scope],
tags := ["simplification", "Try this"],
inherit_description_from := ``squeeze_simp }
|
dc6592d08489b0dcf320d8c0cc9d2649af79c9ba | 29cc89d6158dd3b90acbdbcab4d2c7eb9a7dbf0f | /3.3/33_exercise_sheet.lean | 9ff136ee17c842bfc2e9514807df38aa52c90c00 | [] | 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 | 7,209 | lean | /- Exercise 3.3: Programming Semantics — Denotational Semantics -/
/- First we repeat some material from the lecture. -/
import .x33_library
set_option pp.beta true
class complete_lattice (α : Type) extends partial_order α :=
(Inf : set α → α)
(Inf_le : ∀{s a}, a ∈ s → Inf s ≤ a)
(le_Inf : ∀{s a}, (∀a', a' ∈ s → a ≤ a') → a ≤ Inf s)
namespace set
lemma ext {α : Type} {s t : set α} (h : ∀a, a ∈ s ↔ a ∈ t) : s = t :=
by funext a; exact propext (h a)
instance (α : Type) : complete_lattice (set α) :=
{ le := (⊆),
le_refl := assume s a, id,
le_trans := assume s t u hst htu a has, htu $ hst $ has,
le_antisymm := assume s t hst hts, ext $ assume a, ⟨assume h, hst h, assume h, hts h⟩,
Inf := assume f, {a | ∀s, s ∈ f → a ∈ s},
Inf_le := assume f s hsf a h, h _ hsf,
le_Inf := assume f s h a has t htf, h t htf has }
end set
def monotone {α β} [partial_order α] [partial_order β] (f : α → β) :=
∀a₁ a₂, a₁ ≤ a₂ → f a₁ ≤ f a₂
namespace monotone
lemma id {α : Type} [partial_order α] : monotone (λa : α, a) :=
assume a₁ a₂ ha, ha
lemma const {α β : Type} [partial_order α] [partial_order β] (b : β) : monotone (λa : α, b) :=
assume a₁ a₂ ha, le_refl b
lemma union {α β : Type} [partial_order α] (f g : α → set β)
(hf : monotone f) (hg : monotone g) : monotone (λa, f a ∪ g a) :=
begin
intros a b asmalb,
intros bs fg,
cases fg,
apply or.intro_left,
apply hf a,
repeat{assumption},
apply or.intro_right,
apply hg a,
repeat{assumption}
end
end monotone
namespace complete_lattice
variables {α : Type} [complete_lattice α]
def lfp (f : α → α) : α := Inf {x | f x ≤ x}
lemma lfp_le (f : α → α) (a : α) (h : f a ≤ a) : lfp f ≤ a := sorry
lemma le_lfp (f : α → α) (a : α) (h : ∀a', f a' ≤ a' → a ≤ a') : a ≤ lfp f := sorry
lemma lfp_eq (f : α → α) (hf : monotone f) : lfp f = f (lfp f) := sorry
end complete_lattice
open complete_lattice
def Id (α : Type) : set (α × α) := {x | x.2 = x.1 }
@[simp] lemma mem_Id {α : Type} (a b : α) :
(a, b) ∈ Id α ↔ b = a :=
iff.rfl
def comp {α : Type} (r₁ r₂ : set (α × α)) : set (α × α) :=
{ x | ∃m, (x.1, m) ∈ r₁ ∧ (m, x.2) ∈ r₂ }
infixl ` ◯ ` : 90 := comp
@[simp] lemma mem_comp {α : Type} (r₁ r₂ : set (α × α)) (a b : α) :
(a, b) ∈ r₁ ◯ r₂ ↔ (∃c, (a, c) ∈ r₁ ∧ (c, b) ∈ r₂) :=
iff.rfl
def restrict {α : Type} (r : set (α × α)) (p : α → Prop) : set (α × α) :=
{ x | p x.1 ∧ x ∈ r }
infixl ` ⇃ ` : 90 := restrict
@[simp] lemma mem_restrict {α : Type} (r : set (α × α)) (p : α → Prop) (a b : α) :
(a, b) ∈ r ⇃ p ↔ p a ∧ (a, b) ∈ r :=
by refl
/- Question 1: Monotonicity -/
/- Prove the following two lemmas from the lecture. -/
lemma monotone_comp {α β : Type} [partial_order α] (f g : α → set (β × β))
(hf : monotone f) (hg : monotone g) : monotone (λa, f a ◯ g a) :=
begin
intros a b asmalb h hp,
cases hp,
cases hp_h,
simp[comp],
apply exists.intro hp_w,
apply and.intro,
apply hf a,
repeat{assumption},
apply hg a,
repeat{assumption}
end
lemma monotone_restrict {α β : Type} [partial_order α] (f : α → set (β × β)) (p : β → Prop)
(hf : monotone f) : monotone (λa, f a ⇃ p) :=
begin
intros a b asmalb h hp,
simp[restrict],
apply and.intro,
cases hp,
assumption,
cases hp,
apply hf a,
repeat{assumption}
end
/- Question 2: Kleene's theorem -/
/- We can compute the fixpoint by iteration by taking the union of all finite iterations of `f`:
lfp f = ⋃n, f^^[n] ∅
where
f^^[n] = f ∘ ⋯ ∘ f ∘ id
iterates the function `f` `n` times. However, the above characterization of `lfp` only holds for
continuous functions, a concept we will introduce below. -/
def iterate {α : Type} (f : α → α) : ℕ → α → α
| 0 a := a
| (n + 1) a := f (iterate n a)
notation f`^^[`n`]` := iterate f n
/- 2.1. Fill in the missing proofs below. -/
def Union {α : Type} (s : ℕ → set α) : set α :=
{ a | ∃n, a ∈ s n }
lemma Union_le {α : Type} {s : ℕ → set α} (a : set α) (h : ∀i, s i ≤ a) : Union s ≤ a :=
begin
intro u,
intro us,
cases us,
apply h us_w,
assumption
end
/- A continuous function `f` is a function that commutes with the union of any monotone sequence
`s`: -/
def continuous {α : Type} (f : set α → set α) : Prop :=
∀s : ℕ → set α, monotone s → f (Union s) = Union (λn, f (s n))
/- We need to prove that each continuous function is monotone. To achieve this, we will need the
following sequence: -/
def bi_seq {α : Type} (a₁ a₂ : set α) : ℕ → set α
| 0 := a₁
| (n + 1) := a₂
/- For example, `bi_seq 0 1` is the sequence 0, 1, 1, 1, etc. -/
lemma monotone_bi_seq {α : Type} (a₁ a₂ : set α) (h : a₁ ≤ a₂) :
monotone (bi_seq a₁ a₂)
| 0 0 _ := le_refl _
| 0 (n + 1) _ := h
| (n + 1) (m + 1) _ := le_refl _
lemma Union_bi_seq {α : Type} (a₁ a₂ : set α) (ha : a₁ ≤ a₂) :
Union (bi_seq a₁ a₂) = a₂ :=
begin
apply le_antisymm,
apply Union_le,
intro i,
intros a b,
cases i,
apply ha b,
exact b,
intros a1 a2,
apply exists.intro
end
lemma monotone_of_continuous {α : Type} (f : set α → set α) (hf : continuous f) :
monotone f :=
begin
intros a1 a2,
intros smaller,
apply Union_bi_seq,
end
/- 2.2. Provide the following proof, using a similar case distinction as for `monotone_bi_seq`
above. -/
lemma monotone_iterate {α : Type} (f : set α → set α) (hf : monotone f) :
monotone (λn, f^^[n] ∅)
:= sorry
/- 2.3. Prove the main theorem. A proof sketch is given below.
We break the proof into two proofs of inclusion.
Case 1. lfp f ≤ Union (λn, f^[n] ∅): The key is to use the lemma `lfp_le` together with continuity
of `f`.
Case 2. Union (λn, f^[n] ∅) ≤ lfp f: The lemma `Union_le` gives us a natural number `i`, on which
you can perform induction. You will also need the lemma `lfp_eq` to unfold one iteration of
`lfp f`. -/
lemma lfp_Kleene {α : Type} (f : set α → set α) (hf : continuous f) :
lfp f = Union (λn, f^^[n] ∅) :=
be
/- Question 3 **optional**: Regular expressions -/
inductive regex (α : Type) : Type
| empty {} : regex
| nothing {} : regex
| atom (a : α) : regex
| concat : regex → regex → regex
| alt : regex → regex → regex
| star : regex → regex
open regex
/- 3.1 **optional**. Define a translation of regular expressions to relations. The idea is that an
atom corresponds to a relation, concatenation corresponds to composition of relations, and
alternation is union. -/
def rel_of_regex {α : Type} : regex (set (α × α)) → set (α × α)
| empty := Id α
| _ := sorry
/- 3.2 **optional**. Prove the following recursive equation about your definition. -/
lemma rel_of_regex_star {α : Type} (r : regex (set (α × α))) :
rel_of_regex (star r) = rel_of_regex (alt (concat r (star r)) empty) :=
sorry
|
69c5c7e0d677633dd7ab79e91659ea632bfe92d8 | 9e90bb7eb4d1bde1805f9eb6187c333fdf09588a | /src/stump/algorithm_measurable.lean | 645f26a84e87864a3487b644112a0d9494a27c3b | [
"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 | 3,673 | lean | /-
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
-/
import .algorithm_definition
import .setup_measurable
open set
namespace stump
variables (μ: probability_measure ℍ) (target: ℍ) (n: ℕ)
@[simp]
lemma label_sample_measurable: ∀ n: ℕ, measurable (label_sample target n) :=
begin
intro,
apply measurable_map,
apply label_measurable,
end
@[simp]
lemma max_continuous: ∀ n, continuous (max n) :=
begin
intros,
induction n,
{
unfold max,
apply continuous_id,
},
{
unfold max,
simp,
apply continuous_if; intros,
{
unfold rlt at H, simp at H,
have FOO := @frontier_lt_subset_eq nnreal (vec nnreal (nat.succ n_n)) _ _ _ (λ x, max n_n x.snd) (λ x, x.fst) _ _ (continuous_fst),
{
simp at FOO,
have BAR := mem_of_mem_of_subset H FOO, clear FOO,
rw mem_set_of_eq at BAR,
exact eq.symm BAR,
},
{
apply continuous.comp,
assumption,
apply continuous_snd,
},
},
{
apply continuous.comp,
apply continuous_fst,
apply continuous_id,
},
{
apply continuous.comp,
assumption,
apply continuous.comp,
apply continuous_snd,
apply continuous_id,
},
},
end
@[simp]
lemma max_is_measurable: is_measurable {v: vec ℍ (nat.succ n) | rlt (max n v.snd) (v.fst)} :=
begin
dunfold vec,
unfold rlt,
simp,
apply test''',
{
apply continuous.comp,
apply max_continuous,
apply continuous_snd,
},
{
apply continuous_fst,
},
end
@[simp]
lemma max_measurable: ∀ n, measurable (max n) :=
begin
intro n,
induction n,
{
unfold max,
apply measurable_id,
},
{
unfold max,
apply measurable.if,
unfold_coes, apply max_is_measurable,
apply measurable.fst,
apply measurable_id,
apply measurable.comp,
apply n_ih,
apply measurable.snd,
apply measurable_id,
}
end
@[simp]
lemma choose_measurable: measurable (choose n) :=
begin
unfold choose,
apply measurable.comp,
apply max_measurable,
unfold filter,
apply measurable_map,
apply measurable.if,
unfold_coes,
{
have PROD: {a: ℍ × bool | a.snd = tt} = set.prod {x: ℍ | true} {b: bool | b = tt},
{
rw ext_iff, intros,
rw mem_prod_eq,
repeat {rw mem_set_of_eq},
finish,
},
rw PROD,
apply is_measurable.prod,
{
rw ← univ_def,
exact is_measurable.univ,
},
fsplit,
},
apply measurable.fst,
apply measurable_id,
apply measurable_const,
end
@[simp]
lemma is_measurable_vec_1:
∀ ε, is_measurable {v: vec (ℍ × bool) n | error μ target (choose n v) > ε} :=
begin
intros,
have PREIM: {v: vec (ℍ × bool) n | error μ target (choose n v) > ε} = (choose n) ⁻¹' {h: ℍ | error μ target h > ε},
simp,
rw PREIM,
apply measurable.preimage; try {simp},
end
@[simp]
lemma is_measurable_vec_2:
∀ ε, is_measurable {v: vec (ℍ × bool) n | error μ target (choose n v) ≤ ε} :=
begin
intros,
have PREIM: {v: vec (ℍ × bool) n | error μ target (choose n v) ≤ ε} = (choose n) ⁻¹' {h: ℍ | error μ target h ≤ ε},
simp,
rw PREIM,
apply measurable.preimage; try {simp},
end
end stump
|
f4151ad8c04610458e5a7b4462ca910c8e89cc9b | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/inv_bug.lean | be3cd1f496bd1263833ed521fbfb60e2de9db9c1 | [
"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 | 462 | lean | open nat
open eq.ops
inductive even : nat → Prop :=
| even_zero : even zero
| even_succ_of_odd : ∀ {a}, odd a → even (succ a)
with odd : nat → Prop :=
| odd_succ_of_even : ∀ {a}, even a → odd (succ a)
example : even 1 → false :=
begin
intro He1,
cases He1 with [a, Ho0],
cases Ho0
end
example : even 3 → false :=
begin
intro He3,
cases He3 with [a, Ho2],
cases Ho2 with [a, He1],
cases He1 with [a, Ho0],
cases Ho0
end
|
bae140e3c7d8549f713f07bb487633152b139fb6 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Util/MonadBacktrack.lean | 77b54c8d0fd52c95efccb7d47051f28ccfd6111d | [
"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 | 1,782 | 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
-/
namespace Lean
/-- Similar to `MonadState`, but it retrieves/restores only the "backtrackable" part of the state -/
class MonadBacktrack (s : outParam Type) (m : Type → Type) where
saveState : m s
restoreState : s → m Unit
export MonadBacktrack (saveState restoreState)
@[specialize] def commitWhenSome? [Monad m] [MonadBacktrack s m] [MonadExcept ε m] (x? : m (Option α)) : m (Option α) := do
let s ← saveState
try
match (← x?) with
| some a => pure (some a)
| none =>
restoreState s
pure none
catch ex =>
restoreState s
throw ex
@[specialize] def commitWhen [Monad m] [MonadBacktrack s m] [MonadExcept ε m] (x : m Bool) : m Bool := do
let s ← saveState
try
match (← x) with
| true => pure true
| false =>
restoreState s
pure false
catch ex =>
restoreState s
throw ex
@[specialize] def commitIfNoEx [Monad m] [MonadBacktrack s m] [MonadExcept ε m] (x : m α) : m α := do
let s ← saveState
try
x
catch ex =>
restoreState s
throw ex
@[specialize] def withoutModifyingState [Monad m] [MonadFinally m] [MonadBacktrack s m] (x : m α) : m α := do
let s ← saveState
try
x
finally
restoreState s
@[specialize] def observing? [Monad m] [MonadBacktrack s m] [MonadExcept ε m] (x : m α) : m (Option α) := do
let s ← saveState
try
x
catch _ =>
restoreState s
return none
instance [MonadBacktrack s m] [Monad m] : MonadBacktrack s (ExceptT ε m) where
saveState := ExceptT.lift saveState
restoreState s := ExceptT.lift <| restoreState s
end Lean
|
647c666ead55189a7be1279301fb08d5663eeaa4 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/linear_algebra/vandermonde.lean | 4702d0b28eee6ce85ea933dc6d30bdb9a1519c23 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 6,526 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import algebra.big_operators.fin
import algebra.geom_sum
import group_theory.perm.fin
import linear_algebra.matrix.determinant
import linear_algebra.matrix.nondegenerate
/-!
# Vandermonde matrix
This file defines the `vandermonde` matrix and gives its determinant.
## Main definitions
- `vandermonde v`: a square matrix with the `i, j`th entry equal to `v i ^ j`.
## Main results
- `det_vandermonde`: `det (vandermonde v)` is the product of `v i - v j`, where
`(i, j)` ranges over the unordered pairs.
-/
variables {R : Type*} [comm_ring R]
open equiv finset
open_locale big_operators matrix
namespace matrix
/-- `vandermonde v` is the square matrix with `i`th row equal to `1, v i, v i ^ 2, v i ^ 3, ...`.
-/
def vandermonde {n : ℕ} (v : fin n → R) : matrix (fin n) (fin n) R :=
λ i j, v i ^ (j : ℕ)
@[simp] lemma vandermonde_apply {n : ℕ} (v : fin n → R) (i j) :
vandermonde v i j = v i ^ (j : ℕ) :=
rfl
@[simp] lemma vandermonde_cons {n : ℕ} (v0 : R) (v : fin n → R) :
vandermonde (fin.cons v0 v : fin n.succ → R) =
fin.cons (λ j, v0 ^ (j : ℕ)) (λ i, fin.cons 1 (λ j, v i * vandermonde v i j)) :=
begin
ext i j,
refine fin.cases (by simp) (λ i, _) i,
refine fin.cases (by simp) (λ j, _) j,
simp [pow_succ]
end
lemma vandermonde_succ {n : ℕ} (v : fin n.succ → R) :
vandermonde v =
fin.cons (λ j, v 0 ^ (j : ℕ))
(λ i, fin.cons 1 (λ j, v i.succ * vandermonde (fin.tail v) i j)) :=
begin
conv_lhs { rw [← fin.cons_self_tail v, vandermonde_cons] },
simp only [fin.tail]
end
lemma vandermonde_mul_vandermonde_transpose {n : ℕ} (v w : fin n → R) (i j) :
(vandermonde v ⬝ (vandermonde w)ᵀ) i j = ∑ (k : fin n), (v i * w j) ^ (k : ℕ) :=
by simp only [vandermonde_apply, matrix.mul_apply, matrix.transpose_apply, mul_pow]
lemma vandermonde_transpose_mul_vandermonde {n : ℕ} (v : fin n → R) (i j) :
((vandermonde v)ᵀ ⬝ vandermonde v) i j = ∑ (k : fin n), v k ^ (i + j : ℕ) :=
by simp only [vandermonde_apply, matrix.mul_apply, matrix.transpose_apply, pow_add]
lemma det_vandermonde {n : ℕ} (v : fin n → R) :
det (vandermonde v) = ∏ i : fin n, ∏ j in Ioi i, (v j - v i) :=
begin
unfold vandermonde,
induction n with n ih,
{ exact det_eq_one_of_card_eq_zero (fintype.card_fin 0) },
calc det (of $ λ (i j : fin n.succ), v i ^ (j : ℕ))
= det (of $ λ (i j : fin n.succ), matrix.vec_cons
(v 0 ^ (j : ℕ))
(λ i, v (fin.succ i) ^ (j : ℕ) - v 0 ^ (j : ℕ)) i) :
det_eq_of_forall_row_eq_smul_add_const (matrix.vec_cons 0 1) 0 (fin.cons_zero _ _) _
... = det (of $ λ (i j : fin n), matrix.vec_cons
(v 0 ^ (j.succ : ℕ))
(λ (i : fin n), v (fin.succ i) ^ (j.succ : ℕ) - v 0 ^ (j.succ : ℕ))
(fin.succ_above 0 i)) :
by simp_rw [det_succ_column_zero, fin.sum_univ_succ, of_apply, matrix.cons_val_zero, submatrix,
of_apply, matrix.cons_val_succ,
fin.coe_zero, pow_zero, one_mul, sub_self, mul_zero, zero_mul,
finset.sum_const_zero, add_zero]
... = det (of $ λ (i j : fin n), (v (fin.succ i) - v 0) *
(∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ)) :
matrix _ _ R) :
by { congr, ext i j, rw [fin.succ_above_zero, matrix.cons_val_succ, fin.coe_succ, mul_comm],
exact (geom_sum₂_mul (v i.succ) (v 0) (j + 1 : ℕ)).symm }
... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n),
(∑ k in finset.range (j + 1 : ℕ), v i.succ ^ k * v 0 ^ (j - k : ℕ))) :
det_mul_column (λ i, v (fin.succ i) - v 0) _
... = (∏ (i : fin n), (v (fin.succ i) - v 0)) * det (λ (i j : fin n), v (fin.succ i) ^ (j : ℕ)) :
congr_arg ((*) _) _
... = ∏ i : fin n.succ, ∏ j in Ioi i, (v j - v i) :
by simp_rw [ih (v ∘ fin.succ), fin.prod_univ_succ, fin.prod_Ioi_zero, fin.prod_Ioi_succ],
{ intros i j,
simp_rw [of_apply],
rw matrix.cons_val_zero,
refine fin.cases _ (λ i, _) i,
{ simp },
rw [matrix.cons_val_succ, matrix.cons_val_succ, pi.one_apply],
ring },
{ cases n,
{ simp only [det_eq_one_of_card_eq_zero (fintype.card_fin 0)] },
apply det_eq_of_forall_col_eq_smul_add_pred (λ i, v 0),
{ intro j,
simp },
{ intros i j,
simp only [smul_eq_mul, pi.add_apply, fin.coe_succ, fin.coe_cast_succ, pi.smul_apply],
rw [finset.sum_range_succ, add_comm, tsub_self, pow_zero, mul_one, finset.mul_sum],
congr' 1,
refine finset.sum_congr rfl (λ i' hi', _),
rw [mul_left_comm (v 0), nat.succ_sub, pow_succ],
exact nat.lt_succ_iff.mp (finset.mem_range.mp hi') } }
end
lemma det_vandermonde_eq_zero_iff [is_domain R] {n : ℕ} {v : fin n → R} :
det (vandermonde v) = 0 ↔ ∃ (i j : fin n), v i = v j ∧ i ≠ j :=
begin
split,
{ simp only [det_vandermonde v, finset.prod_eq_zero_iff, sub_eq_zero, forall_exists_index],
exact λ i _ j h₁ h₂, ⟨j, i, h₂, (mem_Ioi.mp h₁).ne'⟩ },
{ simp only [ne.def, forall_exists_index, and_imp],
refine λ i j h₁ h₂, matrix.det_zero_of_row_eq h₂ (funext $ λ k, _),
rw [vandermonde_apply, vandermonde_apply, h₁], }
end
lemma det_vandermonde_ne_zero_iff [is_domain R] {n : ℕ} {v : fin n → R} :
det (vandermonde v) ≠ 0 ↔ function.injective v :=
by simpa only [det_vandermonde_eq_zero_iff, ne.def, not_exists, not_and, not_not]
theorem eq_zero_of_forall_index_sum_pow_mul_eq_zero {R : Type*} [comm_ring R]
[is_domain R] {n : ℕ} {f v : fin n → R} (hf : function.injective f)
(hfv : ∀ j, ∑ i : fin n, (f j ^ (i : ℕ)) * v i = 0) : v = 0 :=
eq_zero_of_mul_vec_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)
theorem eq_zero_of_forall_index_sum_mul_pow_eq_zero {R : Type*} [comm_ring R]
[is_domain R] {n : ℕ} {f v : fin n → R} (hf : function.injective f)
(hfv : ∀ j, ∑ i, v i * (f j ^ (i : ℕ)) = 0) : v = 0 :=
by { apply eq_zero_of_forall_index_sum_pow_mul_eq_zero hf, simp_rw mul_comm, exact hfv }
theorem eq_zero_of_forall_pow_sum_mul_pow_eq_zero {R : Type*} [comm_ring R]
[is_domain R] {n : ℕ} {f v : fin n → R} (hf : function.injective f)
(hfv : ∀ i : fin n, ∑ j : fin n, v j * (f j ^ (i : ℕ)) = 0) : v = 0 :=
eq_zero_of_vec_mul_eq_zero (det_vandermonde_ne_zero_iff.mpr hf) (funext hfv)
end matrix
|
4a65ef483e4ddbb1ad47e15713e558e7a1429bdd | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/indicator_function.lean | 08f80f48aabd828eb082613b1ae70ed021fae31f | [
"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 | 25,351 | lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import algebra.support
/-!
# Indicator function
- `indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise.
- `mul_indicator (s : set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `λx, 1`.
The indicator function is implemented non-computably, to avoid having to pass around `decidable`
arguments. This is in contrast with the design of `pi.single` or `set.piecewise`.
## Tags
indicator, characteristic
-/
open_locale big_operators
open function
variables {α β ι M N : Type*}
namespace set
section has_one
variables [has_one M] [has_one N] {s t : set α} {f g : α → M} {a : α}
/-- `indicator s f a` is `f a` if `a ∈ s`, `0` otherwise. -/
noncomputable def indicator {M} [has_zero M] (s : set α) (f : α → M) : α → M
| x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 0
/-- `mul_indicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/
@[to_additive]
noncomputable def mul_indicator (s : set α) (f : α → M) : α → M
| x := by haveI := classical.dec_pred (∈ s); exact if x ∈ s then f x else 1
@[simp, to_additive] lemma piecewise_eq_mul_indicator [decidable_pred (∈ s)] :
s.piecewise f 1 = s.mul_indicator f :=
funext $ λ x, @if_congr _ _ _ _ (id _) _ _ _ _ iff.rfl rfl rfl
@[to_additive] lemma mul_indicator_apply (s : set α) (f : α → M) (a : α) [decidable (a ∈ s)] :
mul_indicator s f a = if a ∈ s then f a else 1 := by convert rfl
@[simp, to_additive] lemma mul_indicator_of_mem (h : a ∈ s) (f : α → M) :
mul_indicator s f a = f a :=
by { letI := classical.dec (a ∈ s), exact if_pos h }
@[simp, to_additive] lemma mul_indicator_of_not_mem (h : a ∉ s) (f : α → M) :
mul_indicator s f a = 1 :=
by { letI := classical.dec (a ∈ s), exact if_neg h }
@[to_additive] lemma mul_indicator_eq_one_or_self (s : set α) (f : α → M) (a : α) :
mul_indicator s f a = 1 ∨ mul_indicator s f a = f a :=
begin
by_cases h : a ∈ s,
{ exact or.inr (mul_indicator_of_mem h f) },
{ exact or.inl (mul_indicator_of_not_mem h f) }
end
@[simp, to_additive] lemma mul_indicator_apply_eq_self :
s.mul_indicator f a = f a ↔ (a ∉ s → f a = 1) :=
by letI := classical.dec (a ∈ s); exact ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)])
@[simp, to_additive] lemma mul_indicator_eq_self : s.mul_indicator f = f ↔ mul_support f ⊆ s :=
by simp only [funext_iff, subset_def, mem_mul_support, mul_indicator_apply_eq_self, not_imp_comm]
@[to_additive] lemma mul_indicator_eq_self_of_superset (h1 : s.mul_indicator f = f) (h2 : s ⊆ t) :
t.mul_indicator f = f :=
by { rw mul_indicator_eq_self at h1 ⊢, exact subset.trans h1 h2 }
@[simp, to_additive] lemma mul_indicator_apply_eq_one :
mul_indicator s f a = 1 ↔ (a ∈ s → f a = 1) :=
by letI := classical.dec (a ∈ s); exact ite_eq_right_iff
@[simp, to_additive] lemma mul_indicator_eq_one :
mul_indicator s f = (λ x, 1) ↔ disjoint (mul_support f) s :=
by simp only [funext_iff, mul_indicator_apply_eq_one, set.disjoint_left, mem_mul_support,
not_imp_not]
@[simp, to_additive] lemma mul_indicator_eq_one' :
mul_indicator s f = 1 ↔ disjoint (mul_support f) s :=
mul_indicator_eq_one
@[to_additive] lemma mul_indicator_apply_ne_one {a : α} :
s.mul_indicator f a ≠ 1 ↔ a ∈ s ∩ mul_support f :=
by simp only [ne.def, mul_indicator_apply_eq_one, not_imp, mem_inter_eq, mem_mul_support]
@[simp, to_additive] lemma mul_support_mul_indicator :
function.mul_support (s.mul_indicator f) = s ∩ function.mul_support f :=
ext $ λ x, by simp [function.mem_mul_support, mul_indicator_apply_eq_one]
/-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the
set. -/
@[to_additive "If an additive indicator function is not equal to `0` at a point, then that point is
in the set."]
lemma mem_of_mul_indicator_ne_one (h : mul_indicator s f a ≠ 1) : a ∈ s :=
not_imp_comm.1 (λ hn, mul_indicator_of_not_mem hn f) h
@[to_additive] lemma eq_on_mul_indicator : eq_on (mul_indicator s f) f s :=
λ x hx, mul_indicator_of_mem hx f
@[to_additive] lemma mul_support_mul_indicator_subset : mul_support (s.mul_indicator f) ⊆ s :=
λ x hx, hx.imp_symm (λ h, mul_indicator_of_not_mem h f)
@[simp, to_additive] lemma mul_indicator_mul_support : mul_indicator (mul_support f) f = f :=
mul_indicator_eq_self.2 subset.rfl
@[simp, to_additive] lemma mul_indicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) :
mul_indicator (range f) g ∘ f = g ∘ f :=
by letI := classical.dec_pred (∈ range f); exact piecewise_range_comp _ _ _
@[to_additive] lemma mul_indicator_congr (h : eq_on f g s) :
mul_indicator s f = mul_indicator s g :=
funext $ λx, by { simp only [mul_indicator], split_ifs, { exact h h_1 }, refl }
@[simp, to_additive] lemma mul_indicator_univ (f : α → M) : mul_indicator (univ : set α) f = f :=
mul_indicator_eq_self.2 $ subset_univ _
@[simp, to_additive] lemma mul_indicator_empty (f : α → M) : mul_indicator (∅ : set α) f = λa, 1 :=
mul_indicator_eq_one.2 $ disjoint_empty _
@[to_additive] lemma mul_indicator_empty' (f : α → M) : mul_indicator (∅ : set α) f = 1 :=
mul_indicator_empty f
variable (M)
@[simp, to_additive] lemma mul_indicator_one (s : set α) :
mul_indicator s (λx, (1:M)) = λx, (1:M) :=
mul_indicator_eq_one.2 $ by simp only [mul_support_one, empty_disjoint]
@[simp, to_additive] lemma mul_indicator_one' {s : set α} : s.mul_indicator (1 : α → M) = 1 :=
mul_indicator_one M s
variable {M}
@[to_additive] lemma mul_indicator_mul_indicator (s t : set α) (f : α → M) :
mul_indicator s (mul_indicator t f) = mul_indicator (s ∩ t) f :=
funext $ λx, by { simp only [mul_indicator], split_ifs, repeat {simp * at * {contextual := tt}} }
@[simp, to_additive] lemma mul_indicator_inter_mul_support (s : set α) (f : α → M) :
mul_indicator (s ∩ mul_support f) f = mul_indicator s f :=
by rw [← mul_indicator_mul_indicator, mul_indicator_mul_support]
@[to_additive] lemma comp_mul_indicator (h : M → β) (f : α → M) {s : set α} {x : α}
[decidable_pred (∈ s)] :
h (s.mul_indicator f x) = s.piecewise (h ∘ f) (const α (h 1)) x :=
by letI := classical.dec_pred (∈ s); convert s.apply_piecewise f (const α 1) (λ _, h)
@[to_additive] lemma mul_indicator_comp_right {s : set α} (f : β → α) {g : α → M} {x : β} :
mul_indicator (f ⁻¹' s) (g ∘ f) x = mul_indicator s g (f x) :=
by { simp only [mul_indicator], split_ifs; refl }
@[to_additive] lemma mul_indicator_image {s : set α} {f : β → M} {g : α → β} (hg : injective g)
{x : α} : mul_indicator (g '' s) f (g x) = mul_indicator s (f ∘ g) x :=
by rw [← mul_indicator_comp_right, preimage_image_eq _ hg]
@[to_additive] lemma mul_indicator_comp_of_one {g : M → N} (hg : g 1 = 1) :
mul_indicator s (g ∘ f) = g ∘ (mul_indicator s f) :=
begin
funext,
simp only [mul_indicator],
split_ifs; simp [*]
end
@[to_additive] lemma comp_mul_indicator_const (c : M) (f : M → N) (hf : f 1 = 1) :
(λ x, f (s.mul_indicator (λ x, c) x)) = s.mul_indicator (λ x, f c) :=
(mul_indicator_comp_of_one hf).symm
@[to_additive] lemma mul_indicator_preimage (s : set α) (f : α → M) (B : set M) :
(mul_indicator s f)⁻¹' B = s.ite (f ⁻¹' B) (1 ⁻¹' B) :=
by letI := classical.dec_pred (∈ s); exact piecewise_preimage s f 1 B
@[to_additive] lemma mul_indicator_preimage_of_not_mem (s : set α) (f : α → M)
{t : set M} (ht : (1:M) ∉ t) :
(mul_indicator s f)⁻¹' t = f ⁻¹' t ∩ s :=
by simp [mul_indicator_preimage, pi.one_def, set.preimage_const_of_not_mem ht]
@[to_additive] lemma mem_range_mul_indicator {r : M} {s : set α} {f : α → M} :
r ∈ range (mul_indicator s f) ↔ (r = 1 ∧ s ≠ univ) ∨ (r ∈ f '' s) :=
by simp [mul_indicator, ite_eq_iff, exists_or_distrib, eq_univ_iff_forall, and_comm, or_comm,
@eq_comm _ r 1]
@[to_additive] lemma mul_indicator_rel_mul_indicator {r : M → M → Prop} (h1 : r 1 1)
(ha : a ∈ s → r (f a) (g a)) :
r (mul_indicator s f a) (mul_indicator s g a) :=
by { simp only [mul_indicator], split_ifs with has has, exacts [ha has, h1] }
end has_one
section monoid
variables [mul_one_class M] {s t : set α} {f g : α → M} {a : α}
@[to_additive] lemma mul_indicator_union_mul_inter_apply (f : α → M) (s t : set α) (a : α) :
mul_indicator (s ∪ t) f a * mul_indicator (s ∩ t) f a =
mul_indicator s f a * mul_indicator t f a :=
by by_cases hs : a ∈ s; by_cases ht : a ∈ t; simp *
@[to_additive] lemma mul_indicator_union_mul_inter (f : α → M) (s t : set α) :
mul_indicator (s ∪ t) f * mul_indicator (s ∩ t) f = mul_indicator s f * mul_indicator t f :=
funext $ mul_indicator_union_mul_inter_apply f s t
@[to_additive] lemma mul_indicator_union_of_not_mem_inter (h : a ∉ s ∩ t) (f : α → M) :
mul_indicator (s ∪ t) f a = mul_indicator s f a * mul_indicator t f a :=
by rw [← mul_indicator_union_mul_inter_apply f s t, mul_indicator_of_not_mem h, mul_one]
@[to_additive] lemma mul_indicator_union_of_disjoint (h : disjoint s t) (f : α → M) :
mul_indicator (s ∪ t) f = λa, mul_indicator s f a * mul_indicator t f a :=
funext $ λa, mul_indicator_union_of_not_mem_inter (λ ha, h ha) _
@[to_additive] lemma mul_indicator_mul (s : set α) (f g : α → M) :
mul_indicator s (λa, f a * g a) = λa, mul_indicator s f a * mul_indicator s g a :=
by { funext, simp only [mul_indicator], split_ifs, { refl }, rw mul_one }
@[to_additive] lemma mul_indicator_mul' (s : set α) (f g : α → M) :
mul_indicator s (f * g) = mul_indicator s f * mul_indicator s g :=
mul_indicator_mul s f g
@[simp, to_additive] lemma mul_indicator_compl_mul_self_apply (s : set α) (f : α → M) (a : α) :
mul_indicator sᶜ f a * mul_indicator s f a = f a :=
classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha])
@[simp, to_additive] lemma mul_indicator_compl_mul_self (s : set α) (f : α → M) :
mul_indicator sᶜ f * mul_indicator s f = f :=
funext $ mul_indicator_compl_mul_self_apply s f
@[simp, to_additive] lemma mul_indicator_self_mul_compl_apply (s : set α) (f : α → M) (a : α) :
mul_indicator s f a * mul_indicator sᶜ f a = f a :=
classical.by_cases (λ ha : a ∈ s, by simp [ha]) (λ ha, by simp [ha])
@[simp, to_additive] lemma mul_indicator_self_mul_compl (s : set α) (f : α → M) :
mul_indicator s f * mul_indicator sᶜ f = f :=
funext $ mul_indicator_self_mul_compl_apply s f
@[to_additive] lemma mul_indicator_mul_eq_left {f g : α → M}
(h : disjoint (mul_support f) (mul_support g)) :
(mul_support f).mul_indicator (f * g) = f :=
begin
refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support,
have : g x = 1, from nmem_mul_support.1 (disjoint_left.1 h hx),
rw [pi.mul_apply, this, mul_one]
end
@[to_additive] lemma mul_indicator_mul_eq_right {f g : α → M}
(h : disjoint (mul_support f) (mul_support g)) :
(mul_support g).mul_indicator (f * g) = g :=
begin
refine (mul_indicator_congr $ λ x hx, _).trans mul_indicator_mul_support,
have : f x = 1, from nmem_mul_support.1 (disjoint_right.1 h hx),
rw [pi.mul_apply, this, one_mul]
end
@[to_additive] lemma mul_indicator_mul_compl_eq_piecewise
[decidable_pred (∈ s)] (f g : α → M) :
s.mul_indicator f * sᶜ.mul_indicator g = s.piecewise f g :=
begin
ext x,
by_cases h : x ∈ s,
{ rw [piecewise_eq_of_mem _ _ _ h, pi.mul_apply, set.mul_indicator_of_mem h,
set.mul_indicator_of_not_mem (set.not_mem_compl_iff.2 h), mul_one] },
{ rw [piecewise_eq_of_not_mem _ _ _ h, pi.mul_apply, set.mul_indicator_of_not_mem h,
set.mul_indicator_of_mem (set.mem_compl h), one_mul] },
end
/-- `set.mul_indicator` as a `monoid_hom`. -/
@[to_additive "`set.indicator` as an `add_monoid_hom`."]
noncomputable def mul_indicator_hom {α} (M) [mul_one_class M] (s : set α) : (α → M) →* (α → M) :=
{ to_fun := mul_indicator s,
map_one' := mul_indicator_one M s,
map_mul' := mul_indicator_mul s }
end monoid
section distrib_mul_action
variables {A : Type*} [add_monoid A] [monoid M] [distrib_mul_action M A]
lemma indicator_smul_apply (s : set α) (r : α → M) (f : α → A) (x : α) :
indicator s (λ x, r x • f x) x = r x • indicator s f x :=
by { dunfold indicator, split_ifs, exacts [rfl, (smul_zero (r x)).symm] }
lemma indicator_smul (s : set α) (r : α → M) (f : α → A) :
indicator s (λ (x : α), r x • f x) = λ (x : α), r x • indicator s f x :=
funext $ indicator_smul_apply s r f
lemma indicator_const_smul_apply (s : set α) (r : M) (f : α → A) (x : α) :
indicator s (λ x, r • f x) x = r • indicator s f x :=
indicator_smul_apply s (λ x, r) f x
lemma indicator_const_smul (s : set α) (r : M) (f : α → A) :
indicator s (λ (x : α), r • f x) = λ (x : α), r • indicator s f x :=
funext $ indicator_const_smul_apply s r f
end distrib_mul_action
section group
variables {G : Type*} [group G] {s t : set α} {f g : α → G} {a : α}
@[to_additive] lemma mul_indicator_inv' (s : set α) (f : α → G) :
mul_indicator s (f⁻¹) = (mul_indicator s f)⁻¹ :=
(mul_indicator_hom G s).map_inv f
@[to_additive] lemma mul_indicator_inv (s : set α) (f : α → G) :
mul_indicator s (λa, (f a)⁻¹) = λa, (mul_indicator s f a)⁻¹ :=
mul_indicator_inv' s f
@[to_additive] lemma mul_indicator_div (s : set α) (f g : α → G) :
mul_indicator s (λ a, f a / g a) =
λ a, mul_indicator s f a / mul_indicator s g a :=
(mul_indicator_hom G s).map_div f g
@[to_additive] lemma mul_indicator_div' (s : set α) (f g : α → G) :
mul_indicator s (f / g) = mul_indicator s f / mul_indicator s g :=
mul_indicator_div s f g
@[to_additive indicator_compl'] lemma mul_indicator_compl (s : set α) (f : α → G) :
mul_indicator sᶜ f = f * (mul_indicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq $ s.mul_indicator_compl_mul_self f
lemma indicator_compl {G} [add_group G] (s : set α) (f : α → G) :
indicator sᶜ f = f - indicator s f :=
by rw [sub_eq_add_neg, indicator_compl']
@[to_additive indicator_diff'] lemma mul_indicator_diff (h : s ⊆ t) (f : α → G) :
mul_indicator (t \ s) f = mul_indicator t f * (mul_indicator s f)⁻¹ :=
eq_mul_inv_of_mul_eq $ by rw [pi.mul_def, ← mul_indicator_union_of_disjoint disjoint_diff.symm f,
diff_union_self, union_eq_self_of_subset_right h]
lemma indicator_diff {G : Type*} [add_group G] {s t : set α} (h : s ⊆ t) (f : α → G) :
indicator (t \ s) f = indicator t f - indicator s f :=
by rw [indicator_diff' h, sub_eq_add_neg]
end group
section comm_monoid
variables [comm_monoid M]
/-- Consider a product of `g i (f i)` over a `finset`. Suppose `g` is a
function such as `pow`, which maps a second argument of `1` to
`1`. Then if `f` is replaced by the corresponding multiplicative indicator
function, the `finset` may be replaced by a possibly larger `finset`
without changing the value of the sum. -/
@[to_additive] lemma prod_mul_indicator_subset_of_eq_one [has_one N] (f : α → N)
(g : α → N → M) {s t : finset α} (h : s ⊆ t) (hg : ∀ a, g a 1 = 1) :
∏ i in s, g i (f i) = ∏ i in t, g i (mul_indicator ↑s f i) :=
begin
rw ← finset.prod_subset h _,
{ apply finset.prod_congr rfl,
intros i hi,
congr,
symmetry,
exact mul_indicator_of_mem hi _ },
{ refine λ i hi hn, _,
convert hg i,
exact mul_indicator_of_not_mem hn _ }
end
/-- Consider a sum of `g i (f i)` over a `finset`. Suppose `g` is a
function such as multiplication, which maps a second argument of 0 to
0. (A typical use case would be a weighted sum of `f i * h i` or `f i
• h i`, where `f` gives the weights that are multiplied by some other
function `h`.) Then if `f` is replaced by the corresponding indicator
function, the `finset` may be replaced by a possibly larger `finset`
without changing the value of the sum. -/
add_decl_doc set.sum_indicator_subset_of_eq_zero
/-- Taking the product of an indicator function over a possibly larger `finset` is the same as
taking the original function over the original `finset`. -/
@[to_additive "Summing an indicator function over a possibly larger `finset` is the same as summing
the original function over the original `finset`."]
lemma prod_mul_indicator_subset (f : α → M) {s t : finset α} (h : s ⊆ t) :
∏ i in s, f i = ∏ i in t, mul_indicator ↑s f i :=
prod_mul_indicator_subset_of_eq_one _ (λ a b, b) h (λ _, rfl)
@[to_additive] lemma _root_.finset.prod_mul_indicator_eq_prod_filter
(s : finset ι) (f : ι → α → M) (t : ι → set α) (g : ι → α) [decidable_pred (λ i, g i ∈ t i)]:
∏ i in s, mul_indicator (t i) (f i) (g i) = ∏ i in s.filter (λ i, g i ∈ t i), f i (g i) :=
begin
refine (finset.prod_filter_mul_prod_filter_not s (λ i, g i ∈ t i) _).symm.trans _,
refine eq.trans _ (mul_one _),
exact congr_arg2 (*)
(finset.prod_congr rfl $ λ x hx, mul_indicator_of_mem (finset.mem_filter.1 hx).2 _)
(finset.prod_eq_one $ λ x hx, mul_indicator_of_not_mem (finset.mem_filter.1 hx).2 _)
end
@[to_additive] lemma mul_indicator_finset_prod (I : finset ι) (s : set α) (f : ι → α → M) :
mul_indicator s (∏ i in I, f i) = ∏ i in I, mul_indicator s (f i) :=
(mul_indicator_hom M s).map_prod _ _
@[to_additive] lemma mul_indicator_finset_bUnion {ι} (I : finset ι)
(s : ι → set α) {f : α → M} : (∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) →
mul_indicator (⋃ i ∈ I, s i) f = λ a, ∏ i in I, mul_indicator (s i) f a :=
begin
classical,
refine finset.induction_on I _ _,
{ intro h, funext, simp },
assume a I haI ih hI,
funext,
rw [finset.prod_insert haI, finset.set_bUnion_insert, mul_indicator_union_of_not_mem_inter, ih _],
{ assume i hi j hj hij,
exact hI i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj) hij },
simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and],
assume hx a' ha',
refine disjoint_left.1 (hI a (finset.mem_insert_self _ _) a' (finset.mem_insert_of_mem ha') _) hx,
exact (ne_of_mem_of_not_mem ha' haI).symm
end
@[to_additive] lemma mul_indicator_finset_bUnion_apply {ι} (I : finset ι)
(s : ι → set α) {f : α → M} (h : ∀ (i ∈ I) (j ∈ I), i ≠ j → disjoint (s i) (s j)) (x : α) :
mul_indicator (⋃ i ∈ I, s i) f x = ∏ i in I, mul_indicator (s i) f x :=
by rw set.mul_indicator_finset_bUnion I s h
end comm_monoid
section mul_zero_class
variables [mul_zero_class M] {s t : set α} {f g : α → M} {a : α}
lemma indicator_mul (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) = λa, indicator s f a * indicator s g a :=
by { funext, simp only [indicator], split_ifs, { refl }, rw mul_zero }
lemma indicator_mul_left (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) a = indicator s f a * g a :=
by { simp only [indicator], split_ifs, { refl }, rw [zero_mul] }
lemma indicator_mul_right (s : set α) (f g : α → M) :
indicator s (λa, f a * g a) a = f a * indicator s g a :=
by { simp only [indicator], split_ifs, { refl }, rw [mul_zero] }
lemma inter_indicator_mul {t1 t2 : set α} (f g : α → M) (x : α) :
(t1 ∩ t2).indicator (λ x, f x * g x) x = t1.indicator f x * t2.indicator g x :=
by { rw [← set.indicator_indicator], simp [indicator] }
end mul_zero_class
section mul_zero_one_class
variables [mul_zero_one_class M]
lemma inter_indicator_one {s t : set α} :
(s ∩ t).indicator (1 : _ → M) = s.indicator 1 * t.indicator 1 :=
funext (λ _, by simpa only [← inter_indicator_mul, pi.mul_apply, pi.one_apply, one_mul])
lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} :
(s ×ˢ t).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y :=
by { classical, simp [indicator_apply, ←ite_and] }
variables (M) [nontrivial M]
lemma indicator_eq_zero_iff_not_mem {U : set α} {x : α} :
indicator U 1 x = (0 : M) ↔ x ∉ U :=
by { classical, simp [indicator_apply, imp_false] }
lemma indicator_eq_one_iff_mem {U : set α} {x : α} :
indicator U 1 x = (1 : M) ↔ x ∈ U :=
by { classical, simp [indicator_apply, imp_false] }
lemma indicator_one_inj {U V : set α} (h : indicator U (1 : α → M) = indicator V 1) : U = V :=
by { ext, simp_rw [← indicator_eq_one_iff_mem M, h] }
end mul_zero_one_class
section order
variables [has_one M] {s t : set α} {f g : α → M} {a : α} {y : M}
section
variables [has_le M]
@[to_additive] lemma mul_indicator_apply_le' (hfg : a ∈ s → f a ≤ y) (hg : a ∉ s → 1 ≤ y) :
mul_indicator s f a ≤ y :=
begin
by_cases ha : a ∈ s,
{ simpa [ha] using hfg ha },
{ simpa [ha] using hg ha },
end
@[to_additive] lemma mul_indicator_le' (hfg : ∀ a ∈ s, f a ≤ g a) (hg : ∀ a ∉ s, 1 ≤ g a) :
mul_indicator s f ≤ g :=
λ a, mul_indicator_apply_le' (hfg _) (hg _)
@[to_additive] lemma le_mul_indicator_apply {y} (hfg : a ∈ s → y ≤ g a) (hf : a ∉ s → y ≤ 1) :
y ≤ mul_indicator s g a :=
@mul_indicator_apply_le' α Mᵒᵈ ‹_› _ _ _ _ _ hfg hf
@[to_additive] lemma le_mul_indicator (hfg : ∀ a ∈ s, f a ≤ g a) (hf : ∀ a ∉ s, f a ≤ 1) :
f ≤ mul_indicator s g :=
λ a, le_mul_indicator_apply (hfg _) (hf _)
end
variables [preorder M]
@[to_additive indicator_apply_nonneg]
lemma one_le_mul_indicator_apply (h : a ∈ s → 1 ≤ f a) : 1 ≤ mul_indicator s f a :=
le_mul_indicator_apply h (λ _, le_rfl)
@[to_additive indicator_nonneg]
lemma one_le_mul_indicator (h : ∀ a ∈ s, 1 ≤ f a) (a : α) : 1 ≤ mul_indicator s f a :=
one_le_mul_indicator_apply (h a)
@[to_additive] lemma mul_indicator_apply_le_one (h : a ∈ s → f a ≤ 1) : mul_indicator s f a ≤ 1 :=
mul_indicator_apply_le' h (λ _, le_rfl)
@[to_additive] lemma mul_indicator_le_one (h : ∀ a ∈ s, f a ≤ 1) (a : α) :
mul_indicator s f a ≤ 1 :=
mul_indicator_apply_le_one (h a)
@[to_additive] lemma mul_indicator_le_mul_indicator (h : f a ≤ g a) :
mul_indicator s f a ≤ mul_indicator s g a :=
mul_indicator_rel_mul_indicator le_rfl (λ _, h)
attribute [mono] mul_indicator_le_mul_indicator indicator_le_indicator
@[to_additive] lemma mul_indicator_le_mul_indicator_of_subset (h : s ⊆ t) (hf : ∀ a, 1 ≤ f a)
(a : α) :
mul_indicator s f a ≤ mul_indicator t f a :=
mul_indicator_apply_le' (λ ha, le_mul_indicator_apply (λ _, le_rfl) (λ hat, (hat $ h ha).elim))
(λ ha, one_le_mul_indicator_apply (λ _, hf _))
@[to_additive] lemma mul_indicator_le_self' (hf : ∀ x ∉ s, 1 ≤ f x) : mul_indicator s f ≤ f :=
mul_indicator_le' (λ _ _, le_rfl) hf
@[to_additive] lemma mul_indicator_Union_apply {ι M} [complete_lattice M] [has_one M]
(h1 : (⊥:M) = 1) (s : ι → set α) (f : α → M) (x : α) :
mul_indicator (⋃ i, s i) f x = ⨆ i, mul_indicator (s i) f x :=
begin
by_cases hx : x ∈ ⋃ i, s i,
{ rw [mul_indicator_of_mem hx],
rw [mem_Union] at hx,
refine le_antisymm _ (supr_le $ λ i, mul_indicator_le_self' (λ x hx, h1 ▸ bot_le) x),
rcases hx with ⟨i, hi⟩,
exact le_supr_of_le i (ge_of_eq $ mul_indicator_of_mem hi _) },
{ rw [mul_indicator_of_not_mem hx],
simp only [mem_Union, not_exists] at hx,
simp [hx, ← h1] }
end
end order
section canonically_ordered_monoid
variables [canonically_ordered_monoid M]
@[to_additive] lemma mul_indicator_le_self (s : set α) (f : α → M) :
mul_indicator s f ≤ f :=
mul_indicator_le_self' $ λ _ _, one_le _
@[to_additive] lemma mul_indicator_apply_le {a : α} {s : set α} {f g : α → M}
(hfg : a ∈ s → f a ≤ g a) :
mul_indicator s f a ≤ g a :=
mul_indicator_apply_le' hfg $ λ _, one_le _
@[to_additive] lemma mul_indicator_le {s : set α} {f g : α → M} (hfg : ∀ a ∈ s, f a ≤ g a) :
mul_indicator s f ≤ g :=
mul_indicator_le' hfg $ λ _ _, one_le _
end canonically_ordered_monoid
lemma indicator_le_indicator_nonneg {β} [linear_order β] [has_zero β] (s : set α) (f : α → β) :
s.indicator f ≤ {x | 0 ≤ f x}.indicator f :=
begin
intro x,
classical,
simp_rw indicator_apply,
split_ifs,
{ exact le_rfl, },
{ exact (not_le.mp h_1).le, },
{ exact h_1, },
{ exact le_rfl, },
end
lemma indicator_nonpos_le_indicator {β} [linear_order β] [has_zero β] (s : set α) (f : α → β) :
{x | f x ≤ 0}.indicator f ≤ s.indicator f :=
@indicator_le_indicator_nonneg α βᵒᵈ _ _ s f
end set
@[to_additive] lemma monoid_hom.map_mul_indicator
{M N : Type*} [mul_one_class M] [mul_one_class N] (f : M →* N)
(s : set α) (g : α → M) (x : α) :
f (s.mul_indicator g x) = s.mul_indicator (f ∘ g) x :=
congr_fun (set.mul_indicator_comp_of_one f.map_one).symm x
|
35c55b000baaa19e430b4276c1cea4d389a18bfb | 37da0369b6c03e380e057bf680d81e6c9fdf9219 | /hott/types/int/hott.hlean | 3a965c8c1011d6c522c5f292a8ba7494e51555b5 | [
"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 | 6,698 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Theorems about the integers specific to HoTT
-/
import .order types.eq arity algebra.bundled
open core eq is_equiv equiv algebra is_trunc
open nat (hiding pred)
namespace int
section
open algebra
/-
we make these structures reducible, so that n * m in gℤ and agℤ can be interpreted as
multiplication on ℤ. For this it's needed that the carriers of gℤ and agℤ reduce to ℤ unfolding
only reducible definitions.
-/
definition group_integers [reducible] [constructor] : AddGroup :=
AddGroup.mk ℤ _
notation `gℤ` := group_integers
definition AbGroup_int [reducible] [constructor] : AddAbGroup :=
AddAbGroup.mk ℤ _
notation `agℤ` := AbGroup_int
definition ring_int : Ring :=
Ring.mk ℤ _
notation `rℤ` := ring_int
end
definition is_equiv_succ [constructor] [instance] : is_equiv succ :=
adjointify succ pred (λa, !add_sub_cancel) (λa, !sub_add_cancel)
definition equiv_succ [constructor] : ℤ ≃ ℤ := equiv.mk succ _
definition is_equiv_neg [constructor] [instance] : is_equiv (neg : ℤ → ℤ) :=
adjointify neg neg (λx, !neg_neg) (λa, !neg_neg)
definition equiv_neg [constructor] : ℤ ≃ ℤ := equiv.mk neg _
definition iiterate {A : Type} (f : A ≃ A) (a : ℤ) : A ≃ A :=
rec_nat_on a erfl
(λb g, f ⬝e g)
(λb g, g ⬝e f⁻¹ᵉ)
definition max0 : ℤ → ℕ
| (of_nat n) := n
| (-[1+ n]) := 0
lemma le_max0 : Π(n : ℤ), n ≤ of_nat (max0 n)
| (of_nat n) := proof le.refl n qed
| (-[1+ n]) := proof unit.star qed
lemma le_of_max0_le {n : ℤ} {m : ℕ} (h : max0 n ≤ m) : n ≤ of_nat m :=
le.trans (le_max0 n) (of_nat_le_of_nat_of_le h)
-- definition iterate_trans {A : Type} (f : A ≃ A) (a : ℤ)
-- : iterate f a ⬝e f = iterate f (a + 1) :=
-- sorry
-- definition trans_iterate {A : Type} (f : A ≃ A) (a : ℤ)
-- : f ⬝e iterate f a = iterate f (a + 1) :=
-- sorry
-- definition iterate_trans_symm {A : Type} (f : A ≃ A) (a : ℤ)
-- : iterate f a ⬝e f⁻¹e = iterate f (a - 1) :=
-- sorry
-- definition symm_trans_iterate {A : Type} (f : A ≃ A) (a : ℤ)
-- : f⁻¹e ⬝e iterate f a = iterate f (a - 1) :=
-- sorry
-- definition iterate_neg {A : Type} (f : A ≃ A) (a : ℤ)
-- : iterate f (-a) = (iterate f a)⁻¹e :=
-- rec_nat_on a idp
-- (λn p, calc
-- iterate f (-succ n) = iterate f (-n) ⬝e f⁻¹e : rec_nat_on_neg
-- ... = (iterate f n)⁻¹e ⬝e f⁻¹e : by rewrite p
-- ... = (f ⬝e iterate f n)⁻¹e : sorry
-- ... = (iterate f (succ n))⁻¹e : idp)
-- sorry
-- definition iterate_add {A : Type} (f : A ≃ A) (a b : ℤ)
-- : iterate f (a + b) = equiv.trans (iterate f a) (iterate f b) :=
-- sorry
-- definition iterate_sub {A : Type} (f : A ≃ A) (a b : ℤ)
-- : iterate f (a - b) = equiv.trans (iterate f a) (equiv.symm (iterate f b)) :=
-- sorry
-- definition iterate_mul {A : Type} (f : A ≃ A) (a b : ℤ)
-- : iterate f (a * b) = iterate (iterate f a) b :=
-- sorry
end int open int
namespace eq
variables {A : Type} {a : A} (p : a = a) (b c : ℤ) (n : ℕ)
definition power : a = a :=
rec_nat_on b idp
(λc q, q ⬝ p)
(λc q, q ⬝ p⁻¹)
--iterate (equiv_eq_closed_right p a) b idp
-- definition power_neg_succ (n : ℕ) : power p (-succ n) = power p (-n) ⬝ p⁻¹ :=
-- !rec_nat_on_neg
-- local attribute nat.add int.add int.of_num nat.of_num int.succ [constructor]
definition power_con : power p b ⬝ p = power p (succ b) :=
rec_nat_on b
idp
(λn IH, idp)
(λn IH, calc
power p (-succ n) ⬝ p
= (power p (-int.of_nat n) ⬝ p⁻¹) ⬝ p : by krewrite [↑power,rec_nat_on_neg]
... = power p (-int.of_nat n) : inv_con_cancel_right
... = power p (succ (-succ n)) : by rewrite -succ_neg_succ)
definition power_con_inv : power p b ⬝ p⁻¹ = power p (pred b) :=
rec_nat_on b
idp
(λn IH, calc
power p (succ n) ⬝ p⁻¹ = power p n : by apply con_inv_cancel_right
... = power p (pred (succ n)) : by rewrite pred_nat_succ)
(λn IH, calc
power p (-int.of_nat (succ n)) ⬝ p⁻¹
= power p (-int.of_nat (succ (succ n))) : by krewrite [↑power,*rec_nat_on_neg]
... = power p (pred (-succ n)) : by rewrite -neg_succ)
definition con_power : p ⬝ power p b = power p (succ b) :=
rec_nat_on b
( by rewrite ↑[power];exact !idp_con⁻¹)
( λn IH, proof calc
p ⬝ power p (succ n) = (p ⬝ power p n) ⬝ p : con.assoc p _ p
... = power p (succ (succ n)) : by rewrite IH qed)
( λn IH, calc
p ⬝ power p (-int.of_nat (succ n))
= p ⬝ (power p (-int.of_nat n) ⬝ p⁻¹) : by rewrite [↑power, rec_nat_on_neg]
... = (p ⬝ power p (-int.of_nat n)) ⬝ p⁻¹ : con.assoc
... = power p (succ (-int.of_nat n)) ⬝ p⁻¹ : by rewrite IH
... = power p (pred (succ (-int.of_nat n))) : power_con_inv
... = power p (succ (-int.of_nat (succ n))) : by rewrite [succ_neg_nat_succ,int.pred_succ])
definition inv_con_power : p⁻¹ ⬝ power p b = power p (pred b) :=
rec_nat_on b
( by rewrite ↑[power];exact !idp_con⁻¹)
(λn IH, calc
p⁻¹ ⬝ power p (succ n) = p⁻¹ ⬝ power p n ⬝ p : con.assoc
... = power p (pred n) ⬝ p : by rewrite IH
... = power p (succ (pred n)) : power_con
... = power p (pred (succ n)) : by rewrite [succ_pred,-int.pred_succ n])
( λn IH, calc
p⁻¹ ⬝ power p (-int.of_nat (succ n))
= p⁻¹ ⬝ (power p (-int.of_nat n) ⬝ p⁻¹) : by rewrite [↑power,rec_nat_on_neg]
... = (p⁻¹ ⬝ power p (-int.of_nat n)) ⬝ p⁻¹ : con.assoc
... = power p (pred (-int.of_nat n)) ⬝ p⁻¹ : by rewrite IH
... = power p (-int.of_nat (succ n)) ⬝ p⁻¹ : by rewrite -neg_succ
... = power p (-succ (succ n)) : by krewrite [↑power,*rec_nat_on_neg]
... = power p (pred (-succ n)) : by rewrite -neg_succ)
definition power_con_power : Π(b : ℤ), power p b ⬝ power p c = power p (b + c) :=
rec_nat_on c
(λb, by rewrite int.add_zero)
(λn IH b, by rewrite [-con_power,-con.assoc,power_con,IH,↑succ,add.assoc,
add.comm (int.of_nat n)])
(λn IH b, by rewrite [neg_nat_succ,-inv_con_power,-con.assoc,power_con_inv,IH,↑pred,
+sub_eq_add_neg,add.assoc,add.comm (-n)])
end eq
|
38fad0359617b1c6593cc8e3c741128f7b47a71d | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Init/Data/Nat/Gcd.lean | 7654c3a4abf859aabb8485914650d394a157cf77 | [
"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 | 1,116 | 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
-/
prelude
import Init.Data.Nat.Div
namespace Nat
private def gcdF (x : Nat) : (∀ x₁, x₁ < x → Nat → Nat) → Nat → Nat :=
match x with
| 0 => fun _ y => y
| succ x => fun f y => f (y % succ x) (mod_lt _ (zero_lt_succ _)) (succ x)
@[extern "lean_nat_gcd"]
def gcd (a b : @& Nat) : Nat :=
WellFounded.fix (measure id).wf gcdF a b
@[simp] theorem gcd_zero_left (y : Nat) : gcd 0 y = y :=
rfl
theorem gcd_succ (x y : Nat) : gcd (succ x) y = gcd (y % succ x) (succ x) :=
rfl
@[simp] theorem gcd_one_left (n : Nat) : gcd 1 n = 1 := by
rw [gcd_succ, mod_one]
rfl
@[simp] theorem gcd_zero_right (n : Nat) : gcd n 0 = n := by
cases n with
| zero => simp [gcd_succ]
| succ n =>
-- `simp [gcd_succ]` produces an invalid term unless `gcd_succ` is proved with `id rfl` instead
rw [gcd_succ]
exact gcd_zero_left _
@[simp] theorem gcd_self (n : Nat) : gcd n n = n := by
cases n <;> simp [gcd_succ]
end Nat
|
41526436cc15b0c1cc0fab0b8d26c8f56a274b5a | 8fe7510bd7f4eb87049ac0423b0476c841df8fe6 | /src/gen_graph.lean | 11671992f92d096ea962c0244affbccba71cecfc | [] | no_license | robertylewis/import-graph | 26201690ec3221b7923f8141f69023196536e6b1 | 8b82a030dab9b1247c968288e021d960eafa82a0 | refs/heads/master | 1,671,038,042,246 | 1,598,982,544,000 | 1,598,982,544,000 | 292,068,181 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,480 | lean | import meta.rb_map
import meta.expr
import system.io
import data.list.sort
import data.real.basic
import all
/-!
Usage:
```
leanproject get robertylewis/import-graph
cd import-graph
lean --run src/gen_graph.lean
```
-/
@[inline]
meta def expr.get_constants (e : expr) : name_set :=
e.fold mk_name_set $ λ e' _ s, match e' with
| expr.const nm _ := s.insert nm
| _ := s
end
@[inline]
meta def declaration.get_constants : declaration → name_set
| (declaration.ax nm _ tp) := tp.get_constants
| (declaration.cnst nm _ tp is_meta) := tp.get_constants
| (declaration.thm nm _ tp bd) := tp.get_constants.union bd.get.get_constants
| (declaration.defn nm _ tp bd _ is_meta) := tp.get_constants.union bd.get_constants
open io io.fs tactic
meta instance coe_tactic_to_io {α} : has_coe (tactic α) (io α) :=
⟨run_tactic⟩
def fn := "graph.dot"
/-- hack to avoid memory error -/
meta def list.itersplit {α} : list α → ℕ → list (list α)
| l 0 := [l]
| l 1 := let (l1, l2) := l.split in [l1, l2]
| l (k+2) := let (l1, l2) := l.split in list.itersplit l1 (k+1) ++ list.itersplit l2 (k+1)
meta def main : io unit := do
h ← mk_file_handle fn mode.write,
e ← get_env,
let s := list.join $ e.fold [] $ λ d s,
let deps := d.get_constants in
deps.to_list.map (λ n, (d.to_name.to_string, n.to_string))::s,
let s := s.map (λ ⟨lhs, rhs⟩, ("\n\"" ++ lhs ++ "\" -> \"" ++ rhs ++ "\"")),
let s := s.itersplit 10,
s.mmap' $ λ s', s'.mmap' $ put_str h
|
a6cd8f7e5add5bf72a87d749afbd90bb95f7b1cf | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/erased.lean | 7ccca5b054b772e529c9004f463dceac5468cb4f | [
"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,755 | 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 logic.equiv.basic
/-!
# A type for VM-erased data
This file defines a type `erased α` which is classically isomorphic to `α`,
but erased in the VM. That is, at runtime every value of `erased α` is
represented as `0`, just like types and proofs.
-/
universes u
/-- `erased α` is the same as `α`, except that the elements
of `erased α` are erased in the VM in the same way as types
and proofs. This can be used to track data without storing it
literally. -/
def erased (α : Sort u) : Sort (max 1 u) :=
Σ' s : α → Prop, ∃ a, (λ b, a = b) = s
namespace erased
/-- Erase a value. -/
@[inline] def mk {α} (a : α) : erased α := ⟨λ b, a = b, a, rfl⟩
/-- Extracts the erased value, noncomputably. -/
noncomputable def out {α} : erased α → α
| ⟨s, h⟩ := classical.some h
/--
Extracts the erased value, if it is a type.
Note: `(mk a).out_type` is not definitionally equal to `a`.
-/
@[reducible] def out_type (a : erased (Sort u)) : Sort u := out a
/-- Extracts the erased value, if it is a proof. -/
theorem out_proof {p : Prop} (a : erased p) : p := out a
@[simp] theorem out_mk {α} (a : α) : (mk a).out = a :=
begin
let h, show classical.some h = a,
have := classical.some_spec h,
exact cast (congr_fun this a).symm rfl
end
@[simp] theorem mk_out {α} : ∀ (a : erased α), mk (out a) = a
| ⟨s, h⟩ := by simp [mk]; congr; exact classical.some_spec h
@[ext] lemma out_inj {α} (a b : erased α) (h : a.out = b.out) : a = b :=
by simpa using congr_arg mk h
/-- Equivalence between `erased α` and `α`. -/
noncomputable def equiv (α) : erased α ≃ α :=
⟨out, mk, mk_out, out_mk⟩
instance (α : Type u) : has_repr (erased α) := ⟨λ _, "erased"⟩
instance (α : Type u) : has_to_string (erased α) := ⟨λ _, "erased"⟩
meta instance (α : Type u) : has_to_format (erased α) := ⟨λ _, ("erased" : format)⟩
/-- Computably produce an erased value from a proof of nonemptiness. -/
def choice {α} (h : nonempty α) : erased α := mk (classical.choice h)
@[simp] theorem nonempty_iff {α} : nonempty (erased α) ↔ nonempty α :=
⟨λ ⟨a⟩, ⟨a.out⟩, λ ⟨a⟩, ⟨mk a⟩⟩
instance {α} [h : nonempty α] : inhabited (erased α) :=
⟨choice h⟩
/--
`(>>=)` operation on `erased`.
This is a separate definition because `α` and `β` can live in different
universes (the universe is fixed in `monad`).
-/
def bind {α β} (a : erased α) (f : α → erased β) : erased β :=
⟨λ b, (f a.out).1 b, (f a.out).2⟩
@[simp] theorem bind_eq_out {α β} (a f) : @bind α β a f = f a.out :=
by delta bind bind._proof_1; cases f a.out; refl
/--
Collapses two levels of erasure.
-/
def join {α} (a : erased (erased α)) : erased α := bind a id
@[simp] theorem join_eq_out {α} (a) : @join α a = a.out := bind_eq_out _ _
/--
`(<$>)` operation on `erased`.
This is a separate definition because `α` and `β` can live in different
universes (the universe is fixed in `functor`).
-/
def map {α β} (f : α → β) (a : erased α) : erased β :=
bind a (mk ∘ f)
@[simp] theorem map_out {α β} {f : α → β} (a : erased α) : (a.map f).out = f a.out :=
by simp [map]
instance : monad erased := { pure := @mk, bind := @bind, map := @map }
@[simp] lemma pure_def {α} : (pure : α → erased α) = @mk _ := rfl
@[simp] lemma bind_def {α β} : ((>>=) : erased α → (α → erased β) → erased β) = @bind _ _ := rfl
@[simp] lemma map_def {α β} : ((<$>) : (α → β) → erased α → erased β) = @map _ _ := rfl
instance : is_lawful_monad erased := by refine {..}; intros; ext; simp
end erased
|
fa4f415e240b4bef43206fdffc9b5cf755040589 | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/set_theory/cardinal.lean | fa57a95c76ee4ea5241c2d0fd770ae2e15f2cc4e | [
"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 | 44,826 | 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, Mario Carneiro
-/
import data.set.countable data.quot logic.function set_theory.schroeder_bernstein
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
We define the order on cardinal numbers, define omega, and do basic cardinal arithmetic:
addition, multiplication, power, cardinal successor, minimum, supremum,
infinitary sums and products
## Implementation notes
* There is a type of cardinal numbers in every universe level: `cardinal.{u} : Type (u + 1)`
is the quotient of types in `Type u`.
There is a lift operation lifting cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`set_theory/ordinal.lean`, because concepts from that file are used in the proof.
## References
* https://en.wikipedia.org/wiki/Cardinal_number
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, omega
-/
open function lattice set
open_locale classical
universes u v w x
variables {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance cardinal.is_equivalent : setoid (Type u) :=
{ r := λα β, nonempty (α ≃ β),
iseqv := ⟨λα,
⟨equiv.refl α⟩,
λα β ⟨e⟩, ⟨e.symm⟩,
λα β γ ⟨e₁⟩ ⟨e₂⟩, ⟨e₁.trans e₂⟩⟩ }
/-- `cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
def cardinal : Type (u + 1) := quotient cardinal.is_equivalent
namespace cardinal
/-- The cardinal number of a type -/
def mk : Type u → cardinal := quotient.mk
localized "notation `#` := cardinal.mk" in cardinal
protected lemma eq : mk α = mk β ↔ nonempty (α ≃ β) := quotient.eq
@[simp] theorem mk_def (α : Type u) : @eq cardinal ⟦α⟧ (mk α) := rfl
@[simp] theorem mk_out (c : cardinal) : mk (c.out) = c := quotient.out_eq _
/-- We define the order on cardinal numbers by `mk α ≤ mk β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : has_le cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, nonempty $ α ↪ β) $
assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
propext ⟨assume ⟨e⟩, ⟨e.congr e₁ e₂⟩, assume ⟨e⟩, ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : injective f) : mk α ≤ mk β :=
⟨⟨f, hf⟩⟩
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : surjective f) : mk β ≤ mk α :=
⟨embedding.of_surjective hf⟩
theorem le_mk_iff_exists_set {c : cardinal} {α : Type u} :
c ≤ mk α ↔ ∃ p : set α, mk p = c :=
⟨quotient.induction_on c $ λ β ⟨⟨f, hf⟩⟩,
⟨set.range f, eq.symm $ quot.sound ⟨equiv.set.range f hf⟩⟩,
λ ⟨p, e⟩, e ▸ ⟨⟨subtype.val, λ a b, subtype.eq⟩⟩⟩
theorem out_embedding {c c' : cardinal} : c ≤ c' ↔ nonempty (c.out ↪ c'.out) :=
by { transitivity _, rw [←quotient.out_eq c, ←quotient.out_eq c'], refl }
instance : linear_order cardinal.{u} :=
{ le := (≤),
le_refl := by rintros ⟨α⟩; exact ⟨embedding.refl _⟩,
le_trans := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.trans e₂⟩,
le_antisymm := by rintros ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩; exact quotient.sound (e₁.antisymm e₂),
le_total := by rintros ⟨α⟩ ⟨β⟩; exact embedding.total }
noncomputable instance : decidable_linear_order cardinal.{u} := classical.DLO _
noncomputable instance : distrib_lattice cardinal.{u} := by apply_instance
instance : has_zero cardinal.{u} := ⟨⟦pempty⟧⟩
instance : inhabited cardinal.{u} := ⟨0⟩
theorem ne_zero_iff_nonempty {α : Type u} : mk α ≠ 0 ↔ nonempty α :=
not_iff_comm.1
⟨λ h, quotient.sound ⟨(equiv.empty_of_not_nonempty h).trans equiv.empty_equiv_pempty⟩,
λ e, let ⟨h⟩ := quotient.exact e in λ ⟨a⟩, (h a).elim⟩
instance : has_one cardinal.{u} := ⟨⟦punit⟧⟩
instance : zero_ne_one_class cardinal.{u} :=
{ zero := 0, one := 1, zero_ne_one :=
ne.symm $ ne_zero_iff_nonempty.2 ⟨punit.star⟩ }
theorem le_one_iff_subsingleton {α : Type u} : mk α ≤ 1 ↔ subsingleton α :=
⟨λ ⟨f⟩, ⟨λ a b, f.inj (subsingleton.elim _ _)⟩,
λ ⟨h⟩, ⟨⟨λ a, punit.star, λ a b _, h _ _⟩⟩⟩
instance : has_add cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α ⊕ β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.sum_congr e₁ e₂⟩⟩
@[simp] theorem add_def (α β) : mk α + mk β = mk (α ⊕ β) := rfl
instance : has_mul cardinal.{u} :=
⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α × β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.prod_congr e₁ e₂⟩⟩
@[simp] theorem mul_def (α β : Type u) : mk α * mk β = mk (α × β) := rfl
private theorem add_comm (a b : cardinal.{u}) : a + b = b + a :=
quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.sum_comm α β⟩
private theorem mul_comm (a b : cardinal.{u}) : a * b = b * a :=
quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.prod_comm α β⟩
private theorem zero_add (a : cardinal.{u}) : 0 + a = a :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_sum α⟩
private theorem zero_mul (a : cardinal.{u}) : 0 * a = 0 :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_prod α⟩
private theorem one_mul (a : cardinal.{u}) : 1 * a = a :=
quotient.induction_on a $ assume α, quotient.sound ⟨equiv.punit_prod α⟩
private theorem left_distrib (a b c : cardinal.{u}) : a * (b + c) = a * b + a * c :=
quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.prod_sum_distrib α β γ⟩
instance : comm_semiring cardinal.{u} :=
{ zero := 0,
one := 1,
add := (+),
mul := (*),
zero_add := zero_add,
add_zero := assume a, by rw [add_comm a 0, zero_add a],
add_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.sum_assoc α β γ⟩,
add_comm := add_comm,
zero_mul := zero_mul,
mul_zero := assume a, by rw [mul_comm a 0, zero_mul a],
one_mul := one_mul,
mul_one := assume a, by rw [mul_comm a 1, one_mul a],
mul_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.prod_assoc α β γ⟩,
mul_comm := mul_comm,
left_distrib := left_distrib,
right_distrib := assume a b c,
by rw [mul_comm (a + b) c, left_distrib c a b, mul_comm c a, mul_comm c b] }
/-- The cardinal exponential. `mk α ^ mk β` is the cardinal of `β → α`. -/
protected def power (a b : cardinal.{u}) : cardinal.{u} :=
quotient.lift_on₂ a b (λα β, mk (β → α)) $ assume α₁ α₂ β₁ β₂ ⟨e₁⟩ ⟨e₂⟩,
quotient.sound ⟨equiv.arrow_congr e₂ e₁⟩
instance : has_pow cardinal cardinal := ⟨cardinal.power⟩
local infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow
@[simp] theorem power_def (α β) : mk α ^ mk β = mk (β → α) := rfl
@[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.pempty_arrow_equiv_punit α⟩
@[simp] theorem power_one {a : cardinal} : a ^ 1 = a :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.punit_arrow_equiv α⟩
@[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 :=
quotient.induction_on a $ assume α, quotient.sound
⟨equiv.arrow_punit_equiv_punit α⟩
@[simp] theorem prop_eq_two : mk (ulift Prop) = 2 :=
quot.sound ⟨equiv.ulift.trans $ equiv.Prop_equiv_bool.trans equiv.bool_equiv_punit_sum_punit⟩
@[simp] theorem zero_power {a : cardinal} : a ≠ 0 → 0 ^ a = 0 :=
quotient.induction_on a $ assume α heq,
nonempty.rec_on (ne_zero_iff_nonempty.1 heq) $ assume a,
quotient.sound ⟨equiv.equiv_pempty $ assume f, pempty.rec (λ _, false) (f a)⟩
theorem power_ne_zero {a : cardinal} (b) : a ≠ 0 → a ^ b ≠ 0 :=
quotient.induction_on₂ a b $ λ α β h,
let ⟨a⟩ := ne_zero_iff_nonempty.1 h in
ne_zero_iff_nonempty.2 ⟨λ _, a⟩
theorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.arrow_prod_equiv_prod_arrow α β γ⟩
theorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.sum_arrow_equiv_prod_arrow β γ α⟩
theorem power_mul {a b c : cardinal} : (a ^ b) ^ c = a ^ (b * c) :=
by rw [_root_.mul_comm b c];
from (quotient.induction_on₃ a b c $ assume α β γ,
quotient.sound ⟨equiv.arrow_arrow_equiv_prod_arrow γ β α⟩)
@[simp] lemma pow_cast_right (κ : cardinal.{u}) :
∀ n : ℕ, (κ ^ (↑n : cardinal.{u})) = @has_pow.pow _ _ monoid.has_pow κ n
| 0 := by simp
| (_+1) := by rw [nat.cast_succ, power_add, power_one, _root_.mul_comm, pow_succ, pow_cast_right]
section order_properties
open sum
theorem zero_le : ∀(a : cardinal), 0 ≤ a :=
by rintro ⟨α⟩; exact ⟨embedding.of_not_nonempty $ λ ⟨a⟩, a.elim⟩
theorem le_zero (a : cardinal) : a ≤ 0 ↔ a = 0 :=
by simp [le_antisymm_iff, zero_le]
theorem pos_iff_ne_zero {o : cardinal} : 0 < o ↔ o ≠ 0 :=
by simp [lt_iff_le_and_ne, eq_comm, zero_le]
theorem zero_lt_one : (0 : cardinal) < 1 :=
lt_of_le_of_ne (zero_le _) zero_ne_one
lemma zero_power_le (c : cardinal.{u}) : (0 : cardinal.{u}) ^ c ≤ 1 :=
by { by_cases h : c = 0, rw [h, power_zero], rw [zero_power h], apply zero_le }
theorem add_le_add : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨embedding.sum_congr e₁ e₂⟩
theorem add_le_add_left (a) {b c : cardinal} : b ≤ c → a + b ≤ a + c :=
add_le_add (le_refl _)
theorem add_le_add_right {a b : cardinal} (c) (h : a ≤ b) : a + c ≤ b + c :=
add_le_add h (le_refl _)
theorem le_add_right (a b : cardinal) : a ≤ a + b :=
by simpa using add_le_add_left a (zero_le b)
theorem le_add_left (a b : cardinal) : a ≤ b + a :=
by simpa using add_le_add_right a (zero_le b)
theorem mul_le_mul : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a * c ≤ b * d :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨embedding.prod_congr e₁ e₂⟩
theorem mul_le_mul_left (a) {b c : cardinal} : b ≤ c → a * b ≤ a * c :=
mul_le_mul (le_refl _)
theorem mul_le_mul_right {a b : cardinal} (c) (h : a ≤ b) : a * c ≤ b * c :=
mul_le_mul h (le_refl _)
theorem power_le_power_left : ∀{a b c : cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c :=
by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩; exact
let ⟨a⟩ := ne_zero_iff_nonempty.1 hα in
⟨@embedding.arrow_congr_right _ _ _ ⟨a⟩ e⟩
theorem power_le_max_power_one {a b c : cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 :=
begin
by_cases ha : a = 0,
simp [ha, zero_power_le],
exact le_trans (power_le_power_left ha h) (le_max_left _ _)
end
theorem power_le_power_right {a b c : cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
quotient.induction_on₃ a b c $ assume α β γ ⟨e⟩, ⟨embedding.arrow_congr_left e⟩
theorem le_iff_exists_add {a b : cardinal} : a ≤ b ↔ ∃ c, b = a + c :=
⟨quotient.induction_on₂ a b $ λ α β ⟨⟨f, hf⟩⟩,
have (α ⊕ ↥-range f) ≃ β, from
(equiv.sum_congr (equiv.set.range f hf) (equiv.refl _)).trans $
(equiv.set.sum_compl (range f)),
⟨⟦(-range f : set β)⟧, quotient.sound ⟨this.symm⟩⟩,
λ ⟨c, e⟩, add_zero a ▸ e.symm ▸ add_le_add_left _ (zero_le _)⟩
end order_properties
instance : order_bot cardinal.{u} :=
{ bot := 0, bot_le := zero_le, ..cardinal.linear_order }
instance : canonically_ordered_monoid cardinal.{u} :=
{ add_le_add_left := λ a b h c, add_le_add_left _ h,
lt_of_add_lt_add_left := λ a b c, lt_imp_lt_of_le_imp_le (add_le_add_left _),
le_iff_exists_add := @le_iff_exists_add,
..cardinal.lattice.order_bot,
..cardinal.comm_semiring, ..cardinal.linear_order }
theorem cantor : ∀(a : cardinal.{u}), a < 2 ^ a :=
by rw ← prop_eq_two; rintros ⟨a⟩; exact ⟨
⟨⟨λ a b, ⟨a = b⟩, λ a b h, cast (ulift.up.inj (@congr_fun _ _ _ _ h b)).symm rfl⟩⟩,
λ ⟨⟨f, hf⟩⟩, cantor_injective (λ s, f (λ a, ⟨s a⟩)) $
λ s t h, by funext a; injection congr_fun (hf h) a⟩
instance : no_top_order cardinal.{u} :=
{ no_top := λ a, ⟨_, cantor a⟩, ..cardinal.linear_order }
/-- The minimum cardinal in a family of cardinals (the existence
of which is provided by `injective_min`). -/
noncomputable def min {ι} (I : nonempty ι) (f : ι → cardinal) : cardinal :=
f $ classical.some $
@embedding.injective_min _ (λ i, (f i).out) I
theorem min_eq {ι} (I) (f : ι → cardinal) : ∃ i, min I f = f i :=
⟨_, rfl⟩
theorem min_le {ι I} (f : ι → cardinal) (i) : min I f ≤ f i :=
by rw [← mk_out (min I f), ← mk_out (f i)]; exact
let ⟨g⟩ := classical.some_spec
(@embedding.injective_min _ (λ i, (f i).out) I) in
⟨g i⟩
theorem le_min {ι I} {f : ι → cardinal} {a} : a ≤ min I f ↔ ∀ i, a ≤ f i :=
⟨λ h i, le_trans h (min_le _ _),
λ h, let ⟨i, e⟩ := min_eq I f in e.symm ▸ h i⟩
protected theorem wf : @well_founded cardinal.{u} (<) :=
⟨λ a, classical.by_contradiction $ λ h,
let ι := {c :cardinal // ¬ acc (<) c},
f : ι → cardinal := subtype.val,
⟨⟨c, hc⟩, hi⟩ := @min_eq ι ⟨⟨_, h⟩⟩ f in
hc (acc.intro _ (λ j ⟨_, h'⟩,
classical.by_contradiction $ λ hj, h' $
by have := min_le f ⟨j, hj⟩; rwa hi at this))⟩
instance has_wf : @has_well_founded cardinal.{u} := ⟨(<), cardinal.wf⟩
instance wo : @is_well_order cardinal.{u} (<) := ⟨cardinal.wf⟩
/-- The successor cardinal - the smallest cardinal greater than
`c`. This is not the same as `c + 1` except in the case of finite `c`. -/
noncomputable def succ (c : cardinal) : cardinal :=
@min {c' // c < c'} ⟨⟨_, cantor _⟩⟩ subtype.val
theorem lt_succ_self (c : cardinal) : c < succ c :=
by cases min_eq _ _ with s e; rw [succ, e]; exact s.2
theorem succ_le {a b : cardinal} : succ a ≤ b ↔ a < b :=
⟨lt_of_lt_of_le (lt_succ_self _), λ h,
by exact min_le _ (subtype.mk b h)⟩
theorem lt_succ {a b : cardinal} : a < succ b ↔ a ≤ b :=
by rw [← not_le, succ_le, not_lt]
theorem add_one_le_succ (c : cardinal) : c + 1 ≤ succ c :=
begin
refine quot.induction_on c (λ α, _) (lt_succ_self c),
refine quot.induction_on (succ (quot.mk setoid.r α)) (λ β h, _),
cases h.left with f,
have : ¬ surjective f := λ hn,
ne_of_lt h (quotient.sound ⟨equiv.of_bijective ⟨f.inj, hn⟩⟩),
cases classical.not_forall.1 this with b nex,
refine ⟨⟨sum.rec (by exact f) _, _⟩⟩,
{ exact λ _, b },
{ intros a b h, rcases a with a|⟨⟨⟨⟩⟩⟩; rcases b with b|⟨⟨⟨⟩⟩⟩,
{ rw f.inj h },
{ exact nex.elim ⟨_, h⟩ },
{ exact nex.elim ⟨_, h.symm⟩ },
{ refl } }
end
lemma succ_ne_zero (c : cardinal) : succ c ≠ 0 :=
by { rw [←pos_iff_ne_zero, lt_succ], apply zero_le }
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → cardinal) : cardinal := mk Σ i, (f i).out
theorem le_sum {ι} (f : ι → cardinal) (i) : f i ≤ sum f :=
by rw ← quotient.out_eq (f i); exact
⟨⟨λ a, ⟨i, a⟩, λ a b h, eq_of_heq $ by injection h⟩⟩
@[simp] theorem sum_mk {ι} (f : ι → Type*) : sum (λ i, mk (f i)) = mk (Σ i, f i) :=
quot.sound ⟨equiv.sigma_congr_right $ λ i,
classical.choice $ quotient.exact $ quot.out_eq $ mk (f i)⟩
theorem sum_const (ι : Type u) (a : cardinal.{u}) : sum (λ _:ι, a) = mk ι * a :=
quotient.induction_on a $ λ α, by simp; exact
quotient.sound ⟨equiv.sigma_equiv_prod _ _⟩
theorem sum_le_sum {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨embedding.sigma_congr_right $ λ i, classical.choice $
by have := H i; rwa [← quot.out_eq (f i), ← quot.out_eq (g i)] at this⟩
/-- The indexed supremum of cardinals is the smallest cardinal above
everything in the family. -/
noncomputable def sup {ι} (f : ι → cardinal) : cardinal :=
@min {c // ∀ i, f i ≤ c} ⟨⟨sum f, le_sum f⟩⟩ (λ a, a.1)
theorem le_sup {ι} (f : ι → cardinal) (i) : f i ≤ sup f :=
by dsimp [sup]; cases min_eq _ _ with c hc; rw hc; exact c.2 i
theorem sup_le {ι} {f : ι → cardinal} {a} : sup f ≤ a ↔ ∀ i, f i ≤ a :=
⟨λ h i, le_trans (le_sup _ _) h,
λ h, by dsimp [sup]; change a with (⟨a, h⟩:subtype _).1; apply min_le⟩
theorem sup_le_sup {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sup f ≤ sup g :=
sup_le.2 $ λ i, le_trans (H i) (le_sup _ _)
theorem sup_le_sum {ι} (f : ι → cardinal) : sup f ≤ sum f :=
sup_le.2 $ le_sum _
theorem sum_le_sup {ι : Type u} (f : ι → cardinal.{u}) : sum f ≤ mk ι * sup.{u u} f :=
by rw ← sum_const; exact sum_le_sum _ _ (le_sup _)
theorem sup_eq_zero {ι} {f : ι → cardinal} (h : ι → false) : sup f = 0 :=
by { rw [←le_zero, sup_le], intro x, exfalso, exact h x }
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → cardinal) : cardinal := mk (Π i, (f i).out)
@[simp] theorem prod_mk {ι} (f : ι → Type*) : prod (λ i, mk (f i)) = mk (Π i, f i) :=
quot.sound ⟨equiv.Pi_congr_right $ λ i,
classical.choice $ quotient.exact $ mk_out $ mk (f i)⟩
theorem prod_const (ι : Type u) (a : cardinal.{u}) : prod (λ _:ι, a) = a ^ mk ι :=
quotient.induction_on a $ by simp
theorem prod_le_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨embedding.Pi_congr_right $ λ i, classical.choice $
by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
theorem prod_ne_zero {ι} (f : ι → cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 :=
begin
conv in (f _) {rw ← mk_out (f i)},
simp [prod, ne_zero_iff_nonempty, -mk_out, -ne.def],
exact ⟨λ ⟨F⟩ i, ⟨F i⟩, λ h, ⟨λ i, classical.choice (h i)⟩⟩,
end
theorem prod_eq_zero {ι} (f : ι → cardinal) : prod f = 0 ↔ ∃ i, f i = 0 :=
not_iff_not.1 $ by simpa using prod_ne_zero f
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : cardinal.{u} → cardinal.{max u v}` -/
def lift (c : cardinal.{u}) : cardinal.{max u v} :=
quotient.lift_on c (λ α, ⟦ulift α⟧) $ λ α β ⟨e⟩,
quotient.sound ⟨equiv.ulift.trans $ e.trans equiv.ulift.symm⟩
theorem lift_mk (α) : lift.{u v} (mk α) = mk (ulift.{v u} α) := rfl
theorem lift_umax : lift.{u (max u v)} = lift.{u v} :=
funext $ λ a, quot.induction_on a $ λ α,
quotient.sound ⟨equiv.ulift.trans equiv.ulift.symm⟩
theorem lift_id' (a : cardinal) : lift a = a :=
quot.induction_on a $ λ α, quot.sound ⟨equiv.ulift⟩
@[simp] theorem lift_id : ∀ a, lift.{u u} a = a := lift_id'.{u u}
@[simp] theorem lift_lift (a : cardinal) : lift.{(max u v) w} (lift.{u v} a) = lift.{u (max v w)} a :=
quot.induction_on a $ λ α,
quotient.sound ⟨equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm⟩
theorem lift_mk_le {α : Type u} {β : Type v} :
lift.{u (max v w)} (mk α) ≤ lift.{v (max u w)} (mk β) ↔ nonempty (α ↪ β) :=
⟨λ ⟨f⟩, ⟨embedding.congr equiv.ulift equiv.ulift f⟩,
λ ⟨f⟩, ⟨embedding.congr equiv.ulift.symm equiv.ulift.symm f⟩⟩
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{u (max v w)} (mk α) = lift.{v (max u w)} (mk β) ↔ nonempty (α ≃ β) :=
quotient.eq.trans
⟨λ ⟨f⟩, ⟨equiv.ulift.symm.trans $ f.trans equiv.ulift⟩,
λ ⟨f⟩, ⟨equiv.ulift.trans $ f.trans equiv.ulift.symm⟩⟩
@[simp] theorem lift_le {a b : cardinal} : lift a ≤ lift b ↔ a ≤ b :=
quotient.induction_on₂ a b $ λ α β,
by rw ← lift_umax; exact lift_mk_le
@[simp] theorem lift_inj {a b : cardinal} : lift a = lift b ↔ a = b :=
by simp [le_antisymm_iff]
@[simp] theorem lift_lt {a b : cardinal} : lift a < lift b ↔ a < b :=
by simp [lt_iff_le_not_le, -not_le]
@[simp] theorem lift_zero : lift 0 = 0 :=
quotient.sound ⟨equiv.ulift.trans equiv.pempty_equiv_pempty⟩
@[simp] theorem lift_one : lift 1 = 1 :=
quotient.sound ⟨equiv.ulift.trans equiv.punit_equiv_punit⟩
@[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b :=
quotient.induction_on₂ a b $ λ α β,
quotient.sound ⟨equiv.ulift.trans (equiv.arrow_congr equiv.ulift equiv.ulift).symm⟩
@[simp] theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a :=
by simp [bit0]
@[simp] theorem lift_min {ι I} (f : ι → cardinal) : lift (min I f) = min I (lift ∘ f) :=
le_antisymm (le_min.2 $ λ a, lift_le.2 $ min_le _ a) $
let ⟨i, e⟩ := min_eq I (lift ∘ f) in
by rw e; exact lift_le.2 (le_min.2 $ λ j, lift_le.1 $
by have := min_le (lift ∘ f) j; rwa e at this)
theorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a → ∃ a', lift a' = b :=
quotient.induction_on₂ a b $ λ α β,
by dsimp; rw [← lift_id (mk β), ← lift_umax, ← lift_umax.{u v}, lift_mk_le]; exact
λ ⟨f⟩, ⟨mk (set.range f), eq.symm $ lift_mk_eq.2
⟨embedding.equiv_of_surjective
(embedding.cod_restrict _ f set.mem_range_self)
$ λ ⟨a, ⟨b, e⟩⟩, ⟨b, subtype.eq e⟩⟩⟩
theorem le_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b ≤ lift a ↔ ∃ a', lift a' = b ∧ a' ≤ a :=
⟨λ h, let ⟨a', e⟩ := lift_down h in ⟨a', e, lift_le.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_le.2 h⟩
theorem lt_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} :
b < lift a ↔ ∃ a', lift a' = b ∧ a' < a :=
⟨λ h, let ⟨a', e⟩ := lift_down (le_of_lt h) in
⟨a', e, lift_lt.1 $ e.symm ▸ h⟩,
λ ⟨a', e, h⟩, e ▸ lift_lt.2 h⟩
@[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) :=
le_antisymm
(le_of_not_gt $ λ h, begin
rcases lt_lift_iff.1 h with ⟨b, e, h⟩,
rw [lt_succ, ← lift_le, e] at h,
exact not_lt_of_le h (lt_succ_self _)
end)
(succ_le.2 $ lift_lt.2 $ lt_succ_self _)
@[simp] theorem lift_max {a : cardinal.{u}} {b : cardinal.{v}} :
lift.{u (max v w)} a = lift.{v (max u w)} b ↔ lift.{u v} a = lift.{v u} b :=
calc lift.{u (max v w)} a = lift.{v (max u w)} b
↔ lift.{(max u v) w} (lift.{u v} a)
= lift.{(max u v) w} (lift.{v u} b) : by simp
... ↔ lift.{u v} a = lift.{v u} b : lift_inj
theorem mk_prod {α : Type u} {β : Type v} :
mk (α × β) = lift.{u v} (mk α) * lift.{v u} (mk β) :=
quotient.sound ⟨equiv.prod_congr (equiv.ulift).symm (equiv.ulift).symm⟩
theorem sum_const_eq_lift_mul (ι : Type u) (a : cardinal.{v}) :
sum (λ _:ι, a) = lift.{u v} (mk ι) * lift.{v u} a :=
begin
apply quotient.induction_on a,
intro α,
simp only [cardinal.mk_def, cardinal.sum_mk, cardinal.lift_id],
convert mk_prod using 1,
exact quotient.sound ⟨equiv.sigma_equiv_prod ι α⟩,
end
/-- `ω` is the smallest infinite cardinal, also known as ℵ₀. -/
def omega : cardinal.{u} := lift (mk ℕ)
lemma mk_nat : mk nat = omega := (lift_id _).symm
theorem omega_ne_zero : omega ≠ 0 :=
ne_zero_iff_nonempty.2 ⟨⟨0⟩⟩
theorem omega_pos : 0 < omega :=
pos_iff_ne_zero.2 omega_ne_zero
@[simp] theorem lift_omega : lift omega = omega := lift_lift _
/- properties about the cast from nat -/
@[simp] theorem mk_fin : ∀ (n : ℕ), mk (fin n) = n
| 0 := quotient.sound ⟨(equiv.pempty_of_not_nonempty $ λ ⟨h⟩, h.elim0)⟩
| (n+1) := by rw [nat.cast_succ, ← mk_fin]; exact
quotient.sound (fintype.card_eq.1 $ by simp)
@[simp] theorem lift_nat_cast (n : ℕ) : lift n = n :=
by induction n; simp *
lemma lift_eq_nat_iff {a : cardinal.{u}} {n : ℕ} : lift.{u v} a = n ↔ a = n :=
by rw [← lift_nat_cast.{u v} n, lift_inj]
lemma nat_eq_lift_eq_iff {n : ℕ} {a : cardinal.{u}} :
(n : cardinal) = lift.{u v} a ↔ (n : cardinal) = a :=
by rw [← lift_nat_cast.{u v} n, lift_inj]
theorem lift_mk_fin (n : ℕ) : lift (mk (fin n)) = n := by simp
theorem fintype_card (α : Type u) [fintype α] : mk α = fintype.card α :=
by rw [← lift_mk_fin.{u}, ← lift_id (mk α), lift_mk_eq.{u 0 u}];
exact fintype.card_eq.1 (by simp)
theorem card_le_of_finset {α} (s : finset α) :
(s.card : cardinal) ≤ cardinal.mk α :=
begin
rw (_ : (s.card : cardinal) = cardinal.mk (↑s : set α)),
{ exact ⟨function.embedding.subtype _⟩ },
rw [cardinal.fintype_card, fintype.card_coe]
end
@[simp, move_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n :=
by induction n; simp [nat.pow_succ, -_root_.add_comm, power_add, *]
@[simp, elim_cast] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n :=
by rw [← lift_mk_fin, ← lift_mk_fin, lift_le]; exact
⟨λ ⟨⟨f, hf⟩⟩, begin
have : _ = fintype.card _ := finset.card_image_of_injective finset.univ hf,
simp at this,
rw [← fintype.card_fin n, ← this],
exact finset.card_le_of_subset (finset.subset_univ _)
end,
λ h, ⟨⟨λ i, ⟨i.1, lt_of_lt_of_le i.2 h⟩, λ a b h,
have _, from fin.veq_of_eq h, fin.eq_of_veq this⟩⟩⟩
@[simp, elim_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n :=
by simp [lt_iff_le_not_le, -not_le]
@[simp, elim_cast] theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n :=
by simp [le_antisymm_iff]
@[simp, elim_cast] theorem nat_succ (n : ℕ) : succ n = n.succ :=
le_antisymm (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _) (add_one_le_succ _)
@[simp] theorem succ_zero : succ 0 = 1 :=
by simpa using nat_succ 0
theorem cantor' (a) {b : cardinal} (hb : 1 < b) : a < b ^ a :=
by rw [← succ_le, (by simpa using nat_succ 1 : succ 1 = 2)] at hb;
exact lt_of_lt_of_le (cantor _) (power_le_power_right hb)
theorem one_le_iff_pos {c : cardinal} : 1 ≤ c ↔ 0 < c :=
by rw [← succ_zero, succ_le]
theorem one_le_iff_ne_zero {c : cardinal} : 1 ≤ c ↔ c ≠ 0 :=
by rw [one_le_iff_pos, pos_iff_ne_zero]
theorem nat_lt_omega (n : ℕ) : (n : cardinal.{u}) < omega :=
succ_le.1 $ by rw [nat_succ, ← lift_mk_fin, omega, lift_mk_le.{0 0 u}]; exact
⟨⟨fin.val, λ a b, fin.eq_of_veq⟩⟩
theorem one_lt_omega : 1 < omega :=
by simpa using nat_lt_omega 1
theorem lt_omega {c : cardinal.{u}} : c < omega ↔ ∃ n : ℕ, c = n :=
⟨λ h, begin
rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩,
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩,
suffices : finite S,
{ cases this, resetI,
existsi fintype.card S,
rw [← lift_nat_cast.{0 u}, lift_inj, fintype_card S] },
by_contra nf,
have P : ∀ (n : ℕ) (IH : ∀ i<n, S), ∃ a : S, ¬ ∃ y h, IH y h = a :=
λ n IH,
let g : {i | i < n} → S := λ ⟨i, h⟩, IH i h in
classical.not_forall.1 (λ h, nf
⟨fintype.of_surjective g (λ a, subtype.exists.2 (h a))⟩),
let F : ℕ → S := nat.lt_wf.fix (λ n IH, classical.some (P n IH)),
refine not_le_of_lt h' ⟨⟨F, _⟩⟩,
suffices : ∀ (n : ℕ) (m < n), F m ≠ F n,
{ refine λ m n, not_imp_not.1 (λ ne, _),
rcases lt_trichotomy m n with h|h|h,
{ exact this n m h },
{ contradiction },
{ exact (this m n h).symm } },
intros n m h,
have := classical.some_spec (P n (λ y _, F y)),
rw [← show F n = classical.some (P n (λ y _, F y)),
from nat.lt_wf.fix_eq (λ n IH, classical.some (P n IH)) n] at this,
exact λ e, this ⟨m, h, e⟩,
end, λ ⟨n, e⟩, e.symm ▸ nat_lt_omega _⟩
theorem omega_le {c : cardinal.{u}} : omega ≤ c ↔ ∀ n : ℕ, (n:cardinal) ≤ c :=
⟨λ h n, le_trans (le_of_lt (nat_lt_omega _)) h,
λ h, le_of_not_lt $ λ hn, begin
rcases lt_omega.1 hn with ⟨n, rfl⟩,
exact not_le_of_lt (nat.lt_succ_self _) (nat_cast_le.1 (h (n+1)))
end⟩
theorem lt_omega_iff_fintype {α : Type u} : mk α < omega ↔ nonempty (fintype α) :=
lt_omega.trans ⟨λ ⟨n, e⟩, begin
rw [← lift_mk_fin n] at e,
cases quotient.exact e with f,
exact ⟨fintype.of_equiv _ f.symm⟩
end, λ ⟨_⟩, by exactI ⟨_, fintype_card _⟩⟩
theorem lt_omega_iff_finite {α} {S : set α} : mk S < omega ↔ finite S :=
lt_omega_iff_fintype
instance can_lift_cardinal_nat : can_lift cardinal ℕ :=
⟨ coe, λ x, x < omega, λ x hx, let ⟨n, hn⟩ := lt_omega.mp hx in ⟨n, hn.symm⟩⟩
theorem add_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a + b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_omega
end
lemma add_lt_omega_iff {a b : cardinal} : a + b < omega ↔ a < omega ∧ b < omega :=
⟨λ h, ⟨lt_of_le_of_lt (le_add_right _ _) h, lt_of_le_of_lt (le_add_left _ _) h⟩,
λ⟨h1, h2⟩, add_lt_omega h1 h2⟩
theorem mul_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a * b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_mul]; apply nat_lt_omega
end
lemma mul_lt_omega_iff {a b : cardinal} : a * b < omega ↔ a = 0 ∨ b = 0 ∨ a < omega ∧ b < omega :=
begin
split,
{ intro h, by_cases ha : a = 0, { left, exact ha },
right, by_cases hb : b = 0, { left, exact hb },
right, rw [← ne, ← one_le_iff_ne_zero] at ha hb, split,
{ rw [← mul_one a], refine lt_of_le_of_lt (mul_le_mul (le_refl a) hb) h },
{ rw [← _root_.one_mul b], refine lt_of_le_of_lt (mul_le_mul ha (le_refl b)) h }},
rintro (rfl|rfl|⟨ha,hb⟩); simp only [*, mul_lt_omega, omega_pos, _root_.zero_mul, mul_zero]
end
lemma mul_lt_omega_iff_of_ne_zero {a b : cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < omega ↔ a < omega ∧ b < omega :=
by simp [mul_lt_omega_iff, ha, hb]
theorem power_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a ^ b < omega :=
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_pow]; apply nat_lt_omega
end
theorem infinite_iff {α : Type u} : infinite α ↔ omega ≤ mk α :=
by rw [←not_lt, lt_omega_iff_fintype, not_nonempty_fintype]
lemma countable_iff (s : set α) : countable s ↔ mk s ≤ omega :=
begin
rw [countable_iff_exists_injective], split,
rintro ⟨f, hf⟩, exact ⟨embedding.trans ⟨f, hf⟩ equiv.ulift.symm.to_embedding⟩,
rintro ⟨f'⟩, cases embedding.trans f' equiv.ulift.to_embedding with f hf, exact ⟨f, hf⟩
end
lemma denumerable_iff {α : Type u} : nonempty (denumerable α) ↔ mk α = omega :=
⟨λ⟨h⟩, quotient.sound $ by exactI ⟨ (denumerable.eqv α).trans equiv.ulift.symm ⟩,
λ h, by { cases quotient.exact h with f, exact ⟨denumerable.mk' $ f.trans equiv.ulift⟩ }⟩
lemma mk_int : mk ℤ = omega :=
denumerable_iff.mp ⟨by apply_instance⟩
lemma mk_pnat : mk ℕ+ = omega :=
denumerable_iff.mp ⟨by apply_instance⟩
lemma two_le_iff : (2 : cardinal) ≤ mk α ↔ ∃x y : α, x ≠ y :=
begin
split,
{ rintro ⟨f⟩, refine ⟨f $ sum.inl ⟨⟩, f $ sum.inr ⟨⟩, _⟩, intro h, cases f.2 h },
{ rintro ⟨x, y, h⟩, by_contra h',
rw [not_le, ←nat.cast_two, ←nat_succ, lt_succ, nat.cast_one, le_one_iff_subsingleton] at h',
apply h, exactI subsingleton.elim _ _ }
end
lemma two_le_iff' (x : α) : (2 : cardinal) ≤ mk α ↔ ∃y : α, x ≠ y :=
begin
rw [two_le_iff],
split,
{ rintro ⟨y, z, h⟩, refine classical.by_cases (λ(h' : x = y), _) (λ h', ⟨y, h'⟩),
rw [←h'] at h, exact ⟨z, h⟩ },
{ rintro ⟨y, h⟩, exact ⟨x, y, h⟩ }
end
/-- König's theorem -/
theorem sum_lt_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i < g i) : sum f < prod g :=
lt_of_not_ge $ λ ⟨F⟩, begin
have : inhabited (Π (i : ι), (g i).out),
{ refine ⟨λ i, classical.choice $ ne_zero_iff_nonempty.1 _⟩,
rw mk_out,
exact ne_of_gt (lt_of_le_of_lt (zero_le _) (H i)) }, resetI,
let G := inv_fun F,
have sG : surjective G := inv_fun_surjective F.2,
choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b,
{ assume i,
simp only [- not_exists, not_exists.symm, classical.not_forall.symm],
refine λ h, not_le_of_lt (H i) _,
rw [← mk_out (f i), ← mk_out (g i)],
exact ⟨embedding.of_surjective h⟩ },
exact (let ⟨⟨i, a⟩, h⟩ := sG C in hc i a (congr_fun h _))
end
@[simp] theorem mk_empty : mk empty = 0 :=
fintype_card empty
@[simp] theorem mk_pempty : mk pempty = 0 :=
fintype_card pempty
@[simp] theorem mk_plift_of_false {p : Prop} (h : ¬ p) : mk (plift p) = 0 :=
quotient.sound ⟨equiv.plift.trans $ equiv.equiv_pempty h⟩
@[simp] theorem mk_unit : mk unit = 1 :=
(fintype_card unit).trans nat.cast_one
@[simp] theorem mk_punit : mk punit = 1 :=
(fintype_card punit).trans nat.cast_one
@[simp] theorem mk_singleton {α : Type u} (x : α) : mk ({x} : set α) = 1 :=
quotient.sound ⟨equiv.set.singleton x⟩
@[simp] theorem mk_plift_of_true {p : Prop} (h : p) : mk (plift p) = 1 :=
quotient.sound ⟨equiv.plift.trans $ equiv.prop_equiv_punit h⟩
@[simp] theorem mk_bool : mk bool = 2 :=
quotient.sound ⟨equiv.bool_equiv_punit_sum_punit⟩
@[simp] theorem mk_Prop : mk Prop = 2 :=
(quotient.sound ⟨equiv.Prop_equiv_bool⟩ : mk Prop = mk bool).trans mk_bool
@[simp] theorem mk_option {α : Type u} : mk (option α) = mk α + 1 :=
quotient.sound ⟨equiv.option_equiv_sum_punit α⟩
theorem mk_list_eq_sum_pow (α : Type u) : mk (list α) = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) :=
calc mk (list α)
= mk (Σ n, vector α n) : quotient.sound ⟨(equiv.sigma_preimage_equiv list.length).symm⟩
... = mk (Σ n, fin n → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n,
⟨vector.nth, vector.of_fn, vector.of_fn_nth, λ f, funext $ vector.nth_of_fn f⟩⟩
... = mk (Σ n : ℕ, ulift.{u} (fin n) → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n,
equiv.arrow_congr equiv.ulift.symm (equiv.refl α)⟩
... = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) : by simp only [(lift_mk_fin _).symm, lift_mk, power_def, sum_mk]
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : mk (quot r) ≤ mk α :=
mk_le_of_surjective quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : setoid α} : mk (quotient s) ≤ mk α :=
mk_quot_le
theorem mk_subtype_le {α : Type u} (p : α → Prop) : mk (subtype p) ≤ mk α :=
⟨embedding.subtype p⟩
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
mk (subtype p) ≤ mk (subtype q) :=
⟨embedding.subtype_map (embedding.refl α) h⟩
@[simp] theorem mk_emptyc (α : Type u) : mk (∅ : set α) = 0 :=
quotient.sound ⟨equiv.set.pempty α⟩
theorem mk_univ {α : Type u} : mk (@univ α) = mk α :=
quotient.sound ⟨equiv.set.univ α⟩
theorem mk_image_le {α β : Type u} {f : α → β} {s : set α} : mk (f '' s) ≤ mk s :=
mk_le_of_surjective surjective_onto_image
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : set α} :
lift.{v u} (mk (f '' s)) ≤ lift.{u v} (mk s) :=
lift_mk_le.{v u 0}.mpr ⟨embedding.of_surjective surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : mk (range f) ≤ mk α :=
mk_le_of_surjective surjective_onto_range
lemma mk_range_eq (f : α → β) (h : injective f) : mk (range f) = mk α :=
quotient.sound ⟨(equiv.set.range f h).symm⟩
lemma mk_range_eq_of_inj {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{v u} (mk (range f)) = lift.{u v} (mk α) :=
begin
have := (@lift_mk_eq.{v u max u v} (range f) α).2 ⟨(equiv.set.range f hf).symm⟩,
simp only [lift_umax.{u v}, lift_umax.{v u}] at this,
exact this
end
lemma mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : injective f) :
lift.{v (max u w)} (# (range f)) = lift.{u (max v w)} (# α) :=
lift_mk_eq.mpr ⟨(equiv.set.range f hf).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : set α} (hf : injective f) :
mk (f '' s) = mk s :=
quotient.sound ⟨(equiv.set.image f s hf).symm⟩
theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : mk (⋃ i, f i) ≤ sum (λ i, mk (f i)) :=
calc mk (⋃ i, f i) ≤ mk (Σ i, f i) : mk_le_of_surjective (set.surjective_sigma_to_Union f)
... = sum (λ i, mk (f i)) : (sum_mk _).symm
theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) :
mk (⋃ i, f i) = sum (λ i, mk (f i)) :=
calc mk (⋃ i, f i) = mk (Σi, f i) : quot.sound ⟨set.Union_eq_sigma_of_disjoint h⟩
... = sum (λi, mk (f i)) : (sum_mk _).symm
lemma mk_Union_le {α ι : Type u} (f : ι → set α) :
mk (⋃ i, f i) ≤ mk ι * cardinal.sup.{u u} (λ i, mk (f i)) :=
le_trans mk_Union_le_sum_mk (sum_le_sup _)
lemma mk_sUnion_le {α : Type u} (A : set (set α)) :
mk (⋃₀ A) ≤ mk A * cardinal.sup.{u u} (λ s : A, mk s) :=
by { rw [sUnion_eq_Union], apply mk_Union_le }
lemma mk_bUnion_le {ι α : Type u} (A : ι → set α) (s : set ι) :
mk (⋃(x ∈ s), A x) ≤ mk s * cardinal.sup.{u u} (λ x : s, mk (A x.1)) :=
by { rw [bUnion_eq_Union], apply mk_Union_le }
@[simp] lemma finset_card {α : Type u} {s : finset α} : ↑(finset.card s) = mk (↑s : set α) :=
by rw [fintype_card, nat_cast_inj, fintype.card_coe]
lemma finset_card_lt_omega (s : finset α) : mk (↑s : set α) < omega :=
by { rw [lt_omega_iff_fintype], exact ⟨finset.subtype.fintype s⟩ }
theorem mk_union_add_mk_inter {α : Type u} {S T : set α} : mk (S ∪ T : set α) + mk (S ∩ T : set α) = mk S + mk T :=
quot.sound ⟨equiv.set.union_sum_inter S T⟩
theorem mk_union_of_disjoint {α : Type u} {S T : set α} (H : disjoint S T) : mk (S ∪ T : set α) = mk S + mk T :=
quot.sound ⟨equiv.set.union (disjoint_iff.1 H)⟩
lemma mk_sum_compl {α} (s : set α) : #s + #(-s : set α) = #α :=
quotient.sound ⟨equiv.set.sum_compl s⟩
lemma mk_le_mk_of_subset {α} {s t : set α} (h : s ⊆ t) : mk s ≤ mk t :=
⟨ set.embedding_of_subset h ⟩
lemma mk_subtype_mono {p q : α → Prop} (h : ∀x, p x → q x) : mk {x // p x} ≤ mk {x // q x} :=
⟨embedding_of_subset h⟩
lemma mk_set_le (s : set α) : mk s ≤ mk α :=
mk_subtype_le s
lemma mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : injective f) :
lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image f s h).symm⟩
lemma mk_image_eq_of_inj_on_lift {α : Type u} {β : Type v} (f : α → β) (s : set α)
(h : inj_on f s) : lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) :=
lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image_of_inj_on f s h).symm⟩
lemma mk_image_eq_of_inj_on {α β : Type u} (f : α → β) (s : set α) (h : inj_on f s) :
mk (f '' s) = mk s :=
quotient.sound ⟨(equiv.set.image_of_inj_on f s h).symm⟩
lemma mk_subtype_of_equiv {α β : Type u} (p : α → Prop) (e : α ≃ β) :
mk {a : α // p a} = mk {b : β // p (e.symm b)} :=
quotient.sound ⟨equiv.subtype_equiv_of_subtype' e⟩
lemma mk_sep (s : set α) (t : α → Prop) : mk ({ x ∈ s | t x } : set α) = mk { x : s | t x.1 } :=
quotient.sound ⟨equiv.set.sep s t⟩
lemma mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : injective f) : lift.{u v} (mk (f ⁻¹' s)) ≤ lift.{v u} (mk s) :=
begin
rw lift_mk_le.{u v 0}, use subtype.coind (λ x, f x.1) (λ x, x.2),
apply subtype.coind_injective, exact injective_comp h subtype.val_injective
end
lemma mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : set β)
(h : s ⊆ range f) : lift.{v u} (mk s) ≤ lift.{u v} (mk (f ⁻¹' s)) :=
begin
rw lift_mk_le.{v u 0},
refine ⟨⟨_, _⟩⟩,
{ rintro ⟨y, hy⟩, rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩, exact ⟨x, hy⟩ },
rintro ⟨y, hy⟩ ⟨y', hy'⟩, dsimp,
rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩,
rcases classical.subtype_of_exists (h hy') with ⟨x', rfl⟩,
simp, intro hxx', rw hxx'
end
lemma mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : lift.{u v} (mk (f ⁻¹' s)) = lift.{v u} (mk s) :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
lemma mk_preimage_of_injective (f : α → β) (s : set β) (h : injective f) :
mk (f ⁻¹' s) ≤ mk s :=
by { convert mk_preimage_of_injective_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_subset_range (f : α → β) (s : set β)
(h : s ⊆ range f) : mk s ≤ mk (f ⁻¹' s) :=
by { convert mk_preimage_of_subset_range_lift.{u u} f s h using 1; rw [lift_id] }
lemma mk_preimage_of_injective_of_subset_range (f : α → β) (s : set β)
(h : injective f) (h2 : s ⊆ range f) : mk (f ⁻¹' s) = mk s :=
by { convert mk_preimage_of_injective_of_subset_range_lift.{u u} f s h h2 using 1; rw [lift_id] }
lemma mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : set α}
{t : set β} (h : t ⊆ f '' s) :
lift.{v u} (mk t) ≤ lift.{u v} (mk ({ x ∈ s | f x ∈ t } : set α)) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range_lift _ _ h using 1, rw [mk_sep], refl }
lemma mk_subset_ge_of_subset_image (f : α → β) {s : set α} {t : set β} (h : t ⊆ f '' s) :
mk t ≤ mk ({ x ∈ s | f x ∈ t } : set α) :=
by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range _ _ h using 1, rw [mk_sep], refl }
theorem le_mk_iff_exists_subset {c : cardinal} {α : Type u} {s : set α} :
c ≤ mk s ↔ ∃ p : set α, p ⊆ s ∧ mk p = c :=
begin
rw [le_mk_iff_exists_set, ←subtype.exists_set_subtype],
apply exists_congr, intro t, rw [mk_image_eq], apply subtype.val_injective
end
/-- The function α^{<β}, defined to be sup_{γ < β} α^γ.
We index over {s : set β.out // mk s < β } instead of {γ // γ < β}, because the latter lives in a
higher universe -/
noncomputable def powerlt (α β : cardinal.{u}) : cardinal.{u} :=
sup.{u u} (λ(s : {s : set β.out // mk s < β}), α ^ mk.{u} s)
infix ` ^< `:80 := powerlt
theorem powerlt_aux {c c' : cardinal} (h : c < c') :
∃(s : {s : set c'.out // mk s < c'}), mk s = c :=
begin
cases out_embedding.mp (le_of_lt h) with f,
have : mk ↥(range ⇑f) = c, { rwa [mk_range_eq, mk, quotient.out_eq c], exact f.2 },
exact ⟨⟨range f, by convert h⟩, this⟩
end
lemma le_powerlt {c₁ c₂ c₃ : cardinal} (h : c₂ < c₃) : c₁ ^ c₂ ≤ c₁ ^< c₃ :=
by { rcases powerlt_aux h with ⟨s, rfl⟩, apply le_sup _ s }
lemma powerlt_le {c₁ c₂ c₃ : cardinal} : c₁ ^< c₂ ≤ c₃ ↔ ∀(c₄ < c₂), c₁ ^ c₄ ≤ c₃ :=
begin
rw [powerlt, sup_le],
split,
{ intros h c₄ hc₄, rcases powerlt_aux hc₄ with ⟨s, rfl⟩, exact h s },
intros h s, exact h _ s.2
end
lemma powerlt_le_powerlt_left {a b c : cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
by { rw [powerlt, sup_le], rintro ⟨s, hs⟩, apply le_powerlt, exact lt_of_lt_of_le hs h }
lemma powerlt_succ {c₁ c₂ : cardinal} (h : c₁ ≠ 0) : c₁ ^< c₂.succ = c₁ ^ c₂ :=
begin
apply le_antisymm,
{ rw powerlt_le, intros c₃ h2, apply power_le_power_left h, rwa [←lt_succ] },
{ apply le_powerlt, apply lt_succ_self }
end
lemma powerlt_max {c₁ c₂ c₃ : cardinal} : c₁ ^< max c₂ c₃ = max (c₁ ^< c₂) (c₁ ^< c₃) :=
by { cases le_total c₂ c₃; simp only [max_eq_left, max_eq_right, h, powerlt_le_powerlt_left] }
lemma zero_powerlt {a : cardinal} (h : a ≠ 0) : 0 ^< a = 1 :=
begin
apply le_antisymm,
{ rw [powerlt_le], intros c hc, apply zero_power_le },
convert le_powerlt (pos_iff_ne_zero.2 h), rw [power_zero]
end
lemma powerlt_zero {a : cardinal} : a ^< 0 = 0 :=
by { apply sup_eq_zero, rintro ⟨x, hx⟩, rw [←not_le] at hx, apply hx, apply zero_le }
end cardinal
|
784df897d139e7e8ccca11c043664cc3b5628afa | 5fbbd711f9bfc21ee168f46a4be146603ece8835 | /lean/natural_number_game/advanced_multiplication/2.lean | d545313e7e24eb2139b97528132bd8edbe534d0a | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | goedel-gang/maths | 22596f71e3fde9c088e59931f128a3b5efb73a2c | a20a6f6a8ce800427afd595c598a5ad43da1408d | refs/heads/master | 1,623,055,941,960 | 1,621,599,441,000 | 1,621,599,441,000 | 169,335,840 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 266 | lean | theorem eq_zero_or_eq_zero_of_mul_eq_zero (a b : mynat) (h : a * b = 0) :
a = 0 ∨ b = 0 :=
begin
cases a with n hn,
left,
cc,
cases b with m hm,
right,
cc,
have g := mul_pos (succ n) (succ m) (succ_ne_zero n) (succ_ne_zero m),
exfalso,
cc,
end
|
8098430ea85fc9af8334bb226b14e2f7e36107f0 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/PatternVar.lean | 29854a4ed43be321c3410bbf346a48e9352cc9a1 | [
"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 | 13,717 | 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.Meta.Match.MatchPatternAttr
import Lean.Elab.Arg
import Lean.Elab.MatchAltView
namespace Lean.Elab.Term
open Meta
abbrev PatternVar := Syntax -- TODO: should be `Ident`
/-!
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 `[match_pattern]` attribute
- Identifiers
- Anonymous constructors
- Structure instances
- Inaccessible terms
- Named patterns
- Tuple literals
- Type ascriptions
- Literals: num, string and char
-/
namespace CollectPatternVars
/-- State for the pattern variable collector monad. -/
structure State where
/-- Pattern variables found so far. -/
found : NameSet := {}
/-- Pattern variables found so far as an array. It contains the order they were found. -/
vars : Array PatternVar := #[]
deriving Inhabited
abbrev M := StateRefT State TermElabM
private def throwCtorExpected {α} : M α :=
throwError "invalid pattern, constructor or constant marked with '[match_pattern]' expected"
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 `[match_pattern]`.
The elaborator assumes implicit arguments are not accessible and explicit ones are accessible.
-/
structure Context where
funId : Ident
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 Term := #[]
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 `[match_pattern]` 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 idStx, found := s.found.insert id }
return idStx
private def samePatternsVariables (startingAt : Nat) (s₁ s₂ : State) : Bool :=
if h : s₁.vars.size = s₂.vars.size then
Array.isEqvAux s₁.vars s₂.vars h (.==.) startingAt
else
false
open TSyntax.Compat in
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.dotIdent then
return stx
else if k == ``Lean.Parser.Term.hole then
`(.( $stx ))
else if k == ``Lean.Parser.Term.syntheticHole then
`(.( $stx ))
else if k == ``Lean.Parser.Term.typeAscription then
-- Ignore type term
let t := stx[1]
let t ← collect t
return stx.setArg 1 t
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 "@" >> optional (atomic (ident >> ":")) >> termParser
```
TODO: pattern variable for equality proof
-/
let id := stx[0]
discard <| processVar id
let h ← if stx[2].isNone then
`(h)
else
pure stx[2][0]
let pat := stx[3]
let pat ← collect pat
discard <| processVar h
``(_root_.namedPattern $id $pat $h)
else if k == ``Lean.Parser.Term.binop then
let lhs ← collect stx[2]
let rhs ← collect stx[3]
return stx.setArg 2 lhs |>.setArg 3 rhs
else if k == ``Lean.Parser.Term.unop then
let arg ← collect stx[2]
return stx.setArg 2 arg
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 || k == ``Lean.Parser.Term.doubleQuotedName then
return stx
else if k == choiceKind then
/- Remark: If there are `Term.structInst` alternatives, we keep only them. This is a hack to get rid of
Set-like notation in patterns. Recall that in Mathlib `{a, b}` can be a set with two elements or the
structure instance `{ a := a, b := b }`. Possible alternative solution: add a `pattern` category, or at least register
the `Syntax` node kinds that are allowed in patterns. -/
let args :=
let args := stx.getArgs
if args.any (·.isOfKind ``Parser.Term.structInst) then
args.filter (·.isOfKind ``Parser.Term.structInst)
else
args
let stateSaved ← get
let arg0 ← collect args[0]!
let stateNew ← get
let mut argsNew := #[arg0]
for arg in args[1:] do
set stateSaved
argsNew := argsNew.push (← collect arg)
unless samePatternsVariables stateSaved.vars.size stateNew (← get) do
throwError "invalid pattern, overloaded notation is only allowed when all alternative have the same set of pattern variables"
set stateNew
return mkNode choiceKind argsNew
else match stx with
| `({ $[$srcs?,* with]? $fields,* $[..%$ell?]? $[: $ty?]? }) =>
if let some srcs := srcs? then
throwErrorAt (mkNullNode srcs) "invalid struct instance pattern, 'with' is not allowed in patterns"
let fields ← fields.getElems.mapM fun
| `(Parser.Term.structInstField| $lval:structInstLVal := $val) => do
let newVal ← collect val
`(Parser.Term.structInstField| $lval:structInstLVal := $newVal)
| _ => throwInvalidPattern -- `structInstFieldAbbrev` should be expanded at this point
`({ $[$srcs?,* with]? $fields,* $[..%$ell?]? $[: $ty?]? })
| _ => throwInvalidPattern
where
processCtorApp (stx : Syntax) : M Syntax := do
let (f, namedArgs, args, ellipsis) ← expandApp stx
if f.getKind == ``Parser.Term.dotIdent then
let namedArgsNew ← namedArgs.mapM fun
| { ref, name, val := Arg.stx arg } => withRef ref do `(Lean.Parser.Term.namedArgument| ($(mkIdentFrom ref name) := $(← collect arg)))
| _ => unreachable!
let mut argsNew ← args.mapM fun | Arg.stx arg => collect arg | _ => unreachable!
if ellipsis then
argsNew := argsNew.push (mkNode ``Parser.Term.ellipsis #[mkAtomFrom stx ".."])
return Syntax.mkApp f (namedArgsNew ++ argsNew)
else
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 `[match_pattern]` 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.strictImplicit => 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" (withInfo := true) | 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
/--
Collect pattern variables occurring in the `match`-alternative object views.
It also returns the updated views.
-/
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 by the main `match` elaborator, but in the precheck hook and 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
/--
Return the pattern variables occurring in the given patterns.
This method is used in the `match` and `do` notation elaborators
-/
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
def getPatternVarNames (pvars : Array PatternVar) : Array Name :=
pvars.map fun x => x.getId
end Lean.Elab.Term
|
2b1708ce570d1d74f647f91016b55f33a3fe5055 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/limits/constructions/over/products_auto.lean | bc698438d78bb8cdab9f3efc12ebca911efaa324 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,920 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.over
import Mathlib.category_theory.limits.shapes.pullbacks
import Mathlib.category_theory.limits.shapes.wide_pullbacks
import Mathlib.category_theory.limits.shapes.finite_products
import Mathlib.PostPort
universes v u
namespace Mathlib
/-!
# Products in the over category
Shows that products in the over category can be derived from wide pullbacks in the base category.
The main result is `over_product_of_wide_pullback`, which says that if `C` has `J`-indexed wide
pullbacks, then `over B` has `J`-indexed products.
-/
namespace category_theory.over
namespace construct_products
/--
(Implementation)
Given a product diagram in `C/B`, construct the corresponding wide pullback diagram
in `C`.
-/
def wide_pullback_diagram_of_diagram_over {C : Type u} [category C] (B : C) {J : Type v}
(F : discrete J ⥤ over B) : limits.wide_pullback_shape J ⥤ C :=
limits.wide_pullback_shape.wide_cospan B (fun (j : J) => comma.left (functor.obj F j))
fun (j : J) => comma.hom (functor.obj F j)
/-- (Impl) A preliminary definition to avoid timeouts. -/
def cones_equiv_inverse_obj {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B)
(c : limits.cone F) : limits.cone (wide_pullback_diagram_of_diagram_over B F) :=
limits.cone.mk (comma.left (limits.cone.X c))
(nat_trans.mk
fun (X : limits.wide_pullback_shape J) =>
option.cases_on X (comma.hom (limits.cone.X c))
fun (j : J) => comma_morphism.left (nat_trans.app (limits.cone.π c) j))
/-- (Impl) A preliminary definition to avoid timeouts. -/
def cones_equiv_inverse {C : Type u} [category C] (B : C) {J : Type v} (F : discrete J ⥤ over B) :
limits.cone F ⥤ limits.cone (wide_pullback_diagram_of_diagram_over B F) :=
functor.mk (cones_equiv_inverse_obj B F)
fun (c₁ c₂ : limits.cone F) (f : c₁ ⟶ c₂) =>
limits.cone_morphism.mk (comma_morphism.left (limits.cone_morphism.hom f))
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] theorem cones_equiv_functor_map_hom {C : Type u} [category C] (B : C) {J : Type v}
(F : discrete J ⥤ over B) (c₁ : limits.cone (wide_pullback_diagram_of_diagram_over B F))
(c₂ : limits.cone (wide_pullback_diagram_of_diagram_over B F)) (f : c₁ ⟶ c₂) :
limits.cone_morphism.hom (functor.map (cones_equiv_functor B F) f) =
hom_mk (limits.cone_morphism.hom f) :=
Eq.refl (limits.cone_morphism.hom (functor.map (cones_equiv_functor B F) f))
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] def cones_equiv_unit_iso {J : Type v} {C : Type u} [category C] (B : C)
(F : discrete J ⥤ over B) : 𝟭 ≅ cones_equiv_functor B F ⋙ cones_equiv_inverse B F :=
nat_iso.of_components
(fun (_x : limits.cone (wide_pullback_diagram_of_diagram_over B F)) =>
limits.cones.ext (iso.mk 𝟙 𝟙) sorry)
sorry
/-- (Impl) A preliminary definition to avoid timeouts. -/
@[simp] def cones_equiv_counit_iso {J : Type v} {C : Type u} [category C] (B : C)
(F : discrete J ⥤ over B) : cones_equiv_inverse B F ⋙ cones_equiv_functor B F ≅ 𝟭 :=
nat_iso.of_components
(fun (_x : limits.cone F) => limits.cones.ext (iso.mk (hom_mk 𝟙) (hom_mk 𝟙)) sorry) sorry
-- TODO: Can we add `. obviously` to the second arguments of `nat_iso.of_components` and
-- `cones.ext`?
/--
(Impl) Establish an equivalence between the category of cones for `F` and for the "grown" `F`.
-/
@[simp] theorem cones_equiv_unit_iso_2 {J : Type v} {C : Type u} [category C] (B : C)
(F : discrete J ⥤ over B) : equivalence.unit_iso (cones_equiv B F) = cones_equiv_unit_iso B F :=
Eq.refl (equivalence.unit_iso (cones_equiv B F))
/-- Use the above equivalence to prove we have a limit. -/
theorem has_over_limit_discrete_of_wide_pullback_limit {J : Type v} {C : Type u} [category C]
{B : C} (F : discrete J ⥤ over B)
[limits.has_limit (wide_pullback_diagram_of_diagram_over B F)] : limits.has_limit F :=
sorry
/-- Given a wide pullback in `C`, construct a product in `C/B`. -/
theorem over_product_of_wide_pullback {J : Type v} {C : Type u} [category C]
[limits.has_limits_of_shape (limits.wide_pullback_shape J) C] {B : C} :
limits.has_limits_of_shape (discrete J) (over B) :=
limits.has_limits_of_shape.mk
fun (F : discrete J ⥤ over B) => has_over_limit_discrete_of_wide_pullback_limit F
/-- Given a pullback in `C`, construct a binary product in `C/B`. -/
theorem over_binary_product_of_pullback {C : Type u} [category C] [limits.has_pullbacks C] {B : C} :
limits.has_binary_products (over B) :=
over_product_of_wide_pullback
/-- Given all wide pullbacks in `C`, construct products in `C/B`. -/
theorem over_products_of_wide_pullbacks {C : Type u} [category C] [limits.has_wide_pullbacks C]
{B : C} : limits.has_products (over B) :=
fun (J : Type v) => over_product_of_wide_pullback
/-- Given all finite wide pullbacks in `C`, construct finite products in `C/B`. -/
theorem over_finite_products_of_finite_wide_pullbacks {C : Type u} [category C]
[limits.has_finite_wide_pullbacks C] {B : C} : limits.has_finite_products (over B) :=
fun (J : Type v) (𝒥₁ : DecidableEq J) (𝒥₂ : fintype J) => over_product_of_wide_pullback
end construct_products
/--
Construct terminal object in the over category. This isn't an instance as it's not typically the
way we want to define terminal objects.
(For instance, this gives a terminal object which is different from the generic one given by
`over_product_of_wide_pullback` above.)
-/
theorem over_has_terminal {C : Type u} [category C] (B : C) : limits.has_terminal (over B) := sorry
end Mathlib |
6670ec162a75de9f41eda9d49b00945b3d360c0e | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/polynomial/expand.lean | 85f7d0a63c6a959fb0efd656b3a0295c0fb69e92 | [
"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 | 9,954 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import ring_theory.polynomial.basic
import ring_theory.ideal.local_ring
import tactic.ring_exp
/-!
# Expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
## Main definitions
* `polynomial.expand R p f`: expand the polynomial `f` with coefficients in a
commutative semiring `R` by a factor of p, so `expand R p (∑ aₙ xⁿ)` is `∑ aₙ xⁿᵖ`.
* `polynomial.contract p f`: the opposite of `expand`, so it sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`.
-/
universes u v w
open_locale classical big_operators polynomial
open finset
namespace polynomial
section comm_semiring
variables (R : Type u) [comm_semiring R] {S : Type v} [comm_semiring S] (p q : ℕ)
/-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/
noncomputable def expand : R[X] →ₐ[R] R[X] :=
{ commutes' := λ r, eval₂_C _ _,
.. (eval₂_ring_hom C (X ^ p) : R[X] →+* R[X]) }
lemma coe_expand : (expand R p : R[X] → R[X]) = eval₂ C (X ^ p) := rfl
variables {R}
lemma expand_eq_sum {f : R[X]} :
expand R p f = f.sum (λ e a, C a * (X ^ p) ^ e) :=
by { dsimp [expand, eval₂], refl, }
@[simp] lemma expand_C (r : R) : expand R p (C r) = C r := eval₂_C _ _
@[simp] lemma expand_X : expand R p X = X ^ p := eval₂_X _ _
@[simp] lemma expand_monomial (r : R) : expand R p (monomial q r) = monomial (q * p) r :=
by simp_rw [monomial_eq_smul_X, alg_hom.map_smul, alg_hom.map_pow, expand_X, mul_comm, pow_mul]
theorem expand_expand (f : R[X]) : expand R p (expand R q f) = expand R (p * q) f :=
polynomial.induction_on f (λ r, by simp_rw expand_C)
(λ f g ihf ihg, by simp_rw [alg_hom.map_add, ihf, ihg])
(λ n r ih, by simp_rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X,
alg_hom.map_pow, expand_X, pow_mul])
theorem expand_mul (f : R[X]) : expand R (p * q) f = expand R p (expand R q f) :=
(expand_expand p q f).symm
@[simp] theorem expand_zero (f : R[X]) : expand R 0 f = C (eval 1 f) :=
by simp [expand]
@[simp] theorem expand_one (f : R[X]) : expand R 1 f = f :=
polynomial.induction_on f
(λ r, by rw expand_C)
(λ f g ihf ihg, by rw [alg_hom.map_add, ihf, ihg])
(λ n r ih, by rw [alg_hom.map_mul, expand_C, alg_hom.map_pow, expand_X, pow_one])
theorem expand_pow (f : R[X]) : expand R (p ^ q) f = (expand R p ^[q] f) :=
nat.rec_on q (by rw [pow_zero, expand_one, function.iterate_zero, id]) $ λ n ih,
by rw [function.iterate_succ_apply', pow_succ, expand_mul, ih]
theorem derivative_expand (f : R[X]) :
(expand R p f).derivative = expand R p f.derivative * (p * X ^ (p - 1)) :=
by rw [coe_expand, derivative_eval₂_C, derivative_pow, derivative_X, mul_one]
theorem coeff_expand {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) :
(expand R p f).coeff n = if p ∣ n then f.coeff (n / p) else 0 :=
begin
simp only [expand_eq_sum],
simp_rw [coeff_sum, ← pow_mul, C_mul_X_pow_eq_monomial, coeff_monomial, sum],
split_ifs with h,
{ rw [finset.sum_eq_single (n/p), nat.mul_div_cancel' h, if_pos rfl],
{ intros b hb1 hb2, rw if_neg, intro hb3, apply hb2, rw [← hb3, nat.mul_div_cancel_left b hp] },
{ intro hn, rw not_mem_support_iff.1 hn, split_ifs; refl } },
{ rw finset.sum_eq_zero, intros k hk, rw if_neg, exact λ hkn, h ⟨k, hkn.symm⟩, },
end
@[simp] theorem coeff_expand_mul {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) :
(expand R p f).coeff (n * p) = f.coeff n :=
by rw [coeff_expand hp, if_pos (dvd_mul_left _ _), nat.mul_div_cancel _ hp]
@[simp] theorem coeff_expand_mul' {p : ℕ} (hp : 0 < p) (f : R[X]) (n : ℕ) :
(expand R p f).coeff (p * n) = f.coeff n :=
by rw [mul_comm, coeff_expand_mul hp]
theorem expand_inj {p : ℕ} (hp : 0 < p) {f g : R[X]} :
expand R p f = expand R p g ↔ f = g :=
⟨λ H, ext $ λ n, by rw [← coeff_expand_mul hp, H, coeff_expand_mul hp], congr_arg _⟩
theorem expand_eq_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f = 0 ↔ f = 0 :=
by rw [← (expand R p).map_zero, expand_inj hp, alg_hom.map_zero]
theorem expand_ne_zero {p : ℕ} (hp : 0 < p) {f : R[X]} : expand R p f ≠ 0 ↔ f ≠ 0 :=
(expand_eq_zero hp).not
theorem expand_eq_C {p : ℕ} (hp : 0 < p) {f : R[X]} {r : R} :
expand R p f = C r ↔ f = C r :=
by rw [← expand_C, expand_inj hp, expand_C]
theorem nat_degree_expand (p : ℕ) (f : R[X]) :
(expand R p f).nat_degree = f.nat_degree * p :=
begin
cases p.eq_zero_or_pos with hp hp,
{ rw [hp, coe_expand, pow_zero, mul_zero, ← C_1, eval₂_hom, nat_degree_C] },
by_cases hf : f = 0,
{ rw [hf, alg_hom.map_zero, nat_degree_zero, zero_mul] },
have hf1 : expand R p f ≠ 0 := mt (expand_eq_zero hp).1 hf,
rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree hf1],
refine le_antisymm ((degree_le_iff_coeff_zero _ _).2 $ λ n hn, _) _,
{ rw coeff_expand hp, split_ifs with hpn,
{ rw coeff_eq_zero_of_nat_degree_lt, contrapose! hn,
rw [with_bot.coe_le_coe, ← nat.div_mul_cancel hpn], exact nat.mul_le_mul_right p hn },
{ refl } },
{ refine le_degree_of_ne_zero _,
rw [coeff_expand_mul hp, ← leading_coeff], exact mt leading_coeff_eq_zero.1 hf }
end
lemma monic.expand {p : ℕ} {f : R[X]} (hp : 0 < p) (h : f.monic) : (expand R p f).monic :=
begin
rw [monic.def, leading_coeff, nat_degree_expand, coeff_expand hp],
simp [hp, h],
end
theorem map_expand {p : ℕ} {f : R →+* S} {q : R[X]} :
map f (expand R p q) = expand S p (map f q) :=
begin
by_cases hp : p = 0,
{ simp [hp] },
ext,
rw [coeff_map, coeff_expand (nat.pos_of_ne_zero hp), coeff_expand (nat.pos_of_ne_zero hp)],
split_ifs; simp,
end
/-- Expansion is injective. -/
lemma expand_injective {n : ℕ} (hn : 0 < n) :
function.injective (expand R n) :=
λ g g' h, begin
ext,
have h' : (expand R n g).coeff (n * n_1) = (expand R n g').coeff (n * n_1) :=
begin
apply polynomial.ext_iff.1,
exact h,
end,
rw [polynomial.coeff_expand hn g (n * n_1), polynomial.coeff_expand hn g' (n * n_1)] at h',
simp only [if_true, dvd_mul_right] at h',
rw (nat.mul_div_right n_1 hn) at h',
exact h',
end
@[simp]
lemma expand_eval (p : ℕ) (P : R[X]) (r : R) : eval r (expand R p P) = eval (r ^ p) P :=
begin
refine polynomial.induction_on P (λ a, by simp) (λ f g hf hg, _) (λ n a h, by simp),
rw [alg_hom.map_add, eval_add, eval_add, hf, hg]
end
@[simp]
lemma expand_aeval {A : Type*} [semiring A] [algebra R A] (p : ℕ) (P : R[X]) (r : A) :
aeval r (expand R p P) = aeval (r ^ p) P :=
begin
refine polynomial.induction_on P (λ a, by simp) (λ f g hf hg, _) (λ n a h, by simp),
rw [alg_hom.map_add, aeval_add, aeval_add, hf, hg]
end
/-- The opposite of `expand`: sends `∑ aₙ xⁿᵖ` to `∑ aₙ xⁿ`. -/
noncomputable def contract (p : ℕ) (f : R[X]) : R[X] :=
∑ n in range (f.nat_degree + 1), monomial n (f.coeff (n * p))
theorem coeff_contract {p : ℕ} (hp : p ≠ 0) (f : R[X]) (n : ℕ) :
(contract p f).coeff n = f.coeff (n * p) :=
begin
simp only [contract, coeff_monomial, sum_ite_eq', finset_sum_coeff, mem_range, not_lt,
ite_eq_left_iff],
assume hn,
apply (coeff_eq_zero_of_nat_degree_lt _).symm,
calc f.nat_degree < f.nat_degree + 1 : nat.lt_succ_self _
... ≤ n * 1 : by simpa only [mul_one] using hn
... ≤ n * p : mul_le_mul_of_nonneg_left (show 1 ≤ p, from hp.bot_lt) (zero_le n)
end
theorem contract_expand {f : R[X]} (hp : p ≠ 0) : contract p (expand R p f) = f :=
begin
ext,
simp [coeff_contract hp, coeff_expand hp.bot_lt, nat.mul_div_cancel _ hp.bot_lt]
end
section char_p
variable [char_p R p]
theorem expand_contract [no_zero_divisors R] {f : R[X]} (hf : f.derivative = 0)
(hp : p ≠ 0) : expand R p (contract p f) = f :=
begin
ext n,
rw [coeff_expand hp.bot_lt, coeff_contract hp],
split_ifs with h,
{ rw nat.div_mul_cancel h },
{ cases n,
{ exact absurd (dvd_zero p) h },
have := coeff_derivative f n,
rw [hf, coeff_zero, zero_eq_mul] at this,
cases this,
{ rw this },
rw [← nat.cast_succ, char_p.cast_eq_zero_iff R p] at this,
exact absurd this h }
end
variable [hp : fact p.prime]
include hp
theorem expand_char (f : R[X]) : map (frobenius R p) (expand R p f) = f ^ p :=
begin
refine f.induction_on' (λ a b ha hb, _) (λ n a, _),
{ rw [alg_hom.map_add, polynomial.map_add, ha, hb, add_pow_char], },
{ rw [expand_monomial, map_monomial, monomial_eq_C_mul_X, monomial_eq_C_mul_X,
mul_pow, ← C.map_pow, frobenius_def],
ring_exp }
end
theorem map_expand_pow_char (f : R[X]) (n : ℕ) :
map ((frobenius R p) ^ n) (expand R (p ^ n) f) = f ^ (p ^ n) :=
begin
induction n,
{ simp [ring_hom.one_def] },
symmetry,
rw [pow_succ', pow_mul, ← n_ih, ← expand_char, pow_succ, ring_hom.mul_def,
← map_map, mul_comm, expand_mul, ← map_expand]
end
end char_p
end comm_semiring
section is_domain
variables (R : Type u) [comm_ring R] [is_domain R]
theorem is_local_ring_hom_expand {p : ℕ} (hp : 0 < p) :
is_local_ring_hom (↑(expand R p) : R[X] →+* R[X]) :=
begin
refine ⟨λ f hf1, _⟩, rw ← coe_fn_coe_base at hf1,
have hf2 := eq_C_of_degree_eq_zero (degree_eq_zero_of_is_unit hf1),
rw [coeff_expand hp, if_pos (dvd_zero _), p.zero_div] at hf2,
rw [hf2, is_unit_C] at hf1, rw expand_eq_C hp at hf2, rwa [hf2, is_unit_C]
end
variable {R}
theorem of_irreducible_expand {p : ℕ} (hp : p ≠ 0) {f : R[X]}
(hf : irreducible (expand R p f)) : irreducible f :=
let _ := is_local_ring_hom_expand R hp.bot_lt in by exactI of_irreducible_map ↑(expand R p) hf
theorem of_irreducible_expand_pow {p : ℕ} (hp : p ≠ 0) {f : R[X]} {n : ℕ} :
irreducible (expand R (p ^ n) f) → irreducible f :=
nat.rec_on n (λ hf, by rwa [pow_zero, expand_one] at hf) $ λ n ih hf,
ih $ of_irreducible_expand hp $ by { rw pow_succ at hf, rwa [expand_expand] }
end is_domain
end polynomial
|
140de226f2a40a707cbd0f914dc48ddd15e055dd | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/run/list_notation.lean | 53994023f7562db5b8b26bc68e36cb0891b912fe | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 406 | lean | open nat
vm_eval [1, 2, 3]
vm_eval to_bool $ 1 ∈ [1, 2, 3]
vm_eval to_bool $ 4 ∈ [1, 2, 3]
vm_eval [1, 2, 3] ++ [3, 4]
vm_eval 2 :: [3, 4]
vm_eval ([] : list nat)
vm_eval (∅ : list nat)
vm_eval ({1, 3, 2, 2, 3, 1} : list nat)
vm_eval [1, 2, 3] ∪ [3, 4, 1, 5]
vm_eval [1, 2, 3] ∩ [3, 4, 1, 5]
vm_eval (mul 10) <$> [1, 2, 3]
check ({1, 2, 3} : list nat)
check ({1, 2, 3, 4} : set nat)
|
470fff1e97951c86febe8e7b5993d3b751c1729d | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/fintype/sort_auto.lean | ee22486d01e708d75461742f84e62d26dce02c7e | [] | 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 | 985 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fintype.basic
import Mathlib.data.finset.sort
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-- Given a linearly ordered fintype `α` of cardinal `k`, the order isomorphism
`mono_equiv_of_fin α h` is the increasing bijection between `fin k` and `α`. Here, `h` is a proof
that the cardinality of `s` is `k`. We use this instead of an isomorphism `fin s.card ≃o α` to avoid
casting issues in further uses of this function. -/
def mono_equiv_of_fin (α : Type u_1) [fintype α] [linear_order α] {k : ℕ} (h : fintype.card α = k) :
fin k ≃o α :=
order_iso.trans (finset.order_iso_of_fin finset.univ h)
(order_iso.trans (order_iso.set_congr (↑finset.univ) set.univ finset.coe_univ)
order_iso.set.univ)
end Mathlib |
61856c68ae43777f1fcd764ca7e6aa78bdfefd83 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/linear_algebra/finsupp.lean | b83d1ca86318c400f97c29fcb0d6920b51a1aa66 | [
"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 | 17,175 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
Linear structures on function with finite support `α →₀ M`.
-/
import data.monoid_algebra linear_algebra.basic
noncomputable theory
open set linear_map submodule
open_locale classical
namespace finsupp
variables {α : Type*} {M : Type*} {R : Type*}
variables [ring R] [add_comm_group M] [module R M]
def lsingle (a : α) : M →ₗ[R] (α →₀ M) :=
⟨single a, assume a b, single_add, assume c b, (smul_single _ _ _).symm⟩
def lapply (a : α) : (α →₀ M) →ₗ[R] M := ⟨λg, g a, assume a b, rfl, assume a b, rfl⟩
section lsubtype_domain
variables (s : set α)
def lsubtype_domain : (α →₀ M) →ₗ[R] (s →₀ M) :=
⟨subtype_domain (λx, x ∈ s), assume a b, subtype_domain_add, assume c a, ext $ assume a, rfl⟩
lemma lsubtype_domain_apply (f : α →₀ M) :
(lsubtype_domain s : (α →₀ M) →ₗ[R] (s →₀ M)) f = subtype_domain (λx, x ∈ s) f := rfl
end lsubtype_domain
@[simp] lemma lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] (α →₀ M)) b = single a b :=
rfl
@[simp] lemma lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a :=
rfl
@[simp] lemma ker_lsingle (a : α) : (lsingle a : M →ₗ[R] (α →₀ M)).ker = ⊥ :=
ker_eq_bot.2 (injective_single a)
lemma lsingle_range_le_ker_lapply (s t : set α) (h : disjoint s t) :
(⨆a∈s, (lsingle a : M →ₗ[R] (α →₀ M)).range) ≤ (⨅a∈t, ker (lapply a)) :=
begin
refine supr_le (assume a₁, supr_le $ assume h₁, range_le_iff_comap.2 _),
simp only [(ker_comp _ _).symm, eq_top_iff, le_def', mem_ker, comap_infi, mem_infi],
assume b hb a₂ h₂,
have : a₁ ≠ a₂ := assume eq, h ⟨h₁, eq.symm ▸ h₂⟩,
exact single_eq_of_ne this
end
lemma infi_ker_lapply_le_bot : (⨅a, ker (lapply a : (α →₀ M) →ₗ[R] M)) ≤ ⊥ :=
begin
simp only [le_def', mem_infi, mem_ker, mem_bot, lapply_apply],
exact assume a h, finsupp.ext h
end
lemma supr_lsingle_range : (⨆a, (lsingle a : M →ₗ[R] (α →₀ M)).range) = ⊤ :=
begin
refine (eq_top_iff.2 $ le_def'.2 $ assume f _, _),
rw [← sum_single f],
refine sum_mem _ (assume a ha, submodule.mem_supr_of_mem _ a $ set.mem_image_of_mem _ trivial)
end
lemma disjoint_lsingle_lsingle (s t : set α) (hs : disjoint s t) :
disjoint (⨆a∈s, (lsingle a : M →ₗ[R] (α →₀ M)).range) (⨆a∈t, (lsingle a).range) :=
begin
refine disjoint_mono
(lsingle_range_le_ker_lapply _ _ $ disjoint_compl s)
(lsingle_range_le_ker_lapply _ _ $ disjoint_compl t)
(le_trans (le_infi $ assume i, _) infi_ker_lapply_le_bot),
classical,
by_cases his : i ∈ s,
{ by_cases hit : i ∈ t,
{ exact (hs ⟨his, hit⟩).elim },
exact inf_le_right_of_le (infi_le_of_le i $ infi_le _ hit) },
exact inf_le_left_of_le (infi_le_of_le i $ infi_le _ his)
end
lemma span_single_image (s : set M) (a : α) :
submodule.span R (single a '' s) = (submodule.span R s).map (lsingle a) :=
by rw ← span_image; refl
variables (M R)
def supported (s : set α) : submodule R (α →₀ M) :=
begin
refine ⟨ {p | ↑p.support ⊆ s }, _, _, _ ⟩,
{ simp only [subset_def, finset.mem_coe, set.mem_set_of_eq, mem_support_iff, zero_apply],
assume h ha, exact (ha rfl).elim },
{ assume p q hp hq,
refine subset.trans
(subset.trans (finset.coe_subset.2 support_add) _) (union_subset hp hq),
rw [finset.coe_union] },
{ assume a p hp,
refine subset.trans (finset.coe_subset.2 support_smul) hp }
end
variables {M}
lemma mem_supported {s : set α} (p : α →₀ M) : p ∈ (supported M R s) ↔ ↑p.support ⊆ s :=
iff.rfl
lemma mem_supported' {s : set α} (p : α →₀ M) :
p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 :=
by haveI := classical.dec_pred (λ (x : α), x ∈ s);
simp [mem_supported, set.subset_def, not_imp_comm]
lemma single_mem_supported {s : set α} {a : α} (b : M) (h : a ∈ s) :
single a b ∈ supported M R s :=
set.subset.trans support_single_subset (set.singleton_subset_iff.2 h)
lemma supported_eq_span_single [has_one M] (s : set α) :
supported R R s = span R ((λ i, single i 1) '' s) :=
begin
refine (span_eq_of_le _ _ (le_def'.2 $ λ l hl, _)).symm,
{ rintro _ ⟨_, hp, rfl ⟩ , exact single_mem_supported R 1 hp },
{ rw ← l.sum_single,
refine sum_mem _ (λ i il, _),
convert @smul_mem R (α →₀ R) _ _ _ _ (single i 1) (l i) _,
{ simp },
apply subset_span,
apply set.mem_image_of_mem _ (hl il) }
end
variables (M R)
def restrict_dom (s : set α) : (α →₀ M) →ₗ supported M R s :=
linear_map.cod_restrict _
{ to_fun := filter (∈ s),
add := λ l₁ l₂, filter_add,
smul := λ a l, filter_smul }
(λ l, (mem_supported' _ _).2 $ λ x, filter_apply_neg (∈ s) l)
variables {M R}
section
set_option class.instance_max_depth 50
@[simp] theorem restrict_dom_apply (s : set α) (l : α →₀ M) :
((restrict_dom M R s : (α →₀ M) →ₗ supported M R s) l : α →₀ M) = finsupp.filter (∈ s) l := rfl
end
theorem restrict_dom_comp_subtype (s : set α) :
(restrict_dom M R s).comp (submodule.subtype _) = linear_map.id :=
begin
ext l,
apply subtype.coe_ext.2,
simp,
ext a,
by_cases a ∈ s,
{ simp [h] },
{ rw [filter_apply_neg (λ x, x ∈ s) _ h],
exact ((mem_supported' R l.1).1 l.2 a h).symm }
end
theorem range_restrict_dom (s : set α) :
(restrict_dom M R s).range = ⊤ :=
begin
have := linear_map.range_comp (submodule.subtype _) (restrict_dom M R s),
rw [restrict_dom_comp_subtype, linear_map.range_id] at this,
exact eq_top_mono (submodule.map_mono le_top) this.symm
end
theorem supported_mono {s t : set α} (st : s ⊆ t) :
supported M R s ≤ supported M R t :=
λ l h, set.subset.trans h st
@[simp] theorem supported_empty : supported M R (∅ : set α) = ⊥ :=
eq_bot_iff.2 $ λ l h, (submodule.mem_bot R).2 $
by ext; simp [*, mem_supported'] at *
@[simp] theorem supported_univ : supported M R (set.univ : set α) = ⊤ :=
eq_top_iff.2 $ λ l _, set.subset_univ _
theorem supported_Union {δ : Type*} (s : δ → set α) :
supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) :=
begin
refine le_antisymm _ (supr_le $ λ i, supported_mono $ set.subset_Union _ _),
haveI := classical.dec_pred (λ x, x ∈ (⋃ i, s i)),
suffices : ((submodule.subtype _).comp (restrict_dom M R (⋃ i, s i))).range ≤ ⨆ i, supported M R (s i),
{ rwa [linear_map.range_comp, range_restrict_dom, map_top, range_subtype] at this },
rw [range_le_iff_comap, eq_top_iff],
rintro l ⟨⟩, rw mem_coe,
apply finsupp.induction l, {exact zero_mem _},
refine λ x a l hl a0, add_mem _ _,
haveI := classical.dec_pred (λ x, ∃ i, x ∈ s i),
by_cases (∃ i, x ∈ s i); simp [h],
{ cases h with i hi,
exact le_supr (λ i, supported M R (s i)) i (single_mem_supported R _ hi) },
{ rw filter_single_of_neg,
{ simp },
{ exact h } }
end
theorem supported_union (s t : set α) :
supported M R (s ∪ t) = supported M R s ⊔ supported M R t :=
by erw [set.union_eq_Union, supported_Union, supr_bool_eq]; refl
theorem supported_Inter {ι : Type*} (s : ι → set α) :
supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) :=
begin
refine le_antisymm (le_infi $ λ i, supported_mono $ set.Inter_subset _ _) _,
simp [le_def, infi_coe, set.subset_def],
exact λ l, set.subset_Inter
end
section
set_option class.instance_max_depth 37
def supported_equiv_finsupp (s : set α) :
(supported M R s) ≃ₗ[R] (s →₀ M) :=
(restrict_support_equiv s).to_linear_equiv
begin
show is_linear_map R ((lsubtype_domain s : (α →₀ M) →ₗ[R] (s →₀ M)).comp
(submodule.subtype (supported M R s))),
exact linear_map.is_linear _
end
end
def lsum (f : α → R →ₗ[R] M) : (α →₀ R) →ₗ[R] M :=
⟨λ d, d.sum (λ i, f i),
assume d₁ d₂, by simp [sum_add_index],
assume a d, by simp [sum_smul_index, smul_sum, -smul_eq_mul, smul_eq_mul.symm]⟩
@[simp] theorem lsum_apply (f : α → R →ₗ[R] M) (l : α →₀ R) :
(finsupp.lsum f : (α →₀ R) →ₗ M) l = l.sum (λ b, f b) := rfl
section lmap_domain
variables {α' : Type*} {α'' : Type*} (M R)
def lmap_domain (f : α → α') : (α →₀ M) →ₗ[R] (α' →₀ M) :=
⟨map_domain f, assume a b, map_domain_add, map_domain_smul⟩
@[simp] theorem lmap_domain_apply (f : α → α') (l : α →₀ M) :
(lmap_domain M R f : (α →₀ M) →ₗ[R] (α' →₀ M)) l = map_domain f l := rfl
@[simp] theorem lmap_domain_id : (lmap_domain M R id : (α →₀ M) →ₗ[R] α →₀ M) = linear_map.id :=
linear_map.ext $ λ l, map_domain_id
theorem lmap_domain_comp (f : α → α') (g : α' → α'') :
lmap_domain M R (g ∘ f) = (lmap_domain M R g).comp (lmap_domain M R f) :=
linear_map.ext $ λ l, map_domain_comp
theorem supported_comap_lmap_domain (f : α → α') (s : set α') :
supported M R (f ⁻¹' s) ≤ (supported M R s).comap (lmap_domain M R f) :=
λ l (hl : ↑l.support ⊆ f ⁻¹' s),
show ↑(map_domain f l).support ⊆ s, begin
rw [← set.image_subset_iff, ← finset.coe_image] at hl,
exact set.subset.trans map_domain_support hl
end
theorem lmap_domain_supported [nonempty α] (f : α → α') (s : set α) :
(supported M R s).map (lmap_domain M R f) = supported M R (f '' s) :=
begin
inhabit α,
refine le_antisymm (map_le_iff_le_comap.2 $
le_trans (supported_mono $ set.subset_preimage_image _ _)
(supported_comap_lmap_domain _ _ _ _)) _,
intros l hl,
refine ⟨(lmap_domain M R (function.inv_fun_on f s) : (α' →₀ M) →ₗ α →₀ M) l, λ x hx, _, _⟩,
{ rcases finset.mem_image.1 (map_domain_support hx) with ⟨c, hc, rfl⟩,
exact function.inv_fun_on_mem (by simpa using hl hc) },
{ rw [← linear_map.comp_apply, ← lmap_domain_comp],
refine (map_domain_congr $ λ c hc, _).trans map_domain_id,
exact function.inv_fun_on_eq (by simpa using hl hc) }
end
theorem lmap_domain_disjoint_ker (f : α → α') {s : set α}
(H : ∀ a b ∈ s, f a = f b → a = b) :
disjoint (supported M R s) (lmap_domain M R f).ker :=
begin
rintro l ⟨h₁, h₂⟩,
rw [mem_coe, mem_ker, lmap_domain_apply, map_domain] at h₂,
simp, ext x,
haveI := classical.dec_pred (λ x, x ∈ s),
by_cases xs : x ∈ s,
{ have : finsupp.sum l (λ a, finsupp.single (f a)) (f x) = 0, {rw h₂, refl},
rw [finsupp.sum_apply, finsupp.sum, finset.sum_eq_single x] at this,
{ simpa [finsupp.single_apply] },
{ intros y hy xy, simp [mt (H _ _ (h₁ hy) xs) xy] },
{ simp {contextual := tt} } },
{ by_contra h, exact xs (h₁ $ finsupp.mem_support_iff.2 h) }
end
end lmap_domain
section total
variables (α) {α' : Type*} (M) {M' : Type*} (R)
[add_comm_group M'] [module R M']
(v : α → M) {v' : α' → M'}
/-- Interprets (l : α →₀ R) as linear combination of the elements in the family (v : α → M) and
evaluates this linear combination. -/
protected def total : (α →₀ R) →ₗ M := finsupp.lsum (λ i, linear_map.id.smul_right (v i))
variables {α M v}
theorem total_apply (l : α →₀ R) :
finsupp.total α M R v l = l.sum (λ i a, a • v i) := rfl
@[simp] theorem total_single (c : R) (a : α) :
finsupp.total α M R v (single a c) = c • (v a) :=
by simp [total_apply, sum_single_index]
theorem total_range (h : function.surjective v) : (finsupp.total α M R v).range = ⊤ :=
begin
apply range_eq_top.2,
intros x,
apply exists.elim (h x),
exact λ i hi, ⟨single i 1, by simp [hi]⟩
end
lemma range_total : (finsupp.total α M R v).range = span R (range v) :=
begin
ext x,
split,
{ intros hx,
rw [linear_map.mem_range] at hx,
rcases hx with ⟨l, hl⟩,
rw ← hl,
rw finsupp.total_apply,
unfold finsupp.sum,
apply sum_mem (span R (range v)),
{ exact λ i hi, submodule.smul _ _ (subset_span (mem_range_self i)) },
apply_instance },
{ apply span_le.2,
intros x hx,
rcases hx with ⟨i, hi⟩,
rw [mem_coe, linear_map.mem_range],
use finsupp.single i 1,
simp [hi] }
end
theorem lmap_domain_total (f : α → α') (g : M →ₗ[R] M') (h : ∀ i, g (v i) = v' (f i)) :
(finsupp.total α' M' R v').comp (lmap_domain R R f) = g.comp (finsupp.total α M R v) :=
by ext l; simp [total_apply, finsupp.sum_map_domain_index, add_smul, h]
theorem total_emb_domain (f : α ↪ α') (l : α →₀ R) :
(finsupp.total α' M' R v') (emb_domain f l) = (finsupp.total α M' R (v' ∘ f)) l :=
by simp [total_apply, finsupp.sum, support_emb_domain, emb_domain_apply]
theorem total_map_domain (f : α → α') (hf : function.injective f) (l : α →₀ R) :
(finsupp.total α' M' R v') (map_domain f l) = (finsupp.total α M' R (v' ∘ f)) l :=
begin
have : map_domain f l = emb_domain ⟨f, hf⟩ l,
{ rw emb_domain_eq_map_domain ⟨f, hf⟩,
refl },
rw this,
apply total_emb_domain R ⟨f, hf⟩ l
end
theorem span_eq_map_total (s : set α):
span R (v '' s) = submodule.map (finsupp.total α M R v) (supported R R s) :=
begin
apply span_eq_of_le,
{ intros x hx,
rw set.mem_image at hx,
apply exists.elim hx,
intros i hi,
exact ⟨_, finsupp.single_mem_supported R 1 hi.1, by simp [hi.2]⟩ },
{ refine map_le_iff_le_comap.2 (λ z hz, _),
have : ∀i, z i • v i ∈ span R (v '' s),
{ intro c,
haveI := classical.dec_pred (λ x, x ∈ s),
by_cases c ∈ s,
{ exact smul_mem _ _ (subset_span (set.mem_image_of_mem _ h)) },
{ simp [(finsupp.mem_supported' R _).1 hz _ h] } },
refine sum_mem _ _, simp [this] }
end
theorem mem_span_iff_total {s : set α} {x : M} :
x ∈ span R (v '' s) ↔ ∃ l ∈ supported R R s, finsupp.total α M R v l = x :=
by rw span_eq_map_total; simp
variables (α) (M) (v)
protected def total_on (s : set α) : supported R R s →ₗ[R] span R (v '' s) :=
linear_map.cod_restrict _ ((finsupp.total _ _ _ v).comp (submodule.subtype (supported R R s))) $
λ ⟨l, hl⟩, (mem_span_iff_total _).2 ⟨l, hl, rfl⟩
variables {α} {M} {v}
theorem total_on_range (s : set α) : (finsupp.total_on α M R v s).range = ⊤ :=
by rw [finsupp.total_on, linear_map.range, linear_map.map_cod_restrict, ← linear_map.range_le_iff_comap,
range_subtype, map_top, linear_map.range_comp, range_subtype]; exact le_of_eq (span_eq_map_total _ _)
theorem total_comp (f : α' → α) :
(finsupp.total α' M R (v ∘ f)) = (finsupp.total α M R v).comp (lmap_domain R R f) :=
begin
ext l,
simp [total_apply],
rw sum_map_domain_index; simp [add_smul],
end
lemma total_comap_domain
(f : α → α') (l : α' →₀ R) (hf : set.inj_on f (f ⁻¹' l.support.to_set)) :
finsupp.total α M R v (finsupp.comap_domain f l hf) = (l.support.preimage hf).sum (λ i, (l (f i)) • (v i)) :=
by rw finsupp.total_apply; refl
end total
protected def dom_lcongr
{α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) :
(α₁ →₀ M) ≃ₗ[R] (α₂ →₀ M) :=
(finsupp.dom_congr e).to_linear_equiv
begin
change is_linear_map R (lmap_domain M R e : (α₁ →₀ M) →ₗ[R] (α₂ →₀ M)),
exact linear_map.is_linear _
end
noncomputable def congr {α' : Type*} (s : set α) (t : set α') (e : s ≃ t) :
supported M R s ≃ₗ[R] supported M R t :=
begin
haveI := classical.dec_pred (λ x, x ∈ s),
haveI := classical.dec_pred (λ x, x ∈ t),
refine linear_equiv.trans (finsupp.supported_equiv_finsupp s)
(linear_equiv.trans _ (finsupp.supported_equiv_finsupp t).symm),
exact finsupp.dom_lcongr e
end
end finsupp
variables {R : Type*} {M : Type*} {N : Type*}
variables [ring R] [add_comm_group M] [module R M] [add_comm_group N] [module R N]
lemma linear_map.map_finsupp_total
(f : M →ₗ[R] N) {ι : Type*} [fintype ι] {g : ι → M} (l : ι →₀ R) :
f (finsupp.total ι M R g l) = finsupp.total ι N R (f ∘ g) l :=
by simp only [finsupp.total_apply, finsupp.total_apply, finsupp.sum, f.map_sum, f.map_smul]
lemma submodule.exists_finset_of_mem_supr
{ι : Sort*} (p : ι → submodule R M) {m : M} (hm : m ∈ ⨆ i, p i) :
∃ s : finset ι, m ∈ ⨆ i ∈ s, p i :=
begin
obtain ⟨f, hf, rfl⟩ : ∃ f ∈ finsupp.supported R R (⋃ i, ↑(p i)), finsupp.total M M R id f = m,
{ have aux : (id : M → M) '' (⋃ (i : ι), ↑(p i)) = (⋃ (i : ι), ↑(p i)) := set.image_id _,
rwa [supr_eq_span, ← aux, finsupp.mem_span_iff_total R] at hm },
let t : finset M := f.support,
have ht : ∀ x : {x // x ∈ t}, ∃ i, ↑x ∈ p i,
{ intros x,
rw finsupp.mem_supported at hf,
specialize hf x.2,
rwa set.mem_Union at hf },
choose g hg using ht,
let s : finset ι := finset.univ.image g,
use s,
simp only [mem_supr, supr_le_iff],
assume N hN,
rw [finsupp.total_apply, finsupp.sum, ← submodule.mem_coe],
apply is_add_submonoid.finset_sum_mem,
assume x hx,
apply submodule.smul_mem,
let i : ι := g ⟨x, hx⟩,
have hi : i ∈ s, { rw finset.mem_image, exact ⟨⟨x, hx⟩, finset.mem_univ _, rfl⟩ },
exact hN i hi (hg _),
end
|
0f947b4f9c141bc7a506549d81518328e38f44ca | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/metric_space/emetric_space.lean | a1e8643c8967b1291a034f6462ead639f6028329 | [
"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 | 50,787 | lean | /-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import data.nat.interval
import data.real.ennreal
import topology.uniform_space.pi
import topology.uniform_space.uniform_convergence
import topology.uniform_space.uniform_embedding
/-!
# Extended metric spaces
This file is devoted to the definition and study of `emetric_spaces`, i.e., metric
spaces in which the distance is allowed to take the value ∞. This extended distance is
called `edist`, and takes values in `ℝ≥0∞`.
Many definitions and theorems expected on emetric spaces are already introduced on uniform spaces
and topological spaces. For example: open and closed sets, compactness, completeness, continuity and
uniform continuity.
The class `emetric_space` therefore extends `uniform_space` (and `topological_space`).
Since a lot of elementary properties don't require `eq_of_edist_eq_zero` we start setting up the
theory of `pseudo_emetric_space`, where we don't require `edist x y = 0 → x = y` and we specialize
to `emetric_space` at the end.
-/
open set filter classical
open_locale uniformity topological_space big_operators filter nnreal ennreal
universes u v w
variables {α : Type u} {β : Type v} {X : Type*}
/-- Characterizing uniformities associated to a (generalized) distance function `D`
in terms of the elements of the uniformity. -/
theorem uniformity_dist_of_mem_uniformity [linear_order β] {U : filter (α × α)} (z : β)
(D : α → α → β) (H : ∀ s, s ∈ U ↔ ∃ε>z, ∀{a b:α}, D a b < ε → (a, b) ∈ s) :
U = ⨅ ε>z, 𝓟 {p:α×α | D p.1 p.2 < ε} :=
le_antisymm
(le_infi $ λ ε, le_infi $ λ ε0, le_principal_iff.2 $ (H _).2 ⟨ε, ε0, λ a b, id⟩)
(λ r ur, let ⟨ε, ε0, h⟩ := (H _).1 ur in
mem_infi_of_mem ε $ mem_infi_of_mem ε0 $ mem_principal.2 $ λ ⟨a, b⟩, h)
/-- `has_edist α` means that `α` is equipped with an extended distance. -/
class has_edist (α : Type*) := (edist : α → α → ℝ≥0∞)
export has_edist (edist)
/-- Creating a uniform space from an extended distance. -/
def uniform_space_of_edist
(edist : α → α → ℝ≥0∞)
(edist_self : ∀ x : α, edist x x = 0)
(edist_comm : ∀ x y : α, edist x y = edist y x)
(edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z) : uniform_space α :=
uniform_space.of_core
{ uniformity := (⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, edist_self, (>)] {contextual := tt},
comp :=
le_infi $ assume ε, le_infi $ assume h,
have (2 : ℝ≥0∞) = (2 : ℕ) := by simp,
have A : 0 < ε / 2 := ennreal.div_pos_iff.2
⟨ne_of_gt h, by { convert ennreal.nat_ne_top 2 }⟩,
lift'_le
(mem_infi_of_mem (ε / 2) $ mem_infi_of_mem A (subset.refl _)) $
have ∀ (a b c : α), edist a c < ε / 2 → edist c b < ε / 2 → edist a b < ε,
from assume a b c hac hcb,
calc edist a b ≤ edist a c + edist c b : edist_triangle _ _ _
... < ε / 2 + ε / 2 : ennreal.add_lt_add hac hcb
... = ε : by rw [ennreal.add_halves],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [edist_comm] }
-- the uniform structure is embedded in the emetric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- Extended (pseudo) metric spaces, with an extended distance `edist` possibly taking the
value ∞
Each pseudo_emetric space induces a canonical `uniform_space` and hence a canonical
`topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating a `pseudo_emetric_space` structure, the uniformity fields are not necessary, they
will be filled in by default. There is a default value for the uniformity, that can be substituted
in cases of interest, for instance when instantiating a `pseudo_emetric_space` structure
on a product.
Continuity of `edist` is proved in `topology.instances.ennreal`
-/
class pseudo_emetric_space (α : Type u) extends has_edist α : Type u :=
(edist_self : ∀ x : α, edist x x = 0)
(edist_comm : ∀ x y : α, edist x y = edist y x)
(edist_triangle : ∀ x y z : α, edist x z ≤ edist x y + edist y z)
(to_uniform_space : uniform_space α :=
uniform_space_of_edist edist edist_self edist_comm edist_triangle)
(uniformity_edist : 𝓤 α = ⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε} . control_laws_tac)
attribute [priority 100, instance] pseudo_emetric_space.to_uniform_space
/- Pseudoemetric spaces are less common than metric spaces. Therefore, we work in a dedicated
namespace, while notions associated to metric spaces are mostly in the root namespace. -/
variables [pseudo_emetric_space α]
export pseudo_emetric_space (edist_self edist_comm edist_triangle)
attribute [simp] edist_self
/-- Triangle inequality for the extended distance -/
theorem edist_triangle_left (x y z : α) : edist x y ≤ edist z x + edist z y :=
by rw edist_comm z; apply edist_triangle
theorem edist_triangle_right (x y z : α) : edist x y ≤ edist x z + edist y z :=
by rw edist_comm y; apply edist_triangle
lemma edist_triangle4 (x y z t : α) :
edist x t ≤ edist x y + edist y z + edist z t :=
calc
edist x t ≤ edist x z + edist z t : edist_triangle x z t
... ≤ (edist x y + edist y z) + edist z t : add_le_add_right (edist_triangle x y z) _
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) :
edist (f m) (f n) ≤ ∑ i in finset.Ico m n, edist (f i) (f (i + 1)) :=
begin
revert n,
refine nat.le_induction _ _,
{ simp only [finset.sum_empty, finset.Ico_self, edist_self],
-- TODO: Why doesn't Lean close this goal automatically? `exact le_rfl` fails too.
exact le_refl (0:ℝ≥0∞) },
{ assume n hn hrec,
calc edist (f m) (f (n+1)) ≤ edist (f m) (f n) + edist (f n) (f (n+1)) : edist_triangle _ _ _
... ≤ ∑ i in finset.Ico m n, _ + _ : add_le_add hrec le_rfl
... = ∑ i in finset.Ico m (n+1), _ :
by rw [nat.Ico_succ_right_eq_insert_Ico hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) :
edist (f 0) (f n) ≤ ∑ i in finset.range n, edist (f i) (f (i + 1)) :=
nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (nat.zero_le n)
/-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
lemma edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
{d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f m) (f n) ≤ ∑ i in finset.Ico m n, d i :=
le_trans (edist_le_Ico_sum_edist f hmn) $
finset.sum_le_sum $ λ k hk, hd (finset.mem_Ico.1 hk).1 (finset.mem_Ico.1 hk).2
/-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
lemma edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ)
{d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f 0) (f n) ≤ ∑ i in finset.range n, d i :=
nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) (λ _ _, hd)
/-- Reformulation of the uniform structure in terms of the extended distance -/
theorem uniformity_pseudoedist :
𝓤 α = ⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε} :=
pseudo_emetric_space.uniformity_edist
theorem uniformity_basis_edist :
(𝓤 α).has_basis (λ ε : ℝ≥0∞, 0 < ε) (λ ε, {p:α×α | edist p.1 p.2 < ε}) :=
(@uniformity_pseudoedist α _).symm ▸ has_basis_binfi_principal
(λ r hr p hp, ⟨min r p, lt_min hr hp,
λ x hx, lt_of_lt_of_le hx (min_le_left _ _),
λ x hx, lt_of_lt_of_le hx (min_le_right _ _)⟩)
⟨1, ennreal.zero_lt_one⟩
/-- Characterization of the elements of the uniformity in terms of the extended distance -/
theorem mem_uniformity_edist {s : set (α×α)} :
s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, edist a b < ε → (a, b) ∈ s) :=
uniformity_basis_edist.mem_uniformity_iff
/-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_edist`, `uniformity_basis_edist'`,
`uniformity_basis_edist_nnreal`, and `uniformity_basis_edist_inv_nat`. -/
protected theorem emetric.mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | edist p.1 p.2 < f x}) :=
begin
refine ⟨λ s, uniformity_basis_edist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
rcases hf ε ε₀ with ⟨i, hi, H⟩,
exact ⟨i, hi, λ x hx, hε $ lt_of_lt_of_le hx H⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, H⟩ }
end
/-- Given `f : β → ℝ≥0∞`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_edist_le` and `uniformity_basis_edist_le'`. -/
protected theorem emetric.mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ≥0∞}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | edist p.1 p.2 ≤ f x}) :=
begin
refine ⟨λ s, uniformity_basis_edist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
rcases exists_between ε₀ with ⟨ε', hε'⟩,
rcases hf ε' hε'.1 with ⟨i, hi, H⟩,
exact ⟨i, hi, λ x hx, hε $ lt_of_le_of_lt (le_trans hx H) hε'.2⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, λ x hx, H (le_of_lt hx)⟩ }
end
theorem uniformity_basis_edist_le :
(𝓤 α).has_basis (λ ε : ℝ≥0∞, 0 < ε) (λ ε, {p:α×α | edist p.1 p.2 ≤ ε}) :=
emetric.mk_uniformity_basis_le (λ _, id) (λ ε ε₀, ⟨ε, ε₀, le_refl ε⟩)
theorem uniformity_basis_edist' (ε' : ℝ≥0∞) (hε' : 0 < ε') :
(𝓤 α).has_basis (λ ε : ℝ≥0∞, ε ∈ Ioo 0 ε') (λ ε, {p:α×α | edist p.1 p.2 < ε}) :=
emetric.mk_uniformity_basis (λ _, and.left)
(λ ε ε₀, let ⟨δ, hδ⟩ := exists_between hε' in
⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩)
theorem uniformity_basis_edist_le' (ε' : ℝ≥0∞) (hε' : 0 < ε') :
(𝓤 α).has_basis (λ ε : ℝ≥0∞, ε ∈ Ioo 0 ε') (λ ε, {p:α×α | edist p.1 p.2 ≤ ε}) :=
emetric.mk_uniformity_basis_le (λ _, and.left)
(λ ε ε₀, let ⟨δ, hδ⟩ := exists_between hε' in
⟨min ε δ, ⟨lt_min ε₀ hδ.1, lt_of_le_of_lt (min_le_right _ _) hδ.2⟩, min_le_left _ _⟩)
theorem uniformity_basis_edist_nnreal :
(𝓤 α).has_basis (λ ε : ℝ≥0, 0 < ε) (λ ε, {p:α×α | edist p.1 p.2 < ε}) :=
emetric.mk_uniformity_basis (λ _, ennreal.coe_pos.2)
(λ ε ε₀, let ⟨δ, hδ⟩ := ennreal.lt_iff_exists_nnreal_btwn.1 ε₀ in
⟨δ, ennreal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩)
theorem uniformity_basis_edist_nnreal_le :
(𝓤 α).has_basis (λ ε : ℝ≥0, 0 < ε) (λ ε, {p:α×α | edist p.1 p.2 ≤ ε}) :=
emetric.mk_uniformity_basis_le (λ _, ennreal.coe_pos.2)
(λ ε ε₀, let ⟨δ, hδ⟩ := ennreal.lt_iff_exists_nnreal_btwn.1 ε₀ in
⟨δ, ennreal.coe_pos.1 hδ.1, le_of_lt hδ.2⟩)
theorem uniformity_basis_edist_inv_nat :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | edist p.1 p.2 < (↑n)⁻¹}) :=
emetric.mk_uniformity_basis
(λ n _, ennreal.inv_pos.2 $ ennreal.nat_ne_top n)
(λ ε ε₀, let ⟨n, hn⟩ := ennreal.exists_inv_nat_lt (ne_of_gt ε₀) in ⟨n, trivial, le_of_lt hn⟩)
theorem uniformity_basis_edist_inv_two_pow :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | edist p.1 p.2 < 2⁻¹ ^ n}) :=
emetric.mk_uniformity_basis
(λ n _, ennreal.pow_pos (ennreal.inv_pos.2 ennreal.two_ne_top) _)
(λ ε ε₀, let ⟨n, hn⟩ := ennreal.exists_inv_two_pow_lt (ne_of_gt ε₀) in ⟨n, trivial, le_of_lt hn⟩)
/-- Fixed size neighborhoods of the diagonal belong to the uniform structure -/
theorem edist_mem_uniformity {ε:ℝ≥0∞} (ε0 : 0 < ε) :
{p:α×α | edist p.1 p.2 < ε} ∈ 𝓤 α :=
mem_uniformity_edist.2 ⟨ε, ε0, λ a b, id⟩
namespace emetric
@[priority 900]
instance : is_countably_generated (𝓤 α) :=
is_countably_generated_of_seq ⟨_, uniformity_basis_edist_inv_nat.eq_infi⟩
/-- ε-δ characterization of uniform continuity on a set for pseudoemetric spaces -/
theorem uniform_continuous_on_iff [pseudo_emetric_space β] {f : α → β} {s : set α} :
uniform_continuous_on f s ↔ ∀ ε > 0, ∃ δ > 0,
∀ {a b ∈ s}, edist a b < δ → edist (f a) (f b) < ε :=
uniformity_basis_edist.uniform_continuous_on_iff uniformity_basis_edist
/-- ε-δ characterization of uniform continuity on pseudoemetric spaces -/
theorem uniform_continuous_iff [pseudo_emetric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, edist a b < δ → edist (f a) (f b) < ε :=
uniformity_basis_edist.uniform_continuous_iff uniformity_basis_edist
/-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/
theorem uniform_embedding_iff [pseudo_emetric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (edist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_edist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, edist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
/-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y`. -/
theorem controlled_of_uniform_embedding [pseudo_emetric_space β] {f : α → β} :
uniform_embedding f →
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ) :=
begin
assume h,
exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2⟩,
end
/-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/
protected lemma cauchy_iff {f : filter α} :
cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, edist x y < ε :=
by rw ← ne_bot_iff; exact uniformity_basis_edist.cauchy_iff
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) →
∃x, tendsto u at_top (𝓝 x)) :
complete_space α :=
uniform_space.complete_of_convergent_controlled_sequences
(λ n, {p:α×α | edist p.1 p.2 < B n}) (λ n, edist_mem_uniformity $ hB n) H
/-- A sequentially complete pseudoemetric space is complete. -/
theorem complete_of_cauchy_seq_tendsto :
(∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
uniform_space.complete_of_cauchy_seq_tendsto
/-- Expressing locally uniform convergence on a set using `edist`. -/
lemma tendsto_locally_uniformly_on_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_locally_uniformly_on F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε :=
begin
refine ⟨λ H ε hε, H _ (edist_mem_uniformity hε), λ H u hu x hx, _⟩,
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩,
rcases H ε εpos x hx with ⟨t, ht, Ht⟩,
exact ⟨t, ht, Ht.mono (λ n hs x hx, hε (hs x hx))⟩
end
/-- Expressing uniform convergence on a set using `edist`. -/
lemma tendsto_uniformly_on_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_uniformly_on F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε :=
begin
refine ⟨λ H ε hε, H _ (edist_mem_uniformity hε), λ H u hu, _⟩,
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩,
exact (H ε εpos).mono (λ n hs x hx, hε (hs x hx))
end
/-- Expressing locally uniform convergence using `edist`. -/
lemma tendsto_locally_uniformly_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_locally_uniformly F f p ↔
∀ ε > 0, ∀ (x : β), ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε :=
by simp only [← tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff,
mem_univ, forall_const, exists_prop, nhds_within_univ]
/-- Expressing uniform convergence using `edist`. -/
lemma tendsto_uniformly_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_uniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε :=
by simp only [← tendsto_uniformly_on_univ, tendsto_uniformly_on_iff, mem_univ, forall_const]
end emetric
open emetric
/-- Auxiliary function to replace the uniformity on a pseudoemetric space with
a uniformity which is equal to the original one, but maybe not defeq.
This is useful if one wants to construct a pseudoemetric space with a
specified uniformity. See Note [forgetful inheritance] explaining why having definitionally
the right uniformity is often important.
-/
def pseudo_emetric_space.replace_uniformity {α} [U : uniform_space α] (m : pseudo_emetric_space α)
(H : @uniformity _ U = @uniformity _ pseudo_emetric_space.to_uniform_space) :
pseudo_emetric_space α :=
{ edist := @edist _ m.to_has_edist,
edist_self := edist_self,
edist_comm := edist_comm,
edist_triangle := edist_triangle,
to_uniform_space := U,
uniformity_edist := H.trans (@pseudo_emetric_space.uniformity_edist α _) }
/-- The extended pseudometric induced by a function taking values in a pseudoemetric space. -/
def pseudo_emetric_space.induced {α β} (f : α → β)
(m : pseudo_emetric_space β) : pseudo_emetric_space α :=
{ edist := λ x y, edist (f x) (f y),
edist_self := λ x, edist_self _,
edist_comm := λ x y, edist_comm _ _,
edist_triangle := λ x y z, edist_triangle _ _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_edist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, edist (f x) (f y)),
refine λ s, mem_comap.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_edist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, edist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
/-- Pseudoemetric space instance on subsets of pseudoemetric spaces -/
instance {α : Type*} {p : α → Prop} [pseudo_emetric_space α] : pseudo_emetric_space (subtype p) :=
pseudo_emetric_space.induced coe ‹_›
/-- The extended psuedodistance on a subset of a pseudoemetric space is the restriction of
the original pseudodistance, by definition -/
theorem subtype.edist_eq {p : α → Prop} (x y : subtype p) : edist x y = edist (x : α) y := rfl
namespace mul_opposite
/-- Pseudoemetric space instance on the multiplicative opposite of a pseudoemetric space. -/
@[to_additive "Pseudoemetric space instance on the additive opposite of a pseudoemetric space."]
instance {α : Type*} [pseudo_emetric_space α] : pseudo_emetric_space αᵐᵒᵖ :=
pseudo_emetric_space.induced unop ‹_›
@[to_additive] theorem edist_unop (x y : αᵐᵒᵖ) : edist (unop x) (unop y) = edist x y := rfl
@[to_additive] theorem edist_op (x y : α) : edist (op x) (op y) = edist x y := rfl
end mul_opposite
section ulift
instance : pseudo_emetric_space (ulift α) :=
pseudo_emetric_space.induced ulift.down ‹_›
lemma ulift.edist_eq (x y : ulift α) : edist x y = edist x.down y.down := rfl
@[simp] lemma ulift.edist_up_up (x y : α) : edist (ulift.up x) (ulift.up y) = edist x y := rfl
end ulift
/-- The product of two pseudoemetric spaces, with the max distance, is an extended
pseudometric spaces. We make sure that the uniform structure thus constructed is the one
corresponding to the product of uniform spaces, to avoid diamond problems. -/
instance prod.pseudo_emetric_space_max [pseudo_emetric_space β] : pseudo_emetric_space (α × β) :=
{ edist := λ x y, edist x.1 y.1 ⊔ edist x.2 y.2,
edist_self := λ x, by simp,
edist_comm := λ x y, by simp [edist_comm],
edist_triangle := λ x y z, max_le
(le_trans (edist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (edist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
uniformity_edist := begin
refine uniformity_prod.trans _,
simp only [pseudo_emetric_space.uniformity_edist, comap_infi],
rw ← infi_inf_eq, congr, funext,
rw ← infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
lemma prod.edist_eq [pseudo_emetric_space β] (x y : α × β) :
edist x y = max (edist x.1 y.1) (edist x.2 y.2) :=
rfl
section pi
open finset
variables {π : β → Type*} [fintype β]
/-- The product of a finite number of pseudoemetric spaces, with the max distance, is still
a pseudoemetric space.
This construction would also work for infinite products, but it would not give rise
to the product topology. Hence, we only formalize it in the good situation of finitely many
spaces. -/
instance pseudo_emetric_space_pi [∀b, pseudo_emetric_space (π b)] :
pseudo_emetric_space (Πb, π b) :=
{ edist := λ f g, finset.sup univ (λb, edist (f b) (g b)),
edist_self := assume f, bot_unique $ finset.sup_le $ by simp,
edist_comm := assume f g, by unfold edist; congr; funext a; exact edist_comm _ _,
edist_triangle := assume f g h,
begin
simp only [finset.sup_le_iff],
assume b hb,
exact le_trans (edist_triangle _ (g b) _) (add_le_add (le_sup hb) (le_sup hb))
end,
to_uniform_space := Pi.uniform_space _,
uniformity_edist := begin
simp only [Pi.uniformity, pseudo_emetric_space.uniformity_edist, comap_infi, gt_iff_lt,
preimage_set_of_eq, comap_principal],
rw infi_comm, congr, funext ε,
rw infi_comm, congr, funext εpos,
change 0 < ε at εpos,
simp [set.ext_iff, εpos]
end }
lemma edist_pi_def [Π b, pseudo_emetric_space (π b)] (f g : Π b, π b) :
edist f g = finset.sup univ (λb, edist (f b) (g b)) := rfl
lemma edist_le_pi_edist [Π b, pseudo_emetric_space (π b)] (f g : Π b, π b) (b : β) :
edist (f b) (g b) ≤ edist f g :=
finset.le_sup (finset.mem_univ b)
lemma edist_pi_le_iff [Π b, pseudo_emetric_space (π b)] {f g : Π b, π b} {d : ℝ≥0∞} :
edist f g ≤ d ↔ ∀ b, edist (f b) (g b) ≤ d :=
finset.sup_le_iff.trans $ by simp only [finset.mem_univ, forall_const]
lemma edist_pi_const_le (a b : α) : edist (λ _ : β, a) (λ _, b) ≤ edist a b :=
edist_pi_le_iff.2 $ λ _, le_rfl
@[simp] lemma edist_pi_const [nonempty β] (a b : α) : edist (λ x : β, a) (λ _, b) = edist a b :=
finset.sup_const univ_nonempty (edist a b)
end pi
namespace emetric
variables {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : set α}
/-- `emetric.ball x ε` is the set of all points `y` with `edist y x < ε` -/
def ball (x : α) (ε : ℝ≥0∞) : set α := {y | edist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ edist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ edist x y < ε :=
by rw [edist_comm, mem_ball]
/-- `emetric.closed_ball x ε` is the set of all points `y` with `edist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ≥0∞) := {y | edist y x ≤ ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ edist y x ≤ ε := iff.rfl
theorem mem_closed_ball' : y ∈ closed_ball x ε ↔ edist x y ≤ ε :=
by rw [edist_comm, mem_closed_ball]
@[simp] theorem closed_ball_top (x : α) : closed_ball x ∞ = univ :=
eq_univ_of_forall $ λ y, le_top
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
assume y hy, le_of_lt hy
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
lt_of_le_of_lt (zero_le _) hy
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show edist x x < ε, by rw edist_self; assumption
theorem mem_closed_ball_self : x ∈ closed_ball x ε :=
show edist x x ≤ ε, by rw edist_self; exact bot_le
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by rw [mem_ball', mem_ball]
theorem mem_closed_ball_comm : x ∈ closed_ball y ε ↔ y ∈ closed_ball x ε :=
by rw [mem_closed_ball', mem_closed_ball]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
theorem closed_ball_subset_closed_ball (h : ε₁ ≤ ε₂) :
closed_ball x ε₁ ⊆ closed_ball x ε₂ :=
λ y (yx : _ ≤ ε₁), le_trans yx h
theorem ball_disjoint (h : ε₁ + ε₂ ≤ edist x y) : disjoint (ball x ε₁) (ball y ε₂) :=
set.disjoint_left.mpr $ λ z h₁ h₂,
(edist_triangle_left x y z).not_lt $ (ennreal.add_lt_add h₁ h₂).trans_le h
theorem ball_subset (h : edist x y + ε₁ ≤ ε₂) (h' : edist x y ≠ ∞) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, calc
edist z y ≤ edist z x + edist x y : edist_triangle _ _ _
... = edist x y + edist z x : add_comm _ _
... < edist x y + ε₁ : ennreal.add_lt_add_left h' zx
... ≤ ε₂ : h
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
begin
have : 0 < ε - edist y x := by simpa using h,
refine ⟨ε - edist y x, this, ball_subset _ (ne_top_of_lt h)⟩,
exact (add_tsub_cancel_of_le (mem_ball.mp h).le).le
end
theorem ball_eq_empty_iff : ball x ε = ∅ ↔ ε = 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λh, le_bot_iff.1 (le_of_not_gt (λ ε0, h _ (mem_ball_self ε0))),
λε0 y h, not_lt_of_le (le_of_eq ε0) (pos_of_mem_ball h)⟩
lemma ord_connected_set_of_closed_ball_subset (x : α) (s : set α) :
ord_connected {r | closed_ball x r ⊆ s} :=
⟨λ r₁ hr₁ r₂ hr₂ r hr, (closed_ball_subset_closed_ball hr.2).trans hr₂⟩
lemma ord_connected_set_of_ball_subset (x : α) (s : set α) :
ord_connected {r | ball x r ⊆ s} :=
⟨λ r₁ hr₁ r₂ hr₂ r hr, (ball_subset_ball hr.2).trans hr₂⟩
/-- Relation “two points are at a finite edistance” is an equivalence relation. -/
def edist_lt_top_setoid : setoid α :=
{ r := λ x y, edist x y < ⊤,
iseqv := ⟨λ x, by { rw edist_self, exact ennreal.coe_lt_top },
λ x y h, by rwa edist_comm,
λ x y z hxy hyz, lt_of_le_of_lt (edist_triangle x y z) (ennreal.add_lt_top.2 ⟨hxy, hyz⟩)⟩ }
@[simp] lemma ball_zero : ball x 0 = ∅ :=
by rw [emetric.ball_eq_empty_iff]
theorem nhds_basis_eball : (𝓝 x).has_basis (λ ε:ℝ≥0∞, 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_edist
lemma nhds_within_basis_eball : (𝓝[s] x).has_basis (λ ε : ℝ≥0∞, 0 < ε) (λ ε, ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_eball s
theorem nhds_basis_closed_eball : (𝓝 x).has_basis (λ ε:ℝ≥0∞, 0 < ε) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_edist_le
lemma nhds_within_basis_closed_eball :
(𝓝[s] x).has_basis (λ ε : ℝ≥0∞, 0 < ε) (λ ε, closed_ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_closed_eball s
theorem nhds_eq : 𝓝 x = (⨅ε>0, 𝓟 (ball x ε)) :=
nhds_basis_eball.eq_binfi
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s := nhds_basis_eball.mem_iff
lemma mem_nhds_within_iff : s ∈ 𝓝[t] x ↔ ∃ ε > 0, ball x ε ∩ t ⊆ s :=
nhds_within_basis_eball.mem_iff
section
variables [pseudo_emetric_space β] {f : α → β}
lemma tendsto_nhds_within_nhds_within {t : set β} {a b} :
tendsto f (𝓝[s] a) (𝓝[t] b) ↔
∀ ε > 0, ∃ δ > 0, ∀ ⦃x⦄, x ∈ s → edist x a < δ → f x ∈ t ∧ edist (f x) b < ε :=
(nhds_within_basis_eball.tendsto_iff nhds_within_basis_eball).trans $
forall₂_congr $ λ ε hε, exists₂_congr $ λ δ hδ,
forall_congr $ λ x, by simp; itauto
lemma tendsto_nhds_within_nhds {a b} :
tendsto f (𝓝[s] a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → edist x a < δ → edist (f x) b < ε :=
by { rw [← nhds_within_univ b, tendsto_nhds_within_nhds_within], simp only [mem_univ, true_and] }
lemma tendsto_nhds_nhds {a b} :
tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x⦄, edist x a < δ → edist (f x) b < ε :=
nhds_basis_eball.tendsto_iff nhds_basis_eball
end
theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp [is_open_iff_nhds, mem_nhds_iff]
theorem is_open_ball : is_open (ball x ε) :=
is_open_iff.2 $ λ y, exists_ball_subset_ball
theorem is_closed_ball_top : is_closed (ball x ⊤) :=
is_open_compl_iff.1 $ is_open_iff.2 $ λ y hy, ⟨⊤, ennreal.coe_lt_top,
(ball_disjoint $ by { rw ennreal.top_add, exact le_of_not_lt hy }).subset_compl_right⟩
theorem ball_mem_nhds (x : α) {ε : ℝ≥0∞} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
is_open_ball.mem_nhds (mem_ball_self ε0)
theorem closed_ball_mem_nhds (x : α) {ε : ℝ≥0∞} (ε0 : 0 < ε) : closed_ball x ε ∈ 𝓝 x :=
mem_of_superset (ball_mem_nhds x ε0) ball_subset_closed_ball
theorem ball_prod_same [pseudo_emetric_space β] (x : α) (y : β) (r : ℝ≥0∞) :
ball x r ×ˢ ball y r = ball (x, y) r :=
ext $ λ z, max_lt_iff.symm
theorem closed_ball_prod_same [pseudo_emetric_space β] (x : α) (y : β) (r : ℝ≥0∞) :
closed_ball x r ×ˢ closed_ball y r = closed_ball (x, y) r :=
ext $ λ z, max_le_iff.symm
/-- ε-characterization of the closure in pseudoemetric spaces -/
theorem mem_closure_iff :
x ∈ closure s ↔ ∀ε>0, ∃y ∈ s, edist x y < ε :=
(mem_closure_iff_nhds_basis nhds_basis_eball).trans $
by simp only [mem_ball, edist_comm x]
theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, edist (u x) a < ε :=
nhds_basis_eball.tendsto_right_iff
theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, edist (u n) a < ε :=
(at_top_basis.tendsto_iff nhds_basis_eball).trans $
by simp only [exists_prop, true_and, mem_Ici, mem_ball]
theorem inseparable_iff : inseparable x y ↔ edist x y = 0 :=
by simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le']
/-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually,
the pseudoedistance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy_seq_iff [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, edist (u m) (u n) < ε :=
uniformity_basis_edist.cauchy_seq_iff
/-- A variation around the emetric characterization of Cauchy sequences -/
theorem cauchy_seq_iff' [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ ∀ε>(0 : ℝ≥0∞), ∃N, ∀n≥N, edist (u n) (u N) < ε :=
uniformity_basis_edist.cauchy_seq_iff'
/-- A variation of the emetric characterization of Cauchy sequences that deals with
`ℝ≥0` upper bounds. -/
theorem cauchy_seq_iff_nnreal [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≤ n → edist (u n) (u N) < ε :=
uniformity_basis_edist_nnreal.cauchy_seq_iff'
theorem totally_bounded_iff {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, t.finite ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (edist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, h.trans $ Union₂_mono $ λ y yt z, hε⟩⟩
theorem totally_bounded_iff' {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t⊆s, set.finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, (totally_bounded_iff_subset.1 H) _ (edist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru,
⟨t, _, ft, h⟩ := H ε ε0 in
⟨t, ft, h.trans $ Union₂_mono $ λ y yt z, hε⟩⟩
section compact
/-- For a set `s` in a pseudo emetric space, if for every `ε > 0` there exists a countable
set that is `ε`-dense in `s`, then there exists a countable subset `t ⊆ s` that is dense in `s`. -/
lemma subset_countable_closure_of_almost_dense_set (s : set α)
(hs : ∀ ε > 0, ∃ t : set α, t.countable ∧ s ⊆ ⋃ x ∈ t, closed_ball x ε) :
∃ t ⊆ s, (t.countable ∧ s ⊆ closure t) :=
begin
rcases s.eq_empty_or_nonempty with rfl|⟨x₀, hx₀⟩,
{ exact ⟨∅, empty_subset _, countable_empty, empty_subset _⟩ },
choose! T hTc hsT using (λ n : ℕ, hs n⁻¹ (by simp)),
have : ∀ r x, ∃ y ∈ s, closed_ball x r ∩ s ⊆ closed_ball y (r * 2),
{ intros r x,
rcases (closed_ball x r ∩ s).eq_empty_or_nonempty with he|⟨y, hxy, hys⟩,
{ refine ⟨x₀, hx₀, _⟩, rw he, exact empty_subset _ },
{ refine ⟨y, hys, λ z hz, _⟩,
calc edist z y ≤ edist z x + edist y x : edist_triangle_right _ _ _
... ≤ r + r : add_le_add hz.1 hxy
... = r * 2 : (mul_two r).symm } },
choose f hfs hf,
refine ⟨⋃ n : ℕ, (f n⁻¹) '' (T n), Union_subset $ λ n, image_subset_iff.2 (λ z hz, hfs _ _),
countable_Union $ λ n, (hTc n).image _, _⟩,
refine λ x hx, mem_closure_iff.2 (λ ε ε0, _),
rcases ennreal.exists_inv_nat_lt (ennreal.half_pos ε0.lt.ne').ne' with ⟨n, hn⟩,
rcases mem_Union₂.1 (hsT n hx) with ⟨y, hyn, hyx⟩,
refine ⟨f n⁻¹ y, mem_Union.2 ⟨n, mem_image_of_mem _ hyn⟩, _⟩,
calc edist x (f n⁻¹ y) ≤ n⁻¹ * 2 : hf _ _ ⟨hyx, hx⟩
... < ε : ennreal.mul_lt_of_lt_div hn
end
/-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a
countable set. -/
lemma subset_countable_closure_of_compact {s : set α} (hs : is_compact s) :
∃ t ⊆ s, (t.countable ∧ s ⊆ closure t) :=
begin
refine subset_countable_closure_of_almost_dense_set s (λ ε hε, _),
rcases totally_bounded_iff'.1 hs.totally_bounded ε hε with ⟨t, hts, htf, hst⟩,
exact ⟨t, htf.countable,
subset.trans hst $ Union₂_mono $ λ _ _, ball_subset_closed_ball⟩
end
end compact
section second_countable
open _root_.topological_space
variables (α)
/-- A sigma compact pseudo emetric space has second countable topology. This is not an instance
to avoid a loop with `sigma_compact_space_of_locally_compact_second_countable`. -/
lemma second_countable_of_sigma_compact [sigma_compact_space α] :
second_countable_topology α :=
begin
suffices : separable_space α, by exactI uniform_space.second_countable_of_separable α,
choose T hTsub hTc hsubT
using λ n, subset_countable_closure_of_compact (is_compact_compact_covering α n),
refine ⟨⟨⋃ n, T n, countable_Union hTc, λ x, _⟩⟩,
rcases Union_eq_univ_iff.1 (Union_compact_covering α) x with ⟨n, hn⟩,
exact closure_mono (subset_Union _ n) (hsubT _ hn)
end
variable {α}
lemma second_countable_of_almost_dense_set
(hs : ∀ ε > 0, ∃ t : set α, t.countable ∧ (⋃ x ∈ t, closed_ball x ε) = univ) :
second_countable_topology α :=
begin
suffices : separable_space α, by exactI uniform_space.second_countable_of_separable α,
rcases subset_countable_closure_of_almost_dense_set (univ : set α) (λ ε ε0, _)
with ⟨t, -, htc, ht⟩,
{ exact ⟨⟨t, htc, λ x, ht (mem_univ x)⟩⟩ },
{ rcases hs ε ε0 with ⟨t, htc, ht⟩,
exact ⟨t, htc, univ_subset_iff.2 ht⟩ }
end
end second_countable
section diam
/-- The diameter of a set in a pseudoemetric space, named `emetric.diam` -/
noncomputable def diam (s : set α) := ⨆ (x ∈ s) (y ∈ s), edist x y
lemma diam_le_iff {d : ℝ≥0∞} :
diam s ≤ d ↔ ∀ (x ∈ s) (y ∈ s), edist x y ≤ d :=
by simp only [diam, supr_le_iff]
lemma diam_image_le_iff {d : ℝ≥0∞} {f : β → α} {s : set β} :
diam (f '' s) ≤ d ↔ ∀ (x ∈ s) (y ∈ s), edist (f x) (f y) ≤ d :=
by simp only [diam_le_iff, ball_image_iff]
lemma edist_le_of_diam_le {d} (hx : x ∈ s) (hy : y ∈ s) (hd : diam s ≤ d) : edist x y ≤ d :=
diam_le_iff.1 hd x hx y hy
/-- If two points belong to some set, their edistance is bounded by the diameter of the set -/
lemma edist_le_diam_of_mem (hx : x ∈ s) (hy : y ∈ s) : edist x y ≤ diam s :=
edist_le_of_diam_le hx hy le_rfl
/-- If the distance between any two points in a set is bounded by some constant, this constant
bounds the diameter. -/
lemma diam_le {d : ℝ≥0∞} (h : ∀ (x ∈ s) (y ∈ s), edist x y ≤ d) : diam s ≤ d := diam_le_iff.2 h
/-- The diameter of a subsingleton vanishes. -/
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
nonpos_iff_eq_zero.1 $ diam_le $
λ x hx y hy, (hs hx hy).symm ▸ edist_self y ▸ le_rfl
/-- The diameter of the empty set vanishes -/
@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- The diameter of a singleton vanishes -/
@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
diam_subsingleton subsingleton_singleton
lemma diam_Union_mem_option {ι : Type*} (o : option ι) (s : ι → set α) :
diam (⋃ i ∈ o, s i) = ⨆ i ∈ o, diam (s i) :=
by cases o; simp
lemma diam_insert : diam (insert x s) = max (⨆ y ∈ s, edist x y) (diam s) :=
eq_of_forall_ge_iff $ λ d, by simp only [diam_le_iff, ball_insert_iff,
edist_self, edist_comm x, max_le_iff, supr_le_iff, zero_le, true_and,
forall_and_distrib, and_self, ← and_assoc]
lemma diam_pair : diam ({x, y} : set α) = edist x y :=
by simp only [supr_singleton, diam_insert, diam_singleton, ennreal.max_zero_right]
lemma diam_triple :
diam ({x, y, z} : set α) = max (max (edist x y) (edist x z)) (edist y z) :=
by simp only [diam_insert, supr_insert, supr_singleton, diam_singleton,
ennreal.max_zero_right, ennreal.sup_eq_max]
/-- The diameter is monotonous with respect to inclusion -/
lemma diam_mono {s t : set α} (h : s ⊆ t) : diam s ≤ diam t :=
diam_le $ λ x hx y hy, edist_le_diam_of_mem (h hx) (h hy)
/-- The diameter of a union is controlled by the diameter of the sets, and the edistance
between two points in the sets. -/
lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + edist x y + diam t :=
begin
have A : ∀a ∈ s, ∀b ∈ t, edist a b ≤ diam s + edist x y + diam t := λa ha b hb, calc
edist a b ≤ edist a x + edist x y + edist y b : edist_triangle4 _ _ _ _
... ≤ diam s + edist x y + diam t :
add_le_add (add_le_add (edist_le_diam_of_mem ha xs) le_rfl) (edist_le_diam_of_mem yt hb),
refine diam_le (λa ha b hb, _),
cases (mem_union _ _ _).1 ha with h'a h'a; cases (mem_union _ _ _).1 hb with h'b h'b,
{ calc edist a b ≤ diam s : edist_le_diam_of_mem h'a h'b
... ≤ diam s + (edist x y + diam t) : le_self_add
... = diam s + edist x y + diam t : (add_assoc _ _ _).symm },
{ exact A a h'a b h'b },
{ have Z := A b h'b a h'a, rwa [edist_comm] at Z },
{ calc edist a b ≤ diam t : edist_le_diam_of_mem h'a h'b
... ≤ (diam s + edist x y) + diam t : le_add_self }
end
lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
let ⟨x, ⟨xs, xt⟩⟩ := h in by simpa using diam_union xs xt
lemma diam_closed_ball {r : ℝ≥0∞} : diam (closed_ball x r) ≤ 2 * r :=
diam_le $ λa ha b hb, calc
edist a b ≤ edist a x + edist b x : edist_triangle_right _ _ _
... ≤ r + r : add_le_add ha hb
... = 2 * r : (two_mul r).symm
lemma diam_ball {r : ℝ≥0∞} : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball) diam_closed_ball
lemma diam_pi_le_of_le {π : β → Type*} [fintype β] [∀ b, pseudo_emetric_space (π b)]
{s : Π (b : β), set (π b)} {c : ℝ≥0∞} (h : ∀ b, diam (s b) ≤ c) :
diam (set.pi univ s) ≤ c :=
begin
apply diam_le (λ x hx y hy, edist_pi_le_iff.mpr _),
rw [mem_univ_pi] at hx hy,
exact λ b, diam_le_iff.1 (h b) (x b) (hx b) (y b) (hy b),
end
end diam
end emetric --namespace
/-- We now define `emetric_space`, extending `pseudo_emetric_space`. -/
class emetric_space (α : Type u) extends pseudo_emetric_space α : Type u :=
(eq_of_edist_eq_zero : ∀ {x y : α}, edist x y = 0 → x = y)
variables {γ : Type w} [emetric_space γ]
export emetric_space (eq_of_edist_eq_zero)
/-- Characterize the equality of points by the vanishing of their extended distance -/
@[simp] theorem edist_eq_zero {x y : γ} : edist x y = 0 ↔ x = y :=
iff.intro eq_of_edist_eq_zero (assume : x = y, this ▸ edist_self _)
@[simp] theorem zero_eq_edist {x y : γ} : 0 = edist x y ↔ x = y :=
iff.intro (assume h, eq_of_edist_eq_zero (h.symm))
(assume : x = y, this ▸ (edist_self _).symm)
theorem edist_le_zero {x y : γ} : (edist x y ≤ 0) ↔ x = y :=
nonpos_iff_eq_zero.trans edist_eq_zero
@[simp] theorem edist_pos {x y : γ} : 0 < edist x y ↔ x ≠ y := by simp [← not_le]
/-- Two points coincide if their distance is `< ε` for all positive ε -/
theorem eq_of_forall_edist_le {x y : γ} (h : ∀ε > 0, edist x y ≤ ε) : x = y :=
eq_of_edist_eq_zero (eq_of_le_of_forall_le_of_dense bot_le h)
/-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniform_embedding_iff' [emetric_space β] {f : γ → β} :
uniform_embedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, edist a b < δ → edist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < δ) :=
begin
split,
{ assume h,
exact ⟨emetric.uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2⟩ },
{ rintros ⟨h₁, h₂⟩,
refine uniform_embedding_iff.2 ⟨_, emetric.uniform_continuous_iff.2 h₁, h₂⟩,
assume x y hxy,
have : edist x y ≤ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
have : edist (f x) (f y) < ε, by simpa [hxy],
exact hε this },
simpa using this }
end
/-- An emetric space is separated -/
@[priority 100] -- see Note [lower instance priority]
instance to_separated : separated_space γ :=
separated_def.2 $ λ x y h, eq_of_forall_edist_le $
λ ε ε0, le_of_lt (h _ (edist_mem_uniformity ε0))
/-- If a `pseudo_emetric_space` is a T₀ space, then it is an `emetric_space`. -/
def emetric.of_t0_pseudo_emetric_space (α : Type*) [pseudo_emetric_space α] [t0_space α] :
emetric_space α :=
{ eq_of_edist_eq_zero := λ x y hdist, inseparable.eq $ emetric.inseparable_iff.2 hdist,
..‹pseudo_emetric_space α› }
/-- Auxiliary function to replace the uniformity on an emetric space with
a uniformity which is equal to the original one, but maybe not defeq.
This is useful if one wants to construct an emetric space with a
specified uniformity. See Note [forgetful inheritance] explaining why having definitionally
the right uniformity is often important.
-/
def emetric_space.replace_uniformity {γ} [U : uniform_space γ] (m : emetric_space γ)
(H : @uniformity _ U = @uniformity _ pseudo_emetric_space.to_uniform_space) :
emetric_space γ :=
{ edist := @edist _ m.to_has_edist,
edist_self := edist_self,
eq_of_edist_eq_zero := @eq_of_edist_eq_zero _ _,
edist_comm := edist_comm,
edist_triangle := edist_triangle,
to_uniform_space := U,
uniformity_edist := H.trans (@pseudo_emetric_space.uniformity_edist γ _) }
/-- The extended metric induced by an injective function taking values in a emetric space. -/
def emetric_space.induced {γ β} (f : γ → β) (hf : function.injective f)
(m : emetric_space β) : emetric_space γ :=
{ edist := λ x y, edist (f x) (f y),
edist_self := λ x, edist_self _,
eq_of_edist_eq_zero := λ x y h, hf (edist_eq_zero.1 h),
edist_comm := λ x y, edist_comm _ _,
edist_triangle := λ x y z, edist_triangle _ _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_edist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, edist (f x) (f y)),
refine λ s, mem_comap.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_edist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, edist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
/-- Emetric space instance on subsets of emetric spaces -/
instance {α : Type*} {p : α → Prop} [emetric_space α] : emetric_space (subtype p) :=
emetric_space.induced coe subtype.coe_injective ‹_›
/-- Emetric space instance on the multiplicative opposite of an emetric space. -/
@[to_additive "Emetric space instance on the additive opposite of an emetric space."]
instance {α : Type*} [emetric_space α] : emetric_space αᵐᵒᵖ :=
emetric_space.induced mul_opposite.unop mul_opposite.unop_injective ‹_›
instance {α : Type*} [emetric_space α] : emetric_space (ulift α) :=
emetric_space.induced ulift.down ulift.down_injective ‹_›
/-- The product of two emetric spaces, with the max distance, is an extended
metric spaces. We make sure that the uniform structure thus constructed is the one
corresponding to the product of uniform spaces, to avoid diamond problems. -/
instance prod.emetric_space_max [emetric_space β] : emetric_space (γ × β) :=
{ eq_of_edist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
have A : x.fst = y.fst := edist_le_zero.1 h₁,
have B : x.snd = y.snd := edist_le_zero.1 h₂,
exact prod.ext_iff.2 ⟨A, B⟩
end,
..prod.pseudo_emetric_space_max }
/-- Reformulation of the uniform structure in terms of the extended distance -/
theorem uniformity_edist :
𝓤 γ = ⨅ ε>0, 𝓟 {p:γ×γ | edist p.1 p.2 < ε} :=
pseudo_emetric_space.uniformity_edist
section pi
open finset
variables {π : β → Type*} [fintype β]
/-- The product of a finite number of emetric spaces, with the max distance, is still
an emetric space.
This construction would also work for infinite products, but it would not give rise
to the product topology. Hence, we only formalize it in the good situation of finitely many
spaces. -/
instance emetric_space_pi [∀b, emetric_space (π b)] : emetric_space (Πb, π b) :=
{ eq_of_edist_eq_zero := assume f g eq0,
begin
have eq1 : sup univ (λ (b : β), edist (f b) (g b)) ≤ 0 := le_of_eq eq0,
simp only [finset.sup_le_iff] at eq1,
exact (funext $ assume b, edist_le_zero.1 $ eq1 b $ mem_univ b),
end,
..pseudo_emetric_space_pi }
end pi
namespace emetric
/-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/
lemma countable_closure_of_compact {s : set γ} (hs : is_compact s) :
∃ t ⊆ s, (t.countable ∧ s = closure t) :=
begin
rcases subset_countable_closure_of_compact hs with ⟨t, hts, htc, hsub⟩,
exact ⟨t, hts, htc, subset.antisymm hsub (closure_minimal hts hs.is_closed)⟩
end
section diam
variables {s : set γ}
lemma diam_eq_zero_iff : diam s = 0 ↔ s.subsingleton :=
⟨λ h x hx y hy, edist_le_zero.1 $ h ▸ edist_le_diam_of_mem hx hy, diam_subsingleton⟩
lemma diam_pos_iff : 0 < diam s ↔ ∃ (x ∈ s) (y ∈ s), x ≠ y :=
by simp only [pos_iff_ne_zero, ne.def, diam_eq_zero_iff, set.subsingleton, not_forall]
end diam
end emetric
/-!
### `additive`, `multiplicative`
The distance on those type synonyms is inherited without change.
-/
open additive multiplicative
section
variables [has_edist X]
instance : has_edist (additive X) := ‹has_edist X›
instance : has_edist (multiplicative X) := ‹has_edist X›
@[simp] lemma edist_of_mul (a b : X) : edist (of_mul a) (of_mul b) = edist a b := rfl
@[simp] lemma edist_of_add (a b : X) : edist (of_add a) (of_add b) = edist a b := rfl
@[simp] lemma edist_to_mul (a b : additive X) : edist (to_mul a) (to_mul b) = edist a b := rfl
@[simp] lemma edist_to_add (a b : multiplicative X) : edist (to_add a) (to_add b) = edist a b := rfl
end
instance [pseudo_emetric_space X] : pseudo_emetric_space (additive X) := ‹pseudo_emetric_space X›
instance [pseudo_emetric_space X] : pseudo_emetric_space (multiplicative X) :=
‹pseudo_emetric_space X›
instance [emetric_space X] : emetric_space (additive X) := ‹emetric_space X›
instance [emetric_space X] : emetric_space (multiplicative X) := ‹emetric_space X›
/-!
### Order dual
The distance on this type synonym is inherited without change.
-/
open order_dual
section
variables [has_edist X]
instance : has_edist Xᵒᵈ := ‹has_edist X›
@[simp] lemma edist_to_dual (a b : X) : edist (to_dual a) (to_dual b) = edist a b := rfl
@[simp] lemma edist_of_dual (a b : Xᵒᵈ) : edist (of_dual a) (of_dual b) = edist a b := rfl
end
instance [pseudo_emetric_space X] : pseudo_emetric_space Xᵒᵈ := ‹pseudo_emetric_space X›
instance [emetric_space X] : emetric_space Xᵒᵈ := ‹emetric_space X›
|
44a4190eac4e180e967184e1906e1d06c0a6740f | 974acfb39e2c67da7ef1a06bb8e25c4bb2c8b44b | /src/Sample.lean | 649d5d9f597c538582132a1cdc5179913f19e6e3 | [
"LicenseRef-scancode-mit-taylor-variant",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | o89/sample-nitro | 76bce8f46945cebc6c8d9a0b9c46aa3feecbd133 | 81db2099e42de1a0d4af00ff98ca74c95a531546 | refs/heads/master | 1,658,491,011,767 | 1,655,472,656,000 | 1,655,472,656,000 | 204,481,412 | 1 | 3 | null | 1,567,435,234,000 | 1,566,826,033,000 | HTML | UTF-8 | Lean | false | false | 1,169 | lean | import N2O.Default
import NITRO.Default
inductive Example
| send
instance : BERT Example :=
{ toTerm := λ x => match x with
| Example.send => Term.atom "send",
fromTerm := λ x => match x with
| Term.atom "send" => Sum.ok Example.send
| _ => Sum.fail "invalid Example term" }
def index : Nitro Example → Result
| Nitro.init => update Example "send" $
Elem.button "send" [] "Send"
{ source := [ "msg" ], type := "click", postback := Example.send }
| Nitro.message Example.send query =>
match query.lookup "msg" with
| some value => insertBottom Example "hist" (div [] [ Elem.liter value ])
| _ => Result.ok
| Nitro.error s => Result.ok
| Nitro.ping => pong
| _ => Result.ok
def about : Nitro Example → Result
| Nitro.init => updateText "app" "This is the N2O Hello World App"
| Nitro.ping => pong
| _ => Result.ok
def router (cx : Nitro.cx Example) : Nitro.cx Example :=
let handler := match Req.path cx.req with
| "/ws/static/index.html" => index
| "/ws/static/about.html" => about
| _ => ignore;
⟨cx.req, handler⟩
def handler : Handler := mkHandler (nitroProto Example) [ router ]
def main := startServer handler ("localhost", 9000)
|
04b9ea4550cd5ae2740588eda2eeaf5fff6c0e6a | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/topology/instances/nnreal.lean | ff0cd9279ce0ed52ca2a17aad3ad89e125e9bbf7 | [
"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 | 9,243 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import topology.algebra.infinite_sum
import topology.algebra.group_with_zero
/-!
# Topology on `ℝ≥0`
The natural topology on `ℝ≥0` (the one induced from `ℝ`), and a basic API.
## Main definitions
Instances for the following typeclasses are defined:
* `topological_space ℝ≥0`
* `topological_semiring ℝ≥0`
* `second_countable_topology ℝ≥0`
* `order_topology ℝ≥0`
* `has_continuous_sub ℝ≥0`
* `has_continuous_inv₀ ℝ≥0` (continuity of `x⁻¹` away from `0`)
* `has_continuous_smul ℝ≥0 ℝ`
Everything is inherited from the corresponding structures on the reals.
## Main statements
Various mathematically trivial lemmas are proved about the compatibility
of limits and sums in `ℝ≥0` and `ℝ`. For example
* `tendsto_coe {f : filter α} {m : α → ℝ≥0} {x : ℝ≥0} :
tendsto (λa, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ tendsto m f (𝓝 x)`
says that the limit of a filter along a map to `ℝ≥0` is the same in `ℝ` and `ℝ≥0`, and
* `coe_tsum {f : α → ℝ≥0} : ((∑'a, f a) : ℝ) = (∑'a, (f a : ℝ))`
says that says that a sum of elements in `ℝ≥0` is the same in `ℝ` and `ℝ≥0`.
Similarly, some mathematically trivial lemmas about infinite sums are proved,
a few of which rely on the fact that subtraction is continuous.
-/
noncomputable theory
open set topological_space metric filter
open_locale topological_space
namespace nnreal
open_locale nnreal big_operators filter
instance : topological_space ℝ≥0 := infer_instance -- short-circuit type class inference
instance : topological_semiring ℝ≥0 :=
{ continuous_mul := continuous_subtype_mk _ $
(continuous_subtype_val.comp continuous_fst).mul (continuous_subtype_val.comp continuous_snd),
continuous_add := continuous_subtype_mk _ $
(continuous_subtype_val.comp continuous_fst).add (continuous_subtype_val.comp continuous_snd) }
instance : second_countable_topology ℝ≥0 :=
topological_space.subtype.second_countable_topology _ _
instance : order_topology ℝ≥0 := @order_topology_of_ord_connected _ _ _ _ (Ici 0) _
section coe
variable {α : Type*}
open filter finset
lemma _root_.continuous_real_to_nnreal : continuous real.to_nnreal :=
continuous_subtype_mk _ $ continuous_id.max continuous_const
lemma continuous_coe : continuous (coe : ℝ≥0 → ℝ) :=
continuous_subtype_val
/-- Embedding of `ℝ≥0` to `ℝ` as a bundled continuous map. -/
@[simps { fully_applied := ff }] def _root_.continuous_map.coe_nnreal_real : C(ℝ≥0, ℝ) :=
⟨coe, continuous_coe⟩
instance {X : Type*} [topological_space X] : can_lift C(X, ℝ) C(X, ℝ≥0) :=
{ coe := continuous_map.coe_nnreal_real.comp,
cond := λ f, ∀ x, 0 ≤ f x,
prf := λ f hf, ⟨⟨λ x, ⟨f x, hf x⟩, continuous_subtype_mk _ f.2⟩, fun_like.ext' rfl⟩ }
@[simp, norm_cast] lemma tendsto_coe {f : filter α} {m : α → ℝ≥0} {x : ℝ≥0} :
tendsto (λa, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ tendsto m f (𝓝 x) :=
tendsto_subtype_rng.symm
lemma tendsto_coe' {f : filter α} [ne_bot f] {m : α → ℝ≥0} {x : ℝ} :
tendsto (λ a, m a : α → ℝ) f (𝓝 x) ↔ ∃ hx : 0 ≤ x, tendsto m f (𝓝 ⟨x, hx⟩) :=
⟨λ h, ⟨ge_of_tendsto' h (λ c, (m c).2), tendsto_coe.1 h⟩, λ ⟨hx, hm⟩, tendsto_coe.2 hm⟩
@[simp] lemma map_coe_at_top : map (coe : ℝ≥0 → ℝ) at_top = at_top :=
map_coe_Ici_at_top 0
lemma comap_coe_at_top : comap (coe : ℝ≥0 → ℝ) at_top = at_top :=
(at_top_Ici_eq 0).symm
@[simp, norm_cast] lemma tendsto_coe_at_top {f : filter α} {m : α → ℝ≥0} :
tendsto (λ a, (m a : ℝ)) f at_top ↔ tendsto m f at_top :=
tendsto_Ici_at_top.symm
lemma tendsto_real_to_nnreal {f : filter α} {m : α → ℝ} {x : ℝ} (h : tendsto m f (𝓝 x)) :
tendsto (λa, real.to_nnreal (m a)) f (𝓝 (real.to_nnreal x)) :=
(continuous_real_to_nnreal.tendsto _).comp h
lemma nhds_zero : 𝓝 (0 : ℝ≥0) = ⨅a ≠ 0, 𝓟 (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot]
lemma nhds_zero_basis : (𝓝 (0 : ℝ≥0)).has_basis (λ a : ℝ≥0, 0 < a) (λ a, Iio a) :=
nhds_bot_basis
instance : has_continuous_sub ℝ≥0 :=
⟨continuous_subtype_mk _ $
((continuous_coe.comp continuous_fst).sub
(continuous_coe.comp continuous_snd)).max continuous_const⟩
instance : has_continuous_inv₀ ℝ≥0 :=
⟨λ x hx, tendsto_coe.1 $ (real.tendsto_inv $ nnreal.coe_ne_zero.2 hx).comp
continuous_coe.continuous_at⟩
instance : has_continuous_smul ℝ≥0 ℝ :=
{ continuous_smul := continuous.comp real.continuous_mul $ continuous.prod_mk
(continuous.comp continuous_subtype_val continuous_fst) continuous_snd }
@[norm_cast] lemma has_sum_coe {f : α → ℝ≥0} {r : ℝ≥0} :
has_sum (λa, (f a : ℝ)) (r : ℝ) ↔ has_sum f r :=
by simp only [has_sum, coe_sum.symm, tendsto_coe]
lemma has_sum_real_to_nnreal_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : summable f) :
has_sum (λ n, real.to_nnreal (f n)) (real.to_nnreal (∑' n, f n)) :=
begin
have h_sum : (λ s, ∑ b in s, real.to_nnreal (f b)) = λ s, real.to_nnreal (∑ b in s, f b),
from funext (λ _, (real.to_nnreal_sum_of_nonneg (λ n _, hf_nonneg n)).symm),
simp_rw [has_sum, h_sum],
exact tendsto_real_to_nnreal hf.has_sum,
end
@[norm_cast] lemma summable_coe {f : α → ℝ≥0} : summable (λa, (f a : ℝ)) ↔ summable f :=
begin
split,
exact assume ⟨a, ha⟩, ⟨⟨a, has_sum_le (λa, (f a).2) has_sum_zero ha⟩, has_sum_coe.1 ha⟩,
exact assume ⟨a, ha⟩, ⟨a.1, has_sum_coe.2 ha⟩
end
lemma summable_coe_of_nonneg {f : α → ℝ} (hf₁ : ∀ n, 0 ≤ f n) :
@summable (ℝ≥0) _ _ _ (λ n, ⟨f n, hf₁ n⟩) ↔ summable f :=
begin
lift f to α → ℝ≥0 using hf₁ with f rfl hf₁,
simp only [summable_coe, subtype.coe_eta]
end
open_locale classical
@[norm_cast] lemma coe_tsum {f : α → ℝ≥0} : ↑∑'a, f a = ∑'a, (f a : ℝ) :=
if hf : summable f
then (eq.symm $ (has_sum_coe.2 $ hf.has_sum).tsum_eq)
else by simp [tsum, hf, mt summable_coe.1 hf]
lemma coe_tsum_of_nonneg {f : α → ℝ} (hf₁ : ∀ n, 0 ≤ f n) :
(⟨∑' n, f n, tsum_nonneg hf₁⟩ : ℝ≥0) = (∑' n, ⟨f n, hf₁ n⟩ : ℝ≥0) :=
begin
lift f to α → ℝ≥0 using hf₁ with f rfl hf₁,
simp_rw [← nnreal.coe_tsum, subtype.coe_eta]
end
lemma tsum_mul_left (a : ℝ≥0) (f : α → ℝ≥0) : ∑' x, a * f x = a * ∑' x, f x :=
nnreal.eq $ by simp only [coe_tsum, nnreal.coe_mul, tsum_mul_left]
lemma tsum_mul_right (f : α → ℝ≥0) (a : ℝ≥0) : (∑' x, f x * a) = (∑' x, f x) * a :=
nnreal.eq $ by simp only [coe_tsum, nnreal.coe_mul, tsum_mul_right]
lemma summable_comp_injective {β : Type*} {f : α → ℝ≥0} (hf : summable f)
{i : β → α} (hi : function.injective i) :
summable (f ∘ i) :=
nnreal.summable_coe.1 $
show summable ((coe ∘ f) ∘ i), from (nnreal.summable_coe.2 hf).comp_injective hi
lemma summable_nat_add (f : ℕ → ℝ≥0) (hf : summable f) (k : ℕ) : summable (λ i, f (i + k)) :=
summable_comp_injective hf $ add_left_injective k
lemma summable_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) : summable (λ i, f (i + k)) ↔ summable f :=
begin
rw [← summable_coe, ← summable_coe],
exact @summable_nat_add_iff ℝ _ _ _ (λ i, (f i : ℝ)) k,
end
lemma has_sum_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) {a : ℝ≥0} :
has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) :=
by simp [← has_sum_coe, coe_sum, nnreal.coe_add, ← has_sum_nat_add_iff k]
lemma sum_add_tsum_nat_add {f : ℕ → ℝ≥0} (k : ℕ) (hf : summable f) :
∑' i, f i = (∑ i in range k, f i) + ∑' i, f (i + k) :=
by rw [←nnreal.coe_eq, coe_tsum, nnreal.coe_add, coe_sum, coe_tsum,
sum_add_tsum_nat_add k (nnreal.summable_coe.2 hf)]
lemma infi_real_pos_eq_infi_nnreal_pos [complete_lattice α] {f : ℝ → α} :
(⨅ (n : ℝ) (h : 0 < n), f n) = (⨅ (n : ℝ≥0) (h : 0 < n), f n) :=
le_antisymm (infi_mono' $ λ r, ⟨r, le_rfl⟩) (infi₂_mono' $ λ r hr, ⟨⟨r, hr.le⟩, hr, le_rfl⟩)
end coe
lemma tendsto_cofinite_zero_of_summable {α} {f : α → ℝ≥0} (hf : summable f) :
tendsto f cofinite (𝓝 0) :=
begin
have h_f_coe : f = λ n, real.to_nnreal (f n : ℝ), from funext (λ n, real.to_nnreal_coe.symm),
rw [h_f_coe, ← @real.to_nnreal_coe 0],
exact tendsto_real_to_nnreal ((summable_coe.mpr hf).tendsto_cofinite_zero),
end
lemma tendsto_at_top_zero_of_summable {f : ℕ → ℝ≥0} (hf : summable f) :
tendsto f at_top (𝓝 0) :=
by { rw ←nat.cofinite_eq_at_top, exact tendsto_cofinite_zero_of_summable hf }
/-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole
space. This does not need a summability assumption, as otherwise all sums are zero. -/
lemma tendsto_tsum_compl_at_top_zero {α : Type*} (f : α → ℝ≥0) :
tendsto (λ (s : finset α), ∑' b : {x // x ∉ s}, f b) at_top (𝓝 0) :=
begin
simp_rw [← tendsto_coe, coe_tsum, nnreal.coe_zero],
exact tendsto_tsum_compl_at_top_zero (λ (a : α), (f a : ℝ))
end
end nnreal
|
345f22266d1848f336ee446c0e19d9c056dfdb58 | 129628888508a22919f176e3ba2033c3b52fa859 | /src/embedding.lean | 716e94786bc5586704d5267af064d97e0a251bf9 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/P11-Galois-Theory | 1aa35b6aa71c08aec6da3296ba404bf246db8df3 | ced2caa52300feb633316b3120c40ca957c8e8ff | refs/heads/master | 1,671,253,848,362 | 1,600,080,687,000 | 1,600,080,687,000 | 160,926,153 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,455 | lean | import field_theory.minimal_polynomial
import ring_theory.algebra
import field_theory.subfield
import ring_theory.adjoin_root
import linear_algebra.basic
universes u v w
noncomputable theory
open_locale classical
def galois_conjugates (α : Type u) {β : Type v} {γ : Type w}
[field α] [field β] [field γ] [algebra α β] [algebra α γ]
{b : β} {c : γ} (Hb : is_integral α b) (Hc : is_integral α c) : Prop :=
minimal_polynomial Hb = minimal_polynomial Hc
open algebra
open field
open adjoin_root
/-
Goal 1 : Let L, N be K-extensions and a ∈ L algebraic over K.
Then the K-extension morphisms from K(a) to N biject with
the set of galois K-conjugates of a in N.
Formalize as two functions,
(1) taking K-ext morphisms from K(a) into N to a galois conjugate
(2) taking a galois conjugate in N, returning a K-ext morphism
from K(a) to N
-/
open ideal.quotient
open quotient
instance wdihtpt1 {α : Type u} [comm_ring α] (I : ideal α) :
algebra α (I.quotient) :=
ring_hom.to_algebra $ mk_hom I
instance wdihtpt2 {α : Type u} {β : Type v}
[comm_ring α] [comm_ring β] [algebra α β]
(f : polynomial α) : algebra α (adjoin_root f) :=
comap.algebra α (polynomial α) (adjoin_root f)
def wdihtpt3 {α : Type u} {β : Type v} {γ : Type w}
[comm_semiring α] [semiring β] [semiring γ]
[algebra α β] [algebra α γ] (φ : β →+* γ)
(h : ∀ a : α, φ (algebra_map α β a) = algebra_map α γ a) :
β →ₐ[α] γ := ⟨φ.to_fun, ring_hom.map_one _,ring_hom.map_mul _,
ring_hom.map_zero _,ring_hom.map_add _,h⟩
-- Essentially function (2)
-- Actually already exists in ring_theory.adjoin_root
-- but only as a ring map.
def algebra_lift
{α : Type u} {β : Type v} [comm_ring α] [comm_ring β] [algebra α β]
(f : polynomial α) {x : β} (h : f.eval₂ (algebra_map α β) x = 0) :
(adjoin_root f) →ₐ[α] β := wdihtpt3 (adjoin_root.lift (algebra_map α β) x h)
$ λ a : α, lift_of
#check @algebra_lift
open minimal_polynomial
def field.adjoin {K : Type u} {L : Type v}
[field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
subalgebra K L :=
alg_hom.range $ algebra_lift (minimal_polynomial Hx) $ aeval Hx
open function
lemma adjoin_root_to_field_adjoin_inj {K : Type u} {L : Type v}
[field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
injective (algebra_lift (minimal_polynomial Hx) (aeval Hx)) :=
@ring_hom.injective (adjoin_root (minimal_polynomial Hx)) L
(@field.to_division_ring _ (
@adjoin_root.field _ _ (minimal_polynomial Hx)
(minimal_polynomial.irreducible Hx))
) _ ↑(algebra_lift (minimal_polynomial Hx) (aeval Hx))
lemma adjoin_root_to_field_adjoin_surj {K : Type u} {L : Type v}
[field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
surjective (algebra_lift (minimal_polynomial Hx) (aeval Hx)) := sorry
def adjoin_equiv_adjoin {K : Type u} {L : Type v}
[field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
adjoin_root (minimal_polynomial Hx) ≃ₐ[K] field.adjoin Hx :=
sorry
-- instance field.adjoin.is_subfield {K : Type u} {L : Type v}
-- [field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
-- is_subfield (field.adjoin Hx).carrier := sorry
theorem adjoin_eq_closure {K : Type u} {L : Type v}
[field K] [field L] [algebra K L] {x : L} (Hx : is_integral K x) :
(field.adjoin Hx).carrier = closure ((set.range $ algebra_map K L) ∪ {x}) :=
sorry -- do we actually care about this? |
956e7c6f5beb7790618f46d459789150e71ff7dc | 1446f520c1db37e157b631385707cc28a17a595e | /tests/compiler/closure_bug8.lean | 5e53b8b36e2f0baf66b4e30ad79464e641409016 | [
"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 | 501 | lean | def f (x : Nat) : Nat × (Nat → String) :=
let x1 := x + 1;
let x2 := x + 2;
let x3 := x + 3;
let x4 := x + 4;
let x5 := x + 5;
let x6 := x + 6;
let x7 := x + 7;
let x8 := x + 8;
let x9 := x + 9;
let x10 := x + 10;
let x11 := x + 11;
let x12 := x + 12;
let x13 := x + 13;
let x14 := x + 14;
let x15 := x + 15;
let x16 := x + 16;
let x17 := x + 17;
(x, fun y => toString [x1, x2, x3, x4, x5, x6])
def main (xs : List String) : IO Unit :=
IO.println ((f (xs.headD "0").toNat).2 (xs.headD "0").toNat)
|
7ea82c10ff87da53ba56e5895499edaabb5acf46 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/analysis/normed_space/ordered.lean | 92612591ab467b1a419bd652773d69179d614c06 | [
"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 | 1,958 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import analysis.normed_space.basic
/-!
# Ordered normed spaces
In this file, we define classes for fields and groups that are both normed and ordered.
These are mostly useful to avoid diamonds during type class inference.
-/
open filter set
open_locale topological_space
/-- A `normed_linear_ordered_group` is an additive group that is both a `normed_group` and
a `linear_ordered_add_comm_group`. This class is necessary to avoid diamonds. -/
class normed_linear_ordered_group (α : Type*)
extends linear_ordered_add_comm_group α, has_norm α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
@[priority 100] instance normed_linear_ordered_group.to_normed_group (α : Type*)
[normed_linear_ordered_group α] : normed_group α :=
⟨normed_linear_ordered_group.dist_eq⟩
/-- A `normed_linear_ordered_field` is a field that is both a `normed_field` and a
`linear_ordered_field`. This class is necessary to avoid diamonds. -/
class normed_linear_ordered_field (α : Type*)
extends linear_ordered_field α, has_norm α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_mul' : ∀ a b, norm (a * b) = norm a * norm b)
@[priority 100] instance normed_linear_ordered_field.to_normed_field (α : Type*)
[normed_linear_ordered_field α] : normed_field α :=
{ dist_eq := normed_linear_ordered_field.dist_eq,
norm_mul' := normed_linear_ordered_field.norm_mul' }
@[priority 100] instance normed_linear_ordered_field.to_normed_linear_ordered_group (α : Type*)
[normed_linear_ordered_field α] : normed_linear_ordered_group α :=
⟨normed_linear_ordered_field.dist_eq⟩
noncomputable
instance : normed_linear_ordered_field ℚ :=
⟨dist_eq_norm, norm_mul⟩
noncomputable
instance : normed_linear_ordered_field ℝ :=
⟨dist_eq_norm, norm_mul⟩
|
d2c98b2e3d799cc44e1eed58570bfc1cd82df185 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/bad_notation.lean | acb2ed317a5e4d445c5530d66db870e636b1bb09 | [
"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 | 120 | lean | import logic data.nat.basic
open nat
section
variable a : nat
notation `a1`:max := a + 1
end
definition foo := a1
|
44a25f632358cd8b1085d3d28f87c4a312948eb8 | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/algebraic_geometry/locally_ringed_space.lean | 4c1c6871c84d2c0a83873f4cc151cbc39e1994a7 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,604 | 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 algebraic_geometry.ringed_space
import data.equiv.transfer_instance
/-!
# The category of locally ringed spaces
We define (bundled) locally ringed spaces (as `SheafedSpace CommRing` along with the fact that the
stalks are local rings), and morphisms between these (morphisms in `SheafedSpace` with
`is_local_ring_hom` on the stalk maps).
## Future work
* Define the restriction along an open embedding
-/
universes v u
open category_theory
open Top
open topological_space
open opposite
open category_theory.category category_theory.functor
namespace algebraic_geometry
/-- A `LocallyRingedSpace` is a topological space equipped with a sheaf of commutative rings
such that all the stalks are local rings.
A morphism of locally ringed spaces is a morphism of ringed spaces
such that the morphims induced on stalks are local ring homomorphisms. -/
@[nolint has_inhabited_instance]
structure LocallyRingedSpace extends SheafedSpace CommRing :=
(local_ring : ∀ x, local_ring (presheaf.stalk x))
attribute [instance] LocallyRingedSpace.local_ring
namespace LocallyRingedSpace
variables (X : LocallyRingedSpace)
/--
An alias for `to_SheafedSpace`, where the result type is a `RingedSpace`.
This allows us to use dot-notation for the `RingedSpace` namespace.
-/
def to_RingedSpace : RingedSpace := X.to_SheafedSpace
/-- The underlying topological space of a locally ringed space. -/
def to_Top : Top := X.1.carrier
instance : has_coe_to_sort LocallyRingedSpace (Type u) :=
⟨λ X : LocallyRingedSpace, (X.to_Top : Type u)⟩
-- PROJECT: how about a typeclass "has_structure_sheaf" to mediate the 𝒪 notation, rather
-- than defining it over and over for PresheafedSpace, LRS, Scheme, etc.
/-- The structure sheaf of a locally ringed space. -/
def 𝒪 : sheaf CommRing X.to_Top := X.to_SheafedSpace.sheaf
/-- A morphism of locally ringed spaces is a morphism of ringed spaces
such that the morphims induced on stalks are local ring homomorphisms. -/
def hom (X Y : LocallyRingedSpace) : Type* :=
{ f : X.to_SheafedSpace ⟶ Y.to_SheafedSpace //
∀ x, is_local_ring_hom (PresheafedSpace.stalk_map f x) }
instance : quiver LocallyRingedSpace := ⟨hom⟩
@[ext] lemma hom_ext {X Y : LocallyRingedSpace} (f g : hom X Y) (w : f.1 = g.1) : f = g :=
subtype.eq w
/--
The stalk of a locally ringed space, just as a `CommRing`.
-/
-- TODO perhaps we should make a bundled `LocalRing` and return one here?
-- TODO define `sheaf.stalk` so we can write `X.𝒪.stalk` here?
noncomputable
def stalk (X : LocallyRingedSpace) (x : X) : CommRing := X.presheaf.stalk x
/--
A morphism of locally ringed spaces `f : X ⟶ Y` induces
a local ring homomorphism from `Y.stalk (f x)` to `X.stalk x` for any `x : X`.
-/
noncomputable
def stalk_map {X Y : LocallyRingedSpace} (f : X ⟶ Y) (x : X) :
Y.stalk (f.1.1 x) ⟶ X.stalk x :=
PresheafedSpace.stalk_map f.1 x
instance {X Y : LocallyRingedSpace} (f : X ⟶ Y) (x : X) :
is_local_ring_hom (stalk_map f x) := f.2 x
/-- The identity morphism on a locally ringed space. -/
@[simps]
def id (X : LocallyRingedSpace) : hom X X :=
⟨𝟙 _, λ x, by { erw PresheafedSpace.stalk_map.id, apply is_local_ring_hom_id, }⟩
instance (X : LocallyRingedSpace) : inhabited (hom X X) := ⟨id X⟩
/-- Composition of morphisms of locally ringed spaces. -/
@[simps]
def comp {X Y Z : LocallyRingedSpace} (f : hom X Y) (g : hom Y Z) : hom X Z :=
⟨f.val ≫ g.val, λ x,
begin
erw PresheafedSpace.stalk_map.comp,
exact @is_local_ring_hom_comp _ _ _ _ _ _ _ _ (f.2 _) (g.2 _),
end⟩
/-- The category of locally ringed spaces. -/
instance : category LocallyRingedSpace :=
{ hom := hom,
id := id,
comp := λ X Y Z f g, comp f g,
comp_id' := by { intros, ext1, simp, },
id_comp' := by { intros, ext1, simp, },
assoc' := by { intros, ext1, simp, }, }.
/-- The forgetful functor from `LocallyRingedSpace` to `SheafedSpace CommRing`. -/
def forget_to_SheafedSpace : LocallyRingedSpace ⥤ SheafedSpace CommRing :=
{ obj := λ X, X.to_SheafedSpace,
map := λ X Y f, f.1, }
instance : faithful forget_to_SheafedSpace := {}
/--
Given two locally ringed spaces `X` and `Y`, an isomorphism between `X` and `Y` as _sheafed_
spaces can be lifted to a morphism `X ⟶ Y` as locally ringed spaces.
See also `iso_of_SheafedSpace_iso`.
-/
@[simps]
def hom_of_SheafedSpace_hom_of_is_iso {X Y : LocallyRingedSpace}
(f : X.to_SheafedSpace ⟶ Y.to_SheafedSpace) [is_iso f] : X ⟶ Y :=
subtype.mk f $ λ x,
-- Here we need to see that the stalk maps are really local ring homomorphisms.
-- This can be solved by type class inference, because stalk maps of isomorphisms are isomorphisms
-- and isomorphisms are local ring homomorphisms.
show is_local_ring_hom (PresheafedSpace.stalk_map
(SheafedSpace.forget_to_PresheafedSpace.map f) x),
by apply_instance
/--
Given two locally ringed spaces `X` and `Y`, an isomorphism between `X` and `Y` as _sheafed_
spaces can be lifted to an isomorphism `X ⟶ Y` as locally ringed spaces.
This is related to the property that the functor `forget_to_SheafedSpace` reflects isomorphisms.
In fact, it is slightly stronger as we do not require `f` to come from a morphism between
_locally_ ringed spaces.
-/
def iso_of_SheafedSpace_iso {X Y : LocallyRingedSpace}
(f : X.to_SheafedSpace ≅ Y.to_SheafedSpace) : X ≅ Y :=
{ hom := hom_of_SheafedSpace_hom_of_is_iso f.hom,
inv := hom_of_SheafedSpace_hom_of_is_iso f.inv,
hom_inv_id' := hom_ext _ _ f.hom_inv_id,
inv_hom_id' := hom_ext _ _ f.inv_hom_id }
instance : reflects_isomorphisms forget_to_SheafedSpace :=
{ reflects := λ X Y f i,
{ out := by exactI
⟨hom_of_SheafedSpace_hom_of_is_iso (category_theory.inv (forget_to_SheafedSpace.map f)),
hom_ext _ _ (is_iso.hom_inv_id _), hom_ext _ _ (is_iso.inv_hom_id _)⟩ } }
/--
The restriction of a locally ringed space along an open embedding.
-/
@[simps]
def restrict {U : Top} (X : LocallyRingedSpace) (f : U ⟶ X.to_Top)
(h : open_embedding f) : LocallyRingedSpace :=
{ local_ring :=
begin
intro x,
dsimp at *,
-- We show that the stalk of the restriction is isomorphic to the original stalk,
apply @ring_equiv.local_ring _ _ _ (X.local_ring (f x)),
exact (X.to_PresheafedSpace.restrict_stalk_iso f h x).symm.CommRing_iso_to_ring_equiv,
end,
.. X.to_SheafedSpace.restrict f h }
/--
The restriction of a locally ringed space `X` to the top subspace is isomorphic to `X` itself.
-/
def restrict_top_iso (X : LocallyRingedSpace) :
X.restrict (opens.inclusion ⊤) (opens.open_embedding ⊤) ≅ X :=
@iso_of_SheafedSpace_iso (X.restrict (opens.inclusion ⊤) (opens.open_embedding ⊤)) X
X.to_SheafedSpace.restrict_top_iso
/--
The global sections, notated Gamma.
-/
def Γ : LocallyRingedSpaceᵒᵖ ⥤ CommRing :=
forget_to_SheafedSpace.op ⋙ SheafedSpace.Γ
lemma Γ_def : Γ = forget_to_SheafedSpace.op ⋙ SheafedSpace.Γ := rfl
@[simp] lemma Γ_obj (X : LocallyRingedSpaceᵒᵖ) : Γ.obj X = (unop X).presheaf.obj (op ⊤) := rfl
lemma Γ_obj_op (X : LocallyRingedSpace) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl
@[simp] lemma Γ_map {X Y : LocallyRingedSpaceᵒᵖ} (f : X ⟶ Y) :
Γ.map f = f.unop.1.c.app (op ⊤) ≫ (unop Y).presheaf.map (opens.le_map_top _ _).op := rfl
lemma Γ_map_op {X Y : LocallyRingedSpace} (f : X ⟶ Y) :
Γ.map f.op = f.1.c.app (op ⊤) ≫ X.presheaf.map (opens.le_map_top _ _).op := rfl
end LocallyRingedSpace
end algebraic_geometry
|
bdc69a4354eea252cd84550a53d9a8d7c896f7f6 | efce24474b28579aba3272fdb77177dc2b11d7aa | /src/homotopy_theory/formal/cofibrations/cofibration_category.lean | 54efefca93d2edd7bed75716a2128fba6f9ee4f4 | [
"Apache-2.0"
] | permissive | rwbarton/lean-homotopy-theory | cff499f24268d60e1c546e7c86c33f58c62888ed | 39e1b4ea1ed1b0eca2f68bc64162dde6a6396dee | refs/heads/lean-3.4.2 | 1,622,711,883,224 | 1,598,550,958,000 | 1,598,550,958,000 | 136,023,667 | 12 | 6 | Apache-2.0 | 1,573,187,573,000 | 1,528,116,262,000 | Lean | UTF-8 | Lean | false | false | 2,529 | lean | import homotopy_theory.formal.weak_equivalences.definitions
import .precofibration_category
universes v u
open category_theory
local notation f ` ∘ `:80 g:80 := g ≫ f
namespace homotopy_theory.cofibrations
open homotopy_theory.weak_equivalences
variables {C : Type u} [category.{v} C]
/-
[Baues, Algebraic homotopy, §I.1] defines a cofibration category to be
a category equipped with cofibrations and weak equivalences satisfying
the following axioms.
C1. Weak equivalences and cofibrations are subcategories which contain
all the isomorphisms, and weak equivalences satisfy two-out-of-three.
C2. Pushouts by cofibrations exist and are again cofibrations. Moreover,
(a) a pushout of a weak equivalence by a cofibration is again a weak
equivalence;
(b) a pushout of an acyclic cofibration is again acyclic.
C3. Any map may be factored into a cofibration followed by a weak
equivalence.
C4. For any object X, there exists an acyclic cofibration X → RX with
RX fibrant, that is, any trivial cofibration out of RX admits a
retract.
We omit the axiom C2(a). As Baues already notes, many results on
cofibration categories do not depend on this axiom. We call a
cofibration category which additionally satisfies C2(a) left proper.
Axiom C1 and the first part of axiom C2 are contained in the
superclasses `category_with_weak_equivalences`,
`precofibration_category`. The remaining axioms are C2(b), C3, C4.
-/
def is_acof [precofibration_category C] [category_with_weak_equivalences C]
{a x : C} (j : a ⟶ x) : Prop := is_cof j ∧ is_weq j
def fibrant [precofibration_category C] [category_with_weak_equivalences C]
(x : C) : Prop :=
∀ ⦃y⦄ {j : x ⟶ y} (hj : is_acof j), ∃ r, r ∘ j = 𝟙 x
variables (C)
class cofibration_category extends category_with_weak_equivalences C,
precofibration_category.{v} C :=
(pushout_is_acof : ∀ ⦃a b a' b' : C⦄ {f : a ⟶ b} {g : a ⟶ a'} {f' : a' ⟶ b'} {g' : b ⟶ b'},
Is_pushout f g g' f' → is_acof f → is_acof f')
(factorization : ∀ {a x : C} (f : a ⟶ x), ∃ b (j : a ⟶ b) (g : b ⟶ x),
is_cof j ∧ is_weq g ∧ g ∘ j = f)
(fibrant_replacement : ∀ (x : C), ∃ rx (j : x ⟶ rx), is_acof j ∧ fibrant rx)
-- Baues' axiom C2(a).
class left_proper [cofibration_category.{v} C] : Prop :=
(pushout_weq_by_cof : ∀ ⦃a b a' b' : C⦄ {f : a ⟶ b} {g : a ⟶ a'} {f' : a' ⟶ b'} {g' : b ⟶ b'},
Is_pushout f g g' f' → is_cof f → is_weq g → is_weq g')
end homotopy_theory.cofibrations
|
f0c2aef5ded31d850c9caa4adb29048c0f9c0271 | f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58 | /category_theory/category.lean | ee8f7cfb107c10592a551a7abb2b50c291bf3109 | [
"Apache-2.0"
] | permissive | semorrison/mathlib | 1be6f11086e0d24180fec4b9696d3ec58b439d10 | 20b4143976dad48e664c4847b75a85237dca0a89 | refs/heads/master | 1,583,799,212,170 | 1,535,634,130,000 | 1,535,730,505,000 | 129,076,205 | 0 | 0 | Apache-2.0 | 1,551,697,998,000 | 1,523,442,265,000 | Lean | UTF-8 | Lean | false | false | 2,860 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison
Defines a category, as a typeclass parametrised by the type of objects.
Introduces notations
`X ⟶ Y` for the morphism spaces,
`f ≫ g` for composition in the 'arrows' convention.
Users may like to add `f ⊚ g` for composition in the standard convention, using
```
local notation f ` ⊚ `:80 g:80 := category.comp g f -- type as \oo
```
-/
import tactic.restate_axiom
import tactic.replacer
import tactic.interactive
namespace category_theory
universes u v
/-
The propositional fields of `category` are annotated with the auto_param `obviously`, which is just a synonym for `skip`.
Actually, there is a tactic called `obviously` which is not part of this pull request, which should be used here. It successfully
discharges a great many of these goals. For now, proofs which could be provided entirely by `obviously` (and hence omitted entirely
and discharged by an auto_param), are all marked with a comment "-- obviously says:".
-/
def_replacer obviously
/--
The typeclass `category C` describes morphisms associated to objects of type `C`.
The universe levels of the objects and morphisms are unconstrained, and will often need to be specified explicitly, as `category.{u v} C`. (See also `large_category` and `small_category`.)
-/
class category (obj : Type u) : Type (max u (v+1)) :=
(hom : obj → obj → Type v)
(id : Π X : obj, hom X X)
(comp : Π {X Y Z : obj}, hom X Y → hom Y Z → hom X Z)
(id_comp' : ∀ {X Y : obj} (f : hom X Y), comp (id X) f = f . obviously)
(comp_id' : ∀ {X Y : obj} (f : hom X Y), comp f (id Y) = f . obviously)
(assoc' : ∀ {W X Y Z : obj} (f : hom W X) (g : hom X Y) (h : hom Y Z), comp (comp f g) h = comp f (comp g h) . obviously)
notation `𝟙` := category.id -- type as \b1
infixr ` ≫ `:80 := category.comp -- type as \gg
infixr ` ⟶ `:10 := category.hom -- type as \h
-- `restate_axiom` is a command that creates a lemma from a structure field, discarding any auto_param wrappers from the type.
-- (It removes a backtick from the name, if it finds one, and otherwise adds "_lemma".)
restate_axiom category.id_comp'
restate_axiom category.comp_id'
restate_axiom category.assoc'
attribute [simp] category.id_comp category.comp_id category.assoc
/--
A `large_category` has objects in one universe level higher than the universe level of the morphisms.
It is useful for examples such as the category of types, or the category of groups, etc.
-/
abbreviation large_category (C : Type (u+1)) : Type (u+1) := category.{u+1 u} C
/--
A `small_category` has objects and morphisms in the same universe level.
-/
abbreviation small_category (C : Type u) : Type (u+1) := category.{u u} C
end category_theory
|
0dd316ca6cb652f917eb9c7103de37f9d671516e | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/ring_theory/witt_vector/is_poly.lean | f4e53d386b559b0d7e58587decf2c2b22fd4d2cc | [
"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 | 23,404 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import algebra.ring.ulift
import ring_theory.witt_vector.basic
import data.mv_polynomial.funext
/-!
# The `is_poly` predicate
`witt_vector.is_poly` is a (type-valued) predicate on functions `f : Π R, 𝕎 R → 𝕎 R`.
It asserts that there is a family of polynomials `φ : ℕ → mv_polynomial ℕ ℤ`,
such that the `n`th coefficient of `f x` is equal to `φ n` evaluated on the coefficients of `x`.
Many operations on Witt vectors satisfy this predicate (or an analogue for higher arity functions).
We say that such a function `f` is a *polynomial function*.
The power of satisfying this predicate comes from `is_poly.ext`.
It shows that if `φ` and `ψ` witness that `f` and `g` are polynomial functions,
then `f = g` not merely when `φ = ψ`, but in fact it suffices to prove
```
∀ n, bind₁ φ (witt_polynomial p _ n) = bind₁ ψ (witt_polynomial p _ n)
```
(in other words, when evaluating the Witt polynomials on `φ` and `ψ`, we get the same values)
which will then imply `φ = ψ` and hence `f = g`.
Even though this sufficient condition looks somewhat intimidating,
it is rather pleasant to check in practice;
more so than direct checking of `φ = ψ`.
In practice, we apply this technique to show that the composition of `witt_vector.frobenius`
and `witt_vector.verschiebung` is equal to multiplication by `p`.
## Main declarations
* `witt_vector.is_poly`, `witt_vector.is_poly₂`:
two predicates that assert that a unary/binary function on Witt vectors
is polynomial in the coefficients of the input values.
* `witt_vector.is_poly.ext`, `witt_vector.is_poly₂.ext`:
two polynomial functions are equal if their families of polynomials are equal
after evaluating the Witt polynomials on them.
* `witt_vector.is_poly.comp` (+ many variants) show that unary/binary compositions
of polynomial functions are polynomial.
* `witt_vector.id_is_poly`, `witt_vector.neg_is_poly`,
`witt_vector.add_is_poly₂`, `witt_vector.mul_is_poly₂`:
several well-known operations are polynomial functions
(for Verschiebung, Frobenius, and multiplication by `p`, see their respective files).
## On higher arity analogues
Ideally, there should be a predicate `is_polyₙ` for functions of higher arity,
together with `is_polyₙ.comp` that shows how such functions compose.
Since mathlib does not have a library on composition of higher arity functions,
we have only implemented the unary and binary variants so far.
Nullary functions (a.k.a. constants) are treated
as constant functions and fall under the unary case.
## Tactics
There are important metaprograms defined in this file:
the tactics `ghost_simp` and `ghost_calc` and the attributes `@[is_poly]` and `@[ghost_simps]`.
These are used in combination to discharge proofs of identities between polynomial functions.
Any atomic proof of `is_poly` or `is_poly₂` (i.e. not taking additional `is_poly` arguments)
should be tagged as `@[is_poly]`.
Any lemma doing "ring equation rewriting" with polynomial functions should be tagged
`@[ghost_simps]`, e.g.
```lean
@[ghost_simps]
lemma bind₁_frobenius_poly_witt_polynomial (n : ℕ) :
bind₁ (frobenius_poly p) (witt_polynomial p ℤ n) = (witt_polynomial p ℤ (n+1))
```
Proofs of identities between polynomial functions will often follow the pattern
```lean
begin
ghost_calc _,
<minor preprocessing>,
ghost_simp
end
```
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
/-
### Simplification tactics
`ghost_simp` is used later in the development for certain simplifications.
We define it here so it is a shared import.
-/
mk_simp_attribute ghost_simps
"Simplification rules for ghost equations"
namespace tactic
namespace interactive
setup_tactic_parser
/-- A macro for a common simplification when rewriting with ghost component equations. -/
meta def ghost_simp (lems : parse simp_arg_list) : tactic unit :=
do tactic.try tactic.intro1,
simp none none tt
(lems ++ [simp_arg_type.symm_expr ``(sub_eq_add_neg)])
[`ghost_simps] (loc.ns [none])
/--
`ghost_calc` is a tactic for proving identities between polynomial functions.
Typically, when faced with a goal like
```lean
∀ (x y : 𝕎 R), verschiebung (x * frobenius y) = verschiebung x * y
```
you can
1. call `ghost_calc`
2. do a small amount of manual work -- maybe nothing, maybe `rintro`, etc
3. call `ghost_simp`
and this will close the goal.
`ghost_calc` cannot detect whether you are dealing with unary or binary polynomial functions.
You must give it arguments to determine this.
If you are proving a universally quantified goal like the above,
call `ghost_calc _ _`.
If the variables are introduced already, call `ghost_calc x y`.
In the unary case, use `ghost_calc _` or `ghost_calc x`.
`ghost_calc` is a light wrapper around type class inference.
All it does is apply the appropriate extensionality lemma and try to infer the resulting goals.
This is subtle and Lean's elaborator doesn't like it because of the HO unification involved,
so it is easier (and prettier) to put it in a tactic script.
-/
meta def ghost_calc (ids' : parse ident_*) : tactic unit :=
do ids ← ids'.mmap $ λ n, get_local n <|> tactic.intro n,
`(@eq (witt_vector _ %%R) _ _) ← target,
match ids with
| [x] := refine ```(is_poly.ext _ _ _ _ %%x)
| [x, y] := refine ```(is_poly₂.ext _ _ _ _ %%x %%y)
| _ := fail "ghost_calc takes one or two arguments"
end,
nm ← match R with
| expr.local_const _ nm _ _ := return nm
| _ := get_unused_name `R
end,
iterate_exactly 2 apply_instance,
unfreezingI (tactic.clear' tt [R]),
introsI $ [nm, nm<.>"_inst"] ++ ids',
skip
end interactive
end tactic
namespace witt_vector
universe u
variables {p : ℕ} {R S : Type u} {σ idx : Type*} [hp : fact p.prime] [comm_ring R] [comm_ring S]
local notation `𝕎` := witt_vector p -- type as `\bbW`
open mv_polynomial
open function (uncurry)
include hp
variables (p)
noncomputable theory
/-!
### The `is_poly` predicate
-/
lemma poly_eq_of_witt_polynomial_bind_eq' (f g : ℕ → mv_polynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ f (witt_polynomial p _ n) = bind₁ g (witt_polynomial p _ n)) :
f = g :=
begin
ext1 n,
apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective,
rw ← function.funext_iff at h,
replace h := congr_arg
(λ fam, bind₁ (mv_polynomial.map (int.cast_ring_hom ℚ) ∘ fam)
(X_in_terms_of_W p ℚ n)) h,
simpa only [function.comp, map_bind₁, map_witt_polynomial,
← bind₁_bind₁, bind₁_witt_polynomial_X_in_terms_of_W, bind₁_X_right] using h
end
lemma poly_eq_of_witt_polynomial_bind_eq (f g : ℕ → mv_polynomial ℕ ℤ)
(h : ∀ n, bind₁ f (witt_polynomial p _ n) = bind₁ g (witt_polynomial p _ n)) :
f = g :=
begin
ext1 n,
apply mv_polynomial.map_injective (int.cast_ring_hom ℚ) int.cast_injective,
rw ← function.funext_iff at h,
replace h := congr_arg
(λ fam, bind₁ (mv_polynomial.map (int.cast_ring_hom ℚ) ∘ fam)
(X_in_terms_of_W p ℚ n)) h,
simpa only [function.comp, map_bind₁, map_witt_polynomial,
← bind₁_bind₁, bind₁_witt_polynomial_X_in_terms_of_W, bind₁_X_right] using h
end
omit hp
-- Ideally, we would generalise this to n-ary functions
-- But we don't have a good theory of n-ary compositions in mathlib
/--
A function `f : Π R, 𝕎 R → 𝕎 R` that maps Witt vectors to Witt vectors over arbitrary base rings
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x` is given by evaluating `φₙ` at the coefficients of `x`.
See also `witt_vector.is_poly₂` for the binary variant.
The `ghost_calc` tactic treats `is_poly` as a type class,
and the `@[is_poly]` attribute derives certain specialized composition instances
for declarations of type `is_poly f`.
For the most part, users are not expected to treat `is_poly` as a class.
-/
class is_poly (f : Π ⦃R⦄ [comm_ring R], witt_vector p R → 𝕎 R) : Prop :=
mk' :: (poly : ∃ φ : ℕ → mv_polynomial ℕ ℤ, ∀ ⦃R⦄ [comm_ring R] (x : 𝕎 R),
by exactI (f x).coeff = λ n, aeval x.coeff (φ n))
/-- The identity function on Witt vectors is a polynomial function. -/
instance id_is_poly : is_poly p (λ _ _, id) :=
⟨⟨X, by { introsI, simp only [aeval_X, id] }⟩⟩
instance id_is_poly_i' : is_poly p (λ _ _ a, a) :=
witt_vector.id_is_poly _
namespace is_poly
instance : inhabited (is_poly p (λ _ _, id)) :=
⟨witt_vector.id_is_poly p⟩
variables {p}
include hp
lemma ext {f g} (hf : is_poly p f) (hg : is_poly p g)
(h : ∀ (R : Type u) [_Rcr : comm_ring R] (x : 𝕎 R) (n : ℕ),
by exactI ghost_component n (f x) = ghost_component n (g x)) :
∀ (R : Type u) [_Rcr : comm_ring R] (x : 𝕎 R), by exactI f x = g x :=
begin
unfreezingI
{ obtain ⟨φ, hf⟩ := hf,
obtain ⟨ψ, hg⟩ := hg },
intros,
ext n,
rw [hf, hg, poly_eq_of_witt_polynomial_bind_eq p φ ψ],
intro k,
apply mv_polynomial.funext,
intro x,
simp only [hom_bind₁],
specialize h (ulift ℤ) (mk p $ λ i, ⟨x i⟩) k,
simp only [ghost_component_apply, aeval_eq_eval₂_hom] at h,
apply (ulift.ring_equiv.symm : ℤ ≃+* _).injective,
simp only [←ring_equiv.coe_to_ring_hom, map_eval₂_hom],
convert h using 1,
all_goals {
funext i,
simp only [hf, hg, mv_polynomial.eval, map_eval₂_hom],
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
ext1,
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
simp only [coeff_mk], refl }
end
omit hp
/-- The composition of polynomial functions is polynomial. -/
lemma comp {g f} (hg : is_poly p g) (hf : is_poly p f) :
is_poly p (λ R _Rcr, @g R _Rcr ∘ @f R _Rcr) :=
begin
unfreezingI
{ obtain ⟨φ, hf⟩ := hf,
obtain ⟨ψ, hg⟩ := hg },
use (λ n, bind₁ φ (ψ n)),
intros,
simp only [aeval_bind₁, function.comp, hg, hf]
end
end is_poly
/--
A binary function `f : Π R, 𝕎 R → 𝕎 R → 𝕎 R` on Witt vectors
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x y` is given by evaluating `φₙ` at the coefficients of `x` and `y`.
See also `witt_vector.is_poly` for the unary variant.
The `ghost_calc` tactic treats `is_poly₂` as a type class,
and the `@[is_poly]` attribute derives certain specialized composition instances
for declarations of type `is_poly₂ f`.
For the most part, users are not expected to treat `is_poly₂` as a class.
-/
class is_poly₂ (f : Π ⦃R⦄ [comm_ring R], witt_vector p R → 𝕎 R → 𝕎 R) : Prop :=
mk' :: (poly : ∃ φ : ℕ → mv_polynomial (fin 2 × ℕ) ℤ, ∀ ⦃R⦄ [comm_ring R] (x y : 𝕎 R),
by exactI (f x y).coeff = λ n, peval (φ n) ![x.coeff, y.coeff])
variable {p}
/-- The composition of polynomial functions is polynomial. -/
lemma is_poly₂.comp {h f g} (hh : is_poly₂ p h) (hf : is_poly p f) (hg : is_poly p g) :
is_poly₂ p (λ R _Rcr x y, by exactI h (f x) (g y)) :=
begin
unfreezingI
{ obtain ⟨φ, hf⟩ := hf,
obtain ⟨ψ, hg⟩ := hg,
obtain ⟨χ, hh⟩ := hh },
refine ⟨⟨(λ n, bind₁ (uncurry $
![λ k, rename (prod.mk (0 : fin 2)) (φ k),
λ k, rename (prod.mk (1 : fin 2)) (ψ k)]) (χ n)), _⟩⟩,
intros,
funext n,
simp only [peval, aeval_bind₁, function.comp, hh, hf, hg, uncurry],
apply eval₂_hom_congr rfl _ rfl,
ext ⟨i, n⟩,
fin_cases i;
simp only [aeval_eq_eval₂_hom, eval₂_hom_rename, function.comp, matrix.cons_val_zero,
matrix.head_cons, matrix.cons_val_one],
end
/-- The composition of a polynomial function with a binary polynomial function is polynomial. -/
lemma is_poly.comp₂ {g f} (hg : is_poly p g) (hf : is_poly₂ p f) :
is_poly₂ p (λ R _Rcr x y, by exactI g (f x y)) :=
begin
unfreezingI
{ obtain ⟨φ, hf⟩ := hf,
obtain ⟨ψ, hg⟩ := hg },
use (λ n, bind₁ φ (ψ n)),
intros,
simp only [peval, aeval_bind₁, function.comp, hg, hf]
end
/-- The diagonal `λ x, f x x` of a polynomial function `f` is polynomial. -/
lemma is_poly₂.diag {f} (hf : is_poly₂ p f) :
is_poly p (λ R _Rcr x, by exactI f x x) :=
begin
unfreezingI {obtain ⟨φ, hf⟩ := hf},
refine ⟨⟨λ n, bind₁ (uncurry ![X, X]) (φ n), _⟩⟩,
intros, funext n,
simp only [hf, peval, uncurry, aeval_bind₁],
apply eval₂_hom_congr rfl _ rfl,
ext ⟨i, k⟩, fin_cases i;
simp only [matrix.head_cons, aeval_X, matrix.cons_val_zero, matrix.cons_val_one],
end
open tactic
namespace tactic
/-!
### The `@[is_poly]` attribute
This attribute is used to derive specialized composition instances
for `is_poly` and `is_poly₂` declarations.
-/
/--
If `n` is the name of a lemma with opened type `∀ vars, is_poly p _`,
`mk_poly_comp_lemmas n vars p` adds composition instances to the environment
`n.comp_i` and `n.comp₂_i`.
-/
meta def mk_poly_comp_lemmas (n : name) (vars : list expr) (p : expr) : tactic unit :=
do c ← mk_const n,
let appd := vars.foldl expr.app c,
tgt_bod ← to_expr ``(λ f [hf : is_poly %%p f], is_poly.comp %%appd hf) >>=
replace_univ_metas_with_univ_params,
tgt_bod ← lambdas vars tgt_bod,
tgt_tp ← infer_type tgt_bod,
let nm := n <.> "comp_i",
add_decl $ mk_definition nm tgt_tp.collect_univ_params tgt_tp tgt_bod,
set_attribute `instance nm,
tgt_bod ← to_expr ``(λ f [hf : is_poly₂ %%p f], is_poly.comp₂ %%appd hf) >>=
replace_univ_metas_with_univ_params,
tgt_bod ← lambdas vars tgt_bod,
tgt_tp ← infer_type tgt_bod,
let nm := n <.> "comp₂_i",
add_decl $ mk_definition nm tgt_tp.collect_univ_params tgt_tp tgt_bod,
set_attribute `instance nm
/--
If `n` is the name of a lemma with opened type `∀ vars, is_poly₂ p _`,
`mk_poly₂_comp_lemmas n vars p` adds composition instances to the environment
`n.comp₂_i` and `n.comp_diag`.
-/
meta def mk_poly₂_comp_lemmas (n : name) (vars : list expr) (p : expr) : tactic unit :=
do c ← mk_const n,
let appd := vars.foldl expr.app c,
tgt_bod ← to_expr ``(λ {f g} [hf : is_poly %%p f] [hg : is_poly %%p g],
is_poly₂.comp %%appd hf hg) >>= replace_univ_metas_with_univ_params,
tgt_bod ← lambdas vars tgt_bod,
tgt_tp ← infer_type tgt_bod >>= simp_lemmas.mk.dsimplify,
let nm := n <.> "comp₂_i",
add_decl $ mk_definition nm tgt_tp.collect_univ_params tgt_tp tgt_bod,
set_attribute `instance nm,
tgt_bod ← to_expr ``(λ {f g} [hf : is_poly %%p f] [hg : is_poly %%p g],
(is_poly₂.comp %%appd hf hg).diag) >>= replace_univ_metas_with_univ_params,
tgt_bod ← lambdas vars tgt_bod,
tgt_tp ← infer_type tgt_bod >>= simp_lemmas.mk.dsimplify,
let nm := n <.> "comp_diag",
add_decl $ mk_definition nm tgt_tp.collect_univ_params tgt_tp tgt_bod,
set_attribute `instance nm
/--
The `after_set` function for `@[is_poly]`. Calls `mk_poly(₂)_comp_lemmas`.
-/
meta def mk_comp_lemmas (n : name) : tactic unit :=
do d ← get_decl n,
(vars, tp) ← open_pis d.type,
match tp with
| `(is_poly %%p _) := mk_poly_comp_lemmas n vars p
| `(is_poly₂ %%p _) := mk_poly₂_comp_lemmas n vars p
| _ := fail "@[is_poly] should only be applied to terms of type `is_poly _ _` or `is_poly₂ _ _`"
end
/--
`@[is_poly]` is applied to lemmas of the form `is_poly f φ` or `is_poly₂ f φ`.
These lemmas should *not* be tagged as instances, and only atomic `is_poly` defs should be tagged:
composition lemmas should not. Roughly speaking, lemmas that take `is_poly` proofs as arguments
should not be tagged.
Type class inference struggles with function composition, and the higher order unification problems
involved in inferring `is_poly` proofs are complex. The standard style writing these proofs by hand
doesn't work very well. Instead, we construct the type class hierarchy "under the hood", with
limited forms of composition.
Applying `@[is_poly]` to a lemma creates a number of instances. Roughly, if the tagged lemma is a
proof of `is_poly f φ`, the instances added have the form
```lean
∀ g ψ, [is_poly g ψ] → is_poly (f ∘ g) _
```
Since `f` is fixed in this instance, it restricts the HO unification needed when the instance is
applied. Composition lemmas relating `is_poly` with `is_poly₂` are also added.
`id_is_poly` is an atomic instance.
The user-written lemmas are not instances. Users should be able to assemble `is_poly` proofs by hand
"as normal" if the tactic fails.
-/
@[user_attribute] meta def is_poly_attr : user_attribute :=
{ name := `is_poly,
descr := "Lemmas with this attribute describe the polynomial structure of functions",
after_set := some $ λ n _ _, mk_comp_lemmas n }
end tactic
include hp
/-!
### `is_poly` instances
These are not declared as instances at the top level,
but the `@[is_poly]` attribute adds instances based on each one.
Users are expected to use the non-instance versions manually.
-/
/-- The additive negation is a polynomial function on Witt vectors. -/
@[is_poly]
lemma neg_is_poly : is_poly p (λ R _, by exactI @has_neg.neg (𝕎 R) _) :=
⟨⟨λ n, rename prod.snd (witt_neg p n),
begin
introsI, funext n,
rw [neg_coeff, aeval_eq_eval₂_hom, eval₂_hom_rename],
apply eval₂_hom_congr rfl _ rfl,
ext ⟨i, k⟩, fin_cases i, refl,
end⟩⟩
section zero_one
/- To avoid a theory of 0-ary functions (a.k.a. constants)
we model them as constant unary functions. -/
/-- The function that is constantly zero on Witt vectors is a polynomial function. -/
instance zero_is_poly : is_poly p (λ _ _ _, by exactI 0) :=
⟨⟨0, by { introsI, funext n, simp only [pi.zero_apply, alg_hom.map_zero, zero_coeff] }⟩⟩
@[simp] lemma bind₁_zero_witt_polynomial (n : ℕ) :
bind₁ (0 : ℕ → mv_polynomial ℕ R) (witt_polynomial p R n) = 0 :=
by rw [← aeval_eq_bind₁, aeval_zero, constant_coeff_witt_polynomial, ring_hom.map_zero]
omit hp
/-- The coefficients of `1 : 𝕎 R` as polynomials. -/
def one_poly (n : ℕ) : mv_polynomial ℕ ℤ := if n = 0 then 1 else 0
include hp
@[simp] lemma bind₁_one_poly_witt_polynomial (n : ℕ) :
bind₁ one_poly (witt_polynomial p ℤ n) = 1 :=
begin
rw [witt_polynomial_eq_sum_C_mul_X_pow, alg_hom.map_sum, finset.sum_eq_single 0],
{ simp only [one_poly, one_pow, one_mul, alg_hom.map_pow, C_1, pow_zero, bind₁_X_right,
if_true, eq_self_iff_true], },
{ intros i hi hi0,
simp only [one_poly, if_neg hi0, zero_pow (pow_pos hp.1.pos _), mul_zero,
alg_hom.map_pow, bind₁_X_right, alg_hom.map_mul], },
{ rw finset.mem_range, dec_trivial }
end
/-- The function that is constantly one on Witt vectors is a polynomial function. -/
instance one_is_poly : is_poly p (λ _ _ _, by exactI 1) :=
⟨⟨one_poly,
begin
introsI, funext n, cases n,
{ simp only [one_poly, if_true, eq_self_iff_true, one_coeff_zero, alg_hom.map_one], },
{ simp only [one_poly, nat.succ_pos', one_coeff_eq_of_pos,
if_neg n.succ_ne_zero, alg_hom.map_zero] }
end⟩⟩
end zero_one
omit hp
/-- Addition of Witt vectors is a polynomial function. -/
@[is_poly] lemma add_is_poly₂ [fact p.prime] : is_poly₂ p (λ _ _, by exactI (+)) :=
⟨⟨witt_add p, by { introsI, dunfold witt_vector.has_add, simp [eval] }⟩⟩
/-- Multiplication of Witt vectors is a polynomial function. -/
@[is_poly] lemma mul_is_poly₂ [fact p.prime] : is_poly₂ p (λ _ _, by exactI (*)) :=
⟨⟨witt_mul p, by { introsI, dunfold witt_vector.has_mul, simp [eval] }⟩⟩
include hp
-- unfortunately this is not universe polymorphic, merely because `f` isn't
lemma is_poly.map {f} (hf : is_poly p f) (g : R →+* S) (x : 𝕎 R) :
map g (f x) = f (map g x) :=
begin
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
-- see `is_poly₂.map` for a slightly more general proof strategy
unfreezingI {obtain ⟨φ, hf⟩ := hf},
ext n,
simp only [map_coeff, hf, map_aeval],
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
simp only [map_coeff]
end
namespace is_poly₂
omit hp
instance [fact p.prime] : inhabited (is_poly₂ p _) := ⟨add_is_poly₂⟩
variables {p}
/-- The composition of a binary polynomial function
with a unary polynomial function in the first argument is polynomial. -/
lemma comp_left {g f} (hg : is_poly₂ p g) (hf : is_poly p f) :
is_poly₂ p (λ R _Rcr x y, by exactI g (f x) y) :=
hg.comp hf (witt_vector.id_is_poly _)
/-- The composition of a binary polynomial function
with a unary polynomial function in the second argument is polynomial. -/
lemma comp_right {g f} (hg : is_poly₂ p g) (hf : is_poly p f) :
is_poly₂ p (λ R _Rcr x y, by exactI g x (f y)) :=
hg.comp (witt_vector.id_is_poly p) hf
include hp
lemma ext {f g} (hf : is_poly₂ p f) (hg : is_poly₂ p g)
(h : ∀ (R : Type u) [_Rcr : comm_ring R] (x y : 𝕎 R) (n : ℕ),
by exactI ghost_component n (f x y) = ghost_component n (g x y)) :
∀ (R) [_Rcr : comm_ring R] (x y : 𝕎 R), by exactI f x y = g x y :=
begin
unfreezingI
{ obtain ⟨φ, hf⟩ := hf,
obtain ⟨ψ, hg⟩ := hg },
intros,
ext n,
rw [hf, hg, poly_eq_of_witt_polynomial_bind_eq' p φ ψ],
clear x y,
intro k,
apply mv_polynomial.funext,
intro x,
simp only [hom_bind₁],
specialize h (ulift ℤ) (mk p $ λ i, ⟨x (0, i)⟩) (mk p $ λ i, ⟨x (1, i)⟩) k,
simp only [ghost_component_apply, aeval_eq_eval₂_hom] at h,
apply (ulift.ring_equiv.symm : ℤ ≃+* _).injective,
simp only [←ring_equiv.coe_to_ring_hom, map_eval₂_hom],
convert h using 1,
all_goals {
funext i,
simp only [hf, hg, mv_polynomial.eval, map_eval₂_hom],
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
ext1,
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
ext ⟨b, _⟩,
fin_cases b; simp only [coeff_mk, uncurry]; refl }
end
-- unfortunately this is not universe polymorphic, merely because `f` isn't
lemma map {f} (hf : is_poly₂ p f) (g : R →+* S) (x y : 𝕎 R) :
map g (f x y) = f (map g x) (map g y) :=
begin
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
unfreezingI {obtain ⟨φ, hf⟩ := hf},
ext n,
simp only [map_coeff, hf, map_aeval, peval, uncurry],
apply eval₂_hom_congr (ring_hom.ext_int _ _) _ rfl,
try { ext ⟨i, k⟩, fin_cases i },
all_goals {
simp only [map_coeff, matrix.cons_val_zero, matrix.head_cons, matrix.cons_val_one] },
end
end is_poly₂
attribute [ghost_simps]
alg_hom.map_zero alg_hom.map_one alg_hom.map_add alg_hom.map_mul
alg_hom.map_sub alg_hom.map_neg alg_hom.id_apply alg_hom.map_nat_cast
ring_hom.map_zero ring_hom.map_one ring_hom.map_mul ring_hom.map_add
ring_hom.map_sub ring_hom.map_neg ring_hom.id_apply ring_hom.map_nat_cast
mul_add add_mul add_zero zero_add mul_one one_mul mul_zero zero_mul
nat.succ_ne_zero add_tsub_cancel_right nat.succ_eq_add_one
if_true eq_self_iff_true if_false forall_true_iff forall_2_true_iff forall_3_true_iff
end witt_vector
|
244215e5949e010afa2b742aa0d56a7d7cad19e1 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/ring_theory/localization/inv_submonoid.lean | bbab92af6e54b6046b7b835c015fb373e4064004 | [
"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 | 3,966 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import group_theory.submonoid.inverses
import ring_theory.finiteness
import ring_theory.localization.basic
import tactic.ring_exp
/-!
# Submonoid of inverses
## Main definitions
* `is_localization.inv_submonoid M S` is the submonoid of `S = M⁻¹R` consisting of inverses of
each element `x ∈ M`
## Implementation notes
See `src/ring_theory/localization/basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variables {R : Type*} [comm_ring R] (M : submonoid R) (S : Type*) [comm_ring S]
variables [algebra R S] {P : Type*} [comm_ring P]
open function
open_locale big_operators
namespace is_localization
section inv_submonoid
variables (M S)
/-- The submonoid of `S = M⁻¹R` consisting of `{ 1 / x | x ∈ M }`. -/
def inv_submonoid : submonoid S := (M.map (algebra_map R S)).left_inv
variable [is_localization M S]
lemma submonoid_map_le_is_unit : M.map (algebra_map R S) ≤ is_unit.submonoid S :=
by { rintros _ ⟨a, ha, rfl⟩, exact is_localization.map_units S ⟨_, ha⟩ }
/-- There is an equivalence of monoids between the image of `M` and `inv_submonoid`. -/
noncomputable
abbreviation equiv_inv_submonoid : M.map (algebra_map R S) ≃* inv_submonoid M S :=
((M.map (algebra_map R S)).left_inv_equiv (submonoid_map_le_is_unit M S)).symm
/-- There is a canonical map from `M` to `inv_submonoid` sending `x` to `1 / x`. -/
noncomputable
def to_inv_submonoid : M →* inv_submonoid M S :=
(equiv_inv_submonoid M S).to_monoid_hom.comp ((algebra_map R S : R →* S).submonoid_map M)
lemma to_inv_submonoid_surjective : function.surjective (to_inv_submonoid M S) :=
function.surjective.comp (equiv.surjective _) (monoid_hom.submonoid_map_surjective _ _)
@[simp]
lemma to_inv_submonoid_mul (m : M) : (to_inv_submonoid M S m : S) * (algebra_map R S m) = 1 :=
submonoid.left_inv_equiv_symm_mul _ _ _
@[simp]
lemma mul_to_inv_submonoid (m : M) : (algebra_map R S m) * (to_inv_submonoid M S m : S) = 1 :=
submonoid.mul_left_inv_equiv_symm _ _ ⟨_, _⟩
@[simp]
lemma smul_to_inv_submonoid (m : M) : m • (to_inv_submonoid M S m : S) = 1 :=
by { convert mul_to_inv_submonoid M S m, rw ← algebra.smul_def, refl }
variables {S}
lemma surj' (z : S) : ∃ (r : R) (m : M), z = r • to_inv_submonoid M S m :=
begin
rcases is_localization.surj M z with ⟨⟨r, m⟩, e : z * _ = algebra_map R S r⟩,
refine ⟨r, m, _⟩,
rw [algebra.smul_def, ← e, mul_assoc],
simp,
end
lemma to_inv_submonoid_eq_mk' (x : M) :
(to_inv_submonoid M S x : S) = mk' S 1 x :=
by { rw ← (is_localization.map_units S x).mul_left_inj, simp }
lemma mem_inv_submonoid_iff_exists_mk' (x : S) :
x ∈ inv_submonoid M S ↔ ∃ m : M, mk' S 1 m = x :=
begin
simp_rw ← to_inv_submonoid_eq_mk',
exact ⟨λ h, ⟨_, congr_arg subtype.val (to_inv_submonoid_surjective M S ⟨x, h⟩).some_spec⟩,
λ h, h.some_spec ▸ (to_inv_submonoid M S h.some).prop⟩
end
variables (S)
lemma span_inv_submonoid : submodule.span R (inv_submonoid M S : set S) = ⊤ :=
begin
rw eq_top_iff,
rintros x -,
rcases is_localization.surj' M x with ⟨r, m, rfl⟩,
exact submodule.smul_mem _ _ (submodule.subset_span (to_inv_submonoid M S m).prop),
end
lemma finite_type_of_monoid_fg [monoid.fg M] : algebra.finite_type R S :=
begin
have := monoid.fg_of_surjective _ (to_inv_submonoid_surjective M S),
rw monoid.fg_iff_submonoid_fg at this,
rcases this with ⟨s, hs⟩,
refine ⟨⟨s, _⟩⟩,
rw eq_top_iff,
rintro x -,
change x ∈ ((algebra.adjoin R _ : subalgebra R S).to_submodule : set S),
rw [algebra.adjoin_eq_span, hs, span_inv_submonoid],
trivial
end
end inv_submonoid
end is_localization
|
19e2d761ba3819f439964c3be38d05e911feb6d0 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/normed_space/complemented.lean | 288761a0350d489f2b18827b3b1cabd236890023 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,822 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.normed_space.banach
import analysis.normed_space.finite_dimension
/-!
# Complemented subspaces of normed vector spaces
A submodule `p` of a topological module `E` over `R` is called *complemented* if there exists
a continuous linear projection `f : E →ₗ[R] p`, `∀ x : p, f x = x`. We prove that for
a closed subspace of a normed space this condition is equivalent to existence of a closed
subspace `q` such that `p ⊓ q = ⊥`, `p ⊔ q = ⊤`. We also prove that a subspace of finite codimension
is always a complemented subspace.
## Tags
complemented subspace, normed vector space
-/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F] {G : Type*} [normed_group G] [normed_space 𝕜 G]
noncomputable theory
namespace continuous_linear_map
section
variables [complete_space 𝕜]
lemma ker_closed_complemented_of_finite_dimensional_range (f : E →L[𝕜] F)
[finite_dimensional 𝕜 f.range] :
f.ker.closed_complemented :=
begin
set f' : E →L[𝕜] f.range := f.cod_restrict _ (f : E →ₗ[𝕜] F).mem_range_self,
rcases f'.exists_right_inverse_of_surjective (f : E →ₗ[𝕜] F).range_range_restrict with ⟨g, hg⟩,
simpa only [ker_cod_restrict] using f'.closed_complemented_ker_of_right_inverse g (ext_iff.1 hg)
end
end
variables [complete_space E] [complete_space (F × G)]
/-- If `f : E →L[R] F` and `g : E →L[R] G` are two surjective linear maps and
their kernels are complement of each other, then `x ↦ (f x, g x)` defines
a linear equivalence `E ≃L[R] F × G`. -/
def equiv_prod_of_surjective_of_is_compl (f : E →L[𝕜] F) (g : E →L[𝕜] G) (hf : f.range = ⊤)
(hg : g.range = ⊤) (hfg : is_compl f.ker g.ker) :
E ≃L[𝕜] F × G :=
((f : E →ₗ[𝕜] F).equiv_prod_of_surjective_of_is_compl ↑g hf hg
hfg).to_continuous_linear_equiv_of_continuous (f.continuous.prod_mk g.continuous)
@[simp] lemma coe_equiv_prod_of_surjective_of_is_compl {f : E →L[𝕜] F} {g : E →L[𝕜] G}
(hf : f.range = ⊤) (hg : g.range = ⊤) (hfg : is_compl f.ker g.ker) :
(equiv_prod_of_surjective_of_is_compl f g hf hg hfg : E →ₗ[𝕜] F × G) = f.prod g :=
rfl
@[simp] lemma equiv_prod_of_surjective_of_is_compl_to_linear_equiv {f : E →L[𝕜] F} {g : E →L[𝕜] G}
(hf : f.range = ⊤) (hg : g.range = ⊤) (hfg : is_compl f.ker g.ker) :
(equiv_prod_of_surjective_of_is_compl f g hf hg hfg).to_linear_equiv =
linear_map.equiv_prod_of_surjective_of_is_compl f g hf hg hfg :=
rfl
@[simp] lemma equiv_prod_of_surjective_of_is_compl_apply {f : E →L[𝕜] F} {g : E →L[𝕜] G}
(hf : f.range = ⊤) (hg : g.range = ⊤) (hfg : is_compl f.ker g.ker) (x : E):
equiv_prod_of_surjective_of_is_compl f g hf hg hfg x = (f x, g x) :=
rfl
end continuous_linear_map
namespace subspace
variables [complete_space E] (p q : subspace 𝕜 E)
open continuous_linear_map (subtype_val)
/-- If `q` is a closed complement of a closed subspace `p`, then `p × q` is continuously
isomorphic to `E`. -/
def prod_equiv_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))
(hq : is_closed (q : set E)) : (p × q) ≃L[𝕜] E :=
begin
haveI := hp.complete_space_coe, haveI := hq.complete_space_coe,
refine (p.prod_equiv_of_is_compl q h).to_continuous_linear_equiv_of_continuous _,
exact ((subtype_val p).coprod (subtype_val q)).continuous
end
/-- Projection to a closed submodule along a closed complement. -/
def linear_proj_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))
(hq : is_closed (q : set E)) :
E →L[𝕜] p :=
(continuous_linear_map.fst 𝕜 p q) ∘L ↑(prod_equiv_of_closed_compl p q h hp hq).symm
variables {p q}
@[simp] lemma coe_prod_equiv_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))
(hq : is_closed (q : set E)) :
⇑(p.prod_equiv_of_closed_compl q h hp hq) = p.prod_equiv_of_is_compl q h := rfl
@[simp] lemma coe_prod_equiv_of_closed_compl_symm (h : is_compl p q) (hp : is_closed (p : set E))
(hq : is_closed (q : set E)) :
⇑(p.prod_equiv_of_closed_compl q h hp hq).symm = (p.prod_equiv_of_is_compl q h).symm := rfl
@[simp] lemma coe_continuous_linear_proj_of_closed_compl (h : is_compl p q)
(hp : is_closed (p : set E)) (hq : is_closed (q : set E)) :
(p.linear_proj_of_closed_compl q h hp hq : E →ₗ[𝕜] p) = p.linear_proj_of_is_compl q h := rfl
@[simp] lemma coe_continuous_linear_proj_of_closed_compl' (h : is_compl p q)
(hp : is_closed (p : set E)) (hq : is_closed (q : set E)) :
⇑(p.linear_proj_of_closed_compl q h hp hq) = p.linear_proj_of_is_compl q h := rfl
lemma closed_complemented_of_closed_compl (h : is_compl p q) (hp : is_closed (p : set E))
(hq : is_closed (q : set E)) : p.closed_complemented :=
⟨p.linear_proj_of_closed_compl q h hp hq, submodule.linear_proj_of_is_compl_apply_left h⟩
lemma closed_complemented_iff_has_closed_compl : p.closed_complemented ↔
is_closed (p : set E) ∧ ∃ (q : subspace 𝕜 E) (hq : is_closed (q : set E)), is_compl p q :=
⟨λ h, ⟨h.is_closed, h.has_closed_complement⟩,
λ ⟨hp, ⟨q, hq, hpq⟩⟩, closed_complemented_of_closed_compl hpq hp hq⟩
lemma closed_complemented_of_quotient_finite_dimensional [complete_space 𝕜]
[finite_dimensional 𝕜 p.quotient] (hp : is_closed (p : set E)) :
p.closed_complemented :=
begin
obtain ⟨q, hq⟩ : ∃ q, is_compl p q := p.exists_is_compl,
haveI : finite_dimensional 𝕜 q := (p.quotient_equiv_of_is_compl q hq).finite_dimensional,
exact closed_complemented_of_closed_compl hq hp q.closed_of_finite_dimensional
end
end subspace
|
9032f5175d6a5ae9886e360bfc9eadf728045f55 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/1649a.lean | 555d30b1145f0f8b2058a3bdb6d4a47152418f94 | [
"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 | 131 | lean | section
def {u} typer (α : Type u) := α
parameter n : ℕ
meta def blah (n : typer ℕ) : ℕ := n
#check blah
end
#check blah
|
a38a10939e325fd125aadc38959ce72a9f08bef7 | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/limits/preserves/basic.lean | 18761bcd3f1164463a42d695505d4535810bbdca | [
"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 | 27,419 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton, Bhavik Mehta
-/
import category_theory.limits.limits
/-!
# Preservation and reflection of (co)limits.
There are various distinct notions of "preserving limits". The one we
aim to capture here is: A functor F : C → D "preserves limits" if it
sends every limit cone in C to a limit cone in D. Informally, F
preserves all the limits which exist in C.
Note that:
* Of course, we do not want to require F to *strictly* take chosen
limit cones of C to chosen limit cones of D. Indeed, the above
definition makes no reference to a choice of limit cones so it makes
sense without any conditions on C or D.
* Some diagrams in C may have no limit. In this case, there is no
condition on the behavior of F on such diagrams. There are other
notions (such as "flat functor") which impose conditions also on
diagrams in C with no limits, but these are not considered here.
In order to be able to express the property of preserving limits of a
certain form, we say that a functor F preserves the limit of a
diagram K if F sends every limit cone on K to a limit cone. This is
vacuously satisfied when K does not admit a limit, which is consistent
with the above definition of "preserves limits".
-/
open category_theory
noncomputable theory
namespace category_theory.limits
universes v u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [category.{v} C]
variables {D : Type u₂} [category.{v} D]
variables {J : Type v} [small_category J] {K : J ⥤ C}
/--
A functor `F` preserves limits of `K` (written as `preserves_limit K F`)
if `F` maps any limit cone over `K` to a limit cone.
-/
class preserves_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cone K}, is_limit c → is_limit (F.map_cone c))
/--
A functor `F` preserves colimits of `K` (written as `preserves_colimit K F`)
if `F` maps any colimit cocone over `K` to a colimit cocone.
-/
class preserves_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves : Π {c : cocone K}, is_colimit c → is_colimit (F.map_cocone c))
/-- We say that `F` preserves limits of shape `J` if `F` preserves limits for every diagram
`K : J ⥤ C`, i.e., `F` maps limit cones over `K` to limit cones. -/
class preserves_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(preserves_limit : Π {K : J ⥤ C}, preserves_limit K F)
/-- We say that `F` preserves colimits of shape `J` if `F` preserves colimits for every diagram
`K : J ⥤ C`, i.e., `F` maps colimit cocones over `K` to colimit cocones. -/
class preserves_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) :
Type (max u₁ u₂ v) :=
(preserves_colimit : Π {K : J ⥤ C}, preserves_colimit K F)
/-- We say that `F` preserves limits if it sends limit cones over any diagram to limit cones. -/
class preserves_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_limits_of_shape : Π {J : Type v} [𝒥 : small_category J],
by exactI preserves_limits_of_shape J F)
/-- We say that `F` preserves colimits if it sends colimit cocones over any diagram to colimit
cocones.-/
class preserves_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(preserves_colimits_of_shape : Π {J : Type v} [𝒥 : small_category J],
by exactI preserves_colimits_of_shape J F)
attribute [instance, priority 100] -- see Note [lower instance priority]
preserves_limits_of_shape.preserves_limit preserves_limits.preserves_limits_of_shape
preserves_colimits_of_shape.preserves_colimit preserves_colimits.preserves_colimits_of_shape
/--
A convenience function for `preserves_limit`, which takes the functor as an explicit argument to
guide typeclass resolution.
-/
def is_limit_of_preserves (F : C ⥤ D) {c : cone K} (t : is_limit c) [preserves_limit K F] :
is_limit (F.map_cone c) :=
preserves_limit.preserves t
/--
A convenience function for `preserves_colimit`, which takes the functor as an explicit argument to
guide typeclass resolution.
-/
def is_colimit_of_preserves (F : C ⥤ D) {c : cocone K} (t : is_colimit c)
[preserves_colimit K F] :
is_colimit (F.map_cocone c) :=
preserves_colimit.preserves t
instance preserves_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) :
subsingleton (preserves_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) :
subsingleton (preserves_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance preserves_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (preserves_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance preserves_limits_subsingleton (F : C ⥤ D) : subsingleton (preserves_limits F) :=
by { split, intros, cases a, cases b, cc }
instance preserves_colimits_subsingleton (F : C ⥤ D) : subsingleton (preserves_colimits F) :=
by { split, intros, cases a, cases b, cc }
instance id_preserves_limits : preserves_limits (𝟭 C) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩;
exact h.uniq _ m w⟩⟩ } }
instance id_preserves_colimits : preserves_colimits (𝟭 C) :=
{ preserves_colimits_of_shape := λ J 𝒥,
{ preserves_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩;
exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
local attribute [elab_simple] preserves_limit.preserves preserves_colimit.preserves
instance comp_preserves_limit [preserves_limit K F] [preserves_limit (K ⋙ F) G] :
preserves_limit K (F ⋙ G) :=
⟨λ c h, preserves_limit.preserves (preserves_limit.preserves h)⟩
instance comp_preserves_limits_of_shape
[preserves_limits_of_shape J F] [preserves_limits_of_shape J G] :
preserves_limits_of_shape J (F ⋙ G) :=
{ preserves_limit := λ K, infer_instance }
instance comp_preserves_limits [preserves_limits F] [preserves_limits G] :
preserves_limits (F ⋙ G) :=
{ preserves_limits_of_shape := λ J 𝒥₁, infer_instance }
instance comp_preserves_colimit [preserves_colimit K F] [preserves_colimit (K ⋙ F) G] :
preserves_colimit K (F ⋙ G) :=
⟨λ c h, preserves_colimit.preserves (preserves_colimit.preserves h)⟩
instance comp_preserves_colimits_of_shape
[preserves_colimits_of_shape J F] [preserves_colimits_of_shape J G] :
preserves_colimits_of_shape J (F ⋙ G) :=
{ preserves_colimit := λ K, infer_instance }
instance comp_preserves_colimits [preserves_colimits F] [preserves_colimits G] :
preserves_colimits (F ⋙ G) :=
{ preserves_colimits_of_shape := λ J 𝒥₁, infer_instance }
end
/-- If F preserves one limit cone for the diagram K,
then it preserves any limit cone for K. -/
def preserves_limit_of_preserves_limit_cone {F : C ⥤ D} {t : cone K}
(h : is_limit t) (hF : is_limit (F.map_cone t)) : preserves_limit K F :=
⟨λ t' h', is_limit.of_iso_limit hF (functor.map_iso _ (is_limit.unique_up_to_iso h h'))⟩
/-- Transfer preservation of limits along a natural isomorphism in the diagram. -/
def preserves_limit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂)
[preserves_limit K₁ F] : preserves_limit K₂ F :=
{ preserves := λ c t,
begin
apply is_limit.postcompose_inv_equiv (iso_whisker_right h F : _) _ _,
have := (is_limit.postcompose_inv_equiv h c).symm t,
apply is_limit.of_iso_limit (is_limit_of_preserves F this),
refine cones.ext (iso.refl _) (λ j, by tidy),
end }
/-- Transfer preservation of a limit along a natural isomorphism in the functor. -/
def preserves_limit_of_nat_iso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [preserves_limit K F] :
preserves_limit K G :=
{ preserves := λ c t, is_limit.map_cone_equiv h (preserves_limit.preserves t) }
/-- Transfer preservation of limits of shape along a natural isomorphism in the functor. -/
def preserves_limits_of_shape_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [preserves_limits_of_shape J F] :
preserves_limits_of_shape J G :=
{ preserves_limit := λ K, preserves_limit_of_nat_iso K h }
/-- Transfer preservation of limits along a natural isomorphism in the functor. -/
def preserves_limits_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [preserves_limits F] :
preserves_limits G :=
{ preserves_limits_of_shape := λ J 𝒥₁, by exactI preserves_limits_of_shape_of_nat_iso h }
/-- Transfer preservation of limits along a equivalence in the shape. -/
def preserves_limits_of_shape_of_equiv {J' : Type v} [small_category J'] (e : J ≌ J')
(F : C ⥤ D) [preserves_limits_of_shape J F] :
preserves_limits_of_shape J' F :=
{ preserves_limit := λ K,
{ preserves := λ c t,
begin
let equ := e.inv_fun_id_assoc (K ⋙ F),
have := (is_limit_of_preserves F (t.whisker_equivalence e)).whisker_equivalence e.symm,
apply ((is_limit.postcompose_hom_equiv equ _).symm this).of_iso_limit,
refine cones.ext (iso.refl _) (λ j, _),
{ dsimp, simp [←functor.map_comp] }, -- See library note [dsimp, simp].
end } }
/-- If F preserves one colimit cocone for the diagram K,
then it preserves any colimit cocone for K. -/
def preserves_colimit_of_preserves_colimit_cocone {F : C ⥤ D} {t : cocone K}
(h : is_colimit t) (hF : is_colimit (F.map_cocone t)) : preserves_colimit K F :=
⟨λ t' h', is_colimit.of_iso_colimit hF (functor.map_iso _ (is_colimit.unique_up_to_iso h h'))⟩
/-- Transfer preservation of colimits along a natural isomorphism in the shape. -/
def preserves_colimit_of_iso_diagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂)
[preserves_colimit K₁ F] : preserves_colimit K₂ F :=
{ preserves := λ c t,
begin
apply is_colimit.precompose_hom_equiv (iso_whisker_right h F : _) _ _,
have := (is_colimit.precompose_hom_equiv h c).symm t,
apply is_colimit.of_iso_colimit (is_colimit_of_preserves F this),
refine cocones.ext (iso.refl _) (λ j, by tidy),
end }
/-- Transfer preservation of a colimit along a natural isomorphism in the functor. -/
def preserves_colimit_of_nat_iso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [preserves_colimit K F] :
preserves_colimit K G :=
{ preserves := λ c t, is_colimit.map_cocone_equiv h (preserves_colimit.preserves t) }
/-- Transfer preservation of colimits of shape along a natural isomorphism in the functor. -/
def preserves_colimits_of_shape_of_nat_iso {F G : C ⥤ D} (h : F ≅ G)
[preserves_colimits_of_shape J F] : preserves_colimits_of_shape J G :=
{ preserves_colimit := λ K, preserves_colimit_of_nat_iso K h }
/-- Transfer preservation of colimits along a natural isomorphism in the functor. -/
def preserves_colimits_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [preserves_colimits F] :
preserves_colimits G :=
{ preserves_colimits_of_shape := λ J 𝒥₁, by exactI preserves_colimits_of_shape_of_nat_iso h }
/-- Transfer preservation of colimits along a equivalence in the shape. -/
def preserves_colimits_of_shape_of_equiv {J' : Type v} [small_category J'] (e : J ≌ J')
(F : C ⥤ D) [preserves_colimits_of_shape J F] :
preserves_colimits_of_shape J' F :=
{ preserves_colimit := λ K,
{ preserves := λ c t,
begin
let equ := e.inv_fun_id_assoc (K ⋙ F),
have := (is_colimit_of_preserves F (t.whisker_equivalence e)).whisker_equivalence e.symm,
apply ((is_colimit.precompose_inv_equiv equ _).symm this).of_iso_colimit,
refine cocones.ext (iso.refl _) (λ j, _),
{ dsimp, simp [←functor.map_comp] }, -- See library note [dsimp, simp].
end } }
/--
A functor `F : C ⥤ D` reflects limits for `K : J ⥤ C` if
whenever the image of a cone over `K` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cone K}, is_limit (F.map_cone c) → is_limit c)
/--
A functor `F : C ⥤ D` reflects colimits for `K : J ⥤ C` if
whenever the image of a cocone over `K` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimit (K : J ⥤ C) (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects : Π {c : cocone K}, is_colimit (F.map_cocone c) → is_colimit c)
/--
A functor `F : C ⥤ D` reflects limits of shape `J` if
whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_limit : Π {K : J ⥤ C}, reflects_limit K F)
/--
A functor `F : C ⥤ D` reflects colimits of shape `J` if
whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimits_of_shape (J : Type v) [small_category J] (F : C ⥤ D) : Type (max u₁ u₂ v) :=
(reflects_colimit : Π {K : J ⥤ C}, reflects_colimit K F)
/--
A functor `F : C ⥤ D` reflects limits if
whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone in `D`,
the cone was already a limit cone in `C`.
Note that we do not assume a priori that `D` actually has any limits.
-/
class reflects_limits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_limits_of_shape : Π {J : Type v} {𝒥 : small_category J},
by exactI reflects_limits_of_shape J F)
/--
A functor `F : C ⥤ D` reflects colimits if
whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit cocone in `D`,
the cocone was already a colimit cocone in `C`.
Note that we do not assume a priori that `D` actually has any colimits.
-/
class reflects_colimits (F : C ⥤ D) : Type (max u₁ u₂ (v+1)) :=
(reflects_colimits_of_shape : Π {J : Type v} {𝒥 : small_category J},
by exactI reflects_colimits_of_shape J F)
/--
A convenience function for `reflects_limit`, which takes the functor as an explicit argument to
guide typeclass resolution.
-/
def is_limit_of_reflects (F : C ⥤ D) {c : cone K} (t : is_limit (F.map_cone c))
[reflects_limit K F] : is_limit c :=
reflects_limit.reflects t
/--
A convenience function for `reflects_colimit`, which takes the functor as an explicit argument to
guide typeclass resolution.
-/
def is_colimit_of_reflects (F : C ⥤ D) {c : cocone K} (t : is_colimit (F.map_cocone c))
[reflects_colimit K F] :
is_colimit c :=
reflects_colimit.reflects t
instance reflects_limit_subsingleton (K : J ⥤ C) (F : C ⥤ D) : subsingleton (reflects_limit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_colimit_subsingleton (K : J ⥤ C) (F : C ⥤ D) :
subsingleton (reflects_colimit K F) :=
by split; rintros ⟨a⟩ ⟨b⟩; congr
instance reflects_limits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_limits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_colimits_of_shape_subsingleton (J : Type v) [small_category J] (F : C ⥤ D) :
subsingleton (reflects_colimits_of_shape J F) :=
by { split, intros, cases a, cases b, congr }
instance reflects_limits_subsingleton (F : C ⥤ D) : subsingleton (reflects_limits F) :=
by { split, intros, cases a, cases b, cc }
instance reflects_colimits_subsingleton (F : C ⥤ D) : subsingleton (reflects_colimits F) :=
by { split, intros, cases a, cases b, cc }
@[priority 100] -- see Note [lower instance priority]
instance reflects_limit_of_reflects_limits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_limits_of_shape J F] : reflects_limit K F :=
reflects_limits_of_shape.reflects_limit
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimit_of_reflects_colimits_of_shape (K : J ⥤ C) (F : C ⥤ D)
[H : reflects_colimits_of_shape J F] : reflects_colimit K F :=
reflects_colimits_of_shape.reflects_colimit
@[priority 100] -- see Note [lower instance priority]
instance reflects_limits_of_shape_of_reflects_limits (F : C ⥤ D)
[H : reflects_limits F] : reflects_limits_of_shape J F :=
reflects_limits.reflects_limits_of_shape
@[priority 100] -- see Note [lower instance priority]
instance reflects_colimits_of_shape_of_reflects_colimits (F : C ⥤ D)
[H : reflects_colimits F] : reflects_colimits_of_shape J F :=
reflects_colimits.reflects_colimits_of_shape
instance id_reflects_limits : reflects_limits (𝟭 C) :=
{ reflects_limits_of_shape := λ J 𝒥,
{ reflects_limit := λ K, by exactI ⟨λ c h,
⟨λ s, h.lift ⟨s.X, λ j, s.π.app j, λ j j' f, s.π.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩;
exact h.uniq _ m w⟩⟩ } }
instance id_reflects_colimits : reflects_colimits (𝟭 C) :=
{ reflects_colimits_of_shape := λ J 𝒥,
{ reflects_colimit := λ K, by exactI ⟨λ c h,
⟨λ s, h.desc ⟨s.X, λ j, s.ι.app j, λ j j' f, s.ι.naturality f⟩,
by cases K; rcases c with ⟨_, _, _⟩; intros s j; cases s; exact h.fac _ j,
by cases K; rcases c with ⟨_, _, _⟩; intros s m w; rcases s with ⟨_, _, _⟩;
exact h.uniq _ m w⟩⟩ } }
section
variables {E : Type u₃} [ℰ : category.{v} E]
variables (F : C ⥤ D) (G : D ⥤ E)
instance comp_reflects_limit [reflects_limit K F] [reflects_limit (K ⋙ F) G] :
reflects_limit K (F ⋙ G) :=
⟨λ c h, reflects_limit.reflects (reflects_limit.reflects h)⟩
instance comp_reflects_limits_of_shape
[reflects_limits_of_shape J F] [reflects_limits_of_shape J G] :
reflects_limits_of_shape J (F ⋙ G) :=
{ reflects_limit := λ K, infer_instance }
instance comp_reflects_limits [reflects_limits F] [reflects_limits G] :
reflects_limits (F ⋙ G) :=
{ reflects_limits_of_shape := λ J 𝒥₁, infer_instance }
instance comp_reflects_colimit [reflects_colimit K F] [reflects_colimit (K ⋙ F) G] :
reflects_colimit K (F ⋙ G) :=
⟨λ c h, reflects_colimit.reflects (reflects_colimit.reflects h)⟩
instance comp_reflects_colimits_of_shape
[reflects_colimits_of_shape J F] [reflects_colimits_of_shape J G] :
reflects_colimits_of_shape J (F ⋙ G) :=
{ reflects_colimit := λ K, infer_instance }
instance comp_reflects_colimits [reflects_colimits F] [reflects_colimits G] :
reflects_colimits (F ⋙ G) :=
{ reflects_colimits_of_shape := λ J 𝒥₁, infer_instance }
/-- If `F ⋙ G` preserves limits for `K`, and `G` reflects limits for `K ⋙ F`,
then `F` preserves limits for `K`. -/
def preserves_limit_of_reflects_of_preserves [preserves_limit K (F ⋙ G)]
[reflects_limit (K ⋙ F) G] : preserves_limit K F :=
⟨λ c h,
begin
apply is_limit_of_reflects G,
apply is_limit_of_preserves (F ⋙ G) h,
end⟩
/--
If `F ⋙ G` preserves limits of shape `J` and `G` reflects limits of shape `J`, then `F` preserves
limits of shape `J`.
-/
def preserves_limits_of_shape_of_reflects_of_preserves [preserves_limits_of_shape J (F ⋙ G)]
[reflects_limits_of_shape J G] : preserves_limits_of_shape J F :=
{ preserves_limit := λ K, preserves_limit_of_reflects_of_preserves F G }
/-- If `F ⋙ G` preserves limits and `G` reflects limits, then `F` preserves limits. -/
def preserves_limits_of_reflects_of_preserves [preserves_limits (F ⋙ G)] [reflects_limits G] :
preserves_limits F :=
{ preserves_limits_of_shape := λ J 𝒥₁,
by exactI preserves_limits_of_shape_of_reflects_of_preserves F G }
/-- Transfer reflection of a limit along a natural isomorphism in the functor. -/
def reflects_limit_of_nat_iso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [reflects_limit K F] :
reflects_limit K G :=
{ reflects := λ c t, reflects_limit.reflects (is_limit.map_cone_equiv h.symm t) }
/-- Transfer reflection of limits of shape along a natural isomorphism in the functor. -/
def reflects_limits_of_shape_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [reflects_limits_of_shape J F] :
reflects_limits_of_shape J G :=
{ reflects_limit := λ K, reflects_limit_of_nat_iso K h }
/-- Transfer reflection of limits along a natural isomorphism in the functor. -/
def reflects_limits_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [reflects_limits F] :
reflects_limits G :=
{ reflects_limits_of_shape := λ J 𝒥₁, by exactI reflects_limits_of_shape_of_nat_iso h }
/--
If the limit of `F` exists and `G` preserves it, then if `G` reflects isomorphisms then it
reflects the limit of `F`.
-/
def reflects_limit_of_reflects_isomorphisms (F : J ⥤ C) (G : C ⥤ D)
[reflects_isomorphisms G] [has_limit F] [preserves_limit F G] :
reflects_limit F G :=
{ reflects := λ c t,
begin
apply is_limit.of_point_iso (limit.is_limit F),
change is_iso ((cones.forget _).map ((limit.is_limit F).lift_cone_morphism c)),
apply (cones.forget F).map_is_iso _,
apply is_iso_of_reflects_iso _ (cones.functoriality F G),
refine t.hom_is_iso (is_limit_of_preserves G (limit.is_limit F)) _,
end }
/--
If `C` has limits of shape `J` and `G` preserves them, then if `G` reflects isomorphisms then it
reflects limits of shape `J`.
-/
def reflects_limits_of_shape_of_reflects_isomorphisms {G : C ⥤ D}
[reflects_isomorphisms G] [has_limits_of_shape J C] [preserves_limits_of_shape J G] :
reflects_limits_of_shape J G :=
{ reflects_limit := λ F, reflects_limit_of_reflects_isomorphisms F G }
/--
If `C` has limits and `G` preserves limits, then if `G` reflects isomorphisms then it reflects
limits.
-/
def reflects_limits_of_reflects_isomorphisms {G : C ⥤ D}
[reflects_isomorphisms G] [has_limits C] [preserves_limits G] :
reflects_limits G :=
{ reflects_limits_of_shape := λ J 𝒥₁,
by exactI reflects_limits_of_shape_of_reflects_isomorphisms }
/-- If `F ⋙ G` preserves colimits for `K`, and `G` reflects colimits for `K ⋙ F`,
then `F` preserves colimits for `K`. -/
def preserves_colimit_of_reflects_of_preserves [preserves_colimit K (F ⋙ G)]
[reflects_colimit (K ⋙ F) G] : preserves_colimit K F :=
⟨λ c h,
begin
apply is_colimit_of_reflects G,
apply is_colimit_of_preserves (F ⋙ G) h,
end⟩
/--
If `F ⋙ G` preserves colimits of shape `J` and `G` reflects colimits of shape `J`, then `F`
preserves colimits of shape `J`.
-/
def preserves_colimits_of_shape_of_reflects_of_preserves [preserves_colimits_of_shape J (F ⋙ G)]
[reflects_colimits_of_shape J G] : preserves_colimits_of_shape J F :=
{ preserves_colimit := λ K, preserves_colimit_of_reflects_of_preserves F G }
/-- If `F ⋙ G` preserves colimits and `G` reflects colimits, then `F` preserves colimits. -/
def preserves_colimits_of_reflects_of_preserves [preserves_colimits (F ⋙ G)]
[reflects_colimits G] : preserves_colimits F :=
{ preserves_colimits_of_shape := λ J 𝒥₁,
by exactI preserves_colimits_of_shape_of_reflects_of_preserves F G }
/-- Transfer reflection of a colimit along a natural isomorphism in the functor. -/
def reflects_colimit_of_nat_iso (K : J ⥤ C) {F G : C ⥤ D} (h : F ≅ G) [reflects_colimit K F] :
reflects_colimit K G :=
{ reflects := λ c t, reflects_colimit.reflects (is_colimit.map_cocone_equiv h.symm t) }
/-- Transfer reflection of colimits of shape along a natural isomorphism in the functor. -/
def reflects_colimits_of_shape_of_nat_iso {F G : C ⥤ D} (h : F ≅ G)
[reflects_colimits_of_shape J F] : reflects_colimits_of_shape J G :=
{ reflects_colimit := λ K, reflects_colimit_of_nat_iso K h }
/-- Transfer reflection of colimits along a natural isomorphism in the functor. -/
def reflects_colimits_of_nat_iso {F G : C ⥤ D} (h : F ≅ G) [reflects_colimits F] :
reflects_colimits G :=
{ reflects_colimits_of_shape := λ J 𝒥₁, by exactI reflects_colimits_of_shape_of_nat_iso h }
/--
If the colimit of `F` exists and `G` preserves it, then if `G` reflects isomorphisms then it
reflects the colimit of `F`.
-/
def reflects_colimit_of_reflects_isomorphisms (F : J ⥤ C) (G : C ⥤ D)
[reflects_isomorphisms G] [has_colimit F] [preserves_colimit F G] :
reflects_colimit F G :=
{ reflects := λ c t,
begin
apply is_colimit.of_point_iso (colimit.is_colimit F),
change is_iso ((cocones.forget _).map ((colimit.is_colimit F).desc_cocone_morphism c)),
apply (cocones.forget F).map_is_iso _,
apply is_iso_of_reflects_iso _ (cocones.functoriality F G),
refine (is_colimit_of_preserves G (colimit.is_colimit F)).hom_is_iso t _,
end }
/--
If `C` has colimits of shape `J` and `G` preserves them, then if `G` reflects isomorphisms then it
reflects colimits of shape `J`.
-/
def reflects_colimits_of_shape_of_reflects_isomorphisms {G : C ⥤ D}
[reflects_isomorphisms G] [has_colimits_of_shape J C] [preserves_colimits_of_shape J G] :
reflects_colimits_of_shape J G :=
{ reflects_colimit := λ F, reflects_colimit_of_reflects_isomorphisms F G }
/--
If `C` has colimits and `G` preserves colimits, then if `G` reflects isomorphisms then it reflects
colimits.
-/
def reflects_colimits_of_reflects_isomorphisms {G : C ⥤ D}
[reflects_isomorphisms G] [has_colimits C] [preserves_colimits G] :
reflects_colimits G :=
{ reflects_colimits_of_shape := λ J 𝒥₁,
by exactI reflects_colimits_of_shape_of_reflects_isomorphisms }
end
variable (F : C ⥤ D)
/-- A fully faithful functor reflects limits. -/
def fully_faithful_reflects_limits [full F] [faithful F] : reflects_limits F :=
{ reflects_limits_of_shape := λ J 𝒥₁, by exactI
{ reflects_limit := λ K,
{ reflects := λ c t,
is_limit.mk_cone_morphism (λ s, (cones.functoriality K F).preimage (t.lift_cone_morphism _)) $
begin
apply (λ s m, (cones.functoriality K F).map_injective _),
rw [functor.image_preimage],
apply t.uniq_cone_morphism,
end } } }
/-- A fully faithful functor reflects colimits. -/
def fully_faithful_reflects_colimits [full F] [faithful F] : reflects_colimits F :=
{ reflects_colimits_of_shape := λ J 𝒥₁, by exactI
{ reflects_colimit := λ K,
{ reflects := λ c t,
is_colimit.mk_cocone_morphism
(λ s, (cocones.functoriality K F).preimage (t.desc_cocone_morphism _)) $
begin
apply (λ s m, (cocones.functoriality K F).map_injective _),
rw [functor.image_preimage],
apply t.uniq_cocone_morphism,
end } } }
end category_theory.limits
|
6d8dfb780ebfacad3653b31e7acdfa8f2256b2b9 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/theories/analysis/normed_space.lean | 40eccfb6beb98b87c3413ea83ecfdef2f279d399 | [
"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 | 9,467 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Normed spaces.
-/
import algebra.module .metric_space
open real nat classical
noncomputable theory
structure has_norm [class] (M : Type) : Type :=
(norm : M → ℝ)
namespace analysis
definition norm {M : Type} [has_normM : has_norm M] (v : M) : ℝ := has_norm.norm v
notation `∥`v`∥` := norm v
end analysis
/- real vector spaces -/
-- where is the right place to put this?
structure real_vector_space [class] (V : Type) extends vector_space ℝ V
section
variables {V : Type} [real_vector_space V]
-- these specializations help the elaborator when it is hard to infer the ring, e.g. with numerals
proposition smul_left_distrib_real (a : ℝ) (u v : V) : a • (u + v) = a • u + a • v :=
smul_left_distrib a u v
proposition smul_right_distrib_real (a b : ℝ) (u : V) : (a + b) • u = a • u + b • u :=
smul_right_distrib a b u
proposition mul_smul_real (a : ℝ) (b : ℝ) (u : V) : (a * b) • u = a • (b • u) :=
mul_smul a b u
proposition one_smul_real (u : V) : (1 : ℝ) • u = u := one_smul u
proposition zero_smul_real (u : V) : (0 : ℝ) • u = 0 := zero_smul u
proposition smul_zero_real (a : ℝ) : a • (0 : V) = 0 := smul_zero a
proposition neg_smul_real (a : ℝ) (u : V) : (-a) • u = - (a • u) := neg_smul a u
proposition neg_one_smul_real (u : V) : -(1 : ℝ) • u = -u := neg_one_smul u
proposition smul_neg_real (a : ℝ) (u : V) : a • (-u) = -(a • u) := smul_neg a u
end
/- real normed vector spaces -/
structure normed_vector_space [class] (V : Type) extends real_vector_space V, has_norm V :=
(norm_zero : norm zero = 0)
(eq_zero_of_norm_eq_zero : ∀ u : V, norm u = 0 → u = zero)
(norm_triangle : ∀ u v, norm (add u v) ≤ norm u + norm v)
(norm_smul : ∀ (a : ℝ) (v : V), norm (smul a v) = abs a * norm v)
namespace analysis
variable {V : Type}
variable [normed_vector_space V]
proposition norm_zero : ∥ (0 : V) ∥ = 0 := !normed_vector_space.norm_zero
proposition eq_zero_of_norm_eq_zero {u : V} (H : ∥ u ∥ = 0) : u = 0 :=
!normed_vector_space.eq_zero_of_norm_eq_zero H
proposition norm_triangle (u v : V) : ∥ u + v ∥ ≤ ∥ u ∥ + ∥ v ∥ :=
!normed_vector_space.norm_triangle
proposition norm_smul (a : ℝ) (v : V) : ∥ a • v ∥ = abs a * ∥ v ∥ :=
!normed_vector_space.norm_smul
proposition norm_neg (v : V) : ∥ -v ∥ = ∥ v ∥ :=
have abs (1 : ℝ) = 1, from abs_of_nonneg zero_le_one,
by rewrite [-@neg_one_smul ℝ V, norm_smul, abs_neg, this, one_mul]
proposition norm_sub (u v : V) : ∥u - v∥ = ∥v - u∥ :=
by rewrite [-norm_neg, neg_sub]
end analysis
section
open analysis
variable {V : Type}
variable [normed_vector_space V]
attribute [reducible]
private definition nvs_dist (u v : V) := ∥ u - v ∥
private lemma nvs_dist_self (u : V) : nvs_dist u u = 0 :=
by rewrite [↑nvs_dist, sub_self, norm_zero]
private lemma eq_of_nvs_dist_eq_zero (u v : V) (H : nvs_dist u v = 0) : u = v :=
have u - v = 0, from eq_zero_of_norm_eq_zero H,
eq_of_sub_eq_zero this
private lemma nvs_dist_triangle (u v w : V) : nvs_dist u w ≤ nvs_dist u v + nvs_dist v w :=
calc
nvs_dist u w = ∥ (u - v) + (v - w) ∥ : by rewrite [↑nvs_dist, *sub_eq_add_neg, add.assoc,
neg_add_cancel_left]
... ≤ ∥ u - v ∥ + ∥ v - w ∥ : norm_triangle
private lemma nvs_dist_comm (u v : V) : nvs_dist u v = nvs_dist v u :=
by rewrite [↑nvs_dist, -norm_neg, neg_sub]
attribute [trans_instance]
definition normed_vector_space_to_metric_space
(V : Type) [nvsV : normed_vector_space V] :
metric_space V :=
⦃ metric_space,
dist := nvs_dist,
dist_self := nvs_dist_self,
eq_of_dist_eq_zero := eq_of_nvs_dist_eq_zero,
dist_comm := nvs_dist_comm,
dist_triangle := nvs_dist_triangle
⦄
open nat
proposition converges_to_seq_norm_elim {X : ℕ → V} {x : V} (H : X ⟶ x in ℕ) :
∀ {ε : ℝ}, ε > 0 → ∃ N₁ : ℕ, ∀ {n : ℕ}, n ≥ N₁ → ∥ X n - x ∥ < ε := H
proposition dist_eq_norm_sub (u v : V) : dist u v = ∥ u - v ∥ := rfl
proposition norm_eq_dist_zero (u : V) : ∥ u ∥ = dist u 0 :=
by rewrite [dist_eq_norm_sub, sub_zero]
proposition norm_nonneg (u : V) : ∥ u ∥ ≥ 0 :=
by rewrite norm_eq_dist_zero; apply !dist_nonneg
end
structure banach_space [class] (V : Type) extends nvsV : normed_vector_space V :=
(complete : ∀ X, @analysis.cauchy V (@normed_vector_space_to_metric_space V nvsV) X →
@analysis.converges_seq V (@normed_vector_space_to_metric_space V nvsV) X)
attribute [trans_instance]
definition banach_space_to_metric_space (V : Type) [bsV : banach_space V] :
complete_metric_space V :=
⦃ complete_metric_space, normed_vector_space_to_metric_space V,
complete := banach_space.complete
⦄
namespace analysis
variable {V : Type}
variable [normed_vector_space V]
variables {X Y : ℕ → V}
variables {x y : V}
proposition add_converges_to_seq (HX : X ⟶ x in ℕ) (HY : Y ⟶ y in ℕ) :
(λ n, X n + Y n) ⟶ x + y in ℕ :=
take ε : ℝ, suppose ε > 0,
have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos,
obtain (N₁ : ℕ) (HN₁ : ∀ {n}, n ≥ N₁ → ∥ X n - x ∥ < ε / 2),
from converges_to_seq_norm_elim HX e2pos,
obtain (N₂ : ℕ) (HN₂ : ∀ {n}, n ≥ N₂ → ∥ Y n - y ∥ < ε / 2),
from converges_to_seq_norm_elim HY e2pos,
let N := max N₁ N₂ in
exists.intro N
(take n,
suppose n ≥ N,
have ngtN₁ : n ≥ N₁, from nat.le_trans !le_max_left `n ≥ N`,
have ngtN₂ : n ≥ N₂, from nat.le_trans !le_max_right `n ≥ N`,
show ∥ (X n + Y n) - (x + y) ∥ < ε, from calc
∥ (X n + Y n) - (x + y) ∥
= ∥ (X n - x) + (Y n - y) ∥ : by rewrite [sub_add_eq_sub_sub, *sub_eq_add_neg,
*add.assoc, add.left_comm (-x)]
... ≤ ∥ X n - x ∥ + ∥ Y n - y ∥ : norm_triangle
... < ε / 2 + ε / 2 : add_lt_add (HN₁ ngtN₁) (HN₂ ngtN₂)
... = ε : add_halves)
private lemma smul_converges_to_seq_aux {c : ℝ} (cnz : c ≠ 0) (HX : X ⟶ x in ℕ) :
(λ n, c • X n) ⟶ c • x in ℕ :=
take ε : ℝ, suppose ε > 0,
have abscpos : abs c > 0, from abs_pos_of_ne_zero cnz,
have epos : ε / abs c > 0, from div_pos_of_pos_of_pos `ε > 0` abscpos,
obtain N (HN : ∀ {n}, n ≥ N → norm (X n - x) < ε / abs c), from converges_to_seq_norm_elim HX epos,
exists.intro N
(take n,
suppose n ≥ N,
have H : norm (X n - x) < ε / abs c, from HN this,
show norm (c • X n - c • x) < ε, from calc
norm (c • X n - c • x)
= abs c * norm (X n - x) : by rewrite [-smul_sub_left_distrib, norm_smul]
... < abs c * (ε / abs c) : mul_lt_mul_of_pos_left H abscpos
... = ε : mul_div_cancel' (ne_of_gt abscpos))
proposition smul_converges_to_seq (c : ℝ) (HX : X ⟶ x in ℕ) :
(λ n, c • X n) ⟶ c • x in ℕ :=
by_cases
(assume cz : c = 0,
have (λ n, c • X n) = (λ n, 0), from funext (take x, by rewrite [cz, zero_smul]),
begin rewrite [this, cz, zero_smul], apply converges_to_seq_constant end)
(suppose c ≠ 0, smul_converges_to_seq_aux this HX)
proposition neg_converges_to_seq (HX : X ⟶ x in ℕ) :
(λ n, - X n) ⟶ - x in ℕ :=
take ε, suppose ε > 0,
obtain N (HN : ∀ {n}, n ≥ N → norm (X n - x) < ε), from converges_to_seq_norm_elim HX this,
exists.intro N
(take n,
suppose n ≥ N,
show norm (- X n - (- x)) < ε,
by rewrite [-neg_neg_sub_neg, *neg_neg, norm_neg]; exact HN `n ≥ N`)
proposition neg_converges_to_seq_iff : ((λ n, - X n) ⟶ - x in ℕ) ↔ (X ⟶ x in ℕ) :=
have aux : X = λ n, (- (- X n)), from funext (take n, by rewrite neg_neg),
iff.intro
(assume H : (λ n, -X n)⟶ -x in ℕ,
show X ⟶ x in ℕ, by rewrite [aux, -neg_neg x]; exact neg_converges_to_seq H)
neg_converges_to_seq
proposition norm_converges_to_seq_zero (HX : X ⟶ 0 in ℕ) : (λ n, norm (X n)) ⟶ 0 in ℕ :=
take ε, suppose ε > 0,
obtain N (HN : ∀ n, n ≥ N → norm (X n - 0) < ε), from HX `ε > 0`,
exists.intro N
(take n, assume Hn : n ≥ N,
have norm (X n) < ε, begin rewrite -(sub_zero (X n)), apply HN n Hn end,
show abs (norm (X n) - 0) < ε,
by rewrite [sub_zero, abs_of_nonneg !norm_nonneg]; apply this)
proposition converges_to_seq_zero_of_norm_converges_to_seq_zero
(HX : (λ n, norm (X n)) ⟶ 0 in ℕ) :
X ⟶ 0 in ℕ :=
take ε, suppose ε > 0,
obtain N (HN : ∀ n, n ≥ N → abs (norm (X n) - 0) < ε), from HX `ε > 0`,
exists.intro (N : ℕ)
(take n : ℕ, assume Hn : n ≥ N,
have HN' : abs (norm (X n) - 0) < ε, from HN n Hn,
have norm (X n) < ε,
by rewrite [sub_zero at HN', abs_of_nonneg !norm_nonneg at HN']; apply HN',
show norm (X n - 0) < ε,
by rewrite sub_zero; apply this)
proposition norm_converges_to_seq_zero_iff (X : ℕ → V) :
((λ n, norm (X n)) ⟶ 0 in ℕ) ↔ (X ⟶ 0 in ℕ) :=
iff.intro converges_to_seq_zero_of_norm_converges_to_seq_zero norm_converges_to_seq_zero
end analysis
|
0ea2e56215d24a2815913eeeac0b932bcb035acd | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/linear_algebra/matrix/reindex.lean | ee034d336aad5ea27d01a78b7b21630522b6bdc0 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 5,493 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.matrix.determinant
/-!
# Changing the index type of a matrix
This file concerns the map `matrix.reindex`, mapping a `m` by `n` matrix
to an `m'` by `n'` matrix, as long as `m ≃ m'` and `n ≃ n'`.
## Main definitions
* `matrix.reindex_linear_equiv`: `matrix.reindex` is a linear equivalence
* `matrix.reindex_alg_equiv`: `matrix.reindex` is a algebra equivalence
## Tags
matrix, reindex
-/
namespace matrix
open equiv
open_locale matrix
variables {l m n : Type*} [fintype l] [fintype m] [fintype n]
variables {l' m' n' : Type*} [fintype l'] [fintype m'] [fintype n']
variables {m'' n'' : Type*} [fintype m''] [fintype n'']
variables {R : Type*}
/-- The natural map that reindexes a matrix's rows and columns with equivalent types,
`matrix.reindex`, is a linear equivalence. -/
def reindex_linear_equiv [semiring R] (eₘ : m ≃ m') (eₙ : n ≃ n') :
matrix m n R ≃ₗ[R] matrix m' n' R :=
{ map_add' := λ M N, rfl,
map_smul' := λ M N, rfl,
..(reindex eₘ eₙ)}
@[simp] lemma reindex_linear_equiv_apply [semiring R]
(eₘ : m ≃ m') (eₙ : n ≃ n') (M : matrix m n R) :
reindex_linear_equiv eₘ eₙ M = reindex eₘ eₙ M :=
rfl
@[simp] lemma reindex_linear_equiv_symm [semiring R] (eₘ : m ≃ m') (eₙ : n ≃ n') :
(reindex_linear_equiv eₘ eₙ : _ ≃ₗ[R] _).symm = reindex_linear_equiv eₘ.symm eₙ.symm :=
rfl
@[simp] lemma reindex_linear_equiv_refl_refl [semiring R] :
reindex_linear_equiv (equiv.refl m) (equiv.refl n) = linear_equiv.refl R _ :=
linear_equiv.ext $ λ _, rfl
lemma reindex_linear_equiv_trans [semiring R] (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') : (reindex_linear_equiv e₁ e₂).trans (reindex_linear_equiv e₁' e₂') =
(reindex_linear_equiv (e₁.trans e₁') (e₂.trans e₂') : _ ≃ₗ[R] _) :=
by { ext, refl }
lemma reindex_linear_equiv_comp [semiring R] (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') :
(reindex_linear_equiv e₁' e₂' : _ ≃ₗ[R] _) ∘ (reindex_linear_equiv e₁ e₂ : _ ≃ₗ[R] _)
= reindex_linear_equiv (e₁.trans e₁') (e₂.trans e₂') :=
by { rw [← reindex_linear_equiv_trans], refl }
lemma reindex_linear_equiv_comp_apply [semiring R] (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'')
(e₂' : n' ≃ n'') (M : matrix m n R) :
(reindex_linear_equiv e₁' e₂') (reindex_linear_equiv e₁ e₂ M) =
reindex_linear_equiv (e₁.trans e₁') (e₂.trans e₂') M :=
minor_minor _ _ _ _ _
lemma reindex_linear_equiv_one [semiring R] [decidable_eq m] [decidable_eq m']
(e : m ≃ m') : (reindex_linear_equiv e e (1 : matrix m m R)) = 1 :=
minor_one_equiv e.symm
variables {o o' : Type*} [fintype o] [fintype o']
lemma reindex_linear_equiv_mul [semiring R]
(eₘ : m ≃ m') (eₙ : n ≃ n') (eₒ : o ≃ o') (M : matrix m n R) (N : matrix n o R) :
reindex_linear_equiv eₘ eₒ (M ⬝ N) =
reindex_linear_equiv eₘ eₙ M ⬝ reindex_linear_equiv eₙ eₒ N :=
minor_mul_equiv M N _ _ _
lemma mul_reindex_linear_equiv_one [semiring R] [decidable_eq o] (e₁ : o ≃ n) (e₂ : o ≃ n')
(M : matrix m n R) : M.mul (reindex_linear_equiv e₁ e₂ 1) =
reindex_linear_equiv (equiv.refl m) (e₁.symm.trans e₂) M :=
mul_minor_one _ _ _
/--
For square matrices with coefficients in commutative semirings, the natural map that reindexes
a matrix's rows and columns with equivalent types, `matrix.reindex`, is an equivalence of algebras.
-/
def reindex_alg_equiv [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) : matrix m m R ≃ₐ[R] matrix n n R :=
{ to_fun := reindex e e,
map_mul' := reindex_linear_equiv_mul e e e,
commutes' := λ r, by simp [algebra_map, algebra.to_ring_hom, minor_smul],
..(reindex_linear_equiv e e) }
@[simp] lemma reindex_alg_equiv_apply [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) (M : matrix m m R) :
reindex_alg_equiv e M = reindex e e M :=
rfl
@[simp] lemma reindex_alg_equiv_symm [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) :
(reindex_alg_equiv e : _ ≃ₐ[R] _).symm = reindex_alg_equiv e.symm :=
rfl
@[simp] lemma reindex_alg_equiv_refl [comm_semiring R] [decidable_eq m] :
reindex_alg_equiv (equiv.refl m) = (alg_equiv.refl : _ ≃ₐ[R] _) :=
alg_equiv.ext $ λ _, rfl
lemma reindex_alg_equiv_mul [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m ≃ n) (M : matrix m m R) (N : matrix m m R) :
reindex_alg_equiv e (M ⬝ N) = reindex_alg_equiv e M ⬝ reindex_alg_equiv e N :=
(reindex_alg_equiv e).map_mul M N
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_minor_equiv_self`.
-/
lemma det_reindex_linear_equiv_self [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m ≃ n) (A : matrix m m R) :
det (reindex_linear_equiv e e A) = det A :=
det_reindex_self e A
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_minor_equiv_self`.
-/
lemma det_reindex_alg_equiv [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m ≃ n) (A : matrix m m R) :
det (reindex_alg_equiv e A) = det A :=
det_reindex_self e A
end matrix
|
03016477febddbba501d3fbc55915e2d82fcd942 | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/logic/unnamed_1952.lean | f309b96b62308087581190563895bcef56817b63 | [] | 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 | 242 | lean | import data.real.basic
variables {x y : ℝ}
namespace my_abs
-- BEGIN
theorem le_abs_self : x ≤ abs x :=
sorry
theorem neg_le_abs_self : -x ≤ abs x :=
sorry
theorem abs_add : abs (x + y) ≤ abs x + abs y :=
sorry
-- END
end my_abs |
66cc1736d76d68682f1d9b73a132ff025703c6db | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Util/RecDepth.lean | c74972e99b52b88dfc703221be16a86124fa61d9 | [
"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 | 363 | 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.Data.Options
namespace Lean
register_builtin_option maxRecDepth : Nat := {
defValue := defaultMaxRecDepth
descr := "maximum recursion depth for many Lean procedures"
}
end Lean
|
4cede20564045a427c409f0f4aff2d5d12dbe6c5 | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/geometry/manifold/instances/real.lean | adede1bbdb5e70ea501d44667b005b1c74b1ae20 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,580 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import geometry.manifold.algebra.smooth_functions
import linear_algebra.finite_dimensional
import analysis.inner_product_space.pi_L2
/-!
# Constructing examples of manifolds over ℝ
We introduce the necessary bits to be able to define manifolds modelled over `ℝ^n`, boundaryless
or with boundary or with corners. As a concrete example, we construct explicitly the manifold with
boundary structure on the real interval `[x, y]`.
More specifically, we introduce
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary
* `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
## Notations
In the locale `manifold`, we introduce the notations
* `𝓡 n` for the identity model with corners on `euclidean_space ℝ (fin n)`
* `𝓡∂ n` for `model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n)`.
For instance, if a manifold `M` is boundaryless, smooth and modelled on `euclidean_space ℝ (fin m)`,
and `N` is smooth with boundary modelled on `euclidean_half_space n`, and `f : M → N` is a smooth
map, then the derivative of `f` can be written simply as `mfderiv (𝓡 m) (𝓡∂ n) f` (as to why the
model with corners can not be implicit, see the discussion in `smooth_manifold_with_corners.lean`).
## Implementation notes
The manifold structure on the interval `[x, y] = Icc x y` requires the assumption `x < y` as a
typeclass. We provide it as `[fact (x < y)]`.
-/
noncomputable theory
open set function
open_locale manifold
/--
The half-space in `ℝ^n`, used to model manifolds with boundary. We only define it when
`1 ≤ n`, as the definition only makes sense in this case.
-/
def euclidean_half_space (n : ℕ) [has_zero (fin n)] : Type :=
{x : euclidean_space ℝ (fin n) // 0 ≤ x 0}
/--
The quadrant in `ℝ^n`, used to model manifolds with corners, made of all vectors with nonnegative
coordinates.
-/
def euclidean_quadrant (n : ℕ) : Type := {x : euclidean_space ℝ (fin n) // ∀i:fin n, 0 ≤ x i}
section
/- Register class instances for euclidean half-space and quadrant, that can not be noticed
without the following reducibility attribute (which is only set in this section). -/
local attribute [reducible] euclidean_half_space euclidean_quadrant
variable {n : ℕ}
instance [has_zero (fin n)] : topological_space (euclidean_half_space n) := by apply_instance
instance : topological_space (euclidean_quadrant n) := by apply_instance
instance [has_zero (fin n)] : inhabited (euclidean_half_space n) := ⟨⟨0, le_refl _⟩⟩
instance : inhabited (euclidean_quadrant n) := ⟨⟨0, λ i, le_refl _⟩⟩
lemma range_half_space (n : ℕ) [has_zero (fin n)] :
range (λx : euclidean_half_space n, x.val) = {y | 0 ≤ y 0} :=
by simp
lemma range_quadrant (n : ℕ) :
range (λx : euclidean_quadrant n, x.val) = {y | ∀i:fin n, 0 ≤ y i} :=
by simp
end
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_half_space n)`, used as
a model for manifolds with boundary. In the locale `manifold`, use the shortcut `𝓡∂ n`.
-/
def model_with_corners_euclidean_half_space (n : ℕ) [has_zero (fin n)] :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_half_space n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨update x 0 (max (x 0) 0), by simp [le_refl]⟩,
source := univ,
target := {x | 0 ≤ x 0},
map_source' := λx hx, x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, begin
rw [subtype.mk_eq_mk, update_eq_iff],
exact ⟨max_eq_left xprop, λ i _, rfl⟩
end,
right_inv' := λx hx, update_eq_iff.2 ⟨max_eq_left hx, λ i _, rfl⟩,
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.pi (fin n) (λ _, ℝ) _ _ (λ i ∈ ({0} : set (fin n)), unique_diff_on_Ici 0),
by simpa only [singleton_pi] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_id.update 0 $
(continuous_apply 0).max continuous_const }
/--
Definition of the model with corners `(euclidean_space ℝ (fin n), euclidean_quadrant n)`, used as a
model for manifolds with corners -/
def model_with_corners_euclidean_quadrant (n : ℕ) :
model_with_corners ℝ (euclidean_space ℝ (fin n)) (euclidean_quadrant n) :=
{ to_fun := subtype.val,
inv_fun := λx, ⟨λi, max (x i) 0, λi, by simp only [le_refl, or_true, le_max_iff]⟩,
source := univ,
target := {x | ∀ i, 0 ≤ x i},
map_source' := λx hx, by simpa only [subtype.range_val] using x.property,
map_target' := λx hx, mem_univ _,
left_inv' := λ ⟨xval, xprop⟩ hx, by { ext i, simp only [subtype.coe_mk, xprop i, max_eq_left] },
right_inv' := λ x hx, by { ext1 i, simp only [hx i, max_eq_left] },
source_eq := rfl,
unique_diff' :=
have this : unique_diff_on ℝ _ :=
unique_diff_on.univ_pi (fin n) (λ _, ℝ) _ (λ i, unique_diff_on_Ici 0),
by simpa only [pi_univ_Ici] using this,
continuous_to_fun := continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ $ continuous_pi $ λ i,
(continuous_id.max continuous_const).comp (continuous_apply i) }
localized "notation `𝓡 `n := model_with_corners_self ℝ (euclidean_space ℝ (fin n))" in manifold
localized "notation `𝓡∂ `n := model_with_corners_euclidean_half_space n" in manifold
/--
The left chart for the topological space `[x, y]`, defined on `[x,y)` and sending `x` to `0` in
`euclidean_half_space 1`.
-/
def Icc_left_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | z.val < y},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, z.val - x, sub_nonneg.mpr z.property.1⟩,
inv_fun := λz, ⟨min (z.val 0 + x) y, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y))]⟩,
map_source' := by simp only [imp_self, sub_lt_sub_iff_right, mem_set_of_eq, forall_true_iff],
map_target' :=
by { simp only [min_lt_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, min_eq_left, sub_add_cancel]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x + z 0 ≤ y, by linarith,
rw subsingleton.elim i 0,
simp only [A, add_comm, add_sub_cancel', min_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | z < y} := is_open_Iio,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), z - x) :=
continuous.sub (continuous_pi $ λi, continuous_id) continuous_const,
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, min (z + x) y) :=
(continuous_id.add continuous_const).min continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
The right chart for the topological space `[x, y]`, defined on `(x,y]` and sending `y` to `0` in
`euclidean_half_space 1`.
-/
def Icc_right_chart (x y : ℝ) [fact (x < y)] :
local_homeomorph (Icc x y) (euclidean_half_space 1) :=
{ source := {z : Icc x y | x < z.val},
target := {z : euclidean_half_space 1 | z.val 0 < y - x},
to_fun := λ(z : Icc x y), ⟨λi, y - z.val, sub_nonneg.mpr z.property.2⟩,
inv_fun := λz,
⟨max (y - z.val 0) x, by simp [le_refl, z.prop, le_of_lt (fact.out (x < y)), sub_eq_add_neg]⟩,
map_source' := by simp only [imp_self, mem_set_of_eq, sub_lt_sub_iff_left, forall_true_iff],
map_target' :=
by { simp only [lt_max_iff, mem_set_of_eq], assume z hz, left,
dsimp [-subtype.val_eq_coe] at hz, linarith },
left_inv' := begin
rintros ⟨z, hz⟩ h'z,
simp only [mem_set_of_eq, mem_Icc] at hz h'z,
simp only [hz, sub_eq_add_neg, max_eq_left, add_add_neg_cancel'_right, neg_add_rev, neg_neg]
end,
right_inv' := begin
rintros ⟨z, hz⟩ h'z,
rw subtype.mk_eq_mk,
funext,
dsimp at hz h'z,
have A : x ≤ y - z 0, by linarith,
rw subsingleton.elim i 0,
simp only [A, sub_sub_cancel, max_eq_left],
end,
open_source := begin
have : is_open {z : ℝ | x < z} := is_open_Ioi,
exact this.preimage continuous_subtype_val
end,
open_target := begin
have : is_open {z : ℝ | z < y - x} := is_open_Iio,
have : is_open {z : euclidean_space ℝ (fin 1) | z 0 < y - x} :=
this.preimage (@continuous_apply (fin 1) (λ _, ℝ) _ 0),
exact this.preimage continuous_subtype_val
end,
continuous_to_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have : continuous (λ (z : ℝ) (i : fin 1), y - z) :=
continuous_const.sub (continuous_pi (λi, continuous_id)),
exact this.comp continuous_subtype_val,
end,
continuous_inv_fun := begin
apply continuous.continuous_on,
apply continuous_subtype_mk,
have A : continuous (λ z : ℝ, max (y - z) x) :=
(continuous_const.sub continuous_id).max continuous_const,
have B : continuous (λz : euclidean_space ℝ (fin 1), z 0) := continuous_apply 0,
exact (A.comp B).comp continuous_subtype_val
end }
/--
Charted space structure on `[x, y]`, using only two charts taking values in
`euclidean_half_space 1`.
-/
instance Icc_manifold (x y : ℝ) [fact (x < y)] : charted_space (euclidean_half_space 1) (Icc x y) :=
{ atlas := {Icc_left_chart x y, Icc_right_chart x y},
chart_at := λz, if z.val < y then Icc_left_chart x y else Icc_right_chart x y,
mem_chart_source := λz, begin
by_cases h' : z.val < y,
{ simp only [h', if_true],
exact h' },
{ simp only [h', if_false],
apply lt_of_lt_of_le (fact.out (x < y)),
simpa only [not_lt] using h'}
end,
chart_mem_atlas := λz, by { by_cases h' : z.val < y; simp [h'] } }
/--
The manifold structure on `[x, y]` is smooth.
-/
instance Icc_smooth_manifold (x y : ℝ) [fact (x < y)] :
smooth_manifold_with_corners (𝓡∂ 1) (Icc x y) :=
begin
have M : times_cont_diff_on ℝ ∞ (λz : euclidean_space ℝ (fin 1), - z + (λi, y - x)) univ,
{ rw times_cont_diff_on_univ,
exact times_cont_diff_id.neg.add times_cont_diff_const },
apply smooth_manifold_with_corners_of_times_cont_diff_on,
assume e e' he he',
simp only [atlas, mem_singleton_iff, mem_insert_iff] at he he',
/- We need to check that any composition of two charts gives a `C^∞` function. Each chart can be
either the left chart or the right chart, leaving 4 possibilities that we handle successively.
-/
rcases he with rfl | rfl; rcases he' with rfl | rfl,
{ -- `e = left chart`, `e' = left chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_times_cont_diff_groupoid _ _ _)).1 },
{ -- `e = left chart`, `e' = right chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨⟨z, hz₀⟩, rfl⟩⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
update_same, max_eq_left, hz₀, lt_sub_iff_add_lt] with mfld_simps at hz₁ hz₂,
rw [min_eq_left hz₁.le, lt_add_iff_pos_left] at hz₂,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, *,
pi_Lp.add_apply, pi_Lp.neg_apply, max_eq_left, min_eq_left hz₁.le, update_same]
with mfld_simps,
abel },
{ -- `e = right chart`, `e' = left chart`
apply M.congr_mono _ (subset_univ _),
rintro _ ⟨⟨hz₁, hz₂⟩, ⟨z, hz₀⟩, rfl⟩,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart, max_lt_iff,
update_same, max_eq_left hz₀] with mfld_simps at hz₁ hz₂,
rw lt_sub at hz₁,
ext i,
rw subsingleton.elim i 0,
simp only [model_with_corners_euclidean_half_space, Icc_left_chart, Icc_right_chart,
pi_Lp.add_apply, pi_Lp.neg_apply, update_same, max_eq_left, hz₀, hz₁.le] with mfld_simps,
abel },
{ -- `e = right chart`, `e' = right chart`
exact (mem_groupoid_of_pregroupoid.mpr (symm_trans_mem_times_cont_diff_groupoid _ _ _)).1 }
end
/-! Register the manifold structure on `Icc 0 1`, and also its zero and one. -/
section
lemma fact_zero_lt_one : fact ((0 : ℝ) < 1) := ⟨zero_lt_one⟩
local attribute [instance] fact_zero_lt_one
instance : charted_space (euclidean_half_space 1) (Icc (0 : ℝ) 1) := by apply_instance
instance : smooth_manifold_with_corners (𝓡∂ 1) (Icc (0 : ℝ) 1) := by apply_instance
end
|
b2983ce26f80e1d545e5a5de584019017d7ced21 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/ppbeta.lean | a387bf73189c457cd7da30ffdde262d9d187209f | [
"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 | 278 | lean | import data.int
open [coercions] int
open [coercions] nat
definition lt (a b : int) := int.le (int.add a 1) b
infix `<` := lt
infixl `+` := int.add
theorem lt_add_succ2 (a : int) (n : nat) : a < a + nat.succ n :=
int.le_intro (show a + 1 + n = a + nat.succ n, from sorry)
|
677b2c3fdcd5c72891c584241fb12a8bd8eb6410 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/smt/array.lean | 05f2e83c4f6e6d8411c70561733fc945174ab91b | [
"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 | 935 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
namespace smt
definition array (A B : Type) := A → B
variables {A B : Type}
open tactic
definition select (a : array A B) (i : A) : B :=
a i
theorem arrayext (a₁ a₂ : array A B) : (∀ i, select a₁ i = select a₂ i) → a₁ = a₂ :=
funext
variable [decidable_eq A]
definition store (a : array A B) (i : A) (v : B) : array A B :=
λ j, if j = i then v else select a j
theorem select_store [simp] (a : array A B) (i : A) (v : B) : select (store a i v) i = v :=
by unfold [`smt.store, `smt.select] >> dsimp >> rewrite `if_pos >> reflexivity
theorem select_store_ne [simp] (a : array A B) (i j : A) (v : B) : j ≠ i → select (store a i v) j = select a j :=
by intros >> unfold [`smt.store, `smt.select] >> dsimp >> rewrite `if_neg >> assumption
end smt
|
188cbd0c4d59172c294cae9531c17bea6e125025 | 8e381650eb2c1c5361be64ff97e47d956bf2ab9f | /src/sheaves/presheaf_of_rings_maps.lean | 82a49a819ba0ca5f4fe67afcfc95cf2b986345ec | [] | no_license | alreadydone/lean-scheme | 04c51ab08eca7ccf6c21344d45d202780fa667af | 52d7624f57415eea27ed4dfa916cd94189221a1c | refs/heads/master | 1,599,418,221,423 | 1,562,248,559,000 | 1,562,248,559,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,820 | lean | /-
Continuous maps and presheaves of rings.
https://stacks.math.columbia.edu/tag/008C
-/
import to_mathlib.opens
import sheaves.presheaf_of_rings
import sheaves.presheaf_maps
universes u v w
open topological_space
variables {α : Type u} [topological_space α]
variables {β : Type v} [topological_space β]
namespace presheaf_of_rings
-- f induces a functor PSh(α) ⟶ PSh(β).
section pushforward
variables {f : α → β} (Hf : continuous f)
def pushforward (F : presheaf_of_rings α) : presheaf_of_rings β :=
{ Fring := λ U, F.Fring _,
res_is_ring_hom := λ U V HVU, F.res_is_ring_hom _ _ _,
..presheaf.pushforward Hf F.to_presheaf }
def pushforward.morphism (F G : presheaf_of_rings α) (φ : F ⟶ G)
: pushforward Hf F ⟶ pushforward Hf G :=
{ ring_homs := λ U, φ.ring_homs _,
..presheaf.pushforward.morphism Hf F.to_presheaf G.to_presheaf φ.to_morphism }
end pushforward
-- f induces a functor PSh(β) ⟶ PSh(α). Simplified to the case when f is 'nice'.
section pullback
variable (α)
structure pullback (F : presheaf_of_rings β) :=
(φ : α → β)
-- Open immersion. TODO: Package this.
(Hφ₁ : continuous φ)
(Hφ₂ : ∀ (U : opens α), is_open (φ '' U))
(Hφ₃ : function.injective φ)
(range : opens β := ⟨φ '' set.univ, Hφ₂ opens.univ⟩)
(carrier : presheaf_of_rings α :=
{ Fring := λ U, F.Fring _,
res_is_ring_hom := λ U V HVU, F.res_is_ring_hom _ _ _,
..presheaf.pullback Hφ₂ F.to_presheaf })
def pullback_id (F : presheaf_of_rings β) : presheaf_of_rings.pullback β F :=
begin
exact
{ φ := (id : β → β),
Hφ₁ := continuous_id,
Hφ₂ := λ U, by rw set.image_id; by exact U.2,
Hφ₃ := function.injective_id },
exact F,
end
-- TODO : Quite ugly.
lemma pullback_id.iso (F : presheaf_of_rings β) : (pullback_id F).carrier ≅ F :=
nonempty.intro
{ mor :=
{ map :=
begin
intros U,
have HUU : U ⊆ opens.map (pullback_id F).Hφ₂ U,
intros x Hx,
dsimp [opens.map],
erw set.image_id,
exact Hx,
exact F.res (opens.map (pullback_id F).Hφ₂ U) U HUU,
end,
commutes :=
begin
intros U V HVU,
dsimp [pullback_id],
rw ←presheaf.Hcomp,
rw ←presheaf.Hcomp,
end,
ring_homs := by apply_instance, },
inv :=
{ map :=
begin
intros U,
have HUU : opens.map (pullback_id F).Hφ₂ U ⊆ U,
intros x Hx,
dsimp [opens.map] at Hx,
erw set.image_id at Hx,
exact Hx,
exact F.res U (opens.map (pullback_id F).Hφ₂ U) HUU,
end,
commutes :=
begin
intros U V HVU,
dsimp [pullback_id],
rw ←presheaf.Hcomp,
rw ←presheaf.Hcomp,
end,
ring_homs := by apply_instance, },
mor_inv_id :=
begin
simp [presheaf.comp],
congr,
funext U,
rw ←presheaf.Hcomp,
erw presheaf.Hid,
end,
inv_mor_id :=
begin
simp [presheaf.comp],
congr,
funext U,
rw ←presheaf.Hcomp,
erw presheaf.Hid,
end, }
end pullback
-- f induces a `map` from a presheaf of rings on β to a presheaf of rings on α.
variable {α}
variables {f : α → β} (Hf : continuous f)
def fmap (F : presheaf_of_rings α) (G : presheaf_of_rings β) :=
presheaf.fmap Hf F.to_presheaf G.to_presheaf
namespace fmap
variables {γ : Type w} [topological_space γ]
variables {g : β → γ} {Hg : continuous g}
variable {Hf}
def comp {F : presheaf_of_rings α} {G : presheaf_of_rings β} {H : presheaf_of_rings γ}
(f_ : fmap Hf F G) (g_ : fmap Hg G H) : fmap (continuous.comp Hf Hg) F H :=
presheaf.fmap.comp f_ g_
end fmap
end presheaf_of_rings
|
ee0514893665a5471b52b0c234d82552426d32ad | 74caf7451c921a8d5ab9c6e2b828c9d0a35aae95 | /library/init/algebra/group.lean | 39922a7b164c8a9adca9ce0da7154738fc8c9151 | [
"Apache-2.0"
] | permissive | sakas--/lean | f37b6fad4fd4206f2891b89f0f8135f57921fc3f | 570d9052820be1d6442a5cc58ece37397f8a9e4c | refs/heads/master | 1,586,127,145,194 | 1,480,960,018,000 | 1,480,960,635,000 | 40,137,176 | 0 | 0 | null | 1,438,621,351,000 | 1,438,621,351,000 | null | UTF-8 | Lean | false | false | 15,260 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
prelude
import init.logic init.meta.interactive init.meta.decl_cmds
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
set_option default_priority 100
universe variable u
variables {α : Type u}
class semigroup (α : Type u) extends has_mul α :=
(mul_assoc : ∀ a b c : α, a * b * c = a * (b * c))
class comm_semigroup (α : Type u) extends semigroup α :=
(mul_comm : ∀ a b : α, a * b = b * a)
class left_cancel_semigroup (α : Type u) extends semigroup α :=
(mul_left_cancel : ∀ a b c : α, a * b = a * c → b = c)
class right_cancel_semigroup (α : Type u) extends semigroup α :=
(mul_right_cancel : ∀ a b c : α, a * b = c * b → a = c)
class monoid (α : Type u) extends semigroup α, has_one α :=
(one_mul : ∀ a : α, 1 * a = a) (mul_one : ∀ a : α, a * 1 = a)
class comm_monoid (α : Type u) extends monoid α, comm_semigroup α
class group (α : Type u) extends monoid α, has_inv α :=
(mul_left_inv : ∀ a : α, a⁻¹ * a = 1)
class comm_group (α : Type u) extends group α, comm_monoid α
@[simp] lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) :=
semigroup.mul_assoc
@[simp] lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a :=
comm_semigroup.mul_comm
@[simp] lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) :=
left_comm mul mul_comm mul_assoc
lemma mul_left_cancel [left_cancel_semigroup α] {a b c : α} : a * b = a * c → b = c :=
left_cancel_semigroup.mul_left_cancel a b c
lemma mul_right_cancel [right_cancel_semigroup α] {a b c : α} : a * b = c * b → a = c :=
right_cancel_semigroup.mul_right_cancel a b c
@[simp] lemma one_mul [monoid α] : ∀ a : α, 1 * a = a :=
monoid.one_mul
@[simp] lemma mul_one [monoid α] : ∀ a : α, a * 1 = a :=
monoid.mul_one
@[simp] lemma mul_left_inv [group α] : ∀ a : α, a⁻¹ * a = 1 :=
group.mul_left_inv
@[simp] lemma inv_mul_cancel_left [group α] (a b : α) : a⁻¹ * (a * b) = b :=
by rw [-mul_assoc, mul_left_inv, one_mul]
@[simp] lemma inv_mul_cancel_right [group α] (a b : α) : a * b⁻¹ * b = a :=
by simp
@[simp] lemma inv_eq_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a⁻¹ = b :=
by rw [-mul_one a⁻¹, -h, -mul_assoc, mul_left_inv, one_mul]
@[simp] lemma one_inv [group α] : 1⁻¹ = (1 : α) :=
inv_eq_of_mul_eq_one (one_mul 1)
@[simp] lemma inv_inv [group α] (a : α) : (a⁻¹)⁻¹ = a :=
inv_eq_of_mul_eq_one (mul_left_inv a)
@[simp] lemma mul_right_inv [group α] (a : α) : a * a⁻¹ = 1 :=
have a⁻¹⁻¹ * a⁻¹ = 1, by rw mul_left_inv,
by rwa [inv_inv] at this
lemma inv_inj [group α] {a b : α} (h : a⁻¹ = b⁻¹) : a = b :=
have a = a⁻¹⁻¹, by simp,
begin rw this, simp [h] end
lemma group.mul_left_cancel [group α] {a b c : α} (h : a * b = a * c) : b = c :=
have a⁻¹ * (a * b) = b, by simp,
begin simp [h] at this, rw this end
lemma group.mul_right_cancel [group α] {a b c : α} (h : a * b = c * b) : a = c :=
have a * b * b⁻¹ = a, by simp,
begin simp [h] at this, rw this end
instance group.to_left_cancel_semigroup [s : group α] : left_cancel_semigroup α :=
{ s with mul_left_cancel := @group.mul_left_cancel α s }
instance group.to_right_cancel_semigroup [s : group α] : right_cancel_semigroup α :=
{ s with mul_right_cancel := @group.mul_right_cancel α s }
lemma mul_inv_cancel_left [group α] (a b : α) : a * (a⁻¹ * b) = b :=
by rw [-mul_assoc, mul_right_inv, one_mul]
lemma mul_inv_cancel_right [group α] (a b : α) : a * b * b⁻¹ = a :=
by rw [mul_assoc, mul_right_inv, mul_one]
@[simp] lemma mul_inv_rev [group α] (a b : α) : (a * b)⁻¹ = b⁻¹ * a⁻¹ :=
inv_eq_of_mul_eq_one begin rw [mul_assoc, -mul_assoc b, mul_right_inv, one_mul, mul_right_inv] end
lemma eq_inv_of_eq_inv [group α] {a b : α} (h : a = b⁻¹) : b = a⁻¹ :=
by simp [h]
lemma eq_inv_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a = b⁻¹ :=
have a⁻¹ = b, from inv_eq_of_mul_eq_one h,
by simp [this^.symm]
lemma eq_mul_inv_of_mul_eq [group α] {a b c : α} (h : a * c = b) : a = b * c⁻¹ :=
by simp [h^.symm]
lemma eq_inv_mul_of_mul_eq [group α] {a b c : α} (h : b * a = c) : a = b⁻¹ * c :=
by simp [h^.symm]
lemma inv_mul_eq_of_eq_mul [group α] {a b c : α} (h : b = a * c) : a⁻¹ * b = c :=
by simp [h]
lemma mul_inv_eq_of_eq_mul [group α] {a b c : α} (h : a = c * b) : a * b⁻¹ = c :=
by simp [h]
lemma eq_mul_of_mul_inv_eq [group α] {a b c : α} (h : a * c⁻¹ = b) : a = b * c :=
by simp [h^.symm]
lemma eq_mul_of_inv_mul_eq [group α] {a b c : α} (h : b⁻¹ * a = c) : a = b * c :=
by simp [h^.symm, mul_inv_cancel_left]
lemma mul_eq_of_eq_inv_mul [group α] {a b c : α} (h : b = a⁻¹ * c) : a * b = c :=
by rw [h, mul_inv_cancel_left]
lemma mul_eq_of_eq_mul_inv [group α] {a b c : α} (h : a = c * b⁻¹) : a * b = c :=
by simp [h]
lemma mul_inv [comm_group α] (a b : α) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
by rw [mul_inv_rev, mul_comm]
/- αdditive "sister" structures.
Example, add_semigroup mirrors semigroup.
These structures exist just to help automation.
In an alternative design, we could have the binary operation as an
extra argument for semigroup, monoid, group, etc. However, the lemmas
would be hard to index since they would not contain any constant.
For example, mul_assoc would be
lemma mul_assoc {α : Type u} {op : α → α → α} [semigroup α op] :
∀ a b c : α, op (op a b) c = op a (op b c) :=
semigroup.mul_assoc
The simplifier cannot effectively use this lemma since the pattern for
the left-hand-side would be
?op (?op ?a ?b) ?c
Remark: we use a tactic for transporting theorems from the multiplicative fragment
to the additive one.
-/
@[class] def add_semigroup := semigroup
@[class] def add_monoid := monoid
@[class] def add_group := group
@[class] def add_comm_semigroup := comm_semigroup
@[class] def add_comm_monoid := comm_monoid
@[class] def add_comm_group := comm_group
@[class] def add_left_cancel_semigroup := left_cancel_semigroup
@[class] def add_right_cancel_semigroup := right_cancel_semigroup
instance add_semigroup.to_has_add {α : Type u} [s : add_semigroup α] : has_add α :=
⟨@semigroup.mul α s⟩
instance add_monoid.to_has_zero {α : Type u} [s : add_monoid α] : has_zero α :=
⟨@monoid.one α s⟩
instance add_group.to_has_neg {α : Type u} [s : add_group α] : has_neg α :=
⟨@group.inv α s⟩
open tactic
meta def transport_with_dict (dict : name_map name) (src : name) (tgt : name) : command :=
copy_decl_updating_type dict src tgt
>> copy_attribute `reducible src tt tgt
>> copy_attribute `simp src tt tgt
>> copy_attribute `instance src tt tgt
meta def name_map_of_list_name (l : list name) : tactic (name_map name) :=
do list_pair_name ← monad.for l (λ nm, do e ← mk_const nm, eval_expr (list (name × name)) e),
return $ rb_map.of_list (list.join list_pair_name)
meta def transport_using_attr (attr : caching_user_attribute (name_map name))
(src : name) (tgt : name) : command :=
do dict ← caching_user_attribute.get_cache attr,
transport_with_dict dict src tgt
meta def multiplicative_to_additive_transport_attr : caching_user_attribute (name_map name) :=
{ name := `multiplicative_to_additive_transport,
descr := "list of name pairs for transporting multiplicative facts to additive ones",
mk_cache := name_map_of_list_name,
dependencies := [] }
run_command attribute.register `multiplicative_to_additive_transport_attr
meta def transport_to_additive : name → name → command :=
transport_using_attr multiplicative_to_additive_transport_attr
@[multiplicative_to_additive_transport]
meta def multiplicative_to_additive_pairs : list (name × name) :=
[/- map operations -/
(`mul, `add), (`one, `zero), (`inv, `neg),
/- map structures -/
(`semigroup, `add_semigroup),
(`monoid, `add_monoid),
(`group, `add_group),
(`comm_semigroup, `add_comm_semigroup),
(`comm_monoid, `add_comm_monoid),
(`comm_group, `add_comm_group),
(`left_cancel_semigroup, `add_left_cancel_semigroup),
(`right_cancel_semigroup, `add_right_cancel_semigroup),
/- map instances -/
(`semigroup.to_has_mul, `add_semigroup.to_has_add),
(`monoid.to_has_one, `add_monoid.to_has_zero),
(`group.to_has_inv, `add_group.to_has_neg),
(`comm_semigroup.to_semigroup, `add_comm_semigroup.to_add_semigroup),
(`monoid.to_semigroup, `add_monoid.to_add_semigroup),
(`comm_monoid.to_monoid, `add_comm_monoid.to_add_monoid),
(`comm_monoid.to_comm_semigroup, `add_comm_monoid.to_add_comm_semigroup),
(`group.to_monoid, `add_group.to_add_monoid),
(`comm_group.to_group, `add_comm_group.to_add_group),
(`comm_group.to_comm_monoid, `add_comm_group.to_add_comm_monoid),
(`left_cancel_semigroup.to_semigroup, `add_left_cancel_semigroup.to_add_semigroup),
(`right_cancel_semigroup.to_semigroup, `add_right_cancel_semigroup.to_add_semigroup)
]
/- Make sure all constants at multiplicative_to_additive are declared -/
meta def init_multiplicative_to_additive : command :=
list.foldl (λ (tac : tactic unit) (p : name × name), do
(s, t) ← return p,
env ← get_env,
if (env^.get t)^.to_bool = ff
then tac >> transport_to_additive s t
else tac) skip multiplicative_to_additive_pairs
run_command init_multiplicative_to_additive
run_command transport_to_additive `mul_assoc `add_assoc
run_command transport_to_additive `mul_comm `add_comm
run_command transport_to_additive `mul_left_comm `add_left_comm
run_command transport_to_additive `one_mul `zero_add
run_command transport_to_additive `mul_one `add_zero
run_command transport_to_additive `mul_left_inv `add_left_neg
run_command transport_to_additive `mul_left_cancel `add_left_cancel
run_command transport_to_additive `mul_right_cancel `add_right_cancel
run_command transport_to_additive `mul_inv_cancel_left `add_neg_cancel_left
run_command transport_to_additive `mul_inv_cancel_right `add_neg_cancel_right
run_command transport_to_additive `inv_mul_cancel_left `neg_add_cancel_left
run_command transport_to_additive `inv_mul_cancel_right `neg_add_cancel_right
run_command transport_to_additive `inv_eq_of_mul_eq_one `neg_eq_of_add_eq_zero
run_command transport_to_additive `one_inv `neg_zero
run_command transport_to_additive `inv_inv `neg_neg
run_command transport_to_additive `mul_right_inv `add_right_neg
run_command transport_to_additive `mul_inv_rev `neg_add_rev
run_command transport_to_additive `mul_inv `neg_add
run_command transport_to_additive `inv_inj `neg_inj
run_command transport_to_additive `group.to_left_cancel_semigroup `add_group.to_left_cancel_add_semigroup
run_command transport_to_additive `group.to_right_cancel_semigroup `add_group.to_right_cancel_add_semigroup
run_command transport_to_additive `eq_inv_of_eq_inv `eq_neg_of_eq_neg
run_command transport_to_additive `eq_inv_of_mul_eq_one `eq_neg_of_add_eq_zero
run_command transport_to_additive `eq_mul_inv_of_mul_eq `eq_add_neg_of_add_eq
run_command transport_to_additive `eq_inv_mul_of_mul_eq `eq_neg_add_of_add_eq
run_command transport_to_additive `inv_mul_eq_of_eq_mul `neg_add_eq_of_eq_add
run_command transport_to_additive `mul_inv_eq_of_eq_mul `add_neg_eq_of_eq_add
run_command transport_to_additive `eq_mul_of_mul_inv_eq `eq_add_of_add_neg_eq
run_command transport_to_additive `eq_mul_of_inv_mul_eq `eq_add_of_neg_add_eq
run_command transport_to_additive `mul_eq_of_eq_inv_mul `add_eq_of_eq_neg_add
run_command transport_to_additive `mul_eq_of_eq_mul_inv `add_eq_of_eq_add_neg
@[reducible] protected def algebra.sub [add_group α] (a b : α) : α :=
a + -b
instance add_group_has_sub [add_group α] : has_sub α :=
⟨algebra.sub⟩
@[simp] lemma sub_eq_add_neg [add_group α] (a b : α) : a - b = a + -b :=
rfl
lemma sub_self [add_group α] (a : α) : a - a = 0 :=
add_right_neg a
lemma sub_add_cancel [add_group α] (a b : α) : a - b + b = a :=
neg_add_cancel_right a b
lemma add_sub_cancel [add_group α] (a b : α) : a + b - b = a :=
add_neg_cancel_right a b
lemma add_sub_assoc [add_group α] (a b c : α) : a + b - c = a + (b - c) :=
by rw [sub_eq_add_neg, add_assoc, -sub_eq_add_neg]
lemma eq_of_sub_eq_zero [add_group α] {a b : α} (h : a - b = 0) : a = b :=
have 0 + b = b, by rw zero_add,
have (a - b) + b = b, by rwa h,
by rwa [sub_eq_add_neg, neg_add_cancel_right] at this
lemma sub_eq_zero_of_eq [add_group α] {a b : α} (h : a = b) : a - b = 0 :=
by rw [h, sub_self]
lemma zero_sub [add_group α] (a : α) : 0 - a = -a :=
zero_add (-a)
lemma sub_zero [add_group α] (a : α) : a - 0 = a :=
by rw [sub_eq_add_neg, neg_zero, add_zero]
lemma sub_ne_zero_of_ne [add_group α] {a b : α} (h : a ≠ b) : a - b ≠ 0 :=
begin
intro hab,
apply h,
apply eq_of_sub_eq_zero hab
end
lemma sub_neg_eq_add [add_group α] (a b : α) : a - (-b) = a + b :=
by rw [sub_eq_add_neg, neg_neg]
lemma neg_sub [add_group α] (a b : α) : -(a - b) = b - a :=
neg_eq_of_add_eq_zero (by rw [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left, add_right_neg])
lemma add_sub [add_group α] (a b c : α) : a + (b - c) = a + b - c :=
by simp
lemma sub_add_eq_sub_sub_swap [add_group α] (a b c : α) : a - (b + c) = a - c - b :=
by simp
lemma eq_sub_of_add_eq [add_group α] {a b c : α} (h : a + c = b) : a = b - c :=
by simp [h^.symm]
lemma sub_eq_of_eq_add [add_group α] {a b c : α} (h : a = c + b) : a - b = c :=
by simp [h]
lemma eq_add_of_sub_eq [add_group α] {a b c : α} (h : a - c = b) : a = b + c :=
by simp [h^.symm]
lemma add_eq_of_eq_sub [add_group α] {a b c : α} (h : a = c - b) : a + b = c :=
by simp [h]
lemma sub_add_eq_sub_sub [add_comm_group α] (a b c : α) : a - (b + c) = a - b - c :=
by simp
lemma neg_add_eq_sub [add_comm_group α] (a b : α) : -a + b = b - a :=
by simp
lemma sub_add_eq_add_sub [add_comm_group α] (a b c : α) : a - b + c = a + c - b :=
by simp
lemma sub_sub [add_comm_group α] (a b c : α) : a - b - c = a - (b + c) :=
by simp
lemma add_sub_add_left_eq_sub [add_comm_group α] (a b c : α) : (c + a) - (c + b) = a - b :=
by simp
lemma eq_sub_of_add_eq' [add_comm_group α] {a b c : α} (h : c + a = b) : a = b - c :=
by simp [h^.symm]
lemma sub_eq_of_eq_add' [add_comm_group α] {a b c : α} (h : a = b + c) : a - b = c :=
by simp [h]
lemma eq_add_of_sub_eq' [add_comm_group α] {a b c : α} (h : a - b = c) : a = b + c :=
by simp [h^.symm]
lemma add_eq_of_eq_sub' [add_comm_group α] {a b c : α} (h : b = c - a) : a + b = c :=
begin simp [h], rw [add_comm c, add_neg_cancel_left] end
lemma sub_sub_self [add_comm_group α] (a b : α) : a - (a - b) = b :=
begin simp, rw [add_comm b, add_neg_cancel_left] end
lemma add_sub_comm [add_comm_group α] (a b c d : α) : a + b - (c + d) = (a - c) + (b - d) :=
by simp
lemma sub_eq_sub_add_sub [add_comm_group α] (a b c : α) : a - b = c - b + (a - c) :=
by simp
lemma neg_neg_sub_neg [add_comm_group α] (a b : α) : - (-a - -b) = a - b :=
by simp
|
9a52a6316bba504f308b82af50ce78c00e10237b | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/init/meta/rewrite_tactic.lean | 4cc49f71d323859c0006497b2c6fb875297df567 | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 903 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.relation_tactics init.meta.occurrences
namespace tactic
/- (rewrite_core m approx use_instances occs symm H) -/
meta constant rewrite_core : transparency → bool → bool → occurrences → bool → expr → tactic unit
meta constant rewrite_at_core : transparency → bool → bool → occurrences → bool → expr → expr → tactic unit
meta def rewrite (th_name : name) : tactic unit :=
do th ← mk_const th_name,
rewrite_core reducible tt tt occurrences.all ff th,
try (reflexivity_core reducible)
meta def rewrite_at (th_name : name) (H_name : name) : tactic unit :=
do th ← mk_const th_name,
H ← get_local H_name,
rewrite_at_core reducible tt tt occurrences.all ff th H
end tactic
|
087afc90014908e21630f95b22a0f492e4355a9c | c31182a012eec69da0a1f6c05f42b0f0717d212d | /src/for_mathlib/Profinite/clopen_limit.lean | 04ad99adfba9a495c4b418d54c65787ed2f1366c | [] | no_license | Ja1941/lean-liquid | fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc | 8e80ed0cbdf5145d6814e833a674eaf05a1495c1 | refs/heads/master | 1,689,437,983,362 | 1,628,362,719,000 | 1,628,362,719,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,033 | lean | import topology.category.Profinite.cofiltered_limit
import topology.discrete_quotient
import for_mathlib.order
noncomputable theory
open_locale classical
namespace Profinite
open category_theory
open category_theory.limits
universe u
variables {J : Type u} [semilattice_inf J] (F : J ⥤ Profinite.{u}) (C : cone F)
lemma image_eq (hC : is_limit C) (i : J) :
set.range (C.π.app i) = ⋂ (j : J) (h : j ≤ i), set.range (F.map (hom_of_le h)) :=
begin
refine le_antisymm _ _,
{ apply set.subset_Inter,
intros j,
apply set.subset_Inter,
intros hj,
rw ← C.w (hom_of_le hj),
apply set.range_comp_subset_range },
{ rintro x hx,
have cond : ∀ (j : J) (hj : j ≤ i), ∃ y : F.obj j, (F.map (hom_of_le hj)) y = x,
{ intros j hj,
exact hx _ ⟨j,rfl⟩ _ ⟨hj, rfl⟩ },
let Js := Σ' (a b : J), a ≤ b,
let P := Π (j : J), F.obj j,
let Us : Js → set P := λ e, { p | F.map (hom_of_le e.2.2) (p (e.1)) = p (e.2.1) ∧ p i = x},
have hP : (_root_.is_compact (set.univ : set P)) := compact_univ,
have hh := hP.inter_Inter_nonempty Us _ _,
{ rcases hh with ⟨z,hz⟩,
let IC : (limit_cone F) ≅ C := (limit_cone_is_limit F).unique_up_to_iso hC,
let ICX : (limit_cone F).X ≅ C.X := (cones.forget _).map_iso IC,
let z : (limit_cone F).X := ⟨z,_⟩,
swap,
{ intros a b h,
convert (hz.2 _ ⟨⟨a, b, le_of_hom h⟩, rfl⟩).1 },
use ICX.hom z,
change (hC.lift _ ≫ _) _ = _,
rw hC.fac,
exact (hz.2 _ ⟨⟨i,i,le_refl _⟩,rfl⟩).2 },
{ intros i,
refine is_closed.inter (is_closed_eq _ _) (is_closed_eq _ _);
continuity },
{ have : ∀ e : J, nonempty (F.obj e),
{ intros e,
rcases cond (e ⊓ i) inf_le_right with ⟨y,rfl⟩,
use F.map (hom_of_le inf_le_left) y },
haveI : ∀ j : J, inhabited (F.obj j) :=
by {intros j, refine ⟨nonempty.some (this j)⟩},
intros G,
let GG := G.image (λ e : Js, e.1),
haveI : inhabited J := ⟨i⟩,
have := exists_le_finset (insert i GG),
obtain ⟨j0,hj0⟩ := this,
obtain ⟨x0,rfl⟩ := cond j0 (hj0 _ (finset.mem_insert_self _ _)),
let z : P := λ e, if h : j0 ≤ e then F.map (hom_of_le h) x0 else (default _),
use z,
refine ⟨trivial, _⟩,
rintros S ⟨e,rfl⟩,
rintro T ⟨k,rfl⟩,
dsimp [z],
refine ⟨_, by erw dif_pos⟩,
have : j0 ≤ e.fst,
{ apply hj0,
apply finset.mem_insert_of_mem,
rw finset.mem_image,
refine ⟨e,k,rfl⟩ },
erw [dif_pos this, dif_pos (le_trans this e.2.2)],
change (F.map _ ≫ F.map _) _ = _,
rw ← F.map_comp,
refl } }
end
set_option pp.proofs true
lemma image_stabilizes [inhabited J] [∀ i, fintype (F.obj i)]
(i : J) : ∃ (j : J) (hj : j ≤ i), ∀ (k : J) (hk : k ≤ j),
set.range (F.map (hom_of_le $ le_trans hk hj)) =
set.range (F.map (hom_of_le hj)) :=
begin
have := eventually_constant i
(λ e he, set.range (F.map (hom_of_le he))) _,
swap,
{ intros a b ha hb h,
dsimp,
have : hom_of_le ha = (hom_of_le h) ≫ (hom_of_le hb) := rfl,
rw [this, F.map_comp, Profinite.coe_comp],
apply set.range_comp_subset_range },
obtain ⟨j0,hj0,hh⟩ := this,
use j0, use hj0,
exact hh,
end
/-- The images of the transition maps stabilize, in which case they agree with
the image of the cone point. -/
theorem exists_image [inhabited J] [∀ i, fintype (F.obj i)]
(hC : is_limit C) (i : J) : ∃ (j : J) (hj : j ≤ i),
set.range (C.π.app i) = set.range (F.map $ hom_of_le $ hj) :=
begin
have := Inter_eq i (λ e he, set.range (F.map (hom_of_le he))) _,
swap,
{ intros a b ha hb hh,
dsimp,
have : hom_of_le ha = hom_of_le hh ≫ hom_of_le hb, refl,
rw [this, F.map_comp, Profinite.coe_comp],
apply set.range_comp_subset_range },
obtain ⟨j0,hj0,hh⟩ := this,
dsimp at hh,
use j0, use hj0,
rw [image_eq _ _ hC, ← hh],
end
end Profinite
|
7cf7ae3e8e129bba2cd9466d45adfefddd19ef09 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/normed_space/star/mul.lean | 46e1f84950911bdb07e50210d8f44b9270a4c904 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 3,002 | 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 analysis.normed_space.operator_norm
/-! # The left-regular representation is an isometry for C⋆-algebras -/
open continuous_linear_map
local postfix `⋆`:std.prec.max_plus := star
variables (𝕜 : Type*) {E : Type*}
variables [densely_normed_field 𝕜] [non_unital_normed_ring E] [star_ring E] [cstar_ring E]
variables [normed_space 𝕜 E] [is_scalar_tower 𝕜 E E] [smul_comm_class 𝕜 E E] (a : E)
/-- In a C⋆-algebra `E`, either unital or non-unital, multiplication on the left by `a : E` has
norm equal to the norm of `a`. -/
@[simp] lemma op_nnnorm_mul : ‖mul 𝕜 E a‖₊ = ‖a‖₊ :=
begin
rw ←Sup_closed_unit_ball_eq_nnnorm,
refine cSup_eq_of_forall_le_of_forall_lt_exists_gt _ _ (λ r hr, _),
{ exact (metric.nonempty_closed_ball.mpr zero_le_one).image _ },
{ rintro - ⟨x, hx, rfl⟩,
exact ((mul 𝕜 E a).unit_le_op_norm x $ mem_closed_ball_zero_iff.mp hx).trans
(op_norm_mul_apply_le 𝕜 E a) },
{ have ha : 0 < ‖a‖₊ := zero_le'.trans_lt hr,
rw [←inv_inv (‖a‖₊), nnreal.lt_inv_iff_mul_lt (inv_ne_zero ha.ne')] at hr,
obtain ⟨k, hk₁, hk₂⟩ := normed_field.exists_lt_nnnorm_lt 𝕜 (mul_lt_mul_of_pos_right hr $
inv_pos.2 ha),
refine ⟨_, ⟨k • star a, _, rfl⟩, _⟩,
{ simpa only [mem_closed_ball_zero_iff, norm_smul, one_mul, norm_star] using
(nnreal.le_inv_iff_mul_le ha.ne').1 (one_mul ‖a‖₊⁻¹ ▸ hk₂.le : ‖k‖₊ ≤ ‖a‖₊⁻¹) },
{ simp only [map_smul, nnnorm_smul, mul_apply', mul_smul_comm, cstar_ring.nnnorm_self_mul_star],
rwa [←nnreal.div_lt_iff (mul_pos ha ha).ne', div_eq_mul_inv, mul_inv, ←mul_assoc] } },
end
/-- In a C⋆-algebra `E`, either unital or non-unital, multiplication on the right by `a : E` has
norm eqaul to the norm of `a`. -/
@[simp] lemma op_nnnorm_mul_flip : ‖(mul 𝕜 E).flip a‖₊ = ‖a‖₊ :=
begin
rw [←Sup_unit_ball_eq_nnnorm, ←nnnorm_star, ←@op_nnnorm_mul 𝕜 E, ←Sup_unit_ball_eq_nnnorm],
congr' 1,
simp only [mul_apply', flip_apply],
refine set.subset.antisymm _ _;
rintro - ⟨b, hb, rfl⟩;
refine ⟨star b, by simpa only [norm_star, mem_ball_zero_iff] using hb, _⟩,
{ simp only [←star_mul, nnnorm_star] },
{ simpa using (nnnorm_star (star b * a)).symm }
end
variables (E)
/-- In a C⋆-algebra `E`, either unital or non-unital, the left regular representation is an
isometry. -/
lemma mul_isometry : isometry (mul 𝕜 E) :=
add_monoid_hom_class.isometry_of_norm _ (λ a, congr_arg coe $ op_nnnorm_mul 𝕜 a)
/-- In a C⋆-algebra `E`, either unital or non-unital, the right regular anti-representation is an
isometry. -/
lemma mul_flip_isometry : isometry (mul 𝕜 E).flip :=
add_monoid_hom_class.isometry_of_norm _ (λ a, congr_arg coe $ op_nnnorm_mul_flip 𝕜 a)
|
64e2bd58042977d5b6c8d84f0ef47f73b19c5ca2 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/linear_algebra/determinant.lean | 4c8000e69219d7f0a68f781740046171ceec7359 | [
"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 | 13,629 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Tim Baanen
-/
import data.matrix.pequiv
import data.fintype.card
import group_theory.perm.sign
import algebra.algebra.basic
import tactic.ring
universes u v w z
open equiv equiv.perm finset function
namespace matrix
open_locale matrix big_operators
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
local notation `ε` σ:max := ((sign σ : ℤ ) : R)
/-- The determinant of a matrix given by the Leibniz formula. -/
definition det (M : matrix n n R) : R :=
∑ σ : perm n, ε σ * ∏ i, M (σ i) i
@[simp] lemma det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i :=
begin
refine (finset.sum_eq_single 1 _ _).trans _,
{ intros σ h1 h2,
cases not_forall.1 (mt equiv.ext h2) with x h3,
convert mul_zero _,
apply finset.prod_eq_zero,
{ change x ∈ _, simp },
exact if_neg h3 },
{ simp },
{ simp }
end
@[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 :=
by rw [← diagonal_zero, det_diagonal, finset.prod_const, ← fintype.card,
zero_pow (fintype.card_pos_iff.2 h)]
@[simp] lemma det_one : det (1 : matrix n n R) = 1 :=
by rw [← diagonal_one]; simp [-diagonal_one]
lemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 :=
begin
have perm_eq : (univ : finset (perm n)) = {1} :=
univ_eq_singleton_of_card_one (1 : perm n) (by simp [card_univ, fintype.card_perm, h]),
simp [det, card_eq_zero.mp h, perm_eq],
end
lemma det_mul_aux {M N : matrix n n R} {p : n → n} (H : ¬bijective p) :
∑ σ : perm n, (ε σ) * ∏ x, (M (σ x) (p x) * N (p x) x) = 0 :=
begin
obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j,
{ rw [← fintype.injective_iff_bijective, injective] at H,
push_neg at H,
exact H },
exact sum_involution
(λ σ _, σ * swap i j)
(λ σ _,
have ∀ a, p (swap i j a) = p a := λ a, by simp only [swap_apply_def]; split_ifs; cc,
have ∏ x, M (σ x) (p x) = ∏ x, M ((σ * swap i j) x) (p x),
from prod_bij (λ a _, swap i j a) (λ _ _, mem_univ _) (by simp [this])
(λ _ _ _ _ h, (swap i j).injective h)
(λ b _, ⟨swap i j b, mem_univ _, by simp⟩),
by simp [sign_mul, this, sign_swap hij, prod_mul_distrib])
(λ σ _ _ h, hij (σ.injective $ by conv {to_lhs, rw ← h}; simp))
(λ _ _, mem_univ _)
(λ _ _, equiv.ext $ by simp)
end
@[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N :=
calc det (M ⬝ N) = ∑ p : n → n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :
by simp only [det, mul_apply, prod_univ_sum, mul_sum,
fintype.pi_finset_univ]; rw [finset.sum_comm]
... = ∑ p in (@univ (n → n) _).filter bijective, ∑ σ : perm n,
ε σ * ∏ i, (M (σ i) (p i) * N (p i) i) :
eq.symm $ sum_subset (filter_subset _)
(λ f _ hbij, det_mul_aux $ by simpa using hbij)
... = ∑ τ : perm n, ∑ σ : perm n, ε σ * ∏ i, (M (σ i) (τ i) * N (τ i) i) :
sum_bij (λ p h, equiv.of_bijective p (mem_filter.1 h).2) (λ _ _, mem_univ _)
(λ _ _, rfl) (λ _ _ _ _ h, by injection h)
(λ b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, injective_coe_fn rfl⟩)
... = ∑ σ : perm n, ∑ τ : perm n, (∏ i, N (σ i) i) * ε τ * (∏ j, M (τ j) (σ j)) :
by simp [mul_sum, det, mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]
... = ∑ σ : perm n, ∑ τ : perm n, (((∏ i, N (σ i) i) * (ε σ * ε τ)) * ∏ i, M (τ i) i) :
sum_congr rfl (λ σ _, sum_bij (λ τ _, τ * σ⁻¹) (λ _ _, mem_univ _)
(λ τ _,
have ∏ j, M (τ j) (σ j) = ∏ j, M ((τ * σ⁻¹) j) j,
by rw ← σ⁻¹.prod_comp; simp [mul_apply],
have h : ε σ * ε (τ * σ⁻¹) = ε τ :=
calc ε σ * ε (τ * σ⁻¹) = ε ((τ * σ⁻¹) * σ) :
by rw [mul_comm, sign_mul (τ * σ⁻¹)]; simp [sign_mul]
... = ε τ : by simp,
by rw h; simp [this, mul_comm, mul_assoc, mul_left_comm])
(λ _ _ _ _, mul_right_cancel) (λ τ _, ⟨τ * σ, by simp⟩))
... = det M * det N : by simp [det, mul_assoc, mul_sum, mul_comm, mul_left_comm]
instance : is_monoid_hom (det : matrix n n R → R) :=
{ map_one := det_one,
map_mul := det_mul }
/-- Transposing a matrix preserves the determinant. -/
@[simp] lemma det_transpose (M : matrix n n R) : Mᵀ.det = M.det :=
begin
apply sum_bij (λ σ _, σ⁻¹),
{ intros σ _, apply mem_univ },
{ intros σ _,
rw [sign_inv],
congr' 1,
apply prod_bij (λ i _, σ i),
{ intros i _, apply mem_univ },
{ intros i _, simp },
{ intros i j _ _ h, simp at h, assumption },
{ intros i _, use σ⁻¹ i, finish } },
{ intros σ σ' _ _ h, simp at h, assumption },
{ intros σ _, use σ⁻¹, finish }
end
/-- The determinant of a permutation matrix equals its sign. -/
@[simp] lemma det_permutation (σ : perm n) :
matrix.det (σ.to_pequiv.to_matrix : matrix n n R) = σ.sign := begin
suffices : matrix.det (σ.to_pequiv.to_matrix) = ↑σ.sign * det (1 : matrix n n R), { simp [this] },
unfold det,
rw mul_sum,
apply sum_bij (λ τ _, σ * τ),
{ intros τ _, apply mem_univ },
{ intros τ _,
conv_lhs { rw [←one_mul (sign τ), ←int.units_pow_two (sign σ)] },
conv_rhs { rw [←mul_assoc, coe_coe, sign_mul, units.coe_mul, int.cast_mul, ←mul_assoc] },
congr,
{ simp [pow_two] },
{ ext i, apply pequiv.equiv_to_pequiv_to_matrix } },
{ intros τ τ' _ _, exact (mul_right_inj σ).mp },
{ intros τ _, use σ⁻¹ * τ, use (mem_univ _), exact (mul_inv_cancel_left _ _).symm }
end
/-- Permuting the columns changes the sign of the determinant. -/
lemma det_permute (σ : perm n) (M : matrix n n R) : matrix.det (λ i, M (σ i)) = σ.sign * M.det :=
by rw [←det_permutation, ←det_mul, pequiv.to_pequiv_mul_matrix]
@[simp] lemma det_smul {A : matrix n n R} {c : R} : det (c • A) = c ^ fintype.card n * det A :=
calc det (c • A) = det (matrix.mul (diagonal (λ _, c)) A) : by rw [smul_eq_diagonal_mul]
... = det (diagonal (λ _, c)) * det A : det_mul _ _
... = c ^ fintype.card n * det A : by simp [card_univ]
section hom_map
variables {S : Type w} [comm_ring S]
lemma ring_hom.map_det {M : matrix n n R} {f : R →+* S} :
f M.det = matrix.det (f.map_matrix M) :=
by simp [matrix.det, f.map_sum, f.map_prod]
lemma alg_hom.map_det [algebra R S] {T : Type z} [comm_ring T] [algebra R T]
{M : matrix n n S} {f : S →ₐ[R] T} :
f M.det = matrix.det ((f : S →+* T).map_matrix M) :=
by rw [← alg_hom.coe_to_ring_hom, ring_hom.map_det]
end hom_map
section det_zero
/-!
### `det_zero` section
Prove that a matrix with a repeated column has determinant equal to zero.
-/
lemma det_eq_zero_of_row_eq_zero {A : matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=
begin
rw [←det_transpose, det],
convert @sum_const_zero _ _ (univ : finset (perm n)) _,
ext σ,
convert mul_zero ↑(sign σ),
apply prod_eq_zero (mem_univ i),
rw [transpose_apply],
apply h
end
lemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 :=
by { rw ← det_transpose, exact det_eq_zero_of_row_eq_zero j h, }
/--
`mod_swap i j` contains permutations up to swapping `i` and `j`.
We use this to partition permutations in the expression for the determinant,
such that each partitions sums up to `0`.
-/
def mod_swap {n : Type u} [decidable_eq n] (i j : n) : setoid (perm n) :=
⟨ λ σ τ, σ = τ ∨ σ = swap i j * τ,
λ σ, or.inl (refl σ),
λ σ τ h, or.cases_on h (λ h, or.inl h.symm) (λ h, or.inr (by rw [h, swap_mul_self_mul])),
λ σ τ υ hστ hτυ, by cases hστ; cases hτυ; try {rw [hστ, hτυ, swap_mul_self_mul]}; finish⟩
instance (i j : n) : decidable_rel (mod_swap i j).r := λ σ τ, or.decidable
variables {M : matrix n n R} {i j : n}
/-- If a matrix has a repeated row, the determinant will be zero. -/
theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 :=
begin
have swap_invariant : ∀ k, M (swap i j k) = M k,
{ intros k,
rw [swap_apply_def],
by_cases k = i, { rw [if_pos h, h, ←hij] },
rw [if_neg h],
by_cases k = j, { rw [if_pos h, h, hij] },
rw [if_neg h] },
have : ∀ σ, _root_.disjoint {σ} {swap i j * σ},
{ intros σ,
rw [disjoint_singleton, mem_singleton],
exact (not_congr swap_mul_eq_iff).mpr i_ne_j },
apply finset.sum_cancels_of_partition_cancels (mod_swap i j),
intros σ _,
erw [filter_or, filter_eq', filter_eq', if_pos (mem_univ σ), if_pos (mem_univ (swap i j * σ)),
sum_union (this σ), sum_singleton, sum_singleton],
convert add_right_neg (↑↑(sign σ) * ∏ i, M (σ i) i),
rw [neg_mul_eq_neg_mul],
congr,
{ rw [sign_mul, sign_swap i_ne_j], norm_num },
ext j, rw [perm.mul_apply, swap_invariant]
end
end det_zero
lemma det_update_column_add (M : matrix n n R) (j : n) (u v : n → R) :
det (update_column M j $ u + v) = det (update_column M j u) + det (update_column M j v) :=
begin
simp only [det],
have : ∀ σ : perm n, ∏ i, M.update_column j (u + v) (σ i) i =
∏ i, M.update_column j u (σ i) i + ∏ i, M.update_column j v (σ i) i,
{ intros σ,
simp only [update_column_apply, prod_ite, filter_eq',
finset.prod_singleton, finset.mem_univ, if_true, pi.add_apply, add_mul] },
rw [← sum_add_distrib],
apply sum_congr rfl,
intros x _,
rw [this, mul_add]
end
lemma det_update_row_add (M : matrix n n R) (j : n) (u v : n → R) :
det (update_row M j $ u + v) = det (update_row M j u) + det (update_row M j v) :=
begin
rw [← det_transpose, ← update_column_transpose, det_update_column_add],
simp [update_column_transpose, det_transpose]
end
lemma det_update_column_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_column M j $ s • u) = s * det (update_column M j u) :=
begin
simp only [det],
have : ∀ σ : perm n, ∏ i, M.update_column j (s • u) (σ i) i = s * ∏ i, M.update_column j u (σ i) i,
{ intros σ,
simp only [update_column_apply, prod_ite, filter_eq', finset.prod_singleton, finset.mem_univ,
if_true, algebra.id.smul_eq_mul, pi.smul_apply],
ring },
rw mul_sum,
apply sum_congr rfl,
intros x _,
rw this,
ring
end
lemma det_update_row_smul (M : matrix n n R) (j : n) (s : R) (u : n → R) :
det (update_row M j $ s • u) = s * det (update_row M j u) :=
begin
rw [← det_transpose, ← update_column_transpose, det_update_column_smul],
simp [update_column_transpose, det_transpose]
end
@[simp] lemma det_block_diagonal {o : Type*} [fintype o] [decidable_eq o] (M : o → matrix n n R) :
(block_diagonal M).det = ∏ k, (M k).det :=
begin
-- Rewrite the determinants as a sum over permutations.
unfold det,
-- The right hand side is a product of sums, rewrite it as a sum of products.
rw finset.prod_sum,
simp_rw [finset.mem_univ, finset.prod_attach_univ, finset.univ_pi_univ],
-- We claim that the only permutations contributing to the sum are those that
-- preserve their second component.
let preserving_snd : finset (equiv.perm (n × o)) :=
finset.univ.filter (λ σ, ∀ x, (σ x).snd = x.snd),
have mem_preserving_snd : ∀ {σ : equiv.perm (n × o)},
σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd :=
λ σ, finset.mem_filter.trans ⟨λ h, h.2, λ h, ⟨finset.mem_univ _, h⟩⟩,
rw ← finset.sum_subset (finset.subset_univ preserving_snd) _,
-- And that these are in bijection with `o → equiv.perm m`.
rw (finset.sum_bij (λ (σ : ∀ (k : o), k ∈ finset.univ → equiv.perm n) _,
prod_congr_left (λ k, σ k (finset.mem_univ k))) _ _ _ _).symm,
{ intros σ _,
rw mem_preserving_snd,
rintros ⟨k, x⟩,
simp },
{ intros σ _,
rw finset.prod_mul_distrib,
congr,
{ convert congr_arg (λ (x : units ℤ), (↑x : R)) (sign_prod_congr_left (λ k, σ k _)).symm,
simp, congr, ext, congr },
rw [← finset.univ_product_univ, finset.prod_product, finset.prod_comm],
simp },
{ intros σ σ' _ _ eq,
ext x hx k,
simp only at eq,
have : ∀ k x, prod_congr_left (λ k, σ k (finset.mem_univ _)) (k, x) =
prod_congr_left (λ k, σ' k (finset.mem_univ _)) (k, x) :=
λ k x, by rw eq,
simp only [prod_congr_left_apply, prod.mk.inj_iff] at this,
exact (this k x).1 },
{ intros σ hσ,
rw mem_preserving_snd at hσ,
have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd,
{ intro x, conv_rhs { rw [← perm.apply_inv_self σ x, hσ] } },
have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k),
{ intros k x,
ext; simp [hσ] },
have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k),
{ intros k x,
conv_lhs { rw ← perm.apply_inv_self σ (x, k) },
ext; simp [hσ'] },
refine ⟨λ k _, ⟨λ x, (σ (x, k)).fst, λ x, (σ⁻¹ (x, k)).fst, _, _⟩, _, _⟩,
{ intro x,
simp [mk_apply_eq, mk_inv_apply_eq] },
{ intro x,
simp [mk_apply_eq, mk_inv_apply_eq] },
{ apply finset.mem_univ },
{ ext ⟨k, x⟩; simp [hσ] } },
{ intros σ _ hσ,
rw mem_preserving_snd at hσ,
obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ,
rw [finset.prod_eq_zero (finset.mem_univ (k, x)), mul_zero],
rw [← @prod.mk.eta _ _ (σ (k, x)), block_diagonal_apply_ne],
exact hkx }
end
end matrix
|
ac6f628a40f6041bc81e5b78cc0628793dbf6ebb | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/algebra/lie/weights.lean | 77086d8ea0f065cb78aa7ac28c56edab15eebfd2 | [
"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 | 23,993 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.nilpotent
import algebra.lie.tensor_product
import algebra.lie.character
import algebra.lie.engel
import algebra.lie.cartan_subalgebra
import linear_algebra.eigenspace
import ring_theory.tensor_product
/-!
# Weights and roots of Lie modules and Lie algebras
Just as a key tool when studying the behaviour of a linear operator is to decompose the space on
which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M`
of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges
over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`.
When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules.
Even when `L` is not nilpotent, it may be useful to study its representations by restricting them
to a nilpotent subalgebra (e.g., a Cartan subalgebra). In the particular case when we view `L` as a
module over itself via the adjoint action, the weight spaces of `L` restricted to a nilpotent
subalgebra are known as root spaces.
Basic definitions and properties of the above ideas are provided in this file.
## Main definitions
* `lie_module.weight_space`
* `lie_module.is_weight`
* `lie_algebra.root_space`
* `lie_algebra.is_root`
* `lie_algebra.root_space_weight_space_product`
* `lie_algebra.root_space_product`
* `lie_algebra.zero_root_subalgebra_eq_iff_is_cartan`
## References
* [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b)
## Tags
lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector
-/
universes u v w w₁ w₂ w₃
variables {R : Type u} {L : Type v} [comm_ring R] [lie_ring L] [lie_algebra R L]
variables (H : lie_subalgebra R L) [lie_algebra.is_nilpotent R H]
variables (M : Type w) [add_comm_group M] [module R M] [lie_ring_module L M] [lie_module R L M]
namespace lie_module
open lie_algebra
open tensor_product
open tensor_product.lie_module
open_locale big_operators
open_locale tensor_product
/-- Given a Lie module `M` over a Lie algebra `L`, the pre-weight space of `M` with respect to a
map `χ : L → R` is the simultaneous generalized eigenspace of the action of all `x : L` on `M`,
with eigenvalues `χ x`.
See also `lie_module.weight_space`. -/
def pre_weight_space (χ : L → R) : submodule R M :=
⨅ (x : L), (to_endomorphism R L M x).maximal_generalized_eigenspace (χ x)
lemma mem_pre_weight_space (χ : L → R) (m : M) :
m ∈ pre_weight_space M χ ↔ ∀ x, ∃ (k : ℕ), ((to_endomorphism R L M x - (χ x) • 1)^k) m = 0 :=
by simp [pre_weight_space, -linear_map.pow_apply]
variables (R)
lemma exists_pre_weight_space_zero_le_ker_of_is_noetherian [is_noetherian R M] (x : L) :
∃ (k : ℕ), pre_weight_space M (0 : L → R) ≤ ((to_endomorphism R L M x)^k).ker :=
begin
use (to_endomorphism R L M x).maximal_generalized_eigenspace_index 0,
simp only [← module.End.generalized_eigenspace_zero, pre_weight_space, pi.zero_apply, infi_le,
← (to_endomorphism R L M x).maximal_generalized_eigenspace_eq],
end
variables {R} (L)
/-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/
protected lemma weight_vector_multiplication (M₁ : Type w₁) (M₂ : Type w₂) (M₃ : Type w₃)
[add_comm_group M₁] [module R M₁] [lie_ring_module L M₁] [lie_module R L M₁]
[add_comm_group M₂] [module R M₂] [lie_ring_module L M₂] [lie_module R L M₂]
[add_comm_group M₃] [module R M₃] [lie_ring_module L M₃] [lie_module R L M₃]
(g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : L → R) :
((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp
(map_incl (pre_weight_space M₁ χ₁) (pre_weight_space M₂ χ₂))).range ≤
pre_weight_space M₃ (χ₁ + χ₂) :=
begin
/- Unpack the statement of the goal. -/
intros m₃,
simp only [lie_module_hom.coe_to_linear_map, pi.add_apply, function.comp_app,
mem_pre_weight_space, linear_map.coe_comp, tensor_product.map_incl, exists_imp_distrib,
linear_map.mem_range],
rintros t rfl x,
/- Set up some notation. -/
let F : module.End R M₃ := (to_endomorphism R L M₃ x) - (χ₁ x + χ₂ x) • 1,
change ∃ k, (F^k) (g _) = 0,
/- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. -/
apply t.induction_on,
{ use 0, simp only [linear_map.map_zero, lie_module_hom.map_zero], },
swap,
{ rintros t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩, use max k₁ k₂,
simp only [lie_module_hom.map_add, linear_map.map_add,
linear_map.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁,
linear_map.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero], },
/- Now the main argument: pure tensors. -/
rintros ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩,
change ∃ k, (F^k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = 0,
/- Eliminate `g` from the picture. -/
let f₁ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₁ x - (χ₁ x) • 1).rtensor M₂,
let f₂ : module.End R (M₁ ⊗[R] M₂) := (to_endomorphism R L M₂ x - (χ₂ x) • 1).ltensor M₁,
have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂),
{ ext m₁ m₂, simp only [← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul,
lie_tmul_right, tmul_smul, to_endomorphism_apply_apply, lie_module_hom.map_smul,
linear_map.one_apply, lie_module_hom.coe_to_linear_map, linear_map.smul_apply,
function.comp_app, linear_map.coe_comp, linear_map.rtensor_tmul, lie_module_hom.map_add,
linear_map.add_apply, lie_module_hom.map_sub, linear_map.sub_apply, linear_map.ltensor_tmul,
algebra_tensor_module.curry_apply, curry_apply, linear_map.to_fun_eq_coe,
linear_map.coe_restrict_scalars_eq_coe], abel, },
suffices : ∃ k, ((f₁ + f₂)^k) (m₁ ⊗ₜ m₂) = 0,
{ obtain ⟨k, hk⟩ := this, use k,
rw [← linear_map.comp_apply, linear_map.commute_pow_left_of_commute h_comm_square,
linear_map.comp_apply, hk, linear_map.map_zero], },
/- Unpack the information we have about `m₁`, `m₂`. -/
simp only [mem_pre_weight_space] at hm₁ hm₂,
obtain ⟨k₁, hk₁⟩ := hm₁ x,
obtain ⟨k₂, hk₂⟩ := hm₂ x,
have hf₁ : (f₁^k₁) (m₁ ⊗ₜ m₂) = 0,
{ simp only [hk₁, zero_tmul, linear_map.rtensor_tmul, linear_map.rtensor_pow], },
have hf₂ : (f₂^k₂) (m₁ ⊗ₜ m₂) = 0,
{ simp only [hk₂, tmul_zero, linear_map.ltensor_tmul, linear_map.ltensor_pow], },
/- It's now just an application of the binomial theorem. -/
use k₁ + k₂ - 1,
have hf_comm : commute f₁ f₂,
{ ext m₁ m₂, simp only [linear_map.mul_apply, linear_map.rtensor_tmul, linear_map.ltensor_tmul,
algebra_tensor_module.curry_apply, linear_map.to_fun_eq_coe, linear_map.ltensor_tmul,
curry_apply, linear_map.coe_restrict_scalars_eq_coe], },
rw hf_comm.add_pow',
simp only [tensor_product.map_incl, submodule.subtype_apply, finset.sum_apply,
submodule.coe_mk, linear_map.coe_fn_sum, tensor_product.map_tmul, linear_map.smul_apply],
/- The required sum is zero because each individual term is zero. -/
apply finset.sum_eq_zero,
rintros ⟨i, j⟩ hij,
/- Eliminate the binomial coefficients from the picture. -/
suffices : (f₁^i * f₂^j) (m₁ ⊗ₜ m₂) = 0, { rw this, apply smul_zero, },
/- Finish off with appropriate case analysis. -/
cases nat.le_or_le_of_add_eq_add_pred (finset.nat.mem_antidiagonal.mp hij) with hi hj,
{ rw [(hf_comm.pow_pow i j).eq, linear_map.mul_apply, linear_map.pow_map_zero_of_le hi hf₁,
linear_map.map_zero], },
{ rw [linear_map.mul_apply, linear_map.pow_map_zero_of_le hj hf₂, linear_map.map_zero], },
end
variables {L M}
lemma lie_mem_pre_weight_space_of_mem_pre_weight_space {χ₁ χ₂ : L → R} {x : L} {m : M}
(hx : x ∈ pre_weight_space L χ₁) (hm : m ∈ pre_weight_space M χ₂) :
⁅x, m⁆ ∈ pre_weight_space M (χ₁ + χ₂) :=
begin
apply lie_module.weight_vector_multiplication L L M M (to_module_hom R L M) χ₁ χ₂,
simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp,
tensor_product.map_incl, linear_map.mem_range],
use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩],
simp only [submodule.subtype_apply, to_module_hom_apply, tensor_product.map_tmul],
refl,
end
variables (M)
/-- If a Lie algebra is nilpotent, then pre-weight spaces are Lie submodules. -/
def weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) : lie_submodule R L M :=
{ lie_mem := λ x m hm,
begin
rw ← zero_add χ,
refine lie_mem_pre_weight_space_of_mem_pre_weight_space _ hm,
suffices : pre_weight_space L (0 : L → R) = ⊤, { simp only [this, submodule.mem_top], },
exact lie_algebra.infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L,
end,
.. pre_weight_space M χ }
lemma mem_weight_space [lie_algebra.is_nilpotent R L] (χ : L → R) (m : M) :
m ∈ weight_space M χ ↔ m ∈ pre_weight_space M χ :=
iff.rfl
/-- See also the more useful form `lie_module.zero_weight_space_eq_top_of_nilpotent`. -/
@[simp] lemma zero_weight_space_eq_top_of_nilpotent'
[lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
weight_space M (0 : L → R) = ⊤ :=
begin
rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule],
exact infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M,
end
lemma coe_weight_space_of_top [lie_algebra.is_nilpotent R L] (χ : L → R) :
(weight_space M (χ ∘ (⊤ : lie_subalgebra R L).incl) : submodule R M) = weight_space M χ :=
begin
ext m,
simp only [weight_space, lie_submodule.coe_to_submodule_mk, lie_subalgebra.coe_bracket_of_module,
function.comp_app, mem_pre_weight_space],
split; intros h x,
{ obtain ⟨k, hk⟩ := h ⟨x, set.mem_univ x⟩, use k, exact hk, },
{ obtain ⟨k, hk⟩ := h x, use k, exact hk, },
end
@[simp] lemma zero_weight_space_eq_top_of_nilpotent
[lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
weight_space M (0 : (⊤ : lie_subalgebra R L) → R) = ⊤ :=
begin
/- We use `coe_weight_space_of_top` as a trick to circumvent the fact that we don't (yet) know
`is_nilpotent R (⊤ : lie_subalgebra R L) M` is equivalent to `is_nilpotent R L M`. -/
have h₀ : (0 : L → R) ∘ (⊤ : lie_subalgebra R L).incl = 0, { ext, refl, },
rw [← lie_submodule.coe_to_submodule_eq_iff, lie_submodule.top_coe_submodule, ← h₀,
coe_weight_space_of_top, ← infi_max_gen_zero_eigenspace_eq_top_of_nilpotent R L M],
refl,
end
/-- Given a Lie module `M` of a Lie algebra `L`, a weight of `M` with respect to a nilpotent
subalgebra `H ⊆ L` is a Lie character whose corresponding weight space is non-empty. -/
def is_weight (χ : lie_character R H) : Prop := weight_space M χ ≠ ⊥
/-- For a non-trivial nilpotent Lie module over a nilpotent Lie algebra, the zero character is a
weight with respect to the `⊤` Lie subalgebra. -/
lemma is_weight_zero_of_nilpotent
[nontrivial M] [lie_algebra.is_nilpotent R L] [is_nilpotent R L M] :
is_weight (⊤ : lie_subalgebra R L) M 0 :=
by { rw [is_weight, lie_hom.coe_zero, zero_weight_space_eq_top_of_nilpotent], exact top_ne_bot, }
/-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie
module. -/
lemma is_nilpotent_to_endomorphism_weight_space_zero
[lie_algebra.is_nilpotent R L] [is_noetherian R M] (x : L) :
_root_.is_nilpotent $ to_endomorphism R L (weight_space M (0 : L → R)) x :=
begin
obtain ⟨k, hk⟩ := exists_pre_weight_space_zero_le_ker_of_is_noetherian R M x,
use k,
ext ⟨m, hm⟩,
rw [linear_map.zero_apply, lie_submodule.coe_zero, submodule.coe_eq_zero,
← lie_submodule.to_endomorphism_restrict_eq_to_endomorphism, linear_map.pow_restrict,
← set_like.coe_eq_coe, linear_map.restrict_apply, submodule.coe_mk, submodule.coe_zero],
exact hk hm,
end
/-- By Engel's theorem, when the Lie algebra is Noetherian, the zero weight space of a Noetherian
Lie module is nilpotent. -/
instance [lie_algebra.is_nilpotent R L] [is_noetherian R L] [is_noetherian R M] :
is_nilpotent R L (weight_space M (0 : L → R)) :=
is_nilpotent_iff_forall.mpr $ is_nilpotent_to_endomorphism_weight_space_zero M
end lie_module
namespace lie_algebra
open_locale tensor_product
open tensor_product.lie_module
open lie_module
/-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of a map `χ : H → R` is the weight
space of `L` regarded as a module of `H` via the adjoint action. -/
abbreviation root_space (χ : H → R) : lie_submodule R H L := weight_space L χ
@[simp] lemma zero_root_space_eq_top_of_nilpotent [h : is_nilpotent R L] :
root_space (⊤ : lie_subalgebra R L) 0 = ⊤ :=
zero_weight_space_eq_top_of_nilpotent L
/-- A root of a Lie algebra `L` with respect to a nilpotent subalgebra `H ⊆ L` is a weight of `L`,
regarded as a module of `H` via the adjoint action. -/
abbreviation is_root := is_weight H L
@[simp] lemma root_space_comap_eq_weight_space (χ : H → R) :
(root_space H χ).comap H.incl' = weight_space H χ :=
begin
ext x,
let f : H → module.End R L := λ y, to_endomorphism R H L y - (χ y) • 1,
let g : H → module.End R H := λ y, to_endomorphism R H H y - (χ y) • 1,
suffices : (∀ (y : H), ∃ (k : ℕ), ((f y)^k).comp (H.incl : H →ₗ[R] L) x = 0) ↔
∀ (y : H), ∃ (k : ℕ), (H.incl : H →ₗ[R] L).comp ((g y)^k) x = 0,
{ simp only [lie_hom.coe_to_linear_map, lie_subalgebra.coe_incl, function.comp_app,
linear_map.coe_comp, submodule.coe_eq_zero] at this,
simp only [mem_weight_space, mem_pre_weight_space,
lie_subalgebra.coe_incl', lie_submodule.mem_comap, this], },
have hfg : ∀ (y : H), (f y).comp (H.incl : H →ₗ[R] L) = (H.incl : H →ₗ[R] L).comp (g y),
{ rintros ⟨y, hy⟩, ext ⟨z, hz⟩,
simp only [submodule.coe_sub, to_endomorphism_apply_apply, lie_hom.coe_to_linear_map,
linear_map.one_apply, lie_subalgebra.coe_incl, lie_subalgebra.coe_bracket_of_module,
lie_subalgebra.coe_bracket, linear_map.smul_apply, function.comp_app,
submodule.coe_smul_of_tower, linear_map.coe_comp, linear_map.sub_apply], },
simp_rw [linear_map.commute_pow_left_of_commute (hfg _)],
end
variables {H M}
lemma lie_mem_weight_space_of_mem_weight_space {χ₁ χ₂ : H → R} {x : L} {m : M}
(hx : x ∈ root_space H χ₁) (hm : m ∈ weight_space M χ₂) : ⁅x, m⁆ ∈ weight_space M (χ₁ + χ₂) :=
begin
apply lie_module.weight_vector_multiplication
H L M M ((to_module_hom R L M).restrict_lie H) χ₁ χ₂,
simp only [lie_module_hom.coe_to_linear_map, function.comp_app, linear_map.coe_comp,
tensor_product.map_incl, linear_map.mem_range],
use [⟨x, hx⟩ ⊗ₜ ⟨m, hm⟩],
simp only [submodule.subtype_apply, to_module_hom_apply, submodule.coe_mk,
lie_module_hom.coe_restrict_lie, tensor_product.map_tmul],
end
variables (R L H M)
/--
Auxiliary definition for `root_space_weight_space_product`,
which is close to the deterministic timeout limit.
-/
def root_space_weight_space_product_aux {χ₁ χ₂ χ₃ : H → R} (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) →ₗ[R] (weight_space M χ₂) →ₗ[R] (weight_space M χ₃) :=
{ to_fun := λ x,
{ to_fun :=
λ m, ⟨⁅(x : L), (m : M)⁆,
hχ ▸ (lie_mem_weight_space_of_mem_weight_space x.property m.property) ⟩,
map_add' := λ m n, by { simp only [lie_submodule.coe_add, lie_add], refl, },
map_smul' := λ t m, by { conv_lhs { congr, rw [lie_submodule.coe_smul, lie_smul], }, refl, }, },
map_add' := λ x y, by ext m; rw [linear_map.add_apply, linear_map.coe_mk, linear_map.coe_mk,
linear_map.coe_mk, subtype.coe_mk, lie_submodule.coe_add, lie_submodule.coe_add, add_lie,
subtype.coe_mk, subtype.coe_mk],
map_smul' := λ t x,
begin
simp only [ring_hom.id_apply],
ext m,
rw [linear_map.smul_apply, linear_map.coe_mk, linear_map.coe_mk,
subtype.coe_mk, lie_submodule.coe_smul, smul_lie, lie_submodule.coe_smul, subtype.coe_mk],
end, }
/-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors and weight vectors, compatible with the actions of `H`. -/
def root_space_weight_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) ⊗[R] (weight_space M χ₂) →ₗ⁅R,H⁆ weight_space M χ₃ :=
lift_lie R H (root_space H χ₁) (weight_space M χ₂) (weight_space M χ₃)
{ to_linear_map := root_space_weight_space_product_aux R L H M hχ,
map_lie' := λ x y, by ext m; rw [root_space_weight_space_product_aux,
lie_hom.lie_apply, lie_submodule.coe_sub, linear_map.coe_mk,
linear_map.coe_mk, subtype.coe_mk, subtype.coe_mk, lie_submodule.coe_bracket,
lie_submodule.coe_bracket, subtype.coe_mk, lie_subalgebra.coe_bracket_of_module,
lie_subalgebra.coe_bracket_of_module, lie_submodule.coe_bracket,
lie_subalgebra.coe_bracket_of_module, lie_lie], }
@[simp] lemma coe_root_space_weight_space_product_tmul
(χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (m : weight_space M χ₂) :
(root_space_weight_space_product R L H M χ₁ χ₂ χ₃ hχ (x ⊗ₜ m) : M) = ⁅(x : L), (m : M)⁆ :=
by simp only [root_space_weight_space_product, root_space_weight_space_product_aux,
lift_apply, lie_module_hom.coe_to_linear_map,
coe_lift_lie_eq_lift_coe, submodule.coe_mk, linear_map.coe_mk, lie_module_hom.coe_mk]
/-- Given a nilpotent Lie subalgebra `H ⊆ L` together with `χ₁ χ₂ : H → R`, there is a natural
`R`-bilinear product of root vectors, compatible with the actions of `H`. -/
def root_space_product (χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) :
(root_space H χ₁) ⊗[R] (root_space H χ₂) →ₗ⁅R,H⁆ root_space H χ₃ :=
root_space_weight_space_product R L H L χ₁ χ₂ χ₃ hχ
@[simp] lemma root_space_product_def :
root_space_product R L H = root_space_weight_space_product R L H L :=
rfl
lemma root_space_product_tmul
(χ₁ χ₂ χ₃ : H → R) (hχ : χ₁ + χ₂ = χ₃) (x : root_space H χ₁) (y : root_space H χ₂) :
(root_space_product R L H χ₁ χ₂ χ₃ hχ (x ⊗ₜ y) : L) = ⁅(x : L), (y : L)⁆ :=
by simp only [root_space_product_def, coe_root_space_weight_space_product_tmul]
/-- Given a nilpotent Lie subalgebra `H ⊆ L`, the root space of the zero map `0 : H → R` is a Lie
subalgebra of `L`. -/
def zero_root_subalgebra : lie_subalgebra R L :=
{ lie_mem' := λ x y hx hy, by
{ let xy : (root_space H 0) ⊗[R] (root_space H 0) := ⟨x, hx⟩ ⊗ₜ ⟨y, hy⟩,
suffices : (root_space_product R L H 0 0 0 (add_zero 0) xy : L) ∈ root_space H 0,
{ rwa [root_space_product_tmul, subtype.coe_mk, subtype.coe_mk] at this, },
exact (root_space_product R L H 0 0 0 (add_zero 0) xy).property, },
.. (root_space H 0 : submodule R L) }
@[simp] lemma coe_zero_root_subalgebra :
(zero_root_subalgebra R L H : submodule R L) = root_space H 0 :=
rfl
lemma mem_zero_root_subalgebra (x : L) :
x ∈ zero_root_subalgebra R L H ↔ ∀ (y : H), ∃ (k : ℕ), ((to_endomorphism R H L y)^k) x = 0 :=
by simp only [zero_root_subalgebra, mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero,
set_like.mem_coe, zero_smul, lie_submodule.mem_coe_submodule, submodule.mem_carrier,
lie_subalgebra.mem_mk_iff]
lemma to_lie_submodule_le_root_space_zero : H.to_lie_submodule ≤ root_space H 0 :=
begin
intros x hx,
simp only [lie_subalgebra.mem_to_lie_submodule] at hx,
simp only [mem_weight_space, mem_pre_weight_space, pi.zero_apply, sub_zero, zero_smul],
intros y,
unfreezingI { obtain ⟨k, hk⟩ := (infer_instance : is_nilpotent R H) },
use k,
let f : module.End R H := to_endomorphism R H H y,
let g : module.End R L := to_endomorphism R H L y,
have hfg : g.comp (H : submodule R L).subtype = (H : submodule R L).subtype.comp f,
{ ext z, simp only [to_endomorphism_apply_apply, submodule.subtype_apply,
lie_subalgebra.coe_bracket_of_module, lie_subalgebra.coe_bracket, function.comp_app,
linear_map.coe_comp], },
change (g^k).comp (H : submodule R L).subtype ⟨x, hx⟩ = 0,
rw linear_map.commute_pow_left_of_commute hfg k,
have h := iterate_to_endomorphism_mem_lower_central_series R H H y ⟨x, hx⟩ k,
rw [hk, lie_submodule.mem_bot] at h,
simp only [submodule.subtype_apply, function.comp_app, linear_map.pow_apply, linear_map.coe_comp,
submodule.coe_eq_zero],
exact h,
end
lemma le_zero_root_subalgebra : H ≤ zero_root_subalgebra R L H :=
begin
rw [← lie_subalgebra.coe_submodule_le_coe_submodule, ← H.coe_to_lie_submodule,
coe_zero_root_subalgebra, lie_submodule.coe_submodule_le_coe_submodule],
exact to_lie_submodule_le_root_space_zero R L H,
end
@[simp] lemma zero_root_subalgebra_normalizer_eq_self :
(zero_root_subalgebra R L H).normalizer = zero_root_subalgebra R L H :=
begin
refine le_antisymm _ (lie_subalgebra.le_normalizer _),
intros x hx,
rw lie_subalgebra.mem_normalizer_iff at hx,
rw mem_zero_root_subalgebra,
rintros ⟨y, hy⟩,
specialize hx y (le_zero_root_subalgebra R L H hy),
rw mem_zero_root_subalgebra at hx,
obtain ⟨k, hk⟩ := hx ⟨y, hy⟩,
rw [← lie_skew, linear_map.map_neg, neg_eq_zero] at hk,
use k + 1,
rw [linear_map.iterate_succ, linear_map.coe_comp, function.comp_app, to_endomorphism_apply_apply,
lie_subalgebra.coe_bracket_of_module, submodule.coe_mk, hk],
end
/-- If the zero root subalgebra of a nilpotent Lie subalgebra `H` is just `H` then `H` is a Cartan
subalgebra.
When `L` is Noetherian, it follows from Engel's theorem that the converse holds. See
`lie_algebra.zero_root_subalgebra_eq_iff_is_cartan` -/
lemma is_cartan_of_zero_root_subalgebra_eq (h : zero_root_subalgebra R L H = H) :
H.is_cartan_subalgebra :=
{ nilpotent := infer_instance,
self_normalizing := by { rw ← h, exact zero_root_subalgebra_normalizer_eq_self R L H, } }
@[simp] lemma zero_root_subalgebra_eq_of_is_cartan (H : lie_subalgebra R L)
[H.is_cartan_subalgebra] [is_noetherian R L] :
zero_root_subalgebra R L H = H :=
begin
refine le_antisymm _ (le_zero_root_subalgebra R L H),
suffices : root_space H 0 ≤ H.to_lie_submodule, { exact λ x hx, this hx, },
obtain ⟨k, hk⟩ := (root_space H 0).is_nilpotent_iff_exists_self_le_ucs.mp (by apply_instance),
exact hk.trans (lie_submodule.ucs_le_of_centralizer_eq_self (by simp) k),
end
lemma zero_root_subalgebra_eq_iff_is_cartan [is_noetherian R L] :
zero_root_subalgebra R L H = H ↔ H.is_cartan_subalgebra :=
⟨is_cartan_of_zero_root_subalgebra_eq R L H, by { introsI, simp, }⟩
end lie_algebra
namespace lie_module
open lie_algebra
variables {R L H}
/-- A priori, weight spaces are Lie submodules over the Lie subalgebra `H` used to define them.
However they are naturally Lie submodules over the (in general larger) Lie subalgebra
`zero_root_subalgebra R L H`. Even though it is often the case that
`zero_root_subalgebra R L H = H`, it is likely to be useful to have the flexibility not to have
to invoke this equality (as well as to work more generally). -/
def weight_space' (χ : H → R) : lie_submodule R (zero_root_subalgebra R L H) M :=
{ lie_mem := λ x m hm, by
{ have hx : (x : L) ∈ root_space H 0,
{ rw [← lie_submodule.mem_coe_submodule, ← coe_zero_root_subalgebra], exact x.property, },
rw ← zero_add χ,
exact lie_mem_weight_space_of_mem_weight_space hx hm, },
.. (weight_space M χ : submodule R M) }
@[simp] lemma coe_weight_space' (χ : H → R) :
(weight_space' M χ : submodule R M) = weight_space M χ :=
rfl
end lie_module
|
45aebfb356b9492d3fc23c97d9d4c8663b473bfb | cf39355caa609c0f33405126beee2739aa3cb77e | /library/init/control/functor.lean | 9e41319e3de6fbe4ee9263772be988745425212c | [
"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 | 755 | lean | /-
Copyright (c) Luke Nelson and Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch, Sebastian Ullrich, Leonardo de Moura
-/
prelude
import init.core init.function init.meta.name
open function
universes u v
class functor (f : Type u → Type v) : Type (max (u+1) v) :=
(map : Π {α β : Type u}, (α → β) → f α → f β)
(map_const : Π {α β : Type u}, α → f β → f α := λ α β, map ∘ const β)
infixr ` <$> `:100 := functor.map
infixr ` <$ `:100 := functor.map_const
@[reducible] def functor.map_const_rev {f : Type u → Type v} [functor f] {α β : Type u} : f β → α → f α :=
λ a b, b <$ a
infixr ` $> `:100 := functor.map_const_rev
|
7e8e5b7d80b5369e5c375ffb5fbce3b440a0b1a1 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/generator.lean | 5f79ceb63f136d54724ee171342c19462ebe04a6 | [
"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 | 27,464 | 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.balanced
import category_theory.limits.essentially_small
import category_theory.limits.opposites
import category_theory.limits.shapes.zero_morphisms
import category_theory.subobject.lattice
import category_theory.subobject.well_powered
import data.set.opposite
/-!
# Separating and detecting sets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
There are several non-equivalent notions of a generator of a category. Here, we consider two of
them:
* We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`.
* We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism.
There are, of course, also the dual notions of coseparating and codetecting sets.
## Main results
We
* define predicates `is_separating`, `is_coseparating`, `is_detecting` and `is_codetecting` on
sets of objects;
* show that separating and coseparating are dual notions;
* show that detecting and codetecting are dual notions;
* show that if `C` has equalizers, then detecting implies separating;
* show that if `C` has coequalizers, then codetecting implies separating;
* show that if `C` is balanced, then separating implies detecting and coseparating implies
codetecting;
* show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin;
* show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid;
* define predicates `is_separator`, `is_coseparator`, `is_detector` and `is_codetector` as the
singleton counterparts to the definitions for sets above and restate the above results in this
situation;
* show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual);
* show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the
dual).
## Future work
* We currently don't have any examples yet.
* We will want typeclasses `has_separator C` and similar.
-/
universes w v₁ v₂ u₁ u₂
open category_theory.limits opposite
namespace category_theory
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
/-- We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/
def is_separating (𝒢 : set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ (G ∈ 𝒢) (h : G ⟶ X), h ≫ f = h ≫ g) → f = g
/-- We say that `𝒢` is a coseparating set if the functors `C(-, G)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/
def is_coseparating (𝒢 : set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ (G ∈ 𝒢) (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g
/-- We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. -/
def is_detecting (𝒢 : set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G ∈ 𝒢) (h : G ⟶ Y), ∃! (h' : G ⟶ X), h' ≫ f = h) → is_iso f
/-- We say that `𝒢` is a codetecting set if the functors `C(-, G)` collectively reflect
isomorphisms, i.e., if any `h` with codomain in `G` uniquely factors through `f`, then `f` is
an isomorphism. -/
def is_codetecting (𝒢 : set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ (G ∈ 𝒢) (h : X ⟶ G), ∃! (h' : Y ⟶ G), f ≫ h' = h) → is_iso f
section dual
lemma is_separating_op_iff (𝒢 : set C) : is_separating 𝒢.op ↔ is_coseparating 𝒢 :=
begin
refine ⟨λ h𝒢 X Y f g hfg, _, λ h𝒢 X Y f g hfg, _⟩,
{ refine quiver.hom.op_inj (h𝒢 _ _ (λ G hG h, quiver.hom.unop_inj _)),
simpa only [unop_comp, quiver.hom.unop_op] using hfg _ (set.mem_op.1 hG) _ },
{ refine quiver.hom.unop_inj (h𝒢 _ _ (λ G hG h, quiver.hom.op_inj _)),
simpa only [op_comp, quiver.hom.op_unop] using hfg _ (set.op_mem_op.2 hG) _ }
end
lemma is_coseparating_op_iff (𝒢 : set C) : is_coseparating 𝒢.op ↔ is_separating 𝒢 :=
begin
refine ⟨λ h𝒢 X Y f g hfg, _, λ h𝒢 X Y f g hfg, _⟩,
{ refine quiver.hom.op_inj (h𝒢 _ _ (λ G hG h, quiver.hom.unop_inj _)),
simpa only [unop_comp, quiver.hom.unop_op] using hfg _ (set.mem_op.1 hG) _ },
{ refine quiver.hom.unop_inj (h𝒢 _ _ (λ G hG h, quiver.hom.op_inj _)),
simpa only [op_comp, quiver.hom.op_unop] using hfg _ (set.op_mem_op.2 hG) _ }
end
lemma is_coseparating_unop_iff (𝒢 : set Cᵒᵖ) : is_coseparating 𝒢.unop ↔ is_separating 𝒢 :=
by rw [← is_separating_op_iff, set.unop_op]
lemma is_separating_unop_iff (𝒢 : set Cᵒᵖ) : is_separating 𝒢.unop ↔ is_coseparating 𝒢 :=
by rw [← is_coseparating_op_iff, set.unop_op]
lemma is_detecting_op_iff (𝒢 : set C) : is_detecting 𝒢.op ↔ is_codetecting 𝒢 :=
begin
refine ⟨λ h𝒢 X Y f hf, _, λ h𝒢 X Y f hf, _⟩,
{ refine (is_iso_op_iff _).1 (h𝒢 _ (λ G hG h, _)),
obtain ⟨t, ht, ht'⟩ := hf (unop G) (set.mem_op.1 hG) h.unop,
exact ⟨t.op, quiver.hom.unop_inj ht, λ y hy,
quiver.hom.unop_inj (ht' _ (quiver.hom.op_inj hy))⟩ },
{ refine (is_iso_unop_iff _).1 (h𝒢 _ (λ G hG h, _)),
obtain ⟨t, ht, ht'⟩ := hf (op G) (set.op_mem_op.2 hG) h.op,
refine ⟨t.unop, quiver.hom.op_inj ht, λ y hy, quiver.hom.op_inj (ht' _ _)⟩,
exact quiver.hom.unop_inj (by simpa only using hy) }
end
lemma is_codetecting_op_iff (𝒢 : set C) : is_codetecting 𝒢.op ↔ is_detecting 𝒢 :=
begin
refine ⟨λ h𝒢 X Y f hf, _, λ h𝒢 X Y f hf, _⟩,
{ refine (is_iso_op_iff _).1 (h𝒢 _ (λ G hG h, _)),
obtain ⟨t, ht, ht'⟩ := hf (unop G) (set.mem_op.1 hG) h.unop,
exact ⟨t.op, quiver.hom.unop_inj ht, λ y hy,
quiver.hom.unop_inj (ht' _ (quiver.hom.op_inj hy))⟩ },
{ refine (is_iso_unop_iff _).1 (h𝒢 _ (λ G hG h, _)),
obtain ⟨t, ht, ht'⟩ := hf (op G) (set.op_mem_op.2 hG) h.op,
refine ⟨t.unop, quiver.hom.op_inj ht, λ y hy, quiver.hom.op_inj (ht' _ _)⟩,
exact quiver.hom.unop_inj (by simpa only using hy) }
end
lemma is_detecting_unop_iff (𝒢 : set Cᵒᵖ) : is_detecting 𝒢.unop ↔ is_codetecting 𝒢 :=
by rw [← is_codetecting_op_iff, set.unop_op]
lemma is_codetecting_unop_iff {𝒢 : set Cᵒᵖ} : is_codetecting 𝒢.unop ↔ is_detecting 𝒢 :=
by rw [← is_detecting_op_iff, set.unop_op]
end dual
lemma is_detecting.is_separating [has_equalizers C] {𝒢 : set C} (h𝒢 : is_detecting 𝒢) :
is_separating 𝒢 :=
λ X Y f g hfg,
have is_iso (equalizer.ι f g), from h𝒢 _ (λ G hG h, equalizer.exists_unique _ (hfg _ hG _)),
by exactI eq_of_epi_equalizer
section
lemma is_codetecting.is_coseparating [has_coequalizers C] {𝒢 : set C} :
is_codetecting 𝒢 → is_coseparating 𝒢 :=
by simpa only [← is_separating_op_iff, ← is_detecting_op_iff] using is_detecting.is_separating
end
lemma is_separating.is_detecting [balanced C] {𝒢 : set C} (h𝒢 : is_separating 𝒢) :
is_detecting 𝒢 :=
begin
intros X Y f hf,
refine (is_iso_iff_mono_and_epi _).2 ⟨⟨λ Z g h hgh, h𝒢 _ _ (λ G hG i, _)⟩, ⟨λ Z g h hgh, _⟩⟩,
{ obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f),
rw [ht (i ≫ g) (category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ category.assoc _ _ _)] },
{ refine h𝒢 _ _ (λ G hG i, _),
obtain ⟨t, rfl, -⟩ := hf G hG i,
rw [category.assoc, hgh, category.assoc] }
end
section
local attribute [instance] balanced_opposite
lemma is_coseparating.is_codetecting [balanced C] {𝒢 : set C} :
is_coseparating 𝒢 → is_codetecting 𝒢 :=
by simpa only [← is_detecting_op_iff, ← is_separating_op_iff] using is_separating.is_detecting
end
lemma is_detecting_iff_is_separating [has_equalizers C] [balanced C] (𝒢 : set C) :
is_detecting 𝒢 ↔ is_separating 𝒢 :=
⟨is_detecting.is_separating, is_separating.is_detecting⟩
lemma is_codetecting_iff_is_coseparating [has_coequalizers C] [balanced C] {𝒢 : set C} :
is_codetecting 𝒢 ↔ is_coseparating 𝒢 :=
⟨is_codetecting.is_coseparating, is_coseparating.is_codetecting⟩
section mono
lemma is_separating.mono {𝒢 : set C} (h𝒢 : is_separating 𝒢) {ℋ : set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
is_separating ℋ :=
λ X Y f g hfg, h𝒢 _ _ $ λ G hG h, hfg _ (h𝒢ℋ hG) _
lemma is_coseparating.mono {𝒢 : set C} (h𝒢 : is_coseparating 𝒢) {ℋ : set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
is_coseparating ℋ :=
λ X Y f g hfg, h𝒢 _ _ $ λ G hG h, hfg _ (h𝒢ℋ hG) _
lemma is_detecting.mono {𝒢 : set C} (h𝒢 : is_detecting 𝒢) {ℋ : set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
is_detecting ℋ :=
λ X Y f hf, h𝒢 _ $ λ G hG h, hf _ (h𝒢ℋ hG) _
lemma is_codetecting.mono {𝒢 : set C} (h𝒢 : is_codetecting 𝒢) {ℋ : set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
is_codetecting ℋ :=
λ X Y f hf, h𝒢 _ $ λ G hG h, hf _ (h𝒢ℋ hG) _
end mono
section empty
lemma thin_of_is_separating_empty (h : is_separating (∅ : set C)) : quiver.is_thin C :=
λ _ _, ⟨λ f g, h _ _ $ λ G, false.elim⟩
lemma is_separating_empty_of_thin [quiver.is_thin C] : is_separating (∅ : set C) :=
λ X Y f g hfg, subsingleton.elim _ _
lemma thin_of_is_coseparating_empty (h : is_coseparating (∅ : set C)) : quiver.is_thin C :=
λ _ _, ⟨λ f g, h _ _ $ λ G, false.elim⟩
lemma is_coseparating_empty_of_thin [quiver.is_thin C] :
is_coseparating (∅ : set C) :=
λ X Y f g hfg, subsingleton.elim _ _
lemma groupoid_of_is_detecting_empty (h : is_detecting (∅ : set C)) {X Y : C} (f : X ⟶ Y) :
is_iso f :=
h _ $ λ G, false.elim
lemma is_detecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), is_iso f] :
is_detecting (∅ : set C) :=
λ X Y f hf, infer_instance
lemma groupoid_of_is_codetecting_empty (h : is_codetecting (∅ : set C)) {X Y : C} (f : X ⟶ Y) :
is_iso f :=
h _ $ λ G, false.elim
lemma is_codetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), is_iso f] :
is_codetecting (∅ : set C) :=
λ X Y f hf, infer_instance
end empty
lemma is_separating_iff_epi (𝒢 : set C)
[Π (A : C), has_coproduct (λ f : Σ G : 𝒢, (G : C) ⟶ A, (f.1 : C))] :
is_separating 𝒢 ↔ ∀ A : C, epi (sigma.desc (@sigma.snd 𝒢 (λ G, (G : C) ⟶ A))) :=
begin
refine ⟨λ h A, ⟨λ Z u v huv, h _ _ (λ G hG f, _)⟩, λ h X Y f g hh, _⟩,
{ simpa using (sigma.ι (λ f : Σ G : 𝒢, (G : C) ⟶ A, (f.1 : C)) ⟨⟨G, hG⟩, f⟩) ≫= huv },
{ haveI := h X,
refine (cancel_epi (sigma.desc (@sigma.snd 𝒢 (λ G, (G : C) ⟶ X)))).1 (colimit.hom_ext (λ j, _)),
simpa using hh j.as.1.1 j.as.1.2 j.as.2 }
end
lemma is_coseparating_iff_mono (𝒢 : set C)
[Π (A : C), has_product (λ f : Σ G : 𝒢, A ⟶ (G : C), (f.1 : C))] :
is_coseparating 𝒢 ↔ ∀ A : C, mono (pi.lift (@sigma.snd 𝒢 (λ G, A ⟶ (G : C)))) :=
begin
refine ⟨λ h A, ⟨λ Z u v huv, h _ _ (λ G hG f, _)⟩, λ h X Y f g hh, _⟩,
{ simpa using huv =≫ (pi.π (λ f : Σ G : 𝒢, A ⟶ (G : C), (f.1 : C)) ⟨⟨G, hG⟩, f⟩) },
{ haveI := h Y,
refine (cancel_mono (pi.lift (@sigma.snd 𝒢 (λ G, Y ⟶ (G : C))))).1 (limit.hom_ext (λ j, _)),
simpa using hh j.as.1.1 j.as.1.2 j.as.2 }
end
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a complete well-powered
category with a small coseparating set has an initial object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already cocomplete,
see `has_colimits_of_has_limits_of_is_coseparating`. -/
lemma has_initial_of_is_coseparating [well_powered C] [has_limits C] {𝒢 : set C} [small.{v₁} 𝒢]
(h𝒢 : is_coseparating 𝒢) : has_initial C :=
begin
haveI := has_products_of_shape_of_small C 𝒢,
haveI := λ A, has_products_of_shape_of_small.{v₁} C (Σ G : 𝒢, A ⟶ (G : C)),
letI := complete_lattice_of_complete_semilattice_Inf (subobject (pi_obj (coe : 𝒢 → C))),
suffices : ∀ A : C, unique (((⊥ : subobject (pi_obj (coe : 𝒢 → C))) : C) ⟶ A),
{ exactI has_initial_of_unique ((⊥ : subobject (pi_obj (coe : 𝒢 → C))) : C) },
refine λ A, ⟨⟨_⟩, λ f, _⟩,
{ let s := pi.lift (λ f : Σ G : 𝒢, A ⟶ (G : C), id (pi.π (coe : 𝒢 → C)) f.1),
let t := pi.lift (@sigma.snd 𝒢 (λ G, A ⟶ (G : C))),
haveI : mono t := (is_coseparating_iff_mono 𝒢).1 h𝒢 A,
exact subobject.of_le_mk _ (pullback.fst : pullback s t ⟶ _) bot_le ≫ pullback.snd },
{ generalize : default = g,
suffices : is_split_epi (equalizer.ι f g),
{ exactI eq_of_epi_equalizer },
exact is_split_epi.mk' ⟨subobject.of_le_mk _ (equalizer.ι f g ≫ subobject.arrow _)
bot_le, by { ext, simp }⟩ }
end
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a cocomplete well-copowered
category with a small separating set has a terminal object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already complete, see
`has_limits_of_has_colimits_of_is_separating`. -/
lemma has_terminal_of_is_separating [well_powered Cᵒᵖ] [has_colimits C] {𝒢 : set C} [small.{v₁} 𝒢]
(h𝒢 : is_separating 𝒢) : has_terminal C :=
begin
haveI : small.{v₁} 𝒢.op := small_of_injective (set.op_equiv_self 𝒢).injective,
haveI : has_initial Cᵒᵖ := has_initial_of_is_coseparating ((is_coseparating_op_iff _).2 h𝒢),
exact has_terminal_of_has_initial_op
end
section well_powered
namespace subobject
lemma eq_of_le_of_is_detecting {𝒢 : set C} (h𝒢 : is_detecting 𝒢) {X : C} (P Q : subobject X)
(h₁ : P ≤ Q) (h₂ : ∀ (G ∈ 𝒢) {f : G ⟶ X}, Q.factors f → P.factors f) : P = Q :=
begin
suffices : is_iso (of_le _ _ h₁),
{ exactI le_antisymm h₁ (le_of_comm (inv (of_le _ _ h₁)) (by simp)) },
refine h𝒢 _ (λ G hG f, _),
have : P.factors (f ≫ Q.arrow) := h₂ _ hG ((factors_iff _ _).2 ⟨_, rfl⟩),
refine ⟨factor_thru _ _ this, _, λ g (hg : g ≫ _ = f), _⟩,
{ simp only [← cancel_mono Q.arrow, category.assoc, of_le_arrow, factor_thru_arrow] },
{ simp only [← cancel_mono (subobject.of_le _ _ h₁), ← cancel_mono Q.arrow, hg,
category.assoc, of_le_arrow, factor_thru_arrow] }
end
lemma inf_eq_of_is_detecting [has_pullbacks C] {𝒢 : set C} (h𝒢 : is_detecting 𝒢) {X : C}
(P Q : subobject X) (h : ∀ (G ∈ 𝒢) {f : G ⟶ X}, P.factors f → Q.factors f) : P ⊓ Q = P :=
eq_of_le_of_is_detecting h𝒢 _ _ _root_.inf_le_left (λ G hG f hf, (inf_factors _).2 ⟨hf, h _ hG hf⟩)
lemma eq_of_is_detecting [has_pullbacks C] {𝒢 : set C} (h𝒢 : is_detecting 𝒢) {X : C}
(P Q : subobject X) (h : ∀ (G ∈ 𝒢) {f : G ⟶ X}, P.factors f ↔ Q.factors f) : P = Q :=
calc P = P ⊓ Q : eq.symm $ inf_eq_of_is_detecting h𝒢 _ _ $ λ G hG f hf, (h G hG).1 hf
... = Q ⊓ P : inf_comm
... = Q : inf_eq_of_is_detecting h𝒢 _ _ $ λ G hG f hf, (h G hG).2 hf
end subobject
/-- A category with pullbacks and a small detecting set is well-powered. -/
lemma well_powered_of_is_detecting [has_pullbacks C] {𝒢 : set C} [small.{v₁} 𝒢]
(h𝒢 : is_detecting 𝒢) : well_powered C :=
⟨λ X, @small_of_injective _ _ _ (λ P : subobject X, { f : Σ G : 𝒢, G.1 ⟶ X | P.factors f.2 }) $
λ P Q h, subobject.eq_of_is_detecting h𝒢 _ _ (by simpa [set.ext_iff] using h)⟩
end well_powered
namespace structured_arrow
variables (S : D) (T : C ⥤ D)
lemma is_coseparating_proj_preimage {𝒢 : set C} (h𝒢 : is_coseparating 𝒢) :
is_coseparating ((proj S T).obj ⁻¹' 𝒢) :=
begin
refine λ X Y f g hfg, ext _ _ (h𝒢 _ _ (λ G hG h, _)),
exact congr_arg comma_morphism.right (hfg (mk (Y.hom ≫ T.map h)) hG (hom_mk h rfl))
end
end structured_arrow
namespace costructured_arrow
variables (S : C ⥤ D) (T : D)
lemma is_separating_proj_preimage {𝒢 : set C} (h𝒢 : is_separating 𝒢) :
is_separating ((proj S T).obj ⁻¹' 𝒢) :=
begin
refine λ X Y f g hfg, ext _ _ (h𝒢 _ _ (λ G hG h, _)),
convert congr_arg comma_morphism.left (hfg (mk (S.map h ≫ X.hom)) hG (hom_mk h rfl))
end
end costructured_arrow
/-- We say that `G` is a separator if the functor `C(G, -)` is faithful. -/
def is_separator (G : C) : Prop :=
is_separating ({G} : set C)
/-- We say that `G` is a coseparator if the functor `C(-, G)` is faithful. -/
def is_coseparator (G : C) : Prop :=
is_coseparating ({G} : set C)
/-- We say that `G` is a detector if the functor `C(G, -)` reflects isomorphisms. -/
def is_detector (G : C) : Prop :=
is_detecting ({G} : set C)
/-- We say that `G` is a codetector if the functor `C(-, G)` reflects isomorphisms. -/
def is_codetector (G : C) : Prop :=
is_codetecting ({G} : set C)
section dual
lemma is_separator_op_iff (G : C) : is_separator (op G) ↔ is_coseparator G :=
by rw [is_separator, is_coseparator, ← is_separating_op_iff, set.singleton_op]
lemma is_coseparator_op_iff (G : C) : is_coseparator (op G) ↔ is_separator G :=
by rw [is_separator, is_coseparator, ← is_coseparating_op_iff, set.singleton_op]
lemma is_coseparator_unop_iff (G : Cᵒᵖ) : is_coseparator (unop G) ↔ is_separator G :=
by rw [is_separator, is_coseparator, ← is_coseparating_unop_iff, set.singleton_unop]
lemma is_separator_unop_iff (G : Cᵒᵖ) : is_separator (unop G) ↔ is_coseparator G :=
by rw [is_separator, is_coseparator, ← is_separating_unop_iff, set.singleton_unop]
lemma is_detector_op_iff (G : C) : is_detector (op G) ↔ is_codetector G :=
by rw [is_detector, is_codetector, ← is_detecting_op_iff, set.singleton_op]
lemma is_codetector_op_iff (G : C) : is_codetector (op G) ↔ is_detector G :=
by rw [is_detector, is_codetector, ← is_codetecting_op_iff, set.singleton_op]
lemma is_codetector_unop_iff (G : Cᵒᵖ) : is_codetector (unop G) ↔ is_detector G :=
by rw [is_detector, is_codetector, ← is_codetecting_unop_iff, set.singleton_unop]
lemma is_detector_unop_iff (G : Cᵒᵖ) : is_detector (unop G) ↔ is_codetector G :=
by rw [is_detector, is_codetector, ← is_detecting_unop_iff, set.singleton_unop]
end dual
lemma is_detector.is_separator [has_equalizers C] {G : C} : is_detector G → is_separator G :=
is_detecting.is_separating
lemma is_codetector.is_coseparator [has_coequalizers C] {G : C} :
is_codetector G → is_coseparator G :=
is_codetecting.is_coseparating
lemma is_separator.is_detector [balanced C] {G : C} : is_separator G → is_detector G :=
is_separating.is_detecting
lemma is_cospearator.is_codetector [balanced C] {G : C} : is_coseparator G → is_codetector G :=
is_coseparating.is_codetecting
lemma is_separator_def (G : C) :
is_separator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
⟨λ hG X Y f g hfg, hG _ _ $ λ H hH h, by { obtain rfl := set.mem_singleton_iff.1 hH, exact hfg h },
λ hG X Y f g hfg, hG _ _ $ λ h, hfg _ (set.mem_singleton _) _⟩
lemma is_separator.def {G : C} :
is_separator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
(is_separator_def _).1
lemma is_coseparator_def (G : C) :
is_coseparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
⟨λ hG X Y f g hfg, hG _ _ $ λ H hH h, by { obtain rfl := set.mem_singleton_iff.1 hH, exact hfg h },
λ hG X Y f g hfg, hG _ _ $ λ h, hfg _ (set.mem_singleton _) _⟩
lemma is_coseparator.def {G : C} :
is_coseparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
(is_coseparator_def _).1
lemma is_detector_def (G : C) :
is_detector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → is_iso f :=
⟨λ hG X Y f hf, hG _ $ λ H hH h, by { obtain rfl := set.mem_singleton_iff.1 hH, exact hf h },
λ hG X Y f hf, hG _ $ λ h, hf _ (set.mem_singleton _) _⟩
lemma is_detector.def {G : C} :
is_detector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → is_iso f :=
(is_detector_def _).1
lemma is_codetector_def (G : C) :
is_codetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → is_iso f :=
⟨λ hG X Y f hf, hG _ $ λ H hH h, by { obtain rfl := set.mem_singleton_iff.1 hH, exact hf h },
λ hG X Y f hf, hG _ $ λ h, hf _ (set.mem_singleton _) _⟩
lemma is_codetector.def {G : C} :
is_codetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → is_iso f :=
(is_codetector_def _).1
lemma is_separator_iff_faithful_coyoneda_obj (G : C) :
is_separator G ↔ faithful (coyoneda.obj (op G)) :=
⟨λ hG, ⟨λ X Y f g hfg, hG.def _ _ (congr_fun hfg)⟩,
λ h, (is_separator_def _).2 $ λ X Y f g hfg,
by exactI (coyoneda.obj (op G)).map_injective (funext hfg)⟩
lemma is_coseparator_iff_faithful_yoneda_obj (G : C) :
is_coseparator G ↔ faithful (yoneda.obj G) :=
⟨λ hG, ⟨λ X Y f g hfg, quiver.hom.unop_inj (hG.def _ _ (congr_fun hfg))⟩,
λ h, (is_coseparator_def _).2 $ λ X Y f g hfg, quiver.hom.op_inj $
by exactI (yoneda.obj G).map_injective (funext hfg)⟩
lemma is_separator_iff_epi (G : C) [Π A : C, has_coproduct (λ (f : G ⟶ A), G)] :
is_separator G ↔ ∀ (A : C), epi (sigma.desc (λ (f : G ⟶ A), f)) :=
begin
rw is_separator_def,
refine ⟨λ h A, ⟨λ Z u v huv, h _ _ (λ i, _)⟩, λ h X Y f g hh, _⟩,
{ simpa using (sigma.ι _ i) ≫= huv },
{ haveI := h X,
refine (cancel_epi (sigma.desc (λ (f : G ⟶ X), f))).1 (colimit.hom_ext (λ j, _)),
simpa using hh j.as }
end
lemma is_coseparator_iff_mono (G : C) [Π A : C, has_product (λ (f : A ⟶ G), G)] :
is_coseparator G ↔ ∀ (A : C), mono (pi.lift (λ (f : A ⟶ G), f)) :=
begin
rw is_coseparator_def,
refine ⟨λ h A, ⟨λ Z u v huv, h _ _ (λ i, _)⟩, λ h X Y f g hh, _⟩,
{ simpa using huv =≫ (pi.π _ i) },
{ haveI := h Y,
refine (cancel_mono (pi.lift (λ (f : Y ⟶ G), f))).1 (limit.hom_ext (λ j, _)),
simpa using hh j.as }
end
section zero_morphisms
variables [has_zero_morphisms C]
lemma is_separator_coprod (G H : C) [has_binary_coproduct G H] :
is_separator (G ⨿ H) ↔ is_separating ({G, H} : set C) :=
begin
refine ⟨λ h X Y u v huv, _, λ h, (is_separator_def _).2 (λ X Y u v huv, h _ _ (λ Z hZ g, _))⟩,
{ refine h.def _ _ (λ g, coprod.hom_ext _ _),
{ simpa using huv G (by simp) (coprod.inl ≫ g) },
{ simpa using huv H (by simp) (coprod.inr ≫ g) } },
{ simp only [set.mem_insert_iff, set.mem_singleton_iff] at hZ,
unfreezingI { rcases hZ with rfl|rfl },
{ simpa using coprod.inl ≫= huv (coprod.desc g 0) },
{ simpa using coprod.inr ≫= huv (coprod.desc 0 g) } }
end
lemma is_separator_coprod_of_is_separator_left (G H : C) [has_binary_coproduct G H]
(hG : is_separator G) : is_separator (G ⨿ H) :=
(is_separator_coprod _ _).2 $ is_separating.mono hG $ by simp
lemma is_separator_coprod_of_is_separator_right (G H : C) [has_binary_coproduct G H]
(hH : is_separator H) : is_separator (G ⨿ H) :=
(is_separator_coprod _ _).2 $ is_separating.mono hH $ by simp
lemma is_separator_sigma {β : Type w} (f : β → C) [has_coproduct f] :
is_separator (∐ f) ↔ is_separating (set.range f) :=
begin
refine ⟨λ h X Y u v huv, _, λ h, (is_separator_def _).2 (λ X Y u v huv, h _ _ (λ Z hZ g, _))⟩,
{ refine h.def _ _ (λ g, colimit.hom_ext (λ b, _)),
simpa using huv (f b.as) (by simp) (colimit.ι (discrete.functor f) _ ≫ g) },
{ obtain ⟨b, rfl⟩ := set.mem_range.1 hZ,
classical,
simpa using sigma.ι f b ≫= huv (sigma.desc (pi.single b g)) }
end
lemma is_separator_sigma_of_is_separator {β : Type w} (f : β → C) [has_coproduct f]
(b : β) (hb : is_separator (f b)) : is_separator (∐ f) :=
(is_separator_sigma _).2 $ is_separating.mono hb $ by simp
lemma is_coseparator_prod (G H : C) [has_binary_product G H] :
is_coseparator (G ⨯ H) ↔ is_coseparating ({G, H} : set C) :=
begin
refine ⟨λ h X Y u v huv, _, λ h, (is_coseparator_def _).2 (λ X Y u v huv, h _ _ (λ Z hZ g, _))⟩,
{ refine h.def _ _ (λ g, prod.hom_ext _ _),
{ simpa using huv G (by simp) (g ≫ limits.prod.fst) },
{ simpa using huv H (by simp) (g ≫ limits.prod.snd) } },
{ simp only [set.mem_insert_iff, set.mem_singleton_iff] at hZ,
unfreezingI { rcases hZ with rfl|rfl },
{ simpa using huv (prod.lift g 0) =≫ limits.prod.fst },
{ simpa using huv (prod.lift 0 g) =≫ limits.prod.snd } }
end
lemma is_coseparator_prod_of_is_coseparator_left (G H : C) [has_binary_product G H]
(hG : is_coseparator G) : is_coseparator (G ⨯ H) :=
(is_coseparator_prod _ _).2 $ is_coseparating.mono hG $ by simp
lemma is_coseparator_prod_of_is_coseparator_right (G H : C) [has_binary_product G H]
(hH : is_coseparator H) : is_coseparator (G ⨯ H) :=
(is_coseparator_prod _ _).2 $ is_coseparating.mono hH $ by simp
lemma is_coseparator_pi {β : Type w} (f : β → C) [has_product f] :
is_coseparator (∏ f) ↔ is_coseparating (set.range f) :=
begin
refine ⟨λ h X Y u v huv, _, λ h, (is_coseparator_def _).2 (λ X Y u v huv, h _ _ (λ Z hZ g, _))⟩,
{ refine h.def _ _ (λ g, limit.hom_ext (λ b, _)),
simpa using huv (f b.as) (by simp) (g ≫ limit.π (discrete.functor f) _ ) },
{ obtain ⟨b, rfl⟩ := set.mem_range.1 hZ,
classical,
simpa using huv (pi.lift (pi.single b g)) =≫ pi.π f b }
end
lemma is_coseparator_pi_of_is_coseparator {β : Type w} (f : β → C) [has_product f]
(b : β) (hb : is_coseparator (f b)) : is_coseparator (∏ f) :=
(is_coseparator_pi _).2 $ is_coseparating.mono hb $ by simp
end zero_morphisms
lemma is_detector_iff_reflects_isomorphisms_coyoneda_obj (G : C) :
is_detector G ↔ reflects_isomorphisms (coyoneda.obj (op G)) :=
begin
refine ⟨λ hG, ⟨λ X Y f hf, hG.def _ (λ h, _)⟩, λ h, (is_detector_def _).2 (λ X Y f hf, _)⟩,
{ rw [is_iso_iff_bijective, function.bijective_iff_exists_unique] at hf,
exact hf h },
{ suffices : is_iso ((coyoneda.obj (op G)).map f),
{ exactI @is_iso_of_reflects_iso _ _ _ _ _ _ _ (coyoneda.obj (op G)) _ h },
rwa [is_iso_iff_bijective, function.bijective_iff_exists_unique] }
end
lemma is_codetector_iff_reflects_isomorphisms_yoneda_obj (G : C) :
is_codetector G ↔ reflects_isomorphisms (yoneda.obj G) :=
begin
refine ⟨λ hG, ⟨λ X Y f hf, _ ⟩, λ h, (is_codetector_def _).2 (λ X Y f hf, _)⟩,
{ refine (is_iso_unop_iff _).1 (hG.def _ _),
rwa [is_iso_iff_bijective, function.bijective_iff_exists_unique] at hf },
{ rw ← is_iso_op_iff,
suffices : is_iso ((yoneda.obj G).map f.op),
{ exactI @is_iso_of_reflects_iso _ _ _ _ _ _ _ (yoneda.obj G) _ h },
rwa [is_iso_iff_bijective, function.bijective_iff_exists_unique] }
end
lemma well_powered_of_is_detector [has_pullbacks C] (G : C) (hG : is_detector G) :
well_powered C :=
well_powered_of_is_detecting hG
end category_theory
|
bc688af34f1f48cbb894da054646376829214fd5 | bdc27058d2df65f1c05b3dd4ff23a30af9332a2b | /src/euclid.lean | be8778e783a57f47834867a2e7a2f43c36f1c673 | [] | no_license | bakerjd99/leanteach2020 | 19e3dda4167f7bb8785fe0e2fe762a9c53a9214d | 2160909674f3aec475eabb51df73af7fa1d91c65 | refs/heads/master | 1,668,724,511,289 | 1,594,407,424,000 | 1,594,407,424,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,748 | lean | /- Formalizing Euclid's Axioms.-/
import tactic
import data.real.basic -- imports ℝ
noncomputable theory
open_locale classical
-- # Postulated types and relations
----------------------------------
constant Point : Type
constant Line : Type
constant lies_on : Point → Line → Prop
constant between : Point → Point → Point → Prop -- (between a b c) means "b is in between a and c"
constant congruent {A : Type} : A → A → Prop -- variable A is implicit. Lean will figure it out.
-- Missing definition that Euclid needed but did not include:
constant distance : Point → Point → ℝ
-- Notation
-----------
local infix ` ≃ `:55 := congruent -- typed as \ equiv
-- Missing Axiom(s)
-------------------
axiom distance_not_neg {p1 p2 : Point} : 0 ≤ distance p1 p2
axiom distance_pos {p1 p2 : Point} : p1 ≠ p2 ↔ 0 < distance p1 p2
@[instance] axiom distance_is_symm_op : is_symm_op Point ℝ distance
@[simp] axiom distance_zero_segment {p : Point} : distance p p = 0
@[symm] lemma distance_is_symm : ∀ (p1 p2 : Point),
distance p1 p2 = distance p2 p1 := distance_is_symm_op.symm_op
axiom distance_between {a b c : Point} : between a b c ↔ distance a b + distance b c = distance a c
axiom between_refl_left (a b : Point) : between a a b
axiom between_refl_right (a b : Point) : between a b b
@[symm] axiom between_symm {x y z : Point} : between x y z → between z y x
-- Congruence is an equivalence relation.
@[instance] axiom cong_is_equiv {A : Type} : is_equiv A (≃)
-- TODO: The proof for the following lemmas follows from cong_is_equiv.
@[refl] lemma cong_refl {A : Type} : ∀ a : A, a ≃ a :=
cong_is_equiv.to_is_preorder.to_is_refl.refl
lemma cong_symm {A : Type} : ∀ (a b : A), a ≃ b → b ≃ a :=
cong_is_equiv.to_is_symm.symm
@[trans] lemma cong_trans {A : Type} : ∀ (a b c : A), a ≃ b → b ≃ c → a ≃ c :=
cong_is_equiv.to_is_preorder.to_is_trans.trans
lemma cong_equiv {A : Type} : equivalence (@congruent A) :=
-- The @ makes implicit arguments explicit.
mk_equivalence congruent cong_refl cong_symm cong_trans
-- #Postulate I
---------------
-- Given two distinct Points, we can construct a unique Line passing
-- through them.
constant line_of_points (p₁ p₂ : Point) : p₁ ≠ p₂ → Line
axiom line_exists (p₁ p₂ : Point) (h : p₁ ≠ p₂) :
let l : Line := line_of_points p₁ p₂ h in
lies_on p₁ l ∧ lies_on p₂ l
structure Segment: Type :=
(p1 p2 : Point)
local infix `⬝`:56 := Segment.mk -- typed as \ cdot
-- # Helper functions
---------------------
-- condition for 3 terms being distict.
def distinct {A : Type} (a b c : A) := a ≠ b ∧ b ≠ c ∧ c ≠ a
-- length of a segment
def length (a : Segment) := distance a.p1 a.p2
lemma distinct_swap (a b c : Point) : distinct a b c → distinct b c a :=
begin
rintros ⟨h₁, h₂, h₃⟩,
rw distinct,
repeat {cc},
end
axiom distance_congruent {a b c d : Point} :
a⬝b ≃ c⬝d ↔ distance a b = distance c d
-- Missing axiom:
-----------------
axiom segment_symm {p1 p2 : Point} : p1⬝p2 = p2⬝p1
axiom zero_segment {s : Segment} {p : Point} : s ≃ p⬝p → s.p1 = s.p2
def line_of_segment (s : Segment) : s.p1 ≠ s.p2 → Line := line_of_points s.p1 s.p2
def points_of_segment (s : Segment) : set Point := {c : Point | between s.p1 c s.p2}
-- Postulate II
---------------
-- Given two segments, we can find a Point to extend the first Segment
-- by the lenth of the Second.
constant extended_segment (ab cd : Segment) : ab.p1 ≠ ab.p2 → Point
axiom extend (ab cd : Segment) (h : ab.p1 ≠ ab.p2) :
let p : Point := extended_segment ab cd h in
lies_on p (line_of_segment ab h)
∧ between ab.p1 ab.p2 p
∧ cd ≃ ⟨ab.p2, p⟩
-- A Circle is constructed by specifying two Points.
-- Note: Euclid says that the two points should be distinct. But we choose not to make this
-- a strict requirement for defining a Circle.
structure Circle: Type :=
(center outer : Point)
def radius_segment (c : Circle) : Segment := {p1 := c.center, p2 := c.outer}
def radius (c : Circle) : ℝ :=
let r := radius_segment c in distance r.1 r.2
def circumference (c : Circle) : set Point := {x : Point | radius_segment c ≃ ⟨c.center, x⟩}
-- A Ray is constructed by specifying two Points.
structure Ray: Type :=
(base ext : Point)
def line_of_ray (r : Ray) : r.base ≠ r.ext → Line := line_of_points r.base r.ext
def points_of_ray (r : Ray) (ne : r.base ≠ r.ext) : set Point :=
points_of_segment ⟨r.base, r.ext⟩ ∪ {c | lies_on c (line_of_ray r ne) ∧ between r.base r.ext c}
-- Two Rays are opposite if they are distict, have the same base Point
-- and the same Line.
def opposite_rays (r1 r2 : Ray) (h1 : r1.base ≠ r1.ext) (h2 : r2.base ≠ r2.ext) : Prop :=
(r1.base = r2.base) ∧ (r1 ≠ r2) ∧ (line_of_ray r1 h1 = line_of_ray r2 h2)
-- An Angle is constructed by specifying two Rays based at a common
-- Point and a proof that the Rays are not opposite.
structure Angle: Type :=
(r1 r2 : Ray)
(eq_base : r1.base = r2.base)
(not_opposite (h1 : r1.base ≠ r1.ext) (h2 : r2.base ≠ r2.ext) :
¬ opposite_rays r1 r2 h1 h2)
-- A Triangle is constructed by specifying three Points.
structure Triangle: Type :=
(p1 p2 p3 : Point)
def angle_of_points (a b c : Point) (different : distinct a b c) : Angle :=
let r1 := Ray.mk b a in
let r2 := Ray.mk b a in
let same_base : r1.base = r2.base := rfl in
let not_opposite : ∀ (h1 : r1.base ≠ r1.ext) (h2 : r2.base ≠ r2.ext),
¬opposite_rays r1 r2 h1 h2 := sorry in
⟨r1, r2, same_base, not_opposite⟩
-- For every triangle, we get can define three Segments (its sides).
def sides_of_triangle (t : Triangle): Segment × Segment × Segment :=
(⟨t.p1, t.p2⟩, ⟨t.p2, t.p3⟩, ⟨t.p3, t.p1⟩)
def angles_of_triangle (t : Triangle) (different : distinct t.p1 t.p2 t.p3): vector Angle 3 :=
let a123 := angle_of_points t.p1 t.p2 t.p3 different in
let dif2 : distinct t.p2 t.p3 t.p1 :=
begin apply distinct_swap, exact different, end in
let a231 := angle_of_points t.p2 t.p3 t.p1 dif2 in
let dif3 : distinct t.p3 t.p1 t.p2 :=
begin apply distinct_swap, exact dif2, end in
let a312 := angle_of_points t.p3 t.p1 t.p2 dif3 in
⟨[a123, a231, a312], rfl⟩
def is_equilateral (t : Triangle) : Prop :=
let sides := sides_of_triangle t in
sides.1 ≃ sides.2.1 ∧ sides.2.1 ≃ sides.2.2
lemma equilateral_triangle_all_sides_equal (t : Triangle) :
let sides := sides_of_triangle t in
is_equilateral t → sides.1 ≃ sides.2.2 :=
begin
intros,
cases a with h₁ h₂,
transitivity,
repeat {assumption},
end
def is_right_angle : Angle → Prop := sorry
def exists_intersection: Line → Line → Prop := sorry
def is_parallel : Line → Line → Prop := sorry
axiom right_angle (a1 a2 : Angle) : is_right_angle a1 ∧ is_right_angle a2 → a1 ≃ a2
axiom parallel (l1 l2 : Line) : ¬ exists_intersection l1 l2 → is_parallel l1 l2
-- does not mean equadistant
-- constant lies_on : Point → Line → Prop
-- axiom intersect (l1 l2 l3: Line) : ((make_angle l1 l3) + (make_angle l2 l3)) < (rAngle + rAngle) → on_side (Sides_of_line l3).2 (intersection l1 l2)
-- if the angle beteween two lines is less than 2 right angles, the lines meet on that side
-- # Euclid's missing axiom(s)
------------------------------
--If the sum of the radii of two circles is greater than the line joining their centers, then the two circles intersect
--https://mathcs.clarku.edu/~djoyce/java/elements/bookI/propI1.html
-- TODO: Find a reference for this. Or find a justification using Coordinate geometry.
constant circles_intersect {c₁ c₂ : Circle} :
distance c₁.center c₂.center ≤ radius c₁ + radius c₂
→ (abs (radius c₁ - radius c₂) ≤ distance c₁.center c₂.center)
→ Point
axiom circles_intersect' {c₁ c₂ : Circle}
(h₁ : radius c₁ + radius c₂ >= distance c₁.center c₂.center)
(h₂ : (abs (radius c₁ - radius c₂) <= distance c₁.center c₂.center)) :
let p : Point := circles_intersect h₁ h₂ in
p ∈ circumference c₁ ∧ p ∈ circumference c₂
def circle_interior (p : Point) (c : Circle) : Prop :=
distance c.center p < radius c
def circle_exterior (p : Point) (c : Circle) : Prop :=
radius c < distance c.center p
lemma center_in_circle {a b : Point} (ne : a ≠ b) :
let c : Circle := ⟨a, b⟩ in
circle_interior a c :=
begin
intros,
rwa [circle_interior, radius, radius_segment, distance_zero_segment, ← distance_pos],
end
lemma radius_on_circumference (a b : Point) :
let c : Circle := ⟨a, b⟩ in
b ∈ circumference c :=
begin
intros,
rw [circumference, radius_segment],
simp,
end
|
472b34c829ea94b2cb6c56c32215793de36be819 | 9a0b1b3a653ea926b03d1495fef64da1d14b3174 | /tidy/rewrite_search/tactic.lean | cb96c92b4de888b4c45d534c2f62376edbb6ddd2 | [
"Apache-2.0"
] | permissive | khoek/mathlib-tidy | 8623b27b4e04e7d598164e7eaf248610d58f768b | 866afa6ab597c47f1b72e8fe2b82b97fff5b980f | refs/heads/master | 1,585,598,975,772 | 1,538,659,544,000 | 1,538,659,544,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,073 | lean | -- Copyright (c) 2018 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Keeley Hoek, Scott Morrison
import .init
import .discovery
import tidy.lib.list
import tidy.lib.expr
open tactic
variables {α β γ δ : Type}
namespace tidy.rewrite_search
meta def try_search (cfg : rewrite_search_config α β γ δ) (prog : discovery.progress) (rs : list (expr × bool)) (eqn : sided_pair expr) : tactic (option string) := do
i ← try_mk_search_instance cfg prog rs eqn,
match i with
| none := return none
| some i := do
(i, result) ← i.search_until_solved,
match result with
| search_result.failure reason := fail reason
| search_result.success proof steps := do
exact proof,
some <$> i.explain proof steps
end
end
meta def rewrite_search_pair (cfg : rewrite_search_config α β γ δ) (prog : discovery.progress) (rs : list (expr × bool)) (eqn : sided_pair expr) := do
result ← try_search cfg prog rs eqn,
match result with
| some str := return str
| none := do
trace "\nError initialising rewrite_search instance, falling back to emergency config!",
result ← try_search (mk_fallback_config cfg) prog rs eqn,
match result with
| some str := return str
| none := fail "Could not initialise emergency rewrite_search instance!"
end
end
-- TODO If try_search fails due to a failure to init any of the tracer, metric, or strategy we try again
-- using the "fallback" default versions of all three of these. Instead we could be more thoughtful,
-- and try again only replacing the failing one of these with its respective fallback module version.
meta def collect_rw_lemmas (cfg : rewrite_search_config α β γ δ) (use_suggest_annotations : bool) (per : discovery.persistence) (extra_names : list name) (extra_rws : list (expr × bool)) : tactic (discovery.progress × list (expr × bool)) := do
let per := if cfg.help_me then discovery.persistence.try_everything else per,
(prog, rws) ← discovery.collect use_suggest_annotations per cfg.suggest extra_names,
hyp_rws ← discovery.rewrite_list_from_hyps,
let rws := rws ++ extra_rws ++ hyp_rws,
locs ← local_context,
rws ← rws.mmap $ discovery.inflate_rw locs,
return (prog, rws.join)
meta def rewrite_search_target (cfg : rewrite_search_config α β γ δ) (use_suggest_annotations : bool) (per : discovery.persistence) (extra_names : list name) (extra_rws : list (expr × bool)) : tactic string := do
t ← target,
if t.has_meta_var then
fail "rewrite_search is not suitable for goals containing metavariables"
else skip,
(prog, rws) ← collect_rw_lemmas cfg use_suggest_annotations per extra_names extra_rws,
if cfg.trace_rules then
do rs_strings ← pp_rules rws,
trace ("rewrite_search using:\n---\n" ++ (string.intercalate "\n" rs_strings) ++ "\n---")
else skip,
match t with
| `(%%lhs = %%rhs) := rewrite_search_pair cfg prog rws ⟨lhs, rhs⟩
| `(%%lhs ↔ %%rhs) := rewrite_search_pair cfg prog rws ⟨lhs, rhs⟩
| _ := fail "target is not an equation or iff"
end
private meta def add_simps : simp_lemmas → list name → tactic simp_lemmas
| s [] := return s
| s (n::ns) := do s' ← s.add_simp n, add_simps s' ns
private meta def add_expr (s : simp_lemmas) (u : list name) (e : expr) : tactic (simp_lemmas × list name) :=
do
let e := e.erase_annotations,
match e with
| expr.const n _ :=
(do b ← is_valid_simp_lemma_cnst n, guard b, s ← s.add_simp n, return (s, u))
<|>
(do eqns ← get_eqn_lemmas_for tt n, guard (eqns.length > 0), s ← add_simps s eqns, return (s, u))
<|>
(do env ← get_env, guard (env.is_projection n).is_some, return (s, n::u))
<|>
fail n
| _ :=
(do b ← is_valid_simp_lemma e, guard b, s ← s.add e, return (s, u))
<|>
fail e
end
meta def simp_search_target (cfg : rewrite_search_config α β γ δ) (use_suggest_annotations : bool) (per : discovery.persistence) (extra_names : list name) (extra_rws : list (expr × bool)) : tactic unit := do
t ← target,
(prog, rws) ← collect_rw_lemmas cfg use_suggest_annotations per extra_names extra_rws,
if cfg.trace_rules then
do rs_strings ← pp_rules rws,
trace ("simp_search using:\n---\n" ++ (string.intercalate "\n" rs_strings) ++ "\n---")
else skip,
(s, to_unfold) ← mk_simp_set ff [] [] >>= λ sset, rws.mfoldl (λ c e, add_expr c.1 c.2 e.1 <|> return c) sset,
(n, pf) ← simplify s to_unfold t {contextual := tt} `eq failed,
replace_target n pf >> try tactic.triv >> try (tactic.reflexivity reducible)
end tidy.rewrite_search
namespace tactic.interactive
open interactive
open tidy.rewrite_search tidy.rewrite_search.discovery.persistence
meta def rewrite_search (cfg : rewrite_search_config α β γ δ . pick_default_config) : tactic string :=
rewrite_search_target cfg tt try_everything [] []
meta def rewrite_search_with (rs : parse rw_rules) (cfg : rewrite_search_config α β γ δ . pick_default_config) : tactic string := do
extra_rws ← discovery.rewrite_list_from_rw_rules rs.rules,
rewrite_search_target cfg tt try_everything [] extra_rws
meta def rewrite_search_using (as : list name) (cfg : rewrite_search_config α β γ δ . pick_default_config) : tactic string := do
extra_names ← discovery.load_attr_list as,
rewrite_search_target cfg ff try_bundles extra_names []
-- @Scott should we still do this?
-- exprs ← close_under_apps exprs, -- TODO don't do this for everything, it's too expensive: only for specially marked lemmas
meta def simp_search (cfg : rewrite_search_config α β γ δ . pick_default_config) : tactic unit := do
simp_search_target cfg tt try_everything [] []
meta def simp_search_with (rs : parse rw_rules) (cfg : rewrite_search_config α β γ δ . pick_default_config) : tactic unit := do
extra_rws ← discovery.rewrite_list_from_rw_rules rs.rules,
simp_search_target cfg tt try_everything [] extra_rws
end tactic.interactive
|
27bc7669c0f6631a21f61aac9bcbd58eca823db3 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/calculus/inverse.lean | 1ac8f0ab6c3bdc595e52237de8b192ea4276ded6 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 32,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, Heather Macbeth, Sébastien Gouëzel
-/
import analysis.calculus.times_cont_diff
import analysis.normed_space.banach
import topology.local_homeomorph
import topology.metric_space.contracting
import tactic.ring_exp
/-!
# Inverse function theorem
In this file we prove the inverse function theorem. It says that if a map `f : E → F`
has an invertible strict derivative `f'` at `a`, then it is locally invertible,
and the inverse function has derivative `f' ⁻¹`.
We define `has_strict_deriv_at.to_local_homeomorph` that repacks a function `f`
with a `hf : has_strict_fderiv_at f f' a`, `f' : E ≃L[𝕜] F`, into a `local_homeomorph`.
The `to_fun` of this `local_homeomorph` is `defeq` to `f`, so one can apply theorems
about `local_homeomorph` to `hf.to_local_homeomorph f`, and get statements about `f`.
Then we define `has_strict_fderiv_at.local_inverse` to be the `inv_fun` of this `local_homeomorph`,
and prove two versions of the inverse function theorem:
* `has_strict_fderiv_at.to_local_inverse`: if `f` has an invertible derivative `f'` at `a` in the
strict sense (`hf`), then `hf.local_inverse f f' a` has derivative `f'.symm` at `f a` in the
strict sense;
* `has_strict_fderiv_at.to_local_left_inverse`: if `f` has an invertible derivative `f'` at `a` in
the strict sense and `g` is locally left inverse to `f` near `a`, then `g` has derivative
`f'.symm` at `f a` in the strict sense.
In the one-dimensional case we reformulate these theorems in terms of `has_strict_deriv_at` and
`f'⁻¹`.
We also reformulate the theorems in terms of `times_cont_diff`, to give that `C^k` (respectively,
smooth) inputs give `C^k` (smooth) inverses. These versions require that continuous
differentiability implies strict differentiability; this is false over a general field, true over
`ℝ` or `ℂ` and implemented here assuming `is_R_or_C 𝕂`.
Some related theorems, providing the derivative and higher regularity assuming that we already know
the inverse function, are formulated in `fderiv.lean`, `deriv.lean`, and `times_cont_diff.lean`.
## Notations
In the section about `approximates_linear_on` we introduce some `local notation` to make formulas
shorter:
* by `N` we denote `∥f'⁻¹∥`;
* by `g` we denote the auxiliary contracting map `x ↦ x + f'.symm (y - f x)` used to prove that
`{x | f x = y}` is nonempty.
## Tags
derivative, strictly differentiable, continuously differentiable, smooth, inverse function
-/
open function set filter metric
open_locale topological_space classical nnreal
noncomputable theory
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_group G] [normed_space 𝕜 G]
variables {G' : Type*} [normed_group G'] [normed_space 𝕜 G']
variables {ε : ℝ}
open asymptotics filter metric set
open continuous_linear_map (id)
/-!
### Non-linear maps close to affine maps
In this section we study a map `f` such that `∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥` on an open set
`s`, where `f' : E →L[𝕜] F` is a continuous linear map and `c` is suitably small. Maps of this type
behave like `f a + f' (x - a)` near each `a ∈ s`.
When `f'` is onto, we show that `f` is locally onto.
When `f'` is a continuous linear equiv, we show that `f` is a homeomorphism
between `s` and `f '' s`. More precisely, we define `approximates_linear_on.to_local_homeomorph` to
be a `local_homeomorph` with `to_fun = f`, `source = s`, and `target = f '' s`.
Maps of this type naturally appear in the proof of the inverse function theorem (see next section),
and `approximates_linear_on.to_local_homeomorph` will imply that the locally inverse function
exists.
We define this auxiliary notion to split the proof of the inverse function theorem into small
lemmas. This approach makes it possible
- to prove a lower estimate on the size of the domain of the inverse function;
- to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a
function `f : E × F → G` with estimates on `f x y₁ - f x y₂` but not on `f x₁ y - f x₂ y`.
-/
/-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`,
if `∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥` whenever `x, y ∈ s`.
This predicate is defined to facilitate the splitting of the inverse function theorem into small
lemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined
on a specific set. -/
def approximates_linear_on (f : E → F) (f' : E →L[𝕜] F) (s : set E) (c : ℝ≥0) : Prop :=
∀ (x ∈ s) (y ∈ s), ∥f x - f y - f' (x - y)∥ ≤ c * ∥x - y∥
namespace approximates_linear_on
variables [cs : complete_space E] {f : E → F}
/-! First we prove some properties of a function that `approximates_linear_on` a (not necessarily
invertible) continuous linear map. -/
section
variables {f' : E →L[𝕜] F} {s t : set E} {c c' : ℝ≥0}
theorem mono_num (hc : c ≤ c') (hf : approximates_linear_on f f' s c) :
approximates_linear_on f f' s c' :=
λ x hx y hy, le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc $ norm_nonneg _)
theorem mono_set (hst : s ⊆ t) (hf : approximates_linear_on f f' t c) :
approximates_linear_on f f' s c :=
λ x hx y hy, hf x (hst hx) y (hst hy)
lemma lipschitz_sub (hf : approximates_linear_on f f' s c) :
lipschitz_with c (λ x : s, f x - f' x) :=
begin
refine lipschitz_with.of_dist_le_mul (λ x y, _),
rw [dist_eq_norm, subtype.dist_eq, dist_eq_norm],
convert hf x x.2 y y.2 using 2,
rw [f'.map_sub], abel
end
protected lemma lipschitz (hf : approximates_linear_on f f' s c) :
lipschitz_with (nnnorm f' + c) (s.restrict f) :=
by simpa only [restrict_apply, add_sub_cancel'_right]
using (f'.lipschitz.restrict s).add hf.lipschitz_sub
protected lemma continuous (hf : approximates_linear_on f f' s c) :
continuous (s.restrict f) :=
hf.lipschitz.continuous
protected lemma continuous_on (hf : approximates_linear_on f f' s c) :
continuous_on f s :=
continuous_on_iff_continuous_restrict.2 hf.continuous
end
section locally_onto
/-!
We prove that a function which is linearly approximated by a continuous linear map with a nonlinear
right inverse is locally onto. This will apply to the case where the approximating map is a linear
equivalence, for the local inverse theorem, but also whenever the approximating map is onto,
by Banach's open mapping theorem. -/
include cs
variables {s : set E} {c : ℝ≥0} {f' : E →L[𝕜] F}
/-- If a function is linearly approximated by a continuous linear map with a (possibly nonlinear)
right inverse, then it is locally onto: a ball of an explicit radius is included in the image
of the map. -/
theorem surj_on_closed_ball_of_nonlinear_right_inverse
(hf : approximates_linear_on f f' s c) (f'symm : f'.nonlinear_right_inverse)
{ε : ℝ} {b : E} (ε0 : 0 ≤ ε) (hε : closed_ball b ε ⊆ s) :
surj_on f (closed_ball b ε) (closed_ball (f b) (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε)) :=
begin
assume y hy,
cases le_or_lt (f'symm.nnnorm : ℝ) ⁻¹ c with hc hc,
{ refine ⟨b, by simp [ε0], _⟩,
have : dist y (f b) ≤ 0 :=
(mem_closed_ball.1 hy).trans (mul_nonpos_of_nonpos_of_nonneg (by linarith) ε0),
simp only [dist_le_zero] at this,
rw this },
have If' : (0 : ℝ) < f'symm.nnnorm,
by { rw [← inv_pos], exact (nnreal.coe_nonneg _).trans_lt hc },
have Icf' : (c : ℝ) * f'symm.nnnorm < 1, by rwa [inv_eq_one_div, lt_div_iff If'] at hc,
have Jf' : (f'symm.nnnorm : ℝ) ≠ 0 := ne_of_gt If',
have Jcf' : (1 : ℝ) - c * f'symm.nnnorm ≠ 0, by { apply ne_of_gt, linarith },
/- We have to show that `y` can be written as `f x` for some `x ∈ closed_ball b ε`.
The idea of the proof is to apply the Banach contraction principle to the map
`g : x ↦ x + f'symm (y - f x)`, as a fixed point of this map satisfies `f x = y`.
When `f'symm` is a genuine linear inverse, `g` is a contracting map. In our case, since `f'symm`
is nonlinear, this map is not contracting (it is not even continuous), but still the proof of
the contraction theorem holds: `uₙ = gⁿ b` is a Cauchy sequence, converging exponentially fast
to the desired point `x`. Instead of appealing to general results, we check this by hand.
The main point is that `f (u n)` becomes exponentially close to `y`, and therefore
`dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive
bound on `dist (u n) b`, from which one checks that `u n` stays in the ball on which one has a
control. Therefore, the bound can be checked at the next step, and so on inductively.
-/
set g := λ x, x + f'symm (y - f x) with hg,
set u := λ (n : ℕ), g ^[n] b with hu,
have usucc : ∀ n, u (n + 1) = g (u n), by simp [hu, ← iterate_succ_apply' g _ b],
-- First bound: if `f z` is close to `y`, then `g z` is close to `z` (i.e., almost a fixed point).
have A : ∀ z, dist (g z) z ≤ f'symm.nnnorm * dist (f z) y,
{ assume z,
rw [dist_eq_norm, hg, add_sub_cancel', dist_eq_norm'],
exact f'symm.bound _ },
-- Second bound: if `z` and `g z` are in the set with good control, then `f (g z)` becomes closer
-- to `y` than `f z` was (this uses the linear approximation property, and is the reason for the
-- choice of the formula for `g`).
have B : ∀ z ∈ closed_ball b ε, g z ∈ closed_ball b ε →
dist (f (g z)) y ≤ c * f'symm.nnnorm * dist (f z) y,
{ assume z hz hgz,
set v := f'symm (y - f z) with hv,
calc dist (f (g z)) y = ∥f (z + v) - y∥ : by rw [dist_eq_norm]
... = ∥f (z + v) - f z - f' v + f' v - (y - f z)∥ : by { congr' 1, abel }
... = ∥f (z + v) - f z - f' ((z + v) - z)∥ :
by simp only [continuous_linear_map.nonlinear_right_inverse.right_inv,
add_sub_cancel', sub_add_cancel]
... ≤ c * ∥(z + v) - z∥ : hf _ (hε hgz) _ (hε hz)
... ≤ c * (f'symm.nnnorm * dist (f z) y) : begin
apply mul_le_mul_of_nonneg_left _ (nnreal.coe_nonneg c),
simpa [hv, dist_eq_norm'] using f'symm.bound (y - f z),
end
... = c * f'symm.nnnorm * dist (f z) y : by ring },
-- Third bound: a complicated bound on `dist w b` (that will show up in the induction) is enough
-- to check that `w` is in the ball on which one has controls. Will be used to check that `u n`
-- belongs to this ball for all `n`.
have C : ∀ (n : ℕ) (w : E),
dist w b ≤ f'symm.nnnorm * (1 - (c * f'symm.nnnorm)^n) / (1 - c * f'symm.nnnorm) * dist (f b) y
→ w ∈ closed_ball b ε,
{ assume n w hw,
apply hw.trans,
rw [div_mul_eq_mul_div, div_le_iff], swap, { linarith },
calc (f'symm.nnnorm : ℝ) * (1 - (c * f'symm.nnnorm) ^ n) * dist (f b) y
= f'symm.nnnorm * dist (f b) y * (1 - (c * f'symm.nnnorm) ^ n) : by ring
... ≤ f'symm.nnnorm * dist (f b) y * 1 :
begin
apply mul_le_mul_of_nonneg_left _ (mul_nonneg (nnreal.coe_nonneg _) dist_nonneg),
rw [sub_le_self_iff],
exact pow_nonneg (mul_nonneg (nnreal.coe_nonneg _) (nnreal.coe_nonneg _)) _,
end
... ≤ f'symm.nnnorm * (((f'symm.nnnorm : ℝ)⁻¹ - c) * ε) :
by { rw [mul_one],
exact mul_le_mul_of_nonneg_left (mem_closed_ball'.1 hy) (nnreal.coe_nonneg _) }
... = ε * (1 - c * f'symm.nnnorm) : by { field_simp, ring } },
/- Main inductive control: `f (u n)` becomes exponentially close to `y`, and therefore
`dist (u (n+1)) (u n)` becomes exponentally small, making it possible to get an inductive
bound on `dist (u n) b`, from which one checks that `u n` remains in the ball on which we
have estimates. -/
have D : ∀ (n : ℕ), dist (f (u n)) y ≤ (c * f'symm.nnnorm)^n * dist (f b) y
∧ dist (u n) b ≤ f'symm.nnnorm * (1 - (c * f'symm.nnnorm)^n) / (1 - c * f'symm.nnnorm)
* dist (f b) y,
{ assume n,
induction n with n IH, { simp [hu, le_refl] },
rw usucc,
have Ign : dist (g (u n)) b ≤
f'symm.nnnorm * (1 - (c * f'symm.nnnorm)^n.succ) / (1 - c * f'symm.nnnorm) * dist (f b) y :=
calc
dist (g (u n)) b ≤ dist (g (u n)) (u n) + dist (u n) b : dist_triangle _ _ _
... ≤ f'symm.nnnorm * dist (f (u n)) y + dist (u n) b : add_le_add (A _) (le_refl _)
... ≤ f'symm.nnnorm * ((c * f'symm.nnnorm)^n * dist (f b) y) +
f'symm.nnnorm * (1 - (c * f'symm.nnnorm)^n) / (1 - c * f'symm.nnnorm) * dist (f b) y :
add_le_add (mul_le_mul_of_nonneg_left IH.1 (nnreal.coe_nonneg _)) IH.2
... = f'symm.nnnorm * (1 - (c * f'symm.nnnorm)^n.succ) / (1 - c * f'symm.nnnorm)
* dist (f b) y : by { field_simp [Jcf'], ring_exp },
refine ⟨_, Ign⟩,
calc dist (f (g (u n))) y ≤ c * f'symm.nnnorm * dist (f (u n)) y :
B _ (C n _ IH.2) (C n.succ _ Ign)
... ≤ (c * f'symm.nnnorm) * ((c * f'symm.nnnorm)^n * dist (f b) y) :
mul_le_mul_of_nonneg_left IH.1 (mul_nonneg (nnreal.coe_nonneg _) (nnreal.coe_nonneg _))
... = (c * f'symm.nnnorm) ^ n.succ * dist (f b) y : by ring_exp },
-- Deduce from the inductive bound that `uₙ` is a Cauchy sequence, therefore converging.
have : cauchy_seq u,
{ have : ∀ (n : ℕ), dist (u n) (u (n+1)) ≤ f'symm.nnnorm * dist (f b) y * (c * f'symm.nnnorm)^n,
{ assume n,
calc dist (u n) (u (n+1)) = dist (g (u n)) (u n) : by rw [usucc, dist_comm]
... ≤ f'symm.nnnorm * dist (f (u n)) y : A _
... ≤ f'symm.nnnorm * ((c * f'symm.nnnorm)^n * dist (f b) y) :
mul_le_mul_of_nonneg_left (D n).1 (nnreal.coe_nonneg _)
... = f'symm.nnnorm * dist (f b) y * (c * f'symm.nnnorm)^n : by ring },
exact cauchy_seq_of_le_geometric _ _ Icf' this },
obtain ⟨x, hx⟩ : ∃ x, tendsto u at_top (𝓝 x) := cauchy_seq_tendsto_of_complete this,
-- As all the `uₙ` belong to the ball `closed_ball b ε`, so does their limit `x`.
have xmem : x ∈ closed_ball b ε :=
is_closed_ball.mem_of_tendsto hx (eventually_of_forall (λ n, C n _ (D n).2)),
refine ⟨x, xmem, _⟩,
-- It remains to check that `f x = y`. This follows from continuity of `f` on `closed_ball b ε`
-- and from the fact that `f uₙ` is converging to `y` by construction.
have hx' : tendsto u at_top (𝓝[closed_ball b ε] x),
{ simp only [nhds_within, tendsto_inf, hx, true_and, ge_iff_le, tendsto_principal],
exact eventually_of_forall (λ n, C n _ (D n).2) },
have T1 : tendsto (λ n, f (u n)) at_top (𝓝 (f x)) :=
(hf.continuous_on.mono hε x xmem).tendsto.comp hx',
have T2 : tendsto (λ n, f (u n)) at_top (𝓝 y),
{ rw tendsto_iff_dist_tendsto_zero,
refine squeeze_zero (λ n, dist_nonneg) (λ n, (D n).1) _,
simpa using (tendsto_pow_at_top_nhds_0_of_lt_1
(mul_nonneg (nnreal.coe_nonneg _) (nnreal.coe_nonneg _)) Icf').mul tendsto_const_nhds },
exact tendsto_nhds_unique T1 T2,
end
lemma open_image (hf : approximates_linear_on f f' s c) (f'symm : f'.nonlinear_right_inverse)
(hs : is_open s) (hc : subsingleton F ∨ c < f'symm.nnnorm⁻¹) : is_open (f '' s) :=
begin
cases hc with hE hc, { resetI, apply is_open_discrete },
simp only [is_open_iff_mem_nhds, nhds_basis_closed_ball.mem_iff, ball_image_iff] at hs ⊢,
intros x hx,
rcases hs x hx with ⟨ε, ε0, hε⟩,
refine ⟨(f'symm.nnnorm⁻¹ - c) * ε, mul_pos (sub_pos.2 hc) ε0, _⟩,
exact (hf.surj_on_closed_ball_of_nonlinear_right_inverse f'symm (le_of_lt ε0) hε).mono
hε (subset.refl _)
end
lemma image_mem_nhds (hf : approximates_linear_on f f' s c) (f'symm : f'.nonlinear_right_inverse)
{x : E} (hs : s ∈ 𝓝 x) (hc : subsingleton F ∨ c < f'symm.nnnorm⁻¹) :
f '' s ∈ 𝓝 (f x) :=
begin
obtain ⟨t, hts, ht, xt⟩ : ∃ t ⊆ s, is_open t ∧ x ∈ t := _root_.mem_nhds_iff.1 hs,
have := is_open.mem_nhds ((hf.mono_set hts).open_image f'symm ht hc) (mem_image_of_mem _ xt),
exact mem_of_superset this (image_subset _ hts),
end
lemma map_nhds_eq (hf : approximates_linear_on f f' s c) (f'symm : f'.nonlinear_right_inverse)
{x : E} (hs : s ∈ 𝓝 x) (hc : subsingleton F ∨ c < f'symm.nnnorm⁻¹) :
map f (𝓝 x) = 𝓝 (f x) :=
begin
refine le_antisymm ((hf.continuous_on x (mem_of_mem_nhds hs)).continuous_at hs)
(le_map (λ t ht, _)),
have : f '' (s ∩ t) ∈ 𝓝 (f x) := (hf.mono_set (inter_subset_left s t)).image_mem_nhds
f'symm (inter_mem hs ht) hc,
exact mem_of_superset this (image_subset _ (inter_subset_right _ _)),
end
end locally_onto
/-!
From now on we assume that `f` approximates an invertible continuous linear map `f : E ≃L[𝕜] F`.
We also assume that either `E = {0}`, or `c < ∥f'⁻¹∥⁻¹`. We use `N` as an abbreviation for `∥f'⁻¹∥`.
-/
variables {f' : E ≃L[𝕜] F} {s : set E} {c : ℝ≥0}
local notation `N` := nnnorm (f'.symm : F →L[𝕜] E)
protected lemma antilipschitz (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
antilipschitz_with (N⁻¹ - c)⁻¹ (s.restrict f) :=
begin
cases hc with hE hc,
{ haveI : subsingleton s := ⟨λ x y, subtype.eq $ @subsingleton.elim _ hE _ _⟩,
exact antilipschitz_with.of_subsingleton },
convert (f'.antilipschitz.restrict s).add_lipschitz_with hf.lipschitz_sub hc,
simp [restrict]
end
protected lemma injective (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
injective (s.restrict f) :=
(hf.antilipschitz hc).injective
protected lemma inj_on (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
inj_on f s :=
inj_on_iff_injective.2 $ hf.injective hc
/-- A map approximating a linear equivalence on a set defines a local equivalence on this set.
Should not be used outside of this file, because it is superseded by `to_local_homeomorph` below.
This is a first step towards the inverse function. -/
def to_local_equiv (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) : local_equiv E F :=
(hf.inj_on hc).to_local_equiv _ _
/-- The inverse function is continuous on `f '' s`. Use properties of `local_homeomorph` instead. -/
lemma inverse_continuous_on (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) :
continuous_on (hf.to_local_equiv hc).symm (f '' s) :=
begin
apply continuous_on_iff_continuous_restrict.2,
refine ((hf.antilipschitz hc).to_right_inv_on' _ (hf.to_local_equiv hc).right_inv').continuous,
exact (λ x hx, (hf.to_local_equiv hc).map_target hx)
end
include cs
section
variables (f s)
/-- Given a function `f` that approximates a linear equivalence on an open set `s`,
returns a local homeomorph with `to_fun = f` and `source = s`. -/
def to_local_homeomorph (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) : local_homeomorph E F :=
{ to_local_equiv := hf.to_local_equiv hc,
open_source := hs,
open_target := hf.open_image f'.to_nonlinear_right_inverse hs
(by rwa f'.to_linear_equiv.to_equiv.subsingleton_congr at hc),
continuous_to_fun := hf.continuous_on,
continuous_inv_fun := hf.inverse_continuous_on hc }
end
@[simp] lemma to_local_homeomorph_coe (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs : E → F) = f := rfl
@[simp] lemma to_local_homeomorph_source (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs).source = s := rfl
@[simp] lemma to_local_homeomorph_target (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) :
(hf.to_local_homeomorph f s hc hs).target = f '' s := rfl
lemma closed_ball_subset_target (hf : approximates_linear_on f (f' : E →L[𝕜] F) s c)
(hc : subsingleton E ∨ c < N⁻¹) (hs : is_open s) {b : E} (ε0 : 0 ≤ ε) (hε : closed_ball b ε ⊆ s) :
closed_ball (f b) ((N⁻¹ - c) * ε) ⊆ (hf.to_local_homeomorph f s hc hs).target :=
(hf.surj_on_closed_ball_of_nonlinear_right_inverse f'.to_nonlinear_right_inverse
ε0 hε).mono hε (subset.refl _)
end approximates_linear_on
/-!
### Inverse function theorem
Now we prove the inverse function theorem. Let `f : E → F` be a map defined on a complete vector
space `E`. Assume that `f` has an invertible derivative `f' : E ≃L[𝕜] F` at `a : E` in the strict
sense. Then `f` approximates `f'` in the sense of `approximates_linear_on` on an open neighborhood
of `a`, and we can apply `approximates_linear_on.to_local_homeomorph` to construct the inverse
function. -/
namespace has_strict_fderiv_at
/-- If `f` has derivative `f'` at `a` in the strict sense and `c > 0`, then `f` approximates `f'`
with constant `c` on some neighborhood of `a`. -/
lemma approximates_deriv_on_nhds {f : E → F} {f' : E →L[𝕜] F} {a : E}
(hf : has_strict_fderiv_at f f' a) {c : ℝ≥0} (hc : subsingleton E ∨ 0 < c) :
∃ s ∈ 𝓝 a, approximates_linear_on f f' s c :=
begin
cases hc with hE hc,
{ refine ⟨univ, is_open.mem_nhds is_open_univ trivial, λ x hx y hy, _⟩,
simp [@subsingleton.elim E hE x y] },
have := hf.def hc,
rw [nhds_prod_eq, filter.eventually, mem_prod_same_iff] at this,
rcases this with ⟨s, has, hs⟩,
exact ⟨s, has, λ x hx y hy, hs (mk_mem_prod hx hy)⟩
end
lemma map_nhds_eq_of_surj [complete_space E] [complete_space F]
{f : E → F} {f' : E →L[𝕜] F} {a : E}
(hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) (h : f'.range = ⊤) :
map f (𝓝 a) = 𝓝 (f a) :=
begin
let f'symm := f'.nonlinear_right_inverse_of_surjective h,
set c : ℝ≥0 := f'symm.nnnorm⁻¹ / 2 with hc,
have f'symm_pos : 0 < f'symm.nnnorm := f'.nonlinear_right_inverse_of_surjective_nnnorm_pos h,
have cpos : 0 < c, by simp [hc, nnreal.half_pos, nnreal.inv_pos, f'symm_pos],
obtain ⟨s, s_nhds, hs⟩ : ∃ s ∈ 𝓝 a, approximates_linear_on f f' s c :=
hf.approximates_deriv_on_nhds (or.inr cpos),
apply hs.map_nhds_eq f'symm s_nhds (or.inr (nnreal.half_lt_self _)),
simp [ne_of_gt f'symm_pos],
end
variables [cs : complete_space E] {f : E → F} {f' : E ≃L[𝕜] F} {a : E}
lemma approximates_deriv_on_open_nhds (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∃ (s : set E) (hs : a ∈ s ∧ is_open s),
approximates_linear_on f (f' : E →L[𝕜] F) s ((nnnorm (f'.symm : F →L[𝕜] E))⁻¹ / 2) :=
begin
refine ((nhds_basis_opens a).exists_iff _).1 _,
exact (λ s t, approximates_linear_on.mono_set),
exact (hf.approximates_deriv_on_nhds $ f'.subsingleton_or_nnnorm_symm_pos.imp id $
λ hf', nnreal.half_pos $ nnreal.inv_pos.2 $ hf')
end
include cs
variable (f)
/-- Given a function with an invertible strict derivative at `a`, returns a `local_homeomorph`
with `to_fun = f` and `a ∈ source`. This is a part of the inverse function theorem.
The other part `has_strict_fderiv_at.to_local_inverse` states that the inverse function
of this `local_homeomorph` has derivative `f'.symm`. -/
def to_local_homeomorph (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) : local_homeomorph E F :=
approximates_linear_on.to_local_homeomorph f
(classical.some hf.approximates_deriv_on_open_nhds)
(classical.some_spec hf.approximates_deriv_on_open_nhds).snd
(f'.subsingleton_or_nnnorm_symm_pos.imp id $ λ hf', nnreal.half_lt_self $ ne_of_gt $
nnreal.inv_pos.2 $ hf')
(classical.some_spec hf.approximates_deriv_on_open_nhds).fst.2
variable {f}
@[simp] lemma to_local_homeomorph_coe (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
(hf.to_local_homeomorph f : E → F) = f := rfl
lemma mem_to_local_homeomorph_source (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
a ∈ (hf.to_local_homeomorph f).source :=
(classical.some_spec hf.approximates_deriv_on_open_nhds).fst.1
lemma image_mem_to_local_homeomorph_target (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
f a ∈ (hf.to_local_homeomorph f).target :=
(hf.to_local_homeomorph f).map_source hf.mem_to_local_homeomorph_source
lemma map_nhds_eq_of_equiv (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
map f (𝓝 a) = 𝓝 (f a) :=
(hf.to_local_homeomorph f).map_nhds_eq hf.mem_to_local_homeomorph_source
variables (f f' a)
/-- Given a function `f` with an invertible derivative, returns a function that is locally inverse
to `f`. -/
def local_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) : F → E :=
(hf.to_local_homeomorph f).symm
variables {f f' a}
lemma local_inverse_def (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
hf.local_inverse f _ _ = (hf.to_local_homeomorph f).symm :=
rfl
lemma eventually_left_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∀ᶠ x in 𝓝 a, hf.local_inverse f f' a (f x) = x :=
(hf.to_local_homeomorph f).eventually_left_inverse hf.mem_to_local_homeomorph_source
@[simp] lemma local_inverse_apply_image (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
hf.local_inverse f f' a (f a) = a :=
hf.eventually_left_inverse.self_of_nhds
lemma eventually_right_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
∀ᶠ y in 𝓝 (f a), f (hf.local_inverse f f' a y) = y :=
(hf.to_local_homeomorph f).eventually_right_inverse' hf.mem_to_local_homeomorph_source
lemma local_inverse_continuous_at (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
continuous_at (hf.local_inverse f f' a) (f a) :=
(hf.to_local_homeomorph f).continuous_at_symm hf.image_mem_to_local_homeomorph_target
lemma local_inverse_tendsto (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
tendsto (hf.local_inverse f f' a) (𝓝 $ f a) (𝓝 a) :=
(hf.to_local_homeomorph f).tendsto_symm hf.mem_to_local_homeomorph_source
lemma local_inverse_unique (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) {g : F → E}
(hg : ∀ᶠ x in 𝓝 a, g (f x) = x) :
∀ᶠ y in 𝓝 (f a), g y = local_inverse f f' a hf y :=
eventually_eq_of_left_inv_of_right_inv hg hf.eventually_right_inverse $
(hf.to_local_homeomorph f).tendsto_symm hf.mem_to_local_homeomorph_source
/-- If `f` has an invertible derivative `f'` at `a` in the sense of strict differentiability `(hf)`,
then the inverse function `hf.local_inverse f` has derivative `f'.symm` at `f a`. -/
theorem to_local_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) :
has_strict_fderiv_at (hf.local_inverse f f' a) (f'.symm : F →L[𝕜] E) (f a) :=
(hf.to_local_homeomorph f).has_strict_fderiv_at_symm hf.image_mem_to_local_homeomorph_target $
by simpa [← local_inverse_def] using hf
/-- If `f : E → F` has an invertible derivative `f'` at `a` in the sense of strict differentiability
and `g (f x) = x` in a neighborhood of `a`, then `g` has derivative `f'.symm` at `f a`.
For a version assuming `f (g y) = y` and continuity of `g` at `f a` but not `[complete_space E]`
see `of_local_left_inverse`. -/
theorem to_local_left_inverse (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) a) {g : F → E}
(hg : ∀ᶠ x in 𝓝 a, g (f x) = x) :
has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) (f a) :=
hf.to_local_inverse.congr_of_eventually_eq $ (hf.local_inverse_unique hg).mono $ λ _, eq.symm
end has_strict_fderiv_at
/-- If a function has an invertible strict derivative at all points, then it is an open map. -/
lemma open_map_of_strict_fderiv_equiv [complete_space E] {f : E → F} {f' : E → E ≃L[𝕜] F}
(hf : ∀ x, has_strict_fderiv_at f (f' x : E →L[𝕜] F) x) :
is_open_map f :=
is_open_map_iff_nhds_le.2 $ λ x, (hf x).map_nhds_eq_of_equiv.ge
/-!
### Inverse function theorem, 1D case
In this case we prove a version of the inverse function theorem for maps `f : 𝕜 → 𝕜`.
We use `continuous_linear_equiv.units_equiv_aut` to translate `has_strict_deriv_at f f' a` and
`f' ≠ 0` into `has_strict_fderiv_at f (_ : 𝕜 ≃L[𝕜] 𝕜) a`.
-/
namespace has_strict_deriv_at
variables [cs : complete_space 𝕜] {f : 𝕜 → 𝕜} {f' a : 𝕜} (hf : has_strict_deriv_at f f' a)
(hf' : f' ≠ 0)
include cs
variables (f f' a)
/-- A function that is inverse to `f` near `a`. -/
@[reducible] def local_inverse : 𝕜 → 𝕜 :=
(hf.has_strict_fderiv_at_equiv hf').local_inverse _ _ _
variables {f f' a}
lemma map_nhds_eq : map f (𝓝 a) = 𝓝 (f a) :=
(hf.has_strict_fderiv_at_equiv hf').map_nhds_eq_of_equiv
theorem to_local_inverse : has_strict_deriv_at (hf.local_inverse f f' a hf') f'⁻¹ (f a) :=
(hf.has_strict_fderiv_at_equiv hf').to_local_inverse
theorem to_local_left_inverse {g : 𝕜 → 𝕜} (hg : ∀ᶠ x in 𝓝 a, g (f x) = x) :
has_strict_deriv_at g f'⁻¹ (f a) :=
(hf.has_strict_fderiv_at_equiv hf').to_local_left_inverse hg
end has_strict_deriv_at
/-- If a function has a non-zero strict derivative at all points, then it is an open map. -/
lemma open_map_of_strict_deriv [complete_space 𝕜] {f f' : 𝕜 → 𝕜}
(hf : ∀ x, has_strict_deriv_at f (f' x) x) (h0 : ∀ x, f' x ≠ 0) :
is_open_map f :=
is_open_map_iff_nhds_le.2 $ λ x, ((hf x).map_nhds_eq (h0 x)).ge
/-!
### Inverse function theorem, smooth case
-/
namespace times_cont_diff_at
variables {𝕂 : Type*} [is_R_or_C 𝕂]
variables {E' : Type*} [normed_group E'] [normed_space 𝕂 E']
variables {F' : Type*} [normed_group F'] [normed_space 𝕂 F']
variables [complete_space E'] (f : E' → F') {f' : E' ≃L[𝕂] F'} {a : E'}
/-- Given a `times_cont_diff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible
derivative at `a`, returns a `local_homeomorph` with `to_fun = f` and `a ∈ source`. -/
def to_local_homeomorph
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
local_homeomorph E' F' :=
(hf.has_strict_fderiv_at' hf' hn).to_local_homeomorph f
variable {f}
@[simp] lemma to_local_homeomorph_coe
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
(hf.to_local_homeomorph f hf' hn : E' → F') = f := rfl
lemma mem_to_local_homeomorph_source
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
a ∈ (hf.to_local_homeomorph f hf' hn).source :=
(hf.has_strict_fderiv_at' hf' hn).mem_to_local_homeomorph_source
lemma image_mem_to_local_homeomorph_target
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
f a ∈ (hf.to_local_homeomorph f hf' hn).target :=
(hf.has_strict_fderiv_at' hf' hn).image_mem_to_local_homeomorph_target
/-- Given a `times_cont_diff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible derivative
at `a`, returns a function that is locally inverse to `f`. -/
def local_inverse
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
F' → E' :=
(hf.has_strict_fderiv_at' hf' hn).local_inverse f f' a
lemma local_inverse_apply_image
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
hf.local_inverse hf' hn (f a) = a :=
(hf.has_strict_fderiv_at' hf' hn).local_inverse_apply_image
/-- Given a `times_cont_diff` function over `𝕂` (which is `ℝ` or `ℂ`) with an invertible derivative
at `a`, the inverse function (produced by `times_cont_diff.to_local_homeomorph`) is
also `times_cont_diff`. -/
lemma to_local_inverse
{n : with_top ℕ} (hf : times_cont_diff_at 𝕂 n f a) (hf' : has_fderiv_at f (f' : E' →L[𝕂] F') a)
(hn : 1 ≤ n) :
times_cont_diff_at 𝕂 n (hf.local_inverse hf' hn) (f a) :=
begin
have := hf.local_inverse_apply_image hf' hn,
apply (hf.to_local_homeomorph f hf' hn).times_cont_diff_at_symm
(image_mem_to_local_homeomorph_target hf hf' hn),
{ convert hf' },
{ convert hf }
end
end times_cont_diff_at
|
da2e0c5189132eb596889d8fb31f7ae95608a91e | 618003631150032a5676f229d13a079ac875ff77 | /test/differentiable.lean | eeff8b757a967eccc9f88495381dfdd30eaf0a0c | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 1,922 | lean | import analysis.special_functions.trigonometric
namespace real
example : differentiable ℝ (λ (x : ℝ), exp x) :=
by simp
example : differentiable ℝ (λ (x : ℝ), exp ((sin x)^2) - exp (exp (cos (x - 3)))) :=
by simp
example (x : ℝ) : deriv (λ (x : ℝ), (cos x)^2 + (sin x)^2) x = 0 :=
by { simp, ring }
example (x : ℝ) : deriv (λ (x : ℝ), (1+x)^3 - x^3 - 3 * x^2 - 3 * x - 4) x = 0 :=
by { simp, ring }
example (x : ℝ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
example (x : ℝ) : differentiable_at ℝ (λ x, (cos x, x)) x := by simp
example (x : ℝ) (h : 1 + sin x ≠ 0) : deriv (λ x, exp (cos x) / (1 + sin x)) x =
(-(exp (cos x) * sin x * (1 + sin x)) - exp (cos x) * cos x) / (1 + sin x) ^ 2 :=
by simp [h]
example (x : ℝ) : differentiable_at ℝ (λ x, (sin x) / (exp x)) x :=
by simp [exp_ne_zero]
example : differentiable ℝ (λ x, (sin x) / (exp x)) :=
by simp [exp_ne_zero]
example (x : ℝ) (h : x ≠ 0) : deriv (λ x, x * (log x - 1)) x = log x :=
by simp [h]
end real
namespace complex
example : differentiable ℂ (λ (x : ℂ), exp x) :=
by simp
example : differentiable ℂ (λ (x : ℂ), exp ((sin x)^2) - exp (exp (cos (x - 3)))) :=
by simp
example (x : ℂ) : deriv (λ (x : ℂ), (cos x)^2 + (sin x)^2) x = 0 :=
by { simp, ring }
example (x : ℂ) : deriv (λ x, cos (sin x) * exp x) x = (cos(sin(x))-sin(sin(x))*cos(x))*exp(x) :=
by { simp, ring }
example (x : ℂ) : differentiable_at ℂ (λ x, (cos x, x)) x := by simp
example (x : ℂ) (h : 1 + sin x ≠ 0) : deriv (λ x, exp (cos x) / (1 + sin x)) x =
(-(exp (cos x) * sin x * (1 + sin x)) - exp (cos x) * cos x) / (1 + sin x) ^ 2 :=
by simp [h]
example (x : ℂ) : differentiable_at ℂ (λ x, (sin x) / (exp x)) x :=
by simp [exp_ne_zero]
example : differentiable ℂ (λ x, (sin x) / (exp x)) :=
by simp [exp_ne_zero]
end complex
|
4a6e03b2f6ca80c38d110e86af3bd0c7a4a3c1c3 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/logic/basic.lean | aed809947fffa438d733996a5b388ae9578f05db | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 59,309 | 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
-/
import tactic.doc_commands
import tactic.reserved_notation
/-!
# Basic logic properties
This file is one of the earliest imports in mathlib.
## Implementation notes
Theorems that require decidability hypotheses are in the namespace "decidable".
Classical versions are in the namespace "classical".
In the presence of automation, this whole file may be unnecessary. On the other hand,
maybe it is useful for writing automation.
-/
local attribute [instance, priority 10] classical.prop_decidable
section miscellany
/- We add the `inline` attribute to optimize VM computation using these declarations. For example,
`if p ∧ q then ... else ...` will not evaluate the decidability of `q` if `p` is false. -/
attribute [inline] and.decidable or.decidable decidable.false xor.decidable iff.decidable
decidable.true implies.decidable not.decidable ne.decidable
bool.decidable_eq decidable.to_bool
attribute [simp] cast_eq cast_heq
variables {α : Type*} {β : Type*}
/-- An identity function with its main argument implicit. This will be printed as `hidden` even
if it is applied to a large term, so it can be used for elision,
as done in the `elide` and `unelide` tactics. -/
@[reducible] def hidden {α : Sort*} {a : α} := a
/-- Ex falso, the nondependent eliminator for the `empty` type. -/
def empty.elim {C : Sort*} : empty → C.
instance : subsingleton empty := ⟨λa, a.elim⟩
instance subsingleton.prod {α β : Type*} [subsingleton α] [subsingleton β] : subsingleton (α × β) :=
⟨by { intros a b, cases a, cases b, congr, }⟩
instance : decidable_eq empty := λa, a.elim
instance sort.inhabited : inhabited (Sort*) := ⟨punit⟩
instance sort.inhabited' : inhabited (default (Sort*)) := ⟨punit.star⟩
instance psum.inhabited_left {α β} [inhabited α] : inhabited (psum α β) := ⟨psum.inl (default _)⟩
instance psum.inhabited_right {α β} [inhabited β] : inhabited (psum α β) := ⟨psum.inr (default _)⟩
@[priority 10] instance decidable_eq_of_subsingleton
{α} [subsingleton α] : decidable_eq α
| a b := is_true (subsingleton.elim a b)
@[simp] lemma eq_iff_true_of_subsingleton {α : Sort*} [subsingleton α] (x y : α) :
x = y ↔ true :=
by cc
/-- If all points are equal to a given point `x`, then `α` is a subsingleton. -/
lemma subsingleton_of_forall_eq {α : Sort*} (x : α) (h : ∀ y, y = x) : subsingleton α :=
⟨λ a b, (h a).symm ▸ (h b).symm ▸ rfl⟩
lemma subsingleton_iff_forall_eq {α : Sort*} (x : α) : subsingleton α ↔ ∀ y, y = x :=
⟨λ h y, @subsingleton.elim _ h y x, subsingleton_of_forall_eq x⟩
-- TODO[gh-6025]: make this an instance once safe to do so
lemma subtype.subsingleton (α : Sort*) [subsingleton α] (p : α → Prop) : subsingleton (subtype p) :=
⟨λ ⟨x,_⟩ ⟨y,_⟩, have x = y, from subsingleton.elim _ _, by { cases this, refl }⟩
/-- Add an instance to "undo" coercion transitivity into a chain of coercions, because
most simp lemmas are stated with respect to simple coercions and will not match when
part of a chain. -/
@[simp] theorem coe_coe {α β γ} [has_coe α β] [has_coe_t β γ]
(a : α) : (a : γ) = (a : β) := rfl
theorem coe_fn_coe_trans
{α β γ} [has_coe α β] [has_coe_t_aux β γ] [has_coe_to_fun γ]
(x : α) : @coe_fn α _ x = @coe_fn β _ x := rfl
@[simp] theorem coe_fn_coe_base
{α β} [has_coe α β] [has_coe_to_fun β]
(x : α) : @coe_fn α _ x = @coe_fn β _ x := rfl
theorem coe_sort_coe_trans
{α β γ} [has_coe α β] [has_coe_t_aux β γ] [has_coe_to_sort γ]
(x : α) : @coe_sort α _ x = @coe_sort β _ x := rfl
/--
Many structures such as bundled morphisms coerce to functions so that you can
transparently apply them to arguments. For example, if `e : α ≃ β` and `a : α`
then you can write `e a` and this is elaborated as `⇑e a`. This type of
coercion is implemented using the `has_coe_to_fun` type class. There is one
important consideration:
If a type coerces to another type which in turn coerces to a function,
then it **must** implement `has_coe_to_fun` directly:
```lean
structure sparkling_equiv (α β) extends α ≃ β
-- if we add a `has_coe` instance,
instance {α β} : has_coe (sparkling_equiv α β) (α ≃ β) :=
⟨sparkling_equiv.to_equiv⟩
-- then a `has_coe_to_fun` instance **must** be added as well:
instance {α β} : has_coe_to_fun (sparkling_equiv α β) :=
⟨λ _, α → β, λ f, f.to_equiv.to_fun⟩
```
(Rationale: if we do not declare the direct coercion, then `⇑e a` is not in
simp-normal form. The lemma `coe_fn_coe_base` will unfold it to `⇑↑e a`. This
often causes loops in the simplifier.)
-/
library_note "function coercion"
@[simp] theorem coe_sort_coe_base
{α β} [has_coe α β] [has_coe_to_sort β]
(x : α) : @coe_sort α _ x = @coe_sort β _ x := rfl
/-- `pempty` is the universe-polymorphic analogue of `empty`. -/
@[derive decidable_eq]
inductive {u} pempty : Sort u
/-- Ex falso, the nondependent eliminator for the `pempty` type. -/
def pempty.elim {C : Sort*} : pempty → C.
instance subsingleton_pempty : subsingleton pempty := ⟨λa, a.elim⟩
@[simp] lemma not_nonempty_pempty : ¬ nonempty pempty :=
assume ⟨h⟩, h.elim
@[simp] theorem forall_pempty {P : pempty → Prop} : (∀ x : pempty, P x) ↔ true :=
⟨λ h, trivial, λ h x, by cases x⟩
@[simp] theorem exists_pempty {P : pempty → Prop} : (∃ x : pempty, P x) ↔ false :=
⟨λ h, by { cases h with w, cases w }, false.elim⟩
lemma congr_arg_heq {α} {β : α → Sort*} (f : ∀ a, β a) : ∀ {a₁ a₂ : α}, a₁ = a₂ → f a₁ == f a₂
| a _ rfl := heq.rfl
lemma plift.down_inj {α : Sort*} : ∀ (a b : plift α), a.down = b.down → a = b
| ⟨a⟩ ⟨b⟩ rfl := rfl
-- missing [symm] attribute for ne in core.
attribute [symm] ne.symm
lemma ne_comm {α} {a b : α} : a ≠ b ↔ b ≠ a := ⟨ne.symm, ne.symm⟩
@[simp] lemma eq_iff_eq_cancel_left {b c : α} :
(∀ {a}, a = b ↔ a = c) ↔ (b = c) :=
⟨λ h, by rw [← h], λ h a, by rw h⟩
@[simp] lemma eq_iff_eq_cancel_right {a b : α} :
(∀ {c}, a = c ↔ b = c) ↔ (a = b) :=
⟨λ h, by rw h, λ h a, by rw h⟩
/-- Wrapper for adding elementary propositions to the type class systems.
Warning: this can easily be abused. See the rest of this docstring for details.
Certain propositions should not be treated as a class globally,
but sometimes it is very convenient to be able to use the type class system
in specific circumstances.
For example, `zmod p` is a field if and only if `p` is a prime number.
In order to be able to find this field instance automatically by type class search,
we have to turn `p.prime` into an instance implicit assumption.
On the other hand, making `nat.prime` a class would require a major refactoring of the library,
and it is questionable whether making `nat.prime` a class is desirable at all.
The compromise is to add the assumption `[fact p.prime]` to `zmod.field`.
In particular, this class is not intended for turning the type class system
into an automated theorem prover for first order logic. -/
class fact (p : Prop) : Prop := (out [] : p)
lemma fact.elim {p : Prop} (h : fact p) : p := h.1
lemma fact_iff {p : Prop} : fact p ↔ p := ⟨λ h, h.1, λ h, ⟨h⟩⟩
end miscellany
/-!
### Declarations about propositional connectives
-/
theorem false_ne_true : false ≠ true
| h := h.symm ▸ trivial
section propositional
variables {a b c d : Prop}
/-! ### Declarations about `implies` -/
instance : is_refl Prop iff := ⟨iff.refl⟩
instance : is_trans Prop iff := ⟨λ _ _ _, iff.trans⟩
theorem iff_of_eq (e : a = b) : a ↔ b := e ▸ iff.rfl
theorem iff_iff_eq : (a ↔ b) ↔ a = b := ⟨propext, iff_of_eq⟩
@[simp] lemma eq_iff_iff {p q : Prop} : (p = q) ↔ (p ↔ q) := iff_iff_eq.symm
@[simp] theorem imp_self : (a → a) ↔ true := iff_true_intro id
theorem imp_intro {α β : Prop} (h : α) : β → α := λ _, h
theorem imp_false : (a → false) ↔ ¬ a := iff.rfl
theorem imp_and_distrib {α} : (α → b ∧ c) ↔ (α → b) ∧ (α → c) :=
⟨λ h, ⟨λ ha, (h ha).left, λ ha, (h ha).right⟩,
λ h ha, ⟨h.left ha, h.right ha⟩⟩
@[simp] theorem and_imp : (a ∧ b → c) ↔ (a → b → c) :=
iff.intro (λ h ha hb, h ⟨ha, hb⟩) (λ h ⟨ha, hb⟩, h ha hb)
theorem iff_def : (a ↔ b) ↔ (a → b) ∧ (b → a) :=
iff_iff_implies_and_implies _ _
theorem iff_def' : (a ↔ b) ↔ (b → a) ∧ (a → b) :=
iff_def.trans and.comm
theorem imp_true_iff {α : Sort*} : (α → true) ↔ true :=
iff_true_intro $ λ_, trivial
theorem imp_iff_right (ha : a) : (a → b) ↔ b :=
⟨λf, f ha, imp_intro⟩
/-! ### Declarations about `not` -/
/-- Ex falso for negation. From `¬ a` and `a` anything follows. This is the same as `absurd` with
the arguments flipped, but it is in the `not` namespace so that projection notation can be used. -/
def not.elim {α : Sort*} (H1 : ¬a) (H2 : a) : α := absurd H2 H1
@[reducible] theorem not.imp {a b : Prop} (H2 : ¬b) (H1 : a → b) : ¬a := mt H1 H2
theorem not_not_of_not_imp : ¬(a → b) → ¬¬a :=
mt not.elim
theorem not_of_not_imp {a : Prop} : ¬(a → b) → ¬b :=
mt imp_intro
theorem dec_em (p : Prop) [decidable p] : p ∨ ¬p := decidable.em p
theorem dec_em' (p : Prop) [decidable p] : ¬p ∨ p := (dec_em p).swap
theorem em (p : Prop) : p ∨ ¬p := classical.em _
theorem em' (p : Prop) : ¬p ∨ p := (em p).swap
theorem or_not {p : Prop} : p ∨ ¬p := em _
section eq_or_ne
variables {α : Sort*} (x y : α)
theorem decidable.eq_or_ne [decidable (x = y)] : x = y ∨ x ≠ y := dec_em $ x = y
theorem decidable.ne_or_eq [decidable (x = y)] : x ≠ y ∨ x = y := dec_em' $ x = y
theorem eq_or_ne : x = y ∨ x ≠ y := em $ x = y
theorem ne_or_eq : x ≠ y ∨ x = y := em' $ x = y
end eq_or_ne
theorem by_contradiction {p} : (¬p → false) → p := decidable.by_contradiction
-- alias by_contradiction ← by_contra
theorem by_contra {p} : (¬p → false) → p := decidable.by_contradiction
/--
In most of mathlib, we use the law of excluded middle (LEM) and the axiom of choice (AC) freely.
The `decidable` namespace contains versions of lemmas from the root namespace that explicitly
attempt to avoid the axiom of choice, usually by adding decidability assumptions on the inputs.
You can check if a lemma uses the axiom of choice by using `#print axioms foo` and seeing if
`classical.choice` appears in the list.
-/
library_note "decidable namespace"
/--
As mathlib is primarily classical,
if the type signature of a `def` or `lemma` does not require any `decidable` instances to state,
it is preferable not to introduce any `decidable` instances that are needed in the proof
as arguments, but rather to use the `classical` tactic as needed.
In the other direction, when `decidable` instances do appear in the type signature,
it is better to use explicitly introduced ones rather than allowing Lean to automatically infer
classical ones, as these may cause instance mismatch errors later.
-/
library_note "decidable arguments"
-- See Note [decidable namespace]
protected theorem decidable.not_not [decidable a] : ¬¬a ↔ a :=
iff.intro decidable.by_contradiction not_not_intro
/-- The Double Negation Theorem: `¬ ¬ P` is equivalent to `P`.
The left-to-right direction, double negation elimination (DNE),
is classically true but not constructively. -/
@[simp] theorem not_not : ¬¬a ↔ a := decidable.not_not
theorem of_not_not : ¬¬a → a := by_contra
-- See Note [decidable namespace]
protected theorem decidable.of_not_imp [decidable a] (h : ¬ (a → b)) : a :=
decidable.by_contradiction (not_not_of_not_imp h)
theorem of_not_imp : ¬ (a → b) → a := decidable.of_not_imp
-- See Note [decidable namespace]
protected theorem decidable.not_imp_symm [decidable a] (h : ¬a → b) (hb : ¬b) : a :=
decidable.by_contradiction $ hb ∘ h
theorem not.decidable_imp_symm [decidable a] : (¬a → b) → ¬b → a := decidable.not_imp_symm
theorem not.imp_symm : (¬a → b) → ¬b → a := not.decidable_imp_symm
-- See Note [decidable namespace]
protected theorem decidable.not_imp_comm [decidable a] [decidable b] : (¬a → b) ↔ (¬b → a) :=
⟨not.decidable_imp_symm, not.decidable_imp_symm⟩
theorem not_imp_comm : (¬a → b) ↔ (¬b → a) := decidable.not_imp_comm
@[simp] theorem imp_not_self : (a → ¬a) ↔ ¬a := ⟨λ h ha, h ha ha, λ h _, h⟩
theorem decidable.not_imp_self [decidable a] : (¬a → a) ↔ a :=
by { have := @imp_not_self (¬a), rwa decidable.not_not at this }
@[simp] theorem not_imp_self : (¬a → a) ↔ a := decidable.not_imp_self
theorem imp.swap : (a → b → c) ↔ (b → a → c) :=
⟨function.swap, function.swap⟩
theorem imp_not_comm : (a → ¬b) ↔ (b → ¬a) :=
imp.swap
/-! ### Declarations about `xor` -/
@[simp] theorem xor_true : xor true = not := funext $ λ a, by simp [xor]
@[simp] theorem xor_false : xor false = id := funext $ λ a, by simp [xor]
theorem xor_comm (a b) : xor a b = xor b a := by simp [xor, and_comm, or_comm]
instance : is_commutative Prop xor := ⟨xor_comm⟩
@[simp] theorem xor_self (a : Prop) : xor a a = false := by simp [xor]
/-! ### Declarations about `and` -/
theorem and_congr_left (h : c → (a ↔ b)) : a ∧ c ↔ b ∧ c :=
and.comm.trans $ (and_congr_right h).trans and.comm
theorem and_congr_left' (h : a ↔ b) : a ∧ c ↔ b ∧ c := and_congr h iff.rfl
theorem and_congr_right' (h : b ↔ c) : a ∧ b ↔ a ∧ c := and_congr iff.rfl h
theorem not_and_of_not_left (b : Prop) : ¬a → ¬(a ∧ b) :=
mt and.left
theorem not_and_of_not_right (a : Prop) {b : Prop} : ¬b → ¬(a ∧ b) :=
mt and.right
theorem and.imp_left (h : a → b) : a ∧ c → b ∧ c :=
and.imp h id
theorem and.imp_right (h : a → b) : c ∧ a → c ∧ b :=
and.imp id h
lemma and.right_comm : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b :=
by simp only [and.left_comm, and.comm]
lemma and.rotate : a ∧ b ∧ c ↔ b ∧ c ∧ a :=
by simp only [and.left_comm, and.comm]
theorem and_not_self_iff (a : Prop) : a ∧ ¬ a ↔ false :=
iff.intro (assume h, (h.right) (h.left)) (assume h, h.elim)
theorem not_and_self_iff (a : Prop) : ¬ a ∧ a ↔ false :=
iff.intro (assume ⟨hna, ha⟩, hna ha) false.elim
theorem and_iff_left_of_imp {a b : Prop} (h : a → b) : (a ∧ b) ↔ a :=
iff.intro and.left (λ ha, ⟨ha, h ha⟩)
theorem and_iff_right_of_imp {a b : Prop} (h : b → a) : (a ∧ b) ↔ b :=
iff.intro and.right (λ hb, ⟨h hb, hb⟩)
@[simp] theorem and_iff_left_iff_imp {a b : Prop} : ((a ∧ b) ↔ a) ↔ (a → b) :=
⟨λ h ha, (h.2 ha).2, and_iff_left_of_imp⟩
@[simp] theorem and_iff_right_iff_imp {a b : Prop} : ((a ∧ b) ↔ b) ↔ (b → a) :=
⟨λ h ha, (h.2 ha).1, and_iff_right_of_imp⟩
@[simp] lemma iff_self_and {p q : Prop} : (p ↔ p ∧ q) ↔ (p → q) :=
by rw [@iff.comm p, and_iff_left_iff_imp]
@[simp] lemma iff_and_self {p q : Prop} : (p ↔ q ∧ p) ↔ (p → q) :=
by rw [and_comm, iff_self_and]
@[simp] lemma and.congr_right_iff : (a ∧ b ↔ a ∧ c) ↔ (a → (b ↔ c)) :=
⟨λ h ha, by simp [ha] at h; exact h, and_congr_right⟩
@[simp] lemma and.congr_left_iff : (a ∧ c ↔ b ∧ c) ↔ c → (a ↔ b) :=
by simp only [and.comm, ← and.congr_right_iff]
@[simp] lemma and_self_left : a ∧ a ∧ b ↔ a ∧ b :=
⟨λ h, ⟨h.1, h.2.2⟩, λ h, ⟨h.1, h.1, h.2⟩⟩
@[simp] lemma and_self_right : (a ∧ b) ∧ b ↔ a ∧ b :=
⟨λ h, ⟨h.1.1, h.2⟩, λ h, ⟨⟨h.1, h.2⟩, h.2⟩⟩
/-! ### Declarations about `or` -/
theorem or_congr_left (h : a ↔ b) : a ∨ c ↔ b ∨ c := or_congr h iff.rfl
theorem or_congr_right (h : b ↔ c) : a ∨ b ↔ a ∨ c := or_congr iff.rfl h
theorem or.right_comm : (a ∨ b) ∨ c ↔ (a ∨ c) ∨ b := by rw [or_assoc, or_assoc, or_comm b]
theorem or_of_or_of_imp_of_imp (h₁ : a ∨ b) (h₂ : a → c) (h₃ : b → d) : c ∨ d :=
or.imp h₂ h₃ h₁
theorem or_of_or_of_imp_left (h₁ : a ∨ c) (h : a → b) : b ∨ c :=
or.imp_left h h₁
theorem or_of_or_of_imp_right (h₁ : c ∨ a) (h : a → b) : c ∨ b :=
or.imp_right h h₁
theorem or.elim3 (h : a ∨ b ∨ c) (ha : a → d) (hb : b → d) (hc : c → d) : d :=
or.elim h ha (assume h₂, or.elim h₂ hb hc)
theorem or_imp_distrib : (a ∨ b → c) ↔ (a → c) ∧ (b → c) :=
⟨assume h, ⟨assume ha, h (or.inl ha), assume hb, h (or.inr hb)⟩,
assume ⟨ha, hb⟩, or.rec ha hb⟩
-- See Note [decidable namespace]
protected theorem decidable.or_iff_not_imp_left [decidable a] : a ∨ b ↔ (¬ a → b) :=
⟨or.resolve_left, λ h, dite _ or.inl (or.inr ∘ h)⟩
theorem or_iff_not_imp_left : a ∨ b ↔ (¬ a → b) := decidable.or_iff_not_imp_left
-- See Note [decidable namespace]
protected theorem decidable.or_iff_not_imp_right [decidable b] : a ∨ b ↔ (¬ b → a) :=
or.comm.trans decidable.or_iff_not_imp_left
theorem or_iff_not_imp_right : a ∨ b ↔ (¬ b → a) := decidable.or_iff_not_imp_right
-- See Note [decidable namespace]
protected theorem decidable.not_imp_not [decidable a] : (¬ a → ¬ b) ↔ (b → a) :=
⟨assume h hb, decidable.by_contradiction $ assume na, h na hb, mt⟩
theorem not_imp_not : (¬ a → ¬ b) ↔ (b → a) := decidable.not_imp_not
@[simp] theorem or_iff_left_iff_imp : (a ∨ b ↔ a) ↔ (b → a) :=
⟨λ h hb, h.1 (or.inr hb), or_iff_left_of_imp⟩
@[simp] theorem or_iff_right_iff_imp : (a ∨ b ↔ b) ↔ (a → b) :=
by rw [or_comm, or_iff_left_iff_imp]
/-! ### Declarations about distributivity -/
/-- `∧` distributes over `∨` (on the left). -/
theorem and_or_distrib_left : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) :=
⟨λ ⟨ha, hbc⟩, hbc.imp (and.intro ha) (and.intro ha),
or.rec (and.imp_right or.inl) (and.imp_right or.inr)⟩
/-- `∧` distributes over `∨` (on the right). -/
theorem or_and_distrib_right : (a ∨ b) ∧ c ↔ (a ∧ c) ∨ (b ∧ c) :=
(and.comm.trans and_or_distrib_left).trans (or_congr and.comm and.comm)
/-- `∨` distributes over `∧` (on the left). -/
theorem or_and_distrib_left : a ∨ (b ∧ c) ↔ (a ∨ b) ∧ (a ∨ c) :=
⟨or.rec (λha, and.intro (or.inl ha) (or.inl ha)) (and.imp or.inr or.inr),
and.rec $ or.rec (imp_intro ∘ or.inl) (or.imp_right ∘ and.intro)⟩
/-- `∨` distributes over `∧` (on the right). -/
theorem and_or_distrib_right : (a ∧ b) ∨ c ↔ (a ∨ c) ∧ (b ∨ c) :=
(or.comm.trans or_and_distrib_left).trans (and_congr or.comm or.comm)
@[simp] lemma or_self_left : a ∨ a ∨ b ↔ a ∨ b :=
⟨λ h, h.elim or.inl id, λ h, h.elim or.inl (or.inr ∘ or.inr)⟩
@[simp] lemma or_self_right : (a ∨ b) ∨ b ↔ a ∨ b :=
⟨λ h, h.elim id or.inr, λ h, h.elim (or.inl ∘ or.inl) or.inr⟩
/-! Declarations about `iff` -/
theorem iff_of_true (ha : a) (hb : b) : a ↔ b :=
⟨λ_, hb, λ _, ha⟩
theorem iff_of_false (ha : ¬a) (hb : ¬b) : a ↔ b :=
⟨ha.elim, hb.elim⟩
theorem iff_true_left (ha : a) : (a ↔ b) ↔ b :=
⟨λ h, h.1 ha, iff_of_true ha⟩
theorem iff_true_right (ha : a) : (b ↔ a) ↔ b :=
iff.comm.trans (iff_true_left ha)
theorem iff_false_left (ha : ¬a) : (a ↔ b) ↔ ¬b :=
⟨λ h, mt h.2 ha, iff_of_false ha⟩
theorem iff_false_right (ha : ¬a) : (b ↔ a) ↔ ¬b :=
iff.comm.trans (iff_false_left ha)
@[simp]
lemma iff_mpr_iff_true_intro {P : Prop} (h : P) : iff.mpr (iff_true_intro h) true.intro = h := rfl
-- See Note [decidable namespace]
protected theorem decidable.not_or_of_imp [decidable a] (h : a → b) : ¬ a ∨ b :=
if ha : a then or.inr (h ha) else or.inl ha
theorem not_or_of_imp : (a → b) → ¬ a ∨ b := decidable.not_or_of_imp
-- See Note [decidable namespace]
protected theorem decidable.imp_iff_not_or [decidable a] : (a → b) ↔ (¬ a ∨ b) :=
⟨decidable.not_or_of_imp, or.neg_resolve_left⟩
theorem imp_iff_not_or : (a → b) ↔ (¬ a ∨ b) := decidable.imp_iff_not_or
-- See Note [decidable namespace]
protected theorem decidable.imp_or_distrib [decidable a] : (a → b ∨ c) ↔ (a → b) ∨ (a → c) :=
by simp [decidable.imp_iff_not_or, or.comm, or.left_comm]
theorem imp_or_distrib : (a → b ∨ c) ↔ (a → b) ∨ (a → c) := decidable.imp_or_distrib
-- See Note [decidable namespace]
protected theorem decidable.imp_or_distrib' [decidable b] : (a → b ∨ c) ↔ (a → b) ∨ (a → c) :=
by by_cases b; simp [h, or_iff_right_of_imp ((∘) false.elim)]
theorem imp_or_distrib' : (a → b ∨ c) ↔ (a → b) ∨ (a → c) := decidable.imp_or_distrib'
theorem not_imp_of_and_not : a ∧ ¬ b → ¬ (a → b)
| ⟨ha, hb⟩ h := hb $ h ha
-- See Note [decidable namespace]
protected theorem decidable.not_imp [decidable a] : ¬(a → b) ↔ a ∧ ¬b :=
⟨λ h, ⟨decidable.of_not_imp h, not_of_not_imp h⟩, not_imp_of_and_not⟩
theorem not_imp : ¬(a → b) ↔ a ∧ ¬b := decidable.not_imp
-- for monotonicity
lemma imp_imp_imp (h₀ : c → a) (h₁ : b → d) : (a → b) → (c → d) :=
assume (h₂ : a → b), h₁ ∘ h₂ ∘ h₀
-- See Note [decidable namespace]
protected theorem decidable.peirce (a b : Prop) [decidable a] : ((a → b) → a) → a :=
if ha : a then λ h, ha else λ h, h ha.elim
theorem peirce (a b : Prop) : ((a → b) → a) → a := decidable.peirce _ _
theorem peirce' {a : Prop} (H : ∀ b : Prop, (a → b) → a) : a := H _ id
-- See Note [decidable namespace]
protected theorem decidable.not_iff_not [decidable a] [decidable b] : (¬ a ↔ ¬ b) ↔ (a ↔ b) :=
by rw [@iff_def (¬ a), @iff_def' a]; exact and_congr decidable.not_imp_not decidable.not_imp_not
theorem not_iff_not : (¬ a ↔ ¬ b) ↔ (a ↔ b) := decidable.not_iff_not
-- See Note [decidable namespace]
protected theorem decidable.not_iff_comm [decidable a] [decidable b] : (¬ a ↔ b) ↔ (¬ b ↔ a) :=
by rw [@iff_def (¬ a), @iff_def (¬ b)]; exact and_congr decidable.not_imp_comm imp_not_comm
theorem not_iff_comm : (¬ a ↔ b) ↔ (¬ b ↔ a) := decidable.not_iff_comm
-- See Note [decidable namespace]
protected theorem decidable.not_iff : ∀ [decidable b], ¬ (a ↔ b) ↔ (¬ a ↔ b) :=
by intro h; cases h; simp only [h, iff_true, iff_false]
theorem not_iff : ¬ (a ↔ b) ↔ (¬ a ↔ b) := decidable.not_iff
-- See Note [decidable namespace]
protected theorem decidable.iff_not_comm [decidable a] [decidable b] : (a ↔ ¬ b) ↔ (b ↔ ¬ a) :=
by rw [@iff_def a, @iff_def b]; exact and_congr imp_not_comm decidable.not_imp_comm
theorem iff_not_comm : (a ↔ ¬ b) ↔ (b ↔ ¬ a) := decidable.iff_not_comm
-- See Note [decidable namespace]
protected theorem decidable.iff_iff_and_or_not_and_not [decidable b] :
(a ↔ b) ↔ (a ∧ b) ∨ (¬ a ∧ ¬ b) :=
by { split; intro h,
{ rw h; by_cases b; [left,right]; split; assumption },
{ cases h with h h; cases h; split; intro; { contradiction <|> assumption } } }
theorem iff_iff_and_or_not_and_not : (a ↔ b) ↔ (a ∧ b) ∨ (¬ a ∧ ¬ b) :=
decidable.iff_iff_and_or_not_and_not
lemma decidable.iff_iff_not_or_and_or_not [decidable a] [decidable b] :
(a ↔ b) ↔ ((¬a ∨ b) ∧ (a ∨ ¬b)) :=
begin
rw [iff_iff_implies_and_implies a b],
simp only [decidable.imp_iff_not_or, or.comm]
end
lemma iff_iff_not_or_and_or_not : (a ↔ b) ↔ ((¬a ∨ b) ∧ (a ∨ ¬b)) :=
decidable.iff_iff_not_or_and_or_not
-- See Note [decidable namespace]
protected theorem decidable.not_and_not_right [decidable b] : ¬(a ∧ ¬b) ↔ (a → b) :=
⟨λ h ha, h.decidable_imp_symm $ and.intro ha, λ h ⟨ha, hb⟩, hb $ h ha⟩
theorem not_and_not_right : ¬(a ∧ ¬b) ↔ (a → b) := decidable.not_and_not_right
/-- Transfer decidability of `a` to decidability of `b`, if the propositions are equivalent.
**Important**: this function should be used instead of `rw` on `decidable b`, because the
kernel will get stuck reducing the usage of `propext` otherwise,
and `dec_trivial` will not work. -/
@[inline] def decidable_of_iff (a : Prop) (h : a ↔ b) [D : decidable a] : decidable b :=
decidable_of_decidable_of_iff D h
/-- Transfer decidability of `b` to decidability of `a`, if the propositions are equivalent.
This is the same as `decidable_of_iff` but the iff is flipped. -/
@[inline] def decidable_of_iff' (b : Prop) (h : a ↔ b) [D : decidable b] : decidable a :=
decidable_of_decidable_of_iff D h.symm
/-- Prove that `a` is decidable by constructing a boolean `b` and a proof that `b ↔ a`.
(This is sometimes taken as an alternate definition of decidability.) -/
def decidable_of_bool : ∀ (b : bool) (h : b ↔ a), decidable a
| tt h := is_true (h.1 rfl)
| ff h := is_false (mt h.2 bool.ff_ne_tt)
/-! ### De Morgan's laws -/
theorem not_and_of_not_or_not (h : ¬ a ∨ ¬ b) : ¬ (a ∧ b)
| ⟨ha, hb⟩ := or.elim h (absurd ha) (absurd hb)
-- See Note [decidable namespace]
protected theorem decidable.not_and_distrib [decidable a] : ¬ (a ∧ b) ↔ ¬a ∨ ¬b :=
⟨λ h, if ha : a then or.inr (λ hb, h ⟨ha, hb⟩) else or.inl ha, not_and_of_not_or_not⟩
-- See Note [decidable namespace]
protected theorem decidable.not_and_distrib' [decidable b] : ¬ (a ∧ b) ↔ ¬a ∨ ¬b :=
⟨λ h, if hb : b then or.inl (λ ha, h ⟨ha, hb⟩) else or.inr hb, not_and_of_not_or_not⟩
/-- One of de Morgan's laws: the negation of a conjunction is logically equivalent to the
disjunction of the negations. -/
theorem not_and_distrib : ¬ (a ∧ b) ↔ ¬a ∨ ¬b := decidable.not_and_distrib
@[simp] theorem not_and : ¬ (a ∧ b) ↔ (a → ¬ b) := and_imp
theorem not_and' : ¬ (a ∧ b) ↔ b → ¬a :=
not_and.trans imp_not_comm
/-- One of de Morgan's laws: the negation of a disjunction is logically equivalent to the
conjunction of the negations. -/
theorem not_or_distrib : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b :=
⟨λ h, ⟨λ ha, h (or.inl ha), λ hb, h (or.inr hb)⟩,
λ ⟨h₁, h₂⟩ h, or.elim h h₁ h₂⟩
-- See Note [decidable namespace]
protected theorem decidable.or_iff_not_and_not [decidable a] [decidable b] : a ∨ b ↔ ¬ (¬a ∧ ¬b) :=
by rw [← not_or_distrib, decidable.not_not]
theorem or_iff_not_and_not : a ∨ b ↔ ¬ (¬a ∧ ¬b) := decidable.or_iff_not_and_not
-- See Note [decidable namespace]
protected theorem decidable.and_iff_not_or_not [decidable a] [decidable b] :
a ∧ b ↔ ¬ (¬ a ∨ ¬ b) :=
by rw [← decidable.not_and_distrib, decidable.not_not]
theorem and_iff_not_or_not : a ∧ b ↔ ¬ (¬ a ∨ ¬ b) := decidable.and_iff_not_or_not
end propositional
/-! ### Declarations about equality -/
section equality
variables {α : Sort*} {a b : α}
@[simp] theorem heq_iff_eq : a == b ↔ a = b :=
⟨eq_of_heq, heq_of_eq⟩
theorem proof_irrel_heq {p q : Prop} (hp : p) (hq : q) : hp == hq :=
have p = q, from propext ⟨λ _, hq, λ _, hp⟩,
by subst q; refl
theorem ne_of_mem_of_not_mem {α β} [has_mem α β] {s : β} {a b : α}
(h : a ∈ s) : b ∉ s → a ≠ b :=
mt $ λ e, e ▸ h
lemma ne_of_apply_ne {α β : Sort*} (f : α → β) {x y : α} (h : f x ≠ f y) : x ≠ y :=
λ (w : x = y), h (congr_arg f w)
theorem eq_equivalence : equivalence (@eq α) :=
⟨eq.refl, @eq.symm _, @eq.trans _⟩
/-- Transport through trivial families is the identity. -/
@[simp]
lemma eq_rec_constant {α : Sort*} {a a' : α} {β : Sort*} (y : β) (h : a = a') :
(@eq.rec α a (λ a, β) y a' h) = y :=
by { cases h, refl, }
@[simp]
lemma eq_mp_eq_cast {α β : Sort*} (h : α = β) : eq.mp h = cast h := rfl
@[simp]
lemma eq_mpr_eq_cast {α β : Sort*} (h : α = β) : eq.mpr h = cast h.symm := rfl
@[simp]
lemma cast_cast : ∀ {α β γ : Sort*} (ha : α = β) (hb : β = γ) (a : α),
cast hb (cast ha a) = cast (ha.trans hb) a
| _ _ _ rfl rfl a := rfl
@[simp] lemma congr_refl_left {α β : Sort*} (f : α → β) {a b : α} (h : a = b) :
congr (eq.refl f) h = congr_arg f h :=
rfl
@[simp] lemma congr_refl_right {α β : Sort*} {f g : α → β} (h : f = g) (a : α) :
congr h (eq.refl a) = congr_fun h a :=
rfl
@[simp] lemma congr_arg_refl {α β : Sort*} (f : α → β) (a : α) :
congr_arg f (eq.refl a) = eq.refl (f a) :=
rfl
@[simp] lemma congr_fun_rfl {α β : Sort*} (f : α → β) (a : α) :
congr_fun (eq.refl f) a = eq.refl (f a) :=
rfl
@[simp] lemma congr_fun_congr_arg {α β γ : Sort*} (f : α → β → γ) {a a' : α} (p : a = a') (b : β) :
congr_fun (congr_arg f p) b = congr_arg (λ a, f a b) p :=
rfl
lemma heq_of_cast_eq :
∀ {α β : Sort*} {a : α} {a' : β} (e : α = β) (h₂ : cast e a = a'), a == a'
| α ._ a a' rfl h := eq.rec_on h (heq.refl _)
lemma cast_eq_iff_heq {α β : Sort*} {a : α} {a' : β} {e : α = β} : cast e a = a' ↔ a == a' :=
⟨heq_of_cast_eq _, λ h, by cases h; refl⟩
lemma rec_heq_of_heq {β} {C : α → Sort*} {x : C a} {y : β} (eq : a = b) (h : x == y) :
@eq.rec α a C x b eq == y :=
by subst eq; exact h
protected lemma eq.congr {x₁ x₂ y₁ y₂ : α} (h₁ : x₁ = y₁) (h₂ : x₂ = y₂) :
(x₁ = x₂) ↔ (y₁ = y₂) :=
by { subst h₁, subst h₂ }
lemma eq.congr_left {x y z : α} (h : x = y) : x = z ↔ y = z := by rw [h]
lemma eq.congr_right {x y z : α} (h : x = y) : z = x ↔ z = y := by rw [h]
lemma congr_arg2 {α β γ : Type*} (f : α → β → γ) {x x' : α} {y y' : β}
(hx : x = x') (hy : y = y') : f x y = f x' y' :=
by { subst hx, subst hy }
end equality
/-! ### Declarations about quantifiers -/
section quantifiers
variables {α : Sort*} {β : Sort*} {p q : α → Prop} {b : Prop}
lemma forall_imp (h : ∀ a, p a → q a) : (∀ a, p a) → ∀ a, q a :=
λ h' a, h a (h' a)
lemma forall₂_congr {p q : α → β → Prop} (h : ∀ a b, p a b ↔ q a b) :
(∀ a b, p a b) ↔ (∀ a b, q a b) :=
forall_congr (λ a, forall_congr (h a))
lemma forall₃_congr {γ : Sort*} {p q : α → β → γ → Prop}
(h : ∀ a b c, p a b c ↔ q a b c) :
(∀ a b c, p a b c) ↔ (∀ a b c, q a b c) :=
forall_congr (λ a, forall₂_congr (h a))
lemma forall₄_congr {γ δ : Sort*} {p q : α → β → γ → δ → Prop}
(h : ∀ a b c d, p a b c d ↔ q a b c d) :
(∀ a b c d, p a b c d) ↔ (∀ a b c d, q a b c d) :=
forall_congr (λ a, forall₃_congr (h a))
lemma Exists.imp (h : ∀ a, (p a → q a)) (p : ∃ a, p a) : ∃ a, q a := exists_imp_exists h p
lemma exists_imp_exists' {p : α → Prop} {q : β → Prop} (f : α → β) (hpq : ∀ a, p a → q (f a))
(hp : ∃ a, p a) : ∃ b, q b :=
exists.elim hp (λ a hp', ⟨_, hpq _ hp'⟩)
lemma exists₂_congr {p q : α → β → Prop} (h : ∀ a b, p a b ↔ q a b) :
(∃ a b, p a b) ↔ (∃ a b, q a b) :=
exists_congr (λ a, exists_congr (h a))
lemma exists₃_congr {γ : Sort*} {p q : α → β → γ → Prop}
(h : ∀ a b c, p a b c ↔ q a b c) :
(∃ a b c, p a b c) ↔ (∃ a b c, q a b c) :=
exists_congr (λ a, exists₂_congr (h a))
lemma exists₄_congr {γ δ : Sort*} {p q : α → β → γ → δ → Prop}
(h : ∀ a b c d, p a b c d ↔ q a b c d) :
(∃ a b c d, p a b c d) ↔ (∃ a b c d, q a b c d) :=
exists_congr (λ a, exists₃_congr (h a))
theorem forall_swap {p : α → β → Prop} : (∀ x y, p x y) ↔ ∀ y x, p x y :=
⟨function.swap, function.swap⟩
theorem exists_swap {p : α → β → Prop} : (∃ x y, p x y) ↔ ∃ y x, p x y :=
⟨λ ⟨x, y, h⟩, ⟨y, x, h⟩, λ ⟨y, x, h⟩, ⟨x, y, h⟩⟩
@[simp] theorem exists_imp_distrib : ((∃ x, p x) → b) ↔ ∀ x, p x → b :=
⟨λ h x hpx, h ⟨x, hpx⟩, λ h ⟨x, hpx⟩, h x hpx⟩
/--
Extract an element from a existential statement, using `classical.some`.
-/
-- This enables projection notation.
@[reducible] noncomputable def Exists.some {p : α → Prop} (P : ∃ a, p a) : α := classical.some P
/--
Show that an element extracted from `P : ∃ a, p a` using `P.some` satisfies `p`.
-/
lemma Exists.some_spec {p : α → Prop} (P : ∃ a, p a) : p (P.some) := classical.some_spec P
--theorem forall_not_of_not_exists (h : ¬ ∃ x, p x) : ∀ x, ¬ p x :=
--forall_imp_of_exists_imp h
theorem not_exists_of_forall_not (h : ∀ x, ¬ p x) : ¬ ∃ x, p x :=
exists_imp_distrib.2 h
@[simp] theorem not_exists : (¬ ∃ x, p x) ↔ ∀ x, ¬ p x :=
exists_imp_distrib
theorem not_forall_of_exists_not : (∃ x, ¬ p x) → ¬ ∀ x, p x
| ⟨x, hn⟩ h := hn (h x)
-- See Note [decidable namespace]
protected theorem decidable.not_forall {p : α → Prop}
[decidable (∃ x, ¬ p x)] [∀ x, decidable (p x)] : (¬ ∀ x, p x) ↔ ∃ x, ¬ p x :=
⟨not.decidable_imp_symm $ λ nx x, nx.decidable_imp_symm $ λ h, ⟨x, h⟩,
not_forall_of_exists_not⟩
@[simp] theorem not_forall {p : α → Prop} : (¬ ∀ x, p x) ↔ ∃ x, ¬ p x := decidable.not_forall
-- See Note [decidable namespace]
protected theorem decidable.not_forall_not [decidable (∃ x, p x)] :
(¬ ∀ x, ¬ p x) ↔ ∃ x, p x :=
(@decidable.not_iff_comm _ _ _ (decidable_of_iff (¬ ∃ x, p x) not_exists)).1 not_exists
theorem not_forall_not : (¬ ∀ x, ¬ p x) ↔ ∃ x, p x := decidable.not_forall_not
-- See Note [decidable namespace]
protected theorem decidable.not_exists_not [∀ x, decidable (p x)] : (¬ ∃ x, ¬ p x) ↔ ∀ x, p x :=
by simp [decidable.not_not]
@[simp] theorem not_exists_not : (¬ ∃ x, ¬ p x) ↔ ∀ x, p x := decidable.not_exists_not
-- TODO: duplicate of a lemma in core
theorem forall_true_iff : (α → true) ↔ true :=
implies_true_iff α
-- Unfortunately this causes simp to loop sometimes, so we
-- add the 2 and 3 cases as simp lemmas instead
theorem forall_true_iff' (h : ∀ a, p a ↔ true) : (∀ a, p a) ↔ true :=
iff_true_intro (λ _, of_iff_true (h _))
@[simp] theorem forall_2_true_iff {β : α → Sort*} : (∀ a, β a → true) ↔ true :=
forall_true_iff' $ λ _, forall_true_iff
@[simp] theorem forall_3_true_iff {β : α → Sort*} {γ : Π a, β a → Sort*} :
(∀ a (b : β a), γ a b → true) ↔ true :=
forall_true_iff' $ λ _, forall_2_true_iff
lemma exists_unique.exists {α : Sort*} {p : α → Prop} (h : ∃! x, p x) : ∃ x, p x :=
exists.elim h (λ x hx, ⟨x, and.left hx⟩)
@[simp] lemma exists_unique_iff_exists {α : Sort*} [subsingleton α] {p : α → Prop} :
(∃! x, p x) ↔ ∃ x, p x :=
⟨λ h, h.exists, Exists.imp $ λ x hx, ⟨hx, λ y _, subsingleton.elim y x⟩⟩
@[simp] theorem forall_const (α : Sort*) [i : nonempty α] : (α → b) ↔ b :=
⟨i.elim, λ hb x, hb⟩
@[simp] theorem exists_const (α : Sort*) [i : nonempty α] : (∃ x : α, b) ↔ b :=
⟨λ ⟨x, h⟩, h, i.elim exists.intro⟩
theorem exists_unique_const (α : Sort*) [i : nonempty α] [subsingleton α] :
(∃! x : α, b) ↔ b :=
by simp
theorem forall_and_distrib : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=
⟨λ h, ⟨λ x, (h x).left, λ x, (h x).right⟩, λ ⟨h₁, h₂⟩ x, ⟨h₁ x, h₂ x⟩⟩
theorem exists_or_distrib : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=
⟨λ ⟨x, hpq⟩, hpq.elim (λ hpx, or.inl ⟨x, hpx⟩) (λ hqx, or.inr ⟨x, hqx⟩),
λ hepq, hepq.elim (λ ⟨x, hpx⟩, ⟨x, or.inl hpx⟩) (λ ⟨x, hqx⟩, ⟨x, or.inr hqx⟩)⟩
@[simp] theorem exists_and_distrib_left {q : Prop} {p : α → Prop} :
(∃x, q ∧ p x) ↔ q ∧ (∃x, p x) :=
⟨λ ⟨x, hq, hp⟩, ⟨hq, x, hp⟩, λ ⟨hq, x, hp⟩, ⟨x, hq, hp⟩⟩
@[simp] theorem exists_and_distrib_right {q : Prop} {p : α → Prop} :
(∃x, p x ∧ q) ↔ (∃x, p x) ∧ q :=
by simp [and_comm]
@[simp] theorem forall_eq {a' : α} : (∀a, a = a' → p a) ↔ p a' :=
⟨λ h, h a' rfl, λ h a e, e.symm ▸ h⟩
@[simp] theorem forall_eq' {a' : α} : (∀a, a' = a → p a) ↔ p a' :=
by simp [@eq_comm _ a']
-- this lemma is needed to simplify the output of `list.mem_cons_iff`
@[simp] theorem forall_eq_or_imp {a' : α} : (∀ a, a = a' ∨ q a → p a) ↔ p a' ∧ ∀ a, q a → p a :=
by simp only [or_imp_distrib, forall_and_distrib, forall_eq]
@[simp] theorem exists_eq {a' : α} : ∃ a, a = a' := ⟨_, rfl⟩
@[simp] theorem exists_eq' {a' : α} : ∃ a, a' = a := ⟨_, rfl⟩
@[simp] theorem exists_eq_left {a' : α} : (∃ a, a = a' ∧ p a) ↔ p a' :=
⟨λ ⟨a, e, h⟩, e ▸ h, λ h, ⟨_, rfl, h⟩⟩
@[simp] theorem exists_eq_right {a' : α} : (∃ a, p a ∧ a = a') ↔ p a' :=
(exists_congr $ by exact λ a, and.comm).trans exists_eq_left
@[simp] theorem exists_eq_right_right {a' : α} :
(∃ (a : α), p a ∧ b ∧ a = a') ↔ p a' ∧ b :=
⟨λ ⟨_, hp, hq, rfl⟩, ⟨hp, hq⟩, λ ⟨hp, hq⟩, ⟨a', hp, hq, rfl⟩⟩
@[simp] theorem exists_eq_right_right' {a' : α} :
(∃ (a : α), p a ∧ b ∧ a' = a) ↔ p a' ∧ b :=
⟨λ ⟨_, hp, hq, rfl⟩, ⟨hp, hq⟩, λ ⟨hp, hq⟩, ⟨a', hp, hq, rfl⟩⟩
@[simp] theorem exists_apply_eq_apply {α β : Type*} (f : α → β) (a' : α) : ∃ a, f a = f a' :=
⟨a', rfl⟩
@[simp] theorem exists_apply_eq_apply' {α β : Type*} (f : α → β) (a' : α) : ∃ a, f a' = f a :=
⟨a', rfl⟩
@[simp] theorem exists_exists_and_eq_and {f : α → β} {p : α → Prop} {q : β → Prop} :
(∃ b, (∃ a, p a ∧ f a = b) ∧ q b) ↔ ∃ a, p a ∧ q (f a) :=
⟨λ ⟨b, ⟨a, ha, hab⟩, hb⟩, ⟨a, ha, hab.symm ▸ hb⟩, λ ⟨a, hp, hq⟩, ⟨f a, ⟨a, hp, rfl⟩, hq⟩⟩
@[simp] theorem exists_exists_eq_and {f : α → β} {p : β → Prop} :
(∃ b, (∃ a, f a = b) ∧ p b) ↔ ∃ a, p (f a) :=
⟨λ ⟨b, ⟨a, ha⟩, hb⟩, ⟨a, ha.symm ▸ hb⟩, λ ⟨a, ha⟩, ⟨f a, ⟨a, rfl⟩, ha⟩⟩
@[simp] lemma exists_or_eq_left (y : α) (p : α → Prop) : ∃ (x : α), x = y ∨ p x :=
⟨y, or.inl rfl⟩
@[simp] lemma exists_or_eq_right (y : α) (p : α → Prop) : ∃ (x : α), p x ∨ x = y :=
⟨y, or.inr rfl⟩
@[simp] lemma exists_or_eq_left' (y : α) (p : α → Prop) : ∃ (x : α), y = x ∨ p x :=
⟨y, or.inl rfl⟩
@[simp] lemma exists_or_eq_right' (y : α) (p : α → Prop) : ∃ (x : α), p x ∨ y = x :=
⟨y, or.inr rfl⟩
@[simp] theorem forall_apply_eq_imp_iff {f : α → β} {p : β → Prop} :
(∀ a, ∀ b, f a = b → p b) ↔ (∀ a, p (f a)) :=
⟨λ h a, h a (f a) rfl, λ h a b hab, hab ▸ h a⟩
@[simp] theorem forall_apply_eq_imp_iff' {f : α → β} {p : β → Prop} :
(∀ b, ∀ a, f a = b → p b) ↔ (∀ a, p (f a)) :=
by { rw forall_swap, simp }
@[simp] theorem forall_eq_apply_imp_iff {f : α → β} {p : β → Prop} :
(∀ a, ∀ b, b = f a → p b) ↔ (∀ a, p (f a)) :=
by simp [@eq_comm _ _ (f _)]
@[simp] theorem forall_eq_apply_imp_iff' {f : α → β} {p : β → Prop} :
(∀ b, ∀ a, b = f a → p b) ↔ (∀ a, p (f a)) :=
by { rw forall_swap, simp }
@[simp] theorem forall_apply_eq_imp_iff₂ {f : α → β} {p : α → Prop} {q : β → Prop} :
(∀ b, ∀ a, p a → f a = b → q b) ↔ ∀ a, p a → q (f a) :=
⟨λ h a ha, h (f a) a ha rfl, λ h b a ha hb, hb ▸ h a ha⟩
@[simp] theorem exists_eq_left' {a' : α} : (∃ a, a' = a ∧ p a) ↔ p a' :=
by simp [@eq_comm _ a']
@[simp] theorem exists_eq_right' {a' : α} : (∃ a, p a ∧ a' = a) ↔ p a' :=
by simp [@eq_comm _ a']
theorem exists_comm {p : α → β → Prop} : (∃ a b, p a b) ↔ ∃ b a, p a b :=
⟨λ ⟨a, b, h⟩, ⟨b, a, h⟩, λ ⟨b, a, h⟩, ⟨a, b, h⟩⟩
theorem forall_or_of_or_forall (h : b ∨ ∀x, p x) (x) : b ∨ p x :=
h.imp_right $ λ h₂, h₂ x
-- See Note [decidable namespace]
protected theorem decidable.forall_or_distrib_left {q : Prop} {p : α → Prop} [decidable q] :
(∀x, q ∨ p x) ↔ q ∨ (∀x, p x) :=
⟨λ h, if hq : q then or.inl hq else or.inr $ λ x, (h x).resolve_left hq,
forall_or_of_or_forall⟩
theorem forall_or_distrib_left {q : Prop} {p : α → Prop} :
(∀x, q ∨ p x) ↔ q ∨ (∀x, p x) := decidable.forall_or_distrib_left
-- See Note [decidable namespace]
protected theorem decidable.forall_or_distrib_right {q : Prop} {p : α → Prop} [decidable q] :
(∀x, p x ∨ q) ↔ (∀x, p x) ∨ q :=
by simp [or_comm, decidable.forall_or_distrib_left]
theorem forall_or_distrib_right {q : Prop} {p : α → Prop} :
(∀x, p x ∨ q) ↔ (∀x, p x) ∨ q := decidable.forall_or_distrib_right
/-- A predicate holds everywhere on the image of a surjective functions iff
it holds everywhere. -/
theorem forall_iff_forall_surj
{α β : Type*} {f : α → β} (h : function.surjective f) {P : β → Prop} :
(∀ a, P (f a)) ↔ ∀ b, P b :=
⟨λ ha b, by cases h b with a hab; rw ←hab; exact ha a, λ hb a, hb $ f a⟩
@[simp] theorem exists_prop {p q : Prop} : (∃ h : p, q) ↔ p ∧ q :=
⟨λ ⟨h₁, h₂⟩, ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨h₁, h₂⟩⟩
theorem exists_unique_prop {p q : Prop} : (∃! h : p, q) ↔ p ∧ q :=
by simp
@[simp] theorem exists_false : ¬ (∃a:α, false) := assume ⟨a, h⟩, h
@[simp] lemma exists_unique_false : ¬ (∃! (a : α), false) := assume ⟨a, h, h'⟩, h
theorem Exists.fst {p : b → Prop} : Exists p → b
| ⟨h, _⟩ := h
theorem Exists.snd {p : b → Prop} : ∀ h : Exists p, p h.fst
| ⟨_, h⟩ := h
theorem forall_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∀ h' : p, q h') ↔ q h :=
@forall_const (q h) p ⟨h⟩
theorem exists_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∃ h' : p, q h') ↔ q h :=
@exists_const (q h) p ⟨h⟩
theorem exists_unique_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∃! h' : p, q h') ↔ q h :=
@exists_unique_const (q h) p ⟨h⟩ _
theorem forall_prop_of_false {p : Prop} {q : p → Prop} (hn : ¬ p) :
(∀ h' : p, q h') ↔ true :=
iff_true_intro $ λ h, hn.elim h
theorem exists_prop_of_false {p : Prop} {q : p → Prop} : ¬ p → ¬ (∃ h' : p, q h') :=
mt Exists.fst
@[congr] lemma exists_prop_congr {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : Exists q ↔ ∃ h : p', q' (hp.2 h) :=
⟨λ ⟨_, _⟩, ⟨hp.1 ‹_›, (hq _).1 ‹_›⟩, λ ⟨_, _⟩, ⟨_, (hq _).2 ‹_›⟩⟩
@[congr] lemma exists_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : Exists q = ∃ h : p', q' (hp.2 h) :=
propext (exists_prop_congr hq _)
@[simp] lemma exists_true_left (p : true → Prop) : (∃ x, p x) ↔ p true.intro :=
exists_prop_of_true _
@[simp] lemma exists_false_left (p : false → Prop) : ¬ ∃ x, p x :=
exists_prop_of_false not_false
lemma exists_unique.unique {α : Sort*} {p : α → Prop} (h : ∃! x, p x)
{y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ :=
unique_of_exists_unique h py₁ py₂
@[congr] lemma forall_prop_congr {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) ↔ ∀ h : p', q' (hp.2 h) :=
⟨λ h1 h2, (hq _).1 (h1 (hp.2 _)), λ h1 h2, (hq _).2 (h1 (hp.1 h2))⟩
@[congr] lemma forall_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
propext (forall_prop_congr hq _)
@[simp] lemma forall_true_left (p : true → Prop) : (∀ x, p x) ↔ p true.intro :=
forall_prop_of_true _
@[simp] lemma forall_false_left (p : false → Prop) : (∀ x, p x) ↔ true :=
forall_prop_of_false not_false
lemma exists_unique.elim2 {α : Sort*} {p : α → Sort*} [∀ x, subsingleton (p x)]
{q : Π x (h : p x), Prop} {b : Prop} (h₂ : ∃! x (h : p x), q x h)
(h₁ : ∀ x (h : p x), q x h → (∀ y (hy : p y), q y hy → y = x) → b) : b :=
begin
simp only [exists_unique_iff_exists] at h₂,
apply h₂.elim,
exact λ x ⟨hxp, hxq⟩ H, h₁ x hxp hxq (λ y hyp hyq, H y ⟨hyp, hyq⟩)
end
lemma exists_unique.intro2 {α : Sort*} {p : α → Sort*} [∀ x, subsingleton (p x)]
{q : Π (x : α) (h : p x), Prop} (w : α) (hp : p w) (hq : q w hp)
(H : ∀ y (hy : p y), q y hy → y = w) :
∃! x (hx : p x), q x hx :=
begin
simp only [exists_unique_iff_exists],
exact exists_unique.intro w ⟨hp, hq⟩ (λ y ⟨hyp, hyq⟩, H y hyp hyq)
end
lemma exists_unique.exists2 {α : Sort*} {p : α → Sort*} {q : Π (x : α) (h : p x), Prop}
(h : ∃! x (hx : p x), q x hx) :
∃ x (hx : p x), q x hx :=
h.exists.imp (λ x hx, hx.exists)
lemma exists_unique.unique2 {α : Sort*} {p : α → Sort*} [∀ x, subsingleton (p x)]
{q : Π (x : α) (hx : p x), Prop} (h : ∃! x (hx : p x), q x hx)
{y₁ y₂ : α} (hpy₁ : p y₁) (hqy₁ : q y₁ hpy₁)
(hpy₂ : p y₂) (hqy₂ : q y₂ hpy₂) : y₁ = y₂ :=
begin
simp only [exists_unique_iff_exists] at h,
exact h.unique ⟨hpy₁, hqy₁⟩ ⟨hpy₂, hqy₂⟩
end
end quantifiers
/-! ### Classical lemmas -/
namespace classical
variables {α : Sort*} {p : α → Prop}
theorem cases {p : Prop → Prop} (h1 : p true) (h2 : p false) : ∀a, p a :=
assume a, cases_on a h1 h2
/- use shortened names to avoid conflict when classical namespace is open. -/
noncomputable lemma dec (p : Prop) : decidable p := -- see Note [classical lemma]
by apply_instance
noncomputable lemma dec_pred (p : α → Prop) : decidable_pred p := -- see Note [classical lemma]
by apply_instance
noncomputable lemma dec_rel (p : α → α → Prop) : decidable_rel p := -- see Note [classical lemma]
by apply_instance
noncomputable lemma dec_eq (α : Sort*) : decidable_eq α := -- see Note [classical lemma]
by apply_instance
/--
We make decidability results that depends on `classical.choice` noncomputable lemmas.
* We have to mark them as noncomputable, because otherwise Lean will try to generate bytecode
for them, and fail because it depends on `classical.choice`.
* We make them lemmas, and not definitions, because otherwise later definitions will raise
\"failed to generate bytecode\" errors when writing something like
`letI := classical.dec_eq _`.
Cf. <https://leanprover-community.github.io/archive/stream/113488-general/topic/noncomputable.20theorem.html>
-/
library_note "classical lemma"
/-- Construct a function from a default value `H0`, and a function to use if there exists a value
satisfying the predicate. -/
@[elab_as_eliminator]
noncomputable def {u} exists_cases {C : Sort u} (H0 : C) (H : ∀ a, p a → C) : C :=
if h : ∃ a, p a then H (classical.some h) (classical.some_spec h) else H0
lemma some_spec2 {α : Sort*} {p : α → Prop} {h : ∃a, p a}
(q : α → Prop) (hpq : ∀a, p a → q a) : q (some h) :=
hpq _ $ some_spec _
/-- A version of classical.indefinite_description which is definitionally equal to a pair -/
noncomputable def subtype_of_exists {α : Type*} {P : α → Prop} (h : ∃ x, P x) : {x // P x} :=
⟨classical.some h, classical.some_spec h⟩
end classical
/-- This function has the same type as `exists.rec_on`, and can be used to case on an equality,
but `exists.rec_on` can only eliminate into Prop, while this version eliminates into any universe
using the axiom of choice. -/
@[elab_as_eliminator]
noncomputable def {u} exists.classical_rec_on
{α} {p : α → Prop} (h : ∃ a, p a) {C : Sort u} (H : ∀ a, p a → C) : C :=
H (classical.some h) (classical.some_spec h)
/-! ### Declarations about bounded quantifiers -/
section bounded_quantifiers
variables {α : Sort*} {r p q : α → Prop} {P Q : ∀ x, p x → Prop} {b : Prop}
theorem bex_def : (∃ x (h : p x), q x) ↔ ∃ x, p x ∧ q x :=
⟨λ ⟨x, px, qx⟩, ⟨x, px, qx⟩, λ ⟨x, px, qx⟩, ⟨x, px, qx⟩⟩
theorem bex.elim {b : Prop} : (∃ x h, P x h) → (∀ a h, P a h → b) → b
| ⟨a, h₁, h₂⟩ h' := h' a h₁ h₂
theorem bex.intro (a : α) (h₁ : p a) (h₂ : P a h₁) : ∃ x (h : p x), P x h :=
⟨a, h₁, h₂⟩
theorem ball_congr (H : ∀ x h, P x h ↔ Q x h) :
(∀ x h, P x h) ↔ (∀ x h, Q x h) :=
forall_congr $ λ x, forall_congr (H x)
theorem bex_congr (H : ∀ x h, P x h ↔ Q x h) :
(∃ x h, P x h) ↔ (∃ x h, Q x h) :=
exists_congr $ λ x, exists_congr (H x)
theorem bex_eq_left {a : α} : (∃ x (_ : x = a), p x) ↔ p a :=
by simp only [exists_prop, exists_eq_left]
theorem ball.imp_right (H : ∀ x h, (P x h → Q x h))
(h₁ : ∀ x h, P x h) (x h) : Q x h :=
H _ _ $ h₁ _ _
theorem bex.imp_right (H : ∀ x h, (P x h → Q x h)) :
(∃ x h, P x h) → ∃ x h, Q x h
| ⟨x, h, h'⟩ := ⟨_, _, H _ _ h'⟩
theorem ball.imp_left (H : ∀ x, p x → q x)
(h₁ : ∀ x, q x → r x) (x) (h : p x) : r x :=
h₁ _ $ H _ h
theorem bex.imp_left (H : ∀ x, p x → q x) :
(∃ x (_ : p x), r x) → ∃ x (_ : q x), r x
| ⟨x, hp, hr⟩ := ⟨x, H _ hp, hr⟩
theorem ball_of_forall (h : ∀ x, p x) (x) : p x :=
h x
theorem forall_of_ball (H : ∀ x, p x) (h : ∀ x, p x → q x) (x) : q x :=
h x $ H x
theorem bex_of_exists (H : ∀ x, p x) : (∃ x, q x) → ∃ x (_ : p x), q x
| ⟨x, hq⟩ := ⟨x, H x, hq⟩
theorem exists_of_bex : (∃ x (_ : p x), q x) → ∃ x, q x
| ⟨x, _, hq⟩ := ⟨x, hq⟩
@[simp] theorem bex_imp_distrib : ((∃ x h, P x h) → b) ↔ (∀ x h, P x h → b) :=
by simp
theorem not_bex : (¬ ∃ x h, P x h) ↔ ∀ x h, ¬ P x h :=
bex_imp_distrib
theorem not_ball_of_bex_not : (∃ x h, ¬ P x h) → ¬ ∀ x h, P x h
| ⟨x, h, hp⟩ al := hp $ al x h
-- See Note [decidable namespace]
protected theorem decidable.not_ball [decidable (∃ x h, ¬ P x h)] [∀ x h, decidable (P x h)] :
(¬ ∀ x h, P x h) ↔ (∃ x h, ¬ P x h) :=
⟨not.decidable_imp_symm $ λ nx x h, nx.decidable_imp_symm $ λ h', ⟨x, h, h'⟩,
not_ball_of_bex_not⟩
theorem not_ball : (¬ ∀ x h, P x h) ↔ (∃ x h, ¬ P x h) := decidable.not_ball
theorem ball_true_iff (p : α → Prop) : (∀ x, p x → true) ↔ true :=
iff_true_intro (λ h hrx, trivial)
theorem ball_and_distrib : (∀ x h, P x h ∧ Q x h) ↔ (∀ x h, P x h) ∧ (∀ x h, Q x h) :=
iff.trans (forall_congr $ λ x, forall_and_distrib) forall_and_distrib
theorem bex_or_distrib : (∃ x h, P x h ∨ Q x h) ↔ (∃ x h, P x h) ∨ (∃ x h, Q x h) :=
iff.trans (exists_congr $ λ x, exists_or_distrib) exists_or_distrib
theorem ball_or_left_distrib : (∀ x, p x ∨ q x → r x) ↔ (∀ x, p x → r x) ∧ (∀ x, q x → r x) :=
iff.trans (forall_congr $ λ x, or_imp_distrib) forall_and_distrib
theorem bex_or_left_distrib :
(∃ x (_ : p x ∨ q x), r x) ↔ (∃ x (_ : p x), r x) ∨ (∃ x (_ : q x), r x) :=
by simp only [exists_prop]; exact
iff.trans (exists_congr $ λ x, or_and_distrib_right) exists_or_distrib
end bounded_quantifiers
namespace classical
local attribute [instance] prop_decidable
theorem not_ball {α : Sort*} {p : α → Prop} {P : Π (x : α), p x → Prop} :
(¬ ∀ x h, P x h) ↔ (∃ x h, ¬ P x h) := _root_.not_ball
end classical
lemma ite_eq_iff {α} {p : Prop} [decidable p] {a b c : α} :
(if p then a else b) = c ↔ p ∧ a = c ∨ ¬p ∧ b = c :=
by by_cases p; simp *
@[simp] lemma ite_eq_left_iff {α} {p : Prop} [decidable p] {a b : α} :
(if p then a else b) = a ↔ (¬p → b = a) :=
by by_cases p; simp *
@[simp] lemma ite_eq_right_iff {α} {p : Prop} [decidable p] {a b : α} :
(if p then a else b) = b ↔ (p → a = b) :=
by by_cases p; simp *
lemma ite_eq_or_eq {α} {p : Prop} [decidable p] (a b : α) :
ite p a b = a ∨ ite p a b = b :=
decidable.by_cases (λ h, or.inl (if_pos h)) (λ h, or.inr (if_neg h))
/-! ### Declarations about `nonempty` -/
section nonempty
universe variables u v w
variables {α : Type u} {β : Type v} {γ : α → Type w}
attribute [simp] nonempty_of_inhabited
@[priority 20]
instance has_zero.nonempty [has_zero α] : nonempty α := ⟨0⟩
@[priority 20]
instance has_one.nonempty [has_one α] : nonempty α := ⟨1⟩
lemma exists_true_iff_nonempty {α : Sort*} : (∃a:α, true) ↔ nonempty α :=
iff.intro (λ⟨a, _⟩, ⟨a⟩) (λ⟨a⟩, ⟨a, trivial⟩)
@[simp] lemma nonempty_Prop {p : Prop} : nonempty p ↔ p :=
iff.intro (assume ⟨h⟩, h) (assume h, ⟨h⟩)
lemma not_nonempty_iff_imp_false {α : Sort*} : ¬ nonempty α ↔ α → false :=
⟨λ h a, h ⟨a⟩, λ h ⟨a⟩, h a⟩
@[simp] lemma nonempty_sigma : nonempty (Σa:α, γ a) ↔ (∃a:α, nonempty (γ a)) :=
iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩)
@[simp] lemma nonempty_subtype {α : Sort u} {p : α → Prop} : nonempty (subtype p) ↔ (∃a:α, p a) :=
iff.intro (assume ⟨⟨a, h⟩⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a, h⟩⟩)
@[simp] lemma nonempty_prod : nonempty (α × β) ↔ (nonempty α ∧ nonempty β) :=
iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩)
@[simp] lemma nonempty_pprod {α : Sort u} {β : Sort v} :
nonempty (pprod α β) ↔ (nonempty α ∧ nonempty β) :=
iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩)
@[simp] lemma nonempty_sum : nonempty (α ⊕ β) ↔ (nonempty α ∨ nonempty β) :=
iff.intro
(assume ⟨h⟩, match h with sum.inl a := or.inl ⟨a⟩ | sum.inr b := or.inr ⟨b⟩ end)
(assume h, match h with or.inl ⟨a⟩ := ⟨sum.inl a⟩ | or.inr ⟨b⟩ := ⟨sum.inr b⟩ end)
@[simp] lemma nonempty_psum {α : Sort u} {β : Sort v} :
nonempty (psum α β) ↔ (nonempty α ∨ nonempty β) :=
iff.intro
(assume ⟨h⟩, match h with psum.inl a := or.inl ⟨a⟩ | psum.inr b := or.inr ⟨b⟩ end)
(assume h, match h with or.inl ⟨a⟩ := ⟨psum.inl a⟩ | or.inr ⟨b⟩ := ⟨psum.inr b⟩ end)
@[simp] lemma nonempty_psigma {α : Sort u} {β : α → Sort v} :
nonempty (psigma β) ↔ (∃a:α, nonempty (β a)) :=
iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩)
@[simp] lemma nonempty_empty : ¬ nonempty empty :=
assume ⟨h⟩, h.elim
@[simp] lemma nonempty_ulift : nonempty (ulift α) ↔ nonempty α :=
iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩)
@[simp] lemma nonempty_plift {α : Sort u} : nonempty (plift α) ↔ nonempty α :=
iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩)
@[simp] lemma nonempty.forall {α : Sort u} {p : nonempty α → Prop} :
(∀h:nonempty α, p h) ↔ (∀a, p ⟨a⟩) :=
iff.intro (assume h a, h _) (assume h ⟨a⟩, h _)
@[simp] lemma nonempty.exists {α : Sort u} {p : nonempty α → Prop} :
(∃h:nonempty α, p h) ↔ (∃a, p ⟨a⟩) :=
iff.intro (assume ⟨⟨a⟩, h⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a⟩, h⟩)
lemma classical.nonempty_pi {α : Sort u} {β : α → Sort v} :
nonempty (Πa:α, β a) ↔ (∀a:α, nonempty (β a)) :=
iff.intro (assume ⟨f⟩ a, ⟨f a⟩) (assume f, ⟨assume a, classical.choice $ f a⟩)
/-- Using `classical.choice`, lifts a (`Prop`-valued) `nonempty` instance to a (`Type`-valued)
`inhabited` instance. `classical.inhabited_of_nonempty` already exists, in
`core/init/classical.lean`, but the assumption is not a type class argument,
which makes it unsuitable for some applications. -/
noncomputable def classical.inhabited_of_nonempty' {α : Sort u} [h : nonempty α] : inhabited α :=
⟨classical.choice h⟩
/-- Using `classical.choice`, extracts a term from a `nonempty` type. -/
@[reducible] protected noncomputable def nonempty.some {α : Sort u} (h : nonempty α) : α :=
classical.choice h
/-- Using `classical.choice`, extracts a term from a `nonempty` type. -/
@[reducible] protected noncomputable def classical.arbitrary (α : Sort u) [h : nonempty α] : α :=
classical.choice h
/-- Given `f : α → β`, if `α` is nonempty then `β` is also nonempty.
`nonempty` cannot be a `functor`, because `functor` is restricted to `Type`. -/
lemma nonempty.map {α : Sort u} {β : Sort v} (f : α → β) : nonempty α → nonempty β
| ⟨h⟩ := ⟨f h⟩
protected lemma nonempty.map2 {α β γ : Sort*} (f : α → β → γ) : nonempty α → nonempty β → nonempty γ
| ⟨x⟩ ⟨y⟩ := ⟨f x y⟩
protected lemma nonempty.congr {α : Sort u} {β : Sort v} (f : α → β) (g : β → α) :
nonempty α ↔ nonempty β :=
⟨nonempty.map f, nonempty.map g⟩
lemma nonempty.elim_to_inhabited {α : Sort*} [h : nonempty α] {p : Prop}
(f : inhabited α → p) : p :=
h.elim $ f ∘ inhabited.mk
instance {α β} [h : nonempty α] [h2 : nonempty β] : nonempty (α × β) :=
h.elim $ λ g, h2.elim $ λ g2, ⟨⟨g, g2⟩⟩
end nonempty
lemma subsingleton_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : subsingleton α :=
⟨λ x, false.elim $ not_nonempty_iff_imp_false.mp h x⟩
section ite
/-- A `dite` whose results do not actually depend on the condition may be reduced to an `ite`. -/
@[simp]
lemma dite_eq_ite (P : Prop) [decidable P] {α : Sort*} (x y : α) :
dite P (λ h, x) (λ h, y) = ite P x y := rfl
/-- A function applied to a `dite` is a `dite` of that function applied to each of the branches. -/
lemma apply_dite {α β : Sort*} (f : α → β) (P : Prop) [decidable P] (x : P → α) (y : ¬P → α) :
f (dite P x y) = dite P (λ h, f (x h)) (λ h, f (y h)) :=
by { by_cases h : P; simp [h] }
/-- A function applied to a `ite` is a `ite` of that function applied to each of the branches. -/
lemma apply_ite {α β : Sort*} (f : α → β) (P : Prop) [decidable P] (x y : α) :
f (ite P x y) = ite P (f x) (f y) :=
apply_dite f P (λ _, x) (λ _, y)
/-- A two-argument function applied to two `dite`s is a `dite` of that two-argument function
applied to each of the branches. -/
lemma apply_dite2 {α β γ : Sort*} (f : α → β → γ) (P : Prop) [decidable P] (a : P → α)
(b : ¬P → α) (c : P → β) (d : ¬P → β) :
f (dite P a b) (dite P c d) = dite P (λ h, f (a h) (c h)) (λ h, f (b h) (d h)) :=
by { by_cases h : P; simp [h] }
/-- A two-argument function applied to two `ite`s is a `ite` of that two-argument function
applied to each of the branches. -/
lemma apply_ite2 {α β γ : Sort*} (f : α → β → γ) (P : Prop) [decidable P] (a b : α) (c d : β) :
f (ite P a b) (ite P c d) = ite P (f a c) (f b d) :=
apply_dite2 f P (λ _, a) (λ _, b) (λ _, c) (λ _, d)
/-- A 'dite' producing a `Pi` type `Π a, β a`, applied to a value `x : α`
is a `dite` that applies either branch to `x`. -/
lemma dite_apply {α : Sort*} {β : α → Sort*} (P : Prop) [decidable P]
(f : P → Π a, β a) (g : ¬ P → Π a, β a) (x : α) :
(dite P f g) x = dite P (λ h, f h x) (λ h, g h x) :=
by { by_cases h : P; simp [h] }
/-- A 'ite' producing a `Pi` type `Π a, β a`, applied to a value `x : α`
is a `ite` that applies either branch to `x` -/
lemma ite_apply {α : Sort*} {β : α → Sort*} (P : Prop) [decidable P]
(f g : Π a, β a) (x : α) :
(ite P f g) x = ite P (f x) (g x) :=
dite_apply P (λ _, f) (λ _, g) x
/-- Negation of the condition `P : Prop` in a `dite` is the same as swapping the branches. -/
@[simp] lemma dite_not {α : Sort*} (P : Prop) [decidable P] (x : ¬ P → α) (y : ¬¬ P → α) :
dite (¬ P) x y = dite P (λ h, y (not_not_intro h)) x :=
by { by_cases h : P; simp [h] }
/-- Negation of the condition `P : Prop` in a `ite` is the same as swapping the branches. -/
@[simp] lemma ite_not {α : Sort*} (P : Prop) [decidable P] (x y : α) :
ite (¬ P) x y = ite P y x :=
dite_not P (λ _, x) (λ _, y)
lemma ite_and {α} {p q : Prop} [decidable p] [decidable q] {x y : α} :
ite (p ∧ q) x y = ite p (ite q x y) y :=
by { by_cases hp : p; by_cases hq : q; simp [hp, hq] }
end ite
|
e7167d224ef41ce2056be7f88adaf2ea27f485ef | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/category_theory/limits/types.lean | 75a202782b4bbce0fd01ec362eaa27233f6426e2 | [
"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,815 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton
-/
import category_theory.limits.shapes.images
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
open category_theory
open category_theory.limits
namespace category_theory.limits.types
variables {J : Type u} [small_category J]
/-- (internal implementation) the limit cone of a functor, implemented as flat sections of a pi type -/
def limit_ (F : J ⥤ Type u) : cone F :=
{ X := F.sections,
π := { app := λ j u, u.val j } }
local attribute [elab_simple] congr_fun
/-- (internal implementation) the fact that the proposed limit cone is the limit -/
def limit_is_limit_ (F : J ⥤ Type u) : is_limit (limit_ F) :=
{ lift := λ s v, ⟨λ j, s.π.app j v, λ j j' f, congr_fun (cone.w s f) _⟩,
uniq' := by { intros, ext x j, exact congr_fun (w j) x } }
instance : has_limits (Type u) :=
{ has_limits_of_shape := λ J 𝒥,
{ has_limit := λ F, by exactI { cone := limit_ F, is_limit := limit_is_limit_ F } } }
@[simp] lemma types_limit (F : J ⥤ Type u) :
limits.limit F = {u : Π j, F.obj j // ∀ {j j'} f, F.map f (u j) = u j'} := rfl
@[simp] lemma types_limit_π (F : J ⥤ Type u) (j : J) (g : limit F) :
limit.π F j g = g.val j := rfl
@[simp] lemma types_limit_pre
(F : J ⥤ Type u) {K : Type u} [𝒦 : small_category K] (E : K ⥤ J) (g : limit F) :
limit.pre F E g = (⟨λ k, g.val (E.obj k), by obviously⟩ : limit (E ⋙ F)) := rfl
@[simp] lemma types_limit_map {F G : J ⥤ Type u} (α : F ⟶ G) (g : limit F) :
(lim.map α : limit F → limit G) g =
(⟨λ j, (α.app j) (g.val j), λ j j' f,
by {rw ←functor_to_types.naturality, dsimp, rw ←(g.prop f)}⟩ : limit G) := rfl
@[simp] lemma types_limit_lift (F : J ⥤ Type u) (c : cone F) (x : c.X) :
limit.lift F c x = (⟨λ j, c.π.app j x, λ j j' f, congr_fun (cone.w c f) x⟩ : limit F) :=
rfl
/-- (internal implementation) the limit cone of a functor, implemented as a quotient of a sigma type -/
def colimit_ (F : J ⥤ Type u) : cocone F :=
{ X := @quot (Σ j, F.obj j) (λ p p', ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2),
ι :=
{ app := λ j x, quot.mk _ ⟨j, x⟩,
naturality' := λ j j' f, funext $ λ x, eq.symm (quot.sound ⟨f, rfl⟩) } }
local attribute [elab_with_expected_type] quot.lift
/-- (internal implementation) the fact that the proposed colimit cocone is the colimit -/
def colimit_is_colimit_ (F : J ⥤ Type u) : is_colimit (colimit_ F) :=
{ desc := λ s, quot.lift (λ (p : Σ j, F.obj j), s.ι.app p.1 p.2)
(assume ⟨j, x⟩ ⟨j', x'⟩ ⟨f, hf⟩, by rw hf; exact (congr_fun (cocone.w s f) x).symm) }
instance : has_colimits (Type u) :=
{ has_colimits_of_shape := λ J 𝒥,
{ has_colimit := λ F, by exactI { cocone := colimit_ F, is_colimit := colimit_is_colimit_ F } } }
@[simp] lemma types_colimit (F : J ⥤ Type u) :
limits.colimit F = @quot (Σ j, F.obj j) (λ p p', ∃ f : p.1 ⟶ p'.1, p'.2 = F.map f p.2) := rfl
@[simp] lemma types_colimit_ι (F : J ⥤ Type u) (j : J) :
colimit.ι F j = λ x, quot.mk _ ⟨j, x⟩ := rfl
@[simp] lemma types_colimit_pre
(F : J ⥤ Type u) {K : Type u} [𝒦 : small_category K] (E : K ⥤ J) :
colimit.pre F E =
quot.lift (λ p, quot.mk _ ⟨E.obj p.1, p.2⟩) (λ p p' ⟨f, h⟩, quot.sound ⟨E.map f, h⟩) := rfl
@[simp] lemma types_colimit_map {F G : J ⥤ Type u} (α : F ⟶ G) :
(colim.map α : colimit F → colimit G) =
quot.lift
(λ p, quot.mk _ ⟨p.1, (α.app p.1) p.2⟩)
(λ p p' ⟨f, h⟩, quot.sound ⟨f, by rw h; exact functor_to_types.naturality _ _ α f _⟩) := rfl
@[simp] lemma types_colimit_desc (F : J ⥤ Type u) (c : cocone F) :
colimit.desc F c =
quot.lift
(λ p, c.ι.app p.1 p.2)
(λ p p' ⟨f, h⟩, by rw h; exact (functor_to_types.naturality _ _ c.ι f _).symm) := rfl
variables {α β : Type u} (f : α ⟶ β)
section -- implementation of `has_image`
/-- the image of a morphism in Type is just `set.range f` -/
def image : Type u := set.range f
instance [inhabited α] : inhabited (image f) :=
{ default := ⟨f (default α), ⟨_, rfl⟩⟩ }
/-- the inclusion of `image f` into the target -/
def image.ι : image f ⟶ β := subtype.val
instance : mono (image.ι f) :=
(mono_iff_injective _).2 subtype.val_injective
variables {f}
/-- the universal property for the image factorisation -/
noncomputable def image.lift (F' : mono_factorisation f) : image f ⟶ F'.I :=
(λ x, F'.e (classical.indefinite_description _ x.2).1 : image f → F'.I)
lemma image.lift_fac (F' : mono_factorisation f) : image.lift F' ≫ F'.m = image.ι f :=
begin
ext x,
change (F'.e ≫ F'.m) _ = _,
rw [F'.fac, (classical.indefinite_description _ x.2).2],
refl,
end
end
/-- the factorisation of any morphism in AddCommGroup through a mono. -/
def mono_factorisation : mono_factorisation f :=
{ I := image f,
m := image.ι f,
e := set.range_factorization f }
noncomputable instance : has_image f :=
{ F := mono_factorisation f,
is_image :=
{ lift := image.lift,
lift_fac' := image.lift_fac } }
noncomputable instance : has_images (Type u) :=
{ has_image := infer_instance }
noncomputable instance : has_image_maps (Type u) :=
{ has_image_map := λ f g st,
{ map := λ x, ⟨st.right x.1, ⟨st.left (classical.some x.2),
begin
have p := st.w,
replace p := congr_fun p (classical.some x.2),
simp only [functor.id_map, types_comp_apply, subtype.val_eq_coe] at p,
erw [p, classical.some_spec x.2],
end⟩⟩ } }
@[simp] lemma image_map {f g : arrow (Type u)} (st : f ⟶ g) (x : image f.hom) :
(image.map st x).val = st.right x.1 :=
rfl
end category_theory.limits.types
|
6e7490481b92160af47081d1822bbe40d71c86ea | 8e6cad62ec62c6c348e5faaa3c3f2079012bdd69 | /src/topology/connected.lean | 422bd2588e4b90a57af7575157725c46300d4784 | [
"Apache-2.0"
] | permissive | benjamindavidson/mathlib | 8cc81c865aa8e7cf4462245f58d35ae9a56b150d | fad44b9f670670d87c8e25ff9cdf63af87ad731e | refs/heads/master | 1,679,545,578,362 | 1,615,343,014,000 | 1,615,343,014,000 | 312,926,983 | 0 | 0 | Apache-2.0 | 1,615,360,301,000 | 1,605,399,418,000 | Lean | UTF-8 | Lean | false | false | 39,692 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import topology.subset_properties
/-!
# Connected subsets of topological spaces
In this file we define connected subsets of a topological spaces and various other properties and
classes related to connectivity.
## Main definitions
We define the following properties for sets in a topological space:
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
* `connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions, we also have a class stating that the whole space
satisfies that property:
`connected_space`, `totally_disconnected_space`, `totally_separated_space`.
## On the definition of connected sets/spaces
In informal mathematics, connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption as `is_preconnected`.
In other words, the only difference is whether the empty space counts as connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
open set classical topological_space
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} [topological_space α] {s t : set α}
section preconnected
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(s ∩ u).nonempty → (s ∩ v).nonempty → (s ∩ (u ∩ v)).nonempty
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
s.nonempty ∧ is_preconnected s
lemma is_connected.nonempty {s : set α} (h : is_connected s) :
s.nonempty := h.1
lemma is_connected.is_preconnected {s : set α} (h : is_connected s) :
is_preconnected s := h.2
theorem is_preirreducible.is_preconnected {s : set α} (H : is_preirreducible s) :
is_preconnected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_irreducible.is_connected {s : set α} (H : is_irreducible s) : is_connected s :=
⟨H.nonempty, H.is_preirreducible.is_preconnected⟩
theorem is_preconnected_empty : is_preconnected (∅ : set α) :=
is_preirreducible_empty.is_preconnected
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_irreducible_singleton.is_connected
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
begin
rintros u v hu hv hs ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rcases H x y xs ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_preconnected s) : is_preconnected (⋃₀ c) :=
begin
apply is_preconnected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_preconnected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_preconnected s) (H4 : is_preconnected t) : is_preconnected (s ∪ t) :=
sUnion_pair s t ▸ is_preconnected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); assumption)
(by rintro r (rfl | rfl | h); assumption)
theorem is_connected.union {s t : set α} (H : (s ∩ t).nonempty)
(Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
begin
rcases H with ⟨x, hx⟩,
refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, _⟩,
exact is_preconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx)
Hs.is_preconnected Ht.is_preconnected
end
theorem is_preconnected.closure {s : set α} (H : is_preconnected s) :
is_preconnected (closure s) :=
λ u v hu hv hcsuv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := mem_closure_iff.1 hycs u hu hyu in
let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 hzcs v hv hzv in
let ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans subset_closure hcsuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
⟨H.nonempty.closure, H.is_preconnected.closure⟩
theorem is_preconnected.image [topological_space β] {s : set α} (H : is_preconnected s)
(f : α → β) (hf : continuous_on f s) : is_preconnected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_preconnected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
⟨nonempty_image_iff.mpr H.nonempty, H.is_preconnected.image f hf⟩
theorem is_preconnected_closed_iff {s : set α} :
is_preconnected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xt' : x ∉ t', from (h' xs).elim (absurd xt) id,
have yt : y ∉ t, from (h' ys).elim id (absurd yt'),
have := ne_empty_iff_nonempty.2 (h tᶜ t'ᶜ (is_open_compl_iff.2 ht)
(is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not,
← subset_compl_iff_disjoint, compl_inter] at h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := ne_empty_iff_nonempty.2 (h uᶜ vᶜ (is_closed_compl_iff.2 hu)
(is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end⟩
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_preconnected s ∧ x ∈ s }
/-- The connected component of a point inside a set. -/
def connected_component_in (F : set α) (x : F) : set α := coe '' (connected_component x)
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton.is_preconnected, mem_singleton x⟩
theorem is_preconnected_connected_component {x : α} : is_preconnected (connected_component x) :=
is_preconnected_sUnion x _ (λ _, and.right) (λ _, and.left)
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
⟨⟨x, mem_connected_component⟩, is_preconnected_connected_component⟩
theorem is_preconnected.subset_connected_component {x : α} {s : set α}
(H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_connected.subset_connected_component {x : α} {s : set α}
(H1 : is_connected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
H1.2.subset_connected_component H2
theorem connected_component_eq {x y : α} (h : y ∈ connected_component x) :
connected_component x = connected_component y :=
eq_of_subset_of_subset
(is_connected_connected_component.subset_connected_component h)
(is_connected_connected_component.subset_connected_component
(set.mem_of_mem_of_subset mem_connected_component
(is_connected_connected_component.subset_connected_component h)))
lemma connected_component_disjoint {x y : α} (h : connected_component x ≠ connected_component y) :
disjoint (connected_component x) (connected_component y) :=
set.disjoint_left.2 (λ a h1 h2, h
((connected_component_eq h1).trans (connected_component_eq h2).symm))
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(is_connected_connected_component.closure.subset_connected_component
(subset_closure mem_connected_component))
subset_closure
lemma continuous.image_connected_component_subset {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) (a : α) : f '' connected_component a ⊆ connected_component (f a) :=
(is_connected_connected_component.image f h.continuous_on).subset_connected_component
((mem_image f (connected_component a) (f a)).2 ⟨a, mem_connected_component, rfl⟩)
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
is_irreducible_irreducible_component.is_connected.subset_connected_component
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] : Prop :=
(is_preconnected_univ : is_preconnected (univ : set α))
export preconnected_space (is_preconnected_univ)
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α : Prop :=
(to_nonempty : nonempty α)
attribute [instance, priority 50] connected_space.to_nonempty -- see Note [lower instance priority]
lemma is_connected_range [topological_space β] [connected_space α] {f : α → β} (h : continuous f) :
is_connected (range f) :=
begin
inhabit α,
rw ← image_univ,
exact ⟨⟨f (default α), mem_image_of_mem _ (mem_univ _)⟩,
is_preconnected.image is_preconnected_univ _ h.continuous_on⟩
end
lemma connected_space_iff_connected_component :
connected_space α ↔ ∃ x : α, connected_component x = univ :=
begin
split,
{ rintros ⟨h, ⟨x⟩⟩,
exactI ⟨x, eq_univ_of_univ_subset $
is_preconnected_univ.subset_connected_component (mem_univ x)⟩ },
{ rintros ⟨x, h⟩,
haveI : preconnected_space α := ⟨by { rw ← h, exact is_preconnected_connected_component }⟩,
exact ⟨⟨x⟩⟩ }
end
@[priority 100] -- see Note [lower instance priority]
instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
⟨(preirreducible_space.is_preirreducible_univ α).is_preconnected⟩
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
{ to_nonempty := irreducible_space.to_nonempty α }
theorem nonempty_inter [preconnected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ → s.nonempty → t.nonempty → (s ∩ t).nonempty :=
by simpa only [univ_inter, univ_subset_iff] using
@preconnected_space.is_preconnected_univ α _ _ s t
theorem is_clopen_iff [preconnected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ sᶜ ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := nonempty_inter hs.1 hs.2 (union_compl_self s)
(ne_empty_iff_nonempty.1 h1.1) (ne_empty_iff_nonempty.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
lemma eq_univ_of_nonempty_clopen [preconnected_space α] {s : set α}
(h : s.nonempty) (h' : is_clopen s) : s = univ :=
by { rw is_clopen_iff at h', finish [h.ne_empty] }
lemma subtype.preconnected_space {s : set α} (h : is_preconnected s) :
preconnected_space s :=
{ is_preconnected_univ :=
begin
intros u v hu hv hs hsu hsv,
rw is_open_induced_iff at hu hv,
rcases hu with ⟨u, hu, rfl⟩,
rcases hv with ⟨v, hv, rfl⟩,
rcases hsu with ⟨⟨x, hxs⟩, hxs', hxu⟩,
rcases hsv with ⟨⟨y, hys⟩, hys', hyv⟩,
rcases h u v hu hv _ ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ with ⟨z, hzs, ⟨hzu, hzv⟩⟩,
exact ⟨⟨z, hzs⟩, ⟨set.mem_univ _, ⟨hzu, hzv⟩⟩⟩,
intros z hz,
rcases hs (mem_univ ⟨z, hz⟩) with hzu|hzv,
{ left, assumption },
{ right, assumption }
end }
lemma subtype.connected_space {s : set α} (h : is_connected s) :
connected_space s :=
{ is_preconnected_univ :=
(subtype.preconnected_space h.is_preconnected).is_preconnected_univ,
to_nonempty := h.nonempty.to_subtype }
lemma is_preconnected_iff_preconnected_space {s : set α} :
is_preconnected s ↔ preconnected_space s :=
⟨subtype.preconnected_space,
begin
introI,
simpa using is_preconnected_univ.image (coe : s → α) continuous_subtype_coe.continuous_on
end⟩
lemma is_connected_iff_connected_space {s : set α} : is_connected s ↔ connected_space s :=
⟨subtype.connected_space,
λ h, ⟨nonempty_subtype.mp h.2, is_preconnected_iff_preconnected_space.mpr h.1⟩⟩
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
lemma is_preconnected_iff_subset_of_disjoint {s : set α} :
is_preconnected s ↔
∀ (u v : set α) (hu : is_open u) (hv : is_open v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
lemma is_connected_iff_sUnion_disjoint_open {s : set α} :
is_connected s ↔
∀ (U : finset (set α)) (H : ∀ (u v : set α), u ∈ U → v ∈ U → (s ∩ (u ∩ v)).nonempty → u = v)
(hU : ∀ u ∈ U, is_open u) (hs : s ⊆ ⋃₀ ↑U),
∃ u ∈ U, s ⊆ u :=
begin
rw [is_connected, is_preconnected_iff_subset_of_disjoint],
split; intro h,
{ intro U, apply finset.induction_on U,
{ rcases h.left,
suffices : s ⊆ ∅ → false, { simpa },
intro, solve_by_elim },
{ intros u U hu IH hs hU H,
rw [finset.coe_insert, sUnion_insert] at H,
cases h.2 u (⋃₀ ↑U) _ _ H _ with hsu hsU,
{ exact ⟨u, finset.mem_insert_self _ _, hsu⟩ },
{ rcases IH _ _ hsU with ⟨v, hvU, hsv⟩,
{ exact ⟨v, finset.mem_insert_of_mem hvU, hsv⟩ },
{ intros, apply hs; solve_by_elim [finset.mem_insert_of_mem] },
{ intros, solve_by_elim [finset.mem_insert_of_mem] } },
{ solve_by_elim [finset.mem_insert_self] },
{ apply is_open_sUnion,
intros, solve_by_elim [finset.mem_insert_of_mem] },
{ apply eq_empty_of_subset_empty,
rintro x ⟨hxs, hxu, hxU⟩,
rw mem_sUnion at hxU,
rcases hxU with ⟨v, hvU, hxv⟩,
rcases hs u v (finset.mem_insert_self _ _) (finset.mem_insert_of_mem hvU) _ with rfl,
{ contradiction },
{ exact ⟨x, hxs, hxu, hxv⟩ } } } },
{ split,
{ rw ← ne_empty_iff_nonempty,
by_contradiction hs, push_neg at hs, subst hs,
simpa using h ∅ _ _ _; simp },
intros u v hu hv hs hsuv,
rcases h {u, v} _ _ _ with ⟨t, ht, ht'⟩,
{ rw [finset.mem_insert, finset.mem_singleton] at ht,
rcases ht with rfl|rfl; tauto },
{ intros t₁ t₂ ht₁ ht₂ hst,
rw ← ne_empty_iff_nonempty at hst,
rw [finset.mem_insert, finset.mem_singleton] at ht₁ ht₂,
rcases ht₁ with rfl|rfl; rcases ht₂ with rfl|rfl,
all_goals { refl <|> contradiction <|> skip },
rw inter_comm t₁ at hst, contradiction },
{ intro t,
rw [finset.mem_insert, finset.mem_singleton],
rintro (rfl|rfl); assumption },
{ simpa using hs } }
end
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem subset_or_disjoint_of_clopen {α : Type*} [topological_space α] {s t : set α}
(h : is_preconnected t) (h1 : is_clopen s) : s ∩ t = ∅ ∨ t ⊆ s :=
begin
by_contradiction h2,
have h3 : (s ∩ t).nonempty := ne_empty_iff_nonempty.mp (mt or.inl h2),
have h4 : (t ∩ sᶜ).nonempty,
{ apply inter_compl_nonempty_iff.2,
push_neg at h2,
exact h2.2 },
rw [inter_comm] at h3,
apply ne_empty_iff_nonempty.2 (h s sᶜ h1.1 (is_open_compl_iff.2 h1.2) _ h3 h4),
{ rw [inter_compl_self, inter_empty] },
{ rw [union_compl_self],
exact subset_univ t },
end
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed {α : Type*} {s : set α}
[topological_space α] :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hs : s ⊆ u ∪ v) (huv : s ∩ (u ∩ v) = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split; intro h,
{ intros u v hu hv hs huv,
rw is_preconnected_closed_iff at h,
specialize h u v hu hv hs,
contrapose! huv,
rw ne_empty_iff_nonempty,
simp [not_subset] at huv,
rcases huv with ⟨⟨x, hxs, hxu⟩, ⟨y, hys, hyv⟩⟩,
have hxv : x ∈ v := or_iff_not_imp_left.mp (hs hxs) hxu,
have hyu : y ∈ u := or_iff_not_imp_right.mp (hs hys) hyv,
exact h ⟨y, hys, hyu⟩ ⟨x, hxs, hxv⟩ },
{ rw is_preconnected_closed_iff,
intros u v hu hv hs hsu hsv,
rw ← ne_empty_iff_nonempty,
intro H,
specialize h u v hu hv hs H,
contrapose H,
apply ne_empty_iff_nonempty.mpr,
cases h,
{ rcases hsv with ⟨x, hxs, hxv⟩, exact ⟨x, hxs, ⟨h hxs, hxv⟩⟩ },
{ rcases hsu with ⟨x, hxs, hxu⟩, exact ⟨x, hxs, ⟨hxu, h hxs⟩⟩ } }
end
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α) (hu : is_closed u) (hv : is_closed v) (hss : s ⊆ u ∪ v) (huv : u ∩ v = ∅),
s ⊆ u ∨ s ⊆ v :=
begin
split,
{ intros h u v hu hv hss huv,
apply is_preconnected_iff_subset_of_disjoint_closed.1 h u v hu hv hss,
rw huv,
exact inter_empty s },
intro H,
rw is_preconnected_iff_subset_of_disjoint_closed,
intros u v hu hv hss huv,
have H1 := H (u ∩ s) (v ∩ s),
rw [subset_inter_iff, subset_inter_iff] at H1,
simp only [subset.refl, and_true] at H1,
apply H1 (is_closed_inter hu hs) (is_closed_inter hv hs),
{ rw ←inter_distrib_right,
apply subset_inter_iff.2,
exact ⟨hss, subset.refl s⟩ },
{ rw [inter_comm v s, inter_assoc, ←inter_assoc s, inter_self s,
inter_comm, inter_assoc, inter_comm v u, huv] }
end
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
lemma connected_component_subset_Inter_clopen {x : α} :
connected_component x ⊆ ⋂ Z : {Z : set α // is_clopen Z ∧ x ∈ Z}, Z :=
begin
apply subset_Inter (λ Z, _),
cases (subset_or_disjoint_of_clopen (@is_connected_connected_component _ _ x).2 Z.2.1),
{ exfalso,
apply nonempty.ne_empty
(nonempty_of_mem (mem_inter (@mem_connected_component _ _ x) Z.2.2)),
rw inter_comm,
exact h },
exact h,
end
/-- A clopen set is the union of its connected components. -/
lemma is_clopen.eq_union_connected_components {Z : set α} (h : is_clopen Z) :
Z = (⋃ (x : α) (H : x ∈ Z), connected_component x) :=
eq_of_subset_of_subset (λ x xZ, mem_Union.2 ⟨x, mem_Union.2 ⟨xZ, mem_connected_component⟩⟩)
(Union_subset $ λ x, Union_subset $ λ xZ,
(by { apply subset.trans connected_component_subset_Inter_clopen
(Inter_subset _ ⟨Z, ⟨h, xZ⟩⟩) }))
/-- The preimage of a connected component is preconnected if the function has connected fibers
and a subset is closed iff the preimage is. -/
lemma preimage_connected_component_connected {β : Type*} [topological_space β] {f : α → β}
(connected_fibers : ∀ t : β, is_connected (f ⁻¹' {t}))
(hcl : ∀ (T : set β), is_closed T ↔ is_closed (f ⁻¹' T)) (t : β) :
is_connected (f ⁻¹' connected_component t) :=
begin
-- The following proof is essentially https://stacks.math.columbia.edu/tag/0377
-- although the statement is slightly different
have hf : function.surjective f := function.surjective.of_comp (λ t : β, (connected_fibers t).1),
split,
{ cases hf t with s hs,
use s,
rw [mem_preimage, hs],
exact mem_connected_component },
have hT : is_closed (f ⁻¹' connected_component t) :=
(hcl (connected_component t)).1 is_closed_connected_component,
-- To show it's preconnected we decompose (f ⁻¹' connected_component t) as a subset of two
-- closed disjoint sets in α. We want to show that it's a subset of either.
rw is_preconnected_iff_subset_of_fully_disjoint_closed hT,
intros u v hu hv huv uv_disj,
-- To do this we decompose connected_component t into T₁ and T₂
-- we will show that connected_component t is a subset of either and hence
-- (f ⁻¹' connected_component t) is a subset of u or v
let T₁ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ u},
let T₂ := {t' ∈ connected_component t | f ⁻¹' {t'} ⊆ v},
have fiber_decomp : ∀ t' ∈ connected_component t, f ⁻¹' {t'} ⊆ u ∨ f ⁻¹' {t'} ⊆ v,
{ intros t' ht',
apply is_preconnected_iff_subset_of_disjoint_closed.1 (connected_fibers t').2 u v hu hv,
{ exact subset.trans (hf.preimage_subset_preimage_iff.2 (singleton_subset_iff.2 ht')) huv },
rw uv_disj,
exact inter_empty _ },
have T₁_u : f ⁻¹' T₁ = (f ⁻¹' connected_component t) ∩ u,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine bUnion_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hau⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exact h },
{ exfalso,
rw ←not_nonempty_iff_eq_empty at uv_disj,
exact uv_disj (nonempty_of_mem (mem_inter hau (h rfl))) } },
-- This proof is exactly the same as the above (modulo some symmetry)
have T₂_v : f ⁻¹' T₂ = (f ⁻¹' connected_component t) ∩ v,
{ apply eq_of_subset_of_subset,
{ rw ←bUnion_preimage_singleton,
refine bUnion_subset (λ t' ht', subset_inter _ ht'.2),
rw [hf.preimage_subset_preimage_iff, singleton_subset_iff],
exact ht'.1 },
rintros a ⟨hat, hav⟩,
constructor,
{ exact mem_preimage.1 hat },
dsimp only,
cases fiber_decomp (f a) (mem_preimage.1 hat),
{ exfalso,
rw ←not_nonempty_iff_eq_empty at uv_disj,
exact uv_disj (nonempty_of_mem (mem_inter (h rfl) hav)) },
{ exact h } },
-- Now we show T₁, T₂ are closed, cover connected_component t and are disjoint.
have hT₁ : is_closed T₁ := ((hcl T₁).2 (T₁_u.symm ▸ (is_closed_inter hT hu))),
have hT₂ : is_closed T₂ := ((hcl T₂).2 (T₂_v.symm ▸ (is_closed_inter hT hv))),
have T_decomp : connected_component t ⊆ T₁ ∪ T₂,
{ intros t' ht',
rw mem_union t' T₁ T₂,
cases fiber_decomp t' ht' with htu htv,
{ left, exact ⟨ht', htu⟩ },
right, exact ⟨ht', htv⟩ },
have T_disjoint : T₁ ∩ T₂ = ∅,
{ rw ←image_preimage_eq (T₁ ∩ T₂) hf,
suffices : f ⁻¹' (T₁ ∩ T₂) = ∅,
{ rw this, exact image_empty _ },
rw [preimage_inter, T₁_u, T₂_v],
rw inter_comm at uv_disj,
conv
{ congr,
rw [inter_assoc],
congr, skip,
rw [←inter_assoc, inter_comm, ←inter_assoc, uv_disj, empty_inter], },
exact inter_empty _ },
-- Now we do cases on whether (connected_component t) is a subset of T₁ or T₂ to show
-- that the preimage is a subset of u or v.
cases (is_preconnected_iff_subset_of_fully_disjoint_closed is_closed_connected_component).1
is_preconnected_connected_component T₁ T₂ hT₁ hT₂ T_decomp T_disjoint,
{ left,
rw subset.antisymm_iff at T₁_u,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₁,
{ exact subset.trans (subset.trans this T₁_u.1) (inter_subset_right _ _) },
exact preimage_mono h },
right,
rw subset.antisymm_iff at T₂_v,
suffices : f ⁻¹' connected_component t ⊆ f ⁻¹' T₂,
{ exact subset.trans (subset.trans this T₂_v.1) (inter_subset_right _ _) },
exact preimage_mono h,
end
end preconnected
section totally_disconnected
/-- A set is called totally disconnected if all of its connected components are singletons. -/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_preconnected t → subsingleton t
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ t ht _, ⟨λ ⟨_, h⟩, (ht h).elim⟩
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ t ht _, ⟨λ ⟨p, hp⟩ ⟨q, hq⟩, subtype.eq $ show p = q,
from (eq_of_mem_singleton (ht hp)).symm ▸ (eq_of_mem_singleton (ht hq)).symm⟩
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
instance pi.totally_disconnected_space {α : Type*} {β : α → Type*}
[t₂ : Πa, topological_space (β a)] [∀a, totally_disconnected_space (β a)] :
totally_disconnected_space (Π (a : α), β a) :=
⟨λ t h1 h2, ⟨λ a b, subtype.ext $ funext $ λ x, subtype.mk_eq_mk.1 $
(totally_disconnected_space.is_totally_disconnected_univ
((λ (c : Π (a : α), β a), c x) '' t) (set.subset_univ _)
(is_preconnected.image h2 _ (continuous.continuous_on (continuous_apply _)))).cases_on
(λ h3, h3
⟨(a.1 x), by {simp only [set.mem_image, subtype.val_eq_coe], use a, split,
simp only [subtype.coe_prop]}⟩
⟨(b.1 x), by {simp only [set.mem_image, subtype.val_eq_coe], use b, split,
simp only [subtype.coe_prop]}⟩)⟩⟩
instance subtype.totally_disconnected_space {α : Type*} {p : α → Prop} [topological_space α]
[totally_disconnected_space α] : totally_disconnected_space (subtype p) :=
⟨λ s h1 h2,
set.subsingleton_of_image subtype.val_injective s (
totally_disconnected_space.is_totally_disconnected_univ (subtype.val '' s) (set.subset_univ _)
((is_preconnected.image h2 _) (continuous.continuous_on (@continuous_subtype_val _ _ p))))⟩
/-- A space is totally disconnected iff its connected components are subsingletons. -/
lemma totally_disconnected_space_iff_connected_component_subsingleton :
totally_disconnected_space α ↔ ∀ x : α, subsingleton (connected_component x) :=
begin
split,
{ intros h x,
apply h.1,
{ exact subset_univ _ },
exact is_preconnected_connected_component },
intro h, constructor,
intros s s_sub hs,
rw subsingleton_coe,
by_cases s.nonempty,
{ choose x hx using h,
have H := h x,
rw subsingleton_coe at H,
exact H.mono (hs.subset_connected_component hx) },
rw not_nonempty_iff_eq_empty at h,
rw h,
exact subsingleton_empty,
end
/-- A space is totally disconnected iff its connected components are singletons. -/
lemma totally_disconnected_space_iff_connected_component_singleton :
totally_disconnected_space α ↔ ∀ x : α, connected_component x = {x} :=
begin
split,
{ intros h x,
rw totally_disconnected_space_iff_connected_component_subsingleton at h,
specialize h x,
rw subsingleton_coe at h,
rw h.eq_singleton_of_mem,
exact mem_connected_component },
intro h,
rw totally_disconnected_space_iff_connected_component_subsingleton,
intro x,
rw [h x, subsingleton_coe],
exact subsingleton_singleton,
end
/-- The image of a connected component in a totally disconnected space is a singleton. -/
@[simp] lemma continuous.image_connected_component_eq_singleton {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (a : α) :
f '' connected_component a = {f a} :=
begin
have ha : subsingleton (f '' connected_component a),
{ apply _inst_3.1,
{ exact subset_univ _ },
apply is_preconnected_connected_component.image,
exact h.continuous_on },
rw subsingleton_coe at ha,
rw ha.eq_singleton_of_mem,
exact ⟨a, mem_connected_component, refl (f a)⟩,
end
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
λ t hts ht, ⟨λ ⟨x, hxt⟩ ⟨y, hyt⟩, subtype.eq $ classical.by_contradiction $
assume hxy : x ≠ y, let ⟨u, v, hu, hv, hxu, hyv, hsuv, huv⟩ := H x (hts hxt) y (hts hyt) hxy in
let ⟨r, hrt, hruv⟩ := ht u v hu hv (subset.trans hts hsuv) ⟨x, hxt, hxu⟩ ⟨y, hyt, hyv⟩ in
(ext_iff.1 huv r).1 hruv⟩
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ [] : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $
totally_separated_space.is_totally_separated_univ α⟩
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.of_discrete
(α : Type*) [topological_space α] [discrete_topology α] : totally_separated_space α :=
⟨λ a _ b _ h, ⟨{b}ᶜ, {b}, is_open_discrete _, is_open_discrete _, by simpa⟩⟩
end totally_separated
section connected_component_setoid
/-- The setoid of connected components of a topological space -/
def connected_component_setoid (α : Type*) [topological_space α] : setoid α :=
⟨λ x y, connected_component x = connected_component y,
⟨λ x, by trivial, λ x y h1, h1.symm, λ x y z h1 h2, h1.trans h2⟩⟩
-- see Note [lower instance priority]
local attribute [instance, priority 100] connected_component_setoid
lemma connected_component_rel_iff {x y : α} : ⟦x⟧ = ⟦y⟧ ↔
connected_component x = connected_component y :=
⟨λ h, quotient.exact h, λ h, quotient.sound h⟩
lemma connected_component_nrel_iff {x y : α} : ⟦x⟧ ≠ ⟦y⟧ ↔
connected_component x ≠ connected_component y :=
by { rw not_iff_not, exact connected_component_rel_iff }
/-- The quotient of a space by its connected components -/
def connected_components (α : Type u) [topological_space α] :=
quotient (connected_component_setoid α)
instance [inhabited α] : inhabited (connected_components α) := ⟨quotient.mk (default _)⟩
instance connected_components.topological_space : topological_space (connected_components α) :=
quotient.topological_space
lemma continuous.image_eq_of_equiv {β : Type*} [topological_space β] [totally_disconnected_space β]
{f : α → β} (h : continuous f) (a b : α) (hab : a ≈ b) : f a = f b :=
singleton_eq_singleton_iff.1 $
h.image_connected_component_eq_singleton a ▸
h.image_connected_component_eq_singleton b ▸ hab ▸ rfl
/--
The lift to `connected_components α` of a continuous map from `α` to a totally disconnected space
-/
def continuous.connected_components_lift {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) : connected_components α → β :=
quotient.lift f h.image_eq_of_equiv
@[continuity] lemma continuous.connected_components_lift_continuous {β : Type*}
[topological_space β] [totally_disconnected_space β] {f : α → β} (h : continuous f) :
continuous h.connected_components_lift :=
continuous_quotient_lift h.image_eq_of_equiv h
@[simp] lemma continuous.connected_components_lift_factors {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) :
h.connected_components_lift ∘ quotient.mk = f := rfl
lemma continuous.connected_components_lift_unique {β : Type*} [topological_space β]
[totally_disconnected_space β] {f : α → β} (h : continuous f) (g : connected_components α → β)
(hg : g ∘ quotient.mk = f) : g = h.connected_components_lift :=
by { subst hg, ext1 x, exact quotient.induction_on x (λ a, refl _) }
lemma connected_components_lift_unique' {β : Type*} (g₁ : connected_components α → β)
(g₂ : connected_components α → β) (hg : g₁ ∘ quotient.mk = g₂ ∘ quotient.mk ) : g₁ = g₂ :=
begin
ext1 x,
refine quotient.induction_on x (λ a, _),
change (g₁ ∘ quotient.mk) a = (g₂ ∘ quotient.mk) a,
rw hg,
end
/-- The preimage of a singleton in `connected_components` is the connected component
of an element in the equivalence class. -/
lemma connected_components_preimage_singleton {t : α} :
connected_component t = quotient.mk ⁻¹' {⟦t⟧} :=
begin
apply set.eq_of_subset_of_subset; intros a ha,
{ have H : ⟦a⟧ = ⟦t⟧ := quotient.sound (connected_component_eq ha).symm,
rw [mem_preimage, H],
exact mem_singleton ⟦t⟧ },
rw [mem_preimage, mem_singleton_iff] at ha,
have ha' : connected_component a = connected_component t := quotient.exact ha,
rw ←ha',
exact mem_connected_component,
end
/-- The preimage of the image of a set under the quotient map to `connected_components α`
is the union of the connected components of the elements in it. -/
lemma connected_components_preimage_image (U : set α) :
quotient.mk ⁻¹' (quotient.mk '' U) = ⋃ (x : α) (h : x ∈ U), connected_component x :=
begin
apply set.eq_of_subset_of_subset,
{ rintros a ⟨b, hb, hab⟩,
refine mem_Union.2 ⟨b, mem_Union.2 ⟨hb, _⟩⟩,
rw connected_component_rel_iff.1 hab,
exact mem_connected_component },
refine Union_subset (λ a, Union_subset (λ ha, _)),
rw [connected_components_preimage_singleton,
(surjective_quotient_mk _).preimage_subset_preimage_iff, singleton_subset_iff],
exact ⟨a, ha, refl _⟩,
end
instance connected_components.totally_disconnected_space :
totally_disconnected_space (connected_components α) :=
begin
rw totally_disconnected_space_iff_connected_component_singleton,
refine λ x, quotient.induction_on x (λ a, _),
apply eq_of_subset_of_subset _ (singleton_subset_iff.2 mem_connected_component),
rw subset_singleton_iff,
refine λ x, quotient.induction_on x (λ b hb, _),
rw [connected_component_rel_iff, connected_component_eq],
suffices : is_preconnected (quotient.mk ⁻¹' connected_component ⟦a⟧),
{ apply mem_of_subset_of_mem (this.subset_connected_component hb),
exact mem_preimage.2 mem_connected_component },
apply (@preimage_connected_component_connected _ _ _ _ _ _ _ _).2,
{ refine λ t, quotient.induction_on t (λ s, _),
rw ←connected_components_preimage_singleton,
exact is_connected_connected_component },
refine λ T, ⟨λ hT, hT.preimage continuous_quotient_mk, λ hT, _⟩,
rwa [←is_open_compl_iff, ←preimage_compl, quotient_map_quotient_mk.is_open_preimage] at hT,
end
/-- Functoriality of `connected_components` -/
def continuous.connected_components_map {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : connected_components α → connected_components β :=
continuous.connected_components_lift (continuous_quotient_mk.comp h)
lemma continuous.connected_components_map_continuous {β : Type*} [topological_space β] {f : α → β}
(h : continuous f) : continuous h.connected_components_map :=
continuous.connected_components_lift_continuous (continuous_quotient_mk.comp h)
end connected_component_setoid
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.