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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
809909d1061d6c5ed91d24afd2b97f7a6704d48d
|
ca1ad81c8733787aba30f7a8d63f418508e12812
|
/clfrags/src/hilbert/wr/proofs/pt_neg.lean
|
7c8668651b20c9f786be85f8cbbe07e33f6e8145
|
[] |
no_license
|
greati/hilbert-classical-fragments
|
5cdbe07851e979c8a03c621a5efd4d24bbfa333a
|
18a21ac6b2e890060eb4ae65752fc0245394d226
|
refs/heads/master
| 1,591,973,117,184
| 1,573,822,710,000
| 1,573,822,710,000
| 194,334,439
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,492
|
lean
|
import hilbert.wr.pt_neg
namespace clfrags
namespace hilbert
namespace wr
namespace pt_neg
theorem pt₂_neg {a b c : Prop} (h₁ : neg (pt a b c)) : neg (pt b a c) :=
have h₂ : pt (neg a) b c, from ptn₁ h₁,
have h₃ : pt a (neg b) c, from ptn₃ h₂,
have h₄ : pt (neg b) a c, from pt.pt₂ h₃,
show neg (pt b a c), from ptn₂ h₄
theorem pt₃_neg {a b c : Prop} (h₁ : neg (pt a b c)) : neg (pt a c b) :=
have h₂ : pt (neg a) b c, from ptn₁ h₁,
have h₃ : pt (neg a) c b, from pt.pt₃ h₂,
show neg (pt a c b), from ptn₂ h₃
theorem pt₄_neg {a b : Prop} (h₁ : neg a) : neg (pt a b b) :=
have h₂ : pt (neg a) b b, from pt.pt₄ h₁,
show neg (pt a b b), from ptn₂ h₂
theorem pt₅_neg {a b : Prop} (h₁ : neg (pt a b b)) : neg a :=
have h₂ : pt (neg a) b b, from ptn₁ h₁,
show neg a, from pt.pt₅ h₂
theorem pt₆_neg {a b c d e : Prop} (h₁ : neg (pt a b (pt c d e))) : neg (pt (pt a b c) d e) :=
have h₂ : pt (neg a) b (pt c d e), from ptn₁ h₁,
have h₃ : pt (pt (neg a) b c) d e, from pt.pt₆ h₂,
have h₄ : pt d e (pt (neg a) b c), from pt.pt₃ (pt.pt₂ h₃),
have h₅ : pt (pt d e (neg a)) b c, from pt.pt₆ h₄,
have h₆ : pt b c (pt d e (neg a)), from pt.pt₃ (pt.pt₂ h₅),
have h₇ : pt b c (pt (neg a) d e), from pt.pt₂_pt (pt.pt₃_pt h₆),
have h₈ : pt (pt (neg a) d e) b c, from pt.pt₂ (pt.pt₃ h₇),
have h₉ : pt (neg a) d (pt e b c), from pt.pt₇ h₈,
have h₁₀ : neg (pt a d (pt e b c)), from ptn₂ h₉,
have h₁₁ : neg (pt d a (pt e b c)), from pt₂_neg h₁₀,
have h₁₂ : pt (neg d) a (pt e b c), from ptn₁ h₁₁,
have h₁₃ : pt (pt (neg d) a e) b c, from pt.pt₆ h₁₂,
have h₁₄ : pt b c (pt (neg d) a e), from pt.pt₃ (pt.pt₂ h₁₃),
have h₁₅ : pt b c (pt a (neg d) e), from pt.pt₂_pt h₁₄,
have h₁₆ : pt (pt b c a) (neg d) e, from pt.pt₆ h₁₅,
have h₁₇ : pt (neg d) e (pt b c a), from pt.pt₃ (pt.pt₂ h₁₆),
have h₁₈ : pt (neg d) e (pt a b c), from pt.pt₂_pt (pt.pt₃_pt h₁₇),
have h₁₉ : neg (pt d e (pt a b c)), from ptn₂ h₁₈,
show neg (pt (pt a b c) d e), from pt₂_neg (pt₃_neg h₁₉)
theorem pt₇_neg {a b c d e : Prop} (h₁ : neg (pt (pt a b c) d e)) : neg (pt a b (pt c d e)) :=
have h₂ : neg (pt d (pt a b c) e), from pt₂_neg h₁,
have h₃ : neg (pt d e (pt a b c)), from pt₃_neg h₂,
have h₄ : neg (pt (pt d e a) b c), from pt₆_neg h₃,
have h₅ : neg (pt b (pt d e a) c), from pt₂_neg h₄,
have h₆ : neg (pt b c (pt d e a)), from pt₃_neg h₅,
have h₇ : neg (pt (pt b c d) e a), from pt₆_neg h₆,
have h₈ : neg (pt e (pt b c d) a), from pt₂_neg h₇,
have h₉ : neg (pt e a (pt b c d)), from pt₃_neg h₈,
have h₁₀ : neg (pt (pt e a b) c d), from pt₆_neg h₉,
have h₁₁ : neg (pt c (pt e a b) d), from pt₂_neg h₁₀,
have h₁₂ : neg (pt c d (pt e a b)), from pt₃_neg h₁₁,
have h₁₃ : neg (pt (pt c d e) a b), from pt₆_neg h₁₂,
have h₁₄ : neg (pt a (pt c d e) b), from pt₂_neg h₁₃,
show neg (pt a b (pt c d e)), from pt₃_neg h₁₄
theorem n₁_pt {a b c d : Prop} (h₁ : pt c d a) (h₂ : pt c d (neg a)) : pt c d b :=
have h₃ : pt a c d, from pt.pt₂ (pt.pt₃ h₁),
have h₄ : pt (neg a) c d, from pt.pt₂ (pt.pt₃ h₂),
have h₅ : neg (pt a c d), from ptn₂ h₄,
show pt c d b, from n₁ h₃ h₅
theorem ptn₁_pt {a b c d e : Prop} (h₁ : pt d e (neg (pt a b c))) : pt d e (pt (neg a) b c) :=
have h₂ : pt (neg (pt a b c)) d e, from pt.pt₂ (pt.pt₃ h₁),
have h₃ : neg (pt (pt a b c) d e), from ptn₂ h₂,
have h₄ : neg (pt a b (pt c d e)), from pt₇_neg h₃,
have h₅ : pt (neg a) b (pt c d e), from ptn₁ h₄,
have h₆ : pt (pt (neg a) b c) d e, from pt.pt₆ h₅,
show pt d e (pt (neg a) b c), from pt.pt₃ (pt.pt₂ h₆)
theorem ptn₂_pt {a b c d e : Prop} (h₁ : pt d e (pt (neg a) b c)) : pt d e (neg (pt a b c)) :=
have h₂ : pt (pt (neg a) b c) d e, from pt.pt₂ (pt.pt₃ h₁),
have h₃ : pt (neg a) b (pt c d e), from pt.pt₇ h₂,
have h₄ : neg (pt a b (pt c d e)), from ptn₂ h₃,
have h₅ : neg (pt (pt a b c) d e), from pt₆_neg h₄,
have h₆ : pt (neg (pt a b c)) d e, from ptn₁ h₅,
show pt d e (neg (pt a b c)), from pt.pt₃ (pt.pt₂ h₆)
theorem ptn₃_pt {a b c d e : Prop} (h₁ : pt d e (neg (pt a b c))) : pt d e (pt a (neg b) c) :=
have h₂ : pt (neg (pt a b c)) d e, from pt.pt₂ (pt.pt₃ h₁),
have h₃ : neg (pt (pt a b c) d e), from ptn₂ h₂,
have h₄ : neg (pt a b (pt c d e)), from pt₇_neg h₃,
have h₅ : neg (pt b a (pt c d e)), from pt₂_neg h₄,
have h₆ : pt (neg b) a (pt c d e), from ptn₁ h₅,
have h₇ : pt a (neg b) (pt c d e), from pt.pt₂ h₆,
have h₈ : pt (pt a (neg b) c) d e, from pt.pt₆ h₇,
show pt d e (pt a (neg b) c), from pt.pt₃ (pt.pt₂ h₈)
end pt_neg
end wr
end hilbert
end clfrags
|
3665f9dbd238d02dc8ddf81b4e71914449df4be8
|
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
|
/src/algebra/free_monoid.lean
|
d6d45edf173c2ef72a9276d93ee622223e9f9ebf
|
[
"Apache-2.0"
] |
permissive
|
keeferrowan/mathlib
|
f2818da875dbc7780830d09bd4c526b0764a4e50
|
aad2dfc40e8e6a7e258287a7c1580318e865817e
|
refs/heads/master
| 1,661,736,426,952
| 1,590,438,032,000
| 1,590,438,032,000
| 266,892,663
| 0
| 0
|
Apache-2.0
| 1,590,445,835,000
| 1,590,445,835,000
| null |
UTF-8
|
Lean
| false
| false
| 4,444
|
lean
|
/-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Yury Kudryashov
-/
import data.equiv.basic
import data.list.basic
/-!
# Free monoid over a given alphabet
## Main definitions
* `free_monoid α`: free monoid over alphabet `α`; defined as a synonym for `list α`
with multiplication given by `(++)`.
* `free_monoid.of`: embedding `α → free_monoid α` sending each element `x` to `[x]`;
* `free_monoid.lift α M`: natural equivalence between `α → M` and `free_monoid α →* M`;
for technical reasons `α` and `M` are explicit arguments;
* `free_monoid.map`: embedding of `α → β` into `free_monoid α →* free_monoid β` given by `list.map`.
-/
variables {α : Type*} {β : Type*} {γ : Type*} {M : Type*} [monoid M] {N : Type*} [monoid N]
/-- Free monoid over a given alphabet. -/
@[to_additive free_add_monoid "Free nonabelian additive monoid over a given alphabet"]
def free_monoid (α) := list α
namespace free_monoid
@[to_additive]
instance : monoid (free_monoid α) :=
{ one := [],
mul := λ x y, (x ++ y : list α),
mul_one := by intros; apply list.append_nil,
one_mul := by intros; refl,
mul_assoc := by intros; apply list.append_assoc }
@[to_additive]
instance : inhabited (free_monoid α) := ⟨1⟩
@[to_additive]
lemma one_def : (1 : free_monoid α) = [] := rfl
@[to_additive]
lemma mul_def (xs ys : list α) : (xs * ys : free_monoid α) = (xs ++ ys : list α) :=
rfl
/-- Embeds an element of `α` into `free_monoid α` as a singleton list. -/
@[to_additive "Embeds an element of `α` into `free_add_monoid α` as a singleton list." ]
def of (x : α) : free_monoid α := [x]
@[to_additive]
lemma of_def (x : α) : of x = [x] := rfl
/-- Recursor for `free_monoid` using `1` and `of x * xs` instead of `[]` and `x :: xs`. -/
@[to_additive "Recursor for `free_add_monoid` using `0` and `of x + xs` instead of `[]` and `x :: xs`."]
def rec_on {C : free_monoid α → Sort*} (xs : free_monoid α) (h0 : C 1)
(ih : Π x xs, C xs → C (of x * xs)) : C xs := list.rec_on xs h0 ih
attribute [elab_as_eliminator] rec_on free_add_monoid.rec_on
@[to_additive]
lemma hom_eq ⦃f g : free_monoid α →* M⦄ (h : ∀ x, f (of x) = g (of x)) :
f = g :=
monoid_hom.ext $ λ l, rec_on l (f.map_one.trans g.map_one.symm) $
λ x xs hxs, by simp only [h, hxs, monoid_hom.map_mul]
attribute [ext, priority 1500] hom_eq free_add_monoid.hom_eq
section
-- TODO[Lean 4] : make these arguments implicit
variables (α M)
/-- Equivalence between maps `α → M` and monoid homomorphisms `free_monoid α →* M`. -/
@[to_additive "Equivalence between maps `α → A` and additive monoid homomorphisms
`free_add_monoid α →+ A`."]
def lift : (α → M) ≃ (free_monoid α →* M) :=
{ to_fun := λ f, ⟨λ l, (l.map f).prod, rfl,
λ l₁ l₂, by simp only [mul_def, list.map_append, list.prod_append]⟩,
inv_fun := λ f x, f (of x),
left_inv := λ f, funext $ λ x, one_mul (f x),
right_inv := λ f, hom_eq $ λ x, one_mul (f (of x)) }
end
@[to_additive]
lemma lift_apply (f : α → M) (l : list α) : lift α M f l = (l.map f).prod := rfl
@[to_additive]
lemma lift_comp_of (f : α → M) : (lift α M f) ∘ of = f := (lift α M).symm_apply_apply f
@[simp, to_additive]
lemma lift_eval_of (f : α → M) (x : α) : lift α M f (of x) = f x :=
congr_fun (lift_comp_of f) x
@[simp, to_additive]
lemma lift_restrict (f : free_monoid α →* M) : lift α M (f ∘ of) = f :=
(lift α M).apply_symm_apply f
lemma comp_lift (g : M →* N) (f : α → M) : g.comp (lift α M f) = lift α N (g ∘ f) :=
by { ext, simp }
/-- The unique monoid homomorphism `free_monoid α →* free_monoid β` that sends
each `of x` to `of (f x)`. -/
@[to_additive "The unique additive monoid homomorphism `free_add_monoid α →+ free_add_monoid β`
that sends each `of x` to `of (f x)`."]
def map (f : α → β) : free_monoid α →* free_monoid β :=
{ to_fun := list.map f,
map_one' := rfl,
map_mul' := λ l₁ l₂, list.map_append _ _ _ }
@[simp, to_additive] lemma map_of (f : α → β) (x : α) : map f (of x) = of (f x) := rfl
@[to_additive]
lemma lift_of_comp_eq_map (f : α → β) :
lift α (free_monoid β) (λ x, of (f x)) = map f :=
hom_eq $ λ x, rfl
@[to_additive]
lemma map_comp (g : β → γ) (f : α → β) : map (g ∘ f) = (map g).comp (map f) :=
hom_eq $ λ x, rfl
end free_monoid
|
efec7e6a8b2f875b7a9ff98200d4734be2095e49
|
618003631150032a5676f229d13a079ac875ff77
|
/src/data/matrix/notation.lean
|
b50d25b9b944688f43f8364b4e457a5533313908
|
[
"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
| 11,018
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
Notation for vectors and matrices
-/
import data.fintype.card
import data.matrix.basic
import tactic.fin_cases
/-!
# Matrix and vector notation
This file defines notation for vectors and matrices. Given `a b c d : α`,
the notation allows us to write `![a, b, c, d] : fin 4 → α`.
Nesting vectors gives a matrix, so `![![a, b], ![c, d]] : matrix (fin 2) (fin 2) α`.
This file includes `simp` lemmas for applying operations in
`data.matrix.basic` to values built out of this notation.
## Main definitions
* `vec_empty` is the empty vector (or `0` by `n` matrix) `![]`
* `vec_cons` prepends an entry to a vector, so `![a, b]` is `vec_cons a (vec_cons b vec_empty)`
## Implementation notes
The `simp` lemmas require that one of the arguments is of the form `vec_cons _ _`.
This ensures `simp` works with entries only when (some) entries are already given.
In other words, this notation will only appear in the output of `simp` if it
already appears in the input.
## Notations
The main new notation is `![a, b]`, which gets expanded to `vec_cons a (vec_cons b vec_empty)`.
-/
namespace matrix
universe u
variables {α : Type u}
open_locale matrix
section matrix_notation
/-- `![]` is the vector with no entries. -/
def vec_empty : fin 0 → α :=
fin_zero_elim
/-- `vec_cons h t` prepends an entry `h` to a vector `t`.
The inverse functions are `vec_head` and `vec_tail`.
The notation `![a, b, ...]` expands to `vec_cons a (vec_cons b ...)`.
-/
def vec_cons {n : ℕ} (h : α) (t : fin n → α) : fin n.succ → α :=
fin.cons h t
notation `![` l:(foldr `, ` (h t, vec_cons h t) vec_empty `]`) := l
/-- `vec_head v` gives the first entry of the vector `v` -/
def vec_head {n : ℕ} (v : fin n.succ → α) : α :=
v 0
/-- `vec_tail v` gives a vector consisting of all entries of `v` except the first -/
def vec_tail {n : ℕ} (v : fin n.succ → α) : fin n → α :=
v ∘ fin.succ
end matrix_notation
variables {m n o : ℕ} {m' n' o' : Type} [fintype m'] [fintype n'] [fintype o']
lemma empty_eq (v : fin 0 → α) : v = ![] :=
by { ext i, fin_cases i }
section val
@[simp] lemma cons_val_zero (x : α) (u : fin m → α) : vec_cons x u 0 = x := rfl
@[simp] lemma cons_val_zero' (h : 0 < m.succ) (x : α) (u : fin m → α) :
vec_cons x u ⟨0, h⟩ = x :=
rfl
@[simp] lemma cons_val_succ (x : α) (u : fin m → α) (i : fin m) :
vec_cons x u i.succ = u i :=
by simp [vec_cons]
@[simp] lemma cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : fin m → α) :
vec_cons x u ⟨i.succ, h⟩ = u ⟨i, nat.lt_of_succ_lt_succ h⟩ :=
by simp [vec_cons, fin.cons, fin.cases]
@[simp] lemma head_cons (x : α) (u : fin m → α) :
vec_head (vec_cons x u) = x :=
rfl
@[simp] lemma tail_cons (x : α) (u : fin m → α) :
vec_tail (vec_cons x u) = u :=
by { ext, simp [vec_tail] }
@[simp] lemma empty_val' {n' : Type} (j : n') :
(λ i, (![] : fin 0 → n' → α) i j) = ![] :=
empty_eq _
@[simp] lemma cons_val' (v : n' → α) (B : matrix (fin m) n' α) (i j) :
vec_cons v B i j = vec_cons (v j) (λ i, B i j) i :=
by { refine fin.cases _ _ i; simp }
@[simp] lemma head_val' (B : matrix (fin m.succ) n' α) (j : n') :
vec_head (λ i, B i j) = vec_head B j := rfl
@[simp] lemma tail_val' (B : matrix (fin m.succ) n' α) (j : n') :
vec_tail (λ i, B i j) = λ i, vec_tail B i j :=
by { ext, simp [vec_tail] }
@[simp] lemma cons_head_tail (u : fin m.succ → α) :
vec_cons (vec_head u) (vec_tail u) = u :=
by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
/-- `![a, b, ...] 1` is equal to `b`.
The simplifier needs a special lemma for length `≥ 2`, in addition to
`cons_val_succ`, because `1 : fin 1 = 0 : fin 1`.
-/
@[simp] lemma cons_val_one (x : α) (u : fin m.succ → α) :
vec_cons x u 1 = vec_head u :=
cons_val_succ x u 0
@[simp] lemma cons_val_fin_one (x : α) (u : fin 0 → α) (i : fin 1) :
vec_cons x u i = x :=
by { fin_cases i, refl }
end val
section dot_product
variables [add_comm_monoid α] [has_mul α]
@[simp] lemma dot_product_empty (v w : fin 0 → α) :
dot_product v w = 0 := finset.sum_empty
@[simp] lemma cons_dot_product (x : α) (v : fin n → α) (w : fin n.succ → α) :
dot_product (vec_cons x v) w = x * vec_head w + dot_product v (vec_tail w) :=
by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]
@[simp] lemma dot_product_cons (v : fin n.succ → α) (x : α) (w : fin n → α) :
dot_product v (vec_cons x w) = vec_head v * x + dot_product (vec_tail v) w :=
by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail]
end dot_product
section col_row
@[simp] lemma col_empty (v : fin 0 → α) : col v = vec_empty :=
empty_eq _
@[simp] lemma col_cons (x : α) (u : fin m → α) :
col (vec_cons x u) = vec_cons (λ _, x) (col u) :=
by { ext i j, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
@[simp] lemma row_empty : row (vec_empty : fin 0 → α) = λ _, vec_empty :=
by { ext, refl }
@[simp] lemma row_cons (x : α) (u : fin m → α) :
row (vec_cons x u) = λ _, vec_cons x u :=
by { ext, refl }
end col_row
section transpose
@[simp] lemma transpose_empty_rows (A : matrix m' (fin 0) α) : Aᵀ = ![] := empty_eq _
@[simp] lemma transpose_empty_cols : (![] : matrix (fin 0) m' α)ᵀ = λ i, ![] :=
funext (λ i, empty_eq _)
@[simp] lemma cons_transpose (v : n' → α) (A : matrix (fin m) n' α) :
(vec_cons v A)ᵀ = λ i, vec_cons (v i) (Aᵀ i) :=
by { ext i j, refine fin.cases _ _ j; simp }
@[simp] lemma head_transpose (A : matrix m' (fin n.succ) α) : vec_head (Aᵀ) = vec_head ∘ A :=
rfl
@[simp] lemma tail_transpose (A : matrix m' (fin n.succ) α) : vec_tail (Aᵀ) = (vec_tail ∘ A)ᵀ :=
by { ext i j, refl }
end transpose
section mul
variables [semiring α]
@[simp] lemma empty_mul (A : matrix (fin 0) n' α) (B : matrix n' o' α) :
A ⬝ B = ![] :=
empty_eq _
@[simp] lemma empty_mul_empty (A : matrix m' (fin 0) α) (B : matrix (fin 0) o' α) :
A ⬝ B = 0 :=
rfl
@[simp] lemma mul_empty (A : matrix m' n' α) (B : matrix n' (fin 0) α) :
A ⬝ B = λ _, ![] :=
funext (λ _, empty_eq _)
lemma mul_val_succ (A : matrix (fin m.succ) n' α) (B : matrix n' o' α) (i : fin m) (j : o') :
(A ⬝ B) i.succ j = (vec_tail A ⬝ B) i j := rfl
@[simp] lemma cons_mul (v : n' → α) (A : matrix (fin m) n' α) (B : matrix n' o' α) :
vec_cons v A ⬝ B = vec_cons (vec_mul v B) (A ⬝ B) :=
by { ext i j, refine fin.cases _ _ i, { refl }, simp [mul_val_succ] }
end mul
section vec_mul
variables [semiring α]
@[simp] lemma empty_vec_mul (v : fin 0 → α) (B : matrix (fin 0) o' α) :
vec_mul v B = 0 :=
rfl
@[simp] lemma vec_mul_empty (v : n' → α) (B : matrix n' (fin 0) α) :
vec_mul v B = ![] :=
empty_eq _
@[simp] lemma cons_vec_mul (x : α) (v : fin n → α) (B : matrix (fin n.succ) o' α) :
vec_mul (vec_cons x v) B = x • (vec_head B) + vec_mul v (vec_tail B) :=
by { ext i, simp [vec_mul] }
@[simp] lemma vec_mul_cons (v : fin n.succ → α) (w : o' → α) (B : matrix (fin n) o' α) :
vec_mul v (vec_cons w B) = vec_head v • w + vec_mul (vec_tail v) B :=
by { ext i, simp [vec_mul] }
end vec_mul
section mul_vec
variables [semiring α]
@[simp] lemma empty_mul_vec (A : matrix (fin 0) n' α) (v : n' → α) :
mul_vec A v = ![] :=
empty_eq _
@[simp] lemma mul_vec_empty (A : matrix m' (fin 0) α) (v : fin 0 → α) :
mul_vec A v = 0 :=
rfl
@[simp] lemma cons_mul_vec (v : n' → α) (A : fin m → n' → α) (w : n' → α) :
mul_vec (vec_cons v A) w = vec_cons (dot_product v w) (mul_vec A w) :=
by { ext i, refine fin.cases _ _ i; simp [mul_vec] }
@[simp] lemma mul_vec_cons {α} [comm_semiring α] (A : m' → (fin n.succ) → α) (x : α) (v : fin n → α) :
mul_vec A (vec_cons x v) = (x • vec_head ∘ A) + mul_vec (vec_tail ∘ A) v :=
by { ext i, simp [mul_vec, mul_comm] }
end mul_vec
section vec_mul_vec
variables [semiring α]
@[simp] lemma empty_vec_mul_vec (v : fin 0 → α) (w : n' → α) :
vec_mul_vec v w = ![] :=
empty_eq _
@[simp] lemma vec_mul_vec_empty (v : m' → α) (w : fin 0 → α) :
vec_mul_vec v w = λ _, ![] :=
funext (λ i, empty_eq _)
@[simp] lemma cons_vec_mul_vec (x : α) (v : fin m → α) (w : n' → α) :
vec_mul_vec (vec_cons x v) w = vec_cons (x • w) (vec_mul_vec v w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_mul_vec] }
@[simp] lemma vec_mul_vec_cons (v : m' → α) (x : α) (w : fin n → α) :
vec_mul_vec v (vec_cons x w) = λ i, v i • vec_cons x w :=
by { ext i j, simp [vec_mul_vec]}
end vec_mul_vec
section smul
variables [semiring α]
@[simp] lemma smul_empty (x : α) (v : fin 0 → α) : x • v = ![] := empty_eq _
@[simp] lemma smul_cons (x y : α) (v : fin n → α) :
x • vec_cons y v = vec_cons (x * y) (x • v) :=
by { ext i, refine fin.cases _ _ i; simp }
end smul
section add
variables [has_add α]
@[simp] lemma empty_add_empty (v w : fin 0 → α) : v + w = ![] := empty_eq _
@[simp] lemma cons_add (x : α) (v : fin n → α) (w : fin n.succ → α) :
vec_cons x v + w = vec_cons (x + vec_head w) (v + vec_tail w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
@[simp] lemma add_cons (v : fin n.succ → α) (y : α) (w : fin n → α) :
v + vec_cons y w = vec_cons (vec_head v + y) (vec_tail v + w) :=
by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] }
end add
section zero
variables [has_zero α]
@[simp] lemma zero_empty : (0 : fin 0 → α) = ![] :=
empty_eq _
@[simp] lemma cons_zero_zero : vec_cons (0 : α) (0 : fin n → α) = 0 :=
by { ext i j, refine fin.cases _ _ i, { refl }, simp }
@[simp] lemma head_zero : vec_head (0 : fin n.succ → α) = 0 := rfl
@[simp] lemma tail_zero : vec_tail (0 : fin n.succ → α) = 0 := rfl
@[simp] lemma cons_eq_zero_iff {v : fin n → α} {x : α} :
vec_cons x v = 0 ↔ x = 0 ∧ v = 0 :=
⟨ λ h, ⟨ congr_fun h 0, by { convert congr_arg vec_tail h, simp } ⟩,
λ ⟨hx, hv⟩, by simp [hx, hv] ⟩
open_locale classical
lemma cons_nonzero_iff {v : fin n → α} {x : α} :
vec_cons x v ≠ 0 ↔ (x ≠ 0 ∨ v ≠ 0) :=
⟨ λ h, not_and_distrib.mp (h ∘ cons_eq_zero_iff.mpr),
λ h, mt cons_eq_zero_iff.mp (not_and_distrib.mpr h) ⟩
end zero
section neg
variables [has_neg α]
@[simp] lemma neg_empty (v : fin 0 → α) : -v = ![] := empty_eq _
@[simp] lemma neg_cons (x : α) (v : fin n → α) :
-(vec_cons x v) = vec_cons (-x) (-v) :=
by { ext i, refine fin.cases _ _ i; simp }
end neg
section minor
@[simp] lemma minor_empty (A : matrix m' n' α) (row : fin 0 → m') (col : o' → n') :
minor A row col = ![] :=
empty_eq _
@[simp] lemma minor_cons_row (A : matrix m' n' α) (i : m') (row : fin m → m') (col : o' → n') :
minor A (vec_cons i row) col = vec_cons (λ j, A i (col j)) (minor A row col) :=
by { ext i j, refine fin.cases _ _ i; simp [minor] }
end minor
end matrix
|
0700b1f3b5a20248a8fa555f22fcc5ea31dc73ee
|
ec5e5a9dbe7f60fa5784d15211d8bf24ada0825c
|
/src/Alignment.lean
|
6337f78b752eb7eae21b1014f675e8538656d494
|
[] |
no_license
|
pnwamk/lean-llvm
|
fcd9a828e52e80eb197f7d9032b3846f2e09ef74
|
ebc3bca9a57a6aef29529d46394f560398fb5c9c
|
refs/heads/master
| 1,668,418,078,706
| 1,593,548,643,000
| 1,593,548,643,000
| 258,617,753
| 0
| 0
| null | 1,587,760,298,000
| 1,587,760,298,000
| null |
UTF-8
|
Lean
| false
| false
| 3,174
|
lean
|
import Init.Data.RBMap
namespace RBNode
universes u v
variables {α : Type u} {β : α → Type v}
section
variable (lt : α → α → Bool)
@[specialize] def upperBound : RBNode α β → α → Option (Sigma β) → Option (Sigma β)
| leaf, x, ub => ub
| node _ a ky vy b, x, ub =>
if lt x ky then upperBound a x (some ⟨ky, vy⟩)
else if lt ky x then upperBound b x ub
else some ⟨ky, vy⟩
end
end RBNode
namespace RBMap
universes u v
variables {α : Type u} {β : Type v} {lt : α → α → Bool}
/- (upperBound k) retrieves the kv pair of the smallest key larger than or equal to `k`,
if it exists -/
@[inline] def upperBound : RBMap α β lt → α → Option (Sigma (fun (k : α) => β))
| ⟨t, _⟩, x => t.upperBound lt x none
end RBMap
namespace LLVM
-- An alignment represents a number of bytes that must be a power of 2,
-- and is represented via its exponent
structure Alignment := (exponent : Nat)
-- 1-byte alignment, which is the minimum possible
def unaligned : Alignment := ⟨0⟩
-- 2-byte alignment
def align2 : Alignment := ⟨1⟩
-- 4-byte alignment
def align4 : Alignment := ⟨2⟩
-- 8-byte alignment
def align8 : Alignment := ⟨3⟩
-- 16-byte alignment
def align16 : Alignment := ⟨4⟩
def maxAlignment (x y: Alignment) : Alignment := ⟨Nat.max x.exponent y.exponent⟩
instance alignment.inh : Inhabited Alignment := ⟨unaligned⟩
partial def lg2aux : Nat → Nat → Nat
| r, 0 => r
| r, n => lg2aux (r+1) (n/2)
def toAlignment (x:Nat) : Option Alignment :=
let l := lg2aux 0 (x/2);
if 2^l = x then some ⟨l⟩ else none
-- @padToAlignment x a@ returns the smallest value aligned with @a@ not less than @x@.
def padToAlignment (x:Nat) (a:Alignment) :=
let m : Nat := 2^a.exponent;
(x + m - 1)/m * m
-- @padDownToAlignment x a@ returns the largest value aligned with @a@ that is not larger than @x@.
def padDownToAlignment (x:Nat) (a:Alignment) : Nat :=
let m : Nat := 2^a.exponent; x/m * m
def AlignInfo := RBMap Nat Alignment (λx y => decide (x < y))
-- Get alignment for the integer type of the specified bitwidth,
-- using LLVM's rules for integer types: "If no match is found, and
-- the type sought is an integer type, then the smallest integer type
-- that is larger than the bitwidth of the sought type is used. If
-- none of the specifications are larger than the bitwidth then the
-- largest integer type is used."
-- <http://llvm.org/docs/LangRef.html#langref-datalayout>
def computeIntegerAlignment (ai:AlignInfo) (k:Nat) : Alignment :=
match ai.upperBound k with
| some ⟨_, a⟩ => a
| none =>
match ai.max with
| some ⟨_, a⟩ => a
| none => unaligned
-- | Get alignment for a vector type of the specified bitwidth, using
-- LLVM's rules for vector types: "If no match is found, and the type
-- sought is a vector type, then the largest vector type that is
-- smaller than the sought vector type will be used as a fall back."
-- <http://llvm.org/docs/LangRef.html#langref-datalayout>
def computeVectorAlignment (ai:AlignInfo) (k:Nat) : Alignment :=
match ai.lowerBound k with
| some ⟨_, a⟩ => a
| none => unaligned
end LLVM
|
d6788c1d00764a2609ae152ffe4bcdc1f24a46f3
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/dynamics/omega_limit.lean
|
ccdbced232442a8ff42cb461be4bf241a55be254
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 16,642
|
lean
|
/-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import dynamics.flow
/-!
# ω-limits
For a function `ϕ : τ → α → β` where `β` is a topological space, we
define the ω-limit under `ϕ` of a set `s` in `α` with respect to
filter `f` on `τ`: an element `y : β` is in the ω-limit of `s` if the
forward images of `s` intersect arbitrarily small neighbourhoods of
`y` frequently "in the direction of `f`".
In practice `ϕ` is often a continuous monoid-act, but the definition
requires only that `ϕ` has a coercion to the appropriate function
type. In the case where `τ` is `ℕ` or `ℝ` and `f` is `at_top`, we
recover the usual definition of the ω-limit set as the set of all `y`
such that there exist sequences `(tₙ)`, `(xₙ)` such that `ϕ tₙ xₙ ⟶ y`
as `n ⟶ ∞`.
## Notations
The `omega_limit` locale provides the localised notation `ω` for
`omega_limit`, as well as `ω⁺` and `ω⁻` for `omega_limit at_top` and
`omega_limit at_bot` respectively for when the acting monoid is
endowed with an order.
-/
open set function filter
open_locale topological_space
/-!
### Definition and notation
-/
section omega_limit
variables {τ : Type*} {α : Type*} {β : Type*} {ι : Type*}
/-- The ω-limit of a set `s` under `ϕ` with respect to a filter `f` is
⋂ u ∈ f, cl (ϕ u s). -/
def omega_limit [topological_space β] (f : filter τ) (ϕ : τ → α → β) (s : set α) : set β :=
⋂ u ∈ f, closure (image2 ϕ u s)
localized "notation (name := omega_limit) `ω` := omega_limit" in omega_limit
localized "notation (name := omega_limit.at_top) `ω⁺` := omega_limit filter.at_top" in omega_limit
localized "notation (name := omega_limit.at_bot) `ω⁻` := omega_limit filter.at_bot" in omega_limit
variables [topological_space β]
variables (f : filter τ) (ϕ : τ → α → β) (s s₁ s₂: set α)
/-!
### Elementary properties
-/
lemma omega_limit_def : ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ u s) := rfl
lemma omega_limit_subset_of_tendsto {m : τ → τ} {f₁ f₂ : filter τ} (hf : tendsto m f₁ f₂) :
ω f₁ (λ t x, ϕ (m t) x) s ⊆ ω f₂ ϕ s :=
begin
refine Inter₂_mono' (λ u hu, ⟨m ⁻¹' u, tendsto_def.mp hf _ hu, _⟩),
rw ←image2_image_left,
exact closure_mono (image2_subset (image_preimage_subset _ _) subset.rfl),
end
lemma omega_limit_mono_left {f₁ f₂ : filter τ} (hf : f₁ ≤ f₂) : ω f₁ ϕ s ⊆ ω f₂ ϕ s :=
omega_limit_subset_of_tendsto ϕ s (tendsto_id'.2 hf)
lemma omega_limit_mono_right {s₁ s₂ : set α} (hs : s₁ ⊆ s₂) : ω f ϕ s₁ ⊆ ω f ϕ s₂ :=
Inter₂_mono $ λ u hu, closure_mono (image2_subset subset.rfl hs)
lemma is_closed_omega_limit : is_closed (ω f ϕ s) :=
is_closed_Inter $ λ u, is_closed_Inter $ λ hu, is_closed_closure
lemma maps_to_omega_limit' {α' β' : Type*} [topological_space β'] {f : filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : set α'} (hs : maps_to ga s s')
{gb : β → β'} (hg : ∀ᶠ t in f, eq_on (gb ∘ (ϕ t)) (ϕ' t ∘ ga) s)
(hgc : continuous gb) :
maps_to gb (ω f ϕ s) (ω f ϕ' s') :=
begin
simp only [omega_limit_def, mem_Inter, maps_to],
intros y hy u hu,
refine map_mem_closure hgc (hy _ (inter_mem hu hg)) (forall_image2_iff.2 $ λ t ht x hx, _),
calc gb (ϕ t x) = ϕ' t (ga x) : ht.2 hx
... ∈ image2 ϕ' u s' : mem_image2_of_mem ht.1 (hs hx)
end
lemma maps_to_omega_limit {α' β' : Type*} [topological_space β'] {f : filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : set α'} (hs : maps_to ga s s')
{gb : β → β'} (hg : ∀ t x, gb (ϕ t x) = ϕ' t (ga x))
(hgc : continuous gb) :
maps_to gb (ω f ϕ s) (ω f ϕ' s') :=
maps_to_omega_limit' _ hs (eventually_of_forall $ λ t x hx, hg t x) hgc
lemma omega_limit_image_eq {α' : Type*} (ϕ : τ → α' → β) (f : filter τ) (g : α → α') :
ω f ϕ (g '' s) = ω f (λ t x, ϕ t (g x)) s :=
by simp only [omega_limit, image2_image_right]
lemma omega_limit_preimage_subset {α' : Type*} (ϕ : τ → α' → β) (s : set α') (f : filter τ)
(g : α → α') :
ω f (λ t x, ϕ t (g x)) (g ⁻¹' s) ⊆ ω f ϕ s :=
maps_to_omega_limit _ (maps_to_preimage _ _) (λ t x, rfl) continuous_id
/-!
### Equivalent definitions of the omega limit
The next few lemmas are various versions of the property
characterising ω-limits:
-/
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
preimages of an arbitrary neighbourhood of `y` frequently
(w.r.t. `f`) intersects of `s`. -/
lemma mem_omega_limit_iff_frequently (y : β) : y ∈ ω f ϕ s ↔
∀ n ∈ 𝓝 y, ∃ᶠ t in f, (s ∩ ϕ t ⁻¹' n).nonempty :=
begin
simp_rw [frequently_iff, omega_limit_def, mem_Inter, mem_closure_iff_nhds],
split,
{ intros h _ hn _ hu,
rcases h _ hu _ hn with ⟨_, _, _, _, ht, hx, hϕtx⟩,
exact ⟨_, ht, _, hx, by rwa [mem_preimage, hϕtx]⟩, },
{ intros h _ hu _ hn,
rcases h _ hn hu with ⟨_, ht, _, hx, hϕtx⟩,
exact ⟨_, hϕtx, _, _, ht, hx, rfl⟩ }
end
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
forward images of `s` frequently (w.r.t. `f`) intersect arbitrary
neighbourhoods of `y`. -/
lemma mem_omega_limit_iff_frequently₂ (y : β) : y ∈ ω f ϕ s ↔
∀ n ∈ 𝓝 y, ∃ᶠ t in f, (ϕ t '' s ∩ n).nonempty :=
by simp_rw [mem_omega_limit_iff_frequently, image_inter_nonempty_iff]
/-- An element `y` is in the ω-limit of `x` w.r.t. `f` if the forward
images of `x` frequently (w.r.t. `f`) falls within an arbitrary
neighbourhood of `y`. -/
lemma mem_omega_limit_singleton_iff_map_cluster_point (x : α) (y : β) :
y ∈ ω f ϕ {x} ↔ map_cluster_pt y f (λ t, ϕ t x) :=
by simp_rw [mem_omega_limit_iff_frequently, map_cluster_pt_iff, singleton_inter_nonempty,
mem_preimage]
/-!
### Set operations and omega limits
-/
lemma omega_limit_inter : ω f ϕ (s₁ ∩ s₂) ⊆ ω f ϕ s₁ ∩ ω f ϕ s₂ :=
subset_inter (omega_limit_mono_right _ _ (inter_subset_left _ _))
(omega_limit_mono_right _ _(inter_subset_right _ _))
lemma omega_limit_Inter (p : ι → set α) : ω f ϕ (⋂ i, p i) ⊆ ⋂ i, ω f ϕ (p i) :=
subset_Inter $ λ i, omega_limit_mono_right _ _ (Inter_subset _ _)
lemma omega_limit_union : ω f ϕ (s₁ ∪ s₂) = ω f ϕ s₁ ∪ ω f ϕ s₂ :=
begin
ext y, split,
{ simp only [mem_union, mem_omega_limit_iff_frequently, union_inter_distrib_right,
union_nonempty, frequently_or_distrib],
contrapose!,
simp only [not_frequently, not_nonempty_iff_eq_empty, ← subset_empty_iff],
rintro ⟨⟨n₁, hn₁, h₁⟩, ⟨n₂, hn₂, h₂⟩⟩,
refine ⟨n₁ ∩ n₂, inter_mem hn₁ hn₂, h₁.mono $ λ t, _, h₂.mono $ λ t, _⟩,
exacts [subset.trans $ inter_subset_inter_right _ $ preimage_mono $ inter_subset_left _ _,
subset.trans $ inter_subset_inter_right _ $ preimage_mono $ inter_subset_right _ _] },
{ rintros (hy|hy),
exacts [omega_limit_mono_right _ _ (subset_union_left _ _) hy,
omega_limit_mono_right _ _ (subset_union_right _ _) hy] },
end
lemma omega_limit_Union (p : ι → set α) : (⋃ i, ω f ϕ (p i)) ⊆ ω f ϕ ⋃ i, p i :=
by { rw Union_subset_iff,
exact λ i, omega_limit_mono_right _ _ (subset_Union _ _)}
/-!
Different expressions for omega limits, useful for rewrites. In
particular, one may restrict the intersection to sets in `f` which are
subsets of some set `v` also in `f`.
-/
lemma omega_limit_eq_Inter : ω f ϕ s = ⋂ u : ↥f.sets, closure (image2 ϕ u s) :=
bInter_eq_Inter _ _
lemma omega_limit_eq_bInter_inter {v : set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ (u ∩ v) s) :=
subset.antisymm
(Inter₂_mono' $ λ u hu, ⟨u ∩ v, inter_mem hu hv, subset.rfl⟩)
(Inter₂_mono $ λ u hu, closure_mono $ image2_subset (inter_subset_left _ _) subset.rfl)
lemma omega_limit_eq_Inter_inter {v : set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ (u : ↥f.sets), closure (image2 ϕ (u ∩ v) s) :=
by { rw omega_limit_eq_bInter_inter _ _ _ hv, apply bInter_eq_Inter }
lemma omega_limit_subset_closure_fw_image {u : set τ} (hu : u ∈ f) :
ω f ϕ s ⊆ closure (image2 ϕ u s) :=
begin
rw omega_limit_eq_Inter,
intros _ hx,
rw mem_Inter at hx,
exact hx ⟨u, hu⟩,
end
/-!
### `ω-limits and compactness
-/
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
lemma eventually_closure_subset_of_is_compact_absorbing_of_is_open_of_omega_limit_subset'
{c : set β} (hc₁ : is_compact c) (hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c)
{n : set β} (hn₁ : is_open n) (hn₂ : ω f ϕ s ⊆ n) :
∃ u ∈ f, closure (image2 ϕ u s) ⊆ n :=
begin
rcases hc₂ with ⟨v, hv₁, hv₂⟩,
let k := closure (image2 ϕ v s),
have hk : is_compact (k \ n) :=
is_compact.diff (compact_of_is_closed_subset hc₁ is_closed_closure hv₂) hn₁,
let j := λ u, (closure (image2 ϕ (u ∩ v) s))ᶜ,
have hj₁ : ∀ u ∈ f, is_open (j u), from
λ _ _, (is_open_compl_iff.mpr is_closed_closure),
have hj₂ : k \ n ⊆ ⋃ u ∈ f, j u, begin
have : (⋃ u ∈ f, j u) = ⋃ (u : ↥f.sets), j u, from bUnion_eq_Union _ _,
rw [this, diff_subset_comm, diff_Union],
rw omega_limit_eq_Inter_inter _ _ _ hv₁ at hn₂,
simp_rw diff_compl,
rw ←inter_Inter,
exact subset.trans (inter_subset_right _ _) hn₂,
end,
rcases hk.elim_finite_subcover_image hj₁ hj₂ with ⟨g, hg₁ : ∀ u ∈ g, u ∈ f, hg₂, hg₃⟩,
let w := (⋂ u ∈ g, u) ∩ v,
have hw₂ : w ∈ f, by simpa *,
have hw₃ : k \ n ⊆ (closure (image2 ϕ w s))ᶜ, from
calc k \ n ⊆ ⋃ u ∈ g, j u : hg₃
... ⊆ (closure (image2 ϕ w s))ᶜ :
begin
simp only [Union_subset_iff, compl_subset_compl],
intros u hu,
mono* using [w],
exact Inter_subset_of_subset u (Inter_subset_of_subset hu subset.rfl),
end,
have hw₄ : kᶜ ⊆ (closure (image2 ϕ w s))ᶜ, begin
rw compl_subset_compl,
calc closure (image2 ϕ w s)
⊆ _ : closure_mono (image2_subset (inter_subset_right _ _) subset.rfl)
end,
have hnc : nᶜ ⊆ (k \ n) ∪ kᶜ, by rw [union_comm, ←inter_subset, diff_eq, inter_comm],
have hw : closure (image2 ϕ w s) ⊆ n, from
compl_subset_compl.mp (subset.trans hnc (union_subset hw₃ hw₄)),
exact ⟨_, hw₂, hw⟩
end
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
lemma eventually_closure_subset_of_is_compact_absorbing_of_is_open_of_omega_limit_subset
[t2_space β] {c : set β} (hc₁ : is_compact c) (hc₂ : ∀ᶠ t in f, maps_to (ϕ t) s c)
{n : set β} (hn₁ : is_open n) (hn₂ : ω f ϕ s ⊆ n) :
∃ u ∈ f, closure (image2 ϕ u s) ⊆ n :=
eventually_closure_subset_of_is_compact_absorbing_of_is_open_of_omega_limit_subset'
f ϕ _ hc₁ ⟨_, hc₂, closure_minimal (image2_subset_iff.2 (λ t, id)) hc₁.is_closed⟩ hn₁ hn₂
lemma eventually_maps_to_of_is_compact_absorbing_of_is_open_of_omega_limit_subset
[t2_space β] {c : set β} (hc₁ : is_compact c) (hc₂ : ∀ᶠ t in f, maps_to (ϕ t) s c)
{n : set β} (hn₁ : is_open n) (hn₂ : ω f ϕ s ⊆ n) :
∀ᶠ t in f, maps_to (ϕ t) s n :=
begin
rcases eventually_closure_subset_of_is_compact_absorbing_of_is_open_of_omega_limit_subset
f ϕ s hc₁ hc₂ hn₁ hn₂ with ⟨u, hu_mem, hu⟩,
refine mem_of_superset hu_mem (λ t ht x hx, _),
exact hu (subset_closure $ mem_image2_of_mem ht hx)
end
lemma eventually_closure_subset_of_is_open_of_omega_limit_subset [compact_space β]
{v : set β} (hv₁ : is_open v) (hv₂ : ω f ϕ s ⊆ v) :
∃ u ∈ f, closure (image2 ϕ u s) ⊆ v :=
eventually_closure_subset_of_is_compact_absorbing_of_is_open_of_omega_limit_subset'
_ _ _ compact_univ ⟨univ, univ_mem, subset_univ _⟩ hv₁ hv₂
lemma eventually_maps_to_of_is_open_of_omega_limit_subset [compact_space β]
{v : set β} (hv₁ : is_open v) (hv₂ : ω f ϕ s ⊆ v) :
∀ᶠ t in f, maps_to (ϕ t) s v :=
begin
rcases eventually_closure_subset_of_is_open_of_omega_limit_subset f ϕ s hv₁ hv₂
with ⟨u, hu_mem, hu⟩,
refine mem_of_superset hu_mem (λ t ht x hx, _),
exact hu (subset_closure $ mem_image2_of_mem ht hx)
end
/-- The ω-limit of a nonempty set w.r.t. a nontrivial filter is nonempty. -/
lemma nonempty_omega_limit_of_is_compact_absorbing [ne_bot f] {c : set β} (hc₁ : is_compact c)
(hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c) (hs : s.nonempty) :
(ω f ϕ s).nonempty :=
begin
rcases hc₂ with ⟨v, hv₁, hv₂⟩,
rw omega_limit_eq_Inter_inter _ _ _ hv₁,
apply is_compact.nonempty_Inter_of_directed_nonempty_compact_closed,
{ rintro ⟨u₁, hu₁⟩ ⟨u₂, hu₂⟩,
use ⟨u₁ ∩ u₂, inter_mem hu₁ hu₂⟩, split,
all_goals { exact closure_mono (image2_subset
(inter_subset_inter_left _ (by simp)) subset.rfl) }},
{ intro u,
have hn : (image2 ϕ (u ∩ v) s).nonempty, from
nonempty.image2 (nonempty_of_mem (inter_mem u.prop hv₁)) hs,
exact hn.mono subset_closure },
{ intro _,
apply compact_of_is_closed_subset hc₁ is_closed_closure,
calc _ ⊆ closure (image2 ϕ v s) : closure_mono (image2_subset
(inter_subset_right _ _) subset.rfl)
... ⊆ c : hv₂ },
{ exact λ _, is_closed_closure },
end
lemma nonempty_omega_limit [compact_space β] [ne_bot f] (hs : s.nonempty) :
(ω f ϕ s).nonempty :=
nonempty_omega_limit_of_is_compact_absorbing _ _ _
compact_univ ⟨univ, univ_mem, subset_univ _⟩ hs
end omega_limit
/-!
### ω-limits of Flows by a Monoid
-/
namespace flow
variables
{τ : Type*} [topological_space τ] [add_monoid τ] [has_continuous_add τ]
{α : Type*} [topological_space α]
(f : filter τ) (ϕ : flow τ α) (s : set α)
open_locale omega_limit
lemma is_invariant_omega_limit (hf : ∀ t, tendsto ((+) t) f f) :
is_invariant ϕ (ω f ϕ s) :=
begin
refine λ t, maps_to.mono_right _ (omega_limit_subset_of_tendsto ϕ s (hf t)),
exact maps_to_omega_limit _ (maps_to_id _) (λ t' x, (ϕ.map_add _ _ _).symm)
(continuous_const.flow ϕ continuous_id)
end
lemma omega_limit_image_subset (t : τ) (ht : tendsto (+ t) f f) :
ω f ϕ (ϕ t '' s) ⊆ ω f ϕ s :=
begin
simp only [omega_limit_image_eq, ← map_add],
exact omega_limit_subset_of_tendsto ϕ s ht
end
end flow
/-!
### ω-limits of Flows by a Group
-/
namespace flow
variables
{τ : Type*} [topological_space τ] [add_comm_group τ] [topological_add_group τ]
{α : Type*} [topological_space α]
(f : filter τ) (ϕ : flow τ α) (s : set α)
open_locale omega_limit
/-- the ω-limit of a forward image of `s` is the same as the ω-limit of `s`. -/
@[simp] lemma omega_limit_image_eq (hf : ∀ t, tendsto (+ t) f f) (t : τ) :
ω f ϕ (ϕ t '' s) = ω f ϕ s :=
subset.antisymm (omega_limit_image_subset _ _ _ _ (hf t)) $
calc ω f ϕ s = ω f ϕ (ϕ (-t) '' (ϕ t '' s)) : by simp [image_image, ← map_add]
... ⊆ ω f ϕ (ϕ t '' s) : omega_limit_image_subset _ _ _ _ (hf _)
lemma omega_limit_omega_limit (hf : ∀ t, tendsto ((+) t) f f) :
ω f ϕ (ω f ϕ s) ⊆ ω f ϕ s :=
begin
simp only [subset_def, mem_omega_limit_iff_frequently₂, frequently_iff],
intros _ h,
rintro n hn u hu,
rcases mem_nhds_iff.mp hn with ⟨o, ho₁, ho₂, ho₃⟩,
rcases h o (is_open.mem_nhds ho₂ ho₃) hu with ⟨t, ht₁, ht₂⟩,
have l₁ : (ω f ϕ s ∩ o).nonempty, from
ht₂.mono (inter_subset_inter_left _
((is_invariant_iff_image _ _).mp (is_invariant_omega_limit _ _ _ hf) _)),
have l₂ : ((closure (image2 ϕ u s)) ∩ o).nonempty :=
l₁.mono (λ b hb, ⟨omega_limit_subset_closure_fw_image _ _ _ hu hb.1, hb.2⟩),
have l₃ : (o ∩ image2 ϕ u s).nonempty,
begin
rcases l₂ with ⟨b, hb₁, hb₂⟩,
exact mem_closure_iff_nhds.mp hb₁ o (is_open.mem_nhds ho₂ hb₂)
end,
rcases l₃ with ⟨ϕra, ho, ⟨_, _, hr, ha, hϕra⟩⟩,
exact ⟨_, hr, ϕra, ⟨_, ha, hϕra⟩, ho₁ ho⟩,
end
end flow
|
3afefa6c700ec6b0592daa46cf34de654ad3803c
|
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
|
/stage0/src/Init/Data/UInt.lean
|
e6bf545e2aa1671551bfb1e0423242d26d5564cd
|
[
"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
| 11,812
|
lean
|
/-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Fin.Basic
import Init.System.Platform
open Nat
@[extern "lean_uint8_of_nat"]
def UInt8.ofNat (n : @& Nat) : UInt8 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt8 := UInt8.ofNat
@[extern "lean_uint8_to_nat"]
def UInt8.toNat (n : UInt8) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt8.add (a b : UInt8) : UInt8 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt8.sub (a b : UInt8) : UInt8 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt8.mul (a b : UInt8) : UInt8 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt8.div (a b : UInt8) : UInt8 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt8.mod (a b : UInt8) : UInt8 := ⟨a.val % b.val⟩
@[extern "lean_uint8_modn"]
def UInt8.modn (a : UInt8) (n : @& Nat) : UInt8 := ⟨a.val % n⟩
@[extern c inline "#1 & #2"]
def UInt8.land (a b : UInt8) : UInt8 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt8.lor (a b : UInt8) : UInt8 := ⟨Fin.lor a.val b.val⟩
def UInt8.lt (a b : UInt8) : Prop := a.val < b.val
def UInt8.le (a b : UInt8) : Prop := a.val ≤ b.val
instance : OfNat UInt8 n := ⟨UInt8.ofNat n⟩
instance : Add UInt8 := ⟨UInt8.add⟩
instance : Sub UInt8 := ⟨UInt8.sub⟩
instance : Mul UInt8 := ⟨UInt8.mul⟩
instance : Mod UInt8 := ⟨UInt8.mod⟩
instance : HMod UInt8 Nat UInt8 := ⟨UInt8.modn⟩
instance : Div UInt8 := ⟨UInt8.div⟩
instance : HasLess UInt8 := ⟨UInt8.lt⟩
instance : HasLessEq UInt8 := ⟨UInt8.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt8.decLt (a b : UInt8) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt8.decLe (a b : UInt8) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt8) : Decidable (a < b) := UInt8.decLt a b
instance (a b : UInt8) : Decidable (a ≤ b) := UInt8.decLe a b
@[extern "lean_uint16_of_nat"]
def UInt16.ofNat (n : @& Nat) : UInt16 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt16 := UInt16.ofNat
@[extern "lean_uint16_to_nat"]
def UInt16.toNat (n : UInt16) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt16.add (a b : UInt16) : UInt16 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt16.sub (a b : UInt16) : UInt16 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt16.mul (a b : UInt16) : UInt16 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt16.div (a b : UInt16) : UInt16 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt16.mod (a b : UInt16) : UInt16 := ⟨a.val % b.val⟩
@[extern "lean_uint16_modn"]
def UInt16.modn (a : UInt16) (n : @& Nat) : UInt16 := ⟨a.val % n⟩
@[extern c inline "#1 & #2"]
def UInt16.land (a b : UInt16) : UInt16 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt16.lor (a b : UInt16) : UInt16 := ⟨Fin.lor a.val b.val⟩
def UInt16.lt (a b : UInt16) : Prop := a.val < b.val
def UInt16.le (a b : UInt16) : Prop := a.val ≤ b.val
instance : OfNat UInt16 n := ⟨UInt16.ofNat n⟩
instance : Add UInt16 := ⟨UInt16.add⟩
instance : Sub UInt16 := ⟨UInt16.sub⟩
instance : Mul UInt16 := ⟨UInt16.mul⟩
instance : Mod UInt16 := ⟨UInt16.mod⟩
instance : HMod UInt16 Nat UInt16 := ⟨UInt16.modn⟩
instance : Div UInt16 := ⟨UInt16.div⟩
instance : HasLess UInt16 := ⟨UInt16.lt⟩
instance : HasLessEq UInt16 := ⟨UInt16.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt16.decLt (a b : UInt16) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt16.decLe (a b : UInt16) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt16) : Decidable (a < b) := UInt16.decLt a b
instance (a b : UInt16) : Decidable (a ≤ b) := UInt16.decLe a b
@[extern "lean_uint32_of_nat"]
def UInt32.ofNat (n : @& Nat) : UInt32 := ⟨Fin.ofNat n⟩
@[extern "lean_uint32_of_nat"]
def UInt32.ofNat' (n : Nat) (h : n < UInt32.size) : UInt32 := ⟨⟨n, h⟩⟩
abbrev Nat.toUInt32 := UInt32.ofNat
@[extern c inline "#1 + #2"]
def UInt32.add (a b : UInt32) : UInt32 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt32.sub (a b : UInt32) : UInt32 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt32.mul (a b : UInt32) : UInt32 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt32.div (a b : UInt32) : UInt32 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt32.mod (a b : UInt32) : UInt32 := ⟨a.val % b.val⟩
@[extern "lean_uint32_modn"]
def UInt32.modn (a : UInt32) (n : @& Nat) : UInt32 := ⟨a.val % n⟩
@[extern c inline "#1 & #2"]
def UInt32.land (a b : UInt32) : UInt32 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt32.lor (a b : UInt32) : UInt32 := ⟨Fin.lor a.val b.val⟩
@[extern c inline "((uint8_t)#1)"]
def UInt32.toUInt8 (a : UInt32) : UInt8 := a.toNat.toUInt8
@[extern c inline "((uint16_t)#1)"]
def UInt32.toUInt16 (a : UInt32) : UInt16 := a.toNat.toUInt16
@[extern c inline "((uint32_t)#1)"]
def UInt8.toUInt32 (a : UInt8) : UInt32 := a.toNat.toUInt32
instance : OfNat UInt32 n := ⟨UInt32.ofNat n⟩
instance : Add UInt32 := ⟨UInt32.add⟩
instance : Sub UInt32 := ⟨UInt32.sub⟩
instance : Mul UInt32 := ⟨UInt32.mul⟩
instance : Mod UInt32 := ⟨UInt32.mod⟩
instance : HMod UInt32 Nat UInt32 := ⟨UInt32.modn⟩
instance : Div UInt32 := ⟨UInt32.div⟩
@[extern c inline "#1 << #2"]
constant UInt32.shiftLeft (a b : UInt32) : UInt32
@[extern c inline "#1 >> #2"]
constant UInt32.shiftRight (a b : UInt32) : UInt32
@[extern "lean_uint64_of_nat"]
def UInt64.ofNat (n : @& Nat) : UInt64 := ⟨Fin.ofNat n⟩
abbrev Nat.toUInt64 := UInt64.ofNat
@[extern "lean_uint64_to_nat"]
def UInt64.toNat (n : UInt64) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def UInt64.add (a b : UInt64) : UInt64 := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def UInt64.sub (a b : UInt64) : UInt64 := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def UInt64.mul (a b : UInt64) : UInt64 := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def UInt64.div (a b : UInt64) : UInt64 := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def UInt64.mod (a b : UInt64) : UInt64 := ⟨a.val % b.val⟩
@[extern "lean_uint64_modn"]
def UInt64.modn (a : UInt64) (n : @& Nat) : UInt64 := ⟨a.val % n⟩
@[extern c inline "#1 & #2"]
def UInt64.land (a b : UInt64) : UInt64 := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def UInt64.lor (a b : UInt64) : UInt64 := ⟨Fin.lor a.val b.val⟩
def UInt64.lt (a b : UInt64) : Prop := a.val < b.val
def UInt64.le (a b : UInt64) : Prop := a.val ≤ b.val
@[extern c inline "((uint8_t)#1)"]
def UInt64.toUInt8 (a : UInt64) : UInt8 := a.toNat.toUInt8
@[extern c inline "((uint16_t)#1)"]
def UInt64.toUInt16 (a : UInt64) : UInt16 := a.toNat.toUInt16
@[extern c inline "((uint32_t)#1)"]
def UInt64.toUInt32 (a : UInt64) : UInt32 := a.toNat.toUInt32
@[extern c inline "((uint64_t)#1)"]
def UInt32.toUInt64 (a : UInt32) : UInt64 := a.toNat.toUInt64
-- TODO(Leo): give reference implementation for shiftLeft and shiftRight, and define them for other UInt types
@[extern c inline "#1 << #2"]
constant UInt64.shiftLeft (a b : UInt64) : UInt64
@[extern c inline "#1 >> #2"]
constant UInt64.shiftRight (a b : UInt64) : UInt64
instance : OfNat UInt64 n := ⟨UInt64.ofNat n⟩
instance : Add UInt64 := ⟨UInt64.add⟩
instance : Sub UInt64 := ⟨UInt64.sub⟩
instance : Mul UInt64 := ⟨UInt64.mul⟩
instance : Mod UInt64 := ⟨UInt64.mod⟩
instance : HMod UInt64 Nat UInt64 := ⟨UInt64.modn⟩
instance : Div UInt64 := ⟨UInt64.div⟩
instance : HasLess UInt64 := ⟨UInt64.lt⟩
instance : HasLessEq UInt64 := ⟨UInt64.le⟩
@[extern c inline "(uint64_t)#1"]
def Bool.toUInt64 (b : Bool) : UInt64 := if b then 1 else 0
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def UInt64.decLt (a b : UInt64) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def UInt64.decLe (a b : UInt64) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : UInt64) : Decidable (a < b) := UInt64.decLt a b
instance (a b : UInt64) : Decidable (a ≤ b) := UInt64.decLe a b
theorem usizeSzGt0 : USize.size > 0 :=
Nat.posPowOfPos System.Platform.numBits (Nat.zeroLtSucc _)
@[extern "lean_usize_of_nat"]
def USize.ofNat (n : @& Nat) : USize := ⟨Fin.ofNat' n usizeSzGt0⟩
abbrev Nat.toUSize := USize.ofNat
@[extern "lean_usize_to_nat"]
def USize.toNat (n : USize) : Nat := n.val.val
@[extern c inline "#1 + #2"]
def USize.add (a b : USize) : USize := ⟨a.val + b.val⟩
@[extern c inline "#1 - #2"]
def USize.sub (a b : USize) : USize := ⟨a.val - b.val⟩
@[extern c inline "#1 * #2"]
def USize.mul (a b : USize) : USize := ⟨a.val * b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 / #2"]
def USize.div (a b : USize) : USize := ⟨a.val / b.val⟩
@[extern c inline "#2 == 0 ? 0 : #1 % #2"]
def USize.mod (a b : USize) : USize := ⟨a.val % b.val⟩
@[extern "lean_usize_modn"]
def USize.modn (a : USize) (n : @& Nat) : USize := ⟨a.val % n⟩
@[extern c inline "#1 & #2"]
def USize.land (a b : USize) : USize := ⟨Fin.land a.val b.val⟩
@[extern c inline "#1 | #2"]
def USize.lor (a b : USize) : USize := ⟨Fin.lor a.val b.val⟩
@[extern c inline "#1"]
def UInt32.toUSize (a : UInt32) : USize := a.toNat.toUSize
@[extern c inline "((size_t)#1)"]
def UInt64.toUSize (a : UInt64) : USize := a.toNat.toUSize
@[extern c inline "(uint32_t)#1"]
def USize.toUInt32 (a : USize) : UInt32 := a.toNat.toUInt32
-- TODO(Leo): give reference implementation for shiftLeft and shiftRight, and define them for other UInt types
@[extern c inline "#1 << #2"]
constant USize.shiftLeft (a b : USize) : USize
@[extern c inline "#1 >> #2"]
constant USize.shiftRight (a b : USize) : USize
def USize.lt (a b : USize) : Prop := a.val < b.val
def USize.le (a b : USize) : Prop := a.val ≤ b.val
instance : OfNat USize n := ⟨USize.ofNat n⟩
instance : Add USize := ⟨USize.add⟩
instance : Sub USize := ⟨USize.sub⟩
instance : Mul USize := ⟨USize.mul⟩
instance : Mod USize := ⟨USize.mod⟩
instance : HMod USize Nat USize := ⟨USize.modn⟩
instance : Div USize := ⟨USize.div⟩
instance : HasLess USize := ⟨USize.lt⟩
instance : HasLessEq USize := ⟨USize.le⟩
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 < #2"]
def USize.decLt (a b : USize) : Decidable (a < b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n < m))
set_option bootstrap.gen_matcher_code false in
@[extern c inline "#1 <= #2"]
def USize.decLe (a b : USize) : Decidable (a ≤ b) :=
match a, b with
| ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (n <= m))
instance (a b : USize) : Decidable (a < b) := USize.decLt a b
instance (a b : USize) : Decidable (a ≤ b) := USize.decLe a b
theorem USize.modnLt {m : Nat} : ∀ (u : USize), m > 0 → USize.toNat (u % m) < m
| ⟨u⟩, h => Fin.modnLt u h
|
09d6166a357efbaccb3234134a2583eb8f9826c2
|
4727251e0cd73359b15b664c3170e5d754078599
|
/archive/imo/imo2008_q3.lean
|
ce940546064a30a6679198216961bf74850c038d
|
[
"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,833
|
lean
|
/-
Copyright (c) 2021 Manuel Candales. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Manuel Candales
-/
import data.real.basic
import data.real.sqrt
import data.nat.prime
import number_theory.primes_congruent_one
import number_theory.legendre_symbol.quadratic_reciprocity
import tactic.linear_combination
/-!
# IMO 2008 Q3
Prove that there exist infinitely many positive integers `n` such that `n^2 + 1` has a prime
divisor which is greater than `2n + √(2n)`.
# Solution
We first prove the following lemma: for every prime `p > 20`, satisfying `p ≡ 1 [MOD 4]`,
there exists `n ∈ ℕ` such that `p ∣ n^2 + 1` and `p > 2n + √(2n)`. Then the statement of the
problem follows from the fact that there exist infinitely many primes `p ≡ 1 [MOD 4]`.
To prove the lemma, notice that `p ≡ 1 [MOD 4]` implies `∃ n ∈ ℕ` such that `n^2 ≡ -1 [MOD p]`
and we can take this `n` such that `n ≤ p/2`. Let `k = p - 2n ≥ 0`. Then we have:
`k^2 + 4 = (p - 2n)^2 + 4 ≣ 4n^2 + 4 ≡ 0 [MOD p]`. Then `k^2 + 4 ≥ p` and so `k ≥ √(p - 4) > 4`.
Then `p = 2n + k ≥ 2n + √(p - 4) = 2n + √(2n + k - 4) > √(2n)` and we are done.
-/
open real
lemma p_lemma (p : ℕ) (hpp : nat.prime p) (hp_mod_4_eq_1 : p ≡ 1 [MOD 4]) (hp_gt_20 : p > 20) :
∃ n : ℕ, p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) :=
begin
haveI := fact.mk hpp,
have hp_mod_4_ne_3 : p % 4 ≠ 3, { linarith [(show p % 4 = 1, by exact hp_mod_4_eq_1)] },
obtain ⟨y, hy⟩ := (zmod.exists_sq_eq_neg_one_iff p).mpr hp_mod_4_ne_3,
let m := zmod.val_min_abs y,
let n := int.nat_abs m,
have hnat₁ : p ∣ n ^ 2 + 1,
{ refine int.coe_nat_dvd.mp _,
simp only [int.nat_abs_sq, int.coe_nat_pow, int.coe_nat_succ, int.coe_nat_dvd.mp],
refine (zmod.int_coe_zmod_eq_zero_iff_dvd (m ^ 2 + 1) p).mp _,
simp only [int.cast_pow, int.cast_add, int.cast_one, zmod.coe_val_min_abs],
rw [pow_two, ← hy], exact add_left_neg 1 },
have hnat₂ : n ≤ p / 2 := zmod.nat_abs_val_min_abs_le y,
have hnat₃ : p ≥ 2 * n, { linarith [nat.div_mul_le_self p 2] },
set k : ℕ := p - 2 * n with hnat₄,
have hnat₅ : p ∣ k ^ 2 + 4,
{ cases hnat₁ with x hx,
have : (p:ℤ) ∣ k ^ 2 + 4,
{ use (p:ℤ) - 4 * n + 4 * x,
have hcast₁ : (k:ℤ) = p - 2 * n, { assumption_mod_cast },
have hcast₂ : (n:ℤ) ^ 2 + 1 = p * x, { assumption_mod_cast },
linear_combination (hcast₁, (k:ℤ) + p - 2 * n) (hcast₂, 4) },
assumption_mod_cast },
have hnat₆ : k ^ 2 + 4 ≥ p := nat.le_of_dvd (k ^ 2 + 3).succ_pos hnat₅,
have hreal₁ : (k:ℝ) = p - 2 * n, { assumption_mod_cast },
have hreal₂ : (p:ℝ) > 20, { assumption_mod_cast },
have hreal₃ : (k:ℝ) ^ 2 + 4 ≥ p, { assumption_mod_cast },
have hreal₅ : (k:ℝ) > 4,
{ apply lt_of_pow_lt_pow 2 k.cast_nonneg,
linarith only [hreal₂, hreal₃] },
have hreal₆ : (k:ℝ) > sqrt (2 * n),
{ apply lt_of_pow_lt_pow 2 k.cast_nonneg,
rw sq_sqrt (mul_nonneg zero_le_two n.cast_nonneg),
linarith only [hreal₁, hreal₃, hreal₅] },
exact ⟨n, hnat₁, by linarith only [hreal₆, hreal₁]⟩,
end
theorem imo2008_q3 : ∀ N : ℕ, ∃ n : ℕ, n ≥ N ∧
∃ p : ℕ, nat.prime p ∧ p ∣ n ^ 2 + 1 ∧ (p : ℝ) > 2 * n + sqrt(2 * n) :=
begin
intro N,
obtain ⟨p, hpp, hineq₁, hpmod4⟩ := nat.exists_prime_ge_modeq_one (N ^ 2 + 21) zero_lt_four,
obtain ⟨n, hnat, hreal⟩ := p_lemma p hpp hpmod4 (by linarith [hineq₁, nat.zero_le (N ^ 2)]),
have hineq₂ : n ^ 2 + 1 ≥ p := nat.le_of_dvd (n ^ 2).succ_pos hnat,
have hineq₃ : n * n ≥ N * N, { linarith [hineq₁, hineq₂] },
have hn_ge_N : n ≥ N := nat.mul_self_le_mul_self_iff.mpr hineq₃,
exact ⟨n, hn_ge_N, p, hpp, hnat, hreal⟩,
end
|
409e3447947dacdf35b4c469bda831c6c7e834f7
|
4ad6af7525e674c3cdc623c1495472954f3ce34c
|
/src/02_three_languages.lean
|
7bdedf6d12ac37786604c335723e44532c2c4362
|
[] |
no_license
|
alcides/lean3_tutorial
|
4bf48026f7cfa5ae80e9a75f46ca23364d455810
|
7a871e00c4fd5cb000929a59e1bd804a626ef277
|
refs/heads/master
| 1,663,719,613,974
| 1,591,141,389,000
| 1,591,141,389,000
| 268,600,781
| 5
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,947
|
lean
|
import system.io
open io
/-
One of the good things about Lean is that you can see it as three different languages.
While all the languages are actually the same, this purely artificial distinction is
quite helpful for learners.
The next function is a typical function-programming style hello world using monads.
If one were to write a similar hello world in ML or Haskell, the solution would be
quite similar.
Run this function from within the main repo folder:
lean --run src/02_three_languages.lean 1
-/
def main : io unit := do
args <- cmdline_args,
io.print_ln ("hello" ++ (option.get_or_else (list.nth args 0) "a")),
io.print_ln "world"
/-
plus_one is a pure function that adds one to its input.
Both main and plus_one belong to the first language: the language where you define programs
that execute.
-/
def plus_one : nat -> nat
| n := 1 + n
/- Lean provides some helpers to eval and typecheck these expressions: -/
#check 1
#reduce 1 + 1
#check tt
/- tt is the computable version of bool -/
/-
The second language is that of proofs. Everything that starts with theorem,
lemma, example and axiom belongs to this language. You write proofs using tactics.
Due to propositions as types, this is actually the same language as the first (you could
achieve the same using def), but I believe this view of Lean is useful for practicioners.
-/
axiom easy_mode : 0 = 1
example : 1 + 1 = 1 + 0 :=
begin
rw easy_mode,
end
#check true
/- true is the version of Prop that represents truth in the second language -/
/-
The third language is that in which you define new tactics. This language operates on
the meta-structure of programs, like a hygienic macro. This third language is the most
different from the first two, and it is not the focus of this tutorial.
Everything that has meta belongs to this language.
-/
open tactic
meta def my_repeat (t : tactic unit) : tactic unit :=
do
repeat t
|
727c9af4984a4cd9264da522d0737ae5ee7e8472
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/1813.lean
|
c1e82c60469b80c2166f2ab42c8242cfa8942b09
|
[
"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
| 160
|
lean
|
example [Add α] [Neg α] [Mul α] [∀ n, OfNat α n] {a b : α} :=
calc
4 + 5 * b = -6 + 5 * (b + 2) := sorry
_ = -6 + 5 * 3 := sorry
|
3df3d99ae9614436dfdea264f752986acd5904c9
|
302c785c90d40ad3d6be43d33bc6a558354cc2cf
|
/src/data/fintype/card.lean
|
015cc06d268abaa0f9b114ba4d6389a4a25d70f2
|
[
"Apache-2.0"
] |
permissive
|
ilitzroth/mathlib
|
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
|
5254ef14e3465f6504306132fe3ba9cec9ffff16
|
refs/heads/master
| 1,680,086,661,182
| 1,617,715,647,000
| 1,617,715,647,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 17,263
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.fintype.basic
import algebra.big_operators.ring
/-!
Results about "big operations" over a `fintype`, and consequent
results about cardinalities of certain types.
## Implementation note
This content had previously been in `data.fintype.basic`, but was moved here to avoid
requiring `algebra.big_operators` (and hence many other imports) as a
dependency of `fintype`.
However many of the results here really belong in `algebra.big_operators.basic`
and should be moved at some point.
-/
universes u v
variables {α : Type*} {β : Type*} {γ : Type*}
open_locale big_operators
namespace fintype
@[to_additive]
lemma prod_bool [comm_monoid α] (f : bool → α) : ∏ b, f b = f tt * f ff := by simp
lemma card_eq_sum_ones {α} [fintype α] : fintype.card α = ∑ a : α, 1 :=
finset.card_eq_sum_ones _
section
open finset
variables {ι : Type*} [decidable_eq ι] [fintype ι]
@[to_additive]
lemma prod_extend_by_one [comm_monoid α] (s : finset ι) (f : ι → α) :
∏ i, (if i ∈ s then f i else 1) = ∏ i in s, f i :=
by rw [← prod_filter, filter_mem_eq_inter, univ_inter]
end
section
variables {M : Type*} [fintype α] [comm_monoid M]
@[to_additive]
lemma prod_eq_one (f : α → M) (h : ∀ a, f a = 1) :
(∏ a, f a) = 1 :=
finset.prod_eq_one $ λ a ha, h a
@[to_additive]
lemma prod_congr (f g : α → M) (h : ∀ a, f a = g a) :
(∏ a, f a) = ∏ a, g a :=
finset.prod_congr rfl $ λ a ha, h a
@[to_additive]
lemma prod_eq_single {f : α → M} (a : α) (h : ∀ x ≠ a, f x = 1) :
(∏ x, f x) = f a :=
finset.prod_eq_single a (λ x _ hx, h x hx) $ λ ha, (ha (finset.mem_univ a)).elim
@[to_additive]
lemma prod_eq_mul {f : α → M} (a b : α) (h₁ : a ≠ b) (h₂ : ∀ x, x ≠ a ∧ x ≠ b → f x = 1) :
(∏ x, f x) = (f a) * (f b) :=
begin
apply finset.prod_eq_mul a b h₁ (λ x _ hx, h₂ x hx);
exact λ hc, (hc (finset.mem_univ _)).elim
end
@[to_additive]
lemma prod_unique [unique β] (f : β → M) :
(∏ x, f x) = f (default β) :=
by simp only [finset.prod_singleton, univ_unique]
/-- If a product of a `finset` of a subsingleton type has a given
value, so do the terms in that product. -/
@[to_additive "If a sum of a `finset` of a subsingleton type has a given
value, so do the terms in that sum."]
lemma eq_of_subsingleton_of_prod_eq {ι : Type*} [subsingleton ι] {s : finset ι}
{f : ι → M} {b : M} (h : ∏ i in s, f i = b) : ∀ i ∈ s, f i = b :=
finset.eq_of_card_le_one_of_prod_eq (finset.card_le_one_of_subsingleton s) h
end
end fintype
open finset
section
variables {M : Type*} [fintype α] [comm_monoid M]
@[simp, to_additive]
lemma fintype.prod_option (f : option α → M) : ∏ i, f i = f none * ∏ i, f (some i) :=
show ((finset.insert_none _).1.map f).prod = _,
by simp only [finset.prod, finset.insert_none, multiset.map_cons, multiset.prod_cons,
multiset.map_map]
end
@[to_additive]
theorem fin.prod_univ_def [comm_monoid β] {n : ℕ} (f : fin n → β) :
∏ i, f i = ((list.fin_range n).map f).prod :=
by simp [fin.univ_def, finset.fin_range]
@[to_additive]
theorem fin.prod_of_fn [comm_monoid β] {n : ℕ} (f : fin n → β) :
(list.of_fn f).prod = ∏ i, f i :=
by rw [list.of_fn_eq_map, fin.prod_univ_def]
/-- A product of a function `f : fin 0 → β` is `1` because `fin 0` is empty -/
@[simp, to_additive "A sum of a function `f : fin 0 → β` is `0` because `fin 0` is empty"]
theorem fin.prod_univ_zero [comm_monoid β] (f : fin 0 → β) : ∏ i, f i = 1 := rfl
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f x`, for some `x : fin (n + 1)` times the remaining product -/
theorem fin.prod_univ_succ_above [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) (x : fin (n + 1)) :
∏ i, f i = f x * ∏ i : fin n, f (x.succ_above i) :=
begin
rw [fin.univ_succ_above, finset.prod_insert, finset.prod_image],
{ intros x _ y _ hxy, exact fin.succ_above_right_inj.mp hxy },
{ simp [fin.succ_above_ne] }
end
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f x`, for some `x : fin (n + 1)` plus the remaining product -/
theorem fin.sum_univ_succ_above [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β)
(x : fin (n + 1)) :
∑ i, f i = f x + ∑ i : fin n, f (x.succ_above i) :=
by apply @fin.prod_univ_succ_above (multiplicative β)
attribute [to_additive] fin.prod_univ_succ_above
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f 0` plus the remaining product -/
theorem fin.prod_univ_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∏ i, f i = f 0 * ∏ i : fin n, f i.succ :=
fin.prod_univ_succ_above f 0
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f 0` plus the remaining product -/
theorem fin.sum_univ_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∑ i, f i = f 0 + ∑ i : fin n, f i.succ :=
fin.sum_univ_succ_above f 0
attribute [to_additive] fin.prod_univ_succ
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f (fin.last n)` plus the remaining product -/
theorem fin.prod_univ_cast_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∏ i, f i = (∏ i : fin n, f i.cast_succ) * f (fin.last n) :=
by simpa [mul_comm] using fin.prod_univ_succ_above f (fin.last n)
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f (fin.last n)` plus the remaining sum -/
theorem fin.sum_univ_cast_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∑ i, f i = ∑ i : fin n, f i.cast_succ + f (fin.last n) :=
by apply @fin.prod_univ_cast_succ (multiplicative β)
attribute [to_additive] fin.prod_univ_cast_succ
open finset
@[simp] theorem fintype.card_sigma {α : Type*} (β : α → Type*)
[fintype α] [∀ a, fintype (β a)] :
fintype.card (sigma β) = ∑ a, fintype.card (β a) :=
card_sigma _ _
-- FIXME ouch, this should be in the main file.
@[simp] theorem fintype.card_sum (α β : Type*) [fintype α] [fintype β] :
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
by simp [sum.fintype, fintype.of_equiv_card]
@[simp] lemma finset.card_pi [decidable_eq α] {δ : α → Type*}
(s : finset α) (t : Π a, finset (δ a)) :
(s.pi t).card = ∏ a in s, card (t a) :=
multiset.card_pi _ _
@[simp] lemma fintype.card_pi_finset [decidable_eq α] [fintype α]
{δ : α → Type*} (t : Π a, finset (δ a)) :
(fintype.pi_finset t).card = ∏ a, card (t a) :=
by simp [fintype.pi_finset, card_map]
@[simp] lemma fintype.card_pi {β : α → Type*} [decidable_eq α] [fintype α]
[f : Π a, fintype (β a)] : fintype.card (Π a, β a) = ∏ a, fintype.card (β a) :=
fintype.card_pi_finset _
-- FIXME ouch, this should be in the main file.
@[simp] lemma fintype.card_fun [decidable_eq α] [fintype α] [fintype β] :
fintype.card (α → β) = fintype.card β ^ fintype.card α :=
by rw [fintype.card_pi, finset.prod_const]; refl
@[simp] lemma card_vector [fintype α] (n : ℕ) :
fintype.card (vector α n) = fintype.card α ^ n :=
by rw fintype.of_equiv_card; simp
@[simp, to_additive]
lemma finset.prod_attach_univ [fintype α] [comm_monoid β] (f : {a : α // a ∈ @univ α _} → β) :
∏ x in univ.attach, f x = ∏ x, f ⟨x, (mem_univ _)⟩ :=
prod_bij (λ x _, x.1) (λ _ _, mem_univ _) (λ _ _ , by simp) (by simp)
(λ b _, ⟨⟨b, mem_univ _⟩, by simp⟩)
/-- Taking a product over `univ.pi t` is the same as taking the product over `fintype.pi_finset t`.
`univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`, but differ
in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and
`fintype.pi_finset t` is a `finset (Π a, t a)`. -/
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
`fintype.pi_finset t`. `univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`,
but differ in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and
`fintype.pi_finset t` is a `finset (Π a, t a)`."]
lemma finset.prod_univ_pi [decidable_eq α] [fintype α] [comm_monoid β]
{δ : α → Type*} {t : Π (a : α), finset (δ a)}
(f : (Π (a : α), a ∈ (univ : finset α) → δ a) → β) :
∏ x in univ.pi t, f x = ∏ x in fintype.pi_finset t, f (λ a _, x a) :=
prod_bij (λ x _ a, x a (mem_univ _))
(by simp)
(by simp)
(by simp [function.funext_iff] {contextual := tt})
(λ x hx, ⟨λ a _, x a, by simp * at *⟩)
/-- The product over `univ` of a sum can be written as a sum over the product of sets,
`fintype.pi_finset`. `finset.prod_sum` is an alternative statement when the product is not
over `univ` -/
lemma finset.prod_univ_sum [decidable_eq α] [fintype α] [comm_semiring β] {δ : α → Type u_1}
[Π (a : α), decidable_eq (δ a)] {t : Π (a : α), finset (δ a)}
{f : Π (a : α), δ a → β} :
∏ a, ∑ b in t a, f a b = ∑ p in fintype.pi_finset t, ∏ x, f x (p x) :=
by simp only [finset.prod_attach_univ, prod_sum, finset.sum_univ_pi]
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a fintype of cardinality `n`
gives `(a + b)^n`. The "good" proof involves expanding along all coordinates using the fact that
`x^n` is multilinear, but multilinear maps are only available now over rings, so we give instead
a proof reducing to the usual binomial theorem to have a result over semirings. -/
lemma fintype.sum_pow_mul_eq_add_pow
(α : Type*) [fintype α] {R : Type*} [comm_semiring R] (a b : R) :
∑ s : finset α, a ^ s.card * b ^ (fintype.card α - s.card) =
(a + b) ^ (fintype.card α) :=
finset.sum_pow_mul_eq_add_pow _ _ _
lemma fin.sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b : R) :
∑ s : finset (fin n), a ^ s.card * b ^ (n - s.card) =
(a + b) ^ n :=
by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b
@[to_additive]
lemma function.bijective.prod_comp [fintype α] [fintype β] [comm_monoid γ] {f : α → β}
(hf : function.bijective f) (g : β → γ) :
∏ i, g (f i) = ∏ i, g i :=
prod_bij (λ i hi, f i) (λ i hi, mem_univ _) (λ i hi, rfl) (λ i j _ _ h, hf.1 h) $
λ i hi, (hf.2 i).imp $ λ j hj, ⟨mem_univ _, hj.symm⟩
@[to_additive]
lemma equiv.prod_comp [fintype α] [fintype β] [comm_monoid γ] (e : α ≃ β) (f : β → γ) :
∏ i, f (e i) = ∏ i, f i :=
e.bijective.prod_comp f
/-- It is equivalent to sum a function over `fin n` or `finset.range n`. -/
@[to_additive]
lemma fin.prod_univ_eq_prod_range [comm_monoid α] (f : ℕ → α) (n : ℕ) :
∏ i : fin n, f i = ∏ i in range n, f i :=
calc (∏ i : fin n, f i) = ∏ i : {x // x ∈ range n}, f i :
((equiv.fin_equiv_subtype n).trans
(equiv.subtype_equiv_right (λ _, mem_range.symm))).prod_comp (f ∘ coe)
... = ∏ i in range n, f i : by rw [← attach_eq_univ, prod_attach]
@[to_additive]
lemma finset.prod_fin_eq_prod_range [comm_monoid β] {n : ℕ} (c : fin n → β) :
∏ i, c i = ∏ i in finset.range n, if h : i < n then c ⟨i, h⟩ else 1 :=
begin
rw [← fin.prod_univ_eq_prod_range, finset.prod_congr rfl],
rintros ⟨i, hi⟩ _,
simp only [fin.coe_eq_val, hi, dif_pos]
end
@[to_additive]
lemma finset.prod_subtype {M : Type*} [comm_monoid M]
{p : α → Prop} {F : fintype (subtype p)} (s : finset α) (h : ∀ x, x ∈ s ↔ p x) (f : α → M) :
∏ a in s, f a = ∏ a : subtype p, f a :=
have (∈ s) = p, from set.ext h,
begin
rw [← prod_attach, attach_eq_univ],
substI p,
congr
end
@[to_additive]
lemma finset.prod_to_finset_eq_subtype {M : Type*} [comm_monoid M] [fintype α]
(p : α → Prop) [decidable_pred p] (f : α → M) :
∏ a in {x | p x}.to_finset, f a = ∏ a : subtype p, f a :=
by { rw ← finset.prod_subtype, simp }
@[to_additive] lemma finset.prod_fiberwise [decidable_eq β] [fintype β] [comm_monoid γ]
(s : finset α) (f : α → β) (g : α → γ) :
∏ b : β, ∏ a in s.filter (λ a, f a = b), g a = ∏ a in s, g a :=
finset.prod_fiberwise_of_maps_to (λ x _, mem_univ _) _
@[to_additive]
lemma fintype.prod_fiberwise [fintype α] [decidable_eq β] [fintype β] [comm_monoid γ]
(f : α → β) (g : α → γ) :
(∏ b : β, ∏ a : {a // f a = b}, g (a : α)) = ∏ a, g a :=
begin
rw [← (equiv.sigma_preimage_equiv f).prod_comp, ← univ_sigma_univ, prod_sigma],
refl
end
lemma fintype.prod_dite [fintype α] {p : α → Prop} [decidable_pred p]
[comm_monoid β] (f : Π (a : α) (ha : p a), β) (g : Π (a : α) (ha : ¬p a), β) :
(∏ a, dite (p a) (f a) (g a)) = (∏ a : {a // p a}, f a a.2) * (∏ a : {a // ¬p a}, g a a.2) :=
begin
simp only [prod_dite, attach_eq_univ],
congr' 1,
{ convert (equiv.subtype_equiv_right _).prod_comp (λ x : {x // p x}, f x x.2),
simp },
{ convert (equiv.subtype_equiv_right _).prod_comp (λ x : {x // ¬p x}, g x x.2),
simp }
end
section
open finset
variables {α₁ : Type*} {α₂ : Type*} {M : Type*} [fintype α₁] [fintype α₂] [comm_monoid M]
@[to_additive]
lemma fintype.prod_sum_elim (f : α₁ → M) (g : α₂ → M) :
(∏ x, sum.elim f g x) = (∏ a₁, f a₁) * (∏ a₂, g a₂) :=
by { classical, rw [univ_sum_type, prod_sum_elim] }
@[to_additive]
lemma fintype.prod_sum_type (f : α₁ ⊕ α₂ → M) :
(∏ x, f x) = (∏ a₁, f (sum.inl a₁)) * (∏ a₂, f (sum.inr a₂)) :=
by simp only [← fintype.prod_sum_elim, sum.elim_comp_inl_inr]
end
namespace list
lemma prod_take_of_fn [comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
((of_fn f).take i).prod = ∏ j in finset.univ.filter (λ (j : fin n), j.val < i), f j :=
begin
have A : ∀ (j : fin n), ¬ ((j : ℕ) < 0) := λ j, not_lt_bot,
induction i with i IH, { simp [A] },
by_cases h : i < n,
{ have : i < length (of_fn f), by rwa [length_of_fn f],
rw prod_take_succ _ _ this,
have A : ((finset.univ : finset (fin n)).filter (λ j, j.val < i + 1))
= ((finset.univ : finset (fin n)).filter (λ j, j.val < i)) ∪ {(⟨i, h⟩ : fin n)},
by { ext j, simp [nat.lt_succ_iff_lt_or_eq, fin.ext_iff, - add_comm] },
have B : _root_.disjoint (finset.filter (λ (j : fin n), j.val < i) finset.univ)
(singleton (⟨i, h⟩ : fin n)), by simp,
rw [A, finset.prod_union B, IH],
simp },
{ have A : (of_fn f).take i = (of_fn f).take i.succ,
{ rw ← length_of_fn f at h,
have : length (of_fn f) ≤ i := not_lt.mp h,
rw [take_all_of_le this, take_all_of_le (le_trans this (nat.le_succ _))] },
have B : ∀ (j : fin n), ((j : ℕ) < i.succ) = ((j : ℕ) < i),
{ assume j,
have : (j : ℕ) < i := lt_of_lt_of_le j.2 (not_lt.mp h),
simp [this, lt_trans this (nat.lt_succ_self _)] },
simp [← A, B, IH] }
end
-- `to_additive` does not work on `prod_take_of_fn` because of `0 : ℕ` in the proof.
-- Use `multiplicative` instead.
lemma sum_take_of_fn [add_comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
((of_fn f).take i).sum = ∑ j in finset.univ.filter (λ (j : fin n), j.val < i), f j :=
@prod_take_of_fn (multiplicative α) _ n f i
attribute [to_additive] prod_take_of_fn
@[to_additive]
lemma prod_of_fn [comm_monoid α] {n : ℕ} {f : fin n → α} :
(of_fn f).prod = ∏ i, f i :=
begin
convert prod_take_of_fn f n,
{ rw [take_all_of_le (le_of_eq (length_of_fn f))] },
{ have : ∀ (j : fin n), (j : ℕ) < n := λ j, j.is_lt,
simp [this] }
end
lemma alternating_sum_eq_finset_sum {G : Type*} [add_comm_group G] :
∀ (L : list G), alternating_sum L = ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.is_lt
| [] := by { rw [alternating_sum, finset.sum_eq_zero], rintro ⟨i, ⟨⟩⟩ }
| (g :: []) :=
begin
show g = ∑ i : fin 1, (-1 : ℤ) ^ (i : ℕ) •ℤ [g].nth_le i i.2,
rw [fin.sum_univ_succ], simp,
end
| (g :: h :: L) :=
calc g + -h + L.alternating_sum
= g + -h + ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.2 :
congr_arg _ (alternating_sum_eq_finset_sum _)
... = ∑ i : fin (L.length + 2), (-1 : ℤ) ^ (i : ℕ) •ℤ list.nth_le (g :: h :: L) i _ :
begin
rw [fin.sum_univ_succ, fin.sum_univ_succ, add_assoc],
unfold_coes,
simp [nat.succ_eq_add_one, pow_add],
refl,
end
@[to_additive]
lemma alternating_prod_eq_finset_prod {G : Type*} [comm_group G] :
∀ (L : list G), alternating_prod L = ∏ i : fin L.length, (L.nth_le i i.2) ^ ((-1 : ℤ) ^ (i : ℕ))
| [] := by { rw [alternating_prod, finset.prod_eq_one], rintro ⟨i, ⟨⟩⟩ }
| (g :: []) :=
begin
show g = ∏ i : fin 1, [g].nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ),
rw [fin.prod_univ_succ], simp,
end
| (g :: h :: L) :=
calc g * h⁻¹ * L.alternating_prod
= g * h⁻¹ * ∏ i : fin L.length, L.nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ) :
congr_arg _ (alternating_prod_eq_finset_prod _)
... = ∏ i : fin (L.length + 2), list.nth_le (g :: h :: L) i _ ^ (-1 : ℤ) ^ (i : ℕ) :
begin
rw [fin.prod_univ_succ, fin.prod_univ_succ, mul_assoc],
unfold_coes,
simp [nat.succ_eq_add_one, pow_add],
refl,
end
end list
|
86e672156cde8af932c71bd23d0fbe5dcb72e588
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/set/intervals/pi.lean
|
44062039f587c9a9331e4e3a1ce34fd535d2ce8e
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,387
|
lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.set.intervals.basic
import Mathlib.data.set.lattice
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
namespace set
@[simp] theorem pi_univ_Ici {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) : (pi univ fun (i : ι) => Ici (x i)) = Ici x := sorry
@[simp] theorem pi_univ_Iic {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) : (pi univ fun (i : ι) => Iic (x i)) = Iic x := sorry
@[simp] theorem pi_univ_Icc {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) : (pi univ fun (i : ι) => Icc (x i) (y i)) = Icc x y := sorry
theorem pi_univ_Ioi_subset {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) [Nonempty ι] : (pi univ fun (i : ι) => Ioi (x i)) ⊆ Ioi x := sorry
theorem pi_univ_Iio_subset {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) [Nonempty ι] : (pi univ fun (i : ι) => Iio (x i)) ⊆ Iio x :=
pi_univ_Ioi_subset x
theorem pi_univ_Ioo_subset {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) [Nonempty ι] : (pi univ fun (i : ι) => Ioo (x i) (y i)) ⊆ Ioo x y :=
fun (x_1 : (i : ι) → α i) (hx : x_1 ∈ pi univ fun (i : ι) => Ioo (x i) (y i)) =>
{ left := pi_univ_Ioi_subset (fun (i : ι) => x i) fun (i : ι) (hi : i ∈ univ) => and.left (hx i hi),
right := pi_univ_Iio_subset (fun (i : ι) => y i) fun (i : ι) (hi : i ∈ univ) => and.right (hx i hi) }
theorem pi_univ_Ioc_subset {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) [Nonempty ι] : (pi univ fun (i : ι) => Ioc (x i) (y i)) ⊆ Ioc x y :=
fun (x_1 : (i : ι) → α i) (hx : x_1 ∈ pi univ fun (i : ι) => Ioc (x i) (y i)) =>
{ left := pi_univ_Ioi_subset (fun (i : ι) => x i) fun (i : ι) (hi : i ∈ univ) => and.left (hx i hi),
right := fun (i : ι) => and.right (hx i trivial) }
theorem pi_univ_Ico_subset {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) [Nonempty ι] : (pi univ fun (i : ι) => Ico (x i) (y i)) ⊆ Ico x y :=
fun (x_1 : (i : ι) → α i) (hx : x_1 ∈ pi univ fun (i : ι) => Ico (x i) (y i)) =>
{ left := fun (i : ι) => and.left (hx i trivial),
right := pi_univ_Iio_subset (fun (i : ι) => y i) fun (i : ι) (hi : i ∈ univ) => and.right (hx i hi) }
theorem pi_univ_Ioc_update_left {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] [DecidableEq ι] {x : (i : ι) → α i} {y : (i : ι) → α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) : (pi univ fun (i : ι) => Ioc (function.update x i₀ m i) (y i)) =
(set_of fun (z : (i : ι) → α i) => m < z i₀) ∩ pi univ fun (i : ι) => Ioc (x i) (y i) := sorry
theorem pi_univ_Ioc_update_right {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] [DecidableEq ι] {x : (i : ι) → α i} {y : (i : ι) → α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) : (pi univ fun (i : ι) => Ioc (x i) (function.update y i₀ m i)) =
(set_of fun (z : (i : ι) → α i) => z i₀ ≤ m) ∩ pi univ fun (i : ι) => Ioc (x i) (y i) := sorry
theorem disjoint_pi_univ_Ioc_update_left_right {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → preorder (α i)] [DecidableEq ι] {x : (i : ι) → α i} {y : (i : ι) → α i} {i₀ : ι} {m : α i₀} : disjoint (pi univ fun (i : ι) => Ioc (x i) (function.update y i₀ m i))
(pi univ fun (i : ι) => Ioc (function.update x i₀ m i) (y i)) := sorry
theorem pi_univ_Ioc_update_union {ι : Type u_1} {α : ι → Type u_2} [DecidableEq ι] [(i : ι) → linear_order (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) (i₀ : ι) (m : α i₀) (hm : m ∈ Icc (x i₀) (y i₀)) : ((pi univ fun (i : ι) => Ioc (x i) (function.update y i₀ m i)) ∪
pi univ fun (i : ι) => Ioc (function.update x i₀ m i) (y i)) =
pi univ fun (i : ι) => Ioc (x i) (y i) := sorry
/-- If `x`, `y`, `x'`, and `y'` are functions `Π i : ι, α i`, then
the set difference between the box `[x, y]` and the product of the open intervals `(x' i, y' i)`
is covered by the union of the following boxes: for each `i : ι`, we take
`[x, update y i (x' i)]` and `[update x i (y' i), y]`.
E.g., if `x' = x` and `y' = y`, then this lemma states that the difference between a closed box
`[x, y]` and the corresponding open box `{z | ∀ i, x i < z i < y i}` is covered by the union
of the faces of `[x, y]`. -/
theorem Icc_diff_pi_univ_Ioo_subset {ι : Type u_1} {α : ι → Type u_2} [DecidableEq ι] [(i : ι) → linear_order (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) (x' : (i : ι) → α i) (y' : (i : ι) → α i) : (Icc x y \ pi univ fun (i : ι) => Ioo (x' i) (y' i)) ⊆
(Union fun (i : ι) => Icc x (function.update y i (x' i))) ∪ Union fun (i : ι) => Icc (function.update x i (y' i)) y := sorry
/-- If `x`, `y`, `z` are functions `Π i : ι, α i`, then
the set difference between the box `[x, z]` and the product of the intervals `(y i, z i]`
is covered by the union of the boxes `[x, update z i (y i)]`.
E.g., if `x = y`, then this lemma states that the difference between a closed box
`[x, y]` and the product of half-open intervals `{z | ∀ i, x i < z i ≤ y i}` is covered by the union
of the faces of `[x, y]` adjacent to `x`. -/
theorem Icc_diff_pi_univ_Ioc_subset {ι : Type u_1} {α : ι → Type u_2} [DecidableEq ι] [(i : ι) → linear_order (α i)] (x : (i : ι) → α i) (y : (i : ι) → α i) (z : (i : ι) → α i) : (Icc x z \ pi univ fun (i : ι) => Ioc (y i) (z i)) ⊆ Union fun (i : ι) => Icc x (function.update z i (y i)) := sorry
|
915acd194a4804dbfca081498575554beed7a876
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/number_theory/lucas_primality.lean
|
8e565130d18e06a1ff21003ef2c192d4b1d4e2ac
|
[
"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
| 2,698
|
lean
|
/-
Copyright (c) 2020 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey
-/
import data.fintype.basic
import group_theory.order_of_element
import tactic.zify
import data.nat.totient
/-!
# The Lucas test for primes.
This file implements the Lucas test for primes (not to be confused with the Lucas-Lehmer test for
Mersenne primes). A number `a` witnesses that `n` is prime if `a` has order `n-1` in the
multiplicative group of integers mod `n`. This is checked by verifying that `a^(n-1) = 1 (mod n)`
and `a^d ≠ 1 (mod n)` for any divisor `d | n - 1`. This test is the basis of the Pratt primality
certificate.
## TODO
- Bonus: Show the reverse implication i.e. if a number is prime then it has a Lucas witness.
Use `units.is_cyclic` from `ring_theory/integral_domain` to show the group is cyclic.
- Write a tactic that uses this theorem to generate Pratt primality certificates
- Integrate Pratt primality certificates into the norm_num primality verifier
## Implementation notes
Note that the proof for `lucas_primality` relies on analyzing the multiplicative group
modulo `p`. Despite this, the theorem still holds vacuously for `p = 0` and `p = 1`: In these
cases, we can take `q` to be any prime and see that `hd` does not hold, since `a^((p-1)/q)` reduces
to `1`.
-/
/--
If `a^(p-1) = 1 mod p`, but `a^((p-1)/q) ≠ 1 mod p` for all prime factors `q` of `p-1`, then `p`
is prime. This is true because `a` has order `p-1` in the multiplicative group mod `p`, so this
group must itself have order `p-1`, which only happens when `p` is prime.
-/
theorem lucas_primality (p : ℕ) (a : zmod p) (ha : a^(p-1) = 1)
(hd : ∀ q : ℕ, q.prime → q ∣ (p-1) → a^((p-1)/q) ≠ 1) : p.prime :=
begin
have h0 : p ≠ 0, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },
have h1 : p ≠ 1, { rintro ⟨⟩, exact hd 2 nat.prime_two (dvd_zero _) (pow_zero _) },
have hp1 : 1 < p := lt_of_le_of_ne h0.bot_lt h1.symm,
have order_of_a : order_of a = p-1,
{ apply order_of_eq_of_pow_and_pow_div_prime _ ha hd,
exact tsub_pos_of_lt hp1, },
haveI : ne_zero p := ⟨h0⟩,
rw nat.prime_iff_card_units,
-- Prove cardinality of `units` of `zmod p` is both `≤ p-1` and `≥ p-1`
refine le_antisymm (nat.card_units_zmod_lt_sub_one hp1) _,
have hp' : p - 2 + 1 = p - 1 := tsub_add_eq_add_tsub hp1,
let a' : (zmod p)ˣ := units.mk_of_mul_eq_one a (a ^ (p-2)) (by rw [←pow_succ, hp', ha]),
calc p - 1 = order_of a : order_of_a.symm
... = order_of a' : order_of_injective (units.coe_hom (zmod p)) units.ext a'
... ≤ fintype.card (zmod p)ˣ : order_of_le_card_univ,
end
|
c163c054703dbf06b0cbcbafebcf04c4c4aa0605
|
e0b0b1648286e442507eb62344760d5cd8d13f2d
|
/tests/lean/interactive/goalIssue.lean
|
b46c5591633170f47c8341490455279ca30eb81b
|
[
"Apache-2.0"
] |
permissive
|
MULXCODE/lean4
|
743ed389e05e26e09c6a11d24607ad5a697db39b
|
4675817a9e89824eca37192364cd47a4027c6437
|
refs/heads/master
| 1,682,231,879,857
| 1,620,423,501,000
| 1,620,423,501,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 261
|
lean
|
theorem foo1 (x : Nat) : 0 + x = x := by
first
| skip; have x + x = x + x from rfl; done
--^ $/lean/plainGoal
| simp
theorem foo2 (x : Nat) : 0 + x = x := by
induction x with
| zero => done
--^ $/lean/plainGoal
| succ => done
|
c34cac387425dd995eab357525398fc088856690
|
1dd482be3f611941db7801003235dc84147ec60a
|
/src/data/set/function.lean
|
6ae7247495b1b1d304c4c8f55e01e254dc7277dd
|
[
"Apache-2.0"
] |
permissive
|
sanderdahmen/mathlib
|
479039302bd66434bb5672c2a4cecf8d69981458
|
8f0eae75cd2d8b7a083cf935666fcce4565df076
|
refs/heads/master
| 1,587,491,322,775
| 1,549,672,060,000
| 1,549,672,060,000
| 169,748,224
| 0
| 0
|
Apache-2.0
| 1,549,636,694,000
| 1,549,636,694,000
| null |
UTF-8
|
Lean
| false
| false
| 10,790
|
lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu
Functions over sets.
-/
import data.set.basic logic.function
open function
namespace set
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
/- maps to -/
/-- `maps_to f a b` means that the image of `a` is contained in `b`. -/
@[reducible] def maps_to (f : α → β) (a : set α) (b : set β) : Prop := a ⊆ f ⁻¹' b
theorem maps_to' (f : α → β) (a : set α) (b : set β) : maps_to f a b ↔ f '' a ⊆ b :=
image_subset_iff.symm
theorem maps_to_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : maps_to f1 a b) :
maps_to f2 a b :=
λ x h, by rw [mem_preimage_eq, ← h₁ _ h]; exact h₂ h
theorem maps_to_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : maps_to g b c) (h₂ : maps_to f a b) : maps_to (g ∘ f) a c :=
λ x h, h₁ (h₂ h)
theorem maps_to_univ (f : α → β) (a) : maps_to f a univ :=
λ x h, trivial
theorem maps_to_image (f : α → β) (a : set α) : maps_to f a (f '' a) :=
by rw maps_to'
theorem maps_to_range (f : α → β) (a : set α) : maps_to f a (range f) :=
by rw [← image_univ, maps_to']; exact image_subset _ (subset_univ _)
theorem image_subset_of_maps_to_of_subset {f : α → β} {a c : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : c ⊆ a) :
f '' c ⊆ b :=
λ y hy, let ⟨x, hx, heq⟩ := hy in
by rw [←heq]; apply h₁; apply h₂; assumption
theorem image_subset_of_maps_to {f : α → β} {a : set α} {b : set β} (h : maps_to f a b) :
f '' a ⊆ b :=
image_subset_of_maps_to_of_subset h (subset.refl _)
/- injectivity -/
/-- `f` is injective on `a` if the restriction of `f` to `a` is injective. -/
@[reducible] def inj_on (f : α → β) (a : set α) : Prop :=
∀⦃x1 x2 : α⦄, x1 ∈ a → x2 ∈ a → f x1 = f x2 → x1 = x2
theorem inj_on_empty (f : α → β) : inj_on f ∅ :=
λ _ _ h₁ _ _, false.elim h₁
theorem inj_on_of_eq_on {f1 f2 : α → β} {a : set α} (h₁ : eq_on f1 f2 a)
(h₂ : inj_on f1 a) :
inj_on f2 a :=
λ _ _ h₁' h₂' heq, by apply h₂ h₁' h₂'; rw [h₁, heq, ←h₁]; repeat {assumption}
theorem inj_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : inj_on g b) (h₃: inj_on f a) :
inj_on (g ∘ f) a :=
λ _ _ h₁' h₂' heq,
by apply h₃ h₁' h₂'; apply h₂; repeat {apply h₁, assumption}; assumption
theorem inj_on_of_inj_on_of_subset {f : α → β} {a b : set α} (h₁ : inj_on f b) (h₂ : a ⊆ b) :
inj_on f a :=
λ _ _ h₁' h₂' heq, h₁ (h₂ h₁') (h₂ h₂') heq
lemma injective_iff_inj_on_univ {f : α → β} : injective f ↔ inj_on f univ :=
iff.intro (λ h _ _ _ _ heq, h heq) (λ h _ _ heq, h trivial trivial heq)
lemma inj_on_iff_injective {f : α → β} {s : set α} : inj_on f s ↔ injective (λ x:s, f x.1) :=
⟨λ H a b h, subtype.eq $ H a.2 b.2 h,
λ H a b as bs h, congr_arg subtype.val $ @H ⟨a, as⟩ ⟨b, bs⟩ h⟩
lemma inv_fun_on_image [inhabited α] {β : Type v} {s t : set α} {f : α → β}
(h : inj_on f s) (ht : t ⊆ s) : (inv_fun_on f s) '' (f '' t) = t :=
begin
have A : ∀z, z ∈ t → ((inv_fun_on f s) ∘ f) z = z := λz hz, inv_fun_on_eq' h (ht hz),
rw ← image_comp,
ext,
simp [A] {contextual := tt}
end
/- surjectivity -/
/-- `f` is surjective from `a` to `b` if `b` is contained in the image of `a`. -/
@[reducible] def surj_on (f : α → β) (a : set α) (b : set β) : Prop := b ⊆ f '' a
theorem surj_on_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : surj_on f1 a b) :
surj_on f2 a b :=
λ _ h, let ⟨x, hx⟩ := h₂ h in
⟨x, hx.left, by rw [←h₁ _ hx.left]; exact hx.right⟩
theorem surj_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : surj_on g b c) (h₂ : surj_on f a b) :
surj_on (g ∘ f) a c :=
λ z h, let ⟨y, hy⟩ := h₁ h, ⟨x, hx⟩ := h₂ hy.left in
⟨x, hx.left, calc g (f x) = g y : by rw [hx.right]
... = z : hy.right⟩
lemma surjective_iff_surj_on_univ {f : α → β} : surjective f ↔ surj_on f univ univ :=
by simp [surjective, surj_on, subset_def]
lemma surj_on_iff_surjective {f : α → β} {s : set α} : surj_on f s univ ↔ surjective (λ x:s, f x.1) :=
⟨λ H b, let ⟨a, as, e⟩ := @H b trivial in ⟨⟨a, as⟩, e⟩,
λ H b _, let ⟨⟨a, as⟩, e⟩ := H b in ⟨a, as, e⟩⟩
lemma image_eq_of_maps_to_of_surj_on {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : surj_on f a b) :
f '' a = b :=
eq_of_subset_of_subset (image_subset_of_maps_to h₁) h₂
/- bijectivity -/
/-- `f` is bijective from `a` to `b` if `f` is injective on `a` and `f '' a = b`. -/
@[reducible] def bij_on (f : α → β) (a : set α) (b : set β) : Prop :=
maps_to f a b ∧ inj_on f a ∧ surj_on f a b
lemma maps_to_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
maps_to f a b :=
h.left
lemma inj_on_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
inj_on f a :=
h.right.left
lemma surj_on_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
surj_on f a b :=
h.right.right
lemma bij_on.mk {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : inj_on f a) (h₃ : surj_on f a b) :
bij_on f a b :=
⟨h₁, h₂, h₃⟩
theorem bij_on_of_eq_on {f1 f2 : α → β} {a : set α} {b : set β} (h₁ : eq_on f1 f2 a)
(h₂ : bij_on f1 a b) : bij_on f2 a b :=
let ⟨map, inj, surj⟩ := h₂ in
⟨maps_to_of_eq_on h₁ map, inj_on_of_eq_on h₁ inj, surj_on_of_eq_on h₁ surj⟩
lemma image_eq_of_bij_on {f : α → β} {a : set α} {b : set β} (h : bij_on f a b) :
f '' a = b :=
image_eq_of_maps_to_of_surj_on h.left h.right.right
theorem bij_on_comp {g : β → γ} {f : α → β} {a : set α} {b : set β} {c : set γ}
(h₁ : bij_on g b c) (h₂: bij_on f a b) :
bij_on (g ∘ f) a c :=
let ⟨gmap, ginj, gsurj⟩ := h₁, ⟨fmap, finj, fsurj⟩ := h₂ in
⟨maps_to_comp gmap fmap, inj_on_comp fmap ginj finj, surj_on_comp gsurj fsurj⟩
lemma bijective_iff_bij_on_univ {f : α → β} : bijective f ↔ bij_on f univ univ :=
iff.intro
(λ h, let ⟨inj, surj⟩ := h in
⟨maps_to_univ f _, iff.mp injective_iff_inj_on_univ inj, iff.mp surjective_iff_surj_on_univ surj⟩)
(λ h, let ⟨map, inj, surj⟩ := h in
⟨iff.mpr injective_iff_inj_on_univ inj, iff.mpr surjective_iff_surj_on_univ surj⟩)
/- left inverse -/
/-- `g` is a left inverse to `f` on `a` means that `g (f x) = x` for all `x ∈ a`. -/
@[reducible] def left_inv_on (g : β → α) (f : α → β) (a : set α) : Prop :=
∀ x ∈ a, g (f x) = x
theorem left_inv_on_of_eq_on_left {g1 g2 : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : eq_on g1 g2 b) (h₃ : left_inv_on g1 f a) : left_inv_on g2 f a :=
λ x h,
calc
g2 (f x) = g1 (f x) : eq.symm $ h₂ _ (h₁ h)
... = x : h₃ _ h
theorem left_inv_on_of_eq_on_right {g : β → α} {f1 f2 : α → β} {a : set α}
(h₁ : eq_on f1 f2 a) (h₂ : left_inv_on g f1 a) : left_inv_on g f2 a :=
λ x h,
calc
g (f2 x) = g (f1 x) : congr_arg g (h₁ _ h).symm
... = x : h₂ _ h
theorem inj_on_of_left_inv_on {g : β → α} {f : α → β} {a : set α} (h : left_inv_on g f a) :
inj_on f a :=
λ x₁ x₂ h₁ h₂ heq,
calc
x₁ = g (f x₁) : eq.symm $ h _ h₁
... = g (f x₂) : congr_arg g heq
... = x₂ : h _ h₂
theorem left_inv_on_comp {f' : β → α} {g' : γ → β} {g : β → γ} {f : α → β}
{a : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : left_inv_on f' f a) (h₃ : left_inv_on g' g b) : left_inv_on (f' ∘ g') (g ∘ f) a :=
λ x h,
calc
(f' ∘ g') ((g ∘ f) x) = f' (f x) : congr_arg f' (h₃ _ (h₁ h))
... = x : h₂ _ h
/- right inverse -/
/-- `g` is a right inverse to `f` on `b` if `f (g x) = x` for all `x ∈ b`. -/
@[reducible] def right_inv_on (g : β → α) (f : α → β) (b : set β) : Prop :=
left_inv_on f g b
theorem right_inv_on_of_eq_on_left {g1 g2 : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : eq_on g1 g2 b) (h₂ : right_inv_on g1 f b) : right_inv_on g2 f b :=
left_inv_on_of_eq_on_right h₁ h₂
theorem right_inv_on_of_eq_on_right {g : β → α} {f1 f2 : α → β} {a : set α} {b : set β}
(h₁ : maps_to g b a) (h₂ : eq_on f1 f2 a) (h₃ : right_inv_on g f1 b) : right_inv_on g f2 b :=
left_inv_on_of_eq_on_left h₁ h₂ h₃
theorem surj_on_of_right_inv_on {g : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to g b a) (h₂ : right_inv_on g f b) :
surj_on f a b :=
λ y h, ⟨g y, h₁ h, h₂ _ h⟩
theorem right_inv_on_comp {f' : β → α} {g' : γ → β} {g : β → γ} {f : α → β}
{c : set γ} {b : set β} (g'cb : maps_to g' c b)
(h₁ : right_inv_on f' f b) (h₂ : right_inv_on g' g c) : right_inv_on (f' ∘ g') (g ∘ f) c :=
left_inv_on_comp g'cb h₂ h₁
theorem right_inv_on_of_inj_on_of_left_inv_on {f : α → β} {g : β → α} {a : set α} {b : set β}
(h₁ : maps_to f a b) (h₂ : maps_to g b a) (h₃ : inj_on f a) (h₄ : left_inv_on f g b) :
right_inv_on f g a :=
λ x h, h₃ (h₂ $ h₁ h) h (h₄ _ (h₁ h))
theorem eq_on_of_left_inv_of_right_inv {g₁ g₂ : β → α} {f : α → β} {a : set α} {b : set β}
(h₁ : maps_to g₂ b a) (h₂ : left_inv_on g₁ f a) (h₃ : right_inv_on g₂ f b) : eq_on g₁ g₂ b :=
λ y h,
calc
g₁ y = (g₁ ∘ f ∘ g₂) y : congr_arg g₁ (h₃ _ h).symm
... = g₂ y : h₂ _ (h₁ h)
theorem left_inv_on_of_surj_on_right_inv_on {f : α → β} {g : β → α} {a : set α} {b : set β}
(h₁ : surj_on f a b) (h₂ : right_inv_on f g a) :
left_inv_on f g b :=
λ y h, let ⟨x, hx, heq⟩ := h₁ h in
calc
(f ∘ g) y = (f ∘ g ∘ f) x : congr_arg (f ∘ g) heq.symm
... = f x : congr_arg f (h₂ _ hx)
... = y : heq
/- inverses -/
/-- `g` is an inverse to `f` viewed as a map from `a` to `b` -/
@[reducible] def inv_on (g : β → α) (f : α → β) (a : set α) (b : set β) : Prop :=
left_inv_on g f a ∧ right_inv_on g f b
theorem bij_on_of_inv_on {g : β → α} {f : α → β} {a : set α} {b : set β} (h₁ : maps_to f a b)
(h₂ : maps_to g b a) (h₃ : inv_on g f a b) : bij_on f a b :=
⟨h₁, inj_on_of_left_inv_on h₃.left, surj_on_of_right_inv_on h₂ h₃.right⟩
end set
|
abf2063de1e1ac7a9131994ba52715b5a60c7f8b
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/08_Building_Theories_and_Proofs.org.11.lean
|
bd79dd9252c794f87fd428760d76bcacf9331407
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 312
|
lean
|
import standard
import data.nat.order
open nat
-- BEGIN
check @add_lt_add_right
definition foo (n m k : ℕ) (H : n < m) : n + k < m + k := !(add_lt_add_right H)
example {n m k l : ℕ} (H : n < m) (K : m + l < k + l) : n < k + l :=
calc
n ≤ n + l : !le_add_right
... < m + l : !foo H
... < k + l : K
-- END
|
f1cb725661641505af7779f24349eeac13c8de1e
|
2a70b774d16dbdf5a533432ee0ebab6838df0948
|
/_target/deps/mathlib/src/category_theory/adjunction/mates.lean
|
f660fab2d236f10d295e2c2fc34420fa1568ff64
|
[
"Apache-2.0"
] |
permissive
|
hjvromen/lewis
|
40b035973df7c77ebf927afab7878c76d05ff758
|
105b675f73630f028ad5d890897a51b3c1146fb0
|
refs/heads/master
| 1,677,944,636,343
| 1,676,555,301,000
| 1,676,555,301,000
| 327,553,599
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 10,531
|
lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Bhavik Mehta
-/
import category_theory.adjunction.basic
import category_theory.conj
import category_theory.yoneda
/-!
# Mate of natural transformations
This file establishes the bijection between the 2-cells
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
where `L₁ ⊣ R₁` and `L₂ ⊣ R₂`, and shows that in the special case where `G,H` are identity then the
bijection preserves and reflects isomorphisms (i.e. we have bijections `(L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂)`, and
if either side is an iso then the other side is as well).
On its own, this bijection is not particularly useful but it includes a number of interesting cases
as specializations.
For instance, this generalises the fact that adjunctions are unique (since if `L₁ ≅ L₂` then we
deduce `R₁ ≅ R₂`).
Another example arises from considering the square representing that a functor `H` preserves
products, in particular the morphism `HA ⨯ H- ⟶ H(A ⨯ -)`. Then provided `(A ⨯ -)` and `HA ⨯ -` have
left adjoints (for instance if the relevant categories are cartesian closed), the transferred
natural transformation is the exponential comparison morphism: `H(A ^ -) ⟶ HA ^ H-`.
Furthermore if `H` has a left adjoint `L`, this morphism is an isomorphism iff its mate
`L(HA ⨯ -) ⟶ A ⨯ L-` is an isomorphism, see
https://ncatlab.org/nlab/show/Frobenius+reciprocity#InCategoryTheory.
This also relates to Grothendieck's yoga of six operations, though this is not spelled out in
mathlib: https://ncatlab.org/nlab/show/six+operations.
-/
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace category_theory
open category
variables {C : Type u₁} {D : Type u₂} [category.{v₁} C] [category.{v₂} D]
section square
variables {E : Type u₃} {F : Type u₄} [category.{v₃} E] [category.{v₄} F]
variables {G : C ⥤ E} {H : D ⥤ F} {L₁ : C ⥤ D} {R₁ : D ⥤ C} {L₂ : E ⥤ F} {R₂ : F ⥤ E}
variables (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂)
include adj₁ adj₂
/--
Suppose we have a square of functors (where the top and bottom are adjunctions `L₁ ⊣ R₁` and
`L₂ ⊣ R₂` respectively).
C ↔ D
G ↓ ↓ H
E ↔ F
Then we have a bijection between natural transformations `G ⋙ L₂ ⟶ L₁ ⋙ H` and
`R₁ ⋙ G ⟶ H ⋙ R₂`.
This can be seen as a bijection of the 2-cells:
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
Note that if one of the transformations is an iso, it does not imply the other is an iso.
-/
def transfer_nat_trans : (G ⋙ L₂ ⟶ L₁ ⋙ H) ≃ (R₁ ⋙ G ⟶ H ⋙ R₂) :=
{ to_fun := λ h,
{ app := λ X, adj₂.unit.app _ ≫ R₂.map (h.app _ ≫ H.map (adj₁.counit.app _)),
naturality' := λ X Y f,
begin
dsimp,
rw [assoc, ← R₂.map_comp, assoc, ← H.map_comp, ← adj₁.counit_naturality, H.map_comp,
←functor.comp_map L₁, ←h.naturality_assoc],
simp,
end },
inv_fun := λ h,
{ app := λ X, L₂.map (G.map (adj₁.unit.app _) ≫ h.app _) ≫ adj₂.counit.app _,
naturality' := λ X Y f,
begin
dsimp,
rw [← L₂.map_comp_assoc, ← G.map_comp_assoc, ← adj₁.unit_naturality, G.map_comp_assoc,
← functor.comp_map, h.naturality],
simp,
end },
left_inv := λ h,
begin
ext X,
dsimp,
simp only [L₂.map_comp, assoc, adj₂.counit_naturality, adj₂.left_triangle_components_assoc,
←functor.comp_map G L₂, h.naturality_assoc, functor.comp_map L₁, ←H.map_comp,
adj₁.left_triangle_components],
dsimp,
simp, -- See library note [dsimp, simp].
end,
right_inv := λ h,
begin
ext X,
dsimp,
simp [-functor.comp_map, ←functor.comp_map H, functor.comp_map R₁, -nat_trans.naturality,
←h.naturality, -functor.map_comp, ←functor.map_comp_assoc G, R₂.map_comp],
end }
lemma transfer_nat_trans_counit (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (Y : D) :
L₂.map ((transfer_nat_trans adj₁ adj₂ f).app _) ≫ adj₂.counit.app _ =
f.app _ ≫ H.map (adj₁.counit.app Y) :=
by simp [transfer_nat_trans]
lemma unit_transfer_nat_trans (f : G ⋙ L₂ ⟶ L₁ ⋙ H) (X : C) :
G.map (adj₁.unit.app X) ≫ (transfer_nat_trans adj₁ adj₂ f).app _ =
adj₂.unit.app _ ≫ R₂.map (f.app _) :=
begin
dsimp [transfer_nat_trans],
rw [←adj₂.unit_naturality_assoc, ←R₂.map_comp, ← functor.comp_map G L₂, f.naturality_assoc,
functor.comp_map, ← H.map_comp],
dsimp, simp, -- See library note [dsimp, simp]
end
end square
section self
variables {L₁ L₂ L₃ : C ⥤ D} {R₁ R₂ R₃ : D ⥤ C}
variables (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) (adj₃ : L₃ ⊣ R₃)
/--
Given two adjunctions `L₁ ⊣ R₁` and `L₂ ⊣ R₂` both between categories `C`, `D`, there is a
bijection between natural transformations `L₂ ⟶ L₁` and natural transformations `R₁ ⟶ R₂`.
This is defined as a special case of `transfer_nat_trans`, where the two "vertical" functors are
identity.
TODO: Generalise to when the two vertical functors are equivalences rather than being exactly `𝟭`.
Furthermore, this bijection preserves (and reflects) isomorphisms, i.e. a transformation is an iso
iff its image under the bijection is an iso, see eg `category_theory.transfer_nat_trans_self_iso`.
This is in contrast to the general case `transfer_nat_trans` which does not in general have this
property.
-/
def transfer_nat_trans_self : (L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂) :=
calc (L₂ ⟶ L₁) ≃ _ : (iso.hom_congr L₂.left_unitor L₁.right_unitor).symm
... ≃ _ : transfer_nat_trans adj₁ adj₂
... ≃ (R₁ ⟶ R₂) : R₁.right_unitor.hom_congr R₂.left_unitor
lemma transfer_nat_trans_self_counit (f : L₂ ⟶ L₁) (X) :
L₂.map ((transfer_nat_trans_self adj₁ adj₂ f).app _) ≫ adj₂.counit.app X =
f.app _ ≫ adj₁.counit.app X :=
begin
dsimp [transfer_nat_trans_self],
rw [id_comp, comp_id],
have := transfer_nat_trans_counit adj₁ adj₂ (L₂.left_unitor.hom ≫ f ≫ L₁.right_unitor.inv) X,
dsimp at this,
rw this,
simp,
end
lemma unit_transfer_nat_trans_self (f : L₂ ⟶ L₁) (X) :
adj₁.unit.app _ ≫ (transfer_nat_trans_self adj₁ adj₂ f).app _ =
adj₂.unit.app X ≫ functor.map _ (f.app _) :=
begin
dsimp [transfer_nat_trans_self],
rw [id_comp, comp_id],
have := unit_transfer_nat_trans adj₁ adj₂ (L₂.left_unitor.hom ≫ f ≫ L₁.right_unitor.inv) X,
dsimp at this,
rw this,
simp
end
@[simp]
lemma transfer_nat_trans_self_id : transfer_nat_trans_self adj₁ adj₁ (𝟙 _) = 𝟙 _ :=
by { ext, dsimp [transfer_nat_trans_self, transfer_nat_trans], simp }
-- See library note [dsimp, simp]
@[simp]
lemma transfer_nat_trans_self_symm_id :
(transfer_nat_trans_self adj₁ adj₁).symm (𝟙 _) = 𝟙 _ :=
by { rw equiv.symm_apply_eq, simp }
lemma transfer_nat_trans_self_comp (f g) :
transfer_nat_trans_self adj₁ adj₂ f ≫ transfer_nat_trans_self adj₂ adj₃ g =
transfer_nat_trans_self adj₁ adj₃ (g ≫ f) :=
begin
ext,
dsimp [transfer_nat_trans_self, transfer_nat_trans],
simp only [id_comp, comp_id],
rw [←adj₃.unit_naturality_assoc, ←R₃.map_comp, g.naturality_assoc, L₂.map_comp, assoc,
adj₂.counit_naturality, adj₂.left_triangle_components_assoc, assoc],
end
lemma transfer_nat_trans_self_symm_comp (f g) :
(transfer_nat_trans_self adj₂ adj₁).symm f ≫ (transfer_nat_trans_self adj₃ adj₂).symm g =
(transfer_nat_trans_self adj₃ adj₁).symm (g ≫ f) :=
by { rw [equiv.eq_symm_apply, ← transfer_nat_trans_self_comp _ adj₂], simp }
lemma transfer_nat_trans_self_comm {f g} (gf : g ≫ f = 𝟙 _) :
transfer_nat_trans_self adj₁ adj₂ f ≫ transfer_nat_trans_self adj₂ adj₁ g = 𝟙 _ :=
by rw [transfer_nat_trans_self_comp, gf, transfer_nat_trans_self_id]
lemma transfer_nat_trans_self_symm_comm {f g} (gf : g ≫ f = 𝟙 _) :
(transfer_nat_trans_self adj₁ adj₂).symm f ≫ (transfer_nat_trans_self adj₂ adj₁).symm g = 𝟙 _ :=
by rw [transfer_nat_trans_self_symm_comp, gf, transfer_nat_trans_self_symm_id]
/--
If `f` is an isomorphism, then the transferred natural transformation is an isomorphism.
The converse is given in `transfer_nat_trans_self_of_iso`.
-/
instance transfer_nat_trans_self_iso (f : L₂ ⟶ L₁) [is_iso f] :
is_iso (transfer_nat_trans_self adj₁ adj₂ f) :=
{ inv := transfer_nat_trans_self adj₂ adj₁ (inv f),
hom_inv_id' := transfer_nat_trans_self_comm _ _ (by simp),
inv_hom_id' := transfer_nat_trans_self_comm _ _ (by simp) }
/--
If `f` is an isomorphism, then the un-transferred natural transformation is an isomorphism.
The converse is given in `transfer_nat_trans_self_symm_of_iso`.
-/
instance transfer_nat_trans_self_symm_iso (f : R₁ ⟶ R₂) [is_iso f] :
is_iso ((transfer_nat_trans_self adj₁ adj₂).symm f) :=
{ inv := (transfer_nat_trans_self adj₂ adj₁).symm (inv f),
hom_inv_id' := transfer_nat_trans_self_symm_comm _ _ (by simp),
inv_hom_id' := transfer_nat_trans_self_symm_comm _ _ (by simp) }
/--
If `f` is a natural transformation whose transferred natural transformation is an isomorphism,
then `f` is an isomorphism.
The converse is given in `transfer_nat_trans_self_iso`.
-/
def transfer_nat_trans_self_of_iso (f : L₂ ⟶ L₁) [is_iso (transfer_nat_trans_self adj₁ adj₂ f)] :
is_iso f :=
begin
suffices :
is_iso ((transfer_nat_trans_self adj₁ adj₂).symm (transfer_nat_trans_self adj₁ adj₂ f)),
{ simpa using this },
apply_instance,
end
/--
If `f` is a natural transformation whose un-transferred natural transformation is an isomorphism,
then `f` is an isomorphism.
The converse is given in `transfer_nat_trans_self_symm_iso`.
-/
def transfer_nat_trans_self_symm_of_iso (f : R₁ ⟶ R₂)
[is_iso ((transfer_nat_trans_self adj₁ adj₂).symm f)] :
is_iso f :=
begin
suffices :
is_iso ((transfer_nat_trans_self adj₁ adj₂) ((transfer_nat_trans_self adj₁ adj₂).symm f)),
{ simpa using this },
apply_instance,
end
end self
end category_theory
|
97524822491fd7c30b9fdfb68cb8816376a400ad
|
36c7a18fd72e5b57229bd8ba36493daf536a19ce
|
/tests/lean/run/blast_cc12.lean
|
6640000d2f6f93773dbe0080140330c1af50a33b
|
[
"Apache-2.0"
] |
permissive
|
YHVHvx/lean
|
732bf0fb7a298cd7fe0f15d82f8e248c11db49e9
|
038369533e0136dd395dc252084d3c1853accbf2
|
refs/heads/master
| 1,610,701,080,210
| 1,449,128,595,000
| 1,449,128,595,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 388
|
lean
|
set_option blast.subst false
set_option blast.simp false
set_option pp.all true
definition foo1 (a b : nat) (p : Prop) : a = b → (b = a → p) → p :=
by blast
print foo1
definition foo2 (a b c : nat) (p : Prop) : a = b → b = c → (c = a → p) → p :=
by blast
print foo2
definition foo3 (a b c d : nat) (p : Prop) : a ≠ d → (d ≠ a → p) → p :=
by blast
print foo3
|
5ed159dde8876230b799a6d61368b97580ef8388
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/11_Tactic-Style_Proofs.org.6.lean
|
b3ff88c69d126492f221eeb03b88e414d065e9da
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 135
|
lean
|
import standard
theorem test (p q : Prop) (Hp : p) (Hq : q) : p ∧ q ∧ p :=
begin
apply (and.intro Hp); exact (and.intro Hq Hp)
end
|
452813bafbbc768f69ebaa65b51d973cb38b775f
|
f3849be5d845a1cb97680f0bbbe03b85518312f0
|
/library/tools/super/defs.lean
|
5363b9f3a10a636805b66cdae53c9f54de28097d
|
[
"Apache-2.0"
] |
permissive
|
bjoeris/lean
|
0ed95125d762b17bfcb54dad1f9721f953f92eeb
|
4e496b78d5e73545fa4f9a807155113d8e6b0561
|
refs/heads/master
| 1,611,251,218,281
| 1,495,337,658,000
| 1,495,337,658,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,095
|
lean
|
/-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause_ops .prover_state
open tactic expr monad
namespace super
meta def try_unfold_one_def (type : expr) : tactic expr :=
dunfold_expr_core transparency.all type
meta def try_unfold_def_left (c : clause) (i : ℕ) : tactic (list clause) :=
on_left_at c i $ λt, do
t' ← try_unfold_one_def t,
ht' ← mk_local_def `h t',
return [([ht'], ht')]
meta def try_unfold_def_right (c : clause) (i : ℕ) : tactic (list clause) :=
on_right_at c i $ λh, do
t' ← try_unfold_one_def h.local_type,
hnt' ← mk_local_def `h (imp t' c.local_false),
return [([hnt'], app hnt' h)]
@[super.inf]
meta def unfold_def_inf : inf_decl := inf_decl.mk 40 $ take given, sequence' $ do
r ← [try_unfold_def_right, try_unfold_def_left],
-- NOTE: we cannot restrict to selected literals here
-- as this might prevent factoring, e.g. _n>0_ ∨ is_pos(0)
i ← list.range given.c.num_lits,
[inf_if_successful 3 given (r given.c i)]
end super
|
8488ef336a6287e0aff9cfdf861e891ccac59510
|
957a80ea22c5abb4f4670b250d55534d9db99108
|
/library/init/meta/rb_map.lean
|
8dde0c19cad0098029cf9f31376d35dace7c7418
|
[
"Apache-2.0"
] |
permissive
|
GaloisInc/lean
|
aa1e64d604051e602fcf4610061314b9a37ab8cd
|
f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0
|
refs/heads/master
| 1,592,202,909,807
| 1,504,624,387,000
| 1,504,624,387,000
| 75,319,626
| 2
| 1
|
Apache-2.0
| 1,539,290,164,000
| 1,480,616,104,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 7,563
|
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, Jeremy Avigad
-/
prelude
import init.data.ordering init.function init.meta.name init.meta.format init.category.monad
meta constant {u₁ u₂} rb_map : Type u₁ → Type u₂ → Type (max u₁ u₂)
namespace rb_map
meta constant mk_core {key : Type} (data : Type) : (key → key → ordering) → rb_map key data
meta constant size {key : Type} {data : Type} : rb_map key data → nat
meta constant empty {key : Type} {data : Type} : rb_map key data → bool
meta constant insert {key : Type} {data : Type} : rb_map key data → key → data → rb_map key data
meta constant erase {key : Type} {data : Type} : rb_map key data → key → rb_map key data
meta constant contains {key : Type} {data : Type} : rb_map key data → key → bool
meta constant find {key : Type} {data : Type} : rb_map key data → key → option data
meta constant min {key : Type} {data : Type} : rb_map key data → option data
meta constant max {key : Type} {data : Type} : rb_map key data → option data
meta constant fold {key : Type} {data : Type} {α :Type} : rb_map key data → α → (key → data → α → α) → α
attribute [inline]
meta def mk (key : Type) [has_ordering key] (data : Type) : rb_map key data :=
mk_core data has_ordering.cmp
open list
meta def of_list {key : Type} {data : Type} [has_ordering key] : list (key × data) → rb_map key data
| [] := mk key data
| ((k, v)::ls) := insert (of_list ls) k v
meta def keys {key : Type} {data : Type} (m : rb_map key data) : list key :=
fold m [] (λk v ks, k :: ks)
meta def values {key : Type} {data : Type} (m : rb_map key data) : list data :=
fold m [] (λk v vs, v :: vs)
meta def to_list {key : Type} {data : Type} (m : rb_map key data) : list (key × data) :=
fold m [] (λk v res, (k, v) :: res)
meta def set_of_list {A} [has_ordering A] : list A → rb_map A unit
| [] := mk _ _
| (x::xs) := insert (set_of_list xs) x ()
meta def map {A B C} [has_ordering A] (f : B → C) (m : rb_map A B) : rb_map A C :=
fold m (mk _ _) (λk v res, insert res k (f v))
meta def for {A B C} [has_ordering A] (m : rb_map A B) (f : B → C) : rb_map A C :=
map f m
meta def filter {A B} [has_ordering A] (m : rb_map A B) (f : B → Prop) [decidable_pred f] :=
fold m (mk _ _) $ λa b m', if f b then insert m' a b else m'
meta def mfold {key data α :Type} {m : Type → Type} [monad m] (mp : rb_map key data) (a : α) (fn : key → data → α → m α) : m α :=
mp.fold (return a) (λ k d act, act >>= fn k d)
end rb_map
meta def mk_rb_map {key data : Type} [has_ordering key] : rb_map key data :=
rb_map.mk key data
@[reducible] meta def nat_map (data : Type) := rb_map nat data
namespace nat_map
export rb_map (hiding mk)
meta def mk (data : Type) : nat_map data := rb_map.mk nat data
end nat_map
meta def mk_nat_map {data : Type} : nat_map data :=
nat_map.mk data
@[reducible] meta def name_map (data : Type) := rb_map name data
namespace name_map
export rb_map (hiding mk)
meta def mk (data : Type) : name_map data := rb_map.mk name data
end name_map
meta def mk_name_map {data : Type} : name_map data :=
name_map.mk data
open rb_map prod
section
open format
variables {key : Type} {data : Type} [has_to_format key] [has_to_format data]
private meta def format_key_data (k : key) (d : data) (first : bool) : format :=
(if first then to_fmt "" else to_fmt "," ++ line) ++ to_fmt k ++ space ++ to_fmt "←" ++ space ++ to_fmt d
meta instance : has_to_format (rb_map key data) :=
⟨λ m, group $ to_fmt "⟨" ++ nest 1 (fst (fold m (to_fmt "", tt) (λ k d p, (fst p ++ format_key_data k d (snd p), ff)))) ++
to_fmt "⟩"⟩
end
section
variables {key : Type} {data : Type} [has_to_string key] [has_to_string data]
private meta def key_data_to_string (k : key) (d : data) (first : bool) : string :=
(if first then "" else ", ") ++ to_string k ++ " ← " ++ to_string d
meta instance : has_to_string (rb_map key data) :=
⟨λ m, "⟨" ++ (fst (fold m ("", tt) (λ k d p, (fst p ++ key_data_to_string k d (snd p), ff)))) ++ "⟩"⟩
end
/-- a variant of rb_maps that stores a list of elements for each key.
`find` returns the list of elements in the opposite order that they were inserted. -/
meta def rb_lmap (key : Type) (data : Type) : Type := rb_map key (list data)
namespace rb_lmap
protected meta def mk (key : Type) [has_ordering key] (data : Type) : rb_lmap key data :=
rb_map.mk key (list data)
meta def insert {key : Type} {data : Type} (rbl : rb_lmap key data) (k : key) (d : data) :
rb_lmap key data :=
match (rb_map.find rbl k) with
| none := rb_map.insert rbl k [d]
| (some l) := rb_map.insert (rb_map.erase rbl k) k (d :: l)
end
meta def erase {key : Type} {data : Type} (rbl : rb_lmap key data) (k : key) :
rb_lmap key data :=
rb_map.erase rbl k
meta def contains {key : Type} {data : Type} (rbl : rb_lmap key data) (k : key) : bool :=
rb_map.contains rbl k
meta def find {key : Type} {data : Type} (rbl : rb_lmap key data) (k : key) : list data :=
match (rb_map.find rbl k) with
| none := []
| (some l) := l
end
end rb_lmap
meta def rb_set (key) := rb_map key unit
meta def mk_rb_set {key} [has_ordering key] : rb_set key :=
mk_rb_map
open format
private meta def format_key {key} [has_to_format key] (k : key) (first : bool) : format :=
(if first then to_fmt "" else to_fmt "," ++ line) ++ to_fmt k
namespace rb_set
meta def insert {key} (s : rb_set key) (k : key) : rb_set key :=
rb_map.insert s k ()
meta def erase {key} (s : rb_set key) (k : key) : rb_set key :=
rb_map.erase s k
meta def contains {key} (s : rb_set key) (k : key) : bool :=
rb_map.contains s k
meta def size {key} (s : rb_set key) : nat :=
rb_map.size s
meta def empty {key : Type} (s : rb_set key) : bool :=
rb_map.empty s
meta def fold {key α : Type} (s : rb_set key) (a : α) (fn : key → α → α) : α :=
rb_map.fold s a (λ k _ a, fn k a)
meta def mfold {key α :Type} {m : Type → Type} [monad m] (s : rb_set key) (a : α) (fn : key → α → m α) : m α :=
s.fold (return a) (λ k act, act >>= fn k)
meta def to_list {key : Type} (s : rb_set key) : list key :=
s.fold [] list.cons
meta instance {key} [has_to_format key] : has_to_format (rb_set key) :=
⟨λ m, group $ to_fmt "{" ++ nest 1 (fst (fold m (to_fmt "", tt) (λ k p, (fst p ++ format_key k (snd p), ff)))) ++
to_fmt "}"⟩
end rb_set
meta constant name_set : Type
meta constant mk_name_set : name_set
namespace name_set
meta constant insert : name_set → name → name_set
meta constant erase : name_set → name → name_set
meta constant contains : name_set → name → bool
meta constant size : name_set → nat
meta constant empty : name_set → bool
meta constant fold {α :Type} : name_set → α → (name → α → α) → α
meta def to_list (s : name_set) : list name :=
s.fold [] list.cons
meta instance : has_to_format name_set :=
⟨λ m, group $ to_fmt "{" ++ nest 1 (fst (fold m (to_fmt "", tt) (λ k p, (fst p ++ format_key k (snd p), ff)))) ++
to_fmt "}"⟩
meta def of_list (l : list name) : name_set :=
list.foldl name_set.insert mk_name_set l
meta def mfold {α :Type} {m : Type → Type} [monad m] (ns : name_set) (a : α) (fn : name → α → m α) : m α :=
ns.fold (return a) (λ k act, act >>= fn k)
end name_set
|
eb4b0d5787e76bc7d989ab253335c4f2954df8c5
|
ea5678cc400c34ff95b661fa26d15024e27ea8cd
|
/transpostions.lean
|
7c6dcd9e304183b49841db43dd7103ed30bd33c4
|
[] |
no_license
|
ChrisHughes24/leanstuff
|
dca0b5349c3ed893e8792ffbd98cbcadaff20411
|
9efa85f72efaccd1d540385952a6acc18fce8687
|
refs/heads/master
| 1,654,883,241,759
| 1,652,873,885,000
| 1,652,873,885,000
| 134,599,537
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,487
|
lean
|
import group_theory.subgroup data.equiv.basic data.fintype algebra.big_operators
open equiv
variables {α : Type*}
def is_transposition (f : perm α) : Prop :=
∃ x y, f x = y ∧ f y = x ∧ ∀ a, a ≠ x → a ≠ y → f a = a
lemma is_transposition_inv {f : perm α} : is_transposition f →
is_transposition (f⁻¹) :=
λ ⟨x, y, h⟩, ⟨x, y, h.2.1 ▸ equiv.left_inv _ _, h.1 ▸ equiv.left_inv _ _,
λ a hax hay, by conv {to_lhs, rw ← h.2.2 a hax hay};
exact equiv.left_inv _ _⟩
variable [fintype α]
lemma product_of_transpositions (f : perm α) : ∃ s : list (perm α),
f = s.prod ∧ ∀ g ∈ s, is_transposition g := sorry
lemma sign_well_defined_aux : ∀ (n : ℕ) (f : perm α) (m l : list (perm α)),
(∀ g ∈ l, is_transposition g) → l.prod = f → l.length = n →
(∀ g ∈ m, is_transposition g) → m.prod = f → l.length % 2 = m.length % 2
| 0 := λ f m,
match m with
| [] := by simp {contextual := tt}
| (k :: m) := λ l hl hlf hl0, begin
end
end
lemma sign_well_defined (f : perm α) :
(∀ l : list (perm α), (∀ g ∈ l, is_transposition g) → l.prod = f → l.length % 2 = 0) ∨
(∀ l : list (perm α), (∀ g ∈ l, is_transposition g) → l.prod = f → l.length % 2 = 0) :=
have ∀ n : ℕ, ∀ l m : list (perm α), (∀ g ∈ l, is_transposition g) → l.prod = f → l.length = n
(∀ g ∈ m, is_transposition g) → m.prod = f → l.length % 2 = m.length % 2 | 0 :=
begin
end
|
4a8173b19c561496d490b7d6293b9effb76ce4b9
|
26bff4ed296b8373c92b6b025f5d60cdf02104b9
|
/tests/lean/run/revert_tac.lean
|
e873457e1c3a09ed51d0da89395c12788310399b
|
[
"Apache-2.0"
] |
permissive
|
guiquanz/lean
|
b8a878ea24f237b84b0e6f6be2f300e8bf028229
|
242f8ba0486860e53e257c443e965a82ee342db3
|
refs/heads/master
| 1,526,680,092,098
| 1,427,492,833,000
| 1,427,493,281,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 516
|
lean
|
import logic
theorem tst {a b c : Prop} : a → b → c → a ∧ b :=
begin
intros (Ha, Hb, Hc),
revert Ha,
intro Ha2,
apply (and.intro Ha2 Hb),
end
theorem foo1 {A : Type} (a b c : A) (P : A → Prop) : P a → a = b → P b :=
begin
intros (Hp, Heq),
revert Hp,
apply (eq.rec_on Heq),
intro Hpa,
apply Hpa
end
theorem foo2 {A : Type} (a b c : A) (P : A → Prop) : P a → a = b → P b :=
begin
intros (Hp, Heq),
apply (eq.rec_on Heq Hp)
end
print definition foo1
print definition foo2
|
4bc92b91386eb027311675203ef9b32caac8da9c
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/field_theory/perfect_closure.lean
|
5a292ad4b7e00fc1d9aa2bdf437ec151d4de660c
|
[
"Apache-2.0"
] |
permissive
|
fpvandoorn/mathlib
|
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
|
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
|
refs/heads/master
| 1,624,791,089,608
| 1,556,715,231,000
| 1,556,715,231,000
| 165,722,980
| 5
| 0
|
Apache-2.0
| 1,552,657,455,000
| 1,547,494,646,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 17,184
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Kenny Lau
The perfect closure of a field.
-/
import algebra.char_p
universes u v
/-- A perfect field is a field of characteristic p that has p-th root. -/
class perfect_field (α : Type u) [field α] (p : ℕ) [char_p α p] : Type u :=
(pth_root : α → α)
(frobenius_pth_root : ∀ x, frobenius α p (pth_root x) = x)
theorem frobenius_pth_root (α : Type u) [field α] (p : ℕ) [char_p α p] [perfect_field α p] (x : α) :
frobenius α p (perfect_field.pth_root p x) = x :=
perfect_field.frobenius_pth_root p x
theorem pth_root_frobenius (α : Type u) [field α] (p : ℕ) [nat.prime p] [char_p α p] [perfect_field α p] (x : α) :
perfect_field.pth_root p (frobenius α p x) = x :=
frobenius_inj α p _ _ (by rw frobenius_pth_root)
instance pth_root.is_ring_hom (α : Type u) [field α] (p : ℕ) [nat.prime p] [char_p α p] [perfect_field α p] :
is_ring_hom (@perfect_field.pth_root α _ p _ _) :=
{ map_one := frobenius_inj α p _ _ (by rw [frobenius_pth_root, frobenius_one]),
map_mul := λ x y, frobenius_inj α p _ _ (by simp only [frobenius_pth_root, frobenius_mul]),
map_add := λ x y, frobenius_inj α p _ _ (by simp only [frobenius_pth_root, frobenius_add]) }
theorem is_ring_hom.pth_root {α : Type u} [field α] (p : ℕ) [nat.prime p] [char_p α p] [perfect_field α p]
{β : Type v} [field β] [char_p β p] [perfect_field β p] (f : α → β) [is_ring_hom f] {x : α} :
f (perfect_field.pth_root p x) = perfect_field.pth_root p (f x) :=
frobenius_inj β p _ _ (by rw [← is_monoid_hom.map_frobenius f, frobenius_pth_root, frobenius_pth_root])
inductive perfect_closure.r (α : Type u) [monoid α] (p : ℕ) : (ℕ × α) → (ℕ × α) → Prop
| intro : ∀ n x, perfect_closure.r (n, x) (n+1, frobenius α p x)
run_cmd tactic.mk_iff_of_inductive_prop `perfect_closure.r `perfect_closure.r_iff
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def perfect_closure (α : Type u) [monoid α] (p : ℕ) : Type u :=
quot (perfect_closure.r α p)
namespace perfect_closure
variables (α : Type u)
private lemma mul_aux_left [comm_monoid α] (p : ℕ) (x1 x2 y : ℕ × α) (H : r α p x1 x2) :
quot.mk (r α p) (x1.1 + y.1, ((frobenius α p)^[y.1] x1.2) * ((frobenius α p)^[x1.1] y.2)) =
quot.mk (r α p) (x2.1 + y.1, ((frobenius α p)^[y.1] x2.2) * ((frobenius α p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro _ n x := quot.sound $ by rw [← nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', ← frobenius_mul, nat.succ_add]; apply r.intro
end
private lemma mul_aux_right [comm_monoid α] (p : ℕ) (x y1 y2 : ℕ × α) (H : r α p y1 y2) :
quot.mk (r α p) (x.1 + y1.1, ((frobenius α p)^[y1.1] x.2) * ((frobenius α p)^[x.1] y1.2)) =
quot.mk (r α p) (x.1 + y2.1, ((frobenius α p)^[y2.1] x.2) * ((frobenius α p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro _ n y := quot.sound $ by rw [← nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', ← frobenius_mul]; apply r.intro
end
instance [comm_monoid α] (p : ℕ) : has_mul (perfect_closure α p) :=
⟨quot.lift (λ x:ℕ×α, quot.lift (λ y:ℕ×α, quot.mk (r α p)
(x.1 + y.1, ((frobenius α p)^[y.1] x.2) * ((frobenius α p)^[x.1] y.2))) (mul_aux_right α p x))
(λ x1 x2 (H : r α p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
mul_aux_left α p x1 x2 y H)⟩
instance [comm_monoid α] (p : ℕ) : comm_monoid (perfect_closure α p) :=
{ mul_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [add_assoc, mul_assoc, nat.iterate₂ (frobenius_mul _ _),
(nat.iterate_add _ _ _ _).symm, add_comm, add_left_comm],
one := quot.mk _ (0, 1),
one_mul := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [nat.iterate₀ (frobenius_one _ _), nat.iterate_zero, one_mul, zero_add]),
mul_one := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [nat.iterate₀ (frobenius_one _ _), nat.iterate_zero, mul_one, add_zero]),
mul_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm, mul_comm])),
.. (infer_instance : has_mul (perfect_closure α p)) }
private lemma add_aux_left [comm_ring α] (p : ℕ) (hp : nat.prime p) [char_p α p]
(x1 x2 y : ℕ × α) (H : r α p x1 x2) :
quot.mk (r α p) (x1.1 + y.1, ((frobenius α p)^[y.1] x1.2) + ((frobenius α p)^[x1.1] y.2)) =
quot.mk (r α p) (x2.1 + y.1, ((frobenius α p)^[y.1] x2.2) + ((frobenius α p)^[x2.1] y.2)) :=
match x1, x2, H with
| _, _, r.intro _ n x := quot.sound $ by rw [← nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', ← frobenius_add, nat.succ_add]; apply r.intro
end
private lemma add_aux_right [comm_ring α] (p : ℕ) (hp : nat.prime p) [char_p α p]
(x y1 y2 : ℕ × α) (H : r α p y1 y2) :
quot.mk (r α p) (x.1 + y1.1, ((frobenius α p)^[y1.1] x.2) + ((frobenius α p)^[x.1] y1.2)) =
quot.mk (r α p) (x.1 + y2.1, ((frobenius α p)^[y2.1] x.2) + ((frobenius α p)^[x.1] y2.2)) :=
match y1, y2, H with
| _, _, r.intro _ n y := quot.sound $ by rw [← nat.iterate_succ, nat.iterate_succ',
nat.iterate_succ', ← frobenius_add]; apply r.intro
end
instance [comm_ring α] (p : ℕ) [hp : nat.prime p] [char_p α p] : has_add (perfect_closure α p) :=
⟨quot.lift (λ x:ℕ×α, quot.lift (λ y:ℕ×α, quot.mk (r α p)
(x.1 + y.1, ((frobenius α p)^[y.1] x.2) + ((frobenius α p)^[x.1] y.2))) (add_aux_right α p hp x))
(λ x1 x2 (H : r α p x1 x2), funext $ λ e, quot.induction_on e $ λ y,
add_aux_left α p hp x1 x2 y H)⟩
instance [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] : has_neg (perfect_closure α p) :=
⟨quot.lift (λ x:ℕ×α, quot.mk (r α p) (x.1, -x.2)) (λ x y (H : r α p x y), match x, y, H with
| _, _, r.intro _ n x := quot.sound $ by rw ← frobenius_neg; apply r.intro
end)⟩
theorem mk_zero [comm_ring α] (p : ℕ) [nat.prime p] (n : ℕ) : quot.mk (r α p) (n, 0) = quot.mk (r α p) (0, 0) :=
by induction n with n ih; [refl, rw ← ih]; symmetry; apply quot.sound;
have := r.intro p n (0:α); rwa [frobenius_zero α p] at this
theorem r.sound [monoid α] (p m n : ℕ) (x y : α) (H : frobenius α p^[m] x = y) :
quot.mk (r α p) (n, x) = quot.mk (r α p) (m + n, y) :=
by subst H; induction m with m ih; [simp only [zero_add, nat.iterate_zero],
rw [ih, nat.succ_add, nat.iterate_succ']]; apply quot.sound; apply r.intro
instance [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] : comm_ring (perfect_closure α p) :=
{ add_assoc := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, congr_arg (quot.mk _) $
by simp only [add_assoc, nat.iterate₂ (frobenius_add α p),
(nat.iterate_add _ _ _ _).symm, add_comm, add_left_comm],
zero := quot.mk _ (0, 0),
zero_add := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [nat.iterate₀ (frobenius_zero α p), nat.iterate_zero, zero_add]),
add_zero := λ e, quot.induction_on e (λ ⟨n, x⟩, congr_arg (quot.mk _) $
by simp only [nat.iterate₀ (frobenius_zero α p), nat.iterate_zero, add_zero]),
add_left_neg := λ e, quot.induction_on e (λ ⟨n, x⟩, show quot.mk _ _ = _,
by simp only [nat.iterate₁ (frobenius_neg α p), add_left_neg, mk_zero]; refl),
add_comm := λ e f, quot.induction_on e (λ ⟨m, x⟩, quot.induction_on f (λ ⟨n, y⟩,
congr_arg (quot.mk _) $ by simp only [add_comm])),
left_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm, add_left_comm]; apply r.sound;
simp only [nat.iterate₂ (frobenius_mul α p), nat.iterate₂ (frobenius_add α p),
(nat.iterate_add _ _ _ _).symm, mul_add, add_comm, add_left_comm],
right_distrib := λ e f g, quot.induction_on e $ λ ⟨m, x⟩, quot.induction_on f $ λ ⟨n, y⟩,
quot.induction_on g $ λ ⟨s, z⟩, show quot.mk _ _ = quot.mk _ _,
by simp only [add_assoc, add_comm _ s, add_left_comm _ s]; apply r.sound;
simp only [nat.iterate₂ (frobenius_mul α p), nat.iterate₂ (frobenius_add α p),
(nat.iterate_add _ _ _ _).symm, add_mul, add_comm, add_left_comm],
.. (infer_instance : has_add (perfect_closure α p)),
.. (infer_instance : has_neg (perfect_closure α p)),
.. (infer_instance : comm_monoid (perfect_closure α p)) }
instance [discrete_field α] (p : ℕ) [nat.prime p] [char_p α p] : has_inv (perfect_closure α p) :=
⟨quot.lift (λ x:ℕ×α, quot.mk (r α p) (x.1, x.2⁻¹)) (λ x y (H : r α p x y), match x, y, H with
| _, _, r.intro _ n x := quot.sound $ by simp only [frobenius]; rw inv_pow'; apply r.intro
end)⟩
theorem eq_iff' [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p]
(x y : ℕ × α) : quot.mk (r α p) x = quot.mk (r α p) y ↔
∃ z, (frobenius α p^[y.1 + z] x.2) = (frobenius α p^[x.1 + z] y.2) :=
begin
split,
{ intro H,
replace H := quot.exact _ H,
induction H,
case eqv_gen.rel : x y H
{ cases H with n x, exact ⟨0, rfl⟩ },
case eqv_gen.refl : H
{ exact ⟨0, rfl⟩ },
case eqv_gen.symm : x y H ih
{ cases ih with w ih, exact ⟨w, ih.symm⟩ },
case eqv_gen.trans : x y z H1 H2 ih1 ih2
{ cases ih1 with z1 ih1,
cases ih2 with z2 ih2,
existsi z2+(y.1+z1),
rw [← add_assoc, nat.iterate_add, ih1],
rw [← nat.iterate_add, add_comm, nat.iterate_add, ih2],
rw [← nat.iterate_add],
simp only [add_comm, add_left_comm] } },
intro H,
cases x with m x,
cases y with n y,
cases H with z H, dsimp only at H,
rw [r.sound α p (n+z) m x _ rfl, r.sound α p (m+z) n y _ rfl, H],
rw [add_assoc, add_comm, add_comm z]
end
theorem eq_iff [integral_domain α] (p : ℕ) [nat.prime p] [char_p α p]
(x y : ℕ × α) : quot.mk (r α p) x = quot.mk (r α p) y ↔
(frobenius α p^[y.1] x.2) = (frobenius α p^[x.1] y.2) :=
(eq_iff' α p x y).trans ⟨λ ⟨z, H⟩, nat.iterate_inj (frobenius_inj α p) z _ _ $
by simpa only [add_comm, nat.iterate_add] using H,
λ H, ⟨0, H⟩⟩
instance [discrete_field α] (p : ℕ) [nat.prime p] [char_p α p] : discrete_field (perfect_closure α p) :=
{ zero_ne_one := λ H, zero_ne_one ((eq_iff _ _ _ _).1 H),
mul_inv_cancel := λ e, quot.induction_on e $ λ ⟨m, x⟩ H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [nat.iterate₀ (frobenius_one _ _), nat.iterate₀ (frobenius_zero α p),
nat.iterate_zero, (nat.iterate₂ (frobenius_mul α p)).symm] at this ⊢;
rw [mul_inv_cancel this, nat.iterate₀ (frobenius_one _ _)]),
inv_mul_cancel := λ e, quot.induction_on e $ λ ⟨m, x⟩ H,
have _ := mt (eq_iff _ _ _ _).2 H, (eq_iff _ _ _ _).2
(by simp only [nat.iterate₀ (frobenius_one _ _), nat.iterate₀ (frobenius_zero α p),
nat.iterate_zero, (nat.iterate₂ (frobenius_mul α p)).symm] at this ⊢;
rw [inv_mul_cancel this, nat.iterate₀ (frobenius_one _ _)]),
has_decidable_eq := λ e f, quot.rec_on_subsingleton e $ λ ⟨m, x⟩,
quot.rec_on_subsingleton f $ λ ⟨n, y⟩,
decidable_of_iff' _ (eq_iff α p _ _),
inv_zero := congr_arg (quot.mk (r α p)) (by rw [inv_zero]),
.. (infer_instance : has_inv (perfect_closure α p)),
.. (infer_instance : comm_ring (perfect_closure α p)) }
theorem frobenius_mk [comm_monoid α] (p : ℕ) (x : ℕ × α) :
frobenius (perfect_closure α p) p (quot.mk (r α p) x) = quot.mk _ (x.1, x.2^p) :=
begin
unfold frobenius, cases x with n x, dsimp only,
suffices : ∀ p':ℕ, (quot.mk (r α p) (n, x) ^ p' : perfect_closure α p) = quot.mk (r α p) (n, x ^ p'),
{ apply this },
intro p, induction p with p ih,
case nat.zero { apply r.sound, rw [nat.iterate₀ (frobenius_one _ _), pow_zero] },
case nat.succ {
rw [pow_succ, ih],
symmetry,
apply r.sound,
simp only [pow_succ, nat.iterate₂ (frobenius_mul _ _)]
}
end
def frobenius_equiv [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] :
perfect_closure α p ≃ perfect_closure α p :=
{ to_fun := frobenius (perfect_closure α p) p,
inv_fun := λ e, quot.lift_on e (λ x, quot.mk (r α p) (x.1 + 1, x.2)) (λ x y H,
match x, y, H with
| _, _, r.intro _ n x := quot.sound (r.intro _ _ _)
end),
left_inv := λ e, quot.induction_on e (λ ⟨m, x⟩, by rw frobenius_mk;
symmetry; apply quot.sound; apply r.intro),
right_inv := λ e, quot.induction_on e (λ ⟨m, x⟩, by rw frobenius_mk;
symmetry; apply quot.sound; apply r.intro) }
theorem frobenius_equiv_apply [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] {x : perfect_closure α p} :
frobenius_equiv α p x = frobenius _ p x :=
rfl
theorem nat_cast [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] (n x : ℕ) :
(x : perfect_closure α p) = quot.mk (r α p) (n, x) :=
begin
induction n with n ih,
{ induction x with x ih, {refl},
rw [nat.cast_succ, nat.cast_succ, ih], refl },
rw ih, apply quot.sound,
conv {congr, skip, skip, rw ← frobenius_nat_cast α p x},
apply r.intro
end
theorem int_cast [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] (x : ℤ) :
(x : perfect_closure α p) = quot.mk (r α p) (0, x) :=
by induction x; simp only [int.cast_of_nat, int.cast_neg_succ_of_nat, nat_cast α p 0]; refl
theorem nat_cast_eq_iff [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] (x y : ℕ) :
(x : perfect_closure α p) = y ↔ (x : α) = y :=
begin
split; intro H,
{ rw [nat_cast α p 0, nat_cast α p 0, eq_iff'] at H,
cases H with z H,
simpa only [zero_add, nat.iterate₀ (frobenius_nat_cast α p _)] using H },
rw [nat_cast α p 0, nat_cast α p 0, H]
end
instance [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] : char_p (perfect_closure α p) p :=
begin
constructor, intro x, rw ← char_p.cast_eq_zero_iff α,
rw [← nat.cast_zero, nat_cast_eq_iff, nat.cast_zero]
end
instance [discrete_field α] (p : ℕ) [nat.prime p] [char_p α p] : perfect_field (perfect_closure α p) p :=
{ pth_root := (frobenius_equiv α p).symm,
frobenius_pth_root := (frobenius_equiv α p).apply_symm_apply }
def of [monoid α] (p : ℕ) (x : α) : perfect_closure α p :=
quot.mk _ (0, x)
instance [comm_ring α] (p : ℕ) [nat.prime p] [char_p α p] : is_ring_hom (of α p) :=
{ map_one := rfl,
map_mul := λ x y, rfl,
map_add := λ x y, rfl }
theorem eq_pth_root [discrete_field α] (p : ℕ) [nat.prime p] [char_p α p] (m : ℕ) (x : α) :
quot.mk (r α p) (m, x) = (perfect_field.pth_root p^[m] (of α p x) : perfect_closure α p) :=
begin
unfold of,
induction m with m ih, {refl},
rw [nat.iterate_succ', ← ih]; refl
end
def UMP [discrete_field α] (p : ℕ) [nat.prime p] [char_p α p]
(β : Type v) [discrete_field β] [char_p β p] [perfect_field β p] :
{ f : α → β // is_ring_hom f } ≃ { f : perfect_closure α p → β // is_ring_hom f } :=
{ to_fun := λ f, ⟨λ e, quot.lift_on e (λ x, perfect_field.pth_root p^[x.1] (f.1 x.2))
(λ x y H, match x, y, H with | _, _, r.intro _ n x := by letI := f.2;
simp only [is_monoid_hom.map_frobenius f.1, nat.iterate_succ, pth_root_frobenius]
end),
show f.1 1 = 1, from f.2.1,
λ j k, quot.induction_on j $ λ ⟨m, x⟩, quot.induction_on k $ λ ⟨n, y⟩,
show (perfect_field.pth_root p^[_] _) = (perfect_field.pth_root p^[_] _) * (perfect_field.pth_root p^[_] _),
by letI := f.2; simp only [is_ring_hom.map_mul f.1, (nat.iterate₁ (λ x, (is_monoid_hom.map_frobenius f.1 p x).symm)).symm,
@nat.iterate₂ β _ (*) (λ x y, is_ring_hom.map_mul (perfect_field.pth_root p))];
rw [nat.iterate_add, nat.iterate_cancel (pth_root_frobenius β p),
add_comm, nat.iterate_add, nat.iterate_cancel (pth_root_frobenius β p)],
λ j k, quot.induction_on j $ λ ⟨m, x⟩, quot.induction_on k $ λ ⟨n, y⟩,
show (perfect_field.pth_root p^[_] _) = (perfect_field.pth_root p^[_] _) + (perfect_field.pth_root p^[_] _),
by letI := f.2; simp only [is_ring_hom.map_add f.1, (nat.iterate₁ (λ x, (is_monoid_hom.map_frobenius f.1 p x).symm)).symm,
@nat.iterate₂ β _ (+) (λ x y, is_ring_hom.map_add (perfect_field.pth_root p))];
rw [nat.iterate_add, nat.iterate_cancel (pth_root_frobenius β p),
add_comm m, nat.iterate_add, nat.iterate_cancel (pth_root_frobenius β p)]⟩,
inv_fun := λ f, ⟨f.1 ∘ of α p, @@is_ring_hom.comp _ _ _ _ _ _ f.2⟩,
left_inv := λ ⟨f, hf⟩, subtype.eq rfl,
right_inv := λ ⟨f, hf⟩, subtype.eq $ funext $ λ i, quot.induction_on i $ λ ⟨m, x⟩,
show perfect_field.pth_root p^[m] (f _) = f _,
by resetI; rw [eq_pth_root, @nat.iterate₁ _ _ _ _ f (λ x:perfect_closure α p, (is_ring_hom.pth_root p f).symm)] }
end perfect_closure
|
63db26c87bd04e1c9f27f4fef2082deb4959209b
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/topology/partition_of_unity.lean
|
d848c9618af08ab3d205f450fabbf6724d417e1c
|
[
"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
| 20,410
|
lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import algebra.big_operators.finprod
import topology.urysohns_lemma
import topology.paracompact
import topology.shrinking_lemma
import topology.continuous_function.algebra
import set_theory.ordinal
/-!
# Continuous partition of unity
In this file we define `partition_of_unity (ι X : Type*) [topological_space X] (s : set X := univ)`
to be a continuous partition of unity on `s` indexed by `ι`. More precisely, `f : partition_of_unity
ι X s` is a collection of continuous functions `f i : C(X, ℝ)`, `i : ι`, such that
* the supports of `f i` form a locally finite family of sets;
* each `f i` is nonnegative;
* `∑ᶠ i, f i x = 1` for all `x ∈ s`;
* `∑ᶠ i, f i x ≤ 1` for all `x : X`.
In the case `s = univ` the last assumption follows from the previous one but it is convenient to
have this assumption in the case `s ≠ univ`.
We also define a bump function covering,
`bump_covering (ι X : Type*) [topological_space X] (s : set X := univ)`, to be a collection of
functions `f i : C(X, ℝ)`, `i : ι`, such that
* the supports of `f i` form a locally finite family of sets;
* each `f i` is nonnegative;
* for each `x ∈ s` there exists `i : ι` such that `f i y = 1` in a neighborhood of `x`.
The term is motivated by the smooth case.
If `f` is a bump function covering indexed by a linearly ordered type, then
`g i x = f i x * ∏ᶠ j < i, (1 - f j x)` is a partition of unity, see
`bump_covering.to_partition_of_unity`. Note that only finitely many terms `1 - f j x` are not equal
to one, so this product is well-defined.
Note that `g i x = ∏ᶠ j ≤ i, (1 - f j x) - ∏ᶠ j < i, (1 - f j x)`, so most terms in the sum
`∑ᶠ i, g i x` cancel, and we get `∑ᶠ i, g i x = 1 - ∏ᶠ i, (1 - f i x)`, and the latter product
equals zero because one of `f i x` is equal to one.
We say that a partition of unity or a bump function covering `f` is *subordinate* to a family of
sets `U i`, `i : ι`, if the closure of the support of each `f i` is included in `U i`. We use
Urysohn's Lemma to prove that a locally finite open covering of a normal topological space admits a
subordinate bump function covering (hence, a subordinate partition of unity), see
`bump_covering.exists_is_subordinate_of_locally_finite`. If `X` is a paracompact space, then any
open covering admits a locally finite refinement, hence it admits a subordinate bump function
covering and a subordinate partition of unity, see `bump_covering.exists_is_subordinate`.
We also provide two slightly more general versions of these lemmas,
`bump_covering.exists_is_subordinate_of_locally_finite_of_prop` and
`bump_covering.exists_is_subordinate_of_prop`, to be used later in the construction of a smooth
partition of unity.
## Implementation notes
Most (if not all) books only define a partition of unity of the whole space. However, quite a few
proofs only deal with `f i` such that `closure (support (f i))` meets a specific closed subset, and
it is easier to formalize these proofs if we don't have other functions right away.
We use `well_ordering_rel j i` instead of `j < i` in the definition of
`bump_covering.to_partition_of_unity` to avoid a `[linear_order ι]` assumption. While
`well_ordering_rel j i` is a well order, not only a strict linear order, we never use this property.
## Tags
partition of unity, bump function, Urysohn's lemma, normal space, paracompact space
-/
universes u v
open function set filter
open_locale big_operators topological_space classical
noncomputable theory
/-- A continuous partition of unity on a set `s : set X` is a collection of continuous functions
`f i` such that
* the supports of `f i` form a locally finite family of sets, i.e., for every point `x : X` there
exists a neighborhood `U ∋ x` such that all but finitely many functions `f i` are zero on `U`;
* the functions `f i` are nonnegative;
* the sum `∑ᶠ i, f i x` is equal to one for every `x ∈ s` and is less than or equal to one
otherwise.
If `X` is a normal paracompact space, then `partition_of_unity.exists_is_subordinate` guarantees
that for every open covering `U : set (set X)` of `s` there exists a partition of unity that is
subordinate to `U`.
-/
structure partition_of_unity (ι X : Type*) [topological_space X] (s : set X := univ) :=
(to_fun : ι → C(X, ℝ))
(locally_finite' : locally_finite (λ i, support (to_fun i)))
(nonneg' : 0 ≤ to_fun)
(sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, to_fun i x = 1)
(sum_le_one' : ∀ x, ∑ᶠ i, to_fun i x ≤ 1)
/-- A `bump_covering ι X s` is an indexed family of functions `f i`, `i : ι`, such that
* the supports of `f i` form a locally finite family of sets, i.e., for every point `x : X` there
exists a neighborhood `U ∋ x` such that all but finitely many functions `f i` are zero on `U`;
* for all `i`, `x` we have `0 ≤ f i x ≤ 1`;
* each point `x ∈ s` belongs to the interior of `{x | f i x = 1}` for some `i`.
One of the main use cases for a `bump_covering` is to define a `partition_of_unity`, see
`bump_covering.to_partition_of_unity`, but some proofs can directly use a `bump_covering` instead of
a `partition_of_unity`.
If `X` is a normal paracompact space, then `bump_covering.exists_is_subordinate` guarantees that for
every open covering `U : set (set X)` of `s` there exists a `bump_covering` of `s` that is
subordinate to `U`.
-/
structure bump_covering (ι X : Type*) [topological_space X] (s : set X := univ) :=
(to_fun : ι → C(X, ℝ))
(locally_finite' : locally_finite (λ i, support (to_fun i)))
(nonneg' : 0 ≤ to_fun)
(le_one' : to_fun ≤ 1)
(eventually_eq_one' : ∀ x ∈ s, ∃ i, to_fun i =ᶠ[𝓝 x] 1)
variables {ι : Type u} {X : Type v} [topological_space X]
namespace partition_of_unity
variables {s : set X} (f : partition_of_unity ι X s)
instance : has_coe_to_fun (partition_of_unity ι X s) (λ _, ι → C(X, ℝ)) := ⟨to_fun⟩
protected lemma locally_finite : locally_finite (λ i, support (f i)) :=
f.locally_finite'
lemma nonneg (i : ι) (x : X) : 0 ≤ f i x := f.nonneg' i x
lemma sum_eq_one {x : X} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx
lemma sum_le_one (x : X) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x
lemma sum_nonneg (x : X) : 0 ≤ ∑ᶠ i, f i x := finsum_nonneg $ λ i, f.nonneg i x
lemma le_one (i : ι) (x : X) : f i x ≤ 1 :=
(single_le_finsum i (f.locally_finite.point_finite x) (λ j, f.nonneg j x)).trans (f.sum_le_one x)
/-- A partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same type if
for each `i` the closure of the support of `f i` is a subset of `U i`. -/
def is_subordinate (f : partition_of_unity ι X s) (U : ι → set X) : Prop :=
∀ i, closure (support (f i)) ⊆ U i
end partition_of_unity
namespace bump_covering
variables {s : set X} (f : bump_covering ι X s)
instance : has_coe_to_fun (bump_covering ι X s) (λ _, ι → C(X, ℝ)) := ⟨to_fun⟩
protected lemma locally_finite : locally_finite (λ i, support (f i)) :=
f.locally_finite'
protected lemma point_finite (x : X) : finite {i | f i x ≠ 0} :=
f.locally_finite.point_finite x
lemma nonneg (i : ι) (x : X) : 0 ≤ f i x := f.nonneg' i x
lemma le_one (i : ι) (x : X) : f i x ≤ 1 := f.le_one' i x
/-- A `bump_covering` that consists of a single function, uniformly equal to one, defined as an
example for `inhabited` instance. -/
protected def single (i : ι) (s : set X) : bump_covering ι X s :=
{ to_fun := pi.single i 1,
locally_finite' := λ x,
begin
refine ⟨univ, univ_mem, (finite_singleton i).subset _⟩,
rintro j ⟨x, hx, -⟩,
contrapose! hx,
rw [mem_singleton_iff] at hx,
simp [hx]
end,
nonneg' := le_update_iff.2 ⟨λ x, zero_le_one, λ _ _, le_rfl⟩,
le_one' := update_le_iff.2 ⟨le_rfl, λ _ _ _, zero_le_one⟩,
eventually_eq_one' := λ x _, ⟨i, by simp⟩ }
@[simp] lemma coe_single (i : ι) (s : set X) : ⇑(bump_covering.single i s) = pi.single i 1 := rfl
instance [inhabited ι] : inhabited (bump_covering ι X s) :=
⟨bump_covering.single (default ι) s⟩
/-- A collection of bump functions `f i` is subordinate to a family of sets `U i` indexed by the
same type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/
def is_subordinate (f : bump_covering ι X s) (U : ι → set X) : Prop :=
∀ i, closure (support (f i)) ⊆ U i
lemma is_subordinate.mono {f : bump_covering ι X s} {U V : ι → set X} (hU : f.is_subordinate U)
(hV : ∀ i, U i ⊆ V i) :
f.is_subordinate V :=
λ i, subset.trans (hU i) (hV i)
/-- If `X` is a normal topological space and `U i`, `i : ι`, is a locally finite open covering of a
closed set `s`, then there exists a `bump_covering ι X s` that is subordinate to `U`. If `X` is a
paracompact space, then the assumption `hf : locally_finite U` can be omitted, see
`bump_covering.exists_is_subordinate`. This version assumes that `p : (X → ℝ) → Prop` is a predicate
that satisfies Urysohn's lemma, and provides a `bump_covering` such that each function of the
covering satisfies `p`. -/
lemma exists_is_subordinate_of_locally_finite_of_prop [normal_space X] (p : (X → ℝ) → Prop)
(h01 : ∀ s t, is_closed s → is_closed t → disjoint s t →
∃ f : C(X, ℝ), p f ∧ eq_on f 0 s ∧ eq_on f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1)
(hs : is_closed s) (U : ι → set X) (ho : ∀ i, is_open (U i)) (hf : locally_finite U)
(hU : s ⊆ ⋃ i, U i) :
∃ f : bump_covering ι X s, (∀ i, p (f i)) ∧ f.is_subordinate U :=
begin
rcases exists_subset_Union_closure_subset hs ho (λ x _, hf.point_finite x) hU
with ⟨V, hsV, hVo, hVU⟩,
have hVU' : ∀ i, V i ⊆ U i, from λ i, subset.trans subset_closure (hVU i),
rcases exists_subset_Union_closure_subset hs hVo
(λ x _, (hf.subset hVU').point_finite x) hsV with ⟨W, hsW, hWo, hWV⟩,
choose f hfp hf0 hf1 hf01
using λ i, h01 _ _ (is_closed_compl_iff.2 $ hVo i)
is_closed_closure (disjoint_right.2 $ λ x hx, not_not.2 (hWV i hx)),
have hsupp : ∀ i, support (f i) ⊆ V i,
from λ i, support_subset_iff'.2 (hf0 i),
refine ⟨⟨f, hf.subset (λ i, subset.trans (hsupp i) (hVU' i)),
λ i x, (hf01 i x).1, λ i x, (hf01 i x).2, λ x hx, _⟩, hfp,
λ i, subset.trans (closure_mono (hsupp i)) (hVU i)⟩,
rcases mem_Union.1 (hsW hx) with ⟨i, hi⟩,
exact ⟨i, ((hf1 i).mono subset_closure).eventually_eq_of_mem ((hWo i).mem_nhds hi)⟩
end
/-- If `X` is a normal topological space and `U i`, `i : ι`, is a locally finite open covering of a
closed set `s`, then there exists a `bump_covering ι X s` that is subordinate to `U`. If `X` is a
paracompact space, then the assumption `hf : locally_finite U` can be omitted, see
`bump_covering.exists_is_subordinate`. -/
lemma exists_is_subordinate_of_locally_finite [normal_space X] (hs : is_closed s)
(U : ι → set X) (ho : ∀ i, is_open (U i)) (hf : locally_finite U)
(hU : s ⊆ ⋃ i, U i) :
∃ f : bump_covering ι X s, f.is_subordinate U :=
let ⟨f, _, hfU⟩ :=
exists_is_subordinate_of_locally_finite_of_prop (λ _, true)
(λ s t hs ht hd, (exists_continuous_zero_one_of_closed hs ht hd).imp $ λ f hf, ⟨trivial, hf⟩)
hs U ho hf hU
in ⟨f, hfU⟩
/-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set
`s`, then there exists a `bump_covering ι X s` that is subordinate to `U`. This version assumes that
`p : (X → ℝ) → Prop` is a predicate that satisfies Urysohn's lemma, and provides a
`bump_covering` such that each function of the covering satisfies `p`. -/
lemma exists_is_subordinate_of_prop [normal_space X] [paracompact_space X] (p : (X → ℝ) → Prop)
(h01 : ∀ s t, is_closed s → is_closed t → disjoint s t →
∃ f : C(X, ℝ), p f ∧ eq_on f 0 s ∧ eq_on f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1)
(hs : is_closed s) (U : ι → set X) (ho : ∀ i, is_open (U i)) (hU : s ⊆ ⋃ i, U i) :
∃ f : bump_covering ι X s, (∀ i, p (f i)) ∧ f.is_subordinate U :=
begin
rcases precise_refinement_set hs _ ho hU with ⟨V, hVo, hsV, hVf, hVU⟩,
rcases exists_is_subordinate_of_locally_finite_of_prop p h01 hs V hVo hVf hsV with ⟨f, hfp, hf⟩,
exact ⟨f, hfp, hf.mono hVU⟩
end
/-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set
`s`, then there exists a `bump_covering ι X s` that is subordinate to `U`. -/
lemma exists_is_subordinate [normal_space X] [paracompact_space X]
(hs : is_closed s) (U : ι → set X) (ho : ∀ i, is_open (U i)) (hU : s ⊆ ⋃ i, U i) :
∃ f : bump_covering ι X s, f.is_subordinate U :=
begin
rcases precise_refinement_set hs _ ho hU with ⟨V, hVo, hsV, hVf, hVU⟩,
rcases exists_is_subordinate_of_locally_finite hs V hVo hVf hsV with ⟨f, hf⟩,
exact ⟨f, hf.mono hVU⟩
end
/-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/
def ind (x : X) (hx : x ∈ s) : ι := (f.eventually_eq_one' x hx).some
lemma eventually_eq_one (x : X) (hx : x ∈ s) : f (f.ind x hx) =ᶠ[𝓝 x] 1 :=
(f.eventually_eq_one' x hx).some_spec
lemma ind_apply (x : X) (hx : x ∈ s) : f (f.ind x hx) x = 1 :=
(f.eventually_eq_one x hx).eq_of_nhds
/-- Partition of unity defined by a `bump_covering`. We use this auxiliary definition to prove some
properties of the new family of functions before bundling it into a `partition_of_unity`. Do not use
this definition, use `bump_function.to_partition_of_unity` instead.
The partition of unity is given by the formula `g i x = f i x * ∏ᶠ j < i, (1 - f j x)`. In other
words, `g i x = ∏ᶠ j < i, (1 - f j x) - ∏ᶠ j ≤ i, (1 - f j x)`, so
`∑ᶠ i, g i x = 1 - ∏ᶠ j, (1 - f j x)`. If `x ∈ s`, then one of `f j x` equals one, hence the product
of `1 - f j x` vanishes, and `∑ᶠ i, g i x = 1`.
In order to avoid an assumption `linear_order ι`, we use `well_ordering_rel` instead of `(<)`. -/
def to_pou_fun (i : ι) (x : X) : ℝ :=
f i x * ∏ᶠ j (hj : well_ordering_rel j i), (1 - f j x)
lemma to_pou_fun_zero_of_zero {i : ι} {x : X} (h : f i x = 0) :
f.to_pou_fun i x = 0 :=
by rw [to_pou_fun, h, zero_mul]
lemma support_to_pou_fun_subset (i : ι) :
support (f.to_pou_fun i) ⊆ support (f i) :=
λ x, mt $ f.to_pou_fun_zero_of_zero
lemma to_pou_fun_eq_mul_prod (i : ι) (x : X) (t : finset ι)
(ht : ∀ j, well_ordering_rel j i → f j x ≠ 0 → j ∈ t) :
f.to_pou_fun i x = f i x * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - f j x) :=
begin
refine congr_arg _ (finprod_cond_eq_prod_of_cond_iff _ (λ j hj, _)),
rw [ne.def, sub_eq_self] at hj,
rw [finset.mem_filter, iff.comm, and_iff_right_iff_imp],
exact flip (ht j) hj
end
lemma sum_to_pou_fun_eq (x : X) :
∑ᶠ i, f.to_pou_fun i x = 1 - ∏ᶠ i, (1 - f i x) :=
begin
set s := (f.point_finite x).to_finset,
have hs : (s : set ι) = {i | f i x ≠ 0} := finite.coe_to_finset _,
have A : support (λ i, to_pou_fun f i x) ⊆ s,
{ rw hs,
exact λ i hi, f.support_to_pou_fun_subset i hi },
have B : mul_support (λ i, 1 - f i x) ⊆ s,
{ rw [hs, mul_support_one_sub], exact λ i, id },
letI : linear_order ι := linear_order_of_STO' well_ordering_rel,
rw [finsum_eq_sum_of_support_subset _ A, finprod_eq_prod_of_mul_support_subset _ B,
finset.prod_one_sub_ordered, sub_sub_cancel],
refine finset.sum_congr rfl (λ i hi, _),
convert f.to_pou_fun_eq_mul_prod _ _ _ (λ j hji hj, _),
rwa finite.mem_to_finset
end
lemma exists_finset_to_pou_fun_eventually_eq (i : ι) (x : X) :
∃ t : finset ι, f.to_pou_fun i =ᶠ[𝓝 x]
f i * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - f j) :=
begin
rcases f.locally_finite x with ⟨U, hU, hf⟩,
use hf.to_finset,
filter_upwards [hU],
intros y hyU,
simp only [pi.mul_apply, finset.prod_apply],
apply to_pou_fun_eq_mul_prod,
intros j hji hj,
exact hf.mem_to_finset.2 ⟨y, ⟨hj, hyU⟩⟩
end
lemma continuous_to_pou_fun (i : ι) : continuous (f.to_pou_fun i) :=
begin
refine ((f i).continuous.mul $
continuous_finprod_cond (λ j _, continuous_const.sub (f j).continuous) _),
simp only [mul_support_one_sub],
exact f.locally_finite
end
/-- The partition of unity defined by a `bump_covering`.
The partition of unity is given by the formula `g i x = f i x * ∏ᶠ j < i, (1 - f j x)`. In other
words, `g i x = ∏ᶠ j < i, (1 - f j x) - ∏ᶠ j ≤ i, (1 - f j x)`, so
`∑ᶠ i, g i x = 1 - ∏ᶠ j, (1 - f j x)`. If `x ∈ s`, then one of `f j x` equals one, hence the product
of `1 - f j x` vanishes, and `∑ᶠ i, g i x = 1`.
In order to avoid an assumption `linear_order ι`, we use `well_ordering_rel` instead of `(<)`. -/
def to_partition_of_unity : partition_of_unity ι X s :=
{ to_fun := λ i, ⟨f.to_pou_fun i, f.continuous_to_pou_fun i⟩,
locally_finite' := f.locally_finite.subset f.support_to_pou_fun_subset,
nonneg' := λ i x, mul_nonneg (f.nonneg i x)
(finprod_cond_nonneg $ λ j hj, sub_nonneg.2 $ f.le_one j x),
sum_eq_one' := λ x hx,
begin
simp only [continuous_map.coe_mk, sum_to_pou_fun_eq, sub_eq_self],
apply finprod_eq_zero (λ i, 1 - f i x) (f.ind x hx),
{ simp only [f.ind_apply x hx, sub_self] },
{ rw mul_support_one_sub, exact f.point_finite x }
end,
sum_le_one' := λ x,
begin
simp only [continuous_map.coe_mk, sum_to_pou_fun_eq, sub_le_self_iff],
exact finprod_nonneg (λ i, sub_nonneg.2 $ f.le_one i x)
end }
lemma to_partition_of_unity_apply (i : ι) (x : X) :
f.to_partition_of_unity i x = f i x * ∏ᶠ j (hj : well_ordering_rel j i), (1 - f j x) :=
rfl
lemma to_partition_of_unity_eq_mul_prod (i : ι) (x : X) (t : finset ι)
(ht : ∀ j, well_ordering_rel j i → f j x ≠ 0 → j ∈ t) :
f.to_partition_of_unity i x = f i x * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - f j x) :=
f.to_pou_fun_eq_mul_prod i x t ht
lemma exists_finset_to_partition_of_unity_eventually_eq (i : ι) (x : X) :
∃ t : finset ι, f.to_partition_of_unity i =ᶠ[𝓝 x]
f i * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - f j) :=
f.exists_finset_to_pou_fun_eventually_eq i x
lemma to_partition_of_unity_zero_of_zero {i : ι} {x : X} (h : f i x = 0) :
f.to_partition_of_unity i x = 0 :=
f.to_pou_fun_zero_of_zero h
lemma support_to_partition_of_unity_subset (i : ι) :
support (f.to_partition_of_unity i) ⊆ support (f i) :=
f.support_to_pou_fun_subset i
lemma sum_to_partition_of_unity_eq (x : X) :
∑ᶠ i, f.to_partition_of_unity i x = 1 - ∏ᶠ i, (1 - f i x) :=
f.sum_to_pou_fun_eq x
lemma is_subordinate.to_partition_of_unity {f : bump_covering ι X s} {U : ι → set X}
(h : f.is_subordinate U) :
f.to_partition_of_unity.is_subordinate U :=
λ i, subset.trans (closure_mono $ f.support_to_partition_of_unity_subset i) (h i)
end bump_covering
namespace partition_of_unity
variables {s : set X}
instance [inhabited ι] : inhabited (partition_of_unity ι X s) :=
⟨(default (bump_covering ι X s)).to_partition_of_unity⟩
/-- If `X` is a normal topological space and `U` is a locally finite open covering of a closed set
`s`, then there exists a `partition_of_unity ι X s` that is subordinate to `U`. If `X` is a
paracompact space, then the assumption `hf : locally_finite U` can be omitted, see
`bump_covering.exists_is_subordinate`. -/
lemma exists_is_subordinate_of_locally_finite [normal_space X] (hs : is_closed s)
(U : ι → set X) (ho : ∀ i, is_open (U i)) (hf : locally_finite U)
(hU : s ⊆ ⋃ i, U i) :
∃ f : partition_of_unity ι X s, f.is_subordinate U :=
let ⟨f, hf⟩ := bump_covering.exists_is_subordinate_of_locally_finite hs U ho hf hU
in ⟨f.to_partition_of_unity, hf.to_partition_of_unity⟩
/-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set
`s`, then there exists a `partition_of_unity ι X s` that is subordinate to `U`. -/
lemma exists_is_subordinate [normal_space X] [paracompact_space X] (hs : is_closed s)
(U : ι → set X) (ho : ∀ i, is_open (U i)) (hU : s ⊆ ⋃ i, U i) :
∃ f : partition_of_unity ι X s, f.is_subordinate U :=
let ⟨f, hf⟩ := bump_covering.exists_is_subordinate hs U ho hU
in ⟨f.to_partition_of_unity, hf.to_partition_of_unity⟩
end partition_of_unity
|
59ef5ef579c2b995547367ef1a06fd2b12f3f588
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/linear_algebra/tensor_algebra/basic.lean
|
a4bb65422be10a1d621998b1b9bb2fcd8c4b9900
|
[
"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
| 10,070
|
lean
|
/-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import algebra.free_algebra
import algebra.ring_quot
import algebra.triv_sq_zero_ext
import algebra.algebra.operations
import linear_algebra.multilinear.basic
/-!
# Tensor Algebras
Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`.
This is the free `R`-algebra generated (`R`-linearly) by the module `M`.
## Notation
1. `tensor_algebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure.
2. `tensor_algebra.ι R` is the canonical R-linear map `M → tensor_algebra R M`.
3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `tensor_algebra R M → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : tensor_algebra R M → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
## Implementation details
As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`,
modulo the additional relations making the inclusion of `M` into an `R`-linear map.
-/
variables (R : Type*) [comm_semiring R]
variables (M : Type*) [add_comm_monoid M] [module R M]
namespace tensor_algebra
/--
An inductively defined relation on `pre R M` used to force the initial algebra structure on
the associated quotient.
-/
inductive rel : free_algebra R M → free_algebra R M → Prop
-- force `ι` to be linear
| add {a b : M} :
rel (free_algebra.ι R (a+b)) (free_algebra.ι R a + free_algebra.ι R b)
| smul {r : R} {a : M} :
rel (free_algebra.ι R (r • a)) (algebra_map R (free_algebra R M) r * free_algebra.ι R a)
end tensor_algebra
/--
The tensor algebra of the module `M` over the commutative semiring `R`.
-/
@[derive [inhabited, semiring, algebra R]]
def tensor_algebra := ring_quot (tensor_algebra.rel R M)
namespace tensor_algebra
instance {S : Type*} [comm_ring S] [module S M] : ring (tensor_algebra S M) :=
ring_quot.ring (rel S M)
variables {M}
/--
The canonical linear map `M →ₗ[R] tensor_algebra R M`.
-/
def ι : M →ₗ[R] (tensor_algebra R M) :=
{ to_fun := λ m, (ring_quot.mk_alg_hom R _ (free_algebra.ι R m)),
map_add' := λ x y, by { rw [←alg_hom.map_add], exact ring_quot.mk_alg_hom_rel R rel.add, },
map_smul' := λ r x, by { rw [←alg_hom.map_smul], exact ring_quot.mk_alg_hom_rel R rel.smul, } }
lemma ring_quot_mk_alg_hom_free_algebra_ι_eq_ι (m : M) :
ring_quot.mk_alg_hom R (rel R M) (free_algebra.ι R m) = ι R m := rfl
/--
Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `tensor_algebra R M → A`.
-/
@[simps symm_apply]
def lift {A : Type*} [semiring A] [algebra R A] : (M →ₗ[R] A) ≃ (tensor_algebra R M →ₐ[R] A) :=
{ to_fun := ring_quot.lift_alg_hom R ∘ λ f,
⟨free_algebra.lift R ⇑f, λ x y (h : rel R M x y), by induction h; simp [algebra.smul_def]⟩,
inv_fun := λ F, F.to_linear_map.comp (ι R),
left_inv := λ f, linear_map.ext $ λ x,
(ring_quot.lift_alg_hom_mk_alg_hom_apply _ _ _ _).trans (free_algebra.lift_ι_apply f x),
right_inv := λ F, ring_quot.ring_quot_ext' _ _ _ $ free_algebra.hom_ext $ funext $ λ x,
(ring_quot.lift_alg_hom_mk_alg_hom_apply _ _ _ _).trans (free_algebra.lift_ι_apply _ _) }
variables {R}
@[simp]
theorem ι_comp_lift {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) :
(lift R f).to_linear_map.comp (ι R) = f := (lift R).symm_apply_apply f
@[simp]
theorem lift_ι_apply {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (x) :
lift R f (ι R x) = f x := by { dsimp [lift, ι], refl, }
@[simp]
theorem lift_unique {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A)
(g : tensor_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R f :=
(lift R).symm_apply_eq
-- Marking `tensor_algebra` irreducible makes `ring` instances inaccessible on quotients.
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
-- For now, we avoid this by not marking it irreducible.
attribute [irreducible] ι lift
@[simp]
theorem lift_comp_ι {A : Type*} [semiring A] [algebra R A] (g : tensor_algebra R M →ₐ[R] A) :
lift R (g.to_linear_map.comp (ι R)) = g :=
by { rw ←lift_symm_apply, exact (lift R).apply_symm_apply g }
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : tensor_algebra R M →ₐ[R] A}
(w : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g :=
begin
rw [←lift_symm_apply, ←lift_symm_apply] at w,
exact (lift R).symm.injective w,
end
/-- If `C` holds for the `algebra_map` of `r : R` into `tensor_algebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `tensor_algebra R M`.
-/
-- This proof closely follows `free_algebra.induction`
@[elab_as_eliminator]
lemma induction {C : tensor_algebra R M → Prop}
(h_grade0 : ∀ r, C (algebra_map R (tensor_algebra R M) r))
(h_grade1 : ∀ x, C (ι R x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : tensor_algebra R M) :
C a :=
begin
-- the arguments are enough to construct a subalgebra, and a mapping into it from M
let s : subalgebra R (tensor_algebra R M) :=
{ carrier := C,
mul_mem' := h_mul,
add_mem' := h_add,
algebra_map_mem' := h_grade0, },
let of : M →ₗ[R] s := (ι R).cod_restrict s.to_submodule h_grade1,
-- the mapping through the subalgebra is the identity
have of_id : alg_hom.id R (tensor_algebra R M) = s.val.comp (lift R of),
{ ext,
simp [of], },
-- finding a proof is finding an element of the subalgebra
convert subtype.prop (lift R of a),
exact alg_hom.congr_fun of_id a,
end
/-- The left-inverse of `algebra_map`. -/
def algebra_map_inv : tensor_algebra R M →ₐ[R] R :=
lift R (0 : M →ₗ[R] R)
variables (M)
lemma algebra_map_left_inverse :
function.left_inverse algebra_map_inv (algebra_map R $ tensor_algebra R M) :=
λ x, by simp [algebra_map_inv]
@[simp] lemma algebra_map_inj (x y : R) :
algebra_map R (tensor_algebra R M) x = algebra_map R (tensor_algebra R M) y ↔ x = y :=
(algebra_map_left_inverse M).injective.eq_iff
@[simp] lemma algebra_map_eq_zero_iff (x : R) : algebra_map R (tensor_algebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
@[simp] lemma algebra_map_eq_one_iff (x : R) : algebra_map R (tensor_algebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebra_map _ _) (algebra_map_left_inverse _).injective
variables {M}
/-- The canonical map from `tensor_algebra R M` into `triv_sq_zero_ext R M` that sends
`tensor_algebra.ι` to `triv_sq_zero_ext.inr`. -/
def to_triv_sq_zero_ext : tensor_algebra R M →ₐ[R] triv_sq_zero_ext R M :=
lift R (triv_sq_zero_ext.inr_hom R M)
@[simp] lemma to_triv_sq_zero_ext_ι (x : M) :
to_triv_sq_zero_ext (ι R x) = triv_sq_zero_ext.inr x :=
lift_ι_apply _ _
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable
algebra structure. -/
def ι_inv : tensor_algebra R M →ₗ[R] M :=
(triv_sq_zero_ext.snd_hom R M).comp to_triv_sq_zero_ext.to_linear_map
lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → tensor_algebra R M) :=
λ x, by simp [ι_inv]
variables (R)
@[simp] lemma ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_left_inverse.injective.eq_iff
@[simp] lemma ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 :=
by rw [←ι_inj R x 0, linear_map.map_zero]
variables {R}
@[simp] lemma ι_eq_algebra_map_iff (x : M) (r : R) : ι R x = algebra_map R _ r ↔ x = 0 ∧ r = 0 :=
begin
refine ⟨λ h, _, _⟩,
{ have hf0 : to_triv_sq_zero_ext (ι R x) = (0, x), from lift_ι_apply _ _,
rw [h, alg_hom.commutes] at hf0,
have : r = 0 ∧ 0 = x := prod.ext_iff.1 hf0,
exact this.symm.imp_left eq.symm, },
{ rintro ⟨rfl, rfl⟩,
rw [linear_map.map_zero, ring_hom.map_zero] }
end
@[simp] lemma ι_ne_one [nontrivial R] (x : M) : ι R x ≠ 1 :=
begin
rw [←(algebra_map R (tensor_algebra R M)).map_one, ne.def, ι_eq_algebra_map_iff],
exact one_ne_zero ∘ and.right,
end
/-- The generators of the tensor algebra are disjoint from its scalars. -/
lemma ι_range_disjoint_one : disjoint (ι R).range (1 : submodule R (tensor_algebra R M)) :=
begin
rw submodule.disjoint_def,
rintros _ ⟨x, hx⟩ ⟨r, (rfl : algebra_map _ _ _ = _)⟩,
rw ι_eq_algebra_map_iff x at hx,
rw [hx.2, ring_hom.map_zero]
end
variables (R M)
/-- Construct a product of `n` elements of the module within the tensor algebra.
See also `pi_tensor_product.tprod`. -/
def tprod (n : ℕ) : multilinear_map R (λ i : fin n, M) (tensor_algebra R M) :=
(multilinear_map.mk_pi_algebra_fin R n (tensor_algebra R M)).comp_linear_map $ λ _, ι R
@[simp] lemma tprod_apply {n : ℕ} (x : fin n → M) :
tprod R M n x = (list.of_fn (λ i, ι R (x i))).prod := rfl
variables {R M}
end tensor_algebra
namespace free_algebra
variables {R M}
/-- The canonical image of the `free_algebra` in the `tensor_algebra`, which maps
`free_algebra.ι R x` to `tensor_algebra.ι R x`. -/
def to_tensor : free_algebra R M →ₐ[R] tensor_algebra R M :=
free_algebra.lift R (tensor_algebra.ι R)
@[simp] lemma to_tensor_ι (m : M) : (free_algebra.ι R m).to_tensor = tensor_algebra.ι R m :=
by simp [to_tensor]
end free_algebra
|
802b9ec18d091238bcb6130e7ae4be5a6a9c845a
|
88fb7558b0636ec6b181f2a548ac11ad3919f8a5
|
/tests/lean/run/meta_expr1.lean
|
4e59086b40c6b0274a512b3a450f65fca09d6e9e
|
[
"Apache-2.0"
] |
permissive
|
moritayasuaki/lean
|
9f666c323cb6fa1f31ac597d777914aed41e3b7a
|
ae96ebf6ee953088c235ff7ae0e8c95066ba8001
|
refs/heads/master
| 1,611,135,440,814
| 1,493,852,869,000
| 1,493,852,869,000
| 90,269,903
| 0
| 0
| null | 1,493,906,291,000
| 1,493,906,291,000
| null |
UTF-8
|
Lean
| false
| false
| 1,772
|
lean
|
open unsigned list
meta definition e1 := expr.app (expr.app (expr.const `f []) (expr.mk_var 1)) (expr.const `a [])
meta definition e1' := expr.app (expr.app (expr.const `f []) (expr.mk_var 1)) (expr.const `a [])
meta definition tst : e1 = e1' :=
rfl
#eval e1
#eval expr.fold e1 (0:nat) (λ e d n, n+1)
meta definition l1 := expr.lam `a binder_info.default (expr.sort level.zero) (expr.mk_var 0)
meta definition l2 := expr.lam `b binder_info.default (expr.sort level.zero) (expr.mk_var 0)
meta definition l3 := expr.lam `a binder_info.default (expr.const `nat []) (expr.mk_var 0)
#eval l1
#eval l2
#eval l3
#eval decidable.to_bool (l1 = l2)
#eval decidable.to_bool (l1 =ₐ l2)
#eval expr.lex_lt (expr.const `a []) (expr.const `b [])
#eval expr.lt (expr.const `a []) (expr.const `b [])
meta definition v1 := expr.app (expr.app (expr.const `f []) (expr.mk_var 0)) (expr.mk_var 1)
#eval v1
#eval expr.instantiate_var v1 (expr.const `a [])
#eval expr.instantiate_vars v1 [expr.const `a [], expr.const `b []]
meta definition fv1 :=
expr.app
(expr.app (expr.const `f [])
(expr.local_const `a `a binder_info.default (expr.sort level.zero)))
(expr.local_const `b `b binder_info.default (expr.sort level.zero))
#eval fv1
#eval expr.abstract_local (expr.abstract_local fv1 `a) `b
#eval expr.abstract_locals fv1 [`a, `b]
#eval expr.abstract_locals fv1 [`b, `a]
#eval expr.lift_vars (expr.abstract_locals fv1 [`b, `a]) 1 1
#eval expr.has_local fv1
#eval expr.has_var fv1
#eval expr.has_var (expr.abstract_locals fv1 [`b, `a])
meta definition foo : nat → expr
| 0 := expr.const `aa [level.zero, level.succ level.zero]
| (n+1) := foo n
/-
#eval match foo 10 with
| expr.const n ls := list.head (list.tail ls)
| _ := level.zero
end
-/
|
a1dda8bcc406e8fc1a2c33b193eade1a9640a910
|
31f556cdeb9239ffc2fad8f905e33987ff4feab9
|
/src/Lean/Elab/Notation.lean
|
072628dcfbedba85174b3e63a4afb3fc8b277b64
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
tobiasgrosser/lean4
|
ce0fd9cca0feba1100656679bf41f0bffdbabb71
|
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
|
refs/heads/master
| 1,673,103,412,948
| 1,664,930,501,000
| 1,664,930,501,000
| 186,870,185
| 0
| 0
|
Apache-2.0
| 1,665,129,237,000
| 1,557,939,901,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 7,466
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Syntax
import Lean.Elab.AuxDef
import Lean.Elab.BuiltinNotation
namespace Lean.Elab.Command
open Lean.Syntax
open Lean.Parser.Term hiding macroArg
open Lean.Parser.Command
/-- Wrap all occurrences of the given `ident` nodes in antiquotations -/
private partial def antiquote (vars : Array Syntax) : Syntax → Syntax
| stx => match stx with
| `($id:ident) =>
if (vars.findIdx? (fun var => var.getId == id.getId)).isSome then
mkAntiquotNode id (kind := `term) (isPseudoKind := true)
else
stx
| _ => match stx with
| Syntax.node i k args => Syntax.node i k (args.map (antiquote vars))
| stx => stx
def addInheritDocDefault (rhs : Term) (attrs? : Option (TSepArray ``attrInstance ",")) :
Option (TSepArray ``attrInstance ",") :=
attrs?.map fun attrs =>
match rhs with
| `($f:ident $_args*) | `($f:ident) =>
attrs.getElems.map fun stx => Unhygienic.run do
if let `(attrInstance| $attr:ident) := stx then
if attr.getId.eraseMacroScopes == `inheritDoc then
return ← `(attrInstance| $attr:ident $f:ident)
pure ⟨stx⟩
| _ => attrs
/-- Convert `notation` command lhs item into a `syntax` command item -/
def expandNotationItemIntoSyntaxItem : TSyntax ``notationItem → MacroM (TSyntax `stx)
| `(notationItem| $_:ident$[:$prec?]?) => `(stx| term $[:$prec?]?)
| `(notationItem| $s:str) => `(stx| $s:str)
| _ => Macro.throwUnsupported
/-- Convert `notation` command lhs item into a pattern element -/
def expandNotationItemIntoPattern (stx : Syntax) : MacroM Syntax :=
let k := stx.getKind
if k == `Lean.Parser.Command.identPrec then
return mkAntiquotNode stx[0] (kind := `term) (isPseudoKind := true)
else if k == strLitKind then
strLitToPattern stx
else
Macro.throwUnsupported
def removeParenthesesAux (parens body : Syntax) : Syntax :=
match parens.getHeadInfo, body.getHeadInfo, body.getTailInfo, parens.getTailInfo with
| .original lead _ _ _, .original _ pos trail pos',
.original endLead endPos _ endPos', .original _ _ endTrail _ =>
body.setHeadInfo (.original lead pos trail pos') |>.setTailInfo (.original endLead endPos endTrail endPos')
| _, _, _, _ => body
partial def removeParentheses (stx : Syntax) : MacroM Syntax := do
match stx with
| `(($e)) => pure $ removeParenthesesAux stx (←removeParentheses $ (←Term.expandCDot? e).getD e)
| _ =>
match stx with
| .node info kind args => pure $ .node info kind (←args.mapM removeParentheses)
| _ => pure stx
partial def hasDuplicateAntiquot (stxs : Array Syntax) : Bool := Id.run do
let mut seen := NameSet.empty
for stx in stxs do
for node in Syntax.topDown stx true do
if node.isAntiquot then
let ident := node.getAntiquotTerm.getId
if seen.contains ident then
return true
else
seen := seen.insert ident
pure false
/-- Try to derive a `SimpleDelab` from a notation.
The notation must be of the form `notation ... => c body`
where `c` is a declaration in the current scope and `body` any syntax
that contains each variable from the LHS at most once. -/
def mkSimpleDelab (attrKind : TSyntax ``attrKind) (pat qrhs : Term) : OptionT MacroM Syntax := do
let (c, args) ← match qrhs with
| `($c:ident $args*) => pure (c, args)
| `($c:ident) => pure (c, #[])
| _ => failure
let [(c, [])] ← Macro.resolveGlobalName c.getId | failure
/-
Try to remove all non semantic parenthesis. Since the parenthesizer
runs after appUnexpanders we should not match on parenthesis that the user
syntax inserted here for example the right hand side of:
notation "{" x "|" p "}" => setOf (fun x => p)
Should be matched as: setOf fun x => p
-/
let args ← liftM <| args.mapM removeParentheses
/-
The user could mention the same antiquotation from the lhs multiple
times on the rhs, this heuristic does not support this.
-/
guard !hasDuplicateAntiquot args
-- replace head constant with antiquotation so we're not dependent on the exact pretty printing of the head
-- The reference is attached to the syntactic representation of the called function itself, not the entire function application
let lhs ← `($$f:ident)
let lhs := Syntax.mkApp lhs (.mk args)
`(@[$attrKind appUnexpander $(mkIdent c)]
aux_def unexpand $(mkIdent c) : Lean.PrettyPrinter.Unexpander := fun
| `($lhs) => withRef f `($pat)
-- must be a separate case as the LHS and RHS above might not be `app` nodes
| `($lhs $$moreArgs*) => withRef f `($pat $$moreArgs*)
| _ => throw ())
private def isLocalAttrKind (attrKind : Syntax) : Bool :=
match attrKind with
| `(Parser.Term.attrKind| local) => true
| _ => false
private def expandNotationAux (ref : Syntax) (currNamespace : Name)
(doc? : Option (TSyntax ``docComment))
(attrs? : Option (TSepArray ``attrInstance ","))
(attrKind : TSyntax ``attrKind)
(prec? : Option Prec) (name? : Option Ident) (prio? : Option Prio)
(items : Array (TSyntax ``notationItem)) (rhs : Term) : MacroM Syntax := do
let prio ← evalOptPrio prio?
-- build parser
let syntaxParts ← items.mapM expandNotationItemIntoSyntaxItem
let cat := mkIdentFrom ref `term
let name ←
match name? with
| some name => pure name.getId
| none => mkNameFromParserSyntax `term (mkNullNode syntaxParts)
-- build macro rules
let vars := items.filter fun item => item.raw.getKind == ``identPrec
let vars := vars.map fun var => var.raw[0]
let qrhs := ⟨antiquote vars rhs⟩
let attrs? := addInheritDocDefault rhs attrs?
let patArgs ← items.mapM expandNotationItemIntoPattern
/- The command `syntax [<kind>] ...` adds the current namespace to the syntax node kind.
So, we must include current namespace when we create a pattern for the following `macro_rules` commands. -/
let fullName := currNamespace ++ name
let pat : Term := ⟨mkNode fullName patArgs⟩
let stxDecl ← `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
syntax $[: $prec?]? (name := $(name?.getD (mkIdent name))) (priority := $(quote prio)) $[$syntaxParts]* : $cat)
let macroDecl ← `(macro_rules | `($pat) => ``($qrhs))
let macroDecls ←
if isLocalAttrKind attrKind then
-- Make sure the quotation pre-checker takes section variables into account for local notation.
`(section set_option quotPrecheck.allowSectionVars true $macroDecl end)
else
pure ⟨mkNullNode #[macroDecl]⟩
match (← mkSimpleDelab attrKind pat qrhs |>.run) with
| some delabDecl => return mkNullNode #[stxDecl, macroDecls, delabDecl]
| none => return mkNullNode #[stxDecl, macroDecls]
@[builtinMacro Lean.Parser.Command.notation] def expandNotation : Macro
| stx@`($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
notation $[: $prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $items* => $rhs) => do
-- trigger scoped checks early and only once
let _ ← toAttributeKind attrKind
expandNotationAux stx (← Macro.getCurrNamespace) doc? attrs? attrKind prec? name? prio? items rhs
| _ => Macro.throwUnsupported
end Lean.Elab.Command
|
d659f90e6c955213de86e4b0fb656ea08715a4b1
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/category_theory/natural_isomorphism.lean
|
20414563146b5101bfded5df637e1cdf70c6fc8d
|
[
"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
| 7,372
|
lean
|
/-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.functor_category
import category_theory.isomorphism
/-!
# Natural isomorphisms
For the most part, natural isomorphisms are just another sort of isomorphism.
We provide some special support for extracting components:
* if `α : F ≅ G`, then `a.app X : F.obj X ≅ G.obj X`,
and building natural isomorphisms from components:
*
```
nat_iso.of_components
(app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) :
F ≅ G
```
only needing to check naturality in one direction.
## Implementation
Note that `nat_iso` is a namespace without a corresponding definition;
we put some declarations that are specifically about natural isomorphisms in the `iso`
namespace so that they are available using dot notation.
-/
open category_theory
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace category_theory
open nat_trans
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
namespace iso
/-- The application of a natural isomorphism to an object. We put this definition in a different
namespace, so that we can use `α.app` -/
@[simps] def app {F G : C ⥤ D} (α : F ≅ G) (X : C) : F.obj X ≅ G.obj X :=
{ hom := α.hom.app X,
inv := α.inv.app X,
hom_inv_id' := begin rw [← comp_app, iso.hom_inv_id], refl end,
inv_hom_id' := begin rw [← comp_app, iso.inv_hom_id], refl end }
@[simp, reassoc]
lemma hom_inv_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.hom.app X ≫ α.inv.app X = 𝟙 (F.obj X) :=
congr_fun (congr_arg nat_trans.app α.hom_inv_id) X
@[simp, reassoc]
lemma inv_hom_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.inv.app X ≫ α.hom.app X = 𝟙 (G.obj X) :=
congr_fun (congr_arg nat_trans.app α.inv_hom_id) X
end iso
namespace nat_iso
open category_theory.category category_theory.functor
@[simp] lemma trans_app {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) (X : C) :
(α ≪≫ β).app X = α.app X ≪≫ β.app X := rfl
lemma app_hom {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).hom = α.hom.app X := rfl
lemma app_inv {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).inv = α.inv.app X := rfl
variables {F G : C ⥤ D}
instance hom_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.hom.app X) :=
⟨⟨α.inv.app X,
⟨by rw [←comp_app, iso.hom_inv_id, ←id_app], by rw [←comp_app, iso.inv_hom_id, ←id_app]⟩⟩⟩
instance inv_app_is_iso (α : F ≅ G) (X : C) : is_iso (α.inv.app X) :=
⟨⟨α.hom.app X,
⟨by rw [←comp_app, iso.inv_hom_id, ←id_app], by rw [←comp_app, iso.hom_inv_id, ←id_app]⟩⟩⟩
section
/-!
Unfortunately we need a separate set of cancellation lemmas for components of natural isomorphisms,
because the `simp` normal form is `α.hom.app X`, rather than `α.app.hom X`.
(With the later, the morphism would be visibly part of an isomorphism, so general lemmas about
isomorphisms would apply.)
In the future, we should consider a redesign that changes this simp norm form,
but for now it breaks too many proofs.
-/
variables (α : F ≅ G)
@[simp] lemma cancel_nat_iso_hom_left {X : C} {Z : D} (g g' : G.obj X ⟶ Z) :
α.hom.app X ≫ g = α.hom.app X ≫ g' ↔ g = g' :=
by simp only [cancel_epi]
@[simp] lemma cancel_nat_iso_inv_left {X : C} {Z : D} (g g' : F.obj X ⟶ Z) :
α.inv.app X ≫ g = α.inv.app X ≫ g' ↔ g = g' :=
by simp only [cancel_epi]
@[simp] lemma cancel_nat_iso_hom_right {X : D} {Y : C} (f f' : X ⟶ F.obj Y) :
f ≫ α.hom.app Y = f' ≫ α.hom.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_nat_iso_inv_right {X : D} {Y : C} (f f' : X ⟶ G.obj Y) :
f ≫ α.inv.app Y = f' ≫ α.inv.app Y ↔ f = f' :=
by simp only [cancel_mono]
@[simp] lemma cancel_nat_iso_hom_right_assoc {W X X' : D} {Y : C}
(f : W ⟶ X) (g : X ⟶ F.obj Y) (f' : W ⟶ X') (g' : X' ⟶ F.obj Y) :
f ≫ g ≫ α.hom.app Y = f' ≫ g' ≫ α.hom.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
@[simp] lemma cancel_nat_iso_inv_right_assoc {W X X' : D} {Y : C}
(f : W ⟶ X) (g : X ⟶ G.obj Y) (f' : W ⟶ X') (g' : X' ⟶ G.obj Y) :
f ≫ g ≫ α.inv.app Y = f' ≫ g' ≫ α.inv.app Y ↔ f ≫ g = f' ≫ g' :=
by simp only [←category.assoc, cancel_mono]
end
variables {X Y : C}
lemma naturality_1 (α : F ≅ G) (f : X ⟶ Y) :
(α.inv.app X) ≫ (F.map f) ≫ (α.hom.app Y) = G.map f :=
by rw [naturality, ←category.assoc, ←nat_trans.comp_app, α.inv_hom_id, id_app, category.id_comp]
lemma naturality_2 (α : F ≅ G) (f : X ⟶ Y) :
(α.hom.app X) ≫ (G.map f) ≫ (α.inv.app Y) = F.map f :=
by rw [naturality, ←category.assoc, ←nat_trans.comp_app, α.hom_inv_id, id_app, category.id_comp]
/--
The components of a natural isomorphism are isomorphisms.
-/
instance is_iso_app_of_is_iso (α : F ⟶ G) [is_iso α] (X) : is_iso (α.app X) :=
⟨⟨(inv α).app X,
⟨congr_fun (congr_arg nat_trans.app (is_iso.hom_inv_id α)) X,
congr_fun (congr_arg nat_trans.app (is_iso.inv_hom_id α)) X⟩⟩⟩
@[simp] lemma is_iso_inv_app (α : F ⟶ G) [is_iso α] (X) : (inv α).app X = inv (α.app X) :=
by { ext, rw ←nat_trans.comp_app, simp, }
/--
Construct a natural isomorphism between functors by giving object level isomorphisms,
and checking naturality only in the forward direction.
-/
def of_components (app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) :
F ≅ G :=
{ hom := { app := λ X, (app X).hom },
inv :=
{ app := λ X, (app X).inv,
naturality' := λ X Y f,
begin
have h := congr_arg (λ f, (app X).inv ≫ (f ≫ (app Y).inv)) (naturality f).symm,
simp only [iso.inv_hom_id_assoc, iso.hom_inv_id, assoc, comp_id, cancel_mono] at h,
exact h
end }, }
@[simp] lemma of_components.app (app' : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) :
(of_components app' naturality).app X = app' X :=
by tidy
@[simp] lemma of_components.hom_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) :
(of_components app naturality).hom.app X = (app X).hom := rfl
@[simp] lemma of_components.inv_app (app : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) :
(of_components app naturality).inv.app X = (app X).inv :=
by simp [of_components]
/--
A natural transformation is an isomorphism if all its components are isomorphisms.
-/
-- Making this an instance would cause a typeclass inference loop with `is_iso_app_of_is_iso`.
lemma is_iso_of_is_iso_app (α : F ⟶ G) [∀ X : C, is_iso (α.app X)] : is_iso α :=
⟨(is_iso.of_iso (of_components (λ X, as_iso (α.app X)) (by tidy))).1⟩
/-- Horizontal composition of natural isomorphisms. -/
def hcomp {F G : C ⥤ D} {H I : D ⥤ E} (α : F ≅ G) (β : H ≅ I) : F ⋙ H ≅ G ⋙ I :=
begin
refine ⟨α.hom ◫ β.hom, α.inv ◫ β.inv, _, _⟩,
{ ext, rw [←nat_trans.exchange], simp, refl },
ext, rw [←nat_trans.exchange], simp, refl
end
end nat_iso
end category_theory
|
4a5b8fda05f58f91810c9fd55e6741801bac975a
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/Lean3Lib/init/data/ordering/basic_auto.lean
|
abe38c5ebbf483e2850c2a4809f0a6488a4b15e7
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,268
|
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
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.repr
import Mathlib.Lean3Lib.init.data.prod
import Mathlib.Lean3Lib.init.data.sum.basic
universes l u
namespace Mathlib
inductive ordering where
| lt : ordering
| eq : ordering
| gt : ordering
protected instance ordering.has_repr : has_repr ordering := has_repr.mk fun (s : ordering) => sorry
namespace ordering
def swap : ordering → ordering := sorry
def or_else : ordering → ordering → ordering := sorry
theorem swap_swap (o : ordering) : swap (swap o) = o :=
ordering.cases_on o (idRhs (swap (swap lt) = swap (swap lt)) rfl)
(idRhs (swap (swap eq) = swap (swap eq)) rfl) (idRhs (swap (swap gt) = swap (swap gt)) rfl)
end ordering
def cmp_using {α : Type u} (lt : α → α → Prop) [DecidableRel lt] (a : α) (b : α) : ordering :=
ite (lt a b) ordering.lt (ite (lt b a) ordering.gt ordering.eq)
def cmp {α : Type u} [HasLess α] [DecidableRel Less] (a : α) (b : α) : ordering :=
cmp_using Less a b
protected instance ordering.decidable_eq : DecidableEq ordering := fun (a b : ordering) => sorry
end Mathlib
|
161cd1dec019ac71c936d09dba03dd2f3dee4d89
|
31f556cdeb9239ffc2fad8f905e33987ff4feab9
|
/stage0/src/Lean/Compiler/LCNF/Bind.lean
|
06a4b7ecf540bb7d573dc50539d213f9fa4374f9
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
tobiasgrosser/lean4
|
ce0fd9cca0feba1100656679bf41f0bffdbabb71
|
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
|
refs/heads/master
| 1,673,103,412,948
| 1,664,930,501,000
| 1,664,930,501,000
| 186,870,185
| 0
| 0
|
Apache-2.0
| 1,665,129,237,000
| 1,557,939,901,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,981
|
lean
|
/-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.LCNF.InferType
namespace Lean.Compiler.LCNF
/-- Helper class for lifting `CompilerM.codeBind` -/
class MonadCodeBind (m : Type → Type) where
codeBind : (c : Code) → (f : FVarId → m Code) → m Code
/--
Return code that is equivalent to `c >>= f`. That is, executes `c`, and then `f x`, where
`x` is a variable that contains the result of `c`'s computation.
If `c` contains a jump to a join point `jp_i` not declared in `c`, we throw an exception because
an invalid block would be generated. It would be invalid because `f` would not
be applied to `jp_i`. Note that, we could have decided to create a copy of `jp_i` where we apply `f` to it,
by we decided to not do it to avoid code duplication.
-/
abbrev Code.bind [MonadCodeBind m] (c : Code) (f : FVarId → m Code) : m Code :=
MonadCodeBind.codeBind c f
partial def CompilerM.codeBind (c : Code) (f : FVarId → CompilerM Code) : CompilerM Code := do
go c |>.run {}
where
go (c : Code) : ReaderT FVarIdSet CompilerM Code := do
match c with
| .let decl k => return .let decl (← go k)
| .fun decl k => return .fun decl (← go k)
| .jp decl k =>
let value ← go decl.value
let type ← value.inferParamType decl.params
let decl ← decl.update' type value
withReader (fun s => s.insert decl.fvarId) do
return .jp decl (← go k)
| .cases c =>
let alts ← c.alts.mapM fun
| .alt ctorName params k => return .alt ctorName params (← go k)
| .default k => return .default (← go k)
if alts.isEmpty then
throwError "`Code.bind` failed, empty `cases` found"
let resultType ← mkCasesResultType alts
return .cases { c with alts, resultType }
| .return fvarId => f fvarId
| .jmp fvarId .. =>
unless (← read).contains fvarId do
throwError "`Code.bind` failed, it contains a out of scope join point"
return c
| .unreach type =>
/-
Create an auxiliary parameter `aux : type` to compute the resulting type of `f aux`.
This code is not very efficient, we could ask caller to provide the type of `c >>= f`,
but this is more convenient, and this case is seldom reached.
-/
let auxParam ← mkAuxParam type
let k ← f auxParam.fvarId
let typeNew ← k.inferType
eraseCode k
eraseParam auxParam
return .unreach typeNew
instance : MonadCodeBind CompilerM where
codeBind := CompilerM.codeBind
instance [MonadCodeBind m] : MonadCodeBind (ReaderT ρ m) where
codeBind c f ctx := c.bind fun fvarId => f fvarId ctx
instance [STWorld ω m] [MonadCodeBind m] : MonadCodeBind (StateRefT' ω σ m) where
codeBind c f sref := c.bind fun fvarId => f fvarId sref
/--
Create new parameters for the given arrow type.
Example: if `type` is `Nat → Bool → Int`, the result is
an array containing two new parameters with types `Nat` and `Bool`.
-/
partial def mkNewParams (type : Expr) : CompilerM (Array Param) :=
go type #[] #[]
where
go (type : Expr) (xs : Array Expr) (ps : Array Param) : CompilerM (Array Param) := do
match type with
| .forallE _ d b _ =>
let d := d.instantiateRev xs
let p ← mkAuxParam d
go b (xs.push (.fvar p.fvarId)) (ps.push p)
| _ =>
let type := type.instantiateRev xs
let type' := type.headBeta
if type' != type then
go type' #[] ps
else
return ps
def isEtaExpandCandidateCore (type : Expr) (params : Array Param) : Bool :=
let typeArity := getArrowArity type
let valueArity := params.size
typeArity > valueArity
abbrev FunDeclCore.isEtaExpandCandidate (decl : FunDecl) : Bool :=
isEtaExpandCandidateCore decl.type decl.params
def etaExpandCore (type : Expr) (params : Array Param) (value : Code) : CompilerM (Array Param × Code) := do
let valueType ← instantiateForall type params
let psNew ← mkNewParams valueType
let params := params ++ psNew
let xs := psNew.map fun p => Expr.fvar p.fvarId
let value ← value.bind fun fvarId => do
let auxDecl ← mkAuxLetDecl (mkAppN (.fvar fvarId) xs)
return .let auxDecl (.return auxDecl.fvarId)
return (params, value)
def etaExpandCore? (type : Expr) (params : Array Param) (value : Code) : CompilerM (Option (Array Param × Code)) := do
if isEtaExpandCandidateCore type params then
etaExpandCore type params value
else
return none
def FunDeclCore.etaExpand (decl : FunDecl) : CompilerM FunDecl := do
let some (params, value) ← etaExpandCore? decl.type decl.params decl.value | return decl
decl.update decl.type params value
def Decl.etaExpand (decl : Decl) : CompilerM Decl := do
let some (params, value) ← etaExpandCore? decl.type decl.params decl.value | return decl
return { decl with params, value }
end Lean.Compiler.LCNF
|
b67aa4c1676e911ab329404d93d243fb99665e91
|
35677d2df3f081738fa6b08138e03ee36bc33cad
|
/src/measure_theory/l1_space.lean
|
9e563aa543fe8dbfdbcbb837dc73371d01a28028
|
[
"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
| 28,744
|
lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.ae_eq_fun
/-!
# Integrable functions and `L¹` space
In the first part of this file, the predicate `integrable` is defined and basic properties of
integrable functions are proved.
In the second part, the space `L¹` of equivalence classes of integrable functions under the relation
of being almost everywhere equal is defined as a subspace of the space `L⁰`. See the file
`src/measure_theory/ae_eq_fun.lean` for information on `L⁰` space.
## Notation
* `α →₁ β` is the type of `L¹` space, where `α` is a `measure_space` and `β` is a `normed_group` with
a `second_countable_topology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is also used
to denote an `L¹` function.
`₁` can be typed as `\1`.
## Main definitions
* Let `f : α → β` be a function, where `α` is a `measure_space` and `β` a `normed_group`.
Then `f` is called `integrable` if `(∫⁻ a, nnnorm (f a)) < ⊤` holds.
* The space `L¹` is defined as a subspace of `L⁰` :
An `ae_eq_fun` `[f] : α →ₘ β` is in the space `L¹` if `edist [f] 0 < ⊤`, which means
`(∫⁻ a, edist (f a) 0) < ⊤` if we expand the definition of `edist` in `L⁰`.
## Main statements
`L¹`, as a subspace, inherits most of the structures of `L⁰`.
## Implementation notes
Maybe `integrable f` should be mean `(∫⁻ a, edist (f a) 0) < ⊤`, so that `integrable` and
`ae_eq_fun.integrable` are more aligned. But in the end one can use the lemma
`lintegral_nnnorm_eq_lintegral_edist : (∫⁻ a, nnnorm (f a)) = (∫⁻ a, edist (f a) 0)` to switch the
two forms.
## Tags
integrable, function space, l1
-/
noncomputable theory
open_locale classical topological_space
set_option class.instance_max_depth 100
namespace measure_theory
open set filter topological_space ennreal emetric
universes u v w
variables {α : Type u} [measure_space α]
variables {β : Type v} [normed_group β] {γ : Type w} [normed_group γ]
/-- A function is `integrable` if the integral of its pointwise norm is less than infinity. -/
def integrable (f : α → β) : Prop := (∫⁻ a, nnnorm (f a)) < ⊤
lemma integrable_iff_norm (f : α → β) : integrable f ↔ (∫⁻ a, ennreal.of_real ∥f a∥) < ⊤ :=
by simp only [integrable, of_real_norm_eq_coe_nnnorm]
lemma integrable_iff_edist (f : α → β) : integrable f ↔ (∫⁻ a, edist (f a) 0) < ⊤ :=
have eq : (λa, edist (f a) 0) = (λa, (nnnorm(f a) : ennreal)),
by { funext, rw edist_eq_coe_nnnorm },
iff.intro (by { rw eq, exact λh, h }) $ by { rw eq, exact λh, h }
lemma integrable_iff_of_real {f : α → ℝ} (h : ∀ₘ a, 0 ≤ f a) :
integrable f ↔ (∫⁻ a, ennreal.of_real (f a)) < ⊤ :=
have lintegral_eq : (∫⁻ a, ennreal.of_real ∥f a∥) = (∫⁻ a, ennreal.of_real (f a)) :=
begin
apply lintegral_congr_ae,
filter_upwards [h],
simp only [mem_set_of_eq],
assume a h,
rw [real.norm_eq_abs, abs_of_nonneg],
exact h
end,
by rw [integrable_iff_norm, lintegral_eq]
lemma integrable_of_ae_eq {f g : α → β} (hf : integrable f) (h : ∀ₘ a, f a = g a) : integrable g :=
begin
simp only [integrable] at *,
have : (∫⁻ (a : α), ↑(nnnorm (f a))) = (∫⁻ (a : α), ↑(nnnorm (g a))),
{ apply lintegral_congr_ae,
filter_upwards [h],
assume a,
simp only [mem_set_of_eq],
assume h,
rw h },
rwa ← this
end
lemma integrable_congr_ae {f g : α → β} (h : ∀ₘ a, f a = g a) : integrable f ↔ integrable g :=
iff.intro (λhf, integrable_of_ae_eq hf h) (λhg, integrable_of_ae_eq hg (all_ae_eq_symm h))
lemma integrable_of_le_ae {f : α → β} {g : α → γ} (h : ∀ₘ a, ∥f a∥ ≤ ∥g a∥) (hg : integrable g) :
integrable f :=
begin
simp only [integrable_iff_norm] at *,
calc (∫⁻ a, ennreal.of_real ∥f a∥) ≤ (∫⁻ (a : α), ennreal.of_real ∥g a∥) :
lintegral_le_lintegral_ae (by { filter_upwards [h], assume a h, exact of_real_le_of_real h })
... < ⊤ : hg
end
lemma integrable_of_le {f : α → β} {g : α → γ} (h : ∀a, ∥f a∥ ≤ ∥g a∥) (hg : integrable g) :
integrable f :=
integrable_of_le_ae (all_ae_of_all h) hg
lemma lintegral_nnnorm_eq_lintegral_edist (f : α → β) :
(∫⁻ a, nnnorm (f a)) = ∫⁻ a, edist (f a) 0 :=
by simp only [edist_eq_coe_nnnorm]
lemma lintegral_norm_eq_lintegral_edist (f : α → β) :
(∫⁻ a, ennreal.of_real ∥f a∥) = ∫⁻ a, edist (f a) 0 :=
by simp only [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm]
lemma lintegral_edist_triangle [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g h : α → β}
(hf : measurable f) (hg : measurable g) (hh : measurable h) :
(∫⁻ a, edist (f a) (g a)) ≤ (∫⁻ a, edist (f a) (h a)) + ∫⁻ a, edist (g a) (h a) :=
begin
rw ← lintegral_add (hf.edist hh) (hg.edist hh),
apply lintegral_mono,
assume a,
have := edist_triangle (f a) (h a) (g a),
convert this,
rw edist_comm (h a) (g a),
end
lemma lintegral_edist_lt_top [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g : α → β}
(hfm : measurable f) (hfi : integrable f) (hgm : measurable g) (hgi : integrable g) :
(∫⁻ a, edist (f a) (g a)) < ⊤ :=
lt_of_le_of_lt
(lintegral_edist_triangle hfm hgm (measurable_const : measurable (λa, (0 : β))))
(ennreal.add_lt_top.2 $ by { split; rw ← integrable_iff_edist; assumption })
lemma lintegral_nnnorm_zero : (∫⁻ a : α, nnnorm (0 : β)) = 0 := by simp
variables (α β)
@[simp] lemma integrable_zero : integrable (λa:α, (0:β)) :=
by simp [integrable]
variables {α β}
lemma lintegral_nnnorm_add [measurable_space β] [opens_measurable_space β]
[measurable_space γ] [opens_measurable_space γ]
{f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) :
(∫⁻ a, nnnorm (f a) + nnnorm (g a)) = (∫⁻ a, nnnorm (f a)) + ∫⁻ a, nnnorm (g a) :=
lintegral_add hf.ennnorm hg.ennnorm
lemma integrable.add [measurable_space β] [opens_measurable_space β]
{f g : α → β} (hfm : measurable f) (hfi : integrable f)
(hgm : measurable g) (hgi : integrable g) :
integrable (λa, f a + g a) :=
calc
(∫⁻ (a : α), ↑(nnnorm ((f + g) a))) ≤ ∫⁻ (a : α), ↑(nnnorm (f a)) + ↑(nnnorm (g a)) :
lintegral_mono
(assume a, by { simp only [← coe_add, coe_le_coe], exact nnnorm_add_le _ _ })
... = _ :
lintegral_nnnorm_add hfm hgm
... < ⊤ : add_lt_top.2 ⟨hfi, hgi⟩
lemma integrable_finset_sum {ι} [measurable_space β] [borel_space β]
[second_countable_topology β] (s : finset ι) {f : ι → α → β}
(hfm : ∀ i, measurable (f i)) (hfi : ∀ i, integrable (f i)) :
integrable (λ a, s.sum (λ i, f i a)) :=
begin
refine finset.induction_on s _ _,
{ simp only [finset.sum_empty, integrable_zero] },
{ assume i s his ih,
simp only [his, finset.sum_insert, not_false_iff],
refine (hfi _).add (hfm _) (s.measurable_sum hfm) ih }
end
lemma lintegral_nnnorm_neg {f : α → β} :
(∫⁻ (a : α), ↑(nnnorm ((-f) a))) = ∫⁻ (a : α), ↑(nnnorm ((f) a)) :=
by simp only [pi.neg_apply, nnnorm_neg]
lemma integrable.neg {f : α → β} : integrable f → integrable (λa, -f a) :=
assume hfi, calc _ = _ : lintegral_nnnorm_neg
... < ⊤ : hfi
@[simp] lemma integrable_neg_iff (f : α → β) : integrable (λa, -f a) ↔ integrable f :=
begin
split,
{ assume h,
simpa only [_root_.neg_neg] using h.neg },
exact integrable.neg
end
lemma integrable.sub [measurable_space β] [opens_measurable_space β]
{f g : α → β} (hfm : measurable f) (hfi : integrable f) (hgm : measurable g)
(hgi : integrable g) : integrable (λa, f a - g a) :=
calc
(∫⁻ (a : α), ↑(nnnorm ((f - g) a))) ≤ ∫⁻ (a : α), ↑(nnnorm (f a)) + ↑(nnnorm (-g a)) :
lintegral_mono
(assume a, by { simp only [← coe_add, coe_le_coe], exact nnnorm_add_le _ _ })
... = _ :
by { simp only [nnnorm_neg], exact lintegral_nnnorm_add hfm hgm }
... < ⊤ : add_lt_top.2 ⟨hfi, hgi⟩
lemma integrable.norm {f : α → β} (hfi : integrable f) : integrable (λa, ∥f a∥) :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rwa [integrable, eq] }
lemma integrable_norm_iff (f : α → β) : integrable (λa, ∥f a∥) ↔ integrable f :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rw [integrable, integrable, eq] }
lemma integrable_of_integrable_bound {f : α → β} {bound : α → ℝ} (h : integrable bound)
(h_bound : ∀ₘ a, ∥f a∥ ≤ bound a) : integrable f :=
have h₁ : ∀ₘ a, (nnnorm (f a) : ennreal) ≤ ennreal.of_real (bound a),
begin
filter_upwards [h_bound],
simp only [mem_set_of_eq],
assume a h,
calc (nnnorm (f a) : ennreal) = ennreal.of_real (∥f a∥) : by rw of_real_norm_eq_coe_nnnorm
... ≤ ennreal.of_real (bound a) : ennreal.of_real_le_of_real h
end,
calc (∫⁻ a, nnnorm (f a)) ≤ (∫⁻ a, ennreal.of_real (bound a)) :
by { apply lintegral_le_lintegral_ae, exact h₁ }
... ≤ (∫⁻ a, ennreal.of_real ∥bound a∥) : lintegral_mono $
by { assume a, apply ennreal.of_real_le_of_real, exact le_max_left (bound a) (-bound a) }
... < ⊤ : by { rwa [integrable_iff_norm] at h }
section dominated_convergence
variables {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
lemma all_ae_of_real_F_le_bound (h : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a) :
∀ n, ∀ₘ a, ennreal.of_real ∥F n a∥ ≤ ennreal.of_real (bound a) :=
λn, by filter_upwards [h n] λ a h, ennreal.of_real_le_of_real h
lemma all_ae_tendsto_of_real_norm (h : ∀ₘ a, tendsto (λ n, F n a) at_top $ 𝓝 $ f a) :
∀ₘ a, tendsto (λn, ennreal.of_real ∥F n a∥) at_top $ 𝓝 $ ennreal.of_real ∥f a∥ :=
by filter_upwards [h]
λ a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h
lemma all_ae_of_real_f_le_bound (h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
∀ₘ a, ennreal.of_real ∥f a∥ ≤ ennreal.of_real (bound a) :=
begin
have F_le_bound := all_ae_of_real_F_le_bound h_bound,
rw ← all_ae_all_iff at F_le_bound,
apply F_le_bound.mp ((all_ae_tendsto_of_real_norm h_lim).mono _),
assume a tendsto_norm F_le_bound,
exact le_of_tendsto' at_top_ne_bot tendsto_norm (F_le_bound)
end
lemma integrable_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(bound_integrable : integrable bound)
(h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
integrable f :=
/- `∥F n a∥ ≤ bound a` and `∥F n a∥ --> ∥f a∥` implies `∥f a∥ ≤ bound a`,
and so `∫ ∥f∥ ≤ ∫ bound < ⊤` since `bound` is integrable -/
begin
rw integrable_iff_norm,
calc (∫⁻ a, (ennreal.of_real ∥f a∥)) ≤ ∫⁻ a, ennreal.of_real (bound a) :
lintegral_le_lintegral_ae $ all_ae_of_real_f_le_bound h_bound h_lim
... < ⊤ :
begin
rw ← integrable_iff_of_real,
{ exact bound_integrable },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h,
end
end
lemma tendsto_lintegral_norm_of_dominated_convergence [measurable_space β]
[borel_space β] [second_countable_topology β]
{F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(F_measurable : ∀ n, measurable (F n))
(f_measurable : measurable f)
(bound_integrable : integrable bound)
(h_bound : ∀ n, ∀ₘ a, ∥F n a∥ ≤ bound a)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫⁻ a, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0) :=
let b := λa, 2 * ennreal.of_real (bound a) in
/- `∥F n a∥ ≤ bound a` and `F n a --> f a` implies `∥f a∥ ≤ bound a`, and thus by the
triangle inequality, have `∥F n a - f a∥ ≤ 2 * (bound a). -/
have hb : ∀ n, ∀ₘ a, ennreal.of_real ∥F n a - f a∥ ≤ b a,
begin
assume n,
filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],
assume a h₁ h₂,
calc ennreal.of_real ∥F n a - f a∥ ≤ (ennreal.of_real ∥F n a∥) + (ennreal.of_real ∥f a∥) :
begin
rw [← ennreal.of_real_add],
apply of_real_le_of_real,
{ apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }
end
... ≤ (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add' h₁ h₂
... = b a : by rw ← two_mul
end,
/- On the other hand, `F n a --> f a` implies that `∥F n a - f a∥ --> 0` -/
have h : ∀ₘ a, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0),
begin
suffices h : ∀ₘ a, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 $ ennreal.of_real 0),
{ rwa ennreal.of_real_zero at h },
filter_upwards [h_lim],
assume a h,
refine tendsto.comp (continuous.tendsto continuous_of_real _) _,
rw ← tendsto_iff_norm_tendsto_zero,
exact h
end,
/- Therefore, by the dominated convergence theorem for nonnegative integration, have
` ∫ ∥f a - F n a∥ --> 0 ` -/
begin
suffices h : tendsto (λn, ∫⁻ a, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 (∫⁻ (a:α), 0)),
{ rwa lintegral_zero at h },
-- Using the dominated convergence theorem.
refine tendsto_lintegral_of_dominated_convergence _ _ hb _ _,
-- Show `λa, ∥f a - F n a∥` is measurable for all `n`
{ exact λn, measurable_of_real.comp ((F_measurable n).sub f_measurable).norm },
-- Show `2 * bound` is integrable
{ rw integrable_iff_of_real at bound_integrable,
{ calc (∫⁻ a, b a) = 2 * (∫⁻ a, ennreal.of_real (bound a)) :
by { rw lintegral_const_mul', exact coe_ne_top }
... < ⊤ : mul_lt_top (coe_lt_top) bound_integrable },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h },
-- Show `∥f a - F n a∥ --> 0`
{ exact h }
end
end dominated_convergence
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma integrable.max_zero {f : α → ℝ} (hf : integrable f) : integrable (λa, max (f a) 0) :=
begin
simp only [integrable_iff_norm] at *,
calc (∫⁻ a, ennreal.of_real ∥max (f a) 0∥) ≤ (∫⁻ (a : α), ennreal.of_real ∥f a∥) :
lintegral_mono
begin
assume a,
apply of_real_le_of_real,
simp only [real.norm_eq_abs],
calc abs (max (f a) 0) = max (f a) 0 : by { rw abs_of_nonneg, apply le_max_right }
... ≤ abs (f a) : max_le (le_abs_self _) (abs_nonneg _)
end
... < ⊤ : hf
end
lemma integrable.min_zero {f : α → ℝ} (hf : integrable f) : integrable (λa, min (f a) 0) :=
begin
have : (λa, min (f a) 0) = (λa, - max (-f a) 0),
{ funext, rw [min_eq_neg_max_neg_neg, neg_zero] },
rw this,
exact (integrable.max_zero hf.neg).neg,
end
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul (c : 𝕜) {f : α → β} : integrable f → integrable (λa, c • f a) :=
begin
simp only [integrable], assume hfi,
calc
(∫⁻ (a : α), nnnorm ((c • f) a)) = (∫⁻ (a : α), (nnnorm c) * nnnorm (f a)) :
begin
apply lintegral_congr_ae,
filter_upwards [],
assume a,
simp only [nnnorm_smul, set.mem_set_of_eq, pi.smul_apply, ennreal.coe_mul]
end
... < ⊤ :
begin
rw lintegral_const_mul',
apply mul_lt_top,
{ exact coe_lt_top },
{ exact hfi },
{ simp only [ennreal.coe_ne_top, ne.def, not_false_iff] }
end
end
lemma integrable_smul_iff {c : 𝕜} (hc : c ≠ 0) (f : α → β) : integrable (λa, c • f a) ↔ integrable f :=
begin
split,
{ assume h,
simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c⁻¹ },
exact integrable.smul _
end
end normed_space
variables [second_countable_topology β]
namespace ae_eq_fun
variable [measurable_space β]
section
variable [opens_measurable_space β]
/-- An almost everywhere equal function is `integrable` if it has a finite distance to the origin.
Should mean the same thing as the predicate `integrable` over functions. -/
def integrable (f : α →ₘ β) : Prop := f ∈ ball (0 : α →ₘ β) ⊤
lemma integrable_mk {f : α → β} (hf : measurable f) :
(integrable (mk f hf)) ↔ measure_theory.integrable f :=
by simp [integrable, zero_def, edist_mk_mk', measure_theory.integrable, nndist_eq_nnnorm]
lemma integrable_to_fun (f : α →ₘ β) : integrable f ↔ (measure_theory.integrable f.to_fun) :=
by conv_lhs { rw [self_eq_mk f, integrable_mk] }
local attribute [simp] integrable_mk
lemma integrable_zero : integrable (0 : α →ₘ β) := mem_ball_self coe_lt_top
end
section
variable [borel_space β]
lemma integrable.add :
∀ {f g : α →ₘ β}, integrable f → integrable g → integrable (f + g) :=
begin
rintros ⟨f, hf⟩ ⟨g, hg⟩,
simp only [mem_ball, zero_def, mk_add_mk, integrable_mk, quot_mk_eq_mk],
assume hfi hgi,
exact hfi.add hf hg hgi
end
lemma integrable.neg : ∀ {f : α →ₘ β}, integrable f → integrable (-f) :=
begin
rintros ⟨f, hfm⟩ hfi,
exact (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg
end
lemma integrable.sub :
∀ {f g : α →ₘ β}, integrable f → integrable g → integrable (f - g) :=
begin
rintros ⟨f, hfm⟩ ⟨g, hgm⟩,
simp only [quot_mk_eq_mk, integrable_mk, mk_sub_mk],
exact λ hfi hgi, hfi.sub hfm hgm hgi
end
protected lemma is_add_subgroup : is_add_subgroup (ball (0 : α →ₘ β) ⊤) :=
{ zero_mem := integrable_zero,
add_mem := λ _ _, integrable.add,
neg_mem := λ _, integrable.neg }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul : ∀ {c : 𝕜} {f : α →ₘ β}, integrable f → integrable (c • f) :=
begin
rintros c ⟨f, hfm⟩,
simp only [quot_mk_eq_mk, integrable_mk, smul_mk],
exact λ hfi, hfi.smul c
end
end normed_space
end
end ae_eq_fun
section
variables (α β) [measurable_space β] [opens_measurable_space β]
/-- The space of equivalence classes of integrable (and measurable) functions, where two integrable
functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure
`0`. -/
def l1 : Type (max u v) := subtype (@ae_eq_fun.integrable α _ β _ _ _ _)
infixr ` →₁ `:25 := l1
end
namespace l1
open ae_eq_fun
local attribute [instance] ae_eq_fun.is_add_subgroup
variables [measurable_space β]
section
variable [opens_measurable_space β]
instance : has_coe (α →₁ β) (α →ₘ β) := ⟨subtype.val⟩
protected lemma eq {f g : α →₁ β} : (f : α →ₘ β) = (g : α →ₘ β) → f = g := subtype.eq
@[elim_cast] protected lemma eq_iff {f g : α →₁ β} : (f : α →ₘ β) = (g : α →ₘ β) ↔ f = g :=
iff.intro (l1.eq) (congr_arg coe)
/- TODO : order structure of l1-/
/-- `L¹` space forms a `emetric_space`, with the emetric being inherited from almost everywhere
functions, i.e., `edist f g = ∫⁻ a, edist (f a) (g a)`. -/
instance : emetric_space (α →₁ β) := subtype.emetric_space
/-- `L¹` space forms a `metric_space`, with the metric being inherited from almost everywhere
functions, i.e., `edist f g = ennreal.to_real (∫⁻ a, edist (f a) (g a))`. -/
instance : metric_space (α →₁ β) := metric_space_emetric_ball 0 ⊤
end
variable [borel_space β]
instance : add_comm_group (α →₁ β) := subtype.add_comm_group
instance : inhabited (α →₁ β) := ⟨0⟩
@[simp, elim_cast] lemma coe_zero : ((0 : α →₁ β) : α →ₘ β) = 0 := rfl
@[simp, move_cast] lemma coe_add (f g : α →₁ β) : ((f + g : α →₁ β) : α →ₘ β) = f + g := rfl
@[simp, move_cast] lemma coe_neg (f : α →₁ β) : ((-f : α →₁ β) : α →ₘ β) = -f := rfl
@[simp, move_cast] lemma coe_sub (f g : α →₁ β) : ((f - g : α →₁ β) : α →ₘ β) = f - g := rfl
@[simp] lemma edist_eq (f g : α →₁ β) : edist f g = edist (f : α →ₘ β) (g : α →ₘ β) := rfl
lemma dist_eq (f g : α →₁ β) : dist f g = ennreal.to_real (edist (f : α →ₘ β) (g : α →ₘ β)) := rfl
/-- The norm on `L¹` space is defined to be `∥f∥ = ∫⁻ a, edist (f a) 0`. -/
instance : has_norm (α →₁ β) := ⟨λ f, dist f 0⟩
lemma norm_eq (f : α →₁ β) : ∥f∥ = ennreal.to_real (edist (f : α →ₘ β) 0) := rfl
instance : normed_group (α →₁ β) := normed_group.of_add_dist (λ x, rfl) $ by
{ intros, simp only [dist_eq, coe_add], rw edist_eq_add_add }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
instance : has_scalar 𝕜 (α →₁ β) := ⟨λ x f, ⟨x • (f : α →ₘ β), ae_eq_fun.integrable.smul f.2⟩⟩
@[simp, move_cast] lemma coe_smul (c : 𝕜) (f : α →₁ β) :
((c • f : α →₁ β) : α →ₘ β) = c • (f : α →ₘ β) := rfl
instance : semimodule 𝕜 (α →₁ β) :=
{ one_smul := λf, l1.eq (by { simp only [coe_smul], exact one_smul _ _ }),
mul_smul := λx y f, l1.eq (by { simp only [coe_smul], exact mul_smul _ _ _ }),
smul_add := λx f g, l1.eq (by { simp only [coe_smul, coe_add], exact smul_add _ _ _ }),
smul_zero := λx, l1.eq (by { simp only [coe_zero, coe_smul], exact smul_zero _ }),
add_smul := λx y f, l1.eq (by { simp only [coe_smul], exact add_smul _ _ _ }),
zero_smul := λf, l1.eq (by { simp only [coe_smul], exact zero_smul _ _ }) }
instance : module 𝕜 (α →₁ β) := { .. l1.semimodule }
instance : vector_space 𝕜 (α →₁ β) := { .. l1.semimodule }
instance : normed_space 𝕜 (α →₁ β) :=
⟨ begin
rintros x ⟨f, hf⟩,
show ennreal.to_real (edist (x • f) 0) = ∥x∥ * ennreal.to_real (edist f 0),
rw [edist_smul, to_real_of_real_mul],
exact norm_nonneg _
end ⟩
end normed_space
section of_fun
/-- Construct the equivalence class `[f]` of a measurable and integrable function `f`. -/
def of_fun (f : α → β) (hfm : measurable f) (hfi : integrable f) : (α →₁ β) :=
⟨mk f hfm, by { rw integrable_mk, exact hfi }⟩
lemma of_fun_eq_mk (f : α → β) (hfm hfi) : (of_fun f hfm hfi : α →ₘ β) = mk f hfm := rfl
lemma of_fun_eq_of_fun (f g : α → β) (hfm hfi hgm hgi) :
of_fun f hfm hfi = of_fun g hgm hgi ↔ ∀ₘ a, f a = g a :=
by { rw ← l1.eq_iff, simp only [of_fun_eq_mk, mk_eq_mk] }
lemma of_fun_zero :
of_fun (λa:α, (0:β)) (@measurable_const _ _ _ _ (0:β)) (integrable_zero α β) = 0 := rfl
lemma of_fun_add (f g : α → β) (hfm hfi hgm hgi) :
of_fun (λa, f a + g a) (measurable.add hfm hgm) (integrable.add hfm hfi hgm hgi)
= of_fun f hfm hfi + of_fun g hgm hgi :=
rfl
lemma of_fun_neg (f : α → β) (hfm hfi) :
of_fun (λa, - f a) (measurable.neg hfm) (integrable.neg hfi) = - of_fun f hfm hfi := rfl
lemma of_fun_sub (f g : α → β) (hfm hfi hgm hgi) :
of_fun (λa, f a - g a) (measurable.sub hfm hgm) (integrable.sub hfm hfi hgm hgi)
= of_fun f hfm hfi - of_fun g hgm hgi :=
rfl
lemma norm_of_fun (f : α → β) (hfm hfi) : ∥of_fun f hfm hfi∥ = ennreal.to_real (∫⁻ a, edist (f a) 0) :=
rfl
lemma norm_of_fun_eq_lintegral_norm (f : α → β) (hfm hfi) :
∥of_fun f hfm hfi∥ = ennreal.to_real (∫⁻ a, ennreal.of_real ∥f a∥) :=
by { rw [norm_of_fun, lintegral_norm_eq_lintegral_edist] }
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma of_fun_smul (f : α → β) (hfm : measurable f) (hfi : integrable f) (k : 𝕜) :
of_fun (λa, k • f a) (hfm.const_smul _) (hfi.smul _) = k • of_fun f hfm hfi := rfl
end of_fun
section to_fun
/-- Find a representative of an `L¹` function [f] -/
@[reducible]
protected def to_fun (f : α →₁ β) : α → β := (f : α →ₘ β).to_fun
protected lemma measurable (f : α →₁ β) : measurable f.to_fun := f.1.measurable
protected lemma integrable (f : α →₁ β) : integrable f.to_fun :=
by { rw [l1.to_fun, ← integrable_to_fun], exact f.2 }
lemma of_fun_to_fun (f : α →₁ β) : of_fun (f.to_fun) f.measurable f.integrable = f :=
begin
rcases f with ⟨f, hfi⟩,
rw [of_fun, subtype.mk_eq_mk],
exact (self_eq_mk f).symm
end
lemma mk_to_fun (f : α →₁ β) : mk (f.to_fun) f.measurable = f :=
by { rw ← of_fun_eq_mk, rw l1.eq_iff, exact of_fun_to_fun f }
lemma to_fun_of_fun (f : α → β) (hfm hfi) : ∀ₘ a, (of_fun f hfm hfi).to_fun a = f a :=
(all_ae_mk_to_fun f hfm).mono $ assume a, id
variables (α β)
lemma zero_to_fun : ∀ₘ a, (0 : α →₁ β).to_fun a = 0 := ae_eq_fun.zero_to_fun
variables {α β}
lemma add_to_fun (f g : α →₁ β) : ∀ₘ a, (f + g).to_fun a = f.to_fun a + g.to_fun a :=
ae_eq_fun.add_to_fun _ _
lemma neg_to_fun (f : α →₁ β) : ∀ₘ a, (-f).to_fun a = -f.to_fun a := ae_eq_fun.neg_to_fun _
lemma sub_to_fun (f g : α →₁ β) : ∀ₘ a, (f - g).to_fun a = f.to_fun a - g.to_fun a :=
ae_eq_fun.sub_to_fun _ _
lemma dist_to_fun (f g : α →₁ β) : dist f g = ennreal.to_real (∫⁻ x, edist (f.to_fun x) (g.to_fun x)) :=
by { simp only [dist_eq, edist_to_fun] }
lemma norm_eq_nnnorm_to_fun (f : α →₁ β) : ∥f∥ = ennreal.to_real (∫⁻ a, nnnorm (f.to_fun a)) :=
by { rw [lintegral_nnnorm_eq_lintegral_edist, ← edist_zero_to_fun], refl }
lemma norm_eq_norm_to_fun (f : α →₁ β) : ∥f∥ = ennreal.to_real (∫⁻ a, ennreal.of_real ∥f.to_fun a∥) :=
by { rw norm_eq_nnnorm_to_fun, congr, funext, rw of_real_norm_eq_coe_nnnorm }
lemma lintegral_edist_to_fun_lt_top (f g : α →₁ β) : (∫⁻ a, edist (f.to_fun a) (g.to_fun a)) < ⊤ :=
begin
apply lintegral_edist_lt_top,
exact f.measurable, exact f.integrable, exact g.measurable, exact g.integrable
end
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma smul_to_fun (c : 𝕜) (f : α →₁ β) : ∀ₘ a, (c • f).to_fun a = c • f.to_fun a :=
ae_eq_fun.smul_to_fun _ _
end to_fun
section pos_part
/-- Positive part of a function in `L¹` space. -/
def pos_part (f : α →₁ ℝ) : α →₁ ℝ :=
⟨ ae_eq_fun.pos_part f,
begin
rw [ae_eq_fun.integrable_to_fun, integrable_congr_ae (pos_part_to_fun _)],
exact integrable.max_zero f.integrable
end ⟩
/-- Negative part of a function in `L¹` space. -/
def neg_part (f : α →₁ ℝ) : α →₁ ℝ := pos_part (-f)
@[move_cast] lemma coe_pos_part (f : α →₁ ℝ) : (f.pos_part : α →ₘ ℝ) = (f : α →ₘ ℝ).pos_part := rfl
lemma pos_part_to_fun (f : α →₁ ℝ) : ∀ₘ a, (pos_part f).to_fun a = max (f.to_fun a) 0 :=
ae_eq_fun.pos_part_to_fun _
lemma neg_part_to_fun_eq_max (f : α →₁ ℝ) : ∀ₘ a, (neg_part f).to_fun a = max (- f.to_fun a) 0 :=
begin
rw neg_part,
filter_upwards [pos_part_to_fun (-f), neg_to_fun f],
simp only [mem_set_of_eq],
assume a h₁ h₂,
rw [h₁, h₂]
end
lemma neg_part_to_fun_eq_min (f : α →₁ ℝ) : ∀ₘ a, (neg_part f).to_fun a = - min (f.to_fun a) 0 :=
begin
filter_upwards [neg_part_to_fun_eq_max f],
simp only [mem_set_of_eq],
assume a h,
rw [h, min_eq_neg_max_neg_neg, _root_.neg_neg, neg_zero],
end
lemma norm_le_norm_of_ae_le {f g : α →₁ β} (h : ∀ₘ a, ∥f.to_fun a∥ ≤ ∥g.to_fun a∥) : ∥f∥ ≤ ∥g∥ :=
begin
simp only [l1.norm_eq_norm_to_fun],
rw to_real_le_to_real,
{ apply lintegral_le_lintegral_ae,
filter_upwards [h],
simp only [mem_set_of_eq],
assume a h,
exact of_real_le_of_real h },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact f.integrable },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact g.integrable }
end
lemma continuous_pos_part : continuous $ λf : α →₁ ℝ, pos_part f :=
begin
simp only [metric.continuous_iff],
assume g ε hε,
use ε, use hε,
simp only [dist_eq_norm],
assume f hfg,
refine lt_of_le_of_lt (norm_le_norm_of_ae_le _) hfg,
filter_upwards [l1.sub_to_fun f g, l1.sub_to_fun (pos_part f) (pos_part g),
pos_part_to_fun f, pos_part_to_fun g],
simp only [mem_set_of_eq],
assume a h₁ h₂ h₃ h₄,
simp only [real.norm_eq_abs, h₁, h₂, h₃, h₄],
exact abs_max_sub_max_le_abs _ _ _
end
lemma continuous_neg_part : continuous $ λf : α →₁ ℝ, neg_part f :=
have eq : (λf : α →₁ ℝ, neg_part f) = (λf : α →₁ ℝ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
/- TODO: l1 is a complete space -/
end l1
end measure_theory
|
4e4e525361cf9e013c6f985e20d5216481204c5d
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/imp3.lean
|
b82d21cf3c5a9303936b179e3032c4f4ad8dcf06
|
[
"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
| 235
|
lean
|
structure is_equiv [class] {A B : Type} (f : A → B) :=
(inv : B → A)
check @is_equiv.inv
namespace is_equiv
section
parameters A B : Type
parameter f : A → B
parameter c : is_equiv f
check inv f
end
end is_equiv
|
fd4342f01f8a6a2b9a4c31e055c60af24ceff37b
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/measure_theory/function/continuous_map_dense.lean
|
949035b8da651c50e14e897f777e5741fc4f2407
|
[
"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,160
|
lean
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import measure_theory.measure.regular
import measure_theory.function.simple_func_dense_lp
import topology.urysohns_lemma
import measure_theory.function.l1_space
/-!
# Approximation in Lᵖ by continuous functions
This file proves that bounded continuous functions are dense in `Lp E p μ`, for `1 ≤ p < ∞`, if the
domain `α` of the functions is a normal topological space and the measure `μ` is weakly regular.
The result is presented in several versions:
* `measure_theory.Lp.bounded_continuous_function_dense`: The subgroup
`measure_theory.Lp.bounded_continuous_function` of `Lp E p μ`, the additive subgroup of
`Lp E p μ` consisting of equivalence classes containing a continuous representative, is dense in
`Lp E p μ`.
* `bounded_continuous_function.to_Lp_dense_range`: For finite-measure `μ`, the continuous linear
map `bounded_continuous_function.to_Lp p μ 𝕜` from `α →ᵇ E` to `Lp E p μ` has dense range.
* `continuous_map.to_Lp_dense_range`: For compact `α` and finite-measure `μ`, the continuous linear
map `continuous_map.to_Lp p μ 𝕜` from `C(α, E)` to `Lp E p μ` has dense range.
Note that for `p = ∞` this result is not true: the characteristic function of the set `[0, ∞)` in
`ℝ` cannot be continuously approximated in `L∞`.
The proof is in three steps. First, since simple functions are dense in `Lp`, it suffices to prove
the result for a scalar multiple of a characteristic function of a measurable set `s`. Secondly,
since the measure `μ` is weakly regular, the set `s` can be approximated above by an open set and
below by a closed set. Finally, since the domain `α` is normal, we use Urysohn's lemma to find a
continuous function interpolating between these two sets.
## Related results
Are you looking for a result on "directional" approximation (above or below with respect to an
order) of functions whose codomain is `ℝ≥0∞` or `ℝ`, by semicontinuous functions? See the
Vitali-Carathéodory theorem, in the file `measure_theory.vitali_caratheodory`.
-/
open_locale ennreal nnreal topological_space bounded_continuous_function
open measure_theory topological_space continuous_map
variables {α : Type*} [measurable_space α] [topological_space α] [normal_space α] [borel_space α]
variables (E : Type*) [normed_group E]
[second_countable_topology_either α E]
variables {p : ℝ≥0∞} [_i : fact (1 ≤ p)] (hp : p ≠ ∞) (μ : measure α)
include _i hp
namespace measure_theory.Lp
variables [normed_space ℝ E]
/-- A function in `Lp` can be approximated in `Lp` by continuous functions. -/
lemma bounded_continuous_function_dense [μ.weakly_regular] :
(bounded_continuous_function E p μ).topological_closure = ⊤ :=
begin
have hp₀ : 0 < p := lt_of_lt_of_le ennreal.zero_lt_one _i.elim,
have hp₀' : 0 ≤ 1 / p.to_real := div_nonneg zero_le_one ennreal.to_real_nonneg,
have hp₀'' : 0 < p.to_real,
{ simpa [← ennreal.to_real_lt_to_real ennreal.zero_ne_top hp] using hp₀ },
-- It suffices to prove that scalar multiples of the indicator function of a finite-measure
-- measurable set can be approximated by continuous functions
suffices : ∀ (c : E) {s : set α} (hs : measurable_set s) (hμs : μ s < ⊤),
(Lp.simple_func.indicator_const p hs hμs.ne c : Lp E p μ)
∈ (bounded_continuous_function E p μ).topological_closure,
{ rw add_subgroup.eq_top_iff',
refine Lp.induction hp _ _ _ _,
{ exact this },
{ exact λ f g hf hg hfg', add_subgroup.add_mem _ },
{ exact add_subgroup.is_closed_topological_closure _ } },
-- Let `s` be a finite-measure measurable set, let's approximate `c` times its indicator function
intros c s hs hsμ,
refine mem_closure_iff_frequently.mpr _,
rw metric.nhds_basis_closed_ball.frequently_iff,
intros ε hε,
-- A little bit of pre-emptive work, to find `η : ℝ≥0` which will be a margin small enough for
-- our purposes
obtain ⟨η, hη_pos, hη_le⟩ : ∃ η, 0 < η ∧ (↑(∥bit0 (∥c∥)∥₊ * (2 * η) ^ (1 / p.to_real)) : ℝ) ≤ ε,
{ have : filter.tendsto (λ x : ℝ≥0, ∥bit0 (∥c∥)∥₊ * (2 * x) ^ (1 / p.to_real)) (𝓝 0) (𝓝 0),
{ have : filter.tendsto (λ x : ℝ≥0, 2 * x) (𝓝 0) (𝓝 (2 * 0)) := filter.tendsto_id.const_mul 2,
convert ((nnreal.continuous_at_rpow_const (or.inr hp₀')).tendsto.comp this).const_mul _,
simp [hp₀''.ne'] },
let ε' : ℝ≥0 := ⟨ε, hε.le⟩,
have hε' : 0 < ε' := by exact_mod_cast hε,
obtain ⟨δ, hδ, hδε'⟩ :=
nnreal.nhds_zero_basis.eventually_iff.mp (eventually_le_of_tendsto_lt hε' this),
obtain ⟨η, hη, hηδ⟩ := exists_between hδ,
refine ⟨η, hη, _⟩,
exact_mod_cast hδε' hηδ },
have hη_pos' : (0 : ℝ≥0∞) < η := ennreal.coe_pos.2 hη_pos,
-- Use the regularity of the measure to `η`-approximate `s` by an open superset and a closed
-- subset
obtain ⟨u, su, u_open, μu⟩ : ∃ u ⊇ s, is_open u ∧ μ u < μ s + ↑η,
{ refine s.exists_is_open_lt_of_lt _ _,
simpa using ennreal.add_lt_add_left hsμ.ne hη_pos' },
obtain ⟨F, Fs, F_closed, μF⟩ : ∃ F ⊆ s, is_closed F ∧ μ s < μ F + ↑η :=
hs.exists_is_closed_lt_add hsμ.ne hη_pos'.ne',
have : disjoint uᶜ F,
{ rw [set.disjoint_iff_inter_eq_empty, set.inter_comm, ← set.subset_compl_iff_disjoint],
simpa using Fs.trans su },
have h_μ_sdiff : μ (u \ F) ≤ 2 * η,
{ have hFμ : μ F < ⊤ := (measure_mono Fs).trans_lt hsμ,
refine ennreal.le_of_add_le_add_left hFμ.ne _,
have : μ u < μ F + ↑η + ↑η,
from μu.trans (ennreal.add_lt_add_right ennreal.coe_ne_top μF),
convert this.le using 1,
{ rw [add_comm, ← measure_union, set.diff_union_of_subset (Fs.trans su)],
exacts [disjoint_sdiff_self_left, F_closed.measurable_set] },
have : (2:ℝ≥0∞) * η = η + η := by simpa using add_mul (1:ℝ≥0∞) 1 η,
rw this,
abel },
-- Apply Urysohn's lemma to get a continuous approximation to the characteristic function of
-- the set `s`
obtain ⟨g, hgu, hgF, hg_range⟩ :=
exists_continuous_zero_one_of_closed u_open.is_closed_compl F_closed this,
-- Multiply this by `c` to get a continuous approximation to the function `f`; the key point is
-- that this is pointwise bounded by the indicator of the set `u \ F`
have g_norm : ∀ x, ∥g x∥ = g x := λ x, by rw [real.norm_eq_abs, abs_of_nonneg (hg_range x).1],
have gc_bd : ∀ x, ∥g x • c - s.indicator (λ x, c) x∥ ≤ ∥(u \ F).indicator (λ x, bit0 ∥c∥) x∥,
{ intros x,
by_cases hu : x ∈ u,
{ rw ← set.diff_union_of_subset (Fs.trans su) at hu,
cases hu with hFu hF,
{ refine (norm_sub_le _ _).trans _,
refine (add_le_add_left (norm_indicator_le_norm_self (λ x, c) x) _).trans _,
have h₀ : g x * ∥c∥ + ∥c∥ ≤ 2 * ∥c∥,
{ nlinarith [(hg_range x).1, (hg_range x).2, norm_nonneg c] },
have h₁ : (2:ℝ) * ∥c∥ = bit0 (∥c∥) := by simpa using add_mul (1:ℝ) 1 (∥c∥),
simp [hFu, norm_smul, h₀, ← h₁, g_norm x] },
{ simp [hgF hF, Fs hF] } },
{ have : x ∉ s := λ h, hu (su h),
simp [hgu hu, this] } },
-- The rest is basically just `ennreal`-arithmetic
have gc_snorm : snorm ((λ x, g x • c) - s.indicator (λ x, c)) p μ
≤ (↑(∥bit0 (∥c∥)∥₊ * (2 * η) ^ (1 / p.to_real)) : ℝ≥0∞),
{ refine (snorm_mono_ae (filter.eventually_of_forall gc_bd)).trans _,
rw snorm_indicator_const (u_open.sdiff F_closed).measurable_set hp₀.ne' hp,
push_cast [← ennreal.coe_rpow_of_nonneg _ hp₀'],
exact ennreal.mul_left_mono (ennreal.monotone_rpow_of_nonneg hp₀' h_μ_sdiff) },
have gc_cont : continuous (λ x, g x • c) := g.continuous.smul continuous_const,
have gc_mem_ℒp : mem_ℒp (λ x, g x • c) p μ,
{ have : mem_ℒp ((λ x, g x • c) - s.indicator (λ x, c)) p μ :=
⟨gc_cont.ae_strongly_measurable.sub (strongly_measurable_const.indicator hs)
.ae_strongly_measurable,
gc_snorm.trans_lt ennreal.coe_lt_top⟩,
simpa using this.add (mem_ℒp_indicator_const p hs c (or.inr hsμ.ne)) },
refine ⟨gc_mem_ℒp.to_Lp _, _, _⟩,
{ rw mem_closed_ball_iff_norm,
refine le_trans _ hη_le,
rw [simple_func.coe_indicator_const, indicator_const_Lp, ← mem_ℒp.to_Lp_sub, Lp.norm_to_Lp],
exact ennreal.to_real_le_coe_of_le_coe gc_snorm },
{ rw [set_like.mem_coe, mem_bounded_continuous_function_iff],
refine ⟨bounded_continuous_function.of_normed_group _ gc_cont (∥c∥) _, rfl⟩,
intros x,
have h₀ : g x * ∥c∥ ≤ ∥c∥,
{ nlinarith [(hg_range x).1, (hg_range x).2, norm_nonneg c] },
simp [norm_smul, g_norm x, h₀] },
end
end measure_theory.Lp
variables (𝕜 : Type*) [normed_field 𝕜] [normed_algebra ℝ 𝕜] [normed_space 𝕜 E]
namespace bounded_continuous_function
lemma to_Lp_dense_range [μ.weakly_regular] [is_finite_measure μ] :
dense_range ⇑(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ) :=
begin
haveI : normed_space ℝ E := restrict_scalars.normed_space ℝ 𝕜 E,
rw dense_range_iff_closure_range,
suffices : (to_Lp p μ 𝕜 : _ →L[𝕜] Lp E p μ).range.to_add_subgroup.topological_closure = ⊤,
{ exact congr_arg coe this },
simp [range_to_Lp p μ, measure_theory.Lp.bounded_continuous_function_dense E hp],
end
end bounded_continuous_function
namespace continuous_map
lemma to_Lp_dense_range [compact_space α] [μ.weakly_regular] [is_finite_measure μ] :
dense_range ⇑(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ) :=
begin
haveI : normed_space ℝ E := restrict_scalars.normed_space ℝ 𝕜 E,
rw dense_range_iff_closure_range,
suffices : (to_Lp p μ 𝕜 : _ →L[𝕜] Lp E p μ).range.to_add_subgroup.topological_closure = ⊤,
{ exact congr_arg coe this },
simp [range_to_Lp p μ, measure_theory.Lp.bounded_continuous_function_dense E hp]
end
end continuous_map
|
2155ec1e85b3ee9878fbbfc882f341f881ac6262
|
97f752b44fd85ec3f635078a2dd125ddae7a82b6
|
/library/theories/analysis/inner_product.lean
|
c294d8bd3b1ebee894f4bf393c4adeb51b78d493
|
[
"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
| 9,685
|
lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Real inner product spaces.
Note: We can enter ⟨v, w⟩ as \<v, w\>. This file overwrites the notation for dependent pairs.
-/
import theories.analysis.normed_space theories.analysis.sqrt
open nat real classical
noncomputable theory
structure inner_product_space [class] (V : Type) extends real_vector_space V :=
(inner : V → V → ℝ)
(inner_add_left : ∀ u v w, inner (add u v) w = inner u w + inner v w)
(inner_smul_left : ∀ r v w, inner (smul r v) w = r * inner v w)
(inner_comm : ∀ v w, inner v w = inner w v)
(inner_self_nonneg : ∀ v, inner v v ≥ 0)
(eq_zero_of_inner_self_eq_zero : ∀ {v}, inner v v = 0 → v = zero)
namespace analysis
variables {V : Type} [inner_product_space V]
definition inner (v w : V) : ℝ := inner_product_space.inner v w
notation `⟨` v `, ` w `⟩` := inner v w
proposition inner_comm (v w : V) : ⟨v, w⟩ = ⟨w, v⟩ := inner_product_space.inner_comm v w
proposition inner_add_left (u v w : V) : ⟨u + v, w⟩ = ⟨u, w⟩ + ⟨v, w⟩ :=
inner_product_space.inner_add_left u v w
proposition inner_add_right (u v w : V) : ⟨u, v + w⟩ = ⟨u, v⟩ + ⟨u, w⟩ :=
by rewrite [inner_comm, inner_add_left, inner_comm, inner_comm w]
proposition inner_smul_left (r : ℝ) (v w : V) : ⟨r • v, w⟩ = r * ⟨v, w⟩ :=
inner_product_space.inner_smul_left r v w
proposition inner_smul_right (r : ℝ) (v w : V) : ⟨v, r • w⟩ = r * ⟨v, w⟩ :=
by rewrite [inner_comm, inner_smul_left, inner_comm]
proposition inner_self_nonneg (v : V) : ⟨v, v⟩ ≥ 0 := inner_product_space.inner_self_nonneg v
proposition eq_zero_of_inner_self_eq_zero {v : V} (H : ⟨v, v⟩ = 0) : v = 0 :=
inner_product_space.eq_zero_of_inner_self_eq_zero H
proposition inner_neg_left (u v : V) : ⟨-u, v⟩ = -⟨u, v⟩ :=
by rewrite [-neg_one_smul_real, inner_smul_left, -neg_eq_neg_one_mul]
proposition inner_neg_right (u v : V) : ⟨u, -v⟩ = -⟨u, v⟩ :=
by rewrite [inner_comm, inner_neg_left, inner_comm]
proposition inner_sub_left (u v w : V) : ⟨u - v, w⟩ = ⟨u, w⟩ - ⟨v, w⟩ :=
by rewrite [*sub_eq_add_neg, inner_add_left, inner_neg_left]
proposition inner_sub_right (u v w : V) : ⟨u, v - w⟩ = ⟨u, v⟩ - ⟨u, w⟩ :=
by rewrite [*sub_eq_add_neg, inner_add_right, inner_neg_right]
proposition inner_zero_left (v : V) : ⟨0, v⟩ = 0 :=
have (0 : ℝ) • v = 0, from zero_smul v,
using this, by rewrite [-this, inner_smul_left, zero_mul]
proposition inner_zero_right (v : V) : ⟨v, 0⟩ = 0 :=
by rewrite [inner_comm, inner_zero_left]
definition orthogonal (u v : V) : Prop := ⟨u, v⟩ = 0
infix ` ⊥ `:50 := orthogonal
proposition orthogonal_comm {u v : V} (H : u ⊥ v) : v ⊥ u :=
by unfold orthogonal at *; rewrite [inner_comm, H]
/- first, we define norm internally, to show that an inner product space is a normed space -/
private definition ip_norm (v : V) : ℝ := sqrt ⟨v, v⟩
private proposition ip_norm_zero : ip_norm (0 : V) = 0 :=
by rewrite [↑ip_norm, inner_zero_left, sqrt_zero]
private proposition ip_norm_squared (v : V) : (ip_norm v)^2 = ⟨v, v⟩ :=
sqrt_squared (inner_self_nonneg v)
private proposition ip_norm_nonneg (v : V) : ip_norm v ≥ 0 := !sqrt_nonneg
private proposition eq_zero_of_ip_norm_eq_zero {v : V} (H : ip_norm v = 0) : v = 0 :=
have ⟨v, v⟩ = 0, by rewrite [-ip_norm_squared, H, pow_two, zero_mul],
eq_zero_of_inner_self_eq_zero this
private proposition ip_norm_smul (r : ℝ) (v : V) : ip_norm (r • v) = abs r * ip_norm v :=
begin
rewrite [↑ip_norm, inner_smul_left, inner_smul_right, -mul.assoc],
rewrite [sqrt_mul (mul_self_nonneg r) (inner_self_nonneg v), -pow_two, sqrt_squared']
end
private proposition ip_norm_pythagorean {u v : V} (ortho : u ⊥ v) :
(ip_norm (u + v))^2 = (ip_norm u)^2 + (ip_norm v)^2 :=
by rewrite [↑orthogonal at ortho, *ip_norm_squared, inner_add_right, *inner_add_left,
inner_comm v u, *ortho, zero_add, add_zero]
private definition ip_proj_on (u : V) {v : V} (H : v ≠ 0) : V :=
(⟨u, v⟩ / (ip_norm v)^2) • v
private proposition ip_proj_on_orthogonal (u : V) {v : V} (H : v ≠ 0) :
ip_proj_on u H ⊥ (u - ip_proj_on u H) :=
begin
rewrite [↑ip_proj_on, ↑orthogonal, inner_sub_right, +inner_smul_left, inner_smul_right],
rewrite [ip_norm_squared at {3}],
rewrite [div_mul_cancel _ (assume H', H (eq_zero_of_inner_self_eq_zero H'))],
rewrite [inner_comm v u, sub_self]
end
private proposition ip_norm_proj_on_eq (u : V) {v : V} (H : v ≠ 0) :
ip_norm (ip_proj_on u H) = abs ⟨u, v⟩ / ip_norm v :=
have H1 : ip_norm v ≠ 0, from assume H', H (eq_zero_of_ip_norm_eq_zero H'),
begin+
rewrite [↑ip_proj_on, ip_norm_smul, abs_div, abs_of_nonneg (squared_nonneg (ip_norm v)), pow_two],
rewrite [div_mul_eq_mul_div, -div_mul_div, div_self H1, mul_one]
end
private proposition ip_norm_squared_pythagorean (u : V) {v : V} (H : v ≠ 0) :
(ip_norm u)^2 = (ip_norm (u - ip_proj_on u H))^2 + (ip_norm (ip_proj_on u H))^2 :=
calc
(ip_norm u)^2 = (ip_norm (u - ip_proj_on u H + ip_proj_on u H))^2 :
sub_add_cancel
... = (ip_norm (u - ip_proj_on u H))^2 + (ip_norm (ip_proj_on u H))^2 :
ip_norm_pythagorean (orthogonal_comm (ip_proj_on_orthogonal u H))
private proposition ip_norm_proj_on_le (u : V) {v : V} (H : v ≠ 0) :
ip_norm (ip_proj_on u H) ≤ ip_norm u :=
have (ip_norm u)^2 ≥ (ip_norm (ip_proj_on u H))^2,
begin
rewrite [ip_norm_squared_pythagorean u H],
apply le_add_of_nonneg_left (squared_nonneg (ip_norm (u - ip_proj_on u H)))
end,
le_of_squared_le_squared !ip_norm_nonneg this
private proposition ip_cauchy_schwartz (u v : V) : abs ⟨u, v⟩ ≤ ip_norm u * ip_norm v :=
by_cases
(suppose v = (0 : V),
begin
rewrite [this, inner_zero_right, abs_zero, ip_norm_zero, mul_zero],
exact le.refl (0 : ℝ)
end)
(assume vnz : v ≠ 0,
have ip_norm v ≠ 0, from assume H, vnz (eq_zero_of_ip_norm_eq_zero H),
have ip_norm v > 0, from lt_of_le_of_ne !sqrt_nonneg (ne.symm this),
using this, begin
note H := ip_norm_proj_on_le u vnz,
rewrite [ip_norm_proj_on_eq u vnz at H],
exact le_mul_of_div_le this H
end)
private proposition ip_cauchy_schwartz' (u v : V) : ⟨u, v⟩ ≤ ip_norm u * ip_norm v :=
le.trans !le_abs_self !ip_cauchy_schwartz
private proposition ip_norm_triangle (u v : V) : ip_norm (u + v) ≤ ip_norm u + ip_norm v :=
have H : ⟨u, v⟩ ≤ ip_norm u * ip_norm v, from ip_cauchy_schwartz' u v,
have (ip_norm (u + v))^2 ≤ (ip_norm u + ip_norm v)^2, from
calc
(ip_norm (u + v))^2 = (ip_norm u)^2 + (ip_norm v)^2 + ⟨u, v⟩ + ⟨u, v⟩ :
by rewrite [↑ip_norm, *sqrt_squared !inner_self_nonneg, inner_add_left,
*inner_add_right, *inner_comm v u, -add.assoc, -*add.right_comm _ _ ⟨v, v⟩]
... ≤ (ip_norm u)^2 + (ip_norm v)^2 + ip_norm u * ip_norm v + ⟨u, v⟩ :
add_le_add_right (add_le_add_left H _) _
... ≤ (ip_norm u)^2 + (ip_norm v)^2 + ip_norm u * ip_norm v + ip_norm u * ip_norm v :
add_le_add_left H _
... = (ip_norm u + ip_norm v)^2 :
by rewrite [*pow_two, right_distrib, *left_distrib, -add.assoc,
*add.right_comm _ (ip_norm v * ip_norm v),
mul.comm (ip_norm v) (ip_norm u)],
le_of_squared_le_squared (add_nonneg !ip_norm_nonneg !ip_norm_nonneg) this
definition inner_product_space.to_normed_space [trans_instance] [reducible] :
normed_vector_space V :=
⦃ normed_vector_space, _inst_1,
norm := ip_norm,
norm_zero := ip_norm_zero,
eq_zero_of_norm_eq_zero := @eq_zero_of_ip_norm_eq_zero V _,
norm_triangle := ip_norm_triangle,
norm_smul := ip_norm_smul
⦄
/- now we restate the new theorems using the norm notation -/
proposition norm_squared (v : V) : ∥ v ∥^2 = ⟨v, v⟩ := ip_norm_squared v
proposition norm_pythagorean {u v : V} (ortho : u ⊥ v) : ∥ u + v ∥^2 = ∥ u ∥^2 + ∥ v ∥^2 :=
ip_norm_pythagorean ortho
definition proj_on (u : V) {v : V} (H : v ≠ 0) : V := (⟨u, v⟩ / ∥ v ∥^2) • v
proposition proj_on_orthogonal (u : V) {v : V} (H : v ≠ 0) :
proj_on u H ⊥ (u - proj_on u H) :=
ip_proj_on_orthogonal u H
proposition norm_proj_on_eq (u : V) {v : V} (H : v ≠ 0) :
∥ proj_on u H ∥ = abs ⟨u, v⟩ / ∥ v ∥ :=
ip_norm_proj_on_eq u H
proposition norm_squared_pythagorean (u : V) {v : V} (H : v ≠ 0) :
∥ u ∥^2 = ∥ u - proj_on u H ∥^2 + ∥ proj_on u H ∥^2 :=
ip_norm_squared_pythagorean u H
proposition norm_proj_on_le (u : V) {v : V} (H : v ≠ 0) :
∥ proj_on u H ∥ ≤ ∥ u ∥ := ip_norm_proj_on_le u H
theorem cauchy_schwartz (u v : V) : abs ⟨u, v⟩ ≤ ∥ u ∥ * ∥ v ∥ := ip_cauchy_schwartz u v
theorem cauchy_schwartz' (u v : V) : ⟨u, v⟩ ≤ ∥ u ∥ * ∥ v ∥ := ip_cauchy_schwartz' u v
theorem eq_proj_on_cauchy_schwartz {u v : V} (H : v ≠ 0) (H₁ : abs ⟨u, v⟩ = ∥ u ∥ * ∥ v ∥) :
u = proj_on u H :=
assert ∥ v ∥ ≠ 0, from assume H', H (eq_zero_of_norm_eq_zero H'),
assert ∥ u ∥ = ∥ proj_on u H ∥, by rewrite [norm_proj_on_eq, H₁, mul_div_cancel _ this],
have ∥ u - proj_on u H ∥^2 + ∥ u ∥^2 = 0 + ∥ u ∥^2,
by rewrite [zero_add, norm_squared_pythagorean u H at {2}, this],
have ∥ u - proj_on u H ∥^2 = 0, from eq_of_add_eq_add_right this,
show u = proj_on u H,
from eq_of_sub_eq_zero (eq_zero_of_norm_eq_zero (eq_zero_of_squared_eq_zero this))
end analysis
|
4d1b1de54a644d2866ddccf13a4c7e4f0fa05944
|
31f556cdeb9239ffc2fad8f905e33987ff4feab9
|
/src/Lean/Server/InfoUtils.lean
|
4a6f9050c9fae3c1e169c004af0dc1d9546a14d1
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
tobiasgrosser/lean4
|
ce0fd9cca0feba1100656679bf41f0bffdbabb71
|
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
|
refs/heads/master
| 1,673,103,412,948
| 1,664,930,501,000
| 1,664,930,501,000
| 186,870,185
| 0
| 0
|
Apache-2.0
| 1,665,129,237,000
| 1,557,939,901,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 13,911
|
lean
|
/-
Copyright (c) 2021 Wojciech Nawrocki. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Lean.PrettyPrinter
namespace Lean.Elab
/-- Visit nodes, passing in a surrounding context (the innermost one) and accumulating results on the way back up. -/
partial def InfoTree.visitM [Monad m]
(preNode : ContextInfo → Info → (children : PersistentArray InfoTree) → m Unit := fun _ _ _ => pure ())
(postNode : ContextInfo → Info → (children : PersistentArray InfoTree) → List (Option α) → m α)
: InfoTree → m (Option α) :=
go none
where go
| _, context ctx t => go ctx t
| some ctx, node i cs => do
preNode ctx i cs
let as ← cs.toList.mapM (go <| i.updateContext? ctx)
postNode ctx i cs as
| none, node .. => panic! "unexpected context-free info tree node"
| _, hole .. => pure none
/-- `InfoTree.visitM` specialized to `Unit` return type -/
def InfoTree.visitM' [Monad m]
(preNode : ContextInfo → Info → (children : PersistentArray InfoTree) → m Unit := fun _ _ _ => pure ())
(postNode : ContextInfo → Info → (children : PersistentArray InfoTree) → m Unit := fun _ _ _ => pure ())
(t : InfoTree) : m Unit := t.visitM preNode (fun ci i cs _ => postNode ci i cs) |> discard
/--
Visit nodes bottom-up, passing in a surrounding context (the innermost one) and the union of nested results (empty at leaves). -/
def InfoTree.collectNodesBottomUp (p : ContextInfo → Info → PersistentArray InfoTree → List α → List α) (i : InfoTree) : List α :=
i.visitM (m := Id) (postNode := fun ci i cs as => p ci i cs (as.filterMap id).join) |>.getD []
/--
For every branch of the `InfoTree`, find the deepest node in that branch for which `p` returns
`some _` and return the union of all such nodes. The visitor `p` is given a node together with
its innermost surrounding `ContextInfo`. -/
partial def InfoTree.deepestNodes (p : ContextInfo → Info → PersistentArray InfoTree → Option α) (infoTree : InfoTree) : List α :=
infoTree.collectNodesBottomUp fun ctx i cs rs =>
if rs.isEmpty then
match p ctx i cs with
| some r => [r]
| none => []
else
rs
partial def InfoTree.foldInfo (f : ContextInfo → Info → α → α) (init : α) : InfoTree → α :=
go none init
where go ctx? a
| context ctx t => go ctx a t
| node i ts =>
let a := match ctx? with
| none => a
| some ctx => f ctx i a
ts.foldl (init := a) (go <| i.updateContext? ctx?)
| _ => a
def Info.isTerm : Info → Bool
| ofTermInfo _ => true
| _ => false
def Info.isCompletion : Info → Bool
| ofCompletionInfo .. => true
| _ => false
def InfoTree.getCompletionInfos (infoTree : InfoTree) : Array (ContextInfo × CompletionInfo) :=
infoTree.foldInfo (init := #[]) fun ctx info result =>
match info with
| Info.ofCompletionInfo info => result.push (ctx, info)
| _ => result
def Info.stx : Info → Syntax
| ofTacticInfo i => i.stx
| ofTermInfo i => i.stx
| ofCommandInfo i => i.stx
| ofMacroExpansionInfo i => i.stx
| ofFieldInfo i => i.stx
| ofCompletionInfo i => i.stx
| ofCustomInfo i => i.stx
| ofUserWidgetInfo i => i.stx
| ofFVarAliasInfo _ => .missing
| ofFieldRedeclInfo i => i.stx
def Info.lctx : Info → LocalContext
| Info.ofTermInfo i => i.lctx
| Info.ofFieldInfo i => i.lctx
| _ => LocalContext.empty
def Info.pos? (i : Info) : Option String.Pos :=
i.stx.getPos? (canonicalOnly := true)
def Info.tailPos? (i : Info) : Option String.Pos :=
i.stx.getTailPos? (canonicalOnly := true)
def Info.range? (i : Info) : Option String.Range :=
i.stx.getRange? (canonicalOnly := true)
def Info.contains (i : Info) (pos : String.Pos) (includeStop := false) : Bool :=
i.range?.any (·.contains pos includeStop)
def Info.size? (i : Info) : Option String.Pos := do
let pos ← i.pos?
let tailPos ← i.tailPos?
return tailPos - pos
-- `Info` without position information are considered to have "infinite" size
def Info.isSmaller (i₁ i₂ : Info) : Bool :=
match i₁.size?, i₂.pos? with
| some sz₁, some sz₂ => sz₁ < sz₂
| some _, none => true
| _, _ => false
def Info.occursBefore? (i : Info) (hoverPos : String.Pos) : Option String.Pos := do
let tailPos ← i.tailPos?
guard (tailPos ≤ hoverPos)
return hoverPos - tailPos
def Info.occursInside? (i : Info) (hoverPos : String.Pos) : Option String.Pos := do
let headPos ← i.pos?
let tailPos ← i.tailPos?
guard (headPos ≤ hoverPos && hoverPos < tailPos)
return hoverPos - headPos
def InfoTree.smallestInfo? (p : Info → Bool) (t : InfoTree) : Option (ContextInfo × Info) :=
let ts := t.deepestNodes fun ctx i _ => if p i then some (ctx, i) else none
let infos := ts.map fun (ci, i) =>
let diff := i.tailPos?.get! - i.pos?.get!
(diff, ci, i)
infos.toArray.getMax? (fun a b => a.1 > b.1) |>.map fun (_, ci, i) => (ci, i)
/-- Find an info node, if any, which should be shown on hover/cursor at position `hoverPos`. -/
partial def InfoTree.hoverableInfoAt? (t : InfoTree) (hoverPos : String.Pos) (includeStop := false) (omitAppFns := false) : Option (ContextInfo × Info) := Id.run do
let results := t.visitM (m := Id) (postNode := fun ctx info _ results => do
let mut results := results.bind (·.getD [])
if omitAppFns && info.stx.isOfKind ``Parser.Term.app && info.stx[0].isIdent then
results := results.filter (·.2.2.stx != info.stx[0])
unless results.isEmpty do
return results -- prefer innermost results
/-
Remark: we skip `info` nodes associated with the `nullKind` and `withAnnotateState` because they are used by tactics (e.g., `rewrite`) to control
which goal is displayed in the info views. See issue #1403
-/
if info.stx.isOfKind nullKind || info.toElabInfo?.any (·.elaborator == `Lean.Elab.Tactic.evalWithAnnotateState) then
return results
unless (info matches Info.ofFieldInfo _ || info.toElabInfo?.isSome) && info.contains hoverPos includeStop do
return results
let r := info.range?.get!
let priority :=
if r.stop == hoverPos then
0 -- prefer results directly *after* the hover position (only matters for `includeStop = true`; see #767)
else if info matches .ofTermInfo { expr := .fvar .., .. } then
0 -- prefer results for constants over variables (which overlap at declaration names)
else 1
[(priority, ctx, info)]) |>.getD []
let maxPrio? := results.map (·.1) |>.maximum?
let res? := results.find? (·.1 == maxPrio?) |>.map (·.2)
if let some (_, i) := res? then
if let .ofTermInfo ti := i then
if ti.expr.isSyntheticSorry then
return none
return res?
def Info.type? (i : Info) : MetaM (Option Expr) :=
match i with
| Info.ofTermInfo ti => Meta.inferType ti.expr
| Info.ofFieldInfo fi => Meta.inferType fi.val
| _ => return none
def Info.docString? (i : Info) : MetaM (Option String) := do
let env ← getEnv
if let Info.ofTermInfo ti := i then
if let some n := ti.expr.constName? then
return ← findDocString? env n
if let Info.ofFieldInfo fi := i then
return ← findDocString? env fi.projName
if let some ei := i.toElabInfo? then
return ← findDocString? env ei.stx.getKind <||> findDocString? env ei.elaborator
return none
/-- Construct a hover popup, if any, from an info node in a context.-/
def Info.fmtHover? (ci : ContextInfo) (i : Info) : IO (Option Format) := do
ci.runMetaM i.lctx do
let mut fmts := #[]
let modFmt ← try
let (termFmt, modFmt) ← fmtTermAndModule?
if let some f := termFmt then
fmts := fmts.push f
pure modFmt
catch _ => pure none
if let some m ← i.docString? then
fmts := fmts.push m
if let some f := modFmt then
fmts := fmts.push f
if fmts.isEmpty then
return none
else
return f!"\n***\n".joinSep fmts.toList
where
fmtModule? (decl : Name) : MetaM (Option Format) := do
let some mod ← findModuleOf? decl | return none
return some f!"*import {mod}*"
fmtTermAndModule? : MetaM (Option Format × Option Format) := do
match i with
| Info.ofTermInfo ti =>
let e ← instantiateMVars ti.expr
if e.isSort then
-- Types of sorts are funny to look at in widgets, but ultimately not very helpful
return (none, none)
let tp ← instantiateMVars (← Meta.inferType e)
let tpFmt ← Meta.ppExpr tp
if e.isConst then
-- Recall that `ppExpr` adds a `@` if the constant has implicit arguments, and it is quite distracting
let eFmt ← withOptions (pp.fullNames.set · true |> (pp.universes.set · true)) <| PrettyPrinter.ppConst e
return (some f!"```lean\n{eFmt} : {tpFmt}\n```", ← fmtModule? e.constName!)
else
let eFmt ← Meta.ppExpr e
-- Try not to show too scary internals
let showTerm := if let .fvar _ := e then
if let some ldecl := (← getLCtx).findFVar? e then
!ldecl.userName.hasMacroScopes
else false
else isAtomicFormat eFmt
let fmt := if showTerm then f!"{eFmt} : {tpFmt}" else tpFmt
return (some f!"```lean\n{fmt}\n```", none)
| Info.ofFieldInfo fi =>
let tp ← Meta.inferType fi.val
let tpFmt ← Meta.ppExpr tp
return (some f!"```lean\n{fi.fieldName} : {tpFmt}\n```", none)
| _ => return (none, none)
isAtomicFormat : Format → Bool
| Std.Format.text _ => true
| Std.Format.group f _ => isAtomicFormat f
| Std.Format.nest _ f => isAtomicFormat f
| Std.Format.tag _ f => isAtomicFormat f
| _ => false
structure GoalsAtResult where
ctxInfo : ContextInfo
tacticInfo : TacticInfo
useAfter : Bool
/-- Whether the tactic info is further indented than the hover position. -/
indented : Bool
-- for overlapping goals, only keep those of the highest reported priority
priority : Nat
/--
Try to retrieve `TacticInfo` for `hoverPos`.
We retrieve all `TacticInfo` nodes s.t. `hoverPos` is inside the node's range plus trailing whitespace.
We usually prefer the innermost such nodes so that for composite tactics such as `induction`, we show the nested proofs' states.
However, if `hoverPos` is after the tactic, we prefer nodes that are not indented relative to it, meaning that e.g. at `|` in
```lean
have := by
exact foo
|
```
we show the (final, see below) state of `have`, not `exact`.
Moreover, we instruct the LSP server to use the state after tactic execution if
- the hover position is after the info's start position *and*
- there is no nested tactic info after the hover position (tactic combinators should decide for themselves
where to show intermediate states by calling `withTacticInfoContext`) -/
partial def InfoTree.goalsAt? (text : FileMap) (t : InfoTree) (hoverPos : String.Pos) : List GoalsAtResult :=
let gs := t.collectNodesBottomUp fun ctx i cs gs => Id.run do
if let Info.ofTacticInfo ti := i then
if let (some pos, some tailPos) := (i.pos?, i.tailPos?) then
let trailSize := i.stx.getTrailingSize
-- show info at EOF even if strictly outside token + trail
let atEOF := tailPos.byteIdx + trailSize == text.source.endPos.byteIdx
-- include at least one trailing character (see also `priority` below)
if pos ≤ hoverPos ∧ (hoverPos.byteIdx < tailPos.byteIdx + max 1 trailSize || atEOF) then
-- overwrite bottom-up results according to "innermost" heuristics documented above
if gs.isEmpty || hoverPos ≥ tailPos && gs.all (·.indented) then
return [{
ctxInfo := ctx
tacticInfo := ti
useAfter := hoverPos > pos && !cs.any (hasNestedTactic pos tailPos)
indented := (text.toPosition pos).column > (text.toPosition hoverPos).column
-- use goals just before cursor as fall-back only
-- thus for `(by foo)`, placing the cursor after `foo` shows its state as long
-- as there is no state on `)`
priority := if hoverPos.byteIdx == tailPos.byteIdx + trailSize then 0 else 1
}]
return gs
let maxPrio? := gs.map (·.priority) |>.maximum?
gs.filter (some ·.priority == maxPrio?)
where
hasNestedTactic (pos tailPos) : InfoTree → Bool
| InfoTree.node i@(Info.ofTacticInfo _) cs => Id.run do
if let `(by $_) := i.stx then
return false -- ignore term-nested proofs such as in `simp [show p by ...]`
if let (some pos', some tailPos') := (i.pos?, i.tailPos?) then
-- ignore preceding nested infos
-- ignore nested infos of the same tactic, e.g. from expansion
if tailPos' > hoverPos && (pos', tailPos') != (pos, tailPos) then
return true
cs.any (hasNestedTactic pos tailPos)
| InfoTree.node (Info.ofMacroExpansionInfo _) cs =>
cs.any (hasNestedTactic pos tailPos)
| _ => false
partial def InfoTree.termGoalAt? (t : InfoTree) (hoverPos : String.Pos) : Option (ContextInfo × Info) :=
-- In the case `f a b`, where `f` is an identifier, the term goal at `f` should be the goal for the full application `f a b`.
hoverableInfoAt? t hoverPos (includeStop := true) (omitAppFns := true)
partial def InfoTree.hasSorry : InfoTree → IO Bool :=
go none
where go ci?
| .context ci t => go ci t
| .node i cs =>
if let (some ci, .ofTermInfo ti) := (ci?, i) then do
let expr ← ti.runMetaM ci (instantiateMVars ti.expr)
return expr.hasSorry
-- we assume that `cs` are subterms of `ti.expr` and
-- thus do not have to be checked as well
else
cs.anyM (go ci?)
| _ => return false
end Lean.Elab
|
dee76aa743f842b4e68d96c3e3cd310f0f3560f4
|
8e6cad62ec62c6c348e5faaa3c3f2079012bdd69
|
/src/geometry/manifold/smooth_manifold_with_corners.lean
|
d6dcffecaffa90938f8bfe0a15deb74a80636355
|
[
"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
| 38,627
|
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 analysis.calculus.times_cont_diff
import geometry.manifold.charted_space
/-!
# Smooth manifolds (possibly with boundary or corners)
A smooth manifold is a manifold modelled on a normed vector space, or a subset like a
half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps.
We define a model with corners as a map `I : H → E` embedding nicely the topological space `H` in
the vector space `E` (or more precisely as a structure containing all the relevant properties).
Given such a model with corners `I` on `(E, H)`, we define the groupoid of local
homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : with_top ℕ`).
With this groupoid at hand and the general machinery of charted spaces, we thus get the notion
of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a
specific type class for `C^∞` manifolds as these are the most commonly used.
## Main definitions
* `model_with_corners 𝕜 E H` :
a structure containing informations on the way a space `H` embeds in a
model vector space E over the field `𝕜`. This is all that is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
* `model_with_corners_self 𝕜 E` :
trivial model with corners structure on the space `E` embedded in itself by the identity.
* `times_cont_diff_groupoid n I` :
when `I` is a model with corners on `(𝕜, E, H)`, this is the groupoid of local homeos of `H`
which are of class `C^n` over the normed field `𝕜`, when read in `E`.
* `smooth_manifold_with_corners I M` :
a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of
coordinates with respect to the model with corners `I` on `(𝕜, E, H)`. This type class is just
a shortcut for `has_groupoid M (times_cont_diff_groupoid ∞ I)`.
* `ext_chart_at I x`:
in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`,
but often we may want to use their `E`-valued version, obtained by composing the charts with `I`.
Since the target is in general not open, we can not register them as local homeomorphisms, but
we register them as local equivs. `ext_chart_at I x` is the canonical such local equiv around `x`.
As specific examples of models with corners, we define (in the file `real_instances.lean`)
* `model_with_corners_self ℝ (euclidean_space (fin n))` for the model space used to define
`n`-dimensional real manifolds without boundary (with notation `𝓡 n` in the locale `manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary (with notation `𝓡∂ n` in the locale
`manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary,
one could use
`variables {n : ℕ} {M : Type*} [topological_space M] [charted_space (euclidean_space (fin n)) M]
[smooth_manifold_with_corners (𝓡 n) M]`.
However, this is not the recommended way: a theorem proved using this assumption would not apply
for instance to the tangent space of such a manifold, which is modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin n))` and not on `euclidean_space (fin (2 * n))`!
In the same way, it would not apply to product manifolds, modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin m))`.
The right invocation does not focus on one specific construction, but on all constructions sharing
the right properties, like
`variables {E : Type*} [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
{I : model_with_corners ℝ E E} [I.boundaryless]
{M : Type*} [topological_space M] [charted_space E M] [smooth_manifold_with_corners I M]`
Here, `I.boundaryless` is a typeclass property ensuring that there is no boundary (this is for
instance the case for `model_with_corners_self`, or products of these). Note that one could consider
as a natural assumption to only use the trivial model with corners `model_with_corners_self ℝ E`,
but again in product manifolds the natural model with corners will not be this one but the product
one (and they are not defeq as `(λp : E × F, (p.1, p.2))` is not defeq to the identity). So, it is
important to use the above incantation to maximize the applicability of theorems.
## Implementation notes
We want to talk about manifolds modelled on a vector space, but also on manifolds with
boundary, modelled on a half space (or even manifolds with corners). For the latter examples,
we still want to define smooth functions, tangent bundles, and so on. As smooth functions are
well defined on vector spaces or subsets of these, one could take for model space a subtype of a
vector space. With the drawback that the whole vector space itself (which is the most basic
example) is not directly a subtype of itself: the inclusion of `univ : set E` in `set E` would
show up in the definition, instead of `id`.
A good abstraction covering both cases it to have a vector
space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper
half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or
`subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a
model with corners, and we encompass all the relevant properties (in particular the fact that the
image of `H` in `E` should have unique differentials) in the definition of `model_with_corners`.
We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but
later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal
with `C^k` functions as there would be additional conditions `k ≤ n` everywhere. Since one deals
almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that
one could revisit later if needed. `C^k` manifolds are still available, but they should be called
using `has_groupoid M (times_cont_diff_groupoid k I)` where `I` is the model with corners.
I have considered using the model with corners `I` as a typeclass argument, possibly `out_param`, to
get lighter notations later on, but it did not turn out right, as on `E × F` there are two natural
model with corners, the trivial (identity) one, and the product one, and they are not defeq and one
needs to indicate to Lean which one we want to use.
This means that when talking on objects on manifolds one will most often need to specify the model
with corners one is using. For instance, the tangent bundle will be `tangent_bundle I M` and the
derivative will be `mfderiv I I' f`, instead of the more natural notations `tangent_bundle 𝕜 M` and
`mfderiv 𝕜 f` (the field has to be explicit anyway, as some manifolds could be considered both as
real and complex manifolds).
-/
noncomputable theory
universes u v w u' v' w'
open set filter
open_locale manifold filter topological_space
localized "notation `∞` := (⊤ : with_top ℕ)" in manifold
section model_with_corners
/-! ### Models with corners. -/
/-- A structure containing informations on the way a space `H` embeds in a
model vector space `E` over the field `𝕜`. This is all what is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
-/
@[nolint has_inhabited_instance]
structure model_with_corners (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
extends local_equiv H E :=
(source_eq : source = univ)
(unique_diff' : unique_diff_on 𝕜 (range to_fun))
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
attribute [simp, mfld_simps] model_with_corners.source_eq
/-- A vector space is a model with corners. -/
def model_with_corners_self (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : model_with_corners 𝕜 E E :=
{ to_fun := id,
inv_fun := id,
source := univ,
target := univ,
source_eq := rfl,
map_source' := λ_ _, mem_univ _,
map_target' := λ_ _, mem_univ _,
left_inv' := λ_ _, rfl,
right_inv' := λ_ _, rfl,
unique_diff' := by { rw range_id, exact unique_diff_on_univ },
continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id }
localized "notation `𝓘(` 𝕜 `, ` E `)` := model_with_corners_self 𝕜 E" in manifold
localized "notation `𝓘(` 𝕜 `)` := model_with_corners_self 𝕜 𝕜" in manifold
section
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
namespace model_with_corners
instance : has_coe_to_fun (model_with_corners 𝕜 E H) := ⟨_, λ e, e.to_fun⟩
/-- The inverse to a model with corners, only registered as a local equiv. -/
protected def symm : local_equiv E H := I.to_local_equiv.symm
/- Register a few lemmas to make sure that `simp` puts expressions in normal form -/
@[simp, mfld_simps] lemma to_local_equiv_coe : (I.to_local_equiv : H → E) = I :=
rfl
@[simp, mfld_simps] lemma mk_coe (e : local_equiv H E) (a b c d) :
((model_with_corners.mk e a b c d : model_with_corners 𝕜 E H) : H → E) = (e : H → E) := rfl
@[simp, mfld_simps] lemma to_local_equiv_coe_symm : (I.to_local_equiv.symm : E → H) = I.symm := rfl
@[simp, mfld_simps] lemma mk_symm (e : local_equiv H E) (a b c d) :
(model_with_corners.mk e a b c d : model_with_corners 𝕜 E H).symm = e.symm :=
rfl
protected lemma unique_diff : unique_diff_on 𝕜 (range I) := I.unique_diff'
@[continuity] protected lemma continuous : continuous I := I.continuous_to_fun
@[continuity] lemma continuous_symm : continuous I.symm := I.continuous_inv_fun
@[simp, mfld_simps] lemma target_eq : I.target = range (I : H → E) :=
by { rw [← image_univ, ← I.source_eq], exact (I.to_local_equiv.image_source_eq_target).symm }
@[simp, mfld_simps] protected lemma left_inv (x : H) : I.symm (I x) = x :=
by { refine I.left_inv' _, simp }
protected lemma left_inverse : function.left_inverse I.symm I := I.left_inv
@[simp, mfld_simps] lemma symm_comp_self : I.symm ∘ I = id :=
I.left_inverse.comp_eq_id
protected lemma right_inv_on : right_inv_on I.symm I (range I) :=
I.left_inverse.right_inv_on_range
@[simp, mfld_simps] protected lemma right_inv {x : E} (hx : x ∈ range I) : I (I.symm x) = x :=
I.right_inv_on hx
protected lemma image_eq (s : set H) : I '' s = I.symm ⁻¹' s ∩ range I :=
begin
refine (I.to_local_equiv.image_eq_target_inter_inv_preimage _).trans _,
{ rw I.source_eq, exact subset_univ _ },
{ rw [inter_comm, I.target_eq, I.to_local_equiv_coe_symm] }
end
protected lemma closed_embedding : closed_embedding I :=
I.left_inverse.closed_embedding I.continuous_symm I.continuous
lemma closed_range : is_closed (range I) :=
I.closed_embedding.closed_range
lemma map_nhds_eq (x : H) : map I (𝓝 x) = 𝓝[range I] (I x) :=
I.closed_embedding.to_embedding.map_nhds_eq x
lemma image_mem_nhds_within {x : H} {s : set H} (hs : s ∈ 𝓝 x) :
I '' s ∈ 𝓝[range I] (I x) :=
I.map_nhds_eq x ▸ image_mem_map hs
lemma symm_map_nhds_within_range (x : H) :
map I.symm (𝓝[range I] (I x)) = 𝓝 x :=
by rw [← I.map_nhds_eq, map_map, I.symm_comp_self, map_id]
lemma unique_diff_preimage {s : set H} (hs : is_open s) :
unique_diff_on 𝕜 (I.symm ⁻¹' s ∩ range I) :=
by { rw inter_comm, exact I.unique_diff.inter (hs.preimage I.continuous_inv_fun) }
lemma unique_diff_preimage_source {β : Type*} [topological_space β]
{e : local_homeomorph H β} : unique_diff_on 𝕜 (I.symm ⁻¹' (e.source) ∩ range I) :=
I.unique_diff_preimage e.open_source
lemma unique_diff_at_image {x : H} : unique_diff_within_at 𝕜 (range I) (I x) :=
I.unique_diff _ (mem_range_self _)
protected lemma locally_compact [locally_compact_space E] (I : model_with_corners 𝕜 E H) :
locally_compact_space H :=
begin
have : ∀ (x : H), (𝓝 x).has_basis (λ s, s ∈ 𝓝 (I x) ∧ is_compact s)
(λ s, I.symm '' (s ∩ range ⇑I)),
{ intro x,
rw ← I.symm_map_nhds_within_range,
exact ((compact_basis_nhds (I x)).inf_principal _).map _ },
refine locally_compact_space_of_has_basis this _,
rintro x s ⟨-, hsc⟩,
exact (hsc.inter_right I.closed_range).image I.continuous_symm
end
end model_with_corners
section
variables (𝕜 E)
/-- In the trivial model with corners, the associated local equiv is the identity. -/
@[simp, mfld_simps] lemma model_with_corners_self_local_equiv :
(model_with_corners_self 𝕜 E).to_local_equiv = local_equiv.refl E := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe :
(model_with_corners_self 𝕜 E : E → E) = id := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe_symm :
((model_with_corners_self 𝕜 E).symm : E → E) = id := rfl
end
end
section model_with_corners_prod
/-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with
corners `I.prod I'` on `(E × E', H × H')`. This appears in particular for the manifold structure on
the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on `(E × E, H × E)`. -/
def model_with_corners.prod
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H)
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') : model_with_corners 𝕜 (E × E') (model_prod H H') :=
{ to_fun := λ p, (I p.1, I' p.2),
inv_fun := λ p, (I.symm p.1, I'.symm p.2),
source := (univ : set (H × H')),
target := set.prod (range I) (range I'),
map_source' := λ ⟨x, x'⟩ _, by simp [-mem_range, mem_range_self],
map_target' := λ ⟨x, x'⟩ _, mem_univ _,
left_inv' := λ ⟨x, x'⟩ _, by simp,
right_inv' := λ ⟨x, x'⟩ ⟨hx, hx'⟩, by simp [hx, hx'],
source_eq := rfl,
unique_diff' := begin
have : range (λ(p : model_prod H H'), (I p.1, I' p.2)) = set.prod (range I) (range I'),
by { dsimp [model_prod], rw ← prod_range_range_eq },
rw this,
exact unique_diff_on.prod I.unique_diff I'.unique_diff,
end,
continuous_to_fun := (continuous.comp I.continuous_to_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_to_fun continuous_snd),
continuous_inv_fun := (continuous.comp I.continuous_inv_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_inv_fun continuous_snd) }
/-- Special case of product model with corners, which is trivial on the second factor. This shows up
as the model to tangent bundles. -/
@[reducible] def model_with_corners.tangent
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) : model_with_corners 𝕜 (E × E) (model_prod H E) :=
I.prod (model_with_corners_self 𝕜 E)
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F : Type*} [normed_group F] [normed_space 𝕜 F] {F' : Type*} [normed_group F'] [normed_space 𝕜 F']
{H : Type*} [topological_space H] {H' : Type*} [topological_space H']
{G : Type*} [topological_space G] {G' : Type*} [topological_space G']
{I : model_with_corners 𝕜 E H} {J : model_with_corners 𝕜 F G}
@[simp, mfld_simps] lemma model_with_corners_prod_to_local_equiv :
(I.prod J).to_local_equiv = (I.to_local_equiv).prod (J.to_local_equiv) :=
begin
ext1 x,
{ refl, },
{ intro x, refl, },
{ simp only [set.univ_prod_univ, model_with_corners.source_eq, local_equiv.prod_source], }
end
@[simp, mfld_simps] lemma model_with_corners_prod_coe
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
(I.prod I' : _ × _ → _ × _) = prod.map I I' := rfl
@[simp, mfld_simps] lemma model_with_corners_prod_coe_symm
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
((I.prod I').symm : _ × _ → _ × _) = prod.map I.symm I'.symm := rfl
end model_with_corners_prod
section boundaryless
/-- Property ensuring that the model with corners `I` defines manifolds without boundary. -/
class model_with_corners.boundaryless {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H) : Prop :=
(range_eq_univ : range I = univ)
/-- The trivial model with corners has no boundary -/
instance model_with_corners_self_boundaryless (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : (model_with_corners_self 𝕜 E).boundaryless :=
⟨by simp⟩
/-- If two model with corners are boundaryless, their product also is -/
instance model_with_corners.range_eq_univ_prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) [I.boundaryless]
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') [I'.boundaryless] :
(I.prod I').boundaryless :=
begin
split,
dsimp [model_with_corners.prod, model_prod],
rw [← prod_range_range_eq, model_with_corners.boundaryless.range_eq_univ,
model_with_corners.boundaryless.range_eq_univ, univ_prod_univ]
end
end boundaryless
section times_cont_diff_groupoid
/-! ### Smooth functions on models with corners -/
variables {m n : with_top ℕ} {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
variable (n)
/-- Given a model with corners `(E, H)`, we define the groupoid of `C^n` transformations of `H` as
the maps that are `C^n` when read in `E` through `I`. -/
def times_cont_diff_groupoid : structure_groupoid H :=
pregroupoid.groupoid
{ property := λf s, times_cont_diff_on 𝕜 n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
comp := λf g u v hf hg hu hv huv, begin
have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ (I ∘ f ∘ I.symm),
by { ext x, simp },
rw this,
apply times_cont_diff_on.comp hg _,
{ rintros x ⟨hx1, hx2⟩,
simp only with mfld_simps at ⊢ hx1,
exact hx1.2 },
{ refine hf.mono _,
rintros x ⟨hx1, hx2⟩,
exact ⟨hx1.1, hx2⟩ }
end,
id_mem := begin
apply times_cont_diff_on.congr (times_cont_diff_id.times_cont_diff_on),
rintros x ⟨hx1, hx2⟩,
rcases mem_range.1 hx2 with ⟨y, hy⟩,
rw ← hy,
simp only with mfld_simps,
end,
locality := λf u hu H, begin
apply times_cont_diff_on_of_locally_times_cont_diff_on,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rcases H x hy1 with ⟨v, v_open, xv, hv⟩,
have : ((I.symm ⁻¹' (u ∩ v)) ∩ (range I))
= ((I.symm ⁻¹' u) ∩ (range I) ∩ I.symm ⁻¹' v),
{ rw [preimage_inter, inter_assoc, inter_assoc],
congr' 1,
rw inter_comm },
rw this at hv,
exact ⟨I.symm ⁻¹' v, v_open.preimage I.continuous_symm, by simpa, hv⟩
end,
congr := λf g u hu fg hf, begin
apply hf.congr,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rw fg _ hy1
end }
variable {n}
/-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when
`m ≤ n` -/
lemma times_cont_diff_groupoid_le (h : m ≤ n) :
times_cont_diff_groupoid n I ≤ times_cont_diff_groupoid m I :=
begin
rw [times_cont_diff_groupoid, times_cont_diff_groupoid],
apply groupoid_of_pregroupoid_le,
assume f s hfs,
exact times_cont_diff_on.of_le hfs h
end
/-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all
local homeomorphisms -/
lemma times_cont_diff_groupoid_zero_eq :
times_cont_diff_groupoid 0 I = continuous_groupoid H :=
begin
apply le_antisymm le_top,
assume u hu,
-- we have to check that every local homeomorphism belongs to `times_cont_diff_groupoid 0 I`,
-- by unfolding its definition
change u ∈ times_cont_diff_groupoid 0 I,
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
simp only [times_cont_diff_on_zero],
split,
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_to_fun I.continuous_symm.continuous_on
(inter_subset_left _ _) },
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_inv_fun I.continuous_inv_fun.continuous_on
(inter_subset_left _ _) },
end
variable (n)
/-- An identity local homeomorphism belongs to the `C^n` groupoid. -/
lemma of_set_mem_times_cont_diff_groupoid {s : set H} (hs : is_open s) :
local_homeomorph.of_set s hs ∈ times_cont_diff_groupoid n I :=
begin
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
suffices h : times_cont_diff_on 𝕜 n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
by simp [h],
have : times_cont_diff_on 𝕜 n id (univ : set E) :=
times_cont_diff_id.times_cont_diff_on,
exact this.congr_mono (λ x hx, by simp [hx.2]) (subset_univ _)
end
/-- The composition of a local homeomorphism from `H` to `M` and its inverse belongs to
the `C^n` groupoid. -/
lemma symm_trans_mem_times_cont_diff_groupoid (e : local_homeomorph M H) :
e.symm.trans e ∈ times_cont_diff_groupoid n I :=
begin
have : e.symm.trans e ≈ local_homeomorph.of_set e.target e.open_target :=
local_homeomorph.trans_symm_self _,
exact structure_groupoid.eq_on_source _
(of_set_mem_times_cont_diff_groupoid n I e.open_target) this
end
variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {H' : Type*} [topological_space H']
/-- The product of two smooth local homeomorphisms is smooth. -/
lemma times_cont_diff_groupoid_prod
{I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'}
{e : local_homeomorph H H} {e' : local_homeomorph H' H'}
(he : e ∈ times_cont_diff_groupoid ⊤ I) (he' : e' ∈ times_cont_diff_groupoid ⊤ I') :
e.prod e' ∈ times_cont_diff_groupoid ⊤ (I.prod I') :=
begin
cases he with he he_symm,
cases he' with he' he'_symm,
simp only at he he_symm he' he'_symm,
split;
simp only [local_equiv.prod_source, local_homeomorph.prod_to_local_equiv],
{ have h3 := times_cont_diff_on.prod_map he he',
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, },
{ have h3 := times_cont_diff_on.prod_map he_symm he'_symm,
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, }
end
/-- The `C^n` groupoid is closed under restriction. -/
instance : closed_under_restriction (times_cont_diff_groupoid n I) :=
(closed_under_restriction_iff_id_le _).mpr
begin
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
apply (times_cont_diff_groupoid n I).eq_on_source' _ _ _ hes,
exact of_set_mem_times_cont_diff_groupoid n I hs,
end
end times_cont_diff_groupoid
end model_with_corners
section smooth_manifold_with_corners
/-! ### Smooth manifolds with corners -/
set_option old_structure_cmd true
/-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a
field `𝕜` and with infinite smoothness to simplify typeclass search and statements later on. -/
@[ancestor has_groupoid]
class smooth_manifold_with_corners {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M] extends
has_groupoid M (times_cont_diff_groupoid ∞ I) : Prop
lemma smooth_manifold_with_corners_of_times_cont_diff_on
{𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
(h : ∀ (e e' : local_homeomorph M H), e ∈ atlas H M → e' ∈ atlas H M →
times_cont_diff_on 𝕜 ⊤ (I ∘ (e.symm ≫ₕ e') ∘ I.symm)
(I.symm ⁻¹' (e.symm ≫ₕ e').source ∩ range I)) :
smooth_manifold_with_corners I M :=
{ compatible :=
begin
haveI : has_groupoid M (times_cont_diff_groupoid ∞ I) := has_groupoid_of_pregroupoid _ h,
apply structure_groupoid.compatible,
end }
/-- For any model with corners, the model space is a smooth manifold -/
instance model_space_smooth {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
{I : model_with_corners 𝕜 E H} :
smooth_manifold_with_corners I H := { .. has_groupoid_model_space _ _ }
end smooth_manifold_with_corners
namespace smooth_manifold_with_corners
/- We restate in the namespace `smooth_manifolds_with_corners` some lemmas that hold for general
charted space with a structure groupoid, avoiding the need to specify the groupoid
`times_cont_diff_groupoid ∞ I` explicitly. -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
/-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the
model with corners `I`. -/
def maximal_atlas := (times_cont_diff_groupoid ∞ I).maximal_atlas M
variable {M}
lemma mem_maximal_atlas_of_mem_atlas [smooth_manifold_with_corners I M]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ maximal_atlas I M :=
structure_groupoid.mem_maximal_atlas_of_mem_atlas _ he
lemma chart_mem_maximal_atlas [smooth_manifold_with_corners I M] (x : M) :
chart_at H x ∈ maximal_atlas I M :=
structure_groupoid.chart_mem_maximal_atlas _ x
variable {I}
lemma compatible_of_mem_maximal_atlas
{e e' : local_homeomorph M H} (he : e ∈ maximal_atlas I M) (he' : e' ∈ maximal_atlas I M) :
e.symm.trans e' ∈ times_cont_diff_groupoid ∞ I :=
structure_groupoid.compatible_of_mem_maximal_atlas he he'
/-- The product of two smooth manifolds with corners is naturally a smooth manifold with corners. -/
instance prod {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
(M' : Type*) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] :
smooth_manifold_with_corners (I.prod I') (M×M') :=
{ compatible :=
begin
rintros f g ⟨f1, hf1, f2, hf2, hf⟩ ⟨g1, hg1, g2, hg2, hg⟩,
rw [hf, hg, local_homeomorph.prod_symm, local_homeomorph.prod_trans],
have h1 := has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) hf1 hg1,
have h2 := has_groupoid.compatible (times_cont_diff_groupoid ⊤ I') hf2 hg2,
exact times_cont_diff_groupoid_prod h1 h2,
end }
end smooth_manifold_with_corners
section extended_charts
open_locale topological_space
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M]
(x : M) {s t : set M}
/-!
### Extended charts
In a smooth manifold with corners, the model space is the space `H`. However, we will also
need to use extended charts taking values in the model vector space `E`. These extended charts are
not `local_homeomorph` as the target is not open in `E` in general, but we can still register them
as `local_equiv`.
-/
/-- The preferred extended chart on a manifold with corners around a point `x`, from a neighborhood
of `x` to the model vector space. -/
@[simp, mfld_simps] def ext_chart_at (x : M) : local_equiv M E :=
(chart_at H x).to_local_equiv.trans I.to_local_equiv
lemma ext_chart_at_coe : ⇑(ext_chart_at I x) = I ∘ chart_at H x := rfl
lemma ext_chart_at_coe_symm :
⇑(ext_chart_at I x).symm = (chart_at H x).symm ∘ I.symm := rfl
lemma ext_chart_at_source : (ext_chart_at I x).source = (chart_at H x).source :=
by rw [ext_chart_at, local_equiv.trans_source, I.source_eq, preimage_univ, inter_univ]
lemma ext_chart_at_open_source : is_open (ext_chart_at I x).source :=
by { rw ext_chart_at_source, exact (chart_at H x).open_source }
lemma mem_ext_chart_source : x ∈ (ext_chart_at I x).source :=
by simp only [ext_chart_at_source, mem_chart_source]
lemma ext_chart_at_to_inv :
(ext_chart_at I x).symm ((ext_chart_at I x) x) = x :=
(ext_chart_at I x).left_inv (mem_ext_chart_source I x)
lemma ext_chart_at_source_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝 x' :=
mem_nhds_sets (ext_chart_at_open_source I x) h
lemma ext_chart_at_source_mem_nhds : (ext_chart_at I x).source ∈ 𝓝 x :=
ext_chart_at_source_mem_nhds' I x (mem_ext_chart_source I x)
lemma ext_chart_at_source_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝[s] x' :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds' I x h)
lemma ext_chart_at_source_mem_nhds_within :
(ext_chart_at I x).source ∈ 𝓝[s] x :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds I x)
lemma ext_chart_at_continuous_on :
continuous_on (ext_chart_at I x) (ext_chart_at I x).source :=
begin
refine I.continuous.comp_continuous_on _,
rw ext_chart_at_source,
exact (chart_at H x).continuous_on
end
lemma ext_chart_at_continuous_at' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x) x' :=
(ext_chart_at_continuous_on I x).continuous_at $ ext_chart_at_source_mem_nhds' I x h
lemma ext_chart_at_continuous_at : continuous_at (ext_chart_at I x) x :=
ext_chart_at_continuous_at' _ _ (mem_ext_chart_source I x)
lemma ext_chart_at_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
begin
apply continuous_on.comp (chart_at H x).continuous_on_symm I.continuous_symm.continuous_on,
simp [ext_chart_at, local_equiv.trans_target]
end
lemma ext_chart_at_map_nhds' {x y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝 y) = 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [ext_chart_at_coe, (∘), ← I.map_nhds_eq, ← (chart_at H x).map_nhds_eq, map_map],
rwa ext_chart_at_source at hy
end
lemma ext_chart_at_map_nhds :
map (ext_chart_at I x) (𝓝 x) = 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds' I $ mem_ext_chart_source I x
lemma ext_chart_at_target_mem_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [← local_equiv.image_source_eq_target, ← ext_chart_at_map_nhds' I hy],
exact image_mem_map (ext_chart_at_source_mem_nhds' _ _ hy)
end
lemma ext_chart_at_target_mem_nhds_within :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_target_mem_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_target_subset_range : (ext_chart_at I x).target ⊆ range I :=
by simp only with mfld_simps
lemma nhds_within_ext_chart_target_eq' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
𝓝[(ext_chart_at I x).target] (ext_chart_at I x y) =
𝓝[range I] (ext_chart_at I x y) :=
(nhds_within_mono _ (ext_chart_at_target_subset_range _ _)).antisymm $
nhds_within_le_of_mem (ext_chart_at_target_mem_nhds_within' _ _ hy)
lemma nhds_within_ext_chart_target_eq :
𝓝[(ext_chart_at I x).target] ((ext_chart_at I x) x) =
𝓝[range I] ((ext_chart_at I x) x) :=
nhds_within_ext_chart_target_eq' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_at_symm'' {y : E} (h : y ∈ (ext_chart_at I x).target) :
continuous_at (ext_chart_at I x).symm y :=
continuous_at.comp ((chart_at H x).continuous_at_symm h.2) (I.continuous_symm.continuous_at)
lemma ext_chart_continuous_at_symm' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x).symm (ext_chart_at I x x') :=
ext_chart_continuous_at_symm'' I _ $ (ext_chart_at I x).map_source h
lemma ext_chart_continuous_at_symm :
continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x) :=
ext_chart_continuous_at_symm' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
λ y hy, (ext_chart_continuous_at_symm'' _ _ hy).continuous_within_at
lemma ext_chart_at_map_nhds_within_eq_image' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x y) :=
by set e := ext_chart_at I x;
calc map e (𝓝[s] y) = map e (𝓝[e.source ∩ s] y) :
congr_arg (map e) (nhds_within_inter_of_mem (ext_chart_at_source_mem_nhds_within' I x hy)).symm
... = 𝓝[e '' (e.source ∩ s)] (e y) :
((ext_chart_at I x).left_inv_on.mono $ inter_subset_left _ _).map_nhds_within_eq
((ext_chart_at I x).left_inv hy)
(ext_chart_continuous_at_symm' I x hy).continuous_within_at
(ext_chart_at_continuous_at' I x hy).continuous_within_at
lemma ext_chart_at_map_nhds_within_eq_image :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within_eq_image' I x (mem_ext_chart_source I x)
lemma ext_chart_at_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y) :=
by rw [ext_chart_at_map_nhds_within_eq_image' I x hy, nhds_within_inter,
← nhds_within_ext_chart_target_eq' _ _ hy, ← nhds_within_inter,
(ext_chart_at I x).image_source_inter_eq', inter_comm]
lemma ext_chart_at_map_nhds_within :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y)) = 𝓝[s] y :=
begin
rw [← ext_chart_at_map_nhds_within' I x hy, map_map, map_congr, map_id],
exact (ext_chart_at I x).left_inv_on.eq_on.eventually_eq_of_mem
(ext_chart_at_source_mem_nhds_within' _ _ hy)
end
lemma ext_chart_at_symm_map_nhds_within_range' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x y)) = 𝓝 y :=
by rw [← nhds_within_univ, ← ext_chart_at_symm_map_nhds_within' I x hy, preimage_univ, univ_inter]
lemma ext_chart_at_symm_map_nhds_within :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x)) = 𝓝[s] x :=
ext_chart_at_symm_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within_range :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x x)) = 𝓝 x :=
ext_chart_at_symm_map_nhds_within_range' I x (mem_ext_chart_source I x)
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
in the source is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source)
(ht : t ∈ 𝓝[s] x') :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x') :=
by rwa [← ext_chart_at_symm_map_nhds_within' I x h, mem_map] at ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of the
base point is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within (ht : t ∈ 𝓝[s] x) :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x) :=
ext_chart_preimage_mem_nhds_within' I x (mem_ext_chart_source I x) ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
is a neighborhood of the preimage. -/
lemma ext_chart_preimage_mem_nhds (ht : t ∈ 𝓝 x) :
(ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 ((ext_chart_at I x) x) :=
begin
apply (ext_chart_continuous_at_symm I x).preimage_mem_nhds,
rwa (ext_chart_at I x).left_inv (mem_ext_chart_source _ _)
end
/-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to
bring it into a convenient form to apply derivative lemmas. -/
lemma ext_chart_preimage_inter_eq :
((ext_chart_at I x).symm ⁻¹' (s ∩ t) ∩ range I)
= ((ext_chart_at I x).symm ⁻¹' s ∩ range I) ∩ ((ext_chart_at I x).symm ⁻¹' t) :=
by mfld_set_tac
end extended_charts
/-- In the case of the manifold structure on a vector space, the extended charts are just the
identity.-/
lemma ext_chart_model_space_eq_id (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (x : E) :
ext_chart_at (model_with_corners_self 𝕜 E) x = local_equiv.refl E :=
by simp only with mfld_simps
|
ecfd0f8b453647e6058256613a4cd51e1f6b9502
|
9028d228ac200bbefe3a711342514dd4e4458bff
|
/src/algebra/invertible.lean
|
a72964b00257f478134a77018126873901ed4c3c
|
[
"Apache-2.0"
] |
permissive
|
mcncm/mathlib
|
8d25099344d9d2bee62822cb9ed43aa3e09fa05e
|
fde3d78cadeec5ef827b16ae55664ef115e66f57
|
refs/heads/master
| 1,672,743,316,277
| 1,602,618,514,000
| 1,602,618,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 9,097
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Anne Baanen
A typeclass for the two-sided multiplicative inverse.
-/
import algebra.char_zero
import algebra.char_p
/-!
# Invertible elements
This file defines a typeclass `invertible a` for elements `a` with a
multiplicative inverse.
The intent of the typeclass is to provide a way to write e.g. `⅟2` in a ring
like `ℤ[1/2]` where some inverses exist but there is no general `⁻¹` operator;
or to specify that a field has characteristic `≠ 2`.
It is the `Type`-valued analogue to the `Prop`-valued `is_unit`.
This file also includes some instances of `invertible` for specific numbers in
characteristic zero. Some more cases are given as a `def`, to be included only
when needed. To construct instances for concrete numbers,
`invertible_of_nonzero` is a useful definition.
## Notation
* `⅟a` is `invertible.inv_of a`, the inverse of `a`
## Implementation notes
The `invertible` class lives in `Type`, not `Prop`, to make computation easier.
If multiplication is associative, `invertible` is a subsingleton anyway.
The `simp` normal form tries to normalize `⅟a` to `a ⁻¹`. Otherwise, it pushes
`⅟` inside the expression as much as possible.
## Tags
invertible, inverse element, inv_of, a half, one half, a third, one third, ½, ⅓
-/
universes u
variables {α : Type u}
/-- `invertible a` gives a two-sided multiplicative inverse of `a`. -/
class invertible [has_mul α] [has_one α] (a : α) : Type u :=
(inv_of : α) (inv_of_mul_self : inv_of * a = 1) (mul_inv_of_self : a * inv_of = 1)
-- This notation has the same precedence as `has_inv.inv`.
notation `⅟`:1034 := invertible.inv_of
@[simp]
lemma inv_of_mul_self [has_mul α] [has_one α] (a : α) [invertible a] : ⅟a * a = 1 :=
invertible.inv_of_mul_self
@[simp]
lemma mul_inv_of_self [has_mul α] [has_one α] (a : α) [invertible a] : a * ⅟a = 1 :=
invertible.mul_inv_of_self
@[simp]
lemma mul_inv_of_mul_self_cancel [monoid α] (a b : α) [invertible b] : a * ⅟b * b = a :=
by simp [mul_assoc]
@[simp]
lemma mul_mul_inv_of_self_cancel [monoid α] (a b : α) [invertible b] : a * b * ⅟b = a :=
by simp [mul_assoc]
lemma inv_of_eq_right_inv [monoid α] {a b : α} [invertible a] (hac : a * b = 1) : ⅟a = b :=
left_inv_eq_right_inv (inv_of_mul_self _) hac
lemma invertible_unique {α : Type u} [monoid α] (a b : α) (h : a = b) [invertible a] [invertible b] :
⅟a = ⅟b :=
by { apply inv_of_eq_right_inv, rw [h, mul_inv_of_self], }
instance [monoid α] (a : α) : subsingleton (invertible a) :=
⟨ λ ⟨b, hba, hab⟩ ⟨c, hca, hac⟩, by { congr, exact left_inv_eq_right_inv hba hac } ⟩
/-- An `invertible` element is a unit. -/
def unit_of_invertible [monoid α] (a : α) [invertible a] : units α :=
{ val := a,
inv := ⅟a,
val_inv := by simp,
inv_val := by simp, }
@[simp] lemma unit_of_invertible_val [monoid α] (a : α) [invertible a] :
(unit_of_invertible a : α) = a := rfl
@[simp] lemma unit_of_invertible_inv [monoid α] (a : α) [invertible a] :
(↑(unit_of_invertible a)⁻¹ : α) = ⅟a := rfl
lemma is_unit_of_invertible [monoid α] (a : α) [invertible a] : is_unit a :=
⟨unit_of_invertible a, rfl⟩
/-- Each element of a group is invertible. -/
def invertible_of_group [group α] (a : α) : invertible a :=
⟨a⁻¹, inv_mul_self a, mul_inv_self a⟩
@[simp] lemma inv_of_eq_group_inv [group α] (a : α) [invertible a] : ⅟a = a⁻¹ :=
inv_of_eq_right_inv (mul_inv_self a)
/-- `1` is the inverse of itself -/
def invertible_one [monoid α] : invertible (1 : α) :=
⟨ 1, mul_one _, one_mul _ ⟩
@[simp] lemma inv_of_one [monoid α] [invertible (1 : α)] : ⅟(1 : α) = 1 :=
inv_of_eq_right_inv (mul_one _)
/-- `-⅟a` is the inverse of `-a` -/
def invertible_neg [ring α] (a : α) [invertible a] : invertible (-a) :=
⟨ -⅟a, by simp, by simp ⟩
@[simp] lemma inv_of_neg [ring α] (a : α) [invertible a] [invertible (-a)] : ⅟(-a) = -⅟a :=
inv_of_eq_right_inv (by simp)
/-- `a` is the inverse of `⅟a`. -/
instance invertible_inv_of [has_one α] [has_mul α] {a : α} [invertible a] : invertible (⅟a) :=
⟨ a, mul_inv_of_self a, inv_of_mul_self a ⟩
@[simp] lemma inv_of_inv_of [monoid α] {a : α} [invertible a] [invertible (⅟a)] :
⅟(⅟a) = a :=
inv_of_eq_right_inv (inv_of_mul_self _)
/-- `⅟b * ⅟a` is the inverse of `a * b` -/
def invertible_mul [monoid α] (a b : α) [invertible a] [invertible b] : invertible (a * b) :=
⟨ ⅟b * ⅟a, by simp [←mul_assoc], by simp [←mul_assoc] ⟩
@[simp]
lemma inv_of_mul [monoid α] (a b : α) [invertible a] [invertible b] [invertible (a * b)] :
⅟(a * b) = ⅟b * ⅟a :=
inv_of_eq_right_inv (by simp [←mul_assoc])
/--
If `r` is invertible and `s = r`, then `s` is invertible.
-/
def invertible.copy [monoid α] {r : α} (hr : invertible r) (s : α) (hs : s = r) : invertible s :=
{ inv_of := ⅟r,
inv_of_mul_self := by rw [hs, inv_of_mul_self],
mul_inv_of_self := by rw [hs, mul_inv_of_self] }
lemma commute_inv_of {M : Type*} [has_one M] [has_mul M] (m : M) [invertible m] :
commute m (⅟m) :=
calc m * ⅟m = 1 : mul_inv_of_self m
... = ⅟ m * m : (inv_of_mul_self m).symm
instance invertible_pow {M : Type*} [monoid M] (m : M) [invertible m] (n : ℕ) :
invertible (m ^ n) :=
{ inv_of := ⅟ m ^ n,
inv_of_mul_self := by rw [← (commute_inv_of m).symm.mul_pow, inv_of_mul_self, one_pow],
mul_inv_of_self := by rw [← (commute_inv_of m).mul_pow, mul_inv_of_self, one_pow] }
section group_with_zero
variable [group_with_zero α]
lemma nonzero_of_invertible (a : α) [invertible a] : a ≠ 0 :=
λ ha, zero_ne_one $ calc 0 = ⅟a * a : by simp [ha]
... = 1 : inv_of_mul_self a
/-- `a⁻¹` is an inverse of `a` if `a ≠ 0` -/
def invertible_of_nonzero {a : α} (h : a ≠ 0) : invertible a :=
⟨ a⁻¹, inv_mul_cancel h, mul_inv_cancel h ⟩
@[simp] lemma inv_of_eq_inv (a : α) [invertible a] : ⅟a = a⁻¹ :=
inv_of_eq_right_inv (mul_inv_cancel (nonzero_of_invertible a))
@[simp] lemma inv_mul_cancel_of_invertible (a : α) [invertible a] : a⁻¹ * a = 1 :=
inv_mul_cancel (nonzero_of_invertible a)
@[simp] lemma mul_inv_cancel_of_invertible (a : α) [invertible a] : a * a⁻¹ = 1 :=
mul_inv_cancel (nonzero_of_invertible a)
@[simp] lemma div_mul_cancel_of_invertible (a b : α) [invertible b] : a / b * b = a :=
div_mul_cancel a (nonzero_of_invertible b)
@[simp] lemma mul_div_cancel_of_invertible (a b : α) [invertible b] : a * b / b = a :=
mul_div_cancel a (nonzero_of_invertible b)
@[simp] lemma div_self_of_invertible (a : α) [invertible a] : a / a = 1 :=
div_self (nonzero_of_invertible a)
/-- `b / a` is the inverse of `a / b` -/
def invertible_div (a b : α) [invertible a] [invertible b] : invertible (a / b) :=
⟨b / a, by simp [←mul_div_assoc], by simp [←mul_div_assoc]⟩
@[simp] lemma inv_of_div (a b : α) [invertible a] [invertible b] [invertible (a / b)] :
⅟(a / b) = b / a :=
inv_of_eq_right_inv (by simp [←mul_div_assoc])
/-- `a` is the inverse of `a⁻¹` -/
def invertible_inv {a : α} [invertible a] : invertible (a⁻¹) :=
⟨ a, by simp, by simp ⟩
end group_with_zero
/--
Monoid homs preserve invertibility.
-/
def invertible.map {R : Type*} {S : Type*} [monoid R] [monoid S] (f : R →* S) (r : R) [invertible r] :
invertible (f r) :=
{ inv_of := f (⅟r),
inv_of_mul_self := by rw [← f.map_mul, inv_of_mul_self, f.map_one],
mul_inv_of_self := by rw [← f.map_mul, mul_inv_of_self, f.map_one] }
section ring_char
/-- A natural number `t` is invertible in a field `K` if the charactistic of `K` does not divide `t`. -/
def invertible_of_ring_char_not_dvd {K : Type*} [field K]
{t : ℕ} (not_dvd : ¬(ring_char K ∣ t)) : invertible (t : K) :=
invertible_of_nonzero (λ h, not_dvd ((ring_char.spec K t).mp h))
end ring_char
section char_p
/-- A natural number `t` is invertible in a field `K` of charactistic `p` if `p` does not divide `t`. -/
def invertible_of_char_p_not_dvd {K : Type*} [field K] {p : ℕ} [char_p K p]
{t : ℕ} (not_dvd : ¬(p ∣ t)) : invertible (t : K) :=
invertible_of_nonzero (λ h, not_dvd ((char_p.cast_eq_zero_iff K p t).mp h))
instance invertible_of_pos {K : Type*} [field K] [char_zero K] (n : ℕ) [h : fact (0 < n)] :
invertible (n : K) :=
invertible_of_nonzero $ by simpa [nat.pos_iff_ne_zero] using h
end char_p
section division_ring
variable [division_ring α]
instance invertible_succ [char_zero α] (n : ℕ) : invertible (n.succ : α) :=
invertible_of_nonzero (nat.cast_ne_zero.mpr (nat.succ_ne_zero _))
/-!
A few `invertible n` instances for small numerals `n`. Feel free to add your own
number when you need its inverse.
-/
instance invertible_two [char_zero α] : invertible (2 : α) :=
invertible_of_nonzero (by exact_mod_cast (dec_trivial : 2 ≠ 0))
instance invertible_three [char_zero α] : invertible (3 : α) :=
invertible_of_nonzero (by exact_mod_cast (dec_trivial : 3 ≠ 0))
end division_ring
|
3dd99a06cc05826e6afaf7cca187dc51539bd99a
|
159fed64bfae88f3b6a6166836d6278f953bcbf9
|
/Structure/Generic/Instances/Categories.lean
|
6d4040066755677afdd081cd35d6967ebc1b6eba
|
[
"MIT"
] |
permissive
|
SReichelt/lean4-experiments
|
3e56830c8b2fbe3814eda071c48e3c8810d254a8
|
ff55357a01a34a91bf670d712637480089085ee4
|
refs/heads/main
| 1,683,977,454,907
| 1,622,991,121,000
| 1,622,991,121,000
| 340,765,677
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,211
|
lean
|
#exit
import Structure.Generic.Axioms
import Structure.Generic.Instances.Basic
import Structure.Generic.Instances.Bundled
import Structure.Generic.Functors
open GeneralizedRelation
set_option autoBoundImplicitLocal false
set_option pp.universes true
universes u u' v v' w w'
section BundledCategories
variable (M : Universe.{v}) [HasInternalFunctors M] [HasInstanceArrows.{v, w} M]
namespace IsCategory
@[reducible] def Category := Bundled (IsCategory.{(max u v w) + 1} M)
@[reducible] def category : Universe.{(max u v w) + 1} := simpleBundledUniverse.{max u v w} (IsCategory.{(max u v w) + 1} M)
instance (S : category.{u} M) : IsCategory M ⌈S⌉ := simpleBundledInstance.{max u v w} (IsCategory.{(max u v w) + 1} M) S
end IsCategory
namespace IsGroupoid
@[reducible] def Groupoid := Bundled (IsGroupoid.{(max u v w) + 1} M)
@[reducible] def groupoid : Universe.{(max u v w) + 1} := simpleBundledUniverse.{max u v w} (IsGroupoid.{(max u v w) + 1} M)
instance (S : groupoid.{u} M) : IsGroupoid M ⌈S⌉ := simpleBundledInstance.{max u v w} (IsGroupoid.{(max u v w) + 1} M) S
end IsGroupoid
end BundledCategories
section ExternalFunctors
variable (M : Universe.{v}) [HasInternalFunctors M] [HasInstanceArrows.{v, w} M]
(N : Universe.{v'}) [HasInternalFunctors N] [HasInstanceArrows.{v', w'} N]
[HasExternalFunctors M N]
namespace IsCategory
instance hasFunctoriality : Bundled.HasFunctoriality.{max u v w, max u' v' w'} (IsCategory M) (IsCategory N) :=
⟨λ {S T} => IsArrowFunctor.{(max u' v' w') + 1} M N (hα := S.inst.toHasArrows) (hβ := T.inst.toHasArrows)⟩
instance hasExternalFunctors : HasExternalFunctors (category.{u} M) (category.{u'} N) :=
Bundled.hasExternalFunctors.{max u v w, max u' v' w'} (IsCategory M) (IsCategory N)
(h := hasFunctoriality.{u, u'} M N)
instance {S : category.{u} M} {T : category.{u'} N} (F : S ⟶' T) : IsArrowFunctor M N F.f := F.isFun
end IsCategory
namespace IsGroupoid
instance hasFunctoriality : Bundled.HasFunctoriality.{max u v w, max u' v' w'} (IsGroupoid M) (IsGroupoid N) :=
⟨λ {S T} => IsEquivFunctor.{(max u' v' w') + 1} M N (hα := S.inst.toHasEquivalences) (hβ := T.inst.toHasEquivalences)⟩
instance hasExternalFunctors : HasExternalFunctors (groupoid.{u} M) (groupoid.{u'} N) :=
Bundled.hasExternalFunctors.{max u v w, max u' v' w'} (IsGroupoid M) (IsGroupoid N)
(h := hasFunctoriality.{u, u'} M N)
instance {S : groupoid.{u} M} {T : groupoid.{u'} N} (F : S ⟶' T) : IsEquivFunctor M N F.f := F.isFun
end IsGroupoid
end ExternalFunctors
section InternalFunctors
variable (M : Universe.{v}) [HasInternalFunctors M] [HasInstanceEquivalences.{v, w} M]
[hNat : HasNaturalQuantification typeUniverse.{max u v w} typeUniverse.{max u v w} M M]
namespace IsCategory
-- TODO
end IsCategory
namespace IsGroupoid
def Equiv {S T : groupoid.{u} M} (F G : S ⟶' T) := NaturalEquivalence M M F.f G.f
def EquivRel (S T : groupoid.{u} M) : GeneralizedRelation (S ⟶' T) M :=
λ F G => (hNat.hasNat S.inst.Equiv T.inst.Equiv
(h := T.inst.isEquiv.toHasTrans)
(mF := HasInternalFunctors.toBundled F.f) (mG := HasInternalFunctors.toBundled G.f)
F.isFun.mapEquiv G.isFun.mapEquiv).Nat (h := T.inst.isEquiv.toHasTrans)
instance functorGroupoid (S T : groupoid.{u} M) : IsGroupoid.{(max u v w) + 1} M (S ⟶' T) :=
{ Equiv := EquivRel M S T,
isEquiv := sorry,
isIso := sorry }
-- TODO: Check if we can remove the "'" after filling the sorries.
instance hasFunctorInstances : Bundled.HasFunctorInstances'.{max u v w} (IsGroupoid M)
(h := hasFunctoriality.{u, u} M M) :=
⟨functorGroupoid.{u} M⟩
instance hasInternalFunctors : HasInternalFunctors (groupoid.{u} M) :=
Bundled.hasInternalFunctors'.{max u v w} (IsGroupoid M) (h := hasFunctoriality.{u, u} M M)
end IsGroupoid
end InternalFunctors
section ExternalFunctorOperations
section idFun
variable (M : Universe.{v}) [HasInternalFunctors M] [HasInstanceArrows.{v, w} M] [HasIdFun M]
instance IsCategory.hasIdFun : HasIdFun (category.{u} M) := ⟨λ _ => idFun.isArrowFunctor M⟩
instance IsGroupoid.hasIdFun : HasIdFun (groupoid.{u} M) := ⟨λ _ => idFun.isEquivFunctor M⟩
end idFun
-- TODO: constFun, compFun
end ExternalFunctorOperations
-- TODO: Show that:
-- * the universes of categories and groupoids have nice properties
-- (-> bundled functors -> natural transformation as equivalence -> internal functors, also instance arrows/equivalences), and
-- * universes with certain properties are actually categories/groupoids
-- (-> category of categories, groupoid of groupoids).
-- TODO: At some point, we will add the assumption that the `Equiv` relation of a universe has isomorphisms.
-- So all instances are groupoids. How does that fit into this scheme?
|
0b15bd8c48b2dc6fd67924ce4659c1e7fbb572c7
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/src/data/real/ennreal.lean
|
9c26fc425b833aeb7a6dcdb25e8f0c02763095c1
|
[
"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
| 66,892
|
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, Yury Kudryashov
-/
import data.real.nnreal
import data.set.intervals
/-!
# Extended non-negative reals
We define `ennreal = ℝ≥0∞ := with_no ℝ≥0` to be the type of extended nonnegative real numbers,
i.e., the interval `[0, +∞]`. This type is used as the codomain of a `measure_theory.measure`,
and of the extended distance `edist` in a `emetric_space`.
In this file we define some algebraic operations and a linear order on `ℝ≥0∞`
and prove basic properties of these operations, order, and conversions to/from `ℝ`, `ℝ≥0`, and `ℕ`.
## Main definitions
* `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `with_top ℝ≥0`; it is
equipped with the following structures:
- coercion from `ℝ≥0` defined in the natural way;
- the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`;
- `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`;
- `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a *
∞ = ∞ * a = ∞` for `a ≠ 0`;
- `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have
`↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only
subtraction;
- `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for
`p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`.
- `a / b` is defined as `a * b⁻¹`.
The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn
`ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero.
* Coercions to/from other types:
- coercion `ℝ≥0 → ℝ≥0∞` is defined as `has_coe`, so one can use `(p : ℝ≥0)` in a context that
expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically;
- `ennreal.to_nnreal` sends `↑p` to `p` and `∞` to `0`;
- `ennreal.to_real := coe ∘ ennreal.to_nnreal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`;
- `ennreal.of_real := coe ∘ real.to_nnreal` sends `x : ℝ` to `↑⟨max x 0, _⟩`
- `ennreal.ne_top_equiv_nnreal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`.
## Implementation notes
We define a `can_lift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞`
number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha`
in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the
context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`.
## Notations
* `ℝ≥0∞`: the type of the extended nonnegative real numbers;
* `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `data.real.nnreal`;
* `∞`: a localized notation in `ℝ≥0∞` for `⊤ : ℝ≥0∞`.
-/
noncomputable theory
open classical set
open_locale classical big_operators nnreal
variables {α : Type*} {β : Type*}
/-- The extended nonnegative real numbers. This is usually denoted [0, ∞],
and is relevant as the codomain of a measure. -/
@[derive canonically_ordered_comm_semiring, derive complete_linear_order, derive densely_ordered,
derive nontrivial]
def ennreal := with_top ℝ≥0
localized "notation `ℝ≥0∞` := ennreal" in ennreal
localized "notation `∞` := (⊤ : ennreal)" in ennreal
instance : linear_ordered_add_comm_monoid ℝ≥0∞ :=
{ .. ennreal.canonically_ordered_comm_semiring,
.. ennreal.complete_linear_order }
namespace ennreal
variables {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
instance : inhabited ℝ≥0∞ := ⟨0⟩
instance : has_coe ℝ≥0 ℝ≥0∞ := ⟨ option.some ⟩
instance : can_lift ℝ≥0∞ ℝ≥0 :=
{ coe := coe,
cond := λ r, r ≠ ∞,
prf := λ x hx, ⟨option.get $ option.ne_none_iff_is_some.1 hx, option.some_get _⟩ }
@[simp] lemma none_eq_top : (none : ℝ≥0∞) = ∞ := rfl
@[simp] lemma some_eq_coe (a : ℝ≥0) : (some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl
/-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/
protected def to_nnreal : ℝ≥0∞ → ℝ≥0
| (some r) := r
| none := 0
/-- `to_real x` returns `x` if it is real, `0` otherwise. -/
protected def to_real (a : ℝ≥0∞) : real := coe (a.to_nnreal)
/-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/
protected def of_real (r : real) : ℝ≥0∞ := coe (real.to_nnreal r)
@[simp, norm_cast] lemma to_nnreal_coe : (r : ℝ≥0∞).to_nnreal = r := rfl
@[simp] lemma coe_to_nnreal : ∀{a:ℝ≥0∞}, a ≠ ∞ → ↑(a.to_nnreal) = a
| (some r) h := rfl
| none h := (h rfl).elim
@[simp] lemma of_real_to_real {a : ℝ≥0∞} (h : a ≠ ∞) : ennreal.of_real (a.to_real) = a :=
by simp [ennreal.to_real, ennreal.of_real, h]
@[simp] lemma to_real_of_real {r : ℝ} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r :=
by simp [ennreal.to_real, ennreal.of_real, real.coe_to_nnreal _ h]
lemma to_real_of_real' {r : ℝ} : ennreal.to_real (ennreal.of_real r) = max r 0 := rfl
lemma coe_to_nnreal_le_self : ∀{a:ℝ≥0∞}, ↑(a.to_nnreal) ≤ a
| (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _
| none := le_top
lemma coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ennreal.of_real r :=
by { rw [ennreal.of_real, real.to_nnreal], cases r with r h, congr, dsimp, rw max_eq_left h }
lemma of_real_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) :
ennreal.of_real x = @coe ℝ≥0 ℝ≥0∞ _ (⟨x, h⟩ : ℝ≥0) :=
by { rw [coe_nnreal_eq], refl }
@[simp] lemma of_real_coe_nnreal : ennreal.of_real p = p := (coe_nnreal_eq p).symm
@[simp, norm_cast] lemma coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl
@[simp, norm_cast] lemma coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl
@[simp] lemma to_real_nonneg {a : ℝ≥0∞} : 0 ≤ a.to_real := by simp [ennreal.to_real]
@[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl
@[simp] lemma top_to_real : ∞.to_real = 0 := rfl
@[simp] lemma one_to_real : (1 : ℝ≥0∞).to_real = 1 := rfl
@[simp] lemma one_to_nnreal : (1 : ℝ≥0∞).to_nnreal = 1 := rfl
@[simp] lemma coe_to_real (r : ℝ≥0) : (r : ℝ≥0∞).to_real = r := rfl
@[simp] lemma zero_to_nnreal : (0 : ℝ≥0∞).to_nnreal = 0 := rfl
@[simp] lemma zero_to_real : (0 : ℝ≥0∞).to_real = 0 := rfl
@[simp] lemma of_real_zero : ennreal.of_real (0 : ℝ) = 0 :=
by simp [ennreal.of_real]; refl
@[simp] lemma of_real_one : ennreal.of_real (1 : ℝ) = (1 : ℝ≥0∞) :=
by simp [ennreal.of_real]
lemma of_real_to_real_le {a : ℝ≥0∞} : ennreal.of_real (a.to_real) ≤ a :=
if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (of_real_to_real ha)
lemma forall_ennreal {p : ℝ≥0∞ → Prop} : (∀a, p a) ↔ (∀r:ℝ≥0, p r) ∧ p ∞ :=
⟨assume h, ⟨assume r, h _, h _⟩,
assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩
lemma forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a ≠ ∞, p a) ↔ ∀ r : ℝ≥0, p r :=
option.ball_ne_none
lemma exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r :=
option.bex_ne_none
lemma to_nnreal_eq_zero_iff (x : ℝ≥0∞) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ∞ :=
⟨begin
cases x,
{ simp [none_eq_top] },
{ have A : some (0:ℝ≥0) = (0:ℝ≥0∞) := rfl,
simp [ennreal.to_nnreal, A] {contextual := tt} }
end,
by intro h; cases h; simp [h]⟩
lemma to_real_eq_zero_iff (x : ℝ≥0∞) : x.to_real = 0 ↔ x = 0 ∨ x = ∞ :=
by simp [ennreal.to_real, to_nnreal_eq_zero_iff]
@[simp] lemma coe_ne_top : (r : ℝ≥0∞) ≠ ∞ := with_top.coe_ne_top
@[simp] lemma top_ne_coe : ∞ ≠ (r : ℝ≥0∞) := with_top.top_ne_coe
@[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real]
@[simp] lemma of_real_lt_top {r : ℝ} : ennreal.of_real r < ∞ := lt_top_iff_ne_top.2 of_real_ne_top
@[simp] lemma top_ne_of_real {r : ℝ} : ∞ ≠ ennreal.of_real r := by simp [ennreal.of_real]
@[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe
@[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top
@[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe
@[simp, norm_cast] lemma coe_eq_coe : (↑r : ℝ≥0∞) = ↑q ↔ r = q := with_top.coe_eq_coe
@[simp, norm_cast] lemma coe_le_coe : (↑r : ℝ≥0∞) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe
@[simp, norm_cast] lemma coe_lt_coe : (↑r : ℝ≥0∞) < ↑q ↔ r < q := with_top.coe_lt_coe
lemma coe_mono : monotone (coe : ℝ≥0 → ℝ≥0∞) := λ _ _, coe_le_coe.2
@[simp, norm_cast] lemma coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_eq_coe
@[simp, norm_cast] lemma zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_eq_coe
@[simp, norm_cast] lemma coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_eq_coe
@[simp, norm_cast] lemma one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_eq_coe
@[simp, norm_cast] lemma coe_nonneg : 0 ≤ (↑r : ℝ≥0∞) ↔ 0 ≤ r := coe_le_coe
@[simp, norm_cast] lemma coe_pos : 0 < (↑r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe
@[simp, norm_cast] lemma coe_add : ↑(r + p) = (r + p : ℝ≥0∞) := with_top.coe_add
@[simp, norm_cast] lemma coe_mul : ↑(r * p) = (r * p : ℝ≥0∞) := with_top.coe_mul
@[simp, norm_cast] lemma coe_bit0 : (↑(bit0 r) : ℝ≥0∞) = bit0 r := coe_add
@[simp, norm_cast] lemma coe_bit1 : (↑(bit1 r) : ℝ≥0∞) = bit1 r := by simp [bit1]
lemma coe_two : ((2:ℝ≥0) : ℝ≥0∞) = 2 := by norm_cast
protected lemma zero_lt_one : 0 < (1 : ℝ≥0∞) :=
canonically_ordered_comm_semiring.zero_lt_one
@[simp] lemma one_lt_two : (1 : ℝ≥0∞) < 2 :=
coe_one ▸ coe_two ▸ by exact_mod_cast (@one_lt_two ℕ _ _)
@[simp] lemma zero_lt_two : (0:ℝ≥0∞) < 2 := lt_trans ennreal.zero_lt_one one_lt_two
lemma two_ne_zero : (2:ℝ≥0∞) ≠ 0 := (ne_of_lt zero_lt_two).symm
lemma two_ne_top : (2:ℝ≥0∞) ≠ ∞ := coe_two ▸ coe_ne_top
/-- The set of numbers in `ℝ≥0∞` that are not equal to `∞` is equivalent to `ℝ≥0`. -/
def ne_top_equiv_nnreal : {a | a ≠ ∞} ≃ ℝ≥0 :=
{ to_fun := λ x, ennreal.to_nnreal x,
inv_fun := λ x, ⟨x, coe_ne_top⟩,
left_inv := λ ⟨x, hx⟩, subtype.eq $ coe_to_nnreal hx,
right_inv := λ x, to_nnreal_coe }
lemma cinfi_ne_top [has_Inf α] (f : ℝ≥0∞ → α) : (⨅ x : {x // x ≠ ∞}, f x) = ⨅ x : ℝ≥0, f x :=
eq.symm $ infi_congr _ ne_top_equiv_nnreal.symm.surjective $ λ x, rfl
lemma infi_ne_top [complete_lattice α] (f : ℝ≥0∞ → α) : (⨅ x ≠ ∞, f x) = ⨅ x : ℝ≥0, f x :=
by rw [infi_subtype', cinfi_ne_top]
lemma csupr_ne_top [has_Sup α] (f : ℝ≥0∞ → α) : (⨆ x : {x // x ≠ ∞}, f x) = ⨆ x : ℝ≥0, f x :=
@cinfi_ne_top (order_dual α) _ _
lemma supr_ne_top [complete_lattice α] (f : ℝ≥0∞ → α) : (⨆ x ≠ ∞, f x) = ⨆ x : ℝ≥0, f x :=
@infi_ne_top (order_dual α) _ _
lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ℝ≥0∞ → α} :
(⨅ n, f n) = (⨅ n : ℝ≥0, f n) ⊓ f ∞ :=
le_antisymm
(le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _))
(le_infi $ forall_ennreal.2 ⟨λ r, inf_le_of_left_le $ infi_le _ _, inf_le_right⟩)
lemma supr_ennreal {α : Type*} [complete_lattice α] {f : ℝ≥0∞ → α} :
(⨆ n, f n) = (⨆ n : ℝ≥0, f n) ⊔ f ∞ :=
@infi_ennreal (order_dual α) _ _
@[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top
@[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add
/-- Coercion `ℝ≥0 → ℝ≥0∞` as a `ring_hom`. -/
def of_nnreal_hom : ℝ≥0 →+* ℝ≥0∞ :=
⟨coe, coe_one, λ _ _, coe_mul, coe_zero, λ _ _, coe_add⟩
@[simp] lemma coe_of_nnreal_hom : ⇑of_nnreal_hom = coe := rfl
section actions
/-- A `mul_action` over `ℝ≥0∞` restricts to a `mul_action` over `ℝ≥0`. -/
instance {M : Type*} [mul_action ℝ≥0∞ M] : mul_action ℝ≥0 M :=
mul_action.comp_hom M of_nnreal_hom.to_monoid_hom
lemma smul_def {M : Type*} [mul_action ℝ≥0∞ M] (c : ℝ≥0) (x : M) :
c • x = (c : ℝ≥0∞) • x := rfl
instance {M N : Type*} [mul_action ℝ≥0∞ M] [mul_action ℝ≥0∞ N] [has_scalar M N]
[is_scalar_tower ℝ≥0∞ M N] : is_scalar_tower ℝ≥0 M N :=
{ smul_assoc := λ r, (smul_assoc (r : ℝ≥0∞) : _)}
instance smul_comm_class_left {M N : Type*} [mul_action ℝ≥0∞ N] [has_scalar M N]
[smul_comm_class ℝ≥0∞ M N] : smul_comm_class ℝ≥0 M N :=
{ smul_comm := λ r, (smul_comm (r : ℝ≥0∞) : _)}
instance smul_comm_class_right {M N : Type*} [mul_action ℝ≥0∞ N] [has_scalar M N]
[smul_comm_class M ℝ≥0∞ N] : smul_comm_class M ℝ≥0 N :=
{ smul_comm := λ m r, (smul_comm m (r : ℝ≥0∞) : _)}
/-- A `distrib_mul_action` over `ℝ≥0∞` restricts to a `distrib_mul_action` over `ℝ≥0`. -/
instance {M : Type*} [add_monoid M] [distrib_mul_action ℝ≥0∞ M] : distrib_mul_action ℝ≥0 M :=
distrib_mul_action.comp_hom M of_nnreal_hom.to_monoid_hom
/-- A `module` over `ℝ≥0∞` restricts to a `module` over `ℝ≥0`. -/
instance {M : Type*} [add_comm_monoid M] [module ℝ≥0∞ M] : module ℝ≥0 M :=
module.comp_hom M of_nnreal_hom
/-- An `algebra` over `ℝ≥0∞` restricts to an `algebra` over `ℝ≥0`. -/
instance {A : Type*} [semiring A] [algebra ℝ≥0∞ A] : algebra ℝ≥0 A :=
{ smul := (•),
commutes' := λ r x, by simp [algebra.commutes],
smul_def' := λ r x, by simp [←algebra.smul_def (r : ℝ≥0∞) x, smul_def],
to_ring_hom := ((algebra_map ℝ≥0∞ A).comp (of_nnreal_hom : ℝ≥0 →+* ℝ≥0∞)) }
-- verify that the above produces instances we might care about
example : algebra ℝ≥0 ℝ≥0∞ := by apply_instance
example : distrib_mul_action (units ℝ≥0) ℝ≥0∞ := by apply_instance
lemma coe_smul {R} [monoid R] (r : R) (s : ℝ≥0) [mul_action R ℝ≥0] [has_scalar R ℝ≥0∞]
[is_scalar_tower R ℝ≥0 ℝ≥0] [is_scalar_tower R ℝ≥0 ℝ≥0∞] :
(↑(r • s) : ℝ≥0∞) = r • ↑s :=
begin
rw ←smul_one_smul ℝ≥0 r (s: ℝ≥0∞),
change ↑(r • s) = ↑(r • (1 : ℝ≥0)) * ↑s,
rw [←ennreal.coe_mul, smul_mul_assoc, one_mul],
end
end actions
@[simp, norm_cast] lemma coe_indicator {α} (s : set α) (f : α → ℝ≥0) (a : α) :
((s.indicator f a : ℝ≥0) : ℝ≥0∞) = s.indicator (λ x, f x) a :=
(of_nnreal_hom : ℝ≥0 →+ ℝ≥0∞).map_indicator _ _ _
@[simp, norm_cast] lemma coe_pow (n : ℕ) : (↑(r^n) : ℝ≥0∞) = r^n :=
of_nnreal_hom.map_pow r n
@[simp] lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top
@[simp] lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top
lemma to_nnreal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ < ∞) (h₂ : r₂ < ∞) :
(r₁ + r₂).to_nnreal = r₁.to_nnreal + r₂.to_nnreal :=
begin
rw [← coe_eq_coe, coe_add, coe_to_nnreal, coe_to_nnreal, coe_to_nnreal];
apply @ne_top_of_lt ℝ≥0∞ _ _ ∞,
exact h₂,
exact h₁,
exact add_lt_top.2 ⟨h₁, h₂⟩
end
/- rw has trouble with the generic lt_top_iff_ne_top and bot_lt_iff_ne_bot
(contrary to erw). This is solved with the next lemmas -/
protected lemma lt_top_iff_ne_top : a < ∞ ↔ a ≠ ∞ := lt_top_iff_ne_top
protected lemma bot_lt_iff_ne_bot : 0 < a ↔ a ≠ 0 := bot_lt_iff_ne_bot
lemma not_lt_top {x : ℝ≥0∞} : ¬ x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, not_not]
lemma add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ :=
by simpa only [lt_top_iff_ne_top] using add_lt_top
lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end
lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) :=
begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end
@[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top
lemma top_pow {n:ℕ} (h : 0 < n) : ∞^n = ∞ :=
nat.le_induction (pow_one _) (λ m hm hm', by rw [pow_succ, hm', top_mul_top])
_ (nat.succ_le_of_lt h)
lemma mul_eq_top : a * b = ∞ ↔ (a ≠ 0 ∧ b = ∞) ∨ (a = ∞ ∧ b ≠ 0) :=
with_top.mul_eq_top_iff
lemma mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ :=
with_top.mul_lt_top
lemma mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ :=
by simpa only [lt_top_iff_ne_top] using mul_lt_top
lemma ne_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a ≠ ∞ :=
by { simp [mul_eq_top, hb, not_or_distrib] at h ⊢, exact h.2 }
lemma ne_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b ≠ ∞ :=
ne_top_of_mul_ne_top_left (by rwa [mul_comm]) ha
lemma lt_top_of_mul_lt_top_left (h : a * b < ∞) (hb : b ≠ 0) : a < ∞ :=
by { rw [ennreal.lt_top_iff_ne_top] at h ⊢, exact ne_top_of_mul_ne_top_left h hb }
lemma lt_top_of_mul_lt_top_right (h : a * b < ∞) (ha : a ≠ 0) : b < ∞ :=
lt_top_of_mul_lt_top_left (by rwa [mul_comm]) ha
lemma mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ (a < ∞ ∧ b < ∞) ∨ a = 0 ∨ b = 0 :=
begin
split,
{ intro h, rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right], intros hb ha,
exact ⟨lt_top_of_mul_lt_top_left h hb, lt_top_of_mul_lt_top_right h ha⟩ },
{ rintro (⟨ha, hb⟩|rfl|rfl); [exact mul_lt_top ha hb, simp, simp] }
end
lemma mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ :=
by { rw [ennreal.mul_lt_top_iff, and_self, or_self, or_iff_left_iff_imp], rintro rfl, norm_num }
@[simp] lemma mul_pos : 0 < a * b ↔ 0 < a ∧ 0 < b :=
by simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]
lemma pow_eq_top : ∀ n:ℕ, a^n=∞ → a=∞
| 0 := by simp
| (n+1) := λ o, by { rw pow_succ at o,
exact (mul_eq_top.1 o).elim (λ h, pow_eq_top n h.2) and.left }
lemma pow_ne_top (h : a ≠ ∞) {n:ℕ} : a^n ≠ ∞ :=
mt (pow_eq_top n) h
lemma pow_lt_top : a < ∞ → ∀ n:ℕ, a^n < ∞ :=
by simpa only [lt_top_iff_ne_top] using pow_ne_top
@[simp, norm_cast] lemma coe_finset_sum {s : finset α} {f : α → ℝ≥0} :
↑(∑ a in s, f a) = (∑ a in s, f a : ℝ≥0∞) :=
of_nnreal_hom.map_sum f s
@[simp, norm_cast] lemma coe_finset_prod {s : finset α} {f : α → ℝ≥0} :
↑(∏ a in s, f a) = ((∏ a in s, f a) : ℝ≥0∞) :=
of_nnreal_hom.map_prod f s
section order
@[simp] lemma bot_eq_zero : (⊥ : ℝ≥0∞) = 0 := rfl
@[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r
@[simp] lemma not_top_le_coe : ¬ ∞ ≤ ↑r := with_top.not_top_le_coe r
lemma zero_lt_coe_iff : 0 < (↑p : ℝ≥0∞) ↔ 0 < p := coe_lt_coe
@[simp, norm_cast] lemma one_le_coe_iff : (1:ℝ≥0∞) ≤ ↑r ↔ 1 ≤ r := coe_le_coe
@[simp, norm_cast] lemma coe_le_one_iff : ↑r ≤ (1:ℝ≥0∞) ↔ r ≤ 1 := coe_le_coe
@[simp, norm_cast] lemma coe_lt_one_iff : (↑p : ℝ≥0∞) < 1 ↔ p < 1 := coe_lt_coe
@[simp, norm_cast] lemma one_lt_coe_iff : 1 < (↑p : ℝ≥0∞) ↔ 1 < p := coe_lt_coe
@[simp, norm_cast] lemma coe_nat (n : ℕ) : ((n : ℝ≥0) : ℝ≥0∞) = n := with_top.coe_nat n
@[simp] lemma of_real_coe_nat (n : ℕ) : ennreal.of_real n = n := by simp [ennreal.of_real]
@[simp] lemma nat_ne_top (n : ℕ) : (n : ℝ≥0∞) ≠ ∞ := with_top.nat_ne_top n
@[simp] lemma top_ne_nat (n : ℕ) : ∞ ≠ n := with_top.top_ne_nat n
@[simp] lemma one_lt_top : 1 < ∞ := coe_lt_top
lemma le_coe_iff : a ≤ ↑r ↔ (∃p:ℝ≥0, a = p ∧ p ≤ r) := with_top.le_coe_iff
lemma coe_le_iff : ↑r ≤ a ↔ (∀p:ℝ≥0, a = p → r ≤ p) := with_top.coe_le_iff
lemma lt_iff_exists_coe : a < b ↔ (∃p:ℝ≥0, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe
lemma to_real_le_coe_of_le_coe {a : ℝ≥0∞} {b : ℝ≥0} (h : a ≤ b) : a.to_real ≤ b :=
show ↑a.to_nnreal ≤ ↑b,
begin
have : ↑a.to_nnreal = a := ennreal.coe_to_nnreal (lt_of_le_of_lt h coe_lt_top).ne,
rw ← this at h,
exact_mod_cast h
end
@[simp, norm_cast] lemma coe_finset_sup {s : finset α} {f : α → ℝ≥0} :
↑(s.sup f) = s.sup (λ x, (f x : ℝ≥0∞)) :=
finset.comp_sup_eq_sup_comp_of_is_total _ coe_mono rfl
lemma pow_le_pow {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m :=
begin
cases a,
{ cases m,
{ rw eq_bot_iff.mpr h,
exact le_refl _ },
{ rw [none_eq_top, top_pow (nat.succ_pos m)],
exact le_top } },
{ rw [some_eq_coe, ← coe_pow, ← coe_pow, coe_le_coe],
exact pow_le_pow (by simpa using ha) h }
end
@[simp] lemma max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 :=
by simp only [nonpos_iff_eq_zero.symm, max_le_iff]
@[simp] lemma max_zero_left : max 0 a = a := max_eq_right (zero_le a)
@[simp] lemma max_zero_right : max a 0 = a := max_eq_left (zero_le a)
-- TODO: why this is not a `rfl`? There is some hidden diamond here.
@[simp] lemma sup_eq_max : a ⊔ b = max a b :=
eq_of_forall_ge_iff $ λ c, sup_le_iff.trans max_le_iff.symm
protected lemma pow_pos : 0 < a → ∀ n : ℕ, 0 < a^n :=
canonically_ordered_comm_semiring.pow_pos
protected lemma pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a^n ≠ 0 :=
by simpa only [pos_iff_ne_zero] using ennreal.pow_pos
@[simp] lemma not_lt_zero : ¬ a < 0 := by simp
lemma add_lt_add_iff_left (ha : a ≠ ∞) : a + c < a + b ↔ c < b :=
with_top.add_lt_add_iff_left ha
lemma add_lt_add_iff_right (ha : a ≠ ∞) : c + a < b + a ↔ c < b :=
with_top.add_lt_add_iff_right ha
instance contravariant_class_add_lt : contravariant_class ℝ≥0∞ ℝ≥0∞ (+) (<) :=
with_top.contravariant_class_add_lt
lemma lt_add_right (ha : a ≠ ∞) (hb : 0 < b) : a < a + b :=
by rwa [← add_lt_add_iff_left ha, add_zero] at hb
lemma le_of_forall_pos_le_add : ∀{a b : ℝ≥0∞}, (∀ε:ℝ≥0, 0 < ε → b < ∞ → a ≤ b + ε) → a ≤ b
| a none h := le_top
| none (some a) h :=
have ∞ ≤ ↑a + ↑(1:ℝ≥0), from h 1 zero_lt_one coe_lt_top,
by rw [← coe_add] at this; exact (not_top_le_coe this).elim
| (some a) (some b) h :=
by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff]
at *; exact nnreal.le_of_forall_pos_le_add h
lemma lt_iff_exists_rat_btwn :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < real.to_nnreal q ∧ (real.to_nnreal q:ℝ≥0∞) < b) :=
⟨λ h,
begin
rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩,
rcases exists_between h with ⟨c, pc, cb⟩,
rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩,
rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩,
exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩
end,
λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩
lemma lt_iff_exists_real_btwn :
a < b ↔ (∃r:ℝ, 0 ≤ r ∧ a < ennreal.of_real r ∧ (ennreal.of_real r:ℝ≥0∞) < b) :=
⟨λ h, let ⟨q, q0, aq, qb⟩ := ennreal.lt_iff_exists_rat_btwn.1 h in
⟨q, rat.cast_nonneg.2 q0, aq, qb⟩,
λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩
lemma lt_iff_exists_nnreal_btwn :
a < b ↔ (∃r:ℝ≥0, a < r ∧ (r : ℝ≥0∞) < b) :=
with_top.lt_iff_exists_coe_btwn
lemma lt_iff_exists_add_pos_lt : a < b ↔ (∃ r : ℝ≥0, 0 < r ∧ a + r < b) :=
begin
refine ⟨λ hab, _, λ ⟨r, rpos, hr⟩, lt_of_le_of_lt (le_self_add) hr⟩,
cases a, { simpa using hab },
rcases lt_iff_exists_real_btwn.1 hab with ⟨c, c_nonneg, ac, cb⟩,
let d : ℝ≥0 := ⟨c, c_nonneg⟩,
have ad : a < d,
{ rw of_real_eq_coe_nnreal c_nonneg at ac,
exact coe_lt_coe.1 ac },
refine ⟨d-a, nnreal.sub_pos.2 ad, _⟩,
rw [some_eq_coe, ← coe_add],
convert cb,
have : real.to_nnreal c = d,
by { rw [← nnreal.coe_eq, real.coe_to_nnreal _ c_nonneg], refl },
rw [add_comm, this],
exact nnreal.sub_add_cancel_of_le (le_of_lt ad)
end
lemma coe_nat_lt_coe {n : ℕ} : (n : ℝ≥0∞) < r ↔ ↑n < r := ennreal.coe_nat n ▸ coe_lt_coe
lemma coe_lt_coe_nat {n : ℕ} : (r : ℝ≥0∞) < n ↔ r < n := ennreal.coe_nat n ▸ coe_lt_coe
@[simp, norm_cast] lemma coe_nat_lt_coe_nat {m n : ℕ} : (m : ℝ≥0∞) < n ↔ m < n :=
ennreal.coe_nat n ▸ coe_nat_lt_coe.trans nat.cast_lt
lemma coe_nat_ne_top {n : ℕ} : (n : ℝ≥0∞) ≠ ∞ := ennreal.coe_nat n ▸ coe_ne_top
lemma coe_nat_mono : strict_mono (coe : ℕ → ℝ≥0∞) := λ _ _, coe_nat_lt_coe_nat.2
@[simp, norm_cast] lemma coe_nat_le_coe_nat {m n : ℕ} : (m : ℝ≥0∞) ≤ n ↔ m ≤ n :=
coe_nat_mono.le_iff_le
instance : char_zero ℝ≥0∞ := ⟨coe_nat_mono.injective⟩
protected lemma exists_nat_gt {r : ℝ≥0∞} (h : r ≠ ∞) : ∃n:ℕ, r < n :=
begin
lift r to ℝ≥0 using h,
rcases exists_nat_gt r with ⟨n, hn⟩,
exact ⟨n, coe_lt_coe_nat.2 hn⟩,
end
lemma add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d :=
begin
lift a to ℝ≥0 using ne_top_of_lt ac,
lift b to ℝ≥0 using ne_top_of_lt bd,
cases c, { simp }, cases d, { simp },
simp only [← coe_add, some_eq_coe, coe_lt_coe] at *,
exact add_lt_add ac bd
end
@[norm_cast] lemma coe_min : ((min r p:ℝ≥0):ℝ≥0∞) = min r p :=
coe_mono.map_min
@[norm_cast] lemma coe_max : ((max r p:ℝ≥0):ℝ≥0∞) = max r p :=
coe_mono.map_max
lemma le_of_top_imp_top_of_to_nnreal_le {a b : ℝ≥0∞} (h : a = ⊤ → b = ⊤)
(h_nnreal : a ≠ ⊤ → b ≠ ⊤ → a.to_nnreal ≤ b.to_nnreal) :
a ≤ b :=
begin
by_cases ha : a = ⊤,
{ rw h ha,
exact le_top, },
by_cases hb : b = ⊤,
{ rw hb,
exact le_top, },
rw [←coe_to_nnreal hb, ←coe_to_nnreal ha, coe_le_coe],
exact h_nnreal ha hb,
end
end order
section complete_lattice
lemma coe_Sup {s : set ℝ≥0} : bdd_above s → (↑(Sup s) : ℝ≥0∞) = (⨆a∈s, ↑a) := with_top.coe_Sup
lemma coe_Inf {s : set ℝ≥0} : s.nonempty → (↑(Inf s) : ℝ≥0∞) = (⨅a∈s, ↑a) := with_top.coe_Inf
@[simp] lemma top_mem_upper_bounds {s : set ℝ≥0∞} : ∞ ∈ upper_bounds s :=
assume x hx, le_top
lemma coe_mem_upper_bounds {s : set ℝ≥0} :
↑r ∈ upper_bounds ((coe : ℝ≥0 → ℝ≥0∞) '' s) ↔ r ∈ upper_bounds s :=
by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt}
end complete_lattice
section mul
@[mono] lemma mul_le_mul : a ≤ b → c ≤ d → a * c ≤ b * d :=
mul_le_mul'
@[mono] lemma mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d :=
begin
rcases lt_iff_exists_nnreal_btwn.1 ac with ⟨a', aa', a'c⟩,
lift a to ℝ≥0 using ne_top_of_lt aa',
rcases lt_iff_exists_nnreal_btwn.1 bd with ⟨b', bb', b'd⟩,
lift b to ℝ≥0 using ne_top_of_lt bb',
norm_cast at *,
calc ↑(a * b) < ↑(a' * b') :
coe_lt_coe.2 (mul_lt_mul' aa'.le bb' (zero_le _) ((zero_le a).trans_lt aa'))
... = ↑a' * ↑b' : coe_mul
... ≤ c * d : mul_le_mul a'c.le b'd.le
end
lemma mul_left_mono : monotone ((*) a) := λ b c, mul_le_mul (le_refl a)
lemma mul_right_mono : monotone (λ x, x * a) := λ b c h, mul_le_mul h (le_refl a)
lemma max_mul : max a b * c = max (a * c) (b * c) :=
mul_right_mono.map_max
lemma mul_max : a * max b c = max (a * b) (a * c) :=
mul_left_mono.map_max
lemma mul_eq_mul_left : a ≠ 0 → a ≠ ∞ → (a * b = a * c ↔ b = c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm,
nnreal.mul_eq_mul_left] {contextual := tt},
end
lemma mul_eq_mul_right : c ≠ 0 → c ≠ ∞ → (a * c = b * c ↔ a = b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_eq_mul_left
lemma mul_le_mul_left : a ≠ 0 → a ≠ ∞ → (a * b ≤ a * c ↔ b ≤ c) :=
begin
cases a; cases b; cases c;
simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt},
assume h, exact mul_le_mul_left (pos_iff_ne_zero.2 h)
end
lemma mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left
lemma mul_lt_mul_left : a ≠ 0 → a ≠ ∞ → (a * b < a * c ↔ b < c) :=
λ h0 ht, by simp only [mul_le_mul_left h0 ht, lt_iff_le_not_le]
lemma mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left
end mul
section sub
instance : has_sub ℝ≥0∞ := ⟨λa b, Inf {d | a ≤ d + b}⟩
@[norm_cast] lemma coe_sub : ↑(p - r) = (↑p:ℝ≥0∞) - r :=
le_antisymm
(le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $
by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb)
(Inf_le $ show (↑p : ℝ≥0∞) ≤ ↑(p - r) + ↑r,
by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add])
@[simp] lemma top_sub_coe : ∞ - ↑r = ∞ :=
top_unique $ le_Inf $ by simp [add_eq_top]
@[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 :=
le_antisymm (Inf_le $ le_add_left h) (zero_le _)
@[simp] lemma sub_self : a - a = 0 := sub_eq_zero_of_le $ le_refl _
@[simp] lemma zero_sub : 0 - a = 0 :=
le_antisymm (Inf_le $ zero_le $ 0 + a) (zero_le _)
@[simp] lemma sub_top : a - ∞ = 0 :=
le_antisymm (Inf_le $ by simp) (zero_le _)
lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d :=
Inf_le_Inf $ assume e (h : b ≤ e + d),
calc a ≤ b : h₁
... ≤ e + d : h
... ≤ e + c : add_le_add (le_refl _) h₂
@[simp] lemma add_sub_self : ∀{a b : ℝ≥0∞}, b < ∞ → (a + b) - b = a
| a none := by simp [none_eq_top]
| none (some b) := by simp [none_eq_top, some_eq_coe]
| (some a) (some b) :=
by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel]
@[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b :=
by rw [add_comm, add_sub_self h]
lemma add_right_inj (h : a < ∞) : a + b = a + c ↔ b = c :=
⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩
lemma add_left_inj (h : a < ∞) : b + a = c + a ↔ b = c :=
by rw [add_comm, add_comm c, add_right_inj h]
@[simp] lemma sub_add_cancel_of_le : ∀{a b : ℝ≥0∞}, b ≤ a → (a - b) + b = a :=
begin
simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt},
rintros r p x rfl h,
rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h]
end
@[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a :=
by rwa [add_comm, sub_add_cancel_of_le]
lemma sub_add_self_eq_max : (a - b) + b = max a b :=
match le_total a b with
| or.inl h := by simp [h, max_eq_right]
| or.inr h := by simp [h, max_eq_left]
end
lemma le_sub_add_self : a ≤ (a - b) + b :=
by { rw sub_add_self_eq_max, exact le_max_left a b }
@[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b :=
iff.intro
(assume h : a - b ≤ c,
calc a ≤ (a - b) + b : le_sub_add_self
... ≤ c + b : add_le_add_right h _)
(assume h : a ≤ c + b, Inf_le h)
protected lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c :=
add_comm c b ▸ ennreal.sub_le_iff_le_add
lemma sub_eq_of_add_eq : b ≠ ∞ → a + b = c → c - b = a :=
λ hb hc, hc ▸ add_sub_self (lt_top_iff_ne_top.2 hb)
protected lemma sub_le_of_sub_le (h : a - b ≤ c) : a - c ≤ b :=
ennreal.sub_le_iff_le_add.2 $ by { rw add_comm, exact ennreal.sub_le_iff_le_add.1 h }
protected lemma sub_lt_self : a ≠ ∞ → a ≠ 0 → 0 < b → a - b < a :=
match a, b with
| none, _ := by { have := none_eq_top, assume h, contradiction }
| (some a), none := by {intros, simp only [none_eq_top, sub_top, pos_iff_ne_zero], assumption}
| (some a), (some b) :=
begin
simp only [some_eq_coe, coe_sub.symm, coe_pos, coe_eq_zero, coe_lt_coe, ne.def],
assume h₁ h₂, apply nnreal.sub_lt_self, exact pos_iff_ne_zero.2 h₂
end
end
@[simp] protected lemma sub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b :=
by simpa [-ennreal.sub_le_iff_le_add] using @ennreal.sub_le_iff_le_add a b 0
@[simp] lemma zero_lt_sub_iff_lt : 0 < a - b ↔ b < a :=
by simpa [ennreal.bot_lt_iff_ne_bot, -ennreal.sub_eq_zero_iff_le]
using not_iff_not.2 (@ennreal.sub_eq_zero_iff_le a b)
lemma lt_sub_iff_add_lt : a < b - c ↔ a + c < b :=
begin
cases a, { simp },
cases c, { simp },
cases b, { simp only [true_iff, coe_lt_top, some_eq_coe, top_sub_coe, none_eq_top, ← coe_add] },
simp only [some_eq_coe],
rw [← coe_add, ← coe_sub, coe_lt_coe, coe_lt_coe, nnreal.lt_sub_iff_add_lt],
end
lemma sub_le_self (a b : ℝ≥0∞) : a - b ≤ a :=
ennreal.sub_le_iff_le_add.2 $ le_self_add
@[simp] lemma sub_zero : a - 0 = a :=
eq.trans (add_zero (a - 0)).symm $ by simp
/-- A version of triangle inequality for difference as a "distance". -/
lemma sub_le_sub_add_sub : a - c ≤ a - b + (b - c) :=
ennreal.sub_le_iff_le_add.2 $
calc a ≤ a - b + b : le_sub_add_self
... ≤ a - b + ((b - c) + c) : add_le_add_left le_sub_add_self _
... = a - b + (b - c) + c : (add_assoc _ _ _).symm
lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b :=
by rw [← add_left_inj (lt_of_le_of_lt (sub_le_self _ _) h),
sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2]
lemma sub_right_inj {a b c : ℝ≥0∞} (ha : a < ∞) (hb : b ≤ a) (hc : c ≤ a) :
a - b = a - c ↔ b = c :=
iff.intro
begin
assume h, have : a - (a - b) = a - (a - c), rw h,
rw [sub_sub_cancel ha hb, sub_sub_cancel ha hc] at this, exact this
end
(λ h, by rw h)
lemma sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c :=
begin
cases le_or_lt a b with hab hab,
{ simp [hab, mul_right_mono hab] },
symmetry,
cases eq_or_lt_of_le (zero_le b) with hb hb,
{ subst b, simp },
apply sub_eq_of_add_eq,
{ exact mul_ne_top (ne_top_of_lt hab) (h hb hab) },
rw [← add_mul, sub_add_cancel_of_le (le_of_lt hab)]
end
lemma mul_sub (h : 0 < c → c < b → a ≠ ∞) :
a * (b - c) = a * b - a * c :=
by { simp only [mul_comm a], exact sub_mul h }
lemma sub_mul_ge : a * c - b * c ≤ (a - b) * c :=
begin
-- with `0 < b → b < a → c ≠ ∞` Lean names the first variable `a`
by_cases h : ∀ (hb : 0 < b), b < a → c ≠ ∞,
{ rw [sub_mul h],
exact le_refl _ },
{ push_neg at h,
rcases h with ⟨hb, hba, hc⟩,
subst c,
simp only [mul_top, if_neg (ne_of_gt hb), if_neg (ne_of_gt $ lt_trans hb hba), sub_self,
zero_le] }
end
end sub
section sum
open finset
/-- A product of finite numbers is still finite -/
lemma prod_lt_top {s : finset α} {f : α → ℝ≥0∞} (h : ∀a∈s, f a < ∞) : (∏ a in s, f a) < ∞ :=
with_top.prod_lt_top h
/-- A sum of finite numbers is still finite -/
lemma sum_lt_top {s : finset α} {f : α → ℝ≥0∞} :
(∀a∈s, f a < ∞) → ∑ a in s, f a < ∞ :=
with_top.sum_lt_top
/-- A sum of finite numbers is still finite -/
lemma sum_lt_top_iff {s : finset α} {f : α → ℝ≥0∞} :
∑ a in s, f a < ∞ ↔ (∀a∈s, f a < ∞) :=
with_top.sum_lt_top_iff
/-- A sum of numbers is infinite iff one of them is infinite -/
lemma sum_eq_top_iff {s : finset α} {f : α → ℝ≥0∞} :
(∑ x in s, f x) = ∞ ↔ (∃a∈s, f a = ∞) :=
with_top.sum_eq_top_iff
/-- seeing `ℝ≥0∞` as `ℝ≥0` does not change their sum, unless one of the `ℝ≥0∞` is
infinity -/
lemma to_nnreal_sum {s : finset α} {f : α → ℝ≥0∞} (hf : ∀a∈s, f a < ∞) :
ennreal.to_nnreal (∑ a in s, f a) = ∑ a in s, ennreal.to_nnreal (f a) :=
begin
rw [← coe_eq_coe, coe_to_nnreal, coe_finset_sum, sum_congr],
{ refl },
{ intros x hx, exact (coe_to_nnreal (hf x hx).ne).symm },
{ exact (sum_lt_top hf).ne }
end
/-- seeing `ℝ≥0∞` as `real` does not change their sum, unless one of the `ℝ≥0∞` is infinity -/
lemma to_real_sum {s : finset α} {f : α → ℝ≥0∞} (hf : ∀a∈s, f a < ∞) :
ennreal.to_real (∑ a in s, f a) = ∑ a in s, ennreal.to_real (f a) :=
by { rw [ennreal.to_real, to_nnreal_sum hf, nnreal.coe_sum], refl }
lemma of_real_sum_of_nonneg {s : finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) :
ennreal.of_real (∑ i in s, f i) = ∑ i in s, ennreal.of_real (f i) :=
begin
simp_rw [ennreal.of_real, ←coe_finset_sum, coe_eq_coe],
exact real.to_nnreal_sum_of_nonneg hf,
end
end sum
section interval
variables {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : set ℝ≥0∞}
protected lemma Ico_eq_Iio : (Ico 0 y) = (Iio y) :=
ext $ assume a, iff.intro
(assume ⟨_, hx⟩, hx)
(assume hx, ⟨zero_le _, hx⟩)
lemma mem_Iio_self_add : x ≠ ∞ → 0 < ε → x ∈ Iio (x + ε) :=
assume xt ε0, lt_add_right xt ε0
lemma not_mem_Ioo_self_sub : x = 0 → x ∉ Ioo (x - ε) y :=
assume x0, by simp [x0]
lemma mem_Ioo_self_sub_add : x ≠ ∞ → x ≠ 0 → 0 < ε₁ → 0 < ε₂ → x ∈ Ioo (x - ε₁) (x + ε₂) :=
assume xt x0 ε0 ε0', ⟨ennreal.sub_lt_self xt x0 ε0, lt_add_right xt ε0'⟩
end interval
section bit
@[simp] lemma bit0_inj : bit0 a = bit0 b ↔ a = b :=
⟨λh, begin
rcases (lt_trichotomy a b) with h₁| h₂| h₃,
{ exact (absurd h (ne_of_lt (add_lt_add h₁ h₁))) },
{ exact h₂ },
{ exact (absurd h.symm (ne_of_lt (add_lt_add h₃ h₃))) }
end,
λh, congr_arg _ h⟩
@[simp] lemma bit0_eq_zero_iff : bit0 a = 0 ↔ a = 0 :=
by simpa only [bit0_zero] using @bit0_inj a 0
@[simp] lemma bit0_eq_top_iff : bit0 a = ∞ ↔ a = ∞ :=
by rw [bit0, add_eq_top, or_self]
@[simp] lemma bit1_inj : bit1 a = bit1 b ↔ a = b :=
⟨λh, begin
unfold bit1 at h,
rwa [add_left_inj, bit0_inj] at h,
simp [lt_top_iff_ne_top]
end,
λh, congr_arg _ h⟩
@[simp] lemma bit1_ne_zero : bit1 a ≠ 0 :=
by unfold bit1; simp
@[simp] lemma bit1_eq_one_iff : bit1 a = 1 ↔ a = 0 :=
by simpa only [bit1_zero] using @bit1_inj a 0
@[simp] lemma bit1_eq_top_iff : bit1 a = ∞ ↔ a = ∞ :=
by unfold bit1; rw add_eq_top; simp
end bit
section inv
instance : has_inv ℝ≥0∞ := ⟨λa, Inf {b | 1 ≤ a * b}⟩
instance : div_inv_monoid ℝ≥0∞ :=
{ inv := has_inv.inv,
.. (infer_instance : monoid ℝ≥0∞) }
@[simp] lemma inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ :=
show Inf {b : ℝ≥0∞ | 1 ≤ 0 * b} = ∞, by simp; refl
@[simp] lemma inv_top : ∞⁻¹ = 0 :=
bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul]
@[simp, norm_cast] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ :=
le_antisymm
(le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $
by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb)
(Inf_le $ by simp; rw [← coe_mul, mul_inv_cancel hr]; exact le_refl 1)
lemma coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ :=
if hr : r = 0 then by simp only [hr, inv_zero, coe_zero, le_top]
else by simp only [coe_inv hr, le_refl]
@[norm_cast] lemma coe_inv_two : ((2⁻¹:ℝ≥0):ℝ≥0∞) = 2⁻¹ :=
by rw [coe_inv (ne_of_gt _root_.zero_lt_two), coe_two]
@[simp, norm_cast] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r :=
by rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr]
@[simp] lemma inv_one : (1:ℝ≥0∞)⁻¹ = 1 :=
by simpa only [coe_inv one_ne_zero, coe_one] using coe_eq_coe.2 inv_one
@[simp] lemma div_one {a : ℝ≥0∞} : a / 1 = a :=
by rw [div_eq_mul_inv, inv_one, mul_one]
protected lemma inv_pow {n : ℕ} : (a^n)⁻¹ = (a⁻¹)^n :=
begin
by_cases a = 0; cases a; cases n; simp [*, none_eq_top, some_eq_coe,
zero_pow, top_pow, nat.zero_lt_succ] at *,
rw [← coe_inv h, ← coe_pow, ← coe_inv (pow_ne_zero _ h), ← inv_pow', coe_pow]
end
@[simp] lemma inv_inv : (a⁻¹)⁻¹ = a :=
by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe,
-coe_inv, (coe_inv _).symm] at *
lemma inv_involutive : function.involutive (λ a:ℝ≥0∞, a⁻¹) :=
λ a, ennreal.inv_inv
lemma inv_bijective : function.bijective (λ a:ℝ≥0∞, a⁻¹) :=
ennreal.inv_involutive.bijective
@[simp] lemma inv_eq_inv : a⁻¹ = b⁻¹ ↔ a = b := inv_bijective.1.eq_iff
@[simp] lemma inv_eq_top : a⁻¹ = ∞ ↔ a = 0 :=
inv_zero ▸ inv_eq_inv
lemma inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[simp] lemma inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x :=
by { simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero] }
lemma div_lt_top {x y : ℝ≥0∞} (h1 : x < ∞) (h2 : 0 < y) : x / y < ∞ :=
mul_lt_top h1 (inv_lt_top.mpr h2)
@[simp] lemma inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ :=
inv_top ▸ inv_eq_inv
lemma inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
@[simp] lemma inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ :=
pos_iff_ne_zero.trans inv_ne_zero
@[simp] lemma inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a :=
begin
cases a; cases b; simp only [some_eq_coe, none_eq_top, inv_top],
{ simp only [lt_irrefl] },
{ exact inv_pos.trans lt_top_iff_ne_top.symm },
{ simp only [not_lt_zero, not_top_lt] },
{ cases eq_or_lt_of_le (zero_le a) with ha ha;
cases eq_or_lt_of_le (zero_le b) with hb hb,
{ subst a, subst b, simp },
{ subst a, simp },
{ subst b, simp [pos_iff_ne_zero, lt_top_iff_ne_top, inv_ne_top] },
{ rw [← coe_inv (ne_of_gt ha), ← coe_inv (ne_of_gt hb), coe_lt_coe, coe_lt_coe],
simp only [nnreal.coe_lt_coe.symm] at *,
exact inv_lt_inv ha hb } }
end
lemma inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a :=
by simpa only [inv_inv] using @inv_lt_inv a b⁻¹
lemma lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ :=
by simpa only [inv_inv] using @inv_lt_inv a⁻¹ b
@[simp, priority 1100] -- higher than le_inv_iff_mul_le
lemma inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
by simp only [le_iff_lt_or_eq, inv_lt_inv, inv_eq_inv, eq_comm]
lemma inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
by simpa only [inv_inv] using @inv_le_inv a b⁻¹
lemma le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
by simpa only [inv_inv] using @inv_le_inv a⁻¹ b
@[simp] lemma inv_le_one : a⁻¹ ≤ 1 ↔ 1 ≤ a :=
inv_le_iff_inv_le.trans $ by rw inv_one
lemma one_le_inv : 1 ≤ a⁻¹ ↔ a ≤ 1 :=
le_inv_iff_le_inv.trans $ by rw inv_one
@[simp] lemma inv_lt_one : a⁻¹ < 1 ↔ 1 < a :=
inv_lt_iff_inv_lt.trans $ by rw [inv_one]
lemma pow_le_pow_of_le_one {n m : ℕ} (ha : a ≤ 1) (h : n ≤ m) : a ^ m ≤ a ^ n :=
begin
rw [← @inv_inv a, ← ennreal.inv_pow, ← @ennreal.inv_pow a⁻¹, inv_le_inv],
exact pow_le_pow (one_le_inv.2 ha) h
end
@[simp] lemma div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero]
@[simp] lemma top_div_coe : ∞ / p = ∞ := by simp [div_eq_mul_inv, top_mul]
lemma top_div_of_ne_top (h : a ≠ ∞) : ∞ / a = ∞ :=
by { lift a to ℝ≥0 using h, exact top_div_coe }
lemma top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ :=
top_div_of_ne_top h.ne
lemma top_div : ∞ / a = if a = ∞ then 0 else ∞ :=
by by_cases a = ∞; simp [top_div_of_ne_top, *]
@[simp] lemma zero_div : 0 / a = 0 := zero_mul a⁻¹
lemma div_eq_top : a / b = ∞ ↔ (a ≠ 0 ∧ b = 0) ∨ (a = ∞ ∧ b ≠ ∞) :=
by simp [div_eq_mul_inv, ennreal.mul_eq_top]
lemma le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) :
a ≤ c / b ↔ a * b ≤ c :=
begin
cases b,
{ simp at ht,
split,
{ assume ha, simp at ha, simp [ha] },
{ contrapose,
assume ha,
simp at ha,
have : a * ∞ = ∞, by simp [ennreal.mul_eq_top, ha],
simp [this, ht] } },
by_cases hb : b ≠ 0,
{ have : (b : ℝ≥0∞) ≠ 0, by simp [hb],
rw [← ennreal.mul_le_mul_left this coe_ne_top],
suffices : ↑b * a ≤ (↑b * ↑b⁻¹) * c ↔ a * ↑b ≤ c,
{ simpa [some_eq_coe, div_eq_mul_inv, hb, mul_left_comm, mul_comm, mul_assoc] },
rw [← coe_mul, mul_inv_cancel hb, coe_one, one_mul, mul_comm] },
{ simp at hb,
simp [hb] at h0,
have : c / 0 = ∞, by simp [div_eq_top, h0],
simp [hb, this] }
end
lemma div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) : a / b ≤ c ↔ a ≤ c * b :=
begin
suffices : a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_eq_mul_inv],
refine (le_div_iff_mul_le _ _).symm; simpa
end
lemma div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b :=
begin
by_cases h0 : c = 0,
{ have : a = 0, by simpa [h0] using h, simp [*] },
by_cases hinf : c = ∞, by simp [hinf],
exact (div_le_iff_le_mul (or.inl h0) (or.inl hinf)).2 h
end
lemma div_le_of_le_mul' (h : a ≤ b * c) : a / b ≤ c :=
div_le_of_le_mul $ mul_comm b c ▸ h
lemma mul_le_of_le_div (h : a ≤ b / c) : a * c ≤ b :=
begin
rcases _root_.em (c = 0 ∧ b = 0 ∨ c = ∞ ∧ b = ∞) with (⟨rfl, rfl⟩|⟨rfl, rfl⟩)|H,
{ rw [mul_zero], exact le_rfl },
{ exact le_top },
{ simp only [not_or_distrib, not_and_distrib] at H,
rwa ← le_div_iff_mul_le H.1 H.2 }
end
lemma mul_le_of_le_div' (h : a ≤ b / c) : c * a ≤ b :=
mul_comm a c ▸ mul_le_of_le_div h
protected lemma div_lt_iff (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) :
c / b < a ↔ c < a * b :=
lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le h0 ht
lemma mul_lt_of_lt_div (h : a < b / c) : a * c < b :=
by { contrapose! h, exact ennreal.div_le_of_le_mul h }
lemma inv_le_iff_le_mul : (b = ∞ → a ≠ 0) → (a = ∞ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) :=
begin
cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt},
by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, -coe_inv, (coe_inv _).symm, nnreal.inv_le]
end
@[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 :=
begin
cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] },
by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le],
suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_eq_mul_inv, h] },
exact le_div_iff_mul_le (or.inl (mt coe_eq_coe.1 h)) (or.inl coe_ne_top)
end
lemma mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 :=
begin
lift a to ℝ≥0 using ht,
norm_cast at *,
exact mul_inv_cancel h0
end
lemma inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 :=
mul_comm a a⁻¹ ▸ mul_inv_cancel h0 ht
lemma eq_inv_of_mul_eq_one (h : a * b = 1) : a = b⁻¹ :=
begin
rcases eq_or_ne b ∞ with rfl|hb,
{ have : false, by simpa [left_ne_zero_of_mul_eq_one h] using h,
exact this.elim },
{ rw [← mul_one a, ← mul_inv_cancel (right_ne_zero_of_mul_eq_one h) hb, ← mul_assoc, h, one_mul] }
end
lemma mul_le_iff_le_inv {a b r : ℝ≥0∞} (hr₀ : r ≠ 0) (hr₁ : r ≠ ∞) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) :=
by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul]
lemma le_of_forall_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r < x → ↑r ≤ y) : x ≤ y :=
begin
refine le_of_forall_ge_of_dense (λ r hr, _),
lift r to ℝ≥0 using ne_top_of_lt hr,
exact h r hr
end
lemma le_of_forall_pos_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, 0 < r → ↑r < x → ↑r ≤ y) : x ≤ y :=
le_of_forall_nnreal_lt $ λ r hr, (zero_le r).eq_or_lt.elim (λ h, h ▸ zero_le _) (λ h0, h r h0 hr)
lemma eq_top_of_forall_nnreal_le {x : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x) : x = ∞ :=
top_unique $ le_of_forall_nnreal_lt $ λ r hr, h r
lemma div_add_div_same {a b c : ℝ≥0∞} : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 :=
mul_inv_cancel h0 hI
lemma mul_div_cancel (h0 : a ≠ 0) (hI : a ≠ ∞) : (b / a) * a = b :=
by rw [div_eq_mul_inv, mul_assoc, inv_mul_cancel h0 hI, mul_one]
lemma mul_div_cancel' (h0 : a ≠ 0) (hI : a ≠ ∞) : a * (b / a) = b :=
by rw [mul_comm, mul_div_cancel h0 hI]
lemma mul_div_le : a * (b / a) ≤ b :=
begin
by_cases h0 : a = 0, { simp [h0] },
by_cases hI : a = ∞, { simp [hI] },
rw mul_div_cancel' h0 hI, exact le_refl b
end
lemma inv_two_add_inv_two : (2:ℝ≥0∞)⁻¹ + 2⁻¹ = 1 :=
by rw [← two_mul, ← div_eq_mul_inv, div_self two_ne_zero two_ne_top]
lemma add_halves (a : ℝ≥0∞) : a / 2 + a / 2 = a :=
by rw [div_eq_mul_inv, ← mul_add, inv_two_add_inv_two, mul_one]
@[simp] lemma div_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ :=
by simp [div_eq_mul_inv]
@[simp] lemma div_pos_iff : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ∞ :=
by simp [pos_iff_ne_zero, not_or_distrib]
lemma half_pos {a : ℝ≥0∞} (h : 0 < a) : 0 < a / 2 :=
by simp [ne_of_gt h]
lemma one_half_lt_one : (2⁻¹:ℝ≥0∞) < 1 := inv_lt_one.2 $ one_lt_two
lemma half_lt_self {a : ℝ≥0∞} (hz : a ≠ 0) (ht : a ≠ ∞) : a / 2 < a :=
begin
lift a to ℝ≥0 using ht,
have h : (2 : ℝ≥0∞) = ((2 : ℝ≥0) : ℝ≥0∞), from rfl,
have h' : (2 : ℝ≥0) ≠ 0, from _root_.two_ne_zero',
rw [h, ← coe_div h', coe_lt_coe], -- `norm_cast` fails to apply `coe_div`
norm_cast at hz,
exact nnreal.half_lt_self hz
end
lemma sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 :=
begin
lift a to ℝ≥0 using h,
exact sub_eq_of_add_eq (mul_ne_top coe_ne_top $ by simp) (add_halves a)
end
@[simp] lemma one_sub_inv_two : (1:ℝ≥0∞) - 2⁻¹ = 2⁻¹ :=
by simpa only [div_eq_mul_inv, one_mul] using sub_half one_ne_top
lemma exists_inv_nat_lt {a : ℝ≥0∞} (h : a ≠ 0) :
∃n:ℕ, (n:ℝ≥0∞)⁻¹ < a :=
@inv_inv a ▸ by simp only [inv_lt_inv, ennreal.exists_nat_gt (inv_ne_top.2 h)]
lemma exists_nat_pos_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) :
∃ n > 0, b < (n : ℕ) * a :=
begin
have : b / a ≠ ∞, from mul_ne_top hb (inv_ne_top.2 ha),
refine (ennreal.exists_nat_gt this).imp (λ n hn, _),
have : 0 < (n : ℝ≥0∞), from (zero_le _).trans_lt hn,
refine ⟨coe_nat_lt_coe_nat.1 this, _⟩,
rwa [← ennreal.div_lt_iff (or.inl ha) (or.inr hb)]
end
lemma exists_nat_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) :
∃ n : ℕ, b < n * a :=
(exists_nat_pos_mul_gt ha hb).imp $ λ n, Exists.snd
lemma exists_nat_pos_inv_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) :
∃ n > 0, ((n : ℕ) : ℝ≥0∞)⁻¹ * a < b :=
begin
rcases exists_nat_pos_mul_gt hb ha with ⟨n, npos, hn⟩,
have : (n : ℝ≥0∞) ≠ 0 := nat.cast_ne_zero.2 npos.lt.ne',
use [n, npos],
rwa [← one_mul b, ← inv_mul_cancel this coe_nat_ne_top,
mul_assoc, mul_lt_mul_left (inv_ne_zero.2 coe_nat_ne_top) (inv_ne_top.2 this)]
end
lemma exists_nnreal_pos_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) :
∃ n > 0, ↑(n : ℝ≥0) * a < b :=
begin
rcases exists_nat_pos_inv_mul_lt ha hb with ⟨n, npos : 0 < n, hn⟩,
use (n : ℝ≥0)⁻¹,
simp [*, npos.ne', zero_lt_one]
end
lemma exists_inv_two_pow_lt (ha : a ≠ 0) :
∃ n : ℕ, 2⁻¹ ^ n < a :=
begin
rcases exists_inv_nat_lt ha with ⟨n, hn⟩,
simp only [← ennreal.inv_pow],
refine ⟨n, lt_trans (inv_lt_inv.2 _) hn⟩,
norm_cast,
exact n.lt_two_pow
end
end inv
section real
lemma to_real_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a+b).to_real = a.to_real + b.to_real :=
begin
lift a to ℝ≥0 using ha,
lift b to ℝ≥0 using hb,
refl
end
lemma to_real_sub_of_le {a b : ℝ≥0∞} (h : b ≤ a) (ha : a ≠ ∞):
(a - b).to_real = a.to_real - b.to_real :=
begin
lift b to ℝ≥0 using ne_top_of_le_ne_top ha h,
lift a to ℝ≥0 using ha,
simp only [← ennreal.coe_sub, ennreal.coe_to_real, nnreal.coe_sub (ennreal.coe_le_coe.mp h)],
end
lemma to_real_add_le : (a+b).to_real ≤ a.to_real + b.to_real :=
if ha : a = ∞ then by simp only [ha, top_add, top_to_real, zero_add, to_real_nonneg]
else if hb : b = ∞ then by simp only [hb, add_top, top_to_real, add_zero, to_real_nonneg]
else le_of_eq (to_real_add ha hb)
lemma of_real_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ennreal.of_real (p + q) = ennreal.of_real p + ennreal.of_real q :=
by rw [ennreal.of_real, ennreal.of_real, ennreal.of_real, ← coe_add,
coe_eq_coe, real.to_nnreal_add hp hq]
lemma of_real_add_le {p q : ℝ} : ennreal.of_real (p + q) ≤ ennreal.of_real p + ennreal.of_real q :=
coe_le_coe.2 real.to_nnreal_add_le
@[simp] lemma to_real_le_to_real (ha : a ≠ ∞) (hb : b ≠ ∞) : a.to_real ≤ b.to_real ↔ a ≤ b :=
begin
lift a to ℝ≥0 using ha,
lift b to ℝ≥0 using hb,
norm_cast
end
lemma to_real_mono (hb : b ≠ ∞) (h : a ≤ b) : a.to_real ≤ b.to_real :=
(to_real_le_to_real (h.trans_lt (lt_top_iff_ne_top.2 hb)).ne hb).2 h
@[simp] lemma to_real_lt_to_real (ha : a ≠ ∞) (hb : b ≠ ∞) : a.to_real < b.to_real ↔ a < b :=
begin
lift a to ℝ≥0 using ha,
lift b to ℝ≥0 using hb,
norm_cast
end
lemma to_real_strict_mono (hb : b ≠ ∞) (h : a < b) : a.to_real < b.to_real :=
(to_real_lt_to_real (h.trans (lt_top_iff_ne_top.2 hb)).ne hb).2 h
lemma to_real_max (hr : a ≠ ∞) (hp : b ≠ ∞) :
ennreal.to_real (max a b) = max (ennreal.to_real a) (ennreal.to_real b) :=
(le_total a b).elim
(λ h, by simp only [h, (ennreal.to_real_le_to_real hr hp).2 h, max_eq_right])
(λ h, by simp only [h, (ennreal.to_real_le_to_real hp hr).2 h, max_eq_left])
lemma to_nnreal_pos_iff : 0 < a.to_nnreal ↔ (0 < a ∧ a ≠ ∞) :=
begin
cases a,
{ simp [none_eq_top] },
{ simp [some_eq_coe] }
end
lemma to_real_pos_iff : 0 < a.to_real ↔ (0 < a ∧ a ≠ ∞):=
(nnreal.coe_pos).trans to_nnreal_pos_iff
lemma of_real_le_of_real {p q : ℝ} (h : p ≤ q) : ennreal.of_real p ≤ ennreal.of_real q :=
by simp [ennreal.of_real, real.to_nnreal_le_to_nnreal h]
lemma of_real_le_of_le_to_real {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ennreal.to_real b) :
ennreal.of_real a ≤ b :=
(of_real_le_of_real h).trans of_real_to_real_le
@[simp] lemma of_real_le_of_real_iff {p q : ℝ} (h : 0 ≤ q) :
ennreal.of_real p ≤ ennreal.of_real q ↔ p ≤ q :=
by rw [ennreal.of_real, ennreal.of_real, coe_le_coe, real.to_nnreal_le_to_nnreal_iff h]
@[simp] lemma of_real_lt_of_real_iff {p q : ℝ} (h : 0 < q) :
ennreal.of_real p < ennreal.of_real q ↔ p < q :=
by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, real.to_nnreal_lt_to_nnreal_iff h]
lemma of_real_lt_of_real_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) :
ennreal.of_real p < ennreal.of_real q ↔ p < q :=
by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, real.to_nnreal_lt_to_nnreal_iff_of_nonneg hp]
@[simp] lemma of_real_pos {p : ℝ} : 0 < ennreal.of_real p ↔ 0 < p :=
by simp [ennreal.of_real]
@[simp] lemma of_real_eq_zero {p : ℝ} : ennreal.of_real p = 0 ↔ p ≤ 0 :=
by simp [ennreal.of_real]
@[simp] lemma zero_eq_of_real {p : ℝ} : 0 = ennreal.of_real p ↔ p ≤ 0 :=
eq_comm.trans of_real_eq_zero
lemma of_real_le_iff_le_to_real {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) :
ennreal.of_real a ≤ b ↔ a ≤ ennreal.to_real b :=
begin
lift b to ℝ≥0 using hb,
simpa [ennreal.of_real, ennreal.to_real] using real.to_nnreal_le_iff_le_coe
end
lemma of_real_lt_iff_lt_to_real {a : ℝ} {b : ℝ≥0∞} (ha : 0 ≤ a) (hb : b ≠ ∞) :
ennreal.of_real a < b ↔ a < ennreal.to_real b :=
begin
lift b to ℝ≥0 using hb,
simpa [ennreal.of_real, ennreal.to_real] using real.to_nnreal_lt_iff_lt_coe ha
end
lemma le_of_real_iff_to_real_le {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) :
a ≤ ennreal.of_real b ↔ ennreal.to_real a ≤ b :=
begin
lift a to ℝ≥0 using ha,
simpa [ennreal.of_real, ennreal.to_real] using real.le_to_nnreal_iff_coe_le hb
end
lemma to_real_le_of_le_of_real {a : ℝ≥0∞} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ennreal.of_real b) :
ennreal.to_real a ≤ b :=
have ha : a ≠ ∞, from ne_top_of_le_ne_top of_real_ne_top h,
(le_of_real_iff_to_real_le ha hb).1 h
lemma lt_of_real_iff_to_real_lt {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) :
a < ennreal.of_real b ↔ ennreal.to_real a < b :=
begin
lift a to ℝ≥0 using ha,
simpa [ennreal.of_real, ennreal.to_real] using real.lt_to_nnreal_iff_coe_lt
end
lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) :
ennreal.of_real (p * q) = (ennreal.of_real p) * (ennreal.of_real q) :=
by { simp only [ennreal.of_real, coe_mul.symm, coe_eq_coe], exact real.to_nnreal_mul hp }
lemma of_real_pow {p : ℝ} (hp : 0 ≤ p) (n : ℕ) :
ennreal.of_real (p ^ n) = ennreal.of_real p ^ n :=
by rw [of_real_eq_coe_nnreal hp, ← coe_pow, ← of_real_coe_nnreal, nnreal.coe_pow, nnreal.coe_mk]
lemma of_real_inv_of_pos {x : ℝ} (hx : 0 < x) :
(ennreal.of_real x)⁻¹ = ennreal.of_real x⁻¹ :=
by rw [ennreal.of_real, ennreal.of_real, ←@coe_inv (real.to_nnreal x) (by simp [hx]), coe_eq_coe,
real.to_nnreal_inv.symm]
lemma of_real_div_of_pos {x y : ℝ} (hy : 0 < y) :
ennreal.of_real (x / y) = ennreal.of_real x / ennreal.of_real y :=
by rw [div_eq_inv_mul, div_eq_mul_inv, of_real_mul (inv_nonneg.2 hy.le), of_real_inv_of_pos hy,
mul_comm]
lemma to_real_of_real_mul (c : ℝ) (a : ℝ≥0∞) (h : 0 ≤ c) :
ennreal.to_real ((ennreal.of_real c) * a) = c * ennreal.to_real a :=
begin
cases a,
{ simp only [none_eq_top, ennreal.to_real, top_to_nnreal, nnreal.coe_zero, mul_zero, mul_top],
by_cases h' : c ≤ 0,
{ rw [if_pos], { simp }, { convert of_real_zero, exact le_antisymm h' h } },
{ rw [if_neg], refl, rw [of_real_eq_zero], assumption } },
{ simp only [ennreal.to_real, ennreal.to_nnreal],
simp only [some_eq_coe, ennreal.of_real, coe_mul.symm, to_nnreal_coe, nnreal.coe_mul],
congr, apply real.coe_to_nnreal, exact h }
end
@[simp] lemma to_nnreal_mul_top (a : ℝ≥0∞) : ennreal.to_nnreal (a * ∞) = 0 :=
begin
by_cases h : a = 0,
{ rw [h, zero_mul, zero_to_nnreal] },
{ rw [mul_top, if_neg h, top_to_nnreal] }
end
@[simp] lemma to_nnreal_top_mul (a : ℝ≥0∞) : ennreal.to_nnreal (∞ * a) = 0 :=
by rw [mul_comm, to_nnreal_mul_top]
@[simp] lemma to_real_mul_top (a : ℝ≥0∞) : ennreal.to_real (a * ∞) = 0 :=
by rw [ennreal.to_real, to_nnreal_mul_top, nnreal.coe_zero]
@[simp] lemma to_real_top_mul (a : ℝ≥0∞) : ennreal.to_real (∞ * a) = 0 :=
by { rw mul_comm, exact to_real_mul_top _ }
lemma to_real_eq_to_real (ha : a < ∞) (hb : b < ∞) :
ennreal.to_real a = ennreal.to_real b ↔ a = b :=
begin
lift a to ℝ≥0 using ha.ne,
lift b to ℝ≥0 using hb.ne,
simp only [coe_eq_coe, nnreal.coe_eq, coe_to_real],
end
lemma to_real_smul (r : ℝ≥0) (s : ℝ≥0∞) :
(r • s).to_real = r • s.to_real :=
begin
induction s using with_top.rec_top_coe,
{ rw [show r • ∞ = (r : ℝ≥0∞) * ∞, by refl],
simp only [ennreal.to_real_mul_top, ennreal.top_to_real, smul_zero] },
{ rw [← coe_smul, ennreal.coe_to_real, ennreal.coe_to_real],
refl }
end
/-- `ennreal.to_nnreal` as a `monoid_hom`. -/
def to_nnreal_hom : ℝ≥0∞ →* ℝ≥0 :=
{ to_fun := ennreal.to_nnreal,
map_one' := to_nnreal_coe,
map_mul' := by rintro (_|x) (_|y); simp only [← coe_mul, none_eq_top, some_eq_coe,
to_nnreal_top_mul, to_nnreal_mul_top, top_to_nnreal, mul_zero, zero_mul, to_nnreal_coe] }
lemma to_nnreal_mul {a b : ℝ≥0∞}: (a * b).to_nnreal = a.to_nnreal * b.to_nnreal :=
to_nnreal_hom.map_mul a b
lemma to_nnreal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).to_nnreal = a.to_nnreal ^ n :=
to_nnreal_hom.map_pow a n
lemma to_nnreal_prod {ι : Type*} {s : finset ι} {f : ι → ℝ≥0∞} :
(∏ i in s, f i).to_nnreal = ∏ i in s, (f i).to_nnreal :=
to_nnreal_hom.map_prod _ _
lemma to_nnreal_inv (a : ℝ≥0∞) : (a⁻¹).to_nnreal = (a.to_nnreal)⁻¹ :=
begin
by_cases ha_zero : a = 0,
{ simp [ha_zero], },
by_cases ha_top : a = ∞,
{ simp [ha_top], },
have ha_eq : a = a.to_nnreal, from (coe_to_nnreal ha_top).symm,
nth_rewrite 0 ha_eq,
rw ← coe_inv,
{ norm_cast, },
{ rw [ne.def, to_nnreal_eq_zero_iff], push_neg, exact ⟨ha_zero, ha_top⟩, },
end
lemma to_nnreal_div (a b : ℝ≥0∞) : (a / b).to_nnreal = a.to_nnreal / b.to_nnreal :=
by rw [div_eq_mul_inv, to_nnreal_mul, to_nnreal_inv, div_eq_mul_inv]
/-- `ennreal.to_real` as a `monoid_hom`. -/
def to_real_hom : ℝ≥0∞ →* ℝ :=
(nnreal.to_real_hom : ℝ≥0 →* ℝ).comp to_nnreal_hom
lemma to_real_mul : (a * b).to_real = a.to_real * b.to_real :=
to_real_hom.map_mul a b
lemma to_real_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).to_real = a.to_real ^ n :=
to_real_hom.map_pow a n
lemma to_real_prod {ι : Type*} {s : finset ι} {f : ι → ℝ≥0∞} :
(∏ i in s, f i).to_real = ∏ i in s, (f i).to_real :=
to_real_hom.map_prod _ _
lemma to_real_inv (a : ℝ≥0∞) : (a⁻¹).to_real = (a.to_real)⁻¹ :=
by { simp_rw ennreal.to_real, norm_cast, exact to_nnreal_inv a, }
lemma to_real_div (a b : ℝ≥0∞) : (a / b).to_real = a.to_real / b.to_real :=
by rw [div_eq_mul_inv, to_real_mul, to_real_inv, div_eq_mul_inv]
lemma of_real_prod_of_nonneg {s : finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) :
ennreal.of_real (∏ i in s, f i) = ∏ i in s, ennreal.of_real (f i) :=
begin
simp_rw [ennreal.of_real, ←coe_finset_prod, coe_eq_coe],
exact real.to_nnreal_prod_of_nonneg hf,
end
@[simp] lemma to_nnreal_bit0 {x : ℝ≥0∞} : (bit0 x).to_nnreal = bit0 (x.to_nnreal) :=
begin
by_cases hx_top : x = ∞,
{ simp [hx_top, bit0_eq_top_iff.mpr rfl], },
exact to_nnreal_add (lt_top_iff_ne_top.mpr hx_top) (lt_top_iff_ne_top.mpr hx_top),
end
@[simp] lemma to_nnreal_bit1 {x : ℝ≥0∞} (hx_top : x ≠ ∞) :
(bit1 x).to_nnreal = bit1 (x.to_nnreal) :=
by simp [bit1, bit1, to_nnreal_add
(lt_top_iff_ne_top.mpr (by rwa [ne.def, bit0_eq_top_iff])) ennreal.one_lt_top]
@[simp] lemma to_real_bit0 {x : ℝ≥0∞} : (bit0 x).to_real = bit0 (x.to_real) :=
by simp [ennreal.to_real]
@[simp] lemma to_real_bit1 {x : ℝ≥0∞} (hx_top : x ≠ ∞) :
(bit1 x).to_real = bit1 (x.to_real) :=
by simp [ennreal.to_real, hx_top]
@[simp] lemma of_real_bit0 {r : ℝ} (hr : 0 ≤ r) :
ennreal.of_real (bit0 r) = bit0 (ennreal.of_real r) :=
of_real_add hr hr
@[simp] lemma of_real_bit1 {r : ℝ} (hr : 0 ≤ r) :
ennreal.of_real (bit1 r) = bit1 (ennreal.of_real r) :=
(of_real_add (by simp [hr]) zero_le_one).trans (by simp [real.to_nnreal_one, bit1, hr])
end real
section infi
variables {ι : Sort*} {f g : ι → ℝ≥0∞}
lemma infi_add : infi f + a = ⨅i, f i + a :=
le_antisymm
(le_infi $ assume i, add_le_add (infi_le _ _) $ le_refl _)
(ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _)
lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) :=
le_antisymm
(ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i)
(supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a))
lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) :=
begin
refine (eq_of_forall_ge_iff $ λ c, _),
rw [ennreal.sub_le_iff_le_add, add_comm, infi_add],
simp [ennreal.sub_le_iff_le_add, sub_eq_add_neg, add_comm],
end
lemma Inf_add {s : set ℝ≥0∞} : Inf s + a = ⨅b∈s, b + a :=
by simp [Inf_eq_infi, infi_add]
lemma add_infi {a : ℝ≥0∞} : a + infi f = ⨅b, a + f b :=
by rw [add_comm, infi_add]; simp [add_comm]
lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) :=
suffices (⨅a, f a + g a) ≤ infi f + infi g,
from le_antisymm (le_infi $ assume a, add_le_add (infi_le _ _) (infi_le _ _)) this,
calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') :
le_infi $ assume a, le_infi $ assume a',
let ⟨k, h⟩ := h a a' in infi_le_of_le k h
... ≤ infi f + infi g :
by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _
lemma infi_sum {f : ι → α → ℝ≥0∞} {s : finset α} [nonempty ι]
(h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) :
(⨅i, ∑ a in s, f i a) = ∑ a in s, ⨅i, f i a :=
finset.induction_on s (by simp) $ assume a s ha ih,
have ∀ (i j : ι), ∃ (k : ι), f k a + ∑ b in s, f k b ≤ f i a + ∑ b in s, f j b,
from assume i j,
let ⟨k, hk⟩ := h (insert a s) i j in
⟨k, add_le_add (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum $
assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩,
by simp [ha, ih.symm, infi_add_infi this]
/-- If `x ≠ 0` and `x ≠ ∞`, then right multiplication by `x` maps infimum to infimum.
See also `ennreal.infi_mul` that assumes `[nonempty ι]` but does not require `x ≠ 0`. -/
lemma infi_mul_of_ne {ι} {f : ι → ℝ≥0∞} {x : ℝ≥0∞} (h0 : x ≠ 0) (h : x ≠ ∞) :
infi f * x = ⨅ i, f i * x :=
le_antisymm
mul_right_mono.map_infi_le
((div_le_iff_le_mul (or.inl h0) $ or.inl h).mp $ le_infi $
λ i, (div_le_iff_le_mul (or.inl h0) $ or.inl h).mpr $ infi_le _ _)
/-- If `x ≠ ∞`, then right multiplication by `x` maps infimum over a nonempty type to infimum. See
also `ennreal.infi_mul_of_ne` that assumes `x ≠ 0` but does not require `[nonempty ι]`. -/
lemma infi_mul {ι} [nonempty ι] {f : ι → ℝ≥0∞} {x : ℝ≥0∞} (h : x ≠ ∞) :
infi f * x = ⨅ i, f i * x :=
begin
by_cases h0 : x = 0,
{ simp only [h0, mul_zero, infi_const] },
{ exact infi_mul_of_ne h0 h }
end
/-- If `x ≠ ∞`, then left multiplication by `x` maps infimum over a nonempty type to infimum. See
also `ennreal.mul_infi_of_ne` that assumes `x ≠ 0` but does not require `[nonempty ι]`. -/
lemma mul_infi {ι} [nonempty ι] {f : ι → ℝ≥0∞} {x : ℝ≥0∞} (h : x ≠ ∞) :
x * infi f = ⨅ i, x * f i :=
by simpa only [mul_comm] using infi_mul h
/-- If `x ≠ 0` and `x ≠ ∞`, then left multiplication by `x` maps infimum to infimum.
See also `ennreal.mul_infi` that assumes `[nonempty ι]` but does not require `x ≠ 0`. -/
lemma mul_infi_of_ne {ι} {f : ι → ℝ≥0∞} {x : ℝ≥0∞} (h0 : x ≠ 0) (h : x ≠ ∞) :
x * infi f = ⨅ i, x * f i :=
by simpa only [mul_comm] using infi_mul_of_ne h0 h
/-! `supr_mul`, `mul_supr` and variants are in `topology.instances.ennreal`. -/
end infi
section supr
@[simp] lemma supr_eq_zero {ι : Sort*} {f : ι → ℝ≥0∞} : (⨆ i, f i) = 0 ↔ ∀ i, f i = 0 :=
supr_eq_bot
@[simp] lemma supr_zero_eq_zero {ι : Sort*} : (⨆ i : ι, (0 : ℝ≥0∞)) = 0 :=
by simp
lemma sup_eq_zero {a b : ℝ≥0∞} : a ⊔ b = 0 ↔ a = 0 ∧ b = 0 := sup_eq_bot_iff
lemma supr_coe_nat : (⨆n:ℕ, (n : ℝ≥0∞)) = ∞ :=
(supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb)
end supr
/-- `le_of_add_le_add_left` is normally applicable to `ordered_cancel_add_comm_monoid`,
but it holds in `ℝ≥0∞` with the additional assumption that `a < ∞`. -/
lemma le_of_add_le_add_left {a b c : ℝ≥0∞} : a < ∞ →
a + b ≤ a + c → b ≤ c :=
by cases a; cases b; cases c; simp [← ennreal.coe_add, ennreal.coe_le_coe]
/-- `le_of_add_le_add_right` is normally applicable to `ordered_cancel_add_comm_monoid`,
but it holds in `ℝ≥0∞` with the additional assumption that `a < ∞`. -/
lemma le_of_add_le_add_right {a b c : ℝ≥0∞} : a < ∞ →
b + a ≤ c + a → b ≤ c :=
by simpa only [add_comm _ a] using le_of_add_le_add_left
end ennreal
|
a306ef4a1aae5324a8dabd3578ccbaeb6d2ea856
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/group_theory/specific_groups/dihedral.lean
|
889f538502344b686af5586d53e071094c014cd7
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,915
|
lean
|
/-
Copyright (c) 2020 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import data.zmod.basic
import group_theory.exponent
/-!
# Dihedral Groups
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.
For `n ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`
represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of the
`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
/--
For `n ≠ 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.
`r i` represents the rotations of the `n`-gon by `2πi/n`, and `sr i` represents the reflections of
the `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
@[derive decidable_eq]
inductive dihedral_group (n : ℕ) : Type
| r : zmod n → dihedral_group
| sr : zmod n → dihedral_group
namespace dihedral_group
variables {n : ℕ}
/--
Multiplication of the dihedral group.
-/
private def mul : dihedral_group n → dihedral_group n → dihedral_group n
| (r i) (r j) := r (i + j)
| (r i) (sr j) := sr (j - i)
| (sr i) (r j) := sr (i + j)
| (sr i) (sr j) := r (j - i)
/--
The identity `1` is the rotation by `0`.
-/
private def one : dihedral_group n := r 0
instance : inhabited (dihedral_group n) := ⟨one⟩
/--
The inverse of a an element of the dihedral group.
-/
private def inv : dihedral_group n → dihedral_group n
| (r i) := r (-i)
| (sr i) := sr i
/--
The group structure on `dihedral_group n`.
-/
instance : group (dihedral_group n) :=
{ mul := mul,
mul_assoc :=
begin
rintros (a | a) (b | b) (c | c);
simp only [mul];
ring,
end,
one := one,
one_mul :=
begin
rintros (a | a),
exact congr_arg r (zero_add a),
exact congr_arg sr (sub_zero a),
end,
mul_one := begin
rintros (a | a),
exact congr_arg r (add_zero a),
exact congr_arg sr (add_zero a),
end,
inv := inv,
mul_left_inv := begin
rintros (a | a),
exact congr_arg r (neg_add_self a),
exact congr_arg r (sub_self a),
end }
@[simp] lemma r_mul_r (i j : zmod n) : r i * r j = r (i + j) := rfl
@[simp] lemma r_mul_sr (i j : zmod n) : r i * sr j = sr (j - i) := rfl
@[simp] lemma sr_mul_r (i j : zmod n) : sr i * r j = sr (i + j) := rfl
@[simp] lemma sr_mul_sr (i j : zmod n) : sr i * sr j = r (j - i) := rfl
lemma one_def : (1 : dihedral_group n) = r 0 := rfl
private def fintype_helper : (zmod n ⊕ zmod n) ≃ dihedral_group n :=
{ inv_fun := λ i, match i with
| (r j) := sum.inl j
| (sr j) := sum.inr j
end,
to_fun := λ i, match i with
| (sum.inl j) := r j
| (sum.inr j) := sr j
end,
left_inv := by rintro (x | x); refl,
right_inv := by rintro (x | x); refl }
/--
If `0 < n`, then `dihedral_group n` is a finite group.
-/
instance [ne_zero n] : fintype (dihedral_group n) := fintype.of_equiv _ fintype_helper
instance : nontrivial (dihedral_group n) := ⟨⟨r 0, sr 0, dec_trivial⟩⟩
/--
If `0 < n`, then `dihedral_group n` has `2n` elements.
-/
lemma card [ne_zero n] : fintype.card (dihedral_group n) = 2 * n :=
by rw [← fintype.card_eq.mpr ⟨fintype_helper⟩, fintype.card_sum, zmod.card, two_mul]
@[simp] lemma r_one_pow (k : ℕ) : (r 1 : dihedral_group n) ^ k = r k :=
begin
induction k with k IH,
{ rw nat.cast_zero, refl },
{ rw [pow_succ, IH, r_mul_r],
congr' 1,
norm_cast,
rw nat.one_add }
end
@[simp] lemma r_one_pow_n : (r (1 : zmod n))^n = 1 :=
begin
rw [r_one_pow, one_def],
congr' 1,
exact zmod.nat_cast_self _,
end
@[simp] lemma sr_mul_self (i : zmod n) : sr i * sr i = 1 := by rw [sr_mul_sr, sub_self, one_def]
/--
If `0 < n`, then `sr i` has order 2.
-/
@[simp] lemma order_of_sr (i : zmod n) : order_of (sr i) = 2 :=
begin
rw order_of_eq_prime _ _,
{ exact ⟨nat.prime_two⟩ },
rw [sq, sr_mul_self],
dec_trivial,
end
/--
If `0 < n`, then `r 1` has order `n`.
-/
@[simp] lemma order_of_r_one : order_of (r 1 : dihedral_group n) = n :=
begin
rcases eq_zero_or_ne_zero n with rfl | hn,
{ rw order_of_eq_zero_iff',
intros n hn,
rw [r_one_pow, one_def],
apply mt r.inj,
simpa using hn.ne' },
{ resetI,
apply (nat.le_of_dvd (ne_zero.pos n) $ order_of_dvd_of_pow_eq_one $ @r_one_pow_n n)
.lt_or_eq.resolve_left,
intro h,
have h1 : (r 1 : dihedral_group n)^(order_of (r 1)) = 1,
{ exact pow_order_of_eq_one _ },
rw r_one_pow at h1,
injection h1 with h2,
rw [← zmod.val_eq_zero, zmod.val_nat_cast, nat.mod_eq_of_lt h] at h2,
exact absurd h2.symm (order_of_pos _).ne },
end
/--
If `0 < n`, then `i : zmod n` has order `n / gcd n i`.
-/
lemma order_of_r [ne_zero n] (i : zmod n) : order_of (r i) = n / nat.gcd n i.val :=
begin
conv_lhs { rw ←zmod.nat_cast_zmod_val i },
rw [←r_one_pow, order_of_pow, order_of_r_one]
end
lemma exponent : monoid.exponent (dihedral_group n) = lcm n 2 :=
begin
rcases eq_zero_or_ne_zero n with rfl | hn,
{ exact monoid.exponent_eq_zero_of_order_zero order_of_r_one },
resetI,
apply nat.dvd_antisymm,
{ apply monoid.exponent_dvd_of_forall_pow_eq_one,
rintro (m | m),
{ rw [←order_of_dvd_iff_pow_eq_one, order_of_r],
refine nat.dvd_trans ⟨gcd n m.val, _⟩ (dvd_lcm_left n 2),
{ exact (nat.div_mul_cancel (nat.gcd_dvd_left n m.val)).symm } },
{ rw [←order_of_dvd_iff_pow_eq_one, order_of_sr],
exact dvd_lcm_right n 2 } },
{ apply lcm_dvd,
{ convert monoid.order_dvd_exponent (r 1),
exact order_of_r_one.symm },
{ convert monoid.order_dvd_exponent (sr 0),
exact (order_of_sr 0).symm } }
end
end dihedral_group
|
502f9c71d48e255d10fe7f9759b7dc5b3a6000d0
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/unfold_crash.lean
|
c46021fcb3e6c0749a599489b77ef7066c66ce69
|
[
"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
| 198
|
lean
|
--
open nat tactic
example (a b : nat) : a = succ b → a = b + 1 :=
by do
H ← intro `H,
try (unfold_at [`nat.succ] H),
unfold [`add], dsimp, unfold [`nat.add],
trace_state,
assumption
|
446112a9d70f5ee528e50e3c74bafc85fad23a38
|
5883d9218e6f144e20eee6ca1dab8529fa1a97c0
|
/src/vrel/map.lean
|
6a6eadff2c9298abc3c6c9bf3b540d83f0408102
|
[] |
no_license
|
spl/alpha-conversion-is-easy
|
0d035bc570e52a6345d4890e4d0c9e3f9b8126c1
|
ed937fe85d8495daffd9412a5524c77b9fcda094
|
refs/heads/master
| 1,607,649,280,020
| 1,517,380,240,000
| 1,517,380,240,000
| 52,174,747
| 4
| 0
| null | 1,456,052,226,000
| 1,456,001,163,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,718
|
lean
|
/-
This file contains declarations for mapping one `vrel` to another.
-/
import .update
namespace acie -----------------------------------------------------------------
namespace vrel -----------------------------------------------------------------
variables {V : Type} [decidable_eq V] -- Type of variable names
variables {vs : Type → Type} [vset vs V] -- Type of variable name sets
variables {X X₁ X₂ Y Y₁ Y₂ : vs V} -- Variable name sets
-- The type of a function that maps over the sets of a `vrel`.
@[reducible]
protected
def map (R : X₁ ×ν Y₁) (S : X₂ ×ν Y₂) :=
∀ (x : ν∈ X₁) (y : ν∈ Y₁), ⟪x, y⟫ ∈ν R
→ ∃ (px : x.1 ∈ X₂) (py : y.1 ∈ Y₂)
, ⟪vname.map_of_mem x px, vname.map_of_mem y py⟫ ∈ν S
-- Notation for `map`.
infixr ` ⇒ν `:30 := vrel.map
namespace map ------------------------------------------------------------------
section ------------------------------------------------------------------------
variables {R : X₁ ×ν Y₁} {S : X₂ ×ν Y₂} -- Variable name set relations
-- Lift a `map` over `vrel.update`.
protected
theorem update (a b : V) : R ⇒ν S → R ⩁ (a, b) ⇒ν S ⩁ (a, b) :=
begin
intros F x y x_update_R_y,
cases x_update_R_y with H H,
begin
cases H with x_eq_a y_eq_b,
existsi vset.prop_insert_self_if_eq X₂ x_eq_a,
existsi vset.prop_insert_self_if_eq Y₂ y_eq_b,
left, split, exact x_eq_a, exact y_eq_b
end,
begin
cases H with x_ne_a H, cases H with y_ne_b x_R_y,
cases F (vname.erase x x_ne_a) (vname.erase y y_ne_b) x_R_y with px H,
cases H with py x_S_y,
existsi vset.prop_insert a px,
existsi vset.prop_insert b py,
right, existsi x_ne_a, existsi y_ne_b, exact x_S_y
end
end
end /- section -/ --------------------------------------------------------------
section ------------------------------------------------------------------------
variables {R S : X ×ν Y} -- Variable name set relations
-- Lift a simpler function on `vrel` membership to a `map`.
protected
theorem simple : (∀ (x : ν∈ X) (y : ν∈ Y), ⟪x, y⟫ ∈ν R → ⟪x, y⟫ ∈ν S) → R ⇒ν S :=
begin
intros F x y x_R_y,
cases x with x px, cases y with y py,
existsi px, existsi py,
exact F (vname.map_of_mem ⟨x, px⟩ px) (vname.map_of_mem ⟨y, py⟩ py) x_R_y
end
end /- section -/ --------------------------------------------------------------
end /- namespace -/ map --------------------------------------------------------
end /- namespace -/ vrel -------------------------------------------------------
end /- namespace -/ acie -------------------------------------------------------
|
8674289d9c1234c10a6705e2c4fe36920d353c5d
|
968e2f50b755d3048175f176376eff7139e9df70
|
/examples/prop_logic_theory/unnamed_1320.lean
|
27d947c174fca413b670954f440d3357c04af4a4
|
[] |
no_license
|
gihanmarasingha/mth1001_sphinx
|
190a003269ba5e54717b448302a27ca26e31d491
|
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
|
refs/heads/master
| 1,672,913,933,677
| 1,604,516,583,000
| 1,604,516,583,000
| 309,245,750
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 713
|
lean
|
variables p q r : Prop
theorem imp_trans1 : (p → q) → (q → r) → (p → r) :=
λ h₁ h₂ h₃, h₂ (h₁ h₃)
-- BEGIN
example (h₁ : p ↔ q) (h₂ : q ↔ r) : p ↔ r :=
begin
split, -- By iff intro., it suffices to prove `p → r` and `r → p`.
{ show p → r, apply imp_trans1, -- We show `p → r`. By transitivity of `→`, it suffices to prove `p → ?` and `? → r`.
{ show p → q, from h₁.1, }, -- We show `p → q` by left iff elimination on `h₁`.
{ show q → r, from h₂.1, }, }, -- We show `q → r` by left iff elimination on `h₂`.
{ show r → p, sorry }, -- The proof of `r → p` is left to the reader.
end
-- END
|
2362ac1ba9043028d7ca31430186534129c416d8
|
947b78d97130d56365ae2ec264df196ce769371a
|
/tests/lean/run/finally.lean
|
3e6999276ecfc733a3ce42de3d9fb972ef574bf3
|
[
"Apache-2.0"
] |
permissive
|
shyamalschandra/lean4
|
27044812be8698f0c79147615b1d5090b9f4b037
|
6e7a883b21eaf62831e8111b251dc9b18f40e604
|
refs/heads/master
| 1,671,417,126,371
| 1,601,859,995,000
| 1,601,860,020,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,855
|
lean
|
new_frontend
def checkM (b : IO Bool) : IO Unit :=
unlessM b (throw $ IO.userError "failed")
abbrev M := ExceptT String $ StateRefT Nat $ IO
def f1 : M Nat :=
throw "error 1"
def f2 : M Nat :=
throwThe IO.Error $ IO.userError "error 2"
def tst1 : M Nat :=
«catch»
(«finally» f1 (do set 100; IO.println "finisher executed"))
(fun _ => get)
def checkE {α ε : Type} [HasBeq α] (x : IO (Except ε α)) (expected : α) : IO Unit := do
let r ← x;
(match r with
| Except.ok a => «unless» (a == expected) $ throw $ IO.userError "unexpected result"
| Except.error _ => throw $ IO.userError "unexpected error")
#eval (tst1.run).run' 0
#eval checkE ((tst1.run).run' 0) 100
def tst2 : M Nat :=
catchThe IO.Error
(«finally» f2 (do set 100; IO.println "finisher executed"))
(fun _ => get)
#eval (tst2.run).run' 0
#eval checkE ((tst2.run).run' 0) 100
def tst3 : M Nat :=
catchThe IO.Error
(«finally»
(«finally» f1 (do set 100; IO.println "inner finisher executed"; f2; pure ()))
(do modify Nat.succ; IO.println "outer finisher executed"))
(fun _ => get)
#eval (tst3.run).run' 0
#eval checkE ((tst3.run).run' 0) 101
def tst4 : M Nat := do
let a ← «finally»
(«finally» (pure 42) (do set 100; IO.println "inner finisher executed"; pure ()))
(do modify Nat.succ; IO.println "outer finisher executed");
let s ← get;
pure (a + s)
#eval (tst4.run).run' 0
#eval checkE ((tst4.run).run' 0) 143
def tst5 : M Nat := do
let (a, _) ← finally' (pure 42) (fun a? => do IO.println ("finalizer received: " ++ toString a?));
pure a
#eval (tst5.run).run' 0
def tst6 : M Nat := do
let (a, _) ← finally' f2 (fun a? => do IO.println ("finalizer received: " ++ toString a?));
pure a
def tst7 : IO Unit :=
catchThe IO.Error (do (tst6.run).run' 0; pure ()) (fun _ => IO.println "failed as expected")
#eval tst7
|
9cb163526820740fc0020309f338ca3cf12f9de1
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/group_theory/group_action/basic.lean
|
e264febc6ba9c1ee4b5e12b7b391b479c77848cd
|
[
"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
| 12,669
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import algebra.hom.group_action
import group_theory.group_action.defs
import group_theory.group_action.group
import data.setoid.basic
import data.fintype.card
/-!
# Basic properties of group actions
This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of
actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation
of `•` belong elsewhere.
## Main definitions
* `mul_action.orbit`
* `mul_action.fixed_points`
* `mul_action.fixed_by`
* `mul_action.stabilizer`
-/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
open_locale big_operators pointwise
open function
namespace mul_action
variables (α) [monoid α] [mul_action α β]
/-- The orbit of an element under an action. -/
@[to_additive "The orbit of an element under an action."]
def orbit (b : β) := set.range (λ x : α, x • b)
variable {α}
@[to_additive] lemma mem_orbit_iff {b₁ b₂ : β} : b₂ ∈ orbit α b₁ ↔ ∃ x : α, x • b₁ = b₂ :=
iff.rfl
@[simp, to_additive] lemma mem_orbit (b : β) (x : α) : x • b ∈ orbit α b :=
⟨x, rfl⟩
@[simp, to_additive] lemma mem_orbit_self (b : β) : b ∈ orbit α b :=
⟨1, by simp [mul_action.one_smul]⟩
@[to_additive] lemma orbit_nonempty (b : β) : set.nonempty (orbit α b) := set.range_nonempty _
@[to_additive] lemma maps_to_smul_orbit (a : α) (b : β) :
set.maps_to ((•) a) (orbit α b) (orbit α b) :=
set.range_subset_iff.2 $ λ a', ⟨a * a', mul_smul _ _ _⟩
@[to_additive] lemma smul_orbit_subset (a : α) (b : β) : a • orbit α b ⊆ orbit α b :=
(maps_to_smul_orbit a b).image_subset
@[to_additive] lemma orbit_smul_subset (a : α) (b : β) : orbit α (a • b) ⊆ orbit α b :=
set.range_subset_iff.2 $ λ a', mul_smul a' a b ▸ mem_orbit _ _
@[to_additive] instance {b : β} : mul_action α (orbit α b) :=
{ smul := λ a, (maps_to_smul_orbit a b).restrict _ _ _,
one_smul := λ a, subtype.ext (one_smul α a),
mul_smul := λ a a' b', subtype.ext (mul_smul a a' b') }
@[simp, to_additive] lemma orbit.coe_smul {b : β} {a : α} {b' : orbit α b} :
↑(a • b') = a • (b' : β) :=
rfl
variables (α) (β)
/-- The set of elements fixed under the whole action. -/
@[to_additive "The set of elements fixed under the whole action."]
def fixed_points : set β := {b : β | ∀ x : α, x • b = b}
/-- `fixed_by g` is the subfield of elements fixed by `g`. -/
@[to_additive "`fixed_by g` is the subfield of elements fixed by `g`."]
def fixed_by (g : α) : set β :=
{ x | g • x = x }
@[to_additive] theorem fixed_eq_Inter_fixed_by : fixed_points α β = ⋂ g : α, fixed_by α β g :=
set.ext $ λ x, ⟨λ hx, set.mem_Inter.2 $ λ g, hx g, λ hx g, by exact (set.mem_Inter.1 hx g : _)⟩
variables {α} (β)
@[simp, to_additive] lemma mem_fixed_points {b : β} :
b ∈ fixed_points α β ↔ ∀ x : α, x • b = b := iff.rfl
@[simp, to_additive] lemma mem_fixed_by {g : α} {b : β} :
b ∈ fixed_by α β g ↔ g • b = b := iff.rfl
@[to_additive] lemma mem_fixed_points' {b : β} : b ∈ fixed_points α β ↔
(∀ b', b' ∈ orbit α b → b' = b) :=
⟨λ h b h₁, let ⟨x, hx⟩ := mem_orbit_iff.1 h₁ in hx ▸ h x,
λ h b, h _ (mem_orbit _ _)⟩
variables (α) {β}
/-- The stabilizer of a point `b` as a submonoid of `α`. -/
@[to_additive "The stabilizer of a point `b` as an additive submonoid of `α`."]
def stabilizer.submonoid (b : β) : submonoid α :=
{ carrier := { a | a • b = b },
one_mem' := one_smul _ b,
mul_mem' := λ a a' (ha : a • b = b) (hb : a' • b = b),
show (a * a') • b = b, by rw [←smul_smul, hb, ha] }
@[simp, to_additive] lemma mem_stabilizer_submonoid_iff {b : β} {a : α} :
a ∈ stabilizer.submonoid α b ↔ a • b = b := iff.rfl
@[to_additive] lemma orbit_eq_univ [is_pretransitive α β] (x : β) :
orbit α x = set.univ :=
(surjective_smul α x).range_eq
variables {α} {β}
@[to_additive] lemma mem_fixed_points_iff_card_orbit_eq_one {a : β}
[fintype (orbit α a)] : a ∈ fixed_points α β ↔ fintype.card (orbit α a) = 1 :=
begin
rw [fintype.card_eq_one_iff, mem_fixed_points],
split,
{ exact λ h, ⟨⟨a, mem_orbit_self _⟩, λ ⟨b, ⟨x, hx⟩⟩, subtype.eq $ by simp [h x, hx.symm]⟩ },
{ assume h x,
rcases h with ⟨⟨z, hz⟩, hz₁⟩,
calc x • a = z : subtype.mk.inj (hz₁ ⟨x • a, mem_orbit _ _⟩)
... = a : (subtype.mk.inj (hz₁ ⟨a, mem_orbit_self _⟩)).symm }
end
end mul_action
namespace mul_action
variable (α)
variables [group α] [mul_action α β]
/-- The stabilizer of an element under an action, i.e. what sends the element to itself.
A subgroup. -/
@[to_additive "The stabilizer of an element under an action, i.e. what sends the element to itself.
An additive subgroup."]
def stabilizer (b : β) : subgroup α :=
{ inv_mem' := λ a (ha : a • b = b), show a⁻¹ • b = b, by rw [inv_smul_eq_iff, ha]
..stabilizer.submonoid α b }
variables {α} {β}
@[simp, to_additive] lemma mem_stabilizer_iff {b : β} {a : α} :
a ∈ stabilizer α b ↔ a • b = b := iff.rfl
@[simp, to_additive] lemma smul_orbit (a : α) (b : β) :
a • orbit α b = orbit α b :=
(smul_orbit_subset a b).antisymm $
calc orbit α b = a • a⁻¹ • orbit α b : (smul_inv_smul _ _).symm
... ⊆ a • orbit α b : set.image_subset _ (smul_orbit_subset _ _)
@[simp, to_additive] lemma orbit_smul (a : α) (b : β) : orbit α (a • b) = orbit α b :=
(orbit_smul_subset a b).antisymm $
calc orbit α b = orbit α (a⁻¹ • a • b) : by rw inv_smul_smul
... ⊆ orbit α (a • b) : orbit_smul_subset _ _
/-- The action of a group on an orbit is transitive. -/
@[to_additive "The action of an additive group on an orbit is transitive."]
instance (x : β) : is_pretransitive α (orbit α x) :=
⟨by { rintro ⟨_, a, rfl⟩ ⟨_, b, rfl⟩, use b * a⁻¹, ext1, simp [mul_smul] }⟩
@[to_additive] lemma orbit_eq_iff {a b : β} :
orbit α a = orbit α b ↔ a ∈ orbit α b:=
⟨λ h, h ▸ mem_orbit_self _, λ ⟨c, hc⟩, hc ▸ orbit_smul _ _⟩
variables (α) {β}
@[to_additive] lemma mem_orbit_smul (g : α) (a : β) : a ∈ orbit α (g • a) :=
by simp only [orbit_smul, mem_orbit_self]
@[to_additive] lemma smul_mem_orbit_smul (g h : α) (a : β) : g • a ∈ orbit α (h • a) :=
by simp only [orbit_smul, mem_orbit]
variables (α) (β)
/-- The relation 'in the same orbit'. -/
@[to_additive "The relation 'in the same orbit'."]
def orbit_rel : setoid β :=
{ r := λ a b, a ∈ orbit α b,
iseqv := ⟨mem_orbit_self, λ a b, by simp [orbit_eq_iff.symm, eq_comm],
λ a b, by simp [orbit_eq_iff.symm, eq_comm] {contextual := tt}⟩ }
local attribute [instance] orbit_rel
variables {α} {β}
/-- When you take a set `U` in `β`, push it down to the quotient, and pull back, you get the union
of the orbit of `U` under `α`.
-/
@[to_additive] lemma quotient_preimage_image_eq_union_mul (U : set β) :
quotient.mk ⁻¹' (quotient.mk '' U) = ⋃ a : α, ((•) a) '' U :=
begin
set f : β → quotient (mul_action.orbit_rel α β) := quotient.mk,
ext,
split,
{ rintros ⟨y , hy, hxy⟩,
obtain ⟨a, rfl⟩ := quotient.exact hxy,
rw set.mem_Union,
exact ⟨a⁻¹, a • x, hy, inv_smul_smul a x⟩ },
{ intros hx,
rw set.mem_Union at hx,
obtain ⟨a, u, hu₁, hu₂⟩ := hx,
rw [set.mem_preimage, set.mem_image_iff_bex],
refine ⟨a⁻¹ • x, _, by simp only [quotient.eq]; use a⁻¹⟩,
rw ← hu₂,
convert hu₁,
simp only [inv_smul_smul], },
end
@[to_additive] lemma disjoint_image_image_iff {U V : set β} :
disjoint (quotient.mk '' U) (quotient.mk '' V) ↔ ∀ x ∈ U, ∀ a : α, a • x ∉ V :=
begin
set f : β → quotient (mul_action.orbit_rel α β) := quotient.mk,
refine ⟨λ h x x_in_U a a_in_V, h ⟨⟨x, x_in_U, quotient.sound ⟨a⁻¹, _⟩⟩, ⟨a • x, a_in_V, rfl⟩⟩, _⟩,
{ simp },
{ rintro h x ⟨⟨y, hy₁, hy₂⟩, ⟨z, hz₁, hz₂⟩⟩,
obtain ⟨a, rfl⟩ := quotient.exact (hz₂.trans hy₂.symm),
exact h y hy₁ a hz₁ }
end
@[to_additive]
lemma image_inter_image_iff (U V : set β) :
(quotient.mk '' U) ∩ (quotient.mk '' V) = ∅ ↔ ∀ x ∈ U, ∀ a : α, a • x ∉ V :=
set.disjoint_iff_inter_eq_empty.symm.trans disjoint_image_image_iff
variables (α) (β)
local notation `Ω` := (quotient $ orbit_rel α β)
/-- Decomposition of a type `X` as a disjoint union of its orbits under a group action.
This version works with any right inverse to `quotient.mk'` in order to stay computable. In most
cases you'll want to use `quotient.out'`, so we provide `mul_action.self_equiv_sigma_orbits` as
a special case. -/
@[to_additive "Decomposition of a type `X` as a disjoint union of its orbits under an additive group
action. This version works with any right inverse to `quotient.mk'` in order to stay computable.
In most cases you'll want to use `quotient.out'`, so we provide `add_action.self_equiv_sigma_orbits`
as a special case."]
def self_equiv_sigma_orbits' {φ : Ω → β} (hφ : right_inverse φ quotient.mk') :
β ≃ Σ (ω : Ω), orbit α (φ ω) :=
calc β
≃ Σ (ω : Ω), {b // quotient.mk' b = ω} : (equiv.sigma_fiber_equiv quotient.mk').symm
... ≃ Σ (ω : Ω), orbit α (φ ω) :
equiv.sigma_congr_right (λ ω, equiv.subtype_equiv_right $
λ x, by {rw [← hφ ω, quotient.eq', hφ ω], refl })
/-- Decomposition of a type `X` as a disjoint union of its orbits under a group action. -/
@[to_additive "Decomposition of a type `X` as a disjoint union of its orbits under an additive group
action."]
noncomputable def self_equiv_sigma_orbits : β ≃ Σ (ω : Ω), orbit α ω.out' :=
self_equiv_sigma_orbits' α β quotient.out_eq'
variables {α β}
/-- If the stabilizer of `x` is `S`, then the stabilizer of `g • x` is `gSg⁻¹`. -/
lemma stabilizer_smul_eq_stabilizer_map_conj (g : α) (x : β) :
(stabilizer α (g • x) = (stabilizer α x).map (mul_aut.conj g).to_monoid_hom) :=
begin
ext h,
rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, mul_left_inv,
one_smul, ← mem_stabilizer_iff, subgroup.mem_map_equiv, mul_aut.conj_symm_apply]
end
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizer_equiv_stabilizer_of_orbit_rel {x y : β} (h : (orbit_rel α β).rel x y) :
stabilizer α x ≃* stabilizer α y :=
let g : α := classical.some h in
have hg : g • y = x := classical.some_spec h,
have this : stabilizer α x = (stabilizer α y).map (mul_aut.conj g).to_monoid_hom,
by rw [← hg, stabilizer_smul_eq_stabilizer_map_conj],
(mul_equiv.subgroup_congr this).trans ((mul_aut.conj g).subgroup_map $ stabilizer α y).symm
end mul_action
namespace add_action
variables [add_group α] [add_action α β]
/-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/
lemma stabilizer_vadd_eq_stabilizer_map_conj (g : α) (x : β) :
(stabilizer α (g +ᵥ x) = (stabilizer α x).map (add_aut.conj g).to_add_monoid_hom) :=
begin
ext h,
rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g) , vadd_vadd, vadd_vadd, vadd_vadd,
add_left_neg, zero_vadd, ← mem_stabilizer_iff, add_subgroup.mem_map_equiv,
add_aut.conj_symm_apply]
end
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizer_equiv_stabilizer_of_orbit_rel {x y : β}
(h : (orbit_rel α β).rel x y) :
stabilizer α x ≃+ stabilizer α y :=
let g : α := classical.some h in
have hg : g +ᵥ y = x := classical.some_spec h,
have this : stabilizer α x = (stabilizer α y).map (add_aut.conj g).to_add_monoid_hom,
by rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj],
(add_equiv.add_subgroup_congr this).trans
((add_aut.conj g).add_subgroup_map $ stabilizer α y).symm
end add_action
/-- `smul` by a `k : M` over a ring is injective, if `k` is not a zero divisor.
The general theory of such `k` is elaborated by `is_smul_regular`.
The typeclass that restricts all terms of `M` to have this property is `no_zero_smul_divisors`. -/
lemma smul_cancel_of_non_zero_divisor {M R : Type*}
[monoid M] [non_unital_non_assoc_ring R] [distrib_mul_action M R]
(k : M) (h : ∀ (x : R), k • x = 0 → x = 0) {a b : R} (h' : k • a = k • b) :
a = b :=
begin
rw ←sub_eq_zero,
refine h _ _,
rw [smul_sub, h', sub_self]
end
|
c782a1429c1d969cf182e5375fb7ad787d2f5d77
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/topology/homotopy/basic.lean
|
7deeee09350bc9769f4801ddac1beccdff91701f
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/mathlib
|
dc0be621c6c8208c581f5170a8216c5ba6721927
|
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
|
refs/heads/master
| 1,685,523,275,196
| 1,670,184,141,000
| 1,670,184,141,000
| 287,574,545
| 0
| 0
|
Apache-2.0
| 1,670,290,714,000
| 1,597,421,623,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 20,466
|
lean
|
/-
Copyright (c) 2021 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import topology.algebra.order.proj_Icc
import topology.continuous_function.ordered
import topology.compact_open
import topology.unit_interval
/-!
# Homotopy between functions
In this file, we define a homotopy between two functions `f₀` and `f₁`. First we define
`continuous_map.homotopy` between the two functions, with no restrictions on the intermediate
maps. Then, as in the formalisation in HOL-Analysis, we define
`continuous_map.homotopy_with f₀ f₁ P`, for homotopies between `f₀` and `f₁`, where the
intermediate maps satisfy the predicate `P`. Finally, we define
`continuous_map.homotopy_rel f₀ f₁ S`, for homotopies between `f₀` and `f₁` which are fixed
on `S`.
## Definitions
* `continuous_map.homotopy f₀ f₁` is the type of homotopies between `f₀` and `f₁`.
* `continuous_map.homotopy_with f₀ f₁ P` is the type of homotopies between `f₀` and `f₁`, where
the intermediate maps satisfy the predicate `P`.
* `continuous_map.homotopy_rel f₀ f₁ S` is the type of homotopies between `f₀` and `f₁` which
are fixed on `S`.
For each of the above, we have
* `refl f`, which is the constant homotopy from `f` to `f`.
* `symm F`, which reverses the homotopy `F`. For example, if `F : continuous_map.homotopy f₀ f₁`,
then `F.symm : continuous_map.homotopy f₁ f₀`.
* `trans F G`, which concatenates the homotopies `F` and `G`. For example, if
`F : continuous_map.homotopy f₀ f₁` and `G : continuous_map.homotopy f₁ f₂`, then
`F.trans G : continuous_map.homotopy f₀ f₂`.
We also define the relations
* `continuous_map.homotopic f₀ f₁` is defined to be `nonempty (continuous_map.homotopy f₀ f₁)`
* `continuous_map.homotopic_with f₀ f₁ P` is defined to be
`nonempty (continuous_map.homotopy_with f₀ f₁ P)`
* `continuous_map.homotopic_rel f₀ f₁ P` is defined to be
`nonempty (continuous_map.homotopy_rel f₀ f₁ P)`
and for `continuous_map.homotopic` and `continuous_map.homotopic_rel`, we also define the
`setoid` and `quotient` in `C(X, Y)` by these relations.
## References
- [HOL-Analysis formalisation](https://isabelle.in.tum.de/library/HOL/HOL-Analysis/Homotopy.html)
-/
noncomputable theory
universes u v w
variables {F : Type*} {X : Type u} {Y : Type v} {Z : Type w}
variables [topological_space X] [topological_space Y] [topological_space Z]
open_locale unit_interval
namespace continuous_map
/-- `continuous_map.homotopy f₀ f₁` is the type of homotopies from `f₀` to `f₁`.
When possible, instead of parametrizing results over `(f : homotopy f₀ f₁)`,
you should parametrize over `{F : Type*} [homotopy_like F f₀ f₁] (f : F)`.
When you extend this structure, make sure to extend `continuous_map.homotopy_like`. -/
structure homotopy (f₀ f₁ : C(X, Y)) extends C(I × X, Y) :=
(map_zero_left' : ∀ x, to_fun (0, x) = f₀ x)
(map_one_left' : ∀ x, to_fun (1, x) = f₁ x)
section
set_option old_structure_cmd true
/-- `continuous_map.homotopy_like F f₀ f₁` states that `F` is a type of homotopies between `f₀` and
`f₁`.
You should extend this class when you extend `continuous_map.homotopy`. -/
class homotopy_like (F : Type*) (f₀ f₁ : out_param $ C(X, Y))
extends continuous_map_class F (I × X) Y :=
(map_zero_left (f : F) : ∀ x, f (0, x) = f₀ x)
(map_one_left (f : F) : ∀ x, f (1, x) = f₁ x)
end
-- `f₀` and `f₁` are `out_param` so this is not dangerous
attribute [nolint dangerous_instance] homotopy_like.to_continuous_map_class
namespace homotopy
section
variables {f₀ f₁ : C(X, Y)}
instance : homotopy_like (homotopy f₀ f₁) f₀ f₁ :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, by { obtain ⟨⟨_, _⟩, _⟩ := f, obtain ⟨⟨_, _⟩, _⟩ := g, congr' },
map_continuous := λ f, f.continuous_to_fun,
map_zero_left := λ f, f.map_zero_left',
map_one_left := λ f, f.map_one_left' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (homotopy f₀ f₁) (λ _, I × X → Y) := fun_like.has_coe_to_fun
@[ext]
lemma ext {F G : homotopy f₀ f₁} (h : ∀ x, F x = G x) : F = G := fun_like.ext _ _ h
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (F : homotopy f₀ f₁) : I × X → Y := F
initialize_simps_projections homotopy (to_continuous_map_to_fun -> apply, -to_continuous_map)
/-- Deprecated. Use `map_continuous` instead. -/
protected lemma continuous (F : homotopy f₀ f₁) : continuous F := F.continuous_to_fun
@[simp]
lemma apply_zero (F : homotopy f₀ f₁) (x : X) : F (0, x) = f₀ x := F.map_zero_left' x
@[simp]
lemma apply_one (F : homotopy f₀ f₁) (x : X) : F (1, x) = f₁ x := F.map_one_left' x
@[simp]
lemma coe_to_continuous_map (F : homotopy f₀ f₁) : ⇑F.to_continuous_map = F := rfl
/--
Currying a homotopy to a continuous function fron `I` to `C(X, Y)`.
-/
def curry (F : homotopy f₀ f₁) : C(I, C(X, Y)) := F.to_continuous_map.curry
@[simp]
lemma curry_apply (F : homotopy f₀ f₁) (t : I) (x : X) : F.curry t x = F (t, x) := rfl
/--
Continuously extending a curried homotopy to a function from `ℝ` to `C(X, Y)`.
-/
def extend (F : homotopy f₀ f₁) : C(ℝ, C(X, Y)) := F.curry.Icc_extend zero_le_one
lemma extend_apply_of_le_zero (F : homotopy f₀ f₁) {t : ℝ} (ht : t ≤ 0) (x : X) :
F.extend t x = f₀ x :=
begin
rw [←F.apply_zero],
exact continuous_map.congr_fun (set.Icc_extend_of_le_left (zero_le_one' ℝ) F.curry ht) x,
end
lemma extend_apply_of_one_le (F : homotopy f₀ f₁) {t : ℝ} (ht : 1 ≤ t) (x : X) :
F.extend t x = f₁ x :=
begin
rw [←F.apply_one],
exact continuous_map.congr_fun (set.Icc_extend_of_right_le (zero_le_one' ℝ) F.curry ht) x,
end
@[simp]
lemma extend_apply_coe (F : homotopy f₀ f₁) (t : I) (x : X) : F.extend t x = F (t, x) :=
continuous_map.congr_fun (set.Icc_extend_coe (zero_le_one' ℝ) F.curry t) x
@[simp]
lemma extend_apply_of_mem_I (F : homotopy f₀ f₁) {t : ℝ} (ht : t ∈ I) (x : X) :
F.extend t x = F (⟨t, ht⟩, x) :=
continuous_map.congr_fun (set.Icc_extend_of_mem (zero_le_one' ℝ) F.curry ht) x
lemma congr_fun {F G : homotopy f₀ f₁} (h : F = G) (x : I × X) : F x = G x :=
continuous_map.congr_fun (congr_arg _ h) x
lemma congr_arg (F : homotopy f₀ f₁) {x y : I × X} (h : x = y) : F x = F y :=
F.to_continuous_map.congr_arg h
end
/--
Given a continuous function `f`, we can define a `homotopy f f` by `F (t, x) = f x`
-/
@[simps]
def refl (f : C(X, Y)) : homotopy f f :=
{ to_fun := λ x, f x.2,
map_zero_left' := λ _, rfl,
map_one_left' := λ _, rfl }
instance : inhabited (homotopy (continuous_map.id X) (continuous_map.id X)) := ⟨homotopy.refl _⟩
/--
Given a `homotopy f₀ f₁`, we can define a `homotopy f₁ f₀` by reversing the homotopy.
-/
@[simps]
def symm {f₀ f₁ : C(X, Y)} (F : homotopy f₀ f₁) : homotopy f₁ f₀ :=
{ to_fun := λ x, F (σ x.1, x.2),
map_zero_left' := by norm_num,
map_one_left' := by norm_num }
@[simp]
lemma symm_symm {f₀ f₁ : C(X, Y)} (F : homotopy f₀ f₁) : F.symm.symm = F :=
by { ext, simp }
/--
Given `homotopy f₀ f₁` and `homotopy f₁ f₂`, we can define a `homotopy f₀ f₂` by putting the first
homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂) :
homotopy f₀ f₂ :=
{ to_fun := λ x, if (x.1 : ℝ) ≤ 1/2 then F.extend (2 * x.1) x.2 else G.extend (2 * x.1 - 1) x.2,
continuous_to_fun := begin
refine continuous_if_le (continuous_induced_dom.comp continuous_fst) continuous_const
(F.continuous.comp (by continuity)).continuous_on
(G.continuous.comp (by continuity)).continuous_on _,
rintros x hx,
norm_num [hx],
end,
map_zero_left' := λ x, by norm_num,
map_one_left' := λ x, by norm_num }
lemma trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
show ite _ _ _ = _,
by split_ifs; { rw [extend, continuous_map.coe_Icc_extend, set.Icc_extend_of_mem], refl }
lemma symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂) :
(F.trans G).symm = G.symm.trans F.symm :=
begin
ext x,
simp only [symm_apply, trans_apply],
split_ifs with h₁ h₂,
{ change (x.1 : ℝ) ≤ _ at h₂,
change (1 : ℝ) - x.1 ≤ _ at h₁,
have ht : (x.1 : ℝ) = 1/2,
{ linarith },
norm_num [ht] },
{ congr' 2,
apply subtype.ext,
simp only [unit_interval.coe_symm_eq, subtype.coe_mk],
linarith },
{ congr' 2,
apply subtype.ext,
simp only [unit_interval.coe_symm_eq, subtype.coe_mk],
linarith },
{ change ¬ (x.1 : ℝ) ≤ _ at h,
change ¬ (1 : ℝ) - x.1 ≤ _ at h₁,
exfalso, linarith }
end
/--
Casting a `homotopy f₀ f₁` to a `homotopy g₀ g₁` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy f₀ f₁) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy g₀ g₁ :=
{ to_fun := F,
map_zero_left' := by simp [←h₀],
map_one_left' := by simp [←h₁] }
/--
If we have a `homotopy f₀ f₁` and a `homotopy g₀ g₁`, then we can compose them and get a
`homotopy (g₀.comp f₀) (g₁.comp f₁)`.
-/
@[simps]
def hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (F : homotopy f₀ f₁) (G : homotopy g₀ g₁) :
homotopy (g₀.comp f₀) (g₁.comp f₁) :=
{ to_fun := λ x, G (x.1, F x),
map_zero_left' := by simp,
map_one_left' := by simp }
end homotopy
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic if there exists a
`homotopy f₀ f₁`.
-/
def homotopic (f₀ f₁ : C(X, Y)) : Prop :=
nonempty (homotopy f₀ f₁)
namespace homotopic
@[refl]
lemma refl (f : C(X, Y)) : homotopic f f := ⟨homotopy.refl f⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic f g) : homotopic g f := h.map homotopy.symm
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic f g) (h₁ : homotopic g h) : homotopic f h :=
h₀.map2 homotopy.trans h₁
lemma hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (h₀ : homotopic f₀ f₁) (h₁ : homotopic g₀ g₁) :
homotopic (g₀.comp f₀) (g₁.comp f₁) :=
h₀.map2 homotopy.hcomp h₁
lemma equivalence : equivalence (@homotopic X Y _ _) := ⟨refl, symm, trans⟩
end homotopic
/--
The type of homotopies between `f₀ f₁ : C(X, Y)`, where the intermediate maps satisfy the predicate
`P : C(X, Y) → Prop`
-/
structure homotopy_with (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) extends homotopy f₀ f₁ :=
(prop' : ∀ t, P ⟨λ x, to_fun (t, x),
continuous.comp continuous_to_fun (continuous_const.prod_mk continuous_id')⟩)
namespace homotopy_with
section
variables {f₀ f₁ : C(X, Y)} {P : C(X, Y) → Prop}
instance : has_coe_to_fun (homotopy_with f₀ f₁ P) (λ _, I × X → Y) := ⟨λ F, F.to_fun⟩
lemma coe_fn_injective : @function.injective (homotopy_with f₀ f₁ P) (I × X → Y) coe_fn :=
begin
rintros ⟨⟨⟨F, _⟩, _⟩, _⟩ ⟨⟨⟨G, _⟩, _⟩, _⟩ h,
congr' 3,
end
@[ext]
lemma ext {F G : homotopy_with f₀ f₁ P} (h : ∀ x, F x = G x) : F = G :=
coe_fn_injective $ funext h
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (F : homotopy_with f₀ f₁ P) : I × X → Y := F
initialize_simps_projections homotopy_with
(to_homotopy_to_continuous_map_to_fun -> apply, -to_homotopy_to_continuous_map)
@[continuity]
protected lemma continuous (F : homotopy_with f₀ f₁ P) : continuous F := F.continuous_to_fun
@[simp]
lemma apply_zero (F : homotopy_with f₀ f₁ P) (x : X) : F (0, x) = f₀ x := F.map_zero_left' x
@[simp]
lemma apply_one (F : homotopy_with f₀ f₁ P) (x : X) : F (1, x) = f₁ x := F.map_one_left' x
@[simp]
lemma coe_to_continuous_map (F : homotopy_with f₀ f₁ P) : ⇑F.to_continuous_map = F := rfl
@[simp]
lemma coe_to_homotopy (F : homotopy_with f₀ f₁ P) : ⇑F.to_homotopy = F := rfl
lemma prop (F : homotopy_with f₀ f₁ P) (t : I) : P (F.to_homotopy.curry t) := F.prop' t
lemma extend_prop (F : homotopy_with f₀ f₁ P) (t : ℝ) : P (F.to_homotopy.extend t) :=
begin
by_cases ht₀ : 0 ≤ t,
{ by_cases ht₁ : t ≤ 1,
{ convert F.prop ⟨t, ht₀, ht₁⟩,
ext,
rw [F.to_homotopy.extend_apply_of_mem_I ⟨ht₀, ht₁⟩, F.to_homotopy.curry_apply] },
{ convert F.prop 1,
ext,
rw [F.to_homotopy.extend_apply_of_one_le (le_of_not_le ht₁), F.to_homotopy.curry_apply,
F.to_homotopy.apply_one] } },
{ convert F.prop 0,
ext,
rw [F.to_homotopy.extend_apply_of_le_zero (le_of_not_le ht₀), F.to_homotopy.curry_apply,
F.to_homotopy.apply_zero] }
end
end
variable {P : C(X, Y) → Prop}
/--
Given a continuous function `f`, and a proof `h : P f`, we can define a `homotopy_with f f P` by
`F (t, x) = f x`
-/
@[simps]
def refl (f : C(X, Y)) (hf : P f) : homotopy_with f f P :=
{ prop' := λ t, by { convert hf, cases f, refl },
..homotopy.refl f }
instance : inhabited (homotopy_with (continuous_map.id X) (continuous_map.id X) (λ f, true)) :=
⟨homotopy_with.refl _ trivial⟩
/--
Given a `homotopy_with f₀ f₁ P`, we can define a `homotopy_with f₁ f₀ P` by reversing the homotopy.
-/
@[simps]
def symm {f₀ f₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) : homotopy_with f₁ f₀ P :=
{ prop' := λ t, by simpa using F.prop (σ t),
..F.to_homotopy.symm }
@[simp]
lemma symm_symm {f₀ f₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) : F.symm.symm = F :=
ext $ homotopy.congr_fun $ homotopy.symm_symm _
/--
Given `homotopy_with f₀ f₁ P` and `homotopy_with f₁ f₂ P`, we can define a `homotopy_with f₀ f₂ P`
by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P) :
homotopy_with f₀ f₂ P :=
{ prop' := λ t, begin
simp only [homotopy.trans],
change P ⟨λ _, ite ((t : ℝ) ≤ _) _ _, _⟩,
split_ifs,
{ exact F.extend_prop _ },
{ exact G.extend_prop _ }
end,
..F.to_homotopy.trans G.to_homotopy }
lemma trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
homotopy.trans_apply _ _ _
lemma symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P) :
(F.trans G).symm = G.symm.trans F.symm :=
ext $ homotopy.congr_fun $ homotopy.symm_trans _ _
/--
Casting a `homotopy_with f₀ f₁ P` to a `homotopy_with g₀ g₁ P` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy_with g₀ g₁ P :=
{ prop' := F.prop,
..F.to_homotopy.cast h₀ h₁ }
end homotopy_with
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic with respect to the
predicate `P` if there exists a `homotopy_with f₀ f₁ P`.
-/
def homotopic_with (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) : Prop :=
nonempty (homotopy_with f₀ f₁ P)
namespace homotopic_with
variable {P : C(X, Y) → Prop}
@[refl]
lemma refl (f : C(X, Y)) (hf : P f) : homotopic_with f f P :=
⟨homotopy_with.refl f hf⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic_with f g P) : homotopic_with g f P := ⟨h.some.symm⟩
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic_with f g P) (h₁ : homotopic_with g h P) :
homotopic_with f h P :=
⟨h₀.some.trans h₁.some⟩
end homotopic_with
/--
A `homotopy_rel f₀ f₁ S` is a homotopy between `f₀` and `f₁` which is fixed on the points in `S`.
-/
abbreviation homotopy_rel (f₀ f₁ : C(X, Y)) (S : set X) :=
homotopy_with f₀ f₁ (λ f, ∀ x ∈ S, f x = f₀ x ∧ f x = f₁ x)
namespace homotopy_rel
section
variables {f₀ f₁ : C(X, Y)} {S : set X}
lemma eq_fst (F : homotopy_rel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) :
F (t, x) = f₀ x := (F.prop t x hx).1
lemma eq_snd (F : homotopy_rel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) :
F (t, x) = f₁ x := (F.prop t x hx).2
lemma fst_eq_snd (F : homotopy_rel f₀ f₁ S) {x : X} (hx : x ∈ S) :
f₀ x = f₁ x := F.eq_fst 0 hx ▸ F.eq_snd 0 hx
end
variables {f₀ f₁ f₂ : C(X, Y)} {S : set X}
/--
Given a map `f : C(X, Y)` and a set `S`, we can define a `homotopy_rel f f S` by setting
`F (t, x) = f x` for all `t`. This is defined using `homotopy_with.refl`, but with the proof
filled in.
-/
@[simps]
def refl (f : C(X, Y)) (S : set X) : homotopy_rel f f S :=
homotopy_with.refl f (λ x hx, ⟨rfl, rfl⟩)
/--
Given a `homotopy_rel f₀ f₁ S`, we can define a `homotopy_rel f₁ f₀ S` by reversing the homotopy.
-/
@[simps]
def symm (F : homotopy_rel f₀ f₁ S) : homotopy_rel f₁ f₀ S :=
{ prop' := λ t x hx, by simp [F.eq_snd _ hx, F.fst_eq_snd hx],
..homotopy_with.symm F }
@[simp]
lemma symm_symm (F : homotopy_rel f₀ f₁ S) : F.symm.symm = F :=
homotopy_with.symm_symm F
/--
Given `homotopy_rel f₀ f₁ S` and `homotopy_rel f₁ f₂ S`, we can define a `homotopy_rel f₀ f₂ S`
by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S) : homotopy_rel f₀ f₂ S :=
{ prop' := λ t, begin
intros x hx,
simp only [homotopy.trans],
change (⟨λ _, ite ((t : ℝ) ≤ _) _ _, _⟩ : C(X, Y)) _ = _ ∧ _ = _,
split_ifs,
{ simp [(homotopy_with.extend_prop F (2 * t) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] },
{ simp [(homotopy_with.extend_prop G (2 * t - 1) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] },
end,
..homotopy.trans F.to_homotopy G.to_homotopy }
lemma trans_apply (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
homotopy.trans_apply _ _ _
lemma symm_trans (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S) :
(F.trans G).symm = G.symm.trans F.symm :=
homotopy_with.ext $ homotopy.congr_fun $ homotopy.symm_trans _ _
/--
Casting a `homotopy_rel f₀ f₁ S` to a `homotopy_rel g₀ g₁ S` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy_rel f₀ f₁ S) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy_rel g₀ g₁ S :=
{ prop' := λ t x hx, by { simpa [←h₀, ←h₁] using F.prop t x hx },
..homotopy.cast F.to_homotopy h₀ h₁ }
end homotopy_rel
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic relative to a set `S` if
there exists a `homotopy_rel f₀ f₁ S`.
-/
def homotopic_rel (f₀ f₁ : C(X, Y)) (S : set X) : Prop :=
nonempty (homotopy_rel f₀ f₁ S)
namespace homotopic_rel
variable {S : set X}
@[refl]
lemma refl (f : C(X, Y)) : homotopic_rel f f S := ⟨homotopy_rel.refl f S⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic_rel f g S) : homotopic_rel g f S :=
h.map homotopy_rel.symm
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic_rel f g S) (h₁ : homotopic_rel g h S) :
homotopic_rel f h S :=
h₀.map2 homotopy_rel.trans h₁
lemma equivalence : equivalence (λ f g : C(X, Y), homotopic_rel f g S) :=
⟨refl, symm, trans⟩
end homotopic_rel
end continuous_map
|
d78499f02df9db938c886364356b17d2844dad19
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/585c.lean
|
bb0cbaa27cc246be177d6ff4925f2f6b990ac6eb
|
[
"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
| 723
|
lean
|
namespace list
inductive perm {α} : list α → list α → Prop
| nil : perm [] []
| cons : Π (x : α) {l₁ l₂ : list α}, perm l₁ l₂ → perm (x::l₁) (x::l₂)
| swap : Π (x y : α) (l : list α), perm (y::x::l) (x::y::l)
| trans : Π {l₁ l₂ l₃ : list α}, perm l₁ l₂ → perm l₂ l₃ → perm l₁ l₃
infix ` ~ `:50 := perm
@[refl] protected axiom perm.refl {α} : ∀ (l : list α), l ~ l
@[symm] protected axiom perm.symm {α} {l₁ l₂ : list α} (p : l₁ ~ l₂) : l₂ ~ l₁
attribute [trans] perm.trans
end list
example (α) (l : list α) (a b : α) :
a :: b :: l ~ b :: a :: l :=
begin
success_if_fail { simp [← list.perm.cons] }, -- 💣
apply list.perm.swap
end
|
4f9e404fe5637a4c39125dc64933d58c15650f0a
|
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
|
/src/data/list/range.lean
|
d1337de1c598025053590b25657934c8a140b7c7
|
[
"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
| 8,416
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Scott Morrison
-/
import data.list.chain
import data.list.nodup
import data.list.of_fn
open nat
namespace list
/- iota and range(') -/
universe u
variables {α : Type u}
@[simp] theorem length_range' : ∀ (s n : ℕ), length (range' s n) = n
| s 0 := rfl
| s (n+1) := congr_arg succ (length_range' _ _)
@[simp] theorem mem_range' {m : ℕ} : ∀ {s n : ℕ}, m ∈ range' s n ↔ s ≤ m ∧ m < s + n
| s 0 := (false_iff _).2 $ λ ⟨H1, H2⟩, not_le_of_lt H2 H1
| s (succ n) :=
have m = s → m < s + n + 1,
from λ e, e ▸ lt_succ_of_le (le_add_right _ _),
have l : m = s ∨ s + 1 ≤ m ↔ s ≤ m,
by simpa only [eq_comm] using (@le_iff_eq_or_lt _ _ s m).symm,
(mem_cons_iff _ _ _).trans $ by simp only [mem_range',
or_and_distrib_left, or_iff_right_of_imp this, l, add_right_comm]; refl
theorem map_add_range' (a) : ∀ s n : ℕ, map ((+) a) (range' s n) = range' (a + s) n
| s 0 := rfl
| s (n+1) := congr_arg (cons _) (map_add_range' (s+1) n)
theorem map_sub_range' (a) :
∀ (s n : ℕ) (h : a ≤ s), map (λ x, x - a) (range' s n) = range' (s - a) n
| s 0 _ := rfl
| s (n+1) h :=
begin
convert congr_arg (cons (s-a)) (map_sub_range' (s+1) n (nat.le_succ_of_le h)),
rw nat.succ_sub h,
refl,
end
theorem chain_succ_range' : ∀ s n : ℕ, chain (λ a b, b = succ a) s (range' (s+1) n)
| s 0 := chain.nil
| s (n+1) := (chain_succ_range' (s+1) n).cons rfl
theorem chain_lt_range' (s n : ℕ) : chain (<) s (range' (s+1) n) :=
(chain_succ_range' s n).imp (λ a b e, e.symm ▸ lt_succ_self _)
theorem pairwise_lt_range' : ∀ s n : ℕ, pairwise (<) (range' s n)
| s 0 := pairwise.nil
| s (n+1) := (chain_iff_pairwise (by exact λ a b c, lt_trans)).1 (chain_lt_range' s n)
theorem nodup_range' (s n : ℕ) : nodup (range' s n) :=
(pairwise_lt_range' s n).imp (λ a b, ne_of_lt)
@[simp] theorem range'_append : ∀ s m n : ℕ, range' s m ++ range' (s+m) n = range' s (n+m)
| s 0 n := rfl
| s (m+1) n := show s :: (range' (s+1) m ++ range' (s+m+1) n) = s :: range' (s+1) (n+m),
by rw [add_right_comm, range'_append]
theorem range'_sublist_right {s m n : ℕ} : range' s m <+ range' s n ↔ m ≤ n :=
⟨λ h, by simpa only [length_range'] using length_le_of_sublist h,
λ h, by rw [← nat.sub_add_cancel h, ← range'_append]; apply sublist_append_left⟩
theorem range'_subset_right {s m n : ℕ} : range' s m ⊆ range' s n ↔ m ≤ n :=
⟨λ h, le_of_not_lt $ λ hn, lt_irrefl (s+n) $
(mem_range'.1 $ h $ mem_range'.2 ⟨le_add_right _ _, nat.add_lt_add_left hn s⟩).2,
λ h, (range'_sublist_right.2 h).subset⟩
theorem nth_range' : ∀ s {m n : ℕ}, m < n → nth (range' s n) m = some (s + m)
| s 0 (n+1) _ := rfl
| s (m+1) (n+1) h := (nth_range' (s+1) (lt_of_add_lt_add_right h)).trans $
by rw add_right_comm; refl
theorem range'_concat (s n : ℕ) : range' s (n + 1) = range' s n ++ [s+n] :=
by rw add_comm n 1; exact (range'_append s n 1).symm
theorem range_core_range' : ∀ s n : ℕ, range_core s (range' s n) = range' 0 (n + s)
| 0 n := rfl
| (s+1) n := by rw [show n+(s+1) = n+1+s, from add_right_comm n s 1];
exact range_core_range' s (n+1)
theorem range_eq_range' (n : ℕ) : range n = range' 0 n :=
(range_core_range' n 0).trans $ by rw zero_add
theorem range_succ_eq_map (n : ℕ) : range (n + 1) = 0 :: map succ (range n) :=
by rw [range_eq_range', range_eq_range', range',
add_comm, ← map_add_range'];
congr; exact funext one_add
theorem range'_eq_map_range (s n : ℕ) : range' s n = map ((+) s) (range n) :=
by rw [range_eq_range', map_add_range']; refl
@[simp] theorem length_range (n : ℕ) : length (range n) = n :=
by simp only [range_eq_range', length_range']
theorem pairwise_lt_range (n : ℕ) : pairwise (<) (range n) :=
by simp only [range_eq_range', pairwise_lt_range']
theorem nodup_range (n : ℕ) : nodup (range n) :=
by simp only [range_eq_range', nodup_range']
theorem range_sublist {m n : ℕ} : range m <+ range n ↔ m ≤ n :=
by simp only [range_eq_range', range'_sublist_right]
theorem range_subset {m n : ℕ} : range m ⊆ range n ↔ m ≤ n :=
by simp only [range_eq_range', range'_subset_right]
@[simp] theorem mem_range {m n : ℕ} : m ∈ range n ↔ m < n :=
by simp only [range_eq_range', mem_range', nat.zero_le, true_and, zero_add]
@[simp] theorem not_mem_range_self {n : ℕ} : n ∉ range n :=
mt mem_range.1 $ lt_irrefl _
@[simp] theorem self_mem_range_succ (n : ℕ) : n ∈ range (n + 1) :=
by simp only [succ_pos', lt_add_iff_pos_right, mem_range]
theorem nth_range {m n : ℕ} (h : m < n) : nth (range n) m = some m :=
by simp only [range_eq_range', nth_range' _ h, zero_add]
theorem range_concat (n : ℕ) : range (succ n) = range n ++ [n] :=
by simp only [range_eq_range', range'_concat, zero_add]
theorem iota_eq_reverse_range' : ∀ n : ℕ, iota n = reverse (range' 1 n)
| 0 := rfl
| (n+1) := by simp only [iota, range'_concat, iota_eq_reverse_range' n, reverse_append, add_comm]; refl
@[simp] theorem length_iota (n : ℕ) : length (iota n) = n :=
by simp only [iota_eq_reverse_range', length_reverse, length_range']
theorem pairwise_gt_iota (n : ℕ) : pairwise (>) (iota n) :=
by simp only [iota_eq_reverse_range', pairwise_reverse, pairwise_lt_range']
theorem nodup_iota (n : ℕ) : nodup (iota n) :=
by simp only [iota_eq_reverse_range', nodup_reverse, nodup_range']
theorem mem_iota {m n : ℕ} : m ∈ iota n ↔ 1 ≤ m ∧ m ≤ n :=
by simp only [iota_eq_reverse_range', mem_reverse, mem_range', add_comm, lt_succ_iff]
theorem reverse_range' : ∀ s n : ℕ,
reverse (range' s n) = map (λ i, s + n - 1 - i) (range n)
| s 0 := rfl
| s (n+1) := by rw [range'_concat, reverse_append, range_succ_eq_map];
simpa only [show s + (n + 1) - 1 = s + n, from rfl, (∘),
λ a i, show a - 1 - i = a - succ i, from pred_sub _ _,
reverse_singleton, map_cons, nat.sub_zero, cons_append,
nil_append, eq_self_iff_true, true_and, map_map]
using reverse_range' s n
/-- All elements of `fin n`, from `0` to `n-1`. -/
def fin_range (n : ℕ) : list (fin n) :=
(range n).pmap fin.mk (λ _, list.mem_range.1)
@[simp] lemma mem_fin_range {n : ℕ} (a : fin n) : a ∈ fin_range n :=
mem_pmap.2 ⟨a.1, mem_range.2 a.2, fin.eta _ _⟩
lemma nodup_fin_range (n : ℕ) : (fin_range n).nodup :=
nodup_pmap (λ _ _ _ _, fin.veq_of_eq) (nodup_range _)
@[simp] lemma length_fin_range (n : ℕ) : (fin_range n).length = n :=
by rw [fin_range, length_pmap, length_range]
@[to_additive]
theorem prod_range_succ {α : Type u} [monoid α] (f : ℕ → α) (n : ℕ) :
((range n.succ).map f).prod = ((range n).map f).prod * f n :=
by rw [range_concat, map_append, map_singleton,
prod_append, prod_cons, prod_nil, mul_one]
/-- A variant of `prod_range_succ` which pulls off the first
term in the product rather than the last.-/
@[to_additive "A variant of `sum_range_succ` which pulls off the first term in the sum
rather than the last."]
theorem prod_range_succ' {α : Type u} [monoid α] (f : ℕ → α) (n : ℕ) :
((range n.succ).map f).prod = f 0 * ((range n).map (λ i, f (succ i))).prod :=
nat.rec_on n
(show 1 * f 0 = f 0 * 1, by rw [one_mul, mul_one])
(λ _ hd, by rw [list.prod_range_succ, hd, mul_assoc, ←list.prod_range_succ])
@[simp] theorem enum_from_map_fst : ∀ n (l : list α),
map prod.fst (enum_from n l) = range' n l.length
| n [] := rfl
| n (a :: l) := congr_arg (cons _) (enum_from_map_fst _ _)
@[simp] theorem enum_map_fst (l : list α) :
map prod.fst (enum l) = range l.length :=
by simp only [enum, enum_from_map_fst, range_eq_range']
@[simp] lemma nth_le_range {n} (i) (H : i < (range n).length) :
nth_le (range n) i H = i :=
option.some.inj $ by rw [← nth_le_nth _, nth_range (by simpa using H)]
theorem of_fn_eq_pmap {α n} {f : fin n → α} :
of_fn f = pmap (λ i hi, f ⟨i, hi⟩) (range n) (λ _, mem_range.1) :=
by rw [pmap_eq_map_attach]; from ext_le (by simp)
(λ i hi1 hi2, by { simp at hi1, simp [nth_le_of_fn f ⟨i, hi1⟩, -subtype.val_eq_coe] })
theorem nodup_of_fn {α n} {f : fin n → α} (hf : function.injective f) :
nodup (of_fn f) :=
by rw of_fn_eq_pmap; from nodup_pmap
(λ _ _ _ _ H, fin.veq_of_eq $ hf H) (nodup_range n)
end list
|
29a76e212f917bfa6403659f8216f639ec0991f5
|
2cf781335f4a6706b7452ab07ce323201e2e101f
|
/lean/imap.lean
|
63984fd9d9bcf1cb8777718032695d2b93af1148
|
[
"Apache-2.0"
] |
permissive
|
simonjwinwood/reopt-vcg
|
697cdd5e68366b5aa3298845eebc34fc97ccfbe2
|
6aca24e759bff4f2230bb58270bac6746c13665e
|
refs/heads/master
| 1,586,353,878,347
| 1,549,667,148,000
| 1,549,667,148,000
| 159,409,828
| 0
| 0
| null | 1,543,358,444,000
| 1,543,358,444,000
| null |
UTF-8
|
Lean
| false
| false
| 931
|
lean
|
/- A simple interval map -/
structure {u v} data.imap.imap_entry (k : Type u) (val : Type v) : Type (max u v) :=
(start : k)
(extent : k)
(value : val)
def {u v} data.imap (k : Type u) (val : Type v) (lt : k -> k -> Prop)
:= list (data.imap.imap_entry k val)
namespace data.imap
section
universes u v
parameters {k : Type u} {val : Type v} {lt : k -> k -> Prop} [has_add k]
[decidable_rel lt]
def in_entry (key : k) (e : imap_entry k val) : bool :=
not (lt key e.start) ∧ lt key (e.start + e.extent)
def lookup (key : k) : data.imap k val lt -> option (k × val)
| [] := none
| (e :: m) := if in_entry key e
then some (e.start, e.value)
else lookup m
-- FIXME: add overlap check
def insert (start : k) (extent : k) (value : val) : data.imap k val lt -> data.imap k val lt :=
λm, { start := start, extent := extent, value := value } :: m
end
end data.imap
|
db25385559076be225d8a2ba56e5792c8f7c6ce6
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/test/rat.lean
|
737f416d316fa57d9704965219d4904c1f3e1f34
|
[
"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
| 308
|
lean
|
import data.rat.meta_defs
run_cmd let q : ℚ := 3/15 in
guard $ (reflect q : expr) = `((1/5 : ℚ))
constants (α : Type) (h : field α)
attribute [instance] h
run_cmd guard $ expr.eval_rat `(1/3 - 100/6 : α) = some (-49/3)
run_cmd guard $ (expr.eval_rat ∘ rat.reflect) (-(5/3) : ℚ) = some (-5/3)
|
df48dd099343efda091cc6e7b289fa2b35c243d4
|
2fbe653e4bc441efde5e5d250566e65538709888
|
/src/data/set/finite.lean
|
fe1f840cba7a7bfac187c274abd7276b25588c04
|
[
"Apache-2.0"
] |
permissive
|
aceg00/mathlib
|
5e15e79a8af87ff7eb8c17e2629c442ef24e746b
|
8786ea6d6d46d6969ac9a869eb818bf100802882
|
refs/heads/master
| 1,649,202,698,930
| 1,580,924,783,000
| 1,580,924,783,000
| 149,197,272
| 0
| 0
|
Apache-2.0
| 1,537,224,208,000
| 1,537,224,207,000
| null |
UTF-8
|
Lean
| false
| false
| 22,874
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Finite sets.
-/
import logic.function
import data.nat.basic data.fintype data.set.lattice data.set.function
open set lattice function
universes u v w x
variables {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace set
/-- A set is finite if the subtype is a fintype, i.e. there is a
list that enumerates its members. -/
def finite (s : set α) : Prop := nonempty (fintype s)
/-- A set is infinite if it is not finite. -/
def infinite (s : set α) : Prop := ¬ finite s
/-- The subtype corresponding to a finite set is a finite type. Note
that because `finite` isn't a typeclass, this will not fire if it
is made into an instance -/
noncomputable def finite.fintype {s : set α} (h : finite s) : fintype s :=
classical.choice h
/-- Get a finset from a finite set -/
noncomputable def finite.to_finset {s : set α} (h : finite s) : finset α :=
@set.to_finset _ _ (finite.fintype h)
@[simp] theorem finite.mem_to_finset {s : set α} {h : finite s} {a : α} : a ∈ h.to_finset ↔ a ∈ s :=
@mem_to_finset _ _ (finite.fintype h) _
lemma finite.coe_to_finset {α} {s : set α} (h : finite s) : ↑h.to_finset = s :=
by { ext, apply mem_to_finset }
theorem finite.exists_finset {s : set α} : finite s →
∃ s' : finset α, ∀ a : α, a ∈ s' ↔ a ∈ s
| ⟨h⟩ := by exactI ⟨to_finset s, λ _, mem_to_finset⟩
theorem finite.exists_finset_coe {s : set α} (hs : finite s) :
∃ s' : finset α, ↑s' = s :=
⟨hs.to_finset, hs.coe_to_finset⟩
/-- Finite sets can be lifted to finsets. -/
instance : can_lift (set α) (finset α) :=
{ coe := coe,
cond := finite,
prf := λ s hs, hs.exists_finset_coe }
theorem finite_mem_finset (s : finset α) : finite {a | a ∈ s} :=
⟨fintype.of_finset s (λ _, iff.rfl)⟩
theorem finite.of_fintype [fintype α] (s : set α) : finite s :=
by classical; exact ⟨set_fintype s⟩
/-- Membership of a subset of a finite type is decidable.
Using this as an instance leads to potential loops with `subtype.fintype` under certain decidability
assumptions, so it should only be declared a local instance. -/
def decidable_mem_of_fintype [decidable_eq α] (s : set α) [fintype s] (a) : decidable (a ∈ s) :=
decidable_of_iff _ mem_to_finset
instance fintype_empty : fintype (∅ : set α) :=
fintype.of_finset ∅ $ by simp
theorem empty_card : fintype.card (∅ : set α) = 0 := rfl
@[simp] theorem empty_card' {h : fintype.{u} (∅ : set α)} :
@fintype.card (∅ : set α) h = 0 :=
eq.trans (by congr) empty_card
@[simp] theorem finite_empty : @finite α ∅ := ⟨set.fintype_empty⟩
def fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) : fintype (insert a s : set α) :=
fintype.of_finset ⟨a :: s.to_finset.1,
multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2⟩ $ by simp
theorem card_fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) :
@fintype.card _ (fintype_insert' s h) = fintype.card s + 1 :=
by rw [fintype_insert', fintype.card_of_finset];
simp [finset.card, to_finset]; refl
@[simp] theorem card_insert {a : α} (s : set α)
[fintype s] (h : a ∉ s) {d : fintype.{u} (insert a s : set α)} :
@fintype.card _ d = fintype.card s + 1 :=
by rw ← card_fintype_insert' s h; congr
lemma card_image_of_inj_on {s : set α} [fintype s]
{f : α → β} [fintype (f '' s)] (H : ∀x∈s, ∀y∈s, f x = f y → x = y) :
fintype.card (f '' s) = fintype.card s :=
by haveI := classical.prop_decidable; exact
calc fintype.card (f '' s) = (s.to_finset.image f).card : fintype.card_of_finset' _ (by simp)
... = s.to_finset.card : finset.card_image_of_inj_on
(λ x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy)
... = fintype.card s : (fintype.card_of_finset' _ (λ a, mem_to_finset)).symm
lemma card_image_of_injective (s : set α) [fintype s]
{f : α → β} [fintype (f '' s)] (H : function.injective f) :
fintype.card (f '' s) = fintype.card s :=
card_image_of_inj_on $ λ _ _ _ _ h, H h
section
local attribute [instance] decidable_mem_of_fintype
instance fintype_insert [decidable_eq α] (a : α) (s : set α) [fintype s] : fintype (insert a s : set α) :=
if h : a ∈ s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)]
else fintype_insert' _ h
end
@[simp] theorem finite_insert (a : α) {s : set α} : finite s → finite (insert a s)
| ⟨h⟩ := ⟨@set.fintype_insert _ (classical.dec_eq α) _ _ h⟩
lemma to_finset_insert [decidable_eq α] {a : α} {s : set α} (hs : finite s) :
(finite_insert a hs).to_finset = insert a hs.to_finset :=
finset.ext.mpr $ by simp
@[elab_as_eliminator]
theorem finite.induction_on {C : set α → Prop} {s : set α} (h : finite s)
(H0 : C ∅) (H1 : ∀ {a s}, a ∉ s → finite s → C s → C (insert a s)) : C s :=
let ⟨t⟩ := h in by exactI
match s.to_finset, @mem_to_finset _ s _ with
| ⟨l, nd⟩, al := begin
change ∀ a, a ∈ l ↔ a ∈ s at al,
clear _let_match _match t h, revert s nd al,
refine multiset.induction_on l _ (λ a l IH, _); intros s nd al,
{ rw show s = ∅, from eq_empty_iff_forall_not_mem.2 (by simpa using al),
exact H0 },
{ rw ← show insert a {x | x ∈ l} = s, from set.ext (by simpa using al),
cases multiset.nodup_cons.1 nd with m nd',
refine H1 _ ⟨finset.subtype.fintype ⟨l, nd'⟩⟩ (IH nd' (λ _, iff.rfl)),
exact m }
end
end
@[elab_as_eliminator]
theorem finite.dinduction_on {C : ∀s:set α, finite s → Prop} {s : set α} (h : finite s)
(H0 : C ∅ finite_empty)
(H1 : ∀ {a s}, a ∉ s → ∀h:finite s, C s h → C (insert a s) (finite_insert a h)) :
C s h :=
have ∀h:finite s, C s h,
from finite.induction_on h (assume h, H0) (assume a s has hs ih h, H1 has hs (ih _)),
this h
instance fintype_singleton (a : α) : fintype ({a} : set α) :=
fintype_insert' _ (not_mem_empty _)
@[simp] theorem card_singleton (a : α) :
fintype.card ({a} : set α) = 1 :=
by rw [show fintype.card ({a} : set α) = _, from
card_fintype_insert' ∅ (not_mem_empty a)]; refl
@[simp] theorem finite_singleton (a : α) : finite ({a} : set α) :=
⟨set.fintype_singleton _⟩
instance fintype_pure : ∀ a : α, fintype (pure a : set α) :=
set.fintype_singleton
theorem finite_pure (a : α) : finite (pure a : set α) :=
⟨set.fintype_pure a⟩
instance fintype_univ [fintype α] : fintype (@univ α) :=
fintype.of_equiv α $ (equiv.set.univ α).symm
theorem finite_univ [fintype α] : finite (@univ α) := ⟨set.fintype_univ⟩
theorem infinite_univ_iff : (@univ α).infinite ↔ _root_.infinite α :=
⟨λ h₁, ⟨λ h₂, h₁ $ @finite_univ α h₂⟩,
λ ⟨h₁⟩ ⟨h₂⟩, h₁ $ @fintype.of_equiv _ _ h₂ $ equiv.set.univ _⟩
theorem infinite_univ [h : _root_.infinite α] : infinite (@univ α) :=
infinite_univ_iff.2 h
instance fintype_union [decidable_eq α] (s t : set α) [fintype s] [fintype t] : fintype (s ∪ t : set α) :=
fintype.of_finset (s.to_finset ∪ t.to_finset) $ by simp
theorem finite_union {s t : set α} : finite s → finite t → finite (s ∪ t)
| ⟨hs⟩ ⟨ht⟩ := ⟨@set.fintype_union _ (classical.dec_eq α) _ _ hs ht⟩
instance fintype_sep (s : set α) (p : α → Prop) [fintype s] [decidable_pred p] : fintype ({a ∈ s | p a} : set α) :=
fintype.of_finset (s.to_finset.filter p) $ by simp
instance fintype_inter (s t : set α) [fintype s] [decidable_pred t] : fintype (s ∩ t : set α) :=
set.fintype_sep s t
def fintype_subset (s : set α) {t : set α} [fintype s] [decidable_pred t] (h : t ⊆ s) : fintype t :=
by rw ← inter_eq_self_of_subset_right h; apply_instance
theorem finite_subset {s : set α} : finite s → ∀ {t : set α}, t ⊆ s → finite t
| ⟨hs⟩ t h := ⟨@set.fintype_subset _ _ _ hs (classical.dec_pred t) h⟩
instance fintype_image [decidable_eq β] (s : set α) (f : α → β) [fintype s] : fintype (f '' s) :=
fintype.of_finset (s.to_finset.image f) $ by simp
instance fintype_range [decidable_eq β] (f : α → β) [fintype α] : fintype (range f) :=
fintype.of_finset (finset.univ.image f) $ by simp [range]
theorem finite_range (f : α → β) [fintype α] : finite (range f) :=
by haveI := classical.dec_eq β; exact ⟨by apply_instance⟩
theorem finite_image {s : set α} (f : α → β) : finite s → finite (f '' s)
| ⟨h⟩ := ⟨@set.fintype_image _ _ (classical.dec_eq β) _ _ h⟩
instance fintype_map {α β} [decidable_eq β] :
∀ (s : set α) (f : α → β) [fintype s], fintype (f <$> s) := set.fintype_image
theorem finite_map {α β} {s : set α} :
∀ (f : α → β), finite s → finite (f <$> s) := finite_image
def fintype_of_fintype_image (s : set α)
{f : α → β} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s :=
fintype.of_finset ⟨_, @multiset.nodup_filter_map β α g _
(@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2⟩ $ λ a,
begin
suffices : (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s,
by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc],
rw exists_swap,
suffices : (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s, {simpa [and.comm, and.left_comm, and.assoc]},
simp [I _, (injective_of_partial_inv I).eq_iff]
end
theorem finite_of_finite_image_on {s : set α} {f : α → β} (hi : set.inj_on f s) :
finite (f '' s) → finite s | ⟨h⟩ :=
⟨@fintype.of_injective _ _ h (λa:s, ⟨f a.1, mem_image_of_mem f a.2⟩) $
assume a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext.1 eq⟩
theorem finite_image_iff_on {s : set α} {f : α → β} (hi : inj_on f s) :
finite (f '' s) ↔ finite s :=
⟨finite_of_finite_image_on hi, finite_image _⟩
theorem finite_of_finite_image {s : set α} {f : α → β} (I : set.inj_on f s) :
finite (f '' s) → finite s :=
finite_of_finite_image_on I
theorem finite_preimage {s : set β} {f : α → β}
(I : set.inj_on f (f⁻¹' s)) (h : finite s) : finite (f ⁻¹' s) :=
finite_of_finite_image I (finite_subset h (image_preimage_subset f s))
instance fintype_Union [decidable_eq α] {ι : Type*} [fintype ι]
(f : ι → set α) [∀ i, fintype (f i)] : fintype (⋃ i, f i) :=
fintype.of_finset (finset.univ.bind (λ i, (f i).to_finset)) $ by simp
theorem finite_Union {ι : Type*} [fintype ι] {f : ι → set α} (H : ∀i, finite (f i)) : finite (⋃ i, f i) :=
⟨@set.fintype_Union _ (classical.dec_eq α) _ _ _ (λ i, finite.fintype (H i))⟩
def fintype_bUnion [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) (H : ∀ i ∈ s, fintype (f i)) : fintype (⋃ i ∈ s, f i) :=
by rw bUnion_eq_Union; exact
@set.fintype_Union _ _ _ _ _ (by rintro ⟨i, hi⟩; exact H i hi)
instance fintype_bUnion' [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) [H : ∀ i, fintype (f i)] : fintype (⋃ i ∈ s, f i) :=
fintype_bUnion _ (λ i _, H i)
theorem finite_sUnion {s : set (set α)} (h : finite s) (H : ∀t∈s, finite t) : finite (⋃₀ s) :=
by rw sUnion_eq_Union; haveI := finite.fintype h;
apply finite_Union; simpa using H
theorem finite_bUnion {α} {ι : Type*} {s : set ι} {f : ι → set α} :
finite s → (∀i, finite (f i)) → finite (⋃ i∈s, f i)
| ⟨hs⟩ h := by rw [bUnion_eq_Union]; exactI finite_Union (λ i, h _)
theorem finite_bUnion' {α} {ι : Type*} {s : set ι} (f : ι → set α) :
finite s → (∀i ∈ s, finite (f i)) → finite (⋃ i∈s, f i)
| ⟨hs⟩ h := by { rw [bUnion_eq_Union], exactI finite_Union (λ i, h i.1 i.2) }
instance fintype_lt_nat (n : ℕ) : fintype {i | i < n} :=
fintype.of_finset (finset.range n) $ by simp
instance fintype_le_nat (n : ℕ) : fintype {i | i ≤ n} :=
by simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1)
lemma finite_le_nat (n : ℕ) : finite {i | i ≤ n} := ⟨set.fintype_le_nat _⟩
lemma finite_lt_nat (n : ℕ) : finite {i | i < n} := ⟨set.fintype_lt_nat _⟩
instance fintype_prod (s : set α) (t : set β) [fintype s] [fintype t] : fintype (set.prod s t) :=
fintype.of_finset (s.to_finset.product t.to_finset) $ by simp
lemma finite_prod {s : set α} {t : set β} : finite s → finite t → finite (set.prod s t)
| ⟨hs⟩ ⟨ht⟩ := by exactI ⟨set.fintype_prod s t⟩
def fintype_bind {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) (H : ∀ a ∈ s, fintype (f a)) : fintype (s >>= f) :=
set.fintype_bUnion _ H
instance fintype_bind' {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) [H : ∀ a, fintype (f a)] : fintype (s >>= f) :=
fintype_bind _ _ (λ i _, H i)
theorem finite_bind {α β} {s : set α} {f : α → set β} :
finite s → (∀ a ∈ s, finite (f a)) → finite (s >>= f)
| ⟨hs⟩ H := ⟨@fintype_bind _ _ (classical.dec_eq β) _ hs _ (λ a ha, (H a ha).fintype)⟩
instance fintype_seq {α β : Type u} [decidable_eq β]
(f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f <*> s) :=
by rw seq_eq_bind_map; apply set.fintype_bind'
theorem finite_seq {α β : Type u} {f : set (α → β)} {s : set α} :
finite f → finite s → finite (f <*> s)
| ⟨hf⟩ ⟨hs⟩ := by { haveI := classical.dec_eq β, exactI ⟨set.fintype_seq _ _⟩ }
/-- There are finitely many subsets of a given finite set -/
lemma finite_subsets_of_finite {α : Type u} {a : set α} (h : finite a) : finite {b | b ⊆ a} :=
begin
-- we just need to translate the result, already known for finsets,
-- to the language of finite sets
let s := coe '' ((finset.powerset (finite.to_finset h)).to_set),
have : finite s := finite_image _ (finite_mem_finset _),
have : {b | b ⊆ a} ⊆ s :=
begin
assume b hb,
rw [set.mem_image],
rw [set.mem_set_of_eq] at hb,
let b' : finset α := finite.to_finset (finite_subset h hb),
have : b' ∈ (finset.powerset (finite.to_finset h)).to_set :=
show b' ∈ (finset.powerset (finite.to_finset h)),
by simp [b', finset.subset_iff]; exact hb,
have : coe b' = b := by ext; simp,
exact ⟨b', by assumption, by assumption⟩
end,
exact finite_subset ‹finite s› this
end
lemma exists_min [decidable_linear_order β] (s : set α) (f : α → β) (h1 : finite s) :
s.nonempty → ∃ a ∈ s, ∀ b ∈ s, f a ≤ f b
| ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset]
using (finite.to_finset h1).exists_min f ⟨x, finite.mem_to_finset.2 hx⟩
end set
namespace finset
variables [decidable_eq β]
variables {s t u : finset α} {f : α → β} {a : α}
lemma finite_to_set (s : finset α) : set.finite (↑s : set α) :=
set.finite_mem_finset s
@[simp] lemma coe_bind {f : α → finset β} : ↑(s.bind f) = (⋃x ∈ (↑s : set α), ↑(f x) : set β) :=
by simp [set.ext_iff]
@[simp] lemma coe_to_finset {s : set α} {hs : set.finite s} : ↑(hs.to_finset) = s :=
by simp [set.ext_iff]
@[simp] lemma coe_to_finset' (s : set α) [fintype s] : (↑s.to_finset : set α) = s :=
by ext; simp
end finset
namespace set
lemma finite_subset_Union {s : set α} (hs : finite s)
{ι} {t : ι → set α} (h : s ⊆ ⋃ i, t i) : ∃ I : set ι, finite I ∧ s ⊆ ⋃ i ∈ I, t i :=
begin
unfreezeI, cases hs,
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i, {simpa [subset_def] using h},
refine ⟨range f, finite_range f, _⟩,
rintro x hx,
simp,
exact ⟨_, ⟨_, hx, rfl⟩, hf ⟨x, hx⟩⟩
end
lemma finite_range_ite {p : α → Prop} [decidable_pred p] {f g : α → β} (hf : finite (range f))
(hg : finite (range g)) : finite (range (λ x, if p x then f x else g x)) :=
finite_subset (finite_union hf hg) range_ite_subset
lemma finite_range_const {c : β} : finite (range (λ x : α, c)) :=
finite_subset (finite_singleton c) range_const_subset
lemma range_find_greatest_subset {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ}:
range (λ x, nat.find_greatest (P x) b) ⊆ ↑(finset.range (b + 1)) :=
by { rw range_subset_iff, assume x, simp [nat.lt_succ_iff, nat.find_greatest_le] }
lemma finite_range_find_greatest {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ} :
finite (range (λ x, nat.find_greatest (P x) b)) :=
finite_subset (finset.finite_to_set $ finset.range (b + 1)) range_find_greatest_subset
lemma card_lt_card {s t : set α} [fintype s] [fintype t] (h : s ⊂ t) :
fintype.card s < fintype.card t :=
begin
haveI := classical.prop_decidable,
rw [← finset.coe_to_finset' s, ← finset.coe_to_finset' t, finset.coe_ssubset] at h,
rw [fintype.card_of_finset' _ (λ x, mem_to_finset),
fintype.card_of_finset' _ (λ x, mem_to_finset)],
exact finset.card_lt_card h,
end
lemma card_le_of_subset {s t : set α} [fintype s] [fintype t] (hsub : s ⊆ t) :
fintype.card s ≤ fintype.card t :=
calc fintype.card s = s.to_finset.card : fintype.card_of_finset' _ (by simp)
... ≤ t.to_finset.card : finset.card_le_of_subset (λ x hx, by simp [set.subset_def, *] at *)
... = fintype.card t : eq.symm (fintype.card_of_finset' _ (by simp))
lemma eq_of_subset_of_card_le {s t : set α} [fintype s] [fintype t]
(hsub : s ⊆ t) (hcard : fintype.card t ≤ fintype.card s) : s = t :=
(eq_or_ssubset_of_subset hsub).elim id
(λ h, absurd hcard $ not_le_of_lt $ card_lt_card h)
lemma card_range_of_injective [fintype α] {f : α → β} (hf : injective f)
[fintype (range f)] : fintype.card (range f) = fintype.card α :=
eq.symm $ fintype.card_congr (@equiv.of_bijective _ _ (λ a : α, show range f, from ⟨f a, a, rfl⟩)
⟨λ x y h, hf $ subtype.mk.inj h, λ b, let ⟨a, ha⟩ := b.2 in ⟨a, by simp *⟩⟩)
lemma finite.exists_maximal_wrt [partial_order β] (f : α → β) (s : set α) (h : set.finite s) :
s.nonempty → ∃a∈s, ∀a'∈s, f a ≤ f a' → f a = f a' :=
begin
classical,
refine h.induction_on _ _,
{ assume h, exact absurd h empty_not_nonempty },
assume a s his _ ih _,
cases s.eq_empty_or_nonempty with h h,
{ use a, simp [h] },
rcases ih h with ⟨b, hb, ih⟩,
by_cases f b ≤ f a,
{ refine ⟨a, set.mem_insert _ _, assume c hc hac, le_antisymm hac _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ refl },
{ rwa [← ih c hcs (le_trans h hac)] } },
{ refine ⟨b, set.mem_insert_of_mem _ hb, assume c hc hbc, _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ exact (h hbc).elim },
{ exact ih c hcs hbc } }
end
section
local attribute [instance, priority 1] classical.prop_decidable
lemma to_finset_card {α : Type*} [fintype α] (H : set α) :
H.to_finset.card = fintype.card H :=
multiset.card_map subtype.val finset.univ.val
lemma to_finset_inter {α : Type*} [fintype α] (s t : set α) [decidable_eq α] :
(s ∩ t).to_finset = s.to_finset ∩ t.to_finset :=
by ext; simp
end
section
variables [semilattice_sup α] [nonempty α] {s : set α}
/--A finite set is bounded above.-/
lemma bdd_above_finite (hs : finite s) : bdd_above s :=
finite.induction_on hs bdd_above_empty $ λ a s _ _, bdd_above_insert.2
/--A finite union of sets which are all bounded above is still bounded above.-/
lemma bdd_above_finite_union {I : set β} {S : β → set α} (H : finite I) :
(bdd_above (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_above (S i)) :=
⟨λ (bdd : bdd_above (⋃i∈I, S i)) i (hi : i ∈ I),
bdd_above_subset (subset_bUnion_of_mem hi) bdd,
show (∀i ∈ I, bdd_above (S i)) → (bdd_above (⋃i∈I, S i)), from
finite.induction_on H
(λ _, by rw bUnion_empty; exact bdd_above_empty)
(λ x s hn hf IH h, by simp only [
set.mem_insert_iff, or_imp_distrib, forall_and_distrib, forall_eq] at h;
rw [set.bUnion_insert, bdd_above_union]; exact ⟨h.1, IH h.2⟩)⟩
end
section
variables [semilattice_inf α] [nonempty α] {s : set α}
/--A finite set is bounded below.-/
lemma bdd_below_finite (hs : finite s) : bdd_below s :=
finite.induction_on hs bdd_below_empty $ λ a s _ _, bdd_below_insert.2
/--A finite union of sets which are all bounded below is still bounded below.-/
lemma bdd_below_finite_union {I : set β} {S : β → set α} (H : finite I) :
(bdd_below (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_below (S i)) :=
⟨λ (bdd : bdd_below (⋃i∈I, S i)) i (hi : i ∈ I),
bdd_below_subset (subset_bUnion_of_mem hi) bdd,
show (∀i ∈ I, bdd_below (S i)) → (bdd_below (⋃i∈I, S i)), from
finite.induction_on H
(λ _, by rw bUnion_empty; exact bdd_below_empty)
(λ x s hn hf IH h, by simp only [
set.mem_insert_iff, or_imp_distrib, forall_and_distrib, forall_eq] at h;
rw [set.bUnion_insert, bdd_below_union]; exact ⟨h.1, IH h.2⟩)⟩
end
end set
namespace finset
section preimage
noncomputable def preimage {f : α → β} (s : finset β)
(hf : set.inj_on f (f ⁻¹' ↑s)) : finset α :=
set.finite.to_finset (set.finite_preimage hf (set.finite_mem_finset s))
@[simp] lemma mem_preimage {f : α → β} {s : finset β} {hf : set.inj_on f (f ⁻¹' ↑s)} {x : α} :
x ∈ preimage s hf ↔ f x ∈ s :=
by simp [preimage]
@[simp] lemma coe_preimage {f : α → β} (s : finset β)
(hf : set.inj_on f (f ⁻¹' ↑s)) : (↑(preimage s hf) : set α) = f ⁻¹' ↑s :=
by simp [set.ext_iff]
lemma image_preimage [decidable_eq β] (f : α → β) (s : finset β)
(hf : set.bij_on f (f ⁻¹' s.to_set) s.to_set) :
image f (preimage s (set.inj_on_of_bij_on hf)) = s :=
finset.coe_inj.1 $
suffices f '' (f ⁻¹' ↑s) = ↑s, by simpa,
(set.subset.antisymm (image_preimage_subset _ _) hf.2.2)
end preimage
@[to_additive]
lemma prod_preimage [comm_monoid β] (f : α → γ) (s : finset γ)
(hf : set.bij_on f (f ⁻¹' ↑s) ↑s) (g : γ → β) :
(preimage s (set.inj_on_of_bij_on hf)).prod (g ∘ f) = s.prod g :=
by classical;
calc
(preimage s (set.inj_on_of_bij_on hf)).prod (g ∘ f)
= (image f (preimage s (set.inj_on_of_bij_on hf))).prod g :
begin
rw prod_image,
intros x hx y hy hxy,
apply set.inj_on_of_bij_on hf,
repeat { try { rw mem_preimage at hx hy,
rw [set.mem_preimage, mem_coe] },
assumption },
end
... = s.prod g : by rw image_preimage
end finset
lemma fintype.exists_max [fintype α] [nonempty α]
{β : Type*} [decidable_linear_order β] (f : α → β) :
∃ x₀ : α, ∀ x, f x ≤ f x₀ :=
begin
obtain ⟨y, hy⟩ : ∃ y, y ∈ (set.range f).to_finset,
{ haveI := classical.inhabited_of_nonempty ‹nonempty α›,
exact ⟨f (default α), set.mem_to_finset.mpr $ set.mem_range_self _⟩ },
rcases finset.max_of_mem hy with ⟨y₀, h⟩,
rcases set.mem_to_finset.1 (finset.mem_of_max h) with ⟨x₀, rfl⟩,
use x₀,
intro x,
apply finset.le_max_of_mem (set.mem_to_finset.mpr $ set.mem_range_self x) h
end
|
64aa29205f74b7b2864ab03598fdc93183cf8905
|
9028d228ac200bbefe3a711342514dd4e4458bff
|
/src/linear_algebra/finsupp.lean
|
1de22e5e4219c643f4adcf126aeb490812869ba1
|
[
"Apache-2.0"
] |
permissive
|
mcncm/mathlib
|
8d25099344d9d2bee62822cb9ed43aa3e09fa05e
|
fde3d78cadeec5ef827b16ae55664ef115e66f57
|
refs/heads/master
| 1,672,743,316,277
| 1,602,618,514,000
| 1,602,618,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 20,882
|
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 algebra.monoid_algebra
noncomputable theory
open set linear_map submodule
open_locale classical big_operators
namespace finsupp
variables {α : Type*} {M : Type*} {N : Type*} {R : Type*}
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid N] [semimodule R N]
/-- Interpret `finsupp.single a` as a linear map. -/
def lsingle (a : α) : M →ₗ[R] (α →₀ M) :=
{ map_smul' := assume a b, (smul_single _ _ _).symm, ..finsupp.single_add_hom a }
/-- Interpret `λ (f : α →₀ M), f a` as a linear map. -/
def lapply (a : α) : (α →₀ M) →ₗ[R] M :=
{ map_smul' := assume a b, rfl, ..finsupp.eval_add_hom a }
section lsubtype_domain
variables (s : set α)
/-- Interpret `finsupp.subtype_domain s` as a linear map. -/
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_of_injective (single_injective 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_right s)
(lsingle_range_le_ker_lapply _ _ $ disjoint_compl_right 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)
/-- `finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/
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 (finset.singleton_subset_set_iff.2 h)
lemma supported_eq_span_single (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)
/-- Interpret `finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/
def restrict_dom (s : set α) : (α →₀ M) →ₗ supported M R s :=
linear_map.cod_restrict _
{ to_fun := filter (∈ s),
map_add' := λ l₁ l₂, filter_add,
map_smul' := λ a l, filter_smul }
(λ l, (mem_supported' _ _).2 $ λ x, filter_apply_neg (∈ s) l)
variables {M R}
section
@[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 a,
by_cases a ∈ s; simp [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 ⟨⟩,
apply finsupp.induction l, {exact zero_mem _},
refine λ x a l hl a0, add_mem _ _,
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) }
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
/-- Interpret `finsupp.restrict_support_equiv` as a linear equivalence between
`supported M R s` and `s →₀ M`. -/
def supported_equiv_finsupp (s : set α) : (supported M R s) ≃ₗ[R] (s →₀ M) :=
begin
let F : (supported M R s) ≃ (s →₀ M) := restrict_support_equiv s M,
refine F.to_linear_equiv _,
have : (F : (supported M R s) → (↥s →₀ M)) = ((lsubtype_domain s : (α →₀ M) →ₗ[R] (s →₀ M)).comp
(submodule.subtype (supported M R s))) := rfl,
rw this,
exact linear_map.is_linear _
end
/-- `finsupp.sum` as a linear map. -/
def lsum (f : α → M →ₗ[R] N) : (α →₀ M) →ₗ[R] N :=
⟨λ d, d.sum (λ i, f i),
assume d₁ d₂, by simp [sum_add_index],
assume a d, by simp [sum_smul_index', smul_sum]⟩
@[simp] lemma coe_lsum (f : α → M →ₗ[R] N) : (lsum f : (α →₀ M) → N) = λ d, d.sum (λ i, f i) := rfl
theorem lsum_apply (f : α → M →ₗ[R] N) (l : α →₀ M) :
finsupp.lsum f l = l.sum (λ b, f b) := rfl
theorem lsum_single (f : α → M →ₗ[R] N) (i : α) (m : M) :
finsupp.lsum f (finsupp.single i m) = f i m :=
finsupp.sum_single_index (f i).map_zero
section lmap_domain
variables {α' : Type*} {α'' : Type*} (M R)
/-- Interpret `finsupp.lmap_domain` as a linear map. -/
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_monoid M'] [semimodule 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
theorem total_apply_of_mem_supported {l : α →₀ R} {s : finset α}
(hs : l ∈ supported R R (↑s : set α)) :
finsupp.total α M R v l = s.sum (λ i, l i • v i) :=
finset.sum_subset hs $ λ x _ hxg, show l x • v x = 0, by rw [not_mem_support_iff.1 hxg, zero_smul]
@[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_mem _ _ (subset_span (mem_range_self i)) },
{ 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)
/-- `finsupp.total_on M v s` interprets `p : α →₀ R` as a linear combination of a
subset of the vectors in `v`, mapping it to the span of those vectors.
The subset is indicated by a set `s : set α` of indices.
-/
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)) :
finsupp.total α M R v (finsupp.comap_domain f l hf) =
(l.support.preimage f hf).sum (λ i, (l (f i)) • (v i)) :=
by rw finsupp.total_apply; refl
lemma total_on_finset
{s : finset α} {f : α → R} (g : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s):
finsupp.total α M R g (finsupp.on_finset s f hf) =
finset.sum s (λ (x : α), f x • g x) :=
begin
simp only [finsupp.total_apply, finsupp.sum, finsupp.on_finset_apply, finsupp.support_on_finset],
rw finset.sum_filter_of_ne,
intros x hx h,
contrapose! h,
simp [h],
end
end total
/-- An equivalence of domains induces a linear equivalence of finitely supported functions. -/
protected def dom_lcongr
{α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) :
(α₁ →₀ M) ≃ₗ[R] (α₂ →₀ M) :=
(@finsupp.dom_congr M _ _ _ e).to_linear_equiv (lmap_domain M R e).map_smul
@[simp] theorem dom_lcongr_single {α₁ : Type*} {α₂ : Type*} (e : α₁ ≃ α₂) (i : α₁) (m : M) :
(finsupp.dom_lcongr e : _ ≃ₗ[R] _) (finsupp.single i m) = finsupp.single (e i) m :=
by simp [finsupp.dom_lcongr, finsupp.dom_congr, map_domain_single]
/-- An equivalence of sets induces a linear equivalence of `finsupp`s supported on those sets. -/
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
/-- An equivalence of domain and a linear equivalence of codomain induce a linear equivalence of the
corresponding finitely supported functions. -/
def lcongr {ι κ : Sort*} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N) : (ι →₀ M) ≃ₗ[R] (κ →₀ N) :=
(finsupp.dom_lcongr e₁).trans
{ to_fun := map_range e₂ e₂.map_zero,
inv_fun := map_range e₂.symm e₂.symm.map_zero,
left_inv := λ f, finsupp.induction f (by simp_rw map_range_zero) $ λ a b f ha hb ih,
by rw [map_range_add e₂.map_add, map_range_add e₂.symm.map_add,
map_range_single, map_range_single, e₂.symm_apply_apply, ih],
right_inv := λ f, finsupp.induction f (by simp_rw map_range_zero) $ λ a b f ha hb ih,
by rw [map_range_add e₂.symm.map_add, map_range_add e₂.map_add,
map_range_single, map_range_single, e₂.apply_symm_apply, ih],
map_add' := map_range_add e₂.map_add,
map_smul' := λ c f, finsupp.induction f
(by rw [smul_zero, map_range_zero, smul_zero]) $ λ a b f ha hb ih,
by rw [smul_add, smul_single, map_range_add e₂.map_add, map_range_single, e₂.map_smul, ih,
map_range_add e₂.map_add, smul_add, map_range_single, smul_single] }
@[simp] theorem lcongr_single {ι κ : Sort*} (e₁ : ι ≃ κ) (e₂ : M ≃ₗ[R] N)
(i : ι) (m : M) : lcongr e₁ e₂ (finsupp.single i m) = finsupp.single (e₁ i) (e₂ m) :=
by simp [lcongr]
end finsupp
variables {R : Type*} {M : Type*} {N : Type*}
variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid N] [semimodule R N]
lemma linear_map.map_finsupp_total
(f : M →ₗ[R] N) {ι : Type*} {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 N.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
lemma mem_span_finset {s : finset M} {x : M} :
x ∈ span R (↑s : set M) ↔ ∃ f : M → R, ∑ i in s, f i • i = x :=
⟨λ hx, let ⟨v, hvs, hvx⟩ := (finsupp.mem_span_iff_total _).1
(show x ∈ span R (id '' (↑s : set M)), by rwa set.image_id) in
⟨v, hvx ▸ (finsupp.total_apply_of_mem_supported _ hvs).symm⟩,
λ ⟨f, hf⟩, hf ▸ sum_mem _ (λ i hi, smul_mem _ _ $ subset_span hi)⟩
|
94ce39cad58d9467a8bbdafe0d021ee51b7d6fc8
|
1abd1ed12aa68b375cdef28959f39531c6e95b84
|
/src/linear_algebra/matrix/nonsingular_inverse.lean
|
3d4c3178cd707f0074846d6442527051faed69ce
|
[
"Apache-2.0"
] |
permissive
|
jumpy4/mathlib
|
d3829e75173012833e9f15ac16e481e17596de0f
|
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
|
refs/heads/master
| 1,693,508,842,818
| 1,636,203,271,000
| 1,636,203,271,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 13,587
|
lean
|
/-
Copyright (c) 2019 Tim Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baanen, Lu-Ming Zhang
-/
import algebra.regular.smul
import data.matrix.notation
import linear_algebra.matrix.polynomial
import linear_algebra.matrix.adjugate
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible
determinant. For matrices that are not square or not of full rank, there is a
more general notion of pseudoinverses which we do not consider here.
The definition of inverse used in this file is the adjugate divided by the determinant.
We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`),
will result in a multiplicative inverse to `A`.
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace matrix
universes u v
variables {n : Type u} [decidable_eq n] [fintype n] {α : Type v} [comm_ring α]
open_locale matrix big_operators
open equiv equiv.perm finset
variables (A : matrix n n α) (B : matrix n n α)
open_locale classical
lemma is_unit_det_transpose (h : is_unit A.det) : is_unit Aᵀ.det :=
by { rw det_transpose, exact h, }
/-- The inverse of a square matrix, when it is invertible (and zero otherwise).-/
noncomputable instance : has_inv (matrix n n α) := ⟨λ A, ring.inverse A.det • A.adjugate⟩
lemma inv_def (A : matrix n n α) : A⁻¹ = ring.inverse A.det • A.adjugate := rfl
lemma nonsing_inv_apply_not_is_unit (h : ¬ is_unit A.det) :
A⁻¹ = 0 :=
by rw [inv_def, ring.inverse_non_unit _ h, zero_smul]
lemma nonsing_inv_apply (h : is_unit A.det) :
A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate :=
begin
rw [inv_def, ←ring.inverse_unit h.unit],
refl,
end
lemma transpose_nonsing_inv : (A⁻¹)ᵀ = (Aᵀ)⁻¹ :=
by rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
lemma conj_transpose_nonsing_inv [star_ring α] : (A⁻¹)ᴴ = (Aᴴ)⁻¹ :=
by rw [inv_def, inv_def, conj_transpose_smul, det_conj_transpose, adjugate_conj_transpose,
ring.inverse_star]
/-- The `nonsing_inv` of `A` is a right inverse. -/
@[simp] lemma mul_nonsing_inv (h : is_unit A.det) : A ⬝ A⁻¹ = 1 :=
by rw [A.nonsing_inv_apply h, mul_smul, mul_adjugate, smul_smul,
units.inv_mul_of_eq h.unit_spec, one_smul]
/-- The `nonsing_inv` of `A` is a left inverse. -/
@[simp] lemma nonsing_inv_mul (h : is_unit A.det) : A⁻¹ ⬝ A = 1 :=
calc A⁻¹ ⬝ A = (Aᵀ ⬝ (Aᵀ)⁻¹)ᵀ : by { rw [transpose_mul,
Aᵀ.transpose_nonsing_inv,
transpose_transpose], }
... = 1ᵀ : by { rw Aᵀ.mul_nonsing_inv, exact A.is_unit_det_transpose h, }
... = 1 : transpose_one
lemma nonsing_inv_cancel_or_zero :
(A⁻¹ ⬝ A = 1 ∧ A ⬝ A⁻¹ = 1) ∨ A⁻¹ = 0 :=
begin
by_cases h : is_unit A.det,
{ exact or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩ },
{ exact or.inr (nonsing_inv_apply_not_is_unit _ h) }
end
lemma det_nonsing_inv_mul_det (h : is_unit A.det) : A⁻¹.det * A.det = 1 :=
by rw [←det_mul, A.nonsing_inv_mul h, det_one]
@[simp] lemma det_nonsing_inv : A⁻¹.det = ring.inverse A.det :=
begin
rw [inv_def, det_smul, det_adjugate],
casesI is_empty_or_nonempty n,
{ rw [fintype.card_eq_zero, zero_tsub, pow_zero, det_is_empty, pow_zero, ring.inverse_one,
one_mul] },
have hc_pos : 0 < fintype.card n := fintype.card_pos,
by_cases h : is_unit A.det,
{ obtain ⟨u, hu⟩ := h,
rw [←hu, ring.inverse_unit, ←units.coe_pow, ←units.coe_pow, ←units.coe_mul,
inv_pow, ←inv_pow_sub _ tsub_le_self, tsub_tsub_cancel_of_le hc_pos.nat_succ_le, pow_one], },
{ rw [ring.inverse_non_unit _ h, zero_pow hc_pos, zero_mul], },
end
lemma is_unit_nonsing_inv_det (h : is_unit A.det) : is_unit A⁻¹.det :=
is_unit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)
@[simp] lemma nonsing_inv_nonsing_inv (h : is_unit A.det) : (A⁻¹)⁻¹ = A :=
calc (A⁻¹)⁻¹ = 1 ⬝ (A⁻¹)⁻¹ : by rw matrix.one_mul
... = A ⬝ A⁻¹ ⬝ (A⁻¹)⁻¹ : by rw A.mul_nonsing_inv h
... = A : by { rw [matrix.mul_assoc,
(A⁻¹).mul_nonsing_inv (A.is_unit_nonsing_inv_det h),
matrix.mul_one], }
lemma is_unit_nonsing_inv_det_iff {A : matrix n n α} :
is_unit A⁻¹.det ↔ is_unit A.det :=
by rw [matrix.det_nonsing_inv, is_unit_ring_inverse]
/-- If `A.det` has a constructive inverse, produce one for `A`. -/
def invertible_of_det_invertible [invertible A.det] : invertible A :=
{ inv_of := ⅟A.det • A.adjugate,
mul_inv_of_self :=
by rw [mul_smul_comm, matrix.mul_eq_mul, mul_adjugate, smul_smul, inv_of_mul_self, one_smul],
inv_of_mul_self :=
by rw [smul_mul_assoc, matrix.mul_eq_mul, adjugate_mul, smul_smul, inv_of_mul_self, one_smul] }
/-- `A.det` is invertible if `A` has a left inverse. -/
def det_invertible_of_left_inverse (h : B ⬝ A = 1) : invertible A.det :=
{ inv_of := B.det,
mul_inv_of_self := by rw [mul_comm, ← det_mul, h, det_one],
inv_of_mul_self := by rw [← det_mul, h, det_one] }
/-- `A.det` is invertible if `A` has a right inverse. -/
def det_invertible_of_right_inverse (h : A ⬝ B = 1) : invertible A.det :=
{ inv_of := B.det,
mul_inv_of_self := by rw [← det_mul, h, det_one],
inv_of_mul_self := by rw [mul_comm, ← det_mul, h, det_one] }
/-- If `A` has a constructive inverse, produce one for `A.det`. -/
def det_invertible_of_invertible [invertible A] : invertible A.det :=
det_invertible_of_left_inverse A (⅟A) (inv_of_mul_self _)
/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `units (matrix n n α)`-/
def unit_of_det_invertible [invertible A.det] : units (matrix n n α) :=
@unit_of_invertible _ _ A (invertible_of_det_invertible A)
/-- A matrix whose determinant is a unit is itself a unit. This is a noncomputable version of
`matrix.units_of_det_invertible`, with the inverse defeq to `matrix.nonsing_inv`. -/
noncomputable def nonsing_inv_unit (h : is_unit A.det) : units (matrix n n α) :=
{ val := A,
inv := A⁻¹,
val_inv := by { rw matrix.mul_eq_mul, apply A.mul_nonsing_inv h, },
inv_val := by { rw matrix.mul_eq_mul, apply A.nonsing_inv_mul h, } }
lemma unit_of_det_invertible_eq_nonsing_inv_unit [invertible A.det] :
unit_of_det_invertible A = nonsing_inv_unit A (is_unit_of_invertible _) :=
by { ext, refl }
/-- When lowered to a prop, `matrix.det_invertible_of_invertible` and
`matrix.invertible_of_det_invertible` form an `iff`. -/
lemma is_unit_iff_is_unit_det : is_unit A ↔ is_unit A.det :=
begin
split; rintros ⟨x, hx⟩; refine @is_unit_of_invertible _ _ _ (id _),
{ haveI : invertible A := hx.rec x.invertible,
apply det_invertible_of_invertible, },
{ haveI : invertible A.det := hx.rec x.invertible,
apply invertible_of_det_invertible, },
end
/-- The nonsingular inverse is the same as the general `ring.inverse`. -/
lemma nonsing_inv_eq_ring_inverse : A⁻¹ = ring.inverse A :=
begin
by_cases h_det : is_unit A.det,
{ change ↑(nonsing_inv_unit A h_det)⁻¹ = _,
obtain ⟨u, rfl⟩ := (is_unit_iff_is_unit_det _).mpr h_det,
rw [ring.inverse_unit _, units.inv_unique],
refl },
{ have h := mt (is_unit_iff_is_unit_det _).mp h_det,
rw [ring.inverse_non_unit _ h, nonsing_inv_apply_not_is_unit A h_det], },
end
/- `is_unit_of_invertible A`
converts the "stronger" condition `invertible A` to proposition `is_unit A`. -/
/-- `matrix.is_unit_det_of_invertible` converts `invertible A` to `is_unit A.det`. -/
lemma is_unit_det_of_invertible [invertible A] : is_unit A.det :=
@is_unit_of_invertible _ _ _(det_invertible_of_invertible A)
@[simp]
lemma inv_eq_nonsing_inv_of_invertible [invertible A] : ⅟ A = A⁻¹ :=
begin
suffices : is_unit A,
{ rw [←this.mul_left_inj, inv_of_mul_self, matrix.mul_eq_mul, nonsing_inv_mul],
rwa ←is_unit_iff_is_unit_det },
exact is_unit_of_invertible _
end
variables {A} {B}
/- `is_unit.invertible` lifts the proposition `is_unit A` to a constructive inverse of `A`. -/
/-- "Lift" the proposition `is_unit A.det` to a constructive inverse of `A`. -/
noncomputable def invertible_of_is_unit_det (h : is_unit A.det) : invertible A :=
⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩
lemma is_unit_det_of_left_inverse (h : B ⬝ A = 1) : is_unit A.det :=
@is_unit_of_invertible _ _ _ (det_invertible_of_left_inverse _ _ h)
lemma is_unit_det_of_right_inverse (h : A ⬝ B = 1) : is_unit A.det :=
@is_unit_of_invertible _ _ _ (det_invertible_of_right_inverse _ _ h)
lemma det_ne_zero_of_left_inverse [nontrivial α] (h : B ⬝ A = 1) : A.det ≠ 0 :=
is_unit.ne_zero (matrix.is_unit_det_of_left_inverse h)
lemma det_ne_zero_of_right_inverse [nontrivial α] (h : A ⬝ B = 1) : A.det ≠ 0 :=
is_unit.ne_zero (matrix.is_unit_det_of_right_inverse h)
lemma nonsing_inv_left_right (h : A ⬝ B = 1) : B ⬝ A = 1 :=
begin
have h' : is_unit B.det := is_unit_det_of_left_inverse h,
calc B ⬝ A = (B ⬝ A) ⬝ (B ⬝ B⁻¹) : by simp only [h', matrix.mul_one, mul_nonsing_inv]
... = B ⬝ ((A ⬝ B) ⬝ B⁻¹) : by simp only [matrix.mul_assoc]
... = B ⬝ B⁻¹ : by simp only [h, matrix.one_mul]
... = 1 : mul_nonsing_inv B h',
end
lemma nonsing_inv_right_left (h : B ⬝ A = 1) : A ⬝ B = 1 :=
nonsing_inv_left_right h
/-- If matrix A is left invertible, then its inverse equals its left inverse. -/
lemma inv_eq_left_inv (h : B ⬝ A = 1) : A⁻¹ = B :=
begin
have h1 := (is_unit_det_of_left_inverse h),
have h2 := matrix.invertible_of_is_unit_det h1,
have := @inv_of_eq_left_inv (matrix n n α) (infer_instance) A B h2 h,
simp* at *,
end
/-- If matrix A is right invertible, then its inverse equals its right inverse. -/
lemma inv_eq_right_inv (h : A ⬝ B = 1) : A⁻¹ = B :=
begin
have h1 := (is_unit_det_of_right_inverse h),
have h2 := matrix.invertible_of_is_unit_det h1,
have := @inv_of_eq_right_inv (matrix n n α) (infer_instance) A B h2 h,
simp* at *,
end
/-- We can construct an instance of invertible A if A has a left inverse. -/
def invertible_of_left_inverse (h: B ⬝ A = 1) : invertible A :=
⟨B, h, nonsing_inv_right_left h⟩
/-- We can construct an instance of invertible A if A has a right inverse. -/
def invertible_of_right_inverse (h: A ⬝ B = 1) : invertible A :=
⟨B, nonsing_inv_left_right h, h⟩
section inv_eq_inv
variables {C : matrix n n α}
/-- The left inverse of matrix A is unique when existing. -/
lemma left_inv_eq_left_inv (h: B ⬝ A = 1) (g: C ⬝ A = 1) : B = C :=
by rw [←(inv_eq_left_inv h), ←(inv_eq_left_inv g)]
/-- The right inverse of matrix A is unique when existing. -/
lemma right_inv_eq_right_inv (h: A ⬝ B = 1) (g: A ⬝ C = 1) : B = C :=
by rw [←(inv_eq_right_inv h), ←(inv_eq_right_inv g)]
/-- The right inverse of matrix A equals the left inverse of A when they exist. -/
lemma right_inv_eq_left_inv (h: A ⬝ B = 1) (g: C ⬝ A = 1) : B = C :=
by rw [←(inv_eq_right_inv h), ←(inv_eq_left_inv g)]
lemma inv_inj (h : A⁻¹ = B⁻¹) (h' : is_unit A.det) : A = B :=
begin
refine left_inv_eq_left_inv (mul_nonsing_inv _ h') _,
rw h,
refine mul_nonsing_inv _ _,
rwa [←is_unit_nonsing_inv_det_iff, ←h, is_unit_nonsing_inv_det_iff]
end
end inv_eq_inv
variable (A)
@[simp] lemma mul_inv_of_invertible [invertible A] : A ⬝ A⁻¹ = 1 :=
mul_nonsing_inv A (is_unit_det_of_invertible A)
@[simp] lemma inv_mul_of_invertible [invertible A] : A⁻¹ ⬝ A = 1 :=
nonsing_inv_mul A (is_unit_det_of_invertible A)
@[simp] lemma inv_zero : (0 : matrix n n α)⁻¹ = 0 :=
begin
casesI (subsingleton_or_nontrivial α) with ht ht,
{ simp },
cases (fintype.card n).zero_le.eq_or_lt with hc hc,
{ rw [eq_comm, fintype.card_eq_zero_iff] at hc,
haveI := hc,
ext i,
exact (is_empty.false i).elim },
{ have hn : nonempty n := fintype.card_pos_iff.mp hc,
refine nonsing_inv_apply_not_is_unit _ _,
simp [hn] },
end
@[simp] lemma inv_one : (1 : matrix n n α)⁻¹ = 1 :=
inv_eq_left_inv (by simp)
lemma inv_smul (k : α) [invertible k] (h : is_unit A.det) : (k • A)⁻¹ = ⅟k • A⁻¹ :=
inv_eq_left_inv (by simp [h, smul_smul])
lemma inv_smul' (k : units α) (h : is_unit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ :=
inv_eq_left_inv (by simp [h, smul_smul])
lemma inv_adjugate (A : matrix n n α) (h : is_unit A.det) :
(adjugate A)⁻¹ = h.unit⁻¹ • A :=
begin
refine inv_eq_left_inv _,
rw [smul_mul, mul_adjugate, units.smul_def, smul_smul, h.coe_inv_mul, one_smul]
end
@[simp] lemma inv_inv_inv (A : matrix n n α) : A⁻¹⁻¹⁻¹ = A⁻¹ :=
begin
by_cases h : is_unit A.det,
{ rw [nonsing_inv_nonsing_inv _ h] },
{ simp [nonsing_inv_apply_not_is_unit _ h] }
end
lemma mul_inv_rev (A B : matrix n n α) : (A ⬝ B)⁻¹ = B⁻¹ ⬝ A⁻¹ :=
begin
simp only [inv_def],
rw [matrix.smul_mul, matrix.mul_smul, smul_smul, det_mul, adjugate_mul_distrib,
ring.mul_inverse_rev],
end
/-- One form of **Cramer's rule**. See `matrix.mul_vec_cramer` for a stronger form. -/
@[simp] lemma det_smul_inv_mul_vec_eq_cramer (A : matrix n n α) (b : n → α) (h : is_unit A.det) :
A.det • A⁻¹.mul_vec b = cramer A b :=
begin
rw [cramer_eq_adjugate_mul_vec, A.nonsing_inv_apply h, ← smul_mul_vec_assoc,
smul_smul, h.mul_coe_inv, one_smul]
end
end matrix
|
2e82cad3cb6c0e0c98f70ceb1c51009d335f73fd
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/algebra/homology/additive.lean
|
072555a1eabcea49b3cb4a96da9e07ad69d9aa4a
|
[
"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
| 11,209
|
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 algebra.homology.homology
import algebra.homology.single
import category_theory.preadditive.additive_functor
/-!
# Homology is an additive functor
When `V` is preadditive, `homological_complex V c` is also preadditive,
and `homology_functor` is additive.
TODO: similarly for `R`-linear.
-/
universes v u
open_locale classical
noncomputable theory
open category_theory category_theory.category category_theory.limits homological_complex
variables {ι : Type*}
variables {V : Type u} [category.{v} V] [preadditive V]
variables {c : complex_shape ι} {C D E : homological_complex V c}
variables (f g : C ⟶ D) (h k : D ⟶ E) (i : ι)
namespace homological_complex
instance : has_zero (C ⟶ D) := ⟨{ f := λ i, 0 }⟩
instance : has_add (C ⟶ D) := ⟨λ f g, { f := λ i, f.f i + g.f i, }⟩
instance : has_neg (C ⟶ D) := ⟨λ f, { f := λ i, -(f.f i) }⟩
instance : has_sub (C ⟶ D) := ⟨λ f g, { f := λ i, f.f i - g.f i, }⟩
instance has_nat_scalar : has_smul ℕ (C ⟶ D) := ⟨λ n f,
{ f := λ i, n • f.f i,
comm' := λ i j h, by simp [preadditive.nsmul_comp, preadditive.comp_nsmul] }⟩
instance has_int_scalar : has_smul ℤ (C ⟶ D) := ⟨λ n f,
{ f := λ i, n • f.f i,
comm' := λ i j h, by simp [preadditive.zsmul_comp, preadditive.comp_zsmul] }⟩
@[simp] lemma zero_f_apply (i : ι) : (0 : C ⟶ D).f i = 0 := rfl
@[simp] lemma add_f_apply (f g : C ⟶ D) (i : ι) : (f + g).f i = f.f i + g.f i := rfl
@[simp] lemma neg_f_apply (f : C ⟶ D) (i : ι) : (-f).f i = -(f.f i) := rfl
@[simp] lemma sub_f_apply (f g : C ⟶ D) (i : ι) : (f - g).f i = f.f i - g.f i := rfl
@[simp] lemma nsmul_f_apply (n : ℕ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl
@[simp] lemma zsmul_f_apply (n : ℤ) (f : C ⟶ D) (i : ι) : (n • f).f i = n • f.f i := rfl
instance : add_comm_group (C ⟶ D) :=
function.injective.add_comm_group hom.f
homological_complex.hom_f_injective (by tidy) (by tidy) (by tidy) (by tidy) (by tidy) (by tidy)
instance : preadditive (homological_complex V c) := {}
/-- The `i`-th component of a chain map, as an additive map from chain maps to morphisms. -/
@[simps]
def hom.f_add_monoid_hom {C₁ C₂ : homological_complex V c} (i : ι) :
(C₁ ⟶ C₂) →+ (C₁.X i ⟶ C₂.X i) :=
add_monoid_hom.mk' (λ f, hom.f f i) (λ _ _, rfl)
end homological_complex
namespace homological_complex
instance eval_additive (i : ι) : (eval V c i).additive := {}
instance cycles_additive [has_equalizers V] : (cycles_functor V c i).additive := {}
variables [has_images V] [has_image_maps V]
instance boundaries_additive : (boundaries_functor V c i).additive := {}
variables [has_equalizers V] [has_cokernels V]
instance homology_additive : (homology_functor V c i).additive :=
{ map_add' := λ C D f g, begin
dsimp [homology_functor],
ext,
simp only [homology.π_map, preadditive.comp_add, ←preadditive.add_comp],
congr,
ext, simp,
end }
end homological_complex
namespace category_theory
variables {W : Type*} [category W] [preadditive W]
/--
An additive functor induces a functor between homological complexes.
This is sometimes called the "prolongation".
-/
@[simps]
def functor.map_homological_complex (F : V ⥤ W) [F.additive] (c : complex_shape ι) :
homological_complex V c ⥤ homological_complex W c :=
{ obj := λ C,
{ X := λ i, F.obj (C.X i),
d := λ i j, F.map (C.d i j),
shape' := λ i j w, by rw [C.shape _ _ w, F.map_zero],
d_comp_d' := λ i j k _ _, by rw [←F.map_comp, C.d_comp_d, F.map_zero], },
map := λ C D f,
{ f := λ i, F.map (f.f i),
comm' := λ i j h, by { dsimp, rw [←F.map_comp, ←F.map_comp, f.comm], }, }, }.
instance functor.map_homogical_complex_additive
(F : V ⥤ W) [F.additive] (c : complex_shape ι) : (F.map_homological_complex c).additive := {}
/--
A natural transformation between functors induces a natural transformation
between those functors applied to homological complexes.
-/
@[simps]
def nat_trans.map_homological_complex {F G : V ⥤ W} [F.additive] [G.additive]
(α : F ⟶ G) (c : complex_shape ι) : F.map_homological_complex c ⟶ G.map_homological_complex c :=
{ app := λ C, { f := λ i, α.app _, }, }
@[simp] lemma nat_trans.map_homological_complex_id (c : complex_shape ι) (F : V ⥤ W) [F.additive] :
nat_trans.map_homological_complex (𝟙 F) c = 𝟙 (F.map_homological_complex c) :=
by tidy
@[simp] lemma nat_trans.map_homological_complex_comp (c : complex_shape ι)
{F G H : V ⥤ W} [F.additive] [G.additive] [H.additive]
(α : F ⟶ G) (β : G ⟶ H):
nat_trans.map_homological_complex (α ≫ β) c =
nat_trans.map_homological_complex α c ≫ nat_trans.map_homological_complex β c :=
by tidy
@[simp, reassoc] lemma nat_trans.map_homological_complex_naturality {c : complex_shape ι}
{F G : V ⥤ W} [F.additive] [G.additive] (α : F ⟶ G) {C D : homological_complex V c} (f : C ⟶ D) :
(F.map_homological_complex c).map f ≫ (nat_trans.map_homological_complex α c).app D =
(nat_trans.map_homological_complex α c).app C ≫ (G.map_homological_complex c).map f :=
by tidy
end category_theory
namespace chain_complex
variables {W : Type*} [category W] [preadditive W]
variables {α : Type*} [add_right_cancel_semigroup α] [has_one α] [decidable_eq α]
lemma map_chain_complex_of (F : V ⥤ W) [F.additive] (X : α → V) (d : Π n, X (n+1) ⟶ X n)
(sq : ∀ n, d (n+1) ≫ d n = 0) :
(F.map_homological_complex _).obj (chain_complex.of X d sq) =
chain_complex.of (λ n, F.obj (X n))
(λ n, F.map (d n)) (λ n, by rw [ ← F.map_comp, sq n, functor.map_zero]) :=
begin
refine homological_complex.ext rfl _,
rintro i j (rfl : j + 1 = i),
simp only [category_theory.functor.map_homological_complex_obj_d, of_d,
eq_to_hom_refl, comp_id, id_comp],
end
end chain_complex
variables [has_zero_object V] {W : Type*} [category W] [preadditive W] [has_zero_object W]
namespace homological_complex
local attribute [simp] eq_to_hom_map
/--
Turning an object into a complex supported at `j` then applying a functor is
the same as applying the functor then forming the complex.
-/
def single_map_homological_complex (F : V ⥤ W) [F.additive] (c : complex_shape ι) (j : ι):
single V c j ⋙ F.map_homological_complex _ ≅ F ⋙ single W c j :=
nat_iso.of_components (λ X,
{ hom := { f := λ i, if h : i = j then
eq_to_hom (by simp [h])
else
0, },
inv := { f := λ i, if h : i = j then
eq_to_hom (by simp [h])
else
0, },
hom_inv_id' := begin
ext i,
dsimp,
split_ifs with h,
{ simp [h] },
{ rw [zero_comp, if_neg h],
exact (zero_of_source_iso_zero _ F.map_zero_object).symm, },
end,
inv_hom_id' := begin
ext i,
dsimp,
split_ifs with h,
{ simp [h] },
{ rw [zero_comp, if_neg h],
simp, },
end, })
(λ X Y f, begin
ext i,
dsimp,
split_ifs with h; simp [h],
end).
variables (F : V ⥤ W) [functor.additive F] (c)
@[simp] lemma single_map_homological_complex_hom_app_self (j : ι) (X : V) :
((single_map_homological_complex F c j).hom.app X).f j = eq_to_hom (by simp) :=
by simp [single_map_homological_complex]
@[simp] lemma single_map_homological_complex_hom_app_ne
{i j : ι} (h : i ≠ j) (X : V) :
((single_map_homological_complex F c j).hom.app X).f i = 0 :=
by simp [single_map_homological_complex, h]
@[simp] lemma single_map_homological_complex_inv_app_self (j : ι) (X : V) :
((single_map_homological_complex F c j).inv.app X).f j = eq_to_hom (by simp) :=
by simp [single_map_homological_complex]
@[simp] lemma single_map_homological_complex_inv_app_ne
{i j : ι} (h : i ≠ j) (X : V):
((single_map_homological_complex F c j).inv.app X).f i = 0 :=
by simp [single_map_homological_complex, h]
end homological_complex
namespace chain_complex
/--
Turning an object into a chain complex supported at zero then applying a functor is
the same as applying the functor then forming the complex.
-/
def single₀_map_homological_complex (F : V ⥤ W) [F.additive] :
single₀ V ⋙ F.map_homological_complex _ ≅ F ⋙ single₀ W :=
nat_iso.of_components (λ X,
{ hom := { f := λ i, match i with
| 0 := 𝟙 _
| (i+1) := F.map_zero_object.hom
end, },
inv := { f := λ i, match i with
| 0 := 𝟙 _
| (i+1) := F.map_zero_object.inv
end, },
hom_inv_id' := begin
ext (_|i),
{ unfold_aux, simp, },
{ unfold_aux,
dsimp,
simp only [comp_f, id_f, zero_comp],
exact (zero_of_source_iso_zero _ F.map_zero_object).symm, }
end,
inv_hom_id' := by { ext (_|i); { unfold_aux, dsimp, simp, }, }, })
(λ X Y f, by { ext (_|i); { unfold_aux, dsimp, simp, }, }).
@[simp] lemma single₀_map_homological_complex_hom_app_zero (F : V ⥤ W) [F.additive] (X : V) :
((single₀_map_homological_complex F).hom.app X).f 0 = 𝟙 _ := rfl
@[simp] lemma single₀_map_homological_complex_hom_app_succ
(F : V ⥤ W) [F.additive] (X : V) (n : ℕ) :
((single₀_map_homological_complex F).hom.app X).f (n+1) = 0 := rfl
@[simp] lemma single₀_map_homological_complex_inv_app_zero (F : V ⥤ W) [F.additive] (X : V) :
((single₀_map_homological_complex F).inv.app X).f 0 = 𝟙 _ := rfl
@[simp] lemma single₀_map_homological_complex_inv_app_succ
(F : V ⥤ W) [F.additive] (X : V) (n : ℕ) :
((single₀_map_homological_complex F).inv.app X).f (n+1) = 0 := rfl
end chain_complex
namespace cochain_complex
/--
Turning an object into a cochain complex supported at zero then applying a functor is
the same as applying the functor then forming the cochain complex.
-/
def single₀_map_homological_complex (F : V ⥤ W) [F.additive] :
single₀ V ⋙ F.map_homological_complex _ ≅ F ⋙ single₀ W :=
nat_iso.of_components (λ X,
{ hom := { f := λ i, match i with
| 0 := 𝟙 _
| (i+1) := F.map_zero_object.hom
end, },
inv := { f := λ i, match i with
| 0 := 𝟙 _
| (i+1) := F.map_zero_object.inv
end, },
hom_inv_id' := begin
ext (_|i),
{ unfold_aux, simp, },
{ unfold_aux,
dsimp,
simp only [comp_f, id_f, zero_comp],
exact (zero_of_source_iso_zero _ F.map_zero_object).symm, }
end,
inv_hom_id' := by { ext (_|i); { unfold_aux, dsimp, simp, }, }, })
(λ X Y f, by { ext (_|i); { unfold_aux, dsimp, simp, }, }).
@[simp] lemma single₀_map_homological_complex_hom_app_zero (F : V ⥤ W) [F.additive] (X : V) :
((single₀_map_homological_complex F).hom.app X).f 0 = 𝟙 _ := rfl
@[simp] lemma single₀_map_homological_complex_hom_app_succ
(F : V ⥤ W) [F.additive] (X : V) (n : ℕ) :
((single₀_map_homological_complex F).hom.app X).f (n+1) = 0 := rfl
@[simp] lemma single₀_map_homological_complex_inv_app_zero (F : V ⥤ W) [F.additive] (X : V) :
((single₀_map_homological_complex F).inv.app X).f 0 = 𝟙 _ := rfl
@[simp] lemma single₀_map_homological_complex_inv_app_succ
(F : V ⥤ W) [F.additive] (X : V) (n : ℕ) :
((single₀_map_homological_complex F).inv.app X).f (n+1) = 0 := rfl
end cochain_complex
|
9352b6e7f95b67d8661d63bcf7330fe297c3ba20
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/analysis/inner_product_space/l2_space.lean
|
518ff11a4b9a9155bdb409b6101e00204bcc723e
|
[
"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
| 24,802
|
lean
|
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.inner_product_space.projection
import analysis.normed_space.lp_space
import analysis.inner_product_space.pi_L2
/-!
# Hilbert sum of a family of inner product spaces
Given a family `(G : ι → Type*) [Π i, inner_product_space 𝕜 (G i)]` of inner product spaces, this
file equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those
dependent functions `f : Π i, G i` for which `∑' i, ∥f i∥ ^ 2`, the sum of the norms-squared, is
summable. This construction is sometimes called the *Hilbert sum* of the family `G`. By choosing
`G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction.
We also define a *predicate* `is_hilbert_sum 𝕜 E V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that
`V` is an `orthogonal_family` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective.
## Main definitions
* `orthogonal_family.linear_isometry`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with
mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G`
into `E`.
* `is_hilbert_sum`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`,
`is_hilbert_sum 𝕜 E V` means that `V` is an `orthogonal_family` and that the above
linear isometry is surjective.
* `is_hilbert_sum.linear_isometry_equiv`: If a Hilbert space `E` is a Hilbert sum of the
inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the
corresponding `orthogonal_family.linear_isometry` can be upgraded to a `linear_isometry_equiv`.
* `hilbert_basis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single
field `hilbert_basis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert
sum of `ι` copies of `𝕜`). This parallels the definition of `basis`, in `linear_algebra.basis`,
as an isomorphism of an `R`-module with `ι →₀ R`.
* `hilbert_basis.has_coe_to_fun`: More conventionally a Hilbert basis is thought of as a family
`ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness). We obtain
this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image
under `b.repr` of `lp.single 2 i (1:𝕜)`. This parallels the definition `basis.has_coe_to_fun` in
`linear_algebra.basis`.
* `hilbert_basis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors
in `E` whose span is dense. This parallels the definition `basis.mk` in `linear_algebra.basis`.
* `hilbert_basis.mk_of_orthogonal_eq_bot`: Make a Hilbert basis of `E` from an orthonormal family
`v : ι → E` of vectors in `E` whose span has trivial orthogonal complement.
## Main results
* `lp.inner_product_space`: Construction of the inner product space instance on the Hilbert sum
`lp G 2`. Note that from the file `analysis.normed_space.lp_space`, the space `lp G 2` already
held a normed space instance (`lp.normed_space`), and if each `G i` is a Hilbert space (i.e.,
complete), then `lp G 2` was already known to be complete (`lp.complete_space`). So the work
here is to define the inner product and show it is compatible.
* `orthogonal_family.range_linear_isometry`: Given a family `G` of inner product spaces and a family
`V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal
images, the image of the embedding `orthogonal_family.linear_isometry` of the Hilbert sum of `G`
into `E` is the closure of the span of the images of the `G i`.
* `hilbert_basis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of
`x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`.
* `hilbert_basis.has_sum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be
expressed as the "infinite linear combination" `∑' i, b.repr x i • b i` of the basis vectors
`b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`.
* `exists_hilbert_basis`: A Hilbert space admits a Hilbert basis.
## Keywords
Hilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism
-/
open is_R_or_C submodule filter
open_locale big_operators nnreal ennreal classical complex_conjugate
noncomputable theory
variables {ι : Type*}
variables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [inner_product_space 𝕜 E] [cplt : complete_space E]
variables {G : ι → Type*} [Π i, inner_product_space 𝕜 (G i)]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
notation `ℓ²(`ι`, `𝕜`)` := lp (λ i : ι, 𝕜) 2
/-! ### Inner product space structure on `lp G 2` -/
namespace lp
lemma summable_inner (f g : lp G 2) : summable (λ i, ⟪f i, g i⟫) :=
begin
-- Apply the Direct Comparison Test, comparing with ∑' i, ∥f i∥ * ∥g i∥ (summable by Hölder)
refine summable_of_norm_bounded (λ i, ∥f i∥ * ∥g i∥) (lp.summable_mul _ f g) _,
{ rw real.is_conjugate_exponent_iff; norm_num },
intros i,
-- Then apply Cauchy-Schwarz pointwise
exact norm_inner_le_norm _ _,
end
instance : inner_product_space 𝕜 (lp G 2) :=
{ inner := λ f g, ∑' i, ⟪f i, g i⟫,
norm_sq_eq_inner := λ f, begin
calc ∥f∥ ^ 2 = ∥f∥ ^ (2:ℝ≥0∞).to_real : by norm_cast
... = ∑' i, ∥f i∥ ^ (2:ℝ≥0∞).to_real : lp.norm_rpow_eq_tsum _ f
... = ∑' i, ∥f i∥ ^ 2 : by norm_cast
... = ∑' i, re ⟪f i, f i⟫ : by simp only [norm_sq_eq_inner]
... = re (∑' i, ⟪f i, f i⟫) : (is_R_or_C.re_clm.map_tsum _).symm
... = _ : by congr,
{ norm_num },
{ exact summable_inner f f },
end,
conj_sym := λ f g, begin
calc conj _ = conj ∑' i, ⟪g i, f i⟫ : by congr
... = ∑' i, conj ⟪g i, f i⟫ : is_R_or_C.conj_cle.map_tsum
... = ∑' i, ⟪f i, g i⟫ : by simp only [inner_conj_sym]
... = _ : by congr,
end,
add_left := λ f₁ f₂ g, begin
calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ : _
... = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) :
by simp only [inner_add_left, pi.add_apply, coe_fn_add]
... = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ : tsum_add _ _
... = _ : by congr,
{ congr, },
{ exact summable_inner f₁ g },
{ exact summable_inner f₂ g }
end,
smul_left := λ f g c, begin
calc _ = ∑' i, ⟪c • f i, g i⟫ : _
... = ∑' i, conj c * ⟪f i, g i⟫ : by simp only [inner_smul_left]
... = conj c * ∑' i, ⟪f i, g i⟫ : tsum_mul_left
... = _ : _,
{ simp only [coe_fn_smul, pi.smul_apply] },
{ congr },
end,
.. lp.normed_space }
lemma inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl
lemma has_sum_inner (f g : lp G 2) : has_sum (λ i, ⟪f i, g i⟫) ⟪f, g⟫ :=
(summable_inner f g).has_sum
lemma inner_single_left (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ :=
begin
refine (has_sum_inner (lp.single 2 i a) f).unique _,
convert has_sum_ite_eq i ⟪a, f i⟫,
ext j,
rw lp.single_apply,
split_ifs,
{ subst h },
{ simp }
end
lemma inner_single_right (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ :=
by simpa [inner_conj_sym] using congr_arg conj (inner_single_left i a f)
end lp
/-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/
namespace orthogonal_family
variables {V : Π i, G i →ₗᵢ[𝕜] E} (hV : orthogonal_family 𝕜 V)
include cplt hV
protected lemma summable_of_lp (f : lp G 2) : summable (λ i, V i (f i)) :=
begin
rw hV.summable_iff_norm_sq_summable,
convert (lp.mem_ℓp f).summable _,
{ norm_cast },
{ norm_num }
end
/-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the
subspaces into `E`. -/
protected def linear_isometry : lp G 2 →ₗᵢ[𝕜] E :=
{ to_fun := λ f, ∑' i, V i (f i),
map_add' := λ f g, by simp only [tsum_add (hV.summable_of_lp f) (hV.summable_of_lp g),
lp.coe_fn_add, pi.add_apply, linear_isometry.map_add],
map_smul' := λ c f, by simpa only [linear_isometry.map_smul, pi.smul_apply, lp.coe_fn_smul]
using tsum_const_smul (hV.summable_of_lp f),
norm_map' := λ f, begin
classical, -- needed for lattice instance on `finset ι`, for `filter.at_top_ne_bot`
have H : 0 < (2:ℝ≥0∞).to_real := by norm_num,
suffices : ∥∑' (i : ι), V i (f i)∥ ^ ((2:ℝ≥0∞).to_real) = ∥f∥ ^ ((2:ℝ≥0∞).to_real),
{ exact real.rpow_left_inj_on H.ne' (norm_nonneg _) (norm_nonneg _) this },
refine tendsto_nhds_unique _ (lp.has_sum_norm H f),
convert (hV.summable_of_lp f).has_sum.norm.rpow_const (or.inr H.le),
ext s,
exact_mod_cast (hV.norm_sum f s).symm,
end }
protected lemma linear_isometry_apply (f : lp G 2) :
hV.linear_isometry f = ∑' i, V i (f i) :=
rfl
protected lemma has_sum_linear_isometry (f : lp G 2) :
has_sum (λ i, V i (f i)) (hV.linear_isometry f) :=
(hV.summable_of_lp f).has_sum
@[simp] protected lemma linear_isometry_apply_single {i : ι} (x : G i) :
hV.linear_isometry (lp.single 2 i x) = V i x :=
begin
rw [hV.linear_isometry_apply, ← tsum_ite_eq i (V i x)],
congr,
ext j,
rw [lp.single_apply],
split_ifs,
{ subst h },
{ simp }
end
@[simp] protected lemma linear_isometry_apply_dfinsupp_sum_single (W₀ : Π₀ (i : ι), G i) :
hV.linear_isometry (W₀.sum (lp.single 2)) = W₀.sum (λ i, V i) :=
begin
have : hV.linear_isometry (∑ i in W₀.support, lp.single 2 i (W₀ i))
= ∑ i in W₀.support, hV.linear_isometry (lp.single 2 i (W₀ i)),
{ exact hV.linear_isometry.to_linear_map.map_sum },
simp [dfinsupp.sum, this] {contextual := tt},
end
/-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of
`E` into E, has range the closure of the span of the subspaces. -/
protected lemma range_linear_isometry [Π i, complete_space (G i)] :
hV.linear_isometry.to_linear_map.range = (⨆ i, (V i).to_linear_map.range).topological_closure :=
begin
refine le_antisymm _ _,
{ rintros x ⟨f, rfl⟩,
refine mem_closure_of_tendsto (hV.has_sum_linear_isometry f) (eventually_of_forall _),
intros s,
rw set_like.mem_coe,
refine sum_mem _,
intros i hi,
refine mem_supr_of_mem i _,
exact linear_map.mem_range_self _ (f i) },
{ apply topological_closure_minimal,
{ refine supr_le _,
rintros i x ⟨x, rfl⟩,
use lp.single 2 i x,
exact hV.linear_isometry_apply_single x },
exact hV.linear_isometry.isometry.uniform_inducing.is_complete_range.is_closed }
end
end orthogonal_family
section is_hilbert_sum
variables (𝕜 E) (V : Π i, G i →ₗᵢ[𝕜] E) (F : ι → submodule 𝕜 E)
include cplt
/-- Given a family of Hilbert spaces `G : ι → Type*`, a Hilbert sum of `G` consists of a Hilbert
space `E` and an orthogonal family `V : Π i, G i →ₗᵢ[𝕜] E` such that the induced isometry
`Φ : lp G 2 → E` is surjective.
Keeping in mind that `lp G 2` is "the" external Hilbert sum of `G : ι → Type*`, this is analogous
to `direct_sum.is_internal`, except that we don't express it in terms of actual submodules. -/
@[protect_proj] structure is_hilbert_sum : Prop := of_surjective ::
(orthogonal_family : orthogonal_family 𝕜 V)
(surjective_isometry : function.surjective (orthogonal_family.linear_isometry))
variables {𝕜 E V}
/-- If `V : Π i, G i →ₗᵢ[𝕜] E` is an orthogonal family such that the supremum of the ranges of
`V i` is dense, then `(E, V)` is a Hilbert sum of `G`. -/
lemma is_hilbert_sum.mk [Π i, complete_space $ G i]
(hVortho : orthogonal_family 𝕜 V)
(hVtotal : ⊤ ≤ (⨆ i, (V i).to_linear_map.range).topological_closure) :
is_hilbert_sum 𝕜 E V :=
{ orthogonal_family := hVortho,
surjective_isometry :=
begin
rw [←linear_isometry.coe_to_linear_map],
exact linear_map.range_eq_top.mp (eq_top_iff.mpr $
hVtotal.trans_eq hVortho.range_linear_isometry.symm)
end }
/-- This is `orthogonal_family.is_hilbert_sum` in the case of actual inclusions from subspaces. -/
lemma is_hilbert_sum.mk_internal [Π i, complete_space $ F i]
(hFortho : @orthogonal_family 𝕜 E _ _ _ (λ i, F i) _ (λ i, (F i).subtypeₗᵢ))
(hFtotal : ⊤ ≤ (⨆ i, (F i)).topological_closure) :
@is_hilbert_sum _ 𝕜 _ E _ _ (λ i, F i) _ (λ i, (F i).subtypeₗᵢ) :=
is_hilbert_sum.mk hFortho (by simpa [subtypeₗᵢ_to_linear_map, range_subtype] using hFtotal)
/-- *A* Hilbert sum `(E, V)` of `G` is canonically isomorphic to *the* Hilbert sum of `G`,
i.e `lp G 2`.
Note that this goes in the opposite direction from `orthogonal_family.linear_isometry`. -/
noncomputable def is_hilbert_sum.linear_isometry_equiv (hV : is_hilbert_sum 𝕜 E V) :
E ≃ₗᵢ[𝕜] lp G 2 :=
linear_isometry_equiv.symm $
linear_isometry_equiv.of_surjective
hV.orthogonal_family.linear_isometry hV.surjective_isometry
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,
a vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`. -/
protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply
(hV : is_hilbert_sum 𝕜 E V) (w : lp G 2) :
hV.linear_isometry_equiv.symm w = ∑' i, V i (w i) :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,
a vector `w : lp G 2` is the image of the infinite sum of the associated elements in `E`, and this
sum indeed converges. -/
protected lemma is_hilbert_sum.has_sum_linear_isometry_equiv_symm
(hV : is_hilbert_sum 𝕜 E V) (w : lp G 2) :
has_sum (λ i, V i (w i)) (hV.linear_isometry_equiv.symm w) :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.has_sum_linear_isometry]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, an "elementary basis vector" in `lp G 2` supported at `i : ι` is the image of the
associated element in `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_single
(hV : is_hilbert_sum 𝕜 E V) {i : ι} (x : G i) :
hV.linear_isometry_equiv.symm (lp.single 2 i x) = V i x :=
by simp [is_hilbert_sum.linear_isometry_equiv, orthogonal_family.linear_isometry_apply_single]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of
elements of `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_symm_apply_dfinsupp_sum_single
(hV : is_hilbert_sum 𝕜 E V) (W₀ : Π₀ (i : ι), G i) :
hV.linear_isometry_equiv.symm (W₀.sum (lp.single 2)) = (W₀.sum (λ i, V i)) :=
by simp [is_hilbert_sum.linear_isometry_equiv,
orthogonal_family.linear_isometry_apply_dfinsupp_sum_single]
/-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G : ι → Type*` and
`lp G 2`, a finitely-supported vector in `lp G 2` is the image of the associated finite sum of
elements of `E`. -/
@[simp] protected lemma is_hilbert_sum.linear_isometry_equiv_apply_dfinsupp_sum_single
(hV : is_hilbert_sum 𝕜 E V) (W₀ : Π₀ (i : ι), G i) :
(hV.linear_isometry_equiv (W₀.sum (λ i, V i)) : Π i, G i) = W₀ :=
begin
rw ← hV.linear_isometry_equiv_symm_apply_dfinsupp_sum_single,
rw linear_isometry_equiv.apply_symm_apply,
ext i,
simp [dfinsupp.sum, lp.single_apply] {contextual := tt},
end
/-- Given a total orthonormal family `v : ι → E`, `E` is a Hilbert sum of `λ i : ι, 𝕜` relative to
the family of linear isometries `λ i, λ k, k • v i`. -/
lemma orthonormal.is_hilbert_sum {v : ι → E} (hv : orthonormal 𝕜 v)
(hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
@is_hilbert_sum _ 𝕜 _ _ _ _ (λ i : ι, 𝕜) _
(λ i, linear_isometry.to_span_singleton 𝕜 E (hv.1 i)) :=
is_hilbert_sum.mk hv.orthogonal_family
begin
convert hsp,
simp [← linear_map.span_singleton_eq_range, ← submodule.span_Union],
end
lemma submodule.is_hilbert_sum_orthogonal (K : submodule 𝕜 E) [hK : complete_space K] :
@is_hilbert_sum _ 𝕜 _ E _ _ (λ b, ((cond b K Kᗮ : submodule 𝕜 E) : Type*)) _
(λ b, (cond b K Kᗮ).subtypeₗᵢ) :=
begin
haveI : Π b, complete_space ((cond b K Kᗮ : submodule 𝕜 E) : Type*),
{ intro b,
cases b;
exact orthogonal.complete_space K <|> assumption },
refine is_hilbert_sum.mk_internal _ K.orthogonal_family_self _,
refine le_trans _ (submodule.submodule_topological_closure _),
rw supr_bool_eq,
exact submodule.is_compl_orthogonal_of_complete_space.2
end
end is_hilbert_sum
/-! ### Hilbert bases -/
section
variables (ι) (𝕜) (E)
/-- A Hilbert basis on `ι` for an inner product space `E` is an identification of `E` with the `lp`
space `ℓ²(ι, 𝕜)`. -/
structure hilbert_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] ℓ²(ι, 𝕜))
end
namespace hilbert_basis
instance {ι : Type*} : inhabited (hilbert_basis ι 𝕜 ℓ²(ι, 𝕜)) :=
⟨of_repr (linear_isometry_equiv.refl 𝕜 _)⟩
/-- `b i` is the `i`th basis vector. -/
instance : has_coe_to_fun (hilbert_basis ι 𝕜 E) (λ _, ι → E) :=
{ coe := λ b i, b.repr.symm (lp.single 2 i (1:𝕜)) }
@[simp] protected lemma repr_symm_single (b : hilbert_basis ι 𝕜 E) (i : ι) :
b.repr.symm (lp.single 2 i (1:𝕜)) = b i :=
rfl
@[simp] protected lemma repr_self (b : hilbert_basis ι 𝕜 E) (i : ι) :
b.repr (b i) = lp.single 2 i (1:𝕜) :=
by rw [← b.repr_symm_single, linear_isometry_equiv.apply_symm_apply]
protected lemma repr_apply_apply (b : hilbert_basis ι 𝕜 E) (v : E) (i : ι) :
b.repr v i = ⟪b i, v⟫ :=
begin
rw [← b.repr.inner_map_map (b i) v, b.repr_self, lp.inner_single_left],
simp,
end
@[simp] protected lemma orthonormal (b : hilbert_basis ι 𝕜 E) : orthonormal 𝕜 b :=
begin
rw orthonormal_iff_ite,
intros i j,
rw [← b.repr.inner_map_map (b i) (b j), b.repr_self, b.repr_self, lp.inner_single_left,
lp.single_apply],
simp,
end
protected lemma has_sum_repr_symm (b : hilbert_basis ι 𝕜 E) (f : ℓ²(ι, 𝕜)) :
has_sum (λ i, f i • b i) (b.repr.symm f) :=
begin
suffices H : (λ (i : ι), f i • b i) =
(λ (b_1 : ι), (b.repr.symm.to_continuous_linear_equiv) ((λ (i : ι), lp.single 2 i (f i)) b_1)),
{ rw H,
have : has_sum (λ (i : ι), lp.single 2 i (f i)) f := lp.has_sum_single ennreal.two_ne_top f,
exact (↑(b.repr.symm.to_continuous_linear_equiv) : ℓ²(ι, 𝕜) →L[𝕜] E).has_sum this },
ext i,
apply b.repr.injective,
have : lp.single 2 i (f i * 1) = f i • lp.single 2 i 1 := lp.single_smul 2 i (1:𝕜) (f i),
rw mul_one at this,
rw [linear_isometry_equiv.map_smul, b.repr_self, ← this,
linear_isometry_equiv.coe_to_continuous_linear_equiv],
exact (b.repr.apply_symm_apply (lp.single 2 i (f i))).symm,
end
protected lemma has_sum_repr (b : hilbert_basis ι 𝕜 E) (x : E) :
has_sum (λ i, b.repr x i • b i) x :=
by simpa using b.has_sum_repr_symm (b.repr x)
@[simp] protected lemma dense_span (b : hilbert_basis ι 𝕜 E) :
(span 𝕜 (set.range b)).topological_closure = ⊤ :=
begin
classical,
rw eq_top_iff,
rintros x -,
refine mem_closure_of_tendsto (b.has_sum_repr x) (eventually_of_forall _),
intros s,
simp only [set_like.mem_coe],
refine sum_mem _,
rintros i -,
refine smul_mem _ _ _,
exact subset_span ⟨i, rfl⟩
end
protected lemma has_sum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
has_sum (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) ⟪x, y⟫ :=
begin
convert (b.has_sum_repr y).mapL (innerSL x),
ext i,
rw [innerSL_apply, b.repr_apply_apply, inner_smul_right, mul_comm]
end
protected lemma summable_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
summable (λ i, ⟪x, b i⟫ * ⟪b i, y⟫) :=
(b.has_sum_inner_mul_inner x y).summable
protected lemma tsum_inner_mul_inner (b : hilbert_basis ι 𝕜 E) (x y : E) :
∑' i, ⟪x, b i⟫ * ⟪b i, y⟫ = ⟪x, y⟫ :=
(b.has_sum_inner_mul_inner x y).tsum_eq
-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with
-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).
/-- A finite Hilbert basis is an orthonormal basis. -/
protected def to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :
orthonormal_basis ι 𝕜 E :=
orthonormal_basis.mk b.orthonormal
begin
refine eq.ge _,
have := (span 𝕜 (finset.univ.image b : set E)).closed_of_finite_dimensional,
simpa only [finset.coe_image, finset.coe_univ, set.image_univ, hilbert_basis.dense_span] using
this.submodule_topological_closure_eq.symm
end
@[simp] lemma coe_to_orthonormal_basis [fintype ι] (b : hilbert_basis ι 𝕜 E) :
(b.to_orthonormal_basis : ι → E) = b :=
orthonormal_basis.coe_mk _ _
lemma finite_spans_dense (b : hilbert_basis ι 𝕜 E) :
(⨆ J : finset ι, span 𝕜 (J.image b : set E)).topological_closure = ⊤ :=
eq_top_iff.mpr $ b.dense_span.ge.trans
begin
simp_rw [← submodule.span_Union],
exact topological_closure_mono (span_mono $ set.range_subset_iff.mpr $
λ i, set.mem_Union_of_mem {i} $ finset.mem_coe.mpr $ finset.mem_image_of_mem _ $
finset.mem_singleton_self i)
end
variables {v : ι → E} (hv : orthonormal 𝕜 v)
include hv cplt
/-- An orthonormal family of vectors whose span is dense in the whole module is a Hilbert basis. -/
protected def mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
hilbert_basis ι 𝕜 E :=
hilbert_basis.of_repr $
(hv.is_hilbert_sum hsp).linear_isometry_equiv
lemma _root_.orthonormal.linear_isometry_equiv_symm_apply_single_one (h i) :
(hv.is_hilbert_sum h).linear_isometry_equiv.symm (lp.single 2 i 1) = v i :=
by rw [is_hilbert_sum.linear_isometry_equiv_symm_apply_single,
linear_isometry.to_span_singleton_apply, one_smul]
@[simp] protected lemma coe_mk (hsp : ⊤ ≤ (span 𝕜 (set.range v)).topological_closure) :
⇑(hilbert_basis.mk hv hsp) = v :=
by apply (funext $ orthonormal.linear_isometry_equiv_symm_apply_single_one hv hsp)
/-- An orthonormal family of vectors whose span has trivial orthogonal complement is a Hilbert
basis. -/
protected def mk_of_orthogonal_eq_bot (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : hilbert_basis ι 𝕜 E :=
hilbert_basis.mk hv
(by rw [← orthogonal_orthogonal_eq_closure, ← eq_top_iff, orthogonal_eq_top_iff, hsp])
@[simp] protected lemma coe_of_orthogonal_eq_bot_mk (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) :
⇑(hilbert_basis.mk_of_orthogonal_eq_bot hv hsp) = v :=
hilbert_basis.coe_mk hv _
omit hv
-- Note : this should be `b.repr` composed with an identification of `lp (λ i : ι, 𝕜) p` with
-- `pi_Lp p (λ i : ι, 𝕜)` (in this case with `p = 2`), but we don't have this yet (July 2022).
/-- An orthonormal basis is an Hilbert basis. -/
protected def _root_.orthonormal_basis.to_hilbert_basis [fintype ι] (b : orthonormal_basis ι 𝕜 E) :
hilbert_basis ι 𝕜 E :=
hilbert_basis.mk b.orthonormal $
by simpa only [← orthonormal_basis.coe_to_basis, b.to_basis.span_eq, eq_top_iff]
using @subset_closure E _ _
@[simp] lemma _root_.orthonormal_basis.coe_to_hilbert_basis [fintype ι]
(b : orthonormal_basis ι 𝕜 E) : (b.to_hilbert_basis : ι → E) = b :=
hilbert_basis.coe_mk _ _
/-- A Hilbert space admits a Hilbert basis extending a given orthonormal subset. -/
lemma _root_.orthonormal.exists_hilbert_basis_extension
{s : set E} (hs : orthonormal 𝕜 (coe : s → E)) :
∃ (w : set E) (b : hilbert_basis w 𝕜 E), s ⊆ w ∧ ⇑b = (coe : w → E) :=
let ⟨w, hws, hw_ortho, hw_max⟩ := exists_maximal_orthonormal hs in
⟨ w,
hilbert_basis.mk_of_orthogonal_eq_bot hw_ortho
(by simpa [maximal_orthonormal_iff_orthogonal_complement_eq_bot hw_ortho] using hw_max),
hws,
hilbert_basis.coe_of_orthogonal_eq_bot_mk _ _ ⟩
variables (𝕜 E)
/-- A Hilbert space admits a Hilbert basis. -/
lemma _root_.exists_hilbert_basis :
∃ (w : set E) (b : hilbert_basis w 𝕜 E), ⇑b = (coe : w → E) :=
let ⟨w, hw, hw', hw''⟩ := (orthonormal_empty 𝕜 E).exists_hilbert_basis_extension in ⟨w, hw, hw''⟩
end hilbert_basis
|
f82c3cda4e7ae765a8f34bff63accadc33198f95
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/algebraic_geometry/AffineScheme.lean
|
114556cb2195b4ae9598e0e50c2ebf2b700355a5
|
[
"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
| 32,380
|
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 algebraic_geometry.Gamma_Spec_adjunction
import algebraic_geometry.open_immersion
import category_theory.limits.opposites
import ring_theory.localization.inv_submonoid
/-!
# Affine schemes
We define the category of `AffineScheme`s as the essential image of `Spec`.
We also define predicates about affine schemes and affine open sets.
## Main definitions
* `algebraic_geometry.AffineScheme`: The category of affine schemes.
* `algebraic_geometry.is_affine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an
isomorphism.
* `algebraic_geometry.Scheme.iso_Spec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine
scheme.
* `algebraic_geometry.AffineScheme.equiv_CommRing`: The equivalence of categories
`AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and
`AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRing`.
* `algebraic_geometry.is_affine_open`: An open subset of a scheme is affine if the open subscheme is
affine.
* `algebraic_geometry.is_affine_open.from_Spec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`.
-/
noncomputable theory
open category_theory category_theory.limits opposite topological_space
universe u
namespace algebraic_geometry
open Spec (structure_sheaf)
/-- The category of affine schemes -/
@[derive category, nolint has_nonempty_instance]
def AffineScheme := Scheme.Spec.ess_image_subcategory
/-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/
class is_affine (X : Scheme) : Prop :=
(affine : is_iso (Γ_Spec.adjunction.unit.app X))
attribute [instance] is_affine.affine
/-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/
def Scheme.iso_Spec (X : Scheme) [is_affine X] :
X ≅ Scheme.Spec.obj (op $ Scheme.Γ.obj $ op X) :=
as_iso (Γ_Spec.adjunction.unit.app X)
/-- Construct an affine scheme from a scheme and the information that it is affine.
Also see `AffineScheme.of` for a typclass version. -/
@[simps]
def AffineScheme.mk (X : Scheme) (h : is_affine X) : AffineScheme :=
⟨X, @@mem_ess_image_of_unit_is_iso _ _ _ _ h.1⟩
/-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass
version. -/
def AffineScheme.of (X : Scheme) [h : is_affine X] : AffineScheme :=
AffineScheme.mk X h
/-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/
def AffineScheme.of_hom {X Y : Scheme} [is_affine X] [is_affine Y] (f : X ⟶ Y) :
AffineScheme.of X ⟶ AffineScheme.of Y :=
f
lemma mem_Spec_ess_image (X : Scheme) : X ∈ Scheme.Spec.ess_image ↔ is_affine X :=
⟨λ h, ⟨functor.ess_image.unit_is_iso h⟩, λ h, @@mem_ess_image_of_unit_is_iso _ _ _ X h.1⟩
instance is_affine_AffineScheme (X : AffineScheme.{u}) : is_affine X.obj :=
⟨functor.ess_image.unit_is_iso X.property⟩
instance Spec_is_affine (R : CommRingᵒᵖ) : is_affine (Scheme.Spec.obj R) :=
algebraic_geometry.is_affine_AffineScheme ⟨_, Scheme.Spec.obj_mem_ess_image R⟩
lemma is_affine_of_iso {X Y : Scheme} (f : X ⟶ Y) [is_iso f] [h : is_affine Y] :
is_affine X :=
by { rw [← mem_Spec_ess_image] at h ⊢, exact functor.ess_image.of_iso (as_iso f).symm h }
namespace AffineScheme
/-- The `Spec` functor into the category of affine schemes. -/
@[derive [full, faithful, ess_surj]]
def Spec : CommRingᵒᵖ ⥤ AffineScheme := Scheme.Spec.to_ess_image
/-- The forgetful functor `AffineScheme ⥤ Scheme`. -/
@[derive [full, faithful], simps]
def forget_to_Scheme : AffineScheme ⥤ Scheme := Scheme.Spec.ess_image_inclusion
/-- The global section functor of an affine scheme. -/
def Γ : AffineSchemeᵒᵖ ⥤ CommRing := forget_to_Scheme.op ⋙ Scheme.Γ
/-- The category of affine schemes is equivalent to the category of commutative rings. -/
def equiv_CommRing : AffineScheme ≌ CommRingᵒᵖ :=
equiv_ess_image_of_reflective.symm
instance Γ_is_equiv : is_equivalence Γ.{u} :=
begin
haveI : is_equivalence Γ.{u}.right_op.op := is_equivalence.of_equivalence equiv_CommRing.op,
exact (functor.is_equivalence_trans Γ.{u}.right_op.op (op_op_equivalence _).functor : _),
end
instance : has_colimits AffineScheme.{u} :=
begin
haveI := adjunction.has_limits_of_equivalence.{u} Γ.{u},
exactI adjunction.has_colimits_of_equivalence.{u} (op_op_equivalence AffineScheme.{u}).inverse
end
instance : has_limits AffineScheme.{u} :=
begin
haveI := adjunction.has_colimits_of_equivalence Γ.{u},
haveI : has_limits AffineScheme.{u} ᵒᵖᵒᵖ := limits.has_limits_op_of_has_colimits,
exactI adjunction.has_limits_of_equivalence (op_op_equivalence AffineScheme.{u}).inverse
end
noncomputable
instance : preserves_limits Γ.{u}.right_op :=
@@adjunction.is_equivalence_preserves_limits _ _ Γ.right_op
(is_equivalence.of_equivalence equiv_CommRing)
noncomputable
instance : preserves_limits forget_to_Scheme :=
begin
apply_with (@@preserves_limits_of_nat_iso _ _
(iso_whisker_right equiv_CommRing.unit_iso forget_to_Scheme).symm) { instances := ff },
change preserves_limits (equiv_CommRing.functor ⋙ Scheme.Spec),
apply_instance,
end
end AffineScheme
/-- An open subset of a scheme is affine if the open subscheme is affine. -/
def is_affine_open {X : Scheme} (U : opens X.carrier) : Prop :=
is_affine (X.restrict U.open_embedding)
/-- The set of affine opens as a subset of `opens X.carrier`. -/
def Scheme.affine_opens (X : Scheme) : set (opens X.carrier) :=
{ U : opens X.carrier | is_affine_open U }
lemma range_is_affine_open_of_open_immersion {X Y : Scheme} [is_affine X] (f : X ⟶ Y)
[H : is_open_immersion f] : is_affine_open f.opens_range :=
begin
refine is_affine_of_iso (is_open_immersion.iso_of_range_eq f (Y.of_restrict _) _).inv,
exact subtype.range_coe.symm,
apply_instance
end
lemma top_is_affine_open (X : Scheme) [is_affine X] : is_affine_open (⊤ : opens X.carrier) :=
begin
convert range_is_affine_open_of_open_immersion (𝟙 X),
ext1,
exact set.range_id.symm
end
instance Scheme.affine_cover_is_affine (X : Scheme) (i : X.affine_cover.J) :
is_affine (X.affine_cover.obj i) :=
algebraic_geometry.Spec_is_affine _
instance Scheme.affine_basis_cover_is_affine (X : Scheme) (i : X.affine_basis_cover.J) :
is_affine (X.affine_basis_cover.obj i) :=
algebraic_geometry.Spec_is_affine _
lemma is_basis_affine_open (X : Scheme) :
opens.is_basis X.affine_opens :=
begin
rw opens.is_basis_iff_nbhd,
rintros U x (hU : x ∈ (U : set X.carrier)),
obtain ⟨S, hS, hxS, hSU⟩ := X.affine_basis_cover_is_basis.exists_subset_of_mem_open hU U.prop,
refine ⟨⟨S, X.affine_basis_cover_is_basis.is_open hS⟩, _, hxS, hSU⟩,
rcases hS with ⟨i, rfl⟩,
exact range_is_affine_open_of_open_immersion _,
end
/-- The open immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`. -/
def is_affine_open.from_Spec {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U) :
Scheme.Spec.obj (op $ X.presheaf.obj $ op U) ⟶ X :=
begin
haveI : is_affine (X.restrict U.open_embedding) := hU,
have : U.open_embedding.is_open_map.functor.obj ⊤ = U,
{ ext1, exact set.image_univ.trans subtype.range_coe },
exact Scheme.Spec.map (X.presheaf.map (eq_to_hom this.symm).op).op ≫
(X.restrict U.open_embedding).iso_Spec.inv ≫ X.of_restrict _
end
instance is_affine_open.is_open_immersion_from_Spec {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) :
is_open_immersion hU.from_Spec :=
by { delta is_affine_open.from_Spec, apply_instance }
lemma is_affine_open.from_Spec_range {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U) :
set.range hU.from_Spec.1.base = (U : set X.carrier) :=
begin
delta is_affine_open.from_Spec,
erw [← category.assoc, Scheme.comp_val_base],
rw [coe_comp, set.range_comp, set.range_iff_surjective.mpr, set.image_univ],
exact subtype.range_coe,
rw ← Top.epi_iff_surjective,
apply_instance
end
lemma is_affine_open.from_Spec_image_top {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) :
hU.is_open_immersion_from_Spec.base_open.is_open_map.functor.obj ⊤ = U :=
by { ext1, exact set.image_univ.trans hU.from_Spec_range }
lemma is_affine_open.is_compact {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U) :
is_compact (U : set X.carrier) :=
begin
convert @is_compact.image _ _ _ _ set.univ hU.from_Spec.1.base
prime_spectrum.compact_space.1 (by continuity),
convert hU.from_Spec_range.symm,
exact set.image_univ
end
lemma is_affine_open.image_is_open_immersion {X Y : Scheme} {U : opens X.carrier}
(hU : is_affine_open U)
(f : X ⟶ Y) [H : is_open_immersion f] : is_affine_open (f.opens_functor.obj U) :=
begin
haveI : is_affine _ := hU,
convert range_is_affine_open_of_open_immersion (X.of_restrict U.open_embedding ≫ f),
ext1,
change f.1.base '' U.1 = set.range (f.1.base ∘ coe),
rw [set.range_comp, subtype.range_coe],
end
lemma is_affine_open_iff_of_is_open_immersion {X Y : Scheme} (f : X ⟶ Y) [H : is_open_immersion f]
(U : opens X.carrier) :
is_affine_open (H.open_functor.obj U) ↔ is_affine_open U :=
begin
refine ⟨λ hU, @@is_affine_of_iso _ _ hU, λ hU, hU.image_is_open_immersion f⟩,
refine (is_open_immersion.iso_of_range_eq (X.of_restrict _ ≫ f) (Y.of_restrict _) _).hom,
{ rw [Scheme.comp_val_base, coe_comp, set.range_comp],
dsimp [opens.inclusion],
rw [subtype.range_coe, subtype.range_coe],
refl },
{ apply_instance }
end
instance Scheme.quasi_compact_of_affine (X : Scheme) [is_affine X] : compact_space X.carrier :=
⟨(top_is_affine_open X).is_compact⟩
lemma is_affine_open.from_Spec_base_preimage
{X : Scheme} {U : opens X.carrier} (hU : is_affine_open U) :
(opens.map hU.from_Spec.val.base).obj U = ⊤ :=
begin
ext1,
change hU.from_Spec.1.base ⁻¹' (U : set X.carrier) = set.univ,
rw [← hU.from_Spec_range, ← set.image_univ],
exact set.preimage_image_eq _ PresheafedSpace.is_open_immersion.base_open.inj
end
lemma Scheme.Spec_map_presheaf_map_eq_to_hom {X : Scheme} {U V : opens X.carrier} (h : U = V) (W) :
(Scheme.Spec.map (X.presheaf.map (eq_to_hom h).op).op).val.c.app W =
eq_to_hom (by { cases h, dsimp, induction W using opposite.rec, congr, ext1, simpa }) :=
begin
have : Scheme.Spec.map (X.presheaf.map (𝟙 (op U))).op = 𝟙 _,
{ rw [X.presheaf.map_id, op_id, Scheme.Spec.map_id] },
cases h,
refine (Scheme.congr_app this _).trans _,
erw category.id_comp,
simpa [eq_to_hom_map],
end
lemma is_affine_open.Spec_Γ_identity_hom_app_from_Spec {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) :
(Spec_Γ_identity.hom.app (X.presheaf.obj $ op U)) ≫ hU.from_Spec.1.c.app (op U) =
(Scheme.Spec.obj _).presheaf.map (eq_to_hom hU.from_Spec_base_preimage).op :=
begin
haveI : is_affine _ := hU,
have e₁ :=
Spec_Γ_identity.hom.naturality (X.presheaf.map (eq_to_hom U.open_embedding_obj_top).op),
rw ← is_iso.comp_inv_eq at e₁,
have e₂ := Γ_Spec.adjunction_unit_app_app_top (X.restrict U.open_embedding),
erw ← e₂ at e₁,
simp only [functor.id_map, quiver.hom.unop_op, functor.comp_map, ← functor.map_inv, ← op_inv,
LocallyRingedSpace.Γ_map, category.assoc, functor.right_op_map, inv_eq_to_hom] at e₁,
delta is_affine_open.from_Spec Scheme.iso_Spec,
rw [Scheme.comp_val_c_app, Scheme.comp_val_c_app, ← e₁],
simp_rw category.assoc,
erw ← X.presheaf.map_comp_assoc,
rw ← op_comp,
have e₃ : U.open_embedding.is_open_map.adjunction.counit.app U ≫
eq_to_hom U.open_embedding_obj_top.symm =
U.open_embedding.is_open_map.functor.map (eq_to_hom U.inclusion_map_eq_top) :=
subsingleton.elim _ _,
have e₄ : X.presheaf.map _ ≫ _ = _ :=
(as_iso (Γ_Spec.adjunction.unit.app (X.restrict U.open_embedding)))
.inv.1.c.naturality_assoc (eq_to_hom U.inclusion_map_eq_top).op _,
erw [e₃, e₄, ← Scheme.comp_val_c_app_assoc, iso.inv_hom_id],
simp only [eq_to_hom_map, eq_to_hom_op, Scheme.Spec_map_presheaf_map_eq_to_hom],
erw [Scheme.Spec_map_presheaf_map_eq_to_hom, category.id_comp],
simpa only [eq_to_hom_trans]
end
@[elementwise]
lemma is_affine_open.from_Spec_app_eq {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) :
hU.from_Spec.1.c.app (op U) = Spec_Γ_identity.inv.app (X.presheaf.obj $ op U) ≫
(Scheme.Spec.obj _).presheaf.map (eq_to_hom hU.from_Spec_base_preimage).op :=
by rw [← hU.Spec_Γ_identity_hom_app_from_Spec, iso.inv_hom_id_app_assoc]
lemma is_affine_open.basic_open_is_affine {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (f : X.presheaf.obj (op U)) : is_affine_open (X.basic_open f) :=
begin
convert range_is_affine_open_of_open_immersion (Scheme.Spec.map (CommRing.of_hom
(algebra_map (X.presheaf.obj (op U)) (localization.away f))).op ≫ hU.from_Spec),
ext1,
have : hU.from_Spec.val.base '' (hU.from_Spec.val.base ⁻¹' (X.basic_open f : set X.carrier)) =
(X.basic_open f : set X.carrier),
{ rw [set.image_preimage_eq_inter_range, set.inter_eq_left_iff_subset, hU.from_Spec_range],
exact Scheme.basic_open_subset _ _ },
rw [Scheme.hom.opens_range_coe, Scheme.comp_val_base, ← this, coe_comp, set.range_comp],
congr' 1,
refine (congr_arg coe $ Scheme.preimage_basic_open hU.from_Spec f).trans _,
refine eq.trans _ (prime_spectrum.localization_away_comap_range (localization.away f) f).symm,
congr' 1,
have : (opens.map hU.from_Spec.val.base).obj U = ⊤,
{ ext1,
change hU.from_Spec.1.base ⁻¹' (U : set X.carrier) = set.univ,
rw [← hU.from_Spec_range, ← set.image_univ],
exact set.preimage_image_eq _ PresheafedSpace.is_open_immersion.base_open.inj },
refine eq.trans _ (basic_open_eq_of_affine f),
have lm : ∀ s, (opens.map hU.from_Spec.val.base).obj U ⊓ s = s := λ s, this.symm ▸ top_inf_eq,
refine eq.trans _ (lm _),
refine eq.trans _
((Scheme.Spec.obj $ op $ X.presheaf.obj $ op U).basic_open_res _ (eq_to_hom this).op),
rw ← comp_apply,
congr' 2,
rw iso.eq_inv_comp,
erw hU.Spec_Γ_identity_hom_app_from_Spec,
end
lemma is_affine_open.map_restrict_basic_open {X : Scheme} (r : X.presheaf.obj (op ⊤))
{U : opens X.carrier} (hU : is_affine_open U) :
is_affine_open ((opens.map (X.of_restrict (X.basic_open r).open_embedding).1.base).obj U) :=
begin
apply (is_affine_open_iff_of_is_open_immersion
(X.of_restrict (X.basic_open r).open_embedding) _).mp,
delta PresheafedSpace.is_open_immersion.open_functor,
dsimp,
rw [opens.functor_obj_map_obj, opens.open_embedding_obj_top, inf_comm, ← opens.inter_eq,
← Scheme.basic_open_res _ _ (hom_of_le le_top).op],
exact hU.basic_open_is_affine _,
end
lemma Scheme.map_prime_spectrum_basic_open_of_affine (X : Scheme) [is_affine X]
(f : Scheme.Γ.obj (op X)) :
(opens.map X.iso_Spec.hom.1.base).obj (prime_spectrum.basic_open f) = X.basic_open f :=
begin
rw ← basic_open_eq_of_affine,
transitivity (opens.map X.iso_Spec.hom.1.base).obj ((Scheme.Spec.obj
(op (Scheme.Γ.obj (op X)))).basic_open ((inv (X.iso_Spec.hom.1.c.app
(op ((opens.map (inv X.iso_Spec.hom).val.base).obj ⊤)))) ((X.presheaf.map (eq_to_hom _)) f))),
congr,
{ rw [← is_iso.inv_eq_inv, is_iso.inv_inv, is_iso.iso.inv_inv, nat_iso.app_hom],
erw ← Γ_Spec.adjunction_unit_app_app_top,
refl },
{ rw eq_to_hom_map, refl },
{ dsimp, congr },
{ refine (Scheme.preimage_basic_open _ _).trans _,
rw [is_iso.inv_hom_id_apply, Scheme.basic_open_res_eq] }
end
lemma is_basis_basic_open (X : Scheme) [is_affine X] :
opens.is_basis (set.range (X.basic_open : X.presheaf.obj (op ⊤) → opens X.carrier)) :=
begin
delta opens.is_basis,
convert prime_spectrum.is_basis_basic_opens.inducing
(Top.homeo_of_iso (Scheme.forget_to_Top.map_iso X.iso_Spec)).inducing using 1,
ext,
simp only [set.mem_image, exists_exists_eq_and],
split,
{ rintro ⟨_, ⟨x, rfl⟩, rfl⟩,
refine ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, _⟩,
exact congr_arg subtype.val (X.map_prime_spectrum_basic_open_of_affine x) },
{ rintro ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, rfl⟩,
refine ⟨_, ⟨x, rfl⟩, _⟩,
exact congr_arg subtype.val (X.map_prime_spectrum_basic_open_of_affine x).symm }
end
lemma is_affine_open.exists_basic_open_subset {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) {V : opens X.carrier} (x : V) (h : ↑x ∈ U) :
∃ f : X.presheaf.obj (op U), X.basic_open f ⊆ V ∧ ↑x ∈ X.basic_open f :=
begin
haveI : is_affine _ := hU,
obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ := (is_basis_basic_open (X.restrict U.open_embedding))
.exists_subset_of_mem_open _ ((opens.map U.inclusion).obj V).prop,
swap, exact ⟨x, h⟩,
have : U.open_embedding.is_open_map.functor.obj ((X.restrict U.open_embedding).basic_open r)
= X.basic_open (X.presheaf.map (eq_to_hom U.open_embedding_obj_top.symm).op r),
{ refine (Scheme.image_basic_open (X.of_restrict U.open_embedding) r).trans _,
erw ← Scheme.basic_open_res_eq _ _ (eq_to_hom U.open_embedding_obj_top).op,
rw [← comp_apply, ← category_theory.functor.map_comp, ← op_comp, eq_to_hom_trans,
eq_to_hom_refl, op_id, category_theory.functor.map_id],
erw PresheafedSpace.is_open_immersion.of_restrict_inv_app,
congr },
use X.presheaf.map (eq_to_hom U.open_embedding_obj_top.symm).op r,
rw ← this,
exact ⟨set.image_subset_iff.mpr h₂, set.mem_image_of_mem _ h₁⟩,
exact x.prop,
end
instance {X : Scheme} {U : opens X.carrier} (f : X.presheaf.obj (op U)) :
algebra (X.presheaf.obj (op U)) (X.presheaf.obj (op $ X.basic_open f)) :=
(X.presheaf.map (hom_of_le $ RingedSpace.basic_open_subset _ f : _ ⟶ U).op).to_algebra
lemma is_affine_open.opens_map_from_Spec_basic_open {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (f : X.presheaf.obj (op U)) :
(opens.map hU.from_Spec.val.base).obj (X.basic_open f) =
RingedSpace.basic_open _ (Spec_Γ_identity.inv.app (X.presheaf.obj $ op U) f) :=
begin
erw LocallyRingedSpace.preimage_basic_open,
refine eq.trans _ (RingedSpace.basic_open_res_eq (Scheme.Spec.obj $ op $ X.presheaf.obj (op U))
.to_LocallyRingedSpace.to_RingedSpace (eq_to_hom hU.from_Spec_base_preimage).op _),
congr,
rw ← comp_apply,
congr,
erw ← hU.Spec_Γ_identity_hom_app_from_Spec,
rw iso.inv_hom_id_app_assoc,
end
/-- The canonical map `Γ(𝒪ₓ, D(f)) ⟶ Γ(Spec 𝒪ₓ(U), D(Spec_Γ_identity.inv f))`
This is an isomorphism, as witnessed by an `is_iso` instance. -/
def basic_open_sections_to_affine {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U)
(f : X.presheaf.obj (op U)) : X.presheaf.obj (op $ X.basic_open f) ⟶
(Scheme.Spec.obj $ op $ X.presheaf.obj (op U)).presheaf.obj
(op $ Scheme.basic_open _ $ Spec_Γ_identity.inv.app (X.presheaf.obj (op U)) f) :=
hU.from_Spec.1.c.app (op $ X.basic_open f) ≫ (Scheme.Spec.obj $ op $ X.presheaf.obj (op U))
.presheaf.map (eq_to_hom $ (hU.opens_map_from_Spec_basic_open f).symm).op
instance {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U)
(f : X.presheaf.obj (op U)) : is_iso (basic_open_sections_to_affine hU f) :=
begin
delta basic_open_sections_to_affine,
apply_with is_iso.comp_is_iso { instances := ff },
{ apply PresheafedSpace.is_open_immersion.is_iso_of_subset,
rw hU.from_Spec_range,
exact RingedSpace.basic_open_subset _ _ },
apply_instance
end
.
lemma is_localization_basic_open {X : Scheme} {U : opens X.carrier} (hU : is_affine_open U)
(f : X.presheaf.obj (op U)) :
is_localization.away f (X.presheaf.obj (op $ X.basic_open f)) :=
begin
apply (is_localization.is_localization_iff_of_ring_equiv (submonoid.powers f)
(as_iso $ basic_open_sections_to_affine hU f ≫ (Scheme.Spec.obj _).presheaf.map
(eq_to_hom (basic_open_eq_of_affine _).symm).op).CommRing_iso_to_ring_equiv).mpr,
convert structure_sheaf.is_localization.to_basic_open _ f,
change _ ≫ (basic_open_sections_to_affine hU f ≫ _) = _,
delta basic_open_sections_to_affine,
erw ring_hom.algebra_map_to_algebra,
simp only [Scheme.comp_val_c_app, category.assoc],
erw hU.from_Spec.val.c.naturality_assoc,
rw hU.from_Spec_app_eq,
dsimp,
simp only [category.assoc, ← functor.map_comp, ← op_comp],
apply structure_sheaf.to_open_res,
end
instance {X : Scheme} [is_affine X] (r : X.presheaf.obj (op ⊤)) :
is_localization.away r (X.presheaf.obj (op $ X.basic_open r)) :=
is_localization_basic_open (top_is_affine_open X) r
lemma is_localization_of_eq_basic_open {X : Scheme} {U V : opens X.carrier} (i : V ⟶ U)
(hU : is_affine_open U) (r : X.presheaf.obj (op U)) (e : V = X.basic_open r) :
@@is_localization.away _ r (X.presheaf.obj (op V)) _ (X.presheaf.map i.op).to_algebra :=
by { subst e, convert is_localization_basic_open hU r using 3 }
instance Γ_restrict_algebra
{X : Scheme} {Y : Top} {f : Y ⟶ X.carrier} (hf : open_embedding f) :
algebra (Scheme.Γ.obj (op X)) (Scheme.Γ.obj (op $ X.restrict hf)) :=
(Scheme.Γ.map (X.of_restrict hf).op).to_algebra
instance Γ_restrict_is_localization (X : Scheme.{u}) [is_affine X] (r : Scheme.Γ.obj (op X)) :
is_localization.away r (Scheme.Γ.obj (op $ X.restrict (X.basic_open r).open_embedding)) :=
is_localization_of_eq_basic_open _ (top_is_affine_open X) r (opens.open_embedding_obj_top _)
lemma basic_open_basic_open_is_basic_open {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (f : X.presheaf.obj (op U)) (g : X.presheaf.obj (op $ X.basic_open f)) :
∃ f' : X.presheaf.obj (op U), X.basic_open f' = X.basic_open g :=
begin
haveI := is_localization_basic_open hU f,
obtain ⟨x, ⟨_, n, rfl⟩, rfl⟩ := is_localization.surj' (submonoid.powers f) g,
use f * x,
rw [algebra.smul_def, Scheme.basic_open_mul, Scheme.basic_open_mul],
erw Scheme.basic_open_res,
refine (inf_eq_left.mpr _).symm,
convert inf_le_left using 1,
apply Scheme.basic_open_of_is_unit,
apply submonoid.left_inv_le_is_unit _ (is_localization.to_inv_submonoid (submonoid.powers f)
(X.presheaf.obj (op $ X.basic_open f)) _).prop
end
lemma exists_basic_open_subset_affine_inter {X : Scheme} {U V : opens X.carrier}
(hU : is_affine_open U) (hV : is_affine_open V) (x : X.carrier) (hx : x ∈ U ∩ V) :
∃ (f : X.presheaf.obj $ op U) (g : X.presheaf.obj $ op V),
X.basic_open f = X.basic_open g ∧ x ∈ X.basic_open f :=
begin
obtain ⟨f, hf₁, hf₂⟩ := hU.exists_basic_open_subset ⟨x, hx.2⟩ hx.1,
obtain ⟨g, hg₁, hg₂⟩ := hV.exists_basic_open_subset ⟨x, hf₂⟩ hx.2,
obtain ⟨f', hf'⟩ := basic_open_basic_open_is_basic_open hU f
(X.presheaf.map (hom_of_le hf₁ : _ ⟶ V).op g),
replace hf' := (hf'.trans (RingedSpace.basic_open_res _ _ _)).trans (inf_eq_right.mpr hg₁),
exact ⟨f', g, hf', hf'.symm ▸ hg₂⟩
end
/-- The prime ideal of `𝒪ₓ(U)` corresponding to a point `x : U`. -/
noncomputable
def is_affine_open.prime_ideal_of {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (x : U) :
prime_spectrum (X.presheaf.obj $ op U) :=
((Scheme.Spec.map (X.presheaf.map (eq_to_hom $
show U.open_embedding.is_open_map.functor.obj ⊤ = U, from
opens.ext (set.image_univ.trans subtype.range_coe)).op).op).1.base
((@@Scheme.iso_Spec (X.restrict U.open_embedding) hU).hom.1.base x))
lemma is_affine_open.from_Spec_prime_ideal_of {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (x : U) :
hU.from_Spec.val.base (hU.prime_ideal_of x) = x.1 :=
begin
dsimp only [is_affine_open.from_Spec, subtype.coe_mk],
erw [← Scheme.comp_val_base_apply, ← Scheme.comp_val_base_apply],
simpa only [← functor.map_comp_assoc, ← functor.map_comp, ← op_comp, eq_to_hom_trans, op_id,
eq_to_hom_refl, category_theory.functor.map_id, category.id_comp, iso.hom_inv_id_assoc]
end
lemma is_affine_open.is_localization_stalk_aux {X : Scheme} (U : opens X.carrier)
[is_affine (X.restrict U.open_embedding)] :
(inv (Γ_Spec.adjunction.unit.app (X.restrict U.open_embedding))).1.c.app
(op ((opens.map U.inclusion).obj U)) =
X.presheaf.map (eq_to_hom $ by rw opens.inclusion_map_eq_top :
U.open_embedding.is_open_map.functor.obj ⊤ ⟶
(U.open_embedding.is_open_map.functor.obj ((opens.map U.inclusion).obj U))).op ≫
to_Spec_Γ (X.presheaf.obj $ op (U.open_embedding.is_open_map.functor.obj ⊤)) ≫
(Scheme.Spec.obj $ op $ X.presheaf.obj $ _).presheaf.map
(eq_to_hom (by { rw [opens.inclusion_map_eq_top], refl }) : unop _ ⟶ ⊤).op :=
begin
have e : (opens.map (inv (Γ_Spec.adjunction.unit.app (X.restrict U.open_embedding))).1.base).obj
((opens.map U.inclusion).obj U) = ⊤,
by { rw [opens.inclusion_map_eq_top], refl },
rw [Scheme.inv_val_c_app, is_iso.comp_inv_eq, Scheme.app_eq _ e,
Γ_Spec.adjunction_unit_app_app_top],
simp only [category.assoc, eq_to_hom_op],
erw ← functor.map_comp_assoc,
rw [eq_to_hom_trans, eq_to_hom_refl, category_theory.functor.map_id,
category.id_comp],
erw Spec_Γ_identity.inv_hom_id_app_assoc,
simp only [eq_to_hom_map, eq_to_hom_trans],
end
lemma is_affine_open.is_localization_stalk {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (x : U) :
is_localization.at_prime (X.presheaf.stalk x) (hU.prime_ideal_of x).as_ideal :=
begin
haveI : is_affine _ := hU,
haveI : nonempty U := ⟨x⟩,
rcases x with ⟨x, hx⟩,
let y := hU.prime_ideal_of ⟨x, hx⟩,
have : hU.from_Spec.val.base y = x := hU.from_Spec_prime_ideal_of ⟨x, hx⟩,
change is_localization y.as_ideal.prime_compl _,
clear_value y,
subst this,
apply (is_localization.is_localization_iff_of_ring_equiv _
(as_iso $ PresheafedSpace.stalk_map hU.from_Spec.1 y).CommRing_iso_to_ring_equiv).mpr,
convert structure_sheaf.is_localization.to_stalk _ _ using 1,
delta structure_sheaf.stalk_algebra,
congr' 1,
rw ring_hom.algebra_map_to_algebra,
refine (PresheafedSpace.stalk_map_germ hU.from_Spec.1 _ ⟨_, _⟩).trans _,
delta is_affine_open.from_Spec Scheme.iso_Spec structure_sheaf.to_stalk,
simp only [Scheme.comp_val_c_app, category.assoc],
dsimp only [functor.op, as_iso_inv, unop_op],
erw is_affine_open.is_localization_stalk_aux,
simp only [category.assoc],
conv_lhs { rw ← category.assoc },
erw [← X.presheaf.map_comp, Spec_Γ_naturality_assoc],
congr' 1,
simp only [← category.assoc],
transitivity _ ≫ (structure_sheaf (X.presheaf.obj $ op U)).presheaf.germ ⟨_, _⟩,
{ refl },
convert ((structure_sheaf (X.presheaf.obj $ op U)).presheaf.germ_res (hom_of_le le_top) ⟨_, _⟩)
using 2,
rw category.assoc,
erw nat_trans.naturality,
rw [← LocallyRingedSpace.Γ_map_op, ← LocallyRingedSpace.Γ.map_comp_assoc, ← op_comp],
erw ← Scheme.Spec.map_comp,
rw [← op_comp, ← X.presheaf.map_comp],
transitivity LocallyRingedSpace.Γ.map (quiver.hom.op $ Scheme.Spec.map
(X.presheaf.map (𝟙 (op U))).op) ≫ _,
{ congr },
simp only [category_theory.functor.map_id, op_id],
erw category_theory.functor.map_id,
rw category.id_comp,
refl
end
/-- The basic open set of a section `f` on an an affine open as an `X.affine_opens`. -/
@[simps]
def Scheme.affine_basic_open (X : Scheme) {U : X.affine_opens}
(f : X.presheaf.obj $ op U) : X.affine_opens :=
⟨X.basic_open f, U.prop.basic_open_is_affine f⟩
@[simp]
lemma is_affine_open.basic_open_from_Spec_app {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (f : X.presheaf.obj (op U)) :
@Scheme.basic_open (Scheme.Spec.obj $ op (X.presheaf.obj $ op U))
((opens.map hU.from_Spec.1.base).obj U)
(hU.from_Spec.1.c.app (op U) f) = prime_spectrum.basic_open f :=
begin
rw [← Scheme.basic_open_res_eq _ _ (eq_to_hom hU.from_Spec_base_preimage.symm).op,
basic_open_eq_of_affine', is_affine_open.from_Spec_app_eq],
congr,
rw [← comp_apply, ← comp_apply, category.assoc, ← functor.map_comp_assoc,
eq_to_hom_op, eq_to_hom_op, eq_to_hom_trans, eq_to_hom_refl, category_theory.functor.map_id,
category.id_comp, ← iso.app_inv, iso.inv_hom_id],
refl
end
lemma is_affine_open.from_Spec_map_basic_open {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (f : X.presheaf.obj (op U)) :
(opens.map hU.from_Spec.val.base).obj (X.basic_open f) = prime_spectrum.basic_open f :=
by simp
lemma is_affine_open.basic_open_union_eq_self_iff {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (s : set (X.presheaf.obj $ op U)) :
(⨆ (f : s), X.basic_open (f : X.presheaf.obj $ op U)) = U ↔ ideal.span s = ⊤ :=
begin
transitivity (⋃ (i : s), (prime_spectrum.basic_open i.1).1) = set.univ,
transitivity hU.from_Spec.1.base ⁻¹' (⨆ (f : s), X.basic_open (f : X.presheaf.obj $ op U)).1 =
hU.from_Spec.1.base ⁻¹' U.1,
{ refine ⟨λ h, by rw h, _⟩,
intro h,
apply_fun set.image hU.from_Spec.1.base at h,
rw [set.image_preimage_eq_inter_range, set.image_preimage_eq_inter_range,
hU.from_Spec_range] at h,
simp only [set.inter_self, subtype.val_eq_coe, set.inter_eq_right_iff_subset]
at h,
ext1,
refine le_antisymm _ h,
simp only [set.Union_subset_iff, set_coe.forall, opens.supr_def, set.le_eq_subset,
subtype.coe_mk],
intros x hx,
exact X.basic_open_subset x },
{ simp only [opens.supr_def, subtype.coe_mk, set.preimage_Union, subtype.val_eq_coe],
congr' 3,
{ ext1 x,
exact congr_arg subtype.val (hU.from_Spec_map_basic_open _) },
{ exact congr_arg subtype.val hU.from_Spec_base_preimage } },
{ simp only [subtype.val_eq_coe, prime_spectrum.basic_open_eq_zero_locus_compl],
rw [← set.compl_Inter, set.compl_univ_iff, ← prime_spectrum.zero_locus_Union,
← prime_spectrum.zero_locus_empty_iff_eq_top, prime_spectrum.zero_locus_span],
simp only [set.Union_singleton_eq_range, subtype.range_coe_subtype, set.set_of_mem_eq] }
end
lemma is_affine_open.self_le_basic_open_union_iff {X : Scheme} {U : opens X.carrier}
(hU : is_affine_open U) (s : set (X.presheaf.obj $ op U)) :
U ≤ (⨆ (f : s), X.basic_open (f : X.presheaf.obj $ op U)) ↔ ideal.span s = ⊤ :=
begin
rw [← hU.basic_open_union_eq_self_iff, @comm _ eq],
refine ⟨λ h, le_antisymm h _, le_of_eq⟩,
simp only [supr_le_iff, set_coe.forall],
intros x hx,
exact X.basic_open_subset x
end
/--
Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.
Then `P` holds for every affine open of `X`.
This is also known as the **Affine communication lemma** in Vakil's "The rising sea". -/
@[elab_as_eliminator]
lemma of_affine_open_cover {X : Scheme} (V : X.affine_opens) (S : set X.affine_opens)
{P : X.affine_opens → Prop}
(hP₁ : ∀ (U : X.affine_opens) (f : X.presheaf.obj $ op U.1), P U →
P (X.affine_basic_open f))
(hP₂ : ∀ (U : X.affine_opens) (s : finset (X.presheaf.obj $ op U))
(hs : ideal.span (s : set (X.presheaf.obj $ op U)) = ⊤),
(∀ (f : s), P (X.affine_basic_open f.1)) → P U)
(hS : (⋃ (i : S), i : set X.carrier) = set.univ)
(hS' : ∀ (U : S), P U) : P V :=
begin
classical,
have : ∀ (x : V), ∃ (f : X.presheaf.obj $ op V.1),
↑x ∈ (X.basic_open f) ∧ P (X.affine_basic_open f),
{ intro x,
have : ↑x ∈ (set.univ : set X.carrier) := trivial,
rw ← hS at this,
obtain ⟨W, hW⟩ := set.mem_Union.mp this,
obtain ⟨f, g, e, hf⟩ := exists_basic_open_subset_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩,
refine ⟨f, hf, _⟩,
convert hP₁ _ g (hS' W) using 1,
ext1,
exact e },
choose f hf₁ hf₂ using this,
suffices : ideal.span (set.range f) = ⊤,
{ obtain ⟨t, ht₁, ht₂⟩ := (ideal.span_eq_top_iff_finite _).mp this,
apply hP₂ V t ht₂,
rintro ⟨i, hi⟩,
obtain ⟨x, rfl⟩ := ht₁ hi,
exact hf₂ x },
rw ← V.prop.self_le_basic_open_union_iff,
intros x hx,
simp only [exists_prop, set.mem_Union, set.mem_range, set_coe.exists, opens.supr_def,
exists_exists_eq_and, opens.mem_coe, subtype.coe_mk],
refine ⟨_, hf₁ ⟨x, hx⟩⟩,
end
end algebraic_geometry
|
4e5b358e83f814f50b66a9586593f3e3cd2a4110
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/simpperf/simp1000.lean
|
9db027639bbb4fa228783ac5a2dd33aa20f8fdec
|
[
"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
| 84,599
|
lean
|
axiom f (x : Prop) : Prop
axiom g0 (x : Prop) : Prop
axiom g1 (x : Prop) : Prop
axiom g2 (x : Prop) : Prop
axiom g3 (x : Prop) : Prop
axiom g4 (x : Prop) : Prop
axiom g5 (x : Prop) : Prop
axiom g6 (x : Prop) : Prop
axiom g7 (x : Prop) : Prop
axiom g8 (x : Prop) : Prop
axiom g9 (x : Prop) : Prop
axiom g10 (x : Prop) : Prop
axiom g11 (x : Prop) : Prop
axiom g12 (x : Prop) : Prop
axiom g13 (x : Prop) : Prop
axiom g14 (x : Prop) : Prop
axiom g15 (x : Prop) : Prop
axiom g16 (x : Prop) : Prop
axiom g17 (x : Prop) : Prop
axiom g18 (x : Prop) : Prop
axiom g19 (x : Prop) : Prop
axiom g20 (x : Prop) : Prop
axiom g21 (x : Prop) : Prop
axiom g22 (x : Prop) : Prop
axiom g23 (x : Prop) : Prop
axiom g24 (x : Prop) : Prop
axiom g25 (x : Prop) : Prop
axiom g26 (x : Prop) : Prop
axiom g27 (x : Prop) : Prop
axiom g28 (x : Prop) : Prop
axiom g29 (x : Prop) : Prop
axiom g30 (x : Prop) : Prop
axiom g31 (x : Prop) : Prop
axiom g32 (x : Prop) : Prop
axiom g33 (x : Prop) : Prop
axiom g34 (x : Prop) : Prop
axiom g35 (x : Prop) : Prop
axiom g36 (x : Prop) : Prop
axiom g37 (x : Prop) : Prop
axiom g38 (x : Prop) : Prop
axiom g39 (x : Prop) : Prop
axiom g40 (x : Prop) : Prop
axiom g41 (x : Prop) : Prop
axiom g42 (x : Prop) : Prop
axiom g43 (x : Prop) : Prop
axiom g44 (x : Prop) : Prop
axiom g45 (x : Prop) : Prop
axiom g46 (x : Prop) : Prop
axiom g47 (x : Prop) : Prop
axiom g48 (x : Prop) : Prop
axiom g49 (x : Prop) : Prop
axiom g50 (x : Prop) : Prop
axiom g51 (x : Prop) : Prop
axiom g52 (x : Prop) : Prop
axiom g53 (x : Prop) : Prop
axiom g54 (x : Prop) : Prop
axiom g55 (x : Prop) : Prop
axiom g56 (x : Prop) : Prop
axiom g57 (x : Prop) : Prop
axiom g58 (x : Prop) : Prop
axiom g59 (x : Prop) : Prop
axiom g60 (x : Prop) : Prop
axiom g61 (x : Prop) : Prop
axiom g62 (x : Prop) : Prop
axiom g63 (x : Prop) : Prop
axiom g64 (x : Prop) : Prop
axiom g65 (x : Prop) : Prop
axiom g66 (x : Prop) : Prop
axiom g67 (x : Prop) : Prop
axiom g68 (x : Prop) : Prop
axiom g69 (x : Prop) : Prop
axiom g70 (x : Prop) : Prop
axiom g71 (x : Prop) : Prop
axiom g72 (x : Prop) : Prop
axiom g73 (x : Prop) : Prop
axiom g74 (x : Prop) : Prop
axiom g75 (x : Prop) : Prop
axiom g76 (x : Prop) : Prop
axiom g77 (x : Prop) : Prop
axiom g78 (x : Prop) : Prop
axiom g79 (x : Prop) : Prop
axiom g80 (x : Prop) : Prop
axiom g81 (x : Prop) : Prop
axiom g82 (x : Prop) : Prop
axiom g83 (x : Prop) : Prop
axiom g84 (x : Prop) : Prop
axiom g85 (x : Prop) : Prop
axiom g86 (x : Prop) : Prop
axiom g87 (x : Prop) : Prop
axiom g88 (x : Prop) : Prop
axiom g89 (x : Prop) : Prop
axiom g90 (x : Prop) : Prop
axiom g91 (x : Prop) : Prop
axiom g92 (x : Prop) : Prop
axiom g93 (x : Prop) : Prop
axiom g94 (x : Prop) : Prop
axiom g95 (x : Prop) : Prop
axiom g96 (x : Prop) : Prop
axiom g97 (x : Prop) : Prop
axiom g98 (x : Prop) : Prop
axiom g99 (x : Prop) : Prop
axiom g100 (x : Prop) : Prop
axiom g101 (x : Prop) : Prop
axiom g102 (x : Prop) : Prop
axiom g103 (x : Prop) : Prop
axiom g104 (x : Prop) : Prop
axiom g105 (x : Prop) : Prop
axiom g106 (x : Prop) : Prop
axiom g107 (x : Prop) : Prop
axiom g108 (x : Prop) : Prop
axiom g109 (x : Prop) : Prop
axiom g110 (x : Prop) : Prop
axiom g111 (x : Prop) : Prop
axiom g112 (x : Prop) : Prop
axiom g113 (x : Prop) : Prop
axiom g114 (x : Prop) : Prop
axiom g115 (x : Prop) : Prop
axiom g116 (x : Prop) : Prop
axiom g117 (x : Prop) : Prop
axiom g118 (x : Prop) : Prop
axiom g119 (x : Prop) : Prop
axiom g120 (x : Prop) : Prop
axiom g121 (x : Prop) : Prop
axiom g122 (x : Prop) : Prop
axiom g123 (x : Prop) : Prop
axiom g124 (x : Prop) : Prop
axiom g125 (x : Prop) : Prop
axiom g126 (x : Prop) : Prop
axiom g127 (x : Prop) : Prop
axiom g128 (x : Prop) : Prop
axiom g129 (x : Prop) : Prop
axiom g130 (x : Prop) : Prop
axiom g131 (x : Prop) : Prop
axiom g132 (x : Prop) : Prop
axiom g133 (x : Prop) : Prop
axiom g134 (x : Prop) : Prop
axiom g135 (x : Prop) : Prop
axiom g136 (x : Prop) : Prop
axiom g137 (x : Prop) : Prop
axiom g138 (x : Prop) : Prop
axiom g139 (x : Prop) : Prop
axiom g140 (x : Prop) : Prop
axiom g141 (x : Prop) : Prop
axiom g142 (x : Prop) : Prop
axiom g143 (x : Prop) : Prop
axiom g144 (x : Prop) : Prop
axiom g145 (x : Prop) : Prop
axiom g146 (x : Prop) : Prop
axiom g147 (x : Prop) : Prop
axiom g148 (x : Prop) : Prop
axiom g149 (x : Prop) : Prop
axiom g150 (x : Prop) : Prop
axiom g151 (x : Prop) : Prop
axiom g152 (x : Prop) : Prop
axiom g153 (x : Prop) : Prop
axiom g154 (x : Prop) : Prop
axiom g155 (x : Prop) : Prop
axiom g156 (x : Prop) : Prop
axiom g157 (x : Prop) : Prop
axiom g158 (x : Prop) : Prop
axiom g159 (x : Prop) : Prop
axiom g160 (x : Prop) : Prop
axiom g161 (x : Prop) : Prop
axiom g162 (x : Prop) : Prop
axiom g163 (x : Prop) : Prop
axiom g164 (x : Prop) : Prop
axiom g165 (x : Prop) : Prop
axiom g166 (x : Prop) : Prop
axiom g167 (x : Prop) : Prop
axiom g168 (x : Prop) : Prop
axiom g169 (x : Prop) : Prop
axiom g170 (x : Prop) : Prop
axiom g171 (x : Prop) : Prop
axiom g172 (x : Prop) : Prop
axiom g173 (x : Prop) : Prop
axiom g174 (x : Prop) : Prop
axiom g175 (x : Prop) : Prop
axiom g176 (x : Prop) : Prop
axiom g177 (x : Prop) : Prop
axiom g178 (x : Prop) : Prop
axiom g179 (x : Prop) : Prop
axiom g180 (x : Prop) : Prop
axiom g181 (x : Prop) : Prop
axiom g182 (x : Prop) : Prop
axiom g183 (x : Prop) : Prop
axiom g184 (x : Prop) : Prop
axiom g185 (x : Prop) : Prop
axiom g186 (x : Prop) : Prop
axiom g187 (x : Prop) : Prop
axiom g188 (x : Prop) : Prop
axiom g189 (x : Prop) : Prop
axiom g190 (x : Prop) : Prop
axiom g191 (x : Prop) : Prop
axiom g192 (x : Prop) : Prop
axiom g193 (x : Prop) : Prop
axiom g194 (x : Prop) : Prop
axiom g195 (x : Prop) : Prop
axiom g196 (x : Prop) : Prop
axiom g197 (x : Prop) : Prop
axiom g198 (x : Prop) : Prop
axiom g199 (x : Prop) : Prop
axiom g200 (x : Prop) : Prop
axiom g201 (x : Prop) : Prop
axiom g202 (x : Prop) : Prop
axiom g203 (x : Prop) : Prop
axiom g204 (x : Prop) : Prop
axiom g205 (x : Prop) : Prop
axiom g206 (x : Prop) : Prop
axiom g207 (x : Prop) : Prop
axiom g208 (x : Prop) : Prop
axiom g209 (x : Prop) : Prop
axiom g210 (x : Prop) : Prop
axiom g211 (x : Prop) : Prop
axiom g212 (x : Prop) : Prop
axiom g213 (x : Prop) : Prop
axiom g214 (x : Prop) : Prop
axiom g215 (x : Prop) : Prop
axiom g216 (x : Prop) : Prop
axiom g217 (x : Prop) : Prop
axiom g218 (x : Prop) : Prop
axiom g219 (x : Prop) : Prop
axiom g220 (x : Prop) : Prop
axiom g221 (x : Prop) : Prop
axiom g222 (x : Prop) : Prop
axiom g223 (x : Prop) : Prop
axiom g224 (x : Prop) : Prop
axiom g225 (x : Prop) : Prop
axiom g226 (x : Prop) : Prop
axiom g227 (x : Prop) : Prop
axiom g228 (x : Prop) : Prop
axiom g229 (x : Prop) : Prop
axiom g230 (x : Prop) : Prop
axiom g231 (x : Prop) : Prop
axiom g232 (x : Prop) : Prop
axiom g233 (x : Prop) : Prop
axiom g234 (x : Prop) : Prop
axiom g235 (x : Prop) : Prop
axiom g236 (x : Prop) : Prop
axiom g237 (x : Prop) : Prop
axiom g238 (x : Prop) : Prop
axiom g239 (x : Prop) : Prop
axiom g240 (x : Prop) : Prop
axiom g241 (x : Prop) : Prop
axiom g242 (x : Prop) : Prop
axiom g243 (x : Prop) : Prop
axiom g244 (x : Prop) : Prop
axiom g245 (x : Prop) : Prop
axiom g246 (x : Prop) : Prop
axiom g247 (x : Prop) : Prop
axiom g248 (x : Prop) : Prop
axiom g249 (x : Prop) : Prop
axiom g250 (x : Prop) : Prop
axiom g251 (x : Prop) : Prop
axiom g252 (x : Prop) : Prop
axiom g253 (x : Prop) : Prop
axiom g254 (x : Prop) : Prop
axiom g255 (x : Prop) : Prop
axiom g256 (x : Prop) : Prop
axiom g257 (x : Prop) : Prop
axiom g258 (x : Prop) : Prop
axiom g259 (x : Prop) : Prop
axiom g260 (x : Prop) : Prop
axiom g261 (x : Prop) : Prop
axiom g262 (x : Prop) : Prop
axiom g263 (x : Prop) : Prop
axiom g264 (x : Prop) : Prop
axiom g265 (x : Prop) : Prop
axiom g266 (x : Prop) : Prop
axiom g267 (x : Prop) : Prop
axiom g268 (x : Prop) : Prop
axiom g269 (x : Prop) : Prop
axiom g270 (x : Prop) : Prop
axiom g271 (x : Prop) : Prop
axiom g272 (x : Prop) : Prop
axiom g273 (x : Prop) : Prop
axiom g274 (x : Prop) : Prop
axiom g275 (x : Prop) : Prop
axiom g276 (x : Prop) : Prop
axiom g277 (x : Prop) : Prop
axiom g278 (x : Prop) : Prop
axiom g279 (x : Prop) : Prop
axiom g280 (x : Prop) : Prop
axiom g281 (x : Prop) : Prop
axiom g282 (x : Prop) : Prop
axiom g283 (x : Prop) : Prop
axiom g284 (x : Prop) : Prop
axiom g285 (x : Prop) : Prop
axiom g286 (x : Prop) : Prop
axiom g287 (x : Prop) : Prop
axiom g288 (x : Prop) : Prop
axiom g289 (x : Prop) : Prop
axiom g290 (x : Prop) : Prop
axiom g291 (x : Prop) : Prop
axiom g292 (x : Prop) : Prop
axiom g293 (x : Prop) : Prop
axiom g294 (x : Prop) : Prop
axiom g295 (x : Prop) : Prop
axiom g296 (x : Prop) : Prop
axiom g297 (x : Prop) : Prop
axiom g298 (x : Prop) : Prop
axiom g299 (x : Prop) : Prop
axiom g300 (x : Prop) : Prop
axiom g301 (x : Prop) : Prop
axiom g302 (x : Prop) : Prop
axiom g303 (x : Prop) : Prop
axiom g304 (x : Prop) : Prop
axiom g305 (x : Prop) : Prop
axiom g306 (x : Prop) : Prop
axiom g307 (x : Prop) : Prop
axiom g308 (x : Prop) : Prop
axiom g309 (x : Prop) : Prop
axiom g310 (x : Prop) : Prop
axiom g311 (x : Prop) : Prop
axiom g312 (x : Prop) : Prop
axiom g313 (x : Prop) : Prop
axiom g314 (x : Prop) : Prop
axiom g315 (x : Prop) : Prop
axiom g316 (x : Prop) : Prop
axiom g317 (x : Prop) : Prop
axiom g318 (x : Prop) : Prop
axiom g319 (x : Prop) : Prop
axiom g320 (x : Prop) : Prop
axiom g321 (x : Prop) : Prop
axiom g322 (x : Prop) : Prop
axiom g323 (x : Prop) : Prop
axiom g324 (x : Prop) : Prop
axiom g325 (x : Prop) : Prop
axiom g326 (x : Prop) : Prop
axiom g327 (x : Prop) : Prop
axiom g328 (x : Prop) : Prop
axiom g329 (x : Prop) : Prop
axiom g330 (x : Prop) : Prop
axiom g331 (x : Prop) : Prop
axiom g332 (x : Prop) : Prop
axiom g333 (x : Prop) : Prop
axiom g334 (x : Prop) : Prop
axiom g335 (x : Prop) : Prop
axiom g336 (x : Prop) : Prop
axiom g337 (x : Prop) : Prop
axiom g338 (x : Prop) : Prop
axiom g339 (x : Prop) : Prop
axiom g340 (x : Prop) : Prop
axiom g341 (x : Prop) : Prop
axiom g342 (x : Prop) : Prop
axiom g343 (x : Prop) : Prop
axiom g344 (x : Prop) : Prop
axiom g345 (x : Prop) : Prop
axiom g346 (x : Prop) : Prop
axiom g347 (x : Prop) : Prop
axiom g348 (x : Prop) : Prop
axiom g349 (x : Prop) : Prop
axiom g350 (x : Prop) : Prop
axiom g351 (x : Prop) : Prop
axiom g352 (x : Prop) : Prop
axiom g353 (x : Prop) : Prop
axiom g354 (x : Prop) : Prop
axiom g355 (x : Prop) : Prop
axiom g356 (x : Prop) : Prop
axiom g357 (x : Prop) : Prop
axiom g358 (x : Prop) : Prop
axiom g359 (x : Prop) : Prop
axiom g360 (x : Prop) : Prop
axiom g361 (x : Prop) : Prop
axiom g362 (x : Prop) : Prop
axiom g363 (x : Prop) : Prop
axiom g364 (x : Prop) : Prop
axiom g365 (x : Prop) : Prop
axiom g366 (x : Prop) : Prop
axiom g367 (x : Prop) : Prop
axiom g368 (x : Prop) : Prop
axiom g369 (x : Prop) : Prop
axiom g370 (x : Prop) : Prop
axiom g371 (x : Prop) : Prop
axiom g372 (x : Prop) : Prop
axiom g373 (x : Prop) : Prop
axiom g374 (x : Prop) : Prop
axiom g375 (x : Prop) : Prop
axiom g376 (x : Prop) : Prop
axiom g377 (x : Prop) : Prop
axiom g378 (x : Prop) : Prop
axiom g379 (x : Prop) : Prop
axiom g380 (x : Prop) : Prop
axiom g381 (x : Prop) : Prop
axiom g382 (x : Prop) : Prop
axiom g383 (x : Prop) : Prop
axiom g384 (x : Prop) : Prop
axiom g385 (x : Prop) : Prop
axiom g386 (x : Prop) : Prop
axiom g387 (x : Prop) : Prop
axiom g388 (x : Prop) : Prop
axiom g389 (x : Prop) : Prop
axiom g390 (x : Prop) : Prop
axiom g391 (x : Prop) : Prop
axiom g392 (x : Prop) : Prop
axiom g393 (x : Prop) : Prop
axiom g394 (x : Prop) : Prop
axiom g395 (x : Prop) : Prop
axiom g396 (x : Prop) : Prop
axiom g397 (x : Prop) : Prop
axiom g398 (x : Prop) : Prop
axiom g399 (x : Prop) : Prop
axiom g400 (x : Prop) : Prop
axiom g401 (x : Prop) : Prop
axiom g402 (x : Prop) : Prop
axiom g403 (x : Prop) : Prop
axiom g404 (x : Prop) : Prop
axiom g405 (x : Prop) : Prop
axiom g406 (x : Prop) : Prop
axiom g407 (x : Prop) : Prop
axiom g408 (x : Prop) : Prop
axiom g409 (x : Prop) : Prop
axiom g410 (x : Prop) : Prop
axiom g411 (x : Prop) : Prop
axiom g412 (x : Prop) : Prop
axiom g413 (x : Prop) : Prop
axiom g414 (x : Prop) : Prop
axiom g415 (x : Prop) : Prop
axiom g416 (x : Prop) : Prop
axiom g417 (x : Prop) : Prop
axiom g418 (x : Prop) : Prop
axiom g419 (x : Prop) : Prop
axiom g420 (x : Prop) : Prop
axiom g421 (x : Prop) : Prop
axiom g422 (x : Prop) : Prop
axiom g423 (x : Prop) : Prop
axiom g424 (x : Prop) : Prop
axiom g425 (x : Prop) : Prop
axiom g426 (x : Prop) : Prop
axiom g427 (x : Prop) : Prop
axiom g428 (x : Prop) : Prop
axiom g429 (x : Prop) : Prop
axiom g430 (x : Prop) : Prop
axiom g431 (x : Prop) : Prop
axiom g432 (x : Prop) : Prop
axiom g433 (x : Prop) : Prop
axiom g434 (x : Prop) : Prop
axiom g435 (x : Prop) : Prop
axiom g436 (x : Prop) : Prop
axiom g437 (x : Prop) : Prop
axiom g438 (x : Prop) : Prop
axiom g439 (x : Prop) : Prop
axiom g440 (x : Prop) : Prop
axiom g441 (x : Prop) : Prop
axiom g442 (x : Prop) : Prop
axiom g443 (x : Prop) : Prop
axiom g444 (x : Prop) : Prop
axiom g445 (x : Prop) : Prop
axiom g446 (x : Prop) : Prop
axiom g447 (x : Prop) : Prop
axiom g448 (x : Prop) : Prop
axiom g449 (x : Prop) : Prop
axiom g450 (x : Prop) : Prop
axiom g451 (x : Prop) : Prop
axiom g452 (x : Prop) : Prop
axiom g453 (x : Prop) : Prop
axiom g454 (x : Prop) : Prop
axiom g455 (x : Prop) : Prop
axiom g456 (x : Prop) : Prop
axiom g457 (x : Prop) : Prop
axiom g458 (x : Prop) : Prop
axiom g459 (x : Prop) : Prop
axiom g460 (x : Prop) : Prop
axiom g461 (x : Prop) : Prop
axiom g462 (x : Prop) : Prop
axiom g463 (x : Prop) : Prop
axiom g464 (x : Prop) : Prop
axiom g465 (x : Prop) : Prop
axiom g466 (x : Prop) : Prop
axiom g467 (x : Prop) : Prop
axiom g468 (x : Prop) : Prop
axiom g469 (x : Prop) : Prop
axiom g470 (x : Prop) : Prop
axiom g471 (x : Prop) : Prop
axiom g472 (x : Prop) : Prop
axiom g473 (x : Prop) : Prop
axiom g474 (x : Prop) : Prop
axiom g475 (x : Prop) : Prop
axiom g476 (x : Prop) : Prop
axiom g477 (x : Prop) : Prop
axiom g478 (x : Prop) : Prop
axiom g479 (x : Prop) : Prop
axiom g480 (x : Prop) : Prop
axiom g481 (x : Prop) : Prop
axiom g482 (x : Prop) : Prop
axiom g483 (x : Prop) : Prop
axiom g484 (x : Prop) : Prop
axiom g485 (x : Prop) : Prop
axiom g486 (x : Prop) : Prop
axiom g487 (x : Prop) : Prop
axiom g488 (x : Prop) : Prop
axiom g489 (x : Prop) : Prop
axiom g490 (x : Prop) : Prop
axiom g491 (x : Prop) : Prop
axiom g492 (x : Prop) : Prop
axiom g493 (x : Prop) : Prop
axiom g494 (x : Prop) : Prop
axiom g495 (x : Prop) : Prop
axiom g496 (x : Prop) : Prop
axiom g497 (x : Prop) : Prop
axiom g498 (x : Prop) : Prop
axiom g499 (x : Prop) : Prop
axiom g500 (x : Prop) : Prop
axiom g501 (x : Prop) : Prop
axiom g502 (x : Prop) : Prop
axiom g503 (x : Prop) : Prop
axiom g504 (x : Prop) : Prop
axiom g505 (x : Prop) : Prop
axiom g506 (x : Prop) : Prop
axiom g507 (x : Prop) : Prop
axiom g508 (x : Prop) : Prop
axiom g509 (x : Prop) : Prop
axiom g510 (x : Prop) : Prop
axiom g511 (x : Prop) : Prop
axiom g512 (x : Prop) : Prop
axiom g513 (x : Prop) : Prop
axiom g514 (x : Prop) : Prop
axiom g515 (x : Prop) : Prop
axiom g516 (x : Prop) : Prop
axiom g517 (x : Prop) : Prop
axiom g518 (x : Prop) : Prop
axiom g519 (x : Prop) : Prop
axiom g520 (x : Prop) : Prop
axiom g521 (x : Prop) : Prop
axiom g522 (x : Prop) : Prop
axiom g523 (x : Prop) : Prop
axiom g524 (x : Prop) : Prop
axiom g525 (x : Prop) : Prop
axiom g526 (x : Prop) : Prop
axiom g527 (x : Prop) : Prop
axiom g528 (x : Prop) : Prop
axiom g529 (x : Prop) : Prop
axiom g530 (x : Prop) : Prop
axiom g531 (x : Prop) : Prop
axiom g532 (x : Prop) : Prop
axiom g533 (x : Prop) : Prop
axiom g534 (x : Prop) : Prop
axiom g535 (x : Prop) : Prop
axiom g536 (x : Prop) : Prop
axiom g537 (x : Prop) : Prop
axiom g538 (x : Prop) : Prop
axiom g539 (x : Prop) : Prop
axiom g540 (x : Prop) : Prop
axiom g541 (x : Prop) : Prop
axiom g542 (x : Prop) : Prop
axiom g543 (x : Prop) : Prop
axiom g544 (x : Prop) : Prop
axiom g545 (x : Prop) : Prop
axiom g546 (x : Prop) : Prop
axiom g547 (x : Prop) : Prop
axiom g548 (x : Prop) : Prop
axiom g549 (x : Prop) : Prop
axiom g550 (x : Prop) : Prop
axiom g551 (x : Prop) : Prop
axiom g552 (x : Prop) : Prop
axiom g553 (x : Prop) : Prop
axiom g554 (x : Prop) : Prop
axiom g555 (x : Prop) : Prop
axiom g556 (x : Prop) : Prop
axiom g557 (x : Prop) : Prop
axiom g558 (x : Prop) : Prop
axiom g559 (x : Prop) : Prop
axiom g560 (x : Prop) : Prop
axiom g561 (x : Prop) : Prop
axiom g562 (x : Prop) : Prop
axiom g563 (x : Prop) : Prop
axiom g564 (x : Prop) : Prop
axiom g565 (x : Prop) : Prop
axiom g566 (x : Prop) : Prop
axiom g567 (x : Prop) : Prop
axiom g568 (x : Prop) : Prop
axiom g569 (x : Prop) : Prop
axiom g570 (x : Prop) : Prop
axiom g571 (x : Prop) : Prop
axiom g572 (x : Prop) : Prop
axiom g573 (x : Prop) : Prop
axiom g574 (x : Prop) : Prop
axiom g575 (x : Prop) : Prop
axiom g576 (x : Prop) : Prop
axiom g577 (x : Prop) : Prop
axiom g578 (x : Prop) : Prop
axiom g579 (x : Prop) : Prop
axiom g580 (x : Prop) : Prop
axiom g581 (x : Prop) : Prop
axiom g582 (x : Prop) : Prop
axiom g583 (x : Prop) : Prop
axiom g584 (x : Prop) : Prop
axiom g585 (x : Prop) : Prop
axiom g586 (x : Prop) : Prop
axiom g587 (x : Prop) : Prop
axiom g588 (x : Prop) : Prop
axiom g589 (x : Prop) : Prop
axiom g590 (x : Prop) : Prop
axiom g591 (x : Prop) : Prop
axiom g592 (x : Prop) : Prop
axiom g593 (x : Prop) : Prop
axiom g594 (x : Prop) : Prop
axiom g595 (x : Prop) : Prop
axiom g596 (x : Prop) : Prop
axiom g597 (x : Prop) : Prop
axiom g598 (x : Prop) : Prop
axiom g599 (x : Prop) : Prop
axiom g600 (x : Prop) : Prop
axiom g601 (x : Prop) : Prop
axiom g602 (x : Prop) : Prop
axiom g603 (x : Prop) : Prop
axiom g604 (x : Prop) : Prop
axiom g605 (x : Prop) : Prop
axiom g606 (x : Prop) : Prop
axiom g607 (x : Prop) : Prop
axiom g608 (x : Prop) : Prop
axiom g609 (x : Prop) : Prop
axiom g610 (x : Prop) : Prop
axiom g611 (x : Prop) : Prop
axiom g612 (x : Prop) : Prop
axiom g613 (x : Prop) : Prop
axiom g614 (x : Prop) : Prop
axiom g615 (x : Prop) : Prop
axiom g616 (x : Prop) : Prop
axiom g617 (x : Prop) : Prop
axiom g618 (x : Prop) : Prop
axiom g619 (x : Prop) : Prop
axiom g620 (x : Prop) : Prop
axiom g621 (x : Prop) : Prop
axiom g622 (x : Prop) : Prop
axiom g623 (x : Prop) : Prop
axiom g624 (x : Prop) : Prop
axiom g625 (x : Prop) : Prop
axiom g626 (x : Prop) : Prop
axiom g627 (x : Prop) : Prop
axiom g628 (x : Prop) : Prop
axiom g629 (x : Prop) : Prop
axiom g630 (x : Prop) : Prop
axiom g631 (x : Prop) : Prop
axiom g632 (x : Prop) : Prop
axiom g633 (x : Prop) : Prop
axiom g634 (x : Prop) : Prop
axiom g635 (x : Prop) : Prop
axiom g636 (x : Prop) : Prop
axiom g637 (x : Prop) : Prop
axiom g638 (x : Prop) : Prop
axiom g639 (x : Prop) : Prop
axiom g640 (x : Prop) : Prop
axiom g641 (x : Prop) : Prop
axiom g642 (x : Prop) : Prop
axiom g643 (x : Prop) : Prop
axiom g644 (x : Prop) : Prop
axiom g645 (x : Prop) : Prop
axiom g646 (x : Prop) : Prop
axiom g647 (x : Prop) : Prop
axiom g648 (x : Prop) : Prop
axiom g649 (x : Prop) : Prop
axiom g650 (x : Prop) : Prop
axiom g651 (x : Prop) : Prop
axiom g652 (x : Prop) : Prop
axiom g653 (x : Prop) : Prop
axiom g654 (x : Prop) : Prop
axiom g655 (x : Prop) : Prop
axiom g656 (x : Prop) : Prop
axiom g657 (x : Prop) : Prop
axiom g658 (x : Prop) : Prop
axiom g659 (x : Prop) : Prop
axiom g660 (x : Prop) : Prop
axiom g661 (x : Prop) : Prop
axiom g662 (x : Prop) : Prop
axiom g663 (x : Prop) : Prop
axiom g664 (x : Prop) : Prop
axiom g665 (x : Prop) : Prop
axiom g666 (x : Prop) : Prop
axiom g667 (x : Prop) : Prop
axiom g668 (x : Prop) : Prop
axiom g669 (x : Prop) : Prop
axiom g670 (x : Prop) : Prop
axiom g671 (x : Prop) : Prop
axiom g672 (x : Prop) : Prop
axiom g673 (x : Prop) : Prop
axiom g674 (x : Prop) : Prop
axiom g675 (x : Prop) : Prop
axiom g676 (x : Prop) : Prop
axiom g677 (x : Prop) : Prop
axiom g678 (x : Prop) : Prop
axiom g679 (x : Prop) : Prop
axiom g680 (x : Prop) : Prop
axiom g681 (x : Prop) : Prop
axiom g682 (x : Prop) : Prop
axiom g683 (x : Prop) : Prop
axiom g684 (x : Prop) : Prop
axiom g685 (x : Prop) : Prop
axiom g686 (x : Prop) : Prop
axiom g687 (x : Prop) : Prop
axiom g688 (x : Prop) : Prop
axiom g689 (x : Prop) : Prop
axiom g690 (x : Prop) : Prop
axiom g691 (x : Prop) : Prop
axiom g692 (x : Prop) : Prop
axiom g693 (x : Prop) : Prop
axiom g694 (x : Prop) : Prop
axiom g695 (x : Prop) : Prop
axiom g696 (x : Prop) : Prop
axiom g697 (x : Prop) : Prop
axiom g698 (x : Prop) : Prop
axiom g699 (x : Prop) : Prop
axiom g700 (x : Prop) : Prop
axiom g701 (x : Prop) : Prop
axiom g702 (x : Prop) : Prop
axiom g703 (x : Prop) : Prop
axiom g704 (x : Prop) : Prop
axiom g705 (x : Prop) : Prop
axiom g706 (x : Prop) : Prop
axiom g707 (x : Prop) : Prop
axiom g708 (x : Prop) : Prop
axiom g709 (x : Prop) : Prop
axiom g710 (x : Prop) : Prop
axiom g711 (x : Prop) : Prop
axiom g712 (x : Prop) : Prop
axiom g713 (x : Prop) : Prop
axiom g714 (x : Prop) : Prop
axiom g715 (x : Prop) : Prop
axiom g716 (x : Prop) : Prop
axiom g717 (x : Prop) : Prop
axiom g718 (x : Prop) : Prop
axiom g719 (x : Prop) : Prop
axiom g720 (x : Prop) : Prop
axiom g721 (x : Prop) : Prop
axiom g722 (x : Prop) : Prop
axiom g723 (x : Prop) : Prop
axiom g724 (x : Prop) : Prop
axiom g725 (x : Prop) : Prop
axiom g726 (x : Prop) : Prop
axiom g727 (x : Prop) : Prop
axiom g728 (x : Prop) : Prop
axiom g729 (x : Prop) : Prop
axiom g730 (x : Prop) : Prop
axiom g731 (x : Prop) : Prop
axiom g732 (x : Prop) : Prop
axiom g733 (x : Prop) : Prop
axiom g734 (x : Prop) : Prop
axiom g735 (x : Prop) : Prop
axiom g736 (x : Prop) : Prop
axiom g737 (x : Prop) : Prop
axiom g738 (x : Prop) : Prop
axiom g739 (x : Prop) : Prop
axiom g740 (x : Prop) : Prop
axiom g741 (x : Prop) : Prop
axiom g742 (x : Prop) : Prop
axiom g743 (x : Prop) : Prop
axiom g744 (x : Prop) : Prop
axiom g745 (x : Prop) : Prop
axiom g746 (x : Prop) : Prop
axiom g747 (x : Prop) : Prop
axiom g748 (x : Prop) : Prop
axiom g749 (x : Prop) : Prop
axiom g750 (x : Prop) : Prop
axiom g751 (x : Prop) : Prop
axiom g752 (x : Prop) : Prop
axiom g753 (x : Prop) : Prop
axiom g754 (x : Prop) : Prop
axiom g755 (x : Prop) : Prop
axiom g756 (x : Prop) : Prop
axiom g757 (x : Prop) : Prop
axiom g758 (x : Prop) : Prop
axiom g759 (x : Prop) : Prop
axiom g760 (x : Prop) : Prop
axiom g761 (x : Prop) : Prop
axiom g762 (x : Prop) : Prop
axiom g763 (x : Prop) : Prop
axiom g764 (x : Prop) : Prop
axiom g765 (x : Prop) : Prop
axiom g766 (x : Prop) : Prop
axiom g767 (x : Prop) : Prop
axiom g768 (x : Prop) : Prop
axiom g769 (x : Prop) : Prop
axiom g770 (x : Prop) : Prop
axiom g771 (x : Prop) : Prop
axiom g772 (x : Prop) : Prop
axiom g773 (x : Prop) : Prop
axiom g774 (x : Prop) : Prop
axiom g775 (x : Prop) : Prop
axiom g776 (x : Prop) : Prop
axiom g777 (x : Prop) : Prop
axiom g778 (x : Prop) : Prop
axiom g779 (x : Prop) : Prop
axiom g780 (x : Prop) : Prop
axiom g781 (x : Prop) : Prop
axiom g782 (x : Prop) : Prop
axiom g783 (x : Prop) : Prop
axiom g784 (x : Prop) : Prop
axiom g785 (x : Prop) : Prop
axiom g786 (x : Prop) : Prop
axiom g787 (x : Prop) : Prop
axiom g788 (x : Prop) : Prop
axiom g789 (x : Prop) : Prop
axiom g790 (x : Prop) : Prop
axiom g791 (x : Prop) : Prop
axiom g792 (x : Prop) : Prop
axiom g793 (x : Prop) : Prop
axiom g794 (x : Prop) : Prop
axiom g795 (x : Prop) : Prop
axiom g796 (x : Prop) : Prop
axiom g797 (x : Prop) : Prop
axiom g798 (x : Prop) : Prop
axiom g799 (x : Prop) : Prop
axiom g800 (x : Prop) : Prop
axiom g801 (x : Prop) : Prop
axiom g802 (x : Prop) : Prop
axiom g803 (x : Prop) : Prop
axiom g804 (x : Prop) : Prop
axiom g805 (x : Prop) : Prop
axiom g806 (x : Prop) : Prop
axiom g807 (x : Prop) : Prop
axiom g808 (x : Prop) : Prop
axiom g809 (x : Prop) : Prop
axiom g810 (x : Prop) : Prop
axiom g811 (x : Prop) : Prop
axiom g812 (x : Prop) : Prop
axiom g813 (x : Prop) : Prop
axiom g814 (x : Prop) : Prop
axiom g815 (x : Prop) : Prop
axiom g816 (x : Prop) : Prop
axiom g817 (x : Prop) : Prop
axiom g818 (x : Prop) : Prop
axiom g819 (x : Prop) : Prop
axiom g820 (x : Prop) : Prop
axiom g821 (x : Prop) : Prop
axiom g822 (x : Prop) : Prop
axiom g823 (x : Prop) : Prop
axiom g824 (x : Prop) : Prop
axiom g825 (x : Prop) : Prop
axiom g826 (x : Prop) : Prop
axiom g827 (x : Prop) : Prop
axiom g828 (x : Prop) : Prop
axiom g829 (x : Prop) : Prop
axiom g830 (x : Prop) : Prop
axiom g831 (x : Prop) : Prop
axiom g832 (x : Prop) : Prop
axiom g833 (x : Prop) : Prop
axiom g834 (x : Prop) : Prop
axiom g835 (x : Prop) : Prop
axiom g836 (x : Prop) : Prop
axiom g837 (x : Prop) : Prop
axiom g838 (x : Prop) : Prop
axiom g839 (x : Prop) : Prop
axiom g840 (x : Prop) : Prop
axiom g841 (x : Prop) : Prop
axiom g842 (x : Prop) : Prop
axiom g843 (x : Prop) : Prop
axiom g844 (x : Prop) : Prop
axiom g845 (x : Prop) : Prop
axiom g846 (x : Prop) : Prop
axiom g847 (x : Prop) : Prop
axiom g848 (x : Prop) : Prop
axiom g849 (x : Prop) : Prop
axiom g850 (x : Prop) : Prop
axiom g851 (x : Prop) : Prop
axiom g852 (x : Prop) : Prop
axiom g853 (x : Prop) : Prop
axiom g854 (x : Prop) : Prop
axiom g855 (x : Prop) : Prop
axiom g856 (x : Prop) : Prop
axiom g857 (x : Prop) : Prop
axiom g858 (x : Prop) : Prop
axiom g859 (x : Prop) : Prop
axiom g860 (x : Prop) : Prop
axiom g861 (x : Prop) : Prop
axiom g862 (x : Prop) : Prop
axiom g863 (x : Prop) : Prop
axiom g864 (x : Prop) : Prop
axiom g865 (x : Prop) : Prop
axiom g866 (x : Prop) : Prop
axiom g867 (x : Prop) : Prop
axiom g868 (x : Prop) : Prop
axiom g869 (x : Prop) : Prop
axiom g870 (x : Prop) : Prop
axiom g871 (x : Prop) : Prop
axiom g872 (x : Prop) : Prop
axiom g873 (x : Prop) : Prop
axiom g874 (x : Prop) : Prop
axiom g875 (x : Prop) : Prop
axiom g876 (x : Prop) : Prop
axiom g877 (x : Prop) : Prop
axiom g878 (x : Prop) : Prop
axiom g879 (x : Prop) : Prop
axiom g880 (x : Prop) : Prop
axiom g881 (x : Prop) : Prop
axiom g882 (x : Prop) : Prop
axiom g883 (x : Prop) : Prop
axiom g884 (x : Prop) : Prop
axiom g885 (x : Prop) : Prop
axiom g886 (x : Prop) : Prop
axiom g887 (x : Prop) : Prop
axiom g888 (x : Prop) : Prop
axiom g889 (x : Prop) : Prop
axiom g890 (x : Prop) : Prop
axiom g891 (x : Prop) : Prop
axiom g892 (x : Prop) : Prop
axiom g893 (x : Prop) : Prop
axiom g894 (x : Prop) : Prop
axiom g895 (x : Prop) : Prop
axiom g896 (x : Prop) : Prop
axiom g897 (x : Prop) : Prop
axiom g898 (x : Prop) : Prop
axiom g899 (x : Prop) : Prop
axiom g900 (x : Prop) : Prop
axiom g901 (x : Prop) : Prop
axiom g902 (x : Prop) : Prop
axiom g903 (x : Prop) : Prop
axiom g904 (x : Prop) : Prop
axiom g905 (x : Prop) : Prop
axiom g906 (x : Prop) : Prop
axiom g907 (x : Prop) : Prop
axiom g908 (x : Prop) : Prop
axiom g909 (x : Prop) : Prop
axiom g910 (x : Prop) : Prop
axiom g911 (x : Prop) : Prop
axiom g912 (x : Prop) : Prop
axiom g913 (x : Prop) : Prop
axiom g914 (x : Prop) : Prop
axiom g915 (x : Prop) : Prop
axiom g916 (x : Prop) : Prop
axiom g917 (x : Prop) : Prop
axiom g918 (x : Prop) : Prop
axiom g919 (x : Prop) : Prop
axiom g920 (x : Prop) : Prop
axiom g921 (x : Prop) : Prop
axiom g922 (x : Prop) : Prop
axiom g923 (x : Prop) : Prop
axiom g924 (x : Prop) : Prop
axiom g925 (x : Prop) : Prop
axiom g926 (x : Prop) : Prop
axiom g927 (x : Prop) : Prop
axiom g928 (x : Prop) : Prop
axiom g929 (x : Prop) : Prop
axiom g930 (x : Prop) : Prop
axiom g931 (x : Prop) : Prop
axiom g932 (x : Prop) : Prop
axiom g933 (x : Prop) : Prop
axiom g934 (x : Prop) : Prop
axiom g935 (x : Prop) : Prop
axiom g936 (x : Prop) : Prop
axiom g937 (x : Prop) : Prop
axiom g938 (x : Prop) : Prop
axiom g939 (x : Prop) : Prop
axiom g940 (x : Prop) : Prop
axiom g941 (x : Prop) : Prop
axiom g942 (x : Prop) : Prop
axiom g943 (x : Prop) : Prop
axiom g944 (x : Prop) : Prop
axiom g945 (x : Prop) : Prop
axiom g946 (x : Prop) : Prop
axiom g947 (x : Prop) : Prop
axiom g948 (x : Prop) : Prop
axiom g949 (x : Prop) : Prop
axiom g950 (x : Prop) : Prop
axiom g951 (x : Prop) : Prop
axiom g952 (x : Prop) : Prop
axiom g953 (x : Prop) : Prop
axiom g954 (x : Prop) : Prop
axiom g955 (x : Prop) : Prop
axiom g956 (x : Prop) : Prop
axiom g957 (x : Prop) : Prop
axiom g958 (x : Prop) : Prop
axiom g959 (x : Prop) : Prop
axiom g960 (x : Prop) : Prop
axiom g961 (x : Prop) : Prop
axiom g962 (x : Prop) : Prop
axiom g963 (x : Prop) : Prop
axiom g964 (x : Prop) : Prop
axiom g965 (x : Prop) : Prop
axiom g966 (x : Prop) : Prop
axiom g967 (x : Prop) : Prop
axiom g968 (x : Prop) : Prop
axiom g969 (x : Prop) : Prop
axiom g970 (x : Prop) : Prop
axiom g971 (x : Prop) : Prop
axiom g972 (x : Prop) : Prop
axiom g973 (x : Prop) : Prop
axiom g974 (x : Prop) : Prop
axiom g975 (x : Prop) : Prop
axiom g976 (x : Prop) : Prop
axiom g977 (x : Prop) : Prop
axiom g978 (x : Prop) : Prop
axiom g979 (x : Prop) : Prop
axiom g980 (x : Prop) : Prop
axiom g981 (x : Prop) : Prop
axiom g982 (x : Prop) : Prop
axiom g983 (x : Prop) : Prop
axiom g984 (x : Prop) : Prop
axiom g985 (x : Prop) : Prop
axiom g986 (x : Prop) : Prop
axiom g987 (x : Prop) : Prop
axiom g988 (x : Prop) : Prop
axiom g989 (x : Prop) : Prop
axiom g990 (x : Prop) : Prop
axiom g991 (x : Prop) : Prop
axiom g992 (x : Prop) : Prop
axiom g993 (x : Prop) : Prop
axiom g994 (x : Prop) : Prop
axiom g995 (x : Prop) : Prop
axiom g996 (x : Prop) : Prop
axiom g997 (x : Prop) : Prop
axiom g998 (x : Prop) : Prop
axiom g999 (x : Prop) : Prop
@[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x)
@[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x)
@[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x)
@[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x)
@[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x)
@[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x)
@[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x)
@[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x)
@[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x)
@[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x)
@[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x)
@[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x)
@[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x)
@[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x)
@[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x)
@[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x)
@[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x)
@[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x)
@[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x)
@[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x)
@[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x)
@[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x)
@[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x)
@[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x)
@[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x)
@[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x)
@[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x)
@[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x)
@[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x)
@[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x)
@[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x)
@[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x)
@[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x)
@[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x)
@[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x)
@[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x)
@[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x)
@[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x)
@[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x)
@[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x)
@[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x)
@[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x)
@[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x)
@[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x)
@[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x)
@[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x)
@[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x)
@[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x)
@[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x)
@[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x)
@[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x)
@[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x)
@[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x)
@[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x)
@[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x)
@[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x)
@[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x)
@[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x)
@[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x)
@[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x)
@[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x)
@[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x)
@[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x)
@[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x)
@[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x)
@[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x)
@[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x)
@[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x)
@[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x)
@[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x)
@[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x)
@[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x)
@[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x)
@[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x)
@[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x)
@[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x)
@[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x)
@[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x)
@[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x)
@[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x)
@[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x)
@[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x)
@[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x)
@[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x)
@[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x)
@[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x)
@[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x)
@[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x)
@[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x)
@[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x)
@[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x)
@[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x)
@[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x)
@[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x)
@[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x)
@[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x)
@[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x)
@[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x)
@[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x)
@[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x)
@[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x)
@[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x)
@[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x)
@[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x)
@[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x)
@[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x)
@[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x)
@[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x)
@[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x)
@[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x)
@[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x)
@[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x)
@[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x)
@[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x)
@[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x)
@[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x)
@[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x)
@[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x)
@[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x)
@[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x)
@[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x)
@[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x)
@[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x)
@[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x)
@[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x)
@[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x)
@[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x)
@[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x)
@[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x)
@[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x)
@[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x)
@[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x)
@[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x)
@[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x)
@[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x)
@[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x)
@[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x)
@[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x)
@[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x)
@[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x)
@[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x)
@[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x)
@[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x)
@[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x)
@[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x)
@[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x)
@[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x)
@[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x)
@[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x)
@[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x)
@[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x)
@[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x)
@[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x)
@[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x)
@[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x)
@[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x)
@[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x)
@[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x)
@[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x)
@[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x)
@[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x)
@[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x)
@[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x)
@[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x)
@[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x)
@[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x)
@[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x)
@[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x)
@[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x)
@[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x)
@[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x)
@[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x)
@[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x)
@[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x)
@[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x)
@[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x)
@[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x)
@[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x)
@[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x)
@[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x)
@[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x)
@[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x)
@[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x)
@[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x)
@[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x)
@[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x)
@[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x)
@[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x)
@[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x)
@[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x)
@[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x)
@[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x)
@[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x)
@[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x)
@[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x)
@[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x)
@[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x)
@[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x)
@[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x)
@[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x)
@[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x)
@[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x)
@[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x)
@[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x)
@[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x)
@[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x)
@[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x)
@[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x)
@[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x)
@[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x)
@[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x)
@[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x)
@[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x)
@[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x)
@[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x)
@[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x)
@[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x)
@[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x)
@[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x)
@[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x)
@[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x)
@[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x)
@[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x)
@[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x)
@[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x)
@[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x)
@[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x)
@[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x)
@[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x)
@[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x)
@[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x)
@[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x)
@[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x)
@[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x)
@[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x)
@[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x)
@[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x)
@[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x)
@[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x)
@[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x)
@[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x)
@[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x)
@[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x)
@[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x)
@[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x)
@[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x)
@[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x)
@[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x)
@[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x)
@[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x)
@[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x)
@[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x)
@[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x)
@[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x)
@[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x)
@[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x)
@[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x)
@[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x)
@[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x)
@[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x)
@[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x)
@[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x)
@[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x)
@[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x)
@[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x)
@[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x)
@[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x)
@[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x)
@[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x)
@[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x)
@[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x)
@[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x)
@[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x)
@[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x)
@[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x)
@[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x)
@[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x)
@[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x)
@[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x)
@[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x)
@[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x)
@[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x)
@[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x)
@[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x)
@[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x)
@[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x)
@[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x)
@[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x)
@[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x)
@[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x)
@[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x)
@[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x)
@[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x)
@[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x)
@[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x)
@[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x)
@[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x)
@[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x)
@[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x)
@[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x)
@[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x)
@[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x)
@[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x)
@[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x)
@[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x)
@[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x)
@[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x)
@[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x)
@[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x)
@[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x)
@[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x)
@[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x)
@[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x)
@[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x)
@[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x)
@[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x)
@[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x)
@[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x)
@[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x)
@[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x)
@[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x)
@[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x)
@[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x)
@[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x)
@[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x)
@[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x)
@[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x)
@[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x)
@[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x)
@[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x)
@[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x)
@[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x)
@[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x)
@[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x)
@[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x)
@[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x)
@[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x)
@[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x)
@[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x)
@[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x)
@[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x)
@[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x)
@[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x)
@[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x)
@[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x)
@[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x)
@[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x)
@[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x)
@[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x)
@[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x)
@[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x)
@[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x)
@[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x)
@[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x)
@[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x)
@[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x)
@[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x)
@[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x)
@[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x)
@[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x)
@[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x)
@[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x)
@[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x)
@[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x)
@[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x)
@[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x)
@[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x)
@[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x)
@[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x)
@[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x)
@[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x)
@[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x)
@[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x)
@[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x)
@[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x)
@[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x)
@[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x)
@[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x)
@[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x)
@[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x)
@[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x)
@[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x)
@[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x)
@[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x)
@[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x)
@[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x)
@[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x)
@[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x)
@[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x)
@[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x)
@[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x)
@[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x)
@[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x)
@[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x)
@[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x)
@[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x)
@[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x)
@[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x)
@[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x)
@[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x)
@[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x)
@[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x)
@[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x)
@[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x)
@[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x)
@[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x)
@[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x)
@[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x)
@[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x)
@[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x)
@[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x)
@[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x)
@[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x)
@[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x)
@[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x)
@[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x)
@[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x)
@[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x)
@[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x)
@[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x)
@[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x)
@[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x)
@[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x)
@[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x)
@[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x)
@[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x)
@[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x)
@[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x)
@[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x)
@[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x)
@[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x)
@[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x)
@[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x)
@[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x)
@[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x)
@[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x)
@[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x)
@[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x)
@[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x)
@[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x)
@[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x)
@[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x)
@[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x)
@[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x)
@[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x)
@[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x)
@[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x)
@[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x)
@[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x)
@[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x)
@[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x)
@[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x)
@[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x)
@[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x)
@[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x)
@[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x)
@[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x)
@[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x)
@[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x)
@[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x)
@[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x)
@[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x)
@[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x)
@[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x)
@[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x)
@[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x)
@[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x)
@[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x)
@[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x)
@[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x)
@[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x)
@[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x)
@[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x)
@[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x)
@[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x)
@[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x)
@[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x)
@[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x)
@[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x)
@[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x)
@[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x)
@[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x)
@[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x)
@[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x)
@[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x)
@[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x)
@[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x)
@[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x)
@[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x)
@[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x)
@[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x)
@[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x)
@[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x)
@[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x)
@[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x)
@[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x)
@[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x)
@[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x)
@[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x)
@[simp] axiom s499 (x : Prop) : f (g500 x) = f (g499 x)
@[simp] axiom s500 (x : Prop) : f (g501 x) = f (g500 x)
@[simp] axiom s501 (x : Prop) : f (g502 x) = f (g501 x)
@[simp] axiom s502 (x : Prop) : f (g503 x) = f (g502 x)
@[simp] axiom s503 (x : Prop) : f (g504 x) = f (g503 x)
@[simp] axiom s504 (x : Prop) : f (g505 x) = f (g504 x)
@[simp] axiom s505 (x : Prop) : f (g506 x) = f (g505 x)
@[simp] axiom s506 (x : Prop) : f (g507 x) = f (g506 x)
@[simp] axiom s507 (x : Prop) : f (g508 x) = f (g507 x)
@[simp] axiom s508 (x : Prop) : f (g509 x) = f (g508 x)
@[simp] axiom s509 (x : Prop) : f (g510 x) = f (g509 x)
@[simp] axiom s510 (x : Prop) : f (g511 x) = f (g510 x)
@[simp] axiom s511 (x : Prop) : f (g512 x) = f (g511 x)
@[simp] axiom s512 (x : Prop) : f (g513 x) = f (g512 x)
@[simp] axiom s513 (x : Prop) : f (g514 x) = f (g513 x)
@[simp] axiom s514 (x : Prop) : f (g515 x) = f (g514 x)
@[simp] axiom s515 (x : Prop) : f (g516 x) = f (g515 x)
@[simp] axiom s516 (x : Prop) : f (g517 x) = f (g516 x)
@[simp] axiom s517 (x : Prop) : f (g518 x) = f (g517 x)
@[simp] axiom s518 (x : Prop) : f (g519 x) = f (g518 x)
@[simp] axiom s519 (x : Prop) : f (g520 x) = f (g519 x)
@[simp] axiom s520 (x : Prop) : f (g521 x) = f (g520 x)
@[simp] axiom s521 (x : Prop) : f (g522 x) = f (g521 x)
@[simp] axiom s522 (x : Prop) : f (g523 x) = f (g522 x)
@[simp] axiom s523 (x : Prop) : f (g524 x) = f (g523 x)
@[simp] axiom s524 (x : Prop) : f (g525 x) = f (g524 x)
@[simp] axiom s525 (x : Prop) : f (g526 x) = f (g525 x)
@[simp] axiom s526 (x : Prop) : f (g527 x) = f (g526 x)
@[simp] axiom s527 (x : Prop) : f (g528 x) = f (g527 x)
@[simp] axiom s528 (x : Prop) : f (g529 x) = f (g528 x)
@[simp] axiom s529 (x : Prop) : f (g530 x) = f (g529 x)
@[simp] axiom s530 (x : Prop) : f (g531 x) = f (g530 x)
@[simp] axiom s531 (x : Prop) : f (g532 x) = f (g531 x)
@[simp] axiom s532 (x : Prop) : f (g533 x) = f (g532 x)
@[simp] axiom s533 (x : Prop) : f (g534 x) = f (g533 x)
@[simp] axiom s534 (x : Prop) : f (g535 x) = f (g534 x)
@[simp] axiom s535 (x : Prop) : f (g536 x) = f (g535 x)
@[simp] axiom s536 (x : Prop) : f (g537 x) = f (g536 x)
@[simp] axiom s537 (x : Prop) : f (g538 x) = f (g537 x)
@[simp] axiom s538 (x : Prop) : f (g539 x) = f (g538 x)
@[simp] axiom s539 (x : Prop) : f (g540 x) = f (g539 x)
@[simp] axiom s540 (x : Prop) : f (g541 x) = f (g540 x)
@[simp] axiom s541 (x : Prop) : f (g542 x) = f (g541 x)
@[simp] axiom s542 (x : Prop) : f (g543 x) = f (g542 x)
@[simp] axiom s543 (x : Prop) : f (g544 x) = f (g543 x)
@[simp] axiom s544 (x : Prop) : f (g545 x) = f (g544 x)
@[simp] axiom s545 (x : Prop) : f (g546 x) = f (g545 x)
@[simp] axiom s546 (x : Prop) : f (g547 x) = f (g546 x)
@[simp] axiom s547 (x : Prop) : f (g548 x) = f (g547 x)
@[simp] axiom s548 (x : Prop) : f (g549 x) = f (g548 x)
@[simp] axiom s549 (x : Prop) : f (g550 x) = f (g549 x)
@[simp] axiom s550 (x : Prop) : f (g551 x) = f (g550 x)
@[simp] axiom s551 (x : Prop) : f (g552 x) = f (g551 x)
@[simp] axiom s552 (x : Prop) : f (g553 x) = f (g552 x)
@[simp] axiom s553 (x : Prop) : f (g554 x) = f (g553 x)
@[simp] axiom s554 (x : Prop) : f (g555 x) = f (g554 x)
@[simp] axiom s555 (x : Prop) : f (g556 x) = f (g555 x)
@[simp] axiom s556 (x : Prop) : f (g557 x) = f (g556 x)
@[simp] axiom s557 (x : Prop) : f (g558 x) = f (g557 x)
@[simp] axiom s558 (x : Prop) : f (g559 x) = f (g558 x)
@[simp] axiom s559 (x : Prop) : f (g560 x) = f (g559 x)
@[simp] axiom s560 (x : Prop) : f (g561 x) = f (g560 x)
@[simp] axiom s561 (x : Prop) : f (g562 x) = f (g561 x)
@[simp] axiom s562 (x : Prop) : f (g563 x) = f (g562 x)
@[simp] axiom s563 (x : Prop) : f (g564 x) = f (g563 x)
@[simp] axiom s564 (x : Prop) : f (g565 x) = f (g564 x)
@[simp] axiom s565 (x : Prop) : f (g566 x) = f (g565 x)
@[simp] axiom s566 (x : Prop) : f (g567 x) = f (g566 x)
@[simp] axiom s567 (x : Prop) : f (g568 x) = f (g567 x)
@[simp] axiom s568 (x : Prop) : f (g569 x) = f (g568 x)
@[simp] axiom s569 (x : Prop) : f (g570 x) = f (g569 x)
@[simp] axiom s570 (x : Prop) : f (g571 x) = f (g570 x)
@[simp] axiom s571 (x : Prop) : f (g572 x) = f (g571 x)
@[simp] axiom s572 (x : Prop) : f (g573 x) = f (g572 x)
@[simp] axiom s573 (x : Prop) : f (g574 x) = f (g573 x)
@[simp] axiom s574 (x : Prop) : f (g575 x) = f (g574 x)
@[simp] axiom s575 (x : Prop) : f (g576 x) = f (g575 x)
@[simp] axiom s576 (x : Prop) : f (g577 x) = f (g576 x)
@[simp] axiom s577 (x : Prop) : f (g578 x) = f (g577 x)
@[simp] axiom s578 (x : Prop) : f (g579 x) = f (g578 x)
@[simp] axiom s579 (x : Prop) : f (g580 x) = f (g579 x)
@[simp] axiom s580 (x : Prop) : f (g581 x) = f (g580 x)
@[simp] axiom s581 (x : Prop) : f (g582 x) = f (g581 x)
@[simp] axiom s582 (x : Prop) : f (g583 x) = f (g582 x)
@[simp] axiom s583 (x : Prop) : f (g584 x) = f (g583 x)
@[simp] axiom s584 (x : Prop) : f (g585 x) = f (g584 x)
@[simp] axiom s585 (x : Prop) : f (g586 x) = f (g585 x)
@[simp] axiom s586 (x : Prop) : f (g587 x) = f (g586 x)
@[simp] axiom s587 (x : Prop) : f (g588 x) = f (g587 x)
@[simp] axiom s588 (x : Prop) : f (g589 x) = f (g588 x)
@[simp] axiom s589 (x : Prop) : f (g590 x) = f (g589 x)
@[simp] axiom s590 (x : Prop) : f (g591 x) = f (g590 x)
@[simp] axiom s591 (x : Prop) : f (g592 x) = f (g591 x)
@[simp] axiom s592 (x : Prop) : f (g593 x) = f (g592 x)
@[simp] axiom s593 (x : Prop) : f (g594 x) = f (g593 x)
@[simp] axiom s594 (x : Prop) : f (g595 x) = f (g594 x)
@[simp] axiom s595 (x : Prop) : f (g596 x) = f (g595 x)
@[simp] axiom s596 (x : Prop) : f (g597 x) = f (g596 x)
@[simp] axiom s597 (x : Prop) : f (g598 x) = f (g597 x)
@[simp] axiom s598 (x : Prop) : f (g599 x) = f (g598 x)
@[simp] axiom s599 (x : Prop) : f (g600 x) = f (g599 x)
@[simp] axiom s600 (x : Prop) : f (g601 x) = f (g600 x)
@[simp] axiom s601 (x : Prop) : f (g602 x) = f (g601 x)
@[simp] axiom s602 (x : Prop) : f (g603 x) = f (g602 x)
@[simp] axiom s603 (x : Prop) : f (g604 x) = f (g603 x)
@[simp] axiom s604 (x : Prop) : f (g605 x) = f (g604 x)
@[simp] axiom s605 (x : Prop) : f (g606 x) = f (g605 x)
@[simp] axiom s606 (x : Prop) : f (g607 x) = f (g606 x)
@[simp] axiom s607 (x : Prop) : f (g608 x) = f (g607 x)
@[simp] axiom s608 (x : Prop) : f (g609 x) = f (g608 x)
@[simp] axiom s609 (x : Prop) : f (g610 x) = f (g609 x)
@[simp] axiom s610 (x : Prop) : f (g611 x) = f (g610 x)
@[simp] axiom s611 (x : Prop) : f (g612 x) = f (g611 x)
@[simp] axiom s612 (x : Prop) : f (g613 x) = f (g612 x)
@[simp] axiom s613 (x : Prop) : f (g614 x) = f (g613 x)
@[simp] axiom s614 (x : Prop) : f (g615 x) = f (g614 x)
@[simp] axiom s615 (x : Prop) : f (g616 x) = f (g615 x)
@[simp] axiom s616 (x : Prop) : f (g617 x) = f (g616 x)
@[simp] axiom s617 (x : Prop) : f (g618 x) = f (g617 x)
@[simp] axiom s618 (x : Prop) : f (g619 x) = f (g618 x)
@[simp] axiom s619 (x : Prop) : f (g620 x) = f (g619 x)
@[simp] axiom s620 (x : Prop) : f (g621 x) = f (g620 x)
@[simp] axiom s621 (x : Prop) : f (g622 x) = f (g621 x)
@[simp] axiom s622 (x : Prop) : f (g623 x) = f (g622 x)
@[simp] axiom s623 (x : Prop) : f (g624 x) = f (g623 x)
@[simp] axiom s624 (x : Prop) : f (g625 x) = f (g624 x)
@[simp] axiom s625 (x : Prop) : f (g626 x) = f (g625 x)
@[simp] axiom s626 (x : Prop) : f (g627 x) = f (g626 x)
@[simp] axiom s627 (x : Prop) : f (g628 x) = f (g627 x)
@[simp] axiom s628 (x : Prop) : f (g629 x) = f (g628 x)
@[simp] axiom s629 (x : Prop) : f (g630 x) = f (g629 x)
@[simp] axiom s630 (x : Prop) : f (g631 x) = f (g630 x)
@[simp] axiom s631 (x : Prop) : f (g632 x) = f (g631 x)
@[simp] axiom s632 (x : Prop) : f (g633 x) = f (g632 x)
@[simp] axiom s633 (x : Prop) : f (g634 x) = f (g633 x)
@[simp] axiom s634 (x : Prop) : f (g635 x) = f (g634 x)
@[simp] axiom s635 (x : Prop) : f (g636 x) = f (g635 x)
@[simp] axiom s636 (x : Prop) : f (g637 x) = f (g636 x)
@[simp] axiom s637 (x : Prop) : f (g638 x) = f (g637 x)
@[simp] axiom s638 (x : Prop) : f (g639 x) = f (g638 x)
@[simp] axiom s639 (x : Prop) : f (g640 x) = f (g639 x)
@[simp] axiom s640 (x : Prop) : f (g641 x) = f (g640 x)
@[simp] axiom s641 (x : Prop) : f (g642 x) = f (g641 x)
@[simp] axiom s642 (x : Prop) : f (g643 x) = f (g642 x)
@[simp] axiom s643 (x : Prop) : f (g644 x) = f (g643 x)
@[simp] axiom s644 (x : Prop) : f (g645 x) = f (g644 x)
@[simp] axiom s645 (x : Prop) : f (g646 x) = f (g645 x)
@[simp] axiom s646 (x : Prop) : f (g647 x) = f (g646 x)
@[simp] axiom s647 (x : Prop) : f (g648 x) = f (g647 x)
@[simp] axiom s648 (x : Prop) : f (g649 x) = f (g648 x)
@[simp] axiom s649 (x : Prop) : f (g650 x) = f (g649 x)
@[simp] axiom s650 (x : Prop) : f (g651 x) = f (g650 x)
@[simp] axiom s651 (x : Prop) : f (g652 x) = f (g651 x)
@[simp] axiom s652 (x : Prop) : f (g653 x) = f (g652 x)
@[simp] axiom s653 (x : Prop) : f (g654 x) = f (g653 x)
@[simp] axiom s654 (x : Prop) : f (g655 x) = f (g654 x)
@[simp] axiom s655 (x : Prop) : f (g656 x) = f (g655 x)
@[simp] axiom s656 (x : Prop) : f (g657 x) = f (g656 x)
@[simp] axiom s657 (x : Prop) : f (g658 x) = f (g657 x)
@[simp] axiom s658 (x : Prop) : f (g659 x) = f (g658 x)
@[simp] axiom s659 (x : Prop) : f (g660 x) = f (g659 x)
@[simp] axiom s660 (x : Prop) : f (g661 x) = f (g660 x)
@[simp] axiom s661 (x : Prop) : f (g662 x) = f (g661 x)
@[simp] axiom s662 (x : Prop) : f (g663 x) = f (g662 x)
@[simp] axiom s663 (x : Prop) : f (g664 x) = f (g663 x)
@[simp] axiom s664 (x : Prop) : f (g665 x) = f (g664 x)
@[simp] axiom s665 (x : Prop) : f (g666 x) = f (g665 x)
@[simp] axiom s666 (x : Prop) : f (g667 x) = f (g666 x)
@[simp] axiom s667 (x : Prop) : f (g668 x) = f (g667 x)
@[simp] axiom s668 (x : Prop) : f (g669 x) = f (g668 x)
@[simp] axiom s669 (x : Prop) : f (g670 x) = f (g669 x)
@[simp] axiom s670 (x : Prop) : f (g671 x) = f (g670 x)
@[simp] axiom s671 (x : Prop) : f (g672 x) = f (g671 x)
@[simp] axiom s672 (x : Prop) : f (g673 x) = f (g672 x)
@[simp] axiom s673 (x : Prop) : f (g674 x) = f (g673 x)
@[simp] axiom s674 (x : Prop) : f (g675 x) = f (g674 x)
@[simp] axiom s675 (x : Prop) : f (g676 x) = f (g675 x)
@[simp] axiom s676 (x : Prop) : f (g677 x) = f (g676 x)
@[simp] axiom s677 (x : Prop) : f (g678 x) = f (g677 x)
@[simp] axiom s678 (x : Prop) : f (g679 x) = f (g678 x)
@[simp] axiom s679 (x : Prop) : f (g680 x) = f (g679 x)
@[simp] axiom s680 (x : Prop) : f (g681 x) = f (g680 x)
@[simp] axiom s681 (x : Prop) : f (g682 x) = f (g681 x)
@[simp] axiom s682 (x : Prop) : f (g683 x) = f (g682 x)
@[simp] axiom s683 (x : Prop) : f (g684 x) = f (g683 x)
@[simp] axiom s684 (x : Prop) : f (g685 x) = f (g684 x)
@[simp] axiom s685 (x : Prop) : f (g686 x) = f (g685 x)
@[simp] axiom s686 (x : Prop) : f (g687 x) = f (g686 x)
@[simp] axiom s687 (x : Prop) : f (g688 x) = f (g687 x)
@[simp] axiom s688 (x : Prop) : f (g689 x) = f (g688 x)
@[simp] axiom s689 (x : Prop) : f (g690 x) = f (g689 x)
@[simp] axiom s690 (x : Prop) : f (g691 x) = f (g690 x)
@[simp] axiom s691 (x : Prop) : f (g692 x) = f (g691 x)
@[simp] axiom s692 (x : Prop) : f (g693 x) = f (g692 x)
@[simp] axiom s693 (x : Prop) : f (g694 x) = f (g693 x)
@[simp] axiom s694 (x : Prop) : f (g695 x) = f (g694 x)
@[simp] axiom s695 (x : Prop) : f (g696 x) = f (g695 x)
@[simp] axiom s696 (x : Prop) : f (g697 x) = f (g696 x)
@[simp] axiom s697 (x : Prop) : f (g698 x) = f (g697 x)
@[simp] axiom s698 (x : Prop) : f (g699 x) = f (g698 x)
@[simp] axiom s699 (x : Prop) : f (g700 x) = f (g699 x)
@[simp] axiom s700 (x : Prop) : f (g701 x) = f (g700 x)
@[simp] axiom s701 (x : Prop) : f (g702 x) = f (g701 x)
@[simp] axiom s702 (x : Prop) : f (g703 x) = f (g702 x)
@[simp] axiom s703 (x : Prop) : f (g704 x) = f (g703 x)
@[simp] axiom s704 (x : Prop) : f (g705 x) = f (g704 x)
@[simp] axiom s705 (x : Prop) : f (g706 x) = f (g705 x)
@[simp] axiom s706 (x : Prop) : f (g707 x) = f (g706 x)
@[simp] axiom s707 (x : Prop) : f (g708 x) = f (g707 x)
@[simp] axiom s708 (x : Prop) : f (g709 x) = f (g708 x)
@[simp] axiom s709 (x : Prop) : f (g710 x) = f (g709 x)
@[simp] axiom s710 (x : Prop) : f (g711 x) = f (g710 x)
@[simp] axiom s711 (x : Prop) : f (g712 x) = f (g711 x)
@[simp] axiom s712 (x : Prop) : f (g713 x) = f (g712 x)
@[simp] axiom s713 (x : Prop) : f (g714 x) = f (g713 x)
@[simp] axiom s714 (x : Prop) : f (g715 x) = f (g714 x)
@[simp] axiom s715 (x : Prop) : f (g716 x) = f (g715 x)
@[simp] axiom s716 (x : Prop) : f (g717 x) = f (g716 x)
@[simp] axiom s717 (x : Prop) : f (g718 x) = f (g717 x)
@[simp] axiom s718 (x : Prop) : f (g719 x) = f (g718 x)
@[simp] axiom s719 (x : Prop) : f (g720 x) = f (g719 x)
@[simp] axiom s720 (x : Prop) : f (g721 x) = f (g720 x)
@[simp] axiom s721 (x : Prop) : f (g722 x) = f (g721 x)
@[simp] axiom s722 (x : Prop) : f (g723 x) = f (g722 x)
@[simp] axiom s723 (x : Prop) : f (g724 x) = f (g723 x)
@[simp] axiom s724 (x : Prop) : f (g725 x) = f (g724 x)
@[simp] axiom s725 (x : Prop) : f (g726 x) = f (g725 x)
@[simp] axiom s726 (x : Prop) : f (g727 x) = f (g726 x)
@[simp] axiom s727 (x : Prop) : f (g728 x) = f (g727 x)
@[simp] axiom s728 (x : Prop) : f (g729 x) = f (g728 x)
@[simp] axiom s729 (x : Prop) : f (g730 x) = f (g729 x)
@[simp] axiom s730 (x : Prop) : f (g731 x) = f (g730 x)
@[simp] axiom s731 (x : Prop) : f (g732 x) = f (g731 x)
@[simp] axiom s732 (x : Prop) : f (g733 x) = f (g732 x)
@[simp] axiom s733 (x : Prop) : f (g734 x) = f (g733 x)
@[simp] axiom s734 (x : Prop) : f (g735 x) = f (g734 x)
@[simp] axiom s735 (x : Prop) : f (g736 x) = f (g735 x)
@[simp] axiom s736 (x : Prop) : f (g737 x) = f (g736 x)
@[simp] axiom s737 (x : Prop) : f (g738 x) = f (g737 x)
@[simp] axiom s738 (x : Prop) : f (g739 x) = f (g738 x)
@[simp] axiom s739 (x : Prop) : f (g740 x) = f (g739 x)
@[simp] axiom s740 (x : Prop) : f (g741 x) = f (g740 x)
@[simp] axiom s741 (x : Prop) : f (g742 x) = f (g741 x)
@[simp] axiom s742 (x : Prop) : f (g743 x) = f (g742 x)
@[simp] axiom s743 (x : Prop) : f (g744 x) = f (g743 x)
@[simp] axiom s744 (x : Prop) : f (g745 x) = f (g744 x)
@[simp] axiom s745 (x : Prop) : f (g746 x) = f (g745 x)
@[simp] axiom s746 (x : Prop) : f (g747 x) = f (g746 x)
@[simp] axiom s747 (x : Prop) : f (g748 x) = f (g747 x)
@[simp] axiom s748 (x : Prop) : f (g749 x) = f (g748 x)
@[simp] axiom s749 (x : Prop) : f (g750 x) = f (g749 x)
@[simp] axiom s750 (x : Prop) : f (g751 x) = f (g750 x)
@[simp] axiom s751 (x : Prop) : f (g752 x) = f (g751 x)
@[simp] axiom s752 (x : Prop) : f (g753 x) = f (g752 x)
@[simp] axiom s753 (x : Prop) : f (g754 x) = f (g753 x)
@[simp] axiom s754 (x : Prop) : f (g755 x) = f (g754 x)
@[simp] axiom s755 (x : Prop) : f (g756 x) = f (g755 x)
@[simp] axiom s756 (x : Prop) : f (g757 x) = f (g756 x)
@[simp] axiom s757 (x : Prop) : f (g758 x) = f (g757 x)
@[simp] axiom s758 (x : Prop) : f (g759 x) = f (g758 x)
@[simp] axiom s759 (x : Prop) : f (g760 x) = f (g759 x)
@[simp] axiom s760 (x : Prop) : f (g761 x) = f (g760 x)
@[simp] axiom s761 (x : Prop) : f (g762 x) = f (g761 x)
@[simp] axiom s762 (x : Prop) : f (g763 x) = f (g762 x)
@[simp] axiom s763 (x : Prop) : f (g764 x) = f (g763 x)
@[simp] axiom s764 (x : Prop) : f (g765 x) = f (g764 x)
@[simp] axiom s765 (x : Prop) : f (g766 x) = f (g765 x)
@[simp] axiom s766 (x : Prop) : f (g767 x) = f (g766 x)
@[simp] axiom s767 (x : Prop) : f (g768 x) = f (g767 x)
@[simp] axiom s768 (x : Prop) : f (g769 x) = f (g768 x)
@[simp] axiom s769 (x : Prop) : f (g770 x) = f (g769 x)
@[simp] axiom s770 (x : Prop) : f (g771 x) = f (g770 x)
@[simp] axiom s771 (x : Prop) : f (g772 x) = f (g771 x)
@[simp] axiom s772 (x : Prop) : f (g773 x) = f (g772 x)
@[simp] axiom s773 (x : Prop) : f (g774 x) = f (g773 x)
@[simp] axiom s774 (x : Prop) : f (g775 x) = f (g774 x)
@[simp] axiom s775 (x : Prop) : f (g776 x) = f (g775 x)
@[simp] axiom s776 (x : Prop) : f (g777 x) = f (g776 x)
@[simp] axiom s777 (x : Prop) : f (g778 x) = f (g777 x)
@[simp] axiom s778 (x : Prop) : f (g779 x) = f (g778 x)
@[simp] axiom s779 (x : Prop) : f (g780 x) = f (g779 x)
@[simp] axiom s780 (x : Prop) : f (g781 x) = f (g780 x)
@[simp] axiom s781 (x : Prop) : f (g782 x) = f (g781 x)
@[simp] axiom s782 (x : Prop) : f (g783 x) = f (g782 x)
@[simp] axiom s783 (x : Prop) : f (g784 x) = f (g783 x)
@[simp] axiom s784 (x : Prop) : f (g785 x) = f (g784 x)
@[simp] axiom s785 (x : Prop) : f (g786 x) = f (g785 x)
@[simp] axiom s786 (x : Prop) : f (g787 x) = f (g786 x)
@[simp] axiom s787 (x : Prop) : f (g788 x) = f (g787 x)
@[simp] axiom s788 (x : Prop) : f (g789 x) = f (g788 x)
@[simp] axiom s789 (x : Prop) : f (g790 x) = f (g789 x)
@[simp] axiom s790 (x : Prop) : f (g791 x) = f (g790 x)
@[simp] axiom s791 (x : Prop) : f (g792 x) = f (g791 x)
@[simp] axiom s792 (x : Prop) : f (g793 x) = f (g792 x)
@[simp] axiom s793 (x : Prop) : f (g794 x) = f (g793 x)
@[simp] axiom s794 (x : Prop) : f (g795 x) = f (g794 x)
@[simp] axiom s795 (x : Prop) : f (g796 x) = f (g795 x)
@[simp] axiom s796 (x : Prop) : f (g797 x) = f (g796 x)
@[simp] axiom s797 (x : Prop) : f (g798 x) = f (g797 x)
@[simp] axiom s798 (x : Prop) : f (g799 x) = f (g798 x)
@[simp] axiom s799 (x : Prop) : f (g800 x) = f (g799 x)
@[simp] axiom s800 (x : Prop) : f (g801 x) = f (g800 x)
@[simp] axiom s801 (x : Prop) : f (g802 x) = f (g801 x)
@[simp] axiom s802 (x : Prop) : f (g803 x) = f (g802 x)
@[simp] axiom s803 (x : Prop) : f (g804 x) = f (g803 x)
@[simp] axiom s804 (x : Prop) : f (g805 x) = f (g804 x)
@[simp] axiom s805 (x : Prop) : f (g806 x) = f (g805 x)
@[simp] axiom s806 (x : Prop) : f (g807 x) = f (g806 x)
@[simp] axiom s807 (x : Prop) : f (g808 x) = f (g807 x)
@[simp] axiom s808 (x : Prop) : f (g809 x) = f (g808 x)
@[simp] axiom s809 (x : Prop) : f (g810 x) = f (g809 x)
@[simp] axiom s810 (x : Prop) : f (g811 x) = f (g810 x)
@[simp] axiom s811 (x : Prop) : f (g812 x) = f (g811 x)
@[simp] axiom s812 (x : Prop) : f (g813 x) = f (g812 x)
@[simp] axiom s813 (x : Prop) : f (g814 x) = f (g813 x)
@[simp] axiom s814 (x : Prop) : f (g815 x) = f (g814 x)
@[simp] axiom s815 (x : Prop) : f (g816 x) = f (g815 x)
@[simp] axiom s816 (x : Prop) : f (g817 x) = f (g816 x)
@[simp] axiom s817 (x : Prop) : f (g818 x) = f (g817 x)
@[simp] axiom s818 (x : Prop) : f (g819 x) = f (g818 x)
@[simp] axiom s819 (x : Prop) : f (g820 x) = f (g819 x)
@[simp] axiom s820 (x : Prop) : f (g821 x) = f (g820 x)
@[simp] axiom s821 (x : Prop) : f (g822 x) = f (g821 x)
@[simp] axiom s822 (x : Prop) : f (g823 x) = f (g822 x)
@[simp] axiom s823 (x : Prop) : f (g824 x) = f (g823 x)
@[simp] axiom s824 (x : Prop) : f (g825 x) = f (g824 x)
@[simp] axiom s825 (x : Prop) : f (g826 x) = f (g825 x)
@[simp] axiom s826 (x : Prop) : f (g827 x) = f (g826 x)
@[simp] axiom s827 (x : Prop) : f (g828 x) = f (g827 x)
@[simp] axiom s828 (x : Prop) : f (g829 x) = f (g828 x)
@[simp] axiom s829 (x : Prop) : f (g830 x) = f (g829 x)
@[simp] axiom s830 (x : Prop) : f (g831 x) = f (g830 x)
@[simp] axiom s831 (x : Prop) : f (g832 x) = f (g831 x)
@[simp] axiom s832 (x : Prop) : f (g833 x) = f (g832 x)
@[simp] axiom s833 (x : Prop) : f (g834 x) = f (g833 x)
@[simp] axiom s834 (x : Prop) : f (g835 x) = f (g834 x)
@[simp] axiom s835 (x : Prop) : f (g836 x) = f (g835 x)
@[simp] axiom s836 (x : Prop) : f (g837 x) = f (g836 x)
@[simp] axiom s837 (x : Prop) : f (g838 x) = f (g837 x)
@[simp] axiom s838 (x : Prop) : f (g839 x) = f (g838 x)
@[simp] axiom s839 (x : Prop) : f (g840 x) = f (g839 x)
@[simp] axiom s840 (x : Prop) : f (g841 x) = f (g840 x)
@[simp] axiom s841 (x : Prop) : f (g842 x) = f (g841 x)
@[simp] axiom s842 (x : Prop) : f (g843 x) = f (g842 x)
@[simp] axiom s843 (x : Prop) : f (g844 x) = f (g843 x)
@[simp] axiom s844 (x : Prop) : f (g845 x) = f (g844 x)
@[simp] axiom s845 (x : Prop) : f (g846 x) = f (g845 x)
@[simp] axiom s846 (x : Prop) : f (g847 x) = f (g846 x)
@[simp] axiom s847 (x : Prop) : f (g848 x) = f (g847 x)
@[simp] axiom s848 (x : Prop) : f (g849 x) = f (g848 x)
@[simp] axiom s849 (x : Prop) : f (g850 x) = f (g849 x)
@[simp] axiom s850 (x : Prop) : f (g851 x) = f (g850 x)
@[simp] axiom s851 (x : Prop) : f (g852 x) = f (g851 x)
@[simp] axiom s852 (x : Prop) : f (g853 x) = f (g852 x)
@[simp] axiom s853 (x : Prop) : f (g854 x) = f (g853 x)
@[simp] axiom s854 (x : Prop) : f (g855 x) = f (g854 x)
@[simp] axiom s855 (x : Prop) : f (g856 x) = f (g855 x)
@[simp] axiom s856 (x : Prop) : f (g857 x) = f (g856 x)
@[simp] axiom s857 (x : Prop) : f (g858 x) = f (g857 x)
@[simp] axiom s858 (x : Prop) : f (g859 x) = f (g858 x)
@[simp] axiom s859 (x : Prop) : f (g860 x) = f (g859 x)
@[simp] axiom s860 (x : Prop) : f (g861 x) = f (g860 x)
@[simp] axiom s861 (x : Prop) : f (g862 x) = f (g861 x)
@[simp] axiom s862 (x : Prop) : f (g863 x) = f (g862 x)
@[simp] axiom s863 (x : Prop) : f (g864 x) = f (g863 x)
@[simp] axiom s864 (x : Prop) : f (g865 x) = f (g864 x)
@[simp] axiom s865 (x : Prop) : f (g866 x) = f (g865 x)
@[simp] axiom s866 (x : Prop) : f (g867 x) = f (g866 x)
@[simp] axiom s867 (x : Prop) : f (g868 x) = f (g867 x)
@[simp] axiom s868 (x : Prop) : f (g869 x) = f (g868 x)
@[simp] axiom s869 (x : Prop) : f (g870 x) = f (g869 x)
@[simp] axiom s870 (x : Prop) : f (g871 x) = f (g870 x)
@[simp] axiom s871 (x : Prop) : f (g872 x) = f (g871 x)
@[simp] axiom s872 (x : Prop) : f (g873 x) = f (g872 x)
@[simp] axiom s873 (x : Prop) : f (g874 x) = f (g873 x)
@[simp] axiom s874 (x : Prop) : f (g875 x) = f (g874 x)
@[simp] axiom s875 (x : Prop) : f (g876 x) = f (g875 x)
@[simp] axiom s876 (x : Prop) : f (g877 x) = f (g876 x)
@[simp] axiom s877 (x : Prop) : f (g878 x) = f (g877 x)
@[simp] axiom s878 (x : Prop) : f (g879 x) = f (g878 x)
@[simp] axiom s879 (x : Prop) : f (g880 x) = f (g879 x)
@[simp] axiom s880 (x : Prop) : f (g881 x) = f (g880 x)
@[simp] axiom s881 (x : Prop) : f (g882 x) = f (g881 x)
@[simp] axiom s882 (x : Prop) : f (g883 x) = f (g882 x)
@[simp] axiom s883 (x : Prop) : f (g884 x) = f (g883 x)
@[simp] axiom s884 (x : Prop) : f (g885 x) = f (g884 x)
@[simp] axiom s885 (x : Prop) : f (g886 x) = f (g885 x)
@[simp] axiom s886 (x : Prop) : f (g887 x) = f (g886 x)
@[simp] axiom s887 (x : Prop) : f (g888 x) = f (g887 x)
@[simp] axiom s888 (x : Prop) : f (g889 x) = f (g888 x)
@[simp] axiom s889 (x : Prop) : f (g890 x) = f (g889 x)
@[simp] axiom s890 (x : Prop) : f (g891 x) = f (g890 x)
@[simp] axiom s891 (x : Prop) : f (g892 x) = f (g891 x)
@[simp] axiom s892 (x : Prop) : f (g893 x) = f (g892 x)
@[simp] axiom s893 (x : Prop) : f (g894 x) = f (g893 x)
@[simp] axiom s894 (x : Prop) : f (g895 x) = f (g894 x)
@[simp] axiom s895 (x : Prop) : f (g896 x) = f (g895 x)
@[simp] axiom s896 (x : Prop) : f (g897 x) = f (g896 x)
@[simp] axiom s897 (x : Prop) : f (g898 x) = f (g897 x)
@[simp] axiom s898 (x : Prop) : f (g899 x) = f (g898 x)
@[simp] axiom s899 (x : Prop) : f (g900 x) = f (g899 x)
@[simp] axiom s900 (x : Prop) : f (g901 x) = f (g900 x)
@[simp] axiom s901 (x : Prop) : f (g902 x) = f (g901 x)
@[simp] axiom s902 (x : Prop) : f (g903 x) = f (g902 x)
@[simp] axiom s903 (x : Prop) : f (g904 x) = f (g903 x)
@[simp] axiom s904 (x : Prop) : f (g905 x) = f (g904 x)
@[simp] axiom s905 (x : Prop) : f (g906 x) = f (g905 x)
@[simp] axiom s906 (x : Prop) : f (g907 x) = f (g906 x)
@[simp] axiom s907 (x : Prop) : f (g908 x) = f (g907 x)
@[simp] axiom s908 (x : Prop) : f (g909 x) = f (g908 x)
@[simp] axiom s909 (x : Prop) : f (g910 x) = f (g909 x)
@[simp] axiom s910 (x : Prop) : f (g911 x) = f (g910 x)
@[simp] axiom s911 (x : Prop) : f (g912 x) = f (g911 x)
@[simp] axiom s912 (x : Prop) : f (g913 x) = f (g912 x)
@[simp] axiom s913 (x : Prop) : f (g914 x) = f (g913 x)
@[simp] axiom s914 (x : Prop) : f (g915 x) = f (g914 x)
@[simp] axiom s915 (x : Prop) : f (g916 x) = f (g915 x)
@[simp] axiom s916 (x : Prop) : f (g917 x) = f (g916 x)
@[simp] axiom s917 (x : Prop) : f (g918 x) = f (g917 x)
@[simp] axiom s918 (x : Prop) : f (g919 x) = f (g918 x)
@[simp] axiom s919 (x : Prop) : f (g920 x) = f (g919 x)
@[simp] axiom s920 (x : Prop) : f (g921 x) = f (g920 x)
@[simp] axiom s921 (x : Prop) : f (g922 x) = f (g921 x)
@[simp] axiom s922 (x : Prop) : f (g923 x) = f (g922 x)
@[simp] axiom s923 (x : Prop) : f (g924 x) = f (g923 x)
@[simp] axiom s924 (x : Prop) : f (g925 x) = f (g924 x)
@[simp] axiom s925 (x : Prop) : f (g926 x) = f (g925 x)
@[simp] axiom s926 (x : Prop) : f (g927 x) = f (g926 x)
@[simp] axiom s927 (x : Prop) : f (g928 x) = f (g927 x)
@[simp] axiom s928 (x : Prop) : f (g929 x) = f (g928 x)
@[simp] axiom s929 (x : Prop) : f (g930 x) = f (g929 x)
@[simp] axiom s930 (x : Prop) : f (g931 x) = f (g930 x)
@[simp] axiom s931 (x : Prop) : f (g932 x) = f (g931 x)
@[simp] axiom s932 (x : Prop) : f (g933 x) = f (g932 x)
@[simp] axiom s933 (x : Prop) : f (g934 x) = f (g933 x)
@[simp] axiom s934 (x : Prop) : f (g935 x) = f (g934 x)
@[simp] axiom s935 (x : Prop) : f (g936 x) = f (g935 x)
@[simp] axiom s936 (x : Prop) : f (g937 x) = f (g936 x)
@[simp] axiom s937 (x : Prop) : f (g938 x) = f (g937 x)
@[simp] axiom s938 (x : Prop) : f (g939 x) = f (g938 x)
@[simp] axiom s939 (x : Prop) : f (g940 x) = f (g939 x)
@[simp] axiom s940 (x : Prop) : f (g941 x) = f (g940 x)
@[simp] axiom s941 (x : Prop) : f (g942 x) = f (g941 x)
@[simp] axiom s942 (x : Prop) : f (g943 x) = f (g942 x)
@[simp] axiom s943 (x : Prop) : f (g944 x) = f (g943 x)
@[simp] axiom s944 (x : Prop) : f (g945 x) = f (g944 x)
@[simp] axiom s945 (x : Prop) : f (g946 x) = f (g945 x)
@[simp] axiom s946 (x : Prop) : f (g947 x) = f (g946 x)
@[simp] axiom s947 (x : Prop) : f (g948 x) = f (g947 x)
@[simp] axiom s948 (x : Prop) : f (g949 x) = f (g948 x)
@[simp] axiom s949 (x : Prop) : f (g950 x) = f (g949 x)
@[simp] axiom s950 (x : Prop) : f (g951 x) = f (g950 x)
@[simp] axiom s951 (x : Prop) : f (g952 x) = f (g951 x)
@[simp] axiom s952 (x : Prop) : f (g953 x) = f (g952 x)
@[simp] axiom s953 (x : Prop) : f (g954 x) = f (g953 x)
@[simp] axiom s954 (x : Prop) : f (g955 x) = f (g954 x)
@[simp] axiom s955 (x : Prop) : f (g956 x) = f (g955 x)
@[simp] axiom s956 (x : Prop) : f (g957 x) = f (g956 x)
@[simp] axiom s957 (x : Prop) : f (g958 x) = f (g957 x)
@[simp] axiom s958 (x : Prop) : f (g959 x) = f (g958 x)
@[simp] axiom s959 (x : Prop) : f (g960 x) = f (g959 x)
@[simp] axiom s960 (x : Prop) : f (g961 x) = f (g960 x)
@[simp] axiom s961 (x : Prop) : f (g962 x) = f (g961 x)
@[simp] axiom s962 (x : Prop) : f (g963 x) = f (g962 x)
@[simp] axiom s963 (x : Prop) : f (g964 x) = f (g963 x)
@[simp] axiom s964 (x : Prop) : f (g965 x) = f (g964 x)
@[simp] axiom s965 (x : Prop) : f (g966 x) = f (g965 x)
@[simp] axiom s966 (x : Prop) : f (g967 x) = f (g966 x)
@[simp] axiom s967 (x : Prop) : f (g968 x) = f (g967 x)
@[simp] axiom s968 (x : Prop) : f (g969 x) = f (g968 x)
@[simp] axiom s969 (x : Prop) : f (g970 x) = f (g969 x)
@[simp] axiom s970 (x : Prop) : f (g971 x) = f (g970 x)
@[simp] axiom s971 (x : Prop) : f (g972 x) = f (g971 x)
@[simp] axiom s972 (x : Prop) : f (g973 x) = f (g972 x)
@[simp] axiom s973 (x : Prop) : f (g974 x) = f (g973 x)
@[simp] axiom s974 (x : Prop) : f (g975 x) = f (g974 x)
@[simp] axiom s975 (x : Prop) : f (g976 x) = f (g975 x)
@[simp] axiom s976 (x : Prop) : f (g977 x) = f (g976 x)
@[simp] axiom s977 (x : Prop) : f (g978 x) = f (g977 x)
@[simp] axiom s978 (x : Prop) : f (g979 x) = f (g978 x)
@[simp] axiom s979 (x : Prop) : f (g980 x) = f (g979 x)
@[simp] axiom s980 (x : Prop) : f (g981 x) = f (g980 x)
@[simp] axiom s981 (x : Prop) : f (g982 x) = f (g981 x)
@[simp] axiom s982 (x : Prop) : f (g983 x) = f (g982 x)
@[simp] axiom s983 (x : Prop) : f (g984 x) = f (g983 x)
@[simp] axiom s984 (x : Prop) : f (g985 x) = f (g984 x)
@[simp] axiom s985 (x : Prop) : f (g986 x) = f (g985 x)
@[simp] axiom s986 (x : Prop) : f (g987 x) = f (g986 x)
@[simp] axiom s987 (x : Prop) : f (g988 x) = f (g987 x)
@[simp] axiom s988 (x : Prop) : f (g989 x) = f (g988 x)
@[simp] axiom s989 (x : Prop) : f (g990 x) = f (g989 x)
@[simp] axiom s990 (x : Prop) : f (g991 x) = f (g990 x)
@[simp] axiom s991 (x : Prop) : f (g992 x) = f (g991 x)
@[simp] axiom s992 (x : Prop) : f (g993 x) = f (g992 x)
@[simp] axiom s993 (x : Prop) : f (g994 x) = f (g993 x)
@[simp] axiom s994 (x : Prop) : f (g995 x) = f (g994 x)
@[simp] axiom s995 (x : Prop) : f (g996 x) = f (g995 x)
@[simp] axiom s996 (x : Prop) : f (g997 x) = f (g996 x)
@[simp] axiom s997 (x : Prop) : f (g998 x) = f (g997 x)
@[simp] axiom s998 (x : Prop) : f (g999 x) = f (g998 x)
def test (x : Prop) : f (g0 x) = f (g999 x) := by simp
#check test
|
d1e4463925d02e27a7473c6f07a6772f9f2324dd
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/analysis/normed_space/multilinear.lean
|
f18235c17b4c359826fe0b333dec52e88133c0b6
|
[
"Apache-2.0"
] |
permissive
|
waynemunro/mathlib
|
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
|
065a70810b5480d584033f7bbf8e0409480c2118
|
refs/heads/master
| 1,693,417,182,397
| 1,634,644,781,000
| 1,634,644,781,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 73,325
|
lean
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.normed_space.operator_norm
import topology.algebra.multilinear
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `∥f∥` as the
smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `∥f m∥ ≤ C * ∏ i, ∥m i∥` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mk_continuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `∥f∥` is its norm, i.e., the smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for
all `m`.
* `le_op_norm f m` asserts the fundamental inequality `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥`.
* `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`∥f∥` and `∥m₁ - m₂∥`.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
continuous multilinear function `f` in `n+1` variables into a continuous linear function taking
values in continuous multilinear functions in `n` variables, and also into a continuous multilinear
function in `n` variables taking values in continuous linear functions. These operations are called
`f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and
`f.uncurry_right`). They induce continuous linear equivalences between spaces of
continuous multilinear functions in `n+1` variables and spaces of continuous linear functions into
continuous multilinear functions in `n` variables (resp. continuous multilinear functions in `n`
variables taking values in continuous linear functions), called respectively
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
## Implementation notes
We mostly follow the API (and the proofs) of `operator_norm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables. The currying/uncurrying
constructions are based on those in `multilinear.lean`.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
noncomputable theory
open_locale classical big_operators nnreal
open finset metric
local attribute [instance, priority 1001]
add_comm_group.to_add_comm_monoid normed_group.to_add_comm_group normed_space.to_module
-- hack to speed up simp when dealing with complicated types
local attribute [-instance] unique.subsingleton pi.subsingleton
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `nondiscrete_normed_field`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : fin (nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universes u v v' wE wE₁ wE' wEi wG wG'
variables {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {n : ℕ}
{E : ι → Type wE} {E₁ : ι → Type wE₁} {E' : ι' → Type wE'} {Ei : fin n.succ → Type wEi}
{G : Type wG} {G' : Type wG'}
[decidable_eq ι] [fintype ι] [decidable_eq ι'] [fintype ι'] [nondiscrete_normed_field 𝕜]
[Π i, normed_group (E i)] [Π i, normed_space 𝕜 (E i)]
[Π i, normed_group (E₁ i)] [Π i, normed_space 𝕜 (E₁ i)]
[Π i, normed_group (E' i)] [Π i, normed_space 𝕜 (E' i)]
[Π i, normed_group (Ei i)] [Π i, normed_space 𝕜 (Ei i)]
[normed_group G] [normed_space 𝕜 G] [normed_group G'] [normed_space 𝕜 G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, in
both directions. Along the way, we prove useful bounds on the difference `∥f m₁ - f m₂∥`.
-/
namespace multilinear_map
variable (f : multilinear_map 𝕜 E G)
/-- If a multilinear map in finitely many variables on normed spaces satisfies the inequality
`∥f m∥ ≤ C * ∏ i, ∥m i∥` on a shell `ε i / ∥c i∥ < ∥m i∥ < ε i` for some positive numbers `ε i`
and elements `c i : 𝕜`, `1 < ∥c i∥`, then it satisfies this inequality for all `m`. -/
lemma bound_of_shell {ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ∥c i∥)
(hf : ∀ m : Π i, E i, (∀ i, ε i / ∥c i∥ ≤ ∥m i∥) → (∀ i, ∥m i∥ < ε i) → ∥f m∥ ≤ C * ∏ i, ∥m i∥)
(m : Π i, E i) : ∥f m∥ ≤ C * ∏ i, ∥m i∥ :=
begin
rcases em (∃ i, m i = 0) with ⟨i, hi⟩|hm; [skip, push_neg at hm],
{ simp [f.map_coord_zero i hi, prod_eq_zero (mem_univ i), hi] },
choose δ hδ0 hδm_lt hle_δm hδinv using λ i, rescale_to_shell (hc i) (hε i) (hm i),
have hδ0 : 0 < ∏ i, ∥δ i∥, from prod_pos (λ i _, norm_pos_iff.2 (hδ0 i)),
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0]
using hf (λ i, δ i • m i) hle_δm hδm_lt,
end
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (hf : continuous f) :
∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :=
begin
casesI is_empty_or_nonempty ι,
{ refine ⟨∥f 0∥ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, λ m, _⟩,
obtain rfl : m = 0, from funext (is_empty.elim ‹_›),
simp [univ_eq_empty, zero_le_one] },
obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : Π i, E i, ∥m - 0∥ < ε → ∥f m - f 0∥ < 1⟩ :=
normed_group.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one,
simp only [sub_zero, f.map_zero] at hε,
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
have : 0 < (∥c∥ / ε) ^ fintype.card ι, from pow_pos (div_pos (zero_lt_one.trans hc) ε0) _,
refine ⟨_, this, _⟩,
refine f.bound_of_shell (λ _, ε0) (λ _, hc) (λ m hcm hm, _),
refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans _,
rw [← div_le_iff' this, one_div, ← inv_pow₀, inv_div, fintype.card, ← prod_const],
exact prod_le_prod (λ _ _, div_nonneg ε0.le (norm_nonneg _)) (λ i _, hcm i)
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a precise but hard to use version. See
`norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads
`∥f m - f m'∥ ≤
C * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
lemma norm_image_sub_le_of_bound' {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E i) :
∥f m₁ - f m₂∥ ≤
C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :=
begin
have A : ∀(s : finset ι), ∥f m₁ - f (s.piecewise m₂ m₁)∥
≤ C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥,
{ refine finset.induction (by simp) _,
assume i s his Hrec,
have I : ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥
≤ C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥,
{ have A : ((insert i s).piecewise m₂ m₁)
= function.update (s.piecewise m₂ m₁) i (m₂ i) := s.piecewise_insert _ _ _,
have B : s.piecewise m₂ m₁ = function.update (s.piecewise m₂ m₁) i (m₁ i),
{ ext j,
by_cases h : j = i,
{ rw h, simp [his] },
{ simp [h] } },
rw [B, A, ← f.map_sub],
apply le_trans (H _) (mul_le_mul_of_nonneg_left _ hC),
refine prod_le_prod (λj hj, norm_nonneg _) (λj hj, _),
by_cases h : j = i,
{ rw h, simp },
{ by_cases h' : j ∈ s;
simp [h', h, le_refl] } },
calc ∥f m₁ - f ((insert i s).piecewise m₂ m₁)∥ ≤
∥f m₁ - f (s.piecewise m₂ m₁)∥ + ∥f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)∥ :
by { rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm], exact dist_triangle _ _ _ }
... ≤ (C * ∑ i in s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
+ C * ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
add_le_add Hrec I
... = C * ∑ i in insert i s, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
by simp [his, add_comm, left_distrib] },
convert A univ,
simp
end
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`∥f m - f m'∥ ≤ C * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`. -/
lemma norm_image_sub_le_of_bound {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (m₁ m₂ : Πi, E i) :
∥f m₁ - f m₂∥ ≤ C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :=
begin
have A : ∀ (i : ι), ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
≤ ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1),
{ assume i,
calc ∏ j, (if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥)
≤ ∏ j : ι, function.update (λ j, max ∥m₁∥ ∥m₂∥) i (∥m₁ - m₂∥) j :
begin
apply prod_le_prod,
{ assume j hj, by_cases h : j = i; simp [h, norm_nonneg] },
{ assume j hj,
by_cases h : j = i,
{ rw h, simp, exact norm_le_pi_norm (m₁ - m₂) i },
{ simp [h, max_le_max, norm_le_pi_norm] } }
end
... = ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) :
by { rw prod_update_of_mem (finset.mem_univ _), simp [card_univ_diff] } },
calc
∥f m₁ - f m₂∥
≤ C * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :
f.norm_image_sub_le_of_bound' hC H m₁ m₂
... ≤ C * ∑ i, ∥m₁ - m₂∥ * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) :
mul_le_mul_of_nonneg_left (sum_le_sum (λi hi, A i)) hC
... = C * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :
by { rw [sum_const, card_univ, nsmul_eq_mul], ring }
end
/-- If a multilinear map satisfies an inequality `∥f m∥ ≤ C * ∏ i, ∥m i∥`, then it is
continuous. -/
theorem continuous_of_bound (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :
continuous f :=
begin
let D := max C 1,
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _),
replace H : ∀ m, ∥f m∥ ≤ D * ∏ i, ∥m i∥,
{ assume m,
apply le_trans (H m) (mul_le_mul_of_nonneg_right (le_max_left _ _) _),
exact prod_nonneg (λ(i : ι) hi, norm_nonneg (m i)) },
refine continuous_iff_continuous_at.2 (λm, _),
refine continuous_at_of_locally_lipschitz zero_lt_one
(D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1)) (λm' h', _),
rw [dist_eq_norm, dist_eq_norm],
have : 0 ≤ (max ∥m'∥ ∥m∥), by simp,
have : (max ∥m'∥ ∥m∥) ≤ ∥m∥ + 1,
by simp [zero_le_one, norm_le_of_mem_closed_ball (le_of_lt h'), -add_comm],
calc
∥f m' - f m∥
≤ D * (fintype.card ι) * (max ∥m'∥ ∥m∥) ^ (fintype.card ι - 1) * ∥m' - m∥ :
f.norm_image_sub_le_of_bound D_pos H m' m
... ≤ D * (fintype.card ι) * (∥m∥ + 1) ^ (fintype.card ι - 1) * ∥m' - m∥ :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul_of_nonneg_left, mul_nonneg,
norm_nonneg, nat.cast_nonneg, pow_le_pow_of_le_left]
end
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mk_continuous (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :
continuous_multilinear_map 𝕜 E G :=
{ cont := f.continuous_of_bound C H, ..f }
@[simp] lemma coe_mk_continuous (C : ℝ) (H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :
⇑(f.mk_continuous C H) = f :=
rfl
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`∥f.restr v∥ ≤ C * ∥z∥^(n-k) * Π ∥v i∥` if the original function satisfies `∥f v∥ ≤ C * Π ∥v i∥`. -/
lemma restr_norm_le {k n : ℕ} (f : (multilinear_map 𝕜 (λ i : fin n, G) G' : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) {C : ℝ}
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) (v : fin k → G) :
∥f.restr s hk z v∥ ≤ C * ∥z∥ ^ (n - k) * ∏ i, ∥v i∥ :=
begin
rw [mul_right_comm, mul_assoc],
convert H _ using 2,
simp only [apply_dite norm, fintype.prod_dite, prod_const (∥z∥), finset.card_univ,
fintype.card_of_subtype sᶜ (λ x, mem_compl), card_compl, fintype.card_fin, hk, mk_coe,
← (s.order_iso_of_fin hk).symm.bijective.prod_comp (λ x, ∥v x∥)],
refl
end
end multilinear_map
/-!
### Continuous multilinear maps
We define the norm `∥f∥` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥` for all `m`. We show that this
defines a normed space structure on `continuous_multilinear_map 𝕜 E G`.
-/
namespace continuous_multilinear_map
variables (c : 𝕜) (f g : continuous_multilinear_map 𝕜 E G) (m : Πi, E i)
theorem bound : ∃ (C : ℝ), 0 < C ∧ (∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) :=
f.to_multilinear_map.exists_bound_of_continuous f.2
open real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def op_norm := Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥}
instance has_op_norm : has_norm (continuous_multilinear_map 𝕜 E G) := ⟨op_norm⟩
lemma norm_def : ∥f∥ = Inf {c | 0 ≤ (c : ℝ) ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} := rfl
-- So that invocations of `le_cInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : continuous_multilinear_map 𝕜 E G} :
∃ c, c ∈ {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} :=
let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩
lemma bounds_bdd_below {f : continuous_multilinear_map 𝕜 E G} :
bdd_below {c | 0 ≤ c ∧ ∀ m, ∥f m∥ ≤ c * ∏ i, ∥m i∥} :=
⟨0, λ _ ⟨hn, _⟩, hn⟩
lemma op_norm_nonneg : 0 ≤ ∥f∥ :=
le_cInf bounds_nonempty (λ _ ⟨hx, _⟩, hx)
/-- The fundamental property of the operator norm of a continuous multilinear map:
`∥f m∥` is bounded by `∥f∥` times the product of the `∥m i∥`. -/
theorem le_op_norm : ∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
begin
have A : 0 ≤ ∏ i, ∥m i∥ := prod_nonneg (λj hj, norm_nonneg _),
cases A.eq_or_lt with h hlt,
{ rcases prod_eq_zero_iff.1 h.symm with ⟨i, _, hi⟩,
rw norm_eq_zero at hi,
have : f m = 0 := f.map_coord_zero i hi,
rw [this, norm_zero],
exact mul_nonneg (op_norm_nonneg f) A },
{ rw [← div_le_iff hlt],
apply le_cInf bounds_nonempty,
rintro c ⟨_, hc⟩, rw [div_le_iff hlt], apply hc }
end
theorem le_of_op_norm_le {C : ℝ} (h : ∥f∥ ≤ C) : ∥f m∥ ≤ C * ∏ i, ∥m i∥ :=
(f.le_op_norm m).trans $ mul_le_mul_of_nonneg_right h (prod_nonneg $ λ i _, norm_nonneg (m i))
lemma ratio_le_op_norm : ∥f m∥ / ∏ i, ∥m i∥ ≤ ∥f∥ :=
div_le_of_nonneg_of_le_mul (prod_nonneg $ λ i _, norm_nonneg _) (op_norm_nonneg _) (f.le_op_norm m)
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
lemma unit_le_op_norm (h : ∥m∥ ≤ 1) : ∥f m∥ ≤ ∥f∥ :=
calc
∥f m∥ ≤ ∥f∥ * ∏ i, ∥m i∥ : f.le_op_norm m
... ≤ ∥f∥ * ∏ i : ι, 1 :
mul_le_mul_of_nonneg_left (prod_le_prod (λi hi, norm_nonneg _)
(λi hi, le_trans (norm_le_pi_norm _ _) h)) (op_norm_nonneg f)
... = ∥f∥ : by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ m, ∥f m∥ ≤ M * ∏ i, ∥m i∥) :
∥f∥ ≤ M :=
cInf_le bounds_bdd_below ⟨hMp, hM⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ :=
cInf_le bounds_bdd_below
⟨add_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw add_mul,
exact norm_add_le_of_le (le_op_norm _ _) (le_op_norm _ _) }⟩
/-- A continuous linear map is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 :=
begin
split,
{ assume h,
ext m,
simpa [h] using f.le_op_norm m },
{ rintro rfl,
apply le_antisymm (op_norm_le_bound 0 le_rfl (λm, _)) (op_norm_nonneg _),
simp }
end
variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜' 𝕜]
[normed_space 𝕜' G] [is_scalar_tower 𝕜' 𝕜 G]
lemma op_norm_smul_le (c : 𝕜') : ∥c • f∥ ≤ ∥c∥ * ∥f∥ :=
(c • f).op_norm_le_bound
(mul_nonneg (norm_nonneg _) (op_norm_nonneg _))
begin
intro m,
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end
lemma op_norm_neg : ∥-f∥ = ∥f∥ := by { rw norm_def, apply congr_arg, ext, simp }
/-- Continuous multilinear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (continuous_multilinear_map 𝕜 E G) :=
normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩
instance to_normed_space : normed_space 𝕜' (continuous_multilinear_map 𝕜 E G) :=
⟨λ c f, f.op_norm_smul_le c⟩
theorem le_op_norm_mul_prod_of_le {b : ι → ℝ} (hm : ∀ i, ∥m i∥ ≤ b i) : ∥f m∥ ≤ ∥f∥ * ∏ i, b i :=
(f.le_op_norm m).trans $ mul_le_mul_of_nonneg_left
(prod_le_prod (λ _ _, norm_nonneg _) (λ i _, hm i)) (norm_nonneg f)
theorem le_op_norm_mul_pow_card_of_le {b : ℝ} (hm : ∀ i, ∥m i∥ ≤ b) :
∥f m∥ ≤ ∥f∥ * b ^ fintype.card ι :=
by simpa only [prod_const] using f.le_op_norm_mul_prod_of_le m hm
theorem le_op_norm_mul_pow_of_le {Ei : fin n → Type*} [Π i, normed_group (Ei i)]
[Π i, normed_space 𝕜 (Ei i)] (f : continuous_multilinear_map 𝕜 Ei G) (m : Π i, Ei i)
{b : ℝ} (hm : ∥m∥ ≤ b) :
∥f m∥ ≤ ∥f∥ * b ^ n :=
by simpa only [fintype.card_fin]
using f.le_op_norm_mul_pow_card_of_le m (λ i, (norm_le_pi_norm m i).trans hm)
/-- The fundamental property of the operator norm of a continuous multilinear map:
`∥f m∥` is bounded by `∥f∥` times the product of the `∥m i∥`, `nnnorm` version. -/
theorem le_op_nnnorm : nnnorm (f m) ≤ nnnorm f * ∏ i, nnnorm (m i) :=
nnreal.coe_le_coe.1 $ by { push_cast, exact f.le_op_norm m }
theorem le_of_op_nnnorm_le {C : ℝ≥0} (h : nnnorm f ≤ C) : nnnorm (f m) ≤ C * ∏ i, nnnorm (m i) :=
(f.le_op_nnnorm m).trans $ mul_le_mul' h le_rfl
lemma op_norm_prod (f : continuous_multilinear_map 𝕜 E G) (g : continuous_multilinear_map 𝕜 E G') :
∥f.prod g∥ = max (∥f∥) (∥g∥) :=
le_antisymm
(op_norm_le_bound _ (norm_nonneg (f, g)) (λ m,
have H : 0 ≤ ∏ i, ∥m i∥, from prod_nonneg $ λ _ _, norm_nonneg _,
by simpa only [prod_apply, prod.norm_def, max_mul_of_nonneg, H]
using max_le_max (f.le_op_norm m) (g.le_op_norm m))) $
max_le
(f.op_norm_le_bound (norm_nonneg _) $ λ m, (le_max_left _ _).trans ((f.prod g).le_op_norm _))
(g.op_norm_le_bound (norm_nonneg _) $ λ m, (le_max_right _ _).trans ((f.prod g).le_op_norm _))
lemma norm_pi {ι' : Type v'} [fintype ι'] {E' : ι' → Type wE'} [Π i', normed_group (E' i')]
[Π i', normed_space 𝕜 (E' i')] (f : Π i', continuous_multilinear_map 𝕜 E (E' i')) :
∥pi f∥ = ∥f∥ :=
begin
apply le_antisymm,
{ refine (op_norm_le_bound _ (norm_nonneg f) (λ m, _)),
dsimp,
rw pi_norm_le_iff,
exacts [λ i, (f i).le_of_op_norm_le m (norm_le_pi_norm f i),
mul_nonneg (norm_nonneg f) (prod_nonneg $ λ _ _, norm_nonneg _)] },
{ refine (pi_norm_le_iff (norm_nonneg _)).2 (λ i, _),
refine (op_norm_le_bound _ (norm_nonneg _) (λ m, _)),
refine le_trans _ ((pi f).le_op_norm m),
convert norm_le_pi_norm (λ j, f j m) i }
end
section
variables (𝕜 E E' G G')
/-- `continuous_multilinear_map.prod` as a `linear_isometry_equiv`. -/
def prodL :
(continuous_multilinear_map 𝕜 E G) × (continuous_multilinear_map 𝕜 E G') ≃ₗᵢ[𝕜]
continuous_multilinear_map 𝕜 E (G × G') :=
{ to_fun := λ f, f.1.prod f.2,
inv_fun := λ f, ((continuous_linear_map.fst 𝕜 G G').comp_continuous_multilinear_map f,
(continuous_linear_map.snd 𝕜 G G').comp_continuous_multilinear_map f),
map_add' := λ f g, rfl,
map_smul' := λ c f, rfl,
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl,
norm_map' := λ f, op_norm_prod f.1 f.2 }
/-- `continuous_multilinear_map.pi` as a `linear_isometry_equiv`. -/
def piₗᵢ {ι' : Type v'} [fintype ι'] {E' : ι' → Type wE'} [Π i', normed_group (E' i')]
[Π i', normed_space 𝕜 (E' i')] :
@linear_isometry_equiv 𝕜 𝕜 _ _ (ring_hom.id 𝕜) _ _ _
(Π i', continuous_multilinear_map 𝕜 E (E' i')) (continuous_multilinear_map 𝕜 E (Π i, E' i)) _ _
(@pi.module ι' _ 𝕜 _ _ (λ i', infer_instance)) _ :=
{ to_linear_equiv :=
-- note: `pi_linear_equiv` does not unify correctly here, presumably due to issues with dependent
-- typeclass arguments.
{ map_add' := λ f g, rfl,
map_smul' := λ c f, rfl,
.. pi_equiv, },
norm_map' := norm_pi }
end
section restrict_scalars
variables [Π i, normed_space 𝕜' (E i)] [∀ i, is_scalar_tower 𝕜' 𝕜 (E i)]
@[simp] lemma norm_restrict_scalars : ∥f.restrict_scalars 𝕜'∥ = ∥f∥ :=
by simp only [norm_def, coe_restrict_scalars]
variable (𝕜')
/-- `continuous_multilinear_map.restrict_scalars` as a `continuous_multilinear_map`. -/
def restrict_scalars_linear :
continuous_multilinear_map 𝕜 E G →L[𝕜'] continuous_multilinear_map 𝕜' E G :=
linear_map.mk_continuous
{ to_fun := restrict_scalars 𝕜',
map_add' := λ m₁ m₂, rfl,
map_smul' := λ c m, rfl } 1 $ λ f, by simp
variable {𝕜'}
lemma continuous_restrict_scalars :
continuous (restrict_scalars 𝕜' : continuous_multilinear_map 𝕜 E G →
continuous_multilinear_map 𝕜' E G) :=
(restrict_scalars_linear 𝕜').continuous
end restrict_scalars
/-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, precise version.
For a less precise but more usable version, see `norm_image_sub_le`. The bound reads
`∥f m - f m'∥ ≤
∥f∥ * ∥m 1 - m' 1∥ * max ∥m 2∥ ∥m' 2∥ * max ∥m 3∥ ∥m' 3∥ * ... * max ∥m n∥ ∥m' n∥ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`.-/
lemma norm_image_sub_le' (m₁ m₂ : Πi, E i) :
∥f m₁ - f m₂∥ ≤
∥f∥ * ∑ i, ∏ j, if j = i then ∥m₁ i - m₂ i∥ else max ∥m₁ j∥ ∥m₂ j∥ :=
f.to_multilinear_map.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_op_norm _ _
/-- The difference `f m₁ - f m₂` is controlled in terms of `∥f∥` and `∥m₁ - m₂∥`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le'`.
The bound is `∥f m - f m'∥ ≤ ∥f∥ * card ι * ∥m - m'∥ * (max ∥m∥ ∥m'∥) ^ (card ι - 1)`.-/
lemma norm_image_sub_le (m₁ m₂ : Πi, E i) :
∥f m₁ - f m₂∥ ≤ ∥f∥ * (fintype.card ι) * (max ∥m₁∥ ∥m₂∥) ^ (fintype.card ι - 1) * ∥m₁ - m₂∥ :=
f.to_multilinear_map.norm_image_sub_le_of_bound (norm_nonneg _) f.le_op_norm _ _
/-- Applying a multilinear map to a vector is continuous in both coordinates. -/
lemma continuous_eval :
continuous (λ p : continuous_multilinear_map 𝕜 E G × Π i, E i, p.1 p.2) :=
begin
apply continuous_iff_continuous_at.2 (λp, _),
apply continuous_at_of_locally_lipschitz zero_lt_one
((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) + ∏ i, ∥p.2 i∥)
(λq hq, _),
have : 0 ≤ (max ∥q.2∥ ∥p.2∥), by simp,
have : 0 ≤ ∥p∥ + 1, by simp [le_trans zero_le_one],
have A : ∥q∥ ≤ ∥p∥ + 1 := norm_le_of_mem_closed_ball (le_of_lt hq),
have : (max ∥q.2∥ ∥p.2∥) ≤ ∥p∥ + 1 :=
le_trans (max_le_max (norm_snd_le q) (norm_snd_le p)) (by simp [A, -add_comm, zero_le_one]),
have : ∀ (i : ι), i ∈ univ → 0 ≤ ∥p.2 i∥ := λ i hi, norm_nonneg _,
calc dist (q.1 q.2) (p.1 p.2)
≤ dist (q.1 q.2) (q.1 p.2) + dist (q.1 p.2) (p.1 p.2) : dist_triangle _ _ _
... = ∥q.1 q.2 - q.1 p.2∥ + ∥q.1 p.2 - p.1 p.2∥ : by rw [dist_eq_norm, dist_eq_norm]
... ≤ ∥q.1∥ * (fintype.card ι) * (max ∥q.2∥ ∥p.2∥) ^ (fintype.card ι - 1) * ∥q.2 - p.2∥
+ ∥q.1 - p.1∥ * ∏ i, ∥p.2 i∥ :
add_le_add (norm_image_sub_le _ _ _) ((q.1 - p.1).le_op_norm p.2)
... ≤ (∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1) * ∥q - p∥
+ ∥q - p∥ * ∏ i, ∥p.2 i∥ :
by apply_rules [add_le_add, mul_le_mul, le_refl, le_trans (norm_fst_le q) A, nat.cast_nonneg,
mul_nonneg, pow_le_pow_of_le_left, pow_nonneg, norm_snd_le (q - p), norm_nonneg,
norm_fst_le (q - p), prod_nonneg]
... = ((∥p∥ + 1) * (fintype.card ι) * (∥p∥ + 1) ^ (fintype.card ι - 1)
+ (∏ i, ∥p.2 i∥)) * dist q p : by { rw dist_eq_norm, ring }
end
lemma continuous_eval_left (m : Π i, E i) :
continuous (λ p : continuous_multilinear_map 𝕜 E G, p m) :=
continuous_eval.comp (continuous_id.prod_mk continuous_const)
lemma has_sum_eval
{α : Type*} {p : α → continuous_multilinear_map 𝕜 E G} {q : continuous_multilinear_map 𝕜 E G}
(h : has_sum p q) (m : Π i, E i) : has_sum (λ a, p a m) (q m) :=
begin
dsimp [has_sum] at h ⊢,
convert ((continuous_eval_left m).tendsto _).comp h,
ext s,
simp
end
lemma tsum_eval {α : Type*} {p : α → continuous_multilinear_map 𝕜 E G} (hp : summable p)
(m : Π i, E i) : (∑' a, p a) m = ∑' a, p a m :=
(has_sum_eval hp.has_sum m).tsum_eq.symm
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous multilinear maps with its norm is also
complete. The proof is essentially the same as for the space of continuous linear maps (modulo the
addition of `finset.prod` where needed. The duplication could be avoided by deducing the linear
case from the multilinear case via a currying isomorphism. However, this would mess up imports,
and it is more satisfactory to have the simplest case as a standalone proof. -/
instance [complete_space G] : complete_space (continuous_multilinear_map 𝕜 E G) :=
begin
have nonneg : ∀ (v : Π i, E i), 0 ≤ ∏ i, ∥v i∥ :=
λ v, finset.prod_nonneg (λ i hi, norm_nonneg _),
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩,
-- and establish that the evaluation at any point `v : Π i, E i` is Cauchy.
have cau : ∀ v, cauchy_seq (λ n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∏ i, ∥v i∥, λ n, _, _, _⟩,
{ exact mul_nonneg (b0 n) (nonneg v) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `G` is complete)
-- into a function which we call `F`.
choose F hF using λv, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `F` is multilinear,
let Fmult : multilinear_map 𝕜 E G :=
{ to_fun := F,
map_add' := λ v i x y, begin
have A := hF (function.update v i (x + y)),
have B := (hF (function.update v i x)).add (hF (function.update v i y)),
simp at A B,
exact tendsto_nhds_unique A B
end,
map_smul' := λ v i c x, begin
have A := hF (function.update v i (c • x)),
have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hF (function.update v i x)),
simp at A B,
exact tendsto_nhds_unique A B
end },
-- and that `F` has norm at most `(b 0 + ∥f 0∥)`.
have Fnorm : ∀ v, ∥F v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥,
{ assume v,
have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∏ i, ∥v i∥,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (nonneg v),
calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel }
... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _
... ≤ b 0 + ∥f 0∥ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto (hF v).norm (eventually_of_forall A) },
-- Thus `F` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Fcont := Fmult.mk_continuous _ Fnorm,
use Fcont,
-- Our last task is to establish convergence to `F` in norm.
have : ∀ n, ∥f n - Fcont∥ ≤ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (λ v, _),
have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∏ i, ∥v i∥,
{ refine eventually_at_top.2 ⟨n, λ m hm, _⟩,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (nonneg v) },
have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Fcont) v∥)) :=
tendsto.norm (tendsto_const_nhds.sub (hF v)),
exact le_of_tendsto B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (λ n, norm_nonneg _) this b_lim,
end
end continuous_multilinear_map
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mk_continuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma multilinear_map.mk_continuous_norm_le (f : multilinear_map 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : ∥f.mk_continuous C H∥ ≤ C :=
continuous_multilinear_map.op_norm_le_bound _ hC (λm, H m)
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mk_continuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
lemma multilinear_map.mk_continuous_norm_le' (f : multilinear_map 𝕜 E G) {C : ℝ}
(H : ∀ m, ∥f m∥ ≤ C * ∏ i, ∥m i∥) : ∥f.mk_continuous C H∥ ≤ max C 0 :=
continuous_multilinear_map.op_norm_le_bound _ (le_max_right _ _) $
λ m, (H m).trans $ mul_le_mul_of_nonneg_right (le_max_left _ _)
(prod_nonneg $ λ _ _, norm_nonneg _)
namespace continuous_multilinear_map
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : (G [×n]→L[𝕜] G' : _))
(s : finset (fin n)) (hk : s.card = k) (z : G) : G [×k]→L[𝕜] G' :=
(f.to_multilinear_map.restr s hk z).mk_continuous
(∥f∥ * ∥z∥^(n-k)) $ λ v, multilinear_map.restr_norm_le _ _ _ _ f.le_op_norm _
lemma norm_restr {k n : ℕ} (f : G [×n]→L[𝕜] G') (s : finset (fin n)) (hk : s.card = k) (z : G) :
∥f.restr s hk z∥ ≤ ∥f∥ * ∥z∥ ^ (n - k) :=
begin
apply multilinear_map.mk_continuous_norm_le,
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
end
section
variables (𝕜 ι) (A : Type*) [normed_comm_ring A] [normed_algebra 𝕜 A]
/-- The continuous multilinear map on `A^ι`, where `A` is a normed commutative algebra
over `𝕜`, associating to `m` the product of all the `m i`.
See also `continuous_multilinear_map.mk_pi_algebra_fin`. -/
protected def mk_pi_algebra : continuous_multilinear_map 𝕜 (λ i : ι, A) A :=
multilinear_map.mk_continuous
(multilinear_map.mk_pi_algebra 𝕜 ι A) (if nonempty ι then 1 else ∥(1 : A)∥) $
begin
intro m,
casesI is_empty_or_nonempty ι with hι hι,
{ simp [eq_empty_of_is_empty univ, not_nonempty_iff.2 hι] },
{ simp [norm_prod_le' univ univ_nonempty, hι] }
end
variables {A 𝕜 ι}
@[simp] lemma mk_pi_algebra_apply (m : ι → A) :
continuous_multilinear_map.mk_pi_algebra 𝕜 ι A m = ∏ i, m i :=
rfl
lemma norm_mk_pi_algebra_le [nonempty ι] :
∥continuous_multilinear_map.mk_pi_algebra 𝕜 ι A∥ ≤ 1 :=
calc ∥continuous_multilinear_map.mk_pi_algebra 𝕜 ι A∥ ≤ if nonempty ι then 1 else ∥(1 : A)∥ :
multilinear_map.mk_continuous_norm_le _ (by split_ifs; simp [zero_le_one]) _
... = _ : if_pos ‹_›
lemma norm_mk_pi_algebra_of_empty [is_empty ι] :
∥continuous_multilinear_map.mk_pi_algebra 𝕜 ι A∥ = ∥(1 : A)∥ :=
begin
apply le_antisymm,
calc ∥continuous_multilinear_map.mk_pi_algebra 𝕜 ι A∥ ≤ if nonempty ι then 1 else ∥(1 : A)∥ :
multilinear_map.mk_continuous_norm_le _ (by split_ifs; simp [zero_le_one]) _
... = ∥(1 : A)∥ : if_neg (not_nonempty_iff.mpr ‹_›),
convert ratio_le_op_norm _ (λ _, (1 : A)),
simp [eq_empty_of_is_empty (univ : finset ι)],
end
@[simp] lemma norm_mk_pi_algebra [norm_one_class A] :
∥continuous_multilinear_map.mk_pi_algebra 𝕜 ι A∥ = 1 :=
begin
casesI is_empty_or_nonempty ι,
{ simp [norm_mk_pi_algebra_of_empty] },
{ refine le_antisymm norm_mk_pi_algebra_le _,
convert ratio_le_op_norm _ (λ _, 1); [skip, apply_instance],
simp },
end
end
section
variables (𝕜 n) (A : Type*) [normed_ring A] [normed_algebra 𝕜 A]
/-- The continuous multilinear map on `A^n`, where `A` is a normed algebra over `𝕜`, associating to
`m` the product of all the `m i`.
See also: `multilinear_map.mk_pi_algebra`. -/
protected def mk_pi_algebra_fin : continuous_multilinear_map 𝕜 (λ i : fin n, A) A :=
multilinear_map.mk_continuous
(multilinear_map.mk_pi_algebra_fin 𝕜 n A) (nat.cases_on n ∥(1 : A)∥ (λ _, 1)) $
begin
intro m,
cases n,
{ simp },
{ have : @list.of_fn A n.succ m ≠ [] := by simp,
simpa [← fin.prod_of_fn] using list.norm_prod_le' this }
end
variables {A 𝕜 n}
@[simp] lemma mk_pi_algebra_fin_apply (m : fin n → A) :
continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A m = (list.of_fn m).prod :=
rfl
lemma norm_mk_pi_algebra_fin_succ_le :
∥continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n.succ A∥ ≤ 1 :=
multilinear_map.mk_continuous_norm_le _ zero_le_one _
lemma norm_mk_pi_algebra_fin_le_of_pos (hn : 0 < n) :
∥continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A∥ ≤ 1 :=
by cases n; [exact hn.false.elim, exact norm_mk_pi_algebra_fin_succ_le]
lemma norm_mk_pi_algebra_fin_zero :
∥continuous_multilinear_map.mk_pi_algebra_fin 𝕜 0 A∥ = ∥(1 : A)∥ :=
begin
refine le_antisymm (multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _) _,
convert ratio_le_op_norm _ (λ _, 1); [simp, apply_instance]
end
@[simp] lemma norm_mk_pi_algebra_fin [norm_one_class A] :
∥continuous_multilinear_map.mk_pi_algebra_fin 𝕜 n A∥ = 1 :=
begin
cases n,
{ simp [norm_mk_pi_algebra_fin_zero] },
{ refine le_antisymm norm_mk_pi_algebra_fin_succ_le _,
convert ratio_le_op_norm _ (λ _, 1); [skip, apply_instance],
simp }
end
end
variables (𝕜 ι)
/-- The canonical continuous multilinear map on `𝕜^ι`, associating to `m` the product of all the
`m i` (multiplied by a fixed reference element `z` in the target module) -/
protected def mk_pi_field (z : G) : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) G :=
multilinear_map.mk_continuous
(multilinear_map.mk_pi_ring 𝕜 ι z) (∥z∥)
(λ m, by simp only [multilinear_map.mk_pi_ring_apply, norm_smul, normed_field.norm_prod,
mul_comm])
variables {𝕜 ι}
@[simp] lemma mk_pi_field_apply (z : G) (m : ι → 𝕜) :
(continuous_multilinear_map.mk_pi_field 𝕜 ι z : (ι → 𝕜) → G) m = (∏ i, m i) • z := rfl
lemma mk_pi_field_apply_one_eq_self (f : continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) G) :
continuous_multilinear_map.mk_pi_field 𝕜 ι (f (λi, 1)) = f :=
to_multilinear_map_inj f.to_multilinear_map.mk_pi_ring_apply_one_eq_self
variables (𝕜 ι G)
/-- Continuous multilinear maps on `𝕜^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a linear equivalence in
`continuous_multilinear_map.pi_field_equiv_aux`. The continuous linear equivalence is
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv_aux : G ≃ₗ[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) G) :=
{ to_fun := λ z, continuous_multilinear_map.mk_pi_field 𝕜 ι z,
inv_fun := λ f, f (λi, 1),
map_add' := λ z z', by { ext m, simp [smul_add] },
map_smul' := λ c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := λ z, by simp,
right_inv := λ f, f.mk_pi_field_apply_one_eq_self }
/-- Continuous multilinear maps on `𝕜^n` with values in `G` are in bijection with `G`, as such a
continuous multilinear map is completely determined by its value on the constant vector made of
ones. We register this bijection as a continuous linear equivalence in
`continuous_multilinear_map.pi_field_equiv`. -/
protected def pi_field_equiv : G ≃L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : ι), 𝕜) G) :=
{ continuous_to_fun := begin
refine (continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι G).to_linear_map.continuous_of_bound
(1 : ℝ) (λz, _),
rw one_mul,
change ∥continuous_multilinear_map.mk_pi_field 𝕜 ι z∥ ≤ ∥z∥,
exact multilinear_map.mk_continuous_norm_le _ (norm_nonneg _) _
end,
continuous_inv_fun := begin
refine
(continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι G).symm.to_linear_map.continuous_of_bound
(1 : ℝ) (λf, _),
rw one_mul,
change ∥f (λi, 1)∥ ≤ ∥f∥,
apply @continuous_multilinear_map.unit_le_op_norm 𝕜 ι (λ (i : ι), 𝕜) G _ _ _ _ _ _ _ f,
simp [pi_norm_le_iff zero_le_one, le_refl]
end,
.. continuous_multilinear_map.pi_field_equiv_aux 𝕜 ι G }
end continuous_multilinear_map
namespace continuous_linear_map
lemma norm_comp_continuous_multilinear_map_le (g : G →L[𝕜] G')
(f : continuous_multilinear_map 𝕜 E G) :
∥g.comp_continuous_multilinear_map f∥ ≤ ∥g∥ * ∥f∥ :=
continuous_multilinear_map.op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) $ λ m,
calc ∥g (f m)∥ ≤ ∥g∥ * (∥f∥ * ∏ i, ∥m i∥) : g.le_op_norm_of_le $ f.le_op_norm _
... = _ : (mul_assoc _ _ _).symm
/-- `continuous_linear_map.comp_continuous_multilinear_map` as a bundled continuous bilinear map. -/
def comp_continuous_multilinear_mapL :
(G →L[𝕜] G') →L[𝕜] continuous_multilinear_map 𝕜 E G →L[𝕜] continuous_multilinear_map 𝕜 E G' :=
linear_map.mk_continuous₂
(linear_map.mk₂ 𝕜 comp_continuous_multilinear_map (λ f₁ f₂ g, rfl) (λ c f g, rfl)
(λ f g₁ g₂, by { ext1, apply f.map_add }) (λ c f g, by { ext1, simp }))
1 $ λ f g, by { rw one_mul, exact f.norm_comp_continuous_multilinear_map_le g }
/-- Flip arguments in `f : G →L[𝕜] continuous_multilinear_map 𝕜 E G'` to get
`continuous_multilinear_map 𝕜 E (G →L[𝕜] G')` -/
def flip_multilinear (f : G →L[𝕜] continuous_multilinear_map 𝕜 E G') :
continuous_multilinear_map 𝕜 E (G →L[𝕜] G') :=
multilinear_map.mk_continuous
{ to_fun := λ m, linear_map.mk_continuous
{ to_fun := λ x, f x m,
map_add' := λ x y, by simp only [map_add, continuous_multilinear_map.add_apply],
map_smul' := λ c x, by simp only [continuous_multilinear_map.smul_apply, map_smul,
ring_hom.id_apply] }
(∥f∥ * ∏ i, ∥m i∥) $ λ x,
by { rw mul_right_comm, exact (f x).le_of_op_norm_le _ (f.le_op_norm x) },
map_add' := λ m i x y,
by { ext1, simp only [add_apply, continuous_multilinear_map.map_add, linear_map.coe_mk,
linear_map.mk_continuous_apply]},
map_smul' := λ m i c x,
by { ext1, simp only [coe_smul', continuous_multilinear_map.map_smul, linear_map.coe_mk,
linear_map.mk_continuous_apply, pi.smul_apply]} }
∥f∥ $ λ m,
linear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg f) (prod_nonneg $ λ i hi, norm_nonneg (m i))) _
end continuous_linear_map
open continuous_multilinear_map
namespace multilinear_map
/-- Given a map `f : G →ₗ[𝕜] multilinear_map 𝕜 E G'` and an estimate
`H : ∀ x m, ∥f x m∥ ≤ C * ∥x∥ * ∏ i, ∥m i∥`, construct a continuous linear
map from `G` to `continuous_multilinear_map 𝕜 E G'`.
In order to lift, e.g., a map `f : (multilinear_map 𝕜 E G) →ₗ[𝕜] multilinear_map 𝕜 E' G'`
to a map `(continuous_multilinear_map 𝕜 E G) →L[𝕜] continuous_multilinear_map 𝕜 E' G'`,
one can apply this construction to `f.comp continuous_multilinear_map.to_multilinear_map_linear`
which is a linear map from `continuous_multilinear_map 𝕜 E G` to `multilinear_map 𝕜 E' G'`. -/
def mk_continuous_linear (f : G →ₗ[𝕜] multilinear_map 𝕜 E G') (C : ℝ)
(H : ∀ x m, ∥f x m∥ ≤ C * ∥x∥ * ∏ i, ∥m i∥) :
G →L[𝕜] continuous_multilinear_map 𝕜 E G' :=
linear_map.mk_continuous
{ to_fun := λ x, (f x).mk_continuous (C * ∥x∥) $ H x,
map_add' := λ x y, by { ext1, simp },
map_smul' := λ c x, by { ext1, simp } }
(max C 0) $ λ x, ((f x).mk_continuous_norm_le' _).trans_eq $
by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul]
lemma mk_continuous_linear_norm_le' (f : G →ₗ[𝕜] multilinear_map 𝕜 E G') (C : ℝ)
(H : ∀ x m, ∥f x m∥ ≤ C * ∥x∥ * ∏ i, ∥m i∥) :
∥mk_continuous_linear f C H∥ ≤ max C 0 :=
begin
dunfold mk_continuous_linear,
exact linear_map.mk_continuous_norm_le _ (le_max_right _ _) _
end
lemma mk_continuous_linear_norm_le (f : G →ₗ[𝕜] multilinear_map 𝕜 E G') {C : ℝ} (hC : 0 ≤ C)
(H : ∀ x m, ∥f x m∥ ≤ C * ∥x∥ * ∏ i, ∥m i∥) :
∥mk_continuous_linear f C H∥ ≤ C :=
(mk_continuous_linear_norm_le' f C H).trans_eq (max_eq_left hC)
/-- Given a map `f : multilinear_map 𝕜 E (multilinear_map 𝕜 E' G)` and an estimate
`H : ∀ m m', ∥f m m'∥ ≤ C * ∏ i, ∥m i∥ * ∏ i, ∥m' i∥`, upgrade all `multilinear_map`s in the type to
`continuous_multilinear_map`s. -/
def mk_continuous_multilinear (f : multilinear_map 𝕜 E (multilinear_map 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ∥f m₁ m₂∥ ≤ C * (∏ i, ∥m₁ i∥) * ∏ i, ∥m₂ i∥) :
continuous_multilinear_map 𝕜 E (continuous_multilinear_map 𝕜 E' G) :=
mk_continuous
{ to_fun := λ m, mk_continuous (f m) (C * ∏ i, ∥m i∥) $ H m,
map_add' := λ m i x y, by { ext1, simp },
map_smul' := λ m i c x, by { ext1, simp } }
(max C 0) $ λ m, ((f m).mk_continuous_norm_le' _).trans_eq $
by { rw [max_mul_of_nonneg, zero_mul], exact prod_nonneg (λ _ _, norm_nonneg _) }
@[simp] lemma mk_continuous_multilinear_apply (f : multilinear_map 𝕜 E (multilinear_map 𝕜 E' G))
{C : ℝ} (H : ∀ m₁ m₂, ∥f m₁ m₂∥ ≤ C * (∏ i, ∥m₁ i∥) * ∏ i, ∥m₂ i∥) (m : Π i, E i) :
⇑(mk_continuous_multilinear f C H m) = f m :=
rfl
lemma mk_continuous_multilinear_norm_le' (f : multilinear_map 𝕜 E (multilinear_map 𝕜 E' G)) (C : ℝ)
(H : ∀ m₁ m₂, ∥f m₁ m₂∥ ≤ C * (∏ i, ∥m₁ i∥) * ∏ i, ∥m₂ i∥) :
∥mk_continuous_multilinear f C H∥ ≤ max C 0 :=
begin
dunfold mk_continuous_multilinear,
exact mk_continuous_norm_le _ (le_max_right _ _) _
end
lemma mk_continuous_multilinear_norm_le (f : multilinear_map 𝕜 E (multilinear_map 𝕜 E' G)) {C : ℝ}
(hC : 0 ≤ C) (H : ∀ m₁ m₂, ∥f m₁ m₂∥ ≤ C * (∏ i, ∥m₁ i∥) * ∏ i, ∥m₂ i∥) :
∥mk_continuous_multilinear f C H∥ ≤ C :=
(mk_continuous_multilinear_norm_le' f C H).trans_eq (max_eq_left hC)
end multilinear_map
namespace continuous_multilinear_map
lemma norm_comp_continuous_linear_le (g : continuous_multilinear_map 𝕜 E₁ G)
(f : Π i, E i →L[𝕜] E₁ i) :
∥g.comp_continuous_linear_map f∥ ≤ ∥g∥ * ∏ i, ∥f i∥ :=
op_norm_le_bound _ (mul_nonneg (norm_nonneg _) $ prod_nonneg $ λ i hi, norm_nonneg _) $ λ m,
calc ∥g (λ i, f i (m i))∥ ≤ ∥g∥ * ∏ i, ∥f i (m i)∥ : g.le_op_norm _
... ≤ ∥g∥ * ∏ i, (∥f i∥ * ∥m i∥) :
mul_le_mul_of_nonneg_left
(prod_le_prod (λ _ _, norm_nonneg _) (λ i hi, (f i).le_op_norm (m i))) (norm_nonneg g)
... = (∥g∥ * ∏ i, ∥f i∥) * ∏ i, ∥m i∥ : by rw [prod_mul_distrib, mul_assoc]
/-- `continuous_multilinear_map.comp_continuous_linear_map` as a bundled continuous linear map.
This implementation fixes `f : Π i, E i →L[𝕜] E₁ i`.
TODO: Actually, the map is multilinear in `f` but an attempt to formalize this failed because of
issues with class instances. -/
def comp_continuous_linear_mapL (f : Π i, E i →L[𝕜] E₁ i) :
continuous_multilinear_map 𝕜 E₁ G →L[𝕜] continuous_multilinear_map 𝕜 E G :=
linear_map.mk_continuous
{ to_fun := λ g, g.comp_continuous_linear_map f,
map_add' := λ g₁ g₂, rfl,
map_smul' := λ c g, rfl }
(∏ i, ∥f i∥) $ λ g, (norm_comp_continuous_linear_le _ _).trans_eq (mul_comm _ _)
@[simp] lemma comp_continuous_linear_mapL_apply (g : continuous_multilinear_map 𝕜 E₁ G)
(f : Π i, E i →L[𝕜] E₁ i) :
comp_continuous_linear_mapL f g = g.comp_continuous_linear_map f :=
rfl
lemma norm_comp_continuous_linear_mapL_le (f : Π i, E i →L[𝕜] E₁ i) :
∥@comp_continuous_linear_mapL 𝕜 ι E E₁ G _ _ _ _ _ _ _ _ _ f∥ ≤ (∏ i, ∥f i∥) :=
linear_map.mk_continuous_norm_le _ (prod_nonneg $ λ i _, norm_nonneg _) _
end continuous_multilinear_map
section currying
/-!
### Currying
We associate to a continuous multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a continuous linear map on `E 0` taking values
in continuous multilinear maps in `n` variables) and `f.curry_right` (which is a continuous
multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`).
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register continuous linear equiv versions of these correspondences, in
`continuous_multilinear_curry_left_equiv` and `continuous_multilinear_curry_right_equiv`.
-/
open fin function
lemma continuous_linear_map.norm_map_tail_le
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) (m : Πi, Ei i) :
∥f (m 0) (tail m)∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
calc
∥f (m 0) (tail m)∥ ≤ ∥f (m 0)∥ * ∏ i, ∥(tail m) i∥ : (f (m 0)).le_op_norm _
... ≤ (∥f∥ * ∥m 0∥) * ∏ i, ∥(tail m) i∥ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (prod_nonneg (λi hi, norm_nonneg _))
... = ∥f∥ * (∥m 0∥ * ∏ i, ∥(tail m) i∥) : by ring
... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_succ, refl }
lemma continuous_multilinear_map.norm_map_init_le
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →L[𝕜] G))
(m : Πi, Ei i) :
∥f (init m) (m (last n))∥ ≤ ∥f∥ * ∏ i, ∥m i∥ :=
calc
∥f (init m) (m (last n))∥ ≤ ∥f (init m)∥ * ∥m (last n)∥ : (f (init m)).le_op_norm _
... ≤ (∥f∥ * (∏ i, ∥(init m) i∥)) * ∥m (last n)∥ :
mul_le_mul_of_nonneg_right (f.le_op_norm _) (norm_nonneg _)
... = ∥f∥ * ((∏ i, ∥(init m) i∥) * ∥m (last n)∥) : mul_assoc _ _ _
... = ∥f∥ * ∏ i, ∥m i∥ : by { rw prod_univ_cast_succ, refl }
lemma continuous_multilinear_map.norm_map_cons_le
(f : continuous_multilinear_map 𝕜 Ei G) (x : Ei 0) (m : Π(i : fin n), Ei i.succ) :
∥f (cons x m)∥ ≤ ∥f∥ * ∥x∥ * ∏ i, ∥m i∥ :=
calc
∥f (cons x m)∥ ≤ ∥f∥ * ∏ i, ∥cons x m i∥ : f.le_op_norm _
... = (∥f∥ * ∥x∥) * ∏ i, ∥m i∥ : by { rw prod_univ_succ, simp [mul_assoc] }
lemma continuous_multilinear_map.norm_map_snoc_le
(f : continuous_multilinear_map 𝕜 Ei G) (m : Π(i : fin n), Ei i.cast_succ) (x : Ei (last n)) :
∥f (snoc m x)∥ ≤ ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ :=
calc
∥f (snoc m x)∥ ≤ ∥f∥ * ∏ i, ∥snoc m x i∥ : f.le_op_norm _
... = ∥f∥ * (∏ i, ∥m i∥) * ∥x∥ : by { rw prod_univ_cast_succ, simp [mul_assoc] }
/-! #### Left currying -/
/-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables,
construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def continuous_linear_map.uncurry_left
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) :
continuous_multilinear_map 𝕜 Ei G :=
(@linear_map.uncurry_left 𝕜 n Ei G _ _ _ _ _
(continuous_multilinear_map.to_multilinear_map_linear.comp f.to_linear_map)).mk_continuous
(∥f∥) (λm, continuous_linear_map.norm_map_tail_le f m)
@[simp] lemma continuous_linear_map.uncurry_left_apply
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) (m : Πi, Ei i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain
a continuous linear map into continuous multilinear maps in `n` variables, given by
`x ↦ (m ↦ f (cons x m))`. -/
def continuous_multilinear_map.curry_left
(f : continuous_multilinear_map 𝕜 Ei G) :
Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G) :=
linear_map.mk_continuous
{ -- define a linear map into `n` continuous multilinear maps from an `n+1` continuous multilinear
-- map
to_fun := λx, (f.to_multilinear_map.curry_left x).mk_continuous
(∥f∥ * ∥x∥) (f.norm_map_cons_le x),
map_add' := λx y, by { ext m, exact f.cons_add m x y },
map_smul' := λc x, by { ext m, exact f.cons_smul m c x } }
-- then register its continuity thanks to its boundedness properties.
(∥f∥) (λx, multilinear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _)
@[simp] lemma continuous_multilinear_map.curry_left_apply
(f : continuous_multilinear_map 𝕜 Ei G) (x : Ei 0) (m : Π(i : fin n), Ei i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma continuous_linear_map.curry_uncurry_left
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, continuous_linear_map.uncurry_left_apply,
continuous_multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_left
(f : continuous_multilinear_map 𝕜 Ei G) : f.curry_left.uncurry_left = f :=
continuous_multilinear_map.to_multilinear_map_inj $ f.to_multilinear_map.uncurry_curry_left
variables (𝕜 Ei G)
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), E i` is canonically isomorphic to
the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on
`Π(i : fin n), E i.succ `, by separating the first variable. We register this isomorphism in
`continuous_multilinear_curry_left_equiv 𝕜 E E₂`. The algebraic version (without topology) is given
in `multilinear_curry_left_equiv 𝕜 E E₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuous_multilinear_curry_left_equiv :
(Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) ≃ₗᵢ[𝕜]
(continuous_multilinear_map 𝕜 Ei G) :=
linear_isometry_equiv.of_bounds
{ to_fun := continuous_linear_map.uncurry_left,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_left,
left_inv := continuous_linear_map.curry_uncurry_left,
right_inv := continuous_multilinear_map.uncurry_curry_left }
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(λ f, linear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables {𝕜 Ei G}
@[simp] lemma continuous_multilinear_curry_left_equiv_apply
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ i : fin n, Ei i.succ) G)) (v : Π i, Ei i) :
continuous_multilinear_curry_left_equiv 𝕜 Ei G f v = f (v 0) (tail v) := rfl
@[simp] lemma continuous_multilinear_curry_left_equiv_symm_apply
(f : continuous_multilinear_map 𝕜 Ei G) (x : Ei 0) (v : Π i : fin n, Ei i.succ) :
(continuous_multilinear_curry_left_equiv 𝕜 Ei G).symm f x v = f (cons x v) := rfl
@[simp] lemma continuous_multilinear_map.curry_left_norm
(f : continuous_multilinear_map 𝕜 Ei G) : ∥f.curry_left∥ = ∥f∥ :=
(continuous_multilinear_curry_left_equiv 𝕜 Ei G).symm.norm_map f
@[simp] lemma continuous_linear_map.uncurry_left_norm
(f : Ei 0 →L[𝕜] (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.succ) G)) :
∥f.uncurry_left∥ = ∥f∥ :=
(continuous_multilinear_curry_left_equiv 𝕜 Ei G).norm_map f
/-! #### Right currying -/
/-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to
continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1`
variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`. -/
def continuous_multilinear_map.uncurry_right
(f : continuous_multilinear_map 𝕜 (λ i : fin n, Ei i.cast_succ) (Ei (last n) →L[𝕜] G)) :
continuous_multilinear_map 𝕜 Ei G :=
let f' : multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →ₗ[𝕜] G) :=
{ to_fun := λ m, (f m).to_linear_map,
map_add' := λ m i x y, by simp,
map_smul' := λ m i c x, by simp } in
(@multilinear_map.uncurry_right 𝕜 n Ei G _ _ _ _ _ f').mk_continuous
(∥f∥) (λm, f.norm_map_init_le m)
@[simp] lemma continuous_multilinear_map.uncurry_right_apply
(f : continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →L[𝕜] G))
(m : Πi, Ei i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain
a continuous multilinear map in `n` variables into continuous linear maps, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def continuous_multilinear_map.curry_right
(f : continuous_multilinear_map 𝕜 Ei G) :
continuous_multilinear_map 𝕜 (λ i : fin n, Ei i.cast_succ) (Ei (last n) →L[𝕜] G) :=
let f' : multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →L[𝕜] G) :=
{ to_fun := λm, (f.to_multilinear_map.curry_right m).mk_continuous
(∥f∥ * ∏ i, ∥m i∥) $ λx, f.norm_map_snoc_le m x,
map_add' := λ m i x y, by { simp, refl },
map_smul' := λ m i c x, by { simp, refl } } in
f'.mk_continuous (∥f∥) (λm, linear_map.mk_continuous_norm_le _
(mul_nonneg (norm_nonneg _) (prod_nonneg (λj hj, norm_nonneg _))) _)
@[simp] lemma continuous_multilinear_map.curry_right_apply
(f : continuous_multilinear_map 𝕜 Ei G) (m : Π i : fin n, Ei i.cast_succ) (x : Ei (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma continuous_multilinear_map.curry_uncurry_right
(f : continuous_multilinear_map 𝕜 (λ i : fin n, Ei i.cast_succ) (Ei (last n) →L[𝕜] G)) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, continuous_multilinear_map.curry_right_apply,
continuous_multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma continuous_multilinear_map.uncurry_curry_right
(f : continuous_multilinear_map 𝕜 Ei G) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (𝕜 Ei G)
/--
The space of continuous multilinear maps on `Π(i : fin (n+1)), Ei i` is canonically isomorphic to
the space of continuous multilinear maps on `Π(i : fin n), Ei i.cast_succ` with values in the space
of continuous linear maps on `Ei (last n)`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv 𝕜 Ei G`.
The algebraic version (without topology) is given in `multilinear_curry_right_equiv 𝕜 Ei G`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear isometric equivs.
-/
def continuous_multilinear_curry_right_equiv :
(continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →L[𝕜] G)) ≃ₗᵢ[𝕜]
(continuous_multilinear_map 𝕜 Ei G) :=
linear_isometry_equiv.of_bounds
{ to_fun := continuous_multilinear_map.uncurry_right,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := continuous_multilinear_map.curry_right,
left_inv := continuous_multilinear_map.curry_uncurry_right,
right_inv := continuous_multilinear_map.uncurry_curry_right }
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables (n G')
/-- The space of continuous multilinear maps on `Π(i : fin (n+1)), G` is canonically isomorphic to
the space of continuous multilinear maps on `Π(i : fin n), G` with values in the space
of continuous linear maps on `G`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuous_multilinear_curry_right_equiv' 𝕜 n G G'`.
For a version allowing dependent types, see `continuous_multilinear_curry_right_equiv`. When there
are no dependent types, use the primed version as it helps Lean a lot for unification.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuous_multilinear_curry_right_equiv' :
(G [×n]→L[𝕜] (G →L[𝕜] G')) ≃ₗᵢ[𝕜] (G [×n.succ]→L[𝕜] G') :=
continuous_multilinear_curry_right_equiv 𝕜 (λ (i : fin n.succ), G) G'
variables {n 𝕜 G Ei G'}
@[simp] lemma continuous_multilinear_curry_right_equiv_apply
(f : (continuous_multilinear_map 𝕜 (λ(i : fin n), Ei i.cast_succ) (Ei (last n) →L[𝕜] G)))
(v : Π i, Ei i) :
(continuous_multilinear_curry_right_equiv 𝕜 Ei G) f v = f (init v) (v (last n)) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply
(f : continuous_multilinear_map 𝕜 Ei G)
(v : Π (i : fin n), Ei i.cast_succ) (x : Ei (last n)) :
(continuous_multilinear_curry_right_equiv 𝕜 Ei G).symm f v x = f (snoc v x) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_apply'
(f : G [×n]→L[𝕜] (G →L[𝕜] G')) (v : Π (i : fin n.succ), G) :
continuous_multilinear_curry_right_equiv' 𝕜 n G G' f v = f (init v) (v (last n)) := rfl
@[simp] lemma continuous_multilinear_curry_right_equiv_symm_apply'
(f : G [×n.succ]→L[𝕜] G') (v : Π (i : fin n), G) (x : G) :
(continuous_multilinear_curry_right_equiv' 𝕜 n G G').symm f v x = f (snoc v x) := rfl
@[simp] lemma continuous_multilinear_map.curry_right_norm
(f : continuous_multilinear_map 𝕜 Ei G) : ∥f.curry_right∥ = ∥f∥ :=
(continuous_multilinear_curry_right_equiv 𝕜 Ei G).symm.norm_map f
@[simp] lemma continuous_multilinear_map.uncurry_right_norm
(f : continuous_multilinear_map 𝕜 (λ i : fin n, Ei i.cast_succ) (Ei (last n) →L[𝕜] G)) :
∥f.uncurry_right∥ = ∥f∥ :=
(continuous_multilinear_curry_right_equiv 𝕜 Ei G).norm_map f
/-!
#### Currying with `0` variables
The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an
arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!).
Therefore, the space of continuous multilinear maps on `(fin 0) → G` with values in `E₂` is
isomorphic (and even isometric) to `E₂`. As this is the zeroth step in the construction of iterated
derivatives, we register this isomorphism. -/
section
local attribute [instance] unique.subsingleton
variables {𝕜 G G'}
/-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/
def continuous_multilinear_map.uncurry0
(f : continuous_multilinear_map 𝕜 (λ (i : fin 0), G) G') : G' := f 0
variables (𝕜 G)
/-- Associating to an element `x` of a vector space `E₂` the continuous multilinear map in `0`
variables taking the (unique) value `x` -/
def continuous_multilinear_map.curry0 (x : G') : G [×0]→L[𝕜] G' :=
{ to_fun := λm, x,
map_add' := λ m i, fin.elim0 i,
map_smul' := λ m i, fin.elim0 i,
cont := continuous_const }
variable {G}
@[simp] lemma continuous_multilinear_map.curry0_apply (x : G') (m : (fin 0) → G) :
continuous_multilinear_map.curry0 𝕜 G x m = x := rfl
variable {𝕜}
@[simp] lemma continuous_multilinear_map.uncurry0_apply (f : G [×0]→L[𝕜] G') :
f.uncurry0 = f 0 := rfl
@[simp] lemma continuous_multilinear_map.apply_zero_curry0 (f : G [×0]→L[𝕜] G') {x : fin 0 → G} :
continuous_multilinear_map.curry0 𝕜 G (f x) = f :=
by { ext m, simp [(subsingleton.elim _ _ : x = m)] }
lemma continuous_multilinear_map.uncurry0_curry0 (f : G [×0]→L[𝕜] G') :
continuous_multilinear_map.curry0 𝕜 G (f.uncurry0) = f :=
by simp
variables (𝕜 G)
@[simp] lemma continuous_multilinear_map.curry0_uncurry0 (x : G') :
(continuous_multilinear_map.curry0 𝕜 G x).uncurry0 = x := rfl
@[simp] lemma continuous_multilinear_map.curry0_norm (x : G') :
∥continuous_multilinear_map.curry0 𝕜 G x∥ = ∥x∥ :=
begin
apply le_antisymm,
{ exact continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm, by simp) },
{ simpa using (continuous_multilinear_map.curry0 𝕜 G x).le_op_norm 0 }
end
variables {𝕜 G}
@[simp] lemma continuous_multilinear_map.fin0_apply_norm (f : G [×0]→L[𝕜] G') {x : fin 0 → G} :
∥f x∥ = ∥f∥ :=
begin
have : x = 0 := subsingleton.elim _ _, subst this,
refine le_antisymm (by simpa using f.le_op_norm 0) _,
have : ∥continuous_multilinear_map.curry0 𝕜 G (f.uncurry0)∥ ≤ ∥f.uncurry0∥ :=
continuous_multilinear_map.op_norm_le_bound _ (norm_nonneg _) (λm,
by simp [-continuous_multilinear_map.apply_zero_curry0]),
simpa
end
lemma continuous_multilinear_map.uncurry0_norm (f : G [×0]→L[𝕜] G') : ∥f.uncurry0∥ = ∥f∥ :=
by simp
variables (𝕜 G G')
/-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear
maps in `0` variables with values in this normed space.
The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full
framework of linear isometric equivs. -/
def continuous_multilinear_curry_fin0 : (G [×0]→L[𝕜] G') ≃ₗᵢ[𝕜] G' :=
{ to_fun := λf, continuous_multilinear_map.uncurry0 f,
inv_fun := λf, continuous_multilinear_map.curry0 𝕜 G f,
map_add' := λf g, rfl,
map_smul' := λc f, rfl,
left_inv := continuous_multilinear_map.uncurry0_curry0,
right_inv := continuous_multilinear_map.curry0_uncurry0 𝕜 G,
norm_map' := continuous_multilinear_map.uncurry0_norm }
variables {𝕜 G G'}
@[simp] lemma continuous_multilinear_curry_fin0_apply (f : G [×0]→L[𝕜] G') :
continuous_multilinear_curry_fin0 𝕜 G G' f = f 0 := rfl
@[simp] lemma continuous_multilinear_curry_fin0_symm_apply (x : G') (v : (fin 0) → G) :
(continuous_multilinear_curry_fin0 𝕜 G G').symm x v = x := rfl
end
/-! #### With 1 variable -/
variables (𝕜 G G')
/-- Continuous multilinear maps from `G^1` to `G'` are isomorphic with continuous linear maps from
`G` to `G'`. -/
def continuous_multilinear_curry_fin1 : (G [×1]→L[𝕜] G') ≃ₗᵢ[𝕜] (G →L[𝕜] G') :=
(continuous_multilinear_curry_right_equiv 𝕜 (λ (i : fin 1), G) G').symm.trans
(continuous_multilinear_curry_fin0 𝕜 G (G →L[𝕜] G'))
variables {𝕜 G G'}
@[simp] lemma continuous_multilinear_curry_fin1_apply (f : G [×1]→L[𝕜] G') (x : G) :
continuous_multilinear_curry_fin1 𝕜 G G' f x = f (fin.snoc 0 x) := rfl
@[simp] lemma continuous_multilinear_curry_fin1_symm_apply
(f : G →L[𝕜] G') (v : (fin 1) → G) :
(continuous_multilinear_curry_fin1 𝕜 G G').symm f v = f (v 0) := rfl
namespace continuous_multilinear_map
variables (𝕜 G G')
/-- An equivalence of the index set defines a linear isometric equivalence between the spaces
of multilinear maps. -/
def dom_dom_congr (σ : ι ≃ ι') :
continuous_multilinear_map 𝕜 (λ _ : ι, G) G' ≃ₗᵢ[𝕜]
continuous_multilinear_map 𝕜 (λ _ : ι', G) G' :=
linear_isometry_equiv.of_bounds
{ to_fun := λ f, (multilinear_map.dom_dom_congr σ f.to_multilinear_map).mk_continuous ∥f∥ $
λ m, (f.le_op_norm (λ i, m (σ i))).trans_eq $ by rw [← σ.prod_comp],
inv_fun := λ f, (multilinear_map.dom_dom_congr σ.symm f.to_multilinear_map).mk_continuous ∥f∥ $
λ m, (f.le_op_norm (λ i, m (σ.symm i))).trans_eq $ by rw [← σ.symm.prod_comp],
left_inv := λ f, ext $ λ m, congr_arg f $ by simp only [σ.symm_apply_apply],
right_inv := λ f, ext $ λ m, congr_arg f $ by simp only [σ.apply_symm_apply],
map_add' := λ f g, rfl,
map_smul' := λ c f, rfl }
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
variables {𝕜 G G'}
section
variable [decidable_eq (ι ⊕ ι')]
/-- A continuous multilinear map with variables indexed by `ι ⊕ ι'` defines a continuous multilinear
map with variables indexed by `ι` taking values in the space of continuous multilinear maps with
variables indexed by `ι'`. -/
def curry_sum (f : continuous_multilinear_map 𝕜 (λ x : ι ⊕ ι', G) G') :
continuous_multilinear_map 𝕜 (λ x : ι, G) (continuous_multilinear_map 𝕜 (λ x : ι', G) G') :=
multilinear_map.mk_continuous_multilinear (multilinear_map.curry_sum f.to_multilinear_map) (∥f∥) $
λ m m', by simpa [fintype.prod_sum_type, mul_assoc] using f.le_op_norm (sum.elim m m')
@[simp] lemma curry_sum_apply (f : continuous_multilinear_map 𝕜 (λ x : ι ⊕ ι', G) G')
(m : ι → G) (m' : ι' → G) :
f.curry_sum m m' = f (sum.elim m m') :=
rfl
/-- A continuous multilinear map with variables indexed by `ι` taking values in the space of
continuous multilinear maps with variables indexed by `ι'` defines a continuous multilinear map with
variables indexed by `ι ⊕ ι'`. -/
def uncurry_sum
(f : continuous_multilinear_map 𝕜 (λ x : ι, G) (continuous_multilinear_map 𝕜 (λ x : ι', G) G')) :
continuous_multilinear_map 𝕜 (λ x : ι ⊕ ι', G) G' :=
multilinear_map.mk_continuous
(to_multilinear_map_linear.comp_multilinear_map f.to_multilinear_map).uncurry_sum (∥f∥) $ λ m,
by simpa [fintype.prod_sum_type, mul_assoc]
using (f (m ∘ sum.inl)).le_of_op_norm_le (m ∘ sum.inr) (f.le_op_norm _)
@[simp] lemma uncurry_sum_apply
(f : continuous_multilinear_map 𝕜 (λ x : ι, G) (continuous_multilinear_map 𝕜 (λ x : ι', G) G'))
(m : ι ⊕ ι' → G) :
f.uncurry_sum m = f (m ∘ sum.inl) (m ∘ sum.inr) :=
rfl
variables (𝕜 ι ι' G G')
/-- Linear isometric equivalence between the space of continuous multilinear maps with variables
indexed by `ι ⊕ ι'` and the space of continuous multilinear maps with variables indexed by `ι`
taking values in the space of continuous multilinear maps with variables indexed by `ι'`.
The forward and inverse functions are `continuous_multilinear_map.curry_sum`
and `continuous_multilinear_map.uncurry_sum`. Use this definition only if you need
some properties of `linear_isometry_equiv`. -/
def curry_sum_equiv : continuous_multilinear_map 𝕜 (λ x : ι ⊕ ι', G) G' ≃ₗᵢ[𝕜]
continuous_multilinear_map 𝕜 (λ x : ι, G) (continuous_multilinear_map 𝕜 (λ x : ι', G) G') :=
linear_isometry_equiv.of_bounds
{ to_fun := curry_sum,
inv_fun := uncurry_sum,
map_add' := λ f g, by { ext, refl },
map_smul' := λ c f, by { ext, refl },
left_inv := λ f, by { ext m, exact congr_arg f (sum.elim_comp_inl_inr m) },
right_inv := λ f, by { ext m₁ m₂, change f _ _ = f _ _,
rw [sum.elim_comp_inl, sum.elim_comp_inr] } }
(λ f, multilinear_map.mk_continuous_multilinear_norm_le _ (norm_nonneg f) _)
(λ f, multilinear_map.mk_continuous_norm_le _ (norm_nonneg f) _)
end
section
variables (𝕜 G G') {k l : ℕ} {s : finset (fin n)}
/-- If `s : finset (fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of continuous multilinear maps `G [×n]→L[𝕜] G'` of `n` variables is isomorphic
to the space of continuous multilinear maps `G [×k]→L[𝕜] G [×l]→L[𝕜] G'` of `k` variables taking
values in the space of continuous multilinear maps of `l` variables. -/
def curry_fin_finset {k l n : ℕ} {s : finset (fin n)}
(hk : s.card = k) (hl : sᶜ.card = l) :
(G [×n]→L[𝕜] G') ≃ₗᵢ[𝕜] (G [×k]→L[𝕜] G [×l]→L[𝕜] G') :=
(dom_dom_congr 𝕜 G G' (fin_sum_equiv_of_finset hk hl).symm).trans
(curry_sum_equiv 𝕜 (fin k) (fin l) G G')
variables {𝕜 G G'}
@[simp] lemma curry_fin_finset_apply (hk : s.card = k) (hl : sᶜ.card = l)
(f : G [×n]→L[𝕜] G') (mk : fin k → G) (ml : fin l → G) :
curry_fin_finset 𝕜 G G' hk hl f mk ml =
f (λ i, sum.elim mk ml ((fin_sum_equiv_of_finset hk hl).symm i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply (hk : s.card = k) (hl : sᶜ.card = l)
(f : G [×k]→L[𝕜] G [×l]→L[𝕜] G') (m : fin n → G) :
(curry_fin_finset 𝕜 G G' hk hl).symm f m =
f (λ i, m $ fin_sum_equiv_of_finset hk hl (sum.inl i))
(λ i, m $ fin_sum_equiv_of_finset hk hl (sum.inr i)) :=
rfl
@[simp] lemma curry_fin_finset_symm_apply_piecewise_const (hk : s.card = k) (hl : sᶜ.card = l)
(f : G [×k]→L[𝕜] G [×l]→L[𝕜] G') (x y : G) :
(curry_fin_finset 𝕜 G G' hk hl).symm f (s.piecewise (λ _, x) (λ _, y)) = f (λ _, x) (λ _, y) :=
multilinear_map.curry_fin_finset_symm_apply_piecewise_const hk hl _ x y
@[simp] lemma curry_fin_finset_symm_apply_const (hk : s.card = k) (hl : sᶜ.card = l)
(f : G [×k]→L[𝕜] G [×l]→L[𝕜] G') (x : G) :
(curry_fin_finset 𝕜 G G' hk hl).symm f (λ _, x) = f (λ _, x) (λ _, x) :=
rfl
@[simp] lemma curry_fin_finset_apply_const (hk : s.card = k) (hl : sᶜ.card = l)
(f : G [×n]→L[𝕜] G') (x y : G) :
curry_fin_finset 𝕜 G G' hk hl f (λ _, x) (λ _, y) = f (s.piecewise (λ _, x) (λ _, y)) :=
begin
refine (curry_fin_finset_symm_apply_piecewise_const hk hl _ _ _).symm.trans _, -- `rw` fails
rw linear_isometry_equiv.symm_apply_apply
end
end
end continuous_multilinear_map
end currying
|
b81116cb2e417842f335bad7680b0bd114b1da5e
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/src/deprecated/subfield.lean
|
12239b30ba1742a87f9d26362487fa609bb55cf0
|
[
"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
| 5,829
|
lean
|
/-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import deprecated.subring
import algebra.group_with_zero.power
/-
# Unbundled subfields
This file introduces the predicate `is_subfield` on `S : set F` where `F` is a field.
This is *not* the preferred way to do subfields in Lean 3: in general `S : subfield F`
works more smoothly.
## Main definitions
`is_subfield (S : set F)` : the predicate that `S` is the underlying set of a subfield
of the field `F`. Note that the bundled variant `subfield F` is preferred to this approach.
## Tags
is_subfield
-/
variables {F : Type*} [field F] (S : set F)
structure is_subfield extends is_subring S : Prop :=
(inv_mem : ∀ {x : F}, x ∈ S → x⁻¹ ∈ S)
lemma is_subfield.div_mem {S : set F} (hS : is_subfield S) {x y : F} (hx : x ∈ S) (hy : y ∈ S) :
x / y ∈ S :=
by { rw div_eq_mul_inv, exact hS.to_is_subring.to_is_submonoid.mul_mem hx (hS.inv_mem hy) }
lemma is_subfield.pow_mem {a : F} {n : ℤ} {s : set F} (hs : is_subfield s) (h : a ∈ s) :
a ^ n ∈ s :=
begin
cases n,
{ rw gpow_of_nat, exact hs.to_is_subring.to_is_submonoid.pow_mem h },
{ rw gpow_neg_succ_of_nat, exact hs.inv_mem (hs.to_is_subring.to_is_submonoid.pow_mem h) },
end
lemma univ.is_subfield : is_subfield (@set.univ F) :=
{ inv_mem := by intros; trivial,
..univ.is_submonoid,
..is_add_subgroup.univ_add_subgroup }
lemma preimage.is_subfield {K : Type*} [field K]
(f : F →+* K) {s : set K} (hs : is_subfield s) : is_subfield (f ⁻¹' s) :=
{ inv_mem := λ a (ha : f a ∈ s), show f a⁻¹ ∈ s,
by { rw [f.map_inv],
exact hs.inv_mem ha },
..f.is_subring_preimage hs.to_is_subring }
lemma image.is_subfield {K : Type*} [field K]
(f : F →+* K) {s : set F} (hs : is_subfield s) : is_subfield (f '' s) :=
{ inv_mem := λ a ⟨x, xmem, ha⟩, ⟨x⁻¹, hs.inv_mem xmem, ha ▸ f.map_inv _⟩,
..f.is_subring_image hs.to_is_subring }
lemma range.is_subfield {K : Type*} [field K]
(f : F →+* K) : is_subfield (set.range f) :=
by { rw ← set.image_univ, apply image.is_subfield _ univ.is_subfield }
namespace field
/-- `field.closure s` is the minimal subfield that includes `s`. -/
def closure : set F :=
{ x | ∃ y ∈ ring.closure S, ∃ z ∈ ring.closure S, y / z = x }
variables {S}
theorem ring_closure_subset : ring.closure S ⊆ closure S :=
λ x hx, ⟨x, hx, 1, ring.closure.is_subring.to_is_submonoid.one_mem, div_one x⟩
lemma closure.is_submonoid : is_submonoid (closure S) :=
{ mul_mem := by rintros _ _ ⟨p, hp, q, hq, hq0, rfl⟩ ⟨r, hr, s, hs, hs0, rfl⟩;
exact ⟨p * r,
is_submonoid.mul_mem ring.closure.is_subring.to_is_submonoid hp hr,
q * s,
is_submonoid.mul_mem ring.closure.is_subring.to_is_submonoid hq hs,
(div_mul_div _ _ _ _).symm⟩,
one_mem := ring_closure_subset $ is_submonoid.one_mem ring.closure.is_subring.to_is_submonoid }
lemma closure.is_subfield : is_subfield (closure S) :=
have h0 : (0:F) ∈ closure S, from ring_closure_subset $
ring.closure.is_subring.to_is_add_subgroup.to_is_add_submonoid.zero_mem,
{ add_mem := begin
intros a b ha hb,
rcases (id ha) with ⟨p, hp, q, hq, rfl⟩,
rcases (id hb) with ⟨r, hr, s, hs, rfl⟩,
classical, by_cases hq0 : q = 0, by simp [hb, hq0], by_cases hs0 : s = 0, by simp [ha, hs0],
exact ⟨p * s + q * r, is_add_submonoid.add_mem
ring.closure.is_subring.to_is_add_subgroup.to_is_add_submonoid
(ring.closure.is_subring.to_is_submonoid.mul_mem hp hs)
(ring.closure.is_subring.to_is_submonoid.mul_mem hq hr), q * s,
ring.closure.is_subring.to_is_submonoid.mul_mem hq hs,
(div_add_div p r hq0 hs0).symm⟩
end,
zero_mem := h0,
neg_mem := begin
rintros _ ⟨p, hp, q, hq, rfl⟩,
exact ⟨-p, ring.closure.is_subring.to_is_add_subgroup.neg_mem hp, q, hq, neg_div q p⟩
end,
inv_mem := begin
rintros _ ⟨p, hp, q, hq, rfl⟩,
classical, by_cases hp0 : p = 0, by simp [hp0, h0],
exact ⟨q, hq, p, hp, inv_div.symm⟩
end,
..closure.is_submonoid }
theorem mem_closure {a : F} (ha : a ∈ S) : a ∈ closure S :=
ring_closure_subset $ ring.mem_closure ha
theorem subset_closure : S ⊆ closure S :=
λ _, mem_closure
theorem closure_subset {T : set F} (hT : is_subfield T) (H : S ⊆ T) : closure S ⊆ T :=
by rintros _ ⟨p, hp, q, hq, hq0, rfl⟩; exact hT.div_mem (ring.closure_subset hT.to_is_subring H hp)
(ring.closure_subset hT.to_is_subring H hq)
theorem closure_subset_iff {s t : set F} (ht : is_subfield t) : closure s ⊆ t ↔ s ⊆ t :=
⟨set.subset.trans subset_closure, closure_subset ht⟩
theorem closure_mono {s t : set F} (H : s ⊆ t) : closure s ⊆ closure t :=
closure_subset closure.is_subfield $ set.subset.trans H subset_closure
end field
lemma is_subfield_Union_of_directed {ι : Type*} [hι : nonempty ι]
{s : ι → set F} (hs : ∀ i, is_subfield (s i))
(directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
is_subfield (⋃i, s i) :=
{ inv_mem := λ x hx, let ⟨i, hi⟩ := set.mem_Union.1 hx in
set.mem_Union.2 ⟨i, (hs i).inv_mem hi⟩,
to_is_subring := is_subring_Union_of_directed (λ i, (hs i).to_is_subring) directed }
lemma is_subfield.inter {S₁ S₂ : set F} (hS₁ : is_subfield S₁) (hS₂ : is_subfield S₂) :
is_subfield (S₁ ∩ S₂) :=
{ inv_mem := λ x hx, ⟨hS₁.inv_mem hx.1, hS₂.inv_mem hx.2⟩,
..is_subring.inter hS₁.to_is_subring hS₂.to_is_subring }
lemma is_subfield.Inter {ι : Sort*} {S : ι → set F} (h : ∀ y : ι, is_subfield (S y)) :
is_subfield (set.Inter S) :=
{ inv_mem := λ x hx, set.mem_Inter.2 $ λ y, (h y).inv_mem $ set.mem_Inter.1 hx y,
..is_subring.Inter (λ y, (h y).to_is_subring)
}
|
86fd14c7ec8c89c24983c6697ef3199e4e2a2028
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/data/finsupp/basic.lean
|
b33c567e7b050a05d0dbcff23b3a91288f7874fe
|
[
"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
| 79,236
|
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, Scott Morrison
-/
import algebra.group.pi
import algebra.big_operators.order
import algebra.module.linear_map
import data.fintype.card
import data.finset.preimage
import data.multiset.antidiagonal
/-!
# Type of functions with finite support
For any type `α` and a type `M` with zero, we define the type `finsupp α M` (notation: `α →₀ M`)
of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere
on `α` except on a finite set.
Functions with finite support are used (at least) in the following parts of the library:
* `monoid_algebra R M` and `add_monoid_algebra R M` are defined as `M →₀ R`;
* polynomials and multivariate polynomials are defined as `add_monoid_algebra`s, hence they use
`finsupp` under the hood;
* the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to
define linearly independent family `linear_independent`) is defined as a map
`finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`.
Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined
in a different way in the library:
* `multiset α ≃+ α →₀ ℕ`;
* `free_abelian_group α ≃+ α →₀ ℤ`.
Most of the theory assumes that the range is a commutative additive monoid. This gives us the big
sum operator as a powerful way to construct `finsupp` elements.
Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type
instances. E.g., `monoid_algebra`, `add_monoid_algebra`, and types based on these two have
non-pointwise multiplication.
## Notations
This file adds `α →₀ M` as a global notation for `finsupp α M`. We also use the following convention
for `Type*` variables in this file
* `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `finsupp`
somewhere in the statement;
* `ι` : an auxiliary index type;
* `M`, `M'`, `N`, `P`: types with `has_zero` or `(add_)(comm_)monoid` structure; `M` is also used
for a (semi)module over a (semi)ring.
* `G`, `H`: groups (commutative or not, multiplicative or additive);
* `R`, `S`: (semi)rings.
## TODO
* This file is currently ~2K lines long, so possibly it should be splitted into smaller chunks;
* Add the list of definitions and important lemmas to the module docstring.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## Notation
This file defines `α →₀ β` as notation for `finsupp α β`.
-/
noncomputable theory
open_locale classical big_operators
open finset
variables {α β γ ι M M' N P G H R S : Type*}
/-- `finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
`f x = 0` for all but finitely many `x`. -/
structure finsupp (α : Type*) (M : Type*) [has_zero M] :=
(support : finset α)
(to_fun : α → M)
(mem_support_to_fun : ∀a, a ∈ support ↔ to_fun a ≠ 0)
infixr ` →₀ `:25 := finsupp
namespace finsupp
/-! ### Basic declarations about `finsupp` -/
section basic
variable [has_zero M]
instance : has_coe_to_fun (α →₀ M) := ⟨λ _, α → M, to_fun⟩
@[simp] lemma coe_mk (f : α → M) (s : finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) :
⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl
instance : has_zero (α →₀ M) := ⟨⟨∅, (λ _, 0), λ _, ⟨false.elim, λ H, H rfl⟩⟩⟩
@[simp] lemma coe_zero : ⇑(0 : α →₀ M) = (λ _, (0:M)) := rfl
lemma zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl
@[simp] lemma support_zero : (0 : α →₀ M).support = ∅ := rfl
instance : inhabited (α →₀ M) := ⟨0⟩
@[simp] lemma mem_support_iff {f : α →₀ M} : ∀{a:α}, a ∈ f.support ↔ f a ≠ 0 :=
f.mem_support_to_fun
lemma not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
lemma injective_coe_fn : function.injective (show (α →₀ M) → α → M, from coe_fn)
| ⟨s, f, hf⟩ ⟨t, g, hg⟩ h :=
begin
change f = g at h, subst h,
have : s = t, { ext a, exact (hf a).trans (hg a).symm },
subst this
end
@[ext] lemma ext {f g : α →₀ M} (h : ∀a, f a = g a) : f = g := injective_coe_fn (funext h)
lemma ext_iff {f g : α →₀ M} : f = g ↔ (∀a:α, f a = g a) :=
⟨by rintros rfl a; refl, ext⟩
lemma ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨λ h, h ▸ ⟨rfl, λ _ _, rfl⟩, λ ⟨h₁, h₂⟩, ext $ λ a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, from not_mem_support_iff.1 h,
have hg : g a = 0, by rwa [h₁, not_mem_support_iff] at h,
by rw [hf, hg]⟩
@[simp] lemma support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
⟨assume h, ext $ assume a, by_contradiction $ λ H, (finset.ext_iff.1 h a).1 $
mem_support_iff.2 H, by rintro rfl; refl⟩
lemma card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 :=
by simp
instance finsupp.decidable_eq [decidable_eq α] [decidable_eq M] : decidable_eq (α →₀ M) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀a∈f.support, f a = g a)) ext_iff'.symm
lemma finite_supp (f : α →₀ M) : set.finite {a | f a ≠ 0} :=
⟨fintype.of_finset f.support (λ _, mem_support_iff)⟩
lemma support_subset_iff {s : set α} {f : α →₀ M} :
↑f.support ⊆ s ↔ (∀a∉s, f a = 0) :=
by simp only [set.subset_def, mem_coe, mem_support_iff];
exact forall_congr (assume a, not_imp_comm)
/-- Given `fintype α`, `equiv_fun_on_fintype` is the `equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
def equiv_fun_on_fintype [fintype α] : (α →₀ M) ≃ (α → M) :=
⟨λf a, f a, λf, mk (finset.univ.filter $ λa, f a ≠ 0) f (by simp only [true_and, finset.mem_univ,
iff_self, finset.mem_filter, finset.filter_congr_decidable, forall_true_iff]),
begin intro f, ext a, refl end,
begin intro f, ext a, refl end⟩
end basic
/-! ### Declarations about `single` -/
section single
variables [has_zero M] {a a' : α} {b : M}
/-- `single a b` is the finitely supported function which has
value `b` at `a` and zero otherwise. -/
def single (a : α) (b : M) : α →₀ M :=
⟨if b = 0 then ∅ else {a}, λ a', if a = a' then b else 0, λ a', begin
by_cases hb : b = 0; by_cases a = a';
simp only [hb, h, if_pos, if_false, mem_singleton],
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨λ _, hb, λ _, rfl⟩ },
{ exact ⟨λ H _, h H.symm, λ H, (H rfl).elim⟩ }
end⟩
lemma single_apply : (single a b : α →₀ M) a' = if a = a' then b else 0 :=
rfl
@[simp] lemma single_eq_same : (single a b : α →₀ M) a = b :=
if_pos rfl
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 :=
if_neg h
@[simp] lemma single_zero : (single a 0 : α →₀ M) = 0 :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, single_eq_same, zero_apply] },
{ rw [single_eq_of_ne h, zero_apply] }
end
lemma support_single_ne_zero (hb : b ≠ 0) : (single a b).support = {a} :=
if_neg hb
lemma support_single_subset : (single a b).support ⊆ {a} :=
show ite _ _ _ ⊆ _, by split_ifs; [exact empty_subset _, exact subset.refl _]
lemma single_injective (a : α) : function.injective (single a : M → α →₀ M) :=
assume b₁ b₂ eq,
have (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a, by rw eq,
by rwa [single_eq_same, single_eq_same] at this
lemma mem_support_single (a a' : α) (b : M) :
a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 :=
⟨λ H : (a ∈ ite _ _ _), if h : b = 0
then by rw if_pos h at H; exact H.elim
else ⟨by rw if_neg h at H; exact mem_singleton.1 H, h⟩,
λ ⟨h1, h2⟩, show a ∈ ite _ _ _, by rw [if_neg h2]; exact mem_singleton.2 h1⟩
lemma eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b :=
begin
refine ⟨λ h, h.symm ▸ ⟨support_single_subset, single_eq_same⟩, _⟩,
rintro ⟨h, rfl⟩,
ext x,
by_cases hx : a = x; simp only [hx, single_eq_same, single_eq_of_ne, ne.def, not_false_iff],
exact not_mem_support_iff.1 (mt (λ hx, (mem_singleton.1 (h hx)).symm) hx)
end
lemma single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) :
single a₁ b₁ = single a₂ b₂ ↔ ((a₁ = a₂ ∧ b₁ = b₂) ∨ (b₁ = 0 ∧ b₂ = 0)) :=
begin
split,
{ assume eq,
by_cases a₁ = a₂,
{ refine or.inl ⟨h, _⟩,
rwa [h, (single_injective a₂).eq_iff] at eq },
{ rw [ext_iff] at eq,
have h₁ := eq a₁,
have h₂ := eq a₂,
simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (ne.symm h)] at h₁ h₂,
exact or.inr ⟨h₁, h₂.symm⟩ } },
{ rintros (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩),
{ refl },
{ rw [single_zero, single_zero] } }
end
lemma single_left_inj (h : b ≠ 0) :
single a b = single a' b ↔ a = a' :=
⟨λ H, by simpa only [h, single_eq_single_iff,
and_false, or_false, eq_self_iff_true, and_true] using H,
λ H, by rw [H]⟩
lemma single_eq_zero : single a b = 0 ↔ b = 0 :=
⟨λ h, by { rw ext_iff at h, simpa only [single_eq_same, zero_apply] using h a },
λ h, by rw [h, single_zero]⟩
lemma single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ :=
by simp only [single_apply]; ac_refl
instance [nonempty α] [nontrivial M] : nontrivial (α →₀ M) :=
begin
inhabit α,
rcases exists_ne (0 : M) with ⟨x, hx⟩,
exact nontrivial_of_ne (single (default α) x) 0 (mt single_eq_zero.1 hx)
end
lemma unique_single [unique α] (x : α →₀ M) : x = single (default α) (x (default α)) :=
ext $ unique.forall_iff.2 single_eq_same.symm
lemma unique_ext [unique α] {f g : α →₀ M} (h : f (default α) = g (default α)) : f = g :=
ext $ λ a, by rwa [unique.eq_default a]
lemma unique_ext_iff [unique α] {f g : α →₀ M} : f = g ↔ f (default α) = g (default α) :=
⟨λ h, h ▸ rfl, unique_ext⟩
@[simp] lemma unique_single_eq_iff [unique α] {b' : M} :
single a b = single a' b' ↔ b = b' :=
by rw [unique_ext_iff, unique.eq_default a, unique.eq_default a', single_eq_same, single_eq_same]
lemma support_eq_singleton {f : α →₀ M} {a : α} :
f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) :=
⟨λ h, ⟨mem_support_iff.1 $ h.symm ▸ finset.mem_singleton_self a,
eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, λ h, h.2.symm ▸ support_single_ne_zero h.1⟩
lemma support_eq_singleton' {f : α →₀ M} {a : α} :
f.support = {a} ↔ ∃ b ≠ 0, f = single a b :=
⟨λ h, let h := support_eq_singleton.1 h in ⟨_, h.1, h.2⟩,
λ ⟨b, hb, hf⟩, hf.symm ▸ support_single_ne_zero hb⟩
lemma card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) :=
by simp only [card_eq_one, support_eq_singleton]
lemma card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a (b ≠ 0), f = single a b :=
by simp only [card_eq_one, support_eq_singleton']
end single
/-! ### Declarations about `on_finset` -/
section on_finset
variables [has_zero M]
/-- `on_finset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function needs to be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def on_finset (s : finset α) (f : α → M) (hf : ∀a, f a ≠ 0 → a ∈ s) : α →₀ M :=
⟨s.filter (λa, f a ≠ 0), f, by simpa⟩
@[simp] lemma on_finset_apply {s : finset α} {f : α → M} {hf a} :
(on_finset s f hf : α →₀ M) a = f a :=
rfl
@[simp] lemma support_on_finset_subset {s : finset α} {f : α → M} {hf} :
(on_finset s f hf).support ⊆ s :=
filter_subset _
@[simp] lemma mem_support_on_finset
{s : finset α} {f : α → M} (hf : ∀ (a : α), f a ≠ 0 → a ∈ s) {a : α} :
a ∈ (finsupp.on_finset s f hf).support ↔ f a ≠ 0 :=
by rw [finsupp.mem_support_iff, finsupp.on_finset_apply]
lemma support_on_finset
{s : finset α} {f : α → M} (hf : ∀ (a : α), f a ≠ 0 → a ∈ s) :
(finsupp.on_finset s f hf).support = s.filter (λ a, f a ≠ 0) :=
rfl
end on_finset
/-! ### Declarations about `map_range` -/
section map_range
variables [has_zero M] [has_zero N]
/-- The composition of `f : M → N` and `g : α →₀ M` is
`map_range f hf g : α →₀ N`, well-defined when `f 0 = 0`. -/
def map_range (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
on_finset g.support (f ∘ g) $
assume a, by rw [mem_support_iff, not_imp_not]; exact λ H, (congr_arg f H).trans hf
@[simp] lemma map_range_apply {f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} :
map_range f hf g a = f (g a) :=
rfl
@[simp] lemma map_range_zero {f : M → N} {hf : f 0 = 0} : map_range f hf (0 : α →₀ M) = 0 :=
ext $ λ a, by simp only [hf, zero_apply, map_range_apply]
lemma support_map_range {f : M → N} {hf : f 0 = 0} {g : α →₀ M} :
(map_range f hf g).support ⊆ g.support :=
support_on_finset_subset
@[simp] lemma map_range_single {f : M → N} {hf : f 0 = 0} {a : α} {b : M} :
map_range f hf (single a b) = single a (f b) :=
ext $ λ a', show f (ite _ _ _) = ite _ _ _, by split_ifs; [refl, exact hf]
end map_range
/-! ### Declarations about `emb_domain` -/
section emb_domain
variables [has_zero M] [has_zero N]
/-- Given `f : α ↪ β` and `v : α →₀ M`, `emb_domain f v : β →₀ M`
is the finitely supported function whose value at `f a : β` is `v a`.
For a `b : β` outside the range of `f`, it is zero. -/
def emb_domain (f : α ↪ β) (v : α →₀ M) : β →₀ M :=
begin
refine ⟨v.support.map f, λa₂,
if h : a₂ ∈ v.support.map f then v (v.support.choose (λa₁, f a₁ = a₂) _) else 0, _⟩,
{ rcases finset.mem_map.1 h with ⟨a, ha, rfl⟩,
exact exists_unique.intro a ⟨ha, rfl⟩ (assume b ⟨_, hb⟩, f.injective hb) },
{ assume a₂,
split_ifs,
{ simp only [h, true_iff, ne.def],
rw [← not_mem_support_iff, not_not],
apply finset.choose_mem },
{ simp only [h, ne.def, ne_self_iff_false] } }
end
@[simp] lemma support_emb_domain (f : α ↪ β) (v : α →₀ M) :
(emb_domain f v).support = v.support.map f :=
rfl
@[simp] lemma emb_domain_zero (f : α ↪ β) : (emb_domain f 0 : β →₀ M) = 0 :=
rfl
@[simp] lemma emb_domain_apply (f : α ↪ β) (v : α →₀ M) (a : α) :
emb_domain f v (f a) = v a :=
begin
change dite _ _ _ = _,
split_ifs; rw [finset.mem_map' f] at h,
{ refine congr_arg (v : α → M) (f.inj' _),
exact finset.choose_property (λa₁, f a₁ = f a) _ _ },
{ exact (not_mem_support_iff.1 h).symm }
end
lemma emb_domain_notin_range (f : α ↪ β) (v : α →₀ M) (a : β) (h : a ∉ set.range f) :
emb_domain f v a = 0 :=
begin
refine dif_neg (mt (assume h, _) h),
rcases finset.mem_map.1 h with ⟨a, h, rfl⟩,
exact set.mem_range_self a
end
lemma emb_domain_injective (f : α ↪ β) :
function.injective (emb_domain f : (α →₀ M) → (β →₀ M)) :=
λ l₁ l₂ h, ext $ λ a, by simpa only [emb_domain_apply] using ext_iff.1 h (f a)
@[simp] lemma emb_domain_inj {f : α ↪ β} {l₁ l₂ : α →₀ M} :
emb_domain f l₁ = emb_domain f l₂ ↔ l₁ = l₂ :=
(emb_domain_injective f).eq_iff
@[simp] lemma emb_domain_eq_zero {f : α ↪ β} {l : α →₀ M} :
emb_domain f l = 0 ↔ l = 0 :=
(emb_domain_injective f).eq_iff' $ emb_domain_zero f
lemma emb_domain_map_range
(f : α ↪ β) (g : M → N) (p : α →₀ M) (hg : g 0 = 0) :
emb_domain f (map_range g hg p) = map_range g hg (emb_domain f p) :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a', rfl⟩,
rw [map_range_apply, emb_domain_apply, emb_domain_apply, map_range_apply] },
{ rw [map_range_apply, emb_domain_notin_range, emb_domain_notin_range, ← hg]; assumption }
end
lemma single_of_emb_domain_single
(l : α →₀ M) (f : α ↪ β) (a : β) (b : M) (hb : b ≠ 0)
(h : l.emb_domain f = single a b) :
∃ x, l = single x b ∧ f x = a :=
begin
have h_map_support : finset.map f (l.support) = {a},
by rw [←support_emb_domain, h, support_single_ne_zero hb]; refl,
have ha : a ∈ finset.map f (l.support),
by simp only [h_map_support, finset.mem_singleton],
rcases finset.mem_map.1 ha with ⟨c, hc₁, hc₂⟩,
use c,
split,
{ ext d,
rw [← emb_domain_apply f l, h],
by_cases h_cases : c = d,
{ simp only [eq.symm h_cases, hc₂, single_eq_same] },
{ rw [single_apply, single_apply, if_neg, if_neg h_cases],
by_contra hfd,
exact h_cases (f.injective (hc₂.trans hfd)) } },
{ exact hc₂ }
end
end emb_domain
/-! ### Declarations about `zip_with` -/
section zip_with
variables [has_zero M] [has_zero N] [has_zero P]
/-- `zip_with f hf g₁ g₂` is the finitely supported function satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, and it is well-defined when `f 0 0 = 0`. -/
def zip_with (f : M → N → P) (hf : f 0 0 = 0) (g₁ : α →₀ M) (g₂ : α →₀ N) : (α →₀ P) :=
on_finset (g₁.support ∪ g₂.support) (λa, f (g₁ a) (g₂ a)) $ λ a H,
begin
simp only [mem_union, mem_support_iff, ne], rw [← not_and_distrib],
rintro ⟨h₁, h₂⟩, rw [h₁, h₂] at H, exact H hf
end
@[simp] lemma zip_with_apply
{f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} {a : α} :
zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a) :=
rfl
lemma support_zip_with {f : M → N → P} {hf : f 0 0 = 0} {g₁ : α →₀ M} {g₂ : α →₀ N} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
support_on_finset_subset
end zip_with
/-! ### Declarations about `erase` -/
section erase
variables [has_zero M]
/-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to
`0`. -/
def erase (a : α) (f : α →₀ M) : α →₀ M :=
⟨f.support.erase a, (λa', if a' = a then 0 else f a'),
assume a', by rw [mem_erase, mem_support_iff]; split_ifs;
[exact ⟨λ H _, H.1 h, λ H, (H rfl).elim⟩,
exact and_iff_right h]⟩
@[simp] lemma support_erase {a : α} {f : α →₀ M} :
(f.erase a).support = f.support.erase a :=
rfl
@[simp] lemma erase_same {a : α} {f : α →₀ M} : (f.erase a) a = 0 :=
if_pos rfl
@[simp] lemma erase_ne {a a' : α} {f : α →₀ M} (h : a' ≠ a) : (f.erase a) a' = f a' :=
if_neg h
@[simp] lemma erase_single {a : α} {b : M} : (erase a (single a b)) = 0 :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, erase_same], refl },
{ rw [erase_ne hs], exact single_eq_of_ne (ne.symm hs) }
end
lemma erase_single_ne {a a' : α} {b : M} (h : a ≠ a') : (erase a (single a' b)) = single a' b :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, erase_same, single_eq_of_ne (h.symm)] },
{ rw [erase_ne hs] }
end
@[simp] lemma erase_zero (a : α) : erase a (0 : α →₀ M) = 0 :=
by rw [← support_eq_empty, support_erase, support_zero, erase_empty]
end erase
/-!
### Declarations about `sum` and `prod`
In most of this section, the domain `β` is assumed to be an `add_monoid`.
-/
section sum_prod
-- [to_additive sum] for finsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g a (f a)` over the support of `f`. -/
def sum [has_zero M] [add_comm_monoid N] (f : α →₀ M) (g : α → M → N) : N :=
∑ a in f.support, g a (f a)
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive]
def prod [has_zero M] [comm_monoid N] (f : α →₀ M) (g : α → M → N) : N :=
∏ a in f.support, g a (f a)
variables [has_zero M] [has_zero M'] [comm_monoid N]
@[to_additive]
lemma prod_of_support_subset (f : α →₀ M) {s : finset α}
(hs : f.support ⊆ s) (g : α → M → N) (h : ∀ i ∈ s, g i 0 = 1) :
f.prod g = ∏ x in s, g x (f x) :=
finset.prod_subset hs $ λ x hxs hx, h x hxs ▸ congr_arg (g x) $ not_mem_support_iff.1 hx
@[to_additive]
lemma prod_fintype [fintype α] (f : α →₀ M) (g : α → M → N) (h : ∀ i, g i 0 = 1) :
f.prod g = ∏ i, g i (f i) :=
f.prod_of_support_subset (subset_univ _) g (λ x _, h x)
@[simp, to_additive]
lemma prod_single_index {a : α} {b : M} {h : α → M → N} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
calc (single a b).prod h = ∏ x in {a}, h x (single a b x) :
prod_of_support_subset _ support_single_subset h $ λ x hx, (mem_singleton.1 hx).symm ▸ h_zero
... = h a b : by simp
@[to_additive]
lemma prod_map_range_index {f : M → M'} {hf : f 0 = 0} {g : α →₀ M} {h : α → M' → N}
(h0 : ∀a, h a 0 = 1) : (map_range f hf g).prod h = g.prod (λa b, h a (f b)) :=
finset.prod_subset support_map_range $ λ _ _ H,
by rw [not_mem_support_iff.1 H, h0]
@[simp, to_additive]
lemma prod_zero_index {h : α → M → N} : (0 : α →₀ M).prod h = 1 := rfl
@[to_additive]
lemma prod_comm (f : α →₀ M) (g : β →₀ M') (h : α → M → β → M' → N) :
f.prod (λ x v, g.prod (λ x' v', h x v x' v')) = g.prod (λ x' v', f.prod (λ x v, h x v x' v')) :=
finset.prod_comm
@[simp, to_additive]
lemma prod_ite_eq (f : α →₀ M) (a : α) (b : α → M → N) :
f.prod (λ x v, ite (a = x) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 :=
by { dsimp [finsupp.prod], rw f.support.prod_ite_eq, }
/-- A restatement of `prod_ite_eq` with the equality test reversed. -/
@[simp, to_additive "A restatement of `sum_ite_eq` with the equality test reversed."]
lemma prod_ite_eq' (f : α →₀ M) (a : α) (b : α → M → N) :
f.prod (λ x v, ite (x = a) (b x v) 1) = ite (a ∈ f.support) (b a (f a)) 1 :=
by { dsimp [finsupp.prod], rw f.support.prod_ite_eq', }
@[simp] lemma prod_pow [fintype α] (f : α →₀ ℕ) (g : α → N) :
f.prod (λ a b, g a ^ b) = ∏ a, g a ^ (f a) :=
f.prod_fintype _ $ λ a, pow_zero _
/-- If `g` maps a second argument of 0 to 1, then multiplying it over the
result of `on_finset` is the same as multiplying it over the original
`finset`. -/
@[to_additive "If `g` maps a second argument of 0 to 0, summing it over the
result of `on_finset` is the same as summing it over the original
`finset`."]
lemma on_finset_prod {s : finset α} {f : α → M} {g : α → M → N}
(hf : ∀a, f a ≠ 0 → a ∈ s) (hg : ∀ a, g a 0 = 1) :
(on_finset s f hf).prod g = ∏ a in s, g a (f a) :=
finset.prod_subset support_on_finset_subset $ by simp [*] { contextual := tt }
end sum_prod
/-!
### Additive monoid structure on `α →₀ M`
-/
section add_monoid
variables [add_monoid M]
instance : has_add (α →₀ M) := ⟨zip_with (+) (add_zero 0)⟩
@[simp] lemma add_apply {g₁ g₂ : α →₀ M} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a :=
rfl
lemma support_add {g₁ g₂ : α →₀ M} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
lemma support_add_eq {g₁ g₂ : α →₀ M} (h : disjoint g₁.support g₂.support) :
(g₁ + g₂).support = g₁.support ∪ g₂.support :=
le_antisymm support_zip_with $ assume a ha,
(finset.mem_union.1 ha).elim
(assume ha, have a ∉ g₂.support, from disjoint_left.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, add_zero])
(assume ha, have a ∉ g₁.support, from disjoint_right.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, zero_add])
@[simp] lemma single_add {a : α} {b₁ b₂ : M} : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, add_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [add_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, zero_add] }
end
instance : add_monoid (α →₀ M) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := assume ⟨s, f, hf⟩ ⟨t, g, hg⟩ ⟨u, h, hh⟩, ext $ assume a, add_assoc _ _ _,
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
/-- `finsupp.single` as an `add_monoid_hom`. -/
@[simps] def single_add_hom (a : α) : M →+ α →₀ M :=
⟨single a, single_zero, λ _ _, single_add⟩
/-- Evaluation of a function `f : α →₀ M` at a point as an additive monoid homomorphism. -/
def eval_add_hom (a : α) : (α →₀ M) →+ M := ⟨λ g, g a, zero_apply, λ _ _, add_apply⟩
@[simp] lemma eval_add_hom_apply (a : α) (g : α →₀ M) : eval_add_hom a g = g a := rfl
lemma single_add_erase (a : α) (f : α →₀ M) : single a (f a) + f.erase a = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, add_zero]
else by simp only [add_apply, single_eq_of_ne h, zero_add, erase_ne (ne.symm h)]
lemma erase_add_single (a : α) (f : α →₀ M) : f.erase a + single a (f a) = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, zero_add]
else by simp only [add_apply, single_eq_of_ne h, add_zero, erase_ne (ne.symm h)]
@[simp] lemma erase_add (a : α) (f f' : α →₀ M) : erase a (f + f') = erase a f + erase a f' :=
begin
ext s, by_cases hs : s = a,
{ rw [hs, add_apply, erase_same, erase_same, erase_same, add_zero] },
rw [add_apply, erase_ne hs, erase_ne hs, erase_ne hs, add_apply],
end
@[elab_as_eliminator]
protected theorem induction {p : (α →₀ M) → Prop} (f : α →₀ M)
(h0 : p 0) (ha : ∀a b (f : α →₀ M), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) :
p f :=
suffices ∀s (f : α →₀ M), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (single a (f a) + f.erase a), by rwa [single_add_erase] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma induction₂ {p : (α →₀ M) → Prop} (f : α →₀ M)
(h0 : p 0) (ha : ∀a b (f : α →₀ M), a ∉ f.support → b ≠ 0 → p f → p (f + single a b)) :
p f :=
suffices ∀s (f : α →₀ M), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (f.erase a + single a (f a)), by rwa [erase_add_single] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
@[simp] lemma add_closure_Union_range_single :
add_submonoid.closure (⋃ a : α, set.range (single a : M → α →₀ M)) = ⊤ :=
top_unique $ λ x hx, finsupp.induction x (add_submonoid.zero_mem _) $
λ a b f ha hb hf, add_submonoid.add_mem _
(add_submonoid.subset_closure $ set.mem_Union.2 ⟨a, set.mem_range_self _⟩) hf
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`, then
they are equal. -/
lemma add_hom_ext [add_monoid N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x y, f (single x y) = g (single x y)) :
f = g :=
begin
refine add_monoid_hom.eq_of_eq_on_mdense add_closure_Union_range_single (λ f hf, _),
simp only [set.mem_Union, set.mem_range] at hf,
rcases hf with ⟨x, y, rfl⟩,
apply H
end
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`, then
they are equal.
We formulate this using equality of `add_monoid_hom`s so that `ext` tactic can apply a type-specific
extensionality lemma after this one. E.g., if the fiber `M` is `ℕ` or `ℤ`, then it suffices to
verify `f (single a 1) = g (single a 1)`. -/
@[ext] lemma add_hom_ext' [add_monoid N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x, f.comp (single_add_hom x) = g.comp (single_add_hom x)) :
f = g :=
add_hom_ext $ λ x, add_monoid_hom.congr_fun (H x)
lemma mul_hom_ext [monoid N] ⦃f g : multiplicative (α →₀ M) →* N⦄
(H : ∀ x y, f (multiplicative.of_add $ single x y) = g (multiplicative.of_add $ single x y)) :
f = g :=
monoid_hom.ext $ add_monoid_hom.congr_fun $
@add_hom_ext α M (additive N) _ _ f.to_additive'' g.to_additive'' H
@[ext] lemma mul_hom_ext' [monoid N] {f g : multiplicative (α →₀ M) →* N}
(H : ∀ x, f.comp (single_add_hom x).to_multiplicative =
g.comp (single_add_hom x).to_multiplicative) :
f = g :=
mul_hom_ext $ λ x, monoid_hom.congr_fun (H x)
lemma map_range_add [add_monoid N]
{f : M → N} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ M) :
map_range f hf (v₁ + v₂) = map_range f hf v₁ + map_range f hf v₂ :=
ext $ λ a, by simp only [hf', add_apply, map_range_apply]
end add_monoid
section nat_sub
instance nat_sub : has_sub (α →₀ ℕ) := ⟨zip_with (λ m n, m - n) (nat.sub_zero 0)⟩
@[simp] lemma nat_sub_apply {g₁ g₂ : α →₀ ℕ} {a : α} :
(g₁ - g₂) a = g₁ a - g₂ a :=
rfl
@[simp] lemma single_sub {a : α} {n₁ n₂ : ℕ} : single a (n₁ - n₂) = single a n₁ - single a n₂ :=
begin
ext f,
by_cases h : (a = f),
{ rw [h, nat_sub_apply, single_eq_same, single_eq_same, single_eq_same] },
rw [nat_sub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h]
end
-- These next two lemmas are used in developing
-- the partial derivative on `mv_polynomial`.
lemma sub_single_one_add {a : α} {u u' : α →₀ ℕ} (h : u a ≠ 0) :
u - single a 1 + u' = u + u' - single a 1 :=
begin
ext b,
rw [add_apply, nat_sub_apply, nat_sub_apply, add_apply],
by_cases h : a = b,
{ rw [←h, single_eq_same], cases (u a), { contradiction }, { simp }, },
{ simp [h], }
end
lemma add_sub_single_one {a : α} {u u' : α →₀ ℕ} (h : u' a ≠ 0) :
u + (u' - single a 1) = u + u' - single a 1 :=
begin
ext b,
rw [add_apply, nat_sub_apply, nat_sub_apply, add_apply],
by_cases h : a = b,
{ rw [←h, single_eq_same], cases (u' a), { contradiction }, { simp }, },
{ simp [h], }
end
end nat_sub
instance [add_comm_monoid M] : add_comm_monoid (α →₀ M) :=
{ add_comm := assume ⟨s, f, _⟩ ⟨t, g, _⟩, ext $ assume a, add_comm _ _,
.. finsupp.add_monoid }
instance [add_group G] : add_group (α →₀ G) :=
{ neg := map_range (has_neg.neg) neg_zero,
add_left_neg := assume ⟨s, f, _⟩, ext $ assume x, add_left_neg _,
.. finsupp.add_monoid }
instance [add_comm_group G] : add_comm_group (α →₀ G) :=
{ add_comm := add_comm, ..finsupp.add_group }
lemma single_multiset_sum [add_comm_monoid M] (s : multiset M) (a : α) :
single a s.sum = (s.map (single a)).sum :=
multiset.induction_on s single_zero $ λ a s ih,
by rw [multiset.sum_cons, single_add, ih, multiset.map_cons, multiset.sum_cons]
lemma single_finset_sum [add_comm_monoid M] (s : finset ι) (f : ι → M) (a : α) :
single a (∑ b in s, f b) = ∑ b in s, single a (f b) :=
begin
transitivity,
apply single_multiset_sum,
rw [multiset.map_map],
refl
end
lemma single_sum [has_zero M] [add_comm_monoid N] (s : ι →₀ M) (f : ι → M → N) (a : α) :
single a (s.sum f) = s.sum (λd c, single a (f d c)) :=
single_finset_sum _ _ _
@[to_additive]
lemma prod_neg_index [add_group G] [comm_monoid M] {g : α →₀ G} {h : α → G → M}
(h0 : ∀a, h a 0 = 1) :
(-g).prod h = g.prod (λa b, h a (- b)) :=
prod_map_range_index h0
@[simp] lemma neg_apply [add_group G] {g : α →₀ G} {a : α} : (- g) a = - g a :=
rfl
@[simp] lemma sub_apply [add_group G] {g₁ g₂ : α →₀ G} {a : α} : (g₁ - g₂) a = g₁ a - g₂ a :=
rfl
@[simp] lemma support_neg [add_group G] {f : α →₀ G} : support (-f) = support f :=
finset.subset.antisymm
support_map_range
(calc support f = support (- (- f)) : congr_arg support (neg_neg _).symm
... ⊆ support (- f) : support_map_range)
@[simp] lemma sum_apply [has_zero M] [add_comm_monoid N]
{f : α →₀ M} {g : α → M → β →₀ N} {a₂ : β} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(eval_add_hom a₂ : (β →₀ N) →+ _).map_sum _ _
lemma support_sum [has_zero M] [add_comm_monoid N]
{f : α →₀ M} {g : α → M → (β →₀ N)} :
(f.sum g).support ⊆ f.support.bind (λa, (g a (f a)).support) :=
have ∀ c, f.sum (λ a b, g a b c) ≠ 0 → (∃ a, f a ≠ 0 ∧ ¬ (g a (f a)) c = 0),
from assume a₁ h,
let ⟨a, ha, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨a, mem_support_iff.mp ha, ne⟩,
by simpa only [finset.subset_iff, mem_support_iff, finset.mem_bind, sum_apply, exists_prop]
@[simp] lemma sum_zero [has_zero M] [add_comm_monoid N] {f : α →₀ M} :
f.sum (λa b, (0 : N)) = 0 :=
finset.sum_const_zero
@[simp, to_additive]
lemma prod_mul [has_zero M] [comm_monoid N] {f : α →₀ M} {h₁ h₂ : α → M → N} :
f.prod (λa b, h₁ a b * h₂ a b) = f.prod h₁ * f.prod h₂ :=
finset.prod_mul_distrib
@[simp, to_additive]
lemma prod_inv [has_zero M] [comm_group G] {f : α →₀ M}
{h : α → M → G} : f.prod (λa b, (h a b)⁻¹) = (f.prod h)⁻¹ :=
(((monoid_hom.id G)⁻¹).map_prod _ _).symm
@[simp] lemma sum_sub [has_zero M] [add_comm_group G] {f : α →₀ M}
{h₁ h₂ : α → M → G} :
f.sum (λa b, h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
finset.sum_sub_distrib
@[to_additive]
lemma prod_add_index [add_comm_monoid M] [comm_monoid N] {f g : α →₀ M}
{h : α → M → N} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have hf : f.prod h = ∏ a in f.support ∪ g.support, h a (f a),
from f.prod_of_support_subset (subset_union_left _ _) _ $ λ a ha, h_zero a,
have hg : g.prod h = ∏ a in f.support ∪ g.support, h a (g a),
from g.prod_of_support_subset (subset_union_right _ _) _ $ λ a ha, h_zero a,
have hfg : (f + g).prod h = ∏ a in f.support ∪ g.support, h a ((f + g) a),
from (f + g).prod_of_support_subset support_add _ $ λ a ha, h_zero a,
by simp only [*, add_apply, prod_mul_distrib]
@[simp]
lemma sum_add_index' [add_comm_monoid M] [add_comm_monoid N] {f g : α →₀ M} (h : α → M →+ N) :
(f + g).sum (λ x, h x) = f.sum (λ x, h x) + g.sum (λ x, h x) :=
sum_add_index (λ a, (h a).map_zero) (λ a, (h a).map_add)
@[simp]
lemma prod_add_index' [add_comm_monoid M] [comm_monoid N] {f g : α →₀ M}
(h : α → multiplicative M →* N) :
(f + g).prod (λ a b, h a (multiplicative.of_add b)) =
f.prod (λ a b, h a (multiplicative.of_add b)) * g.prod (λ a b, h a (multiplicative.of_add b)) :=
prod_add_index (λ a, (h a).map_one) (λ a, (h a).map_mul)
/-- The canonical isomorphism between families of additive monoid homomorphisms `α → (M →+ N)`
and monoid homomorphisms `(α →₀ M) →+ N`. -/
def lift_add_hom [add_comm_monoid M] [add_comm_monoid N] : (α → M →+ N) ≃+ ((α →₀ M) →+ N) :=
{ to_fun := λ F,
{ to_fun := λ f, f.sum (λ x, F x),
map_zero' := finset.sum_empty,
map_add' := λ _ _, sum_add_index (λ x, (F x).map_zero) (λ x, (F x).map_add) },
inv_fun := λ F x, F.comp $ single_add_hom x,
left_inv := λ F, by { ext, simp },
right_inv := λ F, by { ext, simp },
map_add' := λ F G, by { ext, simp } }
@[simp] lemma lift_add_hom_apply [add_comm_monoid M] [add_comm_monoid N]
(F : α → M →+ N) (f : α →₀ M) :
lift_add_hom F f = f.sum (λ x, F x) :=
rfl
@[simp] lemma lift_add_hom_symm_apply [add_comm_monoid M] [add_comm_monoid N]
(F : (α →₀ M) →+ N) (x : α) :
lift_add_hom.symm F x = F.comp (single_add_hom x) :=
rfl
lemma lift_add_hom_symm_apply_apply [add_comm_monoid M] [add_comm_monoid N]
(F : (α →₀ M) →+ N) (x : α) (y : M) :
lift_add_hom.symm F x y = F (single x y) :=
rfl
@[simp] lemma lift_add_hom_single_add_hom [add_comm_monoid M] :
lift_add_hom (single_add_hom : α → M →+ α →₀ M) = add_monoid_hom.id _ :=
lift_add_hom.to_equiv.apply_eq_iff_eq_symm_apply.2 rfl
@[simp] lemma sum_single [add_comm_monoid M] (f : α →₀ M) :
f.sum single = f :=
add_monoid_hom.congr_fun lift_add_hom_single_add_hom f
@[simp] lemma lift_add_hom_apply_single [add_comm_monoid M] [add_comm_monoid N]
(f : α → M →+ N) (a : α) (b : M) :
lift_add_hom f (single a b) = f a b :=
sum_single_index (f a).map_zero
@[simp] lemma lift_add_hom_comp_single [add_comm_monoid M] [add_comm_monoid N] (f : α → M →+ N)
(a : α) :
(lift_add_hom f).comp (single_add_hom a) = f a :=
add_monoid_hom.ext $ λ b, lift_add_hom_apply_single f a b
lemma comp_lift_add_hom [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P]
(g : N →+ P) (f : α → M →+ N) :
g.comp (lift_add_hom f) = lift_add_hom (λ a, g.comp (f a)) :=
lift_add_hom.symm_apply_eq.1 $ funext $ λ a,
by rw [lift_add_hom_symm_apply, add_monoid_hom.comp_assoc, lift_add_hom_comp_single]
lemma sum_sub_index [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
(f - g).sum h = f.sum h - g.sum h :=
(lift_add_hom (λ a, add_monoid_hom.of_map_sub (h a) (h_sub a))).map_sub f g
@[to_additive]
lemma prod_emb_domain [has_zero M] [comm_monoid N] {v : α →₀ M} {f : α ↪ β} {g : β → M → N} :
(v.emb_domain f).prod g = v.prod (λ a b, g (f a) b) :=
begin
rw [prod, prod, support_emb_domain, finset.prod_map],
simp_rw emb_domain_apply,
end
@[to_additive]
lemma prod_finset_sum_index [add_comm_monoid M] [comm_monoid N]
{s : finset ι} {g : ι → α →₀ M}
{h : α → M → N} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
∏ i in s, (g i).prod h = (∑ i in s, g i).prod h :=
finset.induction_on s rfl $ λ a s has ih,
by rw [prod_insert has, ih, sum_insert has, prod_add_index h_zero h_add]
@[to_additive]
lemma prod_sum_index
[add_comm_monoid M] [add_comm_monoid N] [comm_monoid P]
{f : α →₀ M} {g : α → M → β →₀ N}
{h : β → N → P} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
lemma multiset_sum_sum_index
[add_comm_monoid M] [add_comm_monoid N]
(f : multiset (α →₀ M)) (h : α → M → N)
(h₀ : ∀a, h a 0 = 0) (h₁ : ∀ (a : α) (b₁ b₂ : M), h a (b₁ + b₂) = h a b₁ + h a b₂) :
(f.sum.sum h) = (f.map $ λg:α →₀ M, g.sum h).sum :=
multiset.induction_on f rfl $ assume a s ih,
by rw [multiset.sum_cons, multiset.map_cons, multiset.sum_cons, sum_add_index h₀ h₁, ih]
lemma multiset_map_sum [has_zero M] {f : α →₀ M} {m : β → γ} {h : α → M → multiset β} :
multiset.map m (f.sum h) = f.sum (λa b, (h a b).map m) :=
(f.support.sum_hom _).symm
lemma multiset_sum_sum [has_zero M] [add_comm_monoid N] {f : α →₀ M} {h : α → M → multiset N} :
multiset.sum (f.sum h) = f.sum (λa b, multiset.sum (h a b)) :=
(f.support.sum_hom multiset.sum).symm
section map_range
variables
[add_comm_monoid M] [add_comm_monoid N] (f : M →+ N)
/--
Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
def map_range.add_monoid_hom : (α →₀ M) →+ (α →₀ N) :=
{ to_fun := (map_range f f.map_zero : (α →₀ M) → (α →₀ N)),
map_zero' := map_range_zero,
map_add' := λ a b, map_range_add f.map_add _ _ }
lemma map_range_multiset_sum (m : multiset (α →₀ M)) :
map_range f f.map_zero m.sum = (m.map $ λx, map_range f f.map_zero x).sum :=
(m.sum_hom (map_range.add_monoid_hom f)).symm
lemma map_range_finset_sum (s : finset ι) (g : ι → (α →₀ M)) :
map_range f f.map_zero (∑ x in s, g x) = ∑ x in s, map_range f f.map_zero (g x) :=
by rw [finset.sum.equations._eqn_1, map_range_multiset_sum, multiset.map_map]; refl
end map_range
/-! ### Declarations about `map_domain` -/
section map_domain
variables [add_comm_monoid M] {v v₁ v₂ : α →₀ M}
/-- Given `f : α → β` and `v : α →₀ M`, `map_domain f v : β →₀ M`
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
def map_domain (f : α → β) (v : α →₀ M) : β →₀ M :=
v.sum $ λa, single (f a)
lemma map_domain_apply {f : α → β} (hf : function.injective f) (x : α →₀ M) (a : α) :
map_domain f x (f a) = x a :=
begin
rw [map_domain, sum_apply, sum, finset.sum_eq_single a, single_eq_same],
{ assume b _ hba, exact single_eq_of_ne (hf.ne hba) },
{ assume h, rw [not_mem_support_iff.1 h, single_zero, zero_apply] }
end
lemma map_domain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ set.range f) :
map_domain f x a = 0 :=
begin
rw [map_domain, sum_apply, sum],
exact finset.sum_eq_zero
(assume a' h', single_eq_of_ne $ assume eq, h $ eq ▸ set.mem_range_self _)
end
lemma map_domain_id : map_domain id v = v :=
sum_single _
lemma map_domain_comp {f : α → β} {g : β → γ} :
map_domain (g ∘ f) v = map_domain g (map_domain f v) :=
begin
refine ((sum_sum_index _ _).trans _).symm,
{ intros, exact single_zero },
{ intros, exact single_add },
refine sum_congr rfl (λ _ _, sum_single_index _),
{ exact single_zero }
end
lemma map_domain_single {f : α → β} {a : α} {b : M} : map_domain f (single a b) = single (f a) b :=
sum_single_index single_zero
@[simp] lemma map_domain_zero {f : α → β} : map_domain f (0 : α →₀ M) = (0 : β →₀ M) :=
sum_zero_index
lemma map_domain_congr {f g : α → β} (h : ∀x∈v.support, f x = g x) :
v.map_domain f = v.map_domain g :=
finset.sum_congr rfl $ λ _ H, by simp only [h _ H]
lemma map_domain_add {f : α → β} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
sum_add_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_finset_sum {f : α → β} {s : finset ι} {v : ι → α →₀ M} :
map_domain f (∑ i in s, v i) = ∑ i in s, map_domain f (v i) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_sum [has_zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
map_domain f (s.sum v) = s.sum (λa b, map_domain f (v a b)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_support {f : α → β} {s : α →₀ M} :
(s.map_domain f).support ⊆ s.support.image f :=
finset.subset.trans support_sum $
finset.subset.trans (finset.bind_mono $ assume a ha, support_single_subset) $
by rw [finset.bind_singleton]; exact subset.refl _
@[to_additive]
lemma prod_map_domain_index [comm_monoid N] {f : α → β} {s : α →₀ M}
{h : β → M → N} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(map_domain f s).prod h = s.prod (λa b, h (f a) b) :=
(prod_sum_index h_zero h_add).trans $ prod_congr rfl $ λ _ _, prod_single_index (h_zero _)
lemma emb_domain_eq_map_domain (f : α ↪ β) (v : α →₀ M) :
emb_domain f v = map_domain f v :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a, rfl⟩,
rw [map_domain_apply f.injective, emb_domain_apply] },
{ rw [map_domain_notin_range, emb_domain_notin_range]; assumption }
end
@[to_additive]
lemma prod_map_domain_index_inj [comm_monoid N] {f : α → β} {s : α →₀ M}
{h : β → M → N} (hf : function.injective f) :
(s.map_domain f).prod h = s.prod (λa b, h (f a) b) :=
by rw [←function.embedding.coe_fn_mk f hf, ←emb_domain_eq_map_domain, prod_emb_domain]
lemma map_domain_injective {f : α → β} (hf : function.injective f) :
function.injective (map_domain f : (α →₀ M) → (β →₀ M)) :=
begin
assume v₁ v₂ eq, ext a,
have : map_domain f v₁ (f a) = map_domain f v₂ (f a), { rw eq },
rwa [map_domain_apply hf, map_domain_apply hf] at this,
end
end map_domain
/-! ### Declarations about `comap_domain` -/
section comap_domain
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comap_domain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
def comap_domain [has_zero M] (f : α → β) (l : β →₀ M) (hf : set.inj_on f (f ⁻¹' ↑l.support)) :
α →₀ M :=
{ support := l.support.preimage f hf,
to_fun := (λ a, l (f a)),
mem_support_to_fun :=
begin
intros a,
simp only [finset.mem_def.symm, finset.mem_preimage],
exact l.mem_support_to_fun (f a),
end }
@[simp]
lemma comap_domain_apply [has_zero M] (f : α → β) (l : β →₀ M)
(hf : set.inj_on f (f ⁻¹' ↑l.support)) (a : α) :
comap_domain f l hf a = l (f a) :=
rfl
lemma sum_comap_domain [has_zero M] [add_comm_monoid N]
(f : α → β) (l : β →₀ M) (g : β → M → N)
(hf : set.bij_on f (f ⁻¹' ↑l.support) ↑l.support) :
(comap_domain f l hf.inj_on).sum (g ∘ f) = l.sum g :=
begin
simp only [sum, comap_domain_apply, (∘)],
simp [comap_domain, finset.sum_preimage_of_bij f _ _ (λ x, g x (l x))],
end
lemma eq_zero_of_comap_domain_eq_zero [add_comm_monoid M]
(f : α → β) (l : β →₀ M) (hf : set.bij_on f (f ⁻¹' ↑l.support) ↑l.support) :
comap_domain f l hf.inj_on = 0 → l = 0 :=
begin
rw [← support_eq_empty, ← support_eq_empty, comap_domain],
simp only [finset.ext_iff, finset.not_mem_empty, iff_false, mem_preimage],
assume h a ha,
cases hf.2.2 ha with b hb,
exact h b (hb.2.symm ▸ ha)
end
lemma map_domain_comap_domain [add_comm_monoid M] (f : α → β) (l : β →₀ M)
(hf : function.injective f) (hl : ↑l.support ⊆ set.range f):
map_domain f (comap_domain f l (hf.inj_on _)) = l :=
begin
ext a,
by_cases h_cases: a ∈ set.range f,
{ rcases set.mem_range.1 h_cases with ⟨b, hb⟩,
rw [hb.symm, map_domain_apply hf, comap_domain_apply] },
{ rw map_domain_notin_range _ _ h_cases,
by_contra h_contr,
apply h_cases (hl $ finset.mem_coe.2 $ mem_support_iff.2 $ λ h, h_contr h.symm) }
end
end comap_domain
/-! ### Declarations about `filter` -/
section filter
section has_zero
variables [has_zero M] (p : α → Prop) (f : α →₀ M)
/-- `filter p f` is the function which is `f a` if `p a` is true and 0 otherwise. -/
def filter (p : α → Prop) (f : α →₀ M) : α →₀ M :=
on_finset f.support (λa, if p a then f a else 0) $ λ a H,
mem_support_iff.2 $ λ h, by rw [h, if_t_t] at H; exact H rfl
@[simp] lemma filter_apply_pos {a : α} (h : p a) : f.filter p a = f a :=
if_pos h
@[simp] lemma filter_apply_neg {a : α} (h : ¬ p a) : f.filter p a = 0 :=
if_neg h
@[simp] lemma support_filter : (f.filter p).support = f.support.filter p :=
finset.ext $ assume a, if H : p a
then by simp only [mem_support_iff, filter_apply_pos _ _ H, mem_filter, H, and_true]
else by simp only [mem_support_iff, filter_apply_neg _ _ H, mem_filter, H, and_false, ne.def,
ne_self_iff_false]
lemma filter_zero : (0 : α →₀ M).filter p = 0 :=
by rw [← support_eq_empty, support_filter, support_zero, finset.filter_empty]
@[simp] lemma filter_single_of_pos
{a : α} {b : M} (h : p a) : (single a b).filter p = single a b :=
ext $ λ x, begin
by_cases h' : p x,
{ simp only [h', filter_apply_pos] },
{ simp only [h', filter_apply_neg, not_false_iff],
rw single_eq_of_ne, rintro rfl, exact h' h }
end
@[simp] lemma filter_single_of_neg
{a : α} {b : M} (h : ¬ p a) : (single a b).filter p = 0 :=
ext $ λ x, begin
by_cases h' : p x,
{ simp only [h', filter_apply_pos, zero_apply], rw single_eq_of_ne, rintro rfl, exact h h' },
{ simp only [h', finsupp.zero_apply, not_false_iff, filter_apply_neg] }
end
end has_zero
lemma filter_pos_add_filter_neg [add_monoid M] (f : α →₀ M) (p : α → Prop) :
f.filter p + f.filter (λa, ¬ p a) = f :=
ext $ assume a, if H : p a
then by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_not, add_zero]
else by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_false_iff, zero_add]
end filter
/-! ### Declarations about `frange` -/
section frange
variables [has_zero M]
/-- `frange f` is the image of `f` on the support of `f`. -/
def frange (f : α →₀ M) : finset M := finset.image f f.support
theorem mem_frange {f : α →₀ M} {y : M} :
y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y :=
finset.mem_image.trans
⟨λ ⟨x, hx1, hx2⟩, ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩,
λ ⟨hy, x, hx⟩, ⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩
theorem zero_not_mem_frange {f : α →₀ M} : (0:M) ∉ f.frange :=
λ H, (mem_frange.1 H).1 rfl
theorem frange_single {x : α} {y : M} : frange (single x y) ⊆ {y} :=
λ r hr, let ⟨t, ht1, ht2⟩ := mem_frange.1 hr in ht2 ▸
(by rw single_apply at ht2 ⊢; split_ifs at ht2 ⊢; [exact finset.mem_singleton_self _, cc])
end frange
/-! ### Declarations about `subtype_domain` -/
section subtype_domain
section zero
variables [has_zero M] {p : α → Prop}
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain (p : α → Prop) (f : α →₀ M) : (subtype p →₀ M) :=
⟨f.support.subtype p, f ∘ coe, λ a, by simp only [mem_subtype, mem_support_iff]⟩
@[simp] lemma support_subtype_domain {f : α →₀ M} :
(subtype_domain p f).support = f.support.subtype p :=
rfl
@[simp] lemma subtype_domain_apply {a : subtype p} {v : α →₀ M} :
(subtype_domain p v) a = v (a.val) :=
rfl
@[simp] lemma subtype_domain_zero : subtype_domain p (0 : α →₀ M) = 0 :=
rfl
lemma subtype_domain_eq_zero_iff' {f : α →₀ M} :
f.subtype_domain p = 0 ↔ ∀ x, p x → f x = 0 :=
by simp_rw [← support_eq_empty, support_subtype_domain, subtype_eq_empty, not_mem_support_iff]
lemma subtype_domain_eq_zero_iff {f : α →₀ M} (hf : ∀ x ∈ f.support , p x) :
f.subtype_domain p = 0 ↔ f = 0 :=
subtype_domain_eq_zero_iff'.trans ⟨λ H, ext $ λ x,
if hx : p x then H x hx else not_mem_support_iff.1 $ mt (hf x) hx, λ H x _, by simp [H]⟩
@[to_additive]
lemma prod_subtype_domain_index [comm_monoid N] {v : α →₀ M}
{h : α → M → N} (hp : ∀x∈v.support, p x) :
(v.subtype_domain p).prod (λa b, h a b) = v.prod h :=
prod_bij (λp _, p.val)
(λ _, mem_subtype.1)
(λ _ _, rfl)
(λ _ _ _ _, subtype.eq)
(λ b hb, ⟨⟨b, hp b hb⟩, mem_subtype.2 hb, rfl⟩)
end zero
section monoid
variables [add_monoid M] {p : α → Prop} {v v' : α →₀ M}
@[simp] lemma subtype_domain_add {v v' : α →₀ M} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ λ _, rfl
instance subtype_domain.is_add_monoid_hom :
is_add_monoid_hom (subtype_domain p : (α →₀ M) → subtype p →₀ M) :=
{ map_add := λ _ _, subtype_domain_add, map_zero := subtype_domain_zero }
@[simp] lemma filter_add {v v' : α →₀ M} :
(v + v').filter p = v.filter p + v'.filter p :=
ext $ λ a, begin
by_cases p a,
{ simp only [h, filter_apply_pos, add_apply] },
{ simp only [h, add_zero, add_apply, not_false_iff, filter_apply_neg] }
end
instance filter.is_add_monoid_hom (p : α → Prop) :
is_add_monoid_hom (filter p : (α →₀ M) → (α →₀ M)) :=
{ map_zero := filter_zero p, map_add := λ x y, filter_add }
end monoid
section comm_monoid
variables [add_comm_monoid M] {p : α → Prop}
lemma subtype_domain_sum {s : finset ι} {h : ι → α →₀ M} :
(∑ c in s, h c).subtype_domain p = ∑ c in s, (h c).subtype_domain p :=
eq.symm (s.sum_hom _)
lemma subtype_domain_finsupp_sum [has_zero N] {s : β →₀ N} {h : β → N → α →₀ M} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
lemma filter_sum (s : finset ι) (f : ι → α →₀ M) :
(∑ a in s, f a).filter p = ∑ a in s, filter p (f a) :=
(s.sum_hom (filter p)).symm
end comm_monoid
section group
variables [add_group G] {p : α → Prop} {v v' : α →₀ G}
@[simp] lemma subtype_domain_neg : (- v).subtype_domain p = - v.subtype_domain p :=
ext $ λ _, rfl
@[simp] lemma subtype_domain_sub :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ λ _, rfl
end group
end subtype_domain
/-! ### Declarations relating `finsupp` to `multiset` -/
section multiset
/-- Given `f : α →₀ ℕ`, `f.to_multiset` is the multiset with multiplicities given by the values of
`f` on the elements of `α`. -/
def to_multiset (f : α →₀ ℕ) : multiset α :=
f.sum (λa n, n •ℕ {a})
lemma to_multiset_zero : (0 : α →₀ ℕ).to_multiset = 0 :=
rfl
lemma to_multiset_add (m n : α →₀ ℕ) :
(m + n).to_multiset = m.to_multiset + n.to_multiset :=
sum_add_index (assume a, zero_nsmul _) (assume a b₁ b₂, add_nsmul _ _ _)
lemma to_multiset_single (a : α) (n : ℕ) : to_multiset (single a n) = n •ℕ {a} :=
by rw [to_multiset, sum_single_index]; apply zero_nsmul
instance is_add_monoid_hom.to_multiset : is_add_monoid_hom (to_multiset : _ → multiset α) :=
{ map_zero := to_multiset_zero, map_add := to_multiset_add }
lemma card_to_multiset (f : α →₀ ℕ) : f.to_multiset.card = f.sum (λa, id) :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.card_zero, sum_zero_index] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.card_add, ih, sum_add_index, to_multiset_single,
sum_single_index, multiset.card_smul, multiset.singleton_eq_singleton,
multiset.card_singleton, mul_one]; intros; refl }
end
lemma to_multiset_map (f : α →₀ ℕ) (g : α → β) :
f.to_multiset.map g = (f.map_domain g).to_multiset :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.map_zero, map_domain_zero, to_multiset_zero] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.map_add, ih, map_domain_add, map_domain_single,
to_multiset_single, to_multiset_add, to_multiset_single,
is_add_monoid_hom.map_nsmul (multiset.map g)],
refl }
end
lemma prod_to_multiset [comm_monoid M] (f : M →₀ ℕ) :
f.to_multiset.prod = f.prod (λa n, a ^ n) :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.prod_zero, finsupp.prod_zero_index] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.prod_add, ih, to_multiset_single, finsupp.prod_add_index,
finsupp.prod_single_index, multiset.prod_smul, multiset.singleton_eq_singleton,
multiset.prod_singleton],
{ exact pow_zero a },
{ exact pow_zero },
{ exact pow_add } }
end
lemma to_finset_to_multiset (f : α →₀ ℕ) : f.to_multiset.to_finset = f.support :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.to_finset_zero, support_zero] },
{ assume a n f ha hn ih,
rw [to_multiset_add, multiset.to_finset_add, ih, to_multiset_single, support_add_eq,
support_single_ne_zero hn, multiset.to_finset_nsmul _ _ hn,
multiset.singleton_eq_singleton, multiset.to_finset_cons, multiset.to_finset_zero],
refl,
refine disjoint.mono_left support_single_subset _,
rwa [finset.singleton_disjoint] }
end
@[simp] lemma count_to_multiset (f : α →₀ ℕ) (a : α) :
f.to_multiset.count a = f a :=
calc f.to_multiset.count a = f.sum (λx n, (n •ℕ {x} : multiset α).count a) :
(f.support.sum_hom $ multiset.count a).symm
... = f.sum (λx n, n * ({x} : multiset α).count a) : by simp only [multiset.count_smul]
... = f.sum (λx n, n * (x ::ₘ 0 : multiset α).count a) : rfl
... = f a * (a ::ₘ 0 : multiset α).count a : sum_eq_single _
(λ a' _ H, by simp only [multiset.count_cons_of_ne (ne.symm H), multiset.count_zero, mul_zero])
(λ H, by simp only [not_mem_support_iff.1 H, zero_mul])
... = f a : by simp only [multiset.count_singleton, mul_one]
/-- Given `m : multiset α`, `of_multiset m` is the finitely supported function from `α` to `ℕ`
given by the multiplicities of the elements of `α` in `m`. -/
def of_multiset (m : multiset α) : α →₀ ℕ :=
on_finset m.to_finset (λa, m.count a) $ λ a H, multiset.mem_to_finset.2 $
by_contradiction (mt multiset.count_eq_zero.2 H)
@[simp] lemma of_multiset_apply (m : multiset α) (a : α) :
of_multiset m a = m.count a :=
rfl
/-- `equiv_multiset` defines an `equiv` between finitely supported functions
from `α` to `ℕ` and multisets on `α`. -/
def equiv_multiset : (α →₀ ℕ) ≃ (multiset α) :=
⟨ to_multiset, of_multiset,
assume f, finsupp.ext $ λ a, by rw [of_multiset_apply, count_to_multiset],
assume m, multiset.ext.2 $ λ a, by rw [count_to_multiset, of_multiset_apply] ⟩
lemma mem_support_multiset_sum [add_comm_monoid M]
{s : multiset (α →₀ M)} (a : α) :
a ∈ s.sum.support → ∃f∈s, a ∈ (f : α →₀ M).support :=
multiset.induction_on s false.elim
begin
assume f s ih ha,
by_cases a ∈ f.support,
{ exact ⟨f, multiset.mem_cons_self _ _, h⟩ },
{ simp only [multiset.sum_cons, mem_support_iff, add_apply,
not_mem_support_iff.1 h, zero_add] at ha,
rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩,
exact ⟨f', multiset.mem_cons_of_mem h₀, h₁⟩ }
end
lemma mem_support_finset_sum [add_comm_monoid M]
{s : finset ι} {h : ι → α →₀ M} (a : α) (ha : a ∈ (∑ c in s, h c).support) :
∃ c ∈ s, a ∈ (h c).support :=
let ⟨f, hf, hfa⟩ := mem_support_multiset_sum a ha in
let ⟨c, hc, eq⟩ := multiset.mem_map.1 hf in
⟨c, hc, eq.symm ▸ hfa⟩
@[simp] lemma mem_to_multiset (f : α →₀ ℕ) (i : α) :
i ∈ f.to_multiset ↔ i ∈ f.support :=
by rw [← multiset.count_ne_zero, finsupp.count_to_multiset, finsupp.mem_support_iff]
end multiset
/-! ### Declarations about `curry` and `uncurry` -/
section curry_uncurry
variables [add_comm_monoid M] [add_comm_monoid N]
/-- Given a finitely supported function `f` from a product type `α × β` to `γ`,
`curry f` is the "curried" finitely supported function from `α` to the type of
finitely supported functions from `β` to `γ`. -/
protected def curry (f : (α × β) →₀ M) : α →₀ (β →₀ M) :=
f.sum $ λp c, single p.1 (single p.2 c)
lemma sum_curry_index (f : (α × β) →₀ M) (g : α → β → M → N)
(hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) :
f.curry.sum (λa f, f.sum (g a)) = f.sum (λp c, g p.1 p.2 c) :=
begin
rw [finsupp.curry],
transitivity,
{ exact sum_sum_index (assume a, sum_zero_index)
(assume a b₀ b₁, sum_add_index (assume a, hg₀ _ _) (assume c d₀ d₁, hg₁ _ _ _ _)) },
congr, funext p c,
transitivity,
{ exact sum_single_index sum_zero_index },
exact sum_single_index (hg₀ _ _)
end
/-- Given a finitely supported function `f` from `α` to the type of
finitely supported functions from `β` to `M`,
`uncurry f` is the "uncurried" finitely supported function from `α × β` to `M`. -/
protected def uncurry (f : α →₀ (β →₀ M)) : (α × β) →₀ M :=
f.sum $ λa g, g.sum $ λb c, single (a, b) c
/-- `finsupp_prod_equiv` defines the `equiv` between `((α × β) →₀ M)` and `(α →₀ (β →₀ M))` given by
currying and uncurrying. -/
def finsupp_prod_equiv : ((α × β) →₀ M) ≃ (α →₀ (β →₀ M)) :=
by refine ⟨finsupp.curry, finsupp.uncurry, λ f, _, λ f, _⟩; simp only [
finsupp.curry, finsupp.uncurry, sum_sum_index, sum_zero_index, sum_add_index,
sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff,
forall_3_true_iff, prod.mk.eta, (single_sum _ _ _).symm, sum_single]
lemma filter_curry (f : α × β →₀ M) (p : α → Prop) :
(f.filter (λa:α×β, p a.1)).curry = f.curry.filter p :=
begin
rw [finsupp.curry, finsupp.curry, finsupp.sum, finsupp.sum, filter_sum, support_filter,
sum_filter],
refine finset.sum_congr rfl _,
rintros ⟨a₁, a₂⟩ ha,
dsimp only,
split_ifs,
{ rw [filter_apply_pos, filter_single_of_pos]; exact h },
{ rwa [filter_single_of_neg] }
end
lemma support_curry (f : α × β →₀ M) : f.curry.support ⊆ f.support.image prod.fst :=
begin
rw ← finset.bind_singleton,
refine finset.subset.trans support_sum _,
refine finset.bind_mono (assume a _, support_single_subset)
end
end curry_uncurry
section
variables [group G] [mul_action G α] [add_comm_monoid M]
/--
Scalar multiplication by a group element g,
given by precomposition with the action of g⁻¹ on the domain.
-/
def comap_has_scalar : has_scalar G (α →₀ M) :=
{ smul := λ g f, f.comap_domain (λ a, g⁻¹ • a)
(λ a a' m m' h, by simpa [←mul_smul] using (congr_arg (λ a, g • a) h)) }
local attribute [instance] comap_has_scalar
/--
Scalar multiplication by a group element,
given by precomposition with the action of g⁻¹ on the domain,
is multiplicative in g.
-/
def comap_mul_action : mul_action G (α →₀ M) :=
{ one_smul := λ f, by { ext, dsimp [(•)], simp, },
mul_smul := λ g g' f, by { ext, dsimp [(•)], simp [mul_smul], }, }
local attribute [instance] comap_mul_action
/--
Scalar multiplication by a group element,
given by precomposition with the action of g⁻¹ on the domain,
is additive in the second argument.
-/
def comap_distrib_mul_action :
distrib_mul_action G (α →₀ M) :=
{ smul_zero := λ g, by { ext, dsimp [(•)], simp, },
smul_add := λ g f f', by { ext, dsimp [(•)], simp, }, }
/--
Scalar multiplication by a group element on finitely supported functions on a group,
given by precomposition with the action of g⁻¹. -/
def comap_distrib_mul_action_self :
distrib_mul_action G (G →₀ M) :=
@finsupp.comap_distrib_mul_action G M G _ (mul_action.regular G) _
@[simp]
lemma comap_smul_single (g : G) (a : α) (b : M) :
g • single a b = single (g • a) b :=
begin
ext a',
dsimp [(•)],
by_cases h : g • a = a',
{ subst h, simp [←mul_smul], },
{ simp [single_eq_of_ne h], rw [single_eq_of_ne],
rintro rfl, simpa [←mul_smul] using h, }
end
@[simp]
lemma comap_smul_apply (g : G) (f : α →₀ M) (a : α) :
(g • f) a = f (g⁻¹ • a) := rfl
end
section
instance [semiring R] [add_comm_monoid M] [semimodule R M] : has_scalar R (α →₀ M) :=
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
variables (α M)
@[simp] lemma smul_apply' {_:semiring R} [add_comm_monoid M] [semimodule R M]
{a : α} {b : R} {v : α →₀ M} : (b • v) a = b • (v a) :=
rfl
instance [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (α →₀ M) :=
{ smul := (•),
smul_add := λ a x y, ext $ λ _, smul_add _ _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
one_smul := λ x, ext $ λ _, one_smul _ _,
mul_smul := λ r s x, ext $ λ _, mul_smul _ _ _,
zero_smul := λ x, ext $ λ _, zero_smul _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }
variables {α M} (R)
/-- Evaluation at point as a linear map. This version assumes that the codomain is a semimodule
over some semiring. See also `leval`. -/
def leval' [semiring R] [add_comm_monoid M] [semimodule R M] (a : α) :
(α →₀ M) →ₗ[R] M :=
⟨λ g, g a, λ _ _, add_apply, λ _ _, rfl⟩
@[simp] lemma coe_leval' [semiring R] [add_comm_monoid M] [semimodule R M] (a : α) (g : α →₀ M) :
leval' R a g = g a :=
rfl
variable {R}
/-- Evaluation at point as a linear map. This version assumes that the codomain is a semiring. -/
def leval [semiring R] (a : α) : (α →₀ R) →ₗ[R] R := leval' R a
@[simp] lemma coe_leval [semiring R] (a : α) (g : α →₀ R) : leval a g = g a := rfl
lemma support_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M] {b : R} {g : α →₀ M} :
(b • g).support ⊆ g.support :=
λ a, by simp only [smul_apply', mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
section
variables {p : α → Prop}
@[simp] lemma filter_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
{b : R} {v : α →₀ M} : (b • v).filter p = b • v.filter p :=
ext $ λ a, begin
by_cases p a,
{ simp only [h, smul_apply', filter_apply_pos] },
{ simp only [h, smul_apply', not_false_iff, filter_apply_neg, smul_zero] }
end
end
lemma map_domain_smul {_ : semiring R} [add_comm_monoid M] [semimodule R M]
{f : α → β} (b : R) (v : α →₀ M) : map_domain f (b • v) = b • map_domain f v :=
begin
change map_domain f (map_range _ _ _) = map_range _ _ _,
apply finsupp.induction v, { simp only [map_domain_zero, map_range_zero] },
intros a b v' hv₁ hv₂ IH,
rw [map_range_add, map_domain_add, IH, map_domain_add, map_range_add,
map_range_single, map_domain_single, map_domain_single, map_range_single];
apply smul_add
end
@[simp] lemma smul_single {_ : semiring R} [add_comm_monoid M] [semimodule R M]
(c : R) (a : α) (b : M) : c • finsupp.single a b = finsupp.single a (c • b) :=
ext $ λ a', by by_cases a = a';
[{ subst h, simp only [smul_apply', single_eq_same] },
simp only [h, smul_apply', ne.def, not_false_iff, single_eq_of_ne, smul_zero]]
@[simp] lemma smul_single' {_ : semiring R}
(c : R) (a : α) (b : R) : c • finsupp.single a b = finsupp.single a (c * b) :=
smul_single _ _ _
lemma smul_single_one [semiring R] (a : α) (b : R) : b • single a 1 = single a b :=
by rw [smul_single, smul_eq_mul, mul_one]
end
@[simp] lemma smul_apply [semiring R] {a : α} {b : R} {v : α →₀ R} :
(b • v) a = b • (v a) :=
rfl
lemma sum_smul_index [semiring R] [add_comm_monoid M] {g : α →₀ R} {b : R} {h : α → R → M}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0
lemma sum_smul_index' [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid N]
{g : α →₀ M} {b : R} {h : α → M → N} (h0 : ∀i, h i 0 = 0) :
(b • g).sum h = g.sum (λi c, h i (b • c)) :=
finsupp.sum_map_range_index h0
section
variables [semiring R] [semiring S]
lemma sum_mul (b : S) (s : α →₀ R) {f : α → R → S} :
(s.sum f) * b = s.sum (λ a c, (f a c) * b) :=
by simp only [finsupp.sum, finset.sum_mul]
lemma mul_sum (b : S) (s : α →₀ R) {f : α → R → S} :
b * (s.sum f) = s.sum (λ a c, b * (f a c)) :=
by simp only [finsupp.sum, finset.mul_sum]
instance unique_of_right [subsingleton R] : unique (α →₀ R) :=
{ uniq := λ l, ext $ λ i, subsingleton.elim _ _,
.. finsupp.inhabited }
end
/-- Given an `add_comm_monoid M` and `s : set α`, `restrict_support_equiv s M` is the `equiv`
between the subtype of finitely supported functions with support contained in `s` and
the type of finitely supported functions from `s`. -/
def restrict_support_equiv (s : set α) (M : Type*) [add_comm_monoid M] :
{f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M):=
begin
refine ⟨λf, subtype_domain (λx, x ∈ s) f.1, λ f, ⟨f.map_domain subtype.val, _⟩, _, _⟩,
{ refine set.subset.trans (finset.coe_subset.2 map_domain_support) _,
rw [finset.coe_image, set.image_subset_iff],
exact assume x hx, x.2 },
{ rintros ⟨f, hf⟩,
apply subtype.eq,
ext a,
dsimp only,
refine classical.by_cases (assume h : a ∈ set.range (subtype.val : s → α), _) (assume h, _),
{ rcases h with ⟨x, rfl⟩,
rw [map_domain_apply subtype.val_injective, subtype_domain_apply] },
{ convert map_domain_notin_range _ _ h,
rw [← not_mem_support_iff],
refine mt _ h,
exact assume ha, ⟨⟨a, hf ha⟩, rfl⟩ } },
{ assume f,
ext ⟨a, ha⟩,
dsimp only,
rw [subtype_domain_apply, map_domain_apply subtype.val_injective] }
end
/-- Given `add_comm_monoid M` and `e : α ≃ β`, `dom_congr e` is the corresponding `equiv` between
`α →₀ M` and `β →₀ M`. -/
protected def dom_congr [add_comm_monoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) :=
{ to_fun := map_domain e,
inv_fun := map_domain e.symm,
left_inv := begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.symm_apply_apply],
exact map_domain_id
end,
right_inv := begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.apply_symm_apply],
exact map_domain_id
end,
map_add' := λ a b, map_domain_add, }
end finsupp
@[to_additive]
lemma mul_equiv.map_finsupp_prod [has_zero M] [comm_monoid N] [comm_monoid P]
(h : N ≃* P) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
@[to_additive]
lemma monoid_hom.map_finsupp_prod [has_zero M] [comm_monoid N] [comm_monoid P]
(h : N →* P) (f : α →₀ M) (g : α → M → N) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
lemma ring_hom.map_finsupp_sum [has_zero M] [semiring R] [semiring S]
(h : R →+* S) (f : α →₀ M) (g : α → M → R) : h (f.sum g) = f.sum (λ a b, h (g a b)) :=
h.map_sum _ _
lemma ring_hom.map_finsupp_prod [has_zero M] [comm_semiring R] [comm_semiring S]
(h : R →+* S) (f : α →₀ M) (g : α → M → R) : h (f.prod g) = f.prod (λ a b, h (g a b)) :=
h.map_prod _ _
namespace finsupp
/-! ### Declarations about sigma types -/
section sigma
variables {αs : ι → Type*} [has_zero M] (l : (Σ i, αs i) →₀ M)
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `M` and
an index element `i : ι`, `split l i` is the `i`th component of `l`,
a finitely supported function from `as i` to `M`. -/
def split (i : ι) : αs i →₀ M :=
l.comap_domain (sigma.mk i) (λ x1 x2 _ _ hx, heq_iff_eq.1 (sigma.mk.inj hx).2)
lemma split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ :=
begin
dunfold split,
rw comap_domain_apply
end
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`,
`split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/
def split_support : finset ι := l.support.image sigma.fst
lemma mem_split_support_iff_nonzero (i : ι) :
i ∈ split_support l ↔ split l i ≠ 0 :=
begin
rw [split_support, mem_image, ne.def, ← support_eq_empty, ← ne.def,
← finset.nonempty_iff_ne_empty, split, comap_domain, finset.nonempty],
simp only [exists_prop, finset.mem_preimage, exists_and_distrib_right, exists_eq_right,
mem_support_iff, sigma.exists, ne.def]
end
/-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and
an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a
finitely supported function from the index type `ι` to `γ` given by composing `g i` with
`split l i`. -/
def split_comp [has_zero N] (g : Π i, (αs i →₀ M) → N)
(hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N :=
{ support := split_support l,
to_fun := λ i, g i (split l i),
mem_support_to_fun :=
begin
intros i,
rw [mem_split_support_iff_nonzero, not_iff_not, hg],
end }
lemma sigma_support : l.support = l.split_support.sigma (λ i, (l.split i).support) :=
by simp only [finset.ext_iff, split_support, split, comap_domain, mem_image,
mem_preimage, sigma.forall, mem_sigma]; tauto
lemma sigma_sum [add_comm_monoid N] (f : (Σ (i : ι), αs i) → M → N) :
l.sum f = ∑ i in split_support l, (split l i).sum (λ (a : αs i) b, f ⟨i, a⟩ b) :=
by simp only [sum, sigma_support, sum_sigma, split_apply]
end sigma
end finsupp
/-! ### Declarations relating `multiset` to `finsupp` -/
namespace multiset
/-- Given a multiset `s`, `s.to_finsupp` returns the finitely supported function on `ℕ` given by
the multiplicities of the elements of `s`. -/
def to_finsupp (s : multiset α) : α →₀ ℕ :=
{ support := s.to_finset,
to_fun := λ a, s.count a,
mem_support_to_fun := λ a,
begin
rw mem_to_finset,
convert not_iff_not_of_iff (count_eq_zero.symm),
rw not_not
end }
@[simp] lemma to_finsupp_support (s : multiset α) :
s.to_finsupp.support = s.to_finset :=
rfl
@[simp] lemma to_finsupp_apply (s : multiset α) (a : α) :
s.to_finsupp a = s.count a :=
rfl
@[simp] lemma to_finsupp_zero :
to_finsupp (0 : multiset α) = 0 :=
finsupp.ext $ λ a, count_zero a
@[simp] lemma to_finsupp_add (s t : multiset α) :
to_finsupp (s + t) = to_finsupp s + to_finsupp t :=
finsupp.ext $ λ a, count_add a s t
lemma to_finsupp_singleton (a : α) :
to_finsupp {a} = finsupp.single a 1 :=
finsupp.ext $ λ b,
if h : a = b then by rw [to_finsupp_apply, finsupp.single_apply, h, if_pos rfl,
singleton_eq_singleton, count_singleton] else
begin
rw [to_finsupp_apply, finsupp.single_apply, if_neg h, count_eq_zero,
singleton_eq_singleton, mem_singleton],
rintro rfl, exact h rfl
end
namespace to_finsupp
instance : is_add_monoid_hom (to_finsupp : multiset α → α →₀ ℕ) :=
{ map_zero := to_finsupp_zero,
map_add := to_finsupp_add }
end to_finsupp
@[simp] lemma to_finsupp_to_multiset (s : multiset α) :
s.to_finsupp.to_multiset = s :=
ext.2 $ λ a, by rw [finsupp.count_to_multiset, to_finsupp_apply]
end multiset
/-! ### Declarations about order(ed) instances on `finsupp` -/
namespace finsupp
instance [preorder M] [has_zero M] : preorder (α →₀ M) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
instance [partial_order M] [has_zero M] : partial_order (α →₀ M) :=
{ le_antisymm := λ f g hfg hgf, ext $ λ s, le_antisymm (hfg s) (hgf s),
.. finsupp.preorder }
instance [ordered_cancel_add_comm_monoid M] : add_left_cancel_semigroup (α →₀ M) :=
{ add_left_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_left_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_add_comm_monoid M] : add_right_cancel_semigroup (α →₀ M) :=
{ add_right_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_right_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_add_comm_monoid M] : ordered_cancel_add_comm_monoid (α →₀ M) :=
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
le_of_add_le_add_left := λ a b c h s, le_of_add_le_add_left (h s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order,
.. finsupp.add_left_cancel_semigroup, .. finsupp.add_right_cancel_semigroup }
lemma le_iff [canonically_ordered_add_monoid M] (f g : α →₀ M) :
f ≤ g ↔ ∀ s ∈ f.support, f s ≤ g s :=
⟨λ h s hs, h s,
λ h s, if H : s ∈ f.support then h s H else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩
@[simp] lemma add_eq_zero_iff [canonically_ordered_add_monoid M] (f g : α →₀ M) :
f + g = 0 ↔ f = 0 ∧ g = 0 :=
begin
split,
{ assume h,
split,
all_goals
{ ext s,
suffices H : f s + g s = 0,
{ rw add_eq_zero_iff at H, cases H, assumption },
show (f + g) s = 0,
rw h, refl } },
{ rintro ⟨rfl, rfl⟩, rw add_zero }
end
attribute [simp] to_multiset_zero to_multiset_add
@[simp] lemma to_multiset_to_finsupp (f : α →₀ ℕ) :
f.to_multiset.to_finsupp = f :=
ext $ λ s, by rw [multiset.to_finsupp_apply, count_to_multiset]
lemma to_multiset_strict_mono : strict_mono (@to_multiset α) :=
λ m n h,
begin
rw lt_iff_le_and_ne at h ⊢, cases h with h₁ h₂,
split,
{ rw multiset.le_iff_count, intro s, erw [count_to_multiset m s, count_to_multiset], exact h₁ s },
{ intro H, apply h₂, replace H := congr_arg multiset.to_finsupp H,
simpa only [to_multiset_to_finsupp] using H }
end
lemma sum_id_lt_of_lt (m n : α →₀ ℕ) (h : m < n) :
m.sum (λ _, id) < n.sum (λ _, id) :=
begin
rw [← card_to_multiset, ← card_to_multiset],
apply multiset.card_lt_of_lt,
exact to_multiset_strict_mono h
end
variable (α)
/-- The order on `σ →₀ ℕ` is well-founded.-/
lemma lt_wf : well_founded (@has_lt.lt (α →₀ ℕ) _) :=
subrelation.wf (sum_id_lt_of_lt) $ inv_image.wf _ nat.lt_wf
instance decidable_le : decidable_rel (@has_le.le (α →₀ ℕ) _) :=
λ m n, by rw le_iff; apply_instance
variable {α}
/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of
`s : α →₀ ℕ` consists of all pairs `(t₁, t₂) : (α →₀ ℕ) × (α →₀ ℕ)` such that `t₁ + t₂ = s`.
The finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/
def antidiagonal (f : α →₀ ℕ) : ((α →₀ ℕ) × (α →₀ ℕ)) →₀ ℕ :=
(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp
lemma mem_antidiagonal_support {f : α →₀ ℕ} {p : (α →₀ ℕ) × (α →₀ ℕ)} :
p ∈ (antidiagonal f).support ↔ p.1 + p.2 = f :=
begin
erw [multiset.mem_to_finset, multiset.mem_map],
split,
{ rintros ⟨⟨a, b⟩, h, rfl⟩,
rw multiset.mem_antidiagonal at h,
simpa only [to_multiset_to_finsupp, multiset.to_finsupp_add]
using congr_arg multiset.to_finsupp h},
{ intro h,
refine ⟨⟨p.1.to_multiset, p.2.to_multiset⟩, _, _⟩,
{ simpa only [multiset.mem_antidiagonal, to_multiset_add]
using congr_arg to_multiset h},
{ rw [prod.map, to_multiset_to_finsupp, to_multiset_to_finsupp, prod.mk.eta] } }
end
@[simp] lemma antidiagonal_zero : antidiagonal (0 : α →₀ ℕ) = single (0,0) 1 :=
by rw [← multiset.to_finsupp_singleton]; refl
lemma swap_mem_antidiagonal_support {n : α →₀ ℕ} {f} (hf : f ∈ (antidiagonal n).support) :
f.swap ∈ (antidiagonal n).support :=
by simpa only [mem_antidiagonal_support, add_comm, prod.swap] using hf
/-- Let `n : α →₀ ℕ` be a finitely supported function.
The set of `m : α →₀ ℕ` that are coordinatewise less than or equal to `n`,
is a finite set. -/
lemma finite_le_nat (n : α →₀ ℕ) : set.finite {m | m ≤ n} :=
begin
let I := {i // i ∈ n.support},
let k : ℕ := ∑ i in n.support, n i,
let f : (α →₀ ℕ) → (I → fin (k + 1)) := λ m i, m i,
have hf : ∀ m ≤ n, ∀ i, (f m i : ℕ) = m i,
{ intros m hm i,
apply fin.coe_coe_of_lt,
calc m i ≤ n i : hm i
... < k + 1 : nat.lt_succ_iff.mpr (single_le_sum (λ _ _, nat.zero_le _) i.2) },
have f_im : set.finite (f '' {m | m ≤ n}) := set.finite.of_fintype _,
suffices f_inj : set.inj_on f {m | m ≤ n},
{ exact set.finite_of_finite_image f_inj f_im },
intros m₁ h₁ m₂ h₂ h,
ext i,
by_cases hi : i ∈ n.support,
{ replace h := congr_fun h ⟨i, hi⟩,
rwa [fin.ext_iff, hf m₁ h₁, hf m₂ h₂] at h },
{ rw not_mem_support_iff at hi,
specialize h₁ i,
specialize h₂ i,
rw [hi, nat.le_zero_iff] at h₁ h₂,
rw [h₁, h₂] }
end
/-- Let `n : α →₀ ℕ` be a finitely supported function.
The set of `m : α →₀ ℕ` that are coordinatewise less than or equal to `n`,
but not equal to `n` everywhere, is a finite set. -/
lemma finite_lt_nat (n : α →₀ ℕ) : set.finite {m | m < n} :=
(finite_le_nat n).subset $ λ m, le_of_lt
end finsupp
|
6c2824823df2b2f8d22ccce9d64ddcb61b3df977
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/combinatorics/simple_graph/strongly_regular.lean
|
05fb2fda4ad5c66e6812266f9b66c6d45ae23491
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 7,145
|
lean
|
/-
Copyright (c) 2021 Alena Gusakov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alena Gusakov
-/
import combinatorics.simple_graph.basic
import data.set.finite
/-!
# Strongly regular graphs
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main definitions
* `G.is_SRG_with n k ℓ μ` (see `simple_graph.is_SRG_with`) is a structure for
a `simple_graph` satisfying the following conditions:
* The cardinality of the vertex set is `n`
* `G` is a regular graph with degree `k`
* The number of common neighbors between any two adjacent vertices in `G` is `ℓ`
* The number of common neighbors between any two nonadjacent vertices in `G` is `μ`
## TODO
- Prove that the parameters of a strongly regular graph
obey the relation `(n - k - 1) * μ = k * (k - ℓ - 1)`
- Prove that if `I` is the identity matrix and `J` is the all-one matrix,
then the adj matrix `A` of SRG obeys relation `A^2 = kI + ℓA + μ(J - I - A)`
-/
open finset
universes u
namespace simple_graph
variables {V : Type u}
variables [fintype V] [decidable_eq V]
variables (G : simple_graph V) [decidable_rel G.adj]
/--
A graph is strongly regular with parameters `n k ℓ μ` if
* its vertex set has cardinality `n`
* it is regular with degree `k`
* every pair of adjacent vertices has `ℓ` common neighbors
* every pair of nonadjacent vertices has `μ` common neighbors
-/
structure is_SRG_with (n k ℓ μ : ℕ) : Prop :=
(card : fintype.card V = n)
(regular : G.is_regular_of_degree k)
(of_adj : ∀ (v w : V), G.adj v w → fintype.card (G.common_neighbors v w) = ℓ)
(of_not_adj : ∀ (v w : V), v ≠ w → ¬G.adj v w → fintype.card (G.common_neighbors v w) = μ)
variables {G} {n k ℓ μ : ℕ}
/-- Empty graphs are strongly regular. Note that `ℓ` can take any value
for empty graphs, since there are no pairs of adjacent vertices. -/
lemma bot_strongly_regular :
(⊥ : simple_graph V).is_SRG_with (fintype.card V) 0 ℓ 0 :=
{ card := rfl,
regular := bot_degree,
of_adj := λ v w h, h.elim,
of_not_adj := λ v w h, begin
simp only [card_eq_zero, filter_congr_decidable, fintype.card_of_finset, forall_true_left,
not_false_iff, bot_adj],
ext,
simp [mem_common_neighbors],
end }
/-- Complete graphs are strongly regular. Note that `μ` can take any value
for complete graphs, since there are no distinct pairs of non-adjacent vertices. -/
lemma is_SRG_with.top :
(⊤ : simple_graph V).is_SRG_with (fintype.card V) (fintype.card V - 1) (fintype.card V - 2) μ :=
{ card := rfl,
regular := is_regular_of_degree.top,
of_adj := λ v w h, begin
rw card_common_neighbors_top,
exact h,
end,
of_not_adj := λ v w h h', false.elim $ by simpa using h }
lemma is_SRG_with.card_neighbor_finset_union_eq {v w : V} (h : G.is_SRG_with n k ℓ μ) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card =
2 * k - fintype.card (G.common_neighbors v w) :=
begin
apply @nat.add_right_cancel _ (fintype.card (G.common_neighbors v w)),
rw [nat.sub_add_cancel, ← set.to_finset_card],
{ simp [neighbor_finset, common_neighbors, set.to_finset_inter, finset.card_union_add_card_inter,
h.regular.degree_eq, two_mul], },
{ apply le_trans (card_common_neighbors_le_degree_left _ _ _),
simp [h.regular.degree_eq, two_mul], },
end
/-- Assuming `G` is strongly regular, `2*(k + 1) - m` in `G` is the number of vertices that are
adjacent to either `v` or `w` when `¬G.adj v w`. So it's the cardinality of
`G.neighbor_set v ∪ G.neighbor_set w`. -/
lemma is_SRG_with.card_neighbor_finset_union_of_not_adj {v w : V} (h : G.is_SRG_with n k ℓ μ)
(hne : v ≠ w) (ha : ¬G.adj v w) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card = 2 * k - μ :=
begin
rw ← h.of_not_adj v w hne ha,
apply h.card_neighbor_finset_union_eq,
end
lemma is_SRG_with.card_neighbor_finset_union_of_adj {v w : V} (h : G.is_SRG_with n k ℓ μ)
(ha : G.adj v w) :
(G.neighbor_finset v ∪ G.neighbor_finset w).card = 2 * k - ℓ :=
begin
rw ← h.of_adj v w ha,
apply h.card_neighbor_finset_union_eq,
end
lemma compl_neighbor_finset_sdiff_inter_eq {v w : V} :
(G.neighbor_finset v)ᶜ \ {v} ∩ ((G.neighbor_finset w)ᶜ \ {w}) =
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ \ ({w} ∪ {v}) :=
by { ext, rw ← not_iff_not, simp [imp_iff_not_or, or_assoc, or_comm, or.left_comm], }
lemma sdiff_compl_neighbor_finset_inter_eq {v w : V} (h : G.adj v w) :
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ \ ({w} ∪ {v}) =
(G.neighbor_finset v)ᶜ ∩ (G.neighbor_finset w)ᶜ :=
begin
ext,
simp only [and_imp, mem_union, mem_sdiff, mem_compl, and_iff_left_iff_imp,
mem_neighbor_finset, mem_inter, mem_singleton],
rintros hnv hnw (rfl|rfl),
{ exact hnv h, },
{ apply hnw, rwa adj_comm, },
end
lemma is_SRG_with.compl_is_regular (h : G.is_SRG_with n k ℓ μ) :
Gᶜ.is_regular_of_degree (n - k - 1) :=
begin
rw [← h.card, nat.sub_sub, add_comm, ←nat.sub_sub],
exact h.regular.compl,
end
lemma is_SRG_with.card_common_neighbors_eq_of_adj_compl (h : G.is_SRG_with n k ℓ μ)
{v w : V} (ha : Gᶜ.adj v w) :
fintype.card ↥(Gᶜ.common_neighbors v w) = n - (2 * k - μ) - 2 :=
begin
simp only [←set.to_finset_card, common_neighbors, set.to_finset_inter, neighbor_set_compl,
set.to_finset_diff, set.to_finset_singleton, set.to_finset_compl, ←neighbor_finset_def],
simp_rw compl_neighbor_finset_sdiff_inter_eq,
have hne : v ≠ w := ne_of_adj _ ha,
rw compl_adj at ha,
rw [card_sdiff, ← insert_eq, card_insert_of_not_mem, card_singleton, ← finset.compl_union],
{ change (1 + 1) with 2,
rw [card_compl, h.card_neighbor_finset_union_of_not_adj hne ha.2, ← h.card], },
{ simp only [hne.symm, not_false_iff, mem_singleton], },
{ intro u,
simp only [mem_union, mem_compl, mem_neighbor_finset, mem_inter, mem_singleton],
rintro (rfl|rfl);
simpa [adj_comm] using ha.2, },
end
lemma is_SRG_with.card_common_neighbors_eq_of_not_adj_compl (h : G.is_SRG_with n k ℓ μ)
{v w : V} (hn : v ≠ w) (hna : ¬Gᶜ.adj v w) :
fintype.card ↥(Gᶜ.common_neighbors v w) = n - (2 * k - ℓ) :=
begin
simp only [←set.to_finset_card, common_neighbors, set.to_finset_inter, neighbor_set_compl,
set.to_finset_diff, set.to_finset_singleton, set.to_finset_compl, ←neighbor_finset_def],
simp only [not_and, not_not, compl_adj] at hna,
have h2' := hna hn,
simp_rw [compl_neighbor_finset_sdiff_inter_eq, sdiff_compl_neighbor_finset_inter_eq h2'],
rwa [← finset.compl_union, card_compl, h.card_neighbor_finset_union_of_adj, ← h.card],
end
/-- The complement of a strongly regular graph is strongly regular. -/
lemma is_SRG_with.compl (h : G.is_SRG_with n k ℓ μ) :
Gᶜ.is_SRG_with n (n - k - 1) (n - (2 * k - μ) - 2) (n - (2 * k - ℓ)) :=
{ card := h.card,
regular := h.compl_is_regular,
of_adj := λ v w ha, h.card_common_neighbors_eq_of_adj_compl ha,
of_not_adj := λ v w hn hna, h.card_common_neighbors_eq_of_not_adj_compl hn hna, }
end simple_graph
|
c2628ac34ac0f7fa2486ebcd940eb1eac8c159eb
|
a45212b1526d532e6e83c44ddca6a05795113ddc
|
/src/data/mllist.lean
|
6be6c5ef6d7f931c6d988e5090f8783c162cd736
|
[
"Apache-2.0"
] |
permissive
|
fpvandoorn/mathlib
|
b21ab4068db079cbb8590b58fda9cc4bc1f35df4
|
b3433a51ea8bc07c4159c1073838fc0ee9b8f227
|
refs/heads/master
| 1,624,791,089,608
| 1,556,715,231,000
| 1,556,715,231,000
| 165,722,980
| 5
| 0
|
Apache-2.0
| 1,552,657,455,000
| 1,547,494,646,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,762
|
lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carnerio, Keeley Hoek, Simon Hudon, Scott Morrison
Monadic lazy lists.
The inductive construction is not allowed outside of meta (indeed, we can build infinite objects).
This isn't so bad, as the typical use is with the tactic monad, in any case.
As we're in meta anyway, we don't bother with proofs about these constructions.
-/
import data.option.basic
universes u v
namespace tactic -- We hide this away in the tactic namespace, just because it's all meta.
meta inductive mllist (m : Type u → Type u) (α : Type u) : Type u
| nil {} : mllist
| cons : m (option α × mllist) → mllist
namespace mllist
variables {m : Type u → Type u}
meta def fix {m : Type u → Type u} [alternative m]
{α} (f : α → m α) : α → mllist m α
| x := cons $ (λ a, (some x, fix a)) <$> f x <|> pure (some x, nil)
variables [monad m]
meta def uncons {α : Type u} : mllist m α → m (option (α × mllist m α))
| nil := pure none
| (cons l) := do (x,xs) ← l,
some x ← return x | uncons xs,
return (x,xs)
meta def empty {α : Type u} (xs : mllist m α) : m (ulift bool) :=
(ulift.up ∘ option.is_some) <$> uncons xs
meta def of_list {α : Type u} : list α → mllist m α
| [] := nil
| (h :: t) := cons (pure (h, of_list t))
meta def m_of_list {α : Type u} : list (m α) → mllist m α
| [] := nil
| (h :: t) := cons ((λ x, (x, m_of_list t)) <$> some <$> h)
meta def force {α} : mllist m α → m (list α)
| nil := pure []
| (cons l) :=
do (x,xs) ← l,
some x ← pure x | force xs,
(::) x <$> (force xs)
meta def take {α} : mllist m α → ℕ → m (list α)
| nil _ := pure []
| _ 0 := pure []
| (cons l) (n+1) :=
do (x,xs) ← l,
some x ← pure x | take xs n,
(::) x <$> (take xs n)
meta def map {α β : Type u} (f : α → β) : mllist m α → mllist m β
| nil := nil
| (cons l) := cons $ do (x,xs) ← l, pure (f <$> x, map xs)
meta def mmap {α β : Type u} (f : α → m β) : mllist m α → mllist m β
| nil := nil
| (cons l) :=
cons $ do (x,xs) ← l,
b ← x.traverse f,
return (b, mmap xs)
meta def filter {α : Type u} (p : α → Prop) [decidable_pred p] : mllist m α → mllist m α
| nil := nil
| (cons l) :=
cons $ do (a,r) ← l ,
some a ← return a | return (none, filter r),
return (if p a then some a else none, filter r)
meta def mfilter [alternative m] {α β : Type u} (p : α → m β) : mllist m α → mllist m α
| nil := nil
| (cons l) :=
cons $ do (a,r) ← l,
some a ← return a | return (none, mfilter r),
(p a >> return (a, mfilter r)) <|> return (none , mfilter r)
meta def filter_map {α β : Type u} (f : α → option β) : mllist m α → mllist m β
| nil := nil
| (cons l) :=
cons $ do (a,r) ← l,
some a ← return a | return (none, filter_map r),
match f a with
| (some b) := return (some b, filter_map r)
| none := return (none, filter_map r)
end
meta def mfilter_map [alternative m] {α β : Type u} (f : α → m β) : mllist m α → mllist m β
| nil := nil
| (cons l) :=
cons $ do (a,r) ← l,
some a ← return a | return (none, mfilter_map r),
(f a >>= (λ b, return (some b, mfilter_map r))) <|> return (none, mfilter_map r)
meta def append {α : Type u} : mllist m α → mllist m α → mllist m α
| nil ys := ys
| (cons xs) ys :=
cons $ do (x,xs) ← xs,
return (x, append xs ys)
meta def join {α : Type u} : mllist m (mllist m α) → mllist m α
| nil := nil
| (cons l) :=
cons $ do (xs,r) ← l,
some xs ← return xs | return (none, join r),
match xs with
| nil := return (none, join r)
| cons m := do (a,n) ← m, return (a, join (cons $ return (n, r)))
end
meta def enum_from {α : Type u} : ℕ → mllist m α → mllist m (ℕ × α)
| _ nil := nil
| n (cons l) :=
cons $ do (a,r) ← l,
some a ← return a | return (none, enum_from n r),
return ((n, a), (enum_from (n + 1) r))
meta def enum {α : Type u} : mllist m α → mllist m (ℕ × α) := enum_from 0
meta def concat {α : Type u} : mllist m α → α → mllist m α
| L a := (mllist.of_list [L, mllist.of_list [a]]).join
meta def bind_ {α β : Type u} : mllist m α → (α → mllist m β) → mllist m β
| nil f := nil
| (cons ll) f :=
cons $ do (x,xs) ← ll,
some x ← return x | return (none, bind_ xs f),
return (none, append (f x) (bind_ xs f))
meta def monad_lift {α} (x : m α) : mllist m α := cons $ (flip prod.mk nil ∘ some) <$> x
end mllist
end tactic
|
b97002ff47fe5e8215fd66207c85fa632f3f4043
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/topology/continuous_function/compact.lean
|
7b83f26c73a942af39e2775fd2bb60f979ff541d
|
[
"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
| 18,817
|
lean
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.continuous_function.bounded
import topology.uniform_space.compact
import topology.compact_open
import topology.sets.compacts
/-!
# Continuous functions on a compact space
Continuous functions `C(α, β)` from a compact space `α` to a metric space `β`
are automatically bounded, and so acquire various structures inherited from `α →ᵇ β`.
This file transfers these structures, and restates some lemmas
characterising these structures.
If you need a lemma which is proved about `α →ᵇ β` but not for `C(α, β)` when `α` is compact,
you should restate it here. You can also use
`bounded_continuous_function.equiv_continuous_map_of_compact` to move functions back and forth.
-/
noncomputable theory
open_locale topology classical nnreal bounded_continuous_function big_operators
open set filter metric
open bounded_continuous_function
namespace continuous_map
variables {α β E : Type*} [topological_space α] [compact_space α] [metric_space β]
[normed_add_comm_group E]
section
variables (α β)
/--
When `α` is compact, the bounded continuous maps `α →ᵇ β` are
equivalent to `C(α, β)`.
-/
@[simps { fully_applied := ff }]
def equiv_bounded_of_compact : C(α, β) ≃ (α →ᵇ β) :=
⟨mk_of_compact, bounded_continuous_function.to_continuous_map,
λ f, by { ext, refl, }, λ f, by { ext, refl, }⟩
lemma uniform_inducing_equiv_bounded_of_compact :
uniform_inducing (equiv_bounded_of_compact α β) :=
uniform_inducing.mk'
begin
simp only [has_basis_compact_convergence_uniformity.mem_iff, uniformity_basis_dist_le.mem_iff],
exact λ s, ⟨λ ⟨⟨a, b⟩, ⟨ha, ⟨ε, hε, hb⟩⟩, hs⟩, ⟨{p | ∀ x, (p.1 x, p.2 x) ∈ b},
⟨ε, hε, λ _ h x, hb (by exact (dist_le hε.le).mp h x)⟩, λ f g h, hs (by exact λ x hx, h x)⟩,
λ ⟨t, ⟨ε, hε, ht⟩, hs⟩, ⟨⟨set.univ, {p | dist p.1 p.2 ≤ ε}⟩,
⟨is_compact_univ, ⟨ε, hε, λ _ h, h⟩⟩,
λ ⟨f, g⟩ h, hs _ _ (ht (by exact (dist_le hε.le).mpr (λ x, h x (mem_univ x))))⟩⟩,
end
lemma uniform_embedding_equiv_bounded_of_compact :
uniform_embedding (equiv_bounded_of_compact α β) :=
{ inj := (equiv_bounded_of_compact α β).injective,
.. uniform_inducing_equiv_bounded_of_compact α β }
/--
When `α` is compact, the bounded continuous maps `α →ᵇ 𝕜` are
additively equivalent to `C(α, 𝕜)`.
-/
@[simps apply symm_apply { fully_applied := ff }]
def add_equiv_bounded_of_compact [add_monoid β] [has_lipschitz_add β] :
C(α, β) ≃+ (α →ᵇ β) :=
({ .. to_continuous_map_add_hom α β,
.. (equiv_bounded_of_compact α β).symm, } : (α →ᵇ β) ≃+ C(α, β)).symm
instance : metric_space C(α, β) :=
(uniform_embedding_equiv_bounded_of_compact α β).comap_metric_space _
/--
When `α` is compact, and `β` is a metric space, the bounded continuous maps `α →ᵇ β` are
isometric to `C(α, β)`.
-/
@[simps to_equiv apply symm_apply { fully_applied := ff }]
def isometry_equiv_bounded_of_compact :
C(α, β) ≃ᵢ (α →ᵇ β) :=
{ isometry_to_fun := λ x y, rfl,
to_equiv := equiv_bounded_of_compact α β }
end
@[simp] lemma _root_.bounded_continuous_function.dist_mk_of_compact (f g : C(α, β)) :
dist (mk_of_compact f) (mk_of_compact g) = dist f g := rfl
@[simp] lemma _root_.bounded_continuous_function.dist_to_continuous_map (f g : α →ᵇ β) :
dist (f.to_continuous_map) (g.to_continuous_map) = dist f g := rfl
open bounded_continuous_function
section
variables {α β} {f g : C(α, β)} {C : ℝ}
/-- The pointwise distance is controlled by the distance between functions, by definition. -/
lemma dist_apply_le_dist (x : α) : dist (f x) (g x) ≤ dist f g :=
by simp only [← dist_mk_of_compact, dist_coe_le_dist, ← mk_of_compact_apply]
/-- The distance between two functions is controlled by the supremum of the pointwise distances -/
lemma dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀x:α, dist (f x) (g x) ≤ C :=
by simp only [← dist_mk_of_compact, dist_le C0, mk_of_compact_apply]
lemma dist_le_iff_of_nonempty [nonempty α] :
dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C :=
by simp only [← dist_mk_of_compact, dist_le_iff_of_nonempty, mk_of_compact_apply]
lemma dist_lt_iff_of_nonempty [nonempty α] :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
by simp only [← dist_mk_of_compact, dist_lt_iff_of_nonempty_compact, mk_of_compact_apply]
lemma dist_lt_of_nonempty [nonempty α] (w : ∀x:α, dist (f x) (g x) < C) : dist f g < C :=
(dist_lt_iff_of_nonempty).2 w
lemma dist_lt_iff (C0 : (0 : ℝ) < C) :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
by simp only [← dist_mk_of_compact, dist_lt_iff_of_compact C0, mk_of_compact_apply]
end
instance [complete_space β] : complete_space (C(α, β)) :=
(isometry_equiv_bounded_of_compact α β).complete_space
/-- See also `continuous_map.continuous_eval'` -/
@[continuity] lemma continuous_eval : continuous (λ p : C(α, β) × α, p.1 p.2) :=
continuous_eval.comp ((isometry_equiv_bounded_of_compact α β).continuous.prod_map continuous_id)
/-- See also `continuous_map.continuous_eval_const` -/
@[continuity] lemma continuous_eval_const (x : α) : continuous (λ f : C(α, β), f x) :=
continuous_eval.comp (continuous_id.prod_mk continuous_const)
/-- See also `continuous_map.continuous_coe'` -/
lemma continuous_coe : @continuous (C(α, β)) (α → β) _ _ coe_fn :=
continuous_pi continuous_eval_const
-- TODO at some point we will need lemmas characterising this norm!
-- At the moment the only way to reason about it is to transfer `f : C(α,E)` back to `α →ᵇ E`.
instance : has_norm C(α, E) :=
{ norm := λ x, dist x 0 }
@[simp] lemma _root_.bounded_continuous_function.norm_mk_of_compact (f : C(α, E)) :
‖mk_of_compact f‖ = ‖f‖ := rfl
@[simp] lemma _root_.bounded_continuous_function.norm_to_continuous_map_eq (f : α →ᵇ E) :
‖f.to_continuous_map‖ = ‖f‖ :=
rfl
open bounded_continuous_function
instance : normed_add_comm_group C(α, E) :=
{ dist_eq := λ x y, by
rw [← norm_mk_of_compact, ← dist_mk_of_compact, dist_eq_norm, mk_of_compact_sub],
dist := dist, norm := norm, .. continuous_map.metric_space _ _, .. continuous_map.add_comm_group }
instance [nonempty α] [has_one E] [norm_one_class E] : norm_one_class C(α, E) :=
{ norm_one := by simp only [←norm_mk_of_compact, mk_of_compact_one, norm_one] }
section
variables (f : C(α, E))
-- The corresponding lemmas for `bounded_continuous_function` are stated with `{f}`,
-- and so can not be used in dot notation.
lemma norm_coe_le_norm (x : α) : ‖f x‖ ≤ ‖f‖ :=
(mk_of_compact f).norm_coe_le_norm x
/-- Distance between the images of any two points is at most twice the norm of the function. -/
lemma dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ‖f‖ :=
(mk_of_compact f).dist_le_two_norm x y
/-- The norm of a function is controlled by the supremum of the pointwise norms -/
lemma norm_le {C : ℝ} (C0 : (0 : ℝ) ≤ C) : ‖f‖ ≤ C ↔ ∀x:α, ‖f x‖ ≤ C :=
@bounded_continuous_function.norm_le _ _ _ _
(mk_of_compact f) _ C0
lemma norm_le_of_nonempty [nonempty α] {M : ℝ} : ‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M :=
@bounded_continuous_function.norm_le_of_nonempty _ _ _ _ _ (mk_of_compact f) _
lemma norm_lt_iff {M : ℝ} (M0 : 0 < M) : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
@bounded_continuous_function.norm_lt_iff_of_compact _ _ _ _ _ (mk_of_compact f) _ M0
theorem nnnorm_lt_iff {M : ℝ≥0} (M0 : 0 < M) : ‖f‖₊ < M ↔ ∀ (x : α), ‖f x‖₊ < M :=
f.norm_lt_iff M0
lemma norm_lt_iff_of_nonempty [nonempty α] {M : ℝ} :
‖f‖ < M ↔ ∀ x, ‖f x‖ < M :=
@bounded_continuous_function.norm_lt_iff_of_nonempty_compact _ _ _ _ _ _ (mk_of_compact f) _
lemma nnnorm_lt_iff_of_nonempty [nonempty α] {M : ℝ≥0} :
‖f‖₊ < M ↔ ∀ x, ‖f x‖₊ < M :=
f.norm_lt_iff_of_nonempty
lemma apply_le_norm (f : C(α, ℝ)) (x : α) : f x ≤ ‖f‖ :=
le_trans (le_abs.mpr (or.inl (le_refl (f x)))) (f.norm_coe_le_norm x)
lemma neg_norm_le_apply (f : C(α, ℝ)) (x : α) : -‖f‖ ≤ f x :=
le_trans (neg_le_neg (f.norm_coe_le_norm x)) (neg_le.mp (neg_le_abs_self (f x)))
lemma norm_eq_supr_norm : ‖f‖ = ⨆ x : α, ‖f x‖ :=
(mk_of_compact f).norm_eq_supr_norm
lemma norm_restrict_mono_set {X : Type*} [topological_space X]
(f : C(X, E)) {K L : topological_space.compacts X} (hKL : K ≤ L) :
‖f.restrict K‖ ≤ ‖f.restrict L‖ :=
(norm_le _ (norm_nonneg _)).mpr (λ x, norm_coe_le_norm (f.restrict L) $ set.inclusion hKL x)
end
section
variables {R : Type*} [normed_ring R]
instance : normed_ring C(α,R) :=
{ norm_mul := λ f g, norm_mul_le (mk_of_compact f) (mk_of_compact g),
..(infer_instance : normed_add_comm_group C(α,R)),
.. continuous_map.ring }
end
section
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E]
instance : normed_space 𝕜 C(α,E) :=
{ norm_smul_le := λ c f, (norm_smul_le c (mk_of_compact f) : _) }
section
variables (α 𝕜 E)
/--
When `α` is compact and `𝕜` is a normed field,
the `𝕜`-algebra of bounded continuous maps `α →ᵇ β` is
`𝕜`-linearly isometric to `C(α, β)`.
-/
def linear_isometry_bounded_of_compact :
C(α, E) ≃ₗᵢ[𝕜] (α →ᵇ E) :=
{ map_smul' := λ c f, by { ext, simp, },
norm_map' := λ f, rfl,
.. add_equiv_bounded_of_compact α E }
variables {α E} -- to match bounded_continuous_function.eval_clm
/-- The evaluation at a point, as a continuous linear map from `C(α, 𝕜)` to `𝕜`. -/
def eval_clm (x : α) : C(α, E) →L[𝕜] E :=
(eval_clm 𝕜 x).comp
((linear_isometry_bounded_of_compact α E 𝕜).to_linear_isometry).to_continuous_linear_map
end
-- this lemma and the next are the analogues of those autogenerated by `@[simps]` for
-- `equiv_bounded_of_compact`, `add_equiv_bounded_of_compact`
@[simp] lemma linear_isometry_bounded_of_compact_symm_apply (f : α →ᵇ E) :
(linear_isometry_bounded_of_compact α E 𝕜).symm f = f.to_continuous_map :=
rfl
@[simp] lemma linear_isometry_bounded_of_compact_apply_apply (f : C(α, E)) (a : α) :
(linear_isometry_bounded_of_compact α E 𝕜 f) a = f a :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_to_isometry_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_isometry_equiv =
(isometry_equiv_bounded_of_compact α E) :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_to_add_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_equiv.to_add_equiv =
(add_equiv_bounded_of_compact α E) :=
rfl
@[simp]
lemma linear_isometry_bounded_of_compact_of_compact_to_equiv :
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_equiv.to_equiv =
(equiv_bounded_of_compact α E) :=
rfl
end
section
variables {𝕜 : Type*} {γ : Type*} [normed_field 𝕜] [normed_ring γ] [normed_algebra 𝕜 γ]
instance : normed_algebra 𝕜 C(α, γ) :=
{ ..continuous_map.normed_space }
end
end continuous_map
namespace continuous_map
section uniform_continuity
variables {α β : Type*}
variables [metric_space α] [compact_space α] [metric_space β]
/-!
We now set up some declarations making it convenient to use uniform continuity.
-/
lemma uniform_continuity
(f : C(α, β)) (ε : ℝ) (h : 0 < ε) :
∃ δ > 0, ∀ {x y}, dist x y < δ → dist (f x) (f y) < ε :=
metric.uniform_continuous_iff.mp
(compact_space.uniform_continuous_of_continuous f.continuous) ε h
/--
An arbitrarily chosen modulus of uniform continuity for a given function `f` and `ε > 0`.
-/
-- This definition allows us to separate the choice of some `δ`,
-- and the corresponding use of `dist a b < δ → dist (f a) (f b) < ε`,
-- even across different declarations.
def modulus (f : C(α, β)) (ε : ℝ) (h : 0 < ε) : ℝ :=
classical.some (uniform_continuity f ε h)
lemma modulus_pos (f : C(α, β)) {ε : ℝ} {h : 0 < ε} : 0 < f.modulus ε h :=
(classical.some_spec (uniform_continuity f ε h)).fst
lemma dist_lt_of_dist_lt_modulus
(f : C(α, β)) (ε : ℝ) (h : 0 < ε) {a b : α} (w : dist a b < f.modulus ε h) :
dist (f a) (f b) < ε :=
(classical.some_spec (uniform_continuity f ε h)).snd w
end uniform_continuity
end continuous_map
section comp_left
variables (X : Type*) {𝕜 β γ : Type*} [topological_space X] [compact_space X]
[nontrivially_normed_field 𝕜]
variables [normed_add_comm_group β] [normed_space 𝕜 β] [normed_add_comm_group γ] [normed_space 𝕜 γ]
open continuous_map
/--
Postcomposition of continuous functions into a normed module by a continuous linear map is a
continuous linear map.
Transferred version of `continuous_linear_map.comp_left_continuous_bounded`,
upgraded version of `continuous_linear_map.comp_left_continuous`,
similar to `linear_map.comp_left`. -/
protected def continuous_linear_map.comp_left_continuous_compact (g : β →L[𝕜] γ) :
C(X, β) →L[𝕜] C(X, γ) :=
(linear_isometry_bounded_of_compact X γ 𝕜).symm.to_linear_isometry.to_continuous_linear_map.comp $
(g.comp_left_continuous_bounded X).comp $
(linear_isometry_bounded_of_compact X β 𝕜).to_linear_isometry.to_continuous_linear_map
@[simp] lemma continuous_linear_map.to_linear_comp_left_continuous_compact (g : β →L[𝕜] γ) :
(g.comp_left_continuous_compact X : C(X, β) →ₗ[𝕜] C(X, γ)) = g.comp_left_continuous 𝕜 X :=
by { ext f, refl }
@[simp] lemma continuous_linear_map.comp_left_continuous_compact_apply (g : β →L[𝕜] γ)
(f : C(X, β)) (x : X) :
g.comp_left_continuous_compact X f x = g (f x) :=
rfl
end comp_left
namespace continuous_map
/-!
We now setup variations on `comp_right_* f`, where `f : C(X, Y)`
(that is, precomposition by a continuous map),
as a morphism `C(Y, T) → C(X, T)`, respecting various types of structure.
In particular:
* `comp_right_continuous_map`, the bundled continuous map (for this we need `X Y` compact).
* `comp_right_homeomorph`, when we precompose by a homeomorphism.
* `comp_right_alg_hom`, when `T = R` is a topological ring.
-/
section comp_right
/--
Precomposition by a continuous map is itself a continuous map between spaces of continuous maps.
-/
def comp_right_continuous_map {X Y : Type*} (T : Type*) [topological_space X] [compact_space X]
[topological_space Y] [compact_space Y] [metric_space T]
(f : C(X, Y)) : C(C(Y, T), C(X, T)) :=
{ to_fun := λ g, g.comp f,
continuous_to_fun :=
begin
refine metric.continuous_iff.mpr _,
intros g ε ε_pos,
refine ⟨ε, ε_pos, λ g' h, _⟩,
rw continuous_map.dist_lt_iff ε_pos at h ⊢,
{ exact λ x, h (f x), },
end }
@[simp] lemma comp_right_continuous_map_apply {X Y : Type*} (T : Type*) [topological_space X]
[compact_space X] [topological_space Y] [compact_space Y] [metric_space T]
(f : C(X, Y)) (g : C(Y, T)) :
(comp_right_continuous_map T f) g = g.comp f :=
rfl
/--
Precomposition by a homeomorphism is itself a homeomorphism between spaces of continuous maps.
-/
def comp_right_homeomorph {X Y : Type*} (T : Type*) [topological_space X] [compact_space X]
[topological_space Y] [compact_space Y] [metric_space T]
(f : X ≃ₜ Y) : C(Y, T) ≃ₜ C(X, T) :=
{ to_fun := comp_right_continuous_map T f.to_continuous_map,
inv_fun := comp_right_continuous_map T f.symm.to_continuous_map,
left_inv := λ g, ext $ λ _, congr_arg g (f.apply_symm_apply _),
right_inv := λ g, ext $ λ _, congr_arg g (f.symm_apply_apply _) }
lemma comp_right_alg_hom_continuous {X Y : Type*} (R A : Type*)
[topological_space X] [compact_space X] [topological_space Y] [compact_space Y] [comm_semiring R]
[semiring A] [metric_space A] [topological_semiring A] [algebra R A] (f : C(X, Y)) :
continuous (comp_right_alg_hom R A f) :=
map_continuous (comp_right_continuous_map A f)
end comp_right
section local_normal_convergence
/-! ### Local normal convergence
A sum of continuous functions (on a locally compact space) is "locally normally convergent" if the
sum of its sup-norms on any compact subset is summable. This implies convergence in the topology
of `C(X, E)` (i.e. locally uniform convergence). -/
open topological_space
variables {X : Type*} [topological_space X] [t2_space X] [locally_compact_space X]
variables {E : Type*} [normed_add_comm_group E] [complete_space E]
lemma summable_of_locally_summable_norm {ι : Type*} {F : ι → C(X, E)}
(hF : ∀ K : compacts X, summable (λ i, ‖(F i).restrict K‖)) :
summable F :=
begin
refine (continuous_map.exists_tendsto_compact_open_iff_forall _).2 (λ K hK, _),
lift K to compacts X using hK,
have A : ∀ s : finset ι, restrict ↑K (∑ i in s, F i) = ∑ i in s, restrict K (F i),
{ intro s, ext1 x, simp },
simpa only [has_sum, A] using summable_of_summable_norm (hF K)
end
end local_normal_convergence
/-!
### Star structures
In this section, if `β` is a normed ⋆-group, then so is the space of
continuous functions from `α` to `β`, by using the star operation pointwise.
Furthermore, if `α` is compact and `β` is a C⋆-ring, then `C(α, β)` is a C⋆-ring. -/
section normed_space
variables {α : Type*} {β : Type*}
variables [topological_space α] [normed_add_comm_group β] [star_add_monoid β] [normed_star_group β]
lemma _root_.bounded_continuous_function.mk_of_compact_star [compact_space α] (f : C(α, β)) :
mk_of_compact (star f) = star (mk_of_compact f) := rfl
instance [compact_space α] : normed_star_group C(α, β) :=
{ norm_star := λ f, by rw [←bounded_continuous_function.norm_mk_of_compact,
bounded_continuous_function.mk_of_compact_star, norm_star,
bounded_continuous_function.norm_mk_of_compact] }
end normed_space
section cstar_ring
variables {α : Type*} {β : Type*}
variables [topological_space α] [normed_ring β] [star_ring β]
instance [compact_space α] [cstar_ring β] : cstar_ring C(α, β) :=
{ norm_star_mul_self :=
begin
intros f,
refine le_antisymm _ _,
{ rw [←sq, continuous_map.norm_le _ (sq_nonneg _)],
intro x,
simp only [continuous_map.coe_mul, coe_star, pi.mul_apply, pi.star_apply,
cstar_ring.norm_star_mul_self, ←sq],
refine sq_le_sq' _ _,
{ linarith [norm_nonneg (f x), norm_nonneg f] },
{ exact continuous_map.norm_coe_le_norm f x }, },
{ rw [←sq, ←real.le_sqrt (norm_nonneg _) (norm_nonneg _),
continuous_map.norm_le _ (real.sqrt_nonneg _)],
intro x,
rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ←cstar_ring.norm_star_mul_self],
exact continuous_map.norm_coe_le_norm (star f * f) x },
end }
end cstar_ring
end continuous_map
|
9aa638c289f6a0ffbdbcf47619e573afe0f6cea4
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/src/analysis/normed_space/conformal_linear_map.lean
|
2ca1d2a0a6c12621c195e66f484a88b0dc0be9a0
|
[
"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
| 5,017
|
lean
|
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
import analysis.normed_space.inner_product
/-!
# Conformal Linear Maps
A continuous linear map between `R`-normed spaces `X` and `Y` `is_conformal_map` if it is
a nonzero multiple of a linear isometry.
## Main definitions
* `is_conformal_map`: the main definition of conformal linear maps
## Main results
* The conformality of the composition of two conformal linear maps, the identity map
and multiplications by nonzero constants as continuous linear maps
* `is_conformal_map_iff`: an equivalent definition of the conformality
* `is_conformal_map_of_subsingleton`: all continuous linear maps on singleton spaces are conformal
* `is_conformal_map.preserves_angle`: if a continuous linear map is conformal, then it
preserves all angles in the normed space
## Tags
conformal
## Warning
The definition of conformality in this file does NOT require the maps to be orientation-preserving.
-/
noncomputable theory
open linear_isometry continuous_linear_map
open_locale real_inner_product_space
/-- A continuous linear map `f'` is said to be conformal if it's
a nonzero multiple of a linear isometry. -/
def is_conformal_map {R : Type*} {X Y : Type*} [nondiscrete_normed_field R]
[normed_group X] [normed_group Y] [normed_space R X] [normed_space R Y]
(f' : X →L[R] Y) :=
∃ (c : R) (hc : c ≠ 0) (li : X →ₗᵢ[R] Y), (f' : X → Y) = c • li
variables {E F : Type*} [inner_product_space ℝ E] [inner_product_space ℝ F]
{X Y Z : Type*} [normed_group X] [normed_group Y] [normed_group Z]
[normed_space ℝ X] [normed_space ℝ Y] [normed_space ℝ Z]
{R M N G : Type*} [nondiscrete_normed_field R]
[normed_group M] [normed_group N] [normed_group G]
[normed_space R M] [normed_space R N] [normed_space R G]
lemma is_conformal_map_id : is_conformal_map (id R M) :=
⟨1, one_ne_zero, id, by ext; simp⟩
lemma is_conformal_map_const_smul {c : R} (hc : c ≠ 0) : is_conformal_map (c • (id R M)) :=
⟨c, hc, id, by ext; simp⟩
lemma linear_isometry.is_conformal_map (f' : E →ₗᵢ[ℝ] F) :
is_conformal_map f'.to_continuous_linear_map :=
⟨1, one_ne_zero, f', by ext; simp⟩
lemma is_conformal_map_iff (f' : E →L[ℝ] F) :
is_conformal_map f' ↔ ∃ (c : ℝ), 0 < c ∧
∀ (u v : E), ⟪f' u, f' v⟫ = (c : ℝ) * ⟪u, v⟫ :=
begin
split,
{ rintros ⟨c₁, hc₁, li, h⟩,
refine ⟨c₁ * c₁, mul_self_pos hc₁, λ u v, _⟩,
simp only [h, pi.smul_apply, inner_map_map,
real_inner_smul_left, real_inner_smul_right, mul_assoc], },
{ rintros ⟨c₁, hc₁, huv⟩,
let c := real.sqrt c₁⁻¹,
have hc : c ≠ 0 := λ w, by {simp only [c] at w;
exact (real.sqrt_ne_zero'.mpr $ inv_pos.mpr hc₁) w},
let f₁ := c • f',
have minor : (f₁ : E → F) = c • f' := rfl,
have minor' : (f' : E → F) = c⁻¹ • f₁ := by ext;
simp_rw [minor, pi.smul_apply]; rw [smul_smul, inv_mul_cancel hc, one_smul],
refine ⟨c⁻¹, inv_ne_zero hc, f₁.to_linear_map.isometry_of_inner (λ u v, _), minor'⟩,
simp_rw [to_linear_map_eq_coe, continuous_linear_map.coe_coe, minor, pi.smul_apply],
rw [real_inner_smul_left, real_inner_smul_right,
huv u v, ← mul_assoc, ← mul_assoc,
real.mul_self_sqrt $ le_of_lt $ inv_pos.mpr hc₁,
inv_mul_cancel $ ne_of_gt hc₁, one_mul], },
end
lemma is_conformal_map_of_subsingleton [h : subsingleton M] (f' : M →L[R] N) :
is_conformal_map f' :=
begin
rw subsingleton_iff at h,
have minor : (f' : M → N) = function.const M 0 := by ext x'; rw h x' 0; exact f'.map_zero,
have key : ∀ (x' : M), ∥(0 : M →ₗ[R] N) x'∥ = ∥x'∥ := λ x',
by rw [linear_map.zero_apply, h x' 0]; repeat { rw norm_zero },
exact ⟨(1 : R), one_ne_zero, ⟨0, key⟩,
by rw pi.smul_def; ext p; rw [one_smul, minor]; refl⟩,
end
namespace is_conformal_map
lemma comp {f' : M →L[R] N} {g' : N →L[R] G}
(hg' : is_conformal_map g') (hf' : is_conformal_map f') :
is_conformal_map (g'.comp f') :=
begin
rcases hf' with ⟨cf, hcf, lif, hlif⟩,
rcases hg' with ⟨cg, hcg, lig, hlig⟩,
refine ⟨cg * cf, mul_ne_zero hcg hcf, lig.comp lif, funext (λ x, _)⟩,
simp only [coe_comp', linear_isometry.coe_comp, hlif, hlig, pi.smul_apply,
function.comp_app, linear_isometry.map_smul, smul_smul],
end
lemma injective {f' : M →L[R] N} (h : is_conformal_map f') : function.injective f' :=
let ⟨c, hc, li, hf'⟩ := h in by simp only [hf', pi.smul_def];
exact (smul_right_injective _ hc).comp li.injective
lemma ne_zero [nontrivial M] {f' : M →L[R] N} (hf' : is_conformal_map f') :
f' ≠ 0 :=
begin
intros w,
rcases exists_ne (0 : M) with ⟨a, ha⟩,
have : f' a = f' 0,
{ simp_rw [w, continuous_linear_map.zero_apply], },
exact ha (hf'.injective this),
end
end is_conformal_map
|
c7b6b3fd8feefee926fd61a5d35dd21f9c6ba56d
|
4a092885406df4e441e9bb9065d9405dacb94cd8
|
/src/for_mathlib/finset.lean
|
4b65aa362f8471a42e575a23ade1f3bfca9fba85
|
[
"Apache-2.0"
] |
permissive
|
semorrison/lean-perfectoid-spaces
|
78c1572cedbfae9c3e460d8aaf91de38616904d8
|
bb4311dff45791170bcb1b6a983e2591bee88a19
|
refs/heads/master
| 1,588,841,765,494
| 1,554,805,620,000
| 1,554,805,620,000
| 180,353,546
| 0
| 1
| null | 1,554,809,880,000
| 1,554,809,880,000
| null |
UTF-8
|
Lean
| false
| false
| 1,800
|
lean
|
import data.finset
local attribute [instance] classical.prop_decidable
namespace finset
open function
variables {α : Type*} {β : Type*} (t : finset β) (f : α → β)
set_option pp.proofs true
lemma exists_finset_of_surjective (h : surjective f) :
∃ (s : finset α), s.image f = t :=
⟨t.bind $ λ b, singleton $ classical.some $ h b,
begin
ext b,
simp only [bind_image, mem_bind, mem_image],
split; intro H,
{ rcases H with ⟨b', hb', a, ha, H⟩,
erw [mem_singleton] at ha,
subst ha,
subst H,
rwa classical.some_spec (h b') },
{ use [b, H],
refine ⟨_, mem_singleton_self _, _⟩,
rw classical.some_spec (h b) }
end⟩
lemma exists_finset_of_subset_range (h : (↑t : set β) ⊆ set.range f) :
∃ (s : finset α), s.image f = t :=
begin
let f' := set.range_factorization f,
let t' : finset (set.range f) := finset.subtype _ t,
cases exists_finset_of_surjective t' f' (set.surjective_onto_range) with s hs,
use s,
convert congr_arg (image subtype.val) hs,
{ erw [image_image, set.range_factorization_eq] },
{ ext b,
erw mem_image,
split; intro H,
{ refine ⟨⟨b, h H⟩, mem_subtype.mpr H, rfl⟩ },
{ rcases H with ⟨_, _, rfl⟩,
exact mem_subtype.mp ‹_› } }
end
lemma exists_finset_of_subset_image (s : set α) (h : (↑t : set β) ⊆ f '' s) :
∃ (s' : finset α), s'.image f = t ∧ (↑s' : set α) ⊆ s :=
begin
have H : ↑t ⊆ set.range (f ∘ (subtype.val : s → α)) :=
by rw [set.range_comp, set.subtype.val_range]; exact h,
cases exists_finset_of_subset_range t (f ∘ (subtype.val : s → α)) H with s' hs',
refine ⟨(s'.image (subtype.val : s → α)), _, _⟩,
{ erw image_image, exact hs' },
{ erw coe_image,
apply subtype.val_image_subset }
end
end finset
|
ba34b5deabebf512775d4936706db7751c3fec53
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/binopIssues.lean
|
200dd92bc34e6be8a1c85ab203789c1eb559cd14
|
[
"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
| 245
|
lean
|
axiom Int.add_comm (i j : Int) : i + j = j + i
example (n : Nat) (i : Int) : n + i = i + n := by
rw [Int.add_comm]
def f1 (a : Int) (b c : Nat) : Int :=
a + (b - c)
def f2 (a : Int) (b c : Nat) : Int :=
(b - c) + a
#print f1
#print f2
|
ee7da79439187358953aa4c2dc56d6df125cef57
|
a721fe7446524f18ba361625fc01033d9c8b7a78
|
/elaborate/mul_cancel_induction.lean
|
bf2a14fd5f00c87b23b3355f56c2f99a17888cd0
|
[] |
no_license
|
Sterrs/leaning
|
8fd80d1f0a6117a220bb2e57ece639b9a63deadc
|
3901cc953694b33adda86cb88ca30ba99594db31
|
refs/heads/master
| 1,627,023,822,744
| 1,616,515,221,000
| 1,616,515,221,000
| 245,512,190
| 2
| 0
| null | 1,616,429,050,000
| 1,583,527,118,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 88,091
|
lean
|
mynat.rec
(λ {m k : mynat} (hmn0 : m = zero → false) (hmk0 : zero = mul m k),
eq.rec (eq.refl k)
(mynat.rec
(eq.rec true.intro
(eq.rec (eq.refl ((m = zero → false) → zero = zero → zero = zero))
(eq.rec
(propext
{mp := λ (hab : (m = zero → false) → zero = zero → zero = zero) (hc : m = zero → false),
(eq.rec
{mp := λ (h : zero = zero → zero = zero), h,
mpr := λ (h : zero = zero → zero = zero), h}
(eq.rec
(propext
{mp := λ (hab : zero = zero → zero = zero) (hc : true),
(eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
(hab
((eq.rec
{mp := λ (h : zero = zero), h,
mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
hc)),
mpr := λ (hcd : true → true) (ha : zero = zero),
(eq.rec
{mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
(hcd
((eq.rec
{mp := λ (h : zero = zero), h,
mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
ha))})
(propext
{mp := λ (h : true → true), h true.intro, mpr := λ (h h' : true), h}))).mp
(hab hc),
mpr := λ (hcd : (m = zero → false) → true) (ha : m = zero → false),
(eq.rec
{mp := λ (h : zero = zero → zero = zero), h,
mpr := λ (h : zero = zero → zero = zero), h}
(eq.rec
(propext
{mp := λ (hab : zero = zero → zero = zero) (hc : true),
(eq.rec
{mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
(hab
((eq.rec
{mp := λ (h : zero = zero), h,
mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
hc)),
mpr := λ (hcd : true → true) (ha : zero = zero),
(eq.rec
{mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
(hcd
((eq.rec
{mp := λ (h : zero = zero), h,
mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
ha))})
(propext
{mp := λ (h : true → true), h true.intro, mpr := λ (h h' : true), h}))).mpr
(hcd ha)})
(propext
{mp := λ (h : (m = zero → false) → true), true.intro,
mpr := λ (ha : true) (h : m = zero → false), true.intro}))))
(λ (n : mynat) (ih : (m = zero → false) → mul m n = zero → n = zero) (hmne0 : m = zero → false)
(hmn0 : add m (mul m n) = zero),
false.rec (succ n = zero)
(hmne0
(mynat.rec
(eq.rec true.intro
(eq.rec (eq.refl (add zero (mul m n) = zero → zero = zero))
(eq.rec
(propext
{mp := λ (hab : add zero (mul m n) = zero → zero = zero) (hc : mul m n = zero),
(eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
(hab
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec ⟨eq.refl zero, punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (add zero n = n) ih)
punit)
n)),
⟨eq.rec (eq.refl (succ n))
(eq.rec
(eq.refl
(succ (add zero n) = succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (∀ (m : mynat), add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl (succ (add m n) = add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
((mynat.rec
⟨λ (m : mynat), eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ (succ (add m n))))
(eq.rec
(eq.refl
(succ (add (succ m) n) =
succ
(succ (add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m)
n) =
succ
(succ
(add m n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mpr
hc)),
mpr := λ (hcd : mul m n = zero → true) (ha : add zero (mul m n) = zero),
(eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
(hcd
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec ⟨eq.refl zero, punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (add zero n = n) ih)
punit)
n)),
⟨eq.rec (eq.refl (succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat), add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl (succ (add m n) = add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
((mynat.rec
⟨λ (m : mynat), eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ (succ (add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m) n) =
succ
(succ (add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m)
n) =
succ
(succ
(add m n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mp
ha))})
(propext
{mp := λ (h : mul m n = zero → true), true.intro,
mpr := λ (ha : true) (h : mul m n = zero), true.intro}))))
(λ (n_1 : mynat) (ih : add n_1 (mul m n) = zero → n_1 = zero),
eq.rec
(λ (h : succ (add n_1 (mul m n)) = zero),
false.rec (succ n_1 = zero)
(eq.rec
(λ («_» : succ (add n_1 (mul m n)) = succ (add n_1 (mul m n)))
(a : zero = succ (add n_1 (mul m n))),
eq.rec
(λ (h11 : zero = zero) (a : h == eq.refl (succ (add n_1 (mul m n))) → false),
a)
a
a)
h
h
(eq.refl zero)
(heq.refl h)))
(eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero))
(eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero))
((mynat.rec ⟨λ (m : mynat), eq.refl (succ m), punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add (succ m) n = succ (add m n))
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod (pprod (∀ (m : mynat), add (succ m) n = succ (add m n)) ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec (eq.refl (succ (succ (add m n))))
(eq.rec (eq.refl (succ (add (succ m) n) = succ (succ (add m n))))
(eq.rec (eq.refl (succ (add (succ m) n) = succ (succ (add m n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
n_1))))
m
hmn0)))
k
hmn0
(eq.rec (eq.refl zero) hmk0)))
(λ (n : mynat) (hn : ∀ {m k : mynat}, (m = zero → false) → mul m n = mul m k → n = k) {m k : mynat}
(hmn0 : m = zero → false) (heq_1 : add m (mul m n) = mul m k),
mynat.rec
(λ (heq_1 : add m (mul m n) = zero),
false.rec (succ n = zero)
(eq.rec
(λ («_» : succ n = succ n) (a : zero = succ n),
eq.rec
(λ (h11 : zero = zero)
(a :
false.rec (succ n = zero)
(hmn0
(mynat.rec
(eq.rec true.intro
(eq.rec (eq.refl (add zero (mul m n) = zero → zero = zero))
(eq.rec
(propext
{mp := λ (hab : add zero (mul m n) = zero → zero = zero)
(hc : mul m n = zero),
(eq.rec
{mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
(hab
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec
⟨eq.refl zero,
punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod
(pprod … ih)
punit)
n)),
⟨eq.rec
(eq.refl (succ n))
(eq.rec
(eq.refl
(succ (… n) =
succ n))
(eq.rec
(eq.refl
(succ … =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat),
add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl
(succ (add m n) =
add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) =
add (succ n) m))
((mynat.rec
⟨λ (m : mynat),
eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod (… ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ
(succ …)))
(eq.rec
(eq.refl
(… = …))
(eq.rec
(eq.refl
…)
(ih.fst
m))),
⟨ih,
punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mpr
hc)),
mpr := λ (hcd : mul m n = zero → true)
(ha : add zero (mul m n) = zero),
(eq.rec
{mp := λ (h : zero = zero), h,
mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
(hcd
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec
⟨eq.refl zero,
punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod
(pprod … ih)
punit)
n)),
⟨eq.rec
(eq.refl (succ n))
(eq.rec
(eq.refl
(succ (… n) =
succ n))
(eq.rec
(eq.refl
(succ … =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat),
add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl
(succ (add m n) =
add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) =
add (succ n) m))
((mynat.rec
⟨λ (m : mynat),
eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod (… ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ
(succ
…)))
(eq.rec
(eq.refl
(… =
…))
(eq.rec
(eq.refl
…)
(ih.fst
m))),
⟨ih,
punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mp
ha))})
(propext
{mp := λ (h : mul m n = zero → true), true.intro,
mpr := λ (ha : true) (h : mul m n = zero), true.intro}))))
(λ (n_1 : mynat) (ih : add n_1 (mul m n) = zero → n_1 = zero),
eq.rec
(λ (h : succ (add n_1 (mul m n)) = zero),
false.rec (succ n_1 = zero)
(eq.rec
(λ («_» : succ (add n_1 (mul m n)) = succ (add n_1 (mul m n)))
(a : zero = succ (add n_1 (mul m n))),
eq.rec
(λ (h11 : zero = zero)
(a : h == eq.refl (succ (add n_1 (mul m n))) → false), a)
a
a)
h
h
(eq.refl zero)
(heq.refl h)))
(eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero))
(eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero))
((mynat.rec ⟨λ (m : mynat), eq.refl (succ m), punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add (succ m) n = succ (add m n))
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (∀ (m : mynat), add (succ m) n = succ (add m n))
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec (eq.refl (succ (succ (add m n))))
(eq.rec
(eq.refl (succ (add (succ m) n) = succ (succ (add m n))))
(eq.rec
(eq.refl (succ (add (succ m) n) = succ (succ (add m n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
n_1))))
m
heq_1)) ==
eq.refl (succ n) →
false), a)
a
a)
(false.rec (succ n = zero)
(hmn0
(mynat.rec
(eq.rec true.intro
(eq.rec (eq.refl (add zero (mul m n) = zero → zero = zero))
(eq.rec
(propext
{mp := λ (hab : add zero (mul m n) = zero → zero = zero) (hc : mul m n = zero),
(eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mp
(hab
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec ⟨eq.refl zero, punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (add zero n = n)
ih)
punit)
n)),
⟨eq.rec (eq.refl (succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat), add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
((mynat.rec
⟨λ (m : mynat),
eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod
(pprod
(∀ (m : mynat),
add (succ m) n =
succ
(add m n))
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ (succ (add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m)
n) =
succ
(succ
(add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m)
n) =
succ
(succ
(add m
n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mpr
hc)),
mpr := λ (hcd : mul m n = zero → true) (ha : add zero (mul m n) = zero),
(eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h}
(eq.rec (eq.refl (zero = zero))
(propext
{mp := λ (hl : zero = zero), true.intro,
mpr := λ (hr : true), eq.refl zero}))).mpr
(hcd
((eq.rec
{mp := λ (h : add zero (mul m n) = zero), h,
mpr := λ (h : add zero (mul m n) = zero), h}
(eq.rec (eq.refl (add zero (mul m n) = zero))
(eq.rec (eq.refl (eq (add zero (mul m n))))
(eq.rec (eq.refl (add zero (mul m n)))
((mynat.rec
⟨λ (m : mynat),
eq.rec (eq.refl m)
(eq.rec (eq.refl (m = add zero m))
(eq.rec (eq.refl (m = add zero m))
((mynat.rec
⟨eq.refl zero, punit.star⟩
(λ (n : mynat)
(ih :
pprod (add zero n = n)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod (add zero n = n)
ih)
punit)
n)),
⟨eq.rec (eq.refl (succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(eq.rec
(eq.refl
(succ (add zero n) =
succ n))
(ih.fst))),
⟨ih, punit.star⟩⟩)
m).fst))),
punit.star⟩
(λ (n : mynat)
(ih :
pprod (∀ (m : mynat), add m n = add n m)
(mynat.rec punit
(λ (n : mynat) (ih : Type),
pprod
(pprod
(∀ (m : mynat), add m n = add n m)
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.rec (eq.refl (succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) = succ (add n m)))
(eq.rec
(eq.refl
(succ (add m n) =
succ (add n m)))
(ih.fst m))))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
(eq.rec
(eq.refl
(succ (add m n) = add (succ n) m))
((mynat.rec
⟨λ (m : mynat),
eq.refl (succ m),
punit.star⟩
(λ (n : mynat)
(ih :
pprod
(∀ (m : mynat),
add (succ m) n =
succ (add m n))
(mynat.rec punit
(λ (n : mynat)
(ih : Type),
pprod
(pprod
(∀ (m : mynat),
add (succ m)
n =
succ
(add m n))
ih)
punit)
n)),
⟨λ (m : mynat),
eq.rec
(eq.refl
(succ
(succ (add m n))))
(eq.rec
(eq.refl
(succ
(add (succ m)
n) =
succ
(succ
(add m n))))
(eq.rec
(eq.refl
(succ
(add
(succ m)
n) =
succ
(succ
(add m
n))))
(ih.fst m))),
⟨ih, punit.star⟩⟩)
m).fst
n))),
⟨ih, punit.star⟩⟩)
(mul m n)).fst
zero))))).mp
ha))})
(propext
{mp := λ (h : mul m n = zero → true), true.intro,
mpr := λ (ha : true) (h : mul m n = zero), true.intro}))))
(λ (n_1 : mynat) (ih : add n_1 (mul m n) = zero → n_1 = zero),
eq.rec
(λ (h : succ (add n_1 (mul m n)) = zero),
false.rec (succ n_1 = zero)
(eq.rec
(λ («_» : succ (add n_1 (mul m n)) = succ (add n_1 (mul m n)))
(a : zero = succ (add n_1 (mul m n))),
eq.rec
(λ (h11 : zero = zero)
(a : h == eq.refl (succ (add n_1 (mul m n))) → false), a)
a
a)
h
h
(eq.refl zero)
(heq.refl h)))
(eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero))
(eq.rec (eq.refl …) …)))
m
heq_1)))
…
…
…))
…
k
heq_1)
?M_1
|
f4cb476657fd5600f7d5d369433fa6e0078da927
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/category_theory/limits/shapes/biproducts_auto.lean
|
386f2c6d371f14d17ae8b10fb430c34a2c97e089
|
[] |
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
| 44,424
|
lean
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.limits.shapes.finite_products
import Mathlib.category_theory.limits.shapes.binary_products
import Mathlib.category_theory.preadditive.default
import Mathlib.PostPort
universes v u l
namespace Mathlib
/-!
# Biproducts and binary biproducts
We introduce the notion of (finite) biproducts and binary biproducts.
These are slightly unusual relative to the other shapes in the library,
as they are simultaneously limits and colimits.
(Zero objects are similar; they are "biterminal".)
We treat first the case of a general category with zero morphisms,
and subsequently the case of a preadditive category.
In a category with zero morphisms, we model the (binary) biproduct of `P Q : C`
using a `binary_bicone`, which has a cone point `X`,
and morphisms `fst : X ⟶ P`, `snd : X ⟶ Q`, `inl : P ⟶ X` and `inr : X ⟶ Q`,
such that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`.
Such a `binary_bicone` is a biproduct if the cone is a limit cone, and the cocone is a colimit cocone.
In a preadditive category,
* any `binary_biproduct` satisfies `total : fst ≫ inl + snd ≫ inr = 𝟙 X`
* any `binary_product` is a `binary_biproduct`
* any `binary_coproduct` is a `binary_biproduct`
For biproducts indexed by a `fintype J`, a `bicone` again consists of a cone point `X`
and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
In a preadditive category,
* any `biproduct` satisfies `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`
* any `product` is a `biproduct`
* any `coproduct` is a `biproduct`
## Notation
As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for
a binary biproduct. We introduce `⨁ f` for the indexed biproduct.
-/
namespace category_theory.limits
/--
A `c : bicone F` is:
* an object `c.X` and
* morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
* such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
-/
structure bicone {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C)
where
X : C
π : (j : J) → X ⟶ F j
ι : (j : J) → F j ⟶ X
ι_π :
∀ (j j' : J),
ι j ≫ π j' =
dite (j = j') (fun (h : j = j') => eq_to_hom (congr_arg F h)) fun (h : ¬j = j') => 0
@[simp] theorem bicone_ι_π_self {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {F : J → C} (B : bicone F) (j : J) : bicone.ι B j ≫ bicone.π B j = 𝟙 :=
sorry
@[simp] theorem bicone_ι_π_ne {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {F : J → C} (B : bicone F) {j : J} {j' : J} (h : j ≠ j') :
bicone.ι B j ≫ bicone.π B j' = 0 :=
sorry
namespace bicone
/-- Extract the cone from a bicone. -/
def to_cone {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
{F : J → C} (B : bicone F) : cone (discrete.functor F) :=
cone.mk (X B) (nat_trans.mk fun (j : discrete J) => π B j)
/-- Extract the cocone from a bicone. -/
def to_cocone {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
{F : J → C} (B : bicone F) : cocone (discrete.functor F) :=
cocone.mk (X B) (nat_trans.mk fun (j : discrete J) => ι B j)
end bicone
/--
A bicone over `F : J → C`, which is both a limit cone and a colimit cocone.
-/
structure limit_bicone {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C)
where
bicone : bicone F
is_limit : is_limit (bicone.to_cone bicone)
is_colimit : is_colimit (bicone.to_cocone bicone)
/--
`has_biproduct F` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `F`.
-/
class has_biproduct {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C)
where
mk' :: (exists_biproduct : Nonempty (limit_bicone F))
theorem has_biproduct.mk {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {F : J → C} (d : limit_bicone F) : has_biproduct F :=
has_biproduct.mk' (Nonempty.intro d)
/-- Use the axiom of choice to extract explicit `biproduct_data F` from `has_biproduct F`. -/
def get_biproduct_data {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C) [has_biproduct F] : limit_bicone F :=
Classical.choice sorry
/-- A bicone for `F` which is both a limit cone and a colimit cocone. -/
def biproduct.bicone {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C) [has_biproduct F] : bicone F :=
limit_bicone.bicone (get_biproduct_data F)
/-- `biproduct.bicone F` is a limit cone. -/
def biproduct.is_limit {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C) [has_biproduct F] : is_limit (bicone.to_cone (biproduct.bicone F)) :=
limit_bicone.is_limit (get_biproduct_data F)
/-- `biproduct.bicone F` is a colimit cocone. -/
def biproduct.is_colimit {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (F : J → C) [has_biproduct F] :
is_colimit (bicone.to_cocone (biproduct.bicone F)) :=
limit_bicone.is_colimit (get_biproduct_data F)
protected instance has_product_of_has_biproduct {J : Type v} [DecidableEq J] {C : Type u}
[category C] [has_zero_morphisms C] {F : J → C} [has_biproduct F] :
has_limit (discrete.functor F) :=
has_limit.mk (limit_cone.mk (bicone.to_cone (biproduct.bicone F)) (biproduct.is_limit F))
protected instance has_coproduct_of_has_biproduct {J : Type v} [DecidableEq J] {C : Type u}
[category C] [has_zero_morphisms C] {F : J → C} [has_biproduct F] :
has_colimit (discrete.functor F) :=
has_colimit.mk
(colimit_cocone.mk (bicone.to_cocone (biproduct.bicone F)) (biproduct.is_colimit F))
/--
`C` has biproducts of shape `J` if we have
a limit and a colimit, with the same cone points,
of every function `F : J → C`.
-/
class has_biproducts_of_shape (J : Type v) [DecidableEq J] (C : Type u) [category C]
[has_zero_morphisms C]
where
has_biproduct : ∀ (F : J → C), has_biproduct F
/-- `has_finite_biproducts C` represents a choice of biproduct for every family of objects in `C`
indexed by a finite type with decidable equality. -/
class has_finite_biproducts (C : Type u) [category C] [has_zero_morphisms C] where
has_biproducts_of_shape :
∀ (J : Type v) [_inst_4 : DecidableEq J] [_inst_5 : fintype J], has_biproducts_of_shape J C
protected instance has_finite_products_of_has_finite_biproducts (C : Type u) [category C]
[has_zero_morphisms C] [has_finite_biproducts C] : has_finite_products C :=
fun (J : Type v) (_x : DecidableEq J) (_x_1 : fintype J) =>
has_limits_of_shape.mk
fun (F : discrete J ⥤ C) => has_limit_of_iso (iso.symm discrete.nat_iso_functor)
protected instance has_finite_coproducts_of_has_finite_biproducts (C : Type u) [category C]
[has_zero_morphisms C] [has_finite_biproducts C] : has_finite_coproducts C :=
fun (J : Type v) (_x : DecidableEq J) (_x_1 : fintype J) =>
has_colimits_of_shape.mk fun (F : discrete J ⥤ C) => has_colimit_of_iso discrete.nat_iso_functor
/--
The isomorphism between the specified limit and the specified colimit for
a functor with a bilimit.
-/
def biproduct_iso {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(F : J → C) [has_biproduct F] : ∏ F ≅ ∐ F :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit (discrete.functor F))
(biproduct.is_limit F) ≪≫
is_colimit.cocone_point_unique_up_to_iso (biproduct.is_colimit F)
(colimit.is_colimit (discrete.functor F))
end category_theory.limits
namespace category_theory.limits
/-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an
abbreviation for `limit (discrete.functor f)`, so for most facts about `biproduct f`, you will
just use general facts about limits and colimits.) -/
def biproduct {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(f : J → C) [has_biproduct f] : C :=
bicone.X sorry
prefix:20 "⨁ " => Mathlib.category_theory.limits.biproduct
/-- The projection onto a summand of a biproduct. -/
def biproduct.π {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(f : J → C) [has_biproduct f] (b : J) : ⨁ f ⟶ f b :=
bicone.π (biproduct.bicone f) b
@[simp] theorem biproduct.bicone_π {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] (b : J) :
bicone.π (biproduct.bicone f) b = biproduct.π f b :=
rfl
/-- The inclusion into a summand of a biproduct. -/
def biproduct.ι {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(f : J → C) [has_biproduct f] (b : J) : f b ⟶ ⨁ f :=
bicone.ι (biproduct.bicone f) b
@[simp] theorem biproduct.bicone_ι {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] (b : J) :
bicone.ι (biproduct.bicone f) b = biproduct.ι f b :=
rfl
theorem biproduct.ι_π {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
(f : J → C) [has_biproduct f] (j : J) (j' : J) :
biproduct.ι f j ≫ biproduct.π f j' =
dite (j = j') (fun (h : j = j') => eq_to_hom (congr_arg f h)) fun (h : ¬j = j') => 0 :=
bicone.ι_π (biproduct.bicone f) j j'
@[simp] theorem biproduct.ι_π_self {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] (j : J) :
biproduct.ι f j ≫ biproduct.π f j = 𝟙 :=
sorry
@[simp] theorem biproduct.ι_π_ne {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] {j : J} {j' : J} (h : j ≠ j') :
biproduct.ι f j ≫ biproduct.π f j' = 0 :=
sorry
/-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/
def biproduct.lift {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
{f : J → C} [has_biproduct f] {P : C} (p : (b : J) → P ⟶ f b) : P ⟶ ⨁ f :=
is_limit.lift (biproduct.is_limit f) (fan.mk P p)
/-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/
def biproduct.desc {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
{f : J → C} [has_biproduct f] {P : C} (p : (b : J) → f b ⟶ P) : ⨁ f ⟶ P :=
is_colimit.desc (biproduct.is_colimit f) (cofan.mk P p)
@[simp] theorem biproduct.lift_π {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {f : J → C} [has_biproduct f] {P : C} (p : (b : J) → P ⟶ f b) (j : J) :
biproduct.lift p ≫ biproduct.π f j = p j :=
is_limit.fac (biproduct.is_limit f) (fan.mk P p) j
@[simp] theorem biproduct.ι_desc_assoc {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {f : J → C} [has_biproduct f] {P : C} (p : (b : J) → f b ⟶ P) (j : J)
{X' : C} (f' : P ⟶ X') : biproduct.ι f j ≫ biproduct.desc p ≫ f' = p j ≫ f' :=
sorry
/-- Given a collection of maps between corresponding summands of a pair of biproducts
indexed by the same type, we obtain a map between the biproducts. -/
def biproduct.map {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
[fintype J] {f : J → C} {g : J → C} [has_finite_biproducts C] (p : (b : J) → f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
is_limit.map (bicone.to_cone (biproduct.bicone f)) (biproduct.is_limit g) (discrete.nat_trans p)
/-- An alternative to `biproduct.map` constructed via colimits.
This construction only exists in order to show it is equal to `biproduct.map`. -/
def biproduct.map' {J : Type v} [DecidableEq J] {C : Type u} [category C] [has_zero_morphisms C]
[fintype J] {f : J → C} {g : J → C} [has_finite_biproducts C] (p : (b : J) → f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
is_colimit.map (biproduct.is_colimit f) (bicone.to_cocone (biproduct.bicone g))
(discrete.nat_trans p)
theorem biproduct.hom_ext {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {f : J → C} [has_biproduct f] {Z : C} (g : Z ⟶ ⨁ f) (h : Z ⟶ ⨁ f)
(w : ∀ (j : J), g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h :=
is_limit.hom_ext (biproduct.is_limit f) w
theorem biproduct.hom_ext' {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] {f : J → C} [has_biproduct f] {Z : C} (g : ⨁ f ⟶ Z) (h : ⨁ f ⟶ Z)
(w : ∀ (j : J), biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h :=
is_colimit.hom_ext (biproduct.is_colimit f) w
theorem biproduct.map_eq_map' {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] [fintype J] {f : J → C} {g : J → C} [has_finite_biproducts C]
(p : (b : J) → f b ⟶ g b) : biproduct.map p = biproduct.map' p :=
sorry
protected instance biproduct.ι_mono {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] (b : J) : split_mono (biproduct.ι f b) :=
split_mono.mk
(biproduct.desc
fun (b' : J) =>
dite (b' = b) (fun (h : b' = b) => eq_to_hom (congr_arg f h))
fun (h : ¬b' = b) => biproduct.ι f b' ≫ biproduct.π f b)
protected instance biproduct.π_epi {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] (f : J → C) [has_biproduct f] (b : J) : split_epi (biproduct.π f b) :=
split_epi.mk
(biproduct.lift
fun (b' : J) =>
dite (b = b') (fun (h : b = b') => eq_to_hom (congr_arg f h))
fun (h : ¬b = b') => biproduct.ι f b ≫ biproduct.π f b')
@[simp] theorem biproduct.map_π_assoc {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] [fintype J] {f : J → C} {g : J → C} [has_finite_biproducts C]
(p : (j : J) → f j ⟶ g j) (j : J) {X' : C} (f' : g j ⟶ X') :
biproduct.map p ≫ biproduct.π g j ≫ f' = biproduct.π f j ≫ p j ≫ f' :=
sorry
@[simp] theorem biproduct.ι_map {J : Type v} [DecidableEq J] {C : Type u} [category C]
[has_zero_morphisms C] [fintype J] {f : J → C} {g : J → C} [has_finite_biproducts C]
(p : (j : J) → f j ⟶ g j) (j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j :=
sorry
/--
A binary bicone for a pair of objects `P Q : C` consists of the cone point `X`,
maps from `X` to both `P` and `Q`, and maps from both `P` and `Q` to `X`,
so that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`
-/
structure binary_bicone {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C) where
X : C
fst : X ⟶ P
snd : X ⟶ Q
inl : P ⟶ X
inr : Q ⟶ X
inl_fst' :
autoParam (inl ≫ fst = 𝟙)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously")
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") [])
inl_snd' :
autoParam (inl ≫ snd = 0)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously")
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") [])
inr_fst' :
autoParam (inr ≫ fst = 0)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously")
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") [])
inr_snd' :
autoParam (inr ≫ snd = 𝟙)
(Lean.Syntax.ident Lean.SourceInfo.none (String.toSubstring "Mathlib.obviously")
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "obviously") [])
@[simp] theorem binary_bicone.inl_fst {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) : binary_bicone.inl c ≫ binary_bicone.fst c = 𝟙 :=
sorry
@[simp] theorem binary_bicone.inl_snd {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) : binary_bicone.inl c ≫ binary_bicone.snd c = 0 :=
sorry
@[simp] theorem binary_bicone.inr_fst {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) : binary_bicone.inr c ≫ binary_bicone.fst c = 0 :=
sorry
@[simp] theorem binary_bicone.inr_snd {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) : binary_bicone.inr c ≫ binary_bicone.snd c = 𝟙 :=
sorry
@[simp] theorem binary_bicone.inr_fst_assoc {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) {X' : C} (f' : P ⟶ X') :
binary_bicone.inr c ≫ binary_bicone.fst c ≫ f' = 0 ≫ f' :=
sorry
namespace binary_bicone
/-- Extract the cone from a binary bicone. -/
def to_cone {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : cone (pair P Q) :=
binary_fan.mk (fst c) (snd c)
@[simp] theorem to_cone_X {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : cone.X (to_cone c) = X c :=
rfl
@[simp] theorem to_cone_π_app_left {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : nat_trans.app (cone.π (to_cone c)) walking_pair.left = fst c :=
rfl
@[simp] theorem to_cone_π_app_right {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : nat_trans.app (cone.π (to_cone c)) walking_pair.right = snd c :=
rfl
/-- Extract the cocone from a binary bicone. -/
def to_cocone {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : cocone (pair P Q) :=
binary_cofan.mk (inl c) (inr c)
@[simp] theorem to_cocone_X {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(c : binary_bicone P Q) : cocone.X (to_cocone c) = X c :=
rfl
@[simp] theorem to_cocone_ι_app_left {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) :
nat_trans.app (cocone.ι (to_cocone c)) walking_pair.left = inl c :=
rfl
@[simp] theorem to_cocone_ι_app_right {C : Type u} [category C] [has_zero_morphisms C] {P : C}
{Q : C} (c : binary_bicone P Q) :
nat_trans.app (cocone.ι (to_cocone c)) walking_pair.right = inr c :=
rfl
end binary_bicone
namespace bicone
/-- Convert a `bicone` over a function on `walking_pair` to a binary_bicone. -/
@[simp] theorem to_binary_bicone_snd {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} (b : bicone (functor.obj (pair X Y))) :
binary_bicone.snd (to_binary_bicone b) = π b walking_pair.right :=
Eq.refl (binary_bicone.snd (to_binary_bicone b))
/--
If the cone obtained from a bicone over `pair X Y` is a limit cone,
so is the cone obtained by converting that bicone to a binary_bicone, then to a cone.
-/
def to_binary_bicone_is_limit {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
{b : bicone (functor.obj (pair X Y))} (c : is_limit (to_cone b)) :
is_limit (binary_bicone.to_cone (to_binary_bicone b)) :=
is_limit.mk fun (s : cone (pair X Y)) => is_limit.lift c s
/--
If the cocone obtained from a bicone over `pair X Y` is a colimit cocone,
so is the cocone obtained by converting that bicone to a binary_bicone, then to a cocone.
-/
def to_binary_bicone_is_colimit {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
{b : bicone (functor.obj (pair X Y))} (c : is_colimit (to_cocone b)) :
is_colimit (binary_bicone.to_cocone (to_binary_bicone b)) :=
is_colimit.mk fun (s : cocone (pair X Y)) => is_colimit.desc c s
end bicone
/--
A bicone over `P Q : C`, which is both a limit cone and a colimit cocone.
-/
structure binary_biproduct_data {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C)
where
bicone : binary_bicone P Q
is_limit : is_limit (binary_bicone.to_cone bicone)
is_colimit : is_colimit (binary_bicone.to_cocone bicone)
/--
`has_binary_biproduct P Q` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `pair P Q`.
-/
class has_binary_biproduct {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C) where
mk' :: (exists_binary_biproduct : Nonempty (binary_biproduct_data P Q))
theorem has_binary_biproduct.mk {C : Type u} [category C] [has_zero_morphisms C] {P : C} {Q : C}
(d : binary_biproduct_data P Q) : has_binary_biproduct P Q :=
has_binary_biproduct.mk' (Nonempty.intro d)
/--
Use the axiom of choice to extract explicit `binary_biproduct_data F` from `has_binary_biproduct F`.
-/
def get_binary_biproduct_data {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C)
[has_binary_biproduct P Q] : binary_biproduct_data P Q :=
Classical.choice has_binary_biproduct.exists_binary_biproduct
/-- A bicone for `P Q ` which is both a limit cone and a colimit cocone. -/
def binary_biproduct.bicone {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C)
[has_binary_biproduct P Q] : binary_bicone P Q :=
binary_biproduct_data.bicone (get_binary_biproduct_data P Q)
/-- `binary_biproduct.bicone P Q` is a limit cone. -/
def binary_biproduct.is_limit {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C)
[has_binary_biproduct P Q] : is_limit (binary_bicone.to_cone (binary_biproduct.bicone P Q)) :=
binary_biproduct_data.is_limit (get_binary_biproduct_data P Q)
/-- `binary_biproduct.bicone P Q` is a colimit cocone. -/
def binary_biproduct.is_colimit {C : Type u} [category C] [has_zero_morphisms C] (P : C) (Q : C)
[has_binary_biproduct P Q] :
is_colimit (binary_bicone.to_cocone (binary_biproduct.bicone P Q)) :=
binary_biproduct_data.is_colimit (get_binary_biproduct_data P Q)
/--
`has_binary_biproducts C` represents the existence of a bicone which is
simultaneously a limit and a colimit of the diagram `pair P Q`, for every `P Q : C`.
-/
class has_binary_biproducts (C : Type u) [category C] [has_zero_morphisms C] where
has_binary_biproduct : ∀ (P Q : C), has_binary_biproduct P Q
/--
A category with finite biproducts has binary biproducts.
This is not an instance as typically in concrete categories there will be
an alternative construction with nicer definitional properties.
-/
theorem has_binary_biproducts_of_finite_biproducts (C : Type u) [category C] [has_zero_morphisms C]
[has_finite_biproducts C] : has_binary_biproducts C :=
sorry
protected instance has_binary_biproduct.has_limit_pair {C : Type u} [category C]
[has_zero_morphisms C] {P : C} {Q : C} [has_binary_biproduct P Q] : has_limit (pair P Q) :=
has_limit.mk
(limit_cone.mk (binary_bicone.to_cone (binary_biproduct.bicone P Q))
(binary_biproduct.is_limit P Q))
protected instance has_binary_biproduct.has_colimit_pair {C : Type u} [category C]
[has_zero_morphisms C] {P : C} {Q : C} [has_binary_biproduct P Q] : has_colimit (pair P Q) :=
has_colimit.mk
(colimit_cocone.mk (binary_bicone.to_cocone (binary_biproduct.bicone P Q))
(binary_biproduct.is_colimit P Q))
protected instance has_binary_products_of_has_binary_biproducts {C : Type u} [category C]
[has_zero_morphisms C] [has_binary_biproducts C] : has_binary_products C :=
has_limits_of_shape.mk
fun (F : discrete walking_pair ⥤ C) => has_limit_of_iso (iso.symm (diagram_iso_pair F))
protected instance has_binary_coproducts_of_has_binary_biproducts {C : Type u} [category C]
[has_zero_morphisms C] [has_binary_biproducts C] : has_binary_coproducts C :=
has_colimits_of_shape.mk
fun (F : discrete walking_pair ⥤ C) => has_colimit_of_iso (diagram_iso_pair F)
/--
The isomorphism between the specified binary product and the specified binary coproduct for
a pair for a binary biproduct.
-/
def biprod_iso {C : Type u} [category C] [has_zero_morphisms C] (X : C) (Y : C)
[has_binary_biproduct X Y] : X ⨯ Y ≅ X ⨿ Y :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit (pair X Y))
(binary_biproduct.is_limit X Y) ≪≫
is_colimit.cocone_point_unique_up_to_iso (binary_biproduct.is_colimit X Y)
(colimit.is_colimit (pair X Y))
/-- An arbitrary choice of biproduct of a pair of objects. -/
def biprod {C : Type u} [category C] [has_zero_morphisms C] (X : C) (Y : C)
[has_binary_biproduct X Y] : C :=
binary_bicone.X (binary_biproduct.bicone X Y)
infixl:20 " ⊞ " => Mathlib.category_theory.limits.biprod
/-- The projection onto the first summand of a binary biproduct. -/
def biprod.fst {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : X ⊞ Y ⟶ X :=
binary_bicone.fst (binary_biproduct.bicone X Y)
/-- The projection onto the second summand of a binary biproduct. -/
def biprod.snd {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : X ⊞ Y ⟶ Y :=
binary_bicone.snd (binary_biproduct.bicone X Y)
/-- The inclusion into the first summand of a binary biproduct. -/
def biprod.inl {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : X ⟶ X ⊞ Y :=
binary_bicone.inl (binary_biproduct.bicone X Y)
/-- The inclusion into the second summand of a binary biproduct. -/
def biprod.inr {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : Y ⟶ X ⊞ Y :=
binary_bicone.inr (binary_biproduct.bicone X Y)
@[simp] theorem binary_biproduct.bicone_fst {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] :
binary_bicone.fst (binary_biproduct.bicone X Y) = biprod.fst :=
rfl
@[simp] theorem binary_biproduct.bicone_snd {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] :
binary_bicone.snd (binary_biproduct.bicone X Y) = biprod.snd :=
rfl
@[simp] theorem binary_biproduct.bicone_inl {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] :
binary_bicone.inl (binary_biproduct.bicone X Y) = biprod.inl :=
rfl
@[simp] theorem binary_biproduct.bicone_inr {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] :
binary_bicone.inr (binary_biproduct.bicone X Y) = biprod.inr :=
rfl
@[simp] theorem biprod.inl_fst {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : biprod.inl ≫ biprod.fst = 𝟙 :=
binary_bicone.inl_fst (binary_biproduct.bicone X Y)
@[simp] theorem biprod.inl_snd {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : biprod.inl ≫ biprod.snd = 0 :=
binary_bicone.inl_snd (binary_biproduct.bicone X Y)
@[simp] theorem biprod.inr_fst_assoc {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] {X' : C} (f' : X ⟶ X') :
biprod.inr ≫ biprod.fst ≫ f' = 0 ≫ f' :=
sorry
@[simp] theorem biprod.inr_snd_assoc {C : Type u} [category C] [has_zero_morphisms C] {X : C}
{Y : C} [has_binary_biproduct X Y] {X' : C} (f' : Y ⟶ X') : biprod.inr ≫ biprod.snd ≫ f' = f' :=
sorry
/-- Given a pair of maps into the summands of a binary biproduct,
we obtain a map into the binary biproduct. -/
def biprod.lift {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C} {Y : C}
[has_binary_biproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⊞ Y :=
is_limit.lift (binary_biproduct.is_limit X Y) (binary_fan.mk f g)
/-- Given a pair of maps out of the summands of a binary biproduct,
we obtain a map out of the binary biproduct. -/
def biprod.desc {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C} {Y : C}
[has_binary_biproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⊞ Y ⟶ W :=
is_colimit.desc (binary_biproduct.is_colimit X Y) (binary_cofan.mk f g)
@[simp] theorem biprod.lift_fst_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} [has_binary_biproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) {X' : C} (f' : X ⟶ X') :
biprod.lift f g ≫ biprod.fst ≫ f' = f ≫ f' :=
sorry
@[simp] theorem biprod.lift_snd_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} [has_binary_biproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) {X' : C} (f' : Y ⟶ X') :
biprod.lift f g ≫ biprod.snd ≫ f' = g ≫ f' :=
sorry
@[simp] theorem biprod.inl_desc_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} [has_binary_biproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) {X' : C} (f' : W ⟶ X') :
biprod.inl ≫ biprod.desc f g ≫ f' = f ≫ f' :=
sorry
@[simp] theorem biprod.inr_desc_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} [has_binary_biproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) {X' : C} (f' : W ⟶ X') :
biprod.inr ≫ biprod.desc f g ≫ f' = g ≫ f' :=
sorry
protected instance biprod.mono_lift_of_mono_left {C : Type u} [category C] [has_zero_morphisms C]
{W : C} {X : C} {Y : C} [has_binary_biproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [mono f] :
mono (biprod.lift f g) :=
mono_of_mono_fac (biprod.lift_fst f g)
protected instance biprod.mono_lift_of_mono_right {C : Type u} [category C] [has_zero_morphisms C]
{W : C} {X : C} {Y : C} [has_binary_biproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [mono g] :
mono (biprod.lift f g) :=
mono_of_mono_fac (biprod.lift_snd f g)
protected instance biprod.epi_desc_of_epi_left {C : Type u} [category C] [has_zero_morphisms C]
{W : C} {X : C} {Y : C} [has_binary_biproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [epi f] :
epi (biprod.desc f g) :=
epi_of_epi_fac (biprod.inl_desc f g)
protected instance biprod.epi_desc_of_epi_right {C : Type u} [category C] [has_zero_morphisms C]
{W : C} {X : C} {Y : C} [has_binary_biproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [epi g] :
epi (biprod.desc f g) :=
epi_of_epi_fac (biprod.inr_desc f g)
/-- Given a pair of maps between the summands of a pair of binary biproducts,
we obtain a map between the binary biproducts. -/
def biprod.map {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C} {Y : C} {Z : C}
[has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z :=
is_limit.map (binary_bicone.to_cone (binary_biproduct.bicone W X)) (binary_biproduct.is_limit Y Z)
(map_pair f g)
/-- An alternative to `biprod.map` constructed via colimits.
This construction only exists in order to show it is equal to `biprod.map`. -/
def biprod.map' {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C} {Y : C} {Z : C}
[has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z :=
is_colimit.map (binary_biproduct.is_colimit W X)
(binary_bicone.to_cocone (binary_biproduct.bicone Y Z)) (map_pair f g)
theorem biprod.hom_ext {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C} {Z : C}
[has_binary_biproduct X Y] (f : Z ⟶ X ⊞ Y) (g : Z ⟶ X ⊞ Y)
(h₀ : f ≫ biprod.fst = g ≫ biprod.fst) (h₁ : f ≫ biprod.snd = g ≫ biprod.snd) : f = g :=
binary_fan.is_limit.hom_ext (binary_biproduct.is_limit X Y) h₀ h₁
theorem biprod.hom_ext' {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C} {Z : C}
[has_binary_biproduct X Y] (f : X ⊞ Y ⟶ Z) (g : X ⊞ Y ⟶ Z)
(h₀ : biprod.inl ≫ f = biprod.inl ≫ g) (h₁ : biprod.inr ≫ f = biprod.inr ≫ g) : f = g :=
binary_cofan.is_colimit.hom_ext (binary_biproduct.is_colimit X Y) h₀ h₁
theorem biprod.map_eq_map' {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C} {Y : C}
{Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) :
biprod.map f g = biprod.map' f g :=
sorry
protected instance biprod.inl_mono {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : split_mono biprod.inl :=
split_mono.mk (biprod.desc 𝟙 (biprod.inr ≫ biprod.fst))
protected instance biprod.inr_mono {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : split_mono biprod.inr :=
split_mono.mk (biprod.desc (biprod.inl ≫ biprod.snd) 𝟙)
protected instance biprod.fst_epi {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : split_epi biprod.fst :=
split_epi.mk (biprod.lift 𝟙 (biprod.inl ≫ biprod.snd))
protected instance biprod.snd_epi {C : Type u} [category C] [has_zero_morphisms C] {X : C} {Y : C}
[has_binary_biproduct X Y] : split_epi biprod.snd :=
split_epi.mk (biprod.lift (biprod.inr ≫ biprod.fst) 𝟙)
@[simp] theorem biprod.map_fst {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C}
{Y : C} {Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) :
biprod.map f g ≫ biprod.fst = biprod.fst ≫ f :=
is_limit.map_π (binary_bicone.to_cone (binary_biproduct.bicone W X))
(binary_biproduct.is_limit Y Z) (map_pair f g) walking_pair.left
@[simp] theorem biprod.map_snd_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} {Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) {X' : C} (f' : Z ⟶ X') : biprod.map f g ≫ biprod.snd ≫ f' = biprod.snd ≫ g ≫ f' :=
sorry
-- Because `biprod.map` is defined in terms of `lim` rather than `colim`,
-- we need to provide additional `simp` lemmas.
@[simp] theorem biprod.inl_map_assoc {C : Type u} [category C] [has_zero_morphisms C] {W : C}
{X : C} {Y : C} {Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) {X' : C} (f' : Y ⊞ Z ⟶ X') :
biprod.inl ≫ biprod.map f g ≫ f' = f ≫ biprod.inl ≫ f' :=
sorry
@[simp] theorem biprod.inr_map {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C}
{Y : C} {Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) :
biprod.inr ≫ biprod.map f g = g ≫ biprod.inr :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (biprod.inr ≫ biprod.map f g = g ≫ biprod.inr))
(biprod.map_eq_map' f g)))
(is_colimit.ι_map (binary_biproduct.is_colimit W X)
(binary_bicone.to_cocone (binary_biproduct.bicone Y Z)) (map_pair f g) walking_pair.right)
/-- Given a pair of isomorphisms between the summands of a pair of binary biproducts,
we obtain an isomorphism between the binary biproducts. -/
@[simp] theorem biprod.map_iso_hom {C : Type u} [category C] [has_zero_morphisms C] {W : C} {X : C}
{Y : C} {Z : C} [has_binary_biproduct W X] [has_binary_biproduct Y Z] (f : W ≅ Y) (g : X ≅ Z) :
iso.hom (biprod.map_iso f g) = biprod.map (iso.hom f) (iso.hom g) :=
Eq.refl (iso.hom (biprod.map_iso f g))
/-- The braiding isomorphism which swaps a binary biproduct. -/
@[simp] theorem biprod.braiding_hom {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] (P : C) (Q : C) :
iso.hom (biprod.braiding P Q) = biprod.lift biprod.snd biprod.fst :=
Eq.refl (iso.hom (biprod.braiding P Q))
/--
An alternative formula for the braiding isomorphism which swaps a binary biproduct,
using the fact that the biproduct is a coproduct.
-/
def biprod.braiding' {C : Type u} [category C] [has_zero_morphisms C] [has_binary_biproducts C]
(P : C) (Q : C) : P ⊞ Q ≅ Q ⊞ P :=
iso.mk (biprod.desc biprod.inr biprod.inl) (biprod.desc biprod.inr biprod.inl)
theorem biprod.braiding'_eq_braiding {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] {P : C} {Q : C} : biprod.braiding' P Q = biprod.braiding P Q :=
sorry
/-- The braiding isomorphism can be passed through a map by swapping the order. -/
theorem biprod.braid_natural_assoc {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] {W : C} {X : C} {Y : C} {Z : C} (f : X ⟶ Y) (g : Z ⟶ W) {X' : C}
(f' : W ⊞ Y ⟶ X') :
biprod.map f g ≫ iso.hom (biprod.braiding Y W) ≫ f' =
iso.hom (biprod.braiding X Z) ≫ biprod.map g f ≫ f' :=
sorry
theorem biprod.braiding_map_braiding {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] {W : C} {X : C} {Y : C} {Z : C} (f : W ⟶ Y) (g : X ⟶ Z) :
iso.hom (biprod.braiding X W) ≫ biprod.map f g ≫ iso.hom (biprod.braiding Y Z) =
biprod.map g f :=
sorry
@[simp] theorem biprod.symmetry'_assoc {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] (P : C) (Q : C) {X' : C} (f' : P ⊞ Q ⟶ X') :
biprod.lift biprod.snd biprod.fst ≫ biprod.lift biprod.snd biprod.fst ≫ f' = f' :=
sorry
/-- The braiding isomorphism is symmetric. -/
theorem biprod.symmetry_assoc {C : Type u} [category C] [has_zero_morphisms C]
[has_binary_biproducts C] (P : C) (Q : C) {X' : C} (f' : P ⊞ Q ⟶ X') :
iso.hom (biprod.braiding P Q) ≫ iso.hom (biprod.braiding Q P) ≫ f' = f' :=
sorry
-- TODO:
-- If someone is interested, they could provide the constructions:
-- has_binary_biproducts ↔ has_finite_biproducts
end category_theory.limits
namespace category_theory.limits
/--
In a preadditive category, we can construct a biproduct for `f : J → C` from
any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
theorem has_biproduct_of_total {C : Type u} [category C] [preadditive C] {J : Type v}
[DecidableEq J] [fintype J] {f : J → C} (b : bicone f)
(total : (finset.sum finset.univ fun (j : J) => bicone.π b j ≫ bicone.ι b j) = 𝟙) :
has_biproduct f :=
sorry
/-- In a preadditive category, if the product over `f : J → C` exists,
then the biproduct over `f` exists. -/
theorem has_biproduct.of_has_product {C : Type u} [category C] [preadditive C] {J : Type v}
[DecidableEq J] [fintype J] (f : J → C) [has_product f] : has_biproduct f :=
sorry
/-- In a preadditive category, if the coproduct over `f : J → C` exists,
then the biproduct over `f` exists. -/
theorem has_biproduct.of_has_coproduct {C : Type u} [category C] [preadditive C] {J : Type v}
[DecidableEq J] [fintype J] (f : J → C) [has_coproduct f] : has_biproduct f :=
sorry
/-- A preadditive category with finite products has finite biproducts. -/
theorem has_finite_biproducts.of_has_finite_products {C : Type u} [category C] [preadditive C]
[has_finite_products C] : has_finite_biproducts C :=
has_finite_biproducts.mk
fun (J : Type v) (_x : DecidableEq J) (_x_1 : fintype J) =>
has_biproducts_of_shape.mk fun (F : J → C) => has_biproduct.of_has_product F
/-- A preadditive category with finite coproducts has finite biproducts. -/
theorem has_finite_biproducts.of_has_finite_coproducts {C : Type u} [category C] [preadditive C]
[has_finite_coproducts C] : has_finite_biproducts C :=
has_finite_biproducts.mk
fun (J : Type v) (_x : DecidableEq J) (_x_1 : fintype J) =>
has_biproducts_of_shape.mk fun (F : J → C) => has_biproduct.of_has_coproduct F
/--
In any preadditive category, any biproduct satsifies
`∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`
-/
@[simp] theorem biproduct.total {C : Type u} [category C] [preadditive C] {J : Type v}
[DecidableEq J] [fintype J] {f : J → C} [has_biproduct f] :
(finset.sum finset.univ fun (j : J) => biproduct.π f j ≫ biproduct.ι f j) = 𝟙 :=
sorry
theorem biproduct.lift_eq {C : Type u} [category C] [preadditive C] {J : Type v} [DecidableEq J]
[fintype J] {f : J → C} [has_biproduct f] {T : C} {g : (j : J) → T ⟶ f j} :
biproduct.lift g = finset.sum finset.univ fun (j : J) => g j ≫ biproduct.ι f j :=
sorry
theorem biproduct.desc_eq {C : Type u} [category C] [preadditive C] {J : Type v} [DecidableEq J]
[fintype J] {f : J → C} [has_biproduct f] {T : C} {g : (j : J) → f j ⟶ T} :
biproduct.desc g = finset.sum finset.univ fun (j : J) => biproduct.π f j ≫ g j :=
sorry
@[simp] theorem biproduct.lift_desc {C : Type u} [category C] [preadditive C] {J : Type v}
[DecidableEq J] [fintype J] {f : J → C} [has_biproduct f] {T : C} {U : C}
{g : (j : J) → T ⟶ f j} {h : (j : J) → f j ⟶ U} :
biproduct.lift g ≫ biproduct.desc h = finset.sum finset.univ fun (j : J) => g j ≫ h j :=
sorry
theorem biproduct.map_eq {C : Type u} [category C] [preadditive C] {J : Type v} [DecidableEq J]
[fintype J] [has_finite_biproducts C] {f : J → C} {g : J → C} {h : (j : J) → f j ⟶ g j} :
biproduct.map h =
finset.sum finset.univ fun (j : J) => biproduct.π f j ≫ h j ≫ biproduct.ι g j :=
sorry
/--
In a preadditive category, we can construct a binary biproduct for `X Y : C` from
any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`.
(That is, such a bicone is a limit cone and a colimit cocone.)
-/
theorem has_binary_biproduct_of_total {C : Type u} [category C] [preadditive C] {X : C} {Y : C}
(b : binary_bicone X Y)
(total :
binary_bicone.fst b ≫ binary_bicone.inl b + binary_bicone.snd b ≫ binary_bicone.inr b = 𝟙) :
has_binary_biproduct X Y :=
sorry
/-- In a preadditive category, if the product of `X` and `Y` exists, then the
binary biproduct of `X` and `Y` exists. -/
theorem has_binary_biproduct.of_has_binary_product {C : Type u} [category C] [preadditive C] (X : C)
(Y : C) [has_binary_product X Y] : has_binary_biproduct X Y :=
sorry
/-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/
theorem has_binary_biproducts.of_has_binary_products {C : Type u} [category C] [preadditive C]
[has_binary_products C] : has_binary_biproducts C :=
has_binary_biproducts.mk fun (X Y : C) => has_binary_biproduct.of_has_binary_product X Y
/-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the
binary biproduct of `X` and `Y` exists. -/
theorem has_binary_biproduct.of_has_binary_coproduct {C : Type u} [category C] [preadditive C]
(X : C) (Y : C) [has_binary_coproduct X Y] : has_binary_biproduct X Y :=
sorry
/-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/
theorem has_binary_biproducts.of_has_binary_coproducts {C : Type u} [category C] [preadditive C]
[has_binary_coproducts C] : has_binary_biproducts C :=
has_binary_biproducts.mk fun (X Y : C) => has_binary_biproduct.of_has_binary_coproduct X Y
/--
In any preadditive category, any binary biproduct satsifies
`biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`.
-/
@[simp] theorem biprod.total {C : Type u} [category C] [preadditive C] {X : C} {Y : C}
[has_binary_biproduct X Y] : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 :=
sorry
theorem biprod.lift_eq {C : Type u} [category C] [preadditive C] {X : C} {Y : C}
[has_binary_biproduct X Y] {T : C} {f : T ⟶ X} {g : T ⟶ Y} :
biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr :=
sorry
theorem biprod.desc_eq {C : Type u} [category C] [preadditive C] {X : C} {Y : C}
[has_binary_biproduct X Y] {T : C} {f : X ⟶ T} {g : Y ⟶ T} :
biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g :=
sorry
@[simp] theorem biprod.lift_desc {C : Type u} [category C] [preadditive C] {X : C} {Y : C}
[has_binary_biproduct X Y] {T : C} {U : C} {f : T ⟶ X} {g : T ⟶ Y} {h : X ⟶ U} {i : Y ⟶ U} :
biprod.lift f g ≫ biprod.desc h i = f ≫ h + g ≫ i :=
sorry
theorem biprod.map_eq {C : Type u} [category C] [preadditive C] [has_binary_biproducts C] {W : C}
{X : C} {Y : C} {Z : C} {f : W ⟶ Y} {g : X ⟶ Z} :
biprod.map f g = biprod.fst ≫ f ≫ biprod.inl + biprod.snd ≫ g ≫ biprod.inr :=
sorry
end Mathlib
|
bbe3f899071bf18f062ee782ef08f73a6a8b1d65
|
69d4931b605e11ca61881fc4f66db50a0a875e39
|
/src/category_theory/abelian/projective.lean
|
2f399ba62b6bb7ca65708f0962d61fb579d40530
|
[
"Apache-2.0"
] |
permissive
|
abentkamp/mathlib
|
d9a75d291ec09f4637b0f30cc3880ffb07549ee5
|
5360e476391508e092b5a1e5210bd0ed22dc0755
|
refs/heads/master
| 1,682,382,954,948
| 1,622,106,077,000
| 1,622,106,077,000
| 149,285,665
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 898
|
lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import category_theory.abelian.exact
import category_theory.preadditive.projective
/-!
# Abelian categories with enough projectives have projective resolutions
When `C` is abelian `projective.d f` and `f` are exact.
-/
noncomputable theory
open category_theory
open category_theory.limits
universes v u
namespace category_theory
open category_theory.projective
variables {C : Type u} [category.{v} C]
section
variables [enough_projectives C] [abelian C]
/--
When `C` is abelian, `projective.d f` and `f` are exact.
-/
lemma exact_d_f {X Y : C} (f : X ⟶ Y) : exact (d f) f :=
(abelian.exact_iff _ _).2 $
⟨by simp, zero_of_epi_comp (π _) $ by rw [←category.assoc, cokernel.condition]⟩
end
end category_theory
|
7aed4db8932243e1d521e930591c6954734800b1
|
ac076ebc286fa9b7a67171f6cd11eb98b263d6ef
|
/src/SES.lean
|
5149d17a638a40766326f5c5eb2c1fd34829fc1c
|
[] |
no_license
|
Shamrock-Frost/jordan-holder
|
e891e489d00f8ff9e29c47b3083f22cac7804efb
|
bab3daccd70a4f3c5b25731b899a2cd72d7b8376
|
refs/heads/master
| 1,594,962,465,041
| 1,576,197,432,000
| 1,576,197,432,000
| 205,951,913
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 24,776
|
lean
|
import group_theory.subgroup
import group_theory.quotient_group
import group_theory.category
import .category_theory
open category_theory
universe u
structure SES (A B C : Group.{u}) :=
(f : A ⟶ B) (g : B ⟶ C)
(f_inj : function.injective f)
(g_surj : function.surjective g)
(im_f_eq_ker_g : set.range f = is_group_hom.ker g)
lemma SES.is_cc {A B C : Group} (S : SES A B C)
: ∀ x : A, S.g (S.f x) = 1 :=
by { intro x, apply iff.mp (is_group_hom.mem_ker S.g),
rw ← SES.im_f_eq_ker_g, existsi x, refl }
lemma is_group_hom.im_trivial {G H : Group} (φ : G → H) [is_group_hom φ]
: φ '' is_subgroup.trivial G = is_subgroup.trivial H :=
begin
simp [set.image, set_of], rw is_group_hom.map_one φ,
simp [is_subgroup.trivial], funext, apply propext,
constructor; intro h,
{ rw h, apply or.inl, refl },
{ symmetry, apply or.resolve_right h, exact not_false }
end
lemma SES.inj_of_left_triv {A B C : Group} [subsingleton A] (S : SES A B C)
: function.injective S.g :=
begin
apply iff.mpr (is_group_hom.inj_iff_trivial_ker S.g),
rw ← S.im_f_eq_ker_g,
transitivity S.f '' is_subgroup.trivial A,
rw ← set.image_univ, congr, ext, simp, apply subsingleton.elim,
apply is_group_hom.im_trivial
end
noncomputable
def SES.iso_of_left_triv {A B C : Group} [subsingleton A] (S : SES A B C) : B ≅ C :=
Group.iso_of_bijective S.g ⟨S.inj_of_left_triv, S.g_surj⟩
lemma SES.surj_of_right_triv {A B C : Group} [subsingleton C] (S : SES A B C)
: function.surjective S.f :=
begin
rw [← set.range_iff_surjective, S.im_f_eq_ker_g],
ext, rw is_group_hom.mem_ker, simp,
apply subsingleton.elim,
end
noncomputable
def SES.iso_of_right_triv {A B C : Group} [subsingleton C] (S : SES A B C) : A ≅ B :=
Group.iso_of_bijective S.f ⟨S.f_inj, S.surj_of_right_triv⟩
def SES.transport_iso_mid {A B B' C : Group}
(S : SES A B C) (iso : B ≅ B') : SES A B' C :=
{ f := S.f ≫ iso.hom, g := iso.inv ≫ S.g,
f_inj := function.injective_comp (Group.iso_inj iso) S.f_inj,
g_surj := function.surjective_comp S.g_surj (Group.iso_surj iso.symm),
im_f_eq_ker_g := by {
unfold_coes, simp,
rw set.range_comp,
have := Group.ker_of_comp_inj S.g iso.inv (Group.iso_inj iso.symm),
unfold_coes at this, simp at this, rw this,
have := S.im_f_eq_ker_g, unfold_coes at this, rw this,
apply congr_fun, apply set.image_eq_preimage_of_inverse,
apply Group.iso_left_inverse, apply Group.iso_right_inverse } }
def SES.transport_iso_right {A B C C' : Group}
(S : SES A B C) (iso : C ≅ C') : SES A B C' :=
{ f := S.f, g := S.g ≫ iso.hom, f_inj := S.f_inj,
g_surj := function.surjective_comp
(Group.iso_surj iso)
S.g_surj,
im_f_eq_ker_g := by {
unfold_coes, simp,
transitivity is_group_hom.ker S.g,
exact S.im_f_eq_ker_g,
transitivity is_group_hom.ker (@category_struct.comp Group _ _ _ _ S.g iso.hom),
symmetry, apply Group.ker_of_inj_comp,
apply Group.iso_inj, refl } }
def SES.self_right (G : Group) : SES 1 G G :=
{ f := ⟨λ x, 1, is_group_hom.mk' (λ x y, eq.symm $ mul_one 1)⟩,
g := 𝟙 G,
f_inj := by { intros x y _, apply subsingleton.elim },
g_surj := λ x, ⟨x, rfl⟩,
im_f_eq_ker_g := by {
transitivity is_subgroup.trivial G,
ext, unfold_coes, simp, constructor; intro h; exact h.symm,
symmetry, apply iff.mpr (is_group_hom.trivial_ker_iff_eq_one _),
intros x hx, exact hx } }
def SES.normal_quotient {G : Group} (H : set G) [normal_subgroup H]
: SES (Group.of H) G (Group.of (quotient_group.quotient H)) := {
f := subtype_val.group_hom,
g := ⟨quotient_group.mk, quotient_group.is_group_hom _⟩,
f_inj := subtype.val_injective,
g_surj := @quotient.exists_rep _ (quotient_group.left_rel _),
im_f_eq_ker_g := by {
unfold_coes, transitivity set.range subtype.val, refl,
rw [quotient_group.ker_mk, subtype.val_range], refl } }
def is_group_hom.coim {G H : Group} (φ : G → H) [is_group_hom φ]
:= quotient_group.quotient (is_group_hom.ker φ)
instance coim_is_group {G H : Group}
{φ : G → H} [is_group_hom φ] : group (is_group_hom.coim φ) :=
quotient_group.group (is_group_hom.ker φ)
def SES.ker_coim {G H : Group} (φ : G → H) [is_group_hom φ]
: SES (Group.of (is_group_hom.ker φ)) G (Group.of (is_group_hom.coim φ)) :=
SES.normal_quotient (is_group_hom.ker φ)
def SES.ker_im {G H : Group} (φ : G → H) [is_group_hom φ]
: SES (Group.of (is_group_hom.ker φ)) G (Group.of (set.range φ)) := {
f := subtype_val.group_hom,
g := ⟨set.range_factorization φ, by apply_instance⟩,
f_inj := subtype.val_injective,
g_surj := set.surjective_onto_range,
im_f_eq_ker_g := by {
unfold_coes,
transitivity set.range subtype.val, refl,
transitivity is_group_hom.ker φ,
rw subtype.range_val, funext,
funext, simp [set.range_factorization],
transitivity φ x = 1,
rw ← is_group_hom.mem_ker φ, refl,
rw ← @set.mem_def _ _ (is_group_hom.ker _),
rw is_group_hom.mem_ker, rw subtype.ext, refl } }
lemma SES.left_normal {A B C : Group} (S : SES A B C)
: normal_subgroup (set.range S.f) :=
by rw SES.im_f_eq_ker_g; apply is_group_hom.normal_subgroup_ker
noncomputable
def SES.f_rev {A B C : Group} (S : SES A B C) : set.range S.f → A :=
λ y, classical.some y.property
lemma SES.f_rev_spec_r {A B C : Group} (S : SES A B C)
: ∀ y, S.f (S.f_rev y) = y := λ y, classical.some_spec y.property
lemma SES.f_rev_spec_l {A B C : Group} (S : SES A B C)
: ∀ x, S.f_rev ⟨S.f x, x, rfl⟩ = x :=
λ x, S.f_inj (S.f_rev_spec_r ⟨S.f x, x, rfl⟩)
instance SES.f_rev_hom {A B C} {S : SES A B C}
: is_group_hom (SES.f_rev S) :=
@is_group_hom.mk _ _ _ _ (SES.f_rev S) $ by {
constructor, intros,
cases x with x hx, cases y with y hy,
cases hx with a ha, cases hy with b hb,
subst ha, subst hb,
transitivity SES.f_rev S ⟨S.f (a * b), a*b, rfl⟩,
congr, apply subtype.eq, simp,
rw (is_group_hom.to_is_monoid_hom S.f).map_mul,
apply subtype_val.is_monoid_hom.map_mul,
repeat { rw SES.f_rev_spec_l } }
noncomputable
def SES.left_iso_range {A B C : Group} (S : SES A B C) : A ≅ Group.of (set.range S.f) := {
hom := ⟨λ x, ⟨S.f x, set.mem_range_self x⟩,
is_group_hom.mk' $ λ x y, by {
apply subtype.eq, rw is_monoid_hom.map_mul subtype.val,
apply is_monoid_hom.map_mul S.f, exact subtype_val.is_monoid_hom
}⟩,
inv := ⟨S.f_rev, by apply_instance⟩,
hom_inv_id' := subtype.eq (funext S.f_rev_spec_l),
inv_hom_id' := subtype.eq (funext $ λ x, subtype.eq $ S.f_rev_spec_r x)
}
noncomputable
def SES.pullback {H G K A B : Group} (S : SES H G K) (S' : SES A K B)
: SES H (Group.of ((S.g) ⁻¹' set.range (S'.f))) A :=
{ f := ⟨λ x, subtype.mk (S.f x)
$ by { rw set.mem_preimage,
have : S.f x ∈ is_group_hom.ker S.g,
{ rw ← SES.im_f_eq_ker_g, existsi x, refl },
rw this.resolve_right not_false,
have : is_subgroup (set.range S'.f) := is_group_hom.range_subgroup S'.f,
apply is_submonoid.one_mem },
@is_group_hom.mk _ _ _ _ _ $ by {
constructor, intros, apply subtype.eq,
unfold_coes, simp, transitivity S.f x * S.f y,
apply is_monoid_hom.map_mul, refl }⟩,
f_inj := by { intros x y h, apply S.f_inj,
unfold_coes at h, simp at h, exact h },
g := ⟨λ x, S'.f_rev ⟨S.g x.val, x.property⟩,
@is_group_hom.mk _ _ _ _ _ $ by {
constructor, intros,
rw ← is_monoid_hom.map_mul S'.f_rev, congr,
rw is_monoid_hom.map_mul subtype.val,
unfold_coes, simp,
apply is_monoid_hom.map_mul,
apply is_group_hom.to_is_monoid_hom, }⟩,
g_surj := λ y, by { unfold_coes, simp,
cases S.g_surj (S'.f y) with x hx,
refine exists.intro (subtype.mk x _) _,
apply set.mem_preimage.mpr, existsi y, exact hx.symm,
simp, transitivity S'.f_rev ⟨S'.f y, y, rfl⟩,
congr, assumption, apply SES.f_rev_spec_l },
im_f_eq_ker_g := by {
ext, cases x with x hx,
transitivity x ∈ set.range S.f,
{ constructor; intro h; cases h with a ha,
{ existsi a, unfold_coes at ha, simp at ha, assumption },
{ have h := hx, rw ← ha at h,
rw (_ : subtype.mk x hx = subtype.mk (S.f a) h),
existsi a, refl, apply subtype.eq, exact ha.symm, } },
rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, is_group_hom.mem_ker],
unfold_coes, simp,
constructor; intro h,
{ transitivity S'.f_rev ⟨1, is_submonoid.one_mem _⟩,
congr, assumption, apply is_group_hom.map_one S'.f_rev, },
{ have := congr_arg S'.f h,
rw SES.f_rev_spec_r at this,
unfold_coes at this, simp at this, rw this,
apply is_group_hom.map_one, } } }.
lemma ker_comp {A B C : Group} (f : A ⟶ B) (g : B ⟶ C)
: is_group_hom.ker (g ∘ f) = f⁻¹' (is_group_hom.ker g) :=
by ext; rw [is_group_hom.mem_ker, set.mem_preimage, is_group_hom.mem_ker]
def third_iso {H G K A B : Group}
(S : SES H G K) (S' : SES A K B)
: SES (Group.of (S.g ⁻¹' set.range S'.f)) G B := {
f := subtype_val.group_hom,
g := S.g ≫ S'.g,
f_inj := λ _ _ h, subtype.eq h,
g_surj := function.surjective_comp S'.g_surj S.g_surj,
im_f_eq_ker_g := by {
unfold_coes, transitivity is_group_hom.ker (S'.g ∘ S.g),
rw ker_comp, rw ← S'.im_f_eq_ker_g,
transitivity set.range subtype.val, refl,
simp, refl, refl } }
local attribute [instance] classical.prop_decidable
lemma SES.simple {G : Group}
: simple_group G ↔ (∀ {H K : Group}, nonempty (SES H G K) → subsingleton H ∨ subsingleton K) :=
begin
constructor; intro h,
{ intros H K S, cases S with S,
cases h, cases h (is_group_hom.ker S.g) with h h,
{ apply or.inl,
rw [← S.im_f_eq_ker_g, is_subgroup.eq_trivial_iff] at h,
constructor, intros, apply S.f_inj,
transitivity (1 : G), apply h, existsi a, refl,
symmetry, apply h, existsi b, refl },
{ apply or.inr, constructor, intros,
cases (S.g_surj a) with a ha, subst ha,
cases (S.g_surj b) with b hb, subst hb,
have ha : a ∈ set.univ := set.mem_univ _,
have hb : b ∈ set.univ := set.mem_univ _,
rw [← h, is_group_hom.mem_ker] at ha hb,
transitivity (1 : K), assumption, symmetry, assumption } },
{ constructor, intros,
cases h ⟨@SES.normal_quotient G N _inst_1⟩ with h h,
{ apply or.inl,
rw @is_subgroup.eq_trivial_iff _ _ N _inst_1.to_is_subgroup,
intros, apply @subtype.mk.inj _ N, apply @subsingleton.elim _ h,
assumption, apply @is_submonoid.one_mem _ _ _ _inst_1.to_is_submonoid },
{ apply or.inr, apply set.eq_univ_of_forall,
suffices : ∀ x : G, 1⁻¹ * x ∈ N,
{ intro, specialize this x, rw [one_inv, one_mul] at this, exact this },
cases h with h, intro x,
specialize h (@quotient_group.mk _ _ N _inst_1.to_is_subgroup 1),
specialize h (@quotient_group.mk _ _ N _inst_1.to_is_subgroup x),
dsimp [quotient_group.mk] at h,
rw quotient.eq' at h_1, assumption, } }
end
def partial_second_iso {H H' G G' K K' : Group.{u}}
(iso : G ≅ G') (hK' : simple_group K')
(S : SES H G K) (S' : SES H' G' K')
(x : H) (x_not_in_H' : ¬ (S'.g (iso.hom (S.f x)) = 1))
: SES (Group.of $ pullback (S.f ≫ iso.hom) S'.f) H K' := {
f := @subtype_val.group_hom (Group.of $ H × H') _ _ ≫ @Group.fst H H',
g := S.f ≫ iso.hom ≫ S'.g,
f_inj := by { intros x y h,
cases x with x hx, cases x with x₁ x₂,
cases y with y hy, cases y with y₁ y₂,
replace h : x₁ = y₁ := h, apply subtype.eq,
simp, apply and.intro h, apply S'.f_inj,
exact eq.trans (eq.symm hx) (eq.trans (congr_arg _ h) hy) },
g_surj := by { intro y, cases S'.g_surj y with a ha,
destruct hK', intro hK',
replace hK' := λ inst, @hK' (S'.g '' (iso.hom '' set.range S.f)) inst,
suffices : normal_subgroup (S'.g '' (iso.hom '' set.range S.f)),
have : S'.g '' (iso.hom '' set.range S.f) = set.univ,
{ apply or.resolve_left (hK' this), intro h,
apply x_not_in_H',
rw [← is_subgroup.mem_trivial, ← h],
apply set.mem_image_of_mem,
apply set.mem_image_of_mem,
apply set.mem_range_self },
rw set.eq_univ_iff_forall at this,
simp, cases this y with a ha,
cases ha with ha' ha, cases ha' with a ha, cases ha with ha' ha,
subst ha, subst ha, cases ha' with a ha', existsi a, rw ha',
rw SES.im_f_eq_ker_g, rw ← set.image_comp,
apply @surj_im_normal G K' (iso.hom ≫ S'.g),
apply function.surjective_comp, exact S'.g_surj, apply Group.iso_surj },
im_f_eq_ker_g := by {
unfold_coes, simp,
transitivity is_group_hom.ker (@category_struct.comp Group _ _ _ _ S.f
(@category_struct.comp Group _ _ _ _ iso.hom S'.g)),
rw Group.ker_of_comp_inj _ _ S.f_inj,
dsimp [subtype_val.group_hom, Group.fst],
rw [set.range_comp, subtype.range_val],
rw [Group.ker_of_comp_inj _ _ (Group.iso_inj iso), ← S'.im_f_eq_ker_g],
ext x, rw set.mem_preimage,
constructor; intro h; cases h with k hk,
{ existsi k.snd, symmetry, rw ← hk.right, exact hk.left },
{ existsi (x, k), constructor, exact hk.symm, refl },
refl
}
}
structure SES.equiv {H H' G G' K K' : Group}
(iso : G ≅ G') (S : SES H G K) (S' : SES H' G' K') :=
(α : H ≅ H') (β : K ≅ K')
(l_comm : S.f ≫ iso.hom = α.hom ≫ S'.f)
(r_comm : S.g ≫ β.hom = iso.hom ≫ S'.g)
def SES.equiv_symm {H H' G G' K K' : Group}
(iso : G ≅ G') (S : SES H G K) (S' : SES H' G' K')
(eqv : SES.equiv iso S S') : SES.equiv iso.symm S' S := {
α := eqv.α.symm, β := eqv.β.symm,
l_comm := by {
refine (_ : @category_struct.comp Group _ _ _ _ S'.f iso.inv
= @category_struct.comp Group _ _ _ _ eqv.α.inv S.f),
rw [iso.comp_inv_eq, category.assoc, eqv.l_comm, ← category.assoc,
eqv.α.inv_hom_id, category.id_comp] },
r_comm := by {
refine (_ : @category_struct.comp Group _ _ _ _ S'.g eqv.β.inv
= @category_struct.comp Group _ _ _ _ iso.inv S.g),
symmetry,
rw [iso.inv_comp_eq, ← category.assoc, ← eqv.r_comm, category.assoc,
eqv.β.hom_inv_id, category.comp_id] }
}
noncomputable
def SES.map_out_right {H G G' K : Group} (S : SES H G K)
(φ : G ⟶ G') (hker : ∀ x : H, φ (S.f x) = 1) : K ⟶ G' := {
val := λ k, φ (function.inv_fun S.g k),
property := is_group_hom.mk' $ by {
intros,
rw [← is_monoid_hom.map_mul φ, is_group_hom.one_iff_ker_inv φ],
suffices : function.inv_fun S.g (x * y)
* (function.inv_fun S.g x * function.inv_fun ⇑(S.g) y)⁻¹
∈ set.range S.f,
{ cases this with a ha, rw ← ha, apply_assumption },
rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, ← is_group_hom.one_iff_ker_inv],
rw is_monoid_hom.map_mul S.g,
repeat { rw @function.inv_fun_eq _ _ _ S.g _ (S.g_surj _) }
}
}
lemma SES.map_out_right_comm {H G G' K : Group} (S : SES H G K)
(φ : G ⟶ G') (hker : ∀ x : H, φ (S.f x) = 1)
: ∀ x : G, SES.map_out_right S φ hker (S.g x) = φ x :=
begin
intros,
apply iff.mpr (is_group_hom.one_iff_ker_inv φ (function.inv_fun S.g $ S.g x) x),
suffices : function.inv_fun S.g (S.g x) * x⁻¹ ∈ set.range S.f,
{ cases this with a ha, rw ← ha, apply_assumption },
rw [SES.im_f_eq_ker_g, is_group_hom.mem_ker, ← is_group_hom.one_iff_ker_inv],
apply function.right_inverse_inv_fun, exact S.g_surj
end
noncomputable
def SES.equiv_of_left {H H' G G' K K' : Group}
(iso : G ≅ G') (S : SES H G K) (S' : SES H' G' K')
(α : H ≅ H') (l_comm : S.f ≫ iso.hom = α.hom ≫ S'.f)
: SES.equiv iso S S' :=
have h1 : ∀ x, (iso.hom ≫ S'.g) (S.f x) = 1,
by { intro, rw ← iso.eq_comp_inv at l_comm, rw l_comm,
suffices : S'.g ((iso.hom.val ∘ iso.inv.val) (S'.f (α.hom x))) = 1,
exact this, have := iso.inv_hom_id,
simp [(≫), category_struct.id] at this,
rw this, simp, apply S'.is_cc },
have h2 : ∀ x, (iso.inv ≫ S.g) (S'.f x) = 1,
by by { intro, replace l_comm := l_comm.symm,
rw ← α.eq_inv_comp at l_comm, rw l_comm,
suffices : S.g ((iso.inv.val ∘ iso.hom.val) (S.f (α.inv x))) = 1,
exact this, have := iso.hom_inv_id,
simp [(≫), category_struct.id] at this,
rw this, simp, apply S.is_cc },
{ α := α, l_comm := l_comm,
β := {
hom := SES.map_out_right S (iso.hom ≫ S'.g) h1,
inv := SES.map_out_right S' (iso.inv ≫ S.g) h2,
hom_inv_id' := by {
ext, cases S.g_surj x with x h, subst h, unfold_coes, simp,
have := SES.map_out_right_comm S (iso.hom ≫ S'.g) h1 x,
unfold_coes at this, simp [(≫)] at this, rw this, clear this,
have := SES.map_out_right_comm S' (iso.inv ≫ S.g) h2 (iso.hom.val x),
unfold_coes at this, simp [(≫)] at this, rw this, clear this,
congr, transitivity (iso.inv.val ∘ iso.hom.val) x, refl,
transitivity id x, apply congr_fun, exact subtype.mk.inj iso.hom_inv_id, refl,
},
inv_hom_id' := by {
ext, cases S'.g_surj x with x h, subst h, unfold_coes, simp,
have := SES.map_out_right_comm S' (iso.inv ≫ S.g) h2 x,
unfold_coes at this, simp [(≫)] at this, rw this, clear this,
have := SES.map_out_right_comm S (iso.hom ≫ S'.g) h1 (iso.inv.val x),
unfold_coes at this, simp [(≫)] at this, rw this, clear this,
congr, transitivity (iso.hom.val ∘ iso.inv.val) x, refl,
transitivity id x, apply congr_fun, exact subtype.mk.inj iso.inv_hom_id, refl,
}
},
r_comm := by {
unfold_coes, simp,
ext, transitivity SES.map_out_right S (iso.hom ≫ S'.g) h1 (S.g x),
refl, apply SES.map_out_right_comm,
}
}.
noncomputable
def SES.equiv_of_ker_im_match {H H' G G' K K' : Group}
(iso : G ≅ G') (S : SES H G K) (S' : SES H' G' K')
(h_l : ∀ x : H, S'.g (iso.hom (S.f x)) = 1)
(h_r : ∀ x : H', S.g (iso.inv (S'.f x)) = 1)
: SES.equiv iso S S' :=
have h1 : iso.hom '' set.range S.f ⊆ is_group_hom.ker S'.g
∧ iso.inv '' set.range S'.f ⊆ is_group_hom.ker S.g,
from by { constructor; intros x hx;
cases hx with x hx; cases hx with hx hx;
subst hx; cases hx with x hx; subst hx;
rw is_group_hom.mem_ker; apply_assumption },
have h2 : iso.hom '' set.range S.f = set.range S'.f,
by { rw [← S.im_f_eq_ker_g, ← S'.im_f_eq_ker_g] at h1,
cases h1 with h h', rw set.image_subset_iff at h',
rw ← set.image_eq_preimage_of_inverse at h',
exact funext (λ x, propext ⟨@h x, @h' x⟩),
apply Group.iso_left_inverse, apply Group.iso_right_inverse },
have h3 : Group.of ↥(⇑(iso.hom) '' set.range ⇑(S.f)) = Group.of ↥(set.range ⇑(S'.f)),
by { rw Group.subgroup_eq_of_eq h2, },
have h4 : ∀ {A B : Group} (h : A = B) (t : A),
t == (eq.rec (category_theory.iso.refl A) h : A ≅ B).hom.val t,
by { intros, cases h, refl },
begin
refine SES.equiv_of_left iso S S' _ _,
transitivity,
exact (S.left_iso_range ≪≫ Group.iso_restrict iso _),
transitivity, tactic.swap, apply S'.left_iso_range.symm,
exact eq.rec (category_theory.iso.refl (Group.of ↥(⇑(iso.hom) '' set.range ⇑(S.f)))) h3,
rw category_theory.iso.trans_assoc,
ext,
dsimp [(≪≫)],
dsimp [SES.left_iso_range],
dsimp [Group.iso_restrict],
unfold_coes,
dsimp [subtype.val],
rw (_ : S'.f.val = ⇑(S'.f)), tactic.swap, refl,
rw S'.f_rev_spec_r,
unfold_coes,
clear h1, clear h_l, clear h_r,
generalize h : subtype.mk ((iso.hom).val ((S.f).val x)) _ = t,
transitivity t.val, { subst h },
congr, ext, rw h2, apply h4 h3
end
lemma Group.normal_subgroup_card_lt_of_nontriv_quot
{H G K : Group} [fintype G] (S : SES H G K) (hK : ¬ subsingleton K)
: @fintype.card H (fintype.of_injective S.f S.f_inj) < fintype.card G :=
begin
have : ∃ k : K, k ≠ 1,
{ by_contradiction h, rw not_exists_not at h,
apply hK, constructor, intros,
transitivity (1 : K), apply h, symmetry, apply h },
cases this with k hk, cases S.g_surj k with x hx, subst hx,
replace hk := mt (iff.mp (is_group_hom.mem_ker S.g)) hk,
rw [← S.im_f_eq_ker_g] at hk,
apply @nat.lt_of_le_of_lt _ (@finset.card _ (finset.erase finset.univ x)),
have h1 : ∀ (y : G), y ∈ finset.erase finset.univ x ↔ y ≠ x,
{ intro, rw [finset.mem_erase, (_ : y ∈ finset.univ ↔ true)],
apply and_true, rw iff_true, apply finset.mem_univ },
have h2 : fintype { y : G // y ≠ x } := fintype.subtype _ h1,
rw ← @fintype.subtype_card _ (λ y, y ≠ x) _ h1,
apply @nat.le_trans _ (@fintype.card { y : G // y ≠ x } h2),
apply @fintype.card_le_of_injective H _ (fintype.of_injective S.f S.f_inj) h2
(λ y, ⟨S.f y, λ h, hk ⟨y, h⟩⟩)
(λ _ _ hab, S.f_inj (subtype.mk.inj hab)),
apply nat.le_of_eq, congr,
rw finset.card_erase_of_mem, dsimp [fintype.card],
apply nat.pred_lt, refine (_ : ¬ (fintype.card G = 0)),
rw fintype.card_eq_zero_iff, exact λ h, h 1, apply finset.mem_univ
end
def SES.not_contains_of_simple_quot_and_proper {H H' G G' K K' : Group} (iso : G ≅ G')
(S : SES H G K) (S' : SES H' G' K')
(hK : simple_group K) (hK' : ¬ subsingleton K')
(hnoteqv : SES.equiv iso S S' → false)
: ∃ x, S'.g (iso.hom (S.f x)) ≠ 1 :=
begin
have h1 : ¬ ((∀ x, S'.g (iso.hom (S.f x)) = 1)
∧ (∀ x, S.g (iso.inv (S'.f x)) = 1)),
{ intro h, apply hnoteqv, cases h,
apply SES.equiv_of_ker_im_match; assumption },
rw classical.not_and_distrib at h1, cases h1,
rw ← classical.not_forall, assumption,
rw ← classical.not_forall, intro h2, apply h1,
suffices : iso.inv '' set.range S'.f ⊆ is_group_hom.ker S.g,
{ intro, rw ← is_group_hom.mem_ker S.g,
exact this ⟨S'.f x, set.mem_range_self x, rfl⟩ },
destruct hK, intro,
have : iso.hom '' set.range S.f ⊆ is_group_hom.ker S'.g,
{ intros x hx, cases hx with x' hx,
rw ← hx.right, cases hx.left with x hx, rw ← hx,
rw is_group_hom.mem_ker, apply h2 },
cases @simple (S.g '' (iso.inv '' is_group_hom.ker S'.g))
(@surj_im_normal _ _ S.g S.g_surj _
(surj_im_normal iso.inv (Group.iso_surj iso.symm) _)),
rw [set.image_subset_iff,
← set.image_eq_preimage_of_inverse
(Group.iso_right_inverse _) (Group.iso_left_inverse _)] at this,
transitivity S.g ⁻¹' (S.g '' (iso.inv '' is_group_hom.ker S'.g)),
rw S'.im_f_eq_ker_g, apply set.subset_preimage_image S.g,
rw h, refl, exfalso, apply hK',
have : ∀ x : K', x = 1,
{ have h3 := Group.eq_of_im_eq_and_contain_ker _ h _,
intro x, cases S'.g_surj x with x hx, subst hx,
rw ← is_group_hom.mem_ker S'.g,
have h4 : iso.inv x ∈ set.univ := set.mem_univ _,
rw [← h3, set.mem_image_iff_of_inverse
(Group.iso_right_inverse _) (Group.iso_left_inverse _),
Group.iso_right_inverse _] at h4,
assumption,
rw [← S.im_f_eq_ker_g,
set.image_eq_preimage_of_inverse
(Group.iso_right_inverse _) (Group.iso_left_inverse _)],
rw ← set.image_subset_iff, assumption },
constructor, intros, transitivity (1 : K'),
apply_assumption, symmetry, apply_assumption,
end
noncomputable
def SES.partial_second_iso' {H H' G G' K K' : Group} (iso : G ≅ G')
(S : SES H G K) (S' : SES H' G' K')
(hK₁ : simple_group K) (hK₂ : ¬ subsingleton K)
(hK'₁ : simple_group K') (hK'₂ : ¬ subsingleton K')
(hnoteqv : SES.equiv iso S S' → false)
: SES (Group.of (pullback (S.f ≫ iso.hom) S'.f)) H K' :=
begin
cases classical.subtype_of_exists (SES.not_contains_of_simple_quot_and_proper iso S S' hK₁ hK'₂ hnoteqv),
apply @partial_second_iso H H' G G' K K' iso hK'₁ S S', assumption,
end
|
c46105f03b040949f8da53880e4ff949f75e8ef6
|
a047a4718edfa935d17231e9e6ecec8c7b701e05
|
/src/tactic/core.lean
|
d10b500fa363454d5262f5435550aa5967a6efae
|
[
"Apache-2.0"
] |
permissive
|
utensil-contrib/mathlib
|
bae0c9fafe5e2bdb516efc89d6f8c1502ecc9767
|
b91909e77e219098a2f8cc031f89d595fe274bd2
|
refs/heads/master
| 1,668,048,976,965
| 1,592,442,701,000
| 1,592,442,701,000
| 273,197,855
| 0
| 0
| null | 1,592,472,812,000
| 1,592,472,811,000
| null |
UTF-8
|
Lean
| false
| false
| 84,275
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek
-/
import data.dlist.basic
import control.basic
import meta.expr
import meta.rb_map
import data.bool
import tactic.lean_core_docs
universe variable u
instance : has_lt pos :=
{ lt := λ x y, (x.line, x.column) < (y.line, y.column) }
namespace expr
open tactic
/-- Given an expr `α` representing a type with numeral structure,
`of_nat α n` creates the `α`-valued numeral expression corresponding to `n`. -/
protected meta def of_nat (α : expr) : ℕ → tactic expr :=
nat.binary_rec
(tactic.mk_mapp ``has_zero.zero [some α, none])
(λ b n tac, if n = 0 then mk_mapp ``has_one.one [some α, none] else
do e ← tac, tactic.mk_app (cond b ``bit1 ``bit0) [e])
/-- Given an expr `α` representing a type with numeral structure,
`of_int α n` creates the `α`-valued numeral expression corresponding to `n`.
The output is either a numeral or the negation of a numeral. -/
protected meta def of_int (α : expr) : ℤ → tactic expr
| (n : ℕ) := expr.of_nat α n
| -[1+ n] := do
e ← expr.of_nat α (n+1),
tactic.mk_app ``has_neg.neg [e]
/-- Generates an expression of the form `∃(args), inner`. `args` is assumed to be a list of local
constants. When possible, `p ∧ q` is used instead of `∃(_ : p), q`. -/
meta def mk_exists_lst (args : list expr) (inner : expr) : tactic expr :=
args.mfoldr (λarg i:expr, do
t ← infer_type arg,
sort l ← infer_type t,
return $ if arg.occurs i ∨ l ≠ level.zero
then (const `Exists [l] : expr) t (i.lambdas [arg])
else (const `and [] : expr) t i)
inner
/-- `traverse f e` applies the monadic function `f` to the direct descendants of `e`. -/
meta def traverse {m : Type → Type u} [applicative m]
{elab elab' : bool} (f : expr elab → m (expr elab')) :
expr elab → m (expr elab')
| (var v) := pure $ var v
| (sort l) := pure $ sort l
| (const n ls) := pure $ const n ls
| (mvar n n' e) := mvar n n' <$> f e
| (local_const n n' bi e) := local_const n n' bi <$> f e
| (app e₀ e₁) := app <$> f e₀ <*> f e₁
| (lam n bi e₀ e₁) := lam n bi <$> f e₀ <*> f e₁
| (pi n bi e₀ e₁) := pi n bi <$> f e₀ <*> f e₁
| (elet n e₀ e₁ e₂) := elet n <$> f e₀ <*> f e₁ <*> f e₂
| (macro mac es) := macro mac <$> list.traverse f es
/-- `mfoldl f a e` folds the monadic function `f` over the subterms of the expression `e`,
with initial value `a`. -/
meta def mfoldl {α : Type} {m} [monad m] (f : α → expr → m α) : α → expr → m α
| x e := prod.snd <$> (state_t.run (e.traverse $ λ e',
(get >>= monad_lift ∘ flip f e' >>= put) $> e') x : m _)
/-- `kreplace e old new` replaces all occurrences of the expression `old` in `e`
with `new`. The occurrences of `old` in `e` are determined using keyed matching
with transparency `md`; see `kabstract` for details. If `unify` is true,
we may assign metavariables in `e` as we match subterms of `e` against `old`. -/
meta def kreplace (e old new : expr) (md := semireducible) (unify := tt)
: tactic expr := do
e ← kabstract e old md unify,
pure $ e.instantiate_var new
end expr
namespace interaction_monad
open result
variables {σ : Type} {α : Type u}
/-- `get_state` returns the underlying state inside an interaction monad, from within that monad. -/
-- Note that this is a generalization of `tactic.read` in core.
meta def get_state : interaction_monad σ σ :=
λ state, success state state
/-- `set_state` sets the underlying state inside an interaction monad, from within that monad. -/
-- Note that this is a generalization of `tactic.write` in core.
meta def set_state (state : σ) : interaction_monad σ unit :=
λ _, success () state
/--
`run_with_state state tac` applies `tac` to the given state `state` and returns the result,
subsequently restoring the original state.
If `tac` fails, then `run_with_state` does too.
-/
meta def run_with_state (state : σ) (tac : interaction_monad σ α) : interaction_monad σ α :=
λ s, match tac state with
| success val _ := success val s
| exception fn pos _ := exception fn pos s
end
end interaction_monad
namespace format
/-- `join' [a,b,c]` produces the format object `abc`.
It differs from `format.join` by using `format.nil` instead of `""` for the empty list. -/
meta def join' (xs : list format) : format :=
xs.foldl compose nil
/-- `intercalate x [a, b, c]` produces the format object `a.x.b.x.c`,
where `.` represents `format.join`. -/
meta def intercalate (x : format) : list format → format :=
join' ∘ list.intersperse x
/-- `soft_break` is similar to `line`. Whereas in `group (x ++ line ++ y ++ line ++ z)`
the result either fits on one line or in three, `x ++ soft_break ++ y ++ soft_break ++ z`
each line break is decided independently -/
meta def soft_break : format :=
group line
end format
section format
open format
/-- format a `list` by separating elements with `soft_break` instead of `line` -/
meta def list.to_line_wrap_format {α : Type u} [has_to_format α] : list α → format
| [] := to_fmt "[]"
| xs := to_fmt "[" ++ group (nest 1 $ intercalate ("," ++ soft_break) $ xs.map to_fmt) ++ to_fmt "]"
end format
namespace tactic
open function
/-- Private work function for `add_local_consts_as_local_hyps`: given
`mappings : list (expr × expr)` corresponding to pairs `(var, hyp)` of variables and the local
hypothesis created as a result and `(var :: rest) : list expr` of more local variables we
examine `var` to see if it contains any other variables in `rest`. If it does, we put it to the
back of the queue and recurse. If it does not, then we perform replacements inside the type of
`var` using the `mappings`, create a new associate local hypothesis, add this to the list of
mappings, and recurse. We are done once all local hypotheses have been processed.
If the list of passed local constants have types which depend on one another (which can only
happen by hand-crafting the `expr`s manually), this function will loop forever. -/
private meta def add_local_consts_as_local_hyps_aux
: list (expr × expr) → list expr → tactic (list (expr × expr))
| mappings [] := return mappings
| mappings (var :: rest) := do
/- Determine if `var` contains any local variables in the lift `rest`. -/
let is_dependent := var.local_type.fold ff $ λ e n b,
if b then b else e ∈ rest,
/- If so, then skip it---add it to the end of the variable queue. -/
if is_dependent then
add_local_consts_as_local_hyps_aux mappings (rest ++ [var])
else do
/- Otherwise, replace all of the local constants referenced by the type of `var` with the
respective new corresponding local hypotheses as recorded in the list `mappings`. -/
let new_type := var.local_type.replace_subexprs mappings,
/- Introduce a new local new local hypothesis `hyp` for `var`, with the correct type. -/
hyp ← assertv var.local_pp_name new_type (var.local_const_set_type new_type),
/- Process the next variable in the queue, with the mapping list updated to include the local
hypothesis which we just created. -/
add_local_consts_as_local_hyps_aux ((var, hyp) :: mappings) rest
/-- `add_local_consts_as_local_hyps vars` add the given list `vars` of `expr.local_const`s to the
tactic state. This is harder than it sounds, since the list of local constants which we have
been passed can have dependencies between their types.
For example, suppose we have two local constants `n : ℕ` and `h : n = 3`. Then we cannot blindly
add `h` as a local hypothesis, since we need the `n` to which it refers to be the `n` created as
a new local hypothesis, not the old local constant `n` with the same name. Of course, these
dependencies can be nested arbitrarily deep.
If the list of passed local constants have types which depend on one another (which can only
happen by hand-crafting the `expr`s manually), this function will loop forever. -/
meta def add_local_consts_as_local_hyps (vars : list expr) : tactic (list (expr × expr)) :=
/- The `list.reverse` below is a performance optimisation since the list of available variables
reported by the system is often mostly the reverse of the order in which they are dependent. -/
add_local_consts_as_local_hyps_aux [] vars.reverse.erase_dup
/-- `mk_local_pisn e n` instantiates the first `n` variables of a pi expression `e`,
and returns the new local constants along with the instantiated expression. Fails if `e` does
not begin with at least `n` pi binders. -/
meta def mk_local_pisn : expr → nat → tactic (list expr × expr)
| (expr.pi n bi d b) (c + 1) := do
p ← mk_local' n bi d,
(ps, r) ← mk_local_pisn (b.instantiate_var p) c,
return ((p :: ps), r)
| e 0 := return ([], e)
| _ _ := failed
-- TODO: move to `declaration` namespace in `meta/expr.lean`
/-- `mk_theorem n ls t e` creates a theorem declaration with name `n`, universe parameters named
`ls`, type `t`, and body `e`. -/
meta def mk_theorem (n : name) (ls : list name) (t : expr) (e : expr) : declaration :=
declaration.thm n ls t (task.pure e)
/-- `add_theorem_by n ls type tac` uses `tac` to synthesize a term with type `type`, and adds this
to the environment as a theorem with name `n` and universe parameters `ls`. -/
meta def add_theorem_by (n : name) (ls : list name) (type : expr) (tac : tactic unit) :
tactic expr :=
do ((), body) ← solve_aux type tac,
body ← instantiate_mvars body,
add_decl $ mk_theorem n ls type body,
return $ expr.const n $ ls.map level.param
/-- `eval_expr' α e` attempts to evaluate the expression `e` in the type `α`.
This is a variant of `eval_expr` in core. Due to unexplained behavior in the VM, in rare
situations the latter will fail but the former will succeed. -/
meta def eval_expr' (α : Type*) [_inst_1 : reflected α] (e : expr) : tactic α :=
mk_app ``id [e] >>= eval_expr α
/-- `mk_fresh_name` returns identifiers starting with underscores,
which are not legal when emitted by tactic programs. `mk_user_fresh_name`
turns the useful source of random names provided by `mk_fresh_name` into
names which are usable by tactic programs.
The returned name has four components which are all strings. -/
meta def mk_user_fresh_name : tactic name :=
do nm ← mk_fresh_name,
return $ `user__ ++ nm.pop_prefix.sanitize_name ++ `user__
/-- `has_attribute' attr_name decl_name` checks
whether `decl_name` exists and has attribute `attr_name`. -/
meta def has_attribute' (attr_name decl_name : name) : tactic bool :=
succeeds (has_attribute attr_name decl_name)
/-- Checks whether the name is a simp lemma -/
meta def is_simp_lemma : name → tactic bool :=
has_attribute' `simp
/-- Checks whether the name is an instance. -/
meta def is_instance : name → tactic bool :=
has_attribute' `instance
/-- `local_decls` returns a dictionary mapping names to their corresponding declarations.
Covers all declarations from the current file. -/
meta def local_decls : tactic (name_map declaration) :=
do e ← tactic.get_env,
let xs := e.fold native.mk_rb_map
(λ d s, if environment.in_current_file' e d.to_name
then s.insert d.to_name d else s),
pure xs
/-- If `{nm}_{n}` doesn't exist in the environment, returns that, otherwise tries `{nm}_{n+1}` -/
meta def get_unused_decl_name_aux (e : environment) (nm : name) : ℕ → tactic name | n :=
let nm' := nm.append_suffix ("_" ++ to_string n) in
if e.contains nm' then get_unused_decl_name_aux (n+1) else return nm'
/-- Return a name which doesn't already exist in the environment. If `nm` doesn't exist, it
returns that, otherwise it tries `nm_2`, `nm_3`, ... -/
meta def get_unused_decl_name (nm : name) : tactic name :=
get_env >>= λ e, if e.contains nm then get_unused_decl_name_aux e nm 2 else return nm
/--
Returns a pair `(e, t)`, where `e ← mk_const d.to_name`, and `t = d.type`
but with universe params updated to match the fresh universe metavariables in `e`.
This should have the same effect as just
```lean
do e ← mk_const d.to_name,
t ← infer_type e,
return (e, t)
```
but is hopefully faster.
-/
meta def decl_mk_const (d : declaration) : tactic (expr × expr) :=
do subst ← d.univ_params.mmap $ λ u, prod.mk u <$> mk_meta_univ,
let e : expr := expr.const d.to_name (prod.snd <$> subst),
return (e, d.type.instantiate_univ_params subst)
/--
Replace every universe metavariable in an expression with a universe parameter.
(This is useful when making new declarations.)
-/
meta def replace_univ_metas_with_univ_params (e : expr) : tactic expr :=
do
e.list_univ_meta_vars.enum.mmap (λ n, do
let n' := (`u).append_suffix ("_" ++ to_string (n.1+1)),
unify (expr.sort (level.mvar n.2)) (expr.sort (level.param n'))),
instantiate_mvars e
/-- `mk_local n` creates a dummy local variable with name `n`.
The type of this local constant is a constant with name `n`, so it is very unlikely to be
a meaningful expression. -/
meta def mk_local (n : name) : expr :=
expr.local_const n n binder_info.default (expr.const n [])
/-- `pis loc_consts f` is used to create a pi expression whose body is `f`.
`loc_consts` should be a list of local constants. The function will abstract these local
constants from `f` and bind them with pi binders.
For example, if `a, b` are local constants with types `Ta, Tb`,
``pis [a, b] `(f a b)`` will return the expression
`Π (a : Ta) (b : Tb), f a b`. -/
meta def pis : list expr → expr → tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t ← infer_type e,
f' ← pis es f,
pure $ expr.pi pp info t (expr.abstract_local f' uniq)
| _ f := pure f
/-- `lambdas loc_consts f` is used to create a lambda expression whose body is `f`.
`loc_consts` should be a list of local constants. The function will abstract these local
constants from `f` and bind them with lambda binders.
For example, if `a, b` are local constants with types `Ta, Tb`,
``lambdas [a, b] `(f a b)`` will return the expression
`λ (a : Ta) (b : Tb), f a b`. -/
meta def lambdas : list expr → expr → tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t ← infer_type e,
f' ← lambdas es f,
pure $ expr.lam pp info t (expr.abstract_local f' uniq)
| _ f := pure f
/-- `mk_psigma [x,y,z]`, with `[x,y,z]` list of local constants of types `x : tx`,
`y : ty x` and `z : tz x y`, creates an expression of sigma type:
`⟨x,y,z⟩ : Σ' (x : tx) (y : ty x), tz x y`.
-/
meta def mk_psigma : list expr → tactic expr
| [] := mk_const ``punit
| [x@(expr.local_const _ _ _ _)] := pure x
| (x@(expr.local_const _ _ _ _) :: xs) :=
do y ← mk_psigma xs,
α ← infer_type x,
β ← infer_type y,
t ← lambdas [x] β >>= instantiate_mvars,
r ← mk_mapp ``psigma.mk [α,t],
pure $ r x y
| _ := fail "mk_psigma expects a list of local constants"
/-- `elim_gen_prod n e _ ns` with `e` an expression of type `psigma _`, applies `cases` on `e` `n`
times and uses `ns` to name the resulting variables. Returns a triple: list of new variables,
remaining term and unused variable names.
-/
meta def elim_gen_prod : nat → expr → list expr → list name → tactic (list expr × expr × list name)
| 0 e hs ns := return (hs.reverse, e, ns)
| (n + 1) e hs ns := do
t ← infer_type e,
if t.is_app_of `eq then return (hs.reverse, e, ns)
else do
[(_, [h, h'], _)] ← cases_core e (ns.take 1),
elim_gen_prod n h' (h :: hs) (ns.drop 1)
private meta def elim_gen_sum_aux : nat → expr → list expr → tactic (list expr × expr)
| 0 e hs := return (hs, e)
| (n + 1) e hs := do
[(_, [h], _), (_, [h'], _)] ← induction e [],
swap,
elim_gen_sum_aux n h' (h::hs)
/-- `elim_gen_sum n e` applies cases on `e` `n` times. `e` is assumed to be a local constant whose
type is a (nested) sum `⊕`. Returns the list of local constants representing the components of `e`.
-/
meta def elim_gen_sum (n : nat) (e : expr) : tactic (list expr) := do
(hs, h') ← elim_gen_sum_aux n e [],
gs ← get_goals,
set_goals $ (gs.take (n+1)).reverse ++ gs.drop (n+1),
return $ hs.reverse ++ [h']
/-- Given `elab_def`, a tactic to solve the current goal,
`extract_def n trusted elab_def` will create an auxiliary definition named `n` and use it
to close the goal. If `trusted` is false, it will be a meta definition. -/
meta def extract_def (n : name) (trusted : bool) (elab_def : tactic unit) : tactic unit :=
do cxt ← list.map expr.to_implicit_local_const <$> local_context,
t ← target,
(eqns,d) ← solve_aux t elab_def,
d ← instantiate_mvars d,
t' ← pis cxt t,
d' ← lambdas cxt d,
let univ := t'.collect_univ_params,
add_decl $ declaration.defn n univ t' d' (reducibility_hints.regular 1 tt) trusted,
applyc n
/-- Attempts to close the goal with `dec_trivial`. -/
meta def exact_dec_trivial : tactic unit := `[exact dec_trivial]
/-- Runs a tactic for a result, reverting the state after completion. -/
meta def retrieve {α} (tac : tactic α) : tactic α :=
λ s, result.cases_on (tac s)
(λ a s', result.success a s)
result.exception
/-- Repeat a tactic at least once, calling it recursively on all subgoals,
until it fails. This tactic fails if the first invocation fails. -/
meta def repeat1 (t : tactic unit) : tactic unit := t; repeat t
/-- `iterate_range m n t`: Repeat the given tactic at least `m` times and
at most `n` times or until `t` fails. Fails if `t` does not run at least `m` times. -/
meta def iterate_range : ℕ → ℕ → tactic unit → tactic unit
| 0 0 t := skip
| 0 (n+1) t := try (t >> iterate_range 0 n t)
| (m+1) n t := t >> iterate_range m (n-1) t
/--
Given a tactic `tac` that takes an expression
and returns a new expression and a proof of equality,
use that tactic to change the type of the hypotheses listed in `hs`,
as well as the goal if `tgt = tt`.
Returns `tt` if any types were successfully changed.
-/
meta def replace_at (tac : expr → tactic (expr × expr)) (hs : list expr) (tgt : bool) :
tactic bool :=
do to_remove ← hs.mfilter $ λ h, do {
h_type ← infer_type h,
succeeds $ do
(new_h_type, pr) ← tac h_type,
assert h.local_pp_name new_h_type,
mk_eq_mp pr h >>= tactic.exact },
goal_simplified ← succeeds $ do {
guard tgt,
(new_t, pr) ← target >>= tac,
replace_target new_t pr },
to_remove.mmap' (λ h, try (clear h)),
return (¬ to_remove.empty ∨ goal_simplified)
/-- `revert_after e` reverts all local constants after local constant `e`. -/
meta def revert_after (e : expr) : tactic ℕ := do
l ← local_context,
[pos] ← return $ l.indexes_of e | pp e >>= λ s, fail format!"No such local constant {s}",
let l := l.drop pos.succ, -- all local hypotheses after `e`
revert_lst l
/-- `generalize' e n` generalizes the target with respect to `e`. It creates a new local constant
with name `n` of the same type as `e` and replaces all occurrences of `e` by `n`.
`generalize'` is similar to `generalize` but also succeeds when `e` does not occur in the
goal, in which case it just calls `assert`.
In contrast to `generalize` it already introduces the generalized variable. -/
meta def generalize' (e : expr) (n : name) : tactic expr :=
(generalize e n >> intro1) <|> note n none e
/-!
### Various tactics related to local definitions (local constants of the form `x : α := t`)
We call `t` the value of `x`.
-/
/-- `local_def_value e` returns the value of the expression `e`, assuming that `e` has been defined
locally using a `let` expression. Otherwise it fails. -/
meta def local_def_value (e : expr) : tactic expr :=
pp e >>= λ s, -- running `pp` here, because we cannot access it in the `type_context` monad.
tactic.unsafe.type_context.run $ do
lctx <- tactic.unsafe.type_context.get_local_context,
some ldecl <- return $ lctx.get_local_decl e.local_uniq_name |
tactic.unsafe.type_context.fail format!"No such hypothesis {s}.",
some let_val <- return ldecl.value |
tactic.unsafe.type_context.fail format!"Variable {e} is not a local definition.",
return let_val
/-- `revert_deps e` reverts all the hypotheses that depend on one of the local
constants `e`, including the local definitions that have `e` in their definition.
This fixes a bug in `revert_kdeps` that does not revert local definitions for which `e` only
appears in the definition. -/
/- We cannot implement it as `revert e >> intro1`, because that would change the local constant in
the context. -/
meta def revert_deps (e : expr) : tactic ℕ := do
n ← revert_kdeps e,
l ← local_context,
[pos] ← return $ l.indexes_of e,
let l := l.drop pos.succ, -- local hypotheses after `e`
ls ← l.mfilter $ λ e', try_core (local_def_value e') >>= λ o, return $ o.elim ff $ λ e'',
e''.has_local_constant e,
n' ← revert_lst ls,
return $ n + n'
/-- `is_local_def e` succeeds when `e` is a local definition (a local constant of the form
`e : α := t`) and otherwise fails. -/
meta def is_local_def (e : expr) : tactic unit :=
retrieve $ do revert e, expr.elet _ _ _ _ ← target, skip
/-- `clear_value e` clears the body of the local definition `e`, changing it into a regular
hypothesis. A hypothesis `e : α := t` is changed to `e : α`.
This tactic is called `clearbody` in Coq. -/
meta def clear_value (e : expr) : tactic unit := do
n ← revert_after e,
is_local_def e <|>
pp e >>= λ s, fail format!"Cannot clear the body of {s}. It is not a local definition.",
let nm := e.local_pp_name,
(generalize' e nm >> clear e) <|>
fail format!"Cannot clear the body of {nm}. The resulting goal is not type correct.",
intron n
/-- A variant of `simplify_bottom_up`. Given a tactic `post` for rewriting subexpressions,
`simp_bottom_up post e` tries to rewrite `e` starting at the leaf nodes. Returns the resulting
expression and a proof of equality. -/
meta def simp_bottom_up' (post : expr → tactic (expr × expr)) (e : expr) (cfg : simp_config := {}) :
tactic (expr × expr) :=
prod.snd <$> simplify_bottom_up () (λ _, (<$>) (prod.mk ()) ∘ post) e cfg
/-- Caches unary type classes on a type `α : Type.{univ}`. -/
meta structure instance_cache :=
(α : expr)
(univ : level)
(inst : name_map expr)
/-- Creates an `instance_cache` for the type `α`. -/
meta def mk_instance_cache (α : expr) : tactic instance_cache :=
do u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
return ⟨α, u, mk_name_map⟩
namespace instance_cache
/-- If `n` is the name of a type class with one parameter, `get c n` tries to find an instance of
`n c.α` by checking the cache `c`. If there is no entry in the cache, it tries to find the instance
via type class resolution, and updates the cache. -/
meta def get (c : instance_cache) (n : name) : tactic (instance_cache × expr) :=
match c.inst.find n with
| some i := return (c, i)
| none := do e ← mk_app n [c.α] >>= mk_instance,
return (⟨c.α, c.univ, c.inst.insert n e⟩, e)
end
open expr
/-- If `e` is a `pi` expression that binds an instance-implicit variable of type `n`,
`append_typeclasses e c l` searches `c` for an instance `p` of type `n` and returns `p :: l`. -/
meta def append_typeclasses : expr → instance_cache → list expr →
tactic (instance_cache × list expr)
| (pi _ binder_info.inst_implicit (app (const n _) (var _)) body) c l :=
do (c, p) ← c.get n, return (c, p :: l)
| _ c l := return (c, l)
/-- Creates the application `n c.α p l`, where `p` is a type class instance found in the cache `c`.
-/
meta def mk_app (c : instance_cache) (n : name) (l : list expr) : tactic (instance_cache × expr) :=
do d ← get_decl n,
(c, l) ← append_typeclasses d.type.binding_body c l,
return (c, (expr.const n [c.univ]).mk_app (c.α :: l))
/-- `c.of_nat n` creates the `c.α`-valued numeral expression corresponding to `n`. -/
protected meta def of_nat (c : instance_cache) (n : ℕ) : tactic (instance_cache × expr) :=
if n = 0 then c.mk_app ``has_zero.zero [] else do
(c, ai) ← c.get ``has_add,
(c, oi) ← c.get ``has_one,
(c, one) ← c.mk_app ``has_one.one [],
return (c, n.binary_rec one $ λ b n e,
if n = 0 then one else
cond b
((expr.const ``bit1 [c.univ]).mk_app [c.α, oi, ai, e])
((expr.const ``bit0 [c.univ]).mk_app [c.α, ai, e]))
/-- `c.of_int n` creates the `c.α`-valued numeral expression corresponding to `n`.
The output is either a numeral or the negation of a numeral. -/
protected meta def of_int (c : instance_cache) : ℤ → tactic (instance_cache × expr)
| (n : ℕ) := c.of_nat n
| -[1+ n] := do
(c, e) ← c.of_nat (n+1),
c.mk_app ``has_neg.neg [e]
end instance_cache
private meta def get_expl_pi_arity_aux : expr → tactic nat
| (expr.pi n bi d b) :=
do m ← mk_fresh_name,
let l := expr.local_const m n bi d,
new_b ← whnf (expr.instantiate_var b l),
r ← get_expl_pi_arity_aux new_b,
if bi = binder_info.default then
return (r + 1)
else
return r
| e := return 0
/-- Compute the arity of explicit arguments of the given (Pi-)type. -/
meta def get_expl_pi_arity (type : expr) : tactic nat :=
whnf type >>= get_expl_pi_arity_aux
/-- Compute the arity of explicit arguments of the given function. -/
meta def get_expl_arity (fn : expr) : tactic nat :=
infer_type fn >>= get_expl_pi_arity
/-- Auxilliary defintion for `get_pi_binders`. -/
meta def get_pi_binders_aux : list binder → expr → tactic (list binder × expr)
| es (expr.pi n bi d b) :=
do m ← mk_fresh_name,
let l := expr.local_const m n bi d,
let new_b := expr.instantiate_var b l,
get_pi_binders_aux (⟨n, bi, d⟩::es) new_b
| es e := return (es, e)
/-- Get the binders and target of a pi-type. Instantiates bound variables by
local constants. Cf. `pi_binders` in `meta.expr` (which produces open terms).
See also `mk_local_pis` in `init.core.tactic` which does almost the same. -/
meta def get_pi_binders : expr → tactic (list binder × expr) | e :=
do (es, e) ← get_pi_binders_aux [] e, return (es.reverse, e)
/-- Auxilliary definition for `get_pi_binders_dep`. -/
meta def get_pi_binders_dep_aux : ℕ → expr → tactic (list (ℕ × binder) × expr)
| n (expr.pi nm bi d b) :=
do l ← mk_local' nm bi d,
(ls, r) ← get_pi_binders_dep_aux (n+1) (expr.instantiate_var b l),
return (if b.has_var then ls else (n, ⟨nm, bi, d⟩)::ls, r)
| n e := return ([], e)
/-- A variant of `get_pi_binders` that only returns the binders that do not occur in later
arguments or in the target. Also returns the argument position of each returned binder. -/
meta def get_pi_binders_dep : expr → tactic (list (ℕ × binder) × expr) :=
get_pi_binders_dep_aux 0
/-- A variation on `assert` where a (possibly incomplete)
proof of the assertion is provided as a parameter.
``(h,gs) ← local_proof `h p tac`` creates a local `h : p` and
use `tac` to (partially) construct a proof for it. `gs` is the
list of remaining goals in the proof of `h`.
The benefits over assert are:
- unlike with ``h ← assert `h p, tac`` , `h` cannot be used by `tac`;
- when `tac` does not complete the proof of `h`, returning the list
of goals allows one to write a tactic using `h` and with the confidence
that a proof will not boil over to goals left over from the proof of `h`,
unlike what would be the case when using `tactic.swap`.
-/
meta def local_proof (h : name) (p : expr) (tac₀ : tactic unit) :
tactic (expr × list expr) :=
focus1 $
do h' ← assert h p,
[g₀,g₁] ← get_goals,
set_goals [g₀], tac₀,
gs ← get_goals,
set_goals [g₁],
return (h', gs)
/-- `var_names e` returns a list of the unique names of the initial pi bindings in `e`. -/
meta def var_names : expr → list name
| (expr.pi n _ _ b) := n :: var_names b
| _ := []
/-- When `struct_n` is the name of a structure type,
`subobject_names struct_n` returns two lists of names `(instances, fields)`.
The names in `instances` are the projections from `struct_n` to the structures that it extends
(assuming it was defined with `old_structure_cmd false`).
The names in `fields` are the standard fields of `struct_n`. -/
meta def subobject_names (struct_n : name) : tactic (list name × list name) :=
do env ← get_env,
[c] ← pure $ env.constructors_of struct_n | fail "too many constructors",
vs ← var_names <$> (mk_const c >>= infer_type),
fields ← env.structure_fields struct_n,
return $ fields.partition (λ fn, ↑("_" ++ fn.to_string) ∈ vs)
private meta def expanded_field_list' : name → tactic (dlist $ name × name) | struct_n :=
do (so,fs) ← subobject_names struct_n,
ts ← so.mmap (λ n, do
(_, e) ← mk_const (n.update_prefix struct_n) >>= infer_type >>= mk_local_pis,
expanded_field_list' $ e.get_app_fn.const_name),
return $ dlist.join ts ++ dlist.of_list (fs.map $ prod.mk struct_n)
open functor function
/-- `expanded_field_list struct_n` produces a list of the names of the fields of the structure
named `struct_n`. These are returned as pairs of names `(prefix, name)`, where the full name
of the projection is `prefix.name`. -/
meta def expanded_field_list (struct_n : name) : tactic (list $ name × name) :=
dlist.to_list <$> expanded_field_list' struct_n
/--
Return a list of all type classes which can be instantiated
for the given expression.
-/
meta def get_classes (e : expr) : tactic (list name) :=
attribute.get_instances `class >>= list.mfilter (λ n,
succeeds $ mk_app n [e] >>= mk_instance)
open nat
/-- Create a list of `n` fresh metavariables. -/
meta def mk_mvar_list : ℕ → tactic (list expr)
| 0 := pure []
| (succ n) := (::) <$> mk_mvar <*> mk_mvar_list n
/-- Returns the only goal, or fails if there isn't just one goal. -/
meta def get_goal : tactic expr :=
do gs ← get_goals,
match gs with
| [a] := return a
| [] := fail "there are no goals"
| _ := fail "there are too many goals"
end
/-- `iterate_at_most_on_all_goals n t`: repeat the given tactic at most `n` times on all goals,
or until it fails. Always succeeds. -/
meta def iterate_at_most_on_all_goals : nat → tactic unit → tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := tactic.all_goals' $ (do tac, iterate_at_most_on_all_goals n tac) <|> skip
/-- `iterate_at_most_on_subgoals n t`: repeat the tactic `t` at most `n` times on the first
goal and on all subgoals thus produced, or until it fails. Fails iff `t` fails on
current goal. -/
meta def iterate_at_most_on_subgoals : nat → tactic unit → tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := focus1 (do tac, iterate_at_most_on_all_goals n tac)
/-- `apply_list l`: try to apply the tactics in the list `l` on the first goal, and
fail if none succeeds -/
meta def apply_list_expr : list expr → tactic unit
| [] := fail "no matching rule"
| (h::t) := do interactive.concat_tags (apply h) <|> apply_list_expr t
/-- constructs a list of expressions given a list of p-expressions, as follows:
- if the p-expression is the name of a theorem, use `i_to_expr_for_apply` on it
- if the p-expression is a user attribute, add all the theorems with this attribute
to the list.-/
meta def build_list_expr_for_apply : list pexpr → tactic (list expr)
| [] := return []
| (h::t) := do
tail ← build_list_expr_for_apply t,
a ← i_to_expr_for_apply h,
(do l ← attribute.get_instances (expr.const_name a),
m ← list.mmap mk_const l,
return (m.append tail))
<|> return (a::tail)
/--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times.
Unlike `solve_by_elim`, `apply_rules` does not do any backtracking, and just greedily applies
a lemma from the list until it can't.
-/
meta def apply_rules (hs : list pexpr) (n : nat) : tactic unit :=
do l ← build_list_expr_for_apply hs,
iterate_at_most_on_subgoals n (assumption <|> apply_list_expr l)
/-- `replace h p` elaborates the pexpr `p`, clears the existing hypothesis named `h` from the local
context, and adds a new hypothesis named `h`. The type of this hypothesis is the type of `p`.
Fails if there is nothing named `h` in the local context. -/
meta def replace (h : name) (p : pexpr) : tactic unit :=
do h' ← get_local h,
p ← to_expr p,
note h none p,
clear h'
/-- Auxiliary function for `iff_mp` and `iff_mpr`. Takes a name, which should be either `` `iff.mp``
or `` `iff.mpr``. If the passed expression is an iterated function type eventually producing an
`iff`, returns an expression with the `iff` converted to either the forwards or backwards
implication, as requested. -/
meta def mk_iff_mp_app (iffmp : name) : expr → (nat → expr) → option expr
| (expr.pi n bi e t) f := expr.lam n bi e <$> mk_iff_mp_app t (λ n, f (n+1) (expr.var n))
| `(%%a ↔ %%b) f := some $ @expr.const tt iffmp [] a b (f 0)
| _ f := none
/-- `iff_mp_core e ty` assumes that `ty` is the type of `e`.
If `ty` has the shape `Π ..., A ↔ B`, returns an expression whose type is `Π ..., A → B`. -/
meta def iff_mp_core (e ty: expr) : option expr :=
mk_iff_mp_app `iff.mp ty (λ_, e)
/-- `iff_mpr_core e ty` assumes that `ty` is the type of `e`.
If `ty` has the shape `Π ..., A ↔ B`, returns an expression whose type is `Π ..., B → A`. -/
meta def iff_mpr_core (e ty: expr) : option expr :=
mk_iff_mp_app `iff.mpr ty (λ_, e)
/-- Given an expression whose type is (a possibly iterated function producing) an `iff`,
create the expression which is the forward implication. -/
meta def iff_mp (e : expr) : tactic expr :=
do t ← infer_type e,
iff_mp_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`"
/-- Given an expression whose type is (a possibly iterated function producing) an `iff`,
create the expression which is the reverse implication. -/
meta def iff_mpr (e : expr) : tactic expr :=
do t ← infer_type e,
iff_mpr_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`"
/--
Attempts to apply `e`, and if that fails, if `e` is an `iff`,
try applying both directions separately.
-/
meta def apply_iff (e : expr) : tactic (list (name × expr)) :=
let ap e := tactic.apply e {new_goals := new_goals.non_dep_only} in
ap e <|> (iff_mp e >>= ap) <|> (iff_mpr e >>= ap)
/--
Configuration options for `apply_any`:
* `use_symmetry`: if `apply_any` fails to apply any lemma, call `symmetry` and try again.
* `use_exfalso`: if `apply_any` fails to apply any lemma, call `exfalso` and try again.
* `apply`: specify an alternative to `tactic.apply`; usually `apply := tactic.eapply`.
-/
meta structure apply_any_opt :=
(use_symmetry : bool := tt)
(use_exfalso : bool := tt)
(apply : expr → tactic (list (name × expr)) := tactic.apply)
/--
This is a version of `apply_any` that takes a list of `tactic expr`s instead of `expr`s,
and evaluates these as thunks before trying to apply them.
We need to do this to avoid metavariables getting stuck during subsequent rounds of `apply`.
-/
meta def apply_any_thunk
(lemmas : list (tactic expr))
(opt : apply_any_opt := {})
(tac : tactic unit := skip) : tactic unit :=
do
let modes := [skip]
++ (if opt.use_symmetry then [symmetry] else [])
++ (if opt.use_exfalso then [exfalso] else []),
modes.any_of (λ m, do m,
lemmas.any_of (λ H, H >>= opt.apply >> tac)) <|>
fail "apply_any tactic failed; no lemma could be applied"
/--
`apply_any lemmas` tries to apply one of the list `lemmas` to the current goal.
`apply_any lemmas opt` allows control over how lemmas are applied.
`opt` has fields:
* `use_symmetry`: if no lemma applies, call `symmetry` and try again. (Defaults to `tt`.)
* `use_exfalso`: if no lemma applies, call `exfalso` and try again. (Defaults to `tt`.)
* `apply`: use a tactic other than `tactic.apply` (e.g. `tactic.fapply` or `tactic.eapply`).
`apply_any lemmas tac` calls the tactic `tac` after a successful application.
Defaults to `skip`. This is used, for example, by `solve_by_elim` to arrange
recursive invocations of `apply_any`.
-/
meta def apply_any
(lemmas : list expr)
(opt : apply_any_opt := {})
(tac : tactic unit := skip) : tactic unit :=
apply_any_thunk (lemmas.map pure) opt tac
/-- Try to apply a hypothesis from the local context to the goal. -/
meta def apply_assumption : tactic unit :=
local_context >>= apply_any
/-- `change_core e none` is equivalent to `change e`. It tries to change the goal to `e` and fails
if this is not a definitional equality.
`change_core e (some h)` assumes `h` is a local constant, and tries to change the type of `h` to `e`
by reverting `h`, changing the goal, and reintroducing hypotheses. -/
meta def change_core (e : expr) : option expr → tactic unit
| none := tactic.change e
| (some h) :=
do num_reverted : ℕ ← revert h,
expr.pi n bi d b ← target,
tactic.change $ expr.pi n bi e b,
intron num_reverted
/--
`change_with_at olde newe hyp` replaces occurences of `olde` with `newe` at hypothesis `hyp`,
assuming `olde` and `newe` are defeq when elaborated.
-/
meta def change_with_at (olde newe : pexpr) (hyp : name) : tactic unit :=
do h ← get_local hyp,
tp ← infer_type h,
olde ← to_expr olde, newe ← to_expr newe,
let repl_tp := tp.replace (λ a n, if a = olde then some newe else none),
change_core repl_tp (some h)
/-- Returns a list of all metavariables in the current partial proof. This can differ from
the list of goals, since the goals can be manually edited. -/
meta def metavariables : tactic (list expr) :=
expr.list_meta_vars <$> result
/-- Fail if the target contains a metavariable. -/
meta def no_mvars_in_target : tactic unit :=
expr.has_meta_var <$> target >>= guardb ∘ bnot
/-- Succeeds only if the current goal is a proposition. -/
meta def propositional_goal : tactic unit :=
do g :: _ ← get_goals,
is_proof g >>= guardb
/-- Succeeds only if we can construct an instance showing the
current goal is a subsingleton type. -/
meta def subsingleton_goal : tactic unit :=
do g :: _ ← get_goals,
ty ← infer_type g >>= instantiate_mvars,
to_expr ``(subsingleton %%ty) >>= mk_instance >> skip
/--
Succeeds only if the current goal is "terminal",
in the sense that no other goals depend on it
(except possibly through shared metavariables; see `independent_goal`).
-/
meta def terminal_goal : tactic unit :=
propositional_goal <|> subsingleton_goal <|>
do g₀ :: _ ← get_goals,
mvars ← (λ L, list.erase L g₀) <$> metavariables,
mvars.mmap' $ λ g, do
t ← infer_type g >>= instantiate_mvars,
d ← kdepends_on t g₀,
monad.whenb d $
pp t >>= λ s, fail ("The current goal is not terminal: " ++ s.to_string ++ " depends on it.")
/--
Succeeds only if the current goal is "independent", in the sense
that no other goals depend on it, even through shared meta-variables.
-/
meta def independent_goal : tactic unit :=
no_mvars_in_target >> terminal_goal
/-- `triv'` tries to close the first goal with the proof `trivial : true`. Unlike `triv`,
it only unfolds reducible definitions, so it sometimes fails faster. -/
meta def triv' : tactic unit := do c ← mk_const `trivial, exact c reducible
variable {α : Type}
/-- Apply a tactic as many times as possible, collecting the results in a list.
Fail if the tactic does not succeed at least once. -/
meta def iterate1 (t : tactic α) : tactic (list α) :=
do r ← decorate_ex "iterate1 failed: tactic did not succeed" t,
L ← iterate t,
return (r :: L)
/-- Introduces one or more variables and returns the new local constants.
Fails if `intro` cannot be applied. -/
meta def intros1 : tactic (list expr) :=
iterate1 intro1
/-- Run a tactic "under binders", by running `intros` before, and `revert` afterwards. -/
meta def under_binders {α : Type} (t : tactic α) : tactic α :=
do
v ← intros,
r ← t,
revert_lst v,
return r
namespace interactive
/-- Run a tactic "under binders", by running `intros` before, and `revert` afterwards. -/
meta def under_binders (i : itactic) : itactic := tactic.under_binders i
end interactive
/-- `successes` invokes each tactic in turn, returning the list of successful results. -/
meta def successes (tactics : list (tactic α)) : tactic (list α) :=
list.filter_map id <$> monad.sequence (tactics.map (λ t, try_core t))
/--
Try all the tactics in a list, each time starting at the original `tactic_state`,
returning the list of successful results,
and reverting to the original `tactic_state`.
-/
-- Note this is not the same as `successes`, which keeps track of the evolving `tactic_state`.
meta def try_all {α : Type} (tactics : list (tactic α)) : tactic (list α) :=
λ s, result.success
(tactics.map $
λ t : tactic α,
match t s with
| result.success a s' := [a]
| _ := []
end).join s
/--
Try all the tactics in a list, each time starting at the original `tactic_state`,
returning the list of successful results sorted by
the value produced by a subsequent execution of the `sort_by` tactic,
and reverting to the original `tactic_state`.
-/
meta def try_all_sorted {α : Type} (tactics : list (tactic α)) (sort_by : tactic ℕ := num_goals) :
tactic (list (α × ℕ)) :=
λ s, result.success
((tactics.map $
λ t : tactic α,
match (do a ← t, n ← sort_by, return (a, n)) s with
| result.success a s' := [a]
| _ := []
end).join.qsort (λ p q : α × ℕ, p.2 < q.2)) s
/-- Return target after instantiating metavars and whnf. -/
private meta def target' : tactic expr :=
target >>= instantiate_mvars >>= whnf
/--
Just like `split`, `fsplit` applies the constructor when the type of the target is
an inductive data type with one constructor.
However it does not reorder goals or invoke `auto_param` tactics.
-/
-- FIXME check if we can remove `auto_param := ff`
meta def fsplit : tactic unit :=
do [c] ← target' >>= get_constructors_for |
fail "fsplit tactic failed, target is not an inductive datatype with only one constructor",
mk_const c >>= λ e, apply e {new_goals := new_goals.all, auto_param := ff} >> skip
run_cmd add_interactive [`fsplit]
add_tactic_doc
{ name := "fsplit",
category := doc_category.tactic,
decl_names := [`tactic.interactive.fsplit],
tags := ["logic", "goal management"] }
/-- Calls `injection` on each hypothesis, and then, for each hypothesis on which `injection`
succeeds, clears the old hypothesis. -/
meta def injections_and_clear : tactic unit :=
do l ← local_context,
results ← successes $ l.map $ λ e, injection e >> clear e,
when (results.empty) (fail "could not use `injection` then `clear` on any hypothesis")
run_cmd add_interactive [`injections_and_clear]
add_tactic_doc
{ name := "injections_and_clear",
category := doc_category.tactic,
decl_names := [`tactic.interactive.injections_and_clear],
tags := ["context management"] }
/-- Calls `cases` on every local hypothesis, succeeding if
it succeeds on at least one hypothesis. -/
meta def case_bash : tactic unit :=
do l ← local_context,
r ← successes (l.reverse.map (λ h, cases h >> skip)),
when (r.empty) failed
/--
`note_anon t v`, given a proof `v : t`,
adds `h : t` to the current context, where the name `h` is fresh.
`note_anon none v` will infer the type `t` from `v`.
-/
-- While `note` provides a default value for `t`, it doesn't seem this could ever be used.
meta def note_anon (t : option expr) (v : expr) : tactic expr :=
do h ← get_unused_name `h none,
note h t v
/-- `find_local t` returns a local constant with type t, or fails if none exists. -/
meta def find_local (t : pexpr) : tactic expr :=
do t' ← to_expr t,
(prod.snd <$> solve_aux t' assumption >>= instantiate_mvars) <|>
fail format!"No hypothesis found of the form: {t'}"
/-- `dependent_pose_core l`: introduce dependent hypotheses, where the proofs depend on the values
of the previous local constants. `l` is a list of local constants and their values. -/
meta def dependent_pose_core (l : list (expr × expr)) : tactic unit := do
let lc := l.map prod.fst,
let lm := l.map (λ⟨l, v⟩, (l.local_uniq_name, v)),
t ← target,
new_goal ← mk_meta_var (t.pis lc),
old::other_goals ← get_goals,
set_goals (old :: new_goal :: other_goals),
exact ((new_goal.mk_app lc).instantiate_locals lm),
return ()
/-- Like `mk_local_pis` but translating into weak head normal form before checking if it is a `Π`.
-/
meta def mk_local_pis_whnf : expr → tactic (list expr × expr) | e := do
(expr.pi n bi d b) ← whnf e | return ([], e),
p ← mk_local' n bi d,
(ps, r) ← mk_local_pis (expr.instantiate_var b p),
return ((p :: ps), r)
/-- Changes `(h : ∀xs, ∃a:α, p a) ⊢ g` to `(d : ∀xs, a) (s : ∀xs, p (d xs) ⊢ g`. -/
meta def choose1 (h : expr) (data : name) (spec : name) : tactic expr := do
t ← infer_type h,
(ctxt, t) ← mk_local_pis_whnf t,
`(@Exists %%α %%p) ← whnf t transparency.all |
fail "expected a term of the shape ∀xs, ∃a, p xs a",
α_t ← infer_type α,
expr.sort u ← whnf α_t transparency.all,
value ← mk_local_def data (α.pis ctxt),
t' ← head_beta (p.app (value.mk_app ctxt)),
spec ← mk_local_def spec (t'.pis ctxt),
dependent_pose_core [
(value, ((((expr.const `classical.some [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt),
(spec, ((((expr.const `classical.some_spec [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt)],
try (tactic.clear h),
intro1,
intro1
/-- Changes `(h : ∀xs, ∃as, p as) ⊢ g` to a list of functions `as`,
and a final hypothesis on `p as`. -/
meta def choose : expr → list name → tactic unit
| h [] := fail "expect list of variables"
| h [n] := do
cnt ← revert h,
intro n,
intron (cnt - 1),
return ()
| h (n::ns) := do
v ← get_unused_name >>= choose1 h n,
choose v ns
/--
Instantiates metavariables that appear in the current goal.
-/
meta def instantiate_mvars_in_target : tactic unit :=
target >>= instantiate_mvars >>= change
/--
Instantiates metavariables in all goals.
-/
meta def instantiate_mvars_in_goals : tactic unit :=
all_goals' $ instantiate_mvars_in_target
/-- This makes sure that the execution of the tactic does not change the tactic state.
This can be helpful while using rewrite, apply, or expr munging.
Remember to instantiate your metavariables before you're done! -/
meta def lock_tactic_state {α} (t : tactic α) : tactic α
| s := match t s with
| result.success a s' := result.success a s
| result.exception msg pos s' := result.exception msg pos s
end
/-- Similar to `mk_local_pis` but make meta variables instead of
local constants. -/
meta def mk_meta_pis : expr → tactic (list expr × expr)
| (expr.pi n bi d b) := do
p ← mk_meta_var d,
(ps, r) ← mk_meta_pis (expr.instantiate_var b p),
return ((p :: ps), r)
| e := return ([], e)
/-- Protect the declaration `n` -/
meta def mk_protected (n : name) : tactic unit :=
do env ← get_env, set_env (env.mk_protected n)
end tactic
namespace lean.parser
open tactic interaction_monad
/-- `emit_command_here str` behaves as if the string `str` were placed as a user command at the
current line. -/
meta def emit_command_here (str : string) : lean.parser string :=
do (_, left) ← with_input command_like str,
return left
/-- `emit_code_here str` behaves as if the string `str` were placed at the current location in
source code. -/
meta def emit_code_here : string → lean.parser unit
| str := do left ← emit_command_here str,
if left.length = 0 then return ()
else emit_code_here left
/-- `get_current_namespace` returns the current namespace (it could be `name.anonymous`).
This function deserves a C++ implementation in core lean, and will fail if it is not called from
the body of a command (i.e. anywhere else that the `lean.parser` monad can be invoked). -/
meta def get_current_namespace : lean.parser name :=
do n ← tactic.mk_user_fresh_name,
emit_code_here $ sformat!"def {n} := ()",
nfull ← tactic.resolve_constant n,
return $ nfull.get_nth_prefix n.components.length
/-- `get_variables` returns a list of existing variable names, along with their types and binder
info. -/
meta def get_variables : lean.parser (list (name × binder_info × expr)) :=
list.map expr.get_local_const_kind <$> list_available_include_vars
/-- `get_included_variables` returns those variables `v` returned by `get_variables` which have been
"included" by an `include v` statement and are not (yet) `omit`ed. -/
meta def get_included_variables : lean.parser (list (name × binder_info × expr)) :=
do ns ← list_include_var_names,
list.filter (λ v, v.1 ∈ ns) <$> get_variables
/-- From the `lean.parser` monad, synthesize a `tactic_state` which includes all of the local
variables referenced in `es : list pexpr`, and those variables which have been `include`ed in the
local context---precisely those variables which would be ambiently accessible if we were in a
tactic-mode block where the goals had types `es.mmap to_expr`, for example.
Returns a new `ts : tactic_state` with these local variables added, and
`mappings : list (expr × expr)`, for which pairs `(var, hyp)` correspond to an existing variable
`var` and the local hypothesis `hyp` which was added to the tactic state `ts` as a result. -/
meta def synthesize_tactic_state_with_variables_as_hyps (es : list pexpr)
: lean.parser (tactic_state × list (expr × expr)) :=
do /- First, in order to get `to_expr e` to resolve declared `variables`, we add all of the
declared variables to a fake `tactic_state`, and perform the resolution. At the end,
`to_expr e` has done the work of determining which variables were actually referenced, which
we then obtain from `fe` via `expr.list_local_consts` (which, importantly, is not defined for
`pexpr`s). -/
vars ← list_available_include_vars,
fake_es ← lean.parser.of_tactic $ lock_tactic_state $ do {
/- Note that `add_local_consts_as_local_hyps` returns the mappings it generated, but we discard
them on this first pass. (We return the mappings generated by our second invocation of this
function below.) -/
add_local_consts_as_local_hyps vars,
es.mmap to_expr
},
/- Now calculate lists of a) the explicitly `include`ed variables and b) the variables which were
referenced in `e` when it was resolved to `fake_e`.
It is important that we include variables of the kind a) because we want `simp` to have access
to declared local instances, and it is important that we only restrict to variables of kind a)
and b) together since we do not to recognise a hypothesis which is posited as a `variable`
in the environment but not referenced in the `pexpr` we were passed.
One use case for this behaviour is running `simp` on the passed `pexpr`, since we do not want
simp to use arbitrary hypotheses which were declared as `variables` in the local environment
but not referenced in the expression to simplify (as one would be expect generally in tactic
mode). -/
included_vars ← list_include_var_names,
let referenced_vars := list.join $ fake_es.map $ λ e, e.list_local_consts.map expr.local_pp_name,
/- Look up the explicit `included_vars` and the `referenced_vars` (which have appeared in the
`pexpr` list which we were passed.) -/
let directly_included_vars := vars.filter $ λ var,
(var.local_pp_name ∈ included_vars) ∨ (var.local_pp_name ∈ referenced_vars),
/- Inflate the list `directly_included_vars` to include those variables which are "implicitly
included" by virtue of reference to one or multiple others. For example, given
`variables (n : ℕ) [prime n] [ih : even n]`, a reference to `n` implies that the typeclass
instance `prime n` should be included, but `ih : even n` should not. -/
let all_implicitly_included_vars :=
expr.all_implicitly_included_variables vars directly_included_vars,
/- Capture a tactic state where both of these kinds of variables have been added as local
hypotheses, and resolve `e` against this state with `to_expr`, this time for real. -/
lean.parser.of_tactic $ do {
mappings ← add_local_consts_as_local_hyps all_implicitly_included_vars,
ts ← get_state,
return (ts, mappings)
}
end lean.parser
namespace tactic
variables {α : Type}
/--
Hole command used to fill in a structure's field when specifying an instance.
In the following:
```lean
instance : monad id :=
{! !}
```
invoking the hole command "Instance Stub" ("Generate a skeleton for the structure under
construction.") produces:
```lean
instance : monad id :=
{ map := _,
map_const := _,
pure := _,
seq := _,
seq_left := _,
seq_right := _,
bind := _ }
```
-/
@[hole_command] meta def instance_stub : hole_command :=
{ name := "Instance Stub",
descr := "Generate a skeleton for the structure under construction.",
action := λ _,
do tgt ← target >>= whnf,
let cl := tgt.get_app_fn.const_name,
env ← get_env,
fs ← expanded_field_list cl,
let fs := fs.map prod.snd,
let fs := format.intercalate (",\n " : format) $ fs.map (λ fn, format!"{fn} := _"),
let out := format.to_string format!"{{ {fs} }",
return [(out,"")] }
add_tactic_doc
{ name := "instance_stub",
category := doc_category.hole_cmd,
decl_names := [`tactic.instance_stub],
tags := ["instances"] }
/-- Like `resolve_name` except when the list of goals is
empty. In that situation `resolve_name` fails whereas
`resolve_name'` simply proceeds on a dummy goal -/
meta def resolve_name' (n : name) : tactic pexpr :=
do [] ← get_goals | resolve_name n,
g ← mk_mvar,
set_goals [g],
resolve_name n <* set_goals []
private meta def strip_prefix' (n : name) : list string → name → tactic name
| s name.anonymous := pure $ s.foldl (flip name.mk_string) name.anonymous
| s (name.mk_string a p) :=
do let n' := s.foldl (flip name.mk_string) name.anonymous,
do { n'' ← tactic.resolve_constant n',
if n'' = n
then pure n'
else strip_prefix' (a :: s) p }
<|> strip_prefix' (a :: s) p
| s n@(name.mk_numeral a p) := pure $ s.foldl (flip name.mk_string) n
/-- Strips unnecessary prefixes from a name, e.g. if a namespace is open. -/
meta def strip_prefix : name → tactic name
| n@(name.mk_string a a_1) :=
if (`_private).is_prefix_of n
then let n' := n.update_prefix name.anonymous in
n' <$ resolve_name' n' <|> pure n
else strip_prefix' n [a] a_1
| n := pure n
/-- Used to format return strings for the hole commands `match_stub` and `eqn_stub`. -/
meta def mk_patterns (t : expr) : tactic (list format) :=
do let cl := t.get_app_fn.const_name,
env ← get_env,
let fs := env.constructors_of cl,
fs.mmap $ λ f,
do { (vs,_) ← mk_const f >>= infer_type >>= mk_local_pis,
let vs := vs.filter (λ v, v.is_default_local),
vs ← vs.mmap (λ v,
do v' ← get_unused_name v.local_pp_name,
pose v' none `(()),
pure v' ),
vs.mmap' $ λ v, get_local v >>= clear,
let args := list.intersperse (" " : format) $ vs.map to_fmt,
f ← strip_prefix f,
if args.empty
then pure $ format!"| {f} := _\n"
else pure format!"| ({f} {format.join args}) := _\n" }
/--
Hole command used to generate a `match` expression.
In the following:
```lean
meta def foo (e : expr) : tactic unit :=
{! e !}
```
invoking hole command "Match Stub" ("Generate a list of equations for a `match` expression")
produces:
```lean
meta def foo (e : expr) : tactic unit :=
match e with
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
end
```
-/
@[hole_command] meta def match_stub : hole_command :=
{ name := "Match Stub",
descr := "Generate a list of equations for a `match` expression.",
action := λ es,
do [e] ← pure es | fail "expecting one expression",
e ← to_expr e,
t ← infer_type e >>= whnf,
fs ← mk_patterns t,
e ← pp e,
let out := format.to_string format!"match {e} with\n{format.join fs}end\n",
return [(out,"")] }
add_tactic_doc
{ name := "Match Stub",
category := doc_category.hole_cmd,
decl_names := [`tactic.match_stub],
tags := ["pattern matching"] }
/--
Invoking hole command "Equations Stub" ("Generate a list of equations for a recursive definition")
in the following:
```lean
meta def foo : {! expr → tactic unit !} -- `:=` is omitted
```
produces:
```lean
meta def foo : expr → tactic unit
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
A similar result can be obtained by invoking "Equations Stub" on the following:
```lean
meta def foo : expr → tactic unit := -- do not forget to write `:=`!!
{! !}
```
```lean
meta def foo : expr → tactic unit := -- don't forget to erase `:=`!!
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
-/
@[hole_command] meta def eqn_stub : hole_command :=
{ name := "Equations Stub",
descr := "Generate a list of equations for a recursive definition.",
action := λ es,
do t ← match es with
| [t] := to_expr t
| [] := target
| _ := fail "expecting one type"
end,
e ← whnf t,
(v :: _,_) ← mk_local_pis e | fail "expecting a Pi-type",
t' ← infer_type v,
fs ← mk_patterns t',
t ← pp t,
let out :=
if es.empty then
format.to_string format!"-- do not forget to erase `:=`!!\n{format.join fs}"
else format.to_string format!"{t}\n{format.join fs}",
return [(out,"")] }
add_tactic_doc
{ name := "Equations Stub",
category := doc_category.hole_cmd,
decl_names := [`tactic.eqn_stub],
tags := ["pattern matching"] }
/--
This command lists the constructors that can be used to satisfy the expected type.
Invoking "List Constructors" ("Show the list of constructors of the expected type")
in the following hole:
```lean
def foo : ℤ ⊕ ℕ :=
{! !}
```
produces:
```lean
def foo : ℤ ⊕ ℕ :=
{! sum.inl, sum.inr !}
```
and will display:
```lean
sum.inl : ℤ → ℤ ⊕ ℕ
sum.inr : ℕ → ℤ ⊕ ℕ
```
-/
@[hole_command] meta def list_constructors_hole : hole_command :=
{ name := "List Constructors",
descr := "Show the list of constructors of the expected type.",
action := λ es,
do t ← target >>= whnf,
(_,t) ← mk_local_pis t,
let cl := t.get_app_fn.const_name,
let args := t.get_app_args,
env ← get_env,
let cs := env.constructors_of cl,
ts ← cs.mmap $ λ c,
do { e ← mk_const c,
t ← infer_type (e.mk_app args) >>= pp,
c ← strip_prefix c,
pure format!"\n{c} : {t}\n" },
fs ← format.intercalate ", " <$> cs.mmap (strip_prefix >=> pure ∘ to_fmt),
let out := format.to_string format!"{{! {fs} !}",
trace (format.join ts).to_string,
return [(out,"")] }
add_tactic_doc
{ name := "List Constructors",
category := doc_category.hole_cmd,
decl_names := [`tactic.list_constructors_hole],
tags := ["goal information"] }
/-- Makes the declaration `classical.prop_decidable` available to type class inference.
This asserts that all propositions are decidable, but does not have computational content. -/
meta def classical : tactic unit :=
do h ← get_unused_name `_inst,
mk_const `classical.prop_decidable >>= note h none,
reset_instance_cache
open expr
/-- `mk_comp v e` checks whether `e` is a sequence of nested applications `f (g (h v))`, and if so,
returns the expression `f ∘ g ∘ h`. -/
meta def mk_comp (v : expr) : expr → tactic expr
| (app f e) :=
if e = v then pure f
else do
guard (¬ v.occurs f) <|> fail "bad guard",
e' ← mk_comp e >>= instantiate_mvars,
f ← instantiate_mvars f,
mk_mapp ``function.comp [none,none,none,f,e']
| e :=
do guard (e = v),
t ← infer_type e,
mk_mapp ``id [t]
/--
From a lemma of the shape `∀ x, f (g x) = h x`
derive an auxiliary lemma of the form `f ∘ g = h`
for reasoning about higher-order functions.
-/
meta def mk_higher_order_type : expr → tactic expr
| (pi n bi d b@(pi _ _ _ _)) :=
do v ← mk_local_def n d,
let b' := (b.instantiate_var v),
(pi n bi d ∘ flip abstract_local v.local_uniq_name) <$> mk_higher_order_type b'
| (pi n bi d b) :=
do v ← mk_local_def n d,
let b' := (b.instantiate_var v),
(l,r) ← match_eq b' <|> fail format!"not an equality {b'}",
l' ← mk_comp v l,
r' ← mk_comp v r,
mk_app ``eq [l',r']
| e := failed
open lean.parser interactive.types
/-- A user attribute that applies to lemmas of the shape `∀ x, f (g x) = h x`.
It derives an auxiliary lemma of the form `f ∘ g = h` for reasoning about higher-order functions.
-/
@[user_attribute]
meta def higher_order_attr : user_attribute unit (option name) :=
{ name := `higher_order,
parser := optional ident,
descr :=
"From a lemma of the shape `∀ x, f (g x) = h x` derive an auxiliary lemma of the
form `f ∘ g = h` for reasoning about higher-order functions.",
after_set := some $ λ lmm _ _,
do env ← get_env,
decl ← env.get lmm,
let num := decl.univ_params.length,
let lvls := (list.iota num).map (`l).append_after,
let l : expr := expr.const lmm $ lvls.map level.param,
t ← infer_type l >>= instantiate_mvars,
t' ← mk_higher_order_type t,
(_,pr) ← solve_aux t' $ do {
intros, applyc ``_root_.funext, intro1, applyc lmm; assumption },
pr ← instantiate_mvars pr,
lmm' ← higher_order_attr.get_param lmm,
lmm' ← (flip name.update_prefix lmm.get_prefix <$> lmm') <|> pure lmm.add_prime,
add_decl $ declaration.thm lmm' lvls t' (pure pr),
copy_attribute `simp lmm lmm',
copy_attribute `functor_norm lmm lmm' }
add_tactic_doc
{ name := "higher_order",
category := doc_category.attr,
decl_names := [`tactic.higher_order_attr],
tags := ["lemma derivation"] }
attribute [higher_order map_comp_pure] map_pure
/--
Use `refine` to partially discharge the goal,
or call `fconstructor` and try again.
-/
private meta def use_aux (h : pexpr) : tactic unit :=
(focus1 (refine h >> done)) <|> (fconstructor >> use_aux)
/-- Similar to `existsi`, `use l` will use entries in `l` to instantiate existential obligations
at the beginning of a target. Unlike `existsi`, the pexprs in `l` are elaborated with respect to
the expected type.
```lean
example : ∃ x : ℤ, x = x :=
by tactic.use ``(42)
```
See the doc string for `tactic.interactive.use` for more information.
-/
protected meta def use (l : list pexpr) : tactic unit :=
focus1 $ seq' (l.mmap' $ λ h, use_aux h <|> fail format!"failed to instantiate goal with {h}")
instantiate_mvars_in_target
/-- `clear_aux_decl_aux l` clears all expressions in `l` that represent aux decls from the
local context. -/
meta def clear_aux_decl_aux : list expr → tactic unit
| [] := skip
| (e::l) := do cond e.is_aux_decl (tactic.clear e) skip, clear_aux_decl_aux l
/-- `clear_aux_decl` clears all expressions from the local context that represent aux decls. -/
meta def clear_aux_decl : tactic unit :=
local_context >>= clear_aux_decl_aux
/-- `apply_at_aux e et [] h ht` (with `et` the type of `e` and `ht` the type of `h`)
finds a list of expressions `vs` and returns `(e.mk_args (vs ++ [h]), vs)`. -/
meta def apply_at_aux (arg t : expr) : list expr → expr → expr → tactic (expr × list expr)
| vs e (pi n bi d b) :=
do { v ← mk_meta_var d,
apply_at_aux (v :: vs) (e v) (b.instantiate_var v) } <|>
(e arg, vs) <$ unify d t
| vs e _ := failed
/-- `apply_at e h` applies implication `e` on hypothesis `h` and replaces `h` with the result. -/
meta def apply_at (e h : expr) : tactic unit :=
do ht ← infer_type h,
et ← infer_type e,
(h', gs') ← apply_at_aux h ht [] e et,
note h.local_pp_name none h',
clear h,
gs' ← gs'.mfilter is_assigned,
(g :: gs) ← get_goals,
set_goals (g :: gs' ++ gs)
/-- `symmetry_hyp h` applies `symmetry` on hypothesis `h`. -/
meta def symmetry_hyp (h : expr) (md := semireducible) : tactic unit :=
do tgt ← infer_type h,
env ← get_env,
let r := get_app_fn tgt,
match env.symm_for (const_name r) with
| (some symm) := do s ← mk_const symm,
apply_at s h
| none := fail "symmetry tactic failed, target is not a relation application with the expected property."
end
precedence `setup_tactic_parser`:0
/-- `setup_tactic_parser` is a user command that opens the namespaces used in writing
interactive tactics, and declares the local postfix notation `?` for `optional` and `*` for `many`.
It does *not* use the `namespace` command, so it will typically be used after
`namespace tactic.interactive`.
-/
@[user_command]
meta def setup_tactic_parser_cmd (_ : interactive.parse $ tk "setup_tactic_parser") :
lean.parser unit :=
emit_code_here "
open lean
open lean.parser
open interactive interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many .
"
/-- `finally tac finalizer` runs `tac` first, then runs `finalizer` even if
`tac` fails. `finally tac finalizer` fails if either `tac` or `finalizer` fails. -/
meta def finally {β} (tac : tactic α) (finalizer : tactic β) : tactic α :=
λ s, match tac s with
| (result.success r s') := (finalizer >> pure r) s'
| (result.exception msg p s') := (finalizer >> result.exception msg p) s'
end
/--
`on_exception handler tac` runs `tac` first, and then runs `handler` only if `tac` failed.
-/
meta def on_exception {β} (handler : tactic β) (tac : tactic α) : tactic α | s :=
match tac s with
| result.exception msg p s' := (handler *> result.exception msg p) s'
| ok := ok
end
/-- `decorate_error add_msg tac` prepends `add_msg` to an exception produced by `tac` -/
meta def decorate_error (add_msg : string) (tac : tactic α) : tactic α | s :=
match tac s with
| result.exception msg p s :=
let msg (_ : unit) : format := match msg with
| some msg := add_msg ++ format.line ++ msg ()
| none := add_msg
end in
result.exception msg p s
| ok := ok
end
/-- Applies tactic `t`. If it succeeds, revert the state, and return the value. If it fails,
returns the error message. -/
meta def retrieve_or_report_error {α : Type u} (t : tactic α) : tactic (α ⊕ string) :=
λ s, match t s with
| (interaction_monad.result.success a s') := result.success (sum.inl a) s
| (interaction_monad.result.exception msg' _ s') :=
result.success (sum.inr (msg'.iget ()).to_string) s
end
/-- This tactic succeeds if `t` succeeds or fails with message `msg` such that `p msg` is `tt`.
-/
meta def succeeds_or_fails_with_msg {α : Type} (t : tactic α) (p : string → bool) : tactic unit :=
do x ← retrieve_or_report_error t,
match x with
| (sum.inl _) := skip
| (sum.inr msg) := if p msg then skip else fail msg
end
add_tactic_doc
{ name := "setup_tactic_parser",
category := doc_category.cmd,
decl_names := [`tactic.setup_tactic_parser_cmd],
tags := ["parsing", "notation"] }
/-- `trace_error msg t` executes the tactic `t`. If `t` fails, traces `msg` and the failure message
of `t`. -/
meta def trace_error (msg : string) (t : tactic α) : tactic α
| s := match t s with
| (result.success r s') := result.success r s'
| (result.exception (some msg') p s') := (trace msg >> trace (msg' ()) >> result.exception (some msg') p) s'
| (result.exception none p s') := result.exception none p s'
end
/--
``trace_if_enabled `n msg`` traces the message `msg`
only if tracing is enabled for the name `n`.
Create new names registered for tracing with `declare_trace n`.
Then use `set_option trace.n true/false` to enable or disable tracing for `n`.
-/
meta def trace_if_enabled
(n : name) {α : Type u} [has_to_tactic_format α] (msg : α) : tactic unit :=
when_tracing n (trace msg)
/--
``trace_state_if_enabled `n msg`` prints the tactic state,
preceded by the optional string `msg`,
only if tracing is enabled for the name `n`.
-/
meta def trace_state_if_enabled
(n : name) (msg : string := "") : tactic unit :=
when_tracing n ((if msg = "" then skip else trace msg) >> trace_state)
/--
This combinator is for testing purposes. It succeeds if `t` fails with message `msg`,
and fails otherwise.
-/
meta def success_if_fail_with_msg {α : Type u} (t : tactic α) (msg : string) : tactic unit :=
λ s, match t s with
| (interaction_monad.result.exception msg' _ s') :=
let expected_msg := (msg'.iget ()).to_string in
if msg = expected_msg then result.success () s
else mk_exception format!"failure messages didn't match. Expected:\n{expected_msg}" none s
| (interaction_monad.result.success a s) :=
mk_exception "success_if_fail_with_msg combinator failed, given tactic succeeded" none s
end
/-- `with_local_goals gs tac` runs `tac` on the goals `gs` and then restores the
initial goals and returns the goals `tac` ended on. -/
meta def with_local_goals {α} (gs : list expr) (tac : tactic α) : tactic (α × list expr) :=
do gs' ← get_goals,
set_goals gs,
finally (prod.mk <$> tac <*> get_goals) (set_goals gs')
/-- like `with_local_goals` but discards the resulting goals -/
meta def with_local_goals' {α} (gs : list expr) (tac : tactic α) : tactic α :=
prod.fst <$> with_local_goals gs tac
/-- Representation of a proof goal that lends itself to comparison. The
following goal:
```lean
l₀ : T,
l₁ : T
⊢ ∀ v : T, foo
```
is represented as
```
(2, ∀ l₀ l₁ v : T, foo)
```
The number 2 indicates that first the two bound variables of the
`∀` are actually local constant. Comparing two such goals with `=`
rather than `=ₐ` or `is_def_eq` tells us that proof script should
not see the difference between the two.
-/
meta def packaged_goal := ℕ × expr
/-- proof state made of multiple `goal` meant for comparing
the result of running different tactics -/
meta def proof_state := list packaged_goal
meta instance goal.inhabited : inhabited packaged_goal := ⟨(0,var 0)⟩
meta instance proof_state.inhabited : inhabited proof_state :=
(infer_instance : inhabited (list packaged_goal))
/-- create a `packaged_goal` corresponding to the current goal -/
meta def get_packaged_goal : tactic packaged_goal := do
ls ← local_context,
tgt ← target >>= instantiate_mvars,
tgt ← pis ls tgt,
pure (ls.length, tgt)
/-- `goal_of_mvar g`, with `g` a meta variable, creates a
`packaged_goal` corresponding to `g` interpretted as a proof goal -/
meta def goal_of_mvar (g : expr) : tactic packaged_goal :=
with_local_goals' [g] get_packaged_goal
/-- `get_proof_state` lists the user visible goal for each goal
of the current state and for each goal, abstracts all of the
meta variables of the other gaols.
This produces a list of goals in the form of `ℕ × expr` where
the `expr` encodes the following proof state:
```lean
2 goals
l₁ : t₁,
l₂ : t₂,
l₃ : t₃
⊢ tgt₁
⊢ tgt₂
```
as
```lean
[ (3, ∀ (mv : tgt₁) (mv : tgt₂) (l₁ : t₁) (l₂ : t₂) (l₃ : t₃), tgt₁),
(0, ∀ (mv : tgt₁) (mv : tgt₂), tgt₂) ]
```
with 2 goals, the first 2 bound variables encode the meta variable
of all the goals, the next 3 (in the first goal) and 0 (in the second goal)
are the local constants.
This representation allows us to compare goals and proof states while
ignoring information like the unique name of local constants and
the equality or difference of meta variables that encode the same goal.
-/
meta def get_proof_state : tactic proof_state :=
do gs ← get_goals,
gs.mmap $ λ g, do
⟨n,g⟩ ← goal_of_mvar g,
g ← gs.mfoldl (λ g v, do
g ← kabstract g v reducible ff,
pure $ pi `goal binder_info.default `(true) g ) g,
pure (n,g)
/--
Run `tac` in a disposable proof state and return the state.
See `proof_state`, `goal` and `get_proof_state`.
-/
meta def get_proof_state_after (tac : tactic unit) : tactic (option proof_state) :=
try_core $ retrieve $ tac >> get_proof_state
open lean interactive
/-- A type alias for `tactic format`, standing for "pretty print format". -/
meta def pformat := tactic format
/-- `mk` lifts `fmt : format` to the tactic monad (`pformat`). -/
meta def pformat.mk (fmt : format) : pformat := pure fmt
/-- an alias for `pp`. -/
meta def to_pfmt {α} [has_to_tactic_format α] (x : α) : pformat :=
pp x
meta instance pformat.has_to_tactic_format : has_to_tactic_format pformat :=
⟨ id ⟩
meta instance : has_append pformat :=
⟨ λ x y, (++) <$> x <*> y ⟩
meta instance tactic.has_to_tactic_format [has_to_tactic_format α] :
has_to_tactic_format (tactic α) :=
⟨ λ x, x >>= to_pfmt ⟩
private meta def parse_pformat : string → list char → parser pexpr
| acc [] := pure ``(to_pfmt %%(reflect acc))
| acc ('\n'::s) :=
do f ← parse_pformat "" s,
pure ``(to_pfmt %%(reflect acc) ++ pformat.mk format.line ++ %%f)
| acc ('{'::'{'::s) := parse_pformat (acc ++ "{") s
| acc ('{'::s) :=
do (e, s) ← with_input (lean.parser.pexpr 0) s.as_string,
'}'::s ← return s.to_list | fail "'}' expected",
f ← parse_pformat "" s,
pure ``(to_pfmt %%(reflect acc) ++ to_pfmt %%e ++ %%f)
| acc (c::s) := parse_pformat (acc.str c) s
reserve prefix `pformat! `:100
/-- See `format!` in `init/meta/interactive_base.lean`.
The main differences are that `pp` is called instead of `to_fmt` and that we can use
arguments of type `tactic α` in the quotations.
Now, consider the following:
```lean
e ← to_expr ``(3 + 7),
trace format!"{e}" -- outputs `has_add.add.{0} nat nat.has_add (bit1.{0} nat nat.has_one nat.has_add (has_one.one.{0} nat nat.has_one)) ...`
trace pformat!"{e}" -- outputs `3 + 7`
```
The difference is significant. And now, the following is expressible:
```lean
e ← to_expr ``(3 + 7),
trace pformat!"{e} : {infer_type e}" -- outputs `3 + 7 : ℕ`
```
See also: `trace!` and `fail!`
-/
@[user_notation]
meta def pformat_macro (_ : parse $ tk "pformat!") (s : string) : parser pexpr :=
do e ← parse_pformat "" s.to_list,
return ``(%%e : pformat)
reserve prefix `fail! `:100
/--
The combination of `pformat` and `fail`.
-/
@[user_notation]
meta def fail_macro (_ : parse $ tk "fail!") (s : string) : parser pexpr :=
do e ← pformat_macro () s,
pure ``((%%e : pformat) >>= fail)
reserve prefix `trace! `:100
/--
The combination of `pformat` and `fail`.
-/
@[user_notation]
meta def trace_macro (_ : parse $ tk "trace!") (s : string) : parser pexpr :=
do e ← pformat_macro () s,
pure ``((%%e : pformat) >>= trace)
/-- A hackish way to get the `src` directory of mathlib. -/
meta def get_mathlib_dir : tactic string :=
do e ← get_env,
s ← e.decl_olean `tactic.reset_instance_cache,
return $ s.popn_back 17
/-- Checks whether a declaration with the given name is declared in mathlib.
If you want to run this tactic many times, you should use `environment.is_prefix_of_file` instead,
since it is expensive to execute `get_mathlib_dir` many times. -/
meta def is_in_mathlib (n : name) : tactic bool :=
do ml ← get_mathlib_dir, e ← get_env, return $ e.is_prefix_of_file ml n
/--
Runs a tactic by name.
If it is a `tactic string`, return whatever string it returns.
If it is a `tactic unit`, return the name.
(This is mostly used in invoking "self-reporting tactics", e.g. by `tidy` and `hint`.)
-/
meta def name_to_tactic (n : name) : tactic string :=
do d ← get_decl n,
e ← mk_const n,
let t := d.type,
if (t =ₐ `(tactic unit)) then
(eval_expr (tactic unit) e) >>= (λ t, t >> (name.to_string <$> strip_prefix n))
else if (t =ₐ `(tactic string)) then
(eval_expr (tactic string) e) >>= (λ t, t)
else fail!"name_to_tactic cannot take `{n} as input: its type must be `tactic string` or `tactic unit`"
/-- auxiliary function for `apply_under_n_pis` -/
private meta def apply_under_n_pis_aux (func arg : pexpr) : ℕ → ℕ → expr → pexpr
| n 0 _ :=
let vars := ((list.range n).reverse.map (@expr.var ff)),
bd := vars.foldl expr.app arg.mk_explicit in
func bd
| n (k+1) (expr.pi nm bi tp bd) := expr.pi nm bi (pexpr.of_expr tp) (apply_under_n_pis_aux (n+1) k bd)
| n (k+1) t := apply_under_n_pis_aux n 0 t
/--
Assumes `pi_expr` is of the form `Π x1 ... xn xn+1..., _`.
Creates a pexpr of the form `Π x1 ... xn, func (arg x1 ... xn)`.
All arguments (implicit and explicit) to `arg` should be supplied. -/
meta def apply_under_n_pis (func arg : pexpr) (pi_expr : expr) (n : ℕ) : pexpr :=
apply_under_n_pis_aux func arg 0 n pi_expr
/--
Assumes `pi_expr` is of the form `Π x1 ... xn, _`.
Creates a pexpr of the form `Π x1 ... xn, func (arg x1 ... xn)`.
All arguments (implicit and explicit) to `arg` should be supplied. -/
meta def apply_under_pis (func arg : pexpr) (pi_expr : expr) : pexpr :=
apply_under_n_pis func arg pi_expr pi_expr.pi_arity
/--
If `func` is a `pexpr` representing a function that takes an argument `a`,
`get_pexpr_arg_arity_with_tgt func tgt` returns the arity of `a`.
When `tgt` is a `pi` expr, `func` is elaborated in a context
with the domain of `tgt`.
Examples:
* ```get_pexpr_arg_arity ``(ring) `(true)``` returns 0, since `ring` takes one non-function argument.
* ```get_pexpr_arg_arity_with_tgt ``(monad) `(true)``` returns 1, since `monad` takes one argument of type `α → α`.
* ```get_pexpr_arg_arity_with_tgt ``(module R) `(Π (R : Type), comm_ring R → true)``` returns 0
-/
private meta def get_pexpr_arg_arity_with_tgt (func : pexpr) (tgt : expr) : tactic ℕ :=
lock_tactic_state $ do
mv ← mk_mvar,
solve_aux tgt $ intros >> to_expr ``(%%func %%mv),
expr.pi_arity <$> (instantiate_mvars mv >>= infer_type)
/--
Tries to derive instances by unfolding the newly introduced type and applying type class resolution.
For example,
```lean
@[derive ring] def new_int : Type := ℤ
```
adds an instance `ring new_int`, defined to be the instance of `ring ℤ` found by `apply_instance`.
Multiple instances can be added with `@[derive [ring, module ℝ]]`.
This derive handler applies only to declarations made using `def`, and will fail on such a
declaration if it is unable to derive an instance. It is run with higher priority than the built-in
handlers, which will fail on `def`s.
-/
@[derive_handler, priority 2000] meta def delta_instance : derive_handler :=
λ cls new_decl_name,
do env ← get_env,
if env.is_inductive new_decl_name then return ff else
do new_decl ← get_decl new_decl_name,
new_decl_pexpr ← resolve_name new_decl_name,
arity ← get_pexpr_arg_arity_with_tgt cls new_decl.type,
tgt ← to_expr $ apply_under_n_pis cls new_decl_pexpr new_decl.type (new_decl.type.pi_arity - arity),
(_, inst) ← solve_aux tgt
(intros >> reset_instance_cache >> delta_target [new_decl_name] >> apply_instance >> done),
inst ← instantiate_mvars inst,
inst ← replace_univ_metas_with_univ_params inst,
tgt ← instantiate_mvars tgt,
nm ← get_unused_decl_name $ new_decl_name <.>
match cls with
| (expr.const nm _) := nm.last
| _ := "inst"
end,
add_protected_decl $ declaration.defn nm inst.collect_univ_params tgt inst new_decl.reducibility_hints new_decl.is_trusted,
set_basic_attribute `instance nm tt,
return tt
/-- `find_private_decl n none` finds a private declaration named `n` in any of the imported files.
`find_private_decl n (some m)` finds a private declaration named `n` in the same file where a
declaration named `m` can be found. -/
meta def find_private_decl (n : name) (fr : option name) : tactic name :=
do env ← get_env,
fn ← option_t.run (do
fr ← option_t.mk (return fr),
d ← monad_lift $ get_decl fr,
option_t.mk (return $ env.decl_olean d.to_name) ),
let p : string → bool :=
match fn with
| (some fn) := λ x, fn = x
| none := λ _, tt
end,
let xs := env.decl_filter_map (λ d,
do fn ← env.decl_olean d.to_name,
guard ((`_private).is_prefix_of d.to_name ∧ p fn ∧ d.to_name.update_prefix name.anonymous = n),
pure d.to_name),
match xs with
| [n] := pure n
| [] := fail "no such private found"
| _ := fail "many matches found"
end
open lean.parser interactive
/-- `import_private foo from bar` finds a private declaration `foo` in the same file as `bar`
and creates a local notation to refer to it.
`import_private foo` looks for `foo` in all imported files.
When possible, make `foo` non-private rather than using this feature.
-/
@[user_command]
meta def import_private_cmd (_ : parse $ tk "import_private") : lean.parser unit :=
do n ← ident,
fr ← optional (tk "from" *> ident),
n ← find_private_decl n fr,
c ← resolve_constant n,
d ← get_decl n,
let c := @expr.const tt c d.univ_levels,
new_n ← new_aux_decl_name,
add_decl $ declaration.defn new_n d.univ_params d.type c reducibility_hints.abbrev d.is_trusted,
let new_not := sformat!"local notation `{n.update_prefix name.anonymous}` := {new_n}",
emit_command_here $ new_not,
skip .
add_tactic_doc
{ name := "import_private",
category := doc_category.cmd,
decl_names := [`tactic.import_private_cmd],
tags := ["renaming"] }
/--
The command `mk_simp_attribute simp_name "description"` creates a simp set with name `simp_name`.
Lemmas tagged with `@[simp_name]` will be included when `simp with simp_name` is called.
`mk_simp_attribute simp_name none` will use a default description.
Appending the command with `with attr1 attr2 ...` will include all declarations tagged with
`attr1`, `attr2`, ... in the new simp set.
This command is preferred to using ``run_cmd mk_simp_attr `simp_name`` since it adds a doc string
to the attribute that is defined. If you need to create a simp set in a file where this command is
not available, you should use
```lean
run_cmd mk_simp_attr `simp_name
run_cmd add_doc_string `simp_attr.simp_name "Description of the simp set here"
```
-/
@[user_command]
meta def mk_simp_attribute_cmd (_ : parse $ tk "mk_simp_attribute") : lean.parser unit :=
do n ← ident,
d ← parser.pexpr,
d ← to_expr ``(%%d : option string),
descr ← eval_expr (option string) d,
with_list ← types.with_ident_list <|> return [],
mk_simp_attr n with_list,
add_doc_string (name.append `simp_attr n) $ descr.get_or_else $ "simp set for " ++ to_string n
add_tactic_doc
{ name := "mk_simp_attribute",
category := doc_category.cmd,
decl_names := [`tactic.mk_simp_attribute_cmd],
tags := ["simplification"] }
end tactic
|
d869a9a6fe9ccd54f8ac56d7e3ccece65ebc0a89
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/category_theory/limits/functor_category.lean
|
c867cc0cd9ef5455405679717acdf02e32da56df
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 18,309
|
lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.limits.preserves.limits
/-!
# (Co)limits in functor categories.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We show that if `D` has limits, then the functor category `C ⥤ D` also has limits
(`category_theory.limits.functor_category_has_limits`),
and the evaluation functors preserve limits
(`category_theory.limits.evaluation_preserves_limits`)
(and similarly for colimits).
We also show that `F : D ⥤ K ⥤ C` preserves (co)limits if it does so for each `k : K`
(`category_theory.limits.preserves_limits_of_evaluation` and
`category_theory.limits.preserves_colimits_of_evaluation`).
-/
open category_theory category_theory.category category_theory.functor
-- morphism levels before object levels. See note [category_theory universes].
universes w' w v₁ v₂ u₁ u₂ v v' u u'
namespace category_theory.limits
variables {C : Type u} [category.{v} C] {D : Type u'} [category.{v'} D]
variables {J : Type u₁} [category.{v₁} J] {K : Type u₂} [category.{v₂} K]
@[simp, reassoc]
lemma limit.lift_π_app (H : J ⥤ K ⥤ C) [has_limit H] (c : cone H) (j : J) (k : K) :
(limit.lift H c).app k ≫ (limit.π H j).app k = (c.π.app j).app k :=
congr_app (limit.lift_π c j) k
@[simp, reassoc]
lemma colimit.ι_desc_app (H : J ⥤ K ⥤ C) [has_colimit H] (c : cocone H) (j : J) (k : K) :
(colimit.ι H j).app k ≫ (colimit.desc H c).app k = (c.ι.app j).app k :=
congr_app (colimit.ι_desc c j) k
/--
The evaluation functors jointly reflect limits: that is, to show a cone is a limit of `F`
it suffices to show that each evaluation cone is a limit. In other words, to prove a cone is
limiting you can show it's pointwise limiting.
-/
def evaluation_jointly_reflects_limits {F : J ⥤ K ⥤ C} (c : cone F)
(t : Π (k : K), is_limit (((evaluation K C).obj k).map_cone c)) : is_limit c :=
{ lift := λ s,
{ app := λ k, (t k).lift ⟨s.X.obj k, whisker_right s.π ((evaluation K C).obj k)⟩,
naturality' := λ X Y f, (t Y).hom_ext $ λ j,
begin
rw [assoc, (t Y).fac _ j],
simpa using
((t X).fac_assoc ⟨s.X.obj X, whisker_right s.π ((evaluation K C).obj X)⟩ j _).symm,
end },
fac' := λ s j, nat_trans.ext _ _ $ funext $ λ k, (t k).fac _ j,
uniq' := λ s m w, nat_trans.ext _ _ $ funext $ λ x, (t x).hom_ext $ λ j,
(congr_app (w j) x).trans
((t x).fac ⟨s.X.obj _, whisker_right s.π ((evaluation K C).obj _)⟩ j).symm }
/--
Given a functor `F` and a collection of limit cones for each diagram `X ↦ F X k`, we can stitch
them together to give a cone for the diagram `F`.
`combined_is_limit` shows that the new cone is limiting, and `eval_combined` shows it is
(essentially) made up of the original cones.
-/
@[simps] def combine_cones (F : J ⥤ K ⥤ C) (c : Π (k : K), limit_cone (F.flip.obj k)) :
cone F :=
{ X :=
{ obj := λ k, (c k).cone.X,
map := λ k₁ k₂ f, (c k₂).is_limit.lift ⟨_, (c k₁).cone.π ≫ F.flip.map f⟩,
map_id' := λ k, (c k).is_limit.hom_ext (λ j, by { dsimp, simp }),
map_comp' := λ k₁ k₂ k₃ f₁ f₂, (c k₃).is_limit.hom_ext (λ j, by simp) },
π :=
{ app := λ j, { app := λ k, (c k).cone.π.app j },
naturality' := λ j₁ j₂ g, nat_trans.ext _ _ $ funext $ λ k, (c k).cone.π.naturality g } }
/-- The stitched together cones each project down to the original given cones (up to iso). -/
def evaluate_combined_cones (F : J ⥤ K ⥤ C) (c : Π (k : K), limit_cone (F.flip.obj k)) (k : K) :
((evaluation K C).obj k).map_cone (combine_cones F c) ≅ (c k).cone :=
cones.ext (iso.refl _) (by tidy)
/-- Stitching together limiting cones gives a limiting cone. -/
def combined_is_limit (F : J ⥤ K ⥤ C) (c : Π (k : K), limit_cone (F.flip.obj k)) :
is_limit (combine_cones F c) :=
evaluation_jointly_reflects_limits _
(λ k, (c k).is_limit.of_iso_limit (evaluate_combined_cones F c k).symm)
/--
The evaluation functors jointly reflect colimits: that is, to show a cocone is a colimit of `F`
it suffices to show that each evaluation cocone is a colimit. In other words, to prove a cocone is
colimiting you can show it's pointwise colimiting.
-/
def evaluation_jointly_reflects_colimits {F : J ⥤ K ⥤ C} (c : cocone F)
(t : Π (k : K), is_colimit (((evaluation K C).obj k).map_cocone c)) : is_colimit c :=
{ desc := λ s,
{ app := λ k, (t k).desc ⟨s.X.obj k, whisker_right s.ι ((evaluation K C).obj k)⟩,
naturality' := λ X Y f, (t X).hom_ext $ λ j,
begin
rw [(t X).fac_assoc _ j],
erw ← (c.ι.app j).naturality_assoc f,
erw (t Y).fac ⟨s.X.obj _, whisker_right s.ι _⟩ j,
dsimp,
simp,
end },
fac' := λ s j, nat_trans.ext _ _ $ funext $ λ k, (t k).fac _ j,
uniq' := λ s m w, nat_trans.ext _ _ $ funext $ λ x, (t x).hom_ext $ λ j,
(congr_app (w j) x).trans
((t x).fac ⟨s.X.obj _, whisker_right s.ι ((evaluation K C).obj _)⟩ j).symm }
/--
Given a functor `F` and a collection of colimit cocones for each diagram `X ↦ F X k`, we can stitch
them together to give a cocone for the diagram `F`.
`combined_is_colimit` shows that the new cocone is colimiting, and `eval_combined` shows it is
(essentially) made up of the original cocones.
-/
@[simps] def combine_cocones (F : J ⥤ K ⥤ C) (c : Π (k : K), colimit_cocone (F.flip.obj k)) :
cocone F :=
{ X :=
{ obj := λ k, (c k).cocone.X,
map := λ k₁ k₂ f, (c k₁).is_colimit.desc ⟨_, F.flip.map f ≫ (c k₂).cocone.ι⟩,
map_id' := λ k, (c k).is_colimit.hom_ext (λ j, by { dsimp, simp }),
map_comp' := λ k₁ k₂ k₃ f₁ f₂, (c k₁).is_colimit.hom_ext (λ j, by simp) },
ι :=
{ app := λ j, { app := λ k, (c k).cocone.ι.app j },
naturality' := λ j₁ j₂ g, nat_trans.ext _ _ $ funext $ λ k, (c k).cocone.ι.naturality g } }
/-- The stitched together cocones each project down to the original given cocones (up to iso). -/
def evaluate_combined_cocones
(F : J ⥤ K ⥤ C) (c : Π (k : K), colimit_cocone (F.flip.obj k)) (k : K) :
((evaluation K C).obj k).map_cocone (combine_cocones F c) ≅ (c k).cocone :=
cocones.ext (iso.refl _) (by tidy)
/-- Stitching together colimiting cocones gives a colimiting cocone. -/
def combined_is_colimit (F : J ⥤ K ⥤ C) (c : Π (k : K), colimit_cocone (F.flip.obj k)) :
is_colimit (combine_cocones F c) :=
evaluation_jointly_reflects_colimits _
(λ k, (c k).is_colimit.of_iso_colimit (evaluate_combined_cocones F c k).symm)
noncomputable theory
instance functor_category_has_limits_of_shape
[has_limits_of_shape J C] : has_limits_of_shape J (K ⥤ C) :=
{ has_limit := λ F, has_limit.mk
{ cone := combine_cones F (λ k, get_limit_cone _),
is_limit := combined_is_limit _ _ } }
instance functor_category_has_colimits_of_shape
[has_colimits_of_shape J C] : has_colimits_of_shape J (K ⥤ C) :=
{ has_colimit := λ F, has_colimit.mk
{ cocone := combine_cocones _ (λ k, get_colimit_cocone _),
is_colimit := combined_is_colimit _ _ } }
instance functor_category_has_limits_of_size [has_limits_of_size.{v₁ u₁} C] :
has_limits_of_size.{v₁ u₁} (K ⥤ C) := ⟨infer_instance⟩
instance functor_category_has_colimits_of_size [has_colimits_of_size.{v₁ u₁} C] :
has_colimits_of_size.{v₁ u₁} (K ⥤ C) := ⟨infer_instance⟩
instance evaluation_preserves_limits_of_shape [has_limits_of_shape J C] (k : K) :
preserves_limits_of_shape J ((evaluation K C).obj k) :=
{ preserves_limit :=
λ F, preserves_limit_of_preserves_limit_cone (combined_is_limit _ _) $
is_limit.of_iso_limit (limit.is_limit _)
(evaluate_combined_cones F _ k).symm }
/--
If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a limit,
then the evaluation of that limit at `k` is the limit of the evaluations of `F.obj j` at `k`.
-/
def limit_obj_iso_limit_comp_evaluation [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) :
(limit F).obj k ≅ limit (F ⋙ ((evaluation K C).obj k)) :=
preserves_limit_iso ((evaluation K C).obj k) F
@[simp, reassoc]
lemma limit_obj_iso_limit_comp_evaluation_hom_π
[has_limits_of_shape J C] (F : J ⥤ (K ⥤ C)) (j : J) (k : K) :
(limit_obj_iso_limit_comp_evaluation F k).hom ≫ limit.π (F ⋙ ((evaluation K C).obj k)) j =
(limit.π F j).app k :=
begin
dsimp [limit_obj_iso_limit_comp_evaluation],
simp,
end
@[simp, reassoc]
lemma limit_obj_iso_limit_comp_evaluation_inv_π_app
[has_limits_of_shape J C] (F : J ⥤ (K ⥤ C)) (j : J) (k : K):
(limit_obj_iso_limit_comp_evaluation F k).inv ≫ (limit.π F j).app k =
limit.π (F ⋙ ((evaluation K C).obj k)) j :=
begin
dsimp [limit_obj_iso_limit_comp_evaluation],
rw iso.inv_comp_eq,
simp,
end
@[simp, reassoc]
lemma limit_map_limit_obj_iso_limit_comp_evaluation_hom
[has_limits_of_shape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) :
(limit F).map f ≫ (limit_obj_iso_limit_comp_evaluation _ _).hom =
(limit_obj_iso_limit_comp_evaluation _ _).hom ≫
lim_map (whisker_left _ ((evaluation _ _).map f)) :=
by { ext, dsimp, simp }
@[simp, reassoc]
lemma limit_obj_iso_limit_comp_evaluation_inv_limit_map
[has_limits_of_shape J C] {i j : K} (F : J ⥤ K ⥤ C) (f : i ⟶ j) :
(limit_obj_iso_limit_comp_evaluation _ _).inv ≫ (limit F).map f =
lim_map (whisker_left _ ((evaluation _ _).map f)) ≫
(limit_obj_iso_limit_comp_evaluation _ _).inv :=
by rw [iso.inv_comp_eq, ← category.assoc, iso.eq_comp_inv,
limit_map_limit_obj_iso_limit_comp_evaluation_hom]
@[ext]
lemma limit_obj_ext {H : J ⥤ K ⥤ C} [has_limits_of_shape J C]
{k : K} {W : C} {f g : W ⟶ (limit H).obj k}
(w : ∀ j, f ≫ (limits.limit.π H j).app k = g ≫ (limits.limit.π H j).app k) : f = g :=
begin
apply (cancel_mono (limit_obj_iso_limit_comp_evaluation H k).hom).1,
ext,
simpa using w j,
end
instance evaluation_preserves_colimits_of_shape [has_colimits_of_shape J C] (k : K) :
preserves_colimits_of_shape J ((evaluation K C).obj k) :=
{ preserves_colimit :=
λ F, preserves_colimit_of_preserves_colimit_cocone (combined_is_colimit _ _) $
is_colimit.of_iso_colimit (colimit.is_colimit _)
(evaluate_combined_cocones F _ k).symm }
/--
If `F : J ⥤ K ⥤ C` is a functor into a functor category which has a colimit,
then the evaluation of that colimit at `k` is the colimit of the evaluations of `F.obj j` at `k`.
-/
def colimit_obj_iso_colimit_comp_evaluation [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) :
(colimit F).obj k ≅ colimit (F ⋙ ((evaluation K C).obj k)) :=
preserves_colimit_iso ((evaluation K C).obj k) F
@[simp, reassoc]
lemma colimit_obj_iso_colimit_comp_evaluation_ι_inv
[has_colimits_of_shape J C] (F : J ⥤ (K ⥤ C)) (j : J) (k : K) :
colimit.ι (F ⋙ ((evaluation K C).obj k)) j ≫ (colimit_obj_iso_colimit_comp_evaluation F k).inv =
(colimit.ι F j).app k :=
begin
dsimp [colimit_obj_iso_colimit_comp_evaluation],
simp,
end
@[simp, reassoc]
lemma colimit_obj_iso_colimit_comp_evaluation_ι_app_hom
[has_colimits_of_shape J C] (F : J ⥤ (K ⥤ C)) (j : J) (k : K) :
(colimit.ι F j).app k ≫ (colimit_obj_iso_colimit_comp_evaluation F k).hom =
colimit.ι (F ⋙ ((evaluation K C).obj k)) j :=
begin
dsimp [colimit_obj_iso_colimit_comp_evaluation],
rw ←iso.eq_comp_inv,
simp,
end
@[simp, reassoc]
lemma colimit_obj_iso_colimit_comp_evaluation_inv_colimit_map
[has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) :
(colimit_obj_iso_colimit_comp_evaluation _ _).inv ≫ (colimit F).map f =
colim_map (whisker_left _ ((evaluation _ _).map f)) ≫
(colimit_obj_iso_colimit_comp_evaluation _ _).inv :=
by { ext, dsimp, simp }
@[simp, reassoc]
lemma colimit_map_colimit_obj_iso_colimit_comp_evaluation_hom
[has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) {i j : K} (f : i ⟶ j) :
(colimit F).map f ≫ (colimit_obj_iso_colimit_comp_evaluation _ _).hom =
(colimit_obj_iso_colimit_comp_evaluation _ _).hom ≫
colim_map (whisker_left _ ((evaluation _ _).map f)) :=
by rw [← iso.inv_comp_eq, ← category.assoc, ← iso.eq_comp_inv,
colimit_obj_iso_colimit_comp_evaluation_inv_colimit_map]
@[ext]
lemma colimit_obj_ext {H : J ⥤ K ⥤ C} [has_colimits_of_shape J C]
{k : K} {W : C} {f g : (colimit H).obj k ⟶ W}
(w : ∀ j, (colimit.ι H j).app k ≫ f = (colimit.ι H j).app k ≫ g) : f = g :=
begin
apply (cancel_epi (colimit_obj_iso_colimit_comp_evaluation H k).inv).1,
ext,
simpa using w j,
end
instance evaluation_preserves_limits [has_limits C] (k : K) :
preserves_limits ((evaluation K C).obj k) :=
{ preserves_limits_of_shape := λ J 𝒥, by resetI; apply_instance }
/-- `F : D ⥤ K ⥤ C` preserves the limit of some `G : J ⥤ D` if it does for each `k : K`. -/
def preserves_limit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D)
(H : Π (k : K), preserves_limit G (F ⋙ (evaluation K C).obj k : D ⥤ C)) :
preserves_limit G F := ⟨λ c hc,
begin
apply evaluation_jointly_reflects_limits,
intro X,
haveI := H X,
change is_limit ((F ⋙ (evaluation K C).obj X).map_cone c),
exact preserves_limit.preserves hc,
end⟩
/-- `F : D ⥤ K ⥤ C` preserves limits of shape `J` if it does for each `k : K`. -/
def preserves_limits_of_shape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [category J]
(H : Π (k : K), preserves_limits_of_shape J (F ⋙ (evaluation K C).obj k)) :
preserves_limits_of_shape J F :=
⟨λ G, preserves_limit_of_evaluation F G (λ k, preserves_limits_of_shape.preserves_limit)⟩
/-- `F : D ⥤ K ⥤ C` preserves all limits if it does for each `k : K`. -/
def preserves_limits_of_evaluation (F : D ⥤ K ⥤ C)
(H : Π (k : K), preserves_limits_of_size.{w' w} (F ⋙ (evaluation K C).obj k)) :
preserves_limits_of_size.{w' w} F :=
⟨λ L hL, by exactI preserves_limits_of_shape_of_evaluation
F L (λ k, preserves_limits_of_size.preserves_limits_of_shape)⟩
/-- The constant functor `C ⥤ (D ⥤ C)` preserves limits. -/
instance preserves_limits_const : preserves_limits_of_size.{w' w} (const D : C ⥤ _) :=
preserves_limits_of_evaluation _ $ λ X, preserves_limits_of_nat_iso $ iso.symm $
const_comp_evaluation_obj _ _
instance evaluation_preserves_colimits [has_colimits C] (k : K) :
preserves_colimits ((evaluation K C).obj k) :=
{ preserves_colimits_of_shape := λ J 𝒥, by resetI; apply_instance }
/-- `F : D ⥤ K ⥤ C` preserves the colimit of some `G : J ⥤ D` if it does for each `k : K`. -/
def preserves_colimit_of_evaluation (F : D ⥤ K ⥤ C) (G : J ⥤ D)
(H : Π (k), preserves_colimit G (F ⋙ (evaluation K C).obj k)) : preserves_colimit G F := ⟨λ c hc,
begin
apply evaluation_jointly_reflects_colimits,
intro X,
haveI := H X,
change is_colimit ((F ⋙ (evaluation K C).obj X).map_cocone c),
exact preserves_colimit.preserves hc,
end⟩
/-- `F : D ⥤ K ⥤ C` preserves all colimits of shape `J` if it does for each `k : K`. -/
def preserves_colimits_of_shape_of_evaluation (F : D ⥤ K ⥤ C) (J : Type*) [category J]
(H : Π (k : K), preserves_colimits_of_shape J (F ⋙ (evaluation K C).obj k)) :
preserves_colimits_of_shape J F :=
⟨λ G, preserves_colimit_of_evaluation F G (λ k, preserves_colimits_of_shape.preserves_colimit)⟩
/-- `F : D ⥤ K ⥤ C` preserves all colimits if it does for each `k : K`. -/
def preserves_colimits_of_evaluation (F : D ⥤ K ⥤ C)
(H : Π (k : K), preserves_colimits_of_size.{w' w} (F ⋙ (evaluation K C).obj k)) :
preserves_colimits_of_size.{w' w} F :=
⟨λ L hL, by exactI preserves_colimits_of_shape_of_evaluation
F L (λ k, preserves_colimits_of_size.preserves_colimits_of_shape)⟩
/-- The constant functor `C ⥤ (D ⥤ C)` preserves colimits. -/
instance preserves_colimits_const : preserves_colimits_of_size.{w' w} (const D : C ⥤ _) :=
preserves_colimits_of_evaluation _ $ λ X, preserves_colimits_of_nat_iso $ iso.symm $
const_comp_evaluation_obj _ _
open category_theory.prod
/-- The limit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by
the individual limits on objects. -/
@[simps]
def limit_iso_flip_comp_lim [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) :
limit F ≅ F.flip ⋙ lim :=
nat_iso.of_components (limit_obj_iso_limit_comp_evaluation F) $ by tidy
/-- A variant of `limit_iso_flip_comp_lim` where the arguemnts of `F` are flipped. -/
@[simps]
def limit_flip_iso_comp_lim [has_limits_of_shape J C] (F : K ⥤ J ⥤ C) :
limit F.flip ≅ F ⋙ lim :=
nat_iso.of_components (λ k,
limit_obj_iso_limit_comp_evaluation F.flip k ≪≫
has_limit.iso_of_nat_iso (flip_comp_evaluation _ _)) $ by tidy
/--
For a functor `G : J ⥤ K ⥤ C`, its limit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ lim`.
Note that this does not require `K` to be small.
-/
@[simps] def limit_iso_swap_comp_lim [has_limits_of_shape J C] (G : J ⥤ K ⥤ C) :
limit G ≅ curry.obj (swap K J ⋙ uncurry.obj G) ⋙ lim :=
limit_iso_flip_comp_lim G ≪≫ iso_whisker_right (flip_iso_curry_swap_uncurry _) _
/-- The colimit of a diagram `F : J ⥤ K ⥤ C` is isomorphic to the functor given by
the individual colimits on objects. -/
@[simps]
def colimit_iso_flip_comp_colim [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) :
colimit F ≅ F.flip ⋙ colim :=
nat_iso.of_components (colimit_obj_iso_colimit_comp_evaluation F) $ by tidy
/-- A variant of `colimit_iso_flip_comp_colim` where the arguemnts of `F` are flipped. -/
@[simps]
def colimit_flip_iso_comp_colim [has_colimits_of_shape J C] (F : K ⥤ J ⥤ C) :
colimit F.flip ≅ F ⋙ colim :=
nat_iso.of_components (λ k,
colimit_obj_iso_colimit_comp_evaluation _ _ ≪≫
has_colimit.iso_of_nat_iso (flip_comp_evaluation _ _)) $ by tidy
/--
For a functor `G : J ⥤ K ⥤ C`, its colimit `K ⥤ C` is given by `(G' : K ⥤ J ⥤ C) ⋙ colim`.
Note that this does not require `K` to be small.
-/
@[simps]
def colimit_iso_swap_comp_colim [has_colimits_of_shape J C] (G : J ⥤ K ⥤ C) :
colimit G ≅ curry.obj (swap K J ⋙ uncurry.obj G) ⋙ colim :=
colimit_iso_flip_comp_colim G ≪≫ iso_whisker_right (flip_iso_curry_swap_uncurry _) _
end category_theory.limits
|
1e46de45316e0c08f4370884f856e3a36137947d
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/stage0/src/Lean/Elab/Term.lean
|
3e2120893da5596e7d78f748bc2bfbd1aabeb3e0
|
[
"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
| 79,774
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.ResolveName
import Lean.Log
import Lean.Deprecated
import Lean.Util.Sorry
import Lean.Util.ReplaceExpr
import Lean.Structure
import Lean.Meta.AppBuilder
import Lean.Meta.CollectMVars
import Lean.Meta.Coe
import Lean.Hygiene
import Lean.Util.RecDepth
import Lean.Elab.Config
import Lean.Elab.Level
import Lean.Elab.Attributes
import Lean.Elab.AutoBound
import Lean.Elab.InfoTree
import Lean.Elab.Open
import Lean.Elab.SetOption
import Lean.Elab.DeclModifiers
namespace Lean.Elab
namespace Term
/-- Saved context for postponed terms and tactics to be executed. -/
structure SavedContext where
declName? : Option Name
options : Options
openDecls : List OpenDecl
macroStack : MacroStack
errToSorry : Bool
levelNames : List Name
/-- We use synthetic metavariables as placeholders for pending elaboration steps. -/
inductive SyntheticMVarKind where
| /-- Use typeclass resolution to synthesize value for metavariable. -/
typeClass
| /--
Similar to `typeClass`, but error messages are different.
if `f?` is `some f`, we produce an application type mismatch error message.
Otherwise, if `header?` is `some header`, we generate the error `(header ++ "has type" ++ eType ++ "but it is expected to have type" ++ expectedType)`
Otherwise, we generate the error `("type mismatch" ++ e ++ "has type" ++ eType ++ "but it is expected to have type" ++ expectedType)` -/
coe (header? : Option String) (eNew : Expr) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr)
| /-- Use tactic to synthesize value for metavariable. -/
tactic (tacticCode : Syntax) (ctx : SavedContext)
| /-- Metavariable represents a hole whose elaboration has been postponed. -/
postponed (ctx : SavedContext)
deriving Inhabited
instance : ToString SyntheticMVarKind where
toString
| .typeClass => "typeclass"
| .coe .. => "coe"
| .tactic .. => "tactic"
| .postponed .. => "postponed"
structure SyntheticMVarDecl where
stx : Syntax
kind : SyntheticMVarKind
deriving Inhabited
/--
We can optionally associate an error context with a metavariable (see `MVarErrorInfo`).
We have three different kinds of error context.
-/
inductive MVarErrorKind where
| /-- Metavariable for implicit arguments. `ctx` is the parent application. -/
implicitArg (ctx : Expr)
| /-- Metavariable for explicit holes provided by the user (e.g., `_` and `?m`) -/
hole
| /-- "Custom", `msgData` stores the additional error messages. -/
custom (msgData : MessageData)
deriving Inhabited
instance : ToString MVarErrorKind where
toString
| .implicitArg _ => "implicitArg"
| .hole => "hole"
| .custom _ => "custom"
/--
We can optionally associate an error context with metavariables.
-/
structure MVarErrorInfo where
mvarId : MVarId
ref : Syntax
kind : MVarErrorKind
argName? : Option Name := none
deriving Inhabited
/--
Nested `let rec` expressions are eagerly lifted by the elaborator.
We store the information necessary for performing the lifting here.
-/
structure LetRecToLift where
ref : Syntax
fvarId : FVarId
attrs : Array Attribute
shortDeclName : Name
declName : Name
lctx : LocalContext
localInstances : LocalInstances
type : Expr
val : Expr
mvarId : MVarId
deriving Inhabited
/--
State of the `TermElabM` monad.
-/
structure State where
levelNames : List Name := []
syntheticMVars : MVarIdMap SyntheticMVarDecl := {}
pendingMVars : List MVarId := {}
mvarErrorInfos : MVarIdMap MVarErrorInfo := {}
letRecsToLift : List LetRecToLift := []
deriving Inhabited
end Term
namespace Tactic
/--
State of the `TacticM` monad.
-/
structure State where
goals : List MVarId
deriving Inhabited
/--
Snapshots are used to implement the `save` tactic.
This tactic caches the state of the system, and allows us to "replay"
expensive proofs efficiently. This is only relevant implementing the
LSP server.
-/
structure Snapshot where
core : Core.State
meta : Meta.State
term : Term.State
tactic : Tactic.State
stx : Syntax
deriving Inhabited
/--
Key for the cache used to implement the `save` tactic.
-/
structure CacheKey where
mvarId : MVarId -- TODO: should include all goals
pos : String.Pos
deriving BEq, Hashable, Inhabited
/--
Cache for the `save` tactic.
-/
structure Cache where
pre : Std.PHashMap CacheKey Snapshot := {}
post : Std.PHashMap CacheKey Snapshot := {}
deriving Inhabited
end Tactic
namespace Term
structure Context where
declName? : Option Name := none
/--
Map `.auxDecl` local declarations used to encode recursive declarations to their full-names.
-/
auxDeclToFullName : FVarIdMap Name := {}
macroStack : MacroStack := []
/--
When `mayPostpone == true`, an elaboration function may interrupt its execution by throwing `Exception.postpone`.
The function `elabTerm` catches this exception and creates fresh synthetic metavariable `?m`, stores `?m` in
the list of pending synthetic metavariables, and returns `?m`. -/
mayPostpone : Bool := true
/--
When `errToSorry` is set to true, the method `elabTerm` catches
exceptions and converts them into synthetic `sorry`s.
The implementation of choice nodes and overloaded symbols rely on the fact
that when `errToSorry` is set to false for an elaboration function `F`, then
`errToSorry` remains `false` for all elaboration functions invoked by `F`.
That is, it is safe to transition `errToSorry` from `true` to `false`, but
we must not set `errToSorry` to `true` when it is currently set to `false`. -/
errToSorry : Bool := true
/--
When `autoBoundImplicit` is set to true, instead of producing
an "unknown identifier" error for unbound variables, we generate an
internal exception. This exception is caught at `elabBinders` and
`elabTypeWithUnboldImplicit`. Both methods add implicit declarations
for the unbound variable and try again. -/
autoBoundImplicit : Bool := false
autoBoundImplicits : Std.PArray Expr := {}
/--
A name `n` is only eligible to be an auto implicit name if `autoBoundImplicitForbidden n = false`.
We use this predicate to disallow `f` to be considered an auto implicit name in a definition such
as
```
def f : f → Bool := fun _ => true
```
-/
autoBoundImplicitForbidden : Name → Bool := fun _ => false
/-- Map from user name to internal unique name -/
sectionVars : NameMap Name := {}
/-- Map from internal name to fvar -/
sectionFVars : NameMap Expr := {}
/-- Enable/disable implicit lambdas feature. -/
implicitLambda : Bool := true
/-- Noncomputable sections automatically add the `noncomputable` modifier to any declaration we cannot generate code for -/
isNoncomputableSection : Bool := false
/-- When `true` we skip TC failures. We use this option when processing patterns -/
ignoreTCFailures : Bool := false
/-- `true` when elaborating patterns. It affects how we elaborate named holes. -/
inPattern : Bool := false
/-- Cache for the `save` tactic. It is only `some` in the LSP server. -/
tacticCache? : Option (IO.Ref Tactic.Cache) := none
/-- If `true`, we store in the `Expr` the `Syntax` for recursive applications (i.e., applications
of free variables tagged with `isAuxDecl`). We store the `Syntax` using `mkRecAppWithSyntax`.
We use the `Syntax` object to produce better error messages at `Structural.lean` and `WF.lean`. -/
saveRecAppSyntax : Bool := true
abbrev TermElabM := ReaderT Context $ StateRefT State MetaM
abbrev TermElab := Syntax → Option Expr → TermElabM Expr
-- Make the compiler generate specialized `pure`/`bind` so we do not have to optimize through the
-- whole monad stack at every use site. May eventually be covered by `deriving`.
instance : Monad TermElabM := let i := inferInstanceAs (Monad TermElabM); { pure := i.pure, bind := i.bind }
open Meta
instance : Inhabited (TermElabM α) where
default := throw default
/--
Backtrackable state for the `TermElabM` monad.
-/
structure SavedState where
meta : Meta.SavedState
«elab» : State
deriving Inhabited
protected def saveState : TermElabM SavedState :=
return { meta := (← Meta.saveState), «elab» := (← get) }
def SavedState.restore (s : SavedState) (restoreInfo : Bool := false) : TermElabM Unit := do
let traceState ← getTraceState -- We never backtrack trace message
let infoState ← getInfoState -- We also do not backtrack the info nodes when `restoreInfo == false`
s.meta.restore
set s.elab
setTraceState traceState
unless restoreInfo do
setInfoState infoState
instance : MonadBacktrack SavedState TermElabM where
saveState := Term.saveState
restoreState b := b.restore
abbrev TermElabResult (α : Type) := EStateM.Result Exception SavedState α
instance [Inhabited α] : Inhabited (TermElabResult α) where
default := EStateM.Result.ok default default
/--
Execute `x`, save resulting expression and new state.
We remove any `Info` created by `x`.
The info nodes are committed when we execute `applyResult`.
We use `observing` to implement overloaded notation and decls.
We want to save `Info` nodes for the chosen alternative.
-/
def observing (x : TermElabM α) : TermElabM (TermElabResult α) := do
let s ← saveState
try
let e ← x
let sNew ← saveState
s.restore (restoreInfo := true)
return EStateM.Result.ok e sNew
catch
| ex@(.error ..) =>
let sNew ← saveState
s.restore (restoreInfo := true)
return .error ex sNew
| ex@(.internal id _) =>
if id == postponeExceptionId then
s.restore (restoreInfo := true)
throw ex
/--
Apply the result/exception and state captured with `observing`.
We use this method to implement overloaded notation and symbols. -/
def applyResult (result : TermElabResult α) : TermElabM α := do
match result with
| .ok a r => r.restore (restoreInfo := true); return a
| .error ex r => r.restore (restoreInfo := true); throw ex
/--
Execute `x`, but keep state modifications only if `x` did not postpone.
This method is useful to implement elaboration functions that cannot decide whether
they need to postpone or not without updating the state. -/
def commitIfDidNotPostpone (x : TermElabM α) : TermElabM α := do
-- We just reuse the implementation of `observing` and `applyResult`.
let r ← observing x
applyResult r
/--
Return the universe level names explicitly provided by the user.
-/
def getLevelNames : TermElabM (List Name) :=
return (← get).levelNames
/--
Given a free variable `fvar`, return its declaration.
This function panics if `fvar` is not a free variable.
-/
def getFVarLocalDecl! (fvar : Expr) : TermElabM LocalDecl := do
match (← getLCtx).find? fvar.fvarId! with
| some d => pure d
| none => unreachable!
instance : AddErrorMessageContext TermElabM where
add ref msg := do
let ctx ← read
let ref := getBetterRef ref ctx.macroStack
let msg ← addMessageContext msg
let msg ← addMacroStack msg ctx.macroStack
pure (ref, msg)
/--
Execute `x` but discard changes performed at `Term.State` and `Meta.State`.
Recall that the `Environment` and `InfoState` are at `Core.State`. Thus, any updates to it will
be preserved. This method is useful for performing computations where all
metavariable must be resolved or discarded.
The `InfoTree`s are not discarded, however, and wrapped in `InfoTree.Context`
to store their metavariable context. -/
def withoutModifyingElabMetaStateWithInfo (x : TermElabM α) : TermElabM α := do
let s ← get
let sMeta ← getThe Meta.State
try
withSaveInfoContext x
finally
set s
set sMeta
/--
Execute `x` bud discard changes performed to the state.
However, the info trees and messages are not discarded. -/
private def withoutModifyingStateWithInfoAndMessagesImpl (x : TermElabM α) : TermElabM α := do
let saved ← saveState
try
withSaveInfoContext x
finally
let saved := { saved with meta.core.infoState := (← getInfoState), meta.core.messages := (← getThe Core.State).messages }
restoreState saved
/--
Execute `x` without storing `Syntax` for recursive applications. See `saveRecAppSyntax` field at `Context`.
-/
def withoutSavingRecAppSyntax (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with saveRecAppSyntax := false }) x
unsafe def mkTermElabAttributeUnsafe : IO (KeyedDeclsAttribute TermElab) :=
mkElabAttribute TermElab `Lean.Elab.Term.termElabAttribute `builtinTermElab `termElab `Lean.Parser.Term `Lean.Elab.Term.TermElab "term"
@[implementedBy mkTermElabAttributeUnsafe]
opaque mkTermElabAttribute : IO (KeyedDeclsAttribute TermElab)
builtin_initialize termElabAttribute : KeyedDeclsAttribute TermElab ← mkTermElabAttribute
/--
Auxiliary datatatype for presenting a Lean lvalue modifier.
We represent a unelaborated lvalue as a `Syntax` (or `Expr`) and `List LVal`.
Example: `a.foo.1` is represented as the `Syntax` `a` and the list
`[LVal.fieldName "foo", LVal.fieldIdx 1]`.
-/
inductive LVal where
| fieldIdx (ref : Syntax) (i : Nat)
| /-- Field `suffix?` is for producing better error messages because `x.y` may be a field access or a hierachical/composite name.
`ref` is the syntax object representing the field. `targetStx` is the target object being accessed. -/
fieldName (ref : Syntax) (name : String) (suffix? : Option Name) (targetStx : Syntax)
def LVal.getRef : LVal → Syntax
| .fieldIdx ref _ => ref
| .fieldName ref .. => ref
def LVal.isFieldName : LVal → Bool
| .fieldName .. => true
| _ => false
instance : ToString LVal where
toString
| .fieldIdx _ i => toString i
| .fieldName _ n .. => n
/-- Return the name of the declaration being elaborated if available. -/
def getDeclName? : TermElabM (Option Name) := return (← read).declName?
/-- Return the list of nested `let rec` declarations that need to be lifted. -/
def getLetRecsToLift : TermElabM (List LetRecToLift) := return (← get).letRecsToLift
/-- Return the declaration of the given metavariable -/
def getMVarDecl (mvarId : MVarId) : TermElabM MetavarDecl := return (← getMCtx).getDecl mvarId
/-- Execute `x` with `declName? := name`. See `getDeclName? -/
def withDeclName (name : Name) (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with declName? := name }) x
/-- Update the universe level parameter names. -/
def setLevelNames (levelNames : List Name) : TermElabM Unit :=
modify fun s => { s with levelNames := levelNames }
/-- Execute `x` using `levelNames` as the universe level parameter names. See `getLevelNames`. -/
def withLevelNames (levelNames : List Name) (x : TermElabM α) : TermElabM α := do
let levelNamesSaved ← getLevelNames
setLevelNames levelNames
try x finally setLevelNames levelNamesSaved
/--
Declare an auxiliary local declaration `shortDeclName : type` for elaborating recursive declaration `declName`,
update the mapping `auxDeclToFullName`, and then execute `k`.
-/
def withAuxDecl (shortDeclName : Name) (type : Expr) (declName : Name) (k : Expr → TermElabM α) : TermElabM α :=
withLocalDecl shortDeclName BinderInfo.auxDecl type fun x =>
withReader (fun ctx => { ctx with auxDeclToFullName := ctx.auxDeclToFullName.insert x.fvarId! declName }) do
k x
def withoutErrToSorryImp (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with errToSorry := false }) x
/--
Execute `x` without converting errors (i.e., exceptions) to `sorry` applications.
Recall that when `errToSorry = true`, the method `elabTerm` catches exceptions and convert them into `sorry` applications.
-/
def withoutErrToSorry [MonadFunctorT TermElabM m] : m α → m α :=
monadMap (m := TermElabM) withoutErrToSorryImp
/-- For testing `TermElabM` methods. The #eval command will sign the error. -/
def throwErrorIfErrors : TermElabM Unit := do
if (← MonadLog.hasErrors) then
throwError "Error(s)"
def traceAtCmdPos (cls : Name) (msg : Unit → MessageData) : TermElabM Unit :=
withRef Syntax.missing <| trace cls msg
def ppGoal (mvarId : MVarId) : TermElabM Format :=
Meta.ppGoal mvarId
open Level (LevelElabM)
def liftLevelM (x : LevelElabM α) : TermElabM α := do
let ctx ← read
let mctx ← getMCtx
let ngen ← getNGen
let lvlCtx : Level.Context := { options := (← getOptions), ref := (← getRef), autoBoundImplicit := ctx.autoBoundImplicit }
match (x lvlCtx).run { ngen := ngen, mctx := mctx, levelNames := (← getLevelNames) } with
| .ok a newS => setMCtx newS.mctx; setNGen newS.ngen; setLevelNames newS.levelNames; pure a
| .error ex _ => throw ex
def elabLevel (stx : Syntax) : TermElabM Level :=
liftLevelM <| Level.elabLevel stx
/-- Elaborate `x` with `stx` on the macro stack -/
def withMacroExpansion (beforeStx afterStx : Syntax) (x : TermElabM α) : TermElabM α :=
withMacroExpansionInfo beforeStx afterStx do
withReader (fun ctx => { ctx with macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack }) x
/--
Add the given metavariable to the list of pending synthetic metavariables.
The method `synthesizeSyntheticMVars` is used to process the metavariables on this list. -/
def registerSyntheticMVar (stx : Syntax) (mvarId : MVarId) (kind : SyntheticMVarKind) : TermElabM Unit := do
modify fun s => { s with syntheticMVars := s.syntheticMVars.insert mvarId { stx, kind }, pendingMVars := mvarId :: s.pendingMVars }
def registerSyntheticMVarWithCurrRef (mvarId : MVarId) (kind : SyntheticMVarKind) : TermElabM Unit := do
registerSyntheticMVar (← getRef) mvarId kind
def registerMVarErrorInfo (mvarErrorInfo : MVarErrorInfo) : TermElabM Unit :=
modify fun s => { s with mvarErrorInfos := s.mvarErrorInfos.insert mvarErrorInfo.mvarId mvarErrorInfo }
def registerMVarErrorHoleInfo (mvarId : MVarId) (ref : Syntax) : TermElabM Unit :=
registerMVarErrorInfo { mvarId, ref, kind := .hole }
def registerMVarErrorImplicitArgInfo (mvarId : MVarId) (ref : Syntax) (app : Expr) : TermElabM Unit := do
registerMVarErrorInfo { mvarId, ref, kind := .implicitArg app }
def registerMVarErrorCustomInfo (mvarId : MVarId) (ref : Syntax) (msgData : MessageData) : TermElabM Unit := do
registerMVarErrorInfo { mvarId, ref, kind := .custom msgData }
def getMVarErrorInfo? (mvarId : MVarId) : TermElabM (Option MVarErrorInfo) := do
return (← get).mvarErrorInfos.find? mvarId
def registerCustomErrorIfMVar (e : Expr) (ref : Syntax) (msgData : MessageData) : TermElabM Unit :=
match e.getAppFn with
| Expr.mvar mvarId => registerMVarErrorCustomInfo mvarId ref msgData
| _ => pure ()
/--
Auxiliary method for reporting errors of the form "... contains metavariables ...".
This kind of error is thrown, for example, at `Match.lean` where elaboration
cannot continue if there are metavariables in patterns.
We only want to log it if we haven't logged any error so far. -/
def throwMVarError (m : MessageData) : TermElabM α := do
if (← MonadLog.hasErrors) then
throwAbortTerm
else
throwError m
def MVarErrorInfo.logError (mvarErrorInfo : MVarErrorInfo) (extraMsg? : Option MessageData) : TermElabM Unit := do
match mvarErrorInfo.kind with
| MVarErrorKind.implicitArg app => do
let app ← instantiateMVars app
let msg := addArgName "don't know how to synthesize implicit argument"
let msg := msg ++ m!"{indentExpr app.setAppPPExplicitForExposingMVars}" ++ Format.line ++ "context:" ++ Format.line ++ MessageData.ofGoal mvarErrorInfo.mvarId
logErrorAt mvarErrorInfo.ref (appendExtra msg)
| MVarErrorKind.hole => do
let msg := addArgName "don't know how to synthesize placeholder" " for argument"
let msg := msg ++ Format.line ++ "context:" ++ Format.line ++ MessageData.ofGoal mvarErrorInfo.mvarId
logErrorAt mvarErrorInfo.ref (MessageData.tagged `Elab.synthPlaceholder <| appendExtra msg)
| MVarErrorKind.custom msg =>
logErrorAt mvarErrorInfo.ref (appendExtra msg)
where
/-- Append `mvarErrorInfo` argument name (if available) to the message.
Remark: if the argument name contains macro scopes we do not append it. -/
addArgName (msg : MessageData) (extra : String := "") : MessageData :=
match mvarErrorInfo.argName? with
| none => msg
| some argName => if argName.hasMacroScopes then msg else msg ++ extra ++ m!" '{argName}'"
appendExtra (msg : MessageData) : MessageData :=
match extraMsg? with
| none => msg
| some extraMsg => msg ++ extraMsg
/--
Try to log errors for the unassigned metavariables `pendingMVarIds`.
Return `true` if there were "unfilled holes", and we should "abort" declaration.
TODO: try to fill "all" holes using synthetic "sorry's"
Remark: We only log the "unfilled holes" as new errors if no error has been logged so far. -/
def logUnassignedUsingErrorInfos (pendingMVarIds : Array MVarId) (extraMsg? : Option MessageData := none) : TermElabM Bool := do
if pendingMVarIds.isEmpty then
return false
else
let hasOtherErrors ← MonadLog.hasErrors
let mut hasNewErrors := false
let mut alreadyVisited : MVarIdSet := {}
let mut errors : Array MVarErrorInfo := #[]
for (_, mvarErrorInfo) in (← get).mvarErrorInfos do
let mvarId := mvarErrorInfo.mvarId
unless alreadyVisited.contains mvarId do
alreadyVisited := alreadyVisited.insert mvarId
/- The metavariable `mvarErrorInfo.mvarId` may have been assigned or
delayed assigned to another metavariable that is unassigned. -/
let mvarDeps ← getMVars (mkMVar mvarId)
if mvarDeps.any pendingMVarIds.contains then do
unless hasOtherErrors do
errors := errors.push mvarErrorInfo
hasNewErrors := true
-- To sort the errors by position use
-- let sortedErrors := errors.qsort fun e₁ e₂ => e₁.ref.getPos?.getD 0 < e₂.ref.getPos?.getD 0
for error in errors do
error.mvarId.withContext do
error.logError extraMsg?
return hasNewErrors
/-- Ensure metavariables registered using `registerMVarErrorInfos` (and used in the given declaration) have been assigned. -/
def ensureNoUnassignedMVars (decl : Declaration) : TermElabM Unit := do
let pendingMVarIds ← getMVarsAtDecl decl
if (← logUnassignedUsingErrorInfos pendingMVarIds) then
throwAbortCommand
/--
Execute `x` without allowing it to postpone elaboration tasks.
That is, `tryPostpone` is a noop. -/
def withoutPostponing (x : TermElabM α) : TermElabM α :=
withReader (fun ctx => { ctx with mayPostpone := false }) x
/-- Creates syntax for `(` <ident> `:` <type> `)` -/
def mkExplicitBinder (ident : Syntax) (type : Syntax) : Syntax :=
mkNode ``Lean.Parser.Term.explicitBinder #[mkAtom "(", mkNullNode #[ident], mkNullNode #[mkAtom ":", type], mkNullNode, mkAtom ")"]
/--
Convert unassigned universe level metavariables into parameters.
The new parameter names are of the form `u_i` where `i >= nextParamIdx`.
The method returns the updated expression and new `nextParamIdx`.
Remark: we make sure the generated parameter names do not clash with the universe at `ctx.levelNames`. -/
def levelMVarToParam (e : Expr) (nextParamIdx : Nat := 1) (except : LMVarId → Bool := fun _ => false) : TermElabM (Expr × Nat) := do
let levelNames ← getLevelNames
let r := (← getMCtx).levelMVarToParam (fun n => levelNames.elem n) except e `u nextParamIdx
setMCtx r.mctx
return (r.expr, r.nextParamIdx)
/-- Variant of `levelMVarToParam` where `nextParamIdx` is stored in a state monad. -/
def levelMVarToParam' (e : Expr) (except : LMVarId → Bool := fun _ => false) : StateRefT Nat TermElabM Expr := do
let nextParamIdx ← get
let (e, nextParamIdx) ← levelMVarToParam e nextParamIdx except
set nextParamIdx
return e
/--
Auxiliary method for creating fresh binder names.
Do not confuse with the method for creating fresh free/meta variable ids. -/
def mkFreshBinderName [Monad m] [MonadQuotation m] : m Name :=
withFreshMacroScope <| MonadQuotation.addMacroScope `x
/--
Auxiliary method for creating a `Syntax.ident` containing
a fresh name. This method is intended for creating fresh binder names.
It is just a thin layer on top of `mkFreshUserName`. -/
def mkFreshIdent [Monad m] [MonadQuotation m] (ref : Syntax) : m Syntax :=
return mkIdentFrom ref (← mkFreshBinderName)
private def applyAttributesCore
(declName : Name) (attrs : Array Attribute)
(applicationTime? : Option AttributeApplicationTime) : TermElabM Unit :=
for attr in attrs do
withRef attr.stx do withLogging do
let env ← getEnv
match getAttributeImpl env attr.name with
| Except.error errMsg => throwError errMsg
| Except.ok attrImpl =>
match applicationTime? with
| none => attrImpl.add declName attr.stx attr.kind
| some applicationTime =>
if applicationTime == attrImpl.applicationTime then
attrImpl.add declName attr.stx attr.kind
/-- Apply given attributes **at** a given application time -/
def applyAttributesAt (declName : Name) (attrs : Array Attribute) (applicationTime : AttributeApplicationTime) : TermElabM Unit :=
applyAttributesCore declName attrs applicationTime
def applyAttributes (declName : Name) (attrs : Array Attribute) : TermElabM Unit :=
applyAttributesCore declName attrs none
def mkTypeMismatchError (header? : Option String) (e : Expr) (eType : Expr) (expectedType : Expr) : TermElabM MessageData := do
let header : MessageData := match header? with
| some header => m!"{header} "
| none => m!"type mismatch{indentExpr e}\n"
return m!"{header}{← mkHasTypeButIsExpectedMsg eType expectedType}"
def throwTypeMismatchError (header? : Option String) (expectedType : Expr) (eType : Expr) (e : Expr)
(f? : Option Expr := none) (extraMsg? : Option MessageData := none) : TermElabM α := do
/-
We ignore `extraMsg?` for now. In all our tests, it contained no useful information. It was
always of the form:
```
failed to synthesize instance
CoeT <eType> <e> <expectedType>
```
We should revisit this decision in the future and decide whether it may contain useful information
or not. -/
let extraMsg := Format.nil
/-
let extraMsg : MessageData := match extraMsg? with
| none => Format.nil
| some extraMsg => Format.line ++ extraMsg;
-/
match f? with
| none => throwError "{← mkTypeMismatchError header? e eType expectedType}{extraMsg}"
| some f => Meta.throwAppTypeMismatch f e
def withoutMacroStackAtErr (x : TermElabM α) : TermElabM α :=
withTheReader Core.Context (fun (ctx : Core.Context) => { ctx with options := pp.macroStack.set ctx.options false }) x
namespace ContainsPendingMVar
abbrev M := MonadCacheT Expr Unit (OptionT TermElabM)
/-- See `containsPostponedTerm` -/
partial def visit (e : Expr) : M Unit := do
checkCache e fun _ => do
match e with
| .forallE _ d b _ => visit d; visit b
| .lam _ d b _ => visit d; visit b
| .letE _ t v b _ => visit t; visit v; visit b
| .app f a => visit f; visit a
| .mdata _ b => visit b
| .proj _ _ b => visit b
| .fvar fvarId .. =>
match (← fvarId.getDecl) with
| .cdecl .. => return ()
| .ldecl (value := v) .. => visit v
| .mvar mvarId .. =>
let e' ← instantiateMVars e
if e' != e then
visit e'
else
match (← getDelayedMVarAssignment? mvarId) with
| some d => visit (mkMVar d.mvarIdPending)
| none => failure
| _ => return ()
end ContainsPendingMVar
/-- Return `true` if `e` contains a pending metavariable. Remark: it also visits let-declarations. -/
def containsPendingMVar (e : Expr) : TermElabM Bool := do
match (← ContainsPendingMVar.visit e |>.run.run) with
| some _ => return false
| none => return true
/--
Try to synthesize metavariable using type class resolution.
This method assumes the local context and local instances of `instMVar` coincide
with the current local context and local instances.
Return `true` if the instance was synthesized successfully, and `false` if
the instance contains unassigned metavariables that are blocking the type class
resolution procedure. Throw an exception if resolution or assignment irrevocably fails.
-/
def synthesizeInstMVarCore (instMVar : MVarId) (maxResultSize? : Option Nat := none) : TermElabM Bool := do
let instMVarDecl ← getMVarDecl instMVar
let type := instMVarDecl.type
let type ← instantiateMVars type
let result ← trySynthInstance type maxResultSize?
match result with
| LOption.some val =>
if (← instMVar.isAssigned) then
let oldVal ← instantiateMVars (mkMVar instMVar)
unless (← isDefEq oldVal val) do
if (← containsPendingMVar oldVal <||> containsPendingMVar val) then
/- If `val` or `oldVal` contains metavariables directly or indirectly (e.g., in a let-declaration),
we return `false` to indicate we should try again later. This is very course grain since
the metavariable may not be responsible for the failure. We should refine the test in the future if needed.
This check has been added to address dependencies between postponed metavariables. The following
example demonstrates the issue fixed by this test.
```
structure Point where
x : Nat
y : Nat
def Point.compute (p : Point) : Point :=
let p := { p with x := 1 }
let p := { p with y := 0 }
if (p.x - p.y) > p.x then p else p
```
The `isDefEq` test above fails for `Decidable (p.x - p.y ≤ p.x)` when the structure instance assigned to
`p` has not been elaborated yet.
-/
return false -- we will try again later
let oldValType ← inferType oldVal
let valType ← inferType val
unless (← isDefEq oldValType valType) do
throwError "synthesized type class instance type is not definitionally equal to expected type, synthesized{indentExpr val}\nhas type{indentExpr valType}\nexpected{indentExpr oldValType}"
throwError "synthesized type class instance is not definitionally equal to expression inferred by typing rules, synthesized{indentExpr val}\ninferred{indentExpr oldVal}"
else
unless (← isDefEq (mkMVar instMVar) val) do
throwError "failed to assign synthesized type class instance{indentExpr val}"
return true
| .undef => return false -- we will try later
| .none =>
if (← read).ignoreTCFailures then
return false
else
throwError "failed to synthesize instance{indentExpr type}"
register_builtin_option autoLift : Bool := {
defValue := true
descr := "insert monadic lifts (i.e., `liftM` and coercions) when needed"
}
register_builtin_option maxCoeSize : Nat := {
defValue := 16
descr := "maximum number of instances used to construct an automatic coercion"
}
def synthesizeCoeInstMVarCore (instMVar : MVarId) : TermElabM Bool := do
synthesizeInstMVarCore instMVar (some (maxCoeSize.get (← getOptions)))
/--
The coercion from `α` to `Thunk α` cannot be implemented using an instance because it would
eagerly evaluate `e`
-/
def tryCoeThunk? (expectedType : Expr) (eType : Expr) (e : Expr) : TermElabM (Option Expr) := do
match expectedType with
| .app (.const ``Thunk u) arg =>
if (← isDefEq eType arg) then
return some (mkApp2 (mkConst ``Thunk.mk u) arg (mkSimpleThunk e))
else
return none
| _ =>
return none
def mkCoe (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr := none) (errorMsgHeader? : Option String := none) : TermElabM Expr := do
let u ← getLevel eType
let v ← getLevel expectedType
let coeTInstType := mkAppN (mkConst ``CoeT [u, v]) #[eType, e, expectedType]
let mvar ← mkFreshExprMVar coeTInstType MetavarKind.synthetic
let eNew := mkAppN (mkConst ``CoeT.coe [u, v]) #[eType, e, expectedType, mvar]
let mvarId := mvar.mvarId!
try
withoutMacroStackAtErr do
if (← synthesizeCoeInstMVarCore mvarId) then
expandCoe eNew
else
-- We create an auxiliary metavariable to represent the result, because we need to execute `expandCoe`
-- after we syntheze `mvar`
let mvarAux ← mkFreshExprMVar expectedType MetavarKind.syntheticOpaque
registerSyntheticMVarWithCurrRef mvarAux.mvarId! (SyntheticMVarKind.coe errorMsgHeader? eNew expectedType eType e f?)
return mvarAux
catch
| .error _ msg => throwTypeMismatchError errorMsgHeader? expectedType eType e f? msg
| _ => throwTypeMismatchError errorMsgHeader? expectedType eType e f?
/--
Try to apply coercion to make sure `e` has type `expectedType`.
Relevant definitions:
```
class CoeT (α : Sort u) (a : α) (β : Sort v)
abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β
```
-/
private def tryCoe (errorMsgHeader? : Option String) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr) : TermElabM Expr := do
if (← isDefEq expectedType eType) then
return e
else match (← tryCoeThunk? expectedType eType e) with
| some r => return r
| none => trace[Elab.coe] "adding coercion for {e} : {eType} =?= {expectedType}"; mkCoe expectedType eType e f? errorMsgHeader?
/-- Return `some (m, α)` if `type` can be reduced to an application of the form `m α` using `[reducible]` transparency. -/
def isTypeApp? (type : Expr) : TermElabM (Option (Expr × Expr)) := do
let type ← withReducible <| whnf type
match type with
| .app m α => return some ((← instantiateMVars m), (← instantiateMVars α))
| _ => return none
/-- Helper method used to implement auto-lift and coercions -/
private def synthesizeInst (type : Expr) : TermElabM Expr := do
let type ← instantiateMVars type
match (← trySynthInstance type) with
| .some val => return val
-- Note that `ignoreTCFailures` is not checked here since it must return a result.
| .undef => throwError "failed to synthesize instance{indentExpr type}"
| .none => throwError "failed to synthesize instance{indentExpr type}"
/--
Return `true` if `type` is of the form `m α` where `m` is a `Monad`.
Note that we reduce `type` using transparency `[reducible]`.
-/
def isMonadApp (type : Expr) : TermElabM Bool := do
let some (m, _) ← isTypeApp? type | return false
return (← isMonad? m) |>.isSome
/--
Try coercions and monad lifts to make sure `e` has type `expectedType`.
If `expectedType` is of the form `n β`, we try monad lifts and other extensions.
Otherwise, we just use the basic `tryCoe`.
Extensions for monads.
1. Try to unify `n` and `m`. If it succeeds, then we use
```
coeM {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] (x : m α) : m β
```
`n` must be a `Monad` to use this one.
2. If there is monad lift from `m` to `n` and we can unify `α` and `β`, we use
```
liftM : ∀ {m : Type u_1 → Type u_2} {n : Type u_1 → Type u_3} [self : MonadLiftT m n] {α : Type u_1}, m α → n α
```
Note that `n` may not be a `Monad` in this case. This happens quite a bit in code such as
```
def g (x : Nat) : IO Nat := do
IO.println x
pure x
def f {m} [MonadLiftT IO m] : m Nat :=
g 10
```
3. If there is a monad lift from `m` to `n` and a coercion from `α` to `β`, we use
```
liftCoeM {m : Type u → Type v} {n : Type u → Type w} {α β : Type u} [MonadLiftT m n] [∀ a, CoeT α a β] [Monad n] (x : m α) : n β
```
Note that approach 3 does not subsume 1 because it is only applicable if there is a coercion from `α` to `β` for all values in `α`.
This is not the case for example for `pure $ x > 0` when the expected type is `IO Bool`. The given type is `IO Prop`, and
we only have a coercion from decidable propositions. Approach 1 works because it constructs the coercion `CoeT (m Prop) (pure $ x > 0) (m Bool)`
using the instance `pureCoeDepProp`.
Note that, approach 2 is more powerful than `tryCoe`.
Recall that type class resolution never assigns metavariables created by other modules.
Now, consider the following scenario
```lean
def g (x : Nat) : IO Nat := ...
deg h (x : Nat) : StateT Nat IO Nat := do
v ← g x;
IO.Println v;
...
```
Let's assume there is no other occurrence of `v` in `h`.
Thus, we have that the expected of `g x` is `StateT Nat IO ?α`,
and the given type is `IO Nat`. So, even if we add a coercion.
```
instance {α m n} [MonadLiftT m n] {α} : Coe (m α) (n α) := ...
```
It is not applicable because TC would have to assign `?α := Nat`.
On the other hand, TC can easily solve `[MonadLiftT IO (StateT Nat IO)]`
since this goal does not contain any metavariables. And then, we
convert `g x` into `liftM $ g x`.
-/
private def tryLiftAndCoe (errorMsgHeader? : Option String) (expectedType : Expr) (eType : Expr) (e : Expr) (f? : Option Expr) : TermElabM Expr := do
let expectedType ← instantiateMVars expectedType
let eType ← instantiateMVars eType
let throwMismatch {α} : TermElabM α := throwTypeMismatchError errorMsgHeader? expectedType eType e f?
let tryCoeSimple : TermElabM Expr :=
tryCoe errorMsgHeader? expectedType eType e f?
let some (n, β) ← isTypeApp? expectedType | tryCoeSimple
let some (m, α) ← isTypeApp? eType | tryCoeSimple
if (← isDefEq m n) then
let some monadInst ← isMonad? n | tryCoeSimple
try expandCoe (← mkAppOptM ``Lean.Internal.coeM #[m, α, β, none, monadInst, e]) catch _ => throwMismatch
else if autoLift.get (← getOptions) then
try
-- Construct lift from `m` to `n`
let monadLiftType ← mkAppM ``MonadLiftT #[m, n]
let monadLiftVal ← synthesizeInst monadLiftType
let u_1 ← getDecLevel α
let u_2 ← getDecLevel eType
let u_3 ← getDecLevel expectedType
let eNew := mkAppN (Lean.mkConst ``liftM [u_1, u_2, u_3]) #[m, n, monadLiftVal, α, e]
let eNewType ← inferType eNew
if (← isDefEq expectedType eNewType) then
return eNew -- approach 2 worked
else
let some monadInst ← isMonad? n | tryCoeSimple
let u ← getLevel α
let v ← getLevel β
let coeTInstType := Lean.mkForall `a BinderInfo.default α <| mkAppN (mkConst ``CoeT [u, v]) #[α, mkBVar 0, β]
let coeTInstVal ← synthesizeInst coeTInstType
let eNew ← expandCoe (mkAppN (Lean.mkConst ``Lean.Internal.liftCoeM [u_1, u_2, u_3]) #[m, n, α, β, monadLiftVal, coeTInstVal, monadInst, e])
let eNewType ← inferType eNew
unless (← isDefEq expectedType eNewType) do throwMismatch
return eNew -- approach 3 worked
catch _ =>
/- If `m` is not a monad, then we try to use `tryCoe?`. -/
tryCoeSimple
else
tryCoeSimple
/--
If `expectedType?` is `some t`, then ensure `t` and `eType` are definitionally equal.
If they are not, then try coercions.
Argument `f?` is used only for generating error messages. -/
def ensureHasTypeAux (expectedType? : Option Expr) (eType : Expr) (e : Expr)
(f? : Option Expr := none) (errorMsgHeader? : Option String := none) : TermElabM Expr := do
match expectedType? with
| none => return e
| some expectedType =>
if (← isDefEq eType expectedType) then
return e
else
tryLiftAndCoe errorMsgHeader? expectedType eType e f?
/--
If `expectedType?` is `some t`, then ensure `t` and type of `e` are definitionally equal.
If they are not, then try coercions. -/
def ensureHasType (expectedType? : Option Expr) (e : Expr) (errorMsgHeader? : Option String := none) : TermElabM Expr :=
match expectedType? with
| none => return e
| _ => do
let eType ← inferType e
ensureHasTypeAux expectedType? eType e none errorMsgHeader?
/--
Create a synthetic sorry for the given expected type. If `expectedType? = none`, then a fresh
metavariable is created to represent the type.
-/
private def mkSyntheticSorryFor (expectedType? : Option Expr) : TermElabM Expr := do
let expectedType ← match expectedType? with
| none => mkFreshTypeMVar
| some expectedType => pure expectedType
mkSyntheticSorry expectedType
/--
Log the given exception, and create an synthetic sorry for representing the failed
elaboration step with exception `ex`.
-/
def exceptionToSorry (ex : Exception) (expectedType? : Option Expr) : TermElabM Expr := do
let syntheticSorry ← mkSyntheticSorryFor expectedType?
logException ex
pure syntheticSorry
/-- If `mayPostpone == true`, throw `Expection.postpone`. -/
def tryPostpone : TermElabM Unit := do
if (← read).mayPostpone then
throwPostpone
/-- Return `true` if `e` reduces (by unfolding only `[reducible]` declarations) to `?m ...` -/
def isMVarApp (e : Expr) : TermElabM Bool :=
return (← whnfR e).getAppFn.isMVar
/-- If `mayPostpone == true` and `e`'s head is a metavariable, throw `Exception.postpone`. -/
def tryPostponeIfMVar (e : Expr) : TermElabM Unit := do
if (← isMVarApp e) then
tryPostpone
/-- If `e? = some e`, then `tryPostponeIfMVar e`, otherwise it is just `tryPostpone`. -/
def tryPostponeIfNoneOrMVar (e? : Option Expr) : TermElabM Unit :=
match e? with
| some e => tryPostponeIfMVar e
| none => tryPostpone
/--
Throws `Exception.postpone`, if `expectedType?` contains unassigned metavariables.
It is a noop if `mayPostpone == false`.
-/
def tryPostponeIfHasMVars? (expectedType? : Option Expr) : TermElabM (Option Expr) := do
tryPostponeIfNoneOrMVar expectedType?
let some expectedType := expectedType? | return none
let expectedType ← instantiateMVars expectedType
if expectedType.hasExprMVar then
tryPostpone
return none
return some expectedType
/--
Throws `Exception.postpone`, if `expectedType?` contains unassigned metavariables.
If `mayPostpone == false`, it throws error `msg`.
-/
def tryPostponeIfHasMVars (expectedType? : Option Expr) (msg : String) : TermElabM Expr := do
let some expectedType ← tryPostponeIfHasMVars? expectedType? |
throwError "{msg}, expected type contains metavariables{indentD expectedType?}"
return expectedType
/--
Save relevant context for term elaboration postponement.
-/
def saveContext : TermElabM SavedContext :=
return {
macroStack := (← read).macroStack
declName? := (← read).declName?
options := (← getOptions)
openDecls := (← getOpenDecls)
errToSorry := (← read).errToSorry
levelNames := (← get).levelNames
}
/--
Execute `x` with the context saved using `saveContext`.
-/
def withSavedContext (savedCtx : SavedContext) (x : TermElabM α) : TermElabM α := do
withReader (fun ctx => { ctx with declName? := savedCtx.declName?, macroStack := savedCtx.macroStack, errToSorry := savedCtx.errToSorry }) <|
withTheReader Core.Context (fun ctx => { ctx with options := savedCtx.options, openDecls := savedCtx.openDecls }) <|
withLevelNames savedCtx.levelNames x
/--
Delay the elaboration of `stx`, and return a fresh metavariable that works a placeholder.
Remark: the caller is responsible for making sure the info tree is properly updated.
This method is used only at `elabUsingElabFnsAux`.
-/
private def postponeElabTermCore (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
trace[Elab.postpone] "{stx} : {expectedType?}"
let mvar ← mkFreshExprMVar expectedType? MetavarKind.syntheticOpaque
registerSyntheticMVar stx mvar.mvarId! (SyntheticMVarKind.postponed (← saveContext))
return mvar
def getSyntheticMVarDecl? (mvarId : MVarId) : TermElabM (Option SyntheticMVarDecl) :=
return (← get).syntheticMVars.find? mvarId
/--
Create an auxiliary annotation to make sure we create a `Info` even if `e` is a metavariable.
See `mkTermInfo`.
We use this functions because some elaboration functions elaborate subterms that may not be immediately
part of the resulting term. Example:
```
let_mvar% ?m := b; wait_if_type_mvar% ?m; body
```
If the type of `b` is not known, then `wait_if_type_mvar% ?m; body` is postponed and just return a fresh
metavariable `?n`. The elaborator for
```
let_mvar% ?m := b; wait_if_type_mvar% ?m; body
```
returns `mkSaveInfoAnnotation ?n` to make sure the info nodes created when elaborating `b` are "saved".
This is a bit hackish, but elaborators like `let_mvar%` are rare.
-/
def mkSaveInfoAnnotation (e : Expr) : Expr :=
if e.isMVar then
mkAnnotation `save_info e
else
e
def isSaveInfoAnnotation? (e : Expr) : Option Expr :=
annotation? `save_info e
partial def removeSaveInfoAnnotation (e : Expr) : Expr :=
match isSaveInfoAnnotation? e with
| some e => removeSaveInfoAnnotation e
| _ => e
/--
Return `some mvarId` if `e` corresponds to a hole that is going to be filled "later" by executing a tactic or resuming elaboration.
We do not save `ofTermInfo` for this kind of node in the `InfoTree`.
-/
def isTacticOrPostponedHole? (e : Expr) : TermElabM (Option MVarId) := do
match e with
| Expr.mvar mvarId =>
match (← getSyntheticMVarDecl? mvarId) with
| some { kind := .tactic .., .. } => return mvarId
| some { kind := .postponed .., .. } => return mvarId
| _ => return none
| _ => pure none
def mkTermInfo (elaborator : Name) (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (isBinder := false) : TermElabM (Sum Info MVarId) := do
match (← isTacticOrPostponedHole? e) with
| some mvarId => return Sum.inr mvarId
| none =>
let e := removeSaveInfoAnnotation e
return Sum.inl <| Info.ofTermInfo { elaborator, lctx := lctx?.getD (← getLCtx), expr := e, stx, expectedType?, isBinder }
def addTermInfo (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (elaborator := Name.anonymous) (isBinder := false) : TermElabM Expr := do
if (← read).inPattern then
return mkPatternWithRef e stx
else
withInfoContext' (pure ()) (fun _ => mkTermInfo elaborator stx e expectedType? lctx? isBinder) |> discard
return e
def addTermInfo' (stx : Syntax) (e : Expr) (expectedType? : Option Expr := none) (lctx? : Option LocalContext := none) (elaborator := Name.anonymous) (isBinder := false) : TermElabM Unit :=
discard <| addTermInfo stx e expectedType? lctx? elaborator isBinder
def withInfoContext' (stx : Syntax) (x : TermElabM Expr) (mkInfo : Expr → TermElabM (Sum Info MVarId)) : TermElabM Expr := do
if (← read).inPattern then
let e ← x
return mkPatternWithRef e stx
else
Elab.withInfoContext' x mkInfo
/--
Postpone the elaboration of `stx`, return a metavariable that acts as a placeholder, and
ensures the info tree is updated and a hole id is introduced.
When `stx` is elaborated, new info nodes are created and attached to the new hole id in the info tree.
-/
def postponeElabTerm (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do
withInfoContext' stx (mkInfo := mkTermInfo .anonymous (expectedType? := expectedType?) stx) do
postponeElabTermCore stx expectedType?
/--
Helper function for `elabTerm` is tries the registered elaboration functions for `stxNode` kind until it finds one that supports the syntax or
an error is found. -/
private def elabUsingElabFnsAux (s : SavedState) (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone : Bool)
: List (KeyedDeclsAttribute.AttributeEntry TermElab) → TermElabM Expr
| [] => do throwError "unexpected syntax{indentD stx}"
| (elabFn::elabFns) =>
try
-- record elaborator in info tree, but only when not backtracking to other elaborators (outer `try`)
withInfoContext' stx (mkInfo := mkTermInfo elabFn.declName (expectedType? := expectedType?) stx)
(try
elabFn.value stx expectedType?
catch ex => match ex with
| .error .. =>
if (← read).errToSorry then
exceptionToSorry ex expectedType?
else
throw ex
| .internal id _ =>
if (← read).errToSorry && id == abortTermExceptionId then
exceptionToSorry ex expectedType?
else if id == unsupportedSyntaxExceptionId then
throw ex -- to outer try
else if catchExPostpone && id == postponeExceptionId then
/- If `elab` threw `Exception.postpone`, we reset any state modifications.
For example, we want to make sure pending synthetic metavariables created by `elab` before
it threw `Exception.postpone` are discarded.
Note that we are also discarding the messages created by `elab`.
For example, consider the expression.
`((f.x a1).x a2).x a3`
Now, suppose the elaboration of `f.x a1` produces an `Exception.postpone`.
Then, a new metavariable `?m` is created. Then, `?m.x a2` also throws `Exception.postpone`
because the type of `?m` is not yet known. Then another, metavariable `?n` is created, and
finally `?n.x a3` also throws `Exception.postpone`. If we did not restore the state, we would
keep "dead" metavariables `?m` and `?n` on the pending synthetic metavariable list. This is
wasteful because when we resume the elaboration of `((f.x a1).x a2).x a3`, we start it from scratch
and new metavariables are created for the nested functions. -/
s.restore
postponeElabTermCore stx expectedType?
else
throw ex)
catch ex => match ex with
| .internal id _ =>
if id == unsupportedSyntaxExceptionId then
s.restore -- also removes the info tree created above
elabUsingElabFnsAux s stx expectedType? catchExPostpone elabFns
else
throw ex
| _ => throw ex
private def elabUsingElabFns (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone : Bool) : TermElabM Expr := do
let s ← saveState
let k := stx.getKind
match termElabAttribute.getEntries (← getEnv) k with
| [] => throwError "elaboration function for '{k}' has not been implemented{indentD stx}"
| elabFns => elabUsingElabFnsAux s stx expectedType? catchExPostpone elabFns
instance : MonadMacroAdapter TermElabM where
getCurrMacroScope := getCurrMacroScope
getNextMacroScope := return (← getThe Core.State).nextMacroScope
setNextMacroScope next := modifyThe Core.State fun s => { s with nextMacroScope := next }
private def isExplicit (stx : Syntax) : Bool :=
match stx with
| `(@$_) => true
| _ => false
private def isExplicitApp (stx : Syntax) : Bool :=
stx.getKind == ``Lean.Parser.Term.app && isExplicit stx[0]
/--
Return true if `stx` if a lambda abstraction containing a `{}` or `[]` binder annotation.
Example: `fun {α} (a : α) => a` -/
private def isLambdaWithImplicit (stx : Syntax) : Bool :=
match stx with
| `(fun $binders* => $_) => binders.raw.any fun b => b.isOfKind ``Lean.Parser.Term.implicitBinder || b.isOfKind `Lean.Parser.Term.instBinder
| _ => false
private partial def dropTermParens : Syntax → Syntax := fun stx =>
match stx with
| `(($stx)) => dropTermParens stx
| _ => stx
private def isHole (stx : Syntax) : Bool :=
match stx with
| `(_) => true
| `(? _) => true
| `(? $_:ident) => true
| _ => false
private def isTacticBlock (stx : Syntax) : Bool :=
match stx with
| `(by $_:tacticSeq) => true
| _ => false
private def isNoImplicitLambda (stx : Syntax) : Bool :=
match stx with
| `(no_implicit_lambda% $_:term) => true
| _ => false
private def isTypeAscription (stx : Syntax) : Bool :=
match stx with
| `(($_ : $_)) => true
| _ => false
def hasNoImplicitLambdaAnnotation (type : Expr) : Bool :=
annotation? `noImplicitLambda type |>.isSome
def mkNoImplicitLambdaAnnotation (type : Expr) : Expr :=
if hasNoImplicitLambdaAnnotation type then
type
else
mkAnnotation `noImplicitLambda type
/-- Block usage of implicit lambdas if `stx` is `@f` or `@f arg1 ...` or `fun` with an implicit binder annotation. -/
def blockImplicitLambda (stx : Syntax) : Bool :=
let stx := dropTermParens stx
-- TODO: make it extensible
isExplicit stx || isExplicitApp stx || isLambdaWithImplicit stx || isHole stx || isTacticBlock stx ||
isNoImplicitLambda stx || isTypeAscription stx
/--
Return normalized expected type if it is of the form `{a : α} → β` or `[a : α] → β` and
`blockImplicitLambda stx` is not true, else return `none`.
Remark: implicit lambdas are not triggered by the strict implicit binder annotation `{{a : α}} → β`
-/
private def useImplicitLambda? (stx : Syntax) (expectedType? : Option Expr) : TermElabM (Option Expr) :=
if blockImplicitLambda stx then
return none
else match expectedType? with
| some expectedType => do
if hasNoImplicitLambdaAnnotation expectedType then
return none
else
let expectedType ← whnfForall expectedType
match expectedType with
| .forallE _ _ _ c =>
if c.isImplicit || c.isInstImplicit then
return some expectedType
else
return none
| _ => return none
| _ => return none
private def decorateErrorMessageWithLambdaImplicitVars (ex : Exception) (impFVars : Array Expr) : TermElabM Exception := do
match ex with
| .error ref msg =>
if impFVars.isEmpty then
return Exception.error ref msg
else
let mut msg := m!"{msg}\nthe following variables have been introduced by the implicit lambda feature"
for impFVar in impFVars do
let auxMsg := m!"{impFVar} : {← inferType impFVar}"
let auxMsg ← addMessageContext auxMsg
msg := m!"{msg}{indentD auxMsg}"
msg := m!"{msg}\nyou can disable implict lambdas using `@` or writing a lambda expression with `\{}` or `[]` binder annotations."
return Exception.error ref msg
| _ => return ex
private def elabImplicitLambdaAux (stx : Syntax) (catchExPostpone : Bool) (expectedType : Expr) (impFVars : Array Expr) : TermElabM Expr := do
let body ← elabUsingElabFns stx expectedType catchExPostpone
try
let body ← ensureHasType expectedType body
let r ← mkLambdaFVars impFVars body
trace[Elab.implicitForall] r
return r
catch ex =>
throw (← decorateErrorMessageWithLambdaImplicitVars ex impFVars)
private partial def elabImplicitLambda (stx : Syntax) (catchExPostpone : Bool) (type : Expr) : TermElabM Expr :=
loop type #[]
where
loop
| type@(.forallE n d b c), fvars =>
if c.isExplicit then
elabImplicitLambdaAux stx catchExPostpone type fvars
else withFreshMacroScope do
let n ← MonadQuotation.addMacroScope n
withLocalDecl n c d fun fvar => do
let type ← whnfForall (b.instantiate1 fvar)
loop type (fvars.push fvar)
| type, fvars =>
elabImplicitLambdaAux stx catchExPostpone type fvars
/-- Main loop for `elabTerm` -/
private partial def elabTermAux (expectedType? : Option Expr) (catchExPostpone : Bool) (implicitLambda : Bool) : Syntax → TermElabM Expr
| .missing => mkSyntheticSorryFor expectedType?
| stx => withFreshMacroScope <| withIncRecDepth do
trace[Elab.step] "expected type: {expectedType?}, term\n{stx}"
checkMaxHeartbeats "elaborator"
withNestedTraces do
let env ← getEnv
match (← liftMacroM (expandMacroImpl? env stx)) with
| some (decl, stxNew?) =>
let stxNew ← liftMacroM <| liftExcept stxNew?
withInfoContext' stx (mkInfo := mkTermInfo decl (expectedType? := expectedType?) stx) <|
withMacroExpansion stx stxNew <|
withRef stxNew <|
elabTermAux expectedType? catchExPostpone implicitLambda stxNew
| _ =>
let implicit? ← if implicitLambda && (← read).implicitLambda then useImplicitLambda? stx expectedType? else pure none
match implicit? with
| some expectedType => elabImplicitLambda stx catchExPostpone expectedType
| none => elabUsingElabFns stx expectedType? catchExPostpone
/-- Store in the `InfoTree` that `e` is a "dot"-completion target. -/
def addDotCompletionInfo (stx : Syntax) (e : Expr) (expectedType? : Option Expr) (field? : Option Syntax := none) : TermElabM Unit := do
addCompletionInfo <| CompletionInfo.dot { expr := e, stx, lctx := (← getLCtx), elaborator := .anonymous, expectedType? } (field? := field?) (expectedType? := expectedType?)
/--
Main function for elaborating terms.
It extracts the elaboration methods from the environment using the node kind.
Recall that the environment has a mapping from `SyntaxNodeKind` to `TermElab` methods.
It creates a fresh macro scope for executing the elaboration method.
All unlogged trace messages produced by the elaboration method are logged using
the position information at `stx`. If the elaboration method throws an `Exception.error` and `errToSorry == true`,
the error is logged and a synthetic sorry expression is returned.
If the elaboration throws `Exception.postpone` and `catchExPostpone == true`,
a new synthetic metavariable of kind `SyntheticMVarKind.postponed` is created, registered,
and returned.
The option `catchExPostpone == false` is used to implement `resumeElabTerm`
to prevent the creation of another synthetic metavariable when resuming the elaboration.
If `implicitLambda == true`, then disable implicit lambdas feature for the given syntax, but not for its subterms.
We use this flag to implement, for example, the `@` modifier. If `Context.implicitLambda == false`, then this parameter has no effect.
-/
def elabTerm (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone := true) (implicitLambda := true) : TermElabM Expr :=
withRef stx <| elabTermAux expectedType? catchExPostpone implicitLambda stx
def elabTermEnsuringType (stx : Syntax) (expectedType? : Option Expr) (catchExPostpone := true) (implicitLambda := true) (errorMsgHeader? : Option String := none) : TermElabM Expr := do
let e ← elabTerm stx expectedType? catchExPostpone implicitLambda
withRef stx <| ensureHasType expectedType? e errorMsgHeader?
/-- Execute `x` and return `some` if no new errors were recorded or exceptions was thrown. Otherwise, return `none` -/
def commitIfNoErrors? (x : TermElabM α) : TermElabM (Option α) := do
let saved ← saveState
Core.resetMessageLog
try
let a ← x
if (← MonadLog.hasErrors) then
restoreState saved
return none
else
Core.setMessageLog (saved.meta.core.messages ++ (← Core.getMessageLog))
return a
catch _ =>
restoreState saved
return none
/-- Adapt a syntax transformation to a regular, term-producing elaborator. -/
def adaptExpander (exp : Syntax → TermElabM Syntax) : TermElab := fun stx expectedType? => do
let stx' ← exp stx
withMacroExpansion stx stx' <| elabTerm stx' expectedType?
/--
Create a new metavariable with the given type, and try to synthesize it.
It type class resolution cannot be executed (e.g., it is stuck because of metavariables in `type`),
register metavariable as a pending one.
-/
def mkInstMVar (type : Expr) : TermElabM Expr := do
let mvar ← mkFreshExprMVar type MetavarKind.synthetic
let mvarId := mvar.mvarId!
unless (← synthesizeInstMVarCore mvarId) do
registerSyntheticMVarWithCurrRef mvarId SyntheticMVarKind.typeClass
return mvar
/--
Relevant definitions:
```
class CoeSort (α : Sort u) (β : outParam (Sort v))
```
-/
private def tryCoeSort (α : Expr) (a : Expr) : TermElabM Expr := do
let β ← mkFreshTypeMVar
let u ← getLevel α
let v ← getLevel β
let coeSortInstType := mkAppN (Lean.mkConst ``CoeSort [u, v]) #[α, β]
let mvar ← mkFreshExprMVar coeSortInstType .synthetic
let mvarId := mvar.mvarId!
try
withoutMacroStackAtErr do
if (← synthesizeCoeInstMVarCore mvarId) then
let result ← expandCoe <| mkAppN (Lean.mkConst ``CoeSort.coe [u, v]) #[α, β, mvar, a]
unless (← isType result) do
throwError "failed to coerce{indentExpr a}\nto a type, after applying `CoeSort.coe`, result is still not a type{indentExpr result}\nthis is often due to incorrect `CoeSort` instances, the synthesized value for{indentExpr coeSortInstType}\nwas{indentExpr mvar}"
return result
else
throwError "type expected"
catch
| .error _ msg => throwError "type expected\n{msg}"
| _ => throwError "type expected"
/--
Make sure `e` is a type by inferring its type and making sure it is a `Expr.sort`
or is unifiable with `Expr.sort`, or can be coerced into one. -/
def ensureType (e : Expr) : TermElabM Expr := do
if (← isType e) then
return e
else
let eType ← inferType e
let u ← mkFreshLevelMVar
if (← isDefEq eType (mkSort u)) then
return e
else
tryCoeSort eType e
/-- Elaborate `stx` and ensure result is a type. -/
def elabType (stx : Syntax) : TermElabM Expr := do
let u ← mkFreshLevelMVar
let type ← elabTerm stx (mkSort u)
withRef stx <| ensureType type
/--
Enable auto-bound implicits, and execute `k` while catching auto bound implicit exceptions. When an exception is caught,
a new local declaration is created, registered, and `k` is tried to be executed again. -/
partial def withAutoBoundImplicit (k : TermElabM α) : TermElabM α := do
let flag := autoImplicit.get (← getOptions)
if flag then
withReader (fun ctx => { ctx with autoBoundImplicit := flag, autoBoundImplicits := {} }) do
let rec loop (s : SavedState) : TermElabM α := do
try
k
catch
| ex => match isAutoBoundImplicitLocalException? ex with
| some n =>
-- Restore state, declare `n`, and try again
s.restore
withLocalDecl n .implicit (← mkFreshTypeMVar) fun x =>
withReader (fun ctx => { ctx with autoBoundImplicits := ctx.autoBoundImplicits.push x } ) do
loop (← saveState)
| none => throw ex
loop (← saveState)
else
k
def withoutAutoBoundImplicit (k : TermElabM α) : TermElabM α := do
withReader (fun ctx => { ctx with autoBoundImplicit := false, autoBoundImplicits := {} }) k
partial def withAutoBoundImplicitForbiddenPred (p : Name → Bool) (x : TermElabM α) : TermElabM α := do
withReader (fun ctx => { ctx with autoBoundImplicitForbidden := fun n => p n || ctx.autoBoundImplicitForbidden n }) x
/--
Collect unassigned metavariables in `type` that are not already in `init` and not satisfying `except`.
-/
partial def collectUnassignedMVars (type : Expr) (init : Array Expr := #[]) (except : MVarId → Bool := fun _ => false)
: TermElabM (Array Expr) := do
let mvarIds ← getMVars type
if mvarIds.isEmpty then
return init
else
go mvarIds.toList init
where
go (mvarIds : List MVarId) (result : Array Expr) : TermElabM (Array Expr) := do
match mvarIds with
| [] => return result
| mvarId :: mvarIds => do
if (← mvarId.isAssigned) then
go mvarIds result
else if result.contains (mkMVar mvarId) || except mvarId then
go mvarIds result
else
let mvarType := (← getMVarDecl mvarId).type
let mvarIdsNew ← getMVars mvarType
let mvarIdsNew := mvarIdsNew.filter fun mvarId => !result.contains (mkMVar mvarId)
if mvarIdsNew.isEmpty then
go mvarIds (result.push (mkMVar mvarId))
else
go (mvarIdsNew.toList ++ mvarId :: mvarIds) result
/--
Return `autoBoundImplicits ++ xs`
This methoid throws an error if a variable in `autoBoundImplicits` depends on some `x` in `xs`.
The `autoBoundImplicits` may contain free variables created by the auto-implicit feature, and unassigned free variables.
It avoids the hack used at `autoBoundImplicitsOld`.
Remark: we cannot simply replace every occurrence of `addAutoBoundImplicitsOld` with this one because a particular
use-case may not be able to handle the metavariables in the array being given to `k`.
-/
def addAutoBoundImplicits (xs : Array Expr) : TermElabM (Array Expr) := do
let autos := (← read).autoBoundImplicits
go autos.toList #[]
where
go (todo : List Expr) (autos : Array Expr) : TermElabM (Array Expr) := do
match todo with
| [] =>
for auto in autos do
if auto.isFVar then
let localDecl ← auto.fvarId!.getDecl
for x in xs do
if (← localDeclDependsOn localDecl x.fvarId!) then
throwError "invalid auto implicit argument '{auto}', it depends on explicitly provided argument '{x}'"
return autos ++ xs
| auto :: todo =>
let autos ← collectUnassignedMVars (← inferType auto) autos
go todo (autos.push auto)
/--
Similar to `autoBoundImplicits`, but immediately if the resulting array of expressions contains metavariables,
it immediately use `mkForallFVars` + `forallBoundedTelescope` to convert them into free variables.
The type `type` is modified during the process if type depends on `xs`.
We use this method to simplify the conversion of code using `autoBoundImplicitsOld` to `autoBoundImplicits`
-/
def addAutoBoundImplicits' (xs : Array Expr) (type : Expr) (k : Array Expr → Expr → TermElabM α) : TermElabM α := do
let xs ← addAutoBoundImplicits xs
if xs.all (·.isFVar) then
k xs type
else
forallBoundedTelescope (← mkForallFVars xs type) xs.size fun xs type => k xs type
def mkAuxName (suffix : Name) : TermElabM Name := do
match (← read).declName? with
| none => throwError "auxiliary declaration cannot be created when declaration name is not available"
| some declName => Lean.mkAuxName (declName ++ suffix) 1
builtin_initialize registerTraceClass `Elab.letrec
/-- Return true if mvarId is an auxiliary metavariable created for compiling `let rec` or it
is delayed assigned to one. -/
def isLetRecAuxMVar (mvarId : MVarId) : TermElabM Bool := do
trace[Elab.letrec] "mvarId: {mkMVar mvarId} letrecMVars: {(← get).letRecsToLift.map (mkMVar $ ·.mvarId)}"
let mvarId ← getDelayedMVarRoot mvarId
trace[Elab.letrec] "mvarId root: {mkMVar mvarId}"
return (← get).letRecsToLift.any (·.mvarId == mvarId)
def resolveLocalName (n : Name) : TermElabM (Option (Expr × List String)) := do
let lctx ← getLCtx
let auxDeclToFullName := (← read).auxDeclToFullName
let currNamespace ← getCurrNamespace
let view := extractMacroScopes n
/- Simple case. "Match" function for regular local declarations. -/
let matchLocaDecl? (localDecl : LocalDecl) (givenName : Name) : Option LocalDecl := do
guard (localDecl.userName == givenName)
return localDecl
/-
"Match" function for auxiliary declarations that correspond to recursive definitions being defined.
This function is used in the first-pass.
Note that we do not check for `localDecl.userName == giveName` in this pass as we do for regular local declarations.
Reason: consider the following example
```
mutual
inductive Foo
| somefoo : Foo | bar : Bar → Foo → Foo
inductive Bar
| somebar : Bar| foobar : Foo → Bar → Bar
end
mutual
private def Foo.toString : Foo → String
| Foo.somefoo => go 2 ++ toString.go 2 ++ Foo.toString.go 2
| Foo.bar b f => toString f ++ Bar.toString b
where
go (x : Nat) := s!"foo {x}"
private def _root_.Ex2.Bar.toString : Bar → String
| Bar.somebar => "bar"
| Bar.foobar f b => Foo.toString f ++ Bar.toString b
end
```
In the example above, we have two local declarations named `toString` in the local context, and
we want the `toString f` to be resolved to `Foo.toString f`
-/
let matchAuxRecDecl? (localDecl : LocalDecl) (fullDeclName : Name) (givenNameView : MacroScopesView) : Option LocalDecl := do
let fullDeclView := extractMacroScopes fullDeclName
/- First cleanup private name annotations -/
let fullDeclView := { fullDeclView with name := (privateToUserName? fullDeclView.name).getD fullDeclView.name }
let fullDeclName := fullDeclView.review
let localDeclNameView := extractMacroScopes localDecl.userName
/- If the current namespace is a prefix of the full declaration name,
we use a relaxed matching test where we must satisfy the following conditions
- The local declaration is a suffix of the given name.
- The given name is a suffix of the full declaration.
Recall the `let rec`/`where` declaration naming convention. For example, suppose we have
```
def Foo.Bla.f ... :=
... go ...
where
go ... := ...
```
The current namespace is `Foo.Bla`, and the full name for `go` is `Foo.Bla.f.g`, but we want to
refer to it using just `go`. It is also accepted to refer to it using `f.go`, `Bla.f.go`, etc.
-/
if currNamespace.isPrefixOf fullDeclName then
/- Relaxed mode that allows us to access `let rec` declarations using shorter names -/
guard (localDeclNameView.isSuffixOf givenNameView)
guard (givenNameView.isSuffixOf fullDeclView)
return localDecl
else
/-
It is the standard algorithm we using at `resolveGlobalName` for processing namespaces.
The current solution also has a limitation when using `def _root_` in a mutual block.
The non `def _root_` declarations may update the namespace. See the following example:
```
mutual
def Foo.f ... := ...
def _root_.g ... := ...
let rec h := ...
...
end
```
`def Foo.f` updates the namespace. Then, even when processing `def _root_.g ...`
the condition `currNamespace.isPrefixOf fullDeclName` does not hold.
This is not a big problem because we are planning to modify how we handle the mutual block in the future.
Note that we don't check for `localDecl.userName == givenName` here.
-/
let rec go (ns : Name) : Option LocalDecl := do
if { givenNameView with name := ns ++ givenNameView.name }.review == fullDeclName then
return localDecl
match ns with
| .str pre .. => go pre
| _ => failure
return (← go currNamespace)
/- Traverse the local context backwards looking for match `givenNameView`.
If `skipAuxDecl` we ignore `auxDecl` local declarations. -/
let findLocalDecl? (givenNameView : MacroScopesView) (skipAuxDecl : Bool) : Option LocalDecl :=
let givenName := givenNameView.review
let localDecl? := lctx.decls.findSomeRev? fun localDecl? => do
let localDecl ← localDecl?
if localDecl.binderInfo == .auxDecl then
guard (not skipAuxDecl)
if let some fullDeclName := auxDeclToFullName.find? localDecl.fvarId then
matchAuxRecDecl? localDecl fullDeclName givenNameView
else
matchLocaDecl? localDecl givenName
else
matchLocaDecl? localDecl givenName
if localDecl?.isSome || skipAuxDecl then
localDecl?
else
-- Search auxDecls again trying an exact match of the given name
lctx.decls.findSomeRev? fun localDecl? => do
let localDecl ← localDecl?
guard (localDecl.binderInfo == .auxDecl)
matchLocaDecl? localDecl givenName
let rec loop (n : Name) (projs : List String) :=
let givenNameView := { view with name := n }
/- We do not consider dot notation for local decls corresponding to recursive functions being defined.
The following example would not be elaborated correctly without this case.
```
def foo.aux := 1
def foo : Nat → Nat
| n => foo.aux -- should not be interpreted as `(foo).bar`
```
-/
match findLocalDecl? givenNameView (skipAuxDecl := not projs.isEmpty) with
| some decl => some (decl.toExpr, projs)
| none => match n with
| .str pre s => loop pre (s::projs)
| _ => none
return loop view.name []
/-- Return true iff `stx` is a `Syntax.ident`, and it is a local variable. -/
def isLocalIdent? (stx : Syntax) : TermElabM (Option Expr) :=
match stx with
| Syntax.ident _ _ val _ => do
let r? ← resolveLocalName val
match r? with
| some (fvar, []) => return some fvar
| _ => return none
| _ => return none
/--
Create an `Expr.const` using the given name and explicit levels.
Remark: fresh universe metavariables are created if the constant has more universe
parameters than `explicitLevels`. -/
def mkConst (constName : Name) (explicitLevels : List Level := []) : TermElabM Expr := do
let cinfo ← getConstInfo constName
if explicitLevels.length > cinfo.levelParams.length then
throwError "too many explicit universe levels for '{constName}'"
else
let numMissingLevels := cinfo.levelParams.length - explicitLevels.length
let us ← mkFreshLevelMVars numMissingLevels
return Lean.mkConst constName (explicitLevels ++ us)
private def mkConsts (candidates : List (Name × List String)) (explicitLevels : List Level) : TermElabM (List (Expr × List String)) := do
candidates.foldlM (init := []) fun result (declName, projs) => do
-- TODO: better suppor for `mkConst` failure. We may want to cache the failures, and report them if all candidates fail.
checkDeprecated declName -- TODO: check is occurring too early if there are multiple alternatives. Fix if it is not ok in practice
let const ← mkConst declName explicitLevels
return (const, projs) :: result
def resolveName (stx : Syntax) (n : Name) (preresolved : List (Name × List String)) (explicitLevels : List Level) (expectedType? : Option Expr := none) : TermElabM (List (Expr × List String)) := do
addCompletionInfo <| CompletionInfo.id stx stx.getId (danglingDot := false) (← getLCtx) expectedType?
if let some (e, projs) ← resolveLocalName n then
unless explicitLevels.isEmpty do
throwError "invalid use of explicit universe parameters, '{e}' is a local"
return [(e, projs)]
-- check for section variable capture by a quotation
let ctx ← read
if let some (e, projs) := preresolved.findSome? fun (n, projs) => ctx.sectionFVars.find? n |>.map (·, projs) then
return [(e, projs)] -- section variables should shadow global decls
if preresolved.isEmpty then
process (← resolveGlobalName n)
else
process preresolved
where
process (candidates : List (Name × List String)) : TermElabM (List (Expr × List String)) := do
if candidates.isEmpty then
if (← read).autoBoundImplicit &&
!(← read).autoBoundImplicitForbidden n &&
isValidAutoBoundImplicitName n (relaxedAutoImplicit.get (← getOptions)) then
throwAutoBoundImplicitLocal n
else
throwError "unknown identifier '{Lean.mkConst n}'"
mkConsts candidates explicitLevels
/--
Similar to `resolveName`, but creates identifiers for the main part and each projection with position information derived from `ident`.
Example: Assume resolveName `v.head.bla.boo` produces `(v.head, ["bla", "boo"])`, then this method produces
`(v.head, id, [f₁, f₂])` where `id` is an identifier for `v.head`, and `f₁` and `f₂` are identifiers for fields `"bla"` and `"boo"`. -/
def resolveName' (ident : Syntax) (explicitLevels : List Level) (expectedType? : Option Expr := none) : TermElabM (List (Expr × Syntax × List Syntax)) := do
match ident with
| .ident _ _ n preresolved =>
let r ← resolveName ident n preresolved explicitLevels expectedType?
r.mapM fun (c, fields) => do
let ids := ident.identComponents (nFields? := fields.length)
return (c, ids.head!, ids.tail!)
| _ => throwError "identifier expected"
def resolveId? (stx : Syntax) (kind := "term") (withInfo := false) : TermElabM (Option Expr) :=
match stx with
| .ident _ _ val preresolved => do
let rs ← try resolveName stx val preresolved [] catch _ => pure []
let rs := rs.filter fun ⟨_, projs⟩ => projs.isEmpty
let fs := rs.map fun (f, _) => f
match fs with
| [] => return none
| [f] =>
let f ← if withInfo then addTermInfo stx f else pure f
return some f
| _ => throwError "ambiguous {kind}, use fully qualified name, possible interpretations {fs}"
| _ => throwError "identifier expected"
def TermElabM.run (x : TermElabM α) (ctx : Context := {}) (s : State := {}) : MetaM (α × State) :=
withConfig setElabConfig (x ctx |>.run s)
@[inline] def TermElabM.run' (x : TermElabM α) (ctx : Context := {}) (s : State := {}) : MetaM α :=
(·.1) <$> x.run ctx s
def TermElabM.toIO (x : TermElabM α)
(ctxCore : Core.Context) (sCore : Core.State)
(ctxMeta : Meta.Context) (sMeta : Meta.State)
(ctx : Context) (s : State) : IO (α × Core.State × Meta.State × State) := do
let ((a, s), sCore, sMeta) ← (x.run ctx s).toIO ctxCore sCore ctxMeta sMeta
return (a, sCore, sMeta, s)
instance [MetaEval α] : MetaEval (TermElabM α) where
eval env opts x _ := do
let x : TermElabM α := do
try x finally
(← Core.getMessageLog).forM fun msg => do IO.println (← msg.toString)
MetaEval.eval env opts (hideUnit := true) <| x.run' {}
/--
Execute `x` and then tries to solve pending universe constraints.
Note that, stuck constraints will not be discarded.
-/
def universeConstraintsCheckpoint (x : TermElabM α) : TermElabM α := do
let a ← x
discard <| processPostponed (mayPostpone := true) (exceptionOnFailure := true)
return a
def expandDeclId (currNamespace : Name) (currLevelNames : List Name) (declId : Syntax) (modifiers : Modifiers) : TermElabM ExpandDeclIdResult := do
let r ← Elab.expandDeclId currNamespace currLevelNames declId modifiers
if (← read).sectionVars.contains r.shortName then
throwError "invalid declaration name '{r.shortName}', there is a section variable with the same name"
return r
/--
Helper function for "embedding" an `Expr` in `Syntax`.
It creates a named hole `?m` and immediately assigns `e` to it.
Examples:
```lean
let e := mkConst ``Nat.zero
`(Nat.succ $(← exprToSyntax e))
```
-/
def exprToSyntax (e : Expr) : TermElabM Term := withFreshMacroScope do
let result ← `(?m)
let eType ← inferType e
let mvar ← elabTerm result eType
mvar.mvarId!.assign e
return result
end Term
open Term in
def withoutModifyingStateWithInfoAndMessages [MonadControlT TermElabM m] [Monad m] (x : m α) : m α := do
controlAt TermElabM fun runInBase => withoutModifyingStateWithInfoAndMessagesImpl <| runInBase x
builtin_initialize
registerTraceClass `Elab.postpone
registerTraceClass `Elab.coe
registerTraceClass `Elab.debug
export Term (TermElabM)
end Lean.Elab
|
ea7f7c64a95c37594fb3e6d160dbb8a46e1e010d
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/tactic/lint/misc.lean
|
3aefc3d101946f7bc0d8de04b8fa5bb4e64a216d
|
[
"Apache-2.0"
] |
permissive
|
robertylewis/mathlib
|
3d16e3e6daf5ddde182473e03a1b601d2810952c
|
1d13f5b932f5e40a8308e3840f96fc882fae01f0
|
refs/heads/master
| 1,651,379,945,369
| 1,644,276,960,000
| 1,644,276,960,000
| 98,875,504
| 0
| 0
|
Apache-2.0
| 1,644,253,514,000
| 1,501,495,700,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 21,178
|
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, Robert Y. Lewis
-/
import data.bool.basic
import meta.rb_map
import tactic.lint.basic
/-!
# Various linters
This file defines several small linters:
- `ge_or_gt` checks that `>` and `≥` do not occur in the statement of theorems.
- `dup_namespace` checks that no declaration has a duplicated namespace such as `list.list.monad`.
- `unused_arguments` checks that definitions and theorems do not have unused arguments.
- `doc_blame` checks that every definition has a documentation string.
- `doc_blame_thm` checks that every theorem has a documentation string (not enabled by default).
- `def_lemma` checks that a declaration is a lemma iff its type is a proposition.
- `check_type` checks that the statement of a declaration is well-typed.
- `check_univs` checks that there are no bad `max u v` universe levels.
- `syn_taut` checks that declarations are not syntactic tautologies.
- `unused_haves_suffices` checks that declarations produced via term mode do not have
ineffectual `have` or `suffices` statements
-/
open tactic expr
/-!
## Linter against use of `>`/`≥`
-/
/-- The names of `≥` and `>`, mostly disallowed in lemma statements -/
private meta def illegal_ge_gt : list name := [`gt, `ge]
set_option eqn_compiler.max_steps 20000
/--
Checks whether `≥` and `>` occurs in an illegal way in the expression.
The main ways we legally use these orderings are:
- `f (≥)`
- `∃ x ≥ t, b`. This corresponds to the expression
`@Exists α (fun (x : α), (@Exists (x > t) (λ (H : x > t), b)))`
This function returns `tt` when it finds `ge`/`gt`, except in the following patterns
(which are the same for `gt`):
- `f (@ge _ _)`
- `f (&0 ≥ y) (λ x : t, b)`
- `λ H : &0 ≥ t, b`
Here `&0` is the 0-th de Bruijn variable.
-/
private meta def contains_illegal_ge_gt : expr → bool
| (const nm us) := if nm ∈ illegal_ge_gt then tt else ff
| (app f e@(app (app (const nm us) tp) tc)) :=
contains_illegal_ge_gt f || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt e
| (app (app custom_binder (app (app (app (app (const nm us) tp) tc) (var 0)) t))
e@(lam var_name bi var_type body)) :=
contains_illegal_ge_gt e || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt e
| (app f x) := contains_illegal_ge_gt f || contains_illegal_ge_gt x
| (lam `H bi type@(app (app (app (app (const nm us) tp) tc) (var 0)) t) body) :=
contains_illegal_ge_gt body || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt type
| (lam var_name bi var_type body) := contains_illegal_ge_gt var_type || contains_illegal_ge_gt body
| (pi `H bi type@(app (app (app (app (const nm us) tp) tc) (var 0)) t) body) :=
contains_illegal_ge_gt body || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt type
| (pi var_name bi var_type body) := contains_illegal_ge_gt var_type || contains_illegal_ge_gt body
| (elet var_name type assignment body) :=
contains_illegal_ge_gt type || contains_illegal_ge_gt assignment || contains_illegal_ge_gt body
| _ := ff
/-- Checks whether a `>`/`≥` is used in the statement of `d`.
It first does a quick check to see if there is any `≥` or `>` in the statement, and then does a
slower check whether the occurrences of `≥` and `>` are allowed.
Currently it checks only the conclusion of the declaration, to eliminate false positive from
binders such as `∀ ε > 0, ...` -/
private meta def ge_or_gt_in_statement (d : declaration) : tactic (option string) :=
return $ if d.type.contains_constant (λ n, n ∈ illegal_ge_gt) &&
contains_illegal_ge_gt d.type
then some "the type contains ≥/>. Use ≤/< instead."
else none
-- TODO: the commented out code also checks for classicality in statements, but needs fixing
-- TODO: this probably needs to also check whether the argument is a variable or @eq <var> _ _
-- meta def illegal_constants_in_statement (d : declaration) : tactic (option string) :=
-- return $ if d.type.contains_constant (λ n, (n.get_prefix = `classical ∧
-- n.last ∈ ["prop_decidable", "dec", "dec_rel", "dec_eq"]) ∨ n ∈ [`gt, `ge])
-- then
-- let illegal1 := [`classical.prop_decidable, `classical.dec, `classical.dec_rel,
-- `classical.dec_eq],
-- illegal2 := [`gt, `ge],
-- occur1 := illegal1.filter (λ n, d.type.contains_constant (eq n)),
-- occur2 := illegal2.filter (λ n, d.type.contains_constant (eq n)) in
-- some $ sformat!"the type contains the following declarations: {occur1 ++ occur2}." ++
-- (if occur1 = [] then "" else " Add decidability type-class arguments instead.") ++
-- (if occur2 = [] then "" else " Use ≤/< instead.")
-- else none
/-- A linter for checking whether illegal constants (≥, >) appear in a declaration's type. -/
@[linter] meta def linter.ge_or_gt : linter :=
{ test := ge_or_gt_in_statement,
auto_decls := ff,
no_errors_found := "Not using ≥/> in declarations.",
errors_found := "The following declarations use ≥/>, probably in a way where we would prefer
to use ≤/< instead. See note [nolint_ge] for more information.",
is_fast := ff }
/--
Currently, the linter forbids the use of `>` and `≥` in definitions and
statements, as they cause problems in rewrites.
They are still allowed in statements such as `bounded (≥)` or `∀ ε > 0` or `⨆ n ≥ m`,
and the linter allows that.
If you write a pattern where you bind two or more variables, like `∃ n m > 0`, the linter will
flag this as illegal, but it is also allowed. In this case, add the line
```
@[nolint ge_or_gt] -- see Note [nolint_ge]
```
-/
library_note "nolint_ge"
/-!
## Linter for duplicate namespaces
-/
/-- Checks whether a declaration has a namespace twice consecutively in its name -/
private meta def dup_namespace (d : declaration) : tactic (option string) :=
is_instance d.to_name >>= λ is_inst,
return $ let nm := d.to_name.components in if nm.chain' (≠) ∨ is_inst then none
else let s := (nm.find $ λ n, nm.count n ≥ 2).iget.to_string in
some $ "The namespace `" ++ s ++ "` is duplicated in the name"
/-- A linter for checking whether a declaration has a namespace twice consecutively in its name. -/
@[linter] meta def linter.dup_namespace : linter :=
{ test := dup_namespace,
auto_decls := ff,
no_errors_found := "No declarations have a duplicate namespace.",
errors_found := "DUPLICATED NAMESPACES IN NAME:" }
attribute [nolint dup_namespace] iff.iff
/-!
## Linter for unused arguments
-/
/-- Auxiliary definition for `check_unused_arguments` -/
private meta def check_unused_arguments_aux : list ℕ → ℕ → ℕ → expr → list ℕ | l n n_max e :=
if n > n_max then l else
if ¬ is_lambda e ∧ ¬ is_pi e then l else
let b := e.binding_body in
let l' := if b.has_var_idx 0 then l else n :: l in check_unused_arguments_aux l' (n+1) n_max b
/-- Check which arguments of a declaration are not used.
Prints a list of natural numbers corresponding to which arguments are not used (e.g.
this outputs [1, 4] if the first and fourth arguments are unused).
Checks both the type and the value of `d` for whether the argument is used
(in rare cases an argument is used in the type but not in the value).
We return [] if the declaration was automatically generated.
We print arguments that are larger than the arity of the type of the declaration
(without unfolding definitions). -/
meta def check_unused_arguments (d : declaration) : option (list ℕ) :=
let l := check_unused_arguments_aux [] 1 d.type.pi_arity d.value in
if l = [] then none else
let l2 := check_unused_arguments_aux [] 1 d.type.pi_arity d.type in
(l.filter $ λ n, n ∈ l2).reverse
/-- Check for unused arguments, and print them with their position, variable name, type and whether
the argument is a duplicate.
See also `check_unused_arguments`.
This tactic additionally filters out all unused arguments of type `parse _`.
We skip all declarations that contain `sorry` in their value. -/
private meta def unused_arguments (d : declaration) : tactic (option string) := do
ff ← d.to_name.contains_sorry | return none,
let ns := check_unused_arguments d,
tt ← return ns.is_some | return none,
let ns := ns.iget,
(ds, _) ← get_pi_binders d.type,
let ns := ns.map (λ n, (n, (ds.nth $ n - 1).iget)),
let ns := ns.filter (λ x, x.2.type.get_app_fn ≠ const `interactive.parse []),
ff ← return ns.empty | return none,
ds' ← ds.mmap pp,
ns ← ns.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt n ++ ": " ++ s ++
(if ds.countp (λ b', b.type = b'.type) ≥ 2 then " (duplicate)" else "")) <$> pp b),
return $ some $ ns.to_string_aux tt
/-- A linter object for checking for unused arguments. This is in the default linter set. -/
@[linter] meta def linter.unused_arguments : linter :=
{ test := unused_arguments,
auto_decls := ff,
no_errors_found := "No unused arguments.",
errors_found := "UNUSED ARGUMENTS." }
attribute [nolint unused_arguments] imp_intro
/-!
## Linter for documentation strings
-/
/-- Reports definitions and constants that are missing doc strings -/
private meta def doc_blame_report_defn : declaration → tactic (option string)
| (declaration.defn n _ _ _ _ _) := doc_string n >> return none <|> return "def missing doc string"
| (declaration.cnst n _ _ _) := doc_string n >> return none <|> return "constant missing doc string"
| _ := return none
/-- Reports definitions and constants that are missing doc strings -/
private meta def doc_blame_report_thm : declaration → tactic (option string)
| (declaration.thm n _ _ _) := doc_string n >> return none <|> return "theorem missing doc string"
| _ := return none
/-- A linter for checking definition doc strings -/
@[linter] meta def linter.doc_blame : linter :=
{ test := λ d, mcond (bnot <$> has_attribute' `instance d.to_name)
(doc_blame_report_defn d) (return none),
auto_decls := ff,
no_errors_found := "No definitions are missing documentation.",
errors_found := "DEFINITIONS ARE MISSING DOCUMENTATION STRINGS:" }
/-- A linter for checking theorem doc strings. This is not in the default linter set. -/
meta def linter.doc_blame_thm : linter :=
{ test := doc_blame_report_thm,
auto_decls := ff,
no_errors_found := "No theorems are missing documentation.",
errors_found := "THEOREMS ARE MISSING DOCUMENTATION STRINGS:",
is_fast := ff }
/-!
## Linter for correct usage of `lemma`/`def`
-/
/--
Checks whether the correct declaration constructor (definition or theorem) by
comparing it to its sort. Instances will not be printed.
This test is not very quick: maybe we can speed-up testing that something is a proposition?
This takes almost all of the execution time.
-/
private meta def incorrect_def_lemma (d : declaration) : tactic (option string) :=
if d.is_constant ∨ d.is_axiom
then return none else do
is_instance_d ← is_instance d.to_name,
if is_instance_d then return none else do
-- the following seems to be a little quicker than `is_prop d.type`.
expr.sort n ← infer_type d.type,
is_pattern ← has_attribute' `pattern d.to_name,
return $
if d.is_theorem ↔ n = level.zero then none
else if d.is_theorem then "is a lemma/theorem, should be a def"
else if is_pattern then none -- declarations with `@[pattern]` are allowed to be a `def`.
else "is a def, should be a lemma/theorem"
/-- A linter for checking whether the correct declaration constructor (definition or theorem)
has been used. -/
@[linter] meta def linter.def_lemma : linter :=
{ test := incorrect_def_lemma,
auto_decls := ff,
no_errors_found := "All declarations correctly marked as def/lemma.",
errors_found := "INCORRECT DEF/LEMMA:" }
/-!
## Linter that checks whether declarations are well-typed
-/
/-- Checks whether the statement of a declaration is well-typed. -/
meta def check_type (d : declaration) : tactic (option string) :=
(type_check d.type >> return none) <|> return "The statement doesn't type-check"
/-- A linter for missing checking whether statements of declarations are well-typed. -/
@[linter]
meta def linter.check_type : linter :=
{ test := check_type,
auto_decls := ff,
no_errors_found :=
"The statements of all declarations type-check with default reducibility settings.",
errors_found := "THE STATEMENTS OF THE FOLLOWING DECLARATIONS DO NOT TYPE-CHECK.
Some definitions in the statement are marked `@[irreducible]`, which means that the statement " ++
"is now ill-formed. It is likely that these definitions were locally marked as `@[reducible]` " ++
"or `@[semireducible]`. This can especially cause problems with type class inference or " ++
"`@[simps]`.",
is_fast := tt }
/-!
## Linter for universe parameters
-/
open native
/--
`univ_params_grouped e` computes for each `level` `u` of `e` the parameters that occur in `u`,
and returns the corresponding set of lists of parameters.
In pseudo-mathematical form, this returns `{ { p : parameter | p ∈ u } | (u : level) ∈ e }`
We use `list name` instead of `name_set`, since `name_set` does not have an order.
It will ignore `nm₀._proof_i` declarations.
-/
meta def expr.univ_params_grouped (e : expr) (nm₀ : name) : rb_set (list name) :=
e.fold mk_rb_set $ λ e n l,
match e with
| e@(sort u) := l.insert u.params.to_list
| e@(const nm us) := if nm.get_prefix = nm₀ ∧ nm.last.starts_with "_proof_" then l else
l.union $ rb_set.of_list $ us.map $ λ u : level, u.params.to_list
| _ := l
end
/--
The good parameters are the parameters that occur somewhere in the `rb_set` as a singleton or
(recursively) with only other good parameters.
All other parameters in the `rb_set` are bad.
-/
meta def bad_params : rb_set (list name) → list name | l :=
let good_levels : name_set :=
l.fold mk_name_set $ λ us prev, if us.length = 1 then prev.insert us.head else prev in
if good_levels.empty then
l.fold [] list.union
else bad_params $ rb_set.of_list $ l.to_list.map $ λ us, us.filter $ λ nm, !good_levels.contains nm
/--
Checks whether all universe levels `u` in the type of `d` are "good".
This means that `u` either occurs in a `level` of `d` by itself, or (recursively)
with only other good levels.
When this fails, usually this means that there is a level `max u v`, where neither `u` nor `v`
occur by themselves in a level. It is ok if *one* of `u` or `v` never occurs alone. For example,
`(α : Type u) (β : Type (max u v))` is a occasionally useful method of saying that `β` lives in
a higher universe level than `α`.
-/
meta def check_univs (d : declaration) : tactic (option string) := do
let l := d.type.univ_params_grouped d.to_name,
let bad := bad_params l,
if bad.empty then return none else
return $ some $ "universes " ++ to_string bad ++ " only occur together."
/-- A linter for checking that there are no bad `max u v` universe levels. -/
@[linter]
meta def linter.check_univs : linter :=
{ test := check_univs,
auto_decls := ff,
no_errors_found :=
"All declarations have good universe levels.",
errors_found := "THE STATEMENTS OF THE FOLLOWING DECLARATIONS HAVE BAD UNIVERSE LEVELS. " ++
"This usually means that there is a `max u v` in the type where neither `u` nor `v` " ++
"occur by themselves. Solution: Find the type (or type bundled with data) that has this " ++
"universe argument and provide the universe level explicitly. If this happens in an implicit " ++
"argument of the declaration, a better solution is to move this argument to a `variables` " ++
"command (then it's not necessary to provide the universe level).
It is possible that this linter gives a false positive on definitions where the value of the " ++
"definition has the universes occur separately, and the definition will usually be used with " ++
"explicit universe arguments. In this case, feel free to add `@[nolint check_univs]`.",
is_fast := tt }
/-!
## Linter for syntactic tautologies
-/
/--
Checks whether a lemma is a declaration of the form `∀ a b ... z, e₁ = e₂`
where `e₁` and `e₂` are identical exprs.
We call declarations of this form syntactic tautologies.
Such lemmas are (mostly) useless and sometimes introduced unintentionally when proving basic facts
with rfl when elaboration results in a different term than the user intended.
-/
meta def syn_taut (d : declaration) : tactic (option string) :=
(do (el, er) ← d.type.pi_codomain.is_eq,
guardb (el =ₐ er),
return $ some "LHS equals RHS syntactically") <|>
return none
/-- A linter for checking that declarations aren't syntactic tautologies. -/
@[linter]
meta def linter.syn_taut : linter :=
{ test := syn_taut,
auto_decls := ff, -- many false positives with this enabled
no_errors_found :=
"No declarations are syntactic tautologies.",
errors_found := "THE FOLLOWING DECLARATIONS ARE SYNTACTIC TAUTOLOGIES. " ++
"This usually means that they are of the form `∀ a b ... z, e₁ = e₂` where `e₁` and `e₂` are " ++
"identical expressions. We call declarations of this form syntactic tautologies. " ++
"Such lemmas are (mostly) useless and sometimes introduced unintentionally when proving " ++
"basic facts using `rfl`, when elaboration results in a different term than the user intended. " ++
"You should check that the declaration really says what you think it does.",
is_fast := tt }
attribute [nolint syn_taut] rfl
/-!
## Linters for ineffectual have and suffices statements in term mode
-/
/--
Check if an expression contains `var 0` by folding over the expression and matching the binder depth
-/
meta def expr.has_zero_var (e : expr) : bool :=
e.fold ff $ λ e' d res, res || match e' with | var k := k = d | _ := ff end
/--
Return a list of unused have and suffices terms in an expression
-/
meta def find_unused_have_suffices_macros : expr → tactic (list string)
| (app a b) := (++) <$> find_unused_have_suffices_macros a <*> find_unused_have_suffices_macros b
| (lam var_name bi var_type body) := find_unused_have_suffices_macros body
| (pi var_name bi var_type body) := find_unused_have_suffices_macros body
| (elet var_name type assignment body) := (++) <$> find_unused_have_suffices_macros assignment
<*> find_unused_have_suffices_macros body
| m@(macro md [l@(lam ppnm bi vt bd)]) := do -- term mode have statements are tagged with a macro
-- if the macro annotation is `have then this lambda came from a term mode have statement
(++) (if m.is_annotation.iget.fst = `have ∧ ¬bd.has_zero_var then
["unnecessary have " ++ ppnm.to_string ++ " : " ++ vt.to_string]
else []) <$>
find_unused_have_suffices_macros l
| m@(macro md [app l@(lam ppnm bi vt bd) arg]) := do
-- term mode suffices statements are tagged with a macro
-- if the macro annotation is `suffices then this lambda came from a term mode suffices statement
(++) (if m.is_annotation.iget.fst = `suffices ∧ ¬bd.has_zero_var then
["unnecessary suffices " ++ ppnm.to_string ++ " : " ++ vt.to_string]
else []) <$>
((++) <$> find_unused_have_suffices_macros l <*> find_unused_have_suffices_macros arg)
| (macro md l) := list.join <$> l.mmap find_unused_have_suffices_macros
| _ := return []
/--
Return a list of unused have and suffices terms in a declaration
-/
meta def unused_have_of_decl : declaration → tactic (list string)
| (declaration.defn _ _ _ bd _ _) := find_unused_have_suffices_macros bd
| (declaration.thm _ _ _ bd) := find_unused_have_suffices_macros bd.get
| _ := return []
/--
Checks whether a declaration contains term mode have statements that have no effect on the resulting
term.
-/
meta def has_unused_haves_suffices (d : declaration) : tactic (option string) := do
ns ← unused_have_of_decl d,
if ns.length = 0 then
return none
else
return (", ".intercalate (ns.map to_string))
/-- A linter for checking that declarations don't have unused term mode have statements. We do not
tag this as `@[linter]` so that it is not in the default linter set as it is slow and an uncommon
problem. -/
meta def linter.unused_haves_suffices : linter :=
{ test := has_unused_haves_suffices,
auto_decls := ff,
no_errors_found := "No declarations have unused term mode have statements.",
errors_found := "THE FOLLOWING DECLARATIONS HAVE INEFFECTUAL TERM MODE HAVE/SUFFICES BLOCKS. " ++
"In the case of `have` this is a term of the form `have h := foo, bar` where `bar` does not " ++
"refer to `foo`. Such statements have no effect on the generated proof, and can just be " ++
"replaced by `bar`, in addition to being ineffectual, they may make unnecessary assumptions " ++
"in proofs appear as if they are used. " ++
"For `suffices` this is a term of the form `suffices h : foo, proof_of_goal, proof_of_foo` where" ++
" `proof_of_goal` does not refer to `foo`. " ++
"Such statements have no effect on the generated proof, and can just be replaced by " ++
"`proof_of_goal`, in addition to being ineffectual, they may make unnecessary assumptions in " ++
"proofs appear as if they are used. ",
is_fast := ff }
|
8f7a897bb62e7c82e8b0d8ff5fe69760e42b6173
|
f3849be5d845a1cb97680f0bbbe03b85518312f0
|
/library/init/data/option_t.lean
|
3f572a02c8e1311a1efdf82fff054126847d021e
|
[
"Apache-2.0"
] |
permissive
|
bjoeris/lean
|
0ed95125d762b17bfcb54dad1f9721f953f92eeb
|
4e496b78d5e73545fa4f9a807155113d8e6b0561
|
refs/heads/master
| 1,611,251,218,281
| 1,495,337,658,000
| 1,495,337,658,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,092
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.interactive
universes u v
def option_t (m : Type u → Type v) [monad m] (α : Type u) : Type v :=
m (option α)
@[inline] def option_t_bind {m : Type u → Type v} [monad m] {α β : Type u} (a : option_t m α) (b : α → option_t m β)
: option_t m β :=
show m (option β), from
do o ← a,
match o with
| none := return none
| (some a) := b a
end
@[inline] def option_t_return {m : Type u → Type v} [monad m] {α : Type u} (a : α) : option_t m α :=
show m (option α), from
return (some a)
instance {m : Type u → Type v} [monad m] : monad (option_t m) :=
{pure := @option_t_return m _, bind := @option_t_bind m _,
id_map := begin
intros,
simp [option_t_bind, function.comp],
assert h : option_t_bind._match_1 option_t_return = @pure m _ (option α),
{ apply funext, intro s, cases s, refl, refl },
{ simp [h], apply @monad.bind_pure _ (option α) m },
end,
pure_bind := begin
intros,
simp [option_t_bind, option_t_return, monad.pure_bind]
end,
bind_assoc :=
begin
intros,
simp [option_t_bind, option_t_return, monad.bind_assoc],
apply congr_arg, apply funext, intro x,
cases x,
{ simp [option_t_bind, monad.pure_bind] },
{ refl }
end}
def option_t_orelse {m : Type u → Type v} [monad m] {α : Type u} (a : option_t m α) (b : option_t m α) : option_t m α :=
show m (option α), from
do o ← a,
match o with
| none := b
| (some v) := return (some v)
end
def option_t_fail {m : Type u → Type v} [monad m] {α : Type u} : option_t m α :=
show m (option α), from
return none
instance {m : Type u → Type v} [monad m] : alternative (option_t m) :=
{ @option_t.monad m _ with
failure := @option_t_fail m _,
orelse := @option_t_orelse m _ }
def option_t.lift {m : Type u → Type v} [monad m] {α : Type u} (a : m α) : option_t m α :=
(some <$> a : m (option α))
|
f0ba3e321100cada7ba48a031e540c2032722140
|
46125763b4dbf50619e8846a1371029346f4c3db
|
/src/data/finsupp.lean
|
260c88bd60c15f16b79dca8887856465b584300e
|
[
"Apache-2.0"
] |
permissive
|
thjread/mathlib
|
a9d97612cedc2c3101060737233df15abcdb9eb1
|
7cffe2520a5518bba19227a107078d83fa725ddc
|
refs/heads/master
| 1,615,637,696,376
| 1,583,953,063,000
| 1,583,953,063,000
| 246,680,271
| 0
| 0
|
Apache-2.0
| 1,583,960,875,000
| 1,583,960,875,000
| null |
UTF-8
|
Lean
| false
| false
| 67,805
|
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
-/
import data.finset data.set.finite algebra.big_operators algebra.module
/-!
# Type of functions with finite support
For any type `α` and a type `β` with zero, we define the type `finsupp α β` of finitely supported
functions from `α` to `β`, i.e. the functions which are zero everywhere on `α` except on a finite
set. We write this in infix notation as `α →₀ β`.
Functions with finite support provide the basis for the following concrete instances:
* `ℕ →₀ α`: Polynomials (where `α` is a ring)
* `(σ →₀ ℕ) →₀ α`: Multivariate Polynomials (again `α` is a ring, and `σ` are variable names)
* `α →₀ ℕ`: Multisets
* `α →₀ ℤ`: Abelian groups freely generated by `α`
* `β →₀ α`: Linear combinations over `β` where `α` is the scalar ring
Most of the theory assumes that the range is a commutative monoid. This gives us the big sum
operator as a powerful way to construct `finsupp` elements.
A general piece of advice is to not use `α →₀ β` directly, as the type class setup might not be a
good fit. Defining a copy and selecting the instances that are best suited for the application works
better.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## Notation
This file defines `α →₀ β` as notation for `finsupp α β`.
-/
noncomputable theory
open_locale classical
open finset
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Type*}
{α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*}
/-- `finsupp α β`, denoted `α →₀ β`, is the type of functions `f : α → β` such that
`f x = 0` for all but finitely many `x`. -/
structure finsupp (α : Type*) (β : Type*) [has_zero β] :=
(support : finset α)
(to_fun : α → β)
(mem_support_to_fun : ∀a, a ∈ support ↔ to_fun a ≠ 0)
infixr ` →₀ `:25 := finsupp
namespace finsupp
/-! ### Basic declarations about `finsupp` -/
section basic
variable [has_zero β]
instance : has_coe_to_fun (α →₀ β) := ⟨λ_, α → β, to_fun⟩
instance : has_zero (α →₀ β) := ⟨⟨∅, (λ_, 0), λ _, ⟨false.elim, λ H, H rfl⟩⟩⟩
@[simp] lemma zero_apply {a : α} : (0 : α →₀ β) a = 0 :=
rfl
@[simp] lemma support_zero : (0 : α →₀ β).support = ∅ :=
rfl
instance : inhabited (α →₀ β) := ⟨0⟩
@[simp] lemma mem_support_iff {f : α →₀ β} : ∀{a:α}, a ∈ f.support ↔ f a ≠ 0 :=
f.mem_support_to_fun
lemma not_mem_support_iff {f : α →₀ β} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
@[ext]
lemma ext : ∀{f g : α →₀ β}, (∀a, f a = g a) → f = g
| ⟨s, f, hf⟩ ⟨t, g, hg⟩ h :=
begin
have : f = g, { funext a, exact h a },
subst this,
have : s = t, { ext a, exact (hf a).trans (hg a).symm },
subst this
end
lemma ext_iff {f g : α →₀ β} : f = g ↔ (∀a:α, f a = g a) :=
⟨by rintros rfl a; refl, ext⟩
@[simp] lemma support_eq_empty {f : α →₀ β} : f.support = ∅ ↔ f = 0 :=
⟨assume h, ext $ assume a, by_contradiction $ λ H, (finset.ext.1 h a).1 $
mem_support_iff.2 H, by rintro rfl; refl⟩
instance finsupp.decidable_eq [decidable_eq α] [decidable_eq β] : decidable_eq (α →₀ β) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀a∈f.support, f a = g a))
⟨assume ⟨h₁, h₂⟩, ext $ assume a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, by rwa [mem_support_iff, not_not] at h,
have hg : g a = 0, by rwa [h₁, mem_support_iff, not_not] at h,
by rw [hf, hg],
by rintro rfl; exact ⟨rfl, λ _ _, rfl⟩⟩
lemma finite_supp (f : α →₀ β) : set.finite {a | f a ≠ 0} :=
⟨fintype.of_finset f.support (λ _, mem_support_iff)⟩
lemma support_subset_iff {s : set α} {f : α →₀ β} :
↑f.support ⊆ s ↔ (∀a∉s, f a = 0) :=
by simp only [set.subset_def, mem_coe, mem_support_iff];
exact forall_congr (assume a, @not_imp_comm _ _ (classical.dec _) (classical.dec _))
/-- Given `fintype α`, `equiv_fun_on_fintype` is the `equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
def equiv_fun_on_fintype [fintype α] : (α →₀ β) ≃ (α → β) :=
⟨λf a, f a, λf, mk (finset.univ.filter $ λa, f a ≠ 0) f (by simp only [true_and, finset.mem_univ,
iff_self, finset.mem_filter, finset.filter_congr_decidable, forall_true_iff]),
begin intro f, ext a, refl end,
begin intro f, ext a, refl end⟩
end basic
/-! ### Declarations about `single` -/
section single
variables [has_zero β] {a a' : α} {b : β}
/-- `single a b` is the finitely supported function which has
value `b` at `a` and zero otherwise. -/
def single (a : α) (b : β) : α →₀ β :=
⟨if b = 0 then ∅ else finset.singleton a, λ a', if a = a' then b else 0, λ a', begin
by_cases hb : b = 0; by_cases a = a';
simp only [hb, h, if_pos, if_false, mem_singleton],
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨λ _, hb, λ _, rfl⟩ },
{ exact ⟨λ H _, h H.symm, λ H, (H rfl).elim⟩ }
end⟩
lemma single_apply : (single a b : α →₀ β) a' = if a = a' then b else 0 :=
rfl
@[simp] lemma single_eq_same : (single a b : α →₀ β) a = b :=
if_pos rfl
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ β) a' = 0 :=
if_neg h
@[simp] lemma single_zero : (single a 0 : α →₀ β) = 0 :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, single_eq_same, zero_apply] },
{ rw [single_eq_of_ne h, zero_apply] }
end
lemma support_single_ne_zero (hb : b ≠ 0) : (single a b).support = {a} :=
if_neg hb
lemma support_single_subset : (single a b).support ⊆ {a} :=
show ite _ _ _ ⊆ _, by split_ifs; [exact empty_subset _, exact subset.refl _]
lemma injective_single (a : α) : function.injective (single a : β → α →₀ β) :=
assume b₁ b₂ eq,
have (single a b₁ : α →₀ β) a = (single a b₂ : α →₀ β) a, by rw eq,
by rwa [single_eq_same, single_eq_same] at this
lemma single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : β) :
single a₁ b₁ = single a₂ b₂ ↔ ((a₁ = a₂ ∧ b₁ = b₂) ∨ (b₁ = 0 ∧ b₂ = 0)) :=
begin
split,
{ assume eq,
by_cases a₁ = a₂,
{ refine or.inl ⟨h, _⟩,
rwa [h, (injective_single a₂).eq_iff] at eq },
{ rw [ext_iff] at eq,
have h₁ := eq a₁,
have h₂ := eq a₂,
simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (ne.symm h)] at h₁ h₂,
exact or.inr ⟨h₁, h₂.symm⟩ } },
{ rintros (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩),
{ refl },
{ rw [single_zero, single_zero] } }
end
lemma single_right_inj (h : b ≠ 0) :
single a b = single a' b ↔ a = a' :=
⟨λ H, by simpa only [h, single_eq_single_iff,
and_false, or_false, eq_self_iff_true, and_true] using H,
λ H, by rw [H]⟩
lemma single_eq_zero : single a b = 0 ↔ b = 0 :=
⟨λ h, by { rw ext_iff at h, simpa only [single_eq_same, zero_apply] using h a },
λ h, by rw [h, single_zero]⟩
lemma single_swap {α β : Type*} [has_zero β] (a₁ a₂ : α) (b : β) :
(single a₁ b : α → β) a₂ = (single a₂ b : α → β) a₁ :=
by simp only [single_apply]; ac_refl
lemma unique_single [unique α] (x : α →₀ β) : x = single (default α) (x (default α)) :=
by ext i; simp only [unique.eq_default i, single_eq_same]
@[simp] lemma unique_single_eq_iff [unique α] {b' : β} :
single a b = single a' b' ↔ b = b' :=
begin
rw [single_eq_single_iff],
split,
{ rintros (⟨_, rfl⟩ | ⟨rfl, rfl⟩); refl },
{ intro h, left, exact ⟨subsingleton.elim _ _, h⟩ }
end
end single
/-! ### Declarations about `on_finset` -/
section on_finset
variables [has_zero β]
/-- `on_finset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function needs to be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def on_finset (s : finset α) (f : α → β) (hf : ∀a, f a ≠ 0 → a ∈ s) : α →₀ β :=
⟨s.filter (λa, f a ≠ 0), f,
assume a, classical.by_cases
(assume h : f a = 0, by rw mem_filter; exact ⟨and.right, λ H, (H h).elim⟩)
(assume h : f a ≠ 0, by rw mem_filter; simp only [iff_true_intro h, hf a h, true_and])⟩
@[simp] lemma on_finset_apply {s : finset α} {f : α → β} {hf a} :
(on_finset s f hf : α →₀ β) a = f a :=
rfl
@[simp] lemma support_on_finset_subset {s : finset α} {f : α → β} {hf} :
(on_finset s f hf).support ⊆ s :=
filter_subset _
end on_finset
/-! ### Declarations about `map_range` -/
section map_range
variables [has_zero β₁] [has_zero β₂]
/-- The composition of `f : β₁ → β₂` and `g : α →₀ β₁` is
`map_range f hf g : α →₀ β₂`, well-defined when `f 0 = 0`. -/
def map_range (f : β₁ → β₂) (hf : f 0 = 0) (g : α →₀ β₁) : α →₀ β₂ :=
on_finset g.support (f ∘ g) $
assume a, by rw [mem_support_iff, not_imp_not]; exact λ H, (congr_arg f H).trans hf
@[simp] lemma map_range_apply {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {a : α} :
map_range f hf g a = f (g a) :=
rfl
@[simp] lemma map_range_zero {f : β₁ → β₂} {hf : f 0 = 0} : map_range f hf (0 : α →₀ β₁) = 0 :=
ext $ λ a, by simp only [hf, zero_apply, map_range_apply]
lemma support_map_range {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} :
(map_range f hf g).support ⊆ g.support :=
support_on_finset_subset
@[simp] lemma map_range_single {f : β₁ → β₂} {hf : f 0 = 0} {a : α} {b : β₁} :
map_range f hf (single a b) = single a (f b) :=
ext $ λ a', show f (ite _ _ _) = ite _ _ _, by split_ifs; [refl, exact hf]
end map_range
/-! ### Declarations about `emb_domain` -/
section emb_domain
variables [has_zero β]
/-- Given `f : α₁ ↪ α₂` and `v : α₁ →₀ β`, `emb_domain f v : α₂ →₀ β`
is the finitely supported function whose value at `f a : α₂` is `v a`.
For a `b : α₂` outside the range of `f`, it is zero. -/
def emb_domain (f : α₁ ↪ α₂) (v : α₁ →₀ β) : α₂ →₀ β :=
begin
refine ⟨v.support.map f, λa₂,
if h : a₂ ∈ v.support.map f then v (v.support.choose (λa₁, f a₁ = a₂) _) else 0, _⟩,
{ rcases finset.mem_map.1 h with ⟨a, ha, rfl⟩,
exact exists_unique.intro a ⟨ha, rfl⟩ (assume b ⟨_, hb⟩, f.inj hb) },
{ assume a₂,
split_ifs,
{ simp only [h, true_iff, ne.def],
rw [← not_mem_support_iff, not_not],
apply finset.choose_mem },
{ simp only [h, ne.def, ne_self_iff_false] } }
end
lemma support_emb_domain (f : α₁ ↪ α₂) (v : α₁ →₀ β) :
(emb_domain f v).support = v.support.map f :=
rfl
lemma emb_domain_zero (f : α₁ ↪ α₂) : (emb_domain f 0 : α₂ →₀ β) = 0 :=
rfl
lemma emb_domain_apply (f : α₁ ↪ α₂) (v : α₁ →₀ β) (a : α₁) :
emb_domain f v (f a) = v a :=
begin
change dite _ _ _ = _,
split_ifs; rw [finset.mem_map' f] at h,
{ refine congr_arg (v : α₁ → β) (f.inj' _),
exact finset.choose_property (λa₁, f a₁ = f a) _ _ },
{ exact (not_mem_support_iff.1 h).symm }
end
lemma emb_domain_notin_range (f : α₁ ↪ α₂) (v : α₁ →₀ β) (a : α₂) (h : a ∉ set.range f) :
emb_domain f v a = 0 :=
begin
refine dif_neg (mt (assume h, _) h),
rcases finset.mem_map.1 h with ⟨a, h, rfl⟩,
exact set.mem_range_self a
end
lemma emb_domain_inj {f : α₁ ↪ α₂} {l₁ l₂ : α₁ →₀ β} :
emb_domain f l₁ = emb_domain f l₂ ↔ l₁ = l₂ :=
⟨λ h, ext $ λ a, by simpa only [emb_domain_apply] using ext_iff.1 h (f a),
λ h, by rw h⟩
lemma emb_domain_map_range
{β₁ β₂ : Type*} [has_zero β₁] [has_zero β₂]
(f : α₁ ↪ α₂) (g : β₁ → β₂) (p : α₁ →₀ β₁) (hg : g 0 = 0) :
emb_domain f (map_range g hg p) = map_range g hg (emb_domain f p) :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a', rfl⟩,
rw [map_range_apply, emb_domain_apply, emb_domain_apply, map_range_apply] },
{ rw [map_range_apply, emb_domain_notin_range, emb_domain_notin_range, ← hg]; assumption }
end
lemma single_of_emb_domain_single
(l : α₁ →₀ β) (f : α₁ ↪ α₂) (a : α₂) (b : β) (hb : b ≠ 0)
(h : l.emb_domain f = single a b) :
∃ x, l = single x b ∧ f x = a :=
begin
have h_map_support : finset.map f (l.support) = finset.singleton a,
by rw [←support_emb_domain, h, support_single_ne_zero hb]; refl,
have ha : a ∈ finset.map f (l.support),
by simp only [h_map_support, finset.mem_singleton],
rcases finset.mem_map.1 ha with ⟨c, hc₁, hc₂⟩,
use c,
split,
{ ext d,
rw [← emb_domain_apply f l, h],
by_cases h_cases : c = d,
{ simp only [eq.symm h_cases, hc₂, single_eq_same] },
{ rw [single_apply, single_apply, if_neg, if_neg h_cases],
by_contra hfd,
exact h_cases (f.inj (hc₂.trans hfd)) } },
{ exact hc₂ }
end
end emb_domain
/-! ### Declarations about `zip_with` -/
section zip_with
variables [has_zero β] [has_zero β₁] [has_zero β₂]
/-- `zip_with f hf g₁ g₂` is the finitely supported function satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, and it is well-defined when `f 0 0 = 0`. -/
def zip_with (f : β₁ → β₂ → β) (hf : f 0 0 = 0) (g₁ : α →₀ β₁) (g₂ : α →₀ β₂) : (α →₀ β) :=
on_finset (g₁.support ∪ g₂.support) (λa, f (g₁ a) (g₂ a)) $ λ a H,
begin
simp only [mem_union, mem_support_iff, ne], rw [← not_and_distrib],
rintro ⟨h₁, h₂⟩, rw [h₁, h₂] at H, exact H hf
end
@[simp] lemma zip_with_apply
{f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} {a : α} :
zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a) :=
rfl
lemma support_zip_with {f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
support_on_finset_subset
end zip_with
/-! ### Declarations about `erase` -/
section erase
/-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to
`0`. -/
def erase [has_zero β] (a : α) (f : α →₀ β) : α →₀ β :=
⟨f.support.erase a, (λa', if a' = a then 0 else f a'),
assume a', by rw [mem_erase, mem_support_iff]; split_ifs;
[exact ⟨λ H _, H.1 h, λ H, (H rfl).elim⟩,
exact and_iff_right h]⟩
@[simp] lemma support_erase [has_zero β] {a : α} {f : α →₀ β} :
(f.erase a).support = f.support.erase a :=
rfl
@[simp] lemma erase_same [has_zero β] {a : α} {f : α →₀ β} : (f.erase a) a = 0 :=
if_pos rfl
@[simp] lemma erase_ne [has_zero β] {a a' : α} {f : α →₀ β} (h : a' ≠ a) : (f.erase a) a' = f a' :=
if_neg h
end erase
/-!
### Declarations about `sum` and `prod`
In most of this section, the domain `β` is assumed to be an `add_monoid`.
-/
-- [to_additive sum] for finsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g a (f a)` over the support of `f`. -/
def sum [has_zero β] [add_comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.sum (λa, g a (f a))
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive]
def prod [has_zero β] [comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.prod (λa, g a (f a))
@[to_additive]
lemma prod_map_range_index [has_zero β₁] [has_zero β₂] [comm_monoid γ]
{f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {h : α → β₂ → γ} (h0 : ∀a, h a 0 = 1) :
(map_range f hf g).prod h = g.prod (λa b, h a (f b)) :=
finset.prod_subset support_map_range $ λ _ _ H,
by rw [not_mem_support_iff.1 H, h0]
@[to_additive]
lemma prod_zero_index [add_comm_monoid β] [comm_monoid γ] {h : α → β → γ} :
(0 : α →₀ β).prod h = 1 :=
rfl
section nat_sub
instance nat_sub : has_sub (α →₀ ℕ) := ⟨zip_with (λ m n, m - n) (nat.sub_zero 0)⟩
@[simp] lemma nat_sub_apply {g₁ g₂ : α →₀ ℕ} {a : α} :
(g₁ - g₂) a = g₁ a - g₂ a :=
rfl
end nat_sub
section add_monoid
variables [add_monoid β]
@[to_additive]
lemma prod_single_index [comm_monoid γ] {a : α} {b : β} {h : α → β → γ} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
begin
by_cases h : b = 0,
{ simp only [h, h_zero, single_zero]; refl },
{ simp only [finsupp.prod, support_single_ne_zero h, insert_empty_eq_singleton,
prod_singleton, single_eq_same] }
end
instance : has_add (α →₀ β) := ⟨zip_with (+) (add_zero 0)⟩
@[simp] lemma add_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a :=
rfl
lemma support_add {g₁ g₂ : α →₀ β} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
lemma support_add_eq {g₁ g₂ : α →₀ β} (h : disjoint g₁.support g₂.support) :
(g₁ + g₂).support = g₁.support ∪ g₂.support :=
le_antisymm support_zip_with $ assume a ha,
(finset.mem_union.1 ha).elim
(assume ha, have a ∉ g₂.support, from disjoint_left.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, add_zero])
(assume ha, have a ∉ g₁.support, from disjoint_right.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, zero_add])
@[simp] lemma single_add {a : α} {b₁ b₂ : β} : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, add_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [add_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, zero_add] }
end
instance : add_monoid (α →₀ β) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := assume ⟨s, f, hf⟩ ⟨t, g, hg⟩ ⟨u, h, hh⟩, ext $ assume a, add_assoc _ _ _,
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
instance (a : α) : is_add_monoid_hom (λ g : α →₀ β, g a) :=
{ map_add := λ _ _, add_apply, map_zero := zero_apply }
lemma single_add_erase {a : α} {f : α →₀ β} : single a (f a) + f.erase a = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, add_zero]
else by simp only [add_apply, single_eq_of_ne h, zero_add, erase_ne (ne.symm h)]
lemma erase_add_single {a : α} {f : α →₀ β} : f.erase a + single a (f a) = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, zero_add]
else by simp only [add_apply, single_eq_of_ne h, add_zero, erase_ne (ne.symm h)]
@[elab_as_eliminator]
protected theorem induction {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (single a (f a) + f.erase a), by rwa [single_add_erase] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma induction₂ {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (f + single a b)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (f.erase a + single a (f a)), by rwa [erase_add_single] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma map_range_add [add_monoid β₁] [add_monoid β₂]
{f : β₁ → β₂} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ β₁) :
map_range f hf (v₁ + v₂) = map_range f hf v₁ + map_range f hf v₂ :=
ext $ λ a, by simp only [hf', add_apply, map_range_apply]
end add_monoid
instance [add_comm_monoid β] : add_comm_monoid (α →₀ β) :=
{ add_comm := assume ⟨s, f, _⟩ ⟨t, g, _⟩, ext $ assume a, add_comm _ _,
.. finsupp.add_monoid }
instance [add_group β] : add_group (α →₀ β) :=
{ neg := map_range (has_neg.neg) neg_zero,
add_left_neg := assume ⟨s, f, _⟩, ext $ assume x, add_left_neg _,
.. finsupp.add_monoid }
lemma single_multiset_sum [add_comm_monoid β] (s : multiset β) (a : α) :
single a s.sum = (s.map (single a)).sum :=
multiset.induction_on s single_zero $ λ a s ih,
by rw [multiset.sum_cons, single_add, ih, multiset.map_cons, multiset.sum_cons]
lemma single_finset_sum [add_comm_monoid β] (s : finset γ) (f : γ → β) (a : α) :
single a (s.sum f) = s.sum (λb, single a (f b)) :=
begin
transitivity,
apply single_multiset_sum,
rw [multiset.map_map],
refl
end
lemma single_sum [has_zero γ] [add_comm_monoid β] (s : δ →₀ γ) (f : δ → γ → β) (a : α) :
single a (s.sum f) = s.sum (λd c, single a (f d c)) :=
single_finset_sum _ _ _
@[to_additive]
lemma prod_neg_index [add_group β] [comm_monoid γ]
{g : α →₀ β} {h : α → β → γ} (h0 : ∀a, h a 0 = 1) :
(-g).prod h = g.prod (λa b, h a (- b)) :=
prod_map_range_index h0
@[simp] lemma neg_apply [add_group β] {g : α →₀ β} {a : α} : (- g) a = - g a :=
rfl
@[simp] lemma sub_apply [add_group β] {g₁ g₂ : α →₀ β} {a : α} : (g₁ - g₂) a = g₁ a - g₂ a :=
rfl
@[simp] lemma support_neg [add_group β] {f : α →₀ β} : support (-f) = support f :=
finset.subset.antisymm
support_map_range
(calc support f = support (- (- f)) : congr_arg support (neg_neg _).symm
... ⊆ support (- f) : support_map_range)
instance [add_comm_group β] : add_comm_group (α →₀ β) :=
{ add_comm := add_comm, ..finsupp.add_group }
@[simp] lemma sum_apply [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β} {a₂ : α} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(f.support.sum_hom (λf : α →₀ β, f a₂)).symm
lemma support_sum [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → (α →₀ β)} :
(f.sum g).support ⊆ f.support.bind (λa, (g a (f a)).support) :=
have ∀a₁ : α, f.sum (λ (a : α₁) (b : β₁), (g a b) a₁) ≠ 0 →
(∃ (a : α₁), f a ≠ 0 ∧ ¬ (g a (f a)) a₁ = 0),
from assume a₁ h,
let ⟨a, ha, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨a, mem_support_iff.mp ha, ne⟩,
by simpa only [finset.subset_iff, mem_support_iff, finset.mem_bind, sum_apply, exists_prop]
using this
@[simp] lemma sum_zero [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β} :
f.sum (λa b, (0 : γ)) = 0 :=
finset.sum_const_zero
@[simp] lemma sum_add [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β}
{h₁ h₂ : α → β → γ} :
f.sum (λa b, h₁ a b + h₂ a b) = f.sum h₁ + f.sum h₂ :=
finset.sum_add_distrib
@[simp] lemma sum_neg [add_comm_monoid β] [add_comm_group γ] {f : α →₀ β}
{h : α → β → γ} : f.sum (λa b, - h a b) = - f.sum h :=
f.support.sum_hom (@has_neg.neg γ _)
@[simp] lemma sum_sub [add_comm_monoid β] [add_comm_group γ] {f : α →₀ β}
{h₁ h₂ : α → β → γ} :
f.sum (λa b, h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
by rw [sub_eq_add_neg, ←sum_neg, ←sum_add]; refl
@[simp] lemma sum_single [add_comm_monoid β] (f : α →₀ β) :
f.sum single = f :=
have ∀a:α, f.sum (λa' b, ite (a' = a) b 0) =
({a} : finset α).sum (λa', ite (a' = a) (f a') 0),
begin
intro a,
by_cases h : a ∈ f.support,
{ have : (finset.singleton a : finset α) ⊆ f.support,
{ simpa only [finset.subset_iff, mem_singleton, forall_eq] },
refine (finset.sum_subset this (λ _ _ H, _)).symm,
exact if_neg (mt mem_singleton.2 H) },
{ transitivity (f.support.sum (λa, (0 : β))),
{ refine (finset.sum_congr rfl $ λ a' ha', if_neg _),
rintro rfl, exact h ha' },
{ rw [sum_const_zero, insert_empty_eq_singleton, sum_singleton,
if_pos rfl, not_mem_support_iff.1 h] } }
end,
ext $ assume a, by simp only [sum_apply, single_apply, this,
insert_empty_eq_singleton, sum_singleton, if_pos]
@[to_additive]
lemma prod_add_index [add_comm_monoid β] [comm_monoid γ] {f g : α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have f_eq : (f.support ∪ g.support).prod (λa, h a (f a)) = f.prod h,
from (finset.prod_subset (finset.subset_union_left _ _) $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
have g_eq : (f.support ∪ g.support).prod (λa, h a (g a)) = g.prod h,
from (finset.prod_subset (finset.subset_union_right _ _) $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
calc (f + g).support.prod (λa, h a ((f + g) a)) =
(f.support ∪ g.support).prod (λa, h a ((f + g) a)) :
finset.prod_subset support_add $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]
... = (f.support ∪ g.support).prod (λa, h a (f a)) *
(f.support ∪ g.support).prod (λa, h a (g a)) :
by simp only [add_apply, h_add, finset.prod_mul_distrib]
... = _ : by rw [f_eq, g_eq]
lemma sum_sub_index [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
(f - g).sum h = f.sum h - g.sum h :=
have h_zero : ∀a, h a 0 = 0,
from assume a,
have h a (0 - 0) = h a 0 - h a 0, from h_sub a 0 0,
by simpa only [sub_self] using this,
have h_neg : ∀a b, h a (- b) = - h a b,
from assume a b,
have h a (0 - b) = h a 0 - h a b, from h_sub a 0 b,
by simpa only [h_zero, zero_sub] using this,
have h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂,
from assume a b₁ b₂,
have h a (b₁ - (- b₂)) = h a b₁ - h a (- b₂), from h_sub a b₁ (-b₂),
by simpa only [h_neg, sub_neg_eq_add] using this,
calc (f - g).sum h = (f + - g).sum h : rfl
... = f.sum h + - g.sum h : by simp only [sum_add_index h_zero h_add, sum_neg_index h_zero,
h_neg, sum_neg]
... = f.sum h - g.sum h : rfl
@[to_additive]
lemma prod_finset_sum_index [add_comm_monoid β] [comm_monoid γ]
{s : finset ι} {g : ι → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
s.prod (λi, (g i).prod h) = (s.sum g).prod h :=
finset.induction_on s rfl $ λ a s has ih,
by rw [prod_insert has, ih, sum_insert has, prod_add_index h_zero h_add]
@[to_additive]
lemma prod_sum_index
[add_comm_monoid β₁] [add_comm_monoid β] [comm_monoid γ]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
lemma multiset_sum_sum_index
[add_comm_monoid β] [add_comm_monoid γ]
(f : multiset (α →₀ β)) (h : α → β → γ)
(h₀ : ∀a, h a 0 = 0) (h₁ : ∀ (a : α) (b₁ b₂ : β), h a (b₁ + b₂) = h a b₁ + h a b₂) :
(f.sum.sum h) = (f.map $ λg:α →₀ β, g.sum h).sum :=
multiset.induction_on f rfl $ assume a s ih,
by rw [multiset.sum_cons, multiset.map_cons, multiset.sum_cons, sum_add_index h₀ h₁, ih]
lemma multiset_map_sum [has_zero β] {f : α →₀ β} {m : γ → δ} {h : α → β → multiset γ} :
multiset.map m (f.sum h) = f.sum (λa b, (h a b).map m) :=
(f.support.sum_hom _).symm
lemma multiset_sum_sum [has_zero β] [add_comm_monoid γ] {f : α →₀ β} {h : α → β → multiset γ} :
multiset.sum (f.sum h) = f.sum (λa b, multiset.sum (h a b)) :=
(f.support.sum_hom multiset.sum).symm
section map_range
variables
[add_comm_monoid β₁] [add_comm_monoid β₂]
(f : β₁ → β₂) [hf : is_add_monoid_hom f]
instance is_add_monoid_hom_map_range :
is_add_monoid_hom (map_range f hf.map_zero : (α →₀ β₁) → (α →₀ β₂)) :=
{ map_zero := map_range_zero, map_add := λ a b, map_range_add hf.map_add _ _ }
lemma map_range_multiset_sum (m : multiset (α →₀ β₁)) :
map_range f hf.map_zero m.sum = (m.map $ λx, map_range f hf.map_zero x).sum :=
(m.sum_hom (map_range f hf.map_zero)).symm
lemma map_range_finset_sum {ι : Type*} (s : finset ι) (g : ι → (α →₀ β₁)) :
map_range f hf.map_zero (s.sum g) = s.sum (λx, map_range f hf.map_zero (g x)) :=
by rw [finset.sum.equations._eqn_1, map_range_multiset_sum, multiset.map_map]; refl
end map_range
/-! ### Declarations about `map_domain` -/
section map_domain
variables [add_comm_monoid β] {v v₁ v₂ : α →₀ β}
/-- Given `f : α₁ → α₂` and `v : α₁ →₀ β`, `map_domain f v : α₂ →₀ β`
is the finitely supported function whose value at `a : α₂` is the sum
of `v x` over all `x` such that `f x = a`. -/
def map_domain (f : α₁ → α₂) (v : α₁ →₀ β) : α₂ →₀ β :=
v.sum $ λa, single (f a)
lemma map_domain_apply {f : α₁ → α₂} (hf : function.injective f) (x : α₁ →₀ β) (a : α₁) :
map_domain f x (f a) = x a :=
begin
rw [map_domain, sum_apply, sum, finset.sum_eq_single a, single_eq_same],
{ assume b _ hba, exact single_eq_of_ne (hf.ne hba) },
{ simp only [(∉), (≠), not_not, mem_support_iff],
assume h,
rw [h, single_zero],
refl }
end
lemma map_domain_notin_range {f : α₁ → α₂} (x : α₁ →₀ β) (a : α₂) (h : a ∉ set.range f) :
map_domain f x a = 0 :=
begin
rw [map_domain, sum_apply, sum],
exact finset.sum_eq_zero
(assume a' h', single_eq_of_ne $ assume eq, h $ eq ▸ set.mem_range_self _)
end
lemma map_domain_id : map_domain id v = v :=
sum_single _
lemma map_domain_comp {f : α → α₁} {g : α₁ → α₂} :
map_domain (g ∘ f) v = map_domain g (map_domain f v) :=
begin
refine ((sum_sum_index _ _).trans _).symm,
{ intros, exact single_zero },
{ intros, exact single_add },
refine sum_congr rfl (λ _ _, sum_single_index _),
{ exact single_zero }
end
lemma map_domain_single {f : α → α₁} {a : α} {b : β} : map_domain f (single a b) = single (f a) b :=
sum_single_index single_zero
@[simp] lemma map_domain_zero {f : α → α₂} : map_domain f 0 = (0 : α₂ →₀ β) :=
sum_zero_index
lemma map_domain_congr {f g : α → α₂} (h : ∀x∈v.support, f x = g x) :
v.map_domain f = v.map_domain g :=
finset.sum_congr rfl $ λ _ H, by simp only [h _ H]
lemma map_domain_add {f : α → α₂} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
sum_add_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_finset_sum {f : α → α₂} {s : finset ι} {v : ι → α →₀ β} :
map_domain f (s.sum v) = s.sum (λi, map_domain f (v i)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_sum [has_zero β₁] {f : α → α₂} {s : α →₀ β₁} {v : α → β₁ → α →₀ β} :
map_domain f (s.sum v) = s.sum (λa b, map_domain f (v a b)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_support {f : α → α₂} {s : α →₀ β} :
(s.map_domain f).support ⊆ s.support.image f :=
finset.subset.trans support_sum $
finset.subset.trans (finset.bind_mono $ assume a ha, support_single_subset) $
by rw [finset.bind_singleton]; exact subset.refl _
@[to_additive]
lemma prod_map_domain_index [comm_monoid γ] {f : α → α₂} {s : α →₀ β}
{h : α₂ → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(s.map_domain f).prod h = s.prod (λa b, h (f a) b) :=
(prod_sum_index h_zero h_add).trans $ prod_congr rfl $ λ _ _, prod_single_index (h_zero _)
lemma emb_domain_eq_map_domain (f : α₁ ↪ α₂) (v : α₁ →₀ β) :
emb_domain f v = map_domain f v :=
begin
ext a,
by_cases a ∈ set.range f,
{ rcases h with ⟨a, rfl⟩,
rw [map_domain_apply (function.embedding.inj' _), emb_domain_apply] },
{ rw [map_domain_notin_range, emb_domain_notin_range]; assumption }
end
lemma injective_map_domain {f : α₁ → α₂} (hf : function.injective f) :
function.injective (map_domain f : (α₁ →₀ β) → (α₂ →₀ β)) :=
begin
assume v₁ v₂ eq, ext a,
have : map_domain f v₁ (f a) = map_domain f v₂ (f a), { rw eq },
rwa [map_domain_apply hf, map_domain_apply hf] at this,
end
end map_domain
/-! ### Declarations about `comap_domain` -/
section comap_domain
/-- Given `f : α₁ → α₂`, `l : α₂ →₀ γ` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comap_domain f l hf` is the finitely supported function
from `α₁` to `γ` given by composing `l` with `f`. -/
def comap_domain {α₁ α₂ γ : Type*} [has_zero γ]
(f : α₁ → α₂) (l : α₂ →₀ γ) (hf : set.inj_on f (f ⁻¹' l.support.to_set)) : α₁ →₀ γ :=
{ support := l.support.preimage hf,
to_fun := (λ a, l (f a)),
mem_support_to_fun :=
begin
intros a,
simp only [finset.mem_def.symm, finset.mem_preimage],
exact l.mem_support_to_fun (f a),
end }
lemma comap_domain_apply {α₁ α₂ γ : Type*} [has_zero γ]
(f : α₁ → α₂) (l : α₂ →₀ γ) (hf : set.inj_on f (f ⁻¹' l.support.to_set)) (a : α₁) :
comap_domain f l hf a = l (f a) :=
rfl
lemma sum_comap_domain {α₁ α₂ β γ : Type*} [has_zero β] [add_comm_monoid γ]
(f : α₁ → α₂) (l : α₂ →₀ β) (g : α₂ → β → γ)
(hf : set.bij_on f (f ⁻¹' l.support.to_set) l.support.to_set) :
(comap_domain f l hf.inj_on).sum (g ∘ f) = l.sum g :=
begin
unfold sum,
simp only [comap_domain, comap_domain_apply, finset.sum_preimage f _ _ (λ (x : α₂), g x (l x))],
end
lemma eq_zero_of_comap_domain_eq_zero {α₁ α₂ γ : Type*} [add_comm_monoid γ]
(f : α₁ → α₂) (l : α₂ →₀ γ) (hf : set.bij_on f (f ⁻¹' l.support.to_set) l.support.to_set) :
comap_domain f l hf.inj_on = 0 → l = 0 :=
begin
rw [← support_eq_empty, ← support_eq_empty, comap_domain],
simp only [finset.ext, finset.not_mem_empty, iff_false, mem_preimage],
assume h a ha,
cases hf.2.2 ha with b hb,
exact h b (hb.2.symm ▸ ha)
end
lemma map_domain_comap_domain {α₁ α₂ γ : Type*} [add_comm_monoid γ]
(f : α₁ → α₂) (l : α₂ →₀ γ)
(hf : function.injective f) (hl : ↑l.support ⊆ set.range f):
map_domain f (comap_domain f l (hf.inj_on _)) = l :=
begin
ext a,
by_cases h_cases: a ∈ set.range f,
{ rcases set.mem_range.1 h_cases with ⟨b, hb⟩,
rw [hb.symm, map_domain_apply hf, comap_domain_apply] },
{ rw map_domain_notin_range _ _ h_cases,
by_contra h_contr,
apply h_cases (hl $ finset.mem_coe.2 $ mem_support_iff.2 $ λ h, h_contr h.symm) }
end
end comap_domain
/-! ### Declarations about the product of `finsupp`s -/
/-- The product of `f g : α →₀ β` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x + y = a`. (Think of the product of multivariate
polynomials where `α` is the monoid of monomial exponents.) -/
instance [has_add α] [semiring β] : has_mul (α →₀ β) :=
⟨λf g, f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)⟩
lemma mul_def [has_add α] [semiring β] {f g : α →₀ β} :
f * g = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)) :=
rfl
lemma support_mul [has_add α] [semiring β] (a b : α →₀ β) :
(a * b).support ⊆ a.support.bind (λa₁, b.support.bind $ λa₂, {a₁ + a₂}) :=
subset.trans support_sum $ bind_mono $ assume a₁ _,
subset.trans support_sum $ bind_mono $ assume a₂ _, support_single_subset
/-- The unit of the multiplication is `single 0 1`, i.e. the function
that is `1` at `0` and zero elsewhere. -/
instance [has_zero α] [has_zero β] [has_one β] : has_one (α →₀ β) :=
⟨single 0 1⟩
lemma one_def [has_zero α] [has_zero β] [has_one β] : 1 = (single 0 1 : α →₀ β) :=
rfl
/-! ### Declarations about `filter` -/
section filter
section has_zero
variables [has_zero β] (p : α → Prop) (f : α →₀ β)
/-- `filter p f` is the function which is `f a` if `p a` is true and 0 otherwise. -/
def filter (p : α → Prop) (f : α →₀ β) : α →₀ β :=
on_finset f.support (λa, if p a then f a else 0) $ λ a H,
mem_support_iff.2 $ λ h, by rw [h, if_t_t] at H; exact H rfl
@[simp] lemma filter_apply_pos {a : α} (h : p a) : f.filter p a = f a :=
if_pos h
@[simp] lemma filter_apply_neg {a : α} (h : ¬ p a) : f.filter p a = 0 :=
if_neg h
@[simp] lemma support_filter : (f.filter p).support = f.support.filter p :=
finset.ext.mpr $ assume a, if H : p a
then by simp only [mem_support_iff, filter_apply_pos _ _ H, mem_filter, H, and_true]
else by simp only [mem_support_iff, filter_apply_neg _ _ H, mem_filter, H, and_false, ne.def,
ne_self_iff_false]
lemma filter_zero : (0 : α →₀ β).filter p = 0 :=
by rw [← support_eq_empty, support_filter, support_zero, finset.filter_empty]
@[simp] lemma filter_single_of_pos
{a : α} {b : β} (h : p a) : (single a b).filter p = single a b :=
ext $ λ x, begin
by_cases h' : p x,
{ simp only [h', filter_apply_pos] },
{ simp only [h', filter_apply_neg, not_false_iff],
rw single_eq_of_ne, rintro rfl, exact h' h }
end
@[simp] lemma filter_single_of_neg
{a : α} {b : β} (h : ¬ p a) : (single a b).filter p = 0 :=
ext $ λ x, begin
by_cases h' : p x,
{ simp only [h', filter_apply_pos, zero_apply], rw single_eq_of_ne, rintro rfl, exact h h' },
{ simp only [h', finsupp.zero_apply, not_false_iff, filter_apply_neg] }
end
end has_zero
lemma filter_pos_add_filter_neg [add_monoid β] (f : α →₀ β) (p : α → Prop) :
f.filter p + f.filter (λa, ¬ p a) = f :=
ext $ assume a, if H : p a
then by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_not, add_zero]
else by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_false_iff, zero_add]
end filter
/-! ### Declarations about `frange` -/
section frange
variables [has_zero β]
/-- `frange f` is the image of `f` on the support of `f`. -/
def frange (f : α →₀ β) : finset β := finset.image f f.support
theorem mem_frange {f : α →₀ β} {y : β} :
y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y :=
finset.mem_image.trans
⟨λ ⟨x, hx1, hx2⟩, ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩,
λ ⟨hy, x, hx⟩, ⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩
theorem zero_not_mem_frange {f : α →₀ β} : (0:β) ∉ f.frange :=
λ H, (mem_frange.1 H).1 rfl
theorem frange_single {x : α} {y : β} : frange (single x y) ⊆ {y} :=
λ r hr, let ⟨t, ht1, ht2⟩ := mem_frange.1 hr in ht2 ▸
(by rw single_apply at ht2 ⊢; split_ifs at ht2 ⊢; [exact finset.mem_singleton_self _, cc])
end frange
/-! ### Declarations about `subtype_domain` -/
section subtype_domain
variables {α' : Type*} [has_zero δ] {p : α → Prop}
section zero
variables [has_zero β] {v v' : α' →₀ β}
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain (p : α → Prop) (f : α →₀ β) : (subtype p →₀ β) :=
⟨f.support.subtype p, f ∘ subtype.val, λ a, by simp only [mem_subtype, mem_support_iff]⟩
@[simp] lemma support_subtype_domain {f : α →₀ β} :
(subtype_domain p f).support = f.support.subtype p :=
rfl
@[simp] lemma subtype_domain_apply {a : subtype p} {v : α →₀ β} :
(subtype_domain p v) a = v (a.val) :=
rfl
@[simp] lemma subtype_domain_zero : subtype_domain p (0 : α →₀ β) = 0 :=
rfl
@[to_additive]
lemma prod_subtype_domain_index [comm_monoid γ] {v : α →₀ β}
{h : α → β → γ} (hp : ∀x∈v.support, p x) :
(v.subtype_domain p).prod (λa b, h a.1 b) = v.prod h :=
prod_bij (λp _, p.val)
(λ _, mem_subtype.1)
(λ _ _, rfl)
(λ _ _ _ _, subtype.eq)
(λ b hb, ⟨⟨b, hp b hb⟩, mem_subtype.2 hb, rfl⟩)
end zero
section monoid
variables [add_monoid β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_add {v v' : α →₀ β} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ λ _, rfl
instance subtype_domain.is_add_monoid_hom :
is_add_monoid_hom (subtype_domain p : (α →₀ β) → subtype p →₀ β) :=
{ map_add := λ _ _, subtype_domain_add, map_zero := subtype_domain_zero }
@[simp] lemma filter_add {v v' : α →₀ β} :
(v + v').filter p = v.filter p + v'.filter p :=
ext $ λ a, begin
by_cases p a,
{ simp only [h, filter_apply_pos, add_apply] },
{ simp only [h, add_zero, add_apply, not_false_iff, filter_apply_neg] }
end
instance filter.is_add_monoid_hom (p : α → Prop) :
is_add_monoid_hom (filter p : (α →₀ β) → (α →₀ β)) :=
{ map_zero := filter_zero p, map_add := λ x y, filter_add }
end monoid
section comm_monoid
variables [add_comm_monoid β]
lemma subtype_domain_sum {s : finset γ} {h : γ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc, (h c).subtype_domain p) :=
eq.symm (s.sum_hom _)
lemma subtype_domain_finsupp_sum {s : γ →₀ δ} {h : γ → δ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
lemma filter_sum (s : finset γ) (f : γ → α →₀ β) :
(s.sum f).filter p = s.sum (λa, filter p (f a)) :=
(s.sum_hom (filter p)).symm
end comm_monoid
section group
variables [add_group β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_neg {v : α →₀ β} :
(- v).subtype_domain p = - v.subtype_domain p :=
ext $ λ _, rfl
@[simp] lemma subtype_domain_sub {v v' : α →₀ β} :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ λ _, rfl
end group
end subtype_domain
/-! ### Declarations relating `finsupp` to `multiset` -/
section multiset
/-- Given `f : α →₀ ℕ`, `f.to_multiset` is the multiset with multiplicities given by the values of
`f` on the elements of `α`. -/
def to_multiset (f : α →₀ ℕ) : multiset α :=
f.sum (λa n, add_monoid.smul n {a})
lemma to_multiset_zero : (0 : α →₀ ℕ).to_multiset = 0 :=
rfl
lemma to_multiset_add (m n : α →₀ ℕ) :
(m + n).to_multiset = m.to_multiset + n.to_multiset :=
sum_add_index (assume a, add_monoid.zero_smul _) (assume a b₁ b₂, add_monoid.add_smul _ _ _)
lemma to_multiset_single (a : α) (n : ℕ) : to_multiset (single a n) = add_monoid.smul n {a} :=
by rw [to_multiset, sum_single_index]; apply add_monoid.zero_smul
instance is_add_monoid_hom.to_multiset : is_add_monoid_hom (to_multiset : _ → multiset α) :=
{ map_zero := to_multiset_zero, map_add := to_multiset_add }
lemma card_to_multiset (f : α →₀ ℕ) : f.to_multiset.card = f.sum (λa, id) :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.card_zero, sum_zero_index] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.card_add, ih, sum_add_index, to_multiset_single,
sum_single_index, multiset.card_smul, multiset.singleton_eq_singleton,
multiset.card_singleton, mul_one]; intros; refl }
end
lemma to_multiset_map (f : α →₀ ℕ) (g : α → β) :
f.to_multiset.map g = (f.map_domain g).to_multiset :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.map_zero, map_domain_zero, to_multiset_zero] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.map_add, ih, map_domain_add, map_domain_single,
to_multiset_single, to_multiset_add, to_multiset_single,
is_add_monoid_hom.map_smul (multiset.map g)],
refl }
end
lemma prod_to_multiset [comm_monoid α] (f : α →₀ ℕ) :
f.to_multiset.prod = f.prod (λa n, a ^ n) :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.prod_zero, finsupp.prod_zero_index] },
{ assume a n f _ _ ih,
rw [to_multiset_add, multiset.prod_add, ih, to_multiset_single, finsupp.prod_add_index,
finsupp.prod_single_index, multiset.prod_smul, multiset.singleton_eq_singleton,
multiset.prod_singleton],
{ exact pow_zero a },
{ exact pow_zero },
{ exact pow_add } }
end
lemma to_finset_to_multiset (f : α →₀ ℕ) : f.to_multiset.to_finset = f.support :=
begin
refine f.induction _ _,
{ rw [to_multiset_zero, multiset.to_finset_zero, support_zero] },
{ assume a n f ha hn ih,
rw [to_multiset_add, multiset.to_finset_add, ih, to_multiset_single, support_add_eq,
support_single_ne_zero hn, multiset.to_finset_smul _ _ hn,
multiset.singleton_eq_singleton, multiset.to_finset_cons, multiset.to_finset_zero],
refl,
refine disjoint_mono support_single_subset (subset.refl _) _,
rwa [finset.singleton_eq_singleton, finset.singleton_disjoint] }
end
@[simp] lemma count_to_multiset (f : α →₀ ℕ) (a : α) :
f.to_multiset.count a = f a :=
calc f.to_multiset.count a = f.sum (λx n, (add_monoid.smul n {x} : multiset α).count a) :
(f.support.sum_hom $ multiset.count a).symm
... = f.sum (λx n, n * ({x} : multiset α).count a) : by simp only [multiset.count_smul]
... = f.sum (λx n, n * (x :: 0 : multiset α).count a) : rfl
... = f a * (a :: 0 : multiset α).count a : sum_eq_single _
(λ a' _ H, by simp only [multiset.count_cons_of_ne (ne.symm H), multiset.count_zero, mul_zero])
(λ H, by simp only [not_mem_support_iff.1 H, zero_mul])
... = f a : by simp only [multiset.count_singleton, mul_one]
/-- Given `m : multiset α`, `of_multiset m` is the finitely supported function from `α` to `ℕ`
given by the multiplicities of the elements of `α` in `m`. -/
def of_multiset (m : multiset α) : α →₀ ℕ :=
on_finset m.to_finset (λa, m.count a) $ λ a H, multiset.mem_to_finset.2 $
by_contradiction (mt multiset.count_eq_zero.2 H)
@[simp] lemma of_multiset_apply (m : multiset α) (a : α) :
of_multiset m a = m.count a :=
rfl
/-- `equiv_multiset` defines an `equiv` between finitely supported functions
from `α` to `ℕ` and multisets on `α`. -/
def equiv_multiset : (α →₀ ℕ) ≃ (multiset α) :=
⟨ to_multiset, of_multiset,
assume f, finsupp.ext $ λ a, by rw [of_multiset_apply, count_to_multiset],
assume m, multiset.ext.2 $ λ a, by rw [count_to_multiset, of_multiset_apply] ⟩
lemma mem_support_multiset_sum [add_comm_monoid β]
{s : multiset (α →₀ β)} (a : α) :
a ∈ s.sum.support → ∃f∈s, a ∈ (f : α →₀ β).support :=
multiset.induction_on s false.elim
begin
assume f s ih ha,
by_cases a ∈ f.support,
{ exact ⟨f, multiset.mem_cons_self _ _, h⟩ },
{ simp only [multiset.sum_cons, mem_support_iff, add_apply,
not_mem_support_iff.1 h, zero_add] at ha,
rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩,
exact ⟨f', multiset.mem_cons_of_mem h₀, h₁⟩ }
end
lemma mem_support_finset_sum [add_comm_monoid β]
{s : finset γ} {h : γ → α →₀ β} (a : α) (ha : a ∈ (s.sum h).support) : ∃c∈s, a ∈ (h c).support :=
let ⟨f, hf, hfa⟩ := mem_support_multiset_sum a ha in
let ⟨c, hc, eq⟩ := multiset.mem_map.1 hf in
⟨c, hc, eq.symm ▸ hfa⟩
lemma mem_support_single [has_zero β] (a a' : α) (b : β) :
a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 :=
⟨λ H : (a ∈ ite _ _ _), if h : b = 0
then by rw if_pos h at H; exact H.elim
else ⟨by rw if_neg h at H; exact mem_singleton.1 H, h⟩,
λ ⟨h1, h2⟩, show a ∈ ite _ _ _, by rw [if_neg h2]; exact mem_singleton.2 h1⟩
end multiset
/-! ### Declarations about `curry` and `uncurry` -/
section curry_uncurry
/-- Given a finitely supported function `f` from a product type `α × β` to `γ`,
`curry f` is the "curried" finitely supported function from `α` to the type of
finitely supported functions from `β` to `γ`. -/
protected def curry [add_comm_monoid γ]
(f : (α × β) →₀ γ) : α →₀ (β →₀ γ) :=
f.sum $ λp c, single p.1 (single p.2 c)
lemma sum_curry_index
[add_comm_monoid γ] [add_comm_monoid δ]
(f : (α × β) →₀ γ) (g : α → β → γ → δ)
(hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) :
f.curry.sum (λa f, f.sum (g a)) = f.sum (λp c, g p.1 p.2 c) :=
begin
rw [finsupp.curry],
transitivity,
{ exact sum_sum_index (assume a, sum_zero_index)
(assume a b₀ b₁, sum_add_index (assume a, hg₀ _ _) (assume c d₀ d₁, hg₁ _ _ _ _)) },
congr, funext p c,
transitivity,
{ exact sum_single_index sum_zero_index },
exact sum_single_index (hg₀ _ _)
end
/-- Given a finitely supported function `f` from `α` to the type of
finitely supported functions from `β` to `γ`,
`uncurry f` is the "uncurried" finitely supported function from `α × β` to `γ`. -/
protected def uncurry [add_comm_monoid γ] (f : α →₀ (β →₀ γ)) : (α × β) →₀ γ :=
f.sum $ λa g, g.sum $ λb c, single (a, b) c
/-- `finsupp_prod_equiv` defines the `equiv` between `((α × β) →₀ γ)` and `(α →₀ (β →₀ γ))` given by
currying and uncurrying. -/
def finsupp_prod_equiv [add_comm_monoid γ] : ((α × β) →₀ γ) ≃ (α →₀ (β →₀ γ)) :=
by refine ⟨finsupp.curry, finsupp.uncurry, λ f, _, λ f, _⟩; simp only [
finsupp.curry, finsupp.uncurry, sum_sum_index, sum_zero_index, sum_add_index,
sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff,
forall_3_true_iff, prod.mk.eta, (single_sum _ _ _).symm, sum_single]
lemma filter_curry [add_comm_monoid β] (f : α₁ × α₂ →₀ β) (p : α₁ → Prop) :
(f.filter (λa:α₁×α₂, p a.1)).curry = f.curry.filter p :=
begin
rw [finsupp.curry, finsupp.curry, finsupp.sum, finsupp.sum,
@filter_sum _ (α₂ →₀ β) _ p _ f.support _],
rw [support_filter, sum_filter],
refine finset.sum_congr rfl _,
rintros ⟨a₁, a₂⟩ ha,
dsimp only,
split_ifs,
{ rw [filter_apply_pos, filter_single_of_pos]; exact h },
{ rwa [filter_single_of_neg] }
end
lemma support_curry [add_comm_monoid β] (f : α₁ × α₂ →₀ β) :
f.curry.support ⊆ f.support.image prod.fst :=
begin
rw ← finset.bind_singleton,
refine finset.subset.trans support_sum _,
refine finset.bind_mono (assume a _, support_single_subset)
end
end curry_uncurry
/-!
### Declarations related to semirings
When `α` is an `add_monoid` and `β` is a `semiring`, there is a `semiring` instance on
`α →₀ β`.
-/
section
variables [add_monoid α] [semiring β]
-- TODO: the simplifier unfolds 0 in the instance proof!
private lemma zero_mul (f : α →₀ β) : 0 * f = 0 :=
by simp only [mul_def, sum_zero_index]
private lemma mul_zero (f : α →₀ β) : f * 0 = 0 :=
by simp only [mul_def, sum_zero_index, sum_zero]
private lemma left_distrib (a b c : α →₀ β) : a * (b + c) = a * b + a * c :=
by simp only [mul_def, sum_add_index, mul_add, _root_.mul_zero, single_zero, single_add,
eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_add]
private lemma right_distrib (a b c : α →₀ β) : (a + b) * c = a * c + b * c :=
by simp only [mul_def, sum_add_index, add_mul, _root_.mul_zero, _root_.zero_mul, single_zero,
single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_zero, sum_add]
instance : semiring (α →₀ β) :=
{ one := 1,
mul := (*),
one_mul := assume f, by simp only [mul_def, one_def, sum_single_index, _root_.zero_mul,
single_zero, sum_zero, zero_add, one_mul, sum_single],
mul_one := assume f, by simp only [mul_def, one_def, sum_single_index, _root_.mul_zero,
single_zero, sum_zero, add_zero, mul_one, sum_single],
zero_mul := zero_mul,
mul_zero := mul_zero,
mul_assoc := assume f g h, by simp only [mul_def, sum_sum_index, sum_zero_index, sum_add_index,
sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff,
add_mul, mul_add, add_assoc, mul_assoc, _root_.zero_mul, _root_.mul_zero, sum_zero, sum_add],
left_distrib := left_distrib,
right_distrib := right_distrib,
.. finsupp.add_comm_monoid }
end
instance [add_comm_monoid α] [comm_semiring β] : comm_semiring (α →₀ β) :=
{ mul_comm := assume f g,
begin
simp only [mul_def, finsupp.sum, mul_comm],
rw [finset.sum_comm],
simp only [add_comm]
end,
.. finsupp.semiring }
instance [add_monoid α] [ring β] : ring (α →₀ β) :=
{ neg := has_neg.neg,
add_left_neg := add_left_neg,
.. finsupp.semiring }
instance [add_comm_monoid α] [comm_ring β] : comm_ring (α →₀ β) :=
{ mul_comm := mul_comm, .. finsupp.ring}
lemma single_mul_single [has_add α] [semiring β] {a₁ a₂ : α} {b₁ b₂ : β}:
single a₁ b₁ * single a₂ b₂ = single (a₁ + a₂) (b₁ * b₂) :=
(sum_single_index (by simp only [_root_.zero_mul, single_zero, sum_zero])).trans
(sum_single_index (by rw [_root_.mul_zero, single_zero]))
lemma prod_single [add_comm_monoid α] [comm_semiring β]
{s : finset ι} {a : ι → α} {b : ι → β} :
s.prod (λi, single (a i) (b i)) = single (s.sum a) (s.prod b) :=
finset.induction_on s rfl $ λ a s has ih, by rw [prod_insert has, ih,
single_mul_single, sum_insert has, prod_insert has]
section
instance [semiring γ] [add_comm_monoid β] [semimodule γ β] : has_scalar γ (α →₀ β) :=
⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
variables (α β)
@[simp] lemma smul_apply' {R:semiring γ} [add_comm_monoid β] [semimodule γ β]
{a : α} {b : γ} {v : α →₀ β} : (b • v) a = b • (v a) :=
rfl
instance [semiring γ] [add_comm_monoid β] [semimodule γ β] : semimodule γ (α →₀ β) :=
{ smul := (•),
smul_add := λ a x y, ext $ λ _, smul_add _ _ _,
add_smul := λ a x y, ext $ λ _, add_smul _ _ _,
one_smul := λ x, ext $ λ _, one_smul _ _,
mul_smul := λ r s x, ext $ λ _, mul_smul _ _ _,
zero_smul := λ x, ext $ λ _, zero_smul _ _,
smul_zero := λ x, ext $ λ _, smul_zero _ }
instance [ring γ] [add_comm_group β] [module γ β] : module γ (α →₀ β) :=
{ ..finsupp.semimodule α β }
instance [field γ] [add_comm_group β] [vector_space γ β] : vector_space γ (α →₀ β) :=
{ ..finsupp.module α β }
variables {α β}
lemma support_smul {R:semiring γ} [add_comm_monoid β] [semimodule γ β] {b : γ} {g : α →₀ β} :
(b • g).support ⊆ g.support :=
λ a, by simp only [smul_apply', mem_support_iff, ne.def]; exact mt (λ h, h.symm ▸ smul_zero _)
section
variables {α' : Type*} [has_zero δ] {p : α → Prop}
@[simp] lemma filter_smul {R : semiring γ} [add_comm_monoid β] [semimodule γ β]
{b : γ} {v : α →₀ β} : (b • v).filter p = b • v.filter p :=
ext $ λ a, begin
by_cases p a,
{ simp only [h, smul_apply', filter_apply_pos] },
{ simp only [h, smul_apply', not_false_iff, filter_apply_neg, smul_zero] }
end
end
lemma map_domain_smul {α'} {R : semiring γ} [add_comm_monoid β] [semimodule γ β]
{f : α → α'} (b : γ) (v : α →₀ β) : map_domain f (b • v) = b • map_domain f v :=
begin
change map_domain f (map_range _ _ _) = map_range _ _ _,
apply finsupp.induction v, { simp only [map_domain_zero, map_range_zero] },
intros a b v' hv₁ hv₂ IH,
rw [map_range_add, map_domain_add, IH, map_domain_add, map_range_add,
map_range_single, map_domain_single, map_domain_single, map_range_single];
apply smul_add
end
@[simp] lemma smul_single {R : semiring γ} [add_comm_monoid β] [semimodule γ β]
(c : γ) (a : α) (b : β) : c • finsupp.single a b = finsupp.single a (c • b) :=
ext $ λ a', by by_cases a = a';
[{ subst h, simp only [smul_apply', single_eq_same] },
simp only [h, smul_apply', ne.def, not_false_iff, single_eq_of_ne, smul_zero]]
end
@[simp] lemma smul_apply [ring β] {a : α} {b : β} {v : α →₀ β} :
(b • v) a = b • (v a) :=
rfl
lemma sum_smul_index [ring β] [add_comm_monoid γ] {g : α →₀ β} {b : β} {h : α → β → γ}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0
section
variables [semiring β] [semiring γ]
lemma sum_mul (b : γ) (s : α →₀ β) {f : α → β → γ} :
(s.sum f) * b = s.sum (λ a c, (f a (s a)) * b) :=
by simp only [finsupp.sum, finset.sum_mul]
lemma mul_sum (b : γ) (s : α →₀ β) {f : α → β → γ} :
b * (s.sum f) = s.sum (λ a c, b * (f a (s a))) :=
by simp only [finsupp.sum, finset.mul_sum]
protected lemma eq_zero_of_zero_eq_one
(zero_eq_one : (0 : β) = 1) (l : α →₀ β) : l = 0 :=
by ext i; simp only [eq_zero_of_zero_eq_one β zero_eq_one (l i), finsupp.zero_apply]
end
/-- Given an `add_comm_monoid β` and `s : set α`, `restrict_support_equiv` is the `equiv`
between the subtype of finitely supported functions with support contained in `s` and
the type of finitely supported functions from `s`. -/
def restrict_support_equiv [add_comm_monoid β] (s : set α) :
{f : α →₀ β // ↑f.support ⊆ s } ≃ (s →₀ β):=
begin
refine ⟨λf, subtype_domain (λx, x ∈ s) f.1, λ f, ⟨f.map_domain subtype.val, _⟩, _, _⟩,
{ refine set.subset.trans (finset.coe_subset.2 map_domain_support) _,
rw [finset.coe_image, set.image_subset_iff],
exact assume x hx, x.2 },
{ rintros ⟨f, hf⟩,
apply subtype.eq,
ext a,
dsimp only,
refine classical.by_cases (assume h : a ∈ set.range (subtype.val : s → α), _) (assume h, _),
{ rcases h with ⟨x, rfl⟩,
rw [map_domain_apply subtype.val_injective, subtype_domain_apply] },
{ convert map_domain_notin_range _ _ h,
rw [← not_mem_support_iff],
refine mt _ h,
exact assume ha, ⟨⟨a, hf ha⟩, rfl⟩ } },
{ assume f,
ext ⟨a, ha⟩,
dsimp only,
rw [subtype_domain_apply, map_domain_apply subtype.val_injective] }
end
/-- Given `add_comm_monoid β` and `e : α₁ ≃ α₂`, `dom_congr e` is the corresponding `equiv` between
`α₁ →₀ β` and `α₂ →₀ β`. -/
protected def dom_congr [add_comm_monoid β] (e : α₁ ≃ α₂) : (α₁ →₀ β) ≃ (α₂ →₀ β) :=
⟨map_domain e, map_domain e.symm,
begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.symm_apply_apply],
exact map_domain_id
end,
begin
assume v,
simp only [map_domain_comp.symm, (∘), equiv.apply_symm_apply],
exact map_domain_id
end⟩
/-! ### Declarations about sigma types -/
section sigma
variables {αs : ι → Type*} [has_zero β] (l : (Σ i, αs i) →₀ β)
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β` and
an index element `i : ι`, `split l i` is the `i`th component of `l`,
a finitely supported function from `as i` to `β`. -/
def split (i : ι) : αs i →₀ β :=
l.comap_domain (sigma.mk i) (λ x1 x2 _ _ hx, heq_iff_eq.1 (sigma.mk.inj hx).2)
lemma split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ :=
begin
dunfold split,
rw comap_domain_apply
end
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`,
`split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/
def split_support : finset ι := l.support.image sigma.fst
lemma mem_split_support_iff_nonzero (i : ι) :
i ∈ split_support l ↔ split l i ≠ 0 :=
begin
rw [split_support, mem_image, ne.def, ← support_eq_empty, ← ne.def,
← finset.nonempty_iff_ne_empty, split, comap_domain, finset.nonempty],
simp only [exists_prop, finset.mem_preimage, exists_and_distrib_right, exists_eq_right,
mem_support_iff, sigma.exists, ne.def]
end
/-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and
an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a
finitely supported function from the index type `ι` to `γ` given by composing `g i` with
`split l i`. -/
def split_comp [has_zero γ] (g : Π i, (αs i →₀ β) → γ)
(hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ γ :=
{ support := split_support l,
to_fun := λ i, g i (split l i),
mem_support_to_fun :=
begin
intros i,
rw [mem_split_support_iff_nonzero, not_iff_not, hg],
end }
lemma sigma_support : l.support = l.split_support.sigma (λ i, (l.split i).support) :=
by simp only [finset.ext, split_support, split, comap_domain, mem_image,
mem_preimage, sigma.forall, mem_sigma]; tauto
lemma sigma_sum [add_comm_monoid γ] (f : (Σ (i : ι), αs i) → β → γ) :
l.sum f = (split_support l).sum (λ (i : ι), (split l i).sum (λ (a : αs i) b, f ⟨i, a⟩ b)) :=
by simp only [sum, sigma_support, sum_sigma, split_apply]
end sigma
end finsupp
/-! ### Declarations relating `multiset` to `finsupp` -/
namespace multiset
/-- Given a multiset `s`, `s.to_finsupp` returns the finitely supported function on `ℕ` given by
the multiplicities of the elements of `s`. -/
def to_finsupp (s : multiset α) : α →₀ ℕ :=
{ support := s.to_finset,
to_fun := λ a, s.count a,
mem_support_to_fun := λ a,
begin
rw mem_to_finset,
convert not_iff_not_of_iff (count_eq_zero.symm),
rw not_not
end }
@[simp] lemma to_finsupp_support (s : multiset α) :
s.to_finsupp.support = s.to_finset :=
rfl
@[simp] lemma to_finsupp_apply (s : multiset α) (a : α) :
s.to_finsupp a = s.count a :=
rfl
@[simp] lemma to_finsupp_zero :
to_finsupp (0 : multiset α) = 0 :=
finsupp.ext $ λ a, count_zero a
@[simp] lemma to_finsupp_add (s t : multiset α) :
to_finsupp (s + t) = to_finsupp s + to_finsupp t :=
finsupp.ext $ λ a, count_add a s t
lemma to_finsupp_singleton (a : α) :
to_finsupp {a} = finsupp.single a 1 :=
finsupp.ext $ λ b,
if h : a = b then by rw [to_finsupp_apply, finsupp.single_apply, h, if_pos rfl,
singleton_eq_singleton, count_singleton] else
begin
rw [to_finsupp_apply, finsupp.single_apply, if_neg h, count_eq_zero,
singleton_eq_singleton, mem_singleton],
rintro rfl, exact h rfl
end
namespace to_finsupp
instance : is_add_monoid_hom (to_finsupp : multiset α → α →₀ ℕ) :=
{ map_zero := to_finsupp_zero,
map_add := to_finsupp_add }
end to_finsupp
@[simp] lemma to_finsupp_to_multiset (s : multiset α) :
s.to_finsupp.to_multiset = s :=
ext.2 $ λ a, by rw [finsupp.count_to_multiset, to_finsupp_apply]
end multiset
/-! ### Declarations about order(ed) instances on `finsupp` -/
namespace finsupp
variables {σ : Type*}
instance [preorder α] [has_zero α] : preorder (σ →₀ α) :=
{ le := λ f g, ∀ s, f s ≤ g s,
le_refl := λ f s, le_refl _,
le_trans := λ f g h Hfg Hgh s, le_trans (Hfg s) (Hgh s) }
instance [partial_order α] [has_zero α] : partial_order (σ →₀ α) :=
{ le_antisymm := λ f g hfg hgf, ext $ λ s, le_antisymm (hfg s) (hgf s),
.. finsupp.preorder }
instance [ordered_cancel_comm_monoid α] :
add_left_cancel_semigroup (σ →₀ α) :=
{ add_left_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_left_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_comm_monoid α] :
add_right_cancel_semigroup (σ →₀ α) :=
{ add_right_cancel := λ a b c h, ext $ λ s,
by { rw ext_iff at h, exact add_right_cancel (h s) },
.. finsupp.add_monoid }
instance [ordered_cancel_comm_monoid α] :
ordered_cancel_comm_monoid (σ →₀ α) :=
{ add_le_add_left := λ a b h c s, add_le_add_left (h s) (c s),
le_of_add_le_add_left := λ a b c h s, le_of_add_le_add_left (h s),
.. finsupp.add_comm_monoid, .. finsupp.partial_order,
.. finsupp.add_left_cancel_semigroup, .. finsupp.add_right_cancel_semigroup }
lemma le_iff [canonically_ordered_monoid α] (f g : σ →₀ α) :
f ≤ g ↔ ∀ s ∈ f.support, f s ≤ g s :=
⟨λ h s hs, h s,
λ h s, if H : s ∈ f.support then h s H else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩
@[simp] lemma add_eq_zero_iff [canonically_ordered_monoid α] (f g : σ →₀ α) :
f + g = 0 ↔ f = 0 ∧ g = 0 :=
begin
split,
{ assume h,
split,
all_goals
{ ext s,
suffices H : f s + g s = 0,
{ rw add_eq_zero_iff at H, cases H, assumption },
show (f + g) s = 0,
rw h, refl } },
{ rintro ⟨rfl, rfl⟩, rw add_zero }
end
attribute [simp] to_multiset_zero to_multiset_add
@[simp] lemma to_multiset_to_finsupp (f : σ →₀ ℕ) :
f.to_multiset.to_finsupp = f :=
ext $ λ s, by rw [multiset.to_finsupp_apply, count_to_multiset]
lemma to_multiset_strict_mono : strict_mono (@to_multiset σ) :=
λ m n h,
begin
rw lt_iff_le_and_ne at h ⊢, cases h with h₁ h₂,
split,
{ rw multiset.le_iff_count, intro s, erw [count_to_multiset m s, count_to_multiset], exact h₁ s },
{ intro H, apply h₂, replace H := congr_arg multiset.to_finsupp H,
simpa only [to_multiset_to_finsupp] using H }
end
lemma sum_id_lt_of_lt (m n : σ →₀ ℕ) (h : m < n) :
m.sum (λ _, id) < n.sum (λ _, id) :=
begin
rw [← card_to_multiset, ← card_to_multiset],
apply multiset.card_lt_of_lt,
exact to_multiset_strict_mono h
end
variable (σ)
/-- The order on `σ →₀ ℕ` is well-founded.-/
lemma lt_wf : well_founded (@has_lt.lt (σ →₀ ℕ) _) :=
subrelation.wf (sum_id_lt_of_lt) $ inv_image.wf _ nat.lt_wf
instance decidable_le : decidable_rel (@has_le.le (σ →₀ ℕ) _) :=
λ m n, by rw le_iff; apply_instance
variable {σ}
/-- The `finsupp` counterpart of `multiset.antidiagonal`: the antidiagonal of
`s : σ →₀ ℕ` consists of all pairs `(t₁, t₂) : (σ →₀ ℕ) × (σ →₀ ℕ)` such that `t₁ + t₂ = s`.
The finitely supported function `antidiagonal s` is equal to the multiplicities of these pairs. -/
def antidiagonal (f : σ →₀ ℕ) : ((σ →₀ ℕ) × (σ →₀ ℕ)) →₀ ℕ :=
(f.to_multiset.antidiagonal.map (prod.map multiset.to_finsupp multiset.to_finsupp)).to_finsupp
lemma mem_antidiagonal_support {f : σ →₀ ℕ} {p : (σ →₀ ℕ) × (σ →₀ ℕ)} :
p ∈ (antidiagonal f).support ↔ p.1 + p.2 = f :=
begin
erw [multiset.mem_to_finset, multiset.mem_map],
split,
{ rintros ⟨⟨a, b⟩, h, rfl⟩,
rw multiset.mem_antidiagonal at h,
simpa only [to_multiset_to_finsupp, multiset.to_finsupp_add]
using congr_arg multiset.to_finsupp h},
{ intro h,
refine ⟨⟨p.1.to_multiset, p.2.to_multiset⟩, _, _⟩,
{ simpa only [multiset.mem_antidiagonal, to_multiset_add]
using congr_arg to_multiset h},
{ rw [prod.map, to_multiset_to_finsupp, to_multiset_to_finsupp, prod.mk.eta] } }
end
@[simp] lemma antidiagonal_zero : antidiagonal (0 : σ →₀ ℕ) = single (0,0) 1 :=
by rw [← multiset.to_finsupp_singleton]; refl
lemma swap_mem_antidiagonal_support {n : σ →₀ ℕ} {f} (hf : f ∈ (antidiagonal n).support) :
f.swap ∈ (antidiagonal n).support :=
by simpa only [mem_antidiagonal_support, add_comm, prod.swap] using hf
end finsupp
|
11c71b0e00f88124fa657903e5a591f5daeede6e
|
853df553b1d6ca524e3f0a79aedd32dde5d27ec3
|
/src/geometry/manifold/charted_space.lean
|
3ab18e6f002da536422a3e19903f5e5b1bb1756d
|
[
"Apache-2.0"
] |
permissive
|
DanielFabian/mathlib
|
efc3a50b5dde303c59eeb6353ef4c35a345d7112
|
f520d07eba0c852e96fe26da71d85bf6d40fcc2a
|
refs/heads/master
| 1,668,739,922,971
| 1,595,201,756,000
| 1,595,201,756,000
| 279,469,476
| 0
| 0
| null | 1,594,696,604,000
| 1,594,696,604,000
| null |
UTF-8
|
Lean
| false
| false
| 41,874
|
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 topology.local_homeomorph
/-!
# Charted spaces
A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean
half-space for manifolds with boundaries, or an infinite dimensional vector space for more general
notions of manifolds), i.e., the manifold is covered by open subsets on which there are local
homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth
maps.
In this file, we introduce a general framework describing these notions, where the model space is an
arbitrary topological space. We avoid the word *manifold*, which should be reserved for the
situation where the model space is a (subset of a) vector space, and use the terminology
*charted space* instead.
If the changes of charts satisfy some additional property (for instance if they are smooth), then
`M` inherits additional structure (it makes sense to talk about smooth manifolds). There are
therefore two different ingredients in a charted space:
* the set of charts, which is data
* the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop.
We separate these two parts in the definition: the charted space structure is just the set of
charts, and then the different smoothness requirements (smooth manifold, orientable manifold,
contact manifold, and so on) are additional properties of these charts. These properties are
formalized through the notion of structure groupoid, i.e., a set of local homeomorphisms stable
under composition and inverse, to which the change of coordinates should belong.
## Main definitions
* `structure_groupoid H` : a subset of local homeomorphisms of `H` stable under composition,
inverse and restriction (ex: local diffeos).
* `continuous_groupoid H` : the groupoid of all local homeomorphisms of `H`
* `charted_space H M` : charted space structure on `M` modelled on `H`, given by an atlas of
local homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class.
* `has_groupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space
modelled on `H`, require that all coordinate changes belong to `G`. This is a type class.
* `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted
space structure, i.e., the set of charts.
* `G.maximal_atlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a
structure groupoid, one can consider all the local homeomorphisms from `M` to `H` such that
changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the
maximal atlas (for the groupoid `G`).
* `structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for
the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category.
As a basic example, we give the instance
`instance charted_space_model_space (H : Type*) [topological_space H] : charted_space H H`
saying that a topological space is a charted space over itself, with the identity as unique chart.
This charted space structure is compatible with any groupoid.
Additional useful definitions:
* `pregroupoid H` : a subset of local mas of `H` stable under composition and
restriction, but not inverse (ex: smooth maps)
* `groupoid_of_pregroupoid` : construct a groupoid from a pregroupoid, by requiring that a map and
its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps)
* `chart_at H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on
`H`.
* `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition
of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid.
* `G.compatible_of_mem_maximal_atlas he he'` states that, for any two charts `e` and `e'` in the
maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the
`G` if `M` admits `G` as a structure groupoid.
* `charted_space_core.to_charted_space`: consider a space without a topology, but endowed with a set
of charts (which are local equivs) for which the change of coordinates are local homeos. Then
one can construct a topology on the space for which the charts become local homeos, defining
a genuine charted space structure.
## Implementation notes
The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends
on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current
formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas
defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms
between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the
definition is only that, read in charts, the structomorphism locally belongs to the groupoid under
consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas).
A consequence is that the invariance under structomorphisms of properties defined in terms of the
atlas is not obvious in general, and could require some work in theory (amounting to the fact
that these properties only depend on the maximal atlas, for instance). In practice, this does not
create any real difficulty.
We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the
model space is a half space.
Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and
sometimes as spaces with an atlas from which a topology is deduced. We use the former approach:
otherwise, there would be an instance from manifolds to topological spaces, which means that any
instance search for topological spaces would try to find manifold structures involving a yet
unknown model space, leading to problems. However, we also introduce the latter approach,
through a structure `charted_space_core` making it possible to construct a topology out of a set of
local equivs with compatibility conditions (but we do not register it as an instance).
In the definition of a charted space, the model space is written as an explicit parameter as there
can be several model spaces for a given topological space. For instance, a complex manifold
(modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`.
## Notations
In the locale `manifold`, we denote the composition of local homeomorphisms with `≫ₕ`, and the
composition of local equivs with `≫`.
-/
-- register in the simpset `mfld_simps` several lemmas that are often useful
attribute [mfld_simps] id.def function.comp.left_id set.mem_set_of_eq set.image_eq_empty
set.univ_inter set.preimage_univ set.prod_mk_mem_set_prod_eq and_true set.mem_univ
set.mem_image_of_mem true_and set.mem_inter_eq set.mem_preimage function.comp_app
set.inter_subset_left set.mem_prod set.range_id and_self set.mem_range_self
eq_self_iff_true forall_const forall_true_iff set.inter_univ set.preimage_id function.comp.right_id
not_false_iff and_imp
noncomputable theory
open_locale classical
universes u
variables {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*}
/- Notational shortcut for the composition of local homeomorphisms and local equivs, i.e.,
`local_homeomorph.trans` and `local_equiv.trans`.
Note that, as is usual for equivs, the composition is from left to right, hence the direction of
the arrow. -/
localized "infixr ` ≫ₕ `:100 := local_homeomorph.trans" in manifold
localized "infixr ` ≫ `:100 := local_equiv.trans" in manifold
open set local_homeomorph
/-! ### Structure groupoids-/
section groupoid
/-! One could add to the definition of a structure groupoid the fact that the restriction of an
element of the groupoid to any open set still belongs to the groupoid.
(This is in Kobayashi-Nomizu.)
I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is
made of functions respecting the fibers and linear in the fibers (so that a charted space over this
groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always
defined on sets of the form `s × E`. There is a typeclass `closed_under_restriction` for groupoids
which have the restriction property.
The only nontrivial requirement is locality: if a local homeomorphism belongs to the groupoid
around each point in its domain of definition, then it belongs to the groupoid. Without this
requirement, the composition of structomorphisms does not have to be a structomorphism. Note that
this implies that a local homeomorphism with empty source belongs to any structure groupoid, as
it trivially satisfies this condition.
There is also a technical point, related to the fact that a local homeomorphism is by definition a
global map which is a homeomorphism when restricted to its source subset (and its values outside
of the source are not relevant). Therefore, we also require that being a member of the groupoid only
depends on the values on the source.
We use primes in the structure names as we will reformulate them below (without primes) using a
`has_mem` instance, writing `e ∈ G` instead of `e ∈ G.members`.
-/
/-- A structure groupoid is a set of local homeomorphisms of a topological space stable under
composition and inverse. They appear in the definition of the smoothness class of a manifold. -/
structure structure_groupoid (H : Type u) [topological_space H] :=
(members : set (local_homeomorph H H))
(trans' : ∀e e' : local_homeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members)
(symm' : ∀e : local_homeomorph H H, e ∈ members → e.symm ∈ members)
(id_mem' : local_homeomorph.refl H ∈ members)
(locality' : ∀e : local_homeomorph H H, (∀x ∈ e.source, ∃s, is_open s ∧
x ∈ s ∧ e.restr s ∈ members) → e ∈ members)
(eq_on_source' : ∀ e e' : local_homeomorph H H, e ∈ members → e' ≈ e → e' ∈ members)
variable [topological_space H]
instance : has_mem (local_homeomorph H H) (structure_groupoid H) :=
⟨λ(e : local_homeomorph H H) (G : structure_groupoid H), e ∈ G.members⟩
lemma structure_groupoid.trans (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G :=
G.trans' e e' he he'
lemma structure_groupoid.symm (G : structure_groupoid H) {e : local_homeomorph H H} (he : e ∈ G) :
e.symm ∈ G :=
G.symm' e he
lemma structure_groupoid.id_mem (G : structure_groupoid H) :
local_homeomorph.refl H ∈ G :=
G.id_mem'
lemma structure_groupoid.locality (G : structure_groupoid H) {e : local_homeomorph H H}
(h : ∀x ∈ e.source, ∃s, is_open s ∧ x ∈ s ∧ e.restr s ∈ G) :
e ∈ G :=
G.locality' e h
lemma structure_groupoid.eq_on_source (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (h : e' ≈ e) : e' ∈ G :=
G.eq_on_source' e e' he h
/-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid -/
instance structure_groupoid.partial_order : partial_order (structure_groupoid H) :=
partial_order.lift structure_groupoid.members
(λa b h, by { cases a, cases b, dsimp at h, induction h, refl })
lemma structure_groupoid.le_iff {G₁ G₂ : structure_groupoid H} :
G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ :=
iff.rfl
/-- The trivial groupoid, containing only the identity (and maps with empty source, as this is
necessary from the definition) -/
def id_groupoid (H : Type u) [topological_space H] : structure_groupoid H :=
{ members := {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅},
trans' := λe e' he he', begin
cases he; simp at he he',
{ simpa only [he, refl_trans]},
{ have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _,
rw he at this,
have : (e ≫ₕ e') ∈ {e : local_homeomorph H H | e.source = ∅} := disjoint_iff.1 this,
exact (mem_union _ _ _).2 (or.inr this) },
end,
symm' := λe he, begin
cases (mem_union _ _ _).1 he with E E,
{ finish },
{ right,
simpa only [e.to_local_equiv.image_source_eq_target.symm] with mfld_simps using E},
end,
id_mem' := mem_union_left _ rfl,
locality' := λe he, begin
cases e.source.eq_empty_or_nonempty with h h,
{ right, exact h },
{ left,
rcases h with ⟨x, hx⟩,
rcases he x hx with ⟨s, open_s, xs, hs⟩,
have x's : x ∈ (e.restr s).source,
{ rw [restr_source, interior_eq_of_open open_s],
exact ⟨hx, xs⟩ },
cases hs,
{ replace hs : local_homeomorph.restr e s = local_homeomorph.refl H,
by simpa using hs,
have : (e.restr s).source = univ, by { rw hs, simp },
change (e.to_local_equiv).source ∩ interior s = univ at this,
have : univ ⊆ interior s, by { rw ← this, exact inter_subset_right _ _ },
have : s = univ, by rwa [interior_eq_of_open open_s, univ_subset_iff] at this,
simpa [this, restr_univ] using hs },
{ exfalso,
rw mem_set_of_eq at hs,
rwa hs at x's } },
end,
eq_on_source' := λe e' he he'e, begin
cases he,
{ left,
have : e = e',
{ refine eq_of_eq_on_source_univ (setoid.symm he'e) _ _;
rw set.mem_singleton_iff.1 he ; refl },
rwa ← this },
{ right,
change (e.to_local_equiv).source = ∅ at he,
rwa [set.mem_set_of_eq, he'e.source_eq] }
end }
/-- Every structure groupoid contains the identity groupoid -/
instance : order_bot (structure_groupoid H) :=
{ bot := id_groupoid H,
bot_le := begin
assume u f hf,
change f ∈ {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅} at hf,
simp only [singleton_union, mem_set_of_eq, mem_insert_iff] at hf,
cases hf,
{ rw hf,
apply u.id_mem },
{ apply u.locality,
assume x hx,
rw [hf, mem_empty_eq] at hx,
exact hx.elim }
end,
..structure_groupoid.partial_order }
instance (H : Type u) [topological_space H] : inhabited (structure_groupoid H) :=
⟨id_groupoid H⟩
/-- To construct a groupoid, one may consider classes of local homeos such that both the function
and its inverse have some property. If this property is stable under composition,
one gets a groupoid. `pregroupoid` bundles the properties needed for this construction, with the
groupoid of smooth functions with smooth inverses as an application. -/
structure pregroupoid (H : Type*) [topological_space H] :=
(property : (H → H) → (set H) → Prop)
(comp : ∀{f g u v}, property f u → property g v → is_open u → is_open v → is_open (u ∩ f ⁻¹' v)
→ property (g ∘ f) (u ∩ f ⁻¹' v))
(id_mem : property id univ)
(locality : ∀{f u}, is_open u → (∀x∈u, ∃v, is_open v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u)
(congr : ∀{f g : H → H} {u}, is_open u → (∀x∈u, g x = f x) → property f u → property g u)
/-- Construct a groupoid of local homeos for which the map and its inverse have some property,
from a pregroupoid asserting that this property is stable under composition. -/
def pregroupoid.groupoid (PG : pregroupoid H) : structure_groupoid H :=
{ members := {e : local_homeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target},
trans' := λe e' he he', begin
split,
{ apply PG.comp he.1 he'.1 e.open_source e'.open_source,
apply e.continuous_to_fun.preimage_open_of_open e.open_source e'.open_source },
{ apply PG.comp he'.2 he.2 e'.open_target e.open_target,
apply e'.continuous_inv_fun.preimage_open_of_open e'.open_target e.open_target }
end,
symm' := λe he, ⟨he.2, he.1⟩,
id_mem' := ⟨PG.id_mem, PG.id_mem⟩,
locality' := λe he, begin
split,
{ apply PG.locality e.open_source (λx xu, _),
rcases he x xu with ⟨s, s_open, xs, hs⟩,
refine ⟨s, s_open, xs, _⟩,
convert hs.1,
exact (interior_eq_of_open s_open).symm },
{ apply PG.locality e.open_target (λx xu, _),
rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩,
refine ⟨e.target ∩ e.symm ⁻¹' s, _, ⟨xu, xs⟩, _⟩,
{ exact continuous_on.preimage_open_of_open e.continuous_inv_fun e.open_target s_open },
{ rw [← inter_assoc, inter_self],
convert hs.2,
exact (interior_eq_of_open s_open).symm } },
end,
eq_on_source' := λe e' he ee', begin
split,
{ apply PG.congr e'.open_source ee'.2,
simp only [ee'.1, he.1] },
{ have A := ee'.symm',
apply PG.congr e'.symm.open_source A.2,
convert he.2,
rw A.1,
refl }
end }
lemma mem_groupoid_of_pregroupoid (PG : pregroupoid H) (e : local_homeomorph H H) :
e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target :=
iff.rfl
lemma groupoid_of_pregroupoid_le (PG₁ PG₂ : pregroupoid H)
(h : ∀f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid :=
begin
refine structure_groupoid.le_iff.2 (λ e he, _),
rw mem_groupoid_of_pregroupoid at he ⊢,
exact ⟨h _ _ he.1, h _ _ he.2⟩
end
lemma mem_pregroupoid_of_eq_on_source (PG : pregroupoid H) {e e' : local_homeomorph H H}
(he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source :=
begin
rw ← he'.1,
exact PG.congr e.open_source he'.eq_on.symm he,
end
/-- The pregroupoid of all local maps on a topological space `H` -/
@[reducible] def continuous_pregroupoid (H : Type*) [topological_space H] : pregroupoid H :=
{ property := λf s, true,
comp := λf g u v hf hg hu hv huv, trivial,
id_mem := trivial,
locality := λf u u_open h, trivial,
congr := λf g u u_open hcongr hf, trivial }
instance (H : Type*) [topological_space H] : inhabited (pregroupoid H) :=
⟨continuous_pregroupoid H⟩
/-- The groupoid of all local homeomorphisms on a topological space `H` -/
def continuous_groupoid (H : Type*) [topological_space H] : structure_groupoid H :=
pregroupoid.groupoid (continuous_pregroupoid H)
/-- Every structure groupoid is contained in the groupoid of all local homeomorphisms -/
instance : order_top (structure_groupoid H) :=
{ top := continuous_groupoid H,
le_top := λ u f hf, by { split; exact dec_trivial },
..structure_groupoid.partial_order }
/-- A groupoid is closed under restriction if it contains all restrictions of its element local
homeomorphisms to open subsets of the source. -/
class closed_under_restriction (G : structure_groupoid H) : Prop :=
(closed_under_restriction : ∀ {e : local_homeomorph H H}, e ∈ G → ∀ (s : set H), is_open s →
(e : local_homeomorph H H).restr s ∈ G)
/-- The trivial restriction-closed groupoid, containing only local homeomorphisms equivalent to the
restriction of the identity to the various open subsets. -/
def id_restr_groupoid : structure_groupoid H :=
{ members := {e | ∃ {s : set H} (h : is_open s), e ≈ local_homeomorph.of_set s h},
trans' := begin
rintros e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩,
refine ⟨s ∩ s', is_open_inter hs hs', _⟩,
have := local_homeomorph.eq_on_source.trans' hse hse',
rwa local_homeomorph.of_set_trans_of_set at this,
end,
symm' := begin
rintros e ⟨s, hs, hse⟩,
refine ⟨s, hs, _⟩,
rw [← of_set_symm],
exact local_homeomorph.eq_on_source.symm' hse,
end,
id_mem' := ⟨univ, is_open_univ, by simp only with mfld_simps⟩,
locality' := begin
intros e h,
refine ⟨e.source, e.open_source, by simp only with mfld_simps, _⟩,
intros x hx,
rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩,
have hes : x ∈ (e.restr s).source,
{ rw e.restr_source, refine ⟨hx, _⟩,
rw interior_eq_of_open hs, exact hxs },
simpa only with mfld_simps using local_homeomorph.eq_on_source.eq_on hes' hes,
end,
eq_on_source' := begin
rintros e e' ⟨s, hs, hse⟩ hee',
exact ⟨s, hs, setoid.trans hee' hse⟩,
end
}
lemma id_restr_groupoid_mem {s : set H} (hs : is_open s) :
of_set s hs ∈ (@id_restr_groupoid H _).members := ⟨s, hs, by refl⟩
/-- The trivial restriction-closed groupoid is indeed `closed_under_restriction`. -/
instance closed_under_restriction_id_restr_groupoid :
closed_under_restriction (@id_restr_groupoid H _) :=
⟨ begin
rintros e ⟨s', hs', he⟩ s hs,
use [s' ∩ s, is_open_inter hs' hs],
refine setoid.trans (local_homeomorph.eq_on_source.restr he s) _,
exact ⟨by simp only [interior_eq_of_open hs] with mfld_simps, by simp only with mfld_simps⟩,
end ⟩
/-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed
groupoid. -/
lemma closed_under_restriction_iff_id_le (G : structure_groupoid H) :
closed_under_restriction G ↔ id_restr_groupoid ≤ G :=
begin
split,
{ intros _i,
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
refine G.eq_on_source _ hes,
have h := _i.closed_under_restriction,
convert h G.id_mem s hs,
rw interior_eq_of_open hs,
simp only with mfld_simps },
{ intros h,
split,
intros e he s hs,
rw ← of_set_trans (e : local_homeomorph H H) hs,
refine G.trans _ he,
apply structure_groupoid.le_iff.mp h,
exact id_restr_groupoid_mem hs },
end
/-- The groupoid of all local homeomorphisms on a topological space `H` is closed under restriction.
-/
instance : closed_under_restriction (continuous_groupoid H) :=
(closed_under_restriction_iff_id_le _).mpr (by convert le_top)
end groupoid
/-! ### Charted spaces -/
/-- A charted space is a topological space endowed with an atlas, i.e., a set of local
homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts
cover the whole space. We express the covering property by chosing for each `x` a member
`chart_at H x` of the atlas containing `x` in its source: in the smooth case, this is convenient to
construct the tangent bundle in an efficient way.
The model space is written as an explicit parameter as there can be several model spaces for a
given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen
sometimes as a real manifold over `ℝ^(2n)`.
-/
class charted_space (H : Type*) [topological_space H] (M : Type*) [topological_space M] :=
(atlas [] : set (local_homeomorph M H))
(chart_at [] : M → local_homeomorph M H)
(mem_chart_source [] : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas [] : ∀x, chart_at x ∈ atlas)
export charted_space
attribute [simp, mfld_simps] mem_chart_source chart_mem_atlas
section charted_space
/-- Any space is a charted_space modelled over itself, by just using the identity chart -/
instance manifold_model_space (H : Type*) [topological_space H] : charted_space H H :=
{ atlas := {local_homeomorph.refl H},
chart_at := λx, local_homeomorph.refl H,
mem_chart_source := λx, mem_univ x,
chart_mem_atlas := λx, mem_singleton _ }
/-- In the trivial charted_space structure of a space modelled over itself through the identity, the
atlas members are just the identity -/
@[simp, mfld_simps] lemma model_space_atlas {H : Type*} [topological_space H] {e : local_homeomorph H H} :
e ∈ atlas H H ↔ e = local_homeomorph.refl H :=
by simp [atlas, charted_space.atlas]
/-- In the model space, chart_at is always the identity -/
@[simp, mfld_simps] lemma chart_at_model_space_eq {H : Type*} [topological_space H] {x : H} :
chart_at H x = local_homeomorph.refl H :=
by simpa using chart_mem_atlas H x
/-- Same thing as `H × H'`. We introduce it for technical reasons: a charted space `M` with model `H`
is a set of local charts from `M` to `H` covering the space. Every space is registered as a charted
space over itself, using the only chart `id`, in `manifold_model_space`. You can also define a product
of charted space `M` and `M'` (with model space `H × H'`) by taking the products of the charts. Now,
on `H × H'`, there are two charted space structures with model space `H × H'` itself, the one coming
from `manifold_model_space`, and the one coming from the product of the two `manifold_model_space` on
each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to
`id`), which is bad as we know. This expedient of renaming `H × H'` solves this problem. -/
def model_prod (H : Type*) (H' : Type*) := H × H'
section
local attribute [reducible] model_prod
instance model_prod_inhabited {α β : Type*} [inhabited α] [inhabited β] :
inhabited (model_prod α β) :=
⟨(default α, default β)⟩
instance (H : Type*) [topological_space H] (H' : Type*) [topological_space H'] :
topological_space (model_prod H H') :=
by apply_instance
/- Next lemma shows up often when dealing with derivatives, register it as simp. -/
@[simp, mfld_simps] lemma model_prod_range_prod_id
{H : Type*} {H' : Type*} {α : Type*} (f : H → α) :
range (λ (p : model_prod H H'), (f p.1, p.2)) = set.prod (range f) univ :=
by rw prod_range_univ_eq
end
/-- The product of two charted spaces is naturally a charted space, with the canonical
construction of the atlas of product maps. -/
instance prod_charted_space (H : Type*) [topological_space H]
(M : Type*) [topological_space M] [charted_space H M]
(H' : Type*) [topological_space H']
(M' : Type*) [topological_space M'] [charted_space H' M'] :
charted_space (model_prod H H') (M × M') :=
{ atlas :=
{f : (local_homeomorph (M×M') (model_prod H H')) |
∃ g ∈ charted_space.atlas H M, ∃ h ∈ (charted_space.atlas H' M'),
f = local_homeomorph.prod g h},
chart_at := λ x: (M × M'),
(charted_space.chart_at H x.1).prod (charted_space.chart_at H' x.2),
mem_chart_source :=
begin
intro x,
simp only with mfld_simps,
end,
chart_mem_atlas :=
begin
intro x,
use (charted_space.chart_at H x.1),
split,
{ apply chart_mem_atlas _, },
{ use (charted_space.chart_at H' x.2), simp only [chart_mem_atlas, eq_self_iff_true, and_self], }
end }
section prod_charted_space
variables [topological_space H] [topological_space M] [charted_space H M]
[topological_space H'] [topological_space M'] [charted_space H' M'] {x : M×M'}
@[simp, mfld_simps] lemma prod_charted_space_chart_at :
(chart_at (model_prod H H') x) = (chart_at H x.fst).prod (chart_at H' x.snd) := rfl
end prod_charted_space
end charted_space
/-! ### Constructing a topology from an atlas -/
/-- Sometimes, one may want to construct a charted space structure on a space which does not yet
have a topological structure, where the topology would come from the charts. For this, one needs
charts that are only local equivs, and continuity properties for their composition.
This is formalised in `charted_space_core`. -/
@[nolint has_inhabited_instance]
structure charted_space_core (H : Type*) [topological_space H] (M : Type*) :=
(atlas : set (local_equiv M H))
(chart_at : M → local_equiv M H)
(mem_chart_source : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas : ∀x, chart_at x ∈ atlas)
(open_source : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas → is_open (e.symm.trans e').source)
(continuous_to_fun : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas →
continuous_on (e.symm.trans e') (e.symm.trans e').source)
namespace charted_space_core
variables [topological_space H] (c : charted_space_core H M) {e : local_equiv M H}
/-- Topology generated by a set of charts on a Type. -/
protected def to_topological_space : topological_space M :=
topological_space.generate_from $ ⋃ (e : local_equiv M H) (he : e ∈ c.atlas)
(s : set H) (s_open : is_open s), {e ⁻¹' s ∩ e.source}
lemma open_source' (he : e ∈ c.atlas) : @is_open M c.to_topological_space e.source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨e, he, univ, is_open_univ, _⟩,
simp only [set.univ_inter, set.preimage_univ]
end
lemma open_target (he : e ∈ c.atlas) : is_open e.target :=
begin
have E : e.target ∩ e.symm ⁻¹' e.source = e.target :=
subset.antisymm (inter_subset_left _ _) (λx hx, ⟨hx,
local_equiv.target_subset_preimage_source _ hx⟩),
simpa [local_equiv.trans_source, E] using c.open_source e e he he
end
/-- An element of the atlas in a charted space without topology becomes a local homeomorphism
for the topology constructed from this atlas. The `local_homeomorph` version is given in this
definition. -/
def local_homeomorph (e : local_equiv M H) (he : e ∈ c.atlas) :
@local_homeomorph M H c.to_topological_space _ :=
{ open_source := by convert c.open_source' he,
open_target := by convert c.open_target he,
continuous_to_fun := begin
letI : topological_space M := c.to_topological_space,
rw continuous_on_open_iff (c.open_source' he),
assume s s_open,
rw inter_comm,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨e, he, ⟨s, s_open, rfl⟩⟩
end,
continuous_inv_fun := begin
letI : topological_space M := c.to_topological_space,
apply continuous_on_open_of_generate_from (c.open_target he),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
rcases ht with ⟨e', e'_atlas, s, s_open, ts⟩,
rw ts,
let f := e.symm.trans e',
have : is_open (f ⁻¹' s ∩ f.source),
by simpa [inter_comm] using (continuous_on_open_iff (c.open_source e e' he e'_atlas)).1
(c.continuous_to_fun e e' he e'_atlas) s s_open,
have A : e' ∘ e.symm ⁻¹' s ∩ (e.target ∩ e.symm ⁻¹' e'.source) =
e.target ∩ (e' ∘ e.symm ⁻¹' s ∩ e.symm ⁻¹' e'.source),
by { rw [← inter_assoc, ← inter_assoc], congr' 1, exact inter_comm _ _ },
simpa [local_equiv.trans_source, preimage_inter, preimage_comp.symm, A] using this
end,
..e }
/-- Given a charted space without topology, endow it with a genuine charted space structure with
respect to the topology constructed from the atlas. -/
def to_charted_space : @charted_space H _ M c.to_topological_space :=
{ atlas := ⋃ (e : local_equiv M H) (he : e ∈ c.atlas), {c.local_homeomorph e he},
chart_at := λx, c.local_homeomorph (c.chart_at x) (c.chart_mem_atlas x),
mem_chart_source := λx, c.mem_chart_source x,
chart_mem_atlas := λx, begin
simp only [mem_Union, mem_singleton_iff],
exact ⟨c.chart_at x, c.chart_mem_atlas x, rfl⟩,
end }
end charted_space_core
/-! ### Charted space with a given structure groupoid -/
section has_groupoid
variables [topological_space H] [topological_space M] [charted_space H M]
/-- A charted space has an atlas in a groupoid `G` if the change of coordinates belong to the
groupoid -/
class has_groupoid {H : Type*} [topological_space H] (M : Type*) [topological_space M]
[charted_space H M] (G : structure_groupoid H) : Prop :=
(compatible [] : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → e.symm ≫ₕ e' ∈ G)
/-- Reformulate in the `structure_groupoid` namespace the compatibility condition of charts in a
charted space admitting a structure groupoid, to make it more easily accessible with dot
notation. -/
lemma structure_groupoid.compatible {H : Type*} [topological_space H] (G : structure_groupoid H)
{M : Type*} [topological_space M] [charted_space H M] [has_groupoid M G]
{e e' : local_homeomorph M H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) :
e.symm ≫ₕ e' ∈ G :=
has_groupoid.compatible G he he'
lemma has_groupoid_of_le {G₁ G₂ : structure_groupoid H} (h : has_groupoid M G₁) (hle : G₁ ≤ G₂) :
has_groupoid M G₂ :=
⟨ λ e e' he he', hle ((h.compatible : _) he he') ⟩
lemma has_groupoid_of_pregroupoid (PG : pregroupoid H)
(h : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M
→ PG.property (e.symm ≫ₕ e') (e.symm ≫ₕ e').source) :
has_groupoid M (PG.groupoid) :=
⟨assume e e' he he', (mem_groupoid_of_pregroupoid PG _).mpr ⟨h he he', h he' he⟩⟩
/-- The trivial charted space structure on the model space is compatible with any groupoid -/
instance has_groupoid_model_space (H : Type*) [topological_space H] (G : structure_groupoid H) :
has_groupoid H G :=
{ compatible := λe e' he he', begin
replace he : e ∈ atlas H H := he,
replace he' : e' ∈ atlas H H := he',
rw model_space_atlas at he he',
simp [he, he', structure_groupoid.id_mem]
end }
/-- Any charted space structure is compatible with the groupoid of all local homeomorphisms -/
instance has_groupoid_continuous_groupoid : has_groupoid M (continuous_groupoid H) :=
⟨begin
assume e e' he he',
rw [continuous_groupoid, mem_groupoid_of_pregroupoid],
simp only [and_self]
end⟩
section maximal_atlas
variables (M) (G : structure_groupoid H)
/-- Given a charted space admitting a structure groupoid, the maximal atlas associated to this
structure groupoid is the set of all local charts that are compatible with the atlas, i.e., such
that changing coordinates with an atlas member gives an element of the groupoid. -/
def structure_groupoid.maximal_atlas : set (local_homeomorph M H) :=
{e | ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G}
variable {M}
/-- The elements of the atlas belong to the maximal atlas for any structure groupoid -/
lemma structure_groupoid.mem_maximal_atlas_of_mem_atlas [has_groupoid M G]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ G.maximal_atlas M :=
λ e' he', ⟨G.compatible he he', G.compatible he' he⟩
lemma structure_groupoid.chart_mem_maximal_atlas [has_groupoid M G]
(x : M) : chart_at H x ∈ G.maximal_atlas M :=
G.mem_maximal_atlas_of_mem_atlas (chart_mem_atlas H x)
variable {G}
lemma mem_maximal_atlas_iff {e : local_homeomorph M H} :
e ∈ G.maximal_atlas M ↔ ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G :=
iff.rfl
/-- Changing coordinates between two elements of the maximal atlas gives rise to an element
of the structure groupoid. -/
lemma structure_groupoid.compatible_of_mem_maximal_atlas {e e' : local_homeomorph M H}
(he : e ∈ G.maximal_atlas M) (he' : e' ∈ G.maximal_atlas M) : e.symm ≫ₕ e' ∈ G :=
begin
apply G.locality (λ x hx, _),
set f := chart_at H (e.symm x) with hf,
let s := e.target ∩ (e.symm ⁻¹' f.source),
have hs : is_open s,
{ apply e.symm.continuous_to_fun.preimage_open_of_open; apply open_source },
have xs : x ∈ s, by { dsimp at hx, simp [s, hx] },
refine ⟨s, hs, xs, _⟩,
have A : e.symm ≫ₕ f ∈ G := (mem_maximal_atlas_iff.1 he f (chart_mem_atlas _ _)).1,
have B : f.symm ≫ₕ e' ∈ G := (mem_maximal_atlas_iff.1 he' f (chart_mem_atlas _ _)).2,
have C : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ∈ G := G.trans A B,
have D : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ≈ (e.symm ≫ₕ e').restr s := calc
(e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') = e.symm ≫ₕ (f ≫ₕ f.symm) ≫ₕ e' : by simp [trans_assoc]
... ≈ e.symm ≫ₕ (of_set f.source f.open_source) ≫ₕ e' :
by simp [eq_on_source.trans', trans_self_symm]
... ≈ (e.symm ≫ₕ (of_set f.source f.open_source)) ≫ₕ e' : by simp [trans_assoc]
... ≈ (e.symm.restr s) ≫ₕ e' : by simp [s, trans_of_set']
... ≈ (e.symm ≫ₕ e').restr s : by simp [restr_trans],
exact G.eq_on_source C (setoid.symm D),
end
end maximal_atlas
section singleton
variables {α : Type*} [topological_space α]
variables (e : local_homeomorph α H)
/-- If a single local homeomorphism `e` from a space `α` into `H` has source covering the whole
space `α`, then that local homeomorphism induces an `H`-charted space structure on `α`.
(This condition is equivalent to `e` being an open embedding of `α` into `H`.) -/
def singleton_charted_space (h : e.source = set.univ) : charted_space H α :=
{ atlas := {e},
chart_at := λ _, e,
mem_chart_source := λ _, by simp only [h] with mfld_simps,
chart_mem_atlas := λ _, by tauto }
lemma singleton_charted_space_one_chart (h : e.source = set.univ) (e' : local_homeomorph α H)
(h' : e' ∈ (singleton_charted_space e h).atlas) : e' = e := h'
/-- Given a local homeomorphism `e` from a space `α` into `H`, if its source covers the whole
space `α`, then the induced charted space structure on `α` is `has_groupoid G` for any structure
groupoid `G` which is closed under restrictions. -/
lemma singleton_has_groupoid (h : e.source = set.univ) (G : structure_groupoid H)
[closed_under_restriction G] : @has_groupoid _ _ _ _ (singleton_charted_space e h) G :=
{ compatible := begin
intros e' e'' he' he'',
rw singleton_charted_space_one_chart e h e' he',
rw singleton_charted_space_one_chart e h e'' he'',
refine G.eq_on_source _ e.trans_symm_self,
have hle : id_restr_groupoid ≤ G := (closed_under_restriction_iff_id_le G).mp (by assumption),
exact structure_groupoid.le_iff.mp hle _ (id_restr_groupoid_mem _),
end }
end singleton
/-! ### Structomorphisms -/
/-- A `G`-diffeomorphism between two charted spaces is a homeomorphism which, when read in the
charts, belongs to `G`. We avoid the word diffeomorph as it is too related to the smooth category,
and use structomorph instead. -/
@[nolint has_inhabited_instance]
structure structomorph (G : structure_groupoid H) (M : Type*) (M' : Type*)
[topological_space M] [topological_space M'] [charted_space H M] [charted_space H M']
extends homeomorph M M' :=
(mem_groupoid : ∀c : local_homeomorph M H, ∀c' : local_homeomorph M' H,
c ∈ atlas H M → c' ∈ atlas H M' → c.symm ≫ₕ to_homeomorph.to_local_homeomorph ≫ₕ c' ∈ G)
variables [topological_space M'] [topological_space M'']
{G : structure_groupoid H} [charted_space H M'] [charted_space H M'']
/-- The identity is a diffeomorphism of any charted space, for any groupoid. -/
def structomorph.refl (M : Type*) [topological_space M] [charted_space H M]
[has_groupoid M G] : structomorph G M M :=
{ mem_groupoid := λc c' hc hc', begin
change (local_homeomorph.symm c) ≫ₕ (local_homeomorph.refl M) ≫ₕ c' ∈ G,
rw local_homeomorph.refl_trans,
exact has_groupoid.compatible G hc hc'
end,
..homeomorph.refl M }
/-- The inverse of a structomorphism is a structomorphism -/
def structomorph.symm (e : structomorph G M M') : structomorph G M' M :=
{ mem_groupoid := begin
assume c c' hc hc',
have : (c'.symm ≫ₕ e.to_homeomorph.to_local_homeomorph ≫ₕ c).symm ∈ G :=
G.symm (e.mem_groupoid c' c hc' hc),
rwa [trans_symm_eq_symm_trans_symm, trans_symm_eq_symm_trans_symm, symm_symm, trans_assoc]
at this,
end,
..e.to_homeomorph.symm}
/-- The composition of structomorphisms is a structomorphism -/
def structomorph.trans (e : structomorph G M M') (e' : structomorph G M' M'') : structomorph G M M'' :=
{ mem_groupoid := begin
/- Let c and c' be two charts in M and M''. We want to show that e' ∘ e is smooth in these
charts, around any point x. For this, let y = e (c⁻¹ x), and consider a chart g around y.
Then g ∘ e ∘ c⁻¹ and c' ∘ e' ∘ g⁻¹ are both smooth as e and e' are structomorphisms, so
their composition is smooth, and it coincides with c' ∘ e' ∘ e ∘ c⁻¹ around x. -/
assume c c' hc hc',
refine G.locality (λx hx, _),
let f₁ := e.to_homeomorph.to_local_homeomorph,
let f₂ := e'.to_homeomorph.to_local_homeomorph,
let f := (e.to_homeomorph.trans e'.to_homeomorph).to_local_homeomorph,
have feq : f = f₁ ≫ₕ f₂ := homeomorph.trans_to_local_homeomorph _ _,
-- define the atlas g around y
let y := (c.symm ≫ₕ f₁) x,
let g := chart_at H y,
have hg₁ := chart_mem_atlas H y,
have hg₂ := mem_chart_source H y,
let s := (c.symm ≫ₕ f₁).source ∩ (c.symm ≫ₕ f₁) ⁻¹' g.source,
have open_s : is_open s,
by apply (c.symm ≫ₕ f₁).continuous_to_fun.preimage_open_of_open; apply open_source,
have : x ∈ s,
{ split,
{ simp only [trans_source, preimage_univ, inter_univ, homeomorph.to_local_homeomorph_source],
rw trans_source at hx,
exact hx.1 },
{ exact hg₂ } },
refine ⟨s, open_s, this, _⟩,
let F₁ := (c.symm ≫ₕ f₁ ≫ₕ g) ≫ₕ (g.symm ≫ₕ f₂ ≫ₕ c'),
have A : F₁ ∈ G := G.trans (e.mem_groupoid c g hc hg₁) (e'.mem_groupoid g c' hg₁ hc'),
let F₂ := (c.symm ≫ₕ f ≫ₕ c').restr s,
have : F₁ ≈ F₂ := calc
F₁ ≈ c.symm ≫ₕ f₁ ≫ₕ (g ≫ₕ g.symm) ≫ₕ f₂ ≫ₕ c' : by simp [F₁, trans_assoc]
... ≈ c.symm ≫ₕ f₁ ≫ₕ (of_set g.source g.open_source) ≫ₕ f₂ ≫ₕ c' :
by simp [eq_on_source.trans', trans_self_symm g]
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (of_set g.source g.open_source)) ≫ₕ (f₂ ≫ₕ c') :
by simp [trans_assoc]
... ≈ ((c.symm ≫ₕ f₁).restr s) ≫ₕ (f₂ ≫ₕ c') : by simp [s, trans_of_set']
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (f₂ ≫ₕ c')).restr s : by simp [restr_trans]
... ≈ (c.symm ≫ₕ (f₁ ≫ₕ f₂) ≫ₕ c').restr s : by simp [eq_on_source.restr, trans_assoc]
... ≈ F₂ : by simp [F₂, feq],
have : F₂ ∈ G := G.eq_on_source A (setoid.symm this),
exact this
end,
..homeomorph.trans e.to_homeomorph e'.to_homeomorph }
end has_groupoid
|
dc25223ee19852e72fd20ca41568b7bf4652a4e8
|
9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e
|
/src/data/enumeration.lean
|
527c2d601b93ee3d6c888f37d6f440928308b86f
|
[] |
no_license
|
agusakov/lean_lib
|
c0e9cc29fc7d2518004e224376adeb5e69b5cc1a
|
f88d162da2f990b87c4d34f5f46bbca2bbc5948e
|
refs/heads/master
| 1,642,141,461,087
| 1,557,395,798,000
| 1,557,395,798,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,318
|
lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
This file defines a typeclass for types α with an ordered
enumeration of the elements (as opposed to a `fintype`
instance, which is an unordered enumeration). This is
intended to allow for explicit calculation in a wider range
of cases.
-/
-- TODO:
-- instances for (co) products etc
import data.finset data.fintype data.list.basic
universes u v
variables {α : Type*} {β : Type*} {γ : Type*}
class enumeration (α : Type*) :=
(elems : list α)
(nodup : list.nodup elems)
(complete : ∀ x : α, x ∈ elems)
instance enumeration_fintype [e : enumeration α] : fintype α :=
begin
let elems : finset α := ⟨e.elems,e.nodup⟩,
let complete : ∀ a : α, a ∈ elems := e.complete,
exact ⟨elems,complete⟩,
end
namespace enumeration
variable (α)
variable [enumeration α]
def univ_list : list α := (@enumeration.elems α _)
def univ_nodup : list.nodup (univ_list α) := (@enumeration.nodup α _)
def univ_complete := (@enumeration.complete α _)
lemma enum_card : fintype.card α = (@enumeration.elems α _).length :=
begin
dsimp[fintype.card,finset.univ,fintype.elems,finset.card],refl,
end
def of_equiv (f : α ≃ β) : enumeration β := {
elems := (univ_list α).map f.to_fun,
nodup := list.nodup_map
(function.injective_of_left_inverse f.left_inv) (univ_nodup α),
complete :=
begin
intro b,
rw[← f.right_inv b],
exact list.mem_map_of_mem f.to_fun (univ_complete α (f.inv_fun b)),
end
}
variable [decidable_eq α]
def fin_equiv {n : ℕ} (h : (univ_list α).length = n) : α ≃ (fin n) :=
begin
let els := univ_list α,
let inv_fun : (fin n) → α :=
λ i, els.nth_le i.val (@eq.subst ℕ (nat.lt i.val) _ _ h.symm i.is_lt),
let to_fun_aux : α → {i : fin n // inv_fun i = a} :=
begin
intro a,
let i_val := els.index_of a,
let i_lt_l := list.index_of_lt_length.mpr (enumeration.complete a),
let i_lt_n : i_val < n := @eq.subst ℕ (nat.lt i_val) _ _ h i_lt_l,
let i : fin n := ⟨i_val,i_lt_n⟩,
have : inv_fun i = a := begin
cases h,exact list.index_of_nth_le i_lt_l,
end,
exact ⟨i,this⟩
end,
let to_fun : α → (fin n) := λ a, (to_fun_aux a).val,
let left_inv : ∀ a : α, inv_fun (to_fun a) = a :=
λ a, (to_fun_aux a).property,
let right_inv : ∀ i : (fin n), to_fun (inv_fun i) = i :=
begin
intro i,cases i,
apply fin.eq_of_veq,
let i_lt_l : i_val < els.length :=
@eq.subst ℕ (nat.lt i_val) _ _ h.symm i_is_lt,
exact list.nth_le_index_of (univ_nodup α) i_val i_lt_l,
end,
exact ⟨to_fun,inv_fun,left_inv,right_inv⟩
end
instance : encodable α :=
begin
let els := univ_list α,
let f := fin_equiv α rfl,
let encode : α → ℕ := λ a,(f.to_fun a).val,
let decode : ℕ → option α :=
begin
intro i,
by_cases h : i < els.length,
{exact some (f.inv_fun ⟨i,h⟩),},
{exact none,}
end,
let encodek : ∀ a, decode (encode a) = some a :=
begin
intro a,
dsimp[decode,encode],
simp[(f.to_fun a).is_lt,f.left_inv a],
end,
exact ⟨encode,decode,encodek⟩
end
def subtype_enumeration {p : α → Prop} (l : list α)
(l_nodup : list.nodup l)
(l_mem : ∀ x : α, x ∈ l ↔ p x) : enumeration {x // p x} :=
begin
let α1 := {x // p x},
let elems1 : list α1 := @list.pmap α α1 p subtype.mk l (λ x, (l_mem x).mp),
let nodup : elems1.nodup :=
@list.nodup_pmap α α1 p subtype.mk l (λ x, (l_mem x).mp)
(λ a _ b _,congr_arg subtype.val) l_nodup,
let complete : ∀ a1 : α1, a1 ∈ elems1 :=
begin
intro a1, cases a1,
let h0 := ((@list.mem_pmap α α1 p subtype.mk l
(λ x, (l_mem x).mp)) ⟨a1_val,a1_property⟩).mpr,
have h1 : a1_val ∈ l := (l_mem a1_val).mpr a1_property,
exact h0 ⟨a1_val,h1,rfl⟩,
end,
exact ⟨elems1,nodup,complete⟩
end
instance (p : α → Prop) [decidable_pred p] : enumeration {a // p a} :=
begin
let l := (univ_list α).filter p,
let l_nodup : l.nodup := list.nodup_filter p (univ_nodup α),
let l_mem : ∀ x : α, x ∈ l ↔ p x :=
begin
intro x,
let h0 : x ∈ univ_list α := (univ_complete α) x,
simp[list.mem_filter,h0],
end,
exact subtype_enumeration α l l_nodup l_mem,
end
end enumeration
|
7c98e72b4c193953410cb945ed199f0abe809f50
|
fecda8e6b848337561d6467a1e30cf23176d6ad0
|
/src/measure_theory/l1_space.lean
|
f3ed92d6f942fffe5aecccc74528a2c16957d82b
|
[
"Apache-2.0"
] |
permissive
|
spolu/mathlib
|
bacf18c3d2a561d00ecdc9413187729dd1f705ed
|
480c92cdfe1cf3c2d083abded87e82162e8814f4
|
refs/heads/master
| 1,671,684,094,325
| 1,600,736,045,000
| 1,600,736,045,000
| 297,564,749
| 1
| 0
| null | 1,600,758,368,000
| 1,600,758,367,000
| null |
UTF-8
|
Lean
| false
| false
| 29,960
|
lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.ae_eq_fun
/-!
# Integrable functions and `L¹` space
In the first part of this file, the predicate `integrable` is defined and basic properties of
integrable functions are proved.
In the second part, the space `L¹` of equivalence classes of integrable functions under the relation
of being almost everywhere equal is defined as a subspace of the space `L⁰`. See the file
`src/measure_theory/ae_eq_fun.lean` for information on `L⁰` space.
## Notation
* `α →₁ β` is the type of `L¹` space, where `α` is a `measure_space` and `β` is a `normed_group`
with a `second_countable_topology`. `f : α →ₘ β` is a "function" in `L¹`. In comments, `[f]` is
also used to denote an `L¹` function.
`₁` can be typed as `\1`.
## Main definitions
* Let `f : α → β` be a function, where `α` is a `measure_space` and `β` a `normed_group`.
Then `f` is called `integrable` if `(∫⁻ a, nnnorm (f a)) < ⊤` holds.
* The space `L¹` is defined as a subspace of `L⁰` :
An `ae_eq_fun` `[f] : α →ₘ β` is in the space `L¹` if `edist [f] 0 < ⊤`, which means
`(∫⁻ a, edist (f a) 0) < ⊤` if we expand the definition of `edist` in `L⁰`.
## Main statements
`L¹`, as a subspace, inherits most of the structures of `L⁰`.
## Implementation notes
Maybe `integrable f` should be mean `(∫⁻ a, edist (f a) 0) < ⊤`, so that `integrable` and
`ae_eq_fun.integrable` are more aligned. But in the end one can use the lemma
`lintegral_nnnorm_eq_lintegral_edist : (∫⁻ a, nnnorm (f a)) = (∫⁻ a, edist (f a) 0)` to switch the
two forms.
To prove something for an arbitrary integrable + measurable function, a useful theorem is
`integrable.induction` in the file `set_integral`.
## Tags
integrable, function space, l1
-/
noncomputable theory
open_locale classical topological_space
namespace measure_theory
open set filter topological_space ennreal emetric
open_locale big_operators
universes u v w
variables {α : Type u} [measurable_space α] {μ ν : measure α}
variables {β : Type v} [normed_group β] {γ : Type w} [normed_group γ]
/-- `integrable f μ` means that the integral `∫⁻ a, ∥f a∥ ∂μ` is finite; `integrable f` means
`integrable f volume`. -/
def integrable (f : α → β) (μ : measure α . volume_tac) : Prop := ∫⁻ a, nnnorm (f a) ∂μ < ⊤
lemma integrable_iff_norm (f : α → β) : integrable f μ ↔ ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ < ⊤ :=
by simp only [integrable, of_real_norm_eq_coe_nnnorm]
lemma integrable_iff_edist (f : α → β) : integrable f μ ↔ ∫⁻ a, edist (f a) 0 ∂μ < ⊤ :=
by simp only [integrable_iff_norm, edist_dist, dist_zero_right]
lemma integrable_iff_of_real {f : α → ℝ} (h : 0 ≤ᵐ[μ] f) :
integrable f μ ↔ ∫⁻ a, ennreal.of_real (f a) ∂μ < ⊤ :=
have lintegral_eq : ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, ennreal.of_real (f a) ∂μ :=
begin
refine lintegral_congr_ae (h.mono $ λ a h, _),
rwa [real.norm_eq_abs, abs_of_nonneg]
end,
by rw [integrable_iff_norm, lintegral_eq]
lemma integrable.mono {f : α → β} {g : α → γ} (hg : integrable g μ) (h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) :
integrable f μ :=
begin
simp only [integrable_iff_norm] at *,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ (a : α), (ennreal.of_real ∥g a∥) ∂μ :
lintegral_mono_ae (h.mono $ assume a h, of_real_le_of_real h)
... < ⊤ : hg
end
lemma integrable.mono' {f : α → β} {g : α → ℝ} (hg : integrable g μ) (h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) :
integrable f μ :=
hg.mono $ h.mono $ λ x hx, le_trans hx (le_abs_self _)
lemma integrable.congr' {f : α → β} {g : α → γ} (hf : integrable f μ)
(h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
integrable g μ :=
hf.mono $ eventually_eq.le $ eventually_eq.symm h
lemma integrable_congr' {f : α → β} {g : α → γ} (h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
integrable f μ ↔ integrable g μ :=
⟨λ hf, hf.congr' h, λ hg, hg.congr' $ eventually_eq.symm h⟩
lemma integrable.congr {f g : α → β} (hf : integrable f μ) (h : f =ᵐ[μ] g) : integrable g μ :=
hf.congr' $ h.fun_comp norm
lemma integrable_congr {f g : α → β} (h : f =ᵐ[μ] g) : integrable f μ ↔ integrable g μ :=
integrable_congr' $ h.fun_comp norm
lemma integrable_const_iff {c : β} : integrable (λ x : α, c) μ ↔ c = 0 ∨ μ univ < ⊤ :=
begin
simp only [integrable, lintegral_const],
by_cases hc : c = 0,
{ simp [hc] },
{ simp only [hc, false_or],
refine ⟨λ h, _, λ h, mul_lt_top coe_lt_top h⟩,
replace h := mul_lt_top (@coe_lt_top $ (nnnorm c)⁻¹) h,
rwa [← mul_assoc, ← coe_mul, _root_.inv_mul_cancel, coe_one, one_mul] at h,
rwa [ne.def, nnnorm_eq_zero] }
end
lemma integrable_const [finite_measure μ] (c : β) : integrable (λ x : α, c) μ :=
integrable_const_iff.2 (or.inr $ measure_lt_top _ _)
lemma integrable_of_bounded [finite_measure μ] {f : α → β} {C : ℝ} (hC : ∀ᵐ a ∂μ, ∥f a∥ ≤ C) :
integrable f μ :=
(integrable_const C).mono' hC
lemma integrable.mono_measure {f : α → β} (h : integrable f ν) (hμ : μ ≤ ν) :
integrable f μ :=
lt_of_le_of_lt (lintegral_mono' hμ (le_refl _)) h
lemma integrable.add_measure {f : α → β} (hμ : integrable f μ) (hν : integrable f ν) :
integrable f (μ + ν) :=
begin
simp only [integrable, lintegral_add_measure] at *,
exact add_lt_top.2 ⟨hμ, hν⟩
end
lemma integrable.left_of_add_measure {f : α → β} (h : integrable f (μ + ν)) :
integrable f μ :=
h.mono_measure $ measure.le_add_right $ le_refl _
lemma integrable.right_of_add_measure {f : α → β} (h : integrable f (μ + ν)) :
integrable f ν :=
h.mono_measure $ measure.le_add_left $ le_refl _
@[simp] lemma integrable_add_measure {f : α → β} :
integrable f (μ + ν) ↔ integrable f μ ∧ integrable f ν :=
⟨λ h, ⟨h.left_of_add_measure, h.right_of_add_measure⟩, λ h, h.1.add_measure h.2⟩
lemma integrable.smul_measure {f : α → β} (h : integrable f μ) {c : ennreal} (hc : c < ⊤) :
integrable f (c • μ) :=
begin
simp only [integrable, lintegral_smul_measure] at *,
exact mul_lt_top hc h
end
@[simp] lemma integrable_zero_measure (f : α → β) : integrable f 0 :=
by simp only [integrable, lintegral_zero_measure, with_top.zero_lt_top]
lemma integrable_map_measure {δ} [measurable_space δ] [measurable_space β]
[opens_measurable_space β] {f : α → δ} {g : δ → β}
(hf : measurable f) (hg : measurable g) :
integrable g (measure.map f μ) ↔ integrable (g ∘ f) μ :=
by simp only [integrable, lintegral_map hg.ennnorm hf]
lemma lintegral_nnnorm_eq_lintegral_edist (f : α → β) :
∫⁻ a, nnnorm (f a) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [edist_eq_coe_nnnorm]
lemma lintegral_norm_eq_lintegral_edist (f : α → β) :
∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ = ∫⁻ a, edist (f a) 0 ∂μ :=
by simp only [of_real_norm_eq_coe_nnnorm, edist_eq_coe_nnnorm]
lemma lintegral_edist_triangle [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g h : α → β}
(hf : measurable f) (hg : measurable g) (hh : measurable h) :
∫⁻ a, edist (f a) (g a) ∂μ ≤ ∫⁻ a, edist (f a) (h a) ∂μ + ∫⁻ a, edist (g a) (h a) ∂μ :=
begin
rw ← lintegral_add (hf.edist hh) (hg.edist hh),
refine lintegral_mono (λ a, _),
apply edist_triangle_right
end
lemma lintegral_edist_lt_top [second_countable_topology β] [measurable_space β]
[opens_measurable_space β] {f g : α → β}
(hfm : measurable f) (hfi : integrable f μ) (hgm : measurable g) (hgi : integrable g μ) :
∫⁻ a, edist (f a) (g a) ∂μ < ⊤ :=
lt_of_le_of_lt
(lintegral_edist_triangle hfm hgm (measurable_const : measurable (λa, (0 : β))))
(ennreal.add_lt_top.2 $ by { split; rw ← integrable_iff_edist; assumption })
lemma lintegral_nnnorm_zero : ∫⁻ a : α, nnnorm (0 : β) ∂μ = 0 := by simp
variables (α β μ)
@[simp] lemma integrable_zero : integrable (λa:α, (0:β)) μ :=
by simp [integrable]
variables {α β μ}
lemma lintegral_nnnorm_add [measurable_space β] [opens_measurable_space β]
[measurable_space γ] [opens_measurable_space γ]
{f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) :
∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ + ∫⁻ a, nnnorm (g a) ∂μ :=
lintegral_add hf.ennnorm hg.ennnorm
lemma integrable.add [measurable_space β] [opens_measurable_space β]
{f g : α → β} (hfm : measurable f) (hfi : integrable f μ)
(hgm : measurable g) (hgi : integrable g μ) :
integrable (f + g) μ :=
calc
∫⁻ a, nnnorm (f a + g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (g a) ∂μ :
lintegral_mono
(assume a, by { simp only [← coe_add, coe_le_coe], exact nnnorm_add_le _ _ })
... = _ :
lintegral_nnnorm_add hfm hgm
... < ⊤ : add_lt_top.2 ⟨hfi, hgi⟩
lemma integrable_finset_sum {ι} [measurable_space β] [borel_space β]
[second_countable_topology β] (s : finset ι) {f : ι → α → β}
(hfm : ∀ i, measurable (f i)) (hfi : ∀ i, integrable (f i) μ) :
integrable (λ a, ∑ i in s, f i a) μ :=
begin
refine finset.induction_on s _ _,
{ simp only [finset.sum_empty, integrable_zero] },
{ assume i s his ih,
simp only [his, finset.sum_insert, not_false_iff],
refine (hfi _).add (hfm _) (s.measurable_sum hfm) ih }
end
lemma lintegral_nnnorm_neg {f : α → β} :
∫⁻ a, nnnorm ((-f) a) ∂μ = ∫⁻ a, nnnorm (f a) ∂μ :=
by simp only [pi.neg_apply, nnnorm_neg]
lemma integrable.neg {f : α → β} (hfi : integrable f μ) : integrable (-f) μ :=
calc _ = _ : lintegral_nnnorm_neg
... < ⊤ : hfi
@[simp] lemma integrable_neg_iff {f : α → β} : integrable (-f) μ ↔ integrable f μ :=
⟨λ h, neg_neg f ▸ h.neg, integrable.neg⟩
lemma integrable.sub [measurable_space β] [opens_measurable_space β]
{f g : α → β} (hfm : measurable f) (hfi : integrable f μ) (hgm : measurable g)
(hgi : integrable g μ) : integrable (f - g) μ :=
calc
∫⁻ a, nnnorm (f a - g a) ∂μ ≤ ∫⁻ a, nnnorm (f a) + nnnorm (-g a) ∂μ :
lintegral_mono (assume a, by exact_mod_cast nnnorm_add_le _ _ )
... = _ :
by { simp only [nnnorm_neg], exact lintegral_nnnorm_add hfm hgm }
... < ⊤ : add_lt_top.2 ⟨hfi, hgi⟩
lemma integrable.norm {f : α → β} (hfi : integrable f μ) : integrable (λa, ∥f a∥) μ :=
have eq : (λa, (nnnorm ∥f a∥ : ennreal)) = λa, (nnnorm (f a) : ennreal),
by { funext, rw nnnorm_norm },
by { rwa [integrable, eq] }
lemma integrable_norm_iff (f : α → β) : integrable (λa, ∥f a∥) μ ↔ integrable f μ :=
integrable_congr' $ eventually_of_forall $ λ x, norm_norm (f x)
section dominated_convergence
variables {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
lemma all_ae_of_real_F_le_bound (h : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a) :
∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a∥ ≤ ennreal.of_real (bound a) :=
λn, (h n).mono $ λ a h, ennreal.of_real_le_of_real h
lemma all_ae_tendsto_of_real_norm (h : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top $ 𝓝 $ f a) :
∀ᵐ a ∂μ, tendsto (λn, ennreal.of_real ∥F n a∥) at_top $ 𝓝 $ ennreal.of_real ∥f a∥ :=
h.mono $
λ a h, tendsto_of_real $ tendsto.comp (continuous.tendsto continuous_norm _) h
lemma all_ae_of_real_f_le_bound (h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
∀ᵐ a ∂μ, ennreal.of_real ∥f a∥ ≤ ennreal.of_real (bound a) :=
begin
have F_le_bound := all_ae_of_real_F_le_bound h_bound,
rw ← ae_all_iff at F_le_bound,
apply F_le_bound.mp ((all_ae_tendsto_of_real_norm h_lim).mono _),
assume a tendsto_norm F_le_bound,
exact le_of_tendsto' tendsto_norm (F_le_bound)
end
lemma integrable_of_dominated_convergence {F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(bound_integrable : integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
integrable f μ :=
/- `∥F n a∥ ≤ bound a` and `∥F n a∥ --> ∥f a∥` implies `∥f a∥ ≤ bound a`,
and so `∫ ∥f∥ ≤ ∫ bound < ⊤` since `bound` is integrable -/
begin
rw integrable_iff_norm,
calc ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ ≤ ∫⁻ a, ennreal.of_real (bound a) ∂μ :
lintegral_mono_ae $ all_ae_of_real_f_le_bound h_bound h_lim
... < ⊤ :
begin
rw ← integrable_iff_of_real,
{ exact bound_integrable },
exact (h_bound 0).mono (λ a h, le_trans (norm_nonneg _) h)
end
end
lemma tendsto_lintegral_norm_of_dominated_convergence [measurable_space β]
[borel_space β] [second_countable_topology β]
{F : ℕ → α → β} {f : α → β} {bound : α → ℝ}
(F_measurable : ∀ n, measurable (F n))
(f_measurable : measurable f)
(bound_integrable : integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) :
tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 0) :=
let b := λa, 2 * ennreal.of_real (bound a) in
/- `∥F n a∥ ≤ bound a` and `F n a --> f a` implies `∥f a∥ ≤ bound a`, and thus by the
triangle inequality, have `∥F n a - f a∥ ≤ 2 * (bound a). -/
have hb : ∀ n, ∀ᵐ a ∂μ, ennreal.of_real ∥F n a - f a∥ ≤ b a,
begin
assume n,
filter_upwards [all_ae_of_real_F_le_bound h_bound n, all_ae_of_real_f_le_bound h_bound h_lim],
assume a h₁ h₂,
calc ennreal.of_real ∥F n a - f a∥ ≤ (ennreal.of_real ∥F n a∥) + (ennreal.of_real ∥f a∥) :
begin
rw [← ennreal.of_real_add],
apply of_real_le_of_real,
{ apply norm_sub_le }, { exact norm_nonneg _ }, { exact norm_nonneg _ }
end
... ≤ (ennreal.of_real (bound a)) + (ennreal.of_real (bound a)) : add_le_add h₁ h₂
... = b a : by rw ← two_mul
end,
/- On the other hand, `F n a --> f a` implies that `∥F n a - f a∥ --> 0` -/
have h : ∀ᵐ a ∂μ, tendsto (λ n, ennreal.of_real ∥F n a - f a∥) at_top (𝓝 0),
begin
rw ← ennreal.of_real_zero,
refine h_lim.mono (λ a h, (continuous_of_real.tendsto _).comp _),
rwa ← tendsto_iff_norm_tendsto_zero
end,
/- Therefore, by the dominated convergence theorem for nonnegative integration, have
` ∫ ∥f a - F n a∥ --> 0 ` -/
begin
suffices h : tendsto (λn, ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 (∫⁻ (a:α), 0 ∂μ)),
{ rwa lintegral_zero at h },
-- Using the dominated convergence theorem.
refine tendsto_lintegral_of_dominated_convergence _ _ hb _ _,
-- Show `λa, ∥f a - F n a∥` is measurable for all `n`
{ exact λn, measurable_of_real.comp ((F_measurable n).sub f_measurable).norm },
-- Show `2 * bound` is integrable
{ rw integrable_iff_of_real at bound_integrable,
{ calc ∫⁻ a, b a ∂μ = 2 * ∫⁻ a, ennreal.of_real (bound a) ∂μ :
by { rw lintegral_const_mul', exact coe_ne_top }
... < ⊤ : mul_lt_top (coe_lt_top) bound_integrable },
filter_upwards [h_bound 0] λ a h, le_trans (norm_nonneg _) h },
-- Show `∥f a - F n a∥ --> 0`
{ exact h }
end
end dominated_convergence
section pos_part
/-! Lemmas used for defining the positive part of a `L¹` function -/
lemma integrable.max_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, max (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x, by simp [real.norm_eq_abs, abs_le, abs_nonneg, le_abs_self]
lemma integrable.min_zero {f : α → ℝ} (hf : integrable f μ) : integrable (λa, min (f a) 0) μ :=
hf.mono $ eventually_of_forall $ λ x,
by simp [real.norm_eq_abs, abs_le, abs_nonneg, neg_le, neg_le_abs_self]
end pos_part
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul (c : 𝕜) {f : α → β} : integrable f μ → integrable (c • f) μ :=
begin
simp only [integrable], assume hfi,
calc
∫⁻ (a : α), nnnorm (c • f a) ∂μ = ∫⁻ (a : α), (nnnorm c) * nnnorm (f a) ∂μ :
by simp only [nnnorm_smul, ennreal.coe_mul]
... < ⊤ :
begin
rw lintegral_const_mul',
exacts [mul_lt_top coe_lt_top hfi, coe_ne_top]
end
end
lemma integrable_smul_iff {c : 𝕜} (hc : c ≠ 0) (f : α → β) :
integrable (c • f) μ ↔ integrable f μ :=
begin
split,
{ assume h,
simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.smul c⁻¹ },
exact integrable.smul _
end
lemma integrable.const_mul {f : α → ℝ} (h : integrable f μ) (c : ℝ) : integrable (λ x, c * f x) μ :=
(integrable.smul c h : _)
lemma integrable.mul_const {f : α → ℝ} (h : integrable f μ) (c : ℝ) : integrable (λ x, f x * c) μ :=
by simp_rw [mul_comm, h.const_mul _]
end normed_space
variables [second_countable_topology β]
namespace ae_eq_fun
variable [measurable_space β]
section
variable [opens_measurable_space β]
/-- An almost everywhere equal function is `integrable` if it has a finite distance to the origin.
Should mean the same thing as the predicate `integrable` over functions. -/
def integrable (f : α →ₘ[μ] β) : Prop := f ∈ ball (0 : α →ₘ[μ] β) ⊤
lemma integrable_mk {f : α → β} (hf : measurable f) :
(integrable (mk f hf : α →ₘ[μ] β)) ↔ measure_theory.integrable f μ :=
by simp [integrable, zero_def, edist_mk_mk', measure_theory.integrable, nndist_eq_nnnorm]
lemma integrable_coe_fn {f : α →ₘ[μ] β} : (measure_theory.integrable f μ) ↔ integrable f :=
by rw [← integrable_mk, mk_coe_fn]
local attribute [simp] integrable_mk
lemma integrable_zero : integrable (0 : α →ₘ[μ] β) := mem_ball_self coe_lt_top
end
section
variable [borel_space β]
lemma integrable.add {f g : α →ₘ[μ] β} : integrable f → integrable g → integrable (f + g) :=
begin
refine induction_on₂ f g (λ f hf g hg, _),
simp only [integrable_mk, mk_add_mk],
exact λ hfi hgi, hfi.add hf hg hgi
end
lemma integrable.neg {f : α →ₘ[μ] β} : integrable f → integrable (-f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg
lemma integrable.sub {f g : α →ₘ[μ] β} (hf : integrable f) (hg : integrable g) :
integrable (f - g) :=
hf.add hg.neg
protected lemma is_add_subgroup : is_add_subgroup (ball (0 : α →ₘ[μ] β) ⊤) :=
{ zero_mem := integrable_zero,
add_mem := λ _ _, integrable.add,
neg_mem := λ _, integrable.neg }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma integrable.smul {c : 𝕜} {f : α →ₘ[μ] β} : integrable f → integrable (c • f) :=
induction_on f $ λ f hfm hfi, (integrable_mk _).2 $ ((integrable_mk hfm).1 hfi).smul _
end normed_space
end
end ae_eq_fun
variables (α β)
/-- The space of equivalence classes of integrable (and measurable) functions, where two integrable
functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure
`0`. -/
def l1 [measurable_space β] [opens_measurable_space β] (μ : measure α) : Type (max u v) :=
{f : α →ₘ[μ] β // f.integrable}
notation α ` →₁[`:25 μ `] ` β := l1 α β μ
variables {α β}
namespace l1
open ae_eq_fun
local attribute [instance] ae_eq_fun.is_add_subgroup
variables [measurable_space β]
section
variable [opens_measurable_space β]
instance : has_coe (α →₁[μ] β) (α →ₘ[μ] β) := coe_subtype
instance : has_coe_to_fun (α →₁[μ] β) := ⟨λ f, α → β, λ f, ⇑(f : α →ₘ[μ] β)⟩
@[simp, norm_cast] lemma coe_coe (f : α →₁[μ] β) : ⇑(f : α →ₘ[μ] β) = f := rfl
protected lemma eq {f g : α →₁[μ] β} : (f : α →ₘ[μ] β) = (g : α →ₘ[μ] β) → f = g := subtype.eq
@[norm_cast] protected lemma eq_iff {f g : α →₁[μ] β} : (f : α →ₘ[μ] β) = (g : α →ₘ[μ] β) ↔ f = g :=
iff.intro (l1.eq) (congr_arg coe)
/- TODO : order structure of l1-/
/-- `L¹` space forms a `emetric_space`, with the emetric being inherited from almost everywhere
functions, i.e., `edist f g = ∫⁻ a, edist (f a) (g a)`. -/
instance : emetric_space (α →₁[μ] β) := subtype.emetric_space
/-- `L¹` space forms a `metric_space`, with the metric being inherited from almost everywhere
functions, i.e., `edist f g = ennreal.to_real (∫⁻ a, edist (f a) (g a))`. -/
instance : metric_space (α →₁[μ] β) := metric_space_emetric_ball 0 ⊤
end
variable [borel_space β]
instance : add_comm_group (α →₁[μ] β) := subtype.add_comm_group
instance : inhabited (α →₁[μ] β) := ⟨0⟩
@[simp, norm_cast] lemma coe_zero : ((0 : α →₁[μ] β) : α →ₘ[μ] β) = 0 := rfl
@[simp, norm_cast]
lemma coe_add (f g : α →₁[μ] β) : ((f + g : α →₁[μ] β) : α →ₘ[μ] β) = f + g := rfl
@[simp, norm_cast] lemma coe_neg (f : α →₁[μ] β) : ((-f : α →₁[μ] β) : α →ₘ[μ] β) = -f := rfl
@[simp, norm_cast]
lemma coe_sub (f g : α →₁[μ] β) : ((f - g : α →₁[μ] β) : α →ₘ[μ] β) = f - g := rfl
@[simp] lemma edist_eq (f g : α →₁[μ] β) : edist f g = edist (f : α →ₘ[μ] β) (g : α →ₘ[μ] β) := rfl
lemma dist_eq (f g : α →₁[μ] β) :
dist f g = ennreal.to_real (edist (f : α →ₘ[μ] β) (g : α →ₘ[μ] β)) :=
rfl
/-- The norm on `L¹` space is defined to be `∥f∥ = ∫⁻ a, edist (f a) 0`. -/
instance : has_norm (α →₁[μ] β) := ⟨λ f, dist f 0⟩
lemma norm_eq (f : α →₁[μ] β) : ∥f∥ = ennreal.to_real (edist (f : α →ₘ[μ] β) 0) := rfl
instance : normed_group (α →₁[μ] β) := normed_group.of_add_dist (λ x, rfl) $ by
{ intros, simp only [dist_eq, coe_add], rw edist_add_right }
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
instance : has_scalar 𝕜 (α →₁[μ] β) := ⟨λ x f, ⟨x • (f : α →ₘ[μ] β), ae_eq_fun.integrable.smul f.2⟩⟩
@[simp, norm_cast] lemma coe_smul (c : 𝕜) (f : α →₁[μ] β) :
((c • f : α →₁[μ] β) : α →ₘ[μ] β) = c • (f : α →ₘ[μ] β) := rfl
instance : semimodule 𝕜 (α →₁[μ] β) :=
{ one_smul := λf, l1.eq (by { simp only [coe_smul], exact one_smul _ _ }),
mul_smul := λx y f, l1.eq (by { simp only [coe_smul], exact mul_smul _ _ _ }),
smul_add := λx f g, l1.eq (by { simp only [coe_smul, coe_add], exact smul_add _ _ _ }),
smul_zero := λx, l1.eq (by { simp only [coe_zero, coe_smul], exact smul_zero _ }),
add_smul := λx y f, l1.eq (by { simp only [coe_smul], exact add_smul _ _ _ }),
zero_smul := λf, l1.eq (by { simp only [coe_smul], exact zero_smul _ _ }) }
instance : normed_space 𝕜 (α →₁[μ] β) :=
⟨ begin
rintros x ⟨f, hf⟩,
show ennreal.to_real (edist (x • f) 0) ≤ ∥x∥ * ennreal.to_real (edist f 0),
rw [edist_smul, to_real_of_real_mul],
exact norm_nonneg _
end ⟩
end normed_space
section of_fun
/-- Construct the equivalence class `[f]` of a measurable and integrable function `f`. -/
def of_fun (f : α → β) (hfm : measurable f) (hfi : integrable f μ) : (α →₁[μ] β) :=
⟨mk f hfm, by { rw integrable_mk, exact hfi }⟩
@[simp] lemma of_fun_eq_mk (f : α → β) (hfm hfi) :
((of_fun f hfm hfi : α →₁[μ] β) : α →ₘ[μ] β) = mk f hfm :=
rfl
lemma of_fun_eq_of_fun (f g : α → β) (hfm hfi hgm hgi) :
(of_fun f hfm hfi : α →₁[μ] β) = of_fun g hgm hgi ↔ f =ᵐ[μ] g :=
by { rw ← l1.eq_iff, simp only [of_fun_eq_mk, mk_eq_mk] }
lemma of_fun_zero :
(of_fun (λ _, 0) measurable_zero (integrable_zero α μ β) : α →₁[μ] β) = 0 := rfl
lemma of_fun_add (f g : α → β) (hfm hfi hgm hgi) :
(of_fun (f + g) (measurable.add hfm hgm) (integrable.add hfm hfi hgm hgi) : α →₁[μ] β)
= of_fun f hfm hfi + of_fun g hgm hgi :=
rfl
lemma of_fun_neg (f : α → β) (hfm hfi) :
(of_fun (- f) (measurable.neg hfm) (integrable.neg hfi) : α →₁[μ] β) = - of_fun f hfm hfi := rfl
lemma of_fun_sub (f g : α → β) (hfm hfi hgm hgi) :
(of_fun (f - g) (measurable.sub hfm hgm) (integrable.sub hfm hfi hgm hgi) : α →₁[μ] β)
= of_fun f hfm hfi - of_fun g hgm hgi :=
rfl
lemma norm_of_fun (f : α → β) (hfm hfi) :
∥(of_fun f hfm hfi : α →₁[μ] β)∥ = ennreal.to_real (∫⁻ a, edist (f a) 0 ∂μ) :=
rfl
lemma norm_of_fun_eq_lintegral_norm (f : α → β) (hfm hfi) :
∥(of_fun f hfm hfi : α →₁[μ] β)∥ = ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
by { rw [norm_of_fun, lintegral_norm_eq_lintegral_edist] }
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma of_fun_smul (f : α → β) (hfm : measurable f) (hfi : integrable f μ) (k : 𝕜) :
of_fun (λa, k • f a) (hfm.const_smul _) (hfi.smul _) = k • of_fun f hfm hfi := rfl
end of_fun
section to_fun
protected lemma measurable (f : α →₁[μ] β) : measurable f := f.1.measurable
lemma measurable_norm (f : α →₁[μ] β) : measurable (λ a, ∥f a∥) :=
f.measurable.norm
protected lemma integrable (f : α →₁[μ] β) : integrable ⇑f μ :=
integrable_coe_fn.2 f.2
lemma integrable_norm (f : α →₁[μ] β) : integrable (λ a, ∥f a∥) μ :=
(integrable_norm_iff _).mpr f.integrable
lemma of_fun_to_fun (f : α →₁[μ] β) : of_fun f f.measurable f.integrable = f :=
subtype.ext (f : α →ₘ[μ] β).mk_coe_fn
lemma mk_to_fun (f : α →₁[μ] β) : (mk f f.measurable : α →ₘ[μ] β) = f :=
by { rw ← of_fun_eq_mk, rw l1.eq_iff, exact of_fun_to_fun f }
lemma to_fun_of_fun (f : α → β) (hfm hfi) :
⇑(of_fun f hfm hfi : α →₁[μ] β) =ᵐ[μ] f :=
coe_fn_mk f hfm
variables (α β)
lemma zero_to_fun : ⇑(0 : α →₁[μ] β) =ᵐ[μ] 0 := ae_eq_fun.coe_fn_zero
variables {α β}
lemma add_to_fun (f g : α →₁[μ] β) : ⇑(f + g) =ᵐ[μ] f + g :=
ae_eq_fun.coe_fn_add _ _
lemma neg_to_fun (f : α →₁[μ] β) : ⇑(-f) =ᵐ[μ] -⇑f := ae_eq_fun.coe_fn_neg _
lemma sub_to_fun (f g : α →₁[μ] β) : ⇑(f - g) =ᵐ[μ] ⇑f - ⇑g :=
ae_eq_fun.coe_fn_sub _ _
lemma dist_to_fun (f g : α →₁[μ] β) :
dist f g = ennreal.to_real (∫⁻ x, edist (f x) (g x) ∂μ) :=
by { simp only [← coe_coe, dist_eq, edist_eq_coe] }
lemma norm_eq_nnnorm_to_fun (f : α →₁[μ] β) : ∥f∥ = ennreal.to_real (∫⁻ a, nnnorm (f a) ∂μ) :=
by { rw [← coe_coe, lintegral_nnnorm_eq_lintegral_edist, ← edist_zero_eq_coe], refl }
lemma norm_eq_norm_to_fun (f : α →₁[μ] β) :
∥f∥ = ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
by { rw norm_eq_nnnorm_to_fun, congr, funext, rw of_real_norm_eq_coe_nnnorm }
lemma lintegral_edist_to_fun_lt_top (f g : α →₁[μ] β) : (∫⁻ a, edist (f a) (g a) ∂μ) < ⊤ :=
begin
apply lintegral_edist_lt_top,
exact f.measurable, exact f.integrable, exact g.measurable, exact g.integrable
end
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 β]
lemma smul_to_fun (c : 𝕜) (f : α →₁[μ] β) : ⇑(c • f) =ᵐ[μ] c • f :=
ae_eq_fun.coe_fn_smul _ _
end to_fun
section pos_part
/-- Positive part of a function in `L¹` space. -/
def pos_part (f : α →₁[μ] ℝ) : α →₁[μ] ℝ :=
⟨ae_eq_fun.pos_part f,
begin
rw [← ae_eq_fun.integrable_coe_fn, integrable_congr (coe_fn_pos_part _)],
exact integrable.max_zero f.integrable
end ⟩
/-- Negative part of a function in `L¹` space. -/
def neg_part (f : α →₁[μ] ℝ) : α →₁[μ] ℝ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : α →₁[μ] ℝ) : (f.pos_part : α →ₘ[μ] ℝ) = (f : α →ₘ[μ] ℝ).pos_part := rfl
lemma pos_part_to_fun (f : α →₁[μ] ℝ) : ⇑(pos_part f) =ᵐ[μ] λ a, max (f a) 0 :=
ae_eq_fun.coe_fn_pos_part _
lemma neg_part_to_fun_eq_max (f : α →₁[μ] ℝ) : ∀ᵐ a ∂μ, neg_part f a = max (- f a) 0 :=
begin
rw neg_part,
filter_upwards [pos_part_to_fun (-f), neg_to_fun f],
simp only [mem_set_of_eq],
assume a h₁ h₂,
rw [h₁, h₂, pi.neg_apply]
end
lemma neg_part_to_fun_eq_min (f : α →₁[μ] ℝ) : ∀ᵐ a ∂μ, neg_part f a = - min (f a) 0 :=
(neg_part_to_fun_eq_max f).mono $ assume a h,
by rw [h, min_eq_neg_max_neg_neg, _root_.neg_neg, neg_zero]
lemma norm_le_norm_of_ae_le {f g : α →₁[μ] β} (h : ∀ᵐ a ∂μ, ∥f a∥ ≤ ∥g a∥) : ∥f∥ ≤ ∥g∥ :=
begin
simp only [l1.norm_eq_norm_to_fun],
rw to_real_le_to_real,
{ apply lintegral_mono_ae,
exact h.mono (λ a h, of_real_le_of_real h) },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact f.integrable },
{ rw [← lt_top_iff_ne_top, ← integrable_iff_norm], exact g.integrable }
end
lemma continuous_pos_part : continuous $ λf : α →₁[μ] ℝ, pos_part f :=
begin
simp only [metric.continuous_iff],
assume g ε hε,
use ε, use hε,
simp only [dist_eq_norm],
assume f hfg,
refine lt_of_le_of_lt (norm_le_norm_of_ae_le _) hfg,
filter_upwards [l1.sub_to_fun f g, l1.sub_to_fun (pos_part f) (pos_part g),
pos_part_to_fun f, pos_part_to_fun g],
simp only [mem_set_of_eq],
assume a h₁ h₂ h₃ h₄,
simp only [real.norm_eq_abs, h₁, h₂, h₃, h₄, pi.sub_apply],
exact abs_max_sub_max_le_abs _ _ _
end
lemma continuous_neg_part : continuous $ λf : α →₁[μ] ℝ, neg_part f :=
have eq : (λf : α →₁[μ] ℝ, neg_part f) = (λf : α →₁[μ] ℝ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
/- TODO: l1 is a complete space -/
end l1
end measure_theory
|
1c4efcf330acfcdd50a16830a055e574fff2ed10
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/category_theory/abelian/non_preadditive.lean
|
c9013e51d9e808aa7a057f6f18260c7a270cd77c
|
[
"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
| 32,457
|
lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.limits.shapes.finite_products
import category_theory.limits.shapes.kernels
import category_theory.limits.shapes.pullbacks
import category_theory.limits.shapes.regular_mono
import category_theory.preadditive
/-!
# Every non_preadditive_abelian category is preadditive
In mathlib, we define an abelian category as a preadditive category with a zero object,
kernels and cokernels, products and coproducts and in which every monomorphism and epimorphis is
normal.
While virtually every interesting abelian category has a natural preadditive structure (which is why
it is included in the definition), preadditivity is not actually needed: Every category that has
all of the other properties appearing in the definition of an abelian category admits a preadditive
structure. This is the construction we carry out in this file.
The proof proceeds in roughly five steps:
1. Prove some results (for example that all equalizers exist) that would be trivial if we already
had the preadditive structure but are a bit of work without it.
2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel.
The results of the first two steps are also useful for the "normal" development of abelian
categories, and will be used there.
3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define
subtraction on morphisms as `f - g := prod.lift f g ≫ σ`.
4. Prove a small number of identities about this subtraction from the definition of `σ`.
5. From these identities, prove a large number of other identities that imply that defining
`f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition
is bilinear.
The construction is non-trivial and it is quite remarkable that this abelian group structure can
be constructed purely from the existence of a few limits and colimits. What's even more impressive
is that all additive structures on a category are in some sense isomorphic, so for abelian
categories with a natural preadditive structure, this construction manages to "almost" reconstruct
this natural structure. However, we have not formalized this isomorphism.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable theory
open category_theory
open category_theory.limits
namespace category_theory
section
universes v u
variables (C : Type u) [category.{v} C]
/-- We call a category `non_preadditive_abelian` if it has a zero object, kernels, cokernels, binary
products and coproducts, and every monomorphism and every epimorphism is normal. -/
class non_preadditive_abelian :=
[has_zero_object : has_zero_object C]
[has_zero_morphisms : has_zero_morphisms C]
[has_kernels : has_kernels C]
[has_cokernels : has_cokernels C]
[has_finite_products : has_finite_products C]
[has_finite_coproducts : has_finite_coproducts C]
(normal_mono : Π {X Y : C} (f : X ⟶ Y) [mono f], normal_mono f)
(normal_epi : Π {X Y : C} (f : X ⟶ Y) [epi f], normal_epi f)
set_option default_priority 100
attribute [instance] non_preadditive_abelian.has_zero_object
attribute [instance] non_preadditive_abelian.has_zero_morphisms
attribute [instance] non_preadditive_abelian.has_kernels
attribute [instance] non_preadditive_abelian.has_cokernels
attribute [instance] non_preadditive_abelian.has_finite_products
attribute [instance] non_preadditive_abelian.has_finite_coproducts
end
end category_theory
open category_theory
namespace category_theory.non_preadditive_abelian
universes v u
variables {C : Type u} [category.{v} C]
section
variables [non_preadditive_abelian C]
section strong
local attribute [instance] non_preadditive_abelian.normal_epi
/-- In a `non_preadditive_abelian` category, every epimorphism is strong. -/
lemma strong_epi_of_epi {P Q : C} (f : P ⟶ Q) [epi f] : strong_epi f := by apply_instance
end strong
section mono_epi_iso
variables {X Y : C} (f : X ⟶ Y)
local attribute [instance] strong_epi_of_epi
/-- In a `non_preadditive_abelian` category, a monomorphism which is also an epimorphism is an
isomorphism. -/
def is_iso_of_mono_of_epi [mono f] [epi f] : is_iso f :=
is_iso_of_mono_of_strong_epi _
end mono_epi_iso
/-- The pullback of two monomorphisms exists. -/
@[irreducible]
lemma pullback_of_mono {X Y Z : C} (a : X ⟶ Z) (b : Y ⟶ Z) [mono a] [mono b] :
has_limit (cospan a b) :=
let ⟨P, f, haf, i⟩ := non_preadditive_abelian.normal_mono a in
let ⟨Q, g, hbg, i'⟩ := non_preadditive_abelian.normal_mono b in
let ⟨a', ha'⟩ := kernel_fork.is_limit.lift' i (kernel.ι (prod.lift f g)) $
calc kernel.ι (prod.lift f g) ≫ f
= kernel.ι (prod.lift f g) ≫ prod.lift f g ≫ limits.prod.fst : by rw prod.lift_fst
... = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ limits.prod.fst : by rw kernel.condition_assoc
... = 0 : zero_comp in
let ⟨b', hb'⟩ := kernel_fork.is_limit.lift' i' (kernel.ι (prod.lift f g)) $
calc kernel.ι (prod.lift f g) ≫ g
= kernel.ι (prod.lift f g) ≫ (prod.lift f g) ≫ limits.prod.snd : by rw prod.lift_snd
... = (0 : kernel (prod.lift f g) ⟶ P ⨯ Q) ≫ limits.prod.snd : by rw kernel.condition_assoc
... = 0 : zero_comp in
has_limit.mk { cone := pullback_cone.mk a' b' $ by { simp at ha' hb', rw [ha', hb'] },
is_limit := pullback_cone.is_limit.mk _ _ _
(λ s, kernel.lift (prod.lift f g) (pullback_cone.snd s ≫ b) $ prod.hom_ext
(calc ((pullback_cone.snd s ≫ b) ≫ prod.lift f g) ≫ limits.prod.fst
= pullback_cone.snd s ≫ b ≫ f : by simp only [prod.lift_fst, category.assoc]
... = pullback_cone.fst s ≫ a ≫ f : by rw pullback_cone.condition_assoc
... = pullback_cone.fst s ≫ 0 : by rw haf
... = 0 ≫ limits.prod.fst :
by rw [comp_zero, zero_comp])
(calc ((pullback_cone.snd s ≫ b) ≫ prod.lift f g) ≫ limits.prod.snd
= pullback_cone.snd s ≫ b ≫ g : by simp only [prod.lift_snd, category.assoc]
... = pullback_cone.snd s ≫ 0 : by rw hbg
... = 0 ≫ limits.prod.snd :
by rw [comp_zero, zero_comp]))
(λ s, (cancel_mono a).1 $
by { rw kernel_fork.ι_of_ι at ha', simp [ha', pullback_cone.condition s] })
(λ s, (cancel_mono b).1 $
by { rw kernel_fork.ι_of_ι at hb', simp [hb'] })
(λ s m h₁ h₂, (cancel_mono (kernel.ι (prod.lift f g))).1 $ calc m ≫ kernel.ι (prod.lift f g)
= m ≫ a' ≫ a : by { congr, exact ha'.symm }
... = pullback_cone.fst s ≫ a : by rw [←category.assoc, h₁]
... = pullback_cone.snd s ≫ b : pullback_cone.condition s
... = kernel.lift (prod.lift f g) (pullback_cone.snd s ≫ b) _ ≫ kernel.ι (prod.lift f g) :
by rw kernel.lift_ι) }
/-- The pushout of two epimorphisms exists. -/
@[irreducible]
lemma pushout_of_epi {X Y Z : C} (a : X ⟶ Y) (b : X ⟶ Z) [epi a] [epi b] :
has_colimit (span a b) :=
let ⟨P, f, hfa, i⟩ := non_preadditive_abelian.normal_epi a in
let ⟨Q, g, hgb, i'⟩ := non_preadditive_abelian.normal_epi b in
let ⟨a', ha'⟩ := cokernel_cofork.is_colimit.desc' i (cokernel.π (coprod.desc f g)) $
calc f ≫ cokernel.π (coprod.desc f g)
= coprod.inl ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) : by rw coprod.inl_desc_assoc
... = coprod.inl ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) : by rw cokernel.condition
... = 0 : has_zero_morphisms.comp_zero _ _ in
let ⟨b', hb'⟩ := cokernel_cofork.is_colimit.desc' i' (cokernel.π (coprod.desc f g)) $
calc g ≫ cokernel.π (coprod.desc f g)
= coprod.inr ≫ coprod.desc f g ≫ cokernel.π (coprod.desc f g) : by rw coprod.inr_desc_assoc
... = coprod.inr ≫ (0 : P ⨿ Q ⟶ cokernel (coprod.desc f g)) : by rw cokernel.condition
... = 0 : has_zero_morphisms.comp_zero _ _ in
has_colimit.mk
{ cocone := pushout_cocone.mk a' b' $ by { simp only [cofork.π_of_π] at ha' hb', rw [ha', hb'] },
is_colimit := pushout_cocone.is_colimit.mk _ _ _
(λ s, cokernel.desc (coprod.desc f g) (b ≫ pushout_cocone.inr s) $ coprod.hom_ext
(calc coprod.inl ≫ coprod.desc f g ≫ b ≫ pushout_cocone.inr s
= f ≫ b ≫ pushout_cocone.inr s : by rw coprod.inl_desc_assoc
... = f ≫ a ≫ pushout_cocone.inl s : by rw pushout_cocone.condition
... = 0 ≫ pushout_cocone.inl s : by rw reassoc_of hfa
... = coprod.inl ≫ 0 : by rw [comp_zero, zero_comp])
(calc coprod.inr ≫ coprod.desc f g ≫ b ≫ pushout_cocone.inr s
= g ≫ b ≫ pushout_cocone.inr s : by rw coprod.inr_desc_assoc
... = 0 ≫ pushout_cocone.inr s : by rw reassoc_of hgb
... = coprod.inr ≫ 0 : by rw [comp_zero, zero_comp]))
(λ s, (cancel_epi a).1 $
by { rw cokernel_cofork.π_of_π at ha', simp [reassoc_of ha', pushout_cocone.condition s] })
(λ s, (cancel_epi b).1 $ by { rw cokernel_cofork.π_of_π at hb', simp [reassoc_of hb'] })
(λ s m h₁ h₂, (cancel_epi (cokernel.π (coprod.desc f g))).1 $ calc cokernel.π (coprod.desc f g) ≫ m
= (a ≫ a') ≫ m : by { congr, exact ha'.symm }
... = a ≫ pushout_cocone.inl s : by rw [category.assoc, h₁]
... = b ≫ pushout_cocone.inr s : pushout_cocone.condition s
... = cokernel.π (coprod.desc f g) ≫ cokernel.desc (coprod.desc f g) (b ≫ pushout_cocone.inr s) _ :
by rw cokernel.π_desc) }
section
local attribute [instance] pullback_of_mono
/-- The pullback of `(𝟙 X, f)` and `(𝟙 X, g)` -/
private abbreviation P {X Y : C} (f g : X ⟶ Y)
[mono (prod.lift (𝟙 X) f)] [mono (prod.lift (𝟙 X) g)] : C :=
pullback (prod.lift (𝟙 X) f) (prod.lift (𝟙 X) g)
/-- The equalizer of `f` and `g` exists. -/
@[irreducible]
lemma has_limit_parallel_pair {X Y : C} (f g : X ⟶ Y) : has_limit (parallel_pair f g) :=
have h1f : mono (prod.lift (𝟙 X) f), from mono_of_mono_fac $ prod.lift_fst (𝟙 X) f,
have h1g : mono (prod.lift (𝟙 X) g), from mono_of_mono_fac $ prod.lift_fst (𝟙 X) g,
have huv : (pullback.fst : P f g ⟶ X) = pullback.snd, from
calc (pullback.fst : P f g ⟶ X) = pullback.fst ≫ 𝟙 _ : eq.symm $ category.comp_id _
... = pullback.fst ≫ prod.lift (𝟙 X) f ≫ limits.prod.fst : by rw prod.lift_fst
... = pullback.snd ≫ prod.lift (𝟙 X) g ≫ limits.prod.fst : by rw pullback.condition_assoc
... = pullback.snd : by rw [prod.lift_fst, category.comp_id],
have hvu : (pullback.fst : P f g ⟶ X) ≫ f = pullback.snd ≫ g, from
calc (pullback.fst : P f g ⟶ X) ≫ f
= pullback.fst ≫ prod.lift (𝟙 X) f ≫ limits.prod.snd : by rw prod.lift_snd
... = pullback.snd ≫ prod.lift (𝟙 X) g ≫ limits.prod.snd : by rw pullback.condition_assoc
... = pullback.snd ≫ g : by rw prod.lift_snd,
have huu : (pullback.fst : P f g ⟶ X) ≫ f = pullback.fst ≫ g, by rw [hvu, ←huv],
has_limit.mk { cone := fork.of_ι pullback.fst huu,
is_limit := fork.is_limit.mk _
(λ s, pullback.lift (fork.ι s) (fork.ι s) $ prod.hom_ext
(by simp only [prod.lift_fst, category.assoc])
(by simp only [fork.app_zero_right, fork.app_zero_left, prod.lift_snd, category.assoc]))
(λ s, by simp only [fork.ι_of_ι, pullback.lift_fst])
(λ s m h, pullback.hom_ext
(by simpa only [pullback.lift_fst] using h walking_parallel_pair.zero)
(by simpa only [huv.symm, pullback.lift_fst] using h walking_parallel_pair.zero)) }
end
section
local attribute [instance] pushout_of_epi
/-- The pushout of `(𝟙 Y, f)` and `(𝟙 Y, g)`. -/
private abbreviation Q {X Y : C} (f g : X ⟶ Y)
[epi (coprod.desc (𝟙 Y) f)] [epi (coprod.desc (𝟙 Y) g)] : C :=
pushout (coprod.desc (𝟙 Y) f) (coprod.desc (𝟙 Y) g)
/-- The coequalizer of `f` and `g` exists. -/
@[irreducible]
lemma has_colimit_parallel_pair {X Y : C} (f g : X ⟶ Y) : has_colimit (parallel_pair f g) :=
have h1f : epi (coprod.desc (𝟙 Y) f), from epi_of_epi_fac $ coprod.inl_desc _ _,
have h1g : epi (coprod.desc (𝟙 Y) g), from epi_of_epi_fac $ coprod.inl_desc _ _,
have huv : (pushout.inl : Y ⟶ Q f g) = pushout.inr, from
calc (pushout.inl : Y ⟶ Q f g) = 𝟙 _ ≫ pushout.inl : eq.symm $ category.id_comp _
... = (coprod.inl ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl : by rw coprod.inl_desc
... = (coprod.inl ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr :
by simp only [category.assoc, pushout.condition]
... = pushout.inr : by rw [coprod.inl_desc, category.id_comp],
have hvu : f ≫ (pushout.inl : Y ⟶ Q f g) = g ≫ pushout.inr, from
calc f ≫ (pushout.inl : Y ⟶ Q f g)
= (coprod.inr ≫ coprod.desc (𝟙 Y) f) ≫ pushout.inl : by rw coprod.inr_desc
... = (coprod.inr ≫ coprod.desc (𝟙 Y) g) ≫ pushout.inr :
by simp only [category.assoc, pushout.condition]
... = g ≫ pushout.inr : by rw coprod.inr_desc,
have huu : f ≫ (pushout.inl : Y ⟶ Q f g) = g ≫ pushout.inl, by rw [hvu, huv],
has_colimit.mk { cocone := cofork.of_π pushout.inl huu,
is_colimit := cofork.is_colimit.mk _
(λ s, pushout.desc (cofork.π s) (cofork.π s) $ coprod.hom_ext
(by simp only [coprod.inl_desc_assoc])
(by simp only [cofork.right_app_one, coprod.inr_desc_assoc, cofork.left_app_one]))
(λ s, by simp only [pushout.inl_desc, cofork.π_of_π])
(λ s m h, pushout.hom_ext
(by simpa only [pushout.inl_desc] using h walking_parallel_pair.one)
(by simpa only [huv.symm, pushout.inl_desc] using h walking_parallel_pair.one)) }
end
section
local attribute [instance] has_limit_parallel_pair
/-- A `non_preadditive_abelian` category has all equalizers. -/
@[priority 100] instance has_equalizers : has_equalizers C :=
has_equalizers_of_has_limit_parallel_pair _
end
section
local attribute [instance] has_colimit_parallel_pair
/-- A `non_preadditive_abelian` category has all coequalizers. -/
@[priority 100] instance has_coequalizers : has_coequalizers C :=
has_coequalizers_of_has_colimit_parallel_pair _
end
section
/-- If a zero morphism is a kernel of `f`, then `f` is a monomorphism. -/
lemma mono_of_zero_kernel {X Y : C} (f : X ⟶ Y) (Z : C)
(l : is_limit (kernel_fork.of_ι (0 : Z ⟶ X) (show 0 ≫ f = 0, by simp))) : mono f :=
⟨λ P u v huv,
begin
obtain ⟨W, w, hw, hl⟩ := non_preadditive_abelian.normal_epi (coequalizer.π u v),
obtain ⟨m, hm⟩ := coequalizer.desc' f huv,
have hwf : w ≫ f = 0,
{ rw [←hm, reassoc_of hw, zero_comp] },
obtain ⟨n, hn⟩ := kernel_fork.is_limit.lift' l _ hwf,
rw [fork.ι_of_ι, has_zero_morphisms.comp_zero] at hn,
haveI : is_iso (coequalizer.π u v) :=
by apply is_iso_colimit_cocone_parallel_pair_of_eq hn.symm hl,
apply (cancel_mono (coequalizer.π u v)).1,
exact coequalizer.condition _ _
end⟩
/-- If a zero morphism is a cokernel of `f`, then `f` is an epimorphism. -/
lemma epi_of_zero_cokernel {X Y : C} (f : X ⟶ Y) (Z : C)
(l : is_colimit (cokernel_cofork.of_π (0 : Y ⟶ Z) (show f ≫ 0 = 0, by simp))) : epi f :=
⟨λ P u v huv,
begin
obtain ⟨W, w, hw, hl⟩ := non_preadditive_abelian.normal_mono (equalizer.ι u v),
obtain ⟨m, hm⟩ := equalizer.lift' f huv,
have hwf : f ≫ w = 0,
{ rw [←hm, category.assoc, hw, comp_zero] },
obtain ⟨n, hn⟩ := cokernel_cofork.is_colimit.desc' l _ hwf,
rw [cofork.π_of_π, zero_comp] at hn,
haveI : is_iso (equalizer.ι u v) :=
by apply is_iso_limit_cone_parallel_pair_of_eq hn.symm hl,
apply (cancel_epi (equalizer.ι u v)).1,
exact equalizer.condition _ _
end⟩
local attribute [instance] has_zero_object.has_zero
/-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `0 : 0 ⟶ X` is a kernel of `f`. -/
def zero_kernel_of_cancel_zero {X Y : C} (f : X ⟶ Y)
(hf : ∀ (Z : C) (g : Z ⟶ X) (hgf : g ≫ f = 0), g = 0) :
is_limit (kernel_fork.of_ι (0 : 0 ⟶ X) (show 0 ≫ f = 0, by simp)) :=
fork.is_limit.mk _ (λ s, 0)
(λ s, by rw [hf _ _ (kernel_fork.condition s), zero_comp])
(λ s m h, by ext)
/-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `0 : Y ⟶ 0` is a cokernel of `f`. -/
def zero_cokernel_of_zero_cancel {X Y : C} (f : X ⟶ Y)
(hf : ∀ (Z : C) (g : Y ⟶ Z) (hgf : f ≫ g = 0), g = 0) :
is_colimit (cokernel_cofork.of_π (0 : Y ⟶ 0) (show f ≫ 0 = 0, by simp)) :=
cofork.is_colimit.mk _ (λ s, 0)
(λ s, by rw [hf _ _ (cokernel_cofork.condition s), comp_zero])
(λ s m h, by ext)
/-- If `g ≫ f = 0` implies `g = 0` for all `g`, then `f` is a monomorphism. -/
lemma mono_of_cancel_zero {X Y : C} (f : X ⟶ Y)
(hf : ∀ (Z : C) (g : Z ⟶ X) (hgf : g ≫ f = 0), g = 0) : mono f :=
mono_of_zero_kernel f 0 $ zero_kernel_of_cancel_zero f hf
/-- If `f ≫ g = 0` implies `g = 0` for all `g`, then `g` is a monomorphism. -/
lemma epi_of_zero_cancel {X Y : C} (f : X ⟶ Y)
(hf : ∀ (Z : C) (g : Y ⟶ Z) (hgf : f ≫ g = 0), g = 0) : epi f :=
epi_of_zero_cokernel f 0 $ zero_cokernel_of_zero_cancel f hf
end
section factor
variables {P Q : C} (f : P ⟶ Q)
/-- The kernel of the cokernel of `f` is called the image of `f`. -/
protected abbreviation image : C := kernel (cokernel.π f)
/-- The inclusion of the image into the codomain. -/
protected abbreviation image.ι : non_preadditive_abelian.image f ⟶ Q :=
kernel.ι (cokernel.π f)
/-- There is a canonical epimorphism `p : P ⟶ image f` for every `f`. -/
protected abbreviation factor_thru_image : P ⟶ non_preadditive_abelian.image f :=
kernel.lift (cokernel.π f) f $ cokernel.condition f
/-- `f` factors through its image via the canonical morphism `p`. -/
@[simp, reassoc] protected lemma image.fac :
non_preadditive_abelian.factor_thru_image f ≫ image.ι f = f :=
kernel.lift_ι _ _ _
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : epi (non_preadditive_abelian.factor_thru_image f) :=
let I := non_preadditive_abelian.image f, p := non_preadditive_abelian.factor_thru_image f,
i := kernel.ι (cokernel.π f) in
-- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0.
epi_of_zero_cancel _ $ λ R (g : I ⟶ R) (hpg : p ≫ g = 0),
begin
-- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h.
let u := kernel.ι g ≫ i,
haveI : mono u := mono_comp _ _,
haveI hu := non_preadditive_abelian.normal_mono u,
let h := hu.g,
-- By hypothesis, p factors through the kernel of g via some t.
obtain ⟨t, ht⟩ := kernel.lift' g p hpg,
have fh : f ≫ h = 0, calc
f ≫ h = (p ≫ i) ≫ h : (image.fac f).symm ▸ rfl
... = ((t ≫ kernel.ι g) ≫ i) ≫ h : ht ▸ rfl
... = t ≫ u ≫ h : by simp only [category.assoc]; conv_lhs { congr, skip, rw ←category.assoc }
... = t ≫ 0 : hu.w ▸ rfl
... = 0 : has_zero_morphisms.comp_zero _ _,
-- h factors through the cokernel of f via some l.
obtain ⟨l, hl⟩ := cokernel.desc' f h fh,
have hih : i ≫ h = 0, calc
i ≫ h = i ≫ cokernel.π f ≫ l : hl ▸ rfl
... = 0 ≫ l : by rw [←category.assoc, kernel.condition]
... = 0 : zero_comp,
-- i factors through u = ker h via some s.
obtain ⟨s, hs⟩ := normal_mono.lift' u i hih,
have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i, by rw [category.assoc, hs, category.id_comp],
haveI : epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs'),
-- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required.
exact zero_of_epi_comp _ (kernel.condition g)
end
instance mono_factor_thru_image [mono f] : mono (non_preadditive_abelian.factor_thru_image f) :=
mono_of_mono_fac $ image.fac f
instance is_iso_factor_thru_image [mono f] : is_iso (non_preadditive_abelian.factor_thru_image f) :=
is_iso_of_mono_of_epi _
/-- The cokernel of the kernel of `f` is called the coimage of `f`. -/
protected abbreviation coimage : C := cokernel (kernel.ι f)
/-- The projection onto the coimage. -/
protected abbreviation coimage.π : P ⟶ non_preadditive_abelian.coimage f :=
cokernel.π (kernel.ι f)
/-- There is a canonical monomorphism `i : coimage f ⟶ Q`. -/
protected abbreviation factor_thru_coimage : non_preadditive_abelian.coimage f ⟶ Q :=
cokernel.desc (kernel.ι f) f $ kernel.condition f
/-- `f` factors through its coimage via the canonical morphism `p`. -/
protected lemma coimage.fac : coimage.π f ≫ non_preadditive_abelian.factor_thru_coimage f = f :=
cokernel.π_desc _ _ _
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : mono (non_preadditive_abelian.factor_thru_coimage f) :=
let I := non_preadditive_abelian.coimage f, i := non_preadditive_abelian.factor_thru_coimage f,
p := cokernel.π (kernel.ι f) in
mono_of_cancel_zero _ $ λ R (g : R ⟶ I) (hgi : g ≫ i = 0),
begin
-- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h.
let u := p ≫ cokernel.π g,
haveI : epi u := epi_comp _ _,
haveI hu := non_preadditive_abelian.normal_epi u,
let h := hu.g,
-- By hypothesis, i factors through the cokernel of g via some t.
obtain ⟨t, ht⟩ := cokernel.desc' g i hgi,
have hf : h ≫ f = 0, calc
h ≫ f = h ≫ (p ≫ i) : (coimage.fac f).symm ▸ rfl
... = h ≫ (p ≫ (cokernel.π g ≫ t)) : ht ▸ rfl
... = h ≫ u ≫ t : by simp only [category.assoc]; conv_lhs { congr, skip, rw ←category.assoc }
... = 0 ≫ t : by rw [←category.assoc, hu.w]
... = 0 : zero_comp,
-- h factors through the kernel of f via some l.
obtain ⟨l, hl⟩ := kernel.lift' f h hf,
have hhp : h ≫ p = 0, calc
h ≫ p = (l ≫ kernel.ι f) ≫ p : hl ▸ rfl
... = l ≫ 0 : by rw [category.assoc, cokernel.condition]
... = 0 : comp_zero,
-- p factors through u = coker h via some s.
obtain ⟨s, hs⟩ := normal_epi.desc' u p hhp,
have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I, by rw [←category.assoc, hs, category.comp_id],
haveI : mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs'),
-- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required.
exact zero_of_comp_mono _ (cokernel.condition g)
end
instance epi_factor_thru_coimage [epi f] : epi (non_preadditive_abelian.factor_thru_coimage f) :=
epi_of_epi_fac $ coimage.fac f
instance is_iso_factor_thru_coimage [epi f] :
is_iso (non_preadditive_abelian.factor_thru_coimage f) :=
is_iso_of_mono_of_epi _
end factor
section cokernel_of_kernel
variables {X Y : C} {f : X ⟶ Y}
/-- In a `non_preadditive_abelian` category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `fork.ι s`. -/
def epi_is_cokernel_of_kernel [epi f] (s : fork f 0) (h : is_limit s) :
is_colimit (cokernel_cofork.of_π f (kernel_fork.condition s)) :=
is_cokernel.cokernel_iso _ _
(cokernel.of_iso_comp _ _
(limits.is_limit.cone_point_unique_up_to_iso (limit.is_limit _) h)
(cone_morphism.w (limits.is_limit.unique_up_to_iso (limit.is_limit _) h).hom _))
(as_iso $ non_preadditive_abelian.factor_thru_coimage f) (coimage.fac f)
/-- In a `non_preadditive_abelian` category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `cofork.π s`. -/
def mono_is_kernel_of_cokernel [mono f] (s : cofork f 0) (h : is_colimit s) :
is_limit (kernel_fork.of_ι f (cokernel_cofork.condition s)) :=
is_kernel.iso_kernel _ _
(kernel.of_comp_iso _ _
(limits.is_colimit.cocone_point_unique_up_to_iso h (colimit.is_colimit _))
(cocone_morphism.w (limits.is_colimit.unique_up_to_iso h $ colimit.is_colimit _).hom _))
(as_iso $ non_preadditive_abelian.factor_thru_image f) (image.fac f)
end cokernel_of_kernel
section
/-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map
is the canonical projection into the cokernel. -/
abbreviation r (A : C) : A ⟶ cokernel (diag A) := prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A)
instance mono_Δ {A : C} : mono (diag A) := mono_of_mono_fac $ prod.lift_fst _ _
instance mono_r {A : C} : mono (r A) :=
begin
let hl : is_limit (kernel_fork.of_ι (diag A) (cokernel.condition (diag A))),
{ exact mono_is_kernel_of_cokernel _ (colimit.is_colimit _) },
apply mono_of_cancel_zero,
intros Z x hx,
have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0,
{ rw [category.assoc, hx] },
obtain ⟨y, hy⟩ := kernel_fork.is_limit.lift' hl _ hxx,
rw kernel_fork.ι_of_ι at hy,
have hyy : y = 0,
{ erw [←category.comp_id y, ←limits.prod.lift_snd (𝟙 A) (𝟙 A), ←category.assoc, hy,
category.assoc, prod.lift_snd, has_zero_morphisms.comp_zero] },
haveI : mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _),
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1,
rw [←hy, hyy, zero_comp, zero_comp]
end
instance epi_r {A : C} : epi (r A) :=
begin
have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ limits.prod.snd = 0 := prod.lift_snd _ _,
let hp1 : is_limit (kernel_fork.of_ι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp),
{ refine fork.is_limit.mk _ (λ s, fork.ι s ≫ limits.prod.fst) _ _,
{ intro s,
ext; simp, erw category.comp_id },
{ intros s m h,
haveI : mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _),
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1,
convert h walking_parallel_pair.zero,
ext; simp } },
let hp2 : is_colimit (cokernel_cofork.of_π (limits.prod.snd : A ⨯ A ⟶ A) hlp),
{ exact epi_is_cokernel_of_kernel _ hp1 },
apply epi_of_zero_cancel,
intros Z z hz,
have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0,
{ rw [←category.assoc, hz] },
obtain ⟨t, ht⟩ := cokernel_cofork.is_colimit.desc' hp2 _ h,
rw cokernel_cofork.π_of_π at ht,
have htt : t = 0,
{ rw [←category.id_comp t],
change 𝟙 A ≫ t = 0,
rw [←limits.prod.lift_snd (𝟙 A) (𝟙 A), category.assoc, ht, ←category.assoc,
cokernel.condition, zero_comp] },
apply (cancel_epi (cokernel.π (diag A))).1,
rw [←ht, htt, comp_zero, comp_zero]
end
instance is_iso_r {A : C} : is_iso (r A) :=
is_iso_of_mono_of_epi _
/-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel
followed by the inverse of `r`. In the category of modules, using the normal kernels and
cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for
"subtraction". -/
abbreviation σ {A : C} : A ⨯ A ⟶ A := cokernel.π (diag A) ≫ is_iso.inv (r A)
end
@[simp, reassoc] lemma diag_σ {X : C} : diag X ≫ σ = 0 :=
by rw [cokernel.condition_assoc, zero_comp]
@[simp, reassoc] lemma lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X :=
by rw [←category.assoc, is_iso.hom_inv_id]
@[reassoc] lemma lift_map {X Y : C} (f : X ⟶ Y) :
prod.lift (𝟙 X) 0 ≫ limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 :=
by simp
/-- σ is a cokernel of Δ X. -/
def is_colimit_σ {X : C} : is_colimit (cokernel_cofork.of_π σ diag_σ) :=
cokernel.cokernel_iso _ σ (as_iso (r X)).symm (by rw [iso.symm_hom, as_iso_inv])
/-- This is the key identity satisfied by `σ`. -/
lemma σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = limits.prod.map f f ≫ σ :=
begin
obtain ⟨g, hg⟩ :=
cokernel_cofork.is_colimit.desc' is_colimit_σ (limits.prod.map f f ≫ σ) (by simp),
suffices hfg : f = g,
{ rw [←hg, cofork.π_of_π, hfg] },
calc f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ : by rw [lift_σ, category.comp_id]
... = prod.lift (𝟙 X) 0 ≫ limits.prod.map f f ≫ σ : by rw lift_map_assoc
... = prod.lift (𝟙 X) 0 ≫ σ ≫ g : by rw [←hg, cokernel_cofork.π_of_π]
... = g : by rw [←category.assoc, lift_σ, category.id_comp]
end
section
/- We write `f - g` for `prod.lift f g ≫ σ`. -/
/-- Subtraction of morphisms in a `non_preadditive_abelian` category. -/
def has_sub {X Y : C} : has_sub (X ⟶ Y) := ⟨λ f g, prod.lift f g ≫ σ⟩
local attribute [instance] has_sub
/- We write `-f` for `0 - f`. -/
/-- Negation of morphisms in a `non_preadditive_abelian` category. -/
def has_neg {X Y : C} : has_neg (X ⟶ Y) := ⟨λ f, 0 - f⟩
local attribute [instance] has_neg
/- We write `f + g` for `f - (-g)`. -/
/-- Addition of morphisms in a `non_preadditive_abelian` category. -/
def has_add {X Y : C} : has_add (X ⟶ Y) := ⟨λ f g, f - (-g)⟩
local attribute [instance] has_add
lemma sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl
lemma add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - (-b) := rfl
lemma neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl
lemma sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a :=
begin
rw sub_def,
conv_lhs { congr, congr, rw ←category.comp_id a, skip, rw (show 0 = a ≫ (0 : Y ⟶ Y), by simp)},
rw [← prod.comp_lift, category.assoc, lift_σ, category.comp_id]
end
lemma sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 :=
by rw [sub_def, ←category.comp_id a, ← prod.comp_lift, category.assoc, diag_σ, comp_zero]
lemma lift_sub_lift {X Y : C} (a b c d : X ⟶ Y) :
prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) :=
begin
simp only [sub_def],
ext,
{ rw [category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst] },
{ rw [category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd] }
end
lemma sub_sub_sub {X Y : C} (a b c d : X ⟶ Y) : (a - c) - (b - d) = (a - b) - (c - d) :=
begin
rw [sub_def, ←lift_sub_lift, sub_def, category.assoc, σ_comp, prod.lift_map_assoc], refl
end
lemma neg_sub {X Y : C} (a b : X ⟶ Y) : (-a) - b = (-b) - a :=
by conv_lhs { rw [neg_def, ←sub_zero b, sub_sub_sub, sub_zero, ←neg_def] }
lemma neg_neg {X Y : C} (a : X ⟶ Y) : -(-a) = a :=
begin
rw [neg_def, neg_def],
conv_lhs { congr, rw ←sub_self a },
rw [sub_sub_sub, sub_zero, sub_self, sub_zero]
end
lemma add_comm {X Y : C} (a b : X ⟶ Y) : a + b = b + a :=
begin
rw [add_def],
conv_lhs { rw ←neg_neg a },
rw [neg_def, neg_def, neg_def, sub_sub_sub],
conv_lhs {congr, skip, rw [←neg_def, neg_sub] },
rw [sub_sub_sub, add_def, ←neg_def, neg_neg b, neg_def]
end
lemma add_neg {X Y : C} (a b : X ⟶ Y) : a + (-b) = a - b :=
by rw [add_def, neg_neg]
lemma add_neg_self {X Y : C} (a : X ⟶ Y) : a + (-a) = 0 :=
by rw [add_neg, sub_self]
lemma neg_add_self {X Y : C} (a : X ⟶ Y) : (-a) + a = 0 :=
by rw [add_comm, add_neg_self]
lemma neg_sub' {X Y : C} (a b : X ⟶ Y) : -(a - b) = (-a) + b :=
begin
rw [neg_def, neg_def],
conv_lhs { rw ←sub_self (0 : X ⟶ Y) },
rw [sub_sub_sub, add_def, neg_def]
end
lemma neg_add {X Y : C} (a b : X ⟶ Y) : -(a + b) = (-a) - b :=
by rw [add_def, neg_sub', add_neg]
lemma sub_add {X Y : C} (a b c : X ⟶ Y) : (a - b) + c = a - (b - c) :=
by rw [add_def, neg_def, sub_sub_sub, sub_zero]
lemma add_assoc {X Y : C} (a b c : X ⟶ Y) : (a + b) + c = a + (b + c) :=
begin
conv_lhs { congr, rw add_def },
rw [sub_add, ←add_neg, neg_sub', neg_neg]
end
lemma add_zero {X Y : C} (a : X ⟶ Y) : a + 0 = a :=
by rw [add_def, neg_def, sub_self, sub_zero]
lemma comp_sub {X Y Z : C} (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g - h) = f ≫ g - f ≫ h :=
by rw [sub_def, ←category.assoc, prod.comp_lift, sub_def]
lemma sub_comp {X Y Z : C} (f g : X ⟶ Y) (h : Y ⟶ Z) : (f - g) ≫ h = f ≫ h - g ≫ h :=
by rw [sub_def, category.assoc, σ_comp, ←category.assoc, prod.lift_map, sub_def]
lemma comp_add (X Y Z : C) (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g + h) = f ≫ g + f ≫ h :=
by rw [add_def, comp_sub, neg_def, comp_sub, comp_zero, add_def, neg_def]
lemma add_comp (X Y Z : C) (f g : X ⟶ Y) (h : Y ⟶ Z) : (f + g) ≫ h = f ≫ h + g ≫ h :=
by rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def]
/-- Every `non_preadditive_abelian` category is preadditive. -/
def preadditive : preadditive C :=
{ hom_group := λ X Y,
{ add := (+),
add_assoc := add_assoc,
zero := 0,
zero_add := neg_neg,
add_zero := add_zero,
neg := λ f, -f,
add_left_neg := neg_add_self,
add_comm := add_comm },
add_comp' := add_comp,
comp_add' := comp_add }
end
end
end category_theory.non_preadditive_abelian
|
f6c1ac3bd612262589af88751ca403f220727845
|
6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf
|
/src/game/world4/level5.lean
|
e6ef0305a06cdac1ee1208e4701cbebc9063f767
|
[
"Apache-2.0"
] |
permissive
|
arolihas/natural_number_game
|
4f0c93feefec93b8824b2b96adff8b702b8b43ce
|
8e4f7b4b42888a3b77429f90cce16292bd288138
|
refs/heads/master
| 1,621,872,426,808
| 1,586,270,467,000
| 1,586,270,467,000
| 253,648,466
| 0
| 0
| null | 1,586,219,694,000
| 1,586,219,694,000
| null |
UTF-8
|
Lean
| false
| false
| 296
|
lean
|
import game.world4.level4 -- hide
namespace mynat -- hide
/-
# Power World
## Level 5: `pow_add`
-/
/- Lemma
For all naturals $a$, $m$, $n$, we have $a^{m + n} = a ^ m a ^ n$.
-/
lemma pow_add (a m n : mynat) : a ^ (m + n) = a ^ m * a ^ n :=
begin [nat_num_game]
end
end mynat -- hide
|
c703024cd048483dee4fbcfe94b51fccb958585a
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/algebra/hom/group.lean
|
c67dbb5c7e05c25bfd112398ec54e27ad13b7cc7
|
[
"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
| 52,916
|
lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,
Johannes Hölzl, Yury Kudryashov
-/
import algebra.group.commute
import algebra.group_with_zero.defs
import data.fun_like.basic
/-!
# Monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
This file also defines the lesser-used (and notation-less) homomorphism types which are used as
building blocks for other homomorphisms:
* `zero_hom`
* `one_hom`
* `add_hom`
* `mul_hom`
* `monoid_with_zero_hom`
## Notations
* `→+`: Bundled `add_monoid` homs. Also use for `add_group` homs.
* `→*`: Bundled `monoid` homs. Also use for `group` homs.
* `→*₀`: Bundled `monoid_with_zero` homs. Also use for `group_with_zero` homs.
* `→ₙ*`: Bundled `semigroup` homs.
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `group_hom` -- the idea is that `monoid_hom` is used.
The constructor for `monoid_hom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `monoid_hom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `deprecated/group`.
## Tags
monoid_hom, add_monoid_hom
-/
variables {α β M N P : Type*} -- monoids
variables {G : Type*} {H : Type*} -- groups
variables {F : Type*} -- homs
-- for easy multiple inheritance
set_option old_structure_cmd true
section zero
/-- `zero_hom M N` is the type of functions `M → N` that preserve zero.
When possible, instead of parametrizing results over `(f : zero_hom M N)`,
you should parametrize over `(F : Type*) [zero_hom_class F M N] (f : F)`.
When you extend this structure, make sure to also extend `zero_hom_class`.
-/
structure zero_hom (M : Type*) (N : Type*) [has_zero M] [has_zero N] :=
(to_fun : M → N)
(map_zero' : to_fun 0 = 0)
/-- `zero_hom_class F M N` states that `F` is a type of zero-preserving homomorphisms.
You should extend this typeclass when you extend `zero_hom`.
-/
class zero_hom_class (F : Type*) (M N : out_param $ Type*)
[has_zero M] [has_zero N] extends fun_like F M (λ _, N) :=
(map_zero : ∀ (f : F), f 0 = 0)
-- Instances and lemmas are defined below through `@[to_additive]`.
end zero
section add
/-- `add_hom M N` is the type of functions `M → N` that preserve addition.
When possible, instead of parametrizing results over `(f : add_hom M N)`,
you should parametrize over `(F : Type*) [add_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `add_hom_class`.
-/
structure add_hom (M : Type*) (N : Type*) [has_add M] [has_add N] :=
(to_fun : M → N)
(map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y)
/-- `add_hom_class F M N` states that `F` is a type of addition-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `add_hom`.
-/
class add_hom_class (F : Type*) (M N : out_param $ Type*)
[has_add M] [has_add N] extends fun_like F M (λ _, N) :=
(map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y)
-- Instances and lemmas are defined below through `@[to_additive]`.
end add
section add_zero
/-- `M →+ N` is the type of functions `M → N` that preserve the `add_zero_class` structure.
`add_monoid_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [add_monoid_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `add_monoid_hom_class`.
-/
@[ancestor zero_hom add_hom]
structure add_monoid_hom (M : Type*) (N : Type*) [add_zero_class M] [add_zero_class N]
extends zero_hom M N, add_hom M N
attribute [nolint doc_blame] add_monoid_hom.to_add_hom
attribute [nolint doc_blame] add_monoid_hom.to_zero_hom
infixr ` →+ `:25 := add_monoid_hom
/-- `add_monoid_hom_class F M N` states that `F` is a type of `add_zero_class`-preserving
homomorphisms.
You should also extend this typeclass when you extend `add_monoid_hom`.
-/
@[ancestor add_hom_class zero_hom_class]
class add_monoid_hom_class (F : Type*) (M N : out_param $ Type*)
[add_zero_class M] [add_zero_class N]
extends add_hom_class F M N, zero_hom_class F M N
-- Instances and lemmas are defined below through `@[to_additive]`.
end add_zero
section one
variables [has_one M] [has_one N]
/-- `one_hom M N` is the type of functions `M → N` that preserve one.
When possible, instead of parametrizing results over `(f : one_hom M N)`,
you should parametrize over `(F : Type*) [one_hom_class F M N] (f : F)`.
When you extend this structure, make sure to also extend `one_hom_class`.
-/
@[to_additive]
structure one_hom (M : Type*) (N : Type*) [has_one M] [has_one N] :=
(to_fun : M → N)
(map_one' : to_fun 1 = 1)
/-- `one_hom_class F M N` states that `F` is a type of one-preserving homomorphisms.
You should extend this typeclass when you extend `one_hom`.
-/
@[to_additive]
class one_hom_class (F : Type*) (M N : out_param $ Type*)
[has_one M] [has_one N]
extends fun_like F M (λ _, N) :=
(map_one : ∀ (f : F), f 1 = 1)
@[to_additive]
instance one_hom.one_hom_class : one_hom_class (one_hom M N) M N :=
{ coe := one_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_one := one_hom.map_one' }
@[simp, to_additive] lemma map_one [one_hom_class F M N] (f : F) : f 1 = 1 :=
one_hom_class.map_one f
@[to_additive] lemma map_eq_one_iff [one_hom_class F M N] (f : F)
(hf : function.injective f) {x : M} : f x = 1 ↔ x = 1 :=
hf.eq_iff' (map_one f)
@[to_additive]
lemma map_ne_one_iff {R S F : Type*} [has_one R] [has_one S] [one_hom_class F R S]
(f : F) (hf : function.injective f) {x : R} :
f x ≠ 1 ↔ x ≠ 1 :=
(map_eq_one_iff f hf).not
@[to_additive]
lemma ne_one_of_map {R S F : Type*} [has_one R] [has_one S] [one_hom_class F R S]
{f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 :=
ne_of_apply_ne f $ ne_of_ne_of_eq hx (map_one f).symm
@[to_additive]
instance [one_hom_class F M N] : has_coe_t F (one_hom M N) :=
⟨λ f, { to_fun := f, map_one' := map_one f }⟩
end one
section mul
variables [has_mul M] [has_mul N]
/-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `non_unital_alg_hom` and
`non_unital_ring_hom`, so a `mul_hom` is a non-unital monoid hom.
When possible, instead of parametrizing results over `(f : M →ₙ* N)`,
you should parametrize over `(F : Type*) [mul_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `mul_hom_class`.
-/
@[to_additive]
structure mul_hom (M : Type*) (N : Type*) [has_mul M] [has_mul N] :=
(to_fun : M → N)
(map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y)
infixr ` →ₙ* `:25 := mul_hom
/-- `mul_hom_class F M N` states that `F` is a type of multiplication-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `mul_hom`.
-/
@[to_additive]
class mul_hom_class (F : Type*) (M N : out_param $ Type*)
[has_mul M] [has_mul N] extends fun_like F M (λ _, N) :=
(map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y)
@[to_additive]
instance mul_hom.mul_hom_class : mul_hom_class (M →ₙ* N) M N :=
{ coe := mul_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := mul_hom.map_mul' }
@[simp, to_additive] lemma map_mul [mul_hom_class F M N] (f : F) (x y : M) :
f (x * y) = f x * f y :=
mul_hom_class.map_mul f x y
@[to_additive]
instance [mul_hom_class F M N] : has_coe_t F (M →ₙ* N) :=
⟨λ f, { to_fun := f, map_mul' := map_mul f }⟩
end mul
section mul_one
variables [mul_one_class M] [mul_one_class N]
/-- `M →* N` is the type of functions `M → N` that preserve the `monoid` structure.
`monoid_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [monoid_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `monoid_hom_class`.
-/
@[ancestor one_hom mul_hom, to_additive]
structure monoid_hom (M : Type*) (N : Type*) [mul_one_class M] [mul_one_class N]
extends one_hom M N, M →ₙ* N
attribute [nolint doc_blame] monoid_hom.to_mul_hom
attribute [nolint doc_blame] monoid_hom.to_one_hom
infixr ` →* `:25 := monoid_hom
/-- `monoid_hom_class F M N` states that `F` is a type of `monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `monoid_hom`. -/
@[ancestor mul_hom_class one_hom_class, to_additive
"`add_monoid_hom_class F M N` states that `F` is a type of `add_monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `add_monoid_hom`."]
class monoid_hom_class (F : Type*) (M N : out_param $ Type*)
[mul_one_class M] [mul_one_class N]
extends mul_hom_class F M N, one_hom_class F M N
@[to_additive]
instance monoid_hom.monoid_hom_class : monoid_hom_class (M →* N) M N :=
{ coe := monoid_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := monoid_hom.map_mul',
map_one := monoid_hom.map_one' }
@[to_additive]
instance [monoid_hom_class F M N] : has_coe_t F (M →* N) :=
⟨λ f, { to_fun := f, map_one' := map_one f, map_mul' := map_mul f }⟩
@[to_additive]
lemma map_mul_eq_one [monoid_hom_class F M N] (f : F) {a b : M} (h : a * b = 1) :
f a * f b = 1 :=
by rw [← map_mul, h, map_one]
@[to_additive]
lemma map_div' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H] (f : F)
(hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b :=
by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul, hf]
/-- Group homomorphisms preserve inverse. -/
@[simp, to_additive "Additive group homomorphisms preserve negation."]
lemma map_inv [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (a : G) :
f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one_left $ map_mul_eq_one f $ inv_mul_self _
/-- Group homomorphisms preserve division. -/
@[simp, to_additive "Additive group homomorphisms preserve subtraction."]
lemma map_mul_inv [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (a b : G) :
f (a * b⁻¹) = f a * (f b)⁻¹ :=
by rw [map_mul, map_inv]
/-- Group homomorphisms preserve division. -/
@[simp, to_additive "Additive group homomorphisms preserve subtraction."]
lemma map_div [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) :
∀ a b, f (a / b) = f a / f b :=
map_div' _ $ map_inv f
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
-- swap its arguments.
@[to_additive map_nsmul.aux, simp] theorem map_pow [monoid G] [monoid H] [monoid_hom_class F G H]
(f : F) (a : G) :
∀ (n : ℕ), f (a ^ n) = (f a) ^ n
| 0 := by rw [pow_zero, pow_zero, map_one]
| (n+1) := by rw [pow_succ, pow_succ, map_mul, map_pow]
@[simp] theorem map_nsmul [add_monoid G] [add_monoid H] [add_monoid_hom_class F G H]
(f : F) (n : ℕ) (a : G) : f (n • a) = n • (f a) :=
map_nsmul.aux f a n
attribute [to_additive_reorder 8, to_additive] map_pow
@[to_additive]
theorem map_zpow' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H]
(f : F) (hf : ∀ (x : G), f (x⁻¹) = (f x)⁻¹) (a : G) :
∀ n : ℤ, f (a ^ n) = (f a) ^ n
| (n : ℕ) := by rw [zpow_coe_nat, map_pow, zpow_coe_nat]
| -[1+n] := by rw [zpow_neg_succ_of_nat, hf, map_pow, ← zpow_neg_succ_of_nat]
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
-- swap its arguments.
/-- Group homomorphisms preserve integer power. -/
@[to_additive map_zsmul.aux, simp]
theorem map_zpow [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (g : G) (n : ℤ) :
f (g ^ n) = (f g) ^ n :=
map_zpow' f (map_inv f) g n
/-- Additive group homomorphisms preserve integer scaling. -/
theorem map_zsmul [add_group G] [subtraction_monoid H] [add_monoid_hom_class F G H] (f : F)
(n : ℤ) (g : G) :
f (n • g) = n • f g :=
map_zsmul.aux f g n
attribute [to_additive_reorder 8, to_additive] map_zpow
end mul_one
@[to_additive] lemma group.is_unit [group G] (g : G) : is_unit g :=
⟨⟨g, g⁻¹, mul_inv_self g, inv_mul_self g⟩, rfl⟩
section mul_zero_one
variables [mul_zero_one_class M] [mul_zero_one_class N]
/-- `M →*₀ N` is the type of functions `M → N` that preserve
the `monoid_with_zero` structure.
`monoid_with_zero_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →*₀ N)`,
you should parametrize over `(F : Type*) [monoid_with_zero_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `monoid_with_zero_hom_class`.
-/
@[ancestor zero_hom monoid_hom]
structure monoid_with_zero_hom (M : Type*) (N : Type*) [mul_zero_one_class M] [mul_zero_one_class N]
extends zero_hom M N, monoid_hom M N
attribute [nolint doc_blame] monoid_with_zero_hom.to_monoid_hom
attribute [nolint doc_blame] monoid_with_zero_hom.to_zero_hom
infixr ` →*₀ `:25 := monoid_with_zero_hom
/-- `monoid_with_zero_hom_class F M N` states that `F` is a type of
`monoid_with_zero`-preserving homomorphisms.
You should also extend this typeclass when you extend `monoid_with_zero_hom`.
-/
class monoid_with_zero_hom_class (F : Type*) (M N : out_param $ Type*)
[mul_zero_one_class M] [mul_zero_one_class N]
extends monoid_hom_class F M N, zero_hom_class F M N
instance monoid_with_zero_hom.monoid_with_zero_hom_class :
monoid_with_zero_hom_class (M →*₀ N) M N :=
{ coe := monoid_with_zero_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := monoid_with_zero_hom.map_mul',
map_one := monoid_with_zero_hom.map_one',
map_zero := monoid_with_zero_hom.map_zero' }
instance [monoid_with_zero_hom_class F M N] : has_coe_t F (M →*₀ N) :=
⟨λ f, { to_fun := f, map_one' := map_one f, map_zero' := map_zero f, map_mul' := map_mul f }⟩
end mul_zero_one
-- completely uninteresting lemmas about coercion to function, that all homs need
section coes
/-! Bundled morphisms can be down-cast to weaker bundlings -/
@[to_additive]
instance monoid_hom.has_coe_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} :
has_coe (M →* N) (one_hom M N) := ⟨monoid_hom.to_one_hom⟩
@[to_additive]
instance monoid_hom.has_coe_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} :
has_coe (M →* N) (M →ₙ* N) := ⟨monoid_hom.to_mul_hom⟩
instance monoid_with_zero_hom.has_coe_to_monoid_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe (M →*₀ N) (M →* N) := ⟨monoid_with_zero_hom.to_monoid_hom⟩
instance monoid_with_zero_hom.has_coe_to_zero_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe (M →*₀ N) (zero_hom M N) := ⟨monoid_with_zero_hom.to_zero_hom⟩
/-! The simp-normal form of morphism coercion is `f.to_..._hom`. This choice is primarily because
this is the way things were before the above coercions were introduced. Bundled morphisms defined
elsewhere in Mathlib may choose `↑f` as their simp-normal form instead. -/
@[simp, to_additive]
lemma monoid_hom.coe_eq_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) :
(f : one_hom M N) = f.to_one_hom := rfl
@[simp, to_additive]
lemma monoid_hom.coe_eq_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) :
(f : M →ₙ* N) = f.to_mul_hom := rfl
@[simp]
lemma monoid_with_zero_hom.coe_eq_to_monoid_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) :
(f : M →* N) = f.to_monoid_hom := rfl
@[simp]
lemma monoid_with_zero_hom.coe_eq_to_zero_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) :
(f : zero_hom M N) = f.to_zero_hom := rfl
-- Fallback `has_coe_to_fun` instances to help the elaborator
@[to_additive]
instance {mM : has_one M} {mN : has_one N} : has_coe_to_fun (one_hom M N) (λ _, M → N) :=
⟨one_hom.to_fun⟩
@[to_additive]
instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (M →ₙ* N) (λ _, M → N) :=
⟨mul_hom.to_fun⟩
@[to_additive]
instance {mM : mul_one_class M} {mN : mul_one_class N} : has_coe_to_fun (M →* N) (λ _, M → N) :=
⟨monoid_hom.to_fun⟩
instance {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe_to_fun (M →*₀ N) (λ _, M → N) :=
⟨monoid_with_zero_hom.to_fun⟩
-- these must come after the coe_to_fun definitions
initialize_simps_projections zero_hom (to_fun → apply)
initialize_simps_projections add_hom (to_fun → apply)
initialize_simps_projections add_monoid_hom (to_fun → apply)
initialize_simps_projections one_hom (to_fun → apply)
initialize_simps_projections mul_hom (to_fun → apply)
initialize_simps_projections monoid_hom (to_fun → apply)
initialize_simps_projections monoid_with_zero_hom (to_fun → apply)
@[simp, to_additive]
lemma one_hom.to_fun_eq_coe [has_one M] [has_one N] (f : one_hom M N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma mul_hom.to_fun_eq_coe [has_mul M] [has_mul N] (f : M →ₙ* N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_fun_eq_coe [mul_one_class M] [mul_one_class N]
(f : M →* N) : f.to_fun = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_fun_eq_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma one_hom.coe_mk [has_one M] [has_one N]
(f : M → N) (h1) : (one_hom.mk f h1 : M → N) = f := rfl
@[simp, to_additive]
lemma mul_hom.coe_mk [has_mul M] [has_mul N]
(f : M → N) (hmul) : (mul_hom.mk f hmul : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.coe_mk [mul_one_class M] [mul_one_class N]
(f : M → N) (h1 hmul) : (monoid_hom.mk f h1 hmul : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.coe_mk [mul_zero_one_class M] [mul_zero_one_class N]
(f : M → N) (h0 h1 hmul) : (monoid_with_zero_hom.mk f h0 h1 hmul : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_one_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) :
(f.to_one_hom : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_mul_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) :
(f.to_mul_hom : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_zero_hom_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) :
(f.to_zero_hom : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_monoid_hom_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) :
(f.to_monoid_hom : M → N) = f := rfl
@[ext, to_additive]
lemma one_hom.ext [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext, to_additive]
lemma mul_hom.ext [has_mul M] [has_mul N] ⦃f g : M →ₙ* N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext, to_additive]
lemma monoid_hom.ext [mul_one_class M] [mul_one_class N]
⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext]
lemma monoid_with_zero_hom.ext [mul_zero_one_class M] [mul_zero_one_class N] ⦃f g : M →*₀ N⦄
(h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
section deprecated
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem one_hom.congr_fun [has_one M] [has_one N]
{f g : one_hom M N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem mul_hom.congr_fun [has_mul M] [has_mul N]
{f g : M →ₙ* N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem monoid_hom.congr_fun [mul_one_class M] [mul_one_class N]
{f g : M →* N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
theorem monoid_with_zero_hom.congr_fun [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N}
(h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem one_hom.congr_arg [has_one M] [has_one N]
(f : one_hom M N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem mul_hom.congr_arg [has_mul M] [has_mul N]
(f : M →ₙ* N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem monoid_hom.congr_arg [mul_one_class M] [mul_one_class N]
(f : M →* N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
theorem monoid_with_zero_hom.congr_arg [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N)
{x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma one_hom.coe_inj [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma mul_hom.coe_inj [has_mul M] [has_mul N] ⦃f g : M →ₙ* N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma monoid_hom.coe_inj [mul_one_class M] [mul_one_class N]
⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
lemma monoid_with_zero_hom.coe_inj [mul_zero_one_class M] [mul_zero_one_class N]
⦃f g : M →*₀ N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive "Deprecated: use `fun_like.ext_iff` instead."]
lemma one_hom.ext_iff [has_one M] [has_one N] {f g : one_hom M N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive]
lemma mul_hom.ext_iff [has_mul M] [has_mul N] {f g : M →ₙ* N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive]
lemma monoid_hom.ext_iff [mul_one_class M] [mul_one_class N]
{f g : M →* N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
lemma monoid_with_zero_hom.ext_iff [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N} :
f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
end deprecated
@[simp, to_additive]
lemma one_hom.mk_coe [has_one M] [has_one N]
(f : one_hom M N) (h1) : one_hom.mk f h1 = f :=
one_hom.ext $ λ _, rfl
@[simp, to_additive]
lemma mul_hom.mk_coe [has_mul M] [has_mul N]
(f : M →ₙ* N) (hmul) : mul_hom.mk f hmul = f :=
mul_hom.ext $ λ _, rfl
@[simp, to_additive]
lemma monoid_hom.mk_coe [mul_one_class M] [mul_one_class N]
(f : M →* N) (h1 hmul) : monoid_hom.mk f h1 hmul = f :=
monoid_hom.ext $ λ _, rfl
@[simp]
lemma monoid_with_zero_hom.mk_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N)
(h0 h1 hmul) : monoid_with_zero_hom.mk f h0 h1 hmul = f :=
monoid_with_zero_hom.ext $ λ _, rfl
end coes
/-- Copy of a `one_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive "Copy of a `zero_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def one_hom.copy {hM : has_one M} {hN : has_one N} (f : one_hom M N) (f' : M → N)
(h : f' = f) : one_hom M N :=
{ to_fun := f',
map_one' := h.symm ▸ f.map_one' }
/-- Copy of a `mul_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive "Copy of an `add_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def mul_hom.copy {hM : has_mul M} {hN : has_mul N} (f : M →ₙ* N) (f' : M → N)
(h : f' = f) : M →ₙ* N :=
{ to_fun := f',
map_mul' := h.symm ▸ f.map_mul' }
/-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
@[to_additive "Copy of an `add_monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def monoid_hom.copy {hM : mul_one_class M} {hN : mul_one_class N} (f : M →* N)
(f' : M → N) (h : f' = f) : M →* N :=
{ ..f.to_one_hom.copy f' h, ..f.to_mul_hom.copy f' h }
/-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
protected def monoid_with_zero_hom.copy {hM : mul_zero_one_class M} {hN : mul_zero_one_class N}
(f : M →*₀ N) (f' : M → N) (h : f' = f) : M →* N :=
{ ..f.to_zero_hom.copy f' h, ..f.to_monoid_hom.copy f' h }
@[to_additive]
protected lemma one_hom.map_one [has_one M] [has_one N] (f : one_hom M N) : f 1 = 1 := f.map_one'
/-- If `f` is a monoid homomorphism then `f 1 = 1`. -/
@[to_additive]
protected lemma monoid_hom.map_one [mul_one_class M] [mul_one_class N] (f : M →* N) :
f 1 = 1 := f.map_one'
protected lemma monoid_with_zero_hom.map_one [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f 1 = 1 := f.map_one'
/-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/
add_decl_doc add_monoid_hom.map_zero
protected lemma monoid_with_zero_hom.map_zero [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f 0 = 0 := f.map_zero'
@[to_additive]
protected lemma mul_hom.map_mul [has_mul M] [has_mul N]
(f : M →ₙ* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
/-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/
@[to_additive]
protected lemma monoid_hom.map_mul [mul_one_class M] [mul_one_class N]
(f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
protected lemma monoid_with_zero_hom.map_mul [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
/-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/
add_decl_doc add_monoid_hom.map_add
namespace monoid_hom
variables {mM : mul_one_class M} {mN : mul_one_class N} [monoid_hom_class F M N]
include mM mN
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a right inverse, then `f x` has a right inverse too."]
lemma map_exists_right_inv (f : F) {x : M} (hx : ∃ y, x * y = 1) :
∃ y, f x * y = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, map_mul_eq_one f hy⟩
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see
`is_add_unit.map`."]
lemma map_exists_left_inv (f : F) {x : M} (hx : ∃ y, y * x = 1) :
∃ y, y * f x = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, map_mul_eq_one f hy⟩
end monoid_hom
section division_comm_monoid
variables [division_comm_monoid α]
/-- Inversion on a commutative group, considered as a monoid homomorphism. -/
@[to_additive "Negation on a commutative additive group, considered as an additive monoid
homomorphism."]
def inv_monoid_hom : α →* α :=
{ to_fun := has_inv.inv,
map_one' := inv_one,
map_mul' := mul_inv }
@[simp] lemma coe_inv_monoid_hom : (inv_monoid_hom : α → α) = has_inv.inv := rfl
@[simp] lemma inv_monoid_hom_apply (a : α) : inv_monoid_hom a = a⁻¹ := rfl
end division_comm_monoid
/-- The identity map from a type with 1 to itself. -/
@[to_additive, simps]
def one_hom.id (M : Type*) [has_one M] : one_hom M M :=
{ to_fun := λ x, x, map_one' := rfl, }
/-- The identity map from a type with multiplication to itself. -/
@[to_additive, simps]
def mul_hom.id (M : Type*) [has_mul M] : M →ₙ* M :=
{ to_fun := λ x, x, map_mul' := λ _ _, rfl, }
/-- The identity map from a monoid to itself. -/
@[to_additive, simps]
def monoid_hom.id (M : Type*) [mul_one_class M] : M →* M :=
{ to_fun := λ x, x, map_one' := rfl, map_mul' := λ _ _, rfl, }
/-- The identity map from a monoid_with_zero to itself. -/
@[simps]
def monoid_with_zero_hom.id (M : Type*) [mul_zero_one_class M] : M →*₀ M :=
{ to_fun := λ x, x, map_zero' := rfl, map_one' := rfl, map_mul' := λ _ _, rfl, }
/-- The identity map from an type with zero to itself. -/
add_decl_doc zero_hom.id
/-- The identity map from an type with addition to itself. -/
add_decl_doc add_hom.id
/-- The identity map from an additive monoid to itself. -/
add_decl_doc add_monoid_hom.id
/-- Composition of `one_hom`s as a `one_hom`. -/
@[to_additive]
def one_hom.comp [has_one M] [has_one N] [has_one P]
(hnp : one_hom N P) (hmn : one_hom M N) : one_hom M P :=
{ to_fun := hnp ∘ hmn, map_one' := by simp, }
/-- Composition of `mul_hom`s as a `mul_hom`. -/
@[to_additive]
def mul_hom.comp [has_mul M] [has_mul N] [has_mul P]
(hnp : N →ₙ* P) (hmn : M →ₙ* N) : M →ₙ* P :=
{ to_fun := hnp ∘ hmn, map_mul' := by simp, }
/-- Composition of monoid morphisms as a monoid morphism. -/
@[to_additive]
def monoid_hom.comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(hnp : N →* P) (hmn : M →* N) : M →* P :=
{ to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp, }
/-- Composition of `monoid_with_zero_hom`s as a `monoid_with_zero_hom`. -/
def monoid_with_zero_hom.comp [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P]
(hnp : N →*₀ P) (hmn : M →*₀ N) : M →*₀ P :=
{ to_fun := hnp ∘ hmn, map_zero' := by simp, map_one' := by simp, map_mul' := by simp, }
/-- Composition of `zero_hom`s as a `zero_hom`. -/
add_decl_doc zero_hom.comp
/-- Composition of `add_hom`s as a `add_hom`. -/
add_decl_doc add_hom.comp
/-- Composition of additive monoid morphisms as an additive monoid morphism. -/
add_decl_doc add_monoid_hom.comp
@[simp, to_additive] lemma one_hom.coe_comp [has_one M] [has_one N] [has_one P]
(g : one_hom N P) (f : one_hom M N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp, to_additive] lemma mul_hom.coe_comp [has_mul M] [has_mul N] [has_mul P]
(g : N →ₙ* P) (f : M →ₙ* N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp, to_additive] lemma monoid_hom.coe_comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(g : N →* P) (f : M →* N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp] lemma monoid_with_zero_hom.coe_comp [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) :
⇑(g.comp f) = g ∘ f := rfl
@[to_additive] lemma one_hom.comp_apply [has_one M] [has_one N] [has_one P]
(g : one_hom N P) (f : one_hom M N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive] lemma mul_hom.comp_apply [has_mul M] [has_mul N] [has_mul P]
(g : N →ₙ* P) (f : M →ₙ* N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive] lemma monoid_hom.comp_apply [mul_one_class M] [mul_one_class N] [mul_one_class P]
(g : N →* P) (f : M →* N) (x : M) :
g.comp f x = g (f x) := rfl
lemma monoid_with_zero_hom.comp_apply [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) (x : M) :
g.comp f x = g (f x) := rfl
/-- Composition of monoid homomorphisms is associative. -/
@[to_additive] lemma one_hom.comp_assoc {Q : Type*} [has_one M] [has_one N] [has_one P] [has_one Q]
(f : one_hom M N) (g : one_hom N P) (h : one_hom P Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive] lemma mul_hom.comp_assoc {Q : Type*} [has_mul M] [has_mul N] [has_mul P] [has_mul Q]
(f : M →ₙ* N) (g : N →ₙ* P) (h : P →ₙ* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive] lemma monoid_hom.comp_assoc {Q : Type*}
[mul_one_class M] [mul_one_class N] [mul_one_class P] [mul_one_class Q]
(f : M →* N) (g : N →* P) (h : P →* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
lemma monoid_with_zero_hom.comp_assoc {Q : Type*}
[mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] [mul_zero_one_class Q]
(f : M →*₀ N) (g : N →*₀ P) (h : P →*₀ Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
lemma one_hom.cancel_right [has_one M] [has_one N] [has_one P]
{g₁ g₂ : one_hom N P} {f : one_hom M N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, one_hom.ext $ hf.forall.2 (one_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
@[to_additive]
lemma mul_hom.cancel_right [has_mul M] [has_mul N] [has_mul P]
{g₁ g₂ : N →ₙ* P} {f : M →ₙ* N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, mul_hom.ext $ hf.forall.2 (mul_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.cancel_right
[mul_one_class M] [mul_one_class N] [mul_one_class P]
{g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, monoid_hom.ext $ hf.forall.2 (monoid_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
lemma monoid_with_zero_hom.cancel_right [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] {g₁ g₂ : N →*₀ P} {f : M →*₀ N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, monoid_with_zero_hom.ext $ hf.forall.2 (monoid_with_zero_hom.ext_iff.1 h),
λ h, h ▸ rfl⟩
@[to_additive]
lemma one_hom.cancel_left [has_one M] [has_one N] [has_one P]
{g : one_hom N P} {f₁ f₂ : one_hom M N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, one_hom.ext $ λ x, hg $ by rw [← one_hom.comp_apply, h, one_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma mul_hom.cancel_left [has_mul M] [has_mul N] [has_mul P]
{g : N →ₙ* P} {f₁ f₂ : M →ₙ* N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, mul_hom.ext $ λ x, hg $ by rw [← mul_hom.comp_apply, h, mul_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.cancel_left [mul_one_class M] [mul_one_class N] [mul_one_class P]
{g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← monoid_hom.comp_apply, h, monoid_hom.comp_apply],
λ h, h ▸ rfl⟩
lemma monoid_with_zero_hom.cancel_left [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] {g : N →*₀ P} {f₁ f₂ : M →*₀ N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, monoid_with_zero_hom.ext $ λ x, hg $ by rw [
← monoid_with_zero_hom.comp_apply, h, monoid_with_zero_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.to_one_hom_injective [mul_one_class M] [mul_one_class N] :
function.injective (monoid_hom.to_one_hom : (M →* N) → one_hom M N) :=
λ f g h, monoid_hom.ext $ one_hom.ext_iff.mp h
@[to_additive]
lemma monoid_hom.to_mul_hom_injective [mul_one_class M] [mul_one_class N] :
function.injective (monoid_hom.to_mul_hom : (M →* N) → M →ₙ* N) :=
λ f g h, monoid_hom.ext $ mul_hom.ext_iff.mp h
lemma monoid_with_zero_hom.to_monoid_hom_injective [mul_zero_one_class M] [mul_zero_one_class N] :
function.injective (monoid_with_zero_hom.to_monoid_hom : (M →*₀ N) → M →* N) :=
λ f g h, monoid_with_zero_hom.ext $ monoid_hom.ext_iff.mp h
lemma monoid_with_zero_hom.to_zero_hom_injective [mul_zero_one_class M] [mul_zero_one_class N] :
function.injective (monoid_with_zero_hom.to_zero_hom : (M →*₀ N) → zero_hom M N) :=
λ f g h, monoid_with_zero_hom.ext $ zero_hom.ext_iff.mp h
@[simp, to_additive] lemma one_hom.comp_id [has_one M] [has_one N]
(f : one_hom M N) : f.comp (one_hom.id M) = f := one_hom.ext $ λ x, rfl
@[simp, to_additive] lemma mul_hom.comp_id [has_mul M] [has_mul N]
(f : M →ₙ* N) : f.comp (mul_hom.id M) = f := mul_hom.ext $ λ x, rfl
@[simp, to_additive] lemma monoid_hom.comp_id [mul_one_class M] [mul_one_class N]
(f : M →* N) : f.comp (monoid_hom.id M) = f := monoid_hom.ext $ λ x, rfl
@[simp] lemma monoid_with_zero_hom.comp_id [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f.comp (monoid_with_zero_hom.id M) = f :=
monoid_with_zero_hom.ext $ λ x, rfl
@[simp, to_additive] lemma one_hom.id_comp [has_one M] [has_one N]
(f : one_hom M N) : (one_hom.id N).comp f = f := one_hom.ext $ λ x, rfl
@[simp, to_additive] lemma mul_hom.id_comp [has_mul M] [has_mul N]
(f : M →ₙ* N) : (mul_hom.id N).comp f = f := mul_hom.ext $ λ x, rfl
@[simp, to_additive] lemma monoid_hom.id_comp [mul_one_class M] [mul_one_class N]
(f : M →* N) : (monoid_hom.id N).comp f = f := monoid_hom.ext $ λ x, rfl
@[simp] lemma monoid_with_zero_hom.id_comp [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : (monoid_with_zero_hom.id N).comp f = f :=
monoid_with_zero_hom.ext $ λ x, rfl
@[to_additive add_monoid_hom.map_nsmul]
protected theorem monoid_hom.map_pow [monoid M] [monoid N] (f : M →* N) (a : M) (n : ℕ) :
f (a ^ n) = (f a) ^ n :=
map_pow f a n
@[to_additive]
protected theorem monoid_hom.map_zpow' [div_inv_monoid M] [div_inv_monoid N] (f : M →* N)
(hf : ∀ x, f (x⁻¹) = (f x)⁻¹) (a : M) (n : ℤ) :
f (a ^ n) = (f a) ^ n :=
map_zpow' f hf a n
section End
namespace monoid
variables (M) [mul_one_class M]
/-- The monoid of endomorphisms. -/
protected def End := M →* M
namespace End
instance : monoid (monoid.End M) :=
{ mul := monoid_hom.comp,
one := monoid_hom.id M,
mul_assoc := λ _ _ _, monoid_hom.comp_assoc _ _ _,
mul_one := monoid_hom.comp_id,
one_mul := monoid_hom.id_comp }
instance : inhabited (monoid.End M) := ⟨1⟩
instance : monoid_hom_class (monoid.End M) M M := monoid_hom.monoid_hom_class
end End
@[simp] lemma coe_one : ((1 : monoid.End M) : M → M) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : monoid.End M) : M → M) = f ∘ g := rfl
end monoid
namespace add_monoid
variables (A : Type*) [add_zero_class A]
/-- The monoid of endomorphisms. -/
protected def End := A →+ A
namespace End
instance : monoid (add_monoid.End A) :=
{ mul := add_monoid_hom.comp,
one := add_monoid_hom.id A,
mul_assoc := λ _ _ _, add_monoid_hom.comp_assoc _ _ _,
mul_one := add_monoid_hom.comp_id,
one_mul := add_monoid_hom.id_comp }
instance : inhabited (add_monoid.End A) := ⟨1⟩
instance : add_monoid_hom_class (add_monoid.End A) A A := add_monoid_hom.add_monoid_hom_class
end End
@[simp] lemma coe_one : ((1 : add_monoid.End A) : A → A) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : add_monoid.End A) : A → A) = f ∘ g := rfl
end add_monoid
end End
/-- `1` is the homomorphism sending all elements to `1`. -/
@[to_additive]
instance [has_one M] [has_one N] : has_one (one_hom M N) := ⟨⟨λ _, 1, rfl⟩⟩
/-- `1` is the multiplicative homomorphism sending all elements to `1`. -/
@[to_additive]
instance [has_mul M] [mul_one_class N] : has_one (M →ₙ* N) :=
⟨⟨λ _, 1, λ _ _, (one_mul 1).symm⟩⟩
/-- `1` is the monoid homomorphism sending all elements to `1`. -/
@[to_additive]
instance [mul_one_class M] [mul_one_class N] : has_one (M →* N) :=
⟨⟨λ _, 1, rfl, λ _ _, (one_mul 1).symm⟩⟩
/-- `0` is the homomorphism sending all elements to `0`. -/
add_decl_doc zero_hom.has_zero
/-- `0` is the additive homomorphism sending all elements to `0`. -/
add_decl_doc add_hom.has_zero
/-- `0` is the additive monoid homomorphism sending all elements to `0`. -/
add_decl_doc add_monoid_hom.has_zero
@[simp, to_additive] lemma one_hom.one_apply [has_one M] [has_one N]
(x : M) : (1 : one_hom M N) x = 1 := rfl
@[simp, to_additive] lemma monoid_hom.one_apply [mul_one_class M] [mul_one_class N]
(x : M) : (1 : M →* N) x = 1 := rfl
@[simp, to_additive] lemma one_hom.one_comp [has_one M] [has_one N] [has_one P] (f : one_hom M N) :
(1 : one_hom N P).comp f = 1 := rfl
@[simp, to_additive] lemma one_hom.comp_one [has_one M] [has_one N] [has_one P] (f : one_hom N P) :
f.comp (1 : one_hom M N) = 1 :=
by { ext, simp only [one_hom.map_one, one_hom.coe_comp, function.comp_app, one_hom.one_apply] }
@[to_additive]
instance [has_one M] [has_one N] : inhabited (one_hom M N) := ⟨1⟩
@[to_additive]
instance [has_mul M] [mul_one_class N] : inhabited (M →ₙ* N) := ⟨1⟩
@[to_additive]
instance [mul_one_class M] [mul_one_class N] : inhabited (M →* N) := ⟨1⟩
-- unlike the other homs, `monoid_with_zero_hom` does not have a `1` or `0`
instance [mul_zero_one_class M] : inhabited (M →*₀ M) := ⟨monoid_with_zero_hom.id M⟩
namespace mul_hom
/-- Given two mul morphisms `f`, `g` to a commutative semigroup, `f * g` is the mul morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance [has_mul M] [comm_semigroup N] : has_mul (M →ₙ* N) :=
⟨λ f g,
{ to_fun := λ m, f m * g m,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩
/-- Given two additive morphisms `f`, `g` to an additive commutative semigroup, `f + g` is the
additive morphism sending `x` to `f x + g x`. -/
add_decl_doc add_hom.has_add
@[simp, to_additive] lemma mul_apply {M N} {mM : has_mul M} {mN : comm_semigroup N}
(f g : M →ₙ* N) (x : M) :
(f * g) x = f x * g x := rfl
@[to_additive] lemma mul_comp [has_mul M] [has_mul N] [comm_semigroup P]
(g₁ g₂ : N →ₙ* P) (f : M →ₙ* N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive] lemma comp_mul [has_mul M] [comm_semigroup N] [comm_semigroup P]
(g : N →ₙ* P) (f₁ f₂ : M →ₙ* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] }
end mul_hom
namespace monoid_hom
variables [mM : mul_one_class M] [mN : mul_one_class N] [mP : mul_one_class P]
variables [group G] [comm_group H]
/-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance {M N} {mM : mul_one_class M} [comm_monoid N] : has_mul (M →* N) :=
⟨λ f g,
{ to_fun := λ m, f m * g m,
map_one' := show f 1 * g 1 = 1, by simp,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩
/-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the
additive monoid morphism sending `x` to `f x + g x`. -/
add_decl_doc add_monoid_hom.has_add
@[simp, to_additive] lemma mul_apply {M N} {mM : mul_one_class M} {mN : comm_monoid N}
(f g : M →* N) (x : M) :
(f * g) x = f x * g x := rfl
@[simp, to_additive] lemma one_comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(f : M →* N) : (1 : N →* P).comp f = 1 := rfl
@[simp, to_additive] lemma comp_one [mul_one_class M] [mul_one_class N] [mul_one_class P]
(f : N →* P) : f.comp (1 : M →* N) = 1 :=
by { ext, simp only [map_one, coe_comp, function.comp_app, one_apply] }
@[to_additive] lemma mul_comp [mul_one_class M] [mul_one_class N] [comm_monoid P]
(g₁ g₂ : N →* P) (f : M →* N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive] lemma comp_mul [mul_one_class M] [comm_monoid N] [comm_monoid P]
(g : N →* P) (f₁ f₂ : M →* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] }
/-- If two homomorphisms from a division monoid to a monoid are equal at a unit `x`, then they are
equal at `x⁻¹`. -/
@[to_additive "If two homomorphisms from a subtraction monoid to an additive monoid are equal at an
additive unit `x`, then they are equal at `-x`."]
lemma _root_.is_unit.eq_on_inv {G N} [division_monoid G] [monoid N] [monoid_hom_class F G N] {x : G}
(hx : is_unit x) (f g : F) (h : f x = g x) : f x⁻¹ = g x⁻¹ :=
left_inv_eq_right_inv (map_mul_eq_one f hx.inv_mul_cancel) $
h.symm ▸ map_mul_eq_one g $ hx.mul_inv_cancel
/-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/
@[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`,
then they are equal at `-x`." ]
lemma _root_.eq_on_inv {G} [group G] [monoid M] [monoid_hom_class F G M] (f g : F) {x : G}
(h : f x = g x) : f x⁻¹ = g x⁻¹ :=
(group.is_unit x).eq_on_inv f g h
/-- Group homomorphisms preserve inverse. -/
@[to_additive "Additive group homomorphisms preserve negation."]
protected lemma map_inv [group α] [division_monoid β] (f : α →* β) (a : α) : f a⁻¹ = (f a)⁻¹ :=
map_inv f _
/-- Group homomorphisms preserve integer power. -/
@[to_additive "Additive group homomorphisms preserve integer scaling."]
protected theorem map_zpow [group α] [division_monoid β] (f : α →* β) (g : α) (n : ℤ) :
f (g ^ n) = (f g) ^ n :=
map_zpow f g n
/-- Group homomorphisms preserve division. -/
@[to_additive "Additive group homomorphisms preserve subtraction."]
protected theorem map_div [group α] [division_monoid β] (f : α →* β) (g h : α) :
f (g / h) = f g / f h :=
map_div f g h
/-- Group homomorphisms preserve division. -/
@[to_additive "Additive group homomorphisms preserve subtraction."]
protected theorem map_mul_inv [group α] [division_monoid β] (f : α →* β) (g h : α) :
f (g * h⁻¹) = (f g) * (f h)⁻¹ :=
map_mul_inv f g h
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial.
For the iff statement on the triviality of the kernel, see `injective_iff_map_eq_one'`. -/
@[to_additive "A homomorphism from an additive group to an additive monoid is injective iff
its kernel is trivial. For the iff statement on the triviality of the kernel,
see `injective_iff_map_eq_zero'`."]
lemma _root_.injective_iff_map_eq_one {G H} [group G] [mul_one_class H] [monoid_hom_class F G H]
(f : F) : function.injective f ↔ (∀ a, f a = 1 → a = 1) :=
⟨λ h x, (map_eq_one_iff f h).mp,
λ h x y hxy, mul_inv_eq_one.1 $ h _ $ by rw [map_mul, hxy, ← map_mul, mul_inv_self, map_one]⟩
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial,
stated as an iff on the triviality of the kernel.
For the implication, see `injective_iff_map_eq_one`. -/
@[to_additive "A homomorphism from an additive group to an additive monoid is injective iff its
kernel is trivial, stated as an iff on the triviality of the kernel. For the implication, see
`injective_iff_map_eq_zero`."]
lemma _root_.injective_iff_map_eq_one' {G H} [group G] [mul_one_class H] [monoid_hom_class F G H]
(f : F) : function.injective f ↔ (∀ a, f a = 1 ↔ a = 1) :=
(injective_iff_map_eq_one f).trans $ forall_congr $ λ a, ⟨λ h, ⟨h, λ H, H.symm ▸ map_one f⟩, iff.mp⟩
include mM
/-- Makes a group homomorphism from a proof that the map preserves multiplication. -/
@[to_additive "Makes an additive group homomorphism from a proof that the map preserves addition.",
simps {fully_applied := ff}]
def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G :=
{ to_fun := f,
map_mul' := map_mul,
map_one' := mul_left_eq_self.1 $ by rw [←map_mul, mul_one] }
omit mM
/-- Makes a group homomorphism from a proof that the map preserves right division `λ x y, x * y⁻¹`.
See also `monoid_hom.of_map_div` for a version using `λ x y, x / y`.
-/
@[to_additive "Makes an additive group homomorphism from a proof that the map preserves
the operation `λ a b, a + -b`. See also `add_monoid_hom.of_map_sub` for a version using
`λ a b, a - b`."]
def of_map_mul_inv {H : Type*} [group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) :
G →* H :=
mk' f $ λ x y,
calc f (x * y) = f x * (f $ 1 * 1⁻¹ * y⁻¹)⁻¹ : by simp only [one_mul, inv_one, ← map_div, inv_inv]
... = f x * f y : by { simp only [map_div], simp only [mul_right_inv, one_mul, inv_inv] }
@[simp, to_additive] lemma coe_of_map_mul_inv {H : Type*} [group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) :
⇑(of_map_mul_inv f map_div) = f :=
rfl
/-- Define a morphism of additive groups given a map which respects ratios. -/
@[to_additive /-"Define a morphism of additive groups given a map which respects difference."-/]
def of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) : G →* H :=
of_map_mul_inv f (by simpa only [div_eq_mul_inv] using hf)
@[simp, to_additive]
lemma coe_of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) :
⇑(of_map_div f hf) = f :=
rfl
/-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending
`x` to `(f x)⁻¹`. -/
@[to_additive]
instance {M G} [mul_one_class M] [comm_group G] : has_inv (M →* G) :=
⟨λ f, mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul]⟩
/-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the
homomorphism sending `x` to `-(f x)`. -/
add_decl_doc add_monoid_hom.has_neg
@[simp, to_additive] lemma inv_apply {M G} {mM : mul_one_class M} {gG : comm_group G}
(f : M →* G) (x : M) :
f⁻¹ x = (f x)⁻¹ := rfl
@[simp, to_additive] lemma inv_comp {M N A} {mM : mul_one_class M} {gN : mul_one_class N}
{gA : comm_group A} (φ : N →* A) (ψ : M →* N) : φ⁻¹.comp ψ = (φ.comp ψ)⁻¹ :=
by { ext, simp only [function.comp_app, inv_apply, coe_comp] }
@[simp, to_additive] lemma comp_inv {M A B} {mM : mul_one_class M} {mA : comm_group A}
{mB : comm_group B} (φ : A →* B) (ψ : M →* A) : φ.comp ψ⁻¹ = (φ.comp ψ)⁻¹ :=
by { ext, simp only [function.comp_app, inv_apply, map_inv, coe_comp] }
/-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism
sending `x` to `(f x) / (g x)`. -/
@[to_additive]
instance {M G} [mul_one_class M] [comm_group G] : has_div (M →* G) :=
⟨λ f g, mk' (λ x, f x / g x) $ λ a b,
by simp [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm]⟩
/-- If `f` and `g` are monoid homomorphisms to an additive commutative group, then `f - g`
is the homomorphism sending `x` to `(f x) - (g x)`. -/
add_decl_doc add_monoid_hom.has_sub
@[simp, to_additive] lemma div_apply {M G} {mM : mul_one_class M} {gG : comm_group G}
(f g : M →* G) (x : M) :
(f / g) x = f x / g x := rfl
end monoid_hom
/-- Given two monoid with zero morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid
with zero morphism sending `x` to `f x * g x`. -/
instance {M N} {hM : mul_zero_one_class M} [comm_monoid_with_zero N] : has_mul (M →*₀ N) :=
⟨λ f g,
{ to_fun := λ a, f a * g a,
map_zero' := by rw [map_zero, zero_mul],
..(f * g : M →* N) }⟩
section commute
variables [has_mul M] [has_mul N] {a x y : M}
@[simp, to_additive]
protected lemma semiconj_by.map [mul_hom_class F M N] (h : semiconj_by a x y) (f : F) :
semiconj_by (f a) (f x) (f y) :=
by simpa only [semiconj_by, map_mul] using congr_arg f h
@[simp, to_additive]
protected lemma commute.map [mul_hom_class F M N] (h : commute x y) (f : F) :
commute (f x) (f y) :=
h.map f
end commute
|
215e4817b411c49f9c93ed683fb7ea42be3be089
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/algebra/module/ulift.lean
|
9d4bb1bfc1239a306108ffd77bd1cfa70609cea0
|
[
"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
| 4,307
|
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 algebra.ring.ulift
import algebra.module.equiv
/-!
# `ulift` instances for module and multiplicative actions
This file defines instances for module, mul_action and related structures on `ulift` types.
(Recall `ulift α` is just a "copy" of a type `α` in a higher universe.)
We also provide `ulift.module_equiv : ulift M ≃ₗ[R] M`.
-/
namespace ulift
universes u v w
variable {R : Type u}
variable {M : Type v}
variable {N : Type w}
@[to_additive]
instance has_smul_left [has_smul R M] :
has_smul (ulift R) M :=
⟨λ s x, s.down • x⟩
@[simp, to_additive]
lemma smul_def [has_smul R M] (s : ulift R) (x : M) : s • x = s.down • x := rfl
instance is_scalar_tower [has_smul R M] [has_smul M N] [has_smul R N]
[is_scalar_tower R M N] : is_scalar_tower (ulift R) M N :=
⟨λ x y z, show (x.down • y) • z = x.down • y • z, from smul_assoc _ _ _⟩
instance is_scalar_tower' [has_smul R M] [has_smul M N] [has_smul R N]
[is_scalar_tower R M N] : is_scalar_tower R (ulift M) N :=
⟨λ x y z, show (x • y.down) • z = x • y.down • z, from smul_assoc _ _ _⟩
instance is_scalar_tower'' [has_smul R M] [has_smul M N] [has_smul R N]
[is_scalar_tower R M N] : is_scalar_tower R M (ulift N) :=
⟨λ x y z, show up ((x • y) • z.down) = ⟨x • y • z.down⟩, by rw smul_assoc⟩
instance [has_smul R M] [has_smul Rᵐᵒᵖ M] [is_central_scalar R M] :
is_central_scalar R (ulift M) :=
⟨λ r m, congr_arg up $ op_smul_eq_smul r m.down⟩
@[to_additive]
instance mul_action [monoid R] [mul_action R M] : mul_action (ulift R) M :=
{ smul := (•),
mul_smul := λ _ _, mul_smul _ _,
one_smul := one_smul _ }
@[to_additive]
instance mul_action' [monoid R] [mul_action R M] :
mul_action R (ulift M) :=
{ smul := (•),
mul_smul := λ r s ⟨f⟩, ext _ _ $ mul_smul _ _ _,
one_smul := λ ⟨f⟩, ext _ _ $ one_smul _ _,
..ulift.has_smul_left }
instance distrib_mul_action [monoid R] [add_monoid M] [distrib_mul_action R M] :
distrib_mul_action (ulift R) M :=
{ smul_zero := λ _, smul_zero _,
smul_add := λ _, smul_add _ }
instance distrib_mul_action' [monoid R] [add_monoid M] [distrib_mul_action R M] :
distrib_mul_action R (ulift M) :=
{ smul_zero := λ c, by { ext, simp [smul_zero], },
smul_add := λ c f g, by { ext, simp [smul_add], },
..ulift.mul_action' }
instance mul_distrib_mul_action [monoid R] [monoid M] [mul_distrib_mul_action R M] :
mul_distrib_mul_action (ulift R) M :=
{ smul_one := λ _, smul_one _,
smul_mul := λ _, smul_mul' _ }
instance mul_distrib_mul_action' [monoid R] [monoid M] [mul_distrib_mul_action R M] :
mul_distrib_mul_action R (ulift M) :=
{ smul_one := λ _, by { ext, simp [smul_one], },
smul_mul := λ c f g, by { ext, simp [smul_mul'], },
..ulift.mul_action' }
instance smul_with_zero [has_zero R] [has_zero M] [smul_with_zero R M] :
smul_with_zero (ulift R) M :=
{ smul_zero := λ _, smul_zero' _ _,
zero_smul := zero_smul _,
..ulift.has_smul_left }
instance smul_with_zero' [has_zero R] [has_zero M] [smul_with_zero R M] :
smul_with_zero R (ulift M) :=
{ smul_zero := λ _, ulift.ext _ _ $ smul_zero' _ _,
zero_smul := λ _, ulift.ext _ _ $ zero_smul _ _ }
instance mul_action_with_zero [monoid_with_zero R] [has_zero M] [mul_action_with_zero R M] :
mul_action_with_zero (ulift R) M :=
{ ..ulift.smul_with_zero }
instance mul_action_with_zero' [monoid_with_zero R] [has_zero M] [mul_action_with_zero R M] :
mul_action_with_zero R (ulift M) :=
{ ..ulift.smul_with_zero' }
instance module [semiring R] [add_comm_monoid M] [module R M] : module (ulift R) M :=
{ add_smul := λ _ _, add_smul _ _,
..ulift.smul_with_zero }
instance module' [semiring R] [add_comm_monoid M] [module R M] : module R (ulift M) :=
{ add_smul := λ _ _ _, ulift.ext _ _ $ add_smul _ _ _,
..ulift.smul_with_zero' }
/--
The `R`-linear equivalence between `ulift M` and `M`.
-/
def module_equiv [semiring R] [add_comm_monoid M] [module R M] : ulift M ≃ₗ[R] M :=
{ to_fun := ulift.down,
inv_fun := ulift.up,
map_smul' := λ r x, rfl,
map_add' := λ x y, rfl,
left_inv := by tidy,
right_inv := by tidy, }
end ulift
|
6d6b2698ad8c24484f742c2fafcc101a7db0f309
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/unnecessaryUnfolding.lean
|
b18a1575e969c3b2e6ce46cf4e9b2475e3e83c1d
|
[
"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
| 145
|
lean
|
import Lean
open Lean
abbrev M := StateRefT Nat IO
def M.run (x : M α) (s := 0) : IO α :=
x.run' s
variable (x : M Unit)
#check id x.run
|
9dd42a3ac643d64e8855c6dd907f986a80ff05de
|
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
|
/src/Lean/Meta/Instances.lean
|
59aeb54f07d3dedab69a3e42398740f8999561b4
|
[
"Apache-2.0"
] |
permissive
|
collares/lean4
|
861a9269c4592bce49b71059e232ff0bfe4594cc
|
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
|
refs/heads/master
| 1,691,419,031,324
| 1,618,678,138,000
| 1,618,678,138,000
| 358,989,750
| 0
| 0
|
Apache-2.0
| 1,618,696,333,000
| 1,618,696,333,000
| null |
UTF-8
|
Lean
| false
| false
| 4,922
|
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.ScopedEnvExtension
import Lean.Meta.DiscrTree
namespace Lean.Meta
structure InstanceEntry where
keys : Array DiscrTree.Key
val : Expr
priority : Nat
globalName? : Option Name := none
deriving Inhabited
instance : BEq InstanceEntry where
beq e₁ e₂ := e₁.val == e₂.val
instance : ToFormat InstanceEntry where
format e := match e.globalName? with
| some n => fmt n
| _ => "<local>"
structure Instances where
discrTree : DiscrTree InstanceEntry := DiscrTree.empty
globalInstances : NameSet := {}
deriving Inhabited
def addInstanceEntry (d : Instances) (e : InstanceEntry) : Instances := {
d with
discrTree := d.discrTree.insertCore e.keys e
globalInstances := match e.globalName? with
| some n => d.globalInstances.insert n
| none => d.globalInstances
}
builtin_initialize instanceExtension : SimpleScopedEnvExtension InstanceEntry Instances ←
registerSimpleScopedEnvExtension {
name := `instanceExt
initial := {}
addEntry := addInstanceEntry
}
private def mkInstanceKey (e : Expr) : MetaM (Array DiscrTree.Key) := do
let type ← inferType e
withNewMCtxDepth do
let (_, _, type) ← forallMetaTelescopeReducing type
DiscrTree.mkPath type
def addInstance (declName : Name) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit := do
let c ← mkConstWithLevelParams declName
let keys ← mkInstanceKey c
instanceExtension.add { keys := keys, val := c, priority := prio, globalName? := declName } attrKind
builtin_initialize
registerBuiltinAttribute {
name := `instance
descr := "type class instance"
add := fun declName stx attrKind => do
let prio ← getAttrParamOptPrio stx[1]
discard <| addInstance declName attrKind prio |>.run {} {}
}
@[export lean_is_instance]
def isGlobalInstance (env : Environment) (declName : Name) : Bool :=
Meta.instanceExtension.getState env |>.globalInstances.contains declName
def getGlobalInstancesIndex : MetaM (DiscrTree InstanceEntry) :=
return Meta.instanceExtension.getState (← getEnv) |>.discrTree
/- Default instance support -/
structure DefaultInstanceEntry where
className : Name
instanceName : Name
priority : Nat
abbrev PrioritySet := Std.RBTree Nat (.>.)
structure DefaultInstances where
defaultInstances : NameMap (List (Name × Nat)) := {}
priorities : PrioritySet := {}
deriving Inhabited
def addDefaultInstanceEntry (d : DefaultInstances) (e : DefaultInstanceEntry) : DefaultInstances :=
let d := { d with priorities := d.priorities.insert e.priority }
match d.defaultInstances.find? e.className with
| some insts => { d with defaultInstances := d.defaultInstances.insert e.className <| (e.instanceName, e.priority) :: insts }
| none => { d with defaultInstances := d.defaultInstances.insert e.className [(e.instanceName, e.priority)] }
builtin_initialize defaultInstanceExtension : SimplePersistentEnvExtension DefaultInstanceEntry DefaultInstances ←
registerSimplePersistentEnvExtension {
name := `defaultInstanceExt
addEntryFn := addDefaultInstanceEntry
addImportedFn := fun es => (mkStateFromImportedEntries addDefaultInstanceEntry {} es)
}
def addDefaultInstance (declName : Name) (prio : Nat := 0) : MetaM Unit := do
match (← getEnv).find? declName with
| none => throwError "unknown constant '{declName}'"
| some info =>
forallTelescopeReducing info.type fun _ type => do
match type.getAppFn with
| Expr.const className _ _ =>
unless isClass (← getEnv) className do
throwError "invalid default instance '{declName}', it has type '({className} ...)', but {className}' is not a type class"
setEnv <| defaultInstanceExtension.addEntry (← getEnv) { className := className, instanceName := declName, priority := prio }
| _ => throwError "invalid default instance '{declName}', type must be of the form '(C ...)' where 'C' is a type class"
builtin_initialize
registerBuiltinAttribute {
name := `defaultInstance
descr := "type class default instance"
add := fun declName stx kind => do
let prio ← getAttrParamOptPrio stx[1]
unless kind == AttributeKind.global do throwError "invalid attribute 'defaultInstance', must be global"
discard <| addDefaultInstance declName prio |>.run {} {}
}
def getDefaultInstancesPriorities [Monad m] [MonadEnv m] : m PrioritySet :=
return defaultInstanceExtension.getState (← getEnv) |>.priorities
def getDefaultInstances [Monad m] [MonadEnv m] (className : Name) : m (List (Name × Nat)) :=
return defaultInstanceExtension.getState (← getEnv) |>.defaultInstances.find? className |>.getD []
end Lean.Meta
|
f638820ef86eb5ac0fea6b0fed62404f9cc1626c
|
02fbe05a45fda5abde7583464416db4366eedfbf
|
/library/init/meta/environment.lean
|
86f0c600e85025480e7848f2e6ccbd2fa4891982
|
[
"Apache-2.0"
] |
permissive
|
jasonrute/lean
|
cc12807e11f9ac6b01b8951a8bfb9c2eb35a0154
|
4be962c167ca442a0ec5e84472d7ff9f5302788f
|
refs/heads/master
| 1,672,036,664,637
| 1,601,642,826,000
| 1,601,642,826,000
| 260,777,966
| 0
| 0
|
Apache-2.0
| 1,588,454,819,000
| 1,588,454,818,000
| null |
UTF-8
|
Lean
| false
| false
| 10,699
|
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.declaration init.meta.exceptional init.data.option.basic
import init.meta.rb_map
/-- An __environment__ contains all of the declarations and notation that have been defined so far. -/
meta constant environment : Type
namespace environment
/--
Consider a type `ψ` which is an inductive datatype using a single constructor `mk (a : α) (b : β) : ψ`.
Lean will automatically make two projection functions `a : ψ → α`, `b : ψ → β`.
Lean tags these declarations as __projections__.
This helps the simplifier / rewriter not have to expand projectors.
Eg `a (mk x y)` will automatically reduce to `x`.
If you `extend` a structure, all of the projections on the parent will also be created for the child.
Projections are also treated differently in the VM for efficiency.
Note that projections have nothing to do with the dot `mylist.map` syntax.
You can find out if a declaration is a projection using `environment.is_projection` which returns `projection_info`.
Data for a projection declaration:
- `cname` is the name of the constructor associated with the projection.
- `nparams` is the number of constructor parameters. Eg `and.intro` has two type parameters.
- `idx` is the parameter being projected by this projection.
- `is_class` is tt iff this is a typeclass projection.
### Examples:
- `and.right` is a projection with ``{cname := `and.intro, nparams := 2, idx := 1, is_class := ff}``
- `ordered_ring.neg` is a projection with ``{cname := `ordered_ring.mk, nparams := 1, idx := 5, is_class := tt}``.
-/
structure projection_info :=
(cname : name)
(nparams : nat)
(idx : nat)
(is_class : bool)
/-- A marking on the binders of structures and inductives indicating
how this constructor should mark its parameters.
inductive foo
| one {} : foo -> foo -- relaxed_implicit
| two ( ) : foo -> foo -- explicit
| two [] : foo -> foo -- implicit
| three : foo -> foo -- relaxed implicit (default)
-/
inductive implicit_infer_kind | implicit | relaxed_implicit | none
instance implicit_infer_kind.inhabited : inhabited implicit_infer_kind := ⟨implicit_infer_kind.implicit⟩
/-- One introduction rule in an inductive declaration -/
meta structure intro_rule :=
(constr : name)
(type : expr)
(infer : implicit_infer_kind := implicit_infer_kind.implicit)
/-- Create a standard environment using the given trust level -/
meta constant mk_std : nat → environment
/-- Return the trust level of the given environment -/
meta constant trust_lvl : environment → nat
/-- Add a new declaration to the environment -/
meta constant add : environment → declaration → exceptional environment
/-- make declaration `n` protected -/
meta constant mk_protected : environment → name → environment
/-- add declaration `d` and make it protected -/
meta def add_protected (env : environment) (d : declaration) : exceptional environment := do
env ← env.add d,
pure $ env.mk_protected d.to_name
/-- check if `n` is the name of a protected declaration -/
meta constant is_protected : environment → name → bool
/-- Retrieve a declaration from the environment -/
meta constant get : environment → name → exceptional declaration
meta def contains (env : environment) (d : name) : bool :=
match env.get d with
| exceptional.success _ := tt
| exceptional.exception _ := ff
end
meta constant add_defn_eqns (env : environment) (opt : options)
(lp_params : list name) (params : list expr) (sig : expr)
(eqns : list (list (expr ff) × expr)) (is_meta : bool) : exceptional environment
/-- Register the given name as a namespace, making it available to the `open` command -/
meta constant add_namespace : environment → name → environment
/-- Return tt iff the given name is a namespace -/
meta constant is_namespace : environment → name → bool
/-- Add a new inductive datatype to the environment
name, universe parameters, number of parameters, type, constructors (name and type), is_meta -/
meta constant add_inductive (env : environment)
(n : name) (levels : list name) (num_params : nat) (type : expr)
(intros : list (name × expr)) (is_meta : bool) : exceptional environment
/-- Add a new general inductive declaration to the environment.
This has the same effect as a `inductive` in the file, including generating
all the auxiliary definitions, as well as triggering mutual/nested inductive
compilation, by contrast to `environment.add_inductive` which only adds the
core axioms supported by the kernel.
The `inds` argument should be a list of inductives in the mutual family.
The first argument is a pair of the name of the type being constructed
and the type of this inductive family (not including the params).
The second argument is a list of intro rules, specified by a name, an
`implicit_infer_kind` giving the implicitness of the params for this constructor,
and an expression with the type of the constructor (not including the params).
-/
meta constant add_ginductive (env : environment) (opt : options)
(levels : list name) (params : list expr)
(inds : list ((name × expr) × list intro_rule))
(is_meta : bool) : exceptional environment
/-- Return tt iff the given name is an inductive datatype -/
meta constant is_inductive : environment → name → bool
/-- Return tt iff the given name is a constructor -/
meta constant is_constructor : environment → name → bool
/-- Return tt iff the given name is a recursor -/
meta constant is_recursor : environment → name → bool
/-- Return tt iff the given name is a recursive inductive datatype -/
meta constant is_recursive : environment → name → bool
/-- Return the name of the inductive datatype of the given constructor. -/
meta constant inductive_type_of : environment → name → option name
/-- Return the constructors of the inductive datatype with the given name -/
meta constant constructors_of : environment → name → list name
/-- Return the recursor of the given inductive datatype -/
meta constant recursor_of : environment → name → option name
/-- Return the number of parameters of the inductive datatype -/
meta constant inductive_num_params : environment → name → nat
/-- Return the number of indices of the inductive datatype -/
meta constant inductive_num_indices : environment → name → nat
/-- Return tt iff the inductive datatype recursor supports dependent elimination -/
meta constant inductive_dep_elim : environment → name → bool
/-- Functionally equivalent to `is_inductive`.
Technically, this works by checking if the name is in the ginductive environment
extension which is outside the kernel, whereas `is_inductive` works by looking at the kernel extension.
But there are no `is_inductive`s which are not `is_ginductive`.
-/
meta constant is_ginductive : environment → name → bool
/-- See the docstring for `projection_info`. -/
meta constant is_projection : environment → name → option projection_info
/-- Fold over declarations in the environment. -/
meta constant fold {α :Type} : environment → α → (declaration → α → α) → α
/-- `relation_info env n` returns some value if n is marked as a relation in the given environment.
the tuple contains: total number of arguments of the relation, lhs position and rhs position. -/
meta constant relation_info : environment → name → option (nat × nat × nat)
/-- `refl_for env R` returns the name of the reflexivity theorem for the relation R -/
meta constant refl_for : environment → name → option name
/-- `symm_for env R` returns the name of the symmetry theorem for the relation R -/
meta constant symm_for : environment → name → option name
/-- `trans_for env R` returns the name of the transitivity theorem for the relation R -/
meta constant trans_for : environment → name → option name
/-- `decl_olean env d` returns the name of the .olean file where d was defined.
The result is none if d was not defined in an imported file. -/
meta constant decl_olean : environment → name → option string
/-- `decl_pos env d` returns the source location of d if available. -/
meta constant decl_pos : environment → name → option pos
/-- Return the fields of the structure with the given name, or `none` if it is not a structure -/
meta constant structure_fields : environment → name → option (list name)
/-- `get_class_attribute_symbols env attr_name` return symbols
occurring in instances of type classes tagged with the attribute `attr_name`.
Example: [algebra] -/
meta constant get_class_attribute_symbols : environment → name → name_set
/-- The fingerprint of the environment is a hash formed from all of the declarations in the environment. -/
meta constant fingerprint : environment → nat
/-- Gets the equation lemmas for the declaration `n`. -/
meta constant get_eqn_lemmas_for (env : environment) (n : name) : list name
/-- Gets the equation lemmas for the declaration `n`, including lemmas for match statements, etc. -/
meta constant get_ext_eqn_lemmas_for (env : environment) (n : name) : list name
/--
Adds the equation lemma `n`.
It is added for the declaration `t.pi_codomain.get_app_fn.const_name` where `t` is the type of the equation lemma.
-/
meta constant add_eqn_lemma (env : environment) (n : name) : environment
open expr
meta constant unfold_untrusted_macros : environment → expr → expr
meta constant unfold_all_macros : environment → expr → expr
meta def is_constructor_app (env : environment) (e : expr) : bool :=
is_constant (get_app_fn e) && is_constructor env (const_name (get_app_fn e))
meta def is_refl_app (env : environment) (e : expr) : option (name × expr × expr) :=
match (refl_for env (const_name (get_app_fn e))) with
| (some n) :=
if get_app_num_args e ≥ 2
then some (n, app_arg (app_fn e), app_arg e)
else none
| none := none
end
/-- Return true if 'n' has been declared in the current file -/
meta def in_current_file (env : environment) (n : name) : bool :=
(env.decl_olean n).is_none && env.contains n && (n ∉ [``quot, ``quot.mk, ``quot.lift, ``quot.ind])
meta def is_definition (env : environment) (n : name) : bool :=
match env.get n with
| exceptional.success (declaration.defn _ _ _ _ _ _) := tt
| _ := ff
end
end environment
meta instance : has_repr environment :=
⟨λ e, "[environment]"⟩
meta instance : inhabited environment :=
⟨environment.mk_std 0⟩
|
47a272028a70962f5dc82a43266148587d1c211c
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/sharecommon.lean
|
c4db313573c83b99e528ceb938fc66a32de8104f
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
leanprover/lean4
|
4bdf9790294964627eb9be79f5e8f6157780b4cc
|
f1f9dc0f2f531af3312398999d8b8303fa5f096b
|
refs/heads/master
| 1,693,360,665,786
| 1,693,350,868,000
| 1,693,350,868,000
| 129,571,436
| 2,827
| 311
|
Apache-2.0
| 1,694,716,156,000
| 1,523,760,560,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,948
|
lean
|
import Lean.Util.ShareCommon
open Lean.ShareCommon
def check (b : Bool) : ShareCommonT IO Unit := do
unless b do throw $ IO.userError "check failed"
unsafe def tst1 : ShareCommonT IO Unit := do
let x := [1]
let y := [0].map (fun x => x + 1)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x ← shareCommonM x
let y ← shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z ← shareCommonM [2]
let x ← shareCommonM x
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
check $ ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst1.run
unsafe def tst2 : ShareCommonT IO Unit := do
let x := [1, 2]
let y := [0, 1].map (fun x => x + 1)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x ← shareCommonM x
let y ← shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z ← shareCommonM [2]
let x ← shareCommonM x
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
check $ ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst2.run
structure Foo :=
(x : Nat)
(y : Bool)
(z : Bool)
@[noinline] def mkFoo1 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z }
@[noinline] def mkFoo2 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z }
unsafe def tst3 : ShareCommonT IO Unit := do
let o1 := mkFoo1 10 true
let o2 := mkFoo2 10 true
let o3 := mkFoo2 10 false
check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o2
check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o3
let o1 ← shareCommonM o1
let o2 ← shareCommonM o2
let o3 ← shareCommonM o3
check $
o1.x == 10 && o1.y == true &&
o1.z == true && o3.z == false &&
ptrAddrUnsafe o1 == ptrAddrUnsafe o2 &&
ptrAddrUnsafe o1 != ptrAddrUnsafe o3
IO.println o1.x
pure ()
#eval tst3.run
unsafe def tst4 : ShareCommonT IO Unit := do
let x := ["hello"]
let y := ["ello"].map (fun x => "h" ++ x)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x ← shareCommonM x
let y ← shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z ← shareCommonM ["world"]
let x ← shareCommonM x
check $
ptrAddrUnsafe x == ptrAddrUnsafe y &&
ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst4.run
@[noinline] def mkList1 (x : Nat) : List Nat := List.replicate x x
@[noinline] def mkList2 (x : Nat) : List Nat := List.replicate x x
@[noinline] def mkArray1 (x : Nat) : Array (List Nat) :=
#[ mkList1 x, mkList2 x, mkList2 (x+1) ]
@[noinline] def mkArray2 (x : Nat) : Array (List Nat) :=
mkArray1 x
unsafe def tst5 : ShareCommonT IO Unit := do
let a := mkArray1 3
let b := mkArray2 3
let c := mkArray2 4
IO.println a
IO.println b
IO.println c
check $
ptrAddrUnsafe a != ptrAddrUnsafe b &&
ptrAddrUnsafe a != ptrAddrUnsafe c &&
ptrAddrUnsafe a[0]! != ptrAddrUnsafe a[1]! &&
ptrAddrUnsafe a[0]! != ptrAddrUnsafe a[2]! &&
ptrAddrUnsafe b[0]! != ptrAddrUnsafe b[1]! &&
ptrAddrUnsafe c[0]! != ptrAddrUnsafe c[1]!
let a ← shareCommonM a
let b ← shareCommonM b
let c ← shareCommonM c
check $
ptrAddrUnsafe a == ptrAddrUnsafe b &&
ptrAddrUnsafe a != ptrAddrUnsafe c &&
ptrAddrUnsafe a[0]! == ptrAddrUnsafe a[1]! &&
ptrAddrUnsafe a[0]! != ptrAddrUnsafe a[2]! &&
ptrAddrUnsafe b[0]! == ptrAddrUnsafe b[1]! &&
ptrAddrUnsafe c[0]! == ptrAddrUnsafe c[1]!
pure ()
#eval tst5.run
@[noinline] def mkByteArray1 (x : Nat) : ByteArray :=
let r := ByteArray.empty
let r := r.push x.toUInt8
let r := r.push (x+(1:Nat)).toUInt8
let r := r.push (x+(2:Nat)).toUInt8
r
@[noinline] def mkByteArray2 (x : Nat) : ByteArray :=
mkByteArray1 x
unsafe def tst6 (x : Nat) : ShareCommonT IO Unit := do
let a := [mkByteArray1 x]
let b := [mkByteArray2 x]
let c := [mkByteArray2 (x+1)]
IO.println a
IO.println b
IO.println c
check $ ptrAddrUnsafe a != ptrAddrUnsafe b
check $ ptrAddrUnsafe a != ptrAddrUnsafe c
let a ← shareCommonM a
let b ← shareCommonM b
let c ← shareCommonM c
check $ ptrAddrUnsafe a == ptrAddrUnsafe b
check $ ptrAddrUnsafe a != ptrAddrUnsafe c
pure ()
#eval (tst6 2).run
|
e33502d97be40c8a6e8cdbbc1ada11c2dca4e8b3
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/tut_104.lean
|
86e521155148ecd3eb1a24709ed6ea584c0e3099
|
[
"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
| 1,190
|
lean
|
import data.set
namespace function
section
open set
variables {A B : Type}
set_option pp.beta false
lemma injective_eq_inj_on_univ₁ (f : A → B) : injective f = inj_on f univ :=
begin
esimp [injective, inj_on, univ, mem],
apply propext,
apply iff.intro,
intro Pl a1 a2,
rewrite *true_imp,
exact @Pl a1 a2,
intro Pr a1 a2,
exact Pr trivial trivial
end
lemma injective_eq_inj_on_univ₂ (f : A → B) : injective f = inj_on f univ :=
begin
esimp [injective, inj_on, univ, mem],
apply propext,
apply iff.intro,
intro Pl a1 a2,
rewrite *(propext !true_imp),
exact @Pl a1 a2,
intro Pr a1 a2,
exact Pr trivial trivial
end
lemma injective_eq_inj_on_univ₃ (f : A → B) : injective f = inj_on f univ :=
begin
esimp [injective, inj_on, univ, mem],
apply propext,
repeat (apply forall_congr; intros),
rewrite *(propext !true_imp)
end
lemma injective_eq_inj_on_univ₄ (f : A → B) : injective f = inj_on f univ :=
begin
esimp [injective, inj_on, univ, mem],
apply propext,
repeat (apply forall_congr; intros),
rewrite *true_imp
end
end
end function
|
f5b6b197c7f3d7bf47e8c16a7bca7289e84d4253
|
e6b8240a90527fd55d42d0ec6649253d5d0bd414
|
/src/meta/expr.lean
|
2498ba2ac2993f2b7ea7a97d96df1c843d633975
|
[
"Apache-2.0"
] |
permissive
|
mattearnshaw/mathlib
|
ac90f9fb8168aa642223bea3ffd0286b0cfde44f
|
d8dc1445cf8a8c74f8df60b9f7a1f5cf10946666
|
refs/heads/master
| 1,606,308,351,137
| 1,576,594,130,000
| 1,576,594,130,000
| 228,666,195
| 0
| 0
|
Apache-2.0
| 1,576,603,094,000
| 1,576,603,093,000
| null |
UTF-8
|
Lean
| false
| false
| 25,494
|
lean
|
/-
Copyright (c) 2019 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek, Robert Y. Lewis
-/
import data.string.defs
/-!
# Additional operations on expr and related types
This file defines basic operations on the types expr, name, declaration, level, environment.
This file is mostly for non-tactics. Tactics should generally be placed in `tactic.core`.
## Tags
expr, name, declaration, level, environment, meta, metaprogramming, tactic
-/
namespace binder_info
/-! ### Declarations about `binder_info` -/
instance : inhabited binder_info := ⟨ binder_info.default ⟩
/-- The brackets corresponding to a given binder_info. -/
def brackets : binder_info → string × string
| binder_info.implicit := ("{", "}")
| binder_info.strict_implicit := ("{{", "}}")
| binder_info.inst_implicit := ("[", "]")
| _ := ("(", ")")
end binder_info
namespace name
/-! ### Declarations about `name` -/
/-- Find the largest prefix `n` of a `name` such that `f n ≠ none`, then replace this prefix
with the value of `f n`. -/
def map_prefix (f : name → option name) : name → name
| anonymous := anonymous
| (mk_string s n') := (f (mk_string s n')).get_or_else (mk_string s $ map_prefix n')
| (mk_numeral d n') := (f (mk_numeral d n')).get_or_else (mk_numeral d $ map_prefix n')
/-- If `nm` is a simple name (having only one string component) starting with `_`, then `deinternalize_field nm` removes the underscore. Otherwise, it does nothing. -/
meta def deinternalize_field : name → name
| (mk_string s name.anonymous) :=
let i := s.mk_iterator in
if i.curr = '_' then i.next.next_to_string else s
| n := n
/-- `get_nth_prefix nm n` removes the last `n` components from `nm` -/
meta def get_nth_prefix : name → ℕ → name
| nm 0 := nm
| nm (n + 1) := get_nth_prefix nm.get_prefix n
/-- Auxilliary definition for `pop_nth_prefix` -/
private meta def pop_nth_prefix_aux : name → ℕ → name × ℕ
| anonymous n := (anonymous, 1)
| nm n := let (pfx, height) := pop_nth_prefix_aux nm.get_prefix n in
if height ≤ n then (anonymous, height + 1)
else (nm.update_prefix pfx, height + 1)
/-- Pops the top `n` prefixes from the given name. -/
meta def pop_nth_prefix (nm : name) (n : ℕ) : name :=
prod.fst $ pop_nth_prefix_aux nm n
/-- Pop the prefix of a name -/
meta def pop_prefix (n : name) : name :=
pop_nth_prefix n 1
/-- Auxilliary definition for `from_components` -/
private def from_components_aux : name → list string → name
| n [] := n
| n (s :: rest) := from_components_aux (name.mk_string s n) rest
/-- Build a name from components. For example `from_components ["foo","bar"]` becomes
``` `foo.bar``` -/
def from_components : list string → name :=
from_components_aux name.anonymous
/-- `name`s can contain numeral pieces, which are not legal names
when typed/passed directly to the parser. We turn an arbitrary
name into a legal identifier name by turning the numbers to strings. -/
meta def sanitize_name : name → name
| name.anonymous := name.anonymous
| (name.mk_string s p) := name.mk_string s $ sanitize_name p
| (name.mk_numeral s p) := name.mk_string sformat!"n{s}" $ sanitize_name p
/-- Append a string to the last component of a name -/
def append_suffix : name → string → name
| (mk_string s n) s' := mk_string (s ++ s') n
| n _ := n
/-- The first component of a name, turning a number to a string -/
meta def head : name → string
| (mk_string s anonymous) := s
| (mk_string s p) := head p
| (mk_numeral n p) := head p
| anonymous := "[anonymous]"
/-- Tests whether the first component of a name is `"_private"` -/
meta def is_private (n : name) : bool :=
n.head = "_private"
/-- Get the last component of a name, and convert it to a string. -/
meta def last : name → string
| (mk_string s _) := s
| (mk_numeral n _) := repr n
| anonymous := "[anonymous]"
/-- Returns the number of characters used to print all the string components of a name,
including periods between name segments. Ignores numerical parts of a name. -/
meta def length : name → ℕ
| (mk_string s anonymous) := s.length
| (mk_string s p) := s.length + 1 + p.length
| (mk_numeral n p) := p.length
| anonymous := "[anonymous]".length
/-- Checks whether `nm` has a prefix (including itself) such that P is true -/
def has_prefix (P : name → bool) : name → bool
| anonymous := ff
| (mk_string s nm) := P (mk_string s nm) ∨ has_prefix nm
| (mk_numeral s nm) := P (mk_numeral s nm) ∨ has_prefix nm
/-- Appends `'` to the end of a name. -/
meta def add_prime : name → name
| (name.mk_string s p) := name.mk_string (s ++ "'") p
| n := (name.mk_string "x'" n)
def last_string : name → string
| anonymous := "[anonymous]"
| (mk_string s _) := s
| (mk_numeral _ n) := last_string n
end name
namespace level
/-! ### Declarations about `level` -/
/-- Tests whether a universe level is non-zero for all assignments of its variables -/
meta def nonzero : level → bool
| (succ _) := tt
| (max l₁ l₂) := l₁.nonzero || l₂.nonzero
| (imax _ l₂) := l₂.nonzero
| _ := ff
end level
/-! ### Declarations about `binder` -/
/-- The type of binders containing a name, the binding info and the binding type -/
@[derive decidable_eq]
meta structure binder :=
(name : name)
(info : binder_info)
(type : expr)
namespace binder
/-- Turn a binder into a string. Uses expr.to_string for the type. -/
protected meta def to_string (b : binder) : string :=
let (l, r) := b.info.brackets in
l ++ b.name.to_string ++ " : " ++ b.type.to_string ++ r
open tactic
meta instance : inhabited binder := ⟨⟨default _, default _, default _⟩⟩
meta instance : has_to_string binder := ⟨ binder.to_string ⟩
meta instance : has_to_format binder := ⟨ λ b, b.to_string ⟩
meta instance : has_to_tactic_format binder :=
⟨ λ b, let (l, r) := b.info.brackets in
(λ e, l ++ b.name.to_string ++ " : " ++ e ++ r) <$> pp b.type ⟩
end binder
/-!
### Converting between expressions and numerals
There are a number of ways to convert between expressions and numerals, depending on the input and
output types and whether you want to infer the necessary type classes.
See also the tactics `expr.of_nat`, `expr.of_int`, `expr.of_rat`.
-/
/--
`nat.mk_numeral n` embeds `n` as a numeral expression inside a type with 0, 1, and +.
`type`: an expression representing the target type. This must live in Type 0.
`has_zero`, `has_one`, `has_add`: expressions of the type `has_zero %%type`, etc.
-/
meta def nat.mk_numeral (type has_zero has_one has_add : expr) : ℕ → expr :=
let z : expr := `(@has_zero.zero.{0} %%type %%has_zero),
o : expr := `(@has_one.one.{0} %%type %%has_one) in
nat.binary_rec z
(λ b n e, if n = 0 then o else
if b then `(@bit1.{0} %%type %%has_one %%has_add %%e)
else `(@bit0.{0} %%type %%has_add %%e))
/--
`int.mk_numeral z` embeds `z` as a numeral expression inside a type with 0, 1, +, and -.
`type`: an expression representing the target type. This must live in Type 0.
`has_zero`, `has_one`, `has_add`, `has_neg`: expressions of the type `has_zero %%type`, etc.
-/
meta def int.mk_numeral (type has_zero has_one has_add has_neg : expr) : ℤ → expr
| (int.of_nat n) := n.mk_numeral type has_zero has_one has_add
| -[1+n] := let ne := (n+1).mk_numeral type has_zero has_one has_add in
`(@has_neg.neg.{0} %%type %%has_neg %%ne)
namespace expr
/-- Turns an expression into a positive natural number, assuming it is only built up from
`has_one.one`, `bit0` and `bit1`. -/
protected meta def to_pos_nat : expr → option ℕ
| `(has_one.one _) := some 1
| `(bit0 %%e) := bit0 <$> e.to_pos_nat
| `(bit1 %%e) := bit1 <$> e.to_pos_nat
| _ := none
/-- Turns an expression into a natural number, assuming it is only built up from
`has_one.one`, `bit0`, `bit1` and `has_zero.zero`. -/
protected meta def to_nat : expr → option ℕ
| `(has_zero.zero _) := some 0
| e := e.to_pos_nat
/-- Turns an expression into a integer, assuming it is only built up from
`has_one.one`, `bit0`, `bit1`, `has_zero.zero` and a optionally a single `has_neg.neg` as head. -/
protected meta def to_int : expr → option ℤ
| `(has_neg.neg %%e) := do n ← e.to_nat, some (-n)
| e := coe <$> e.to_nat
/--
is_num_eq n1 n2 returns true if n1 and n2 are both numerals with the same numeral structure,
ignoring differences in type and type class arguments.
-/
meta def is_num_eq : expr → expr → bool
| `(@has_zero.zero _ _) `(@has_zero.zero _ _) := tt
| `(@has_one.one _ _) `(@has_one.one _ _) := tt
| `(bit0 %%a) `(bit0 %%b) := a.is_num_eq b
| `(bit1 %%a) `(bit1 %%b) := a.is_num_eq b
| `(-%%a) `(-%%b) := a.is_num_eq b
| `(%%a/%%a') `(%%b/%%b') := a.is_num_eq b
| _ _ := ff
end expr
/-! ### Declarations about `expr` -/
namespace expr
open tactic
/-- `replace_with e s s'` replaces ocurrences of `s` with `s'` in `e`. -/
meta def replace_with (e : expr) (s : expr) (s' : expr) : expr :=
e.replace $ λc d, if c = s then some (s'.lift_vars 0 d) else none
/-- Apply a function to each constant (inductive type, defined function etc) in an expression. -/
protected meta def apply_replacement_fun (f : name → name) (e : expr) : expr :=
e.replace $ λ e d,
match e with
| expr.const n ls := some $ expr.const (f n) ls
| _ := none
end
/-- Tests whether an expression is a meta-variable. -/
meta def is_mvar : expr → bool
| (mvar _ _ _) := tt
| _ := ff
/-- Tests whether an expression is a sort. -/
meta def is_sort : expr → bool
| (sort _) := tt
| e := ff
/-- If `e` is a local constant, `to_implicit_local_const e` changes the binder info of `e` to
`implicit`. See also `to_implicit_binder`, which also changes lambdas and pis. -/
meta def to_implicit_local_const : expr → expr
| (expr.local_const uniq n bi t) := expr.local_const uniq n binder_info.implicit t
| e := e
/-- If `e` is a local constant, lamda, or pi expression, `to_implicit_binder e` changes the binder
info of `e` to `implicit`. See also `to_implicit_local_const`, which only changes local constants. -/
meta def to_implicit_binder : expr → expr
| (local_const n₁ n₂ _ d) := local_const n₁ n₂ binder_info.implicit d
| (lam n _ d b) := lam n binder_info.implicit d b
| (pi n _ d b) := pi n binder_info.implicit d b
| e := e
/-- Returns a list of all local constants in an expression (without duplicates). -/
meta def list_local_consts (e : expr) : list expr :=
e.fold [] (λ e' _ es, if e'.is_local_constant then insert e' es else es)
/-- Returns a name_set of all constants in an expression. -/
meta def list_constant (e : expr) : name_set :=
e.fold mk_name_set (λ e' _ es, if e'.is_constant then es.insert e'.const_name else es)
/-- Returns a list of all meta-variables in an expression (without duplicates). -/
meta def list_meta_vars (e : expr) : list expr :=
e.fold [] (λ e' _ es, if e'.is_mvar then insert e' es else es)
/-- Returns a name_set of all constants in an expression starting with a certain prefix. -/
meta def list_names_with_prefix (pre : name) (e : expr) : name_set :=
e.fold mk_name_set $ λ e' _ l,
match e' with
| expr.const n _ := if n.get_prefix = pre then l.insert n else l
| _ := l
end
/-- Returns true if `e` contains a name `n` where `p n` is true.
Returns `true` if `p name.anonymous` is true -/
meta def contains_constant (e : expr) (p : name → Prop) [decidable_pred p] : bool :=
e.fold ff (λ e' _ b, if p (e'.const_name) then tt else b)
/-- Simplifies the expression `t` with the specified options.
The result is `(new_e, pr)` with the new expression `new_e` and a proof
`pr : e = new_e`. -/
meta def simp (t : expr)
(cfg : simp_config := {}) (discharger : tactic unit := failed)
(no_defaults := ff) (attr_names : list name := []) (hs : list simp_arg_type := []) :
tactic (expr × expr) :=
do (s, to_unfold) ← mk_simp_set no_defaults attr_names hs,
simplify s to_unfold t cfg `eq discharger
/-- Definitionally simplifies the expression `t` with the specified options.
The result is the simplified expression. -/
meta def dsimp (t : expr)
(cfg : dsimp_config := {})
(no_defaults := ff) (attr_names : list name := []) (hs : list simp_arg_type := []) :
tactic expr :=
do (s, to_unfold) ← mk_simp_set no_defaults attr_names hs,
s.dsimplify to_unfold t cfg
/-- Auxilliary definition for `expr.pi_arity` -/
meta def pi_arity_aux : ℕ → expr → ℕ
| n (pi _ _ _ b) := pi_arity_aux (n + 1) b
| n e := n
/-- The arity of a pi-type. Does not perform any reduction of the expression.
In one application this was ~30 times quicker than `tactic.get_pi_arity`. -/
meta def pi_arity : expr → ℕ :=
pi_arity_aux 0
/-- Get the names of the bound variables by a sequence of pis or lambdas. -/
meta def binding_names : expr → list name
| (pi n _ _ e) := n :: e.binding_names
| (lam n _ _ e) := n :: e.binding_names
| e := []
/-- head-reduce a single let expression -/
meta def reduce_let : expr → expr
| (elet _ _ v b) := b.instantiate_var v
| e := e
/-- head-reduce all let expressions -/
meta def reduce_lets : expr → expr
| (elet _ _ v b) := reduce_lets $ b.instantiate_var v
| e := e
/-- Instantiate lambdas in the second argument by expressions from the first. -/
meta def instantiate_lambdas : list expr → expr → expr
| (e'::es) (lam n bi t e) := instantiate_lambdas es (e.instantiate_var e')
| _ e := e
/-- `instantiate_lambdas_or_apps es e` instantiates lambdas in `e` by expressions from `es`.
If the length of `es` is larger than the number of lambdas in `e`,
then the term is applied to the remaining terms.
Also reduces head let-expressions in `e`, including those after instantiating all lambdas. -/
meta def instantiate_lambdas_or_apps : list expr → expr → expr
| (v::es) (lam n bi t b) := instantiate_lambdas_or_apps es $ b.instantiate_var v
| es (elet _ _ v b) := instantiate_lambdas_or_apps es $ b.instantiate_var v
| es e := mk_app e es
/- Note [open expressions]:
Some declarations work with open expressions, i.e. an expr that has free variables.
Terms will free variables are not well-typed, and one should not use them in tactics like
`infer_type` or `unify`. You can still do syntactic analysis/manipulation on them.
The reason for working with open types is for performance: instantiating variables requires
iterating through the expression. In one performance test `pi_binders` was more than 6x
quicker than `mk_local_pis` (when applied to the type of all imported declarations 100x).
-/
/-- Get the codomain/target of a pi-type.
This definition doesn't instantiate bound variables, and therefore produces a term that is open.-/
meta def pi_codomain : expr → expr -- see note [open expressions]
| (pi n bi d b) := pi_codomain b
| e := e
/-- Auxilliary defintion for `pi_binders`. -/
-- see note [open expressions]
meta def pi_binders_aux : list binder → expr → list binder × expr
| es (pi n bi d b) := pi_binders_aux (⟨n, bi, d⟩::es) b
| es e := (es, e)
/-- Get the binders and codomain of a pi-type.
This definition doesn't instantiate bound variables, and therefore produces a term that is open.
The.tactic `get_pi_binders` in `tactic.core` does the same, but also instantiates the
free variables -/
meta def pi_binders (e : expr) : list binder × expr := -- see note [open expressions]
let (es, e) := pi_binders_aux [] e in (es.reverse, e)
/-- Auxilliary defintion for `get_app_fn_args`. -/
meta def get_app_fn_args_aux : list expr → expr → expr × list expr
| r (app f a) := get_app_fn_args_aux (a::r) f
| r e := (e, r)
/-- A combination of `get_app_fn` and `get_app_args`: lists both the
function and its arguments of an application -/
meta def get_app_fn_args : expr → expr × list expr :=
get_app_fn_args_aux []
/-- `drop_pis es e` instantiates the pis in `e` with the expressions from `es`. -/
meta def drop_pis : list expr → expr → tactic expr
| (list.cons v vs) (pi n bi d b) := do
t ← infer_type v,
guard (t =ₐ d),
drop_pis vs (b.instantiate_var v)
| [] e := return e
| _ _ := failed
/-- `mk_op_lst op empty [x1, x2, ...]` is defined as `op x1 (op x2 ...)`.
Returns `empty` if the list is empty. -/
meta def mk_op_lst (op : expr) (empty : expr) : list expr → expr
| [] := empty
| [e] := e
| (e :: es) := op e $ mk_op_lst es
/-- `mk_and_lst [x1, x2, ...]` is defined as `x1 ∧ (x2 ∧ ...)`, or `true` if the list is empty. -/
meta def mk_and_lst : list expr → expr := mk_op_lst `(and) `(true)
/-- `mk_or_lst [x1, x2, ...]` is defined as `x1 ∨ (x2 ∨ ...)`, or `false` if the list is empty. -/
meta def mk_or_lst : list expr → expr := mk_op_lst `(or) `(false)
/-- `local_binding_info e` returns the binding info of `e` if `e` is a local constant.
Otherwise returns `binder_info.default`. -/
meta def local_binding_info : expr → binder_info
| (expr.local_const _ _ bi _) := bi
| _ := binder_info.default
/-- `is_default_local e` tests whether `e` is a local constant with binder info
`binder_info.default` -/
meta def is_default_local : expr → bool
| (expr.local_const _ _ binder_info.default _) := tt
| _ := ff
end expr
/-! ### Declarations about `environment` -/
namespace environment
/-- Tests whether a name is declared in the current file. Fixes an error in `in_current_file`
which returns `tt` for the four names `quot, quot.mk, quot.lift, quot.ind` -/
meta def in_current_file' (env : environment) (n : name) : bool :=
env.in_current_file n && (n ∉ [``quot, ``quot.mk, ``quot.lift, ``quot.ind])
/-- Tests whether `n` is a structure. -/
meta def is_structure (env : environment) (n : name) : bool :=
(env.structure_fields n).is_some
/-- Get the full names of all projections of the structure `n`. Returns `none` if `n` is not a
structure. -/
meta def structure_fields_full (env : environment) (n : name) : option (list name) :=
(env.structure_fields n).map (list.map $ λ n', n ++ n')
/-- Tests whether `nm` is a generalized inductive type that is not a normal inductive type.
Note that `is_ginductive` returns `tt` even on regular inductive types.
This returns `tt` if `nm` is (part of a) mutually defined inductive type or a nested inductive
type. -/
meta def is_ginductive' (e : environment) (nm : name) : bool :=
e.is_ginductive nm ∧ ¬ e.is_inductive nm
/-- For all declarations `d` where `f d = some x` this adds `x` to the returned list. -/
meta def decl_filter_map {α : Type} (e : environment) (f : declaration → option α) : list α :=
e.fold [] $ λ d l, match f d with
| some r := r :: l
| none := l
end
/-- Maps `f` to all declarations in the environment. -/
meta def decl_map {α : Type} (e : environment) (f : declaration → α) : list α :=
e.decl_filter_map $ λ d, some (f d)
/-- Lists all declarations in the environment -/
meta def get_decls (e : environment) : list declaration :=
e.decl_map id
/-- Lists all trusted (non-meta) declarations in the environment -/
meta def get_trusted_decls (e : environment) : list declaration :=
e.decl_filter_map (λ d, if d.is_trusted then some d else none)
/-- Lists the name of all declarations in the environment -/
meta def get_decl_names (e : environment) : list name :=
e.decl_map declaration.to_name
/-- Fold a monad over all declarations in the environment. -/
meta def mfold {α : Type} {m : Type → Type} [monad m] (e : environment) (x : α)
(fn : declaration → α → m α) : m α :=
e.fold (return x) (λ d t, t >>= fn d)
/-- Filters all declarations in the environment. -/
meta def mfilter (e : environment) (test : declaration → tactic bool) : tactic (list declaration) :=
e.mfold [] $ λ d ds, do b ← test d, return $ if b then d::ds else ds
/-- Checks whether `s` is a prefix of the file where `n` is declared.
This is used to check whether `n` is declared in mathlib, where `s` is the mathlib directory. -/
meta def is_prefix_of_file (e : environment) (s : string) (n : name) : bool :=
s.is_prefix_of $ (e.decl_olean n).get_or_else ""
end environment
/-!
### `is_eta_expansion`
In this section we define the tactic `is_eta_expansion` which checks whether an expression
is an eta-expansion of a structure. (not to be confused with eta-expanion for `λ`).
-/
namespace expr
open tactic
/-- `is_eta_expansion_of args univs l` checks whether for all elements `(nm, pr)` in `l` we have
`pr = nm.{univs} args`.
Used in `is_eta_expansion`, where `l` consists of the projections and the fields of the value we
want to eta-reduce. -/
meta def is_eta_expansion_of (args : list expr) (univs : list level) (l : list (name × expr)) :
bool :=
l.all $ λ⟨proj, val⟩, val = (const proj univs).mk_app args
/-- `is_eta_expansion_test l` checks whether there is a list of expresions `args` such that for all
elements `(nm, pr)` in `l` we have `pr = nm args`. If so, returns the last element of `args`.
Used in `is_eta_expansion`, where `l` consists of the projections and the fields of the value we
want to eta-reduce. -/
meta def is_eta_expansion_test : list (name × expr) → option expr
| [] := none
| (⟨proj, val⟩::l) :=
match val.get_app_fn with
| (const nm univs : expr) :=
if nm = proj then
let args := val.get_app_args in
let e := args.ilast in
if is_eta_expansion_of args univs l then some e else none
else
none
| _ := none
end
/-- `is_eta_expansion_aux val l` checks whether `val` can be eta-reduced to an expression `e`.
Here `l` is intended to consists of the projections and the fields of `val`.
This tactic calls `is_eta_expansion_test l`, but first removes all proofs from the list `l` and
afterward checks whether the retulting expression `e` unifies with `val`.
This last check is necessary, because `val` and `e` might have different types. -/
meta def is_eta_expansion_aux (val : expr) (l : list (name × expr)) : tactic (option expr) :=
do l' ← l.mfilter (λ⟨proj, val⟩, bnot <$> is_proof val),
match is_eta_expansion_test l' with
| some e := option.map (λ _, e) <$> try_core (unify e val)
| none := return none
end
/-- `is_eta_expansion val` checks whether there is an expression `e` such that `val` is the
eta-expansion of `e`.
With eta-expansion we here mean the eta-expansion of a structure, not of a function.
For example, the eta-expansion of `x : α × β` is `⟨x.1, x.2⟩`.
This assumes that `val` is a fully-applied application of the constructor of a structure.
This is useful to reduce expressions generated by the notation
`{ field_1 := _, ..other_structure }`
If `other_structure` is itself a field of the structure, then the elaborator will insert an
eta-expanded version of `other_structure`. -/
meta def is_eta_expansion (val : expr) : tactic (option expr) := do
e ← get_env,
type ← infer_type val,
projs ← e.structure_fields_full type.get_app_fn.const_name,
let args := (val.get_app_args).drop type.get_app_args.length,
is_eta_expansion_aux val (projs.zip args)
end expr
/-! ### Declarations about `declaration` -/
namespace declaration
open tactic
protected meta def update_with_fun (f : name → name) (tgt : name) (decl : declaration) :
declaration :=
let decl := decl.update_name $ tgt in
let decl := decl.update_type $ decl.type.apply_replacement_fun f in
decl.update_value $ decl.value.apply_replacement_fun f
/-- Checks whether the declaration is declared in the current file.
This is a simple wrapper around `environment.in_current_file'`
Use `environment.in_current_file'` instead if performance matters. -/
meta def in_current_file (d : declaration) : tactic bool :=
do e ← get_env, return $ e.in_current_file' d.to_name
/-- Checks whether a declaration is a theorem -/
meta def is_theorem : declaration → bool
| (thm _ _ _ _) := tt
| _ := ff
/-- Checks whether a declaration is a constant -/
meta def is_constant : declaration → bool
| (cnst _ _ _ _) := tt
| _ := ff
/-- Checks whether a declaration is a axiom -/
meta def is_axiom : declaration → bool
| (ax _ _ _) := tt
| _ := ff
/-- Checks whether a declaration is automatically generated in the environment.
There is no cheap way to check whether a declaration in the namespace of a generalized
inductive type is automatically generated, so for now we say that all of them are automatically
generated. -/
meta def is_auto_generated (e : environment) (d : declaration) : bool :=
e.is_constructor d.to_name ∨
(e.is_projection d.to_name).is_some ∨
(e.is_constructor d.to_name.get_prefix ∧
d.to_name.last ∈ ["inj", "inj_eq", "sizeof_spec", "inj_arrow"]) ∨
(e.is_inductive d.to_name.get_prefix ∧
d.to_name.last ∈ ["below", "binduction_on", "brec_on", "cases_on", "dcases_on", "drec_on", "drec",
"rec", "rec_on", "no_confusion", "no_confusion_type", "sizeof", "ibelow", "has_sizeof_inst"]) ∨
d.to_name.has_prefix (λ nm, e.is_ginductive' nm)
/-- Returns the list of universe levels of a declaration. -/
meta def univ_levels (d : declaration) : list level :=
d.univ_params.map level.param
end declaration
|
3816212b3f0cd28916849395a1aad563505d72fe
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/tactic/solve_by_elim.lean
|
01156d5fff9a5cbf330e45dae2cb3c117ecf1894
|
[
"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
| 6,812
|
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.core
namespace tactic
/--
Builds a collection of lemmas for use in the backtracking search in `solve_by_elim`.
* By default, it includes all local hypotheses, along with `rfl`, `trivial`, `congr_fun` and
`congr_arg`.
* The flag `no_dflt` removes these.
* The argument `hs` is a list of `simp_arg_type`s,
and can be used to add, or remove, lemmas or expressions from the set.
* The argument `attr : list name` adds all lemmas tagged with one of a specified list of attributes.
-/
meta def mk_assumption_set (no_dflt : bool) (hs : list simp_arg_type) (attr : list name) :
tactic (list expr) :=
do (hs, gex, hex, all_hyps) ← decode_simp_arg_list hs,
hs ← hs.mmap i_to_expr_for_apply,
l ← attr.mmap $ λ a, attribute.get_instances a,
let l := l.join,
m ← list.mmap mk_const l,
let hs := (hs ++ m).filter $ λ h, expr.const_name h ∉ gex,
hs ← if no_dflt then
return hs
else
do { rfl_const ← mk_const `rfl,
trivial_const ← mk_const `trivial,
congr_fun ← mk_const `congr_fun,
congr_arg ← mk_const `congr_arg,
return (rfl_const :: trivial_const :: congr_fun :: congr_arg :: hs) },
if ¬ no_dflt ∨ all_hyps then do
ctx ← local_context,
return $ hs.append (ctx.filter (λ h, h.local_uniq_name ∉ hex)) -- remove local exceptions
else return hs
/--
The internal implementation of `solve_by_elim`, with a limiting counter.
-/
meta def solve_by_elim_aux (discharger : tactic unit) (lemmas : list expr) : ℕ → tactic unit
| 0 := done
| (n+1) := done <|>
(apply_any lemmas $ solve_by_elim_aux n) <|>
(discharger >> solve_by_elim_aux n)
/--
Configuration options for `solve_by_elim`.
* By default `solve_by_elim` operates only on the first goal,
but with `backtrack_all_goals := true`, it operates on all goals at once,
backtracking across goals as needed,
and only succeeds if it discharges all goals.
* `discharger` specifies an additional tactic to apply on subgoals for which no lemma applies.
If that tactic succeeds, `solve_by_elim` will continue applying lemmas on resulting goals.
* `assumptions` generates the list of lemmas to use in the backtracking search.
* `max_steps` bounds the depth of the search.
-/
meta structure by_elim_opt :=
(backtrack_all_goals : bool := ff)
(discharger : tactic unit := done)
(lemmas : option (list expr) := none)
(max_steps : ℕ := 3)
/--
If no lemmas have been specified, generate the default set
(local hypotheses, along with `rfl`, `trivial`, `congr_arg`, and `congr_fun`).
-/
meta def by_elim_opt.get_lemmas (opt : by_elim_opt) : tactic (list expr) :=
match opt.lemmas with
| none := mk_assumption_set ff [] []
| some lemmas := return lemmas
end
/--
`solve_by_elim` repeatedly tries `apply`ing a lemma
from the list of assumptions (passed via the `by_elim_opt` argument),
recursively operating on any generated subgoals.
It succeeds only if it discharges the first goal
(or with `backtrack_all_goals := tt`, if it discharges all goals.)
If passed an empty list of assumptions, `solve_by_elim` builds a default set
as per the interactive tactic, using the `local_context` along with
`rfl`, `trivial`, `congr_arg`, and `congr_fun`.
-/
meta def solve_by_elim (opt : by_elim_opt := { }) : tactic unit :=
do
tactic.fail_if_no_goals,
lemmas ← opt.get_lemmas,
(if opt.backtrack_all_goals then id else focus1) $
solve_by_elim_aux opt.discharger lemmas opt.max_steps
open interactive lean.parser interactive.types
local postfix `?`:9001 := optional
namespace interactive
/--
`apply_assumption` looks for an assumption of the form `... → ∀ _, ... → head`
where `head` matches the current goal.
If this fails, `apply_assumption` will call `symmetry` and try again.
If this also fails, `apply_assumption` will call `exfalso` and try again,
so that if there is an assumption of the form `P → ¬ Q`, the new tactic state
will have two goals, `P` and `Q`.
Optional arguments:
- `lemmas`: a list of expressions to apply, instead of the local constants
- `tac`: a tactic to run on each subgoal after applying an assumption; if
this tactic fails, the corresponding assumption will be rejected and
the next one will be attempted.
-/
meta def apply_assumption
(lemmas : option (list expr) := none)
(tac : tactic unit := skip) : tactic unit :=
do
lemmas ← match lemmas with
| none := local_context
| some lemmas := return lemmas
end,
tactic.apply_any lemmas tac
add_tactic_doc
{ name := "apply_assumption",
category := doc_category.tactic,
decl_names := [`tactic.interactive.apply_assumption],
tags := ["context management", "lemma application"] }
/--
`solve_by_elim` calls `apply` on the main goal to find an assumption whose head matches
and then repeatedly calls `apply` on the generated subgoals until no subgoals remain,
performing at most `max_steps` recursive steps.
`solve_by_elim` discharges the current goal or fails.
`solve_by_elim` performs back-tracking if subgoals can not be solved.
By default, the assumptions passed to `apply` are the local context, `rfl`, `trivial`,
`congr_fun` and `congr_arg`.
The assumptions can be modified with similar syntax as for `simp`:
* `solve_by_elim [h₁, h₂, ..., hᵣ]` also applies the named lemmas.
* `solve_by_elim with attr₁ ... attrᵣ` also applies all lemmas tagged with the specified attributes.
* `solve_by_elim only [h₁, h₂, ..., hᵣ]` does not include the local context,
`rfl`, `trivial`, `congr_fun`, or `congr_arg` unless they are explicitly included.
* `solve_by_elim [-id_1, ... -id_n]` uses the default assumptions, removing the specified ones.
`solve_by_elim*` tries to solve all goals together, using backtracking if a solution for one goal
makes other goals impossible.
optional arguments passed via a configuration argument:
- discharger: a subsidiary tactic to try at each step when no lemmas apply (e.g. `cc` may be helpful)
- max_steps: number of attempts at discharging generated sub-goals
-/
meta def solve_by_elim (all_goals : parse $ (tk "*")?) (no_dflt : parse only_flag)
(hs : parse simp_arg_list) (attr_names : parse with_ident_list) (opt : by_elim_opt := { }) :
tactic unit :=
do lemmas ← mk_assumption_set no_dflt hs attr_names,
tactic.solve_by_elim
{ backtrack_all_goals := all_goals.is_some ∨ opt.backtrack_all_goals,
lemmas := lemmas,
..opt }
add_tactic_doc
{ name := "solve_by_elim",
category := doc_category.tactic,
decl_names := [`tactic.interactive.solve_by_elim],
tags := ["search"] }
end interactive
end tactic
|
d37b9176b3c69de8779e04e4f2e24175399a4c1a
|
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
|
/tests/lean/run/meta3.lean
|
30183b44d3caaa7bc8442727a533cc6b3bba538e
|
[
"Apache-2.0"
] |
permissive
|
walterhu1015/lean4
|
b2c71b688975177402758924eaa513475ed6ce72
|
2214d81e84646a905d0b20b032c89caf89c737ad
|
refs/heads/master
| 1,671,342,096,906
| 1,599,695,985,000
| 1,599,695,985,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,782
|
lean
|
import Lean.Meta
open Lean
open Lean.Meta
def dbgOpt : Options :=
let opt : Options := {};
let opt := opt.setBool `trace.Meta true;
-- let opt := opt.setBool `trace.Meta.check false;
opt
def print (msg : MessageData) : MetaM Unit :=
trace! `Meta.debug msg
def check (x : MetaM Bool) : MetaM Unit :=
unlessM x $ throwError "check failed"
def getAssignment (m : Expr) : MetaM Expr :=
do v? ← getExprMVarAssignment? m.mvarId!;
match v? with
| some v => pure v
| none => throwError "metavariable is not assigned"
unsafe def run (mods : List Name) (x : MetaM Unit) (opts : Options := dbgOpt) : IO Unit :=
withImportModules (mods.map $ fun m => {module := m}) 0 fun env => do
let x := do { x; printTraces };
_ ← x.toIO { options := opts } { env := env };
pure ()
def nat := mkConst `Nat
def succ := mkConst `Nat.succ
def add := mkAppN (mkConst `HasAdd.add [levelZero]) #[nat, mkConst `Nat.HasAdd]
def tst1 : MetaM Unit :=
do let d : DiscrTree Nat := {};
mvar ← mkFreshExprMVar nat;
d ← d.insert (mkAppN add #[mvar, mkNatLit 10]) 1;
d ← d.insert (mkAppN add #[mkNatLit 0, mkNatLit 10]) 2;
d ← d.insert (mkAppN (mkConst `Nat.add) #[mkNatLit 0, mkNatLit 20]) 3;
d ← d.insert (mkAppN add #[mvar, mkNatLit 20]) 4;
d ← d.insert mvar 5;
print (format d);
vs ← d.getMatch (mkAppN add #[mkNatLit 1, mkNatLit 10]);
print (format vs);
let t := mkAppN add #[mvar, mvar];
print t;
vs ← d.getMatch t;
print (format vs);
vs ← d.getUnify t;
print (format vs);
vs ← d.getUnify mvar;
print (format vs);
vs ← d.getUnify $ mkAppN add #[mkNatLit 0, mvar];
print (format vs);
vs ← d.getUnify $ mkAppN add #[mvar, mkNatLit 20];
print (format vs);
pure ()
#eval run [`Init.Data.Nat] tst1
|
b57feac56e1371829a2f4e401b1fef896f0857c3
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/archive/100-theorems-list/83_friendship_graphs.lean
|
f0e9917d046d0cee4441459797f490d5b60ce360
|
[
"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
| 13,773
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller
-/
import combinatorics.simple_graph.adj_matrix
import linear_algebra.char_poly.coeff
import data.int.modeq
import data.zmod.basic
import tactic.interval_cases
/-!
# The Friendship Theorem
## Definitions and Statement
- A `friendship` graph is one in which any two distinct vertices have exactly one neighbor in common
- A `politician`, at least in the context of this problem, is a vertex in a graph which is adjacent
to every other vertex.
- The friendship theorem (Erdős, Rényi, Sós 1966) states that every finite friendship graph has a
politician.
## Proof outline
The proof revolves around the theory of adjacency matrices, although some steps could equivalently
be phrased in terms of counting walks.
- Assume `G` is a finite friendship graph.
- First we show that any two nonadjacent vertices have the same degree
- Assume for contradiction that `G` does not have a politician.
- Conclude from the last two points that `G` is `d`-regular for some `d : ℕ`.
- Show that `G` has `d ^ 2 - d + 1` vertices.
- By casework, show that if `d = 0, 1, 2`, then `G` has a politician.
- If `3 ≤ d`, let `p` be a prime factor of `d - 1`.
- If `A` is the adjacency matrix of `G` with entries in `ℤ/pℤ`, we show that `A ^ p` has trace `1`.
- This gives a contradiction, as `A` has trace `0`, and thus `A ^ p` has trace `0`.
## References
- [P. Erdős, A. Rényi, V. Sós, *On A Problem of Graph Theory*][erdosrenyisos]
- [C. Huneke, *The Friendship Theorem*][huneke2002]
-/
open_locale classical big_operators
noncomputable theory
open finset simple_graph matrix
universes u v
variables {V : Type u} {R : Type v} [semiring R]
section friendship_def
variables (G : simple_graph V)
/--
This property of a graph is the hypothesis of the friendship theorem:
every pair of nonadjacent vertices has exactly one common friend,
a vertex to which both are adjacent.
-/
def friendship [fintype V] : Prop := ∀ ⦃v w : V⦄, v ≠ w → fintype.card (G.common_neighbors v w) = 1
/--
A politician is a vertex that is adjacent to all other vertices.
-/
def exists_politician : Prop := ∃ (v : V), ∀ (w : V), v ≠ w → G.adj v w
end friendship_def
variables [fintype V] {G : simple_graph V} {d : ℕ} (hG : friendship G)
include hG
namespace friendship
variables (R)
/-- One characterization of a friendship graph is that there is exactly one walk of length 2
between distinct vertices. These walks are counted in off-diagonal entries of the square of
the adjacency matrix, so for a friendship graph, those entries are all 1. -/
theorem adj_matrix_sq_of_ne {v w : V} (hvw : v ≠ w) :
((G.adj_matrix R) ^ 2) v w = 1 :=
begin
rw [sq, ← nat.cast_one, ← hG hvw],
simp [common_neighbors, neighbor_finset_eq_filter, finset.filter_filter, finset.filter_inter,
and_comm],
end
/-- This calculation amounts to counting the number of length 3 walks between nonadjacent vertices.
We use it to show that nonadjacent vertices have equal degrees. -/
lemma adj_matrix_pow_three_of_not_adj {v w : V} (non_adj : ¬ G.adj v w) :
((G.adj_matrix R) ^ 3) v w = degree G v :=
begin
rw [pow_succ, mul_eq_mul, adj_matrix_mul_apply, degree, card_eq_sum_ones, nat.cast_sum],
apply sum_congr rfl,
intros x hx,
rw [adj_matrix_sq_of_ne _ hG, nat.cast_one],
rintro ⟨rfl⟩,
rw mem_neighbor_finset at hx,
exact non_adj hx,
end
variable {R}
/-- As `v` and `w` not being adjacent implies
`degree G v = ((G.adj_matrix R) ^ 3) v w` and `degree G w = ((G.adj_matrix R) ^ 3) v w`,
the degrees are equal if `((G.adj_matrix R) ^ 3) v w = ((G.adj_matrix R) ^ 3) w v`
This is true as the adjacency matrix is symmetric. -/
lemma degree_eq_of_not_adj {v w : V} (hvw : ¬ G.adj v w) :
degree G v = degree G w :=
begin
rw [← nat.cast_id (G.degree v), ← nat.cast_id (G.degree w),
← adj_matrix_pow_three_of_not_adj ℕ hG hvw,
← adj_matrix_pow_three_of_not_adj ℕ hG (λ h, hvw (G.symm h))],
conv_lhs {rw ← transpose_adj_matrix},
simp only [pow_succ, sq, mul_eq_mul, ← transpose_mul, transpose_apply],
simp only [← mul_eq_mul, mul_assoc],
end
/-- Let `A` be the adjacency matrix of a graph `G`.
If `G` is a friendship graph, then all of the off-diagonal entries of `A^2` are 1.
If `G` is `d`-regular, then all of the diagonal entries of `A^2` are `d`.
Putting these together determines `A^2` exactly for a `d`-regular friendship graph. -/
theorem adj_matrix_sq_of_regular (hd : G.is_regular_of_degree d) :
((G.adj_matrix R) ^ 2) = λ v w, if v = w then d else 1 :=
begin
ext v w, by_cases h : v = w,
{ rw [h, sq, mul_eq_mul, adj_matrix_mul_self_apply_self, hd], simp, },
{ rw [adj_matrix_sq_of_ne R hG h, if_neg h], },
end
lemma adj_matrix_sq_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) ^ 2 = λ _ _, 1 :=
by simp [adj_matrix_sq_of_regular hG hd, dmod]
section nonempty
variable [nonempty V]
/-- If `G` is a friendship graph without a politician (a vertex adjacent to all others), then
it is regular. We have shown that nonadjacent vertices of a friendship graph have the same degree,
and if there isn't a politician, we can show this for adjacent vertices by finding a vertex
neither is adjacent to, and then using transitivity. -/
theorem is_regular_of_not_exists_politician (hG' : ¬exists_politician G) :
∃ (d : ℕ), G.is_regular_of_degree d :=
begin
have v := classical.arbitrary V,
use G.degree v,
intro x,
by_cases hvx : G.adj v x, swap, { exact (degree_eq_of_not_adj hG hvx).symm, },
dunfold exists_politician at hG',
push_neg at hG',
rcases hG' v with ⟨w, hvw', hvw⟩,
rcases hG' x with ⟨y, hxy', hxy⟩,
by_cases hxw : G.adj x w,
swap, { rw degree_eq_of_not_adj hG hvw, exact degree_eq_of_not_adj hG hxw },
rw degree_eq_of_not_adj hG hxy,
by_cases hvy : G.adj v y,
swap, { exact (degree_eq_of_not_adj hG hvy).symm },
rw degree_eq_of_not_adj hG hvw,
apply degree_eq_of_not_adj hG,
intro hcontra,
rcases finset.card_eq_one.mp (hG hvw') with ⟨⟨a, ha⟩, h⟩,
have key : ∀ {x}, x ∈ G.common_neighbors v w → x = a,
{ intros x hx,
have h' := mem_univ (subtype.mk x hx),
rw [h, mem_singleton] at h',
injection h', },
apply hxy',
rw [key ((mem_common_neighbors G).mpr ⟨hvx, G.symm hxw⟩),
key ((mem_common_neighbors G).mpr ⟨hvy, G.symm hcontra⟩)],
end
/-- Let `A` be the adjacency matrix of a `d`-regular friendship graph, and let `v` be a vector
all of whose components are `1`. Then `v` is an eigenvector of `A ^ 2`, and we can compute
the eigenvalue to be `d * d`, or as `d + (fintype.card V - 1)`, so those quantities must be equal.
This essentially means that the graph has `d ^ 2 - d + 1` vertices. -/
lemma card_of_regular (hd : G.is_regular_of_degree d) :
d + (fintype.card V - 1) = d * d :=
begin
have v := classical.arbitrary V,
transitivity ((G.adj_matrix ℕ) ^ 2).mul_vec (λ _, 1) v,
{ rw [adj_matrix_sq_of_regular hG hd, mul_vec, dot_product, ← insert_erase (mem_univ v)],
simp only [sum_insert, mul_one, if_true, nat.cast_id, eq_self_iff_true,
mem_erase, not_true, ne.def, not_false_iff, add_right_inj, false_and],
rw [finset.sum_const_nat, card_erase_of_mem (mem_univ v), mul_one], { refl },
intros x hx, simp [(ne_of_mem_erase hx).symm], },
{ rw [sq, mul_eq_mul, ← mul_vec_mul_vec],
simp [adj_matrix_mul_vec_const_apply_of_regular hd, neighbor_finset,
card_neighbor_set_eq_degree, hd v], }
end
/-- The size of a `d`-regular friendship graph is `1 mod (d-1)`, and thus `1 mod p` for a
factor `p ∣ d-1`. -/
lemma card_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1) (hd : G.is_regular_of_degree d) :
(fintype.card V : zmod p) = 1 :=
begin
have hpos : 0 < fintype.card V := fintype.card_pos_iff.mpr infer_instance,
rw [← nat.succ_pred_eq_of_pos hpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
have h := congr_arg (λ n, (↑n : zmod p)) (card_of_regular hG hd),
revert h, simp [dmod],
end
end nonempty
omit hG
lemma adj_matrix_sq_mul_const_one_of_regular (hd : G.is_regular_of_degree d) :
(G.adj_matrix R) * (λ _ _, 1) = λ _ _, d :=
by { ext x, simp [← hd x, degree] }
lemma adj_matrix_mul_const_one_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) * (λ _ _, 1) = λ _ _, 1 :=
by rw [adj_matrix_sq_mul_const_one_of_regular hd, dmod]
include hG
/-- Modulo a factor of `d-1`, the square and all higher powers of the adjacency matrix
of a `d`-regular friendship graph reduce to the matrix whose entries are all 1. -/
lemma adj_matrix_pow_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) {k : ℕ} (hk : 2 ≤ k) :
(G.adj_matrix (zmod p)) ^ k = λ _ _, 1 :=
begin
iterate 2 {cases k with k, { exfalso, linarith, }, },
induction k with k hind,
{ exact adj_matrix_sq_mod_p_of_regular hG dmod hd, },
rw [pow_succ, hind (nat.le_add_left 2 k)],
exact adj_matrix_mul_const_one_mod_p_of_regular dmod hd,
end
variable [nonempty V]
/-- This is the main proof. Assuming that `3 ≤ d`, we take `p` to be a prime factor of `d-1`.
Then the `p`th power of the adjacency matrix of a `d`-regular friendship graph must have trace 1
mod `p`, but we can also show that the trace must be the `p`th power of the trace of the original
adjacency matrix, which is 0, a contradiction.
-/
lemma false_of_three_le_degree (hd : G.is_regular_of_degree d) (h : 3 ≤ d) : false :=
begin
-- get a prime factor of d - 1
let p : ℕ := (d - 1).min_fac,
have p_dvd_d_pred := (zmod.nat_coe_zmod_eq_zero_iff_dvd _ _).mpr (d - 1).min_fac_dvd,
have dpos : 0 < d := by linarith,
have d_cast : ↑(d - 1) = (d : ℤ) - 1 := by norm_cast,
haveI : fact p.prime := ⟨nat.min_fac_prime (by linarith)⟩,
have hp2 : 2 ≤ p := (fact.out p.prime).two_le,
have dmod : (d : zmod p) = 1,
{ rw [← nat.succ_pred_eq_of_pos dpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
exact p_dvd_d_pred, },
have Vmod := card_mod_p_of_regular hG dmod hd,
-- now we reduce to a trace calculation
have := zmod.trace_pow_card (G.adj_matrix (zmod p)),
contrapose! this, clear this,
-- the trace is 0 mod p when computed one way
rw [trace_adj_matrix, zero_pow (fact.out p.prime).pos],
-- but the trace is 1 mod p when computed the other way
rw adj_matrix_pow_mod_p_of_regular hG dmod hd hp2,
dunfold fintype.card at Vmod,
simp only [matrix.trace, diag_apply, mul_one, nsmul_eq_mul, linear_map.coe_mk, sum_const],
rw [Vmod, ← nat.cast_one, zmod.nat_coe_zmod_eq_zero_iff_dvd, nat.dvd_one,
nat.min_fac_eq_one_iff],
linarith,
end
/-- If `d ≤ 1`, a `d`-regular friendship graph has at most one vertex, which is
trivially a politician. -/
lemma exists_politician_of_degree_le_one (hd : G.is_regular_of_degree d) (hd1 : d ≤ 1) :
exists_politician G :=
begin
have sq : d * d = d := by { interval_cases d; norm_num },
have h := card_of_regular hG hd,
rw sq at h,
have : fintype.card V ≤ 1,
{ cases fintype.card V with n,
{ exact zero_le _, },
{ have : n = 0,
{ rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at h,
linarith },
subst n, } },
use classical.arbitrary V,
intros w h, exfalso,
apply h,
apply fintype.card_le_one_iff.mp this,
end
/-- If `d = 2`, a `d`-regular friendship graph has 3 vertices, so it must be complete graph,
and all the vertices are politicians. -/
lemma neighbor_finset_eq_of_degree_eq_two (hd : G.is_regular_of_degree 2) (v : V) :
G.neighbor_finset v = finset.univ.erase v :=
begin
apply finset.eq_of_subset_of_card_le,
{ rw finset.subset_iff,
intro x,
rw [mem_neighbor_finset, finset.mem_erase],
exact λ h, ⟨(G.ne_of_adj h).symm, finset.mem_univ _⟩ },
convert_to 2 ≤ _,
{ convert_to _ = fintype.card V - 1,
{ have hfr:= card_of_regular hG hd,
linarith },
{ exact finset.card_erase_of_mem (finset.mem_univ _), }, },
{ dsimp [is_regular_of_degree, degree] at hd,
rw hd, }
end
lemma exists_politician_of_degree_eq_two (hd : G.is_regular_of_degree 2) :
exists_politician G :=
begin
have v := classical.arbitrary V,
use v,
intros w hvw,
rw [← mem_neighbor_finset, neighbor_finset_eq_of_degree_eq_two hG hd v, finset.mem_erase],
exact ⟨hvw.symm, finset.mem_univ _⟩,
end
lemma exists_politician_of_degree_le_two (hd : G.is_regular_of_degree d) (h : d ≤ 2) :
exists_politician G :=
begin
interval_cases d,
iterate 2 { apply exists_politician_of_degree_le_one hG hd, norm_num },
{ exact exists_politician_of_degree_eq_two hG hd },
end
end friendship
/-- **Friendship theorem**: We wish to show that a friendship graph has a politician (a vertex
adjacent to all others). We proceed by contradiction, and assume the graph has no politician.
We have already proven that a friendship graph with no politician is `d`-regular for some `d`,
and now we do casework on `d`.
If the degree is at most 2, we observe by casework that it has a politician anyway.
If the degree is at least 3, the graph cannot exist. -/
theorem friendship_theorem [nonempty V] : exists_politician G :=
begin
by_contradiction npG,
rcases hG.is_regular_of_not_exists_politician npG with ⟨d, dreg⟩,
cases lt_or_le d 3 with dle2 dge3,
{ exact npG (hG.exists_politician_of_degree_le_two dreg (nat.lt_succ_iff.mp dle2)) },
{ exact hG.false_of_three_le_degree dreg dge3 },
end
|
6f69af34e1870caba64ac792a0eade3c392afc37
|
592ee40978ac7604005a4e0d35bbc4b467389241
|
/Library/generated/mathscheme-lean/MoufangLoop.lean
|
1e58d9b5d7c51f94f5885e8f8397bdceb3a6ff8b
|
[] |
no_license
|
ysharoda/Deriving-Definitions
|
3e149e6641fae440badd35ac110a0bd705a49ad2
|
dfecb27572022de3d4aa702cae8db19957523a59
|
refs/heads/master
| 1,679,127,857,700
| 1,615,939,007,000
| 1,615,939,007,000
| 229,785,731
| 4
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 13,429
|
lean
|
import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section MoufangLoop
structure MoufangLoop (A : Type) : Type :=
(op : (A → (A → A)))
(e : A)
(lunit_e : (∀ {x : A} , (op e x) = x))
(runit_e : (∀ {x : A} , (op x e) = x))
(linv : (A → (A → A)))
(leftCancel : (∀ {x y : A} , (op x (linv x y)) = y))
(lefCancelOp : (∀ {x y : A} , (linv x (op x y)) = y))
(rinv : (A → (A → A)))
(rightCancel : (∀ {x y : A} , (op (rinv y x) x) = y))
(rightCancelOp : (∀ {x y : A} , (rinv (op y x) x) = y))
(moufangId : (∀ {x y z : A} , (op (op z x) (op y z)) = (op (op z (op x y)) z)))
open MoufangLoop
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
(eS : AS)
(linvS : (AS → (AS → AS)))
(rinvS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(eP : (Prod A A))
(linvP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(rinvP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(lunit_eP : (∀ {xP : (Prod A A)} , (opP eP xP) = xP))
(runit_eP : (∀ {xP : (Prod A A)} , (opP xP eP) = xP))
(leftCancelP : (∀ {xP yP : (Prod A A)} , (opP xP (linvP xP yP)) = yP))
(lefCancelOpP : (∀ {xP yP : (Prod A A)} , (linvP xP (opP xP yP)) = yP))
(rightCancelP : (∀ {xP yP : (Prod A A)} , (opP (rinvP yP xP) xP) = yP))
(rightCancelOpP : (∀ {xP yP : (Prod A A)} , (rinvP (opP yP xP) xP) = yP))
(moufangIdP : (∀ {xP yP zP : (Prod A A)} , (opP (opP zP xP) (opP yP zP)) = (opP (opP zP (opP xP yP)) zP)))
structure Hom {A1 : Type} {A2 : Type} (Mo1 : (MoufangLoop A1)) (Mo2 : (MoufangLoop A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Mo1) x1 x2)) = ((op Mo2) (hom x1) (hom x2))))
(pres_e : (hom (e Mo1)) = (e Mo2))
(pres_linv : (∀ {x1 x2 : A1} , (hom ((linv Mo1) x1 x2)) = ((linv Mo2) (hom x1) (hom x2))))
(pres_rinv : (∀ {x1 x2 : A1} , (hom ((rinv Mo1) x1 x2)) = ((rinv Mo2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Mo1 : (MoufangLoop A1)) (Mo2 : (MoufangLoop A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Mo1) x1 x2) ((op Mo2) y1 y2))))))
(interp_e : (interp (e Mo1) (e Mo2)))
(interp_linv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((linv Mo1) x1 x2) ((linv Mo2) y1 y2))))))
(interp_rinv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((rinv Mo1) x1 x2) ((rinv Mo2) y1 y2))))))
inductive MoufangLoopLTerm : Type
| opL : (MoufangLoopLTerm → (MoufangLoopLTerm → MoufangLoopLTerm))
| eL : MoufangLoopLTerm
| linvL : (MoufangLoopLTerm → (MoufangLoopLTerm → MoufangLoopLTerm))
| rinvL : (MoufangLoopLTerm → (MoufangLoopLTerm → MoufangLoopLTerm))
open MoufangLoopLTerm
inductive ClMoufangLoopClTerm (A : Type) : Type
| sing : (A → ClMoufangLoopClTerm)
| opCl : (ClMoufangLoopClTerm → (ClMoufangLoopClTerm → ClMoufangLoopClTerm))
| eCl : ClMoufangLoopClTerm
| linvCl : (ClMoufangLoopClTerm → (ClMoufangLoopClTerm → ClMoufangLoopClTerm))
| rinvCl : (ClMoufangLoopClTerm → (ClMoufangLoopClTerm → ClMoufangLoopClTerm))
open ClMoufangLoopClTerm
inductive OpMoufangLoopOLTerm (n : ℕ) : Type
| v : ((fin n) → OpMoufangLoopOLTerm)
| opOL : (OpMoufangLoopOLTerm → (OpMoufangLoopOLTerm → OpMoufangLoopOLTerm))
| eOL : OpMoufangLoopOLTerm
| linvOL : (OpMoufangLoopOLTerm → (OpMoufangLoopOLTerm → OpMoufangLoopOLTerm))
| rinvOL : (OpMoufangLoopOLTerm → (OpMoufangLoopOLTerm → OpMoufangLoopOLTerm))
open OpMoufangLoopOLTerm
inductive OpMoufangLoopOL2Term2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpMoufangLoopOL2Term2)
| sing2 : (A → OpMoufangLoopOL2Term2)
| opOL2 : (OpMoufangLoopOL2Term2 → (OpMoufangLoopOL2Term2 → OpMoufangLoopOL2Term2))
| eOL2 : OpMoufangLoopOL2Term2
| linvOL2 : (OpMoufangLoopOL2Term2 → (OpMoufangLoopOL2Term2 → OpMoufangLoopOL2Term2))
| rinvOL2 : (OpMoufangLoopOL2Term2 → (OpMoufangLoopOL2Term2 → OpMoufangLoopOL2Term2))
open OpMoufangLoopOL2Term2
def simplifyCl {A : Type} : ((ClMoufangLoopClTerm A) → (ClMoufangLoopClTerm A))
| (opCl eCl x) := x
| (opCl x eCl) := x
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| eCl := eCl
| (linvCl x1 x2) := (linvCl (simplifyCl x1) (simplifyCl x2))
| (rinvCl x1 x2) := (rinvCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpMoufangLoopOLTerm n) → (OpMoufangLoopOLTerm n))
| (opOL eOL x) := x
| (opOL x eOL) := x
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| eOL := eOL
| (linvOL x1 x2) := (linvOL (simplifyOpB x1) (simplifyOpB x2))
| (rinvOL x1 x2) := (rinvOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpMoufangLoopOL2Term2 n A) → (OpMoufangLoopOL2Term2 n A))
| (opOL2 eOL2 x) := x
| (opOL2 x eOL2) := x
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| eOL2 := eOL2
| (linvOL2 x1 x2) := (linvOL2 (simplifyOp x1) (simplifyOp x2))
| (rinvOL2 x1 x2) := (rinvOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((MoufangLoop A) → (MoufangLoopLTerm → A))
| Mo (opL x1 x2) := ((op Mo) (evalB Mo x1) (evalB Mo x2))
| Mo eL := (e Mo)
| Mo (linvL x1 x2) := ((linv Mo) (evalB Mo x1) (evalB Mo x2))
| Mo (rinvL x1 x2) := ((rinv Mo) (evalB Mo x1) (evalB Mo x2))
def evalCl {A : Type} : ((MoufangLoop A) → ((ClMoufangLoopClTerm A) → A))
| Mo (sing x1) := x1
| Mo (opCl x1 x2) := ((op Mo) (evalCl Mo x1) (evalCl Mo x2))
| Mo eCl := (e Mo)
| Mo (linvCl x1 x2) := ((linv Mo) (evalCl Mo x1) (evalCl Mo x2))
| Mo (rinvCl x1 x2) := ((rinv Mo) (evalCl Mo x1) (evalCl Mo x2))
def evalOpB {A : Type} {n : ℕ} : ((MoufangLoop A) → ((vector A n) → ((OpMoufangLoopOLTerm n) → A)))
| Mo vars (v x1) := (nth vars x1)
| Mo vars (opOL x1 x2) := ((op Mo) (evalOpB Mo vars x1) (evalOpB Mo vars x2))
| Mo vars eOL := (e Mo)
| Mo vars (linvOL x1 x2) := ((linv Mo) (evalOpB Mo vars x1) (evalOpB Mo vars x2))
| Mo vars (rinvOL x1 x2) := ((rinv Mo) (evalOpB Mo vars x1) (evalOpB Mo vars x2))
def evalOp {A : Type} {n : ℕ} : ((MoufangLoop A) → ((vector A n) → ((OpMoufangLoopOL2Term2 n A) → A)))
| Mo vars (v2 x1) := (nth vars x1)
| Mo vars (sing2 x1) := x1
| Mo vars (opOL2 x1 x2) := ((op Mo) (evalOp Mo vars x1) (evalOp Mo vars x2))
| Mo vars eOL2 := (e Mo)
| Mo vars (linvOL2 x1 x2) := ((linv Mo) (evalOp Mo vars x1) (evalOp Mo vars x2))
| Mo vars (rinvOL2 x1 x2) := ((rinv Mo) (evalOp Mo vars x1) (evalOp Mo vars x2))
def inductionB {P : (MoufangLoopLTerm → Type)} : ((∀ (x1 x2 : MoufangLoopLTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → ((P eL) → ((∀ (x1 x2 : MoufangLoopLTerm) , ((P x1) → ((P x2) → (P (linvL x1 x2))))) → ((∀ (x1 x2 : MoufangLoopLTerm) , ((P x1) → ((P x2) → (P (rinvL x1 x2))))) → (∀ (x : MoufangLoopLTerm) , (P x))))))
| popl pel plinvl prinvl (opL x1 x2) := (popl _ _ (inductionB popl pel plinvl prinvl x1) (inductionB popl pel plinvl prinvl x2))
| popl pel plinvl prinvl eL := pel
| popl pel plinvl prinvl (linvL x1 x2) := (plinvl _ _ (inductionB popl pel plinvl prinvl x1) (inductionB popl pel plinvl prinvl x2))
| popl pel plinvl prinvl (rinvL x1 x2) := (prinvl _ _ (inductionB popl pel plinvl prinvl x1) (inductionB popl pel plinvl prinvl x2))
def inductionCl {A : Type} {P : ((ClMoufangLoopClTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClMoufangLoopClTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → ((P eCl) → ((∀ (x1 x2 : (ClMoufangLoopClTerm A)) , ((P x1) → ((P x2) → (P (linvCl x1 x2))))) → ((∀ (x1 x2 : (ClMoufangLoopClTerm A)) , ((P x1) → ((P x2) → (P (rinvCl x1 x2))))) → (∀ (x : (ClMoufangLoopClTerm A)) , (P x)))))))
| psing popcl pecl plinvcl prinvcl (sing x1) := (psing x1)
| psing popcl pecl plinvcl prinvcl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl pecl plinvcl prinvcl x1) (inductionCl psing popcl pecl plinvcl prinvcl x2))
| psing popcl pecl plinvcl prinvcl eCl := pecl
| psing popcl pecl plinvcl prinvcl (linvCl x1 x2) := (plinvcl _ _ (inductionCl psing popcl pecl plinvcl prinvcl x1) (inductionCl psing popcl pecl plinvcl prinvcl x2))
| psing popcl pecl plinvcl prinvcl (rinvCl x1 x2) := (prinvcl _ _ (inductionCl psing popcl pecl plinvcl prinvcl x1) (inductionCl psing popcl pecl plinvcl prinvcl x2))
def inductionOpB {n : ℕ} {P : ((OpMoufangLoopOLTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpMoufangLoopOLTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → ((P eOL) → ((∀ (x1 x2 : (OpMoufangLoopOLTerm n)) , ((P x1) → ((P x2) → (P (linvOL x1 x2))))) → ((∀ (x1 x2 : (OpMoufangLoopOLTerm n)) , ((P x1) → ((P x2) → (P (rinvOL x1 x2))))) → (∀ (x : (OpMoufangLoopOLTerm n)) , (P x)))))))
| pv popol peol plinvol prinvol (v x1) := (pv x1)
| pv popol peol plinvol prinvol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol peol plinvol prinvol x1) (inductionOpB pv popol peol plinvol prinvol x2))
| pv popol peol plinvol prinvol eOL := peol
| pv popol peol plinvol prinvol (linvOL x1 x2) := (plinvol _ _ (inductionOpB pv popol peol plinvol prinvol x1) (inductionOpB pv popol peol plinvol prinvol x2))
| pv popol peol plinvol prinvol (rinvOL x1 x2) := (prinvol _ _ (inductionOpB pv popol peol plinvol prinvol x1) (inductionOpB pv popol peol plinvol prinvol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpMoufangLoopOL2Term2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpMoufangLoopOL2Term2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → ((P eOL2) → ((∀ (x1 x2 : (OpMoufangLoopOL2Term2 n A)) , ((P x1) → ((P x2) → (P (linvOL2 x1 x2))))) → ((∀ (x1 x2 : (OpMoufangLoopOL2Term2 n A)) , ((P x1) → ((P x2) → (P (rinvOL2 x1 x2))))) → (∀ (x : (OpMoufangLoopOL2Term2 n A)) , (P x))))))))
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x1) (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x2))
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 eOL2 := peol2
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 (linvOL2 x1 x2) := (plinvol2 _ _ (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x1) (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x2))
| pv2 psing2 popol2 peol2 plinvol2 prinvol2 (rinvOL2 x1 x2) := (prinvol2 _ _ (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x1) (inductionOp pv2 psing2 popol2 peol2 plinvol2 prinvol2 x2))
def stageB : (MoufangLoopLTerm → (Staged MoufangLoopLTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
| eL := (Now eL)
| (linvL x1 x2) := (stage2 linvL (codeLift2 linvL) (stageB x1) (stageB x2))
| (rinvL x1 x2) := (stage2 rinvL (codeLift2 rinvL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClMoufangLoopClTerm A) → (Staged (ClMoufangLoopClTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
| eCl := (Now eCl)
| (linvCl x1 x2) := (stage2 linvCl (codeLift2 linvCl) (stageCl x1) (stageCl x2))
| (rinvCl x1 x2) := (stage2 rinvCl (codeLift2 rinvCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpMoufangLoopOLTerm n) → (Staged (OpMoufangLoopOLTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
| eOL := (Now eOL)
| (linvOL x1 x2) := (stage2 linvOL (codeLift2 linvOL) (stageOpB x1) (stageOpB x2))
| (rinvOL x1 x2) := (stage2 rinvOL (codeLift2 rinvOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpMoufangLoopOL2Term2 n A) → (Staged (OpMoufangLoopOL2Term2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
| eOL2 := (Now eOL2)
| (linvOL2 x1 x2) := (stage2 linvOL2 (codeLift2 linvOL2) (stageOp x1) (stageOp x2))
| (rinvOL2 x1 x2) := (stage2 rinvOL2 (codeLift2 rinvOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
(eT : (Repr A))
(linvT : ((Repr A) → ((Repr A) → (Repr A))))
(rinvT : ((Repr A) → ((Repr A) → (Repr A))))
end MoufangLoop
|
c1c41306cdc6b4fb22ba80a948723603c51d8f65
|
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
|
/src/topology/metric_space/basic.lean
|
623643ba4c29e760365e483f7e74c70b39588ba3
|
[
"Apache-2.0"
] |
permissive
|
anthony2698/mathlib
|
03cd69fe5c280b0916f6df2d07c614c8e1efe890
|
407615e05814e98b24b2ff322b14e8e3eb5e5d67
|
refs/heads/master
| 1,678,792,774,873
| 1,614,371,563,000
| 1,614,371,563,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 77,017
|
lean
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Metric spaces.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
topological spaces. For example:
open and closed sets, compactness, completeness, continuity and uniform continuity
-/
import topology.metric_space.emetric_space
import topology.algebra.ordered
import data.fintype.intervals
open set filter classical topological_space
noncomputable theory
open_locale uniformity topological_space big_operators filter nnreal ennreal
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Construct a uniform structure from a distance function and metric space axioms -/
def uniform_space_of_dist
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
uniform_space.of_core {
uniformity := (⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
comp := le_infi $ assume ε, le_infi $ assume h, lift'_le
(mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos h zero_lt_two) (subset.refl _)) $
have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
from assume a b c hac hcb,
calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
... < ε / 2 + ε / 2 : add_lt_add hac hcb
... = ε : by rw [div_add_div_same, add_self_div_two],
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 [dist_comm] }
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
class has_dist (α : Type*) := (dist : α → α → ℝ)
export has_dist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- Metric space
Each metric 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 `metric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. In the same way, each metric space induces an emetric space structure.
It is included in the structure, but filled in by default.
-/
class metric_space (α : Type u) extends has_dist α : Type u :=
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(edist : α → α → ℝ≥0∞ := λx y, ennreal.of_real (dist x y))
(edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)
(to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)
(uniformity_dist : 𝓤 α = ⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
variables [metric_space α]
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_uniform_space' : uniform_space α :=
metric_space.to_uniform_space
@[priority 200] -- see Note [lower instance priority]
instance metric_space.to_has_edist : has_edist α := ⟨metric_space.edist⟩
@[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x
theorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=
metric_space.eq_of_dist_eq_zero
theorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y
theorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=
metric_space.edist_dist x y
@[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
@[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=
by rw [eq_comm, dist_eq_zero]
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
metric_space.dist_triangle x y z
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
by rw dist_comm z; apply dist_triangle
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
by rw dist_comm y; apply dist_triangle
lemma dist_triangle4 (x y z w : α) :
dist x w ≤ dist x y + dist y z + dist z w :=
calc dist x w ≤ dist x z + dist z w : dist_triangle x z w
... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (dist_triangle x y z) _
lemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
by { rw [add_left_comm, dist_comm x₁, ← add_assoc], apply dist_triangle4 }
lemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
by { rw [add_right_comm, dist_comm y₁], apply dist_triangle4 }
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, dist (f i) (f (i + 1)) :=
begin
revert n,
apply nat.le_induction,
{ simp only [finset.sum_empty, finset.Ico.self_eq_empty, dist_self] },
{ assume n hn hrec,
calc dist (f m) (f (n+1)) ≤ dist (f m) (f n) + dist _ _ : dist_triangle _ _ _
... ≤ ∑ i in finset.Ico m n, _ + _ : add_le_add hrec (le_refl _)
... = ∑ i in finset.Ico m (n+1), _ :
by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, dist (f i) (f (i + 1)) :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n)
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
{d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, d i :=
le_trans (dist_le_Ico_sum_dist f hmn) $
finset.sum_le_sum $ λ k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ)
{d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, d i :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) (λ _ _, hd)
theorem swap_dist : function.swap (@dist α _) = dist :=
by funext x y; exact dist_comm _ _
theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
have 2 * dist x y ≥ 0,
from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
nonneg_of_mul_nonneg_left this zero_lt_two
@[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=
by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
@[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=
by simpa only [not_le] using not_congr dist_le_zero
@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
abs_of_nonneg dist_nonneg
theorem eq_of_forall_dist_le {x y : α} (h : ∀ ε > 0, dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
/-- Distance as a nonnegative real number. -/
def nndist (a b : α) : ℝ≥0 := ⟨dist a b, dist_nonneg⟩
/--Express `nndist` in terms of `edist`-/
lemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=
by simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]
/--Express `edist` in terms of `nndist`-/
lemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=
by { rw [edist_dist, nndist, ennreal.of_real_eq_coe_nnreal] }
@[simp, norm_cast] lemma ennreal_coe_nndist (x y : α) : ↑(nndist x y) = edist x y :=
(edist_nndist x y).symm
@[simp, norm_cast] lemma edist_lt_coe {x y : α} {c : ℝ≥0} :
edist x y < c ↔ nndist x y < c :=
by rw [edist_nndist, ennreal.coe_lt_coe]
@[simp, norm_cast] lemma edist_le_coe {x y : α} {c : ℝ≥0} :
edist x y ≤ c ↔ nndist x y ≤ c :=
by rw [edist_nndist, ennreal.coe_le_coe]
/--In a metric space, the extended distance is always finite-/
lemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
by rw [edist_dist x y]; apply ennreal.coe_ne_top
/--In a metric space, the extended distance is always finite-/
lemma edist_lt_top {α : Type*} [metric_space α] (x y : α) : edist x y < ⊤ :=
ennreal.lt_top_iff_ne_top.2 (edist_ne_top x y)
/--`nndist x x` vanishes-/
@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
/--Express `dist` in terms of `nndist`-/
lemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl
@[simp, norm_cast] lemma coe_nndist (x y : α) : ↑(nndist x y) = dist x y :=
(dist_nndist x y).symm
@[simp, norm_cast] lemma dist_lt_coe {x y : α} {c : ℝ≥0} :
dist x y < c ↔ nndist x y < c :=
iff.rfl
@[simp, norm_cast] lemma dist_le_coe {x y : α} {c : ℝ≥0} :
dist x y ≤ c ↔ nndist x y ≤ c :=
iff.rfl
/--Express `nndist` in terms of `dist`-/
lemma nndist_dist (x y : α) : nndist x y = nnreal.of_real (dist x y) :=
by rw [dist_nndist, nnreal.of_real_coe]
/--Deduce the equality of points with the vanishing of the nonnegative distance-/
theorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
by simpa only [dist_nndist, nnreal.coe_eq] using dist_comm x y
/--Characterize the equality of points with the vanishing of the nonnegative distance-/
@[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
@[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, zero_eq_dist]
/--Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
dist_triangle _ _ _
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
dist_triangle_left _ _ _
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
dist_triangle_right _ _ _
/--Express `dist` in terms of `edist`-/
lemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=
by rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]
namespace metric
/- instantiate metric space as a topology -/
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
@[simp] lemma nonempty_ball (h : 0 < ε) : (ball x ε).nonempty :=
⟨x, by simp [h]⟩
lemma ball_eq_ball (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.2 p.1 < ε} = metric.ball x ε := rfl
lemma ball_eq_ball' (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.1 p.2 < ε} = metric.ball x ε :=
by { ext, simp [dist_comm, uniform_space.ball] }
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) := {y | dist y x = ε}
@[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := iff.rfl
theorem mem_closed_ball' : y ∈ closed_ball x ε ↔ dist x y ≤ ε :=
by { rw dist_comm, refl }
lemma nonempty_closed_ball (h : 0 ≤ ε) : (closed_ball x ε).nonempty :=
⟨x, by simp [h]⟩
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
assume y (hy : _ < _), le_of_lt hy
theorem sphere_subset_closed_ball : sphere x ε ⊆ closed_ball x ε :=
λ y, le_of_eq
theorem sphere_disjoint_ball : disjoint (sphere x ε) (ball x ε) :=
λ y ⟨hy₁, hy₂⟩, absurd hy₁ $ ne_of_lt hy₂
@[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closed_ball x ε :=
set.ext $ λ y, (@le_iff_lt_or_eq ℝ _ _ _).symm
@[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closed_ball x ε :=
by rw [union_comm, ball_union_sphere]
@[simp] theorem closed_ball_diff_sphere : closed_ball x ε \ sphere x ε = ball x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_right sphere_disjoint_ball.symm]
@[simp] theorem closed_ball_diff_ball : closed_ball x ε \ ball x ε = sphere x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_left sphere_disjoint_ball.symm]
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
lt_of_le_of_lt dist_nonneg hy
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show dist x x < ε, by rw dist_self; assumption
theorem mem_closed_ball_self (h : 0 ≤ ε) : x ∈ closed_ball x ε :=
show dist x x ≤ ε, by rw dist_self; assumption
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by simp [dist_comm]
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 : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
not_lt_of_le (dist_triangle_left x y z)
(lt_of_lt_of_le (add_lt_add h₁ h₂) h)
theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
ball_disjoint $ by rwa [← two_mul, ← le_div_iff' (@zero_lt_two ℝ _ _)]
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset $ by rw sub_self_div_two; exact le_of_lt h
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
@[simp] theorem ball_eq_empty_iff_nonpos : ball x ε = ∅ ↔ ε ≤ 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,
λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩
@[simp] theorem closed_ball_eq_empty_iff_neg : closed_ball x ε = ∅ ↔ ε < 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, not_le.1 $ λ ε0, h x $ mem_closed_ball_self ε0,
λ ε0 y h, not_lt_of_le (mem_closed_ball.1 h) (lt_of_lt_of_le ε0 dist_nonneg)⟩
@[simp] lemma ball_zero : ball x 0 = ∅ :=
by rw [ball_eq_empty_iff_nonpos]
@[simp] lemma closed_ball_zero : closed_ball x 0 = {x} :=
set.ext $ λ y, dist_le_zero
theorem uniformity_basis_dist :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 < ε}) :=
begin
rw ← metric_space.uniformity_dist.symm,
refine has_basis_binfi_principal _ nonempty_Ioi,
exact λ r (hr : 0 < r) p (hp : 0 < p), ⟨min r p, lt_min hr hp,
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_left r p),
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_right r p)⟩
end
/-- Given `f : β → ℝ`, 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_dist`, `uniformity_basis_dist_inv_nat_succ`,
and `uniformity_basis_dist_inv_nat_pos`. -/
protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i (hi : p i), f i ≤ ε) :
(𝓤 α).has_basis p (λ i, {p:α×α | dist p.1 p.2 < f i}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
obtain ⟨i, hi, H⟩ : ∃ i (hi : p i), f i ≤ ε, from hf ε₀,
exact ⟨i, hi, λ x (hx : _ < _), hε $ lt_of_lt_of_le hx H⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, H⟩ }
end
theorem uniformity_basis_dist_inv_nat_succ :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / (↑n+1) }) :=
metric.mk_uniformity_basis (λ n _, div_pos zero_lt_one $ nat.cast_add_one_pos n)
(λ ε ε0, (exists_nat_one_div_lt ε0).imp $ λ n hn, ⟨trivial, le_of_lt hn⟩)
theorem uniformity_basis_dist_inv_nat_pos :
(𝓤 α).has_basis (λ n:ℕ, 0<n) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / ↑n }) :=
metric.mk_uniformity_basis (λ n hn, div_pos zero_lt_one $ nat.cast_pos.2 hn)
(λ ε ε0, let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 in ⟨n+1, nat.succ_pos n, le_of_lt hn⟩)
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}`
form a basis of `𝓤 α`.
Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor.
More can be easily added if needed in the future. -/
protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | dist p.1 p.2 ≤ f x}) :=
begin
refine ⟨λ s, uniformity_basis_dist.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
/-- Contant size closed neighborhoods of the diagonal form a basis
of the uniformity filter. -/
theorem uniformity_basis_dist_le :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 ≤ ε}) :=
metric.mk_uniformity_basis_le (λ _, id) (λ ε ε₀, ⟨ε, ε₀, le_refl ε⟩)
theorem mem_uniformity_dist {s : set (α×α)} :
s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
uniformity_basis_dist.mem_uniformity_iff
/-- A constant size neighborhood of the diagonal is an entourage. -/
theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
{p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=
mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
theorem uniform_continuous_iff [metric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
uniformity_basis_dist.uniform_continuous_iff uniformity_basis_dist
lemma uniform_continuous_on_iff [metric_space β] {f : α → β} {s : set α} :
uniform_continuous_on f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x y ∈ s, dist x y < δ → dist (f x) (f y) < ε :=
begin
dsimp [uniform_continuous_on],
rw (metric.uniformity_basis_dist.inf_principal (s.prod s)).tendsto_iff
metric.uniformity_basis_dist,
simp only [and_imp, exists_prop, prod.forall, mem_inter_eq, gt_iff_lt, mem_set_of_eq, mem_prod],
finish,
end
theorem uniform_embedding_iff [metric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniform_embedding_iff' [metric_space β] {f : α → β} :
uniform_embedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ) :=
begin
split,
{ assume h,
exact ⟨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 ⟨_, uniform_continuous_iff.2 h₁, h₂⟩,
assume x y hxy,
have : dist x y ≤ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
have : dist (f x) (f y) < ε, by simpa [hxy],
exact hε this },
simpa using this }
end
theorem totally_bounded_iff {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
/-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the
space from finitely many data. -/
lemma totally_bounded_of_finite_discretization {s : set α}
(H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),
∀x y, F x = F y → dist (x:α) y < ε) :
totally_bounded s :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw hs, exact totally_bounded_empty },
rcases hs with ⟨x0, hx0⟩,
haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,
refine totally_bounded_iff.2 (λ ε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,
let x' := Finv (F ⟨x, xs⟩),
have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,
simp only [set.mem_Union, set.mem_range],
exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
end
theorem finite_approx_of_totally_bounded {s : set α} (hs : totally_bounded s) :
∀ ε > 0, ∃ t ⊆ s, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
begin
intros ε ε_pos,
rw totally_bounded_iff_subset at hs,
exact hs _ (dist_mem_uniformity ε_pos),
end
/-- Expressing locally uniform convergence on a set using `dist`. -/
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, dist (f y) (F n y) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu x hx, _⟩,
rcases mem_uniformity_dist.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 `dist`. -/
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, dist (f x) (F n x) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
exact (H ε εpos).mono (λ n hs x hx, hε (hs x hx))
end
/-- Expressing locally uniform convergence using `dist`. -/
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, dist (f y) (F n y) < ε :=
by simp only [← tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff,
nhds_within_univ, mem_univ, forall_const, exists_prop]
/-- Expressing uniform convergence using `dist`. -/
lemma tendsto_uniformly_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_uniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε :=
by { rw [← tendsto_uniformly_on_univ, tendsto_uniformly_on_iff], simp }
protected lemma cauchy_iff {f : filter α} :
cauchy f ↔ ne_bot f ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=
uniformity_basis_dist.cauchy_iff
theorem nhds_basis_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_dist
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s :=
nhds_basis_ball.mem_iff
theorem eventually_nhds_iff {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ε>0, ∀ ⦃y⦄, dist y x < ε → p y :=
mem_nhds_iff
lemma eventually_nhds_iff_ball {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε>0, ∀ y ∈ ball x ε, p y :=
mem_nhds_iff
theorem nhds_basis_closed_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_dist_le
theorem nhds_basis_ball_inv_nat_succ :
(𝓝 x).has_basis (λ _, true) (λ n:ℕ, ball x (1 / (↑n+1))) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ
theorem nhds_basis_ball_inv_nat_pos :
(𝓝 x).has_basis (λ n, 0<n) (λ n:ℕ, ball x (1 / ↑n)) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos
theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp only [is_open_iff_mem_nhds, mem_nhds_iff]
theorem is_open_ball : is_open (ball x ε) :=
is_open_iff.2 $ λ y, exists_ball_subset_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
mem_nhds_sets is_open_ball (mem_ball_self ε0)
theorem closed_ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closed_ball x ε ∈ 𝓝 x :=
mem_sets_of_superset (ball_mem_nhds x ε0) ball_subset_closed_ball
theorem nhds_within_basis_ball {s : set α} :
(𝓝[s] x).has_basis (λ ε:ℝ, 0 < ε) (λ ε, ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_ball s
theorem mem_nhds_within_iff {t : set α} : s ∈ 𝓝[t] x ↔ ∃ε>0, ball x ε ∩ t ⊆ s :=
nhds_within_basis_ball.mem_iff
theorem tendsto_nhds_within_nhds_within [metric_space β] {t : set β} {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝[t] b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
(nhds_within_basis_ball.tendsto_iff nhds_within_basis_ball).trans $
by simp only [inter_comm, mem_inter_iff, and_imp, mem_ball]
theorem tendsto_nhds_within_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
by { rw [← nhds_within_univ b, tendsto_nhds_within_nhds_within],
simp only [mem_univ, true_and] }
theorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (𝓝 a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
nhds_basis_ball.tendsto_iff nhds_basis_ball
theorem continuous_at_iff [metric_space β] {f : α → β} {a : α} :
continuous_at f a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_at, tendsto_nhds_nhds]
theorem continuous_within_at_iff [metric_space β] {f : α → β} {a : α} {s : set α} :
continuous_within_at f s a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_within_at, tendsto_nhds_within_nhds]
theorem continuous_on_iff [metric_space β] {f : α → β} {s : set α} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∃ δ > 0, ∀a ∈ s, dist a b < δ → dist (f a) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff]
theorem continuous_iff [metric_space β] {f : α → β} :
continuous f ↔
∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds
theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε :=
nhds_basis_ball.tendsto_right_iff
theorem continuous_at_iff' [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔
∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε :=
by rw [continuous_at, tendsto_nhds]
theorem continuous_within_at_iff' [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔
∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by rw [continuous_within_at, tendsto_nhds]
theorem continuous_on_iff' [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff']
theorem continuous_iff' [topological_space β] {f : β → α} :
continuous f ↔ ∀a (ε > 0), ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds
theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=
(at_top_basis.tendsto_iff nhds_basis_ball).trans $
by { simp only [exists_prop, true_and], refl }
lemma is_open_singleton_iff {X : Type*} [metric_space X] {x : X} :
is_open ({x} : set X) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x :=
by simp [is_open_iff, subset_singleton_iff, mem_ball]
/-- Given a point `x` in a discrete subset `s` of a metric space, there is an open ball
centered at `x` and intersecting `s` only at `x`. -/
lemma exists_ball_inter_eq_singleton_of_mem_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.ball x ε ∩ s = {x} :=
nhds_basis_ball.exists_inter_eq_singleton_of_mem_discrete hx
/-- Given a point `x` in a discrete subset `s` of a metric space, there is a closed ball
of positive radius centered at `x` and intersecting `s` only at `x`. -/
lemma exists_closed_ball_inter_eq_singleton_of_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.closed_ball x ε ∩ s = {x} :=
nhds_basis_closed_ball.exists_inter_eq_singleton_of_mem_discrete hx
end metric
open metric
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_separated : separated_space α :=
separated_def.2 $ λ x y h, eq_of_forall_dist_le $
λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
/-Instantiate a metric space as an emetric space. Before we can state the instance,
we need to show that the uniform structure coming from the edistance and the
distance coincide. -/
/-- Expressing the uniformity in terms of `edist` -/
protected lemma metric.uniformity_basis_edist :
(𝓤 α).has_basis (λ ε:ℝ≥0∞, 0 < ε) (λ ε, {p | edist p.1 p.2 < ε}) :=
⟨begin
intro t,
refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,
{ use [ennreal.of_real ε, ennreal.of_real_pos.2 ε0],
rintros ⟨a, b⟩,
simp only [edist_dist, ennreal.of_real_lt_of_real_iff ε0],
exact Hε },
{ rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,
rw [ennreal.of_real_pos] at ε0',
refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,
rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }
end⟩
theorem metric.uniformity_edist : 𝓤 α = (⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε}) :=
metric.uniformity_basis_edist.eq_binfi
/-- A metric space induces an emetric space -/
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_emetric_space : emetric_space α :=
{ edist := edist,
edist_self := by simp [edist_dist],
eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,
edist_comm := by simp only [edist_dist, dist_comm]; simp,
edist_triangle := assume x y z, begin
simp only [edist_dist, ← ennreal.of_real_add, dist_nonneg],
rw ennreal.of_real_le_of_real_iff _,
{ exact dist_triangle _ _ _ },
{ simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }
end,
uniformity_edist := metric.uniformity_edist,
..‹metric_space α› }
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=
begin
ext y,
simp only [emetric.mem_ball, mem_ball, edist_dist],
exact ennreal.of_real_lt_of_real_iff_of_nonneg dist_nonneg
end
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball_nnreal {x : α} {ε : ℝ≥0} : emetric.ball x ε = ball x ε :=
by { convert metric.emetric_ball, simp }
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :
emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=
by ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball_nnreal {x : α} {ε : ℝ≥0} :
emetric.closed_ball x ε = closed_ball x ε :=
by { convert metric.emetric_closed_ball ε.2, simp }
/-- Build a new metric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)
(H : @uniformity _ U = @uniformity _ emetric_space.to_uniform_space') :
metric_space α :=
{ dist := @dist _ m.to_has_dist,
dist_self := dist_self,
eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
edist := edist,
edist_dist := edist_dist,
to_uniform_space := U,
uniformity_dist := H.trans metric_space.uniformity_dist }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. In this definition, the distance
is given separately, to be able to prescribe some expression which is not defeq to the push-forward
of the edistance to reals. -/
def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α]
(dist : α → α → ℝ)
(edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
(h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
metric_space α :=
let m : metric_space α :=
{ dist := dist,
eq_of_dist_eq_zero := λx y hxy,
by simpa [h, ennreal.to_real_eq_zero_iff, edist_ne_top x y] using hxy,
dist_self := λx, by simp [h],
dist_comm := λx y, by simp [h, emetric_space.edist_comm],
dist_triangle := λx y z, begin
simp only [h],
rw [← ennreal.to_real_add (edist_ne_top _ _) (edist_ne_top _ _),
ennreal.to_real_le_to_real (edist_ne_top _ _)],
{ exact edist_triangle _ _ _ },
{ simp [ennreal.add_eq_top, edist_ne_top] }
end,
edist := λx y, edist x y,
edist_dist := λx y, by simp [h, ennreal.of_real_to_real, edist_ne_top] } in
m.replace_uniformity $ by { rw [uniformity_edist, metric.uniformity_edist], refl }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. -/
def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :
metric_space α :=
emetric_space.to_metric_space_of_dist (λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (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 metric.complete_of_convergent_controlled_sequences (B : ℕ → real) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) →
∃x, tendsto u at_top (𝓝 x)) :
complete_space α :=
begin
-- this follows from the same criterion in emetric spaces. We just need to translate
-- the convergence assumption from `dist` to `edist`
apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
{ simp [hB] },
{ assume u Hu,
apply H,
assume N n m hn hm,
rw [← ennreal.of_real_lt_of_real_iff (hB N), ← edist_dist],
exact Hu N n m hn hm }
end
theorem metric.complete_of_cauchy_seq_tendsto :
(∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
emetric.complete_of_cauchy_seq_tendsto
section real
/-- Instantiate the reals as a metric space. -/
instance real.metric_space : metric_space ℝ :=
{ dist := λx y, abs (x - y),
dist_self := by simp [abs_zero],
eq_of_dist_eq_zero := by simp [sub_eq_zero],
dist_comm := assume x y, abs_sub _ _,
dist_triangle := assume x y z, abs_sub_le _ _ _ }
theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
by simp [real.dist_eq]
instance : order_topology ℝ :=
order_topology_of_nhds_abs $ λ x, begin
simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,
by simp [abs_sub, ball, real.dist_eq]],
apply le_antisymm,
{ simp [le_infi_iff],
exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },
{ intros s h,
rcases mem_nhds_iff.1 h with ⟨ε, ε0, ss⟩,
exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },
end
lemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=
by ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,
abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the
general case. -/
lemma squeeze_zero' {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀ᶠ t in t₀, 0 ≤ f t)
(hft : ∀ᶠ t in t₀, f t ≤ g t) (g0 : tendsto g t₀ (nhds 0)) : tendsto f t₀ (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le`
and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/
lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
(g0 : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
squeeze_zero' (eventually_of_forall hf) (eventually_of_forall hft) g0
theorem metric.uniformity_eq_comap_nhds_zero :
𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) :=
by { ext s,
simp [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff, subset_def, real.dist_0_eq_abs] }
lemma cauchy_seq_iff_tendsto_dist_at_top_0 [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) :=
by rw [cauchy_seq_iff_tendsto, metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff,
prod.map_def]
lemma tendsto_uniformity_iff_dist_tendsto_zero {ι : Type*} {f : ι → α × α} {p : filter ι} :
tendsto f p (𝓤 α) ↔ tendsto (λ x, dist (f x).1 (f x).2) p (𝓝 0) :=
by rw [metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff]
lemma filter.tendsto.congr_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h₁ : tendsto f₁ p (𝓝 a)) (h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₂ p (𝓝 a) :=
h₁.congr_uniformity $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
alias filter.tendsto.congr_dist ← tendsto_of_tendsto_of_dist
lemma tendsto_iff_of_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₁ p (𝓝 a) ↔ tendsto f₂ p (𝓝 a) :=
uniform.tendsto_congr $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
end real
section cauchy_seq
variables [nonempty β] [semilattice_sup β]
/-- In a metric space, Cauchy sequences are characterized by the fact that, eventually,
the distance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.cauchy_seq_iff {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=
uniformity_basis_dist.cauchy_seq_iff
/-- A variation around the metric characterization of Cauchy sequences -/
theorem metric.cauchy_seq_iff' {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=
uniformity_basis_dist.cauchy_seq_iff'
/-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
(h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : tendsto b at_top (nhds 0)) :
cauchy_seq s :=
metric.cauchy_seq_iff.2 $ λ ε ε0,
(metric.tendsto_at_top.1 h₀ ε ε0).imp $ λ N hN m n hm hn,
calc dist (s m) (s n) ≤ b N : h m n N hm hn
... ≤ abs (b N) : le_abs_self _
... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl
... < ε : (hN _ (le_refl N))
/-- A Cauchy sequence on the natural numbers is bounded. -/
theorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :
∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
begin
rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,
suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,
{ rcases this with ⟨R, R0, H⟩,
exact ⟨_, add_pos R0 R0, λ m n,
lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },
let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),
refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,
cases le_or_lt N n,
{ exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },
{ have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),
exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }
end
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,
(∀ n, 0 ≤ b n) ∧
(∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧
tendsto b at_top (𝓝 0) :=
⟨λ hs, begin
/- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`.
First, we prove that all these distances are bounded, as otherwise the Sup
would not make sense. -/
let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},
have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,
exact le_of_lt (hR m n) },
have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },
-- Prove that it bounds the distances of points in the Cauchy sequence
have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ Sup (S N) :=
λ m n N hm hn, real.le_Sup _ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,
have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,
have S0 := λ n, real.le_Sup _ (hS n) (S0m n),
-- Prove that it tends to `0`, by using the Cauchy property of `s`
refine ⟨λ N, Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,
refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),
rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],
refine lt_of_le_of_lt (real.Sup_le_ub _ ⟨_, S0m _⟩ _) (half_lt_self ε0),
rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,
exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))
end,
λ ⟨b, _, b_bound, b_lim⟩, cauchy_seq_of_le_tendsto_0 b b_bound b_lim⟩
end cauchy_seq
/-- Metric space structure pulled back by an injective function. Injectivity is necessary to
ensure that `dist x y = 0` only if `x = y`. -/
def metric_space.induced {α β} (f : α → β) (hf : function.injective f)
(m : metric_space β) : metric_space α :=
{ dist := λ x y, dist (f x) (f y),
dist_self := λ x, dist_self _,
eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
dist_comm := λ x y, dist_comm _ _,
dist_triangle := λ x y z, dist_triangle _ _ _,
edist := λ x y, edist (f x) (f y),
edist_dist := λ x y, edist_dist _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_dist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),
refine λ s, mem_comap_sets.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
instance subtype.metric_space {α : Type*} {p : α → Prop} [t : metric_space α] :
metric_space (subtype p) :=
metric_space.induced coe (λ x y, subtype.ext) t
theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist (x : α) y := rfl
section nnreal
instance : metric_space ℝ≥0 := by unfold nnreal; apply_instance
lemma nnreal.dist_eq (a b : ℝ≥0) : dist a b = abs ((a:ℝ) - b) := rfl
lemma nnreal.nndist_eq (a b : ℝ≥0) :
nndist a b = max (a - b) (b - a) :=
begin
wlog h : a ≤ b,
{ apply nnreal.coe_eq.1,
rw [nnreal.sub_eq_zero h, max_eq_right (zero_le $ b - a), ← dist_nndist, nnreal.dist_eq,
nnreal.coe_sub h, abs, neg_sub],
apply max_eq_right,
linarith [nnreal.coe_le_coe.2 h] },
rwa [nndist_comm, max_comm]
end
end nnreal
section prod
instance prod.metric_space_max [metric_space β] : metric_space (α × β) :=
{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
dist_self := λ x, by simp,
eq_of_dist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
end,
dist_comm := λ x y, by simp [dist_comm],
dist_triangle := λ x y z, max_le
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),
edist_dist := assume x y, begin
have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,
rw [edist_dist, edist_dist, ← this.map_max]
end,
uniformity_dist := begin
refine uniformity_prod.trans _,
simp only [uniformity_basis_dist.eq_binfi, 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.dist_eq [metric_space β] {x y : α × β} :
dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
theorem ball_prod_same [metric_space β] (x : α) (y : β) (r : ℝ) :
(ball x r).prod (ball y r) = ball (x, y) r :=
ext $ λ z, by simp [prod.dist_eq]
theorem closed_ball_prod_same [metric_space β] (x : α) (y : β) (r : ℝ) :
(closed_ball x r).prod (closed_ball y r) = closed_ball (x, y) r :=
ext $ λ z, by simp [prod.dist_eq]
end prod
theorem uniform_continuous_dist : uniform_continuous (λp:α×α, dist p.1 p.2) :=
metric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
begin
suffices,
{ intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
cases max_lt_iff.1 h with h₁ h₂, clear h,
dsimp at h₁ h₂ ⊢,
rw real.dist_eq,
refine abs_sub_lt_iff.2 ⟨_, _⟩,
{ revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
{ apply this; rwa dist_comm } },
intros p₁ p₂ q₁ q₂ h₁ h₂,
have := add_lt_add
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
end⟩)
theorem uniform_continuous.dist [uniform_space β] {f g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (λb, dist (f b) (g b)) :=
uniform_continuous_dist.comp (hf.prod_mk hg)
theorem continuous_dist : continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_dist.continuous
theorem continuous.dist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
continuous_dist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.dist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, dist (f x) (g x)) x (𝓝 (dist a b)) :=
(continuous_dist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a :=
by simp only [@nhds_eq_comap_uniformity α, metric.uniformity_eq_comap_nhds_zero,
comap_comap, (∘), dist_comm]
lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
(tendsto f x (𝓝 a)) ↔ (tendsto (λb, dist (f b) a) x (𝓝 0)) :=
by rw [← nhds_comap_dist a, tendsto_comap_iff]
lemma uniform_continuous_nndist : uniform_continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_subtype_mk uniform_continuous_dist _
lemma uniform_continuous.nndist [uniform_space β] {f g : β → α} (hf : uniform_continuous f)
(hg : uniform_continuous g) :
uniform_continuous (λ b, nndist (f b) (g b)) :=
uniform_continuous_nndist.comp (hf.prod_mk hg)
lemma continuous_nndist : continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_nndist.continuous
lemma continuous.nndist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, nndist (f b) (g b)) :=
continuous_nndist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.nndist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, nndist (f x) (g x)) x (𝓝 (nndist a b)) :=
(continuous_nndist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
namespace metric
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
theorem is_closed_ball : is_closed (closed_ball x ε) :=
is_closed_le (continuous_id.dist continuous_const) continuous_const
lemma is_closed_sphere : is_closed (sphere x ε) :=
is_closed_eq (continuous_id.dist continuous_const) continuous_const
@[simp] theorem closure_closed_ball : closure (closed_ball x ε) = closed_ball x ε :=
is_closed_ball.closure_eq
theorem closure_ball_subset_closed_ball : closure (ball x ε) ⊆ closed_ball x ε :=
closure_minimal ball_subset_closed_ball is_closed_ball
theorem frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε :=
frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem frontier_closed_ball_subset_sphere : frontier (closed_ball x ε) ⊆ sphere x ε :=
frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem ball_subset_interior_closed_ball : ball x ε ⊆ interior (closed_ball x ε) :=
interior_maximal ball_subset_closed_ball is_open_ball
/-- ε-characterization of the closure in metric spaces-/
theorem mem_closure_iff {α : Type u} [metric_space α] {s : set α} {a : α} :
a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
(mem_closure_iff_nhds_basis nhds_basis_ball).trans $
by simp only [mem_ball, dist_comm]
lemma mem_closure_range_iff {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε :=
by simp only [mem_closure_iff, exists_range_iff]
lemma mem_closure_range_iff_nat {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
(mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans $
by simp only [mem_ball, dist_comm, exists_range_iff, forall_const]
theorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s)
{a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
by simpa only [hs.closure_eq] using @mem_closure_iff _ _ s a
end metric
section pi
open finset
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
/-- A finite product of metric spaces is a metric space, with the sup distance. -/
instance metric_space_pi : metric_space (Πb, π b) :=
begin
/- we construct the instance from the emetric space instance to avoid checking again that the
uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
refine emetric_space.to_metric_space_of_dist
(λf g, ((sup univ (λb, nndist (f b) (g b)) : ℝ≥0) : ℝ)) _ _,
show ∀ (x y : Π (b : β), π b), edist x y ≠ ⊤,
{ assume x y,
rw ← lt_top_iff_ne_top,
have : (⊥ : ℝ≥0∞) < ⊤ := ennreal.coe_lt_top,
simp [edist_pi_def, finset.sup_lt_iff this, edist_lt_top] },
show ∀ (x y : Π (b : β), π b), ↑(sup univ (λ (b : β), nndist (x b) (y b))) =
ennreal.to_real (sup univ (λ (b : β), edist (x b) (y b))),
{ assume x y,
simp only [edist_nndist],
norm_cast }
end
lemma nndist_pi_def (f g : Πb, π b) : nndist f g = sup univ (λb, nndist (f b) (g b)) :=
subtype.eta _ _
lemma dist_pi_def (f g : Πb, π b) :
dist f g = (sup univ (λb, nndist (f b) (g b)) : ℝ≥0) := rfl
@[simp] lemma dist_pi_const [nonempty β] (a b : α) : dist (λ x : β, a) (λ _, b) = dist a b :=
by simpa only [dist_edist] using congr_arg ennreal.to_real (edist_pi_const a b)
@[simp] lemma nndist_pi_const [nonempty β] (a b : α) : nndist (λ x : β, a) (λ _, b) = nndist a b :=
nnreal.eq $ dist_pi_const a b
lemma dist_pi_lt_iff {f g : Πb, π b} {r : ℝ} (hr : 0 < r) :
dist f g < r ↔ ∀b, dist (f b) (g b) < r :=
begin
lift r to ℝ≥0 using hr.le,
simp [dist_pi_def, finset.sup_lt_iff (show ⊥ < r, from hr)],
end
lemma dist_pi_le_iff {f g : Πb, π b} {r : ℝ} (hr : 0 ≤ r) :
dist f g ≤ r ↔ ∀b, dist (f b) (g b) ≤ r :=
begin
lift r to ℝ≥0 using hr,
simp [nndist_pi_def]
end
lemma nndist_le_pi_nndist (f g : Πb, π b) (b : β) : nndist (f b) (g b) ≤ nndist f g :=
by { rw [nndist_pi_def], exact finset.le_sup (finset.mem_univ b) }
lemma dist_le_pi_dist (f g : Πb, π b) (b : β) : dist (f b) (g b) ≤ dist f g :=
by simp only [dist_nndist, nnreal.coe_le_coe, nndist_le_pi_nndist f g b]
/-- An open ball in a product space is a product of open balls. The assumption `0 < r`
is necessary for the case of the empty product. -/
lemma ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 < r) :
ball x r = { y | ∀b, y b ∈ ball (x b) r } :=
by { ext p, simp [dist_pi_lt_iff hr] }
/-- A closed ball in a product space is a product of closed balls. The assumption `0 ≤ r`
is necessary for the case of the empty product. -/
lemma closed_ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 ≤ r) :
closed_ball x r = { y | ∀b, y b ∈ closed_ball (x b) r } :=
by { ext p, simp [dist_pi_le_iff hr] }
end pi
section compact
/-- Any compact set in a metric space can be covered by finitely many balls of a given positive
radius -/
lemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}
(hs : is_compact s) {e : ℝ} (he : 0 < e) :
∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=
begin
apply hs.elim_finite_subcover_image,
{ simp [is_open_ball] },
{ intros x xs,
simp,
exact ⟨x, ⟨xs, by simpa⟩⟩ }
end
alias finite_cover_balls_of_compact ← is_compact.finite_cover_balls
end compact
section proper_space
open metric
/-- A metric space is proper if all closed balls are compact. -/
class proper_space (α : Type u) [metric_space α] : Prop :=
(compact_ball : ∀x:α, ∀r, is_compact (closed_ball x r))
lemma tendsto_dist_right_cocompact_at_top [proper_space α] (x : α) :
tendsto (λ y, dist y x) (cocompact α) at_top :=
(has_basis_cocompact.tendsto_iff at_top_basis).2 $ λ r hr,
⟨closed_ball x r, proper_space.compact_ball x r, λ y hy, (not_le.1 $ mt mem_closed_ball.2 hy).le⟩
lemma tendsto_dist_left_cocompact_at_top [proper_space α] (x : α) :
tendsto (dist x) (cocompact α) at_top :=
by simpa only [dist_comm] using tendsto_dist_right_cocompact_at_top x
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
lemma proper_space_of_compact_closed_ball_of_le
(R : ℝ) (h : ∀x:α, ∀r, R ≤ r → is_compact (closed_ball x r)) :
proper_space α :=
⟨begin
assume x r,
by_cases hr : R ≤ r,
{ exact h x r hr },
{ have : closed_ball x r = closed_ball x R ∩ closed_ball x r,
{ symmetry,
apply inter_eq_self_of_subset_right,
exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr)) },
rw this,
exact (h x R (le_refl _)).inter_right is_closed_ball }
end⟩
/- A compact metric space is proper -/
@[priority 100] -- see Note [lower instance priority]
instance proper_of_compact [compact_space α] : proper_space α :=
⟨assume x r, is_closed_ball.compact⟩
/-- A proper space is locally compact -/
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_proper [proper_space α] :
locally_compact_space α :=
locally_compact_space_of_has_basis (λ x, nhds_basis_closed_ball) $
λ x ε ε0, proper_space.compact_ball _ _
/-- A proper space is complete -/
@[priority 100] -- see Note [lower instance priority]
instance complete_of_proper [proper_space α] : complete_space α :=
⟨begin
intros f hf,
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
have A : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 := (metric.cauchy_iff.1 hf).2 1 zero_lt_one,
rcases A with ⟨t, ⟨t_fset, ht⟩⟩,
rcases hf.1.nonempty_of_mem t_fset with ⟨x, xt⟩,
have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),
have : closed_ball x 1 ∈ f := f.sets_of_superset t_fset this,
rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf
(le_principal_iff.2 this) with ⟨y, _, hy⟩,
exact ⟨y, hy⟩
end⟩
/-- A proper metric space is separable, and therefore second countable. Indeed, any ball is
compact, and therefore admits a countable dense subset. Taking a countable union over the balls
centered at a fixed point and with integer radius, one obtains a countable set which is
dense in the whole space. -/
@[priority 100] -- see Note [lower instance priority]
instance second_countable_of_proper [proper_space α] :
second_countable_topology α :=
begin
/- It suffices to show that `α` admits a countable dense subset. -/
suffices : separable_space α,
{ resetI, apply emetric.second_countable_of_separable },
constructor,
/- We show that the space admits a countable dense subset. The case where the space is empty
is special, and trivial. -/
rcases _root_.em (nonempty α) with (⟨⟨x⟩⟩|hα), swap,
{ exact ⟨∅, countable_empty, λ x, (hα ⟨x⟩).elim⟩ },
/- When the space is not empty, we take a point `x` in the space, and then a countable set
`T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set
`t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union
of countable sets, and dense in the space by construction. -/
choose T T_sub T_count T_closure using
show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),
from assume r, emetric.countable_closure_of_compact (proper_space.compact_ball _ _),
use [⋃n:ℕ, T (n : ℝ), countable_Union (λ n, T_count n)],
intro y,
rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,
have h : y ∈ closed_ball x (n : ℝ) := n_large.le,
rw [T_closure] at h,
exact closure_mono (subset_Union _ _) h
end
/-- A finite product of proper spaces is proper. -/
instance pi_proper_space {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
[h : ∀b, proper_space (π b)] : proper_space (Πb, π b) :=
begin
refine proper_space_of_compact_closed_ball_of_le 0 (λx r hr, _),
rw closed_ball_pi _ hr,
apply compact_pi_infinite (λb, _),
apply (h b).compact_ball
end
end proper_space
namespace metric
section second_countable
open topological_space
/-- A metric space is second countable if, for every `ε > 0`, there is a countable set which is
`ε`-dense. -/
lemma second_countable_of_almost_dense_set
(H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :
second_countable_topology α :=
begin
choose T T_dense using H,
have I1 : ∀n:ℕ, (n:ℝ) + 1 > 0 :=
λn, lt_of_lt_of_le zero_lt_one (le_add_of_nonneg_left (nat.cast_nonneg _)),
have I : ∀n:ℕ, (n+1 : ℝ)⁻¹ > 0 := λn, inv_pos.2 (I1 n),
let t := ⋃n:ℕ, T (n+1)⁻¹ (I n),
have count_t : countable t := by finish [countable_Union],
have dense_t : dense t,
{ refine (λx, mem_closure_iff.2 (λε εpos, _)),
rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩,
have : ε⁻¹ < n + 1 := lt_of_lt_of_le hn (le_add_of_nonneg_right zero_le_one),
have nε : ((n:ℝ)+1)⁻¹ < ε := (inv_lt (I1 n) εpos).2 this,
rcases (T_dense (n+1)⁻¹ (I n)).2 x with ⟨y, yT, Dxy⟩,
have : y ∈ t := mem_of_mem_of_subset yT (by apply subset_Union (λ (n:ℕ), T (n+1)⁻¹ (I n))),
exact ⟨y, this, lt_of_le_of_lt Dxy nε⟩ },
haveI : separable_space α := ⟨⟨t, ⟨count_t, dense_t⟩⟩⟩,
exact emetric.second_countable_of_separable α
end
/-- A metric space space is second countable if one can reconstruct up to any `ε>0` any element of
the space from countably many data. -/
lemma second_countable_of_countable_discretization {α : Type u} [metric_space α]
(H : ∀ε > (0 : ℝ), ∃ (β : Type*) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :
second_countable_topology α :=
begin
cases (univ : set α).eq_empty_or_nonempty with hs hs,
{ haveI : compact_space α := ⟨by rw hs; exact compact_empty⟩, by apply_instance },
rcases hs with ⟨x0, hx0⟩,
letI : inhabited α := ⟨x0⟩,
refine second_countable_of_almost_dense_set (λε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,
let x' := Finv (F x),
have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,
exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
end
end second_countable
end metric
lemma lebesgue_number_lemma_of_metric
{s : set α} {ι} {c : ι → set α} (hs : is_compact s)
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
lemma lebesgue_number_lemma_of_metric_sUnion
{s : set α} {c : set (set α)} (hs : is_compact s)
(hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
namespace metric
/-- Boundedness of a subset of a metric space. We formulate the definition to work
even in the empty space. -/
def bounded (s : set α) : Prop :=
∃C, ∀x y ∈ s, dist x y ≤ C
section bounded
variables {x : α} {s t : set α} {r : ℝ}
@[simp] lemma bounded_empty : bounded (∅ : set α) :=
⟨0, by simp⟩
lemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=
⟨λ h _ _, h, λ H,
s.eq_empty_or_nonempty.elim
(λ hs, hs.symm ▸ bounded_empty)
(λ ⟨x, hx⟩, H x hx)⟩
/-- Subsets of a bounded set are also bounded -/
lemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=
Exists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)
/-- Closed balls are bounded -/
lemma bounded_closed_ball : bounded (closed_ball x r) :=
⟨r + r, λ y z hy hz, begin
simp only [mem_closed_ball] at *,
calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add hy hz
end⟩
/-- Open balls are bounded -/
lemma bounded_ball : bounded (ball x r) :=
bounded_closed_ball.subset ball_subset_closed_ball
/-- Given a point, a bounded subset is included in some ball around this point -/
lemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=
begin
split; rintro ⟨C, hC⟩,
{ cases s.eq_empty_or_nonempty with h h,
{ subst s, exact ⟨0, by simp⟩ },
{ rcases h with ⟨x, hx⟩,
exact ⟨C + dist x c, λ y hy, calc
dist y c ≤ dist y x + dist x c : dist_triangle _ _ _
... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },
{ exact bounded_closed_ball.subset hC }
end
lemma bounded_closure_of_bounded (h : bounded s) : bounded (closure s) :=
begin
cases h with C h,
replace h : ∀ p : α × α, p ∈ set.prod s s → dist p.1 p.2 ∈ { d | d ≤ C },
{ rintros ⟨x, y⟩ ⟨x_in, y_in⟩,
exact h x y x_in y_in },
use C,
suffices : ∀ p : α × α, p ∈ closure (set.prod s s) → dist p.1 p.2 ∈ { d | d ≤ C },
{ rw closure_prod_eq at this,
intros x y x_in y_in,
exact this (x, y) (mk_mem_prod x_in y_in) },
intros p p_in,
have := map_mem_closure continuous_dist p_in h,
rwa (is_closed_le' C).closure_eq at this
end
alias bounded_closure_of_bounded ← bounded.closure
/-- The union of two bounded sets is bounded iff each of the sets is bounded -/
@[simp] lemma bounded_union :
bounded (s ∪ t) ↔ bounded s ∧ bounded t :=
⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,
begin
rintro ⟨hs, ht⟩,
refine bounded_iff_mem_bounded.2 (λ x _, _),
rw bounded_iff_subset_ball x at hs ht ⊢,
rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,
exact ⟨max Cs Ct, union_subset
(subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)
(subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,
end⟩
/-- A finite union of bounded sets is bounded -/
lemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :
bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=
finite.induction_on H (by simp) $ λ x I _ _ IH,
by simp [or_imp_distrib, forall_and_distrib, IH]
/-- A compact set is bounded -/
lemma bounded_of_compact {s : set α} (h : is_compact s) : bounded s :=
-- We cover the compact set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
let ⟨t, ht, fint, subs⟩ := finite_cover_balls_of_compact h zero_lt_one in
bounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball
alias bounded_of_compact ← is_compact.bounded
/-- A finite set is bounded -/
lemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=
h.is_compact.bounded
/-- A singleton is bounded -/
lemma bounded_singleton {x : α} : bounded ({x} : set α) :=
bounded_of_finite $ finite_singleton _
/-- Characterization of the boundedness of the range of a function -/
lemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=
exists_congr $ λ C, ⟨
λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,
by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩
/-- In a compact space, all sets are bounded -/
lemma bounded_of_compact_space [compact_space α] : bounded s :=
compact_univ.bounded.subset (subset_univ _)
/-- The Heine–Borel theorem:
In a proper space, a set is compact if and only if it is closed and bounded -/
lemma compact_iff_closed_bounded [proper_space α] :
is_compact s ↔ is_closed s ∧ bounded s :=
⟨λ h, ⟨h.is_closed, h.bounded⟩, begin
rintro ⟨hc, hb⟩,
cases s.eq_empty_or_nonempty with h h, {simp [h, compact_empty]},
rcases h with ⟨x, hx⟩,
rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,
exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr
end⟩
end bounded
section diam
variables {s : set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the emetric.diameter -/
def diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)
/-- The diameter of a set is always nonnegative -/
lemma diam_nonneg : 0 ≤ diam s := ennreal.to_real_nonneg
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
by simp only [diam, emetric.diam_subsingleton hs, ennreal.zero_to_real]
/-- The empty set has zero diameter -/
@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- A singleton has zero diameter -/
@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
diam_subsingleton subsingleton_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
lemma diam_pair : diam ({x, y} : set α) = dist x y :=
by simp only [diam, emetric.diam_pair, dist_edist]
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
lemma diam_triple :
metric.diam ({x, y, z} : set α) = max (max (dist x y) (dist x z)) (dist y z) :=
begin
simp only [metric.diam, emetric.diam_triple, dist_edist],
rw [ennreal.to_real_max, ennreal.to_real_max];
apply_rules [ne_of_lt, edist_lt_top, max_lt]
end
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ennreal.of_real C` bounds the emetric diameter of this set. -/
lemma ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
emetric.diam s ≤ ennreal.of_real C :=
emetric.diam_le_of_forall_edist_le $
λ x hx y hy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy)
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
diam s ≤ C :=
ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h)
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le_of_nonempty (hs : s.nonempty) {C : ℝ}
(h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C, from let ⟨x, hx⟩ := hs in le_trans dist_nonneg (h x hx x hx),
diam_le_of_forall_dist_le h₀ h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem' (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s :=
begin
rw [diam, dist_edist],
rw ennreal.to_real_le_to_real (edist_ne_top _ _) h,
exact emetric.edist_le_diam_of_mem hx hy
end
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
lemma bounded_iff_ediam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=
iff.intro
(λ ⟨C, hC⟩, ne_top_of_le_ne_top ennreal.of_real_ne_top
(ediam_le_of_forall_dist_le $ λ x hx y hy, hC x y hx hy))
(λ h, ⟨diam s, λ x y hx hy, dist_le_diam_of_mem' h hx hy⟩)
lemma bounded.ediam_ne_top (h : bounded s) : emetric.diam s ≠ ⊤ :=
bounded_iff_ediam_ne_top.1 h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
lemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=
begin
simp only [bounded_iff_ediam_ne_top, not_not, ne.def] at h,
simp [diam, h]
end
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
lemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=
begin
unfold diam,
rw ennreal.to_real_le_to_real (bounded.subset h ht).ediam_ne_top ht.ediam_ne_top,
exact emetric.diam_mono h
end
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + dist x y + diam t :=
begin
classical, by_cases H : bounded (s ∪ t),
{ have hs : bounded s, from H.subset (subset_union_left _ _),
have ht : bounded t, from H.subset (subset_union_right _ _),
rw [bounded_iff_ediam_ne_top] at H hs ht,
rw [dist_edist, diam, diam, diam, ← ennreal.to_real_add, ← ennreal.to_real_add,
ennreal.to_real_le_to_real];
repeat { apply ennreal.add_ne_top.2; split }; try { assumption };
try { apply edist_ne_top },
exact emetric.diam_union xs yt },
{ rw [diam_eq_zero_of_unbounded H],
apply_rules [add_nonneg, diam_nonneg, dist_nonneg] }
end
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
begin
rcases h with ⟨x, ⟨xs, xt⟩⟩,
simpa using diam_union xs xt
end
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
lemma diam_closed_ball {r : ℝ} (h : 0 ≤ r) : diam (closed_ball x r) ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg (le_of_lt zero_lt_two) h) $ λa ha b hb, calc
dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add ha hb
... = 2 * r : by simp [mul_two, mul_comm]
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
lemma diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
end diam
end metric
namespace int
open metric
/-- Under the coercion from `ℤ` to `ℝ`, inverse images of compact sets are finite. -/
lemma tendsto_coe_cofinite : tendsto (coe : ℤ → ℝ) cofinite (cocompact ℝ) :=
begin
simp only [filter.has_basis_cocompact.tendsto_right_iff, eventually_iff_exists_mem],
intros s hs,
obtain ⟨r, hr⟩ : ∃ r, s ⊆ closed_ball (0:ℝ) r,
{ rw ← bounded_iff_subset_ball,
exact hs.bounded },
refine ⟨(coe ⁻¹' closed_ball (0:ℝ) r)ᶜ, _, _⟩,
{ simp [mem_cofinite, closed_ball_Icc, set.Icc_ℤ_finite] },
{ rw ← compl_subset_compl at hr,
intros y hy,
exact hr hy }
end
end int
|
8c58ed744848756fc5e5f3e6734a0dd45fe0ac7e
|
82e44445c70db0f03e30d7be725775f122d72f3e
|
/src/geometry/manifold/instances/real.lean
|
495f61c15ec32275a12d668e0c440fb9aca279bf
|
[
"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
| 13,574
|
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.normed_space.pi_Lp
/-!
# 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
|
e3362bd98ed362215d57f948c84a8a6c16213976
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/library/data/unit/basic.lean
|
df303f48e074fb0297db6e17bc5e6458e7d5a28a
|
[
"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
| 213
|
lean
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
inductive unit.{l} : Type.{l} :=
star : unit
|
ac3fcec63c59be4cab4224e939bd59456676587b
|
1d335ec6ac4181a0a762b12797936770cc9fcef9
|
/eval/geometryEval.lean
|
ec3bfdbef6ba7637588c7ff8f84109605595435a
|
[] |
no_license
|
rohanrajnair/lang
|
dbadcc3997e44245ca84d48dc1733cf09a2605a6
|
3beb4e29d8faa692983a55fa18acb6eb947134e8
|
refs/heads/master
| 1,672,640,379,424
| 1,597,948,771,000
| 1,597,948,771,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 260
|
lean
|
import ..imperative_DSL.environment
open lang.classicalGeometry
def classicalGeometryEval : lang.classicalGeometry.expr → environment.env → classicalGeometry
| (lang.classicalGeometry.expr.lit s) i := s
| (lang.classicalGeometry.expr.var v) i := i.g v
|
d8a20dbc47ffffa683ed9118bb502f584770d95a
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/ring_theory/tensor_product.lean
|
dcb86fa9955b31827e60669fa320045355db90ae
|
[
"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
| 16,587
|
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 linear_algebra.tensor_product
import algebra.algebra.basic
universes u v₁ v₂ v₃ v₄
/-!
The tensor product of R-algebras.
We construct the R-algebra structure on `A ⊗[R] B`, when `A` and `B` are both `R`-algebras,
and provide the structure isomorphisms
* `R ⊗[R] A ≃ₐ[R] A`
* `A ⊗[R] R ≃ₐ[R] A`
* `A ⊗[R] B ≃ₐ[R] B ⊗[R] A`
The code for
* `((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))`
is written and compiles, but takes longer than the `-T100000` time limit,
so is currently commented out.
-/
namespace algebra
open_locale tensor_product
open tensor_product
namespace tensor_product
section semiring
variables {R : Type u} [comm_semiring R]
variables {A : Type v₁} [semiring A] [algebra R A]
variables {B : Type v₂} [semiring B] [algebra R B]
/--
(Implementation detail)
The multiplication map on `A ⊗[R] B`,
for a fixed pure tensor in the first argument,
as an `R`-linear map.
-/
def mul_aux (a₁ : A) (b₁ : B) : (A ⊗[R] B) →ₗ[R] (A ⊗[R] B) :=
begin
-- Why doesn't `apply tensor_product.lift` work?
apply @tensor_product.lift R _ A B (A ⊗[R] B) _ _ _ _ _ _ _,
fsplit,
intro a₂,
fsplit,
intro b₂,
exact (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂),
{ intros b₂ b₂',
simp [mul_add, tmul_add], },
{ intros c b₂,
simp [mul_smul, tmul_smul], },
{ intros a₂ a₂', ext b₂,
simp [mul_add, add_tmul], },
{ intros c a₂, ext b₂,
simp [mul_smul, smul_tmul], }
end
@[simp]
lemma mul_aux_apply (a₁ a₂ : A) (b₁ b₂ : B) :
(mul_aux a₁ b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
/--
(Implementation detail)
The multiplication map on `A ⊗[R] B`,
as an `R`-bilinear map.
-/
def mul : (A ⊗[R] B) →ₗ[R] (A ⊗[R] B) →ₗ[R] (A ⊗[R] B) :=
begin
apply @tensor_product.lift R _ A B ((A ⊗[R] B) →ₗ[R] (A ⊗[R] B)) _ _ _ _ _ _ _,
fsplit,
intro a₁,
fsplit,
intro b₁,
exact mul_aux a₁ b₁,
{ intros b₁ b₁',
-- Why doesn't just `apply tensor_product.ext`, or indeed `ext` work?!
apply @tensor_product.ext R _ A B (A ⊗[R] B) _ _ _ _ _ _,
intros a₂ b₂,
simp [add_mul, tmul_add], },
{ intros c b₁,
apply @tensor_product.ext R _ A B (A ⊗[R] B) _ _ _ _ _ _,
intros a₂ b₂,
simp, },
{ intros a₁ a₁', ext1 b₁,
apply @tensor_product.ext R _ A B (A ⊗[R] B) _ _ _ _ _ _,
intros a₂ b₂,
simp [add_mul, add_tmul], },
{ intros c a₁, ext1 b₁,
apply @tensor_product.ext R _ A B (A ⊗[R] B) _ _ _ _ _ _,
intros a₂ b₂,
simp [smul_tmul], },
end
@[simp]
lemma mul_apply (a₁ a₂ : A) (b₁ b₂ : B) :
mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
lemma mul_assoc' (mul : (A ⊗[R] B) →ₗ[R] (A ⊗[R] B) →ₗ[R] (A ⊗[R] B))
(h : ∀ (a₁ a₂ a₃ : A) (b₁ b₂ b₃ : B),
mul (mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂)) (a₃ ⊗ₜ[R] b₃) =
mul (a₁ ⊗ₜ[R] b₁) (mul (a₂ ⊗ₜ[R] b₂) (a₃ ⊗ₜ[R] b₃))) :
∀ (x y z : A ⊗[R] B), mul (mul x y) z = mul x (mul y z) :=
begin
intros,
apply tensor_product.induction_on x,
{ simp, },
apply tensor_product.induction_on y,
{ simp, },
apply tensor_product.induction_on z,
{ simp, },
{ intros, simp [h], },
{ intros, simp [linear_map.map_add, *], },
{ intros, simp [linear_map.map_add, *], },
{ intros, simp [linear_map.map_add, *], },
end
lemma mul_assoc (x y z : A ⊗[R] B) : mul (mul x y) z = mul x (mul y z) :=
mul_assoc' mul (by { intros, simp only [mul_apply, mul_assoc], }) x y z
lemma one_mul (x : A ⊗[R] B) : mul (1 ⊗ₜ 1) x = x :=
begin
apply tensor_product.induction_on x;
simp {contextual := tt},
end
lemma mul_one (x : A ⊗[R] B) : mul x (1 ⊗ₜ 1) = x :=
begin
apply tensor_product.induction_on x;
simp {contextual := tt},
end
instance : semiring (A ⊗[R] B) :=
{ zero := 0,
add := (+),
one := 1 ⊗ₜ 1,
mul := λ a b, mul a b,
one_mul := one_mul,
mul_one := mul_one,
mul_assoc := mul_assoc,
zero_mul := by simp,
mul_zero := by simp,
left_distrib := by simp,
right_distrib := by simp,
.. (by apply_instance : add_comm_monoid (A ⊗[R] B)) }.
lemma one_def : (1 : A ⊗[R] B) = (1 : A) ⊗ₜ (1 : B) := rfl
@[simp]
lemma tmul_mul_tmul (a₁ a₂ : A) (b₁ b₂ : B) :
(a₁ ⊗ₜ[R] b₁) * (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
@[simp]
lemma tmul_pow (a : A) (b : B) (k : ℕ) :
(a ⊗ₜ[R] b)^k = (a^k) ⊗ₜ[R] (b^k) :=
begin
induction k with k ih,
{ simp [one_def], },
{ simp [pow_succ, ih], }
end
/--
The algebra map `R →+* (A ⊗[R] B)` giving `A ⊗[R] B` the structure of an `R`-algebra.
-/
def tensor_algebra_map : R →+* (A ⊗[R] B) :=
{ to_fun := λ r, algebra_map R A r ⊗ₜ[R] 1,
map_one' := by { simp, refl },
map_mul' := by simp,
map_zero' := by simp [zero_tmul],
map_add' := by simp [add_tmul], }
instance : algebra R (A ⊗[R] B) :=
{ commutes' := λ r x,
begin
apply tensor_product.induction_on x,
{ simp, },
{ intros a b, simp [tensor_algebra_map, algebra.commutes], },
{ intros y y' h h', simp at h h', simp [mul_add, add_mul, h, h'], },
end,
smul_def' := λ r x,
begin
apply tensor_product.induction_on x,
{ simp [smul_zero], },
{ intros a b,
rw [tensor_algebra_map, ←tmul_smul, ←smul_tmul, algebra.smul_def r a],
simp, },
{ intros, dsimp, simp [smul_add, mul_add, *], },
end,
.. tensor_algebra_map,
.. (by apply_instance : semimodule R (A ⊗[R] B)) }.
@[simp]
lemma algebra_map_apply (r : R) :
(algebra_map R (A ⊗[R] B)) r = ((algebra_map R A) r) ⊗ₜ[R] 1 := rfl
variables {C : Type v₃} [semiring C] [algebra R C]
@[ext]
theorem ext {g h : (A ⊗[R] B) →ₐ[R] C}
(H : ∀ a b, g (a ⊗ₜ b) = h (a ⊗ₜ b)) : g = h :=
begin
apply @alg_hom.to_linear_map_inj R (A ⊗[R] B) C _ _ _ _ _ _ _ _,
ext,
simp [H],
end
/-- The algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
def include_left : A →ₐ[R] A ⊗[R] B :=
{ to_fun := λ a, a ⊗ₜ 1,
map_zero' := by simp,
map_add' := by simp [add_tmul],
map_one' := rfl,
map_mul' := by simp,
commutes' := by simp, }
@[simp]
lemma include_left_apply (a : A) : (include_left : A →ₐ[R] A ⊗[R] B) a = a ⊗ₜ 1 := rfl
/-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/
def include_right : B →ₐ[R] A ⊗[R] B :=
{ to_fun := λ b, 1 ⊗ₜ b,
map_zero' := by simp,
map_add' := by simp [tmul_add],
map_one' := rfl,
map_mul' := by simp,
commutes' := λ r,
begin
simp only [algebra_map_apply],
transitivity r • ((1 : A) ⊗ₜ[R] (1 : B)),
{ rw [←tmul_smul, algebra.smul_def], simp, },
{ simp [algebra.smul_def], },
end, }
@[simp]
lemma include_right_apply (b : B) : (include_right : B →ₐ[R] A ⊗[R] B) b = 1 ⊗ₜ b := rfl
end semiring
section ring
variables {R : Type u} [comm_ring R]
variables {A : Type v₁} [ring A] [algebra R A]
variables {B : Type v₂} [ring B] [algebra R B]
instance : ring (A ⊗[R] B) :=
{ .. (by apply_instance : add_comm_group (A ⊗[R] B)),
.. (by apply_instance : semiring (A ⊗[R] B)) }.
end ring
section comm_ring
variables {R : Type u} [comm_ring R]
variables {A : Type v₁} [comm_ring A] [algebra R A]
variables {B : Type v₂} [comm_ring B] [algebra R B]
instance : comm_ring (A ⊗[R] B) :=
{ mul_comm := λ x y,
begin
apply tensor_product.induction_on x,
{ simp, },
{ intros a₁ b₁,
apply tensor_product.induction_on y,
{ simp, },
{ intros a₂ b₂,
simp [mul_comm], },
{ intros a₂ b₂ ha hb,
simp [mul_add, add_mul, ha, hb], }, },
{ intros x₁ x₂ h₁ h₂,
simp [mul_add, add_mul, h₁, h₂], },
end
.. (by apply_instance : ring (A ⊗[R] B)) }.
end comm_ring
/--
Verify that typeclass search finds the ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely rings, by treating both as `ℤ`-algebras.
-/
example {A : Type v₁} [ring A] {B : Type v₂} [ring B] : ring (A ⊗[ℤ] B) :=
by apply_instance
/--
Verify that typeclass search finds the comm_ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely comm_rings, by treating both as `ℤ`-algebras.
-/
example {A : Type v₁} [comm_ring A] {B : Type v₂} [comm_ring B] : comm_ring (A ⊗[ℤ] B) :=
by apply_instance
/-!
We now build the structure maps for the symmetric monoidal category of `R`-algebras.
-/
section monoidal
section
variables {R : Type u} [comm_semiring R]
variables {A : Type v₁} [semiring A] [algebra R A]
variables {B : Type v₂} [semiring B] [algebra R B]
variables {C : Type v₃} [semiring C] [algebra R C]
variables {D : Type v₄} [semiring D] [algebra R D]
/--
Build an algebra morphism from a linear map out of a tensor product,
and evidence of multiplicativity on pure tensors.
-/
def alg_hom_of_linear_map_tensor_product
(f : A ⊗[R] B →ₗ[R] C)
(w₁ : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(w₂ : ∀ r, f ((algebra_map R A) r ⊗ₜ[R] 1) = (algebra_map R C) r):
A ⊗[R] B →ₐ[R] C :=
{ map_one' := by simpa using w₂ 1,
map_zero' := by simp,
map_mul' := λ x y,
begin
apply tensor_product.induction_on x,
{ simp, },
{ intros a₁ b₁,
apply tensor_product.induction_on y,
{ simp, },
{ intros a₂ b₂,
simp [w₁], },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [mul_add, add_mul, h₁, h₂], }, },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [mul_add, add_mul, h₁, h₂], }
end,
commutes' := λ r, by simp [w₂],
.. f }
@[simp]
lemma alg_hom_of_linear_map_tensor_product_apply (f w₁ w₂ x) :
(alg_hom_of_linear_map_tensor_product f w₁ w₂ : A ⊗[R] B →ₐ[R] C) x = f x := rfl
/--
Build an algebra equivalence from a linear equivalence out of a tensor product,
and evidence of multiplicativity on pure tensors.
-/
def alg_equiv_of_linear_equiv_tensor_product
(f : A ⊗[R] B ≃ₗ[R] C)
(w₁ : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(w₂ : ∀ r, f ((algebra_map R A) r ⊗ₜ[R] 1) = (algebra_map R C) r):
A ⊗[R] B ≃ₐ[R] C :=
{ .. alg_hom_of_linear_map_tensor_product (f : A ⊗[R] B →ₗ[R] C) w₁ w₂,
.. f }
@[simp]
lemma alg_equiv_of_linear_equiv_tensor_product_apply (f w₁ w₂ x) :
(alg_equiv_of_linear_equiv_tensor_product f w₁ w₂ : A ⊗[R] B ≃ₐ[R] C) x = f x := rfl
/--
Build an algebra equivalence from a linear equivalence out of a triple tensor product,
and evidence of multiplicativity on pure tensors.
-/
def alg_equiv_of_linear_equiv_triple_tensor_product
(f : ((A ⊗[R] B) ⊗[R] C) ≃ₗ[R] D)
(w₁ : ∀ (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C),
f ((a₁ * a₂) ⊗ₜ (b₁ * b₂) ⊗ₜ (c₁ * c₂)) = f (a₁ ⊗ₜ b₁ ⊗ₜ c₁) * f (a₂ ⊗ₜ b₂ ⊗ₜ c₂))
(w₂ : ∀ r, f (((algebra_map R A) r ⊗ₜ[R] (1 : B)) ⊗ₜ[R] (1 : C)) = (algebra_map R D) r) :
(A ⊗[R] B) ⊗[R] C ≃ₐ[R] D :=
{ map_mul' := λ x y,
begin
apply tensor_product.induction_on x,
{ simp, },
{ intros ab₁ c₁,
apply tensor_product.induction_on y,
{ simp, },
{ intros ab₂ c₂,
apply tensor_product.induction_on ab₁,
{ simp, },
{ intros a₁ b₁,
apply tensor_product.induction_on ab₂,
{ simp, },
{ simp [w₁], },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [mul_add, add_tmul, h₁, h₂], }, },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [add_mul, add_tmul, h₁, h₂], }, },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [mul_add, add_mul, h₁, h₂], }, },
{ intros x₁ x₂ h₁ h₂,
simp at h₁, simp at h₂,
simp [mul_add, add_mul, h₁, h₂], }
end,
commutes' := λ r, by simp [w₂],
.. f }
@[simp]
lemma alg_equiv_of_linear_equiv_triple_tensor_product_apply (f w₁ w₂ x) :
(alg_equiv_of_linear_equiv_triple_tensor_product f w₁ w₂ : (A ⊗[R] B) ⊗[R] C ≃ₐ[R] D) x = f x :=
rfl
end
variables {R : Type u} [comm_semiring R]
variables {A : Type v₁} [semiring A] [algebra R A]
variables {B : Type v₂} [semiring B] [algebra R B]
variables {C : Type v₃} [semiring C] [algebra R C]
variables {D : Type v₄} [semiring D] [algebra R D]
section
variables (R A)
/--
The base ring is a left identity for the tensor product of algebra, up to algebra isomorphism.
-/
protected def lid : R ⊗[R] A ≃ₐ[R] A :=
alg_equiv_of_linear_equiv_tensor_product (tensor_product.lid R A)
(by simp [mul_smul]) (by simp [algebra.smul_def])
@[simp] theorem lid_tmul (r : R) (a : A) :
(tensor_product.lid R A : (R ⊗ A → A)) (r ⊗ₜ a) = r • a :=
by simp [tensor_product.lid]
/--
The base ring is a right identity for the tensor product of algebra, up to algebra isomorphism.
-/
protected def rid : A ⊗[R] R ≃ₐ[R] A :=
alg_equiv_of_linear_equiv_tensor_product (tensor_product.rid R A)
(by simp [mul_smul]) (by simp [algebra.smul_def])
@[simp] theorem rid_tmul (r : R) (a : A) :
(tensor_product.rid R A : (A ⊗ R → A)) (a ⊗ₜ r) = r • a :=
by simp [tensor_product.rid]
section
variables (R A B)
/--
The tensor product of R-algebras is commutative, up to algebra isomorphism.
-/
protected def comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A :=
alg_equiv_of_linear_equiv_tensor_product (tensor_product.comm R A B)
(by simp)
(λ r, begin
transitivity r • ((1 : B) ⊗ₜ[R] (1 : A)),
{ rw [←tmul_smul, algebra.smul_def], simp, },
{ simp [algebra.smul_def], },
end)
@[simp]
theorem comm_tmul (a : A) (b : B) :
(tensor_product.comm R A B : (A ⊗[R] B → B ⊗[R] A)) (a ⊗ₜ b) = (b ⊗ₜ a) :=
by simp [tensor_product.comm]
end
section
variables {R A B C}
lemma assoc_aux_1 (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C) :
(tensor_product.assoc R A B C) (((a₁ * a₂) ⊗ₜ[R] b₁ * b₂) ⊗ₜ[R] c₁ * c₂) =
(tensor_product.assoc R A B C) ((a₁ ⊗ₜ[R] b₁) ⊗ₜ[R] c₁) *
(tensor_product.assoc R A B C) ((a₂ ⊗ₜ[R] b₂) ⊗ₜ[R] c₂) :=
rfl
lemma assoc_aux_2 (r : R) :
(tensor_product.assoc R A B C) (((algebra_map R A) r ⊗ₜ[R] 1) ⊗ₜ[R] 1) =
(algebra_map R (A ⊗ (B ⊗ C))) r := rfl
-- variables (R A B C)
-- -- local attribute [elab_simple] alg_equiv_of_linear_equiv_triple_tensor_product
-- /-- The associator for tensor product of R-algebras, as an algebra isomorphism. -/
-- -- FIXME This is _really_ slow to compile. :-(
-- protected def assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C)) :=
-- alg_equiv_of_linear_equiv_triple_tensor_product
-- (tensor_product.assoc R A B C)
-- assoc_aux_1 assoc_aux_2
-- variables {R A B C}
-- @[simp] theorem assoc_tmul (a : A) (b : B) (c : C) :
-- ((tensor_product.assoc R A B C) : (A ⊗[R] B) ⊗[R] C → A ⊗[R] (B ⊗[R] C)) ((a ⊗ₜ b) ⊗ₜ c) = a ⊗ₜ (b ⊗ₜ c) :=
-- rfl
end
variables {R A B C D}
/-- The tensor product of a pair of algebra morphisms. -/
def map (f : A →ₐ[R] B) (g : C →ₐ[R] D) : A ⊗[R] C →ₐ[R] B ⊗[R] D :=
alg_hom_of_linear_map_tensor_product
(tensor_product.map f.to_linear_map g.to_linear_map)
(by simp)
(by simp [alg_hom.commutes])
@[simp] theorem map_tmul (f : A →ₐ[R] B) (g : C →ₐ[R] D) (a : A) (c : C) :
map f g (a ⊗ₜ c) = f a ⊗ₜ g c :=
rfl
/--
Construct an isomorphism between tensor products of R-algebras
from isomorphisms between the tensor factors.
-/
def congr (f : A ≃ₐ[R] B) (g : C ≃ₐ[R] D) : A ⊗[R] C ≃ₐ[R] B ⊗[R] D :=
alg_equiv.of_alg_hom (map f g) (map f.symm g.symm)
(ext $ λ b d, by simp)
(ext $ λ a c, by simp)
@[simp]
lemma congr_apply (f : A ≃ₐ[R] B) (g : C ≃ₐ[R] D) (x) :
congr f g x = (map (f : A →ₐ[R] B) (g : C →ₐ[R] D)) x := rfl
@[simp]
lemma congr_symm_apply (f : A ≃ₐ[R] B) (g : C ≃ₐ[R] D) (x) :
(congr f g).symm x = (map (f.symm : B →ₐ[R] A) (g.symm : D →ₐ[R] C)) x := rfl
end
end monoidal
end tensor_product
end algebra
|
c691ed4df0de8d41904d3e742556f89b1c772e23
|
4950bf76e5ae40ba9f8491647d0b6f228ddce173
|
/src/data/matrix/basic.lean
|
a98d8ce39f26f0e78bdfe1913f1312bc4de0058a
|
[
"Apache-2.0"
] |
permissive
|
ntzwq/mathlib
|
ca50b21079b0a7c6781c34b62199a396dd00cee2
|
36eec1a98f22df82eaccd354a758ef8576af2a7f
|
refs/heads/master
| 1,675,193,391,478
| 1,607,822,996,000
| 1,607,822,996,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 42,236
|
lean
|
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin
-/
import algebra.big_operators.pi
import algebra.module.pi
import algebra.module.linear_map
import algebra.big_operators.ring
import algebra.star.basic
import data.equiv.ring
import data.fintype.card
/-!
# Matrices
-/
universes u u' v w
open_locale big_operators
/-- `matrix m n` is the type of matrices whose rows are indexed by the fintype `m`
and whose columns are indexed by the fintype `n`. -/
@[nolint unused_arguments]
def matrix (m : Type u) (n : Type u') [fintype m] [fintype n] (α : Type v) : Type (max u u' v) :=
m → n → α
variables {l m n o : Type*} [fintype l] [fintype m] [fintype n] [fintype o]
variables {α : Type v}
namespace matrix
section ext
variables {M N : matrix m n α}
theorem ext_iff : (∀ i j, M i j = N i j) ↔ M = N :=
⟨λ h, funext $ λ i, funext $ h i, λ h, by simp [h]⟩
@[ext] theorem ext : (∀ i j, M i j = N i j) → M = N :=
ext_iff.mp
end ext
/-- `M.map f` is the matrix obtained by applying `f` to each entry of the matrix `M`. -/
def map (M : matrix m n α) {β : Type w} (f : α → β) : matrix m n β := λ i j, f (M i j)
@[simp]
lemma map_apply {M : matrix m n α} {β : Type w} {f : α → β} {i : m} {j : n} :
M.map f i j = f (M i j) := rfl
@[simp]
lemma map_map {M : matrix m n α} {β γ : Type*} {f : α → β} {g : β → γ} :
(M.map f).map g = M.map (g ∘ f) :=
by { ext, simp, }
/-- The transpose of a matrix. -/
def transpose (M : matrix m n α) : matrix n m α
| x y := M y x
localized "postfix `ᵀ`:1500 := matrix.transpose" in matrix
/-- `matrix.col u` is the column matrix whose entries are given by `u`. -/
def col (w : m → α) : matrix m unit α
| x y := w x
/-- `matrix.row u` is the row matrix whose entries are given by `u`. -/
def row (v : n → α) : matrix unit n α
| x y := v y
instance [inhabited α] : inhabited (matrix m n α) := pi.inhabited _
instance [has_add α] : has_add (matrix m n α) := pi.has_add
instance [add_semigroup α] : add_semigroup (matrix m n α) := pi.add_semigroup
instance [add_comm_semigroup α] : add_comm_semigroup (matrix m n α) := pi.add_comm_semigroup
instance [has_zero α] : has_zero (matrix m n α) := pi.has_zero
instance [add_monoid α] : add_monoid (matrix m n α) := pi.add_monoid
instance [add_comm_monoid α] : add_comm_monoid (matrix m n α) := pi.add_comm_monoid
instance [has_neg α] : has_neg (matrix m n α) := pi.has_neg
instance [add_group α] : add_group (matrix m n α) := pi.add_group
instance [add_comm_group α] : add_comm_group (matrix m n α) := pi.add_comm_group
@[simp] theorem zero_apply [has_zero α] (i j) :
(0 : matrix m n α) i j = 0 :=
rfl
@[simp] theorem neg_apply [has_neg α] (M : matrix m n α) (i j) :
(- M) i j = - M i j :=
rfl
@[simp] theorem add_apply [has_add α] (M N : matrix m n α) (i j) :
(M + N) i j = M i j + N i j :=
rfl
-- TODO: this should assume `has_sub α` when we fix the `add_group -> has_sub` diamond issue
@[simp] theorem sub_apply [add_group α] (M N : matrix m n α) (i j) :
(M - N) i j = M i j - N i j :=
rfl
@[simp] lemma map_zero [has_zero α] {β : Type w} [has_zero β] {f : α → β} (h : f 0 = 0) :
(0 : matrix m n α).map f = 0 :=
by { ext, simp [h], }
lemma map_add [add_monoid α] {β : Type w} [add_monoid β] (f : α →+ β)
(M N : matrix m n α) : (M + N).map f = M.map f + N.map f :=
by { ext, simp, }
lemma map_sub [add_group α] {β : Type w} [add_group β] (f : α →+ β)
(M N : matrix m n α) : (M - N).map f = M.map f - N.map f :=
by { ext, simp }
lemma subsingleton_of_empty_left (hm : ¬ nonempty m) : subsingleton (matrix m n α) :=
⟨λ M N, by { ext, contrapose! hm, use i }⟩
lemma subsingleton_of_empty_right (hn : ¬ nonempty n) : subsingleton (matrix m n α) :=
⟨λ M N, by { ext, contrapose! hn, use j }⟩
end matrix
/-- The `add_monoid_hom` between spaces of matrices induced by an `add_monoid_hom` between their
coefficients. -/
def add_monoid_hom.map_matrix [add_monoid α] {β : Type w} [add_monoid β] (f : α →+ β) :
matrix m n α →+ matrix m n β :=
{ to_fun := λ M, M.map f,
map_zero' := by simp,
map_add' := matrix.map_add f, }
@[simp] lemma add_monoid_hom.map_matrix_apply [add_monoid α] {β : Type w} [add_monoid β]
(f : α →+ β) (M : matrix m n α) : f.map_matrix M = M.map f := rfl
open_locale matrix
namespace matrix
section diagonal
variables [decidable_eq n]
/-- `diagonal d` is the square matrix such that `(diagonal d) i i = d i` and `(diagonal d) i j = 0`
if `i ≠ j`. -/
def diagonal [has_zero α] (d : n → α) : matrix n n α := λ i j, if i = j then d i else 0
@[simp] theorem diagonal_apply_eq [has_zero α] {d : n → α} (i : n) : (diagonal d) i i = d i :=
by simp [diagonal]
@[simp] theorem diagonal_apply_ne [has_zero α] {d : n → α} {i j : n} (h : i ≠ j) :
(diagonal d) i j = 0 := by simp [diagonal, h]
theorem diagonal_apply_ne' [has_zero α] {d : n → α} {i j : n} (h : j ≠ i) :
(diagonal d) i j = 0 := diagonal_apply_ne h.symm
@[simp] theorem diagonal_zero [has_zero α] : (diagonal (λ _, 0) : matrix n n α) = 0 :=
by simp [diagonal]; refl
@[simp] lemma diagonal_transpose [has_zero α] (v : n → α) :
(diagonal v)ᵀ = diagonal v :=
begin
ext i j,
by_cases h : i = j,
{ simp [h, transpose] },
{ simp [h, transpose, diagonal_apply_ne' h] }
end
@[simp] theorem diagonal_add [add_monoid α] (d₁ d₂ : n → α) :
diagonal d₁ + diagonal d₂ = diagonal (λ i, d₁ i + d₂ i) :=
by ext i j; by_cases h : i = j; simp [h]
@[simp] lemma diagonal_map {β : Type w} [has_zero α] [has_zero β]
{f : α → β} (h : f 0 = 0) {d : n → α} :
(diagonal d).map f = diagonal (λ m, f (d m)) :=
by { ext, simp only [diagonal, map_apply], split_ifs; simp [h], }
section one
variables [has_zero α] [has_one α]
instance : has_one (matrix n n α) := ⟨diagonal (λ _, 1)⟩
@[simp] theorem diagonal_one : (diagonal (λ _, 1) : matrix n n α) = 1 := rfl
theorem one_apply {i j} : (1 : matrix n n α) i j = if i = j then 1 else 0 := rfl
@[simp] theorem one_apply_eq (i) : (1 : matrix n n α) i i = 1 := diagonal_apply_eq i
@[simp] theorem one_apply_ne {i j} : i ≠ j → (1 : matrix n n α) i j = 0 :=
diagonal_apply_ne
theorem one_apply_ne' {i j} : j ≠ i → (1 : matrix n n α) i j = 0 :=
diagonal_apply_ne'
@[simp] lemma one_map {β : Type w} [has_zero β] [has_one β]
{f : α → β} (h₀ : f 0 = 0) (h₁ : f 1 = 1) :
(1 : matrix n n α).map f = (1 : matrix n n β) :=
by { ext, simp only [one_apply, map_apply], split_ifs; simp [h₀, h₁], }
end one
section numeral
@[simp] lemma bit0_apply [has_add α] (M : matrix m m α) (i : m) (j : m) :
(bit0 M) i j = bit0 (M i j) := rfl
variables [add_monoid α] [has_one α]
lemma bit1_apply (M : matrix n n α) (i : n) (j : n) :
(bit1 M) i j = if i = j then bit1 (M i j) else bit0 (M i j) :=
by dsimp [bit1]; by_cases h : i = j; simp [h]
@[simp]
lemma bit1_apply_eq (M : matrix n n α) (i : n) :
(bit1 M) i i = bit1 (M i i) :=
by simp [bit1_apply]
@[simp]
lemma bit1_apply_ne (M : matrix n n α) {i j : n} (h : i ≠ j) :
(bit1 M) i j = bit0 (M i j) :=
by simp [bit1_apply, h]
end numeral
end diagonal
section dot_product
/-- `dot_product v w` is the sum of the entrywise products `v i * w i` -/
def dot_product [has_mul α] [add_comm_monoid α] (v w : m → α) : α :=
∑ i, v i * w i
lemma dot_product_assoc [semiring α] (u : m → α) (v : m → n → α) (w : n → α) :
dot_product (λ j, dot_product u (λ i, v i j)) w = dot_product u (λ i, dot_product (v i) w) :=
by simpa [dot_product, finset.mul_sum, finset.sum_mul, mul_assoc] using finset.sum_comm
lemma dot_product_comm [comm_semiring α] (v w : m → α) :
dot_product v w = dot_product w v :=
by simp_rw [dot_product, mul_comm]
@[simp] lemma dot_product_punit [add_comm_monoid α] [has_mul α] (v w : punit → α) :
dot_product v w = v ⟨⟩ * w ⟨⟩ :=
by simp [dot_product]
@[simp] lemma dot_product_zero [semiring α] (v : m → α) : dot_product v 0 = 0 :=
by simp [dot_product]
@[simp] lemma dot_product_zero' [semiring α] (v : m → α) : dot_product v (λ _, 0) = 0 :=
dot_product_zero v
@[simp] lemma zero_dot_product [semiring α] (v : m → α) : dot_product 0 v = 0 :=
by simp [dot_product]
@[simp] lemma zero_dot_product' [semiring α] (v : m → α) : dot_product (λ _, (0 : α)) v = 0 :=
zero_dot_product v
@[simp] lemma add_dot_product [semiring α] (u v w : m → α) :
dot_product (u + v) w = dot_product u w + dot_product v w :=
by simp [dot_product, add_mul, finset.sum_add_distrib]
@[simp] lemma dot_product_add [semiring α] (u v w : m → α) :
dot_product u (v + w) = dot_product u v + dot_product u w :=
by simp [dot_product, mul_add, finset.sum_add_distrib]
@[simp] lemma diagonal_dot_product [decidable_eq m] [semiring α] (v w : m → α) (i : m) :
dot_product (diagonal v i) w = v i * w i :=
have ∀ j ≠ i, diagonal v i j * w j = 0 := λ j hij, by simp [diagonal_apply_ne' hij],
by convert finset.sum_eq_single i (λ j _, this j) _; simp
@[simp] lemma dot_product_diagonal [decidable_eq m] [semiring α] (v w : m → α) (i : m) :
dot_product v (diagonal w i) = v i * w i :=
have ∀ j ≠ i, v j * diagonal w i j = 0 := λ j hij, by simp [diagonal_apply_ne' hij],
by convert finset.sum_eq_single i (λ j _, this j) _; simp
@[simp] lemma dot_product_diagonal' [decidable_eq m] [semiring α] (v w : m → α) (i : m) :
dot_product v (λ j, diagonal w j i) = v i * w i :=
have ∀ j ≠ i, v j * diagonal w j i = 0 := λ j hij, by simp [diagonal_apply_ne hij],
by convert finset.sum_eq_single i (λ j _, this j) _; simp
@[simp] lemma neg_dot_product [ring α] (v w : m → α) : dot_product (-v) w = - dot_product v w :=
by simp [dot_product]
@[simp] lemma dot_product_neg [ring α] (v w : m → α) : dot_product v (-w) = - dot_product v w :=
by simp [dot_product]
@[simp] lemma smul_dot_product [semiring α] (x : α) (v w : m → α) :
dot_product (x • v) w = x * dot_product v w :=
by simp [dot_product, finset.mul_sum, mul_assoc]
@[simp] lemma dot_product_smul [comm_semiring α] (x : α) (v w : m → α) :
dot_product v (x • w) = x * dot_product v w :=
by simp [dot_product, finset.mul_sum, mul_assoc, mul_comm, mul_left_comm]
end dot_product
/-- `M ⬝ N` is the usual product of matrices `M` and `N`, i.e. we have that
`(M ⬝ N) i k` is the dot product of the `i`-th row of `M` by the `k`-th column of `Ǹ`. -/
protected def mul [has_mul α] [add_comm_monoid α] (M : matrix l m α) (N : matrix m n α) :
matrix l n α :=
λ i k, dot_product (λ j, M i j) (λ j, N j k)
localized "infixl ` ⬝ `:75 := matrix.mul" in matrix
theorem mul_apply [has_mul α] [add_comm_monoid α] {M : matrix l m α} {N : matrix m n α} {i k} :
(M ⬝ N) i k = ∑ j, M i j * N j k := rfl
instance [has_mul α] [add_comm_monoid α] : has_mul (matrix n n α) := ⟨matrix.mul⟩
@[simp] theorem mul_eq_mul [has_mul α] [add_comm_monoid α] (M N : matrix n n α) :
M * N = M ⬝ N := rfl
theorem mul_apply' [has_mul α] [add_comm_monoid α] {M N : matrix n n α} {i k} :
(M ⬝ N) i k = dot_product (λ j, M i j) (λ j, N j k) := rfl
section semigroup
variables [semiring α]
protected theorem mul_assoc (L : matrix l m α) (M : matrix m n α) (N : matrix n o α) :
(L ⬝ M) ⬝ N = L ⬝ (M ⬝ N) :=
by { ext, apply dot_product_assoc }
instance : semigroup (matrix n n α) :=
{ mul_assoc := matrix.mul_assoc, ..matrix.has_mul }
end semigroup
@[simp] theorem diagonal_neg [decidable_eq n] [add_group α] (d : n → α) :
-diagonal d = diagonal (λ i, -d i) :=
by ext i j; by_cases i = j; simp [h]
section semiring
variables [semiring α]
@[simp] protected theorem mul_zero (M : matrix m n α) : M ⬝ (0 : matrix n o α) = 0 :=
by { ext i j, apply dot_product_zero }
@[simp] protected theorem zero_mul (M : matrix m n α) : (0 : matrix l m α) ⬝ M = 0 :=
by { ext i j, apply zero_dot_product }
protected theorem mul_add (L : matrix m n α) (M N : matrix n o α) : L ⬝ (M + N) = L ⬝ M + L ⬝ N :=
by { ext i j, apply dot_product_add }
protected theorem add_mul (L M : matrix l m α) (N : matrix m n α) : (L + M) ⬝ N = L ⬝ N + M ⬝ N :=
by { ext i j, apply add_dot_product }
@[simp] theorem diagonal_mul [decidable_eq m]
(d : m → α) (M : matrix m n α) (i j) : (diagonal d).mul M i j = d i * M i j :=
diagonal_dot_product _ _ _
@[simp] theorem mul_diagonal [decidable_eq n]
(d : n → α) (M : matrix m n α) (i j) : (M ⬝ diagonal d) i j = M i j * d j :=
by { rw ← diagonal_transpose, apply dot_product_diagonal }
@[simp] protected theorem one_mul [decidable_eq m] (M : matrix m n α) : (1 : matrix m m α) ⬝ M = M :=
by ext i j; rw [← diagonal_one, diagonal_mul, one_mul]
@[simp] protected theorem mul_one [decidable_eq n] (M : matrix m n α) : M ⬝ (1 : matrix n n α) = M :=
by ext i j; rw [← diagonal_one, mul_diagonal, mul_one]
instance [decidable_eq n] : monoid (matrix n n α) :=
{ one_mul := matrix.one_mul,
mul_one := matrix.mul_one,
..matrix.has_one, ..matrix.semigroup }
instance [decidable_eq n] : semiring (matrix n n α) :=
{ mul_zero := matrix.mul_zero,
zero_mul := matrix.zero_mul,
left_distrib := matrix.mul_add,
right_distrib := matrix.add_mul,
..matrix.add_comm_monoid,
..matrix.monoid }
@[simp] theorem diagonal_mul_diagonal [decidable_eq n] (d₁ d₂ : n → α) :
(diagonal d₁) ⬝ (diagonal d₂) = diagonal (λ i, d₁ i * d₂ i) :=
by ext i j; by_cases i = j; simp [h]
theorem diagonal_mul_diagonal' [decidable_eq n] (d₁ d₂ : n → α) :
diagonal d₁ * diagonal d₂ = diagonal (λ i, d₁ i * d₂ i) :=
diagonal_mul_diagonal _ _
@[simp]
lemma map_mul {L : matrix m n α} {M : matrix n o α}
{β : Type w} [semiring β] {f : α →+* β} :
(L ⬝ M).map f = L.map f ⬝ M.map f :=
by { ext, simp [mul_apply, ring_hom.map_sum], }
-- TODO: there should be a way to avoid restating these for each `foo_hom`.
/-- A version of `one_map` where `f` is a ring hom. -/
@[simp] lemma ring_hom_map_one [decidable_eq n]
{β : Type w} [semiring β] (f : α →+* β) :
(1 : matrix n n α).map f = 1 :=
one_map f.map_zero f.map_one
/-- A version of `one_map` where `f` is a `ring_equiv`. -/
@[simp] lemma ring_equiv_map_one [decidable_eq n]
{β : Type w} [semiring β] (f : α ≃+* β) :
(1 : matrix n n α).map f = 1 :=
one_map f.map_zero f.map_one
/-- A version of `map_zero` where `f` is a `zero_hom`. -/
@[simp] lemma zero_hom_map_zero
{β : Type w} [has_zero β] (f : zero_hom α β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `add_monoid_hom`. -/
@[simp] lemma add_monoid_hom_map_zero
{β : Type w} [add_monoid β] (f : α →+ β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `add_equiv`. -/
@[simp] lemma add_equiv_map_zero
{β : Type w} [add_monoid β] (f : α ≃+ β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `linear_map`. -/
@[simp] lemma linear_map_map_zero {R : Type*} [semiring R]
{β : Type w} [add_comm_monoid β] [semimodule R α] [semimodule R β] (f : α →ₗ[R] β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `linear_equiv`. -/
@[simp] lemma linear_equiv_map_zero {R : Type*} [semiring R]
{β : Type w} [add_comm_monoid β] [semimodule R α] [semimodule R β] (f : α ≃ₗ[R] β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `ring_hom`. -/
@[simp] lemma ring_hom_map_zero
{β : Type w} [semiring β] (f : α →+* β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
/-- A version of `map_zero` where `f` is a `ring_equiv`. -/
@[simp] lemma ring_equiv_map_zero
{β : Type w} [semiring β] (f : α ≃+* β) :
(0 : matrix n n α).map f = 0 :=
map_zero f.map_zero
lemma is_add_monoid_hom_mul_left (M : matrix l m α) :
is_add_monoid_hom (λ x : matrix m n α, M ⬝ x) :=
{ to_is_add_hom := ⟨matrix.mul_add _⟩, map_zero := matrix.mul_zero _ }
lemma is_add_monoid_hom_mul_right (M : matrix m n α) :
is_add_monoid_hom (λ x : matrix l m α, x ⬝ M) :=
{ to_is_add_hom := ⟨λ _ _, matrix.add_mul _ _ _⟩, map_zero := matrix.zero_mul _ }
protected lemma sum_mul {β : Type*} (s : finset β) (f : β → matrix l m α)
(M : matrix m n α) : (∑ a in s, f a) ⬝ M = ∑ a in s, f a ⬝ M :=
(@finset.sum_hom _ _ _ _ _ s f (λ x, x ⬝ M)
/- This line does not type-check without `id` and `: _`. Lean did not recognize that two different
`add_monoid` instances were def-eq -/
(id (@is_add_monoid_hom_mul_right l _ _ _ _ _ _ _ M) : _)).symm
protected lemma mul_sum {β : Type*} (s : finset β) (f : β → matrix m n α)
(M : matrix l m α) : M ⬝ ∑ a in s, f a = ∑ a in s, M ⬝ f a :=
(@finset.sum_hom _ _ _ _ _ s f (λ x, M ⬝ x)
/- This line does not type-check without `id` and `: _`. Lean did not recognize that two different
`add_monoid` instances were def-eq -/
(id (@is_add_monoid_hom_mul_left _ _ n _ _ _ _ _ M) : _)).symm
@[simp]
lemma row_mul_col_apply (v w : m → α) (i j) : (row v ⬝ col w) i j = dot_product v w :=
rfl
end semiring
end matrix
/-- The `ring_hom` between spaces of square matrices induced by a `ring_hom` between their
coefficients. -/
def ring_hom.map_matrix [decidable_eq m] [semiring α] {β : Type w} [semiring β] (f : α →+* β) :
matrix m m α →+* matrix m m β :=
{ to_fun := λ M, M.map f,
map_one' := by simp,
map_mul' := λ L M, matrix.map_mul,
..(f.to_add_monoid_hom).map_matrix }
@[simp] lemma ring_hom.map_matrix_apply [decidable_eq m] [semiring α] {β : Type w} [semiring β]
(f : α →+* β) (M : matrix m m α) : f.map_matrix M = M.map f := rfl
open_locale matrix
namespace matrix
section ring
variables [ring α]
@[simp] theorem neg_mul (M : matrix m n α) (N : matrix n o α) :
(-M) ⬝ N = -(M ⬝ N) :=
by { ext, apply neg_dot_product }
@[simp] theorem mul_neg (M : matrix m n α) (N : matrix n o α) :
M ⬝ (-N) = -(M ⬝ N) :=
by { ext, apply dot_product_neg }
protected theorem sub_mul (M M' : matrix m n α) (N : matrix n o α) :
(M - M') ⬝ N = M ⬝ N - M' ⬝ N :=
by rw [sub_eq_add_neg, matrix.add_mul, neg_mul, sub_eq_add_neg]
protected theorem mul_sub (M : matrix m n α) (N N' : matrix n o α) :
M ⬝ (N - N') = M ⬝ N - M ⬝ N' :=
by rw [sub_eq_add_neg, matrix.mul_add, mul_neg, sub_eq_add_neg]
end ring
instance [decidable_eq n] [ring α] : ring (matrix n n α) :=
{ ..matrix.semiring, ..matrix.add_comm_group }
instance [semiring α] : has_scalar α (matrix m n α) := pi.has_scalar
instance {β : Type w} [semiring α] [add_comm_monoid β] [semimodule α β] :
semimodule α (matrix m n β) := pi.semimodule _ _ _
@[simp] lemma smul_apply [semiring α] (a : α) (A : matrix m n α) (i : m) (j : n) : (a • A) i j = a * A i j := rfl
section semiring
variables [semiring α]
lemma smul_eq_diagonal_mul [decidable_eq m] (M : matrix m n α) (a : α) :
a • M = diagonal (λ _, a) ⬝ M :=
by { ext, simp }
@[simp] lemma smul_mul (M : matrix m n α) (a : α) (N : matrix n l α) : (a • M) ⬝ N = a • M ⬝ N :=
by { ext, apply smul_dot_product }
@[simp] lemma mul_mul_left (M : matrix m n α) (N : matrix n o α) (a : α) :
(λ i j, a * M i j) ⬝ N = a • (M ⬝ N) :=
begin
simp only [←smul_apply],
simp,
end
/--
The ring homomorphism `α →+* matrix n n α`
sending `a` to the diagonal matrix with `a` on the diagonal.
-/
def scalar (n : Type u) [decidable_eq n] [fintype n] : α →+* matrix n n α :=
{ to_fun := λ a, a • 1,
map_zero' := by simp,
map_add' := by { intros, ext, simp [add_mul], },
map_one' := by simp,
map_mul' := by { intros, ext, simp [mul_assoc], }, }
section scalar
variable [decidable_eq n]
@[simp] lemma coe_scalar : (scalar n : α → matrix n n α) = λ a, a • 1 := rfl
lemma scalar_apply_eq (a : α) (i : n) :
scalar n a i i = a :=
by simp only [coe_scalar, mul_one, one_apply_eq, smul_apply]
lemma scalar_apply_ne (a : α) (i j : n) (h : i ≠ j) :
scalar n a i j = 0 :=
by simp only [h, coe_scalar, one_apply_ne, ne.def, not_false_iff, smul_apply, mul_zero]
lemma scalar_inj [nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s :=
begin
split,
{ intro h,
inhabit n,
rw [← scalar_apply_eq r (arbitrary n), ← scalar_apply_eq s (arbitrary n), h] },
{ rintro rfl, refl }
end
end scalar
end semiring
section comm_semiring
variables [comm_semiring α]
lemma smul_eq_mul_diagonal [decidable_eq n] (M : matrix m n α) (a : α) :
a • M = M ⬝ diagonal (λ _, a) :=
by { ext, simp [mul_comm] }
@[simp] lemma mul_smul (M : matrix m n α) (a : α) (N : matrix n l α) : M ⬝ (a • N) = a • M ⬝ N :=
by { ext, apply dot_product_smul }
@[simp] lemma mul_mul_right (M : matrix m n α) (N : matrix n o α) (a : α) :
M ⬝ (λ i j, a * N i j) = a • (M ⬝ N) :=
begin
simp only [←smul_apply],
simp,
end
lemma scalar.commute [decidable_eq n] (r : α) (M : matrix n n α) : commute (scalar n r) M :=
by simp [commute, semiconj_by]
end comm_semiring
section semiring
variables [semiring α]
/-- For two vectors `w` and `v`, `vec_mul_vec w v i j` is defined to be `w i * v j`.
Put another way, `vec_mul_vec w v` is exactly `col w ⬝ row v`. -/
def vec_mul_vec (w : m → α) (v : n → α) : matrix m n α
| x y := w x * v y
/-- `mul_vec M v` is the matrix-vector product of `M` and `v`, where `v` is seen as a column matrix.
Put another way, `mul_vec M v` is the vector whose entries
are those of `M ⬝ col v` (see `col_mul_vec`). -/
def mul_vec (M : matrix m n α) (v : n → α) : m → α
| i := dot_product (λ j, M i j) v
/-- `vec_mul v M` is the vector-matrix product of `v` and `M`, where `v` is seen as a row matrix.
Put another way, `vec_mul v M` is the vector whose entries
are those of `row v ⬝ M` (see `row_vec_mul`). -/
def vec_mul (v : m → α) (M : matrix m n α) : n → α
| j := dot_product v (λ i, M i j)
instance mul_vec.is_add_monoid_hom_left (v : n → α) :
is_add_monoid_hom (λM:matrix m n α, mul_vec M v) :=
{ map_zero := by ext; simp [mul_vec]; refl,
map_add :=
begin
intros x y,
ext m,
apply add_dot_product
end }
lemma mul_vec_diagonal [decidable_eq m] (v w : m → α) (x : m) :
mul_vec (diagonal v) w x = v x * w x :=
diagonal_dot_product v w x
lemma vec_mul_diagonal [decidable_eq m] (v w : m → α) (x : m) :
vec_mul v (diagonal w) x = v x * w x :=
dot_product_diagonal' v w x
@[simp] lemma mul_vec_one [decidable_eq m] (v : m → α) : mul_vec 1 v = v :=
by { ext, rw [←diagonal_one, mul_vec_diagonal, one_mul] }
@[simp] lemma vec_mul_one [decidable_eq m] (v : m → α) : vec_mul v 1 = v :=
by { ext, rw [←diagonal_one, vec_mul_diagonal, mul_one] }
@[simp] lemma mul_vec_zero (A : matrix m n α) : mul_vec A 0 = 0 :=
by { ext, simp [mul_vec] }
@[simp] lemma vec_mul_zero (A : matrix m n α) : vec_mul 0 A = 0 :=
by { ext, simp [vec_mul] }
@[simp] lemma vec_mul_vec_mul (v : m → α) (M : matrix m n α) (N : matrix n o α) :
vec_mul (vec_mul v M) N = vec_mul v (M ⬝ N) :=
by { ext, apply dot_product_assoc }
@[simp] lemma mul_vec_mul_vec (v : o → α) (M : matrix m n α) (N : matrix n o α) :
mul_vec M (mul_vec N v) = mul_vec (M ⬝ N) v :=
by { ext, symmetry, apply dot_product_assoc }
lemma vec_mul_vec_eq (w : m → α) (v : n → α) :
vec_mul_vec w v = (col w) ⬝ (row v) :=
by { ext i j, simp [vec_mul_vec, mul_apply], refl }
variables [decidable_eq m] [decidable_eq n]
/--
`std_basis_matrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column,
and zeroes elsewhere.
-/
def std_basis_matrix (i : m) (j : n) (a : α) : matrix m n α :=
(λ i' j', if i' = i ∧ j' = j then a else 0)
@[simp] lemma smul_std_basis_matrix (i : m) (j : n) (a b : α) :
b • std_basis_matrix i j a = std_basis_matrix i j (b • a) :=
by { unfold std_basis_matrix, ext, simp }
@[simp] lemma std_basis_matrix_zero (i : m) (j : n) :
std_basis_matrix i j (0 : α) = 0 :=
by { unfold std_basis_matrix, ext, simp }
lemma std_basis_matrix_add (i : m) (j : n) (a b : α) :
std_basis_matrix i j (a + b) = std_basis_matrix i j a + std_basis_matrix i j b :=
begin
unfold std_basis_matrix, ext,
split_ifs with h; simp [h],
end
lemma matrix_eq_sum_std_basis (x : matrix n m α) :
x = ∑ (i : n) (j : m), std_basis_matrix i j (x i j) :=
begin
ext, symmetry,
iterate 2 { rw finset.sum_apply },
convert fintype.sum_eq_single i _,
{ simp [std_basis_matrix] },
{ intros j hj,
simp [std_basis_matrix, hj.symm] }
end
-- TODO: tie this up with the `basis` machinery of linear algebra
-- this is not completely trivial because we are indexing by two types, instead of one
-- TODO: add `std_basis_vec`
lemma std_basis_eq_basis_mul_basis (i : m) (j : n) :
std_basis_matrix i j 1 = vec_mul_vec (λ i', ite (i = i') 1 0) (λ j', ite (j = j') 1 0) :=
begin
ext, norm_num [std_basis_matrix, vec_mul_vec],
split_ifs; tauto,
end
@[elab_as_eliminator] protected lemma induction_on'
{X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
(h_zero : M 0)
(h_add : ∀p q, M p → M q → M (p + q))
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
M m :=
begin
rw [matrix_eq_sum_std_basis m, ← finset.sum_product'],
apply finset.sum_induction _ _ h_add h_zero,
{ intros, apply h_std_basis, }
end
@[elab_as_eliminator] protected lemma induction_on
[nonempty n] {X : Type*} [semiring X] {M : matrix n n X → Prop} (m : matrix n n X)
(h_add : ∀p q, M p → M q → M (p + q))
(h_std_basis : ∀ i j x, M (std_basis_matrix i j x)) :
M m :=
matrix.induction_on' m
begin
have i : n := classical.choice (by assumption),
simpa using h_std_basis i i 0,
end
h_add h_std_basis
end semiring
section ring
variables [ring α]
lemma neg_vec_mul (v : m → α) (A : matrix m n α) : vec_mul (-v) A = - vec_mul v A :=
by { ext, apply neg_dot_product }
lemma vec_mul_neg (v : m → α) (A : matrix m n α) : vec_mul v (-A) = - vec_mul v A :=
by { ext, apply dot_product_neg }
lemma neg_mul_vec (v : n → α) (A : matrix m n α) : mul_vec (-A) v = - mul_vec A v :=
by { ext, apply neg_dot_product }
lemma mul_vec_neg (v : n → α) (A : matrix m n α) : mul_vec A (-v) = - mul_vec A v :=
by { ext, apply dot_product_neg }
lemma smul_mul_vec_assoc (A : matrix n n α) (b : n → α) (a : α) :
(a • A).mul_vec b = a • (A.mul_vec b) :=
begin
ext i, change dot_product ((a • A) i) b = _,
simp only [mul_vec, smul_eq_mul, pi.smul_apply, smul_dot_product],
end
end ring
section transpose
open_locale matrix
/--
Tell `simp` what the entries are in a transposed matrix.
Compare with `mul_apply`, `diagonal_apply_eq`, etc.
-/
@[simp] lemma transpose_apply (M : matrix m n α) (i j) : M.transpose j i = M i j := rfl
@[simp] lemma transpose_transpose (M : matrix m n α) :
Mᵀᵀ = M :=
by ext; refl
@[simp] lemma transpose_zero [has_zero α] : (0 : matrix m n α)ᵀ = 0 :=
by ext i j; refl
@[simp] lemma transpose_one [decidable_eq n] [has_zero α] [has_one α] : (1 : matrix n n α)ᵀ = 1 :=
begin
ext i j,
unfold has_one.one transpose,
by_cases i = j,
{ simp only [h, diagonal_apply_eq] },
{ simp only [diagonal_apply_ne h, diagonal_apply_ne (λ p, h (symm p))] }
end
@[simp] lemma transpose_add [has_add α] (M : matrix m n α) (N : matrix m n α) :
(M + N)ᵀ = Mᵀ + Nᵀ :=
by { ext i j, simp }
@[simp] lemma transpose_sub [add_group α] (M : matrix m n α) (N : matrix m n α) :
(M - N)ᵀ = Mᵀ - Nᵀ :=
by { ext i j, simp }
@[simp] lemma transpose_mul [comm_semiring α] (M : matrix m n α) (N : matrix n l α) :
(M ⬝ N)ᵀ = Nᵀ ⬝ Mᵀ :=
begin
ext i j,
apply dot_product_comm
end
@[simp] lemma transpose_smul [semiring α] (c : α) (M : matrix m n α) :
(c • M)ᵀ = c • Mᵀ :=
by { ext i j, refl }
@[simp] lemma transpose_neg [has_neg α] (M : matrix m n α) :
(- M)ᵀ = - Mᵀ :=
by ext i j; refl
lemma transpose_map {β : Type w} {f : α → β} {M : matrix m n α} : Mᵀ.map f = (M.map f)ᵀ :=
by { ext, refl }
end transpose
section star_ring
variables [decidable_eq n] {R : Type*} [semiring R] [star_ring R]
/--
When `R` is a *-(semi)ring, `matrix n n R` becomes a *-(semi)ring with
the star operation given by taking the conjugate, and the star of each entry.
-/
instance : star_ring (matrix n n R) :=
{ star := λ M, M.transpose.map star,
star_involutive := λ M, by { ext, simp, },
star_add := λ M N, by { ext, simp, },
star_mul := λ M N, by { ext, simp [mul_apply], }, }
@[simp] lemma star_apply (M : matrix n n R) (i j) : star M i j = star (M j i) := rfl
end star_ring
/-- `M.minor row col` is the matrix obtained by reindexing the rows and the lines of
`M`, such that `M.minor row col i j = M (row i) (col j)`. Note that the total number
of row/colums doesn't have to be preserved. -/
def minor (A : matrix m n α) (row : l → m) (col : o → n) : matrix l o α :=
λ i j, A (row i) (col j)
/-- The left `n × l` part of a `n × (l+r)` matrix. -/
@[reducible]
def sub_left {m l r : nat} (A : matrix (fin m) (fin (l + r)) α) : matrix (fin m) (fin l) α :=
minor A id (fin.cast_add r)
/-- The right `n × r` part of a `n × (l+r)` matrix. -/
@[reducible]
def sub_right {m l r : nat} (A : matrix (fin m) (fin (l + r)) α) : matrix (fin m) (fin r) α :=
minor A id (fin.nat_add l)
/-- The top `u × n` part of a `(u+d) × n` matrix. -/
@[reducible]
def sub_up {d u n : nat} (A : matrix (fin (u + d)) (fin n) α) : matrix (fin u) (fin n) α :=
minor A (fin.cast_add d) id
/-- The bottom `d × n` part of a `(u+d) × n` matrix. -/
@[reducible]
def sub_down {d u n : nat} (A : matrix (fin (u + d)) (fin n) α) : matrix (fin d) (fin n) α :=
minor A (fin.nat_add u) id
/-- The top-right `u × r` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_up_right {d u l r : nat} (A: matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin u) (fin r) α :=
sub_up (sub_right A)
/-- The bottom-right `d × r` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_down_right {d u l r : nat} (A : matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin d) (fin r) α :=
sub_down (sub_right A)
/-- The top-left `u × l` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_up_left {d u l r : nat} (A : matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin u) (fin (l)) α :=
sub_up (sub_left A)
/-- The bottom-left `d × l` part of a `(u+d) × (l+r)` matrix. -/
@[reducible]
def sub_down_left {d u l r : nat} (A: matrix (fin (u + d)) (fin (l + r)) α) :
matrix (fin d) (fin (l)) α :=
sub_down (sub_left A)
section row_col
/-!
### `row_col` section
Simplification lemmas for `matrix.row` and `matrix.col`.
-/
open_locale matrix
@[simp] lemma col_add [semiring α] (v w : m → α) : col (v + w) = col v + col w := by { ext, refl }
@[simp] lemma col_smul [semiring α] (x : α) (v : m → α) : col (x • v) = x • col v := by { ext, refl }
@[simp] lemma row_add [semiring α] (v w : m → α) : row (v + w) = row v + row w := by { ext, refl }
@[simp] lemma row_smul [semiring α] (x : α) (v : m → α) : row (x • v) = x • row v := by { ext, refl }
@[simp] lemma col_apply (v : m → α) (i j) : matrix.col v i j = v i := rfl
@[simp] lemma row_apply (v : m → α) (i j) : matrix.row v i j = v j := rfl
@[simp]
lemma transpose_col (v : m → α) : (matrix.col v).transpose = matrix.row v := by {ext, refl}
@[simp]
lemma transpose_row (v : m → α) : (matrix.row v).transpose = matrix.col v := by {ext, refl}
lemma row_vec_mul [semiring α] (M : matrix m n α) (v : m → α) :
matrix.row (matrix.vec_mul v M) = matrix.row v ⬝ M := by {ext, refl}
lemma col_vec_mul [semiring α] (M : matrix m n α) (v : m → α) :
matrix.col (matrix.vec_mul v M) = (matrix.row v ⬝ M)ᵀ := by {ext, refl}
lemma col_mul_vec [semiring α] (M : matrix m n α) (v : n → α) :
matrix.col (matrix.mul_vec M v) = M ⬝ matrix.col v := by {ext, refl}
lemma row_mul_vec [semiring α] (M : matrix m n α) (v : n → α) :
matrix.row (matrix.mul_vec M v) = (M ⬝ matrix.col v)ᵀ := by {ext, refl}
end row_col
section update
/-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/
def update_row [decidable_eq n] (M : matrix n m α) (i : n) (b : m → α) : matrix n m α :=
function.update M i b
/-- Update, i.e. replace the `j`th column of matrix `A` with the values in `b`. -/
def update_column [decidable_eq m] (M : matrix n m α) (j : m) (b : n → α) : matrix n m α :=
λ i, function.update (M i) j (b i)
variables {M : matrix n m α} {i : n} {j : m} {b : m → α} {c : n → α}
@[simp] lemma update_row_self [decidable_eq n] : update_row M i b i = b :=
function.update_same i b M
@[simp] lemma update_column_self [decidable_eq m] : update_column M j c i j = c i :=
function.update_same j (c i) (M i)
@[simp] lemma update_row_ne [decidable_eq n] {i' : n} (i_ne : i' ≠ i) :
update_row M i b i' = M i' := function.update_noteq i_ne b M
@[simp] lemma update_column_ne [decidable_eq m] {j' : m} (j_ne : j' ≠ j) :
update_column M j c i j' = M i j' := function.update_noteq j_ne (c i) (M i)
lemma update_row_apply [decidable_eq n] {i' : n} :
update_row M i b i' j = if i' = i then b j else M i' j :=
begin
by_cases i' = i,
{ rw [h, update_row_self, if_pos rfl] },
{ rwa [update_row_ne h, if_neg h] }
end
lemma update_column_apply [decidable_eq m] {j' : m} : update_column M j c i j' = if j' = j then c i else M i j' :=
begin
by_cases j' = j,
{ rw [h, update_column_self, if_pos rfl] },
{ rwa [update_column_ne h, if_neg h] }
end
lemma update_row_transpose [decidable_eq m] : update_row Mᵀ j c = (update_column M j c)ᵀ :=
begin
ext i' j,
rw [transpose_apply, update_row_apply, update_column_apply],
refl
end
lemma update_column_transpose [decidable_eq n] : update_column Mᵀ i b = (update_row M i b)ᵀ :=
begin
ext i' j,
rw [transpose_apply, update_row_apply, update_column_apply],
refl
end
end update
section block_matrices
/-- We can form a single large matrix by flattening smaller 'block' matrices of compatible
dimensions. -/
def from_blocks (A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
matrix (n ⊕ o) (l ⊕ m) α :=
sum.elim (λ i, sum.elim (A i) (B i))
(λ i, sum.elim (C i) (D i))
@[simp] lemma from_blocks_apply₁₁
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) (i : n) (j : l) :
from_blocks A B C D (sum.inl i) (sum.inl j) = A i j :=
rfl
@[simp] lemma from_blocks_apply₁₂
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) (i : n) (j : m) :
from_blocks A B C D (sum.inl i) (sum.inr j) = B i j :=
rfl
@[simp] lemma from_blocks_apply₂₁
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) (i : o) (j : l) :
from_blocks A B C D (sum.inr i) (sum.inl j) = C i j :=
rfl
@[simp] lemma from_blocks_apply₂₂
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) (i : o) (j : m) :
from_blocks A B C D (sum.inr i) (sum.inr j) = D i j :=
rfl
/-- Given a matrix whose row and column indexes are sum types, we can extract the correspnding
"top left" submatrix. -/
def to_blocks₁₁ (M : matrix (n ⊕ o) (l ⊕ m) α) : matrix n l α :=
λ i j, M (sum.inl i) (sum.inl j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the correspnding
"top right" submatrix. -/
def to_blocks₁₂ (M : matrix (n ⊕ o) (l ⊕ m) α) : matrix n m α :=
λ i j, M (sum.inl i) (sum.inr j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the correspnding
"bottom left" submatrix. -/
def to_blocks₂₁ (M : matrix (n ⊕ o) (l ⊕ m) α) : matrix o l α :=
λ i j, M (sum.inr i) (sum.inl j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the correspnding
"bottom right" submatrix. -/
def to_blocks₂₂ (M : matrix (n ⊕ o) (l ⊕ m) α) : matrix o m α :=
λ i j, M (sum.inr i) (sum.inr j)
lemma from_blocks_to_blocks (M : matrix (n ⊕ o) (l ⊕ m) α) :
from_blocks M.to_blocks₁₁ M.to_blocks₁₂ M.to_blocks₂₁ M.to_blocks₂₂ = M :=
begin
ext i j, rcases i; rcases j; refl,
end
@[simp] lemma to_blocks_from_blocks₁₁
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
(from_blocks A B C D).to_blocks₁₁ = A :=
rfl
@[simp] lemma to_blocks_from_blocks₁₂
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
(from_blocks A B C D).to_blocks₁₂ = B :=
rfl
@[simp] lemma to_blocks_from_blocks₂₁
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
(from_blocks A B C D).to_blocks₂₁ = C :=
rfl
@[simp] lemma to_blocks_from_blocks₂₂
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
(from_blocks A B C D).to_blocks₂₂ = D :=
rfl
lemma from_blocks_transpose
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
(from_blocks A B C D)ᵀ = from_blocks Aᵀ Cᵀ Bᵀ Dᵀ :=
begin
ext i j, rcases i; rcases j; simp [from_blocks],
end
variables [semiring α]
lemma from_blocks_smul
(x : α) (A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α) :
x • (from_blocks A B C D) = from_blocks (x • A) (x • B) (x • C) (x • D) :=
begin
ext i j, rcases i; rcases j; simp [from_blocks],
end
lemma from_blocks_add
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α)
(A' : matrix n l α) (B' : matrix n m α) (C' : matrix o l α) (D' : matrix o m α) :
(from_blocks A B C D) + (from_blocks A' B' C' D') =
from_blocks (A + A') (B + B')
(C + C') (D + D') :=
begin
ext i j, rcases i; rcases j; refl,
end
lemma from_blocks_multiply {p q : Type*} [fintype p] [fintype q]
(A : matrix n l α) (B : matrix n m α) (C : matrix o l α) (D : matrix o m α)
(A' : matrix l p α) (B' : matrix l q α) (C' : matrix m p α) (D' : matrix m q α) :
(from_blocks A B C D) ⬝ (from_blocks A' B' C' D') =
from_blocks (A ⬝ A' + B ⬝ C') (A ⬝ B' + B ⬝ D')
(C ⬝ A' + D ⬝ C') (C ⬝ B' + D ⬝ D') :=
begin
ext i j, rcases i; rcases j;
simp only [from_blocks, mul_apply, fintype.sum_sum_type, sum.elim_inl, sum.elim_inr,
pi.add_apply],
end
variables [decidable_eq l] [decidable_eq m]
@[simp] lemma from_blocks_diagonal (d₁ : l → α) (d₂ : m → α) :
from_blocks (diagonal d₁) 0 0 (diagonal d₂) = diagonal (sum.elim d₁ d₂) :=
begin
ext i j, rcases i; rcases j; simp [diagonal],
end
@[simp] lemma from_blocks_one : from_blocks (1 : matrix l l α) 0 0 (1 : matrix m m α) = 1 :=
by { ext i j, rcases i; rcases j; simp [one_apply] }
end block_matrices
section block_diagonal
variables (M N : o → matrix m n α) [decidable_eq o]
section has_zero
variables [has_zero α]
/-- `matrix.block_diagonal M` turns `M : o → matrix m n α'` into a
`m × o`-by`n × o` block matrix which has the entries of `M` along the diagonal
and zero elsewhere. -/
def block_diagonal : matrix (m × o) (n × o) α
| ⟨i, k⟩ ⟨j, k'⟩ := if k = k' then M k i j else 0
lemma block_diagonal_apply (ik jk) :
block_diagonal M ik jk = if ik.2 = jk.2 then M ik.2 ik.1 jk.1 else 0 :=
by { cases ik, cases jk, refl }
@[simp]
lemma block_diagonal_apply_eq (i j k) :
block_diagonal M (i, k) (j, k) = M k i j :=
if_pos rfl
lemma block_diagonal_apply_ne (i j) {k k'} (h : k ≠ k') :
block_diagonal M (i, k) (j, k') = 0 :=
if_neg h
@[simp] lemma block_diagonal_transpose :
(block_diagonal M)ᵀ = (block_diagonal (λ k, (M k)ᵀ)) :=
begin
ext,
simp only [transpose_apply, block_diagonal_apply, eq_comm],
split_ifs with h,
{ rw h },
{ refl }
end
@[simp] lemma block_diagonal_zero :
block_diagonal (0 : o → matrix m n α) = 0 :=
by { ext, simp [block_diagonal_apply] }
@[simp] lemma block_diagonal_diagonal [decidable_eq m] (d : o → m → α) :
(block_diagonal (λ k, diagonal (d k))) = diagonal (λ ik, d ik.2 ik.1) :=
begin
ext ⟨i, k⟩ ⟨j, k'⟩,
simp only [block_diagonal_apply, diagonal],
split_ifs; finish
end
@[simp] lemma block_diagonal_one [decidable_eq m] [has_one α] :
(block_diagonal (1 : o → matrix m m α)) = 1 :=
show (block_diagonal (λ (_ : o), diagonal (λ (_ : m), (1 : α)))) = diagonal (λ _, 1),
by rw [block_diagonal_diagonal]
end has_zero
@[simp] lemma block_diagonal_add [add_monoid α] :
block_diagonal (M + N) = block_diagonal M + block_diagonal N :=
begin
ext,
simp only [block_diagonal_apply, add_apply],
split_ifs; simp
end
@[simp] lemma block_diagonal_neg [add_group α] :
block_diagonal (-M) = - block_diagonal M :=
begin
ext,
simp only [block_diagonal_apply, neg_apply],
split_ifs; simp
end
@[simp] lemma block_diagonal_sub [add_group α] :
block_diagonal (M - N) = block_diagonal M - block_diagonal N :=
by simp [sub_eq_add_neg]
@[simp] lemma block_diagonal_mul {p : Type*} [fintype p] [semiring α]
(N : o → matrix n p α) : block_diagonal (λ k, M k ⬝ N k) = block_diagonal M ⬝ block_diagonal N :=
begin
ext ⟨i, k⟩ ⟨j, k'⟩,
simp only [block_diagonal_apply, mul_apply, ← finset.univ_product_univ, finset.sum_product],
split_ifs with h; simp [h]
end
@[simp] lemma block_diagonal_smul {R : Type*} [semiring R] [add_comm_monoid α] [semimodule R α]
(x : R) : block_diagonal (x • M) = x • block_diagonal M :=
by { ext, simp only [block_diagonal_apply, pi.smul_apply, smul_apply], split_ifs; simp }
end block_diagonal
end matrix
namespace ring_hom
variables {β : Type*} [semiring α] [semiring β]
lemma map_matrix_mul (M : matrix m n α) (N : matrix n o α) (i : m) (j : o) (f : α →+* β) :
f (matrix.mul M N i j) = matrix.mul (λ i j, f (M i j)) (λ i j, f (N i j)) i j :=
by simp [matrix.mul_apply, ring_hom.map_sum]
end ring_hom
|
cab2b25ff35483730c3ec9d7c9c84619e5088d53
|
8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3
|
/src/ring_theory/polynomial/content.lean
|
cf6e2574c83f281151f4d3d2a0d916439b986405
|
[
"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
| 17,074
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import algebra.gcd_monoid.finset
import data.polynomial
import data.polynomial.erase_lead
import data.polynomial.cancel_leads
/-!
# GCD structures on polynomials
Definitions and basic results about polynomials over GCD domains, particularly their contents
and primitive polynomials.
## Main Definitions
Let `p : polynomial R`.
- `p.content` is the `gcd` of the coefficients of `p`.
- `p.is_primitive` indicates that `p.content = 1`.
## Main Results
- `polynomial.content_mul`:
If `p q : polynomial R`, then `(p * q).content = p.content * q.content`.
- `polynomial.gcd_monoid`:
The polynomial ring of a GCD domain is itself a GCD domain.
-/
namespace polynomial
section primitive
variables {R : Type*} [comm_semiring R]
/-- A polynomial is primitive when the only constant polynomials dividing it are units -/
def is_primitive (p : polynomial R) : Prop :=
∀ (r : R), C r ∣ p → is_unit r
lemma is_primitive_iff_is_unit_of_C_dvd {p : polynomial R} :
p.is_primitive ↔ ∀ (r : R), C r ∣ p → is_unit r :=
iff.rfl
@[simp]
lemma is_primitive_one : is_primitive (1 : polynomial R) :=
λ r h, is_unit_C.mp (is_unit_of_dvd_one (C r) h)
lemma monic.is_primitive {p : polynomial R} (hp : p.monic) : p.is_primitive :=
begin
rintros r ⟨q, h⟩,
exact is_unit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [←coeff_C_mul, ←h]),
end
lemma is_primitive.ne_zero [nontrivial R] {p : polynomial R} (hp : p.is_primitive) : p ≠ 0 :=
begin
rintro rfl,
exact (hp 0 (dvd_zero (C 0))).ne_zero rfl,
end
end primitive
variables {R : Type*} [integral_domain R]
section gcd_monoid
variable [gcd_monoid R]
/-- `p.content` is the `gcd` of the coefficients of `p`. -/
def content (p : polynomial R) : R := (p.support).gcd p.coeff
lemma content_dvd_coeff {p : polynomial R} (n : ℕ) : p.content ∣ p.coeff n :=
begin
by_cases h : n ∈ p.support,
{ apply finset.gcd_dvd h },
rw [mem_support_iff, not_not] at h,
rw h,
apply dvd_zero,
end
@[simp] lemma content_C {r : R} : (C r).content = normalize r :=
begin
rw content,
by_cases h0 : r = 0,
{ simp [h0] },
have h : (C r).support = {0} := support_monomial _ _ h0,
simp [h],
end
@[simp] lemma content_zero : content (0 : polynomial R) = 0 :=
by rw [← C_0, content_C, normalize_zero]
@[simp] lemma content_one : content (1 : polynomial R) = 1 :=
by rw [← C_1, content_C, normalize_one]
lemma content_X_mul {p : polynomial R} : content (X * p) = content p :=
begin
rw [content, content, finset.gcd_def, finset.gcd_def],
refine congr rfl _,
have h : (X * p).support = p.support.map ⟨nat.succ, nat.succ_injective⟩,
{ ext a,
simp only [exists_prop, finset.mem_map, function.embedding.coe_fn_mk, ne.def,
mem_support_iff],
cases a,
{ simp [coeff_X_mul_zero, nat.succ_ne_zero] },
rw [mul_comm, coeff_mul_X],
split,
{ intro h,
use a,
simp [h] },
{ rintros ⟨b, ⟨h1, h2⟩⟩,
rw ← nat.succ_injective h2,
apply h1 } },
rw h,
simp only [finset.map_val, function.comp_app, function.embedding.coe_fn_mk, multiset.map_map],
refine congr (congr rfl _) rfl,
ext a,
rw mul_comm,
simp [coeff_mul_X],
end
@[simp] lemma content_X_pow {k : ℕ} : content ((X : polynomial R) ^ k) = 1 :=
begin
induction k with k hi,
{ simp },
rw [pow_succ, content_X_mul, hi]
end
@[simp] lemma content_X : content (X : polynomial R) = 1 :=
by { rw [← mul_one X, content_X_mul, content_one] }
lemma content_C_mul (r : R) (p : polynomial R) : (C r * p).content = normalize r * p.content :=
begin
by_cases h0 : r = 0, { simp [h0] },
rw content, rw content, rw ← finset.gcd_mul_left,
refine congr (congr rfl _) _; ext; simp [h0, mem_support_iff]
end
@[simp] lemma content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r :=
by { rw [monomial_eq_C_mul_X, content_C_mul, content_X_pow, mul_one] }
lemma content_eq_zero_iff {p : polynomial R} : content p = 0 ↔ p = 0 :=
begin
rw [content, finset.gcd_eq_zero_iff],
split; intro h,
{ ext n,
by_cases h0 : n ∈ p.support,
{ rw [h n h0, coeff_zero], },
{ rw mem_support_iff at h0,
push_neg at h0,
simp [h0] } },
{ intros x h0,
simp [h] }
end
@[simp] lemma normalize_content {p : polynomial R} : normalize p.content = p.content :=
finset.normalize_gcd
lemma content_eq_gcd_range_of_lt (p : polynomial R) (n : ℕ) (h : p.nat_degree < n) :
p.content = (finset.range n).gcd p.coeff :=
begin
apply dvd_antisymm_of_normalize_eq normalize_content finset.normalize_gcd,
{ rw finset.dvd_gcd_iff,
intros i hi,
apply content_dvd_coeff _ },
{ apply finset.gcd_mono,
intro i,
simp only [nat.lt_succ_iff, mem_support_iff, ne.def, finset.mem_range],
contrapose!,
intro h1,
apply coeff_eq_zero_of_nat_degree_lt (lt_of_lt_of_le h h1), }
end
lemma content_eq_gcd_range_succ (p : polynomial R) :
p.content = (finset.range p.nat_degree.succ).gcd p.coeff :=
content_eq_gcd_range_of_lt _ _ (nat.lt_succ_self _)
lemma content_eq_gcd_leading_coeff_content_erase_lead (p : polynomial R) :
p.content = gcd_monoid.gcd p.leading_coeff (erase_lead p).content :=
begin
by_cases h : p = 0,
{ simp [h] },
rw [← leading_coeff_eq_zero, leading_coeff, ← ne.def, ← mem_support_iff] at h,
rw [content, ← finset.insert_erase h, finset.gcd_insert, leading_coeff, content,
erase_lead_support],
refine congr rfl (finset.gcd_congr rfl (λ i hi, _)),
rw finset.mem_erase at hi,
rw [erase_lead_coeff, if_neg hi.1],
end
lemma dvd_content_iff_C_dvd {p : polynomial R} {r : R} : r ∣ p.content ↔ C r ∣ p :=
begin
rw C_dvd_iff_dvd_coeff,
split,
{ intros h i,
apply h.trans (content_dvd_coeff _) },
{ intro h,
rw [content, finset.dvd_gcd_iff],
intros i hi,
apply h i }
end
lemma C_content_dvd (p : polynomial R) : C p.content ∣ p :=
dvd_content_iff_C_dvd.1 (dvd_refl _)
lemma is_primitive_iff_content_eq_one {p : polynomial R} : p.is_primitive ↔ p.content = 1 :=
begin
rw [←normalize_content, normalize_eq_one, is_primitive],
simp_rw [←dvd_content_iff_C_dvd],
exact ⟨λ h, h p.content (dvd_refl p.content), λ h r hdvd, is_unit_of_dvd_unit hdvd h⟩,
end
lemma is_primitive.content_eq_one {p : polynomial R} (hp : p.is_primitive) : p.content = 1 :=
is_primitive_iff_content_eq_one.mp hp
open_locale classical
noncomputable theory
section prim_part
/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by
`p.content`. If `p = 0`, then `p.prim_part = 1`. -/
def prim_part (p : polynomial R) : polynomial R :=
if p = 0 then 1 else classical.some (C_content_dvd p)
lemma eq_C_content_mul_prim_part (p : polynomial R) : p = C p.content * p.prim_part :=
begin
by_cases h : p = 0, { simp [h] },
rw [prim_part, if_neg h, ← classical.some_spec (C_content_dvd p)],
end
@[simp]
lemma prim_part_zero : prim_part (0 : polynomial R) = 1 := if_pos rfl
lemma is_primitive_prim_part (p : polynomial R) : p.prim_part.is_primitive :=
begin
by_cases h : p = 0, { simp [h] },
rw ← content_eq_zero_iff at h,
rw is_primitive_iff_content_eq_one,
apply mul_left_cancel' h,
conv_rhs { rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content] }
end
lemma content_prim_part (p : polynomial R) : p.prim_part.content = 1 :=
p.is_primitive_prim_part.content_eq_one
lemma prim_part_ne_zero (p : polynomial R) : p.prim_part ≠ 0 := p.is_primitive_prim_part.ne_zero
lemma nat_degree_prim_part (p : polynomial R) : p.prim_part.nat_degree = p.nat_degree :=
begin
by_cases h : C p.content = 0,
{ rw [C_eq_zero, content_eq_zero_iff] at h, simp [h] },
conv_rhs { rw [p.eq_C_content_mul_prim_part,
nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add] },
end
@[simp]
lemma is_primitive.prim_part_eq {p : polynomial R} (hp : p.is_primitive) : p.prim_part = p :=
by rw [← one_mul p.prim_part, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_prim_part]
lemma is_unit_prim_part_C (r : R) : is_unit (C r).prim_part :=
begin
by_cases h0 : r = 0,
{ simp [h0] },
unfold is_unit,
refine ⟨⟨C ↑(norm_unit r)⁻¹, C ↑(norm_unit r),
by rw [← ring_hom.map_mul, units.inv_mul, C_1],
by rw [← ring_hom.map_mul, units.mul_inv, C_1]⟩, _⟩,
rw [← normalize_eq_zero, ← C_eq_zero] at h0,
apply mul_left_cancel' h0,
conv_rhs { rw [← content_C, ← (C r).eq_C_content_mul_prim_part], },
simp only [units.coe_mk, normalize_apply, ring_hom.map_mul],
rw [mul_assoc, ← ring_hom.map_mul, units.mul_inv, C_1, mul_one],
end
lemma prim_part_dvd (p : polynomial R) : p.prim_part ∣ p :=
dvd.intro_left (C p.content) p.eq_C_content_mul_prim_part.symm
end prim_part
lemma gcd_content_eq_of_dvd_sub {a : R} {p q : polynomial R} (h : C a ∣ p - q) :
gcd_monoid.gcd a p.content = gcd_monoid.gcd a q.content :=
begin
rw content_eq_gcd_range_of_lt p (max p.nat_degree q.nat_degree).succ
(lt_of_le_of_lt (le_max_left _ _) (nat.lt_succ_self _)),
rw content_eq_gcd_range_of_lt q (max p.nat_degree q.nat_degree).succ
(lt_of_le_of_lt (le_max_right _ _) (nat.lt_succ_self _)),
apply finset.gcd_eq_of_dvd_sub,
intros x hx,
cases h with w hw,
use w.coeff x,
rw [← coeff_sub, hw, coeff_C_mul]
end
lemma content_mul_aux {p q : polynomial R} :
gcd_monoid.gcd (p * q).erase_lead.content p.leading_coeff =
gcd_monoid.gcd (p.erase_lead * q).content p.leading_coeff :=
begin
rw [gcd_comm (content _) _, gcd_comm (content _) _],
apply gcd_content_eq_of_dvd_sub,
rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,
sub_sub_cancel, leading_coeff_mul, ring_hom.map_mul, mul_assoc, mul_assoc],
apply dvd_sub (dvd.intro _ rfl) (dvd.intro _ rfl),
end
@[simp]
theorem content_mul {p q : polynomial R} : (p * q).content = p.content * q.content :=
begin
classical,
suffices h : ∀ (n : ℕ) (p q : polynomial R), ((p * q).degree < n) →
(p * q).content = p.content * q.content,
{ apply h,
apply (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_succ_self _))) },
intro n,
induction n with n ih,
{ intros p q hpq,
rw [with_bot.coe_zero, nat.with_bot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq,
rcases hpq with rfl | rfl; simp },
intros p q hpq,
by_cases p0 : p = 0, { simp [p0] },
by_cases q0 : q = 0, { simp [q0] },
rw [degree_eq_nat_degree (mul_ne_zero p0 q0), with_bot.coe_lt_coe, nat.lt_succ_iff_lt_or_eq,
← with_bot.coe_lt_coe, ← degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq,
rcases hpq with hlt | heq, { apply ih _ _ hlt },
rw [← p.nat_degree_prim_part, ← q.nat_degree_prim_part, ← with_bot.coe_eq_coe, with_bot.coe_add,
← degree_eq_nat_degree p.prim_part_ne_zero, ← degree_eq_nat_degree q.prim_part_ne_zero] at heq,
rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part],
suffices h : (q.prim_part * p.prim_part).content = 1,
{ rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.prim_part, mul_assoc, content_C_mul,
content_C_mul, h, mul_one, content_prim_part, content_prim_part, mul_one, mul_one] },
rw [← normalize_content, normalize_eq_one, is_unit_iff_dvd_one,
content_eq_gcd_leading_coeff_content_erase_lead, leading_coeff_mul, gcd_comm],
apply (gcd_mul_dvd_mul_gcd _ _ _).trans,
rw [content_mul_aux, ih, content_prim_part, mul_one, gcd_comm,
← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part, one_mul,
mul_comm q.prim_part, content_mul_aux, ih, content_prim_part, mul_one, gcd_comm,
← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part],
{ rw [← heq, degree_mul, with_bot.add_lt_add_iff_right],
{ apply degree_erase_lt p.prim_part_ne_zero },
{ rw [bot_lt_iff_ne_bot, ne.def, degree_eq_bot],
apply q.prim_part_ne_zero } },
{ rw [mul_comm, ← heq, degree_mul, with_bot.add_lt_add_iff_left],
{ apply degree_erase_lt q.prim_part_ne_zero },
{ rw [bot_lt_iff_ne_bot, ne.def, degree_eq_bot],
apply p.prim_part_ne_zero } }
end
theorem is_primitive.mul {p q : polynomial R} (hp : p.is_primitive) (hq : q.is_primitive) :
(p * q).is_primitive :=
by rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]
@[simp]
theorem prim_part_mul {p q : polynomial R} (h0 : p * q ≠ 0) :
(p * q).prim_part = p.prim_part * q.prim_part :=
begin
rw [ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0,
apply mul_left_cancel' h0,
conv_lhs { rw [← (p * q).eq_C_content_mul_prim_part,
p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part] },
rw [content_mul, ring_hom.map_mul],
ring,
end
lemma is_primitive.is_primitive_of_dvd {p q : polynomial R} (hp : p.is_primitive) (hdvd : q ∣ p) :
q.is_primitive :=
begin
rcases hdvd with ⟨r, rfl⟩,
rw [is_primitive_iff_content_eq_one, ← normalize_content, normalize_eq_one, is_unit_iff_dvd_one],
apply dvd.intro r.content,
rwa [is_primitive_iff_content_eq_one, content_mul] at hp,
end
lemma is_primitive.dvd_prim_part_iff_dvd {p q : polynomial R}
(hp : p.is_primitive) (hq : q ≠ 0) :
p ∣ q.prim_part ↔ p ∣ q :=
begin
refine ⟨λ h, h.trans (dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), λ h, _⟩,
rcases h with ⟨r, rfl⟩,
apply dvd.intro _,
rw [prim_part_mul hq, hp.prim_part_eq],
end
theorem exists_primitive_lcm_of_is_primitive {p q : polynomial R}
(hp : p.is_primitive) (hq : q.is_primitive) :
∃ r : polynomial R, r.is_primitive ∧ (∀ s : polynomial R, p ∣ s ∧ q ∣ s ↔ r ∣ s) :=
begin
classical,
have h : ∃ (n : ℕ) (r : polynomial R), r.nat_degree = n ∧ r.is_primitive ∧ p ∣ r ∧ q ∣ r :=
⟨(p * q).nat_degree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩,
rcases nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩,
refine ⟨r, rprim, λ s, ⟨_, λ rs, ⟨pr.trans rs, qr.trans rs⟩⟩⟩,
suffices hs : ∀ (n : ℕ) (s : polynomial R), s.nat_degree = n → (p ∣ s ∧ q ∣ s → r ∣ s),
{ apply hs s.nat_degree s rfl },
clear s,
by_contra con,
push_neg at con,
rcases nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩,
have s0 : s ≠ 0,
{ contrapose! rs, simp [rs] },
have hs := nat.find_min' h ⟨_, s.nat_degree_prim_part, s.is_primitive_prim_part,
(hp.dvd_prim_part_iff_dvd s0).2 ps, (hq.dvd_prim_part_iff_dvd s0).2 qs⟩,
rw ← rdeg at hs,
by_cases sC : s.nat_degree ≤ 0,
{ rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one,
content_C, normalize_eq_one] at rprim,
rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs,
apply rs rprim.dvd },
have hcancel := nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree hs (lt_of_not_ge sC),
rw sdeg at hcancel,
apply nat.find_min con hcancel,
refine ⟨_, rfl, ⟨dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs⟩,
λ rcs, rs _⟩,
rw ← rprim.dvd_prim_part_iff_dvd s0,
rw [cancel_leads, nat.sub_eq_zero_of_le hs, pow_zero, mul_one] at rcs,
have h := dvd_add rcs (dvd.intro_left _ rfl),
have hC0 := rprim.ne_zero,
rw [ne.def, ← leading_coeff_eq_zero, ← C_eq_zero] at hC0,
rw [sub_add_cancel, ← rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h,
rcases is_unit_prim_part_C r.leading_coeff with ⟨u, hu⟩,
apply h.trans (associated.symm ⟨u, _⟩).dvd,
rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm],
end
lemma dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part
{p q : polynomial R} (hq : q ≠ 0) :
p ∣ q ↔ p.content ∣ q.content ∧ p.prim_part ∣ q.prim_part :=
begin
split; intro h,
{ rcases h with ⟨r, rfl⟩,
rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq],
exact ⟨dvd.intro _ rfl, p.prim_part_dvd.trans (dvd.intro _ rfl)⟩ },
{ rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part],
exact mul_dvd_mul (ring_hom.map_dvd C h.1) h.2 }
end
@[priority 100]
instance gcd_monoid : gcd_monoid (polynomial R) :=
gcd_monoid_of_exists_lcm $ λ p q, begin
rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part q.is_primitive_prim_part
with ⟨r, rprim, hr⟩,
refine ⟨C (lcm p.content q.content) * r, λ s, _⟩,
by_cases hs : s = 0,
{ simp [hs] },
by_cases hpq : C (lcm p.content q.content) = 0,
{ rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq,
rcases hpq with hpq | hpq; simp [hpq, hs] },
iterate 3 { rw dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part hs },
rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff,
prim_part_mul (mul_ne_zero hpq rprim.ne_zero), rprim.prim_part_eq,
is_unit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), ← hr s.prim_part],
tauto,
end
end gcd_monoid
end polynomial
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.