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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
380fda653d1af3634871ce1c3d10e11347beccce
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/qpf/multivariate/constructions/prj.lean
|
4e42a9e26c667360edb0464d88c42134b08b7283
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,797
|
lean
|
/-
Copyright (c) 2020 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.control.functor.multivariate
import Mathlib.data.qpf.multivariate.basic
import Mathlib.PostPort
universes u u_1 u_2
namespace Mathlib
/-!
Projection functors are QPFs. The `n`-ary projection functors on `i` is an `n`-ary
functor `F` such that `F (α₀..αᵢ₋₁, αᵢ, αᵢ₊₁..αₙ₋₁) = αᵢ`
-/
namespace mvqpf
/-- The projection `i` functor -/
def prj {n : ℕ} (i : fin2 n) (v : typevec n) :=
v i
protected instance prj.inhabited {n : ℕ} (i : fin2 n) {v : typevec n} [Inhabited (v i)] : Inhabited (prj i v) :=
{ default := Inhabited.default }
/-- `map` on functor `prj i` -/
def prj.map {n : ℕ} (i : fin2 n) {α : typevec n} {β : typevec n} (f : typevec.arrow α β) : prj i α → prj i β :=
f i
protected instance prj.mvfunctor {n : ℕ} (i : fin2 n) : mvfunctor (prj i) :=
mvfunctor.mk (prj.map i)
/-- Polynomial representation of the projection functor -/
def prj.P {n : ℕ} (i : fin2 n) : mvpfunctor n :=
mvpfunctor.mk PUnit fun (_x : PUnit) (j : fin2 n) => ulift (plift (i = j))
/-- Abstraction function of the `qpf` instance -/
def prj.abs {n : ℕ} (i : fin2 n) {α : typevec n} : mvpfunctor.obj (prj.P i) α → prj i α :=
sorry
/-- Representation function of the `qpf` instance -/
def prj.repr {n : ℕ} (i : fin2 n) {α : typevec n} : prj i α → mvpfunctor.obj (prj.P i) α :=
fun (x : α i) => sigma.mk PUnit.unit fun (j : fin2 n) (_x : mvpfunctor.B (prj.P i) PUnit.unit j) => sorry
protected instance prj.mvqpf {n : ℕ} (i : fin2 n) : mvqpf (prj i) :=
mk (prj.P i) (prj.abs i) (prj.repr i) sorry sorry
|
42f523e5e79dfc8aa9bdb331a15dffa6738e7cad
|
037dba89703a79cd4a4aec5e959818147f97635d
|
/src/2019/questions/sheet4.lean
|
42a656dae16a5e445cab78f947b2ece5524a03f2
|
[] |
no_license
|
ImperialCollegeLondon/M40001_lean
|
3a6a09298da395ab51bc220a535035d45bbe919b
|
62a76fa92654c855af2b2fc2bef8e60acd16ccec
|
refs/heads/master
| 1,666,750,403,259
| 1,665,771,117,000
| 1,665,771,117,000
| 209,141,835
| 115
| 12
| null | 1,640,270,596,000
| 1,568,749,174,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,433
|
lean
|
/- Math40001 : Introduction to university mathematics.
Problem Sheet 4, October 2019.
This is a Lean file. It can be read with the Lean theorem prover.
You can work on this file online at
https://tinyurl.com/Lean-M40001-Example-Sheet-4
or you can install Lean and its maths library following the
instructions at
https://github.com/leanprover-community/mathlib#installation
There are advantages to installing Lean on your own computer
(for example it's faster), but it's more hassle than
just using it online.
In the below, delete "sorry" and replace it with some
tactics which prove the result.
-/
import data.real.basic -- the real numbers
/- Question 1.
For each of the sets~$X$ and binary relations~$R$ below, figure out whether~$R$ is (a) reflexive, (b) symmetric, (c) antisymmetric, (d) transitive.
\begin{enumerate}
\item Let $X$ be the set $\{1,2\}$ and define~$R$ like this: $R(1,1)$ is true, $R(1,2)$ is true, $R(2,1)$ is true and $R(2,2)$ is false.
\item Let~$X=\R$ and define $R(a,b)$ to be the proposition $a=-b$.
\item Let~$X=\R$ and define $R(a,b)$ to be false for all real numbers~$a$ and~$b$.
\item Let~$X$ be the empty set and define~$R$ to be the empty binary relation (we don't have to say what its value is on any pair $(a,b)$ because no such pairs exist).
\end{enumerate}
-/
namespace Q1a
inductive X : Type
| one : X
| two : X
namespace X
def R : X → X → Prop
| one one := true
| one two := true
| two one := true
| two two := false
-- insert "¬" if you think it's not reflexive
lemma Q1a_refl : reflexive R :=
begin
sorry
end
-- insert "¬" if you think it's not symmetric
lemma Q1a_symm : symmetric R :=
begin
sorry
end
-- insert "¬" if you think it's not transitive
lemma Q1a_trans : transitive R :=
begin
sorry
end
-- insert "¬" if you think it's not an equiv reln
lemma Q1a_equiv : equivalence R :=
begin
sorry
end
end X
end Q1a
namespace Q1b
def R (a b : ℝ) : Prop := a = -b
-- insert "¬" if you think it's not reflexive
lemma Q1b_refl : reflexive R :=
begin
sorry
end
-- insert "¬" if you think it's not symmetric
lemma Q1b_symm : symmetric R :=
begin
sorry
end
-- insert "¬" if you think it's not transitive
lemma Q1b_trans : transitive R :=
begin
sorry
end
-- insert "¬" if you think it's not an equiv reln
lemma Q1b_equiv : equivalence R :=
begin
sorry
end
end Q1b
namespace Q1c
def R (a b : ℝ) : Prop := false
-- insert "¬" if you think it's not reflexive
lemma Q1c_refl : reflexive R :=
begin
sorry
end
-- insert "¬" if you think it's not symmetric
lemma Q1c_symm : symmetric R :=
begin
sorry
end
-- insert "¬" if you think it's not transitive
lemma Q1c_trans : transitive R :=
begin
sorry
end
-- insert "¬" if you think it's not an equiv reln
lemma Q1c_equiv : equivalence R :=
begin
sorry
end
end Q1c
namespace Q1d
def R (a b : empty) : Prop := by cases a -- i.e. "I'll define it in all cases -- oh look there are no cases"
-- insert "¬" if you think it's not reflexive
lemma Q1d_refl : reflexive R :=
begin
sorry
end
-- insert "¬" if you think it's not symmetric
lemma Q1d_symm : symmetric R :=
begin
sorry
end
-- insert "¬" if you think it's not transitive
lemma Q1d_trans : transitive R :=
begin
sorry
end
-- insert "¬" if you think it's not an equiv reln
lemma Q1d_equiv : equivalence R :=
begin
sorry
end
end Q1d
-- `set ℤ` is the type of subsets of the integers.
def Q2a : partial_order (set ℤ) :=
{ le := λ A B, A ⊆ B,
le_refl := begin sorry end,
le_antisymm := begin sorry end,
le_trans := begin sorry end
}
-- insert ¬ at the beginning if you think it's wrong
lemma Q2b : is_total (set ℤ) (λ A B, A ⊆ B) :=
begin
sorry
end
-- put ¬ in front if you think it's wrong
lemma Q3a : symmetric (λ a b : ℝ, a < b) :=
begin
sorry
end
-- put ¬ in front if you think it's wrong
lemma Q3b : symmetric (λ a b : (∅ : set ℝ), a < b) :=
begin
sorry
end
-- type in the proof in the question. Where do you get stuck?
lemma Q4 (X : Type) (R : X → (X → Prop)) (hs : symmetric R) (ht : transitive R) : reflexive R :=
begin
sorry
end
open function
definition pals {X Y Z : Type} (f : X → Y) (g : X → Z) := ∃ h : Y → Z, bijective h ∧ g = h ∘ f
lemma Q5 (X Y Z: Type) (f : X → Y) (g : X → Z) (hf : surjective f) (hg : surjective g) : pals f g ↔ ∀ a b : X, (f a = f b) ↔ (g a = g b) :=
begin
sorry
end
|
fab1768cc8ad34b345d0d9f2e4551218353dd2bc
|
36c7a18fd72e5b57229bd8ba36493daf536a19ce
|
/library/data/bag.lean
|
0bbfa3a3a30d809031a91c1743f3ac25c9977c41
|
[
"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
| 34,434
|
lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
Finite bags.
-/
import data.nat data.list.perm algebra.binary
open nat quot list subtype binary function eq.ops
open [declarations] perm
open algebra
variable {A : Type}
definition bag.setoid [instance] (A : Type) : setoid (list A) :=
setoid.mk (@perm A) (mk_equivalence (@perm A) (@perm.refl A) (@perm.symm A) (@perm.trans A))
definition bag (A : Type) : Type :=
quot (bag.setoid A)
namespace bag
definition of_list (l : list A) : bag A :=
⟦l⟧
definition empty : bag A :=
of_list nil
definition singleton (a : A) : bag A :=
of_list [a]
definition insert (a : A) (b : bag A) : bag A :=
quot.lift_on b (λ l, ⟦a::l⟧)
(λ l₁ l₂ h, quot.sound (perm.skip a h))
lemma insert_empty_eq_singleton (a : A) : insert a empty = singleton a :=
rfl
definition insert.comm (a₁ a₂ : A) (b : bag A) : insert a₁ (insert a₂ b) = insert a₂ (insert a₁ b) :=
quot.induction_on b (λ l, quot.sound !perm.swap)
definition append (b₁ b₂ : bag A) : bag A :=
quot.lift_on₂ b₁ b₂ (λ l₁ l₂, ⟦l₁++l₂⟧)
(λ l₁ l₂ l₃ l₄ h₁ h₂, quot.sound (perm_app h₁ h₂))
infix ++ := append
lemma append.comm (b₁ b₂ : bag A) : b₁ ++ b₂ = b₂ ++ b₁ :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂, quot.sound !perm_app_comm)
lemma append.assoc (b₁ b₂ b₃ : bag A) : (b₁ ++ b₂) ++ b₃ = b₁ ++ (b₂ ++ b₃) :=
quot.induction_on₃ b₁ b₂ b₃ (λ l₁ l₂ l₃, quot.sound (by rewrite list.append.assoc; apply perm.refl))
lemma append_empty_left (b : bag A) : empty ++ b = b :=
quot.induction_on b (λ l, quot.sound (by rewrite append_nil_left; apply perm.refl))
lemma append_empty_right (b : bag A) : b ++ empty = b :=
quot.induction_on b (λ l, quot.sound (by rewrite append_nil_right; apply perm.refl))
lemma append_insert_left (a : A) (b₁ b₂ : bag A) : insert a b₁ ++ b₂ = insert a (b₁ ++ b₂) :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂, quot.sound (by rewrite append_cons; apply perm.refl))
lemma append_insert_right (a : A) (b₁ b₂ : bag A) : b₁ ++ insert a b₂ = insert a (b₁ ++ b₂) :=
calc b₁ ++ insert a b₂ = insert a b₂ ++ b₁ : append.comm
... = insert a (b₂ ++ b₁) : append_insert_left
... = insert a (b₁ ++ b₂) : append.comm
protected lemma induction_on [recursor 3] {C : bag A → Prop} (b : bag A) (h₁ : C empty) (h₂ : ∀ a b, C b → C (insert a b)) : C b :=
quot.induction_on b (λ l, list.induction_on l h₁ (λ h t ih, h₂ h ⟦t⟧ ih))
section decidable_eq
variable [decA : decidable_eq A]
include decA
open decidable
definition has_decidable_eq [instance] (b₁ b₂ : bag A) : decidable (b₁ = b₂) :=
quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match decidable_perm l₁ l₂ with
| inl h := inl (quot.sound h)
| inr h := inr (λ n, absurd (quot.exact n) h)
end)
end decidable_eq
section count
variable [decA : decidable_eq A]
include decA
definition count (a : A) (b : bag A) : nat :=
quot.lift_on b (λ l, count a l)
(λ l₁ l₂ h, count_eq_of_perm h a)
lemma count_empty (a : A) : count a empty = 0 :=
rfl
lemma count_insert (a : A) (b : bag A) : count a (insert a b) = succ (count a b) :=
quot.induction_on b (λ l, begin unfold [insert, count], rewrite count_cons_eq end)
lemma count_insert_of_ne {a₁ a₂ : A} (h : a₁ ≠ a₂) (b : bag A) : count a₁ (insert a₂ b) = count a₁ b :=
quot.induction_on b (λ l, begin unfold [insert, count], rewrite (count_cons_of_ne h) end)
lemma count_singleton (a : A) : count a (singleton a) = 1 :=
begin rewrite [-insert_empty_eq_singleton, count_insert] end
lemma count_append (a : A) (b₁ b₂ : bag A) : count a (append b₁ b₂) = count a b₁ + count a b₂ :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂, begin unfold [append, count], rewrite list.count_append end)
open perm decidable
protected lemma ext {b₁ b₂ : bag A} : (∀ a, count a b₁ = count a b₂) → b₁ = b₂ :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂ (h : ∀ a, count a ⟦l₁⟧ = count a ⟦l₂⟧),
have gen : ∀ (l₁ l₂ : list A), (∀ a, list.count a l₁ = list.count a l₂) → l₁ ~ l₂
| [] [] h₁ := !perm.refl
| [] (a₂::s₂) h₁ := assert list.count a₂ [] = list.count a₂ (a₂::s₂), from h₁ a₂, by rewrite [count_nil at this, count_cons_eq at this]; contradiction
| (a::s₁) s₂ h₁ :=
assert g₁ : list.count a (a::s₁) > 0, from count_gt_zero_of_mem !mem_cons,
assert list.count a (a::s₁) = list.count a s₂, from h₁ a,
assert list.count a s₂ > 0, by rewrite [-this]; exact g₁,
have a ∈ s₂, from mem_of_count_gt_zero this,
have ∃ l r, s₂ = l++(a::r), from mem_split this,
obtain l r (e₁ : s₂ = l++(a::r)), from this,
have ∀ a, list.count a s₁ = list.count a (l++r), from
take a₁,
assert e₂ : list.count a₁ (a::s₁) = list.count a₁ (l++(a::r)), by rewrite -e₁; exact h₁ a₁,
by_cases
(suppose a₁ = a, begin
rewrite [-this at e₂, list.count_append at e₂, *count_cons_eq at e₂, add_succ at e₂],
injection e₂ with e₃, rewrite e₃,
rewrite list.count_append
end)
(suppose a₁ ≠ a,
by rewrite [list.count_append at e₂, *count_cons_of_ne this at e₂, e₂, list.count_append]),
have ih : s₁ ~ l++r, from gen s₁ (l++r) this,
calc a::s₁ ~ a::(l++r) : perm.skip a ih
... ~ l++(a::r) : perm_middle
... = s₂ : e₁,
quot.sound (gen l₁ l₂ h))
definition insert.inj {a : A} {b₁ b₂ : bag A} : insert a b₁ = insert a b₂ → b₁ = b₂ :=
assume h, bag.ext (take x,
assert e : count x (insert a b₁) = count x (insert a b₂), by rewrite h,
by_cases
(suppose x = a, begin subst x, rewrite [*count_insert at e], injection e, assumption end)
(suppose x ≠ a, begin rewrite [*count_insert_of_ne this at e], assumption end))
end count
section extract
open decidable
variable [decA : decidable_eq A]
include decA
definition extract (a : A) (b : bag A) : bag A :=
quot.lift_on b (λ l, ⟦filter (λ c, c ≠ a) l⟧)
(λ l₁ l₂ h, quot.sound (perm_filter h))
lemma extract_singleton (a : A) : extract a (singleton a) = empty :=
begin unfold [extract, singleton, of_list, filter], rewrite [if_neg (λ h : a ≠ a, absurd rfl h)] end
lemma extract_insert (a : A) (b : bag A) : extract a (insert a b) = extract a b :=
quot.induction_on b (λ l, begin
unfold [insert, extract],
rewrite [@filter_cons_of_neg _ (λ c, c ≠ a) _ _ l (not_not_intro (eq.refl a))]
end)
lemma extract_insert_of_ne {a₁ a₂ : A} (h : a₁ ≠ a₂) (b : bag A) : extract a₁ (insert a₂ b) = insert a₂ (extract a₁ b) :=
quot.induction_on b (λ l, begin
unfold [insert, extract],
rewrite [@filter_cons_of_pos _ (λ c, c ≠ a₁) _ _ l (ne.symm h)]
end)
lemma count_extract (a : A) (b : bag A) : count a (extract a b) = 0 :=
bag.induction_on b rfl
(λ c b ih, by_cases
(suppose a = c, begin subst c, rewrite [extract_insert, ih] end)
(suppose a ≠ c, begin rewrite [extract_insert_of_ne this, count_insert_of_ne this, ih] end))
lemma count_extract_of_ne {a₁ a₂ : A} (h : a₁ ≠ a₂) (b : bag A) : count a₁ (extract a₂ b) = count a₁ b :=
bag.induction_on b rfl
(take x b ih, by_cases
(suppose x = a₁, begin subst x, rewrite [extract_insert_of_ne (ne.symm h), *count_insert, ih] end)
(suppose x ≠ a₁, by_cases
(suppose x = a₂, begin subst x, rewrite [extract_insert, ih, count_insert_of_ne h] end)
(suppose x ≠ a₂, begin
rewrite [count_insert_of_ne (ne.symm `x ≠ a₁`), extract_insert_of_ne (ne.symm this)],
rewrite [count_insert_of_ne (ne.symm `x ≠ a₁`), ih]
end)))
end extract
section erase
variable [decA : decidable_eq A]
include decA
definition erase (a : A) (b : bag A) : bag A :=
quot.lift_on b (λ l, ⟦erase a l⟧)
(λ l₁ l₂ h, quot.sound (erase_perm_erase_of_perm _ h))
lemma erase_empty (a : A) : erase a empty = empty :=
rfl
lemma erase_insert (a : A) (b : bag A) : erase a (insert a b) = b :=
quot.induction_on b (λ l, quot.sound (by rewrite erase_cons_head; apply perm.refl))
lemma erase_insert_of_ne {a₁ a₂ : A} (h : a₁ ≠ a₂) (b : bag A) : erase a₁ (insert a₂ b) = insert a₂ (erase a₁ b) :=
quot.induction_on b (λ l, quot.sound (by rewrite (erase_cons_tail _ h); apply perm.refl))
end erase
section member
variable [decA : decidable_eq A]
include decA
definition mem (a : A) (b : bag A) := count a b > 0
infix ∈ := mem
lemma mem_def (a : A) (b : bag A) : (a ∈ b) = (count a b > 0) :=
rfl
lemma mem_insert (a : A) (b : bag A) : a ∈ insert a b :=
begin unfold mem, rewrite count_insert, exact dec_trivial end
lemma mem_of_list_iff_mem (a : A) (l : list A) : a ∈ of_list l ↔ a ∈ l :=
iff.intro !mem_of_count_gt_zero !count_gt_zero_of_mem
lemma count_of_list_eq_count (a : A) (l : list A) : count a (of_list l) = list.count a l :=
rfl
end member
section union_inter
variable [decA : decidable_eq A]
include decA
open perm decidable
private definition union_list (l₁ l₂ : list A) :=
erase_dup (l₁ ++ l₂)
private lemma perm_union_list {l₁ l₂ l₃ l₄ : list A} (h₁ : l₁ ~ l₃) (h₂ : l₂ ~ l₄) : union_list l₁ l₂ ~ union_list l₃ l₄ :=
perm_erase_dup_of_perm (perm_app h₁ h₂)
private lemma nodup_union_list (l₁ l₂ : list A) : nodup (union_list l₁ l₂) :=
!nodup_erase_dup
private definition not_mem_of_not_mem_union_list_left {a : A} {l₁ l₂ : list A} (h : a ∉ union_list l₁ l₂) : a ∉ l₁ :=
suppose a ∈ l₁,
have a ∈ l₁ ++ l₂, from mem_append_left _ this,
have a ∈ erase_dup (l₁ ++ l₂), from mem_erase_dup this,
absurd this h
private definition not_mem_of_not_mem_union_list_right {a : A} {l₁ l₂ : list A} (h : a ∉ union_list l₁ l₂) : a ∉ l₂ :=
suppose a ∈ l₂,
have a ∈ l₁ ++ l₂, from mem_append_right _ this,
have a ∈ erase_dup (l₁ ++ l₂), from mem_erase_dup this,
absurd this h
private definition gen : nat → A → list A
| 0 a := nil
| (n+1) a := a :: gen n a
private lemma not_mem_gen_of_ne {a b : A} (h : a ≠ b) : ∀ n, a ∉ gen n b
| 0 := !not_mem_nil
| (n+1) := not_mem_cons_of_ne_of_not_mem h (not_mem_gen_of_ne n)
private lemma count_gen : ∀ (a : A) (n : nat), list.count a (gen n a) = n
| a 0 := rfl
| a (n+1) := begin unfold gen, rewrite [count_cons_eq, count_gen] end
private lemma count_gen_eq_zero_of_ne {a b : A} (h : a ≠ b) : ∀ n, list.count a (gen n b) = 0
| 0 := rfl
| (n+1) := begin unfold gen, rewrite [count_cons_of_ne h, count_gen_eq_zero_of_ne] end
private definition max_count (l₁ l₂ : list A) : list A → list A
| [] := []
| (a::l) := if list.count a l₁ ≥ list.count a l₂ then gen (list.count a l₁) a ++ max_count l else gen (list.count a l₂) a ++ max_count l
private definition min_count (l₁ l₂ : list A) : list A → list A
| [] := []
| (a::l) := if list.count a l₁ ≤ list.count a l₂ then gen (list.count a l₁) a ++ min_count l else gen (list.count a l₂) a ++ min_count l
private lemma not_mem_max_count_of_not_mem (l₁ l₂ : list A) : ∀ {a l}, a ∉ l → a ∉ max_count l₁ l₂ l
| a [] h := !not_mem_nil
| a (b::l) h :=
assert ih : a ∉ max_count l₁ l₂ l, from not_mem_max_count_of_not_mem (not_mem_of_not_mem_cons h),
assert a ≠ b, from ne_of_not_mem_cons h,
by_cases
(suppose list.count b l₁ ≥ list.count b l₂, begin
unfold max_count, rewrite [if_pos this],
exact not_mem_append (not_mem_gen_of_ne `a ≠ b` _) ih
end)
(suppose ¬ list.count b l₁ ≥ list.count b l₂, begin
unfold max_count, rewrite [if_neg this],
exact not_mem_append (not_mem_gen_of_ne `a ≠ b` _) ih
end)
private lemma max_count_eq (l₁ l₂ : list A) : ∀ {a : A} {l : list A}, a ∈ l → nodup l → list.count a (max_count l₁ l₂ l) = max (list.count a l₁) (list.count a l₂)
| a [] h₁ h₂ := absurd h₁ !not_mem_nil
| a (b::l) h₁ h₂ :=
assert nodup l, from nodup_of_nodup_cons h₂,
assert b ∉ l, from not_mem_of_nodup_cons h₂,
or.elim h₁
(suppose a = b,
have a ∉ l, by rewrite this; assumption,
assert a ∉ max_count l₁ l₂ l, from not_mem_max_count_of_not_mem l₁ l₂ this,
by_cases
(suppose i : list.count a l₁ ≥ list.count a l₂, begin
unfold max_count, subst b,
rewrite [if_pos i, list.count_append, count_gen, max_eq_left i, count_eq_zero_of_not_mem `a ∉ max_count l₁ l₂ l`]
end)
(suppose i : ¬ list.count a l₁ ≥ list.count a l₂, begin
unfold max_count, subst b,
rewrite [if_neg i, list.count_append, count_gen, max_eq_right_of_lt (lt_of_not_ge i), count_eq_zero_of_not_mem `a ∉ max_count l₁ l₂ l`]
end))
(suppose a ∈ l,
assert a ≠ b, from suppose a = b, by subst b; contradiction,
assert ih : list.count a (max_count l₁ l₂ l) = max (list.count a l₁) (list.count a l₂), from max_count_eq `a ∈ l` `nodup l`,
by_cases
(suppose i : list.count b l₁ ≥ list.count b l₂, begin
unfold max_count,
rewrite [if_pos i, -ih, list.count_append, count_gen_eq_zero_of_ne `a ≠ b`, zero_add]
end)
(suppose i : ¬ list.count b l₁ ≥ list.count b l₂, begin
unfold max_count,
rewrite [if_neg i, -ih, list.count_append, count_gen_eq_zero_of_ne `a ≠ b`, zero_add]
end))
private lemma not_mem_min_count_of_not_mem (l₁ l₂ : list A) : ∀ {a l}, a ∉ l → a ∉ min_count l₁ l₂ l
| a [] h := !not_mem_nil
| a (b::l) h :=
assert ih : a ∉ min_count l₁ l₂ l, from not_mem_min_count_of_not_mem (not_mem_of_not_mem_cons h),
assert a ≠ b, from ne_of_not_mem_cons h,
by_cases
(suppose list.count b l₁ ≤ list.count b l₂, begin
unfold min_count, rewrite [if_pos this],
exact not_mem_append (not_mem_gen_of_ne `a ≠ b` _) ih
end)
(suppose ¬ list.count b l₁ ≤ list.count b l₂, begin
unfold min_count, rewrite [if_neg this],
exact not_mem_append (not_mem_gen_of_ne `a ≠ b` _) ih
end)
private lemma min_count_eq (l₁ l₂ : list A) : ∀ {a : A} {l : list A}, a ∈ l → nodup l → list.count a (min_count l₁ l₂ l) = min (list.count a l₁) (list.count a l₂)
| a [] h₁ h₂ := absurd h₁ !not_mem_nil
| a (b::l) h₁ h₂ :=
assert nodup l, from nodup_of_nodup_cons h₂,
assert b ∉ l, from not_mem_of_nodup_cons h₂,
or.elim h₁
(suppose a = b,
have a ∉ l, by rewrite this; assumption,
assert a ∉ min_count l₁ l₂ l, from not_mem_min_count_of_not_mem l₁ l₂ this,
by_cases
(suppose i : list.count a l₁ ≤ list.count a l₂, begin
unfold min_count, subst b,
rewrite [if_pos i, list.count_append, count_gen, min_eq_left i, count_eq_zero_of_not_mem `a ∉ min_count l₁ l₂ l`]
end)
(suppose i : ¬ list.count a l₁ ≤ list.count a l₂, begin
unfold min_count, subst b,
rewrite [if_neg i, list.count_append, count_gen, min_eq_right (le_of_lt (lt_of_not_ge i)), count_eq_zero_of_not_mem `a ∉ min_count l₁ l₂ l`]
end))
(suppose a ∈ l,
assert a ≠ b, from suppose a = b, by subst b; contradiction,
assert ih : list.count a (min_count l₁ l₂ l) = min (list.count a l₁) (list.count a l₂), from min_count_eq `a ∈ l` `nodup l`,
by_cases
(suppose i : list.count b l₁ ≤ list.count b l₂, begin
unfold min_count,
rewrite [if_pos i, -ih, list.count_append, count_gen_eq_zero_of_ne `a ≠ b`, zero_add]
end)
(suppose i : ¬ list.count b l₁ ≤ list.count b l₂, begin
unfold min_count,
rewrite [if_neg i, -ih, list.count_append, count_gen_eq_zero_of_ne `a ≠ b`, zero_add]
end))
private lemma perm_max_count_left {l₁ l₂ l₃ l₄ : list A} (h₁ : l₁ ~ l₃) (h₂ : l₂ ~ l₄) : ∀ l, max_count l₁ l₂ l ~ max_count l₃ l₄ l
| [] := by esimp
| (a::l) :=
assert e₁ : list.count a l₁ = list.count a l₃, from count_eq_of_perm h₁ a,
assert e₂ : list.count a l₂ = list.count a l₄, from count_eq_of_perm h₂ a,
by_cases
(suppose list.count a l₁ ≥ list.count a l₂,
begin unfold max_count, rewrite [-e₁, -e₂, *if_pos this], exact perm_app !perm.refl !perm_max_count_left end)
(suppose ¬ list.count a l₁ ≥ list.count a l₂,
begin unfold max_count, rewrite [-e₁, -e₂, *if_neg this], exact perm_app !perm.refl !perm_max_count_left end)
private lemma perm_app_left_comm (l₁ l₂ l₃ : list A) : l₁ ++ (l₂ ++ l₃) ~ l₂ ++ (l₁ ++ l₃) :=
calc l₁ ++ (l₂ ++ l₃) = (l₁ ++ l₂) ++ l₃ : list.append.assoc
... ~ (l₂ ++ l₁) ++ l₃ : perm_app !perm_app_comm !perm.refl
... = l₂ ++ (l₁ ++ l₃) : list.append.assoc
private lemma perm_max_count_right {l r : list A} (h : l ~ r) : ∀ l₁ l₂, max_count l₁ l₂ l ~ max_count l₁ l₂ r :=
perm.induction_on h
(λ l₁ l₂, !perm.refl)
(λ x s₁ s₂ p ih l₁ l₂, by_cases
(suppose i : list.count x l₁ ≥ list.count x l₂,
begin unfold max_count, rewrite [*if_pos i], exact perm_app !perm.refl !ih end)
(suppose i : ¬ list.count x l₁ ≥ list.count x l₂,
begin unfold max_count, rewrite [*if_neg i], exact perm_app !perm.refl !ih end))
(λ x y l l₁ l₂, by_cases
(suppose i₁ : list.count x l₁ ≥ list.count x l₂, by_cases
(suppose i₂ : list.count y l₁ ≥ list.count y l₂,
begin unfold max_count, unfold max_count, rewrite [*if_pos i₁, *if_pos i₂], apply perm_app_left_comm end)
(suppose i₂ : ¬ list.count y l₁ ≥ list.count y l₂,
begin unfold max_count, unfold max_count, rewrite [*if_pos i₁, *if_neg i₂], apply perm_app_left_comm end))
(suppose i₁ : ¬ list.count x l₁ ≥ list.count x l₂, by_cases
(suppose i₂ : list.count y l₁ ≥ list.count y l₂,
begin unfold max_count, unfold max_count, rewrite [*if_neg i₁, *if_pos i₂], apply perm_app_left_comm end)
(suppose i₂ : ¬ list.count y l₁ ≥ list.count y l₂,
begin unfold max_count, unfold max_count, rewrite [*if_neg i₁, *if_neg i₂], apply perm_app_left_comm end)))
(λ s₁ s₂ s₃ p₁ p₂ ih₁ ih₂ l₁ l₂, perm.trans (ih₁ l₁ l₂) (ih₂ l₁ l₂))
private lemma perm_max_count {l₁ l₂ l₃ r₁ r₂ r₃ : list A} (p₁ : l₁ ~ r₁) (p₂ : l₂ ~ r₂) (p₃ : l₃ ~ r₃) : max_count l₁ l₂ l₃ ~ max_count r₁ r₂ r₃ :=
calc max_count l₁ l₂ l₃ ~ max_count r₁ r₂ l₃ : perm_max_count_left p₁ p₂
... ~ max_count r₁ r₂ r₃ : perm_max_count_right p₃
private lemma perm_min_count_left {l₁ l₂ l₃ l₄ : list A} (h₁ : l₁ ~ l₃) (h₂ : l₂ ~ l₄) : ∀ l, min_count l₁ l₂ l ~ min_count l₃ l₄ l
| [] := by esimp
| (a::l) :=
assert e₁ : list.count a l₁ = list.count a l₃, from count_eq_of_perm h₁ a,
assert e₂ : list.count a l₂ = list.count a l₄, from count_eq_of_perm h₂ a,
by_cases
(suppose list.count a l₁ ≤ list.count a l₂,
begin unfold min_count, rewrite [-e₁, -e₂, *if_pos this], exact perm_app !perm.refl !perm_min_count_left end)
(suppose ¬ list.count a l₁ ≤ list.count a l₂,
begin unfold min_count, rewrite [-e₁, -e₂, *if_neg this], exact perm_app !perm.refl !perm_min_count_left end)
private lemma perm_min_count_right {l r : list A} (h : l ~ r) : ∀ l₁ l₂, min_count l₁ l₂ l ~ min_count l₁ l₂ r :=
perm.induction_on h
(λ l₁ l₂, !perm.refl)
(λ x s₁ s₂ p ih l₁ l₂, by_cases
(suppose i : list.count x l₁ ≤ list.count x l₂,
begin unfold min_count, rewrite [*if_pos i], exact perm_app !perm.refl !ih end)
(suppose i : ¬ list.count x l₁ ≤ list.count x l₂,
begin unfold min_count, rewrite [*if_neg i], exact perm_app !perm.refl !ih end))
(λ x y l l₁ l₂, by_cases
(suppose i₁ : list.count x l₁ ≤ list.count x l₂, by_cases
(suppose i₂ : list.count y l₁ ≤ list.count y l₂,
begin unfold min_count, unfold min_count, rewrite [*if_pos i₁, *if_pos i₂], apply perm_app_left_comm end)
(suppose i₂ : ¬ list.count y l₁ ≤ list.count y l₂,
begin unfold min_count, unfold min_count, rewrite [*if_pos i₁, *if_neg i₂], apply perm_app_left_comm end))
(suppose i₁ : ¬ list.count x l₁ ≤ list.count x l₂, by_cases
(suppose i₂ : list.count y l₁ ≤ list.count y l₂,
begin unfold min_count, unfold min_count, rewrite [*if_neg i₁, *if_pos i₂], apply perm_app_left_comm end)
(suppose i₂ : ¬ list.count y l₁ ≤ list.count y l₂,
begin unfold min_count, unfold min_count, rewrite [*if_neg i₁, *if_neg i₂], apply perm_app_left_comm end)))
(λ s₁ s₂ s₃ p₁ p₂ ih₁ ih₂ l₁ l₂, perm.trans (ih₁ l₁ l₂) (ih₂ l₁ l₂))
private lemma perm_min_count {l₁ l₂ l₃ r₁ r₂ r₃ : list A} (p₁ : l₁ ~ r₁) (p₂ : l₂ ~ r₂) (p₃ : l₃ ~ r₃) : min_count l₁ l₂ l₃ ~ min_count r₁ r₂ r₃ :=
calc min_count l₁ l₂ l₃ ~ min_count r₁ r₂ l₃ : perm_min_count_left p₁ p₂
... ~ min_count r₁ r₂ r₃ : perm_min_count_right p₃
definition union (b₁ b₂ : bag A) : bag A :=
quot.lift_on₂ b₁ b₂ (λ l₁ l₂, ⟦max_count l₁ l₂ (union_list l₁ l₂)⟧)
(λ l₁ l₂ l₃ l₄ p₁ p₂, quot.sound (perm_max_count p₁ p₂ (perm_union_list p₁ p₂)))
infix ∪ := union
definition inter (b₁ b₂ : bag A) : bag A :=
quot.lift_on₂ b₁ b₂ (λ l₁ l₂, ⟦min_count l₁ l₂ (union_list l₁ l₂)⟧)
(λ l₁ l₂ l₃ l₄ p₁ p₂, quot.sound (perm_min_count p₁ p₂ (perm_union_list p₁ p₂)))
infix ∩ := inter
lemma count_union (a : A) (b₁ b₂ : bag A) : count a (b₁ ∪ b₂) = max (count a b₁) (count a b₂) :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂, by_cases
(suppose a ∈ union_list l₁ l₂, !max_count_eq this !nodup_union_list)
(suppose ¬ a ∈ union_list l₁ l₂,
assert ¬ a ∈ l₁, from not_mem_of_not_mem_union_list_left `¬ a ∈ union_list l₁ l₂`,
assert ¬ a ∈ l₂, from not_mem_of_not_mem_union_list_right `¬ a ∈ union_list l₁ l₂`,
assert n : ¬ a ∈ max_count l₁ l₂ (union_list l₁ l₂), from not_mem_max_count_of_not_mem l₁ l₂ `¬ a ∈ union_list l₁ l₂`,
begin
unfold [union, count],
rewrite [count_eq_zero_of_not_mem `¬ a ∈ l₁`, count_eq_zero_of_not_mem `¬ a ∈ l₂`, max_self],
rewrite [count_eq_zero_of_not_mem n]
end))
lemma count_inter (a : A) (b₁ b₂ : bag A) : count a (b₁ ∩ b₂) = min (count a b₁) (count a b₂) :=
quot.induction_on₂ b₁ b₂ (λ l₁ l₂, by_cases
(suppose a ∈ union_list l₁ l₂, !min_count_eq this !nodup_union_list)
(suppose ¬ a ∈ union_list l₁ l₂,
assert ¬ a ∈ l₁, from not_mem_of_not_mem_union_list_left `¬ a ∈ union_list l₁ l₂`,
assert ¬ a ∈ l₂, from not_mem_of_not_mem_union_list_right `¬ a ∈ union_list l₁ l₂`,
assert n : ¬ a ∈ min_count l₁ l₂ (union_list l₁ l₂), from not_mem_min_count_of_not_mem l₁ l₂ `¬ a ∈ union_list l₁ l₂`,
begin
unfold [inter, count],
rewrite [count_eq_zero_of_not_mem `¬ a ∈ l₁`, count_eq_zero_of_not_mem `¬ a ∈ l₂`, min_self],
rewrite [count_eq_zero_of_not_mem n]
end))
lemma union.comm (b₁ b₂ : bag A) : b₁ ∪ b₂ = b₂ ∪ b₁ :=
bag.ext (λ a, by rewrite [*count_union, max.comm])
lemma union.assoc (b₁ b₂ b₃ : bag A) : (b₁ ∪ b₂) ∪ b₃ = b₁ ∪ (b₂ ∪ b₃) :=
bag.ext (λ a, by rewrite [*count_union, max.assoc])
theorem union.left_comm (s₁ s₂ s₃ : bag A) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
!left_comm union.comm union.assoc s₁ s₂ s₃
lemma union_self (b : bag A) : b ∪ b = b :=
bag.ext (λ a, by rewrite [*count_union, max_self])
lemma union_empty (b : bag A) : b ∪ empty = b :=
bag.ext (λ a, by rewrite [*count_union, count_empty, max_zero])
lemma empty_union (b : bag A) : empty ∪ b = b :=
calc empty ∪ b = b ∪ empty : union.comm
... = b : union_empty
lemma inter.comm (b₁ b₂ : bag A) : b₁ ∩ b₂ = b₂ ∩ b₁ :=
bag.ext (λ a, by rewrite [*count_inter, min.comm])
lemma inter.assoc (b₁ b₂ b₃ : bag A) : (b₁ ∩ b₂) ∩ b₃ = b₁ ∩ (b₂ ∩ b₃) :=
bag.ext (λ a, by rewrite [*count_inter, min.assoc])
theorem inter.left_comm (s₁ s₂ s₃ : bag A) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
!left_comm inter.comm inter.assoc s₁ s₂ s₃
lemma inter_self (b : bag A) : b ∩ b = b :=
bag.ext (λ a, by rewrite [*count_inter, min_self])
lemma inter_empty (b : bag A) : b ∩ empty = empty :=
bag.ext (λ a, by rewrite [*count_inter, count_empty, min_zero])
lemma empty_inter (b : bag A) : empty ∩ b = empty :=
calc empty ∩ b = b ∩ empty : inter.comm
... = empty : inter_empty
lemma append_union_inter (b₁ b₂ : bag A) : (b₁ ∪ b₂) ++ (b₁ ∩ b₂) = b₁ ++ b₂ :=
bag.ext (λ a, begin
rewrite [*count_append, count_inter, count_union],
apply (or.elim (lt_or_ge (count a b₁) (count a b₂))),
{ intro H, rewrite [min_eq_left_of_lt H, max_eq_right_of_lt H, add.comm] },
{ intro H, rewrite [min_eq_right H, max_eq_left H, add.comm] }
end)
lemma inter.left_distrib (b₁ b₂ b₃ : bag A) : b₁ ∩ (b₂ ∪ b₃) = (b₁ ∩ b₂) ∪ (b₁ ∩ b₃) :=
bag.ext (λ a, begin
rewrite [*count_inter, *count_union, *count_inter],
apply (@by_cases (count a b₁ ≤ count a b₂)),
{ intro H₁₂, apply (@by_cases (count a b₂ ≤ count a b₃)),
{ intro H₂₃,
have H₁₃ : count a b₁ ≤ count a b₃, from le.trans H₁₂ H₂₃,
rewrite [max_eq_right H₂₃, min_eq_left H₁₂, min_eq_left H₁₃, max_self]},
{ intro H₂₃,
rewrite [min_eq_left H₁₂, max.comm, max_eq_right_of_lt (lt_of_not_ge H₂₃) ],
apply (@by_cases (count a b₁ ≤ count a b₃)),
{ intro H₁₃, rewrite [min_eq_left H₁₃, max_self, min_eq_left H₁₂] },
{ intro H₁₃,
rewrite [min.comm (count a b₁) (count a b₃), min_eq_left_of_lt (lt_of_not_ge H₁₃),
min_eq_left H₁₂, max.comm, max_eq_right_of_lt (lt_of_not_ge H₁₃)]}}},
{ intro H₁₂, apply (@by_cases (count a b₂ ≤ count a b₃)),
{ intro H₂₃,
rewrite [max_eq_right H₂₃],
apply (@by_cases (count a b₁ ≤ count a b₃)),
{ intro H₁₃, rewrite [min_eq_left H₁₃, min.comm, min_eq_left_of_lt (lt_of_not_ge H₁₂), max_eq_right_of_lt (lt_of_not_ge H₁₂)] },
{ intro H₁₃, rewrite [min.comm, min_eq_left_of_lt (lt_of_not_ge H₁₃), min.comm, min_eq_left_of_lt (lt_of_not_ge H₁₂), max_eq_right H₂₃] } },
{ intro H₂₃,
have H₁₃ : count a b₁ > count a b₃, from lt.trans (lt_of_not_ge H₂₃) (lt_of_not_ge H₁₂),
rewrite [max.comm, max_eq_right_of_lt (lt_of_not_ge H₂₃), min.comm, min_eq_left_of_lt (lt_of_not_ge H₁₂)],
rewrite [min.comm, min_eq_left_of_lt H₁₃, max.comm, max_eq_right_of_lt (lt_of_not_ge H₂₃)] } }
end)
lemma inter.right_distrib (b₁ b₂ b₃ : bag A) : (b₁ ∪ b₂) ∩ b₃ = (b₁ ∩ b₃) ∪ (b₂ ∩ b₃) :=
calc (b₁ ∪ b₂) ∩ b₃ = b₃ ∩ (b₁ ∪ b₂) : inter.comm
... = (b₃ ∩ b₁) ∪ (b₃ ∩ b₂) : inter.left_distrib
... = (b₁ ∩ b₃) ∪ (b₃ ∩ b₂) : inter.comm
... = (b₁ ∩ b₃) ∪ (b₂ ∩ b₃) : inter.comm
end union_inter
section subbag
variable [decA : decidable_eq A]
include decA
definition subbag (b₁ b₂ : bag A) := ∀ a, count a b₁ ≤ count a b₂
infix ⊆ := subbag
lemma subbag.refl (b : bag A) : b ⊆ b :=
take a, !le.refl
lemma subbag.trans {b₁ b₂ b₃ : bag A} : b₁ ⊆ b₂ → b₂ ⊆ b₃ → b₁ ⊆ b₃ :=
assume h₁ h₂, take a, le.trans (h₁ a) (h₂ a)
lemma subbag.antisymm {b₁ b₂ : bag A} : b₁ ⊆ b₂ → b₂ ⊆ b₁ → b₁ = b₂ :=
assume h₁ h₂, bag.ext (take a, le.antisymm (h₁ a) (h₂ a))
lemma count_le_of_subbag {b₁ b₂ : bag A} : b₁ ⊆ b₂ → ∀ a, count a b₁ ≤ count a b₂ :=
assume h, h
lemma subbag.intro {b₁ b₂ : bag A} : (∀ a, count a b₁ ≤ count a b₂) → b₁ ⊆ b₂ :=
assume h, h
lemma empty_subbag (b : bag A) : empty ⊆ b :=
subbag.intro (take a, !zero_le)
lemma eq_empty_of_subbag_empty {b : bag A} : b ⊆ empty → b = empty :=
assume h, subbag.antisymm h (empty_subbag b)
lemma union_subbag_of_subbag_of_subbag {b₁ b₂ b₃ : bag A} : b₁ ⊆ b₃ → b₂ ⊆ b₃ → b₁ ∪ b₂ ⊆ b₃ :=
assume h₁ h₂, subbag.intro (λ a, calc
count a (b₁ ∪ b₂) = max (count a b₁) (count a b₂) : by rewrite count_union
... ≤ count a b₃ : max_le (h₁ a) (h₂ a))
lemma subbag_inter_of_subbag_of_subbag {b₁ b₂ b₃ : bag A} : b₁ ⊆ b₂ → b₁ ⊆ b₃ → b₁ ⊆ b₂ ∩ b₃ :=
assume h₁ h₂, subbag.intro (λ a, calc
count a b₁ ≤ min (count a b₂) (count a b₃) : le_min (h₁ a) (h₂ a)
... = count a (b₂ ∩ b₃) : by rewrite count_inter)
lemma subbag_union_left (b₁ b₂ : bag A) : b₁ ⊆ b₁ ∪ b₂ :=
subbag.intro (take a, by rewrite [count_union]; apply le_max_left)
lemma subbag_union_right (b₁ b₂ : bag A) : b₂ ⊆ b₁ ∪ b₂ :=
subbag.intro (take a, by rewrite [count_union]; apply le_max_right)
lemma inter_subbag_left (b₁ b₂ : bag A) : b₁ ∩ b₂ ⊆ b₁ :=
subbag.intro (take a, by rewrite [count_inter]; apply min_le_left)
lemma inter_subbag_right (b₁ b₂ : bag A) : b₁ ∩ b₂ ⊆ b₂ :=
subbag.intro (take a, by rewrite [count_inter]; apply min_le_right)
lemma subbag_append_left (b₁ b₂ : bag A) : b₁ ⊆ b₁ ++ b₂ :=
subbag.intro (take a, by rewrite [count_append]; apply le_add_right)
lemma subbag_append_right (b₁ b₂ : bag A) : b₂ ⊆ b₁ ++ b₂ :=
subbag.intro (take a, by rewrite [count_append]; apply le_add_left)
lemma inter_subbag_union (b₁ b₂ : bag A) : b₁ ∩ b₂ ⊆ b₁ ∪ b₂ :=
subbag.trans (inter_subbag_left b₁ b₂) (subbag_union_left b₁ b₂)
open decidable
lemma union_subbag_append (b₁ b₂ : bag A) : b₁ ∪ b₂ ⊆ b₁ ++ b₂ :=
subbag.intro (take a, begin
rewrite [count_append, count_union],
exact (or.elim !lt_or_ge)
(suppose count a b₁ < count a b₂, by rewrite [max_eq_right_of_lt this]; apply le_add_left)
(suppose count a b₁ ≥ count a b₂, by rewrite [max_eq_left this]; apply le_add_right)
end)
lemma subbag_insert (a : A) (b : bag A) : b ⊆ insert a b :=
subbag.intro (take x, by_cases
(suppose x = a, by rewrite [this, count_insert]; apply le_succ)
(suppose x ≠ a, by rewrite [count_insert_of_ne this]))
lemma mem_of_subbag_of_mem {a : A} {b₁ b₂ : bag A} : b₁ ⊆ b₂ → a ∈ b₁ → a ∈ b₂ :=
assume h₁ h₂,
have count a b₁ ≤ count a b₂, from count_le_of_subbag h₁ a,
have count a b₁ > 0, from h₂,
show count a b₂ > 0, from lt_of_lt_of_le `0 < count a b₁` `count a b₁ ≤ count a b₂`
lemma extract_subbag (a : A) (b : bag A) : extract a b ⊆ b :=
subbag.intro (take x, by_cases
(suppose x = a, by rewrite [this, count_extract]; apply zero_le)
(suppose x ≠ a, by rewrite [count_extract_of_ne this]))
open bool
private definition subcount : list A → list A → bool
| [] l₂ := tt
| (a::l₁) l₂ := if list.count a (a::l₁) ≤ list.count a l₂ then subcount l₁ l₂ else ff
private lemma all_of_subcount_eq_tt : ∀ {l₁ l₂ : list A}, subcount l₁ l₂ = tt → ∀ a, list.count a l₁ ≤ list.count a l₂
| [] l₂ h := take x, !zero_le
| (a::l₁) l₂ h := take x,
have subcount l₁ l₂ = tt, from by_contradiction (suppose subcount l₁ l₂ ≠ tt,
assert subcount l₁ l₂ = ff, from eq_ff_of_ne_tt this,
begin unfold subcount at h, rewrite [this at h, if_t_t at h], contradiction end),
assert ih : ∀ a, list.count a l₁ ≤ list.count a l₂, from all_of_subcount_eq_tt this,
assert i : list.count a (a::l₁) ≤ list.count a l₂, from by_contradiction (suppose ¬ list.count a (a::l₁) ≤ list.count a l₂,
begin unfold subcount at h, rewrite [if_neg this at h], contradiction end),
by_cases
(suppose x = a, by rewrite this; apply i)
(suppose x ≠ a, by rewrite [list.count_cons_of_ne this]; apply ih)
private lemma ex_of_subcount_eq_ff : ∀ {l₁ l₂ : list A}, subcount l₁ l₂ = ff → ∃ a, ¬ list.count a l₁ ≤ list.count a l₂
| [] l₂ h := by contradiction
| (a::l₁) l₂ h := by_cases
(suppose i : list.count a (a::l₁) ≤ list.count a l₂,
have subcount l₁ l₂ = ff, from by_contradiction (suppose subcount l₁ l₂ ≠ ff,
assert subcount l₁ l₂ = tt, from eq_tt_of_ne_ff this,
begin
unfold subcount at h,
rewrite [if_pos i at h, this at h],
contradiction
end),
have ih : ∃ a, ¬ list.count a l₁ ≤ list.count a l₂, from ex_of_subcount_eq_ff this,
obtain w hw, from ih, by_cases
(suppose w = a, begin subst w, existsi a, rewrite list.count_cons_eq, apply not_lt_of_ge, apply le_of_lt (lt_of_not_ge hw) end)
(suppose w ≠ a, exists.intro w (by rewrite (list.count_cons_of_ne `w ≠ a`); exact hw)))
(suppose ¬ list.count a (a::l₁) ≤ list.count a l₂, exists.intro a this)
definition decidable_subbag [instance] (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quot.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match subcount l₁ l₂ with
| tt := suppose subcount l₁ l₂ = tt, inl (all_of_subcount_eq_tt this)
| ff := suppose subcount l₁ l₂ = ff, inr (suppose h : (∀ a, list.count a l₁ ≤ list.count a l₂),
obtain w hw, from ex_of_subcount_eq_ff `subcount l₁ l₂ = ff`,
absurd (h w) hw)
end rfl)
end subbag
end bag
|
30e2092892a543ee57226849db27f039967c714d
|
0707842a58b971bc2c537fdcab2f5cef1c12d77a
|
/lean4/05_first_class_functions.lean
|
bc53c6ba8133b0515a9f8bff3109bca0776995ac
|
[] |
no_license
|
adolfont/LearningProgramming
|
7a41e5dfde8df72fc0b4a23592999ecdb22a26e0
|
866e6654d347287bd0c63aa31d18705174f00324
|
refs/heads/master
| 1,652,902,832,503
| 1,651,315,660,000
| 1,651,315,660,000
| 1,328,601
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,350
|
lean
|
-- Source: https://leanprover.github.io/lean4/doc/tour.html
-- Lean has first-class functions.
-- `twice` takes two arguments `f` and `a` where
-- `f` is a function from natural numbers to natural numbers, and
-- `a` is a natural number.
def twice (f : Nat → Nat) (a : Nat) :=
f (f a)
-- `fun` is used to declare anonymous functions
#eval twice (fun x => x + 2) 10
-- You can prove theorems about your functions.
-- The following theorem states that for any natural number `a`,
-- adding 2 twice produces a value equal to `a + 4`.
theorem twiceAdd2 (a : Nat) : twice (fun x => x + 2) a = a + 4 :=
-- The proof is by reflexivity. Lean "symbolically" reduces both sides of the equality
-- until they are identical.
rfl
-- `(· + 2)` is syntax sugar for `(fun x => x + 2)`. The parentheses + `·` notation
-- is useful for defining simple anonymous functions.
#eval twice (· + 2) 10
-- Enumerated types are a special case of inductive types in Lean,
-- which we will learn about later.
-- The following command creates a new type `Weekday`.
inductive Weekday where
| sunday : Weekday
| monday : Weekday
| tuesday : Weekday
| wednesday : Weekday
| thursday : Weekday
| friday : Weekday
| saturday : Weekday
-- `Weekday` has 7 constructors/elements.
-- The constructors live in the `Weekday` namespace.
-- Think of `sunday`, `monday`, …, `saturday` as being distinct elements of `Weekday`,
-- with no other distinguishing properties.
-- The command `#check` prints the type of a term in Lean.
#check Weekday.sunday
#check Weekday.monday
-- The `open` command opens a namespace, making all declarations in it accessible without
-- qualification.
open Weekday
#check sunday
#check tuesday
-- You can define functions by pattern matching.
-- The following function converts a `Weekday` into a natural number.
def natOfWeekday (d : Weekday) : Nat :=
match d with
| sunday => 1
| monday => 2
| tuesday => 3
| wednesday => 4
| thursday => 5
| friday => 6
| saturday => 7
#eval natOfWeekday tuesday
def isMonday : Weekday → Bool :=
-- `fun` + `match` is a common idiom.
-- The following expression is syntax sugar for
-- `fun d => match d with | monday => true | _ => false`.
fun
| monday => true
| _ => false
#eval isMonday monday
#eval isMonday sunday
-- Lean has support for type classes and polymorphic methods.
-- The `toString` method converts a value into a `String`.
#eval toString 10
#eval toString (10, 20)
-- The method `toString` converts values of any type that implements
-- the class `ToString`.
-- You can implement instances of `ToString` for your own types.
instance : ToString Weekday where
toString (d : Weekday) : String :=
match d with
| sunday => "Sunday"
| monday => "Monday"
| tuesday => "Tuesday"
| wednesday => "Wednesday"
| thursday => "Thursday"
| friday => "Friday"
| saturday => "Saturday"
#eval toString (sunday, 10)
def Weekday.next (d : Weekday) : Weekday :=
match d with
| sunday => monday
| monday => tuesday
| tuesday => wednesday
| wednesday => thursday
| thursday => friday
| friday => saturday
| saturday => sunday
#eval Weekday.next Weekday.wednesday
-- Since the `Weekday` namespace has already been opened, you can also write
#eval next wednesday
-- Matching on a parameter like in the previous definition
-- is so common that Lean provides syntax sugar for it. The following
-- function uses it.
def Weekday.previous : Weekday -> Weekday
| sunday => saturday
| monday => sunday
| tuesday => monday
| wednesday => tuesday
| thursday => wednesday
| friday => thursday
| saturday => friday
#eval next (previous wednesday)
-- We can prove that for any `Weekday` `d`, `next (previous d) = d`
theorem Weekday.nextOfPrevious (d : Weekday) : next (previous d) = d :=
match d with
| sunday => rfl
| monday => rfl
| tuesday => rfl
| wednesday => rfl
| thursday => rfl
| friday => rfl
| saturday => rfl
-- You can automate definitions such as `Weekday.nextOfPrevious`
-- using metaprogramming (or "tactics").
theorem Weekday.nextOfPrevious' (d : Weekday) : next (previous d) = d := by
cases d -- A proof by case distinction
all_goals rfl -- Each case is solved using `rfl`
|
0c24995b432d3ebc8d6eb9a3b5b69e9c069dcb3a
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/Lean3Lib/init/data/ordering/lemmas.lean
|
75f8791e634bb2b8e853ba06974e1caa0e9dcb5c
|
[] |
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,454
|
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
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.ordering.basic
import Mathlib.Lean3Lib.init.meta.default
import Mathlib.Lean3Lib.init.algebra.classes
import Mathlib.Lean3Lib.init.ite_simp
universes u
namespace Mathlib
namespace ordering
@[simp] theorem ite_eq_lt_distrib (c : Prop) [Decidable c] (a : ordering) (b : ordering) : ite c a b = lt = ite c (a = lt) (b = lt) := sorry
@[simp] theorem ite_eq_eq_distrib (c : Prop) [Decidable c] (a : ordering) (b : ordering) : ite c a b = eq = ite c (a = eq) (b = eq) := sorry
@[simp] theorem ite_eq_gt_distrib (c : Prop) [Decidable c] (a : ordering) (b : ordering) : ite c a b = gt = ite c (a = gt) (b = gt) := sorry
/- ------------------------------------------------------------------ -/
end ordering
@[simp] theorem cmp_using_eq_lt {α : Type u} {lt : α → α → Prop} [DecidableRel lt] (a : α) (b : α) : cmp_using lt a b = ordering.lt = lt a b := sorry
@[simp] theorem cmp_using_eq_gt {α : Type u} {lt : α → α → Prop} [DecidableRel lt] [is_strict_order α lt] (a : α) (b : α) : cmp_using lt a b = ordering.gt = lt b a := sorry
@[simp] theorem cmp_using_eq_eq {α : Type u} {lt : α → α → Prop} [DecidableRel lt] (a : α) (b : α) : cmp_using lt a b = ordering.eq = (¬lt a b ∧ ¬lt b a) := sorry
|
158f26e7dbe202cc9978eee47a9aae053afd3e2d
|
274748215b6d042f0d9c9a505f9551fa8e0c5f38
|
/src/for_mathlib/commutative_algebra/Zariski_lemma.lean
|
831986fdb50d040a0e1c0bb79f3c2f1844c58ed6
|
[
"Apache-2.0"
] |
permissive
|
ImperialCollegeLondon/M4P33
|
878ecb515c77d20cc799ff1ebd78f1bf4fd65c12
|
1a179372db71ad6802d11eacbc1f02f327d55f8f
|
refs/heads/master
| 1,607,519,867,193
| 1,583,344,297,000
| 1,583,344,297,000
| 233,316,107
| 59
| 4
|
Apache-2.0
| 1,579,285,778,000
| 1,578,788,367,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 10,111
|
lean
|
/-
Zariski's Lemma: if k is a field and K is a field finitely generated
as a k-algebra, then K is also finitely-generated as a k-module
-/
import ring_theory.integral_closure field_theory.subfield
import linear_algebra.finite_dimensional
import for_mathlib.finset -- Chris' lemma about S - {s}
import field_theory.minimal_polynomial -- I need a poly for an algebraic element
-- and this will do
example : 2 + 2 = 4 := rfl
open_locale classical
lemma subalgebra.mem_coe_submodule (R : Type*) [comm_ring R] (A : Type*)
[comm_ring A] [algebra R A]
(M : subalgebra R A) (x : A) : x ∈ (M : submodule R A) ↔ x ∈ M := iff.rfl
lemma subalgebra.coe_submodule_top (R : Type*) [comm_ring R]
(A : Type*) [comm_ring A] [algebra R A] :
((⊤ : subalgebra R A) : submodule R A) = ⊤ :=
begin
ext,
convert iff.refl true,
rw [eq_true, subalgebra.mem_coe_submodule],
exact algebra.mem_top,
end
lemma field.closure.clear_denominators
{K : Type*} [discrete_field K]
{S : finset K} {T : set K}
(hST : ↑S ⊆ field.closure T) :
∃ D : K, D ≠ 0 ∧ D ∈ ring.closure T ∧ ∀ s ∈ S, D * s ∈ ring.closure T :=
begin
revert hST,
apply finset.induction_on S, -- no good because I lose hST
{ intro, use 1,
split, symmetry, exact zero_ne_one,
split, exact is_submonoid.one_mem _,
intros s hs, cases hs,
},
rintros a s has H hasT,
replace H := H (set.subset.trans (finset.subset_insert a s) hasT),
rcases H with ⟨D0, hD00, hD0T, hD0⟩,
rcases hasT (finset.mem_insert_self a s) with ⟨n, hn, d, hd, hd0, hnd⟩,
use D0 * d,
split, exact mul_ne_zero hD00 hd0,
split, exact is_submonoid.mul_mem hD0T hd,
intros k hk,
rw finset.mem_insert at hk,
cases hk,
{ rw hk,
rw mul_assoc,
apply is_submonoid.mul_mem hD0T,
convert hn,
rw ←hnd,
exact mul_div_cancel' n hd0,
},
rw [mul_assoc, mul_left_comm],
exact is_submonoid.mul_mem hd (hD0 k hk),
end
universes u
open set algebra
lemma algebra.adjoin_eq_closure (R : Type*) [comm_ring R] {A : Type*} [ring A]
[algebra R A] (s : set A) :
(↑(adjoin R s) : set A) = ring.closure (set.range (algebra_map A : R → A) ∪ s) := rfl
/-
We formalise the proof in "A note on Zariski's Lemma" by John McCabe,
AMM Vol 83 No 7.
-/
-- needed to get [algebra R K] from (R : subalgebra k K) in next proof
set_option class.instance_max_depth 38
-- We start with the following lemma.
lemma not_fin_dim_of_fin_gen_alg_of_nonintegral
-- Let k be a field
(k : Type*) [discrete_field k] (K : Type*) [discrete_field K]
-- and let K be a field which is generated as a k-algebra
-- by the finite set S ⊆ K
[algebra k K] (S : finset K) (hSgen : adjoin k (↑S : set K) = ⊤)
-- Say s ∈ S is transcendental over k
(s : K) (hs : s ∈ S) (hsnonint : ¬ is_integral k s)
-- Then
:
-- K/k(s) can't be finite-dimensional
¬ (finite_dimensional (field.closure (range (algebra_map K : k → K) ∪ {s})) K)
:=
begin
/-
The argument to prove this in Atiyah--Macdonald uses the Artin-Tate lemma.
I won't formalise this but I'll leave it here for reference.
Assume K is finite-dimensional over L := k(s).
Choose a basis y₁, y₂, … yₘ.
We can write each sᵢ∈S as sᵢ=∑ⱼ aᵢⱼyⱼ
and we can write each yᵢyⱼ as Σₖ bᵢⱼₖ yₖ with the a's and b's in L.
If R is the k-algebra generated by the aᵢⱼ and the bᵢⱼₖ then
any polynomial in the sᵢ with coefficients in k is easily checked to
be an R-linear combination of the yₖ, and in particular K is a finite R-module.
Because R is Noetherian we have that K is a Noetherian R-module, and hence
its submodule L is a Noetherian R-module. Because R is a finitely-generated
k-algebra this means that L is also a finitely-generated k-algebra.
But L=k(s) is not finitely-generated, because consider 1/(d₁d₂…dₙ+1)
where the dᵢ are the denominators of a finite set of generators
A shorter to formalise argument is found in "A note on Zariski's Lemma"
by John McCabe, AMM Vol 83 No 7. I'll formalise this instead.
-/
-- Assume K/L is finite-dimensional
set L := (field.closure (range (algebra_map K : k → K) ∪ {s})) with hL,
intro hKL,
-- Each sᵢ ∈ S is thus algebraic over L,
have hLKi : ∀ (t : K), is_integral ↥L t,
intro t,
exact is_integral_of_noetherian' hKL t,
-- so if we let X be the (finite) set of the coefficients
-- of all the min polys of the sᵢ over L=k(s)
set X := finset.image subtype.val (finset.bind S
(λ t, let p := minimal_polynomial (hLKi t) in
finset.image p.coeff (@finsupp.support ℕ _ _ p))) with hX,
-- and if we choose D ∈ k[s] non-zero such that D*X ⊆ k[s]
have hXfc : ↑X ⊆ field.closure (range (algebra_map K) ∪ {s}),
{ rintro x hx,
rw finset.mem_coe at hx,
rw [hX, finset.mem_image] at hx,
rcases hx with ⟨⟨yv, yp⟩, hy, hyx⟩,
rw [←hL, ←hyx],
exact yp },
rcases field.closure.clear_denominators hXfc
with ⟨D, hD0, hDL, hDden⟩,
-- then X ⊆ R := k[s][1/D]
set R := adjoin k ({s, D⁻¹} : set K) with hR,
have hXR : (↑X : set K) ⊆ ↑R,
{ intros x hx,
replace hDden := hDden x hx,
rw hR,
rw algebra.adjoin_eq_closure,
have htemp : x = D⁻¹ * (D * x),
field_simp [hD0], ring,
rw htemp,
apply is_submonoid.mul_mem,
{ apply ring.mem_closure,
right, left, refl,
},
refine ring.closure_mono _ hDden,
simp,
},
-- so each sᵢ is integral over R := k[s][1/D].
have hSint : ∀ t ∈ S, is_integral R t,
{ intros t ht,
set f := minimal_polynomial (hLKi t) with hf,
have Hf : finset.image subtype.val (finset.image (polynomial.coeff f) f.support) ⊆ X,
{ rw hX,
apply finset.image_mono,
intros x hx,
rw finset.mem_bind,
use t, use ht,
rw hf at hx, exact hx},
sorry
},
-- TODO
-- Hence K=k[S] is integral over k[s][1/D].
-- This means k[s][1/D] is a field (a standard trick; a non-zero element of k[s][1/D]
-- has an inverse in K, which is integral over k[s][1/D] and now multiply up
-- and expand out), which can't happen (it implies
-- that D is in every maximal ideal of k[s] and hence 1+D is in
-- none of them, thus 1+D is in k, so D is too, contradiction)
sorry
end
#check finsupp
#check polynomial
#check ring.closure
#check is_subring
#exit
def XXX (A : Type*) [comm_ring A] (C : Type*) [comm_ring C] [algebra A C]
(B : subalgebra A C) : algebra B C := by apply_instance
#print XXX
#check @subalgebra.to_algebra
/-
subalgebra.to_algebra :
Π (R : Type u_1) (A : Type u_2) [_inst_4 : comm_ring R] [_inst_5 : comm_ring A] [_inst_6 : algebra R A]
(S : subalgebra R A), algebra ↥S A
-/
/-
1 goal
L : set K := field.closure (range (algebra_map K) ∪ {s}),
hL : L = field.closure (range (algebra_map K) ∪ {s}),
hKL : finite_dimensional ↥L K
⊢ false
-/
instance Zariski's_lemma
-- let k be a field
(k : Type u) [discrete_field k]
-- and let k ⊆ K be another field (note: I seem to need that it's in the same universe)
(K : Type u) [discrete_field K] [algebra k K]
-- Assume that there's a finite subset S of K
(S : finset K)
-- which generates K as a k-algebra
-- (note: `⊤` is "the largest k-subalgebra of K", i.e., K)
(hsgen : adjoin k (↑S : set K) = ⊤)
-- Then
:
-- K is finite-dimensional as a k-vector space
finite_dimensional k K
:=
begin
-- I will show that if K is a field and S is a finite subset,
-- then for all subfields k of K, if K=k(S) then K is finite-dimensional
-- as a k-vector space.
unfreezeI, revert S k,
-- We'll do it by induction on the size of S,
intro S, apply finset.strong_induction_on S, clear S, intros S IH,
intros k hk hka, letI := hk, letI := hka,
intro hSgen,
-- Let's deal first with the case where all the elements of S are algebraic
-- over k
by_cases h_int : ∀ s ∈ S, is_integral k s,
-- In this case, the result is standard, because K is finitely-generated
-- and algebraic over k, so it's module-finite (use the
-- tower law and induction)
{ convert fg_adjoin_of_finite (finset.finite_to_set S) h_int,
rw hSgen,
rw finite_dimensional.iff_fg,
apply congr_arg,
convert (subalgebra.coe_submodule_top k K).symm,
},
-- The remaining case is where S contains an element transcendental over k.
push_neg at h_int,
rcases h_int with ⟨s, hs, hsnonint⟩,
-- We prove that this cannot happen.
exfalso,
-- Let L:=k(s) be the subfield of K generated by k and s.
set L := field.closure ((set.range (algebra_map K : k → K)) ∪ {s}) with hL,
-- then K = L(S - {s})
-- and |S - {s}| < |S|, so by induction, K is finite-dimensional over L,
have hKL : finite_dimensional L K,
{ refine IH (S.erase s) (finset.erase_ssubset hs) ↥L _,
-- NB this is a proof that k(S)=L(S - {s})
rw algebra.eq_top_iff at ⊢ hSgen,
intro x, replace hSgen := hSgen x,
rw ←subalgebra.mem_coe at ⊢ hSgen,
revert hSgen x,
show ring.closure (range (algebra_map K) ∪ ↑S) ≤
ring.closure (range (algebra_map K) ∪ ↑(S.erase s)),
apply ring.closure_subset,
apply union_subset,
{ refine subset.trans _ ring.subset_closure,
refine subset.trans _ (subset_union_left _ _),
rintro x ⟨x0, hx0⟩,
suffices hx : x ∈ L,
{ use ⟨x, hx⟩,
refl,
},
rw hL,
apply field.subset_closure,
apply subset_union_left _ _,
use x0,
exact hx0
},
{ refine subset.trans _ ring.subset_closure,
intros t ht,
by_cases hst : t = s,
{ apply subset_union_left,
cases hst, clear hst,
suffices hsL : s ∈ L,
use ⟨s, hsL⟩,
refl,
rw hL,
apply field.subset_closure,
apply subset_union_right _ _,
apply mem_singleton
},
{ apply subset_union_right _ _,
exact finset.mem_erase_of_ne_of_mem hst ht,
}
}
},
convert not_fin_dim_of_fin_gen_alg_of_nonintegral k K S hSgen s hs hsnonint hKL, refl,
end
|
42bac2b6d0966b430cad2cad45f2ebf6858f2a85
|
302c785c90d40ad3d6be43d33bc6a558354cc2cf
|
/src/tactic/monotonicity/lemmas.lean
|
0cd12911a52fdcf7f21a52eed748ea5c45307431
|
[
"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
| 2,277
|
lean
|
/-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import tactic.monotonicity.basic
import data.set.lattice
import order.bounds
variables {α : Type*}
@[mono]
lemma mul_mono_nonneg {x y z : α} [ordered_semiring α]
(h' : 0 ≤ z)
(h : x ≤ y)
: x * z ≤ y * z :=
by apply mul_le_mul_of_nonneg_right; assumption
lemma lt_of_mul_lt_mul_neg_right {a b c : α} [linear_ordered_ring α]
(h : a * c < b * c) (hc : c ≤ 0) : b < a :=
have nhc : -c ≥ 0, from neg_nonneg_of_nonpos hc,
have h2 : -(b * c) < -(a * c), from neg_lt_neg h,
have h3 : b * (-c) < a * (-c), from calc
b * (-c) = - (b * c) : by rewrite neg_mul_eq_mul_neg
... < - (a * c) : h2
... = a * (-c) : by rewrite neg_mul_eq_mul_neg,
lt_of_mul_lt_mul_right h3 nhc
@[mono]
lemma mul_mono_nonpos {x y z : α} [linear_ordered_ring α]
(h' : z ≤ 0) (h : y ≤ x) : x * z ≤ y * z :=
begin
classical,
by_contradiction h'',
revert h,
apply not_le_of_lt,
apply lt_of_mul_lt_mul_neg_right _ h',
apply lt_of_not_ge h''
end
@[mono]
lemma nat.sub_mono_left_strict {x y z : ℕ}
(h' : z ≤ x)
(h : x < y)
: x - z < y - z :=
begin
have : z ≤ y,
{ transitivity, assumption, apply le_of_lt h, },
apply @nat.lt_of_add_lt_add_left z,
rw [nat.add_sub_of_le,nat.add_sub_of_le];
solve_by_elim
end
@[mono]
lemma nat.sub_mono_right_strict {x y z : ℕ}
(h' : x ≤ z)
(h : y < x)
: z - x < z - y :=
begin
have h'' : y ≤ z,
{ transitivity, apply le_of_lt h, assumption },
apply @nat.lt_of_add_lt_add_right _ x,
rw [nat.sub_add_cancel h'],
apply @lt_of_le_of_lt _ _ _ (z - y + y),
rw [nat.sub_add_cancel h''],
apply nat.add_lt_add_left h
end
open set
attribute [mono] inter_subset_inter union_subset_union
sUnion_mono bUnion_mono sInter_subset_sInter bInter_mono
image_subset preimage_mono prod_mono monotone_prod seq_mono
image2_subset order_embedding.monotone
attribute [mono] upper_bounds_mono_set lower_bounds_mono_set
upper_bounds_mono_mem lower_bounds_mono_mem
upper_bounds_mono lower_bounds_mono
bdd_above.mono bdd_below.mono
|
b294dbc645329ccc42f48ff73ccb216fb6851c0e
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/group_theory/group_action/basic.lean
|
82a51b02837dfb2cc8a56cc9d6d4752558e695d8
|
[] |
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
| 7,689
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.group_theory.group_action.defs
import Mathlib.group_theory.group_action.group
import Mathlib.group_theory.coset
import Mathlib.PostPort
universes u v u_1 w
namespace Mathlib
/-!
# Basic properties of group actions
-/
namespace mul_action
/-- The orbit of an element under an action. -/
def orbit (α : Type u) {β : Type v} [monoid α] [mul_action α β] (b : β) : set β :=
set.range fun (x : α) => x • b
theorem mem_orbit_iff {α : Type u} {β : Type v} [monoid α] [mul_action α β] {b₁ : β} {b₂ : β} : b₂ ∈ orbit α b₁ ↔ ∃ (x : α), x • b₁ = b₂ :=
iff.rfl
@[simp] theorem mem_orbit {α : Type u} {β : Type v} [monoid α] [mul_action α β] (b : β) (x : α) : x • b ∈ orbit α b :=
Exists.intro x rfl
@[simp] theorem mem_orbit_self {α : Type u} {β : Type v} [monoid α] [mul_action α β] (b : β) : b ∈ orbit α b := sorry
/-- The stabilizer of an element under an action, i.e. what sends the element to itself. Note
that this is a set: for the group stabilizer see `stabilizer`. -/
def stabilizer_carrier (α : Type u) {β : Type v} [monoid α] [mul_action α β] (b : β) : set α :=
set_of fun (x : α) => x • b = b
@[simp] theorem mem_stabilizer_iff {α : Type u} {β : Type v} [monoid α] [mul_action α β] {b : β} {x : α} : x ∈ stabilizer_carrier α b ↔ x • b = b :=
iff.rfl
/-- The set of elements fixed under the whole action. -/
def fixed_points (α : Type u) (β : Type v) [monoid α] [mul_action α β] : set β :=
set_of fun (b : β) => ∀ (x : α), x • b = b
/-- `fixed_by g` is the subfield of elements fixed by `g`. -/
def fixed_by (α : Type u) (β : Type v) [monoid α] [mul_action α β] (g : α) : set β :=
set_of fun (x : β) => g • x = x
theorem fixed_eq_Inter_fixed_by (α : Type u) (β : Type v) [monoid α] [mul_action α β] : fixed_points α β = set.Inter fun (g : α) => fixed_by α β g := sorry
@[simp] theorem mem_fixed_points {α : Type u} (β : Type v) [monoid α] [mul_action α β] {b : β} : b ∈ fixed_points α β ↔ ∀ (x : α), x • b = b :=
iff.rfl
@[simp] theorem mem_fixed_by {α : Type u} (β : Type v) [monoid α] [mul_action α β] {g : α} {b : β} : b ∈ fixed_by α β g ↔ g • b = b :=
iff.rfl
theorem mem_fixed_points' {α : Type u} (β : Type v) [monoid α] [mul_action α β] {b : β} : b ∈ fixed_points α β ↔ ∀ (b' : β), b' ∈ orbit α b → b' = b := sorry
/-- The stabilizer of a point `b` as a submonoid of `α`. -/
def stabilizer.submonoid (α : Type u) {β : Type v} [monoid α] [mul_action α β] (b : β) : submonoid α :=
submonoid.mk (stabilizer_carrier α b) (one_smul α b) sorry
end mul_action
namespace mul_action
/-- The stabilizer of an element under an action, i.e. what sends the element to itself.
A subgroup. -/
def stabilizer (α : Type u) {β : Type v} [group α] [mul_action α β] (b : β) : subgroup α :=
subgroup.mk (submonoid.carrier sorry) sorry sorry sorry
theorem orbit_eq_iff {α : Type u} {β : Type v} [group α] [mul_action α β] {a : β} {b : β} : orbit α a = orbit α b ↔ a ∈ orbit α b := sorry
/-- The stabilizer of a point `b` as a subgroup of `α`. -/
def stabilizer.subgroup (α : Type u) {β : Type v} [group α] [mul_action α β] (b : β) : subgroup α :=
subgroup.mk (submonoid.carrier (stabilizer.submonoid α b)) sorry sorry sorry
@[simp] theorem mem_orbit_smul (α : Type u) {β : Type v} [group α] [mul_action α β] (g : α) (a : β) : a ∈ orbit α (g • a) := sorry
@[simp] theorem smul_mem_orbit_smul (α : Type u) {β : Type v} [group α] [mul_action α β] (g : α) (h : α) (a : β) : g • a ∈ orbit α (h • a) := sorry
/-- The relation "in the same orbit". -/
def orbit_rel (α : Type u) (β : Type v) [group α] [mul_action α β] : setoid β :=
setoid.mk (fun (a b : β) => a ∈ orbit α b) sorry
/-- Action on left cosets. -/
def mul_left_cosets {α : Type u} [group α] (H : subgroup α) (x : α) (y : quotient_group.quotient H) : quotient_group.quotient H :=
quotient.lift_on' y (fun (y : α) => quotient_group.mk (x * y)) sorry
protected instance quotient {α : Type u} [group α] (H : subgroup α) : mul_action α (quotient_group.quotient H) :=
mk sorry sorry
@[simp] theorem quotient.smul_mk {α : Type u} [group α] (H : subgroup α) (a : α) (x : α) : a • quotient_group.mk x = quotient_group.mk (a * x) :=
rfl
@[simp] theorem quotient.smul_coe {α : Type u_1} [comm_group α] (H : subgroup α) (a : α) (x : α) : a • ↑x = ↑(a * x) :=
rfl
protected instance mul_left_cosets_comp_subtype_val {α : Type u} [group α] (H : subgroup α) (I : subgroup α) : mul_action (↥I) (quotient_group.quotient H) :=
comp_hom (quotient_group.quotient H) (subgroup.subtype I)
/-- The canonical map from the quotient of the stabilizer to the set. -/
def of_quotient_stabilizer (α : Type u) {β : Type v} [group α] [mul_action α β] (x : β) (g : quotient_group.quotient (stabilizer α x)) : β :=
quotient.lift_on' g (fun (_x : α) => _x • x) sorry
@[simp] theorem of_quotient_stabilizer_mk (α : Type u) {β : Type v} [group α] [mul_action α β] (x : β) (g : α) : of_quotient_stabilizer α x (quotient_group.mk g) = g • x :=
rfl
theorem of_quotient_stabilizer_mem_orbit (α : Type u) {β : Type v} [group α] [mul_action α β] (x : β) (g : quotient_group.quotient (stabilizer α x)) : of_quotient_stabilizer α x g ∈ orbit α x :=
quotient.induction_on' g fun (g : α) => Exists.intro g rfl
theorem of_quotient_stabilizer_smul (α : Type u) {β : Type v} [group α] [mul_action α β] (x : β) (g : α) (g' : quotient_group.quotient (stabilizer α x)) : of_quotient_stabilizer α x (g • g') = g • of_quotient_stabilizer α x g' :=
quotient.induction_on' g' fun (_x : α) => mul_smul g _x x
theorem injective_of_quotient_stabilizer (α : Type u) {β : Type v} [group α] [mul_action α β] (x : β) : function.injective (of_quotient_stabilizer α x) := sorry
/-- Orbit-stabilizer theorem. -/
def orbit_equiv_quotient_stabilizer (α : Type u) {β : Type v} [group α] [mul_action α β] (b : β) : ↥(orbit α b) ≃ quotient_group.quotient (stabilizer α b) :=
equiv.symm
(equiv.of_bijective
(fun (g : quotient_group.quotient (stabilizer α b)) =>
{ val := of_quotient_stabilizer α b g, property := of_quotient_stabilizer_mem_orbit α b g })
sorry)
@[simp] theorem orbit_equiv_quotient_stabilizer_symm_apply (α : Type u) {β : Type v} [group α] [mul_action α β] (b : β) (a : α) : ↑(coe_fn (equiv.symm (orbit_equiv_quotient_stabilizer α b)) ↑a) = a • b :=
rfl
end mul_action
theorem list.smul_sum {α : Type u} {β : Type v} [monoid α] [add_monoid β] [distrib_mul_action α β] {r : α} {l : List β} : r • list.sum l = list.sum (list.map (has_scalar.smul r) l) :=
add_monoid_hom.map_list_sum (const_smul_hom β r) l
theorem multiset.smul_sum {α : Type u} {β : Type v} [monoid α] [add_comm_monoid β] [distrib_mul_action α β] {r : α} {s : multiset β} : r • multiset.sum s = multiset.sum (multiset.map (has_scalar.smul r) s) :=
add_monoid_hom.map_multiset_sum (const_smul_hom β r) s
theorem finset.smul_sum {α : Type u} {β : Type v} {γ : Type w} [monoid α] [add_comm_monoid β] [distrib_mul_action α β] {r : α} {f : γ → β} {s : finset γ} : (r • finset.sum s fun (x : γ) => f x) = finset.sum s fun (x : γ) => r • f x :=
add_monoid_hom.map_sum (const_smul_hom β r) f s
|
842b76df426cbe690543e941e986ab64bd28e0ef
|
92e157ec9825b5e4597a6d715a8928703bc8e3b2
|
/src/mywork/lecture_8.lean
|
8ebbdc6f9f1fcf892f50586ef01cf9c94e63b00d
|
[] |
no_license
|
exb3dg/cs2120f21
|
9e566bc508762573c023d3e70f83cb839c199ec8
|
319b8bf0d63bf96437bf17970ce0198d0b3525cd
|
refs/heads/main
| 1,692,970,909,568
| 1,634,584,540,000
| 1,634,584,540,000
| 399,947,025
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,076
|
lean
|
theorem and_associative : ∀ (P Q R : Prop), (P ∧ Q) ∧ R → P ∧ (Q ∧ R) :=
/- and is defined as right associative P ∧ Q ∧ R ⟶ P ∧ (Q ∧ R) -/
begin
assume P Q R,
assume h,
have pq : P ∧ Q := and.elim_left h,
have p : P := and.elim_left pq,
have q : Q := and.elim_right pq,
have r : R := and.elim_right h,
exact and.intro p (and.intro q r),
/-
apply and.intro _ (and.intro q r),
exact p,
p fills in the underscore in the line above
-/
end
/-
The or connective, ∨, in predicate logic
join any two propositions, P, Q, into a
larger proposition, P ∨ Q. This proposition
is judged as true if either (or both) P, Q
are true.
-/
/-
Introduction rules (two of them).
There are two ways to prove a proposition,
(P ∨ Q): with a proof of P, or with a proof
of Q. Either will do. We thus have two intro
rules for ∨. They are called the left and
right introduction rules.
The left one takes a proof, let's say, p, of
the left proposition, P (from which it infers)
P along with the right proposition, Q, and then
returns a proof of P ∨ Q. The arguments are
actually given in the other order. The right
introduction rule thus takes the proposition,
P and a proof of the proposition, Q, and also
returns a proof of P ∨ Q.
Exercise: Suppose that it's true (and thus
that we we have a proof) that Joe chews gum.
Give an English proof of the proposition that
(Joe is tall) ∨ (Joe chews gum).
Proof: Apply the right introduction rule for
∨ to (1) our proof that Joe chews gum, and
(2) the proposition that Joe is tall. The
result is the proof we want, of the proposition
(Joe chews gum) ∨ (Joe is tall).
Exercise: Give an English language proof of:
(Joe is tall) ∨ (Joe chews gum).
-/
/-
In Lean, the rules are called or.intro_left
and or.intro_right.
-/
#check @or.intro_left
#check @or.intro_right
/-
In the preceding outputs, you can see that the
arguments that are required explicitly are in
parentheses, and the arguments whose values are
inferred from other arguments are given in {}.
-/
/-
Let's formalize our example in Lean.
-/
axioms (Joe_is_tall Joe_chews_gum : Prop) /- assume we have a proof of both -/
axiom jcg: Joe_chews_gum /- jcp is the proof of Joe_chews_gum -/
theorem jcg_or_jit: Joe_chews_gum ∨ Joe_is_tall :=
or.intro_left Joe_is_tall jcg
/-
begin
apply or.intro_left Joe_is_tall jcg
end
-/
/-
Exercise: Formalize our second version of this
proposition and a proof of it.
-/
/-
We thus have two inference rules (axioms) that we
can use to create a proof of a "disjunction".
(Q : Prop) {P : Prop} (p : P)
----------------------------- ∨ intro_left
pf : P ∨ Q
(P : Prop) {Q : Prop} (q : Q)
----------------------------- ∨ intro_right
pf : P ∨ Q
-/
/-
Suppose that if Joe is tall then he is funny,
that if Joe chews gum he is also funny, and that
Joe chews gum ∨ Joe is tall. What can we deduce
from these assumptions/facts?
-/
/-
You have just used the elimination rule for ∨.
Here it is a little more generally. Suppose P,
Q, and R are propositions, that P → R and Q → R,
and finally that P ∨ Q is true? What can we then
deduce? Why, R, of course!
{P Q R : Prop} (pq : P ∨ Q) (pr : P → R) (qr : Q → R)
-----------------------------------------------------
pf : R
-/
#check @or.elim
/-
Let's add a few assumptions and see this rule in action.
-/
axioms (P Q R : Prop) (pq : P ∨ Q) (pr : P → R) (qr : Q → R)
example : R := or.elim pq pr qr
axioms
(Joe_is_funny : Prop)
(torf : Joe_is_tall ∨ Joe_chews_gum)
(tf: Joe_is_tall → Joe_is_funny)
(gf : Joe_chews_gum → Joe_is_funny)
example : Joe_is_funny :=
or.elim torf tf gf
/-
In English, under the given assumptions
(axioms, just above) we can prove that Joe
is funny *by cases*. We know that Joe chews
gum OR Joe is tall, so least one of these
cases must hold. Let's consider the cases
in turn.
Case 1: Suppose that (Joe is tall ∨ Joe
chews gum) is true because Joe is tall.
In this case we apply the fact that (Joe
is tall → Joe is funny) to the fact hat
(Joe is tall) to deduce that Joe is funny.
Exercise: What inference rule did we use
right there?
Case 2: The reasoning is similar. Suppose
the disjunction is true because Joe chews
gum. We can use "modus ponens", applying
the fact that (Joe chews gum → Joe is funny)
to deduce (Joe is funny).
Therefore Joe is funny *in either case*,
and *there are no other cases to consider*
so we can deduce that Joe is funny.
-/
/-
Here it is formally!
-/
-- By cases
example : Joe_is_funny :=
begin
cases torf, -- applies or.elim
apply tf h,
apply gf h,
end
-- Equivalent direct application of or.elim
example : Joe_is_funny :=
begin
apply or.elim torf _ _, -- applies or.elim
exact tf,
exact gf,
end
/-
Yay, now how about proving some theorems.
-/
/-
Problem #1: State precisely and prove that
∨ is commutative, in English then formally.
-/
/-
Problem #2: State precisely and prove that ∨
is associative, first in English then formally.
-/
|
ea41776899a3deaf502cb21134eb459d7e090e7d
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/category_theory/category/basic.lean
|
75db02fc3617bf6efddd9d17c12b4a27ddd88528
|
[
"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,867
|
lean
|
/-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Johannes Hölzl, Reid Barton
-/
import combinatorics.quiver.basic
import tactic.basic
/-!
# Categories
Defines a category, as a type class parametrised by the type of objects.
## Notations
Introduces notations
* `X ⟶ Y` for the morphism spaces,
* `f ≫ g` for composition in the 'arrows' convention.
Users may like to add `f ⊚ g` for composition in the standard convention, using
```lean
local notation f ` ⊚ `:80 g:80 := category.comp g f -- type as \oo
```
-/
/--
The typeclass `category C` describes morphisms associated to objects of type `C : Type u`.
The universe levels of the objects and morphisms are independent, and will often need to be
specified explicitly, as `category.{v} C`.
Typically any concrete example will either be a `small_category`, where `v = u`,
which can be introduced as
```
universes u
variables {C : Type u} [small_category C]
```
or a `large_category`, where `u = v+1`, which can be introduced as
```
universes u
variables {C : Type (u+1)} [large_category C]
```
In order for the library to handle these cases uniformly,
we generally work with the unconstrained `category.{v u}`,
for which objects live in `Type u` and morphisms live in `Type v`.
Because the universe parameter `u` for the objects can be inferred from `C`
when we write `category C`, while the universe parameter `v` for the morphisms
can not be automatically inferred, through the category theory library
we introduce universe parameters with morphism levels listed first,
as in
```
universes v u
```
or
```
universes v₁ v₂ u₁ u₂
```
when multiple independent universes are needed.
This has the effect that we can simply write `category.{v} C`
(that is, only specifying a single parameter) while `u` will be inferred.
Often, however, it's not even necessary to include the `.{v}`.
(Although it was in earlier versions of Lean.)
If it is omitted a "free" universe will be used.
-/
library_note "category_theory universes"
universes v u
namespace category_theory
/-- A preliminary structure on the way to defining a category,
containing the data, but none of the axioms. -/
class category_struct (obj : Type u)
extends quiver.{v+1} obj : Type (max u (v+1)) :=
(id : Π X : obj, hom X X)
(comp : Π {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z))
notation `𝟙` := category_struct.id -- type as \b1
infixr ` ≫ `:80 := category_struct.comp -- type as \gg
/--
The typeclass `category C` describes morphisms associated to objects of type `C`.
The universe levels of the objects and morphisms are unconstrained, and will often need to be
specified explicitly, as `category.{v} C`. (See also `large_category` and `small_category`.)
See <https://stacks.math.columbia.edu/tag/0014>.
-/
class category (obj : Type u)
extends category_struct.{v} obj : Type (max u (v+1)) :=
(id_comp' : ∀ {X Y : obj} (f : hom X Y), 𝟙 X ≫ f = f . obviously)
(comp_id' : ∀ {X Y : obj} (f : hom X Y), f ≫ 𝟙 Y = f . obviously)
(assoc' : ∀ {W X Y Z : obj} (f : hom W X) (g : hom X Y) (h : hom Y Z),
(f ≫ g) ≫ h = f ≫ (g ≫ h) . obviously)
-- `restate_axiom` is a command that creates a lemma from a structure field,
-- discarding any auto_param wrappers from the type.
-- (It removes a backtick from the name, if it finds one, and otherwise adds "_lemma".)
restate_axiom category.id_comp'
restate_axiom category.comp_id'
restate_axiom category.assoc'
attribute [simp] category.id_comp category.comp_id category.assoc
attribute [trans] category_struct.comp
/--
A `large_category` has objects in one universe level higher than the universe level of
the morphisms. It is useful for examples such as the category of types, or the category
of groups, etc.
-/
abbreviation large_category (C : Type (u+1)) : Type (u+1) := category.{u} C
/--
A `small_category` has objects and morphisms in the same universe level.
-/
abbreviation small_category (C : Type u) : Type (u+1) := category.{u} C
section
variables {C : Type u} [category.{v} C] {X Y Z : C}
initialize_simps_projections category (to_category_struct_to_quiver_hom → hom,
to_category_struct_comp → comp, to_category_struct_id → id, -to_category_struct)
/-- postcompose an equation between morphisms by another morphism -/
lemma eq_whisker {f g : X ⟶ Y} (w : f = g) (h : Y ⟶ Z) : f ≫ h = g ≫ h :=
by rw w
/-- precompose an equation between morphisms by another morphism -/
lemma whisker_eq (f : X ⟶ Y) {g h : Y ⟶ Z} (w : g = h) : f ≫ g = f ≫ h :=
by rw w
infixr ` =≫ `:80 := eq_whisker
infixr ` ≫= `:80 := whisker_eq
lemma eq_of_comp_left_eq {f g : X ⟶ Y} (w : ∀ {Z : C} (h : Y ⟶ Z), f ≫ h = g ≫ h) : f = g :=
by { convert w (𝟙 Y), tidy }
lemma eq_of_comp_right_eq {f g : Y ⟶ Z} (w : ∀ {X : C} (h : X ⟶ Y), h ≫ f = h ≫ g) : f = g :=
by { convert w (𝟙 Y), tidy }
lemma eq_of_comp_left_eq' (f g : X ⟶ Y)
(w : (λ {Z : C} (h : Y ⟶ Z), f ≫ h) = (λ {Z : C} (h : Y ⟶ Z), g ≫ h)) : f = g :=
eq_of_comp_left_eq (λ Z h, by convert congr_fun (congr_fun w Z) h)
lemma eq_of_comp_right_eq' (f g : Y ⟶ Z)
(w : (λ {X : C} (h : X ⟶ Y), h ≫ f) = (λ {X : C} (h : X ⟶ Y), h ≫ g)) : f = g :=
eq_of_comp_right_eq (λ X h, by convert congr_fun (congr_fun w X) h)
lemma id_of_comp_left_id (f : X ⟶ X) (w : ∀ {Y : C} (g : X ⟶ Y), f ≫ g = g) : f = 𝟙 X :=
by { convert w (𝟙 X), tidy }
lemma id_of_comp_right_id (f : X ⟶ X) (w : ∀ {Y : C} (g : Y ⟶ X), g ≫ f = g) : f = 𝟙 X :=
by { convert w (𝟙 X), tidy }
lemma comp_ite {P : Prop} [decidable P]
{X Y Z : C} (f : X ⟶ Y) (g g' : (Y ⟶ Z)) :
(f ≫ if P then g else g') = (if P then f ≫ g else f ≫ g') :=
by { split_ifs; refl }
lemma ite_comp {P : Prop} [decidable P]
{X Y Z : C} (f f' : (X ⟶ Y)) (g : Y ⟶ Z) :
(if P then f else f') ≫ g = (if P then f ≫ g else f' ≫ g) :=
by { split_ifs; refl }
lemma comp_dite {P : Prop} [decidable P]
{X Y Z : C} (f : X ⟶ Y) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) :
(f ≫ if h : P then g h else g' h) = (if h : P then f ≫ g h else f ≫ g' h) :=
by { split_ifs; refl }
lemma dite_comp {P : Prop} [decidable P]
{X Y Z : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (g : Y ⟶ Z) :
(if h : P then f h else f' h) ≫ g = (if h : P then f h ≫ g else f' h ≫ g) :=
by { split_ifs; refl }
/--
A morphism `f` is an epimorphism if it can be "cancelled" when precomposed:
`f ≫ g = f ≫ h` implies `g = h`.
See <https://stacks.math.columbia.edu/tag/003B>.
-/
class epi (f : X ⟶ Y) : Prop :=
(left_cancellation : Π {Z : C} (g h : Y ⟶ Z) (w : f ≫ g = f ≫ h), g = h)
/--
A morphism `f` is a monomorphism if it can be "cancelled" when postcomposed:
`g ≫ f = h ≫ f` implies `g = h`.
See <https://stacks.math.columbia.edu/tag/003B>.
-/
class mono (f : X ⟶ Y) : Prop :=
(right_cancellation : Π {Z : C} (g h : Z ⟶ X) (w : g ≫ f = h ≫ f), g = h)
instance (X : C) : epi (𝟙 X) :=
⟨λ Z g h w, by simpa using w⟩
instance (X : C) : mono (𝟙 X) :=
⟨λ Z g h w, by simpa using w⟩
lemma cancel_epi (f : X ⟶ Y) [epi f] {g h : Y ⟶ Z} : (f ≫ g = f ≫ h) ↔ g = h :=
⟨λ p, epi.left_cancellation g h p, congr_arg _⟩
lemma cancel_mono (f : X ⟶ Y) [mono f] {g h : Z ⟶ X} : (g ≫ f = h ≫ f) ↔ g = h :=
⟨λ p, mono.right_cancellation g h p, congr_arg _⟩
lemma cancel_epi_id (f : X ⟶ Y) [epi f] {h : Y ⟶ Y} : (f ≫ h = f) ↔ h = 𝟙 Y :=
by { convert cancel_epi f, simp, }
lemma cancel_mono_id (f : X ⟶ Y) [mono f] {g : X ⟶ X} : (g ≫ f = f) ↔ g = 𝟙 X :=
by { convert cancel_mono f, simp, }
lemma epi_comp {X Y Z : C} (f : X ⟶ Y) [epi f] (g : Y ⟶ Z) [epi g] : epi (f ≫ g) :=
begin
split, intros Z a b w,
apply (cancel_epi g).1,
apply (cancel_epi f).1,
simpa using w,
end
lemma mono_comp {X Y Z : C} (f : X ⟶ Y) [mono f] (g : Y ⟶ Z) [mono g] : mono (f ≫ g) :=
begin
split, intros Z a b w,
apply (cancel_mono f).1,
apply (cancel_mono g).1,
simpa using w,
end
lemma mono_of_mono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [mono (f ≫ g)] : mono f :=
begin
split, intros Z a b w,
replace w := congr_arg (λ k, k ≫ g) w,
dsimp at w,
rw [category.assoc, category.assoc] at w,
exact (cancel_mono _).1 w,
end
lemma mono_of_mono_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [mono h] (w : f ≫ g = h) :
mono f :=
by { substI h, exact mono_of_mono f g, }
lemma epi_of_epi {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [epi (f ≫ g)] : epi g :=
begin
split, intros Z a b w,
replace w := congr_arg (λ k, f ≫ k) w,
dsimp at w,
rw [←category.assoc, ←category.assoc] at w,
exact (cancel_epi _).1 w,
end
lemma epi_of_epi_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [epi h] (w : f ≫ g = h) :
epi g :=
by substI h; exact epi_of_epi f g
end
section
variable (C : Type u)
variable [category.{v} C]
universe u'
instance ulift_category : category.{v} (ulift.{u'} C) :=
{ hom := λ X Y, (X.down ⟶ Y.down),
id := λ X, 𝟙 X.down,
comp := λ _ _ _ f g, f ≫ g }
-- We verify that this previous instance can lift small categories to large categories.
example (D : Type u) [small_category D] : large_category (ulift.{u+1} D) := by apply_instance
end
end category_theory
/--
Many proofs in the category theory library use the `dsimp, simp` pattern,
which typically isn't necessary elsewhere.
One would usually hope that the same effect could be achieved simply with `simp`.
The essential issue is that composition of morphisms involves dependent types.
When you have a chain of morphisms being composed, say `f : X ⟶ Y` and `g : Y ⟶ Z`,
then `simp` can operate succesfully on the morphisms
(e.g. if `f` is the identity it can strip that off).
However if we have an equality of objects, say `Y = Y'`,
then `simp` can't operate because it would break the typing of the composition operations.
We rarely have interesting equalities of objects
(because that would be "evil" --- anything interesting should be expressed as an isomorphism
and tracked explicitly),
except of course that we have plenty of definitional equalities of objects.
`dsimp` can apply these safely, even inside a composition.
After `dsimp` has cleared up the object level, `simp` can resume work on the morphism level ---
but without the `dsimp` step, because `simp` looks at expressions syntactically,
the relevant lemmas might not fire.
There's no bound on how many times you potentially could have to switch back and forth,
if the `simp` introduced new objects we again need to `dsimp`.
In practice this does occur, but only rarely, because `simp` tends to shorten chains of compositions
(i.e. not introduce new objects at all).
-/
library_note "dsimp, simp"
|
0e7270f6e3a4975d74dd67957ad51541e948a3cf
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/number_theory/legendre_symbol/quadratic_char.lean
|
9e6d5d17c9fded7c09a15c7483aeaab8bd131bbe
|
[
"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
| 18,658
|
lean
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import data.fintype.parity
import number_theory.legendre_symbol.zmod_char
import field_theory.finite.basic
import number_theory.legendre_symbol.gauss_sum
/-!
# Quadratic characters of finite fields
This file defines the quadratic character on a finite field `F` and proves
some basic statements about it.
## Tags
quadratic character
-/
/-!
### Definition of the quadratic character
We define the quadratic character of a finite field `F` with values in ℤ.
-/
section define
/-- Define the quadratic character with values in ℤ on a monoid with zero `α`.
It takes the value zero at zero; for non-zero argument `a : α`, it is `1`
if `a` is a square, otherwise it is `-1`.
This only deserves the name "character" when it is multiplicative,
e.g., when `α` is a finite field. See `quadratic_char_fun_mul`.
We will later define `quadratic_char` to be a multiplicative character
of type `mul_char F ℤ`, when the domain is a finite field `F`.
-/
def quadratic_char_fun (α : Type*) [monoid_with_zero α] [decidable_eq α]
[decidable_pred (is_square : α → Prop)] (a : α) : ℤ :=
if a = 0 then 0 else if is_square a then 1 else -1
end define
/-!
### Basic properties of the quadratic character
We prove some properties of the quadratic character.
We work with a finite field `F` here.
The interesting case is when the characteristic of `F` is odd.
-/
section quadratic_char
open mul_char
variables {F : Type*} [field F] [fintype F] [decidable_eq F]
/-- Some basic API lemmas -/
lemma quadratic_char_fun_eq_zero_iff {a : F} : quadratic_char_fun F a = 0 ↔ a = 0 :=
begin
simp only [quadratic_char_fun],
by_cases ha : a = 0,
{ simp only [ha, eq_self_iff_true, if_true], },
{ simp only [ha, if_false, iff_false],
split_ifs; simp only [neg_eq_zero, one_ne_zero, not_false_iff], },
end
@[simp]
lemma quadratic_char_fun_zero : quadratic_char_fun F 0 = 0 :=
by simp only [quadratic_char_fun, eq_self_iff_true, if_true, id.def]
@[simp]
lemma quadratic_char_fun_one : quadratic_char_fun F 1 = 1 :=
by simp only [quadratic_char_fun, one_ne_zero, is_square_one, if_true, if_false, id.def]
/-- If `ring_char F = 2`, then `quadratic_char_fun F` takes the value `1` on nonzero elements. -/
lemma quadratic_char_fun_eq_one_of_char_two (hF : ring_char F = 2) {a : F} (ha : a ≠ 0) :
quadratic_char_fun F a = 1 :=
begin
simp only [quadratic_char_fun, ha, if_false, ite_eq_left_iff],
exact λ h, false.rec _ (h (finite_field.is_square_of_char_two hF a))
end
/-- If `ring_char F` is odd, then `quadratic_char_fun F a` can be computed in
terms of `a ^ (fintype.card F / 2)`. -/
lemma quadratic_char_fun_eq_pow_of_char_ne_two (hF : ring_char F ≠ 2) {a : F} (ha : a ≠ 0) :
quadratic_char_fun F a = if a ^ (fintype.card F / 2) = 1 then 1 else -1 :=
begin
simp only [quadratic_char_fun, ha, if_false],
simp_rw finite_field.is_square_iff hF ha,
end
/-- The quadratic character is multiplicative. -/
lemma quadratic_char_fun_mul (a b : F) :
quadratic_char_fun F (a * b) = quadratic_char_fun F a * quadratic_char_fun F b :=
begin
by_cases ha : a = 0,
{ rw [ha, zero_mul, quadratic_char_fun_zero, zero_mul], },
-- now `a ≠ 0`
by_cases hb : b = 0,
{ rw [hb, mul_zero, quadratic_char_fun_zero, mul_zero], },
-- now `a ≠ 0` and `b ≠ 0`
have hab := mul_ne_zero ha hb,
by_cases hF : ring_char F = 2,
{ -- case `ring_char F = 2`
rw [quadratic_char_fun_eq_one_of_char_two hF ha,
quadratic_char_fun_eq_one_of_char_two hF hb,
quadratic_char_fun_eq_one_of_char_two hF hab,
mul_one], },
{ -- case of odd characteristic
rw [quadratic_char_fun_eq_pow_of_char_ne_two hF ha,
quadratic_char_fun_eq_pow_of_char_ne_two hF hb,
quadratic_char_fun_eq_pow_of_char_ne_two hF hab,
mul_pow],
cases finite_field.pow_dichotomy hF hb with hb' hb',
{ simp only [hb', mul_one, eq_self_iff_true, if_true], },
{ have h := ring.neg_one_ne_one_of_char_ne_two hF, -- `-1 ≠ 1`
simp only [hb', h, mul_neg, mul_one, if_false, ite_mul, neg_mul],
cases finite_field.pow_dichotomy hF ha with ha' ha';
simp only [ha', h, neg_neg, eq_self_iff_true, if_true, if_false], }, },
end
variables (F)
/-- The quadratic character as a multiplicative character. -/
@[simps] def quadratic_char : mul_char F ℤ :=
{ to_fun := quadratic_char_fun F,
map_one' := quadratic_char_fun_one,
map_mul' := quadratic_char_fun_mul,
map_nonunit' := λ a ha, by { rw of_not_not (mt ne.is_unit ha), exact quadratic_char_fun_zero, } }
variables {F}
/-- The value of the quadratic character on `a` is zero iff `a = 0`. -/
lemma quadratic_char_eq_zero_iff {a : F} : quadratic_char F a = 0 ↔ a = 0 :=
quadratic_char_fun_eq_zero_iff
@[simp]
lemma quadratic_char_zero : quadratic_char F 0 = 0 :=
by simp only [quadratic_char_apply, quadratic_char_fun_zero]
/-- For nonzero `a : F`, `quadratic_char F a = 1 ↔ is_square a`. -/
lemma quadratic_char_one_iff_is_square {a : F} (ha : a ≠ 0) :
quadratic_char F a = 1 ↔ is_square a :=
by simp only [quadratic_char_apply, quadratic_char_fun, ha, (dec_trivial : (-1 : ℤ) ≠ 1),
if_false, ite_eq_left_iff, imp_false, not_not]
/-- The quadratic character takes the value `1` on nonzero squares. -/
lemma quadratic_char_sq_one' {a : F} (ha : a ≠ 0) : quadratic_char F (a ^ 2) = 1 :=
by simp only [quadratic_char_fun, ha, pow_eq_zero_iff, nat.succ_pos', is_square_sq, if_true,
if_false, quadratic_char_apply]
/-- The square of the quadratic character on nonzero arguments is `1`. -/
lemma quadratic_char_sq_one {a : F} (ha : a ≠ 0) : (quadratic_char F a) ^ 2 = 1 :=
by rwa [pow_two, ← map_mul, ← pow_two, quadratic_char_sq_one']
/-- The quadratic character is `1` or `-1` on nonzero arguments. -/
lemma quadratic_char_dichotomy {a : F} (ha : a ≠ 0) :
quadratic_char F a = 1 ∨ quadratic_char F a = -1 :=
sq_eq_one_iff.1 $ quadratic_char_sq_one ha
/-- The quadratic character is `1` or `-1` on nonzero arguments. -/
lemma quadratic_char_eq_neg_one_iff_not_one {a : F} (ha : a ≠ 0) :
quadratic_char F a = -1 ↔ ¬ quadratic_char F a = 1 :=
begin
refine ⟨λ h, _, λ h₂, (or_iff_right h₂).mp (quadratic_char_dichotomy ha)⟩,
rw h,
norm_num,
end
/-- For `a : F`, `quadratic_char F a = -1 ↔ ¬ is_square a`. -/
lemma quadratic_char_neg_one_iff_not_is_square {a : F} :
quadratic_char F a = -1 ↔ ¬ is_square a :=
begin
by_cases ha : a = 0,
{ simp only [ha, is_square_zero, mul_char.map_zero, zero_eq_neg, one_ne_zero, not_true], },
{ rw [quadratic_char_eq_neg_one_iff_not_one ha, quadratic_char_one_iff_is_square ha] },
end
/-- If `F` has odd characteristic, then `quadratic_char F` takes the value `-1`. -/
lemma quadratic_char_exists_neg_one (hF : ring_char F ≠ 2) : ∃ a, quadratic_char F a = -1 :=
(finite_field.exists_nonsquare hF).imp $ λ b h₁, quadratic_char_neg_one_iff_not_is_square.mpr h₁
/-- If `ring_char F = 2`, then `quadratic_char F` takes the value `1` on nonzero elements. -/
lemma quadratic_char_eq_one_of_char_two (hF : ring_char F = 2) {a : F} (ha : a ≠ 0) :
quadratic_char F a = 1 :=
quadratic_char_fun_eq_one_of_char_two hF ha
/-- If `ring_char F` is odd, then `quadratic_char F a` can be computed in
terms of `a ^ (fintype.card F / 2)`. -/
lemma quadratic_char_eq_pow_of_char_ne_two (hF : ring_char F ≠ 2) {a : F} (ha : a ≠ 0) :
quadratic_char F a = if a ^ (fintype.card F / 2) = 1 then 1 else -1 :=
quadratic_char_fun_eq_pow_of_char_ne_two hF ha
lemma quadratic_char_eq_pow_of_char_ne_two' (hF : ring_char F ≠ 2) (a : F) :
(quadratic_char F a : F) = a ^ (fintype.card F / 2) :=
begin
by_cases ha : a = 0,
{ have : 0 < fintype.card F / 2 := nat.div_pos fintype.one_lt_card two_pos,
simp only [ha, zero_pow this, quadratic_char_apply, quadratic_char_zero, int.cast_zero], },
{ rw [quadratic_char_eq_pow_of_char_ne_two hF ha],
by_cases ha' : a ^ (fintype.card F / 2) = 1,
{ simp only [ha', eq_self_iff_true, if_true, int.cast_one], },
{ have ha'' := or.resolve_left (finite_field.pow_dichotomy hF ha) ha',
simp only [ha'', int.cast_ite, int.cast_one, int.cast_neg, ite_eq_right_iff],
exact eq.symm, } }
end
variables (F)
/-- The quadratic character is quadratic as a multiplicative character. -/
lemma quadratic_char_is_quadratic : (quadratic_char F).is_quadratic :=
begin
intro a,
by_cases ha : a = 0,
{ left, rw ha, exact quadratic_char_zero, },
{ right, exact quadratic_char_dichotomy ha, },
end
variables {F}
/-- The quadratic character is nontrivial as a multiplicative character
when the domain has odd characteristic. -/
lemma quadratic_char_is_nontrivial (hF : ring_char F ≠ 2) : (quadratic_char F).is_nontrivial :=
begin
rcases quadratic_char_exists_neg_one hF with ⟨a, ha⟩,
have hu : is_unit a := by { by_contra hf, rw map_nonunit _ hf at ha, norm_num at ha, },
refine ⟨hu.unit, (_ : quadratic_char F a ≠ 1)⟩,
rw ha,
norm_num,
end
/-- The number of solutions to `x^2 = a` is determined by the quadratic character. -/
lemma quadratic_char_card_sqrts (hF : ring_char F ≠ 2) (a : F) :
↑{x : F | x^2 = a}.to_finset.card = quadratic_char F a + 1 :=
begin
-- we consider the cases `a = 0`, `a` is a nonzero square and `a` is a nonsquare in turn
by_cases h₀ : a = 0,
{ simp only [h₀, pow_eq_zero_iff, nat.succ_pos', int.coe_nat_succ, int.coe_nat_zero,
mul_char.map_zero, set.set_of_eq_eq_singleton, set.to_finset_card,
set.card_singleton], },
{ set s := {x : F | x^2 = a}.to_finset with hs,
by_cases h : is_square a,
{ rw (quadratic_char_one_iff_is_square h₀).mpr h,
rcases h with ⟨b, h⟩,
rw [h, mul_self_eq_zero] at h₀,
have h₁ : s = [b, -b].to_finset := by
{ ext x,
simp only [finset.mem_filter, finset.mem_univ, true_and, list.to_finset_cons,
list.to_finset_nil, insert_emptyc_eq, finset.mem_insert, finset.mem_singleton],
rw ← pow_two at h,
simp only [hs, set.mem_to_finset, set.mem_set_of_eq, h],
split,
{ exact eq_or_eq_neg_of_sq_eq_sq _ _, },
{ rintro (h₂ | h₂); rw h₂,
simp only [neg_sq], }, },
norm_cast,
rw [h₁, list.to_finset_cons, list.to_finset_cons, list.to_finset_nil],
exact finset.card_doubleton
(ne.symm (mt (ring.eq_self_iff_eq_zero_of_char_ne_two hF).mp h₀)), },
{ rw quadratic_char_neg_one_iff_not_is_square.mpr h,
simp only [int.coe_nat_eq_zero, finset.card_eq_zero, set.to_finset_card,
fintype.card_of_finset, set.mem_set_of_eq, add_left_neg],
ext x,
simp only [iff_false, finset.mem_filter, finset.mem_univ, true_and, finset.not_mem_empty],
rw is_square_iff_exists_sq at h,
exact λ h', h ⟨_, h'.symm⟩, }, },
end
open_locale big_operators
/-- The sum over the values of the quadratic character is zero when the characteristic is odd. -/
lemma quadratic_char_sum_zero (hF : ring_char F ≠ 2) : ∑ (a : F), quadratic_char F a = 0 :=
is_nontrivial.sum_eq_zero (quadratic_char_is_nontrivial hF)
end quadratic_char
/-!
### Special values of the quadratic character
We express `quadratic_char F (-1)` in terms of `χ₄`.
-/
section special_values
open zmod mul_char
variables {F : Type} [field F] [fintype F]
/-- The value of the quadratic character at `-1` -/
lemma quadratic_char_neg_one [decidable_eq F] (hF : ring_char F ≠ 2) :
quadratic_char F (-1) = χ₄ (fintype.card F) :=
begin
have h := quadratic_char_eq_pow_of_char_ne_two hF (neg_ne_zero.mpr one_ne_zero),
rw [h, χ₄_eq_neg_one_pow (finite_field.odd_card_of_char_ne_two hF)],
set n := fintype.card F / 2,
cases (nat.even_or_odd n) with h₂ h₂,
{ simp only [even.neg_one_pow h₂, eq_self_iff_true, if_true], },
{ simp only [odd.neg_one_pow h₂, ite_eq_right_iff],
exact λ hf, false.rec (1 = -1) (ring.neg_one_ne_one_of_char_ne_two hF hf), },
end
/-- `-1` is a square in `F` iff `#F` is not congruent to `3` mod `4`. -/
lemma finite_field.is_square_neg_one_iff : is_square (-1 : F) ↔ fintype.card F % 4 ≠ 3 :=
begin
classical, -- suggested by the linter (instead of `[decidable_eq F]`)
by_cases hF : ring_char F = 2,
{ simp only [finite_field.is_square_of_char_two hF, ne.def, true_iff],
exact (λ hf, one_ne_zero $ (nat.odd_of_mod_four_eq_three hf).symm.trans
$ finite_field.even_card_of_char_two hF) },
{ have h₁ := finite_field.odd_card_of_char_ne_two hF,
rw [← quadratic_char_one_iff_is_square (neg_ne_zero.mpr (one_ne_zero' F)),
quadratic_char_neg_one hF, χ₄_nat_eq_if_mod_four, h₁],
simp only [nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : ℤ) ≠ 1),
imp_false, not_not],
exact ⟨λ h, ne_of_eq_of_ne h (dec_trivial : 1 ≠ 3),
or.resolve_right (nat.odd_mod_four_iff.mp h₁)⟩, },
end
/-- The value of the quadratic character at `2` -/
lemma quadratic_char_two [decidable_eq F] (hF : ring_char F ≠ 2) :
quadratic_char F 2 = χ₈ (fintype.card F) :=
is_quadratic.eq_of_eq_coe (quadratic_char_is_quadratic F) is_quadratic_χ₈ hF
((quadratic_char_eq_pow_of_char_ne_two' hF 2).trans (finite_field.two_pow_card hF))
/-- `2` is a square in `F` iff `#F` is not congruent to `3` or `5` mod `8`. -/
lemma finite_field.is_square_two_iff :
is_square (2 : F) ↔ fintype.card F % 8 ≠ 3 ∧ fintype.card F % 8 ≠ 5 :=
begin
classical,
by_cases hF : ring_char F = 2,
focus
{ have h := finite_field.even_card_of_char_two hF,
simp only [finite_field.is_square_of_char_two hF, true_iff], },
rotate, focus
{ have h := finite_field.odd_card_of_char_ne_two hF,
rw [← quadratic_char_one_iff_is_square (ring.two_ne_zero hF), quadratic_char_two hF,
χ₈_nat_eq_if_mod_eight],
simp only [h, nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : ℤ) ≠ 1),
imp_false, not_not], },
all_goals
{ rw [← nat.mod_mod_of_dvd _ (by norm_num : 2 ∣ 8)] at h,
have h₁ := nat.mod_lt (fintype.card F) (dec_trivial : 0 < 8),
revert h₁ h,
generalize : fintype.card F % 8 = n,
dec_trivial!, }
end
/-- The value of the quadratic character at `-2` -/
lemma quadratic_char_neg_two [decidable_eq F] (hF : ring_char F ≠ 2) :
quadratic_char F (-2) = χ₈' (fintype.card F) :=
begin
rw [(by norm_num : (-2 : F) = (-1) * 2), map_mul, χ₈'_eq_χ₄_mul_χ₈, quadratic_char_neg_one hF,
quadratic_char_two hF, @cast_nat_cast _ (zmod 4) _ _ _ (by norm_num : 4 ∣ 8)],
end
/-- `-2` is a square in `F` iff `#F` is not congruent to `5` or `7` mod `8`. -/
lemma finite_field.is_square_neg_two_iff :
is_square (-2 : F) ↔ fintype.card F % 8 ≠ 5 ∧ fintype.card F % 8 ≠ 7 :=
begin
classical,
by_cases hF : ring_char F = 2,
focus
{ have h := finite_field.even_card_of_char_two hF,
simp only [finite_field.is_square_of_char_two hF, true_iff], },
rotate, focus
{ have h := finite_field.odd_card_of_char_ne_two hF,
rw [← quadratic_char_one_iff_is_square (neg_ne_zero.mpr (ring.two_ne_zero hF)),
quadratic_char_neg_two hF, χ₈'_nat_eq_if_mod_eight],
simp only [h, nat.one_ne_zero, if_false, ite_eq_left_iff, ne.def, (dec_trivial : (-1 : ℤ) ≠ 1),
imp_false, not_not], },
all_goals
{ rw [← nat.mod_mod_of_dvd _ (by norm_num : 2 ∣ 8)] at h,
have h₁ := nat.mod_lt (fintype.card F) (dec_trivial : 0 < 8),
revert h₁ h,
generalize : fintype.card F % 8 = n,
dec_trivial! }
end
/-- The relation between the values of the quadratic character of one field `F` at the
cardinality of another field `F'` and of the quadratic character of `F'` at the cardinality
of `F`. -/
lemma quadratic_char_card_card [decidable_eq F] (hF : ring_char F ≠ 2) {F' : Type} [field F']
[fintype F'] [decidable_eq F'] (hF' : ring_char F' ≠ 2) (h : ring_char F' ≠ ring_char F) :
quadratic_char F (fintype.card F') = quadratic_char F' (quadratic_char F (-1) * fintype.card F) :=
begin
let χ := (quadratic_char F).ring_hom_comp (algebra_map ℤ F'),
have hχ₁ : χ.is_nontrivial,
{ obtain ⟨a, ha⟩ := quadratic_char_exists_neg_one hF,
have hu : is_unit a,
{ contrapose ha,
exact ne_of_eq_of_ne (map_nonunit (quadratic_char F) ha)
(mt zero_eq_neg.mp one_ne_zero), },
use hu.unit,
simp only [is_unit.unit_spec, ring_hom_comp_apply, eq_int_cast, ne.def, ha],
rw [int.cast_neg, int.cast_one],
exact ring.neg_one_ne_one_of_char_ne_two hF', },
have hχ₂ : χ.is_quadratic := is_quadratic.comp (quadratic_char_is_quadratic F) _,
have h := char.card_pow_card hχ₁ hχ₂ h hF',
rw [← quadratic_char_eq_pow_of_char_ne_two' hF'] at h,
exact (is_quadratic.eq_of_eq_coe (quadratic_char_is_quadratic F')
(quadratic_char_is_quadratic F) hF' h).symm,
end
/-- The value of the quadratic character at an odd prime `p` different from `ring_char F`. -/
lemma quadratic_char_odd_prime [decidable_eq F] (hF : ring_char F ≠ 2) {p : ℕ} [fact p.prime]
(hp₁ : p ≠ 2) (hp₂ : ring_char F ≠ p) :
quadratic_char F p = quadratic_char (zmod p) (χ₄ (fintype.card F) * fintype.card F) :=
begin
rw [← quadratic_char_neg_one hF],
have h := quadratic_char_card_card hF (ne_of_eq_of_ne (ring_char_zmod_n p) hp₁)
(ne_of_eq_of_ne (ring_char_zmod_n p) hp₂.symm),
rwa [card p] at h,
end
/-- An odd prime `p` is a square in `F` iff the quadratic character of `zmod p` does not
take the value `-1` on `χ₄(#F) * #F`. -/
lemma finite_field.is_square_odd_prime_iff (hF : ring_char F ≠ 2) {p : ℕ} [fact p.prime]
(hp : p ≠ 2) :
is_square (p : F) ↔ quadratic_char (zmod p) (χ₄ (fintype.card F) * fintype.card F) ≠ -1 :=
begin
classical,
by_cases hFp : ring_char F = p,
{ rw [show (p : F) = 0, by { rw ← hFp, exact ring_char.nat.cast_ring_char }],
simp only [is_square_zero, ne.def, true_iff, map_mul],
obtain ⟨n, _, hc⟩ := finite_field.card F (ring_char F),
have hchar : ring_char F = ring_char (zmod p) := by {rw hFp, exact (ring_char_zmod_n p).symm},
conv {congr, to_lhs, congr, skip, rw [hc, nat.cast_pow, map_pow, hchar, map_ring_char], },
simp only [zero_pow n.pos, mul_zero, zero_eq_neg, one_ne_zero, not_false_iff], },
{ rw [← iff.not_left (@quadratic_char_neg_one_iff_not_is_square F _ _ _ _),
quadratic_char_odd_prime hF hp],
exact hFp, },
end
end special_values
|
c882796ea4274ead2e45952d8e35e5cf85163cf8
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/analysis/seminorm.lean
|
29ea0d7171a47ef7e433b8142551336311de6dff
|
[] |
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
| 7,680
|
lean
|
/-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.pointwise
import Mathlib.analysis.normed_space.basic
import Mathlib.PostPort
universes u_1 u_2 l
namespace Mathlib
/-!
# Seminorms and Local Convexity
This file introduces the following notions, defined for a vector space
over a normed field:
- the subset properties of being `absorbent` and `balanced`,
- a `seminorm`, a function to the reals that is positive-semidefinite,
absolutely homogeneous, and subadditive.
We prove related properties.
## TODO
Define and show equivalence of two notions of local convexity for a
topological vector space over ℝ or ℂ: that it has a local base of
balanced convex absorbent sets, and that it carries the initial
topology induced by a family of seminorms.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
-/
/-!
### Subset Properties
Absorbent and balanced sets in a vector space over a
nondiscrete normed field.
-/
/-- A set `A` absorbs another set `B` if `B` is contained in scaling
`A` by elements of sufficiently large norms. -/
def absorbs (𝕜 : Type u_1) [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (A : set E) (B : set E) :=
∃ (r : ℝ), ∃ (H : r > 0), ∀ (a : 𝕜), r ≤ norm a → B ⊆ a • A
/-- A set is absorbent if it absorbs every singleton. -/
def absorbent (𝕜 : Type u_1) [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (A : set E) :=
∀ (x : E), ∃ (r : ℝ), ∃ (H : r > 0), ∀ (a : 𝕜), r ≤ norm a → x ∈ a • A
/-- A set `A` is balanced if `a • A` is contained in `A` whenever `a`
has norm no greater than one. -/
def balanced (𝕜 : Type u_1) [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (A : set E) :=
∀ (a : 𝕜), norm a ≤ 1 → a • A ⊆ A
/-- A balanced set absorbs itself. -/
theorem balanced.absorbs_self {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] {A : set E} (hA : balanced 𝕜 A) : absorbs 𝕜 A A := sorry
/-!
Properties of balanced and absorbing sets in a topological vector space:
-/
/-- Every neighbourhood of the origin is absorbent. -/
theorem absorbent_nhds_zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] {A : set E} [topological_space E] [topological_vector_space 𝕜 E] (hA : A ∈ nhds 0) : absorbent 𝕜 A := sorry
/-- The union of `{0}` with the interior of a balanced set
is balanced. -/
theorem balanced_zero_union_interior {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] {A : set E} [topological_space E] [topological_vector_space 𝕜 E] (hA : balanced 𝕜 A) : balanced 𝕜 (singleton 0 ∪ interior A) := sorry
/-- The interior of a balanced set is balanced if it contains the origin. -/
theorem balanced.interior {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] {A : set E} [topological_space E] [topological_vector_space 𝕜 E] (hA : balanced 𝕜 A) (h : 0 ∈ interior A) : balanced 𝕜 (interior A) := sorry
/-- The closure of a balanced set is balanced. -/
theorem balanced.closure {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] {A : set E} [topological_space E] [topological_vector_space 𝕜 E] (hA : balanced 𝕜 A) : balanced 𝕜 (closure A) := sorry
/-!
### Seminorms
-/
/-- A seminorm on a vector space over a normed field is a function to
the reals that is positive semidefinite, positive homogeneous, and
subadditive. -/
structure seminorm (𝕜 : Type u_1) (E : Type u_2) [normed_field 𝕜] [add_comm_group E] [vector_space 𝕜 E]
where
to_fun : E → ℝ
smul' : ∀ (a : 𝕜) (x : E), to_fun (a • x) = norm a * to_fun x
triangle' : ∀ (x y : E), to_fun (x + y) ≤ to_fun x + to_fun y
protected instance seminorm.inhabited {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] : Inhabited (seminorm 𝕜 E) :=
{ default := seminorm.mk (fun (_x : E) => 0) sorry sorry }
protected instance seminorm.has_coe_to_fun {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] : has_coe_to_fun (seminorm 𝕜 E) :=
has_coe_to_fun.mk (fun (p : seminorm 𝕜 E) => E → ℝ) fun (p : seminorm 𝕜 E) => seminorm.to_fun p
namespace seminorm
protected theorem smul {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (c : 𝕜) (x : E) : coe_fn p (c • x) = norm c * coe_fn p x :=
smul' p c x
protected theorem triangle {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) (y : E) : coe_fn p (x + y) ≤ coe_fn p x + coe_fn p y :=
triangle' p x y
@[simp] protected theorem zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) : coe_fn p 0 = 0 := sorry
@[simp] protected theorem neg {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) : coe_fn p (-x) = coe_fn p x := sorry
theorem nonneg {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) : 0 ≤ coe_fn p x := sorry
theorem sub_rev {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) (y : E) : coe_fn p (x - y) = coe_fn p (y - x) :=
eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn p (x - y) = coe_fn p (y - x))) (Eq.symm (neg_sub y x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn p (-(y - x)) = coe_fn p (y - x))) (seminorm.neg p (y - x))))
(Eq.refl (coe_fn p (y - x))))
/-- The ball of radius `r` at `x` with respect to seminorm `p`
is the set of elements `y` with `p (y - x) < `r`. -/
def ball {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) (r : ℝ) : set E :=
set_of fun (y : E) => coe_fn p (y - x) < r
theorem mem_ball {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (x : E) (y : E) (r : ℝ) : y ∈ ball p x r ↔ coe_fn p (y - x) < r :=
iff.rfl
theorem mem_ball_zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (y : E) (r : ℝ) : y ∈ ball p 0 r ↔ coe_fn p y < r :=
eq.mpr (id (Eq._oldrec (Eq.refl (y ∈ ball p 0 r ↔ coe_fn p y < r)) (propext (mem_ball p 0 y r))))
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn p (y - 0) < r ↔ coe_fn p y < r)) (sub_zero y))) (iff.refl (coe_fn p y < r)))
theorem ball_zero_eq {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (r : ℝ) : ball p 0 r = set_of fun (y : E) => coe_fn p y < r := sorry
/-- Seminorm-balls at the origin are balanced. -/
theorem balanced_ball_zero {𝕜 : Type u_1} [nondiscrete_normed_field 𝕜] {E : Type u_2} [add_comm_group E] [vector_space 𝕜 E] (p : seminorm 𝕜 E) (r : ℝ) : balanced 𝕜 (ball p 0 r) := sorry
|
6f44d9e9928c4af34bc8b97f224725f09ceae7a3
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/algebra/module/basic.lean
|
b48d6898e86f5ba9260af4539fcfe90268b42851
|
[
"Apache-2.0"
] |
permissive
|
agjftucker/mathlib
|
d634cd0d5256b6325e3c55bb7fb2403548371707
|
87fe50de17b00af533f72a102d0adefe4a2285e8
|
refs/heads/master
| 1,625,378,131,941
| 1,599,166,526,000
| 1,599,166,526,000
| 160,748,509
| 0
| 0
|
Apache-2.0
| 1,544,141,789,000
| 1,544,141,789,000
| null |
UTF-8
|
Lean
| false
| false
| 22,257
|
lean
|
/-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import group_theory.group_action
/-!
# Modules over a ring
In this file we define
* `semimodule R M` : an additive commutative monoid `M` is a `semimodule` over a
`semiring` `R` if for `r : R` and `x : M` their "scalar multiplication `r • x : M` is defined, and
the operation `•` satisfies some natural associativity and distributivity axioms similar to those
on a ring.
* `module R M` : same as `semimodule R M` but assumes that `R` is a `ring` and `M` is an
additive commutative group.
* `vector_space k M` : same as `semimodule k M` and `module k M` but assumes that `k` is a `field`
and `M` is an additive commutative group.
* `linear_map R M M₂`, `M →ₗ[R] M₂` : a linear map between two R-`semimodule`s.
* `is_linear_map R f` : predicate saying that `f : M → M₂` is a linear map.
## Implementation notes
* `vector_space` and `module` are abbreviations for `semimodule R M`.
## Tags
semimodule, module, vector space, linear map
-/
open function
open_locale big_operators
universes u u' v w x y z
variables {R : Type u} {k : Type u'} {S : Type v} {M : Type w} {M₂ : Type x} {M₃ : Type y}
{ι : Type z}
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A semimodule is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`,
connected by a "scalar multiplication" operation `r • x : M`
(where `r : R` and `x : M`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
@[protect_proj] class semimodule (R : Type u) (M : Type v) [semiring R]
[add_comm_monoid M] extends distrib_mul_action R M :=
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
(zero_smul : ∀x : M, (0 : R) • x = 0)
end prio
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [semimodule R M] (r s : R) (x y : M)
theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x
variables (R)
@[simp] theorem zero_smul : (0 : R) • x = 0 := semimodule.zero_smul x
theorem two_smul : (2 : R) • x = x + x := by rw [bit0, add_smul, one_smul]
/-- Pullback a `semimodule` structure along an injective additive monoid homomorphism. -/
protected def function.injective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M₂ →+ M)
(hf : injective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) :
semimodule R M₂ :=
{ smul := (•),
add_smul := λ c₁ c₂ x, hf $ by simp only [smul, f.map_add, add_smul],
zero_smul := λ x, hf $ by simp only [smul, zero_smul, f.map_zero],
.. hf.distrib_mul_action f smul }
/-- Pushforward a `semimodule` structure along a surjective additive monoid homomorphism. -/
protected def function.surjective.semimodule [add_comm_monoid M₂] [has_scalar R M₂] (f : M →+ M₂)
(hf : surjective f) (smul : ∀ (c : R) x, f (c • x) = c • f x) :
semimodule R M₂ :=
{ smul := (•),
add_smul := λ c₁ c₂ x, by { rcases hf x with ⟨x, rfl⟩,
simp only [add_smul, ← smul, ← f.map_add] },
zero_smul := λ x, by { rcases hf x with ⟨x, rfl⟩, simp only [← f.map_zero, ← smul, zero_smul] },
.. hf.distrib_mul_action f smul }
variable (M)
/-- `(•)` as an `add_monoid_hom`. -/
def smul_add_hom : R →+ M →+ M :=
{ to_fun := const_smul_hom M,
map_zero' := add_monoid_hom.ext $ λ r, by simp,
map_add' := λ x y, add_monoid_hom.ext $ λ r, by simp [add_smul] }
variables {R M}
@[simp] lemma smul_add_hom_apply (r : R) (x : M) :
smul_add_hom R M r x = r • x := rfl
lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 :=
by rw [←one_smul R x, ←zero_eq_one, zero_smul]
lemma list.sum_smul {l : list R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum :=
((smul_add_hom R M).flip x).map_list_sum l
lemma multiset.sum_smul {l : multiset R} {x : M} : l.sum • x = (l.map (λ r, r • x)).sum :=
((smul_add_hom R M).flip x).map_multiset_sum l
lemma finset.sum_smul {f : ι → R} {s : finset ι} {x : M} :
(∑ i in s, f i) • x = (∑ i in s, (f i) • x) :=
((smul_add_hom R M).flip x).map_sum f s
end add_comm_monoid
section add_comm_group
variables (R M) [semiring R] [add_comm_group M]
/-- A structure containing most informations as in a semimodule, except the fields `zero_smul`
and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`,
this provides a way to construct a semimodule structure by checking less properties, in
`semimodule.of_core`. -/
@[nolint has_inhabited_instance]
structure semimodule.core extends has_scalar R M :=
(smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)
(add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
(mul_smul : ∀(r s : R) (x : M), (r * s) • x = r • s • x)
(one_smul : ∀x : M, (1 : R) • x = x)
variables {R M}
/-- Define `semimodule` without proving `zero_smul` and `smul_zero` by using an auxiliary
structure `semimodule.core`, when the underlying space is an `add_comm_group`. -/
def semimodule.of_core (H : semimodule.core R M) : semimodule R M :=
by letI := H.to_has_scalar; exact
{ zero_smul := λ x, (add_monoid_hom.mk' (λ r : R, r • x) (λ r s, H.add_smul r s x)).map_zero,
smul_zero := λ r, (add_monoid_hom.mk' ((•) r) (H.smul_add r)).map_zero,
..H }
end add_comm_group
/--
Modules are defined as an `abbreviation` for semimodules,
if the base semiring is a ring.
(A previous definition made `module` a structure
defined to be `semimodule`.)
This has as advantage that modules are completely transparent
for type class inference, which means that all instances for semimodules
are immediately picked up for modules as well.
A cosmetic disadvantage is that one can not extend modules as such,
in definitions such as `normed_space`.
The solution is to extend `semimodule` instead.
-/
library_note "module definition"
/-- A module is the same as a semimodule, except the scalar semiring is actually
a ring.
This is the traditional generalization of spaces like `ℤ^n`, which have a natural
addition operation and a way to multiply them by elements of a ring, but no multiplication
operation between vectors. -/
abbreviation module (R : Type u) (M : Type v) [ring R] [add_comm_group M] :=
semimodule R M
/--
To prove two module structures on a fixed `add_comm_group` agree,
it suffices to check the scalar multiplications agree.
-/
-- We'll later use this to show `module ℤ M` is a subsingleton.
@[ext]
lemma module_ext {R : Type*} [ring R] {M : Type*} [add_comm_group M] (P Q : module R M)
(w : ∀ (r : R) (m : M), by { haveI := P, exact r • m } = by { haveI := Q, exact r • m }) :
P = Q :=
begin
unfreezingI { rcases P with ⟨⟨⟨⟨P⟩⟩⟩⟩, rcases Q with ⟨⟨⟨⟨Q⟩⟩⟩⟩ },
congr,
funext r m,
exact w r m,
all_goals { apply proof_irrel_heq },
end
section module
variables [ring R] [add_comm_group M] [module R M] (r s : R) (x y : M)
@[simp] theorem neg_smul : -r • x = - (r • x) :=
eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul])
variables (R)
theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp
variables {R}
theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y :=
by simp [add_smul, sub_eq_add_neg]
theorem smul_eq_zero {R E : Type*} [division_ring R] [add_comm_group E] [module R E]
{c : R} {x : E} :
c • x = 0 ↔ c = 0 ∨ x = 0 :=
⟨λ h, or_iff_not_imp_left.2 $ λ hc, (units.mk0 c hc).smul_eq_zero.1 h,
λ h, h.elim (λ hc, hc.symm ▸ zero_smul R x) (λ hx, hx.symm ▸ smul_zero c)⟩
end module
section
set_option default_priority 910
instance semiring.to_semimodule [semiring R] : semimodule R R :=
{ smul := (*),
smul_add := mul_add,
add_smul := add_mul,
mul_smul := mul_assoc,
one_smul := one_mul,
zero_smul := zero_mul,
smul_zero := mul_zero }
end
@[simp] lemma smul_eq_mul [semiring R] {a a' : R} : a • a' = a * a' := rfl
/-- A ring homomorphism `f : R →+* M` defines a module structure by `r • x = f r * x`. -/
def ring_hom.to_semimodule [semiring R] [semiring S] (f : R →+* S) : semimodule R S :=
{ smul := λ r x, f r * x,
smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add],
add_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_add, add_mul],
mul_smul := λ r s x, by unfold has_scalar.smul; rw [f.map_mul, mul_assoc],
one_smul := λ x, show f 1 * x = _, by rw [f.map_one, one_mul],
zero_smul := λ x, show f 0 * x = 0, by rw [f.map_zero, zero_mul],
smul_zero := λ r, mul_zero (f r) }
/-- A map `f` between semimodules over a semiring is linear if it satisfies the two properties
`f (x + y) = f x + f y` and `f (c • x) = c • f x`. The predicate `is_linear_map R f` asserts this
property. A bundled version is available with `linear_map`, and should be favored over
`is_linear_map` most of the time. -/
structure is_linear_map (R : Type u) {M : Type v} {M₂ : Type w}
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂]
(f : M → M₂) : Prop :=
(map_add : ∀ x y, f (x + y) = f x + f y)
(map_smul : ∀ (c : R) x, f (c • x) = c • f x)
/-- A map `f` between semimodules over a semiring is linear if it satisfies the two properties
`f (x + y) = f x + f y` and `f (c • x) = c • f x`. Elements of `linear_map R M M₂` (available under
the notation `M →ₗ[R] M₂`) are bundled versions of such maps. An unbundled version is available with
the predicate `is_linear_map`, but it should be avoided most of the time. -/
structure linear_map (R : Type u) (M : Type v) (M₂ : Type w)
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂] :=
(to_fun : M → M₂)
(map_add' : ∀x y, to_fun (x + y) = to_fun x + to_fun y)
(map_smul' : ∀(c : R) x, to_fun (c • x) = c • to_fun x)
infixr ` →ₗ `:25 := linear_map _
notation M ` →ₗ[`:25 R:25 `] `:0 M₂:0 := linear_map R M M₂
namespace linear_map
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃]
section
variables [semimodule R M] [semimodule R M₂]
instance : has_coe_to_fun (M →ₗ[R] M₂) := ⟨_, to_fun⟩
@[simp] lemma coe_mk (f : M → M₂) (h₁ h₂) :
((linear_map.mk f h₁ h₂ : M →ₗ[R] M₂) : M → M₂) = f := rfl
/-- Identity map as a `linear_map` -/
def id : M →ₗ[R] M :=
⟨id, λ _ _, rfl, λ _ _, rfl⟩
lemma id_apply (x : M) :
@id R M _ _ _ x = x := rfl
@[simp, norm_cast] lemma id_coe : ((linear_map.id : M →ₗ[R] M) : M → M) = _root_.id :=
by { ext x, refl }
end
section
-- We can infer the module structure implicitly from the linear maps,
-- rather than via typeclass resolution.
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables (f g : M →ₗ[R] M₂)
@[simp] lemma to_fun_eq_coe : f.to_fun = ⇑f := rfl
theorem is_linear : is_linear_map R f := ⟨f.2, f.3⟩
variables {f g}
theorem coe_inj (h : (f : M → M₂) = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext] theorem ext (H : ∀ x, f x = g x) : f = g :=
coe_inj $ funext H
lemma coe_fn_congr : Π {x x' : M}, x = x' → f x = f x'
| _ _ rfl := rfl
theorem ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨by { rintro rfl x, refl } , ext⟩
/-- If two linear maps are equal, they are equal at each point. -/
lemma lcongr_fun (h : f = g) (m : M) : f m = g m :=
congr_fun (congr_arg linear_map.to_fun h) m
variables (f g)
@[simp] lemma map_add (x y : M) : f (x + y) = f x + f y := f.map_add' x y
@[simp] lemma map_smul (c : R) (x : M) : f (c • x) = c • f x := f.map_smul' c x
@[simp] lemma map_zero : f 0 = 0 :=
by rw [← zero_smul R, map_smul f 0 0, zero_smul]
instance : is_add_monoid_hom f :=
{ map_add := map_add f,
map_zero := map_zero f }
/-- convert a linear map to an additive map -/
def to_add_monoid_hom : M →+ M₂ :=
{ to_fun := f,
map_zero' := f.map_zero,
map_add' := f.map_add }
@[simp] lemma to_add_monoid_hom_coe :
((f.to_add_monoid_hom) : M → M₂) = f := rfl
@[simp] lemma map_sum {ι} {t : finset ι} {g : ι → M} :
f (∑ i in t, g i) = (∑ i in t, f (g i)) :=
f.to_add_monoid_hom.map_sum _ _
end
section
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
{semimodule_M₃ : semimodule R M₃}
variables (f : M₂ →ₗ[R] M₃) (g : M →ₗ[R] M₂)
/-- Composition of two linear maps is a linear map -/
def comp : M →ₗ[R] M₃ := ⟨f ∘ g, by simp, by simp⟩
@[simp] lemma comp_apply (x : M) : f.comp g x = f (g x) := rfl
@[norm_cast]
lemma comp_coe : (f : M₂ → M₃) ∘ (g : M → M₂) = f.comp g := rfl
end
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂]
variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂}
variables (f : M →ₗ[R] M₂)
@[simp] lemma map_neg (x : M) : f (- x) = - f x :=
f.to_add_monoid_hom.map_neg x
@[simp] lemma map_sub (x y : M) : f (x - y) = f x - f y :=
f.to_add_monoid_hom.map_sub x y
instance : is_add_group_hom f :=
{ map_add := map_add f}
end add_comm_group
end linear_map
namespace is_linear_map
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
variables [semimodule R M] [semimodule R M₂]
include R
/-- Convert an `is_linear_map` predicate to a `linear_map` -/
def mk' (f : M → M₂) (H : is_linear_map R f) : M →ₗ M₂ := ⟨f, H.1, H.2⟩
@[simp] theorem mk'_apply {f : M → M₂} (H : is_linear_map R f) (x : M) :
mk' f H x = f x := rfl
lemma is_linear_map_smul {R M : Type*} [comm_semiring R] [add_comm_monoid M] [semimodule R M] (c : R) :
is_linear_map R (λ (z : M), c • z) :=
begin
refine is_linear_map.mk (smul_add c) _,
intros _ _,
simp only [smul_smul, mul_comm]
end
--TODO: move
lemma is_linear_map_smul' {R M : Type*} [semiring R] [add_comm_monoid M] [semimodule R M] (a : M) :
is_linear_map R (λ (c : R), c • a) :=
is_linear_map.mk (λ x y, add_smul x y a) (λ x y, mul_smul x y a)
variables {f : M → M₂} (lin : is_linear_map R f)
include M M₂ lin
lemma map_zero : f (0 : M) = (0 : M₂) := (lin.mk' f).map_zero
end add_comm_monoid
section add_comm_group
variables [semiring R] [add_comm_group M] [add_comm_group M₂]
variables [semimodule R M] [semimodule R M₂]
include R
lemma is_linear_map_neg :
is_linear_map R (λ (z : M), -z) :=
is_linear_map.mk neg_add (λ x y, (smul_neg x y).symm)
variables {f : M → M₂} (lin : is_linear_map R f)
include M M₂ lin
lemma map_neg (x : M) : f (- x) = - f x := (lin.mk' f).map_neg x
lemma map_sub (x y) : f (x - y) = f x - f y := (lin.mk' f).map_sub x y
end add_comm_group
end is_linear_map
/-- Ring of linear endomorphismsms of a module. -/
abbreviation module.End (R : Type u) (M : Type v)
[semiring R] [add_comm_monoid M] [semimodule R M] := M →ₗ[R] M
/--
Vector spaces are defined as an `abbreviation` for semimodules,
if the base ring is a field.
(A previous definition made `vector_space` a structure
defined to be `module`.)
This has as advantage that vector spaces are completely transparent
for type class inference, which means that all instances for semimodules
are immediately picked up for vector spaces as well.
A cosmetic disadvantage is that one can not extend vector spaces as such,
in definitions such as `normed_space`.
The solution is to extend `semimodule` instead.
-/
library_note "vector space definition"
/-- A vector space is the same as a module, except the scalar ring is actually
a field. (This adds commutativity of the multiplication and existence of inverses.)
This is the traditional generalization of spaces like `ℝ^n`, which have a natural
addition operation and a way to multiply them by real numbers, but no multiplication
operation between vectors. -/
abbreviation vector_space (R : Type u) (M : Type v) [field R] [add_comm_group M] :=
semimodule R M
namespace add_comm_monoid
open add_monoid
variables [add_comm_monoid M]
/-- The natural ℕ-semimodule structure on any `add_comm_monoid`. -/
-- We don't make this a global instance, as it results in too many instances,
-- and confusing ambiguity in the notation `n • x` when `n : ℕ`.
def nat_semimodule : semimodule ℕ M :=
{ smul := nsmul,
smul_add := λ _ _ _, nsmul_add _ _ _,
add_smul := λ _ _ _, add_nsmul _ _ _,
mul_smul := λ _ _ _, mul_nsmul _ _ _,
one_smul := one_nsmul,
zero_smul := zero_nsmul,
smul_zero := nsmul_zero }
end add_comm_monoid
namespace add_comm_group
variables [add_comm_group M]
/-- The natural ℤ-module structure on any `add_comm_group`. -/
-- We don't immediately make this a global instance, as it results in too many instances,
-- and confusing ambiguity in the notation `n • x` when `n : ℤ`.
-- We do turn it into a global instance, but only at the end of this file,
-- and I remain dubious whether this is a good idea.
def int_module : module ℤ M :=
{ smul := gsmul,
smul_add := λ _ _ _, gsmul_add _ _ _,
add_smul := λ _ _ _, add_gsmul _ _ _,
mul_smul := λ _ _ _, gsmul_mul _ _ _,
one_smul := one_gsmul,
zero_smul := zero_gsmul,
smul_zero := gsmul_zero }
instance : subsingleton (module ℤ M) :=
begin
split,
intros P Q,
ext,
-- isn't that lovely: `r • m = r • m`
have one_smul : by { haveI := P, exact (1 : ℤ) • m } = by { haveI := Q, exact (1 : ℤ) • m },
begin
rw [@one_smul ℤ _ _ (by { haveI := P, apply_instance, }) m],
rw [@one_smul ℤ _ _ (by { haveI := Q, apply_instance, }) m],
end,
have nat_smul : ∀ n : ℕ, by { haveI := P, exact (n : ℤ) • m } = by { haveI := Q, exact (n : ℤ) • m },
begin
intro n,
induction n with n ih,
{ erw [zero_smul, zero_smul], },
{ rw [int.coe_nat_succ, add_smul, add_smul],
erw ih,
rw [one_smul], }
end,
cases r,
{ rw [int.of_nat_eq_coe, nat_smul], },
{ rw [int.neg_succ_of_nat_coe, neg_smul, neg_smul, nat_smul], }
end
end add_comm_group
section
local attribute [instance] add_comm_monoid.nat_semimodule
lemma semimodule.smul_eq_smul (R : Type*) [semiring R]
{M : Type*} [add_comm_monoid M] [semimodule R M]
(n : ℕ) (b : M) : n • b = (n : R) • b :=
begin
induction n with n ih,
{ rw [nat.cast_zero, zero_smul, zero_smul] },
{ change (n + 1) • b = (n + 1 : R) • b,
rw [add_smul, add_smul, one_smul, ih, one_smul] }
end
lemma semimodule.nsmul_eq_smul (R : Type*) [semiring R]
{M : Type*} [add_comm_monoid M] [semimodule R M] (n : ℕ) (b : M) :
n •ℕ b = (n : R) • b :=
semimodule.smul_eq_smul R n b
lemma nat.smul_def {M : Type*} [add_comm_monoid M] (n : ℕ) (x : M) :
n • x = n •ℕ x :=
rfl
end
section
local attribute [instance] add_comm_group.int_module
lemma gsmul_eq_smul {M : Type*} [add_comm_group M] (n : ℤ) (x : M) : gsmul n x = n • x := rfl
lemma module.gsmul_eq_smul_cast (R : Type*) [ring R] {M : Type*} [add_comm_group M] [module R M]
(n : ℤ) (b : M) : gsmul n b = (n : R) • b :=
begin
cases n,
{ apply semimodule.nsmul_eq_smul, },
{ dsimp,
rw semimodule.nsmul_eq_smul R,
push_cast,
rw neg_smul, }
end
lemma module.gsmul_eq_smul {M : Type*} [add_comm_group M] [module ℤ M]
(n : ℤ) (b : M) : gsmul n b = n • b :=
by rw [module.gsmul_eq_smul_cast ℤ, int.cast_id]
end
-- We prove this without using the `add_comm_group.int_module` instance, so the `•`s here
-- come from whatever the local `module ℤ` structure actually is.
lemma add_monoid_hom.map_int_module_smul
[add_comm_group M] [add_comm_group M₂]
[module ℤ M] [module ℤ M₂] (f : M →+ M₂) (x : ℤ) (a : M) : f (x • a) = x • f a :=
by simp only [← module.gsmul_eq_smul, f.map_gsmul]
lemma add_monoid_hom.map_int_cast_smul
[ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
(f : M →+ M₂) (x : ℤ) (a : M) : f ((x : R) • a) = (x : R) • f a :=
by simp only [← module.gsmul_eq_smul_cast, f.map_gsmul]
lemma add_monoid_hom.map_nat_cast_smul
[semiring R] [add_comm_monoid M] [add_comm_monoid M₂]
[semimodule R M] [semimodule R M₂] (f : M →+ M₂) (x : ℕ) (a : M) :
f ((x : R) • a) = (x : R) • f a :=
by simp only [← semimodule.nsmul_eq_smul, f.map_nsmul]
lemma add_monoid_hom.map_rat_cast_smul {R : Type*} [division_ring R] [char_zero R]
{E : Type*} [add_comm_group E] [module R E] {F : Type*} [add_comm_group F] [module R F]
(f : E →+ F) (c : ℚ) (x : E) :
f ((c : R) • x) = (c : R) • f x :=
begin
have : ∀ (x : E) (n : ℕ), 0 < n → f (((n⁻¹ : ℚ) : R) • x) = ((n⁻¹ : ℚ) : R) • f x,
{ intros x n hn,
replace hn : (n : R) ≠ 0 := nat.cast_ne_zero.2 (ne_of_gt hn),
conv_rhs { congr, skip, rw [← one_smul R x, ← mul_inv_cancel hn, mul_smul] },
rw [f.map_nat_cast_smul, smul_smul, rat.cast_inv, rat.cast_coe_nat,
inv_mul_cancel hn, one_smul] },
refine c.num_denom_cases_on (λ m n hn hmn, _),
rw [rat.mk_eq_div, div_eq_mul_inv, rat.cast_mul, int.cast_coe_nat, mul_smul, mul_smul,
rat.cast_coe_int, f.map_int_cast_smul, this _ n hn]
end
lemma add_monoid_hom.map_rat_module_smul {E : Type*} [add_comm_group E] [vector_space ℚ E]
{F : Type*} [add_comm_group F] [module ℚ F] (f : E →+ F) (c : ℚ) (x : E) :
f (c • x) = c • f x :=
rat.cast_id c ▸ f.map_rat_cast_smul c x
-- We finally turn on these instances globally:
attribute [instance] add_comm_monoid.nat_semimodule add_comm_group.int_module
/-- Reinterpret an additive homomorphism as a `ℤ`-linear map. -/
def add_monoid_hom.to_int_linear_map [add_comm_group M] [add_comm_group M₂] (f : M →+ M₂) :
M →ₗ[ℤ] M₂ :=
⟨f, f.map_add, f.map_int_module_smul⟩
/-- Reinterpret an additive homomorphism as a `ℚ`-linear map. -/
def add_monoid_hom.to_rat_linear_map [add_comm_group M] [vector_space ℚ M]
[add_comm_group M₂] [vector_space ℚ M₂] (f : M →+ M₂) :
M →ₗ[ℚ] M₂ :=
⟨f, f.map_add, f.map_rat_module_smul⟩
|
e19b283268a1ca454ee8d0930f0f2c963c119cde
|
82e44445c70db0f03e30d7be725775f122d72f3e
|
/src/tactic/interactive.lean
|
8a8f2c89419ef81f6a81aa27a13a0dcff6bd9f09
|
[
"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
| 38,825
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Sébastien Gouëzel, Scott Morrison
-/
import tactic.lint
import tactic.dependencies
open lean
open lean.parser
local postfix `?`:9001 := optional
local postfix *:9001 := many
namespace tactic
namespace interactive
open interactive interactive.types expr
/-- Similar to `constructor`, but does not reorder goals. -/
meta def fconstructor : tactic unit := concat_tags tactic.fconstructor
add_tactic_doc
{ name := "fconstructor",
category := doc_category.tactic,
decl_names := [`tactic.interactive.fconstructor],
tags := ["logic", "goal management"] }
/-- `try_for n { tac }` executes `tac` for `n` ticks, otherwise uses `sorry` to close the goal.
Never fails. Useful for debugging. -/
meta def try_for (max : parse parser.pexpr) (tac : itactic) : tactic unit :=
do max ← i_to_expr_strict max >>= tactic.eval_expr nat,
λ s, match _root_.try_for max (tac s) with
| some r := r
| none := (tactic.trace "try_for timeout, using sorry" >> admit) s
end
/-- Multiple `subst`. `substs x y z` is the same as `subst x, subst y, subst z`. -/
meta def substs (l : parse ident*) : tactic unit :=
propagate_tags $ l.mmap' (λ h, get_local h >>= tactic.subst) >> try (tactic.reflexivity reducible)
add_tactic_doc
{ name := "substs",
category := doc_category.tactic,
decl_names := [`tactic.interactive.substs],
tags := ["rewriting"] }
/-- Unfold coercion-related definitions -/
meta def unfold_coes (loc : parse location) : tactic unit :=
unfold [
``coe, ``coe_t, ``has_coe_t.coe, ``coe_b,``has_coe.coe,
``lift, ``has_lift.lift, ``lift_t, ``has_lift_t.lift,
``coe_fn, ``has_coe_to_fun.coe, ``coe_sort, ``has_coe_to_sort.coe] loc
add_tactic_doc
{ name := "unfold_coes",
category := doc_category.tactic,
decl_names := [`tactic.interactive.unfold_coes],
tags := ["simplification"] }
/-- Unfold `has_well_founded.r`, `sizeof` and other such definitions. -/
meta def unfold_wf :=
propagate_tags (well_founded_tactics.unfold_wf_rel; well_founded_tactics.unfold_sizeof)
/-- Unfold auxiliary definitions associated with the current declaration. -/
meta def unfold_aux : tactic unit :=
do tgt ← target,
name ← decl_name,
let to_unfold := (tgt.list_names_with_prefix name),
guard (¬ to_unfold.empty),
-- should we be using simp_lemmas.mk_default?
simp_lemmas.mk.dsimplify to_unfold.to_list tgt >>= tactic.change
/-- For debugging only. This tactic checks the current state for any
missing dropped goals and restores them. Useful when there are no
goals to solve but "result contains meta-variables". -/
meta def recover : tactic unit :=
metavariables >>= tactic.set_goals
/-- Like `try { tac }`, but in the case of failure it continues
from the failure state instead of reverting to the original state. -/
meta def continue (tac : itactic) : tactic unit :=
λ s, result.cases_on (tac s)
(λ a, result.success ())
(λ e ref, result.success ())
/-- `id { tac }` is the same as `tac`, but it is useful for creating a block scope without
requiring the goal to be solved at the end like `{ tac }`. It can also be used to enclose a
non-interactive tactic for patterns like `tac1; id {tac2}` where `tac2` is non-interactive. -/
@[inline] protected meta def id (tac : itactic) : tactic unit := tac
/--
`work_on_goal n { tac }` creates a block scope for the `n`-goal (indexed from zero),
and does not require that the goal be solved at the end
(any remaining subgoals are inserted back into the list of goals).
Typically usage might look like:
````
intros,
simp,
apply lemma_1,
work_on_goal 2 {
dsimp,
simp
},
refl
````
See also `id { tac }`, which is equivalent to `work_on_goal 0 { tac }`.
-/
meta def work_on_goal : parse small_nat → itactic → tactic unit
| n t := do
goals ← get_goals,
let earlier_goals := goals.take n,
let later_goals := goals.drop (n+1),
set_goals (goals.nth n).to_list,
t,
new_goals ← get_goals,
set_goals (earlier_goals ++ new_goals ++ later_goals)
/--
`swap n` will move the `n`th goal to the front.
`swap` defaults to `swap 2`, and so interchanges the first and second goals.
See also `tactic.interactive.rotate`, which moves the first `n` goals to the back.
-/
meta def swap (n := 2) : tactic unit :=
do gs ← get_goals,
match gs.nth (n-1) with
| (some g) := set_goals (g :: gs.remove_nth (n-1))
| _ := skip
end
add_tactic_doc
{ name := "swap",
category := doc_category.tactic,
decl_names := [`tactic.interactive.swap],
tags := ["goal management"] }
/--
`rotate` moves the first goal to the back. `rotate n` will do this `n` times.
See also `tactic.interactive.swap`, which moves the `n`th goal to the front.
-/
meta def rotate (n := 1) : tactic unit := tactic.rotate n
add_tactic_doc
{ name := "rotate",
category := doc_category.tactic,
decl_names := [`tactic.interactive.rotate],
tags := ["goal management"] }
/-- Clear all hypotheses starting with `_`, like `_match` and `_let_match`. -/
meta def clear_ : tactic unit := tactic.repeat $ do
l ← local_context,
l.reverse.mfirst $ λ h, do
name.mk_string s p ← return $ local_pp_name h,
guard (s.front = '_'),
cl ← infer_type h >>= is_class, guard (¬ cl),
tactic.clear h
add_tactic_doc
{ name := "clear_",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_],
tags := ["context management"] }
/--
Acts like `have`, but removes a hypothesis with the same name as
this one. For example if the state is `h : p ⊢ goal` and `f : p → q`,
then after `replace h := f h` the goal will be `h : q ⊢ goal`,
where `have h := f h` would result in the state `h : p, h : q ⊢ goal`.
This can be used to simulate the `specialize` and `apply at` tactics
of Coq. -/
meta def replace (h : parse ident?) (q₁ : parse (tk ":" *> texpr)?)
(q₂ : parse $ (tk ":=" *> texpr)?) : tactic unit :=
do let h := h.get_or_else `this,
old ← try_core (get_local h),
«have» h q₁ q₂,
match old, q₂ with
| none, _ := skip
| some o, some _ := tactic.clear o
| some o, none := swap >> tactic.clear o >> swap
end
add_tactic_doc
{ name := "replace",
category := doc_category.tactic,
decl_names := [`tactic.interactive.replace],
tags := ["context management"] }
/-- Make every proposition in the context decidable. -/
meta def classical := tactic.classical
add_tactic_doc
{ name := "classical",
category := doc_category.tactic,
decl_names := [`tactic.interactive.classical],
tags := ["classical logic", "type class"] }
private meta def generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `eq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def generalize_arg_p : parser (pexpr × name) :=
with_desc "expr = id" $ parser.pexpr 0 >>= generalize_arg_p_aux
@[nolint def_lemma]
lemma {u} generalize_a_aux {α : Sort u}
(h : ∀ x : Sort u, (α → x) → x) : α := h α id
/--
Like `generalize` but also considers assumptions
specified by the user. The user can also specify to
omit the goal.
-/
meta def generalize_hyp (h : parse ident?) (_ : parse $ tk ":")
(p : parse generalize_arg_p)
(l : parse location) :
tactic unit :=
do h' ← get_unused_name `h,
x' ← get_unused_name `x,
g ← if ¬ l.include_goal then
do refine ``(generalize_a_aux _),
some <$> (prod.mk <$> tactic.intro x' <*> tactic.intro h')
else pure none,
n ← l.get_locals >>= tactic.revert_lst,
generalize h () p,
intron n,
match g with
| some (x',h') :=
do tactic.apply h',
tactic.clear h',
tactic.clear x'
| none := return ()
end
add_tactic_doc
{ name := "generalize_hyp",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalize_hyp],
tags := ["context management"] }
meta def compact_decl_aux : list name → binder_info → expr → list expr →
tactic (list (list name × binder_info × expr))
| ns bi t [] := pure [(ns.reverse, bi, t)]
| ns bi t (v'@(local_const n pp bi' t') :: xs) :=
do t' ← infer_type v',
if bi = bi' ∧ t = t'
then compact_decl_aux (pp :: ns) bi t xs
else do vs ← compact_decl_aux [pp] bi' t' xs,
pure $ (ns.reverse, bi, t) :: vs
| ns bi t (_ :: xs) := compact_decl_aux ns bi t xs
/-- go from (x₀ : t₀) (x₁ : t₀) (x₂ : t₀) to (x₀ x₁ x₂ : t₀) -/
meta def compact_decl : list expr → tactic (list (list name × binder_info × expr))
| [] := pure []
| (v@(local_const n pp bi t) :: xs) :=
do t ← infer_type v,
compact_decl_aux [pp] bi t xs
| (_ :: xs) := compact_decl xs
/--
Remove identity functions from a term. These are normally
automatically generated with terms like `show t, from p` or
`(p : t)` which translate to some variant on `@id t p` in
order to retain the type.
-/
meta def clean (q : parse texpr) : tactic unit :=
do tgt : expr ← target,
e ← i_to_expr_strict ``(%%q : %%tgt),
tactic.exact $ e.clean
meta def source_fields (missing : list name) (e : pexpr) : tactic (list (name × pexpr)) :=
do e ← to_expr e,
t ← infer_type e,
let struct_n : name := t.get_app_fn.const_name,
fields ← expanded_field_list struct_n,
let exp_fields := fields.filter (λ x, x.2 ∈ missing),
exp_fields.mmap $ λ ⟨p,n⟩,
(prod.mk n ∘ to_pexpr) <$> mk_mapp (n.update_prefix p) [none,some e]
meta def collect_struct' : pexpr → state_t (list $ expr×structure_instance_info) tactic pexpr | e :=
do some str ← pure (e.get_structure_instance_info)
| e.traverse collect_struct',
v ← monad_lift mk_mvar,
modify (list.cons (v,str)),
pure $ to_pexpr v
meta def collect_struct (e : pexpr) : tactic $ pexpr × list (expr×structure_instance_info) :=
prod.map id list.reverse <$> (collect_struct' e).run []
meta def refine_one (str : structure_instance_info) :
tactic $ list (expr×structure_instance_info) :=
do tgt ← target >>= whnf,
let struct_n : name := tgt.get_app_fn.const_name,
exp_fields ← expanded_field_list struct_n,
let missing_f := exp_fields.filter (λ f, (f.2 : name) ∉ str.field_names),
(src_field_names,src_field_vals) ← (@list.unzip name _ ∘ list.join) <$>
str.sources.mmap (source_fields $ missing_f.map prod.snd),
let provided := exp_fields.filter (λ f, (f.2 : name) ∈ str.field_names),
let missing_f' := missing_f.filter (λ x, x.2 ∉ src_field_names),
vs ← mk_mvar_list missing_f'.length,
(field_values,new_goals) ← list.unzip <$> (str.field_values.mmap collect_struct : tactic _),
e' ← to_expr $ pexpr.mk_structure_instance
{ struct := some struct_n
, field_names := str.field_names ++ missing_f'.map prod.snd ++ src_field_names
, field_values := field_values ++ vs.map to_pexpr ++ src_field_vals },
tactic.exact e',
gs ← with_enable_tags (
mzip_with (λ (n : name × name) v, do
set_goals [v],
try (dsimp_target simp_lemmas.mk),
apply_auto_param
<|> apply_opt_param
<|> (set_main_tag [`_field,n.2,n.1]),
get_goals)
missing_f' vs),
set_goals gs.join,
return new_goals.join
meta def refine_recursively : expr × structure_instance_info → tactic (list expr) | (e,str) :=
do set_goals [e],
rs ← refine_one str,
gs ← get_goals,
gs' ← rs.mmap refine_recursively,
return $ gs'.join ++ gs
/--
`refine_struct { .. }` acts like `refine` but works only with structure instance
literals. It creates a goal for each missing field and tags it with the name of the
field so that `have_field` can be used to generically refer to the field currently
being refined.
As an example, we can use `refine_struct` to automate the construction of semigroup
instances:
```lean
refine_struct ( { .. } : semigroup α ),
-- case semigroup, mul
-- α : Type u,
-- ⊢ α → α → α
-- case semigroup, mul_assoc
-- α : Type u,
-- ⊢ ∀ (a b c : α), a * b * c = a * (b * c)
```
`have_field`, used after `refine_struct _`, poses `field` as a local constant
with the type of the field of the current goal:
```lean
refine_struct ({ .. } : semigroup α),
{ have_field, ... },
{ have_field, ... },
```
behaves like
```lean
refine_struct ({ .. } : semigroup α),
{ have field := @semigroup.mul, ... },
{ have field := @semigroup.mul_assoc, ... },
```
-/
meta def refine_struct : parse texpr → tactic unit | e :=
do (x,xs) ← collect_struct e,
refine x,
gs ← get_goals,
xs' ← xs.mmap refine_recursively,
set_goals (xs'.join ++ gs)
/--
`guard_hyp' h : t` fails if the hypothesis `h` does not have type `t`.
We use this tactic for writing tests.
Fixes `guard_hyp` by instantiating meta variables
-/
meta def guard_hyp' (n : parse ident) (p : parse $ tk ":" *> texpr) : tactic unit :=
do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_eq h p
/--
`match_hyp h : t` fails if the hypothesis `h` does not match the type `t` (which may be a pattern).
We use this tactic for writing tests.
-/
meta def match_hyp (n : parse ident) (p : parse $ tk ":" *> texpr) (m := reducible) : tactic (list expr) :=
do
h ← get_local n >>= infer_type >>= instantiate_mvars,
match_expr p h m
/--
`guard_expr_strict t := e` fails if the expr `t` is not equal to `e`. By contrast
to `guard_expr`, this tests strict (syntactic) equality.
We use this tactic for writing tests.
-/
meta def guard_expr_strict (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e ← to_expr p, guard (t = e)
/--
`guard_target_strict t` fails if the target of the main goal is not syntactically `t`.
We use this tactic for writing tests.
-/
meta def guard_target_strict (p : parse texpr) : tactic unit :=
do t ← target, guard_expr_strict t p
/--
`guard_hyp_strict h : t` fails if the hypothesis `h` does not have type syntactically equal
to `t`.
We use this tactic for writing tests.
-/
meta def guard_hyp_strict (n : parse ident) (p : parse $ tk ":" *> texpr) : tactic unit :=
do h ← get_local n >>= infer_type >>= instantiate_mvars, guard_expr_strict h p
/-- Tests that there are `n` hypotheses in the current context. -/
meta def guard_hyp_nums (n : ℕ) : tactic unit :=
do k ← local_context,
guard (n = k.length) <|> fail format!"{k.length} hypotheses found"
/-- Test that `t` is the tag of the main goal. -/
meta def guard_tags (tags : parse ident*) : tactic unit :=
do (t : list name) ← get_main_tag,
guard (t = tags)
/-- `guard_proof_term { t } e` applies tactic `t` and tests whether the resulting proof term
unifies with `p`. -/
meta def guard_proof_term (t : itactic) (p : parse texpr) : itactic :=
do
g :: _ ← get_goals,
e ← to_expr p,
t,
g ← instantiate_mvars g,
unify e g
/-- `success_if_fail_with_msg { tac } msg` succeeds if the interactive tactic `tac` fails with
error message `msg` (for test writing purposes). -/
meta def success_if_fail_with_msg (tac : tactic.interactive.itactic) :=
tactic.success_if_fail_with_msg tac
/-- Get the field of the current goal. -/
meta def get_current_field : tactic name :=
do [_,field,str] ← get_main_tag,
expr.const_name <$> resolve_name (field.update_prefix str)
meta def field (n : parse ident) (tac : itactic) : tactic unit :=
do gs ← get_goals,
ts ← gs.mmap get_tag,
([g],gs') ← pure $ (list.zip gs ts).partition (λ x, x.snd.nth 1 = some n),
set_goals [g.1],
tac, done,
set_goals $ gs'.map prod.fst
/--
`have_field`, used after `refine_struct _` poses `field` as a local constant
with the type of the field of the current goal:
```lean
refine_struct ({ .. } : semigroup α),
{ have_field, ... },
{ have_field, ... },
```
behaves like
```lean
refine_struct ({ .. } : semigroup α),
{ have field := @semigroup.mul, ... },
{ have field := @semigroup.mul_assoc, ... },
```
-/
meta def have_field : tactic unit :=
propagate_tags $
get_current_field
>>= mk_const
>>= note `field none
>> return ()
/-- `apply_field` functions as `have_field, apply field, clear field` -/
meta def apply_field : tactic unit :=
propagate_tags $
get_current_field >>= applyc
add_tactic_doc
{ name := "refine_struct",
category := doc_category.tactic,
decl_names := [`tactic.interactive.refine_struct, `tactic.interactive.apply_field,
`tactic.interactive.have_field],
tags := ["structures"],
inherit_description_from := `tactic.interactive.refine_struct }
/--
`apply_rules hs n` applies the list of lemmas `hs` and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times.
`n` is optional, equal to 50 by default.
You can pass an `apply_cfg` option argument as `apply_rules hs n opt`.
(A typical usage would be with `apply_rules hs n { md := reducible })`,
which asks `apply_rules` to not unfold `semireducible` definitions (i.e. most)
when checking if a lemma matches the goal.)
`hs` can contain user attributes: in this case all theorems with this
attribute are added to the list of rules.
For instance:
```lean
@[user_attribute]
meta def mono_rules : user_attribute :=
{ name := `mono_rules,
descr := "lemmas usable to prove monotonicity" }
attribute [mono_rules] add_le_add mul_le_mul_of_nonneg_right
lemma my_test {a b c d e : real} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 0 ≤ e) :
a + c * e + a + c + 0 ≤ b + d * e + b + d + e :=
-- any of the following lines solve the goal:
add_le_add (add_le_add (add_le_add (add_le_add h1 (mul_le_mul_of_nonneg_right h2 h3)) h1 ) h2) h3
by apply_rules [add_le_add, mul_le_mul_of_nonneg_right]
by apply_rules [mono_rules]
by apply_rules mono_rules
```
-/
meta def apply_rules (hs : parse pexpr_list_or_texpr) (n : nat := 50) (opt : apply_cfg := {}) :
tactic unit :=
tactic.apply_rules hs n opt
add_tactic_doc
{ name := "apply_rules",
category := doc_category.tactic,
decl_names := [`tactic.interactive.apply_rules],
tags := ["lemma application"] }
meta def return_cast (f : option expr) (t : option (expr × expr))
(es : list (expr × expr × expr))
(e x x' eq_h : expr) :
tactic (option (expr × expr) × list (expr × expr × expr)) :=
(do guard (¬ e.has_var),
unify x x',
u ← mk_meta_univ,
f ← f <|> mk_mapp ``_root_.id [(expr.sort u : expr)],
t' ← infer_type e,
some (f',t) ← pure t | return (some (f,t'), (e,x',eq_h) :: es),
infer_type e >>= is_def_eq t,
unify f f',
return (some (f,t), (e,x',eq_h) :: es)) <|>
return (t, es)
meta def list_cast_of_aux (x : expr) (t : option (expr × expr))
(es : list (expr × expr × expr)) :
expr → tactic (option (expr × expr) × list (expr × expr × expr))
| e@`(cast %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mp %%eq_h %%x') := return_cast none t es e x x' eq_h
| e@`(eq.mpr %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast none t es e x x'
| e@`(@eq.subst %%α %%p %%a %%b %%eq_h %%x') := return_cast p t es e x x' eq_h
| e@`(@eq.substr %%α %%p %%a %%b %%eq_h %%x') := mk_eq_symm eq_h >>= return_cast p t es e x x'
| e@`(@eq.rec %%α %%a %%f %%x' _ %%eq_h) := return_cast f t es e x x' eq_h
| e@`(@eq.rec_on %%α %%a %%f %%b %%eq_h %%x') := return_cast f t es e x x' eq_h
| e := return (t,es)
meta def list_cast_of (x tgt : expr) : tactic (list (expr × expr × expr)) :=
(list.reverse ∘ prod.snd) <$> tgt.mfold (none, []) (λ e i es, list_cast_of_aux x es.1 es.2 e)
private meta def h_generalize_arg_p_aux : pexpr → parser (pexpr × name)
| (app (app (macro _ [const `heq _ ]) h) (local_const x _ _ _)) := pure (h, x)
| _ := fail "parse error"
private meta def h_generalize_arg_p : parser (pexpr × name) :=
with_desc "expr == id" $ parser.pexpr 0 >>= h_generalize_arg_p_aux
/--
`h_generalize Hx : e == x` matches on `cast _ e` in the goal and replaces it with
`x`. It also adds `Hx : e == x` as an assumption. If `cast _ e` appears multiple
times (not necessarily with the same proof), they are all replaced by `x`. `cast`
`eq.mp`, `eq.mpr`, `eq.subst`, `eq.substr`, `eq.rec` and `eq.rec_on` are all treated
as casts.
- `h_generalize Hx : e == x with h` adds hypothesis `α = β` with `e : α, x : β`;
- `h_generalize Hx : e == x with _` chooses automatically chooses the name of
assumption `α = β`;
- `h_generalize! Hx : e == x` reverts `Hx`;
- when `Hx` is omitted, assumption `Hx : e == x` is not added.
-/
meta def h_generalize (rev : parse (tk "!")?)
(h : parse ident_?)
(_ : parse (tk ":"))
(arg : parse h_generalize_arg_p)
(eqs_h : parse ( (tk "with" >> pure <$> ident_) <|> pure [])) :
tactic unit :=
do let (e,n) := arg,
let h' := if h = `_ then none else h,
h' ← (h' : tactic name) <|> get_unused_name ("h" ++ n.to_string : string),
e ← to_expr e,
tgt ← target,
((e,x,eq_h)::es) ← list_cast_of e tgt | fail "no cast found",
interactive.generalize h' () (to_pexpr e, n),
asm ← get_local h',
v ← get_local n,
hs ← es.mmap (λ ⟨e,_⟩, mk_app `eq [e,v]),
(eqs_h.zip [e]).mmap' (λ ⟨h,e⟩, do
h ← if h ≠ `_ then pure h else get_unused_name `h,
() <$ note h none eq_h ),
hs.mmap' (λ h,
do h' ← assert `h h,
tactic.exact asm,
try (rewrite_target h'),
tactic.clear h' ),
when h.is_some (do
(to_expr ``(heq_of_eq_rec_left %%eq_h %%asm)
<|> to_expr ``(heq_of_cast_eq %%eq_h %%asm))
>>= note h' none >> pure ()),
tactic.clear asm,
when rev.is_some (interactive.revert [n])
add_tactic_doc
{ name := "h_generalize",
category := doc_category.tactic,
decl_names := [`tactic.interactive.h_generalize],
tags := ["context management"] }
/-- Tests whether `t` is definitionally equal to `p`. The difference with `guard_expr_eq` is that
this uses definitional equality instead of alpha-equivalence. -/
meta def guard_expr_eq' (t : expr) (p : parse $ tk ":=" *> texpr) : tactic unit :=
do e ← to_expr p, is_def_eq t e
/--
`guard_target' t` fails if the target of the main goal is not definitionally equal to `t`.
We use this tactic for writing tests.
The difference with `guard_target` is that this uses definitional equality instead of
alpha-equivalence.
-/
meta def guard_target' (p : parse texpr) : tactic unit :=
do t ← target, guard_expr_eq' t p
add_tactic_doc
{ name := "guard_target'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.guard_target'],
tags := ["testing"] }
/--
a weaker version of `trivial` that tries to solve the goal by reflexivity or by reducing it to true,
unfolding only `reducible` constants. -/
meta def triv : tactic unit :=
tactic.triv' <|> tactic.reflexivity reducible <|> tactic.contradiction <|> fail "triv tactic failed"
add_tactic_doc
{ name := "triv",
category := doc_category.tactic,
decl_names := [`tactic.interactive.triv],
tags := ["finishing"] }
/--
Similar to `existsi`. `use x` will instantiate the first term of an `∃` or `Σ` goal with `x`.
It will then try to close the new goal using `triv`, or try to simplify it by applying `exists_prop`.
Unlike `existsi`, `x` is elaborated with respect to the expected type.
`use` will alternatively take a list of terms `[x0, ..., xn]`.
`use` will work with constructors of arbitrary inductive types.
Examples:
```lean
example (α : Type) : ∃ S : set α, S = S :=
by use ∅
example : ∃ x : ℤ, x = x :=
by use 42
example : ∃ n > 0, n = n :=
begin
use 1,
-- goal is now 1 > 0 ∧ 1 = 1, whereas it would be ∃ (H : 1 > 0), 1 = 1 after existsi 1.
exact ⟨zero_lt_one, rfl⟩,
end
example : ∃ a b c : ℤ, a + b + c = 6 :=
by use [1, 2, 3]
example : ∃ p : ℤ × ℤ, p.1 = 1 :=
by use ⟨1, 42⟩
example : Σ x y : ℤ, (ℤ × ℤ) × ℤ :=
by use [1, 2, 3, 4, 5]
inductive foo
| mk : ℕ → bool × ℕ → ℕ → foo
example : foo :=
by use [100, tt, 4, 3]
```
-/
meta def use (l : parse pexpr_list_or_texpr) : tactic unit :=
focus1 $
tactic.use l;
try (triv <|> (do
`(Exists %%p) ← target,
to_expr ``(exists_prop.mpr) >>= tactic.apply >> skip))
add_tactic_doc
{ name := "use",
category := doc_category.tactic,
decl_names := [`tactic.interactive.use, `tactic.interactive.existsi],
tags := ["logic"],
inherit_description_from := `tactic.interactive.use }
/--
`clear_aux_decl` clears every `aux_decl` in the local context for the current goal.
This includes the induction hypothesis when using the equation compiler and
`_let_match` and `_fun_match`.
It is useful when using a tactic such as `finish`, `simp *` or `subst` that may use these
auxiliary declarations, and produce an error saying the recursion is not well founded.
```lean
example (n m : ℕ) (h₁ : n = m) (h₂ : ∃ a : ℕ, a = n ∧ a = m) : 2 * m = 2 * n :=
let ⟨a, ha⟩ := h₂ in
begin
clear_aux_decl, -- subst will fail without this line
subst h₁
end
example (x y : ℕ) (h₁ : ∃ n : ℕ, n * 1 = 2) (h₂ : 1 + 1 = 2 → x * 1 = y) : x = y :=
let ⟨n, hn⟩ := h₁ in
begin
clear_aux_decl, -- finish produces an error without this line
finish
end
```
-/
meta def clear_aux_decl : tactic unit := tactic.clear_aux_decl
add_tactic_doc
{ name := "clear_aux_decl",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_aux_decl, `tactic.clear_aux_decl],
tags := ["context management"],
inherit_description_from := `tactic.interactive.clear_aux_decl }
meta def loc.get_local_pp_names : loc → tactic (list name)
| loc.wildcard := list.map expr.local_pp_name <$> local_context
| (loc.ns l) := return l.reduce_option
meta def loc.get_local_uniq_names (l : loc) : tactic (list name) :=
list.map expr.local_uniq_name <$> l.get_locals
/--
The logic of `change x with y at l` fails when there are dependencies.
`change'` mimics the behavior of `change`, except in the case of `change x with y at l`.
In this case, it will correctly replace occurences of `x` with `y` at all possible hypotheses
in `l`. As long as `x` and `y` are defeq, it should never fail.
-/
meta def change' (q : parse texpr) : parse (tk "with" *> texpr)? → parse location → tactic unit
| none (loc.ns [none]) := do e ← i_to_expr q, change_core e none
| none (loc.ns [some h]) := do eq ← i_to_expr q, eh ← get_local h, change_core eq (some eh)
| none _ := fail "change-at does not support multiple locations"
| (some w) l :=
do l' ← loc.get_local_pp_names l,
l'.mmap' (λ e, try (change_with_at q w e)),
when l.include_goal $ change q w (loc.ns [none])
add_tactic_doc
{ name := "change'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.change', `tactic.interactive.change],
tags := ["renaming"],
inherit_description_from := `tactic.interactive.change' }
private meta def opt_dir_with : parser (option (bool × name)) :=
(do tk "with",
arrow ← (tk "<-")?,
h ← ident,
return (arrow.is_some, h)) <|> return none
/--
`set a := t with h` is a variant of `let a := t`. It adds the hypothesis `h : a = t` to
the local context and replaces `t` with `a` everywhere it can.
`set a := t with ←h` will add `h : t = a` instead.
`set! a := t with h` does not do any replacing.
```lean
example (x : ℕ) (h : x = 3) : x + x + x = 9 :=
begin
set y := x with ←h_xy,
/-
x : ℕ,
y : ℕ := x,
h_xy : x = y,
h : y = 3
⊢ y + y + y = 9
-/
end
```
-/
meta def set (h_simp : parse (tk "!")?) (a : parse ident) (tp : parse ((tk ":") >> texpr)?)
(_ : parse (tk ":=")) (pv : parse texpr)
(rev_name : parse opt_dir_with) :=
do tp ← i_to_expr $ tp.get_or_else pexpr.mk_placeholder,
pv ← to_expr ``(%%pv : %%tp),
tp ← instantiate_mvars tp,
definev a tp pv,
when h_simp.is_none $ change' ``(%%pv) (some (expr.const a [])) $ interactive.loc.wildcard,
match rev_name with
| some (flip, id) :=
do nv ← get_local a,
mk_app `eq (cond flip [pv, nv] [nv, pv]) >>= assert id,
reflexivity
| none := skip
end
add_tactic_doc
{ name := "set",
category := doc_category.tactic,
decl_names := [`tactic.interactive.set],
tags := ["context management"] }
/--
`clear_except h₀ h₁` deletes all the assumptions it can except for `h₀` and `h₁`.
-/
meta def clear_except (xs : parse ident *) : tactic unit :=
do n ← xs.mmap (try_core ∘ get_local) >>= revert_lst ∘ list.filter_map id,
ls ← local_context,
ls.reverse.mmap' $ try ∘ tactic.clear,
intron_no_renames n
add_tactic_doc
{ name := "clear_except",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_except],
tags := ["context management"] }
meta def format_names (ns : list name) : format :=
format.join $ list.intersperse " " (ns.map to_fmt)
private meta def indent_bindents (l r : string) : option (list name) → expr → tactic format
| none e :=
do e ← pp e,
pformat!"{l}{format.nest l.length e}{r}"
| (some ns) e :=
do e ← pp e,
let ns := format_names ns,
let margin := l.length + ns.to_string.length + " : ".length,
pformat!"{l}{ns} : {format.nest margin e}{r}"
private meta def format_binders : list name × binder_info × expr → tactic format
| (ns, binder_info.default, t) := indent_bindents "(" ")" ns t
| (ns, binder_info.implicit, t) := indent_bindents "{" "}" ns t
| (ns, binder_info.strict_implicit, t) := indent_bindents "⦃" "⦄" ns t
| ([n], binder_info.inst_implicit, t) :=
if "_".is_prefix_of n.to_string
then indent_bindents "[" "]" none t
else indent_bindents "[" "]" [n] t
| (ns, binder_info.inst_implicit, t) := indent_bindents "[" "]" ns t
| (ns, binder_info.aux_decl, t) := indent_bindents "(" ")" ns t
private meta def partition_vars' (s : name_set) : list expr → list expr → list expr → tactic (list expr × list expr)
| [] as bs := pure (as.reverse, bs.reverse)
| (x :: xs) as bs :=
do t ← infer_type x,
if t.has_local_in s then partition_vars' xs as (x :: bs)
else partition_vars' xs (x :: as) bs
private meta def partition_vars : tactic (list expr × list expr) :=
do ls ← local_context,
partition_vars' (name_set.of_list $ ls.map expr.local_uniq_name) ls [] []
/--
Format the current goal as a stand-alone example. Useful for testing tactics
or creating [minimal working examples](https://leanprover-community.github.io/mwe.html).
* `extract_goal`: formats the statement as an `example` declaration
* `extract_goal my_decl`: formats the statement as a `lemma` or `def` declaration
called `my_decl`
* `extract_goal with i j k:` only use local constants `i`, `j`, `k` in the declaration
Examples:
```lean
example (i j k : ℕ) (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
begin
extract_goal,
-- prints:
-- example (i j k : ℕ) (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
-- begin
-- admit,
-- end
extract_goal my_lemma
-- prints:
-- lemma my_lemma (i j k : ℕ) (h₀ : i ≤ j) (h₁ : j ≤ k) : i ≤ k :=
-- begin
-- admit,
-- end
end
example {i j k x y z w p q r m n : ℕ} (h₀ : i ≤ j) (h₁ : j ≤ k) (h₁ : k ≤ p) (h₁ : p ≤ q) : i ≤ k :=
begin
extract_goal my_lemma,
-- prints:
-- lemma my_lemma {i j k x y z w p q r m n : ℕ}
-- (h₀ : i ≤ j)
-- (h₁ : j ≤ k)
-- (h₁ : k ≤ p)
-- (h₁ : p ≤ q) :
-- i ≤ k :=
-- begin
-- admit,
-- end
extract_goal my_lemma with i j k
-- prints:
-- lemma my_lemma {p i j k : ℕ}
-- (h₀ : i ≤ j)
-- (h₁ : j ≤ k)
-- (h₁ : k ≤ p) :
-- i ≤ k :=
-- begin
-- admit,
-- end
end
example : true :=
begin
let n := 0,
have m : ℕ, admit,
have k : fin n, admit,
have : n + m + k.1 = 0, extract_goal,
-- prints:
-- example (m : ℕ) : let n : ℕ := 0 in ∀ (k : fin n), n + m + k.val = 0 :=
-- begin
-- intros n k,
-- admit,
-- end
end
```
-/
meta def extract_goal (print_use : parse $ tt <$ tk "!" <|> pure ff)
(n : parse ident?) (vs : parse with_ident_list)
: tactic unit :=
do tgt ← target,
solve_aux tgt $ do {
((cxt₀,cxt₁,ls,tgt),_) ← solve_aux tgt $ do {
when (¬ vs.empty) (clear_except vs),
ls ← local_context,
ls ← ls.mfilter $ succeeds ∘ is_local_def,
n ← revert_lst ls,
(c₀,c₁) ← partition_vars,
tgt ← target,
ls ← intron' n,
pure (c₀,c₁,ls,tgt) },
is_prop ← is_prop tgt,
let title := match n, is_prop with
| none, _ := to_fmt "example"
| (some n), tt := format!"lemma {n}"
| (some n), ff := format!"def {n}"
end,
cxt₀ ← compact_decl cxt₀ >>= list.mmap format_binders,
cxt₁ ← compact_decl cxt₁ >>= list.mmap format_binders,
stmt ← pformat!"{tgt} :=",
let fmt :=
format.group $ format.nest 2 $
title ++ cxt₀.foldl (λ acc x, acc ++ format.group (format.line ++ x)) "" ++
format.join (list.map (λ x, format.line ++ x) cxt₁) ++ " :" ++
format.line ++ stmt,
trace $ fmt.to_string $ options.mk.set_nat `pp.width 80,
let var_names := format.intercalate " " $ ls.map (to_fmt ∘ local_pp_name),
let call_intron := if ls.empty
then to_fmt ""
else format!"\n intros {var_names},",
trace!"begin{call_intron}\n admit,\nend\n" },
skip
add_tactic_doc
{ name := "extract_goal",
category := doc_category.tactic,
decl_names := [`tactic.interactive.extract_goal],
tags := ["goal management", "proof extraction", "debugging"] }
/--
`inhabit α` tries to derive a `nonempty α` instance and then upgrades this
to an `inhabited α` instance.
If the target is a `Prop`, this is done constructively;
otherwise, it uses `classical.choice`.
```lean
example (α) [nonempty α] : ∃ a : α, true :=
begin
inhabit α,
existsi default α,
trivial
end
```
-/
meta def inhabit (t : parse parser.pexpr) (inst_name : parse ident?) : tactic unit :=
do ty ← i_to_expr t,
nm ← returnopt inst_name <|> get_unused_name `inst,
tgt ← target,
tgt_is_prop ← is_prop tgt,
if tgt_is_prop then do
decorate_error "could not infer nonempty instance:" $
mk_mapp ``nonempty.elim_to_inhabited [ty, none, tgt] >>= tactic.apply,
introI nm
else do
decorate_error "could not infer nonempty instance:" $
mk_mapp ``classical.inhabited_of_nonempty' [ty, none] >>= note nm none,
resetI
add_tactic_doc
{ name := "inhabit",
category := doc_category.tactic,
decl_names := [`tactic.interactive.inhabit],
tags := ["context management", "type class"] }
/-- `revert_deps n₁ n₂ ...` reverts all the hypotheses that depend on one of `n₁, n₂, ...`
It does not revert `n₁, n₂, ...` themselves (unless they depend on another `nᵢ`). -/
meta def revert_deps (ns : parse ident*) : tactic unit :=
propagate_tags $
ns.mmap get_local >>= revert_reverse_dependencies_of_hyps >> skip
add_tactic_doc
{ name := "revert_deps",
category := doc_category.tactic,
decl_names := [`tactic.interactive.revert_deps],
tags := ["context management", "goal management"] }
/-- `revert_after n` reverts all the hypotheses after `n`. -/
meta def revert_after (n : parse ident) : tactic unit :=
propagate_tags $ get_local n >>= tactic.revert_after >> skip
add_tactic_doc
{ name := "revert_after",
category := doc_category.tactic,
decl_names := [`tactic.interactive.revert_after],
tags := ["context management", "goal management"] }
/-- Reverts all local constants on which the target depends (recursively). -/
meta def revert_target_deps : tactic unit :=
propagate_tags $ tactic.revert_target_deps >> skip
add_tactic_doc
{ name := "revert_target_deps",
category := doc_category.tactic,
decl_names := [`tactic.interactive.revert_target_deps],
tags := ["context management", "goal management"] }
/-- `clear_value n₁ n₂ ...` clears the bodies of the local definitions `n₁, n₂ ...`, changing them
into regular hypotheses. A hypothesis `n : α := t` is changed to `n : α`. -/
meta def clear_value (ns : parse ident*) : tactic unit :=
propagate_tags $ ns.reverse.mmap get_local >>= tactic.clear_value
add_tactic_doc
{ name := "clear_value",
category := doc_category.tactic,
decl_names := [`tactic.interactive.clear_value],
tags := ["context management"] }
/--
`generalize' : e = x` replaces all occurrences of `e` in the target with a new hypothesis `x` of
the same type.
`generalize' h : e = x` in addition registers the hypothesis `h : e = x`.
`generalize'` is similar to `generalize`. The difference is that `generalize' : e = x` also
succeeds when `e` does not occur in the goal. It is similar to `set`, but the resulting hypothesis
`x` is not a local definition.
-/
meta def generalize' (h : parse ident?) (_ : parse $ tk ":") (p : parse generalize_arg_p) : tactic unit :=
propagate_tags $
do let (p, x) := p,
e ← i_to_expr p,
some h ← pure h | tactic.generalize' e x >> skip,
-- `h` is given, the regular implementation of `generalize` works.
tgt ← target,
tgt' ← do {
⟨tgt', _⟩ ← solve_aux tgt (tactic.generalize e x >> target),
to_expr ``(Π x, %%e = x → %%(tgt'.binding_body.lift_vars 0 1))
} <|> to_expr ``(Π x, %%e = x → %%tgt),
t ← assert h tgt',
swap,
exact ``(%%t %%e rfl),
intro x,
intro h
add_tactic_doc
{ name := "generalize'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalize'],
tags := ["context management"] }
/--
If the expression `q` is a local variable with type `x = t` or `t = x`, where `x` is a local
constant, `tactic.interactive.subst' q` substitutes `x` by `t` everywhere in the main goal and
then clears `q`.
If `q` is another local variable, then we find a local constant with type `q = t` or `t = q` and
substitute `t` for `q`.
Like `tactic.interactive.subst`, but fails with a nicer error message if the substituted variable is
a local definition. It is trickier to fix this in core, since `tactic.is_local_def` is in mathlib.
-/
meta def subst' (q : parse texpr) : tactic unit := do
i_to_expr q >>= tactic.subst' >> try (tactic.reflexivity reducible)
add_tactic_doc
{ name := "subst'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.subst'],
tags := ["context management"] }
end interactive
end tactic
|
1709f78ca683661c3de6dd29cb70b0a812e253ec
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/stage0/src/Lean/Elab/Deriving/FromToJson.lean
|
a6f0ad4b30a9751057f27f9a7321630df421fe48
|
[
"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
| 9,267
|
lean
|
/-
Copyright (c) 2020 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich, Dany Fabian
-/
import Lean.Meta.Transform
import Lean.Elab.Deriving.Basic
import Lean.Elab.Deriving.Util
import Lean.Data.Json.FromToJson
namespace Lean.Elab.Deriving.FromToJson
open Lean.Elab.Command
open Lean.Json
open Lean.Parser.Term
open Lean.Meta
def mkJsonField (n : Name) : Bool × Term :=
let s := n.toString
let s₁ := s.dropRightWhile (· == '?')
(s != s₁, Syntax.mkStrLit s₁)
def mkToJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if declNames.size == 1 then
if isStructure (← getEnv) declNames[0]! then
let cmds ← liftTermElabM do
let ctx ← mkContext "toJson" declNames[0]!
let header ← mkHeader ``ToJson 1 ctx.typeInfos[0]!
let fields := getStructureFieldsFlattened (← getEnv) declNames[0]! (includeSubobjectFields := false)
let fields ← fields.mapM fun field => do
let (isOptField, nm) := mkJsonField field
if isOptField then ``(opt $nm $(mkIdent <| header.targetNames[0]! ++ field))
else ``([($nm, toJson $(mkIdent <| header.targetNames[0]! ++ field))])
let cmd ← `(private def $(mkIdent ctx.auxFunNames[0]!):ident $header.binders:bracketedBinder* : Json :=
mkObj <| List.join [$fields,*])
return #[cmd] ++ (← mkInstanceCmds ctx ``ToJson declNames)
cmds.forM elabCommand
return true
else
let indVal ← getConstInfoInduct declNames[0]!
let cmds ← liftTermElabM do
let ctx ← mkContext "toJson" declNames[0]!
let toJsonFuncId := mkIdent ctx.auxFunNames[0]!
-- Return syntax to JSONify `id`, either via `ToJson` or recursively
-- if `id`'s type is the type we're deriving for.
let mkToJson (id : Ident) (type : Expr) : TermElabM Term := do
if type.isAppOf indVal.name then `($toJsonFuncId:ident $id:ident)
else ``(toJson $id:ident)
let header ← mkHeader ``ToJson 1 ctx.typeInfos[0]!
let discrs ← mkDiscrs header indVal
let alts ← mkAlts indVal fun ctor args userNames => do
match args, userNames with
| #[], _ => ``(toJson $(quote ctor.name.getString!))
| #[(x, t)], none => ``(mkObj [($(quote ctor.name.getString!), $(← mkToJson x t))])
| xs, none =>
let xs ← xs.mapM fun (x, t) => mkToJson x t
``(mkObj [($(quote ctor.name.getString!), Json.arr #[$[$xs:term],*])])
| xs, some userNames =>
let xs ← xs.mapIdxM fun idx (x, t) => do
`(($(quote userNames[idx]!.getString!), $(← mkToJson x t)))
``(mkObj [($(quote ctor.name.getString!), mkObj [$[$xs:term],*])])
let auxTerm ← `(match $[$discrs],* with $alts:matchAlt*)
let auxCmd ←
if ctx.usePartial then
let letDecls ← mkLocalInstanceLetDecls ctx ``ToJson header.argNames
let auxTerm ← mkLet letDecls auxTerm
`(private partial def $toJsonFuncId:ident $header.binders:bracketedBinder* : Json := $auxTerm)
else
`(private def $toJsonFuncId:ident $header.binders:bracketedBinder* : Json := $auxTerm)
return #[auxCmd] ++ (← mkInstanceCmds ctx ``ToJson declNames)
cmds.forM elabCommand
return true
else
return false
where
mkAlts
(indVal : InductiveVal)
(rhs : ConstructorVal → Array (Ident × Expr) → Option (Array Name) → TermElabM Term) : TermElabM (Array (TSyntax ``matchAlt)) := do
indVal.ctors.toArray.mapM fun ctor => do
let ctorInfo ← getConstInfoCtor ctor
forallTelescopeReducing ctorInfo.type fun xs _ => do
let mut patterns := #[]
-- add `_` pattern for indices
for _ in [:indVal.numIndices] do
patterns := patterns.push (← `(_))
let mut ctorArgs := #[]
-- add `_` for inductive parameters, they are inaccessible
for _ in [:indVal.numParams] do
ctorArgs := ctorArgs.push (← `(_))
-- bound constructor arguments and their types
let mut binders := #[]
let mut userNames := #[]
for i in [:ctorInfo.numFields] do
let x := xs[indVal.numParams + i]!
let localDecl ← x.fvarId!.getDecl
if !localDecl.userName.hasMacroScopes then
userNames := userNames.push localDecl.userName
let a := mkIdent (← mkFreshUserName `a)
binders := binders.push (a, localDecl.type)
ctorArgs := ctorArgs.push a
patterns := patterns.push (← `(@$(mkIdent ctorInfo.name):ident $ctorArgs:term*))
let rhs ← rhs ctorInfo binders (if userNames.size == binders.size then some userNames else none)
`(matchAltExpr| | $[$patterns:term],* => $rhs:term)
def mkFromJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if declNames.size == 1 then
if isStructure (← getEnv) declNames[0]! then
let cmds ← liftTermElabM do
let ctx ← mkContext "fromJson" declNames[0]!
let header ← mkHeader ``FromJson 0 ctx.typeInfos[0]!
let fields := getStructureFieldsFlattened (← getEnv) declNames[0]! (includeSubobjectFields := false)
let jsonFields := fields.map (Prod.snd ∘ mkJsonField)
let fields := fields.map mkIdent
let cmd ← `(private def $(mkIdent ctx.auxFunNames[0]!):ident $header.binders:bracketedBinder* (j : Json)
: Except String $(← mkInductiveApp ctx.typeInfos[0]! header.argNames) := do
$[let $fields:ident ← getObjValAs? j _ $jsonFields]*
return { $[$fields:ident := $(id fields)],* })
return #[cmd] ++ (← mkInstanceCmds ctx ``FromJson declNames)
cmds.forM elabCommand
return true
else
let indVal ← getConstInfoInduct declNames[0]!
let cmds ← liftTermElabM do
let ctx ← mkContext "fromJson" declNames[0]!
let header ← mkHeader ``FromJson 0 ctx.typeInfos[0]!
let fromJsonFuncId := mkIdent ctx.auxFunNames[0]!
let alts ← mkAlts indVal fromJsonFuncId
let mut auxTerm ← alts.foldrM (fun xs x => `(Except.orElseLazy $xs (fun _ => $x))) (← `(Except.error "no inductive constructor matched"))
if ctx.usePartial then
let letDecls ← mkLocalInstanceLetDecls ctx ``FromJson header.argNames
auxTerm ← mkLet letDecls auxTerm
-- FromJson is not structurally recursive even non-nested recursive inductives,
-- so we also use `partial` then.
let auxCmd ←
if ctx.usePartial || indVal.isRec then
`(private partial def $fromJsonFuncId:ident $header.binders:bracketedBinder* (json : Json)
: Except String $(← mkInductiveApp ctx.typeInfos[0]! header.argNames) :=
$auxTerm)
else
`(private def $fromJsonFuncId:ident $header.binders:bracketedBinder* (json : Json)
: Except String $(← mkInductiveApp ctx.typeInfos[0]! header.argNames) :=
$auxTerm)
return #[auxCmd] ++ (← mkInstanceCmds ctx ``FromJson declNames)
cmds.forM elabCommand
return true
else
return false
where
mkAlts (indVal : InductiveVal) (fromJsonFuncId : Ident) : TermElabM (Array Term) := do
let alts ←
indVal.ctors.toArray.mapM fun ctor => do
let ctorInfo ← getConstInfoCtor ctor
forallTelescopeReducing ctorInfo.type fun xs _ => do
let mut binders := #[]
let mut userNames := #[]
for i in [:ctorInfo.numFields] do
let x := xs[indVal.numParams + i]!
let localDecl ← x.fvarId!.getDecl
if !localDecl.userName.hasMacroScopes then
userNames := userNames.push localDecl.userName
let a := mkIdent (← mkFreshUserName `a)
binders := binders.push (a, localDecl.type)
-- Return syntax to parse `id`, either via `FromJson` or recursively
-- if `id`'s type is the type we're deriving for.
let mkFromJson (idx : Nat) (type : Expr) : TermElabM (TSyntax ``doExpr) :=
if type.isAppOf indVal.name then `(Lean.Parser.Term.doExpr| $fromJsonFuncId:ident jsons[$(quote idx)]!)
else `(Lean.Parser.Term.doExpr| fromJson? jsons[$(quote idx)]!)
let identNames := binders.map Prod.fst
let fromJsons ← binders.mapIdxM fun idx (_, type) => mkFromJson idx type
let userNamesOpt ← if binders.size == userNames.size then
``(some #[$[$(userNames.map quote)],*])
else
``(none)
let stx ←
`((Json.parseTagged json $(quote ctor.getString!) $(quote ctorInfo.numFields) $(quote userNamesOpt)).bind
(fun jsons => do
$[let $identNames:ident ← $fromJsons:doExpr]*
return $(mkIdent ctor):ident $identNames*))
pure (stx, ctorInfo.numFields)
-- the smaller cases, especially the ones without fields are likely faster
let alts := alts.qsort (fun (_, x) (_, y) => x < y)
return alts.map Prod.fst
builtin_initialize
registerDerivingHandler ``ToJson mkToJsonInstanceHandler
registerDerivingHandler ``FromJson mkFromJsonInstanceHandler
end Lean.Elab.Deriving.FromToJson
|
2e0f9e91c23bd1e08f11bd8bab3aaadb28c317b7
|
5ffb8080b18aa71638631832811ab18c0aec5879
|
/src/subgroup/basic.lean
|
424d5d9b57bdbb6550f722ef26390815167300c2
|
[
"Apache-2.0"
] |
permissive
|
isabella232/group-theory-game
|
805ba8f473af58e3b0437121712dfc36f535b71a
|
152ec4a92ad67b6174a3d240c63fa56a6df6017e
|
refs/heads/master
| 1,679,206,314,315
| 1,611,521,951,000
| 1,611,521,951,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 12,349
|
lean
|
import group.basic group.powers finsum.basic
/-!
Basic definitions for subgroups in group theory.
Not for the mathematician beginner.
-/
-- We're always overwriting group theory here so we always work in
-- a namespace
namespace mygroup
open mygroup.group
/- subgroups (bundled) -/
/-- A subgroup of a group G is a subset containing 1
and closed under multiplication and inverse. -/
structure subgroup (G : Type) [group G] :=
(carrier : set G)
(one_mem' : (1 : G) ∈ carrier)
(mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier)
(inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier)
-- Defintion of normal subgroup (in a bundled form)
structure normal (G : Type) [group G] extends subgroup G :=
(conj_mem' : ∀ n, n ∈ carrier → ∀ g : G, g * n * g⁻¹ ∈ carrier)
-- we put dashes in all the names, because we'll define
-- non-dashed versions which don't mention `carrier` at all
-- and just talk about elements of the subgroup.
namespace subgroup
variables {G : Type} [group G] (H : subgroup G)
-- Instead let's define ∈ directly
instance : has_mem G (subgroup G) := ⟨λ m H, m ∈ H.carrier⟩
-- subgroups form a lattice and we might want to prove this
-- later on?
instance : has_le (subgroup G) := ⟨λ S T, S.carrier ⊆ T.carrier⟩
/-- Two subgroups are equal if the underlying subsets are equal. -/
theorem ext' {H K : subgroup G} (h : H.carrier = K.carrier) : H = K :=
by cases H; cases K; congr'
/-- Two subgroups are equal if they have the same elements. -/
theorem ext {H K : subgroup G}
(h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := ext' $ set.ext h
lemma mem_coe {g : G} : g ∈ H.carrier ↔ g ∈ H := iff.rfl
/-- Two subgroups are equal if and only if the underlying subsets are equal. -/
protected theorem ext'_iff {H K : subgroup G} :
H.carrier = K.carrier ↔ H = K :=
⟨ext', λ h, h ▸ rfl⟩
attribute [ext] subgroup.ext
/-- A subgroup contains the group's 1. -/
theorem one_mem : (1 : G) ∈ H := H.one_mem'
/-- A subgroup is closed under multiplication. -/
theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := subgroup.mul_mem' _
/-- A subgroup is closed under inverse -/
theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := subgroup.inv_mem' _
/-- A subgroup is closed under integer powers -/
theorem pow_mem {x : G} {n : ℤ} : x ∈ H → x ^ n ∈ H :=
begin
intro hx,
apply int.induction_on n,
{ rw group.pow_zero, exact H.one_mem },
{ intros i hi,
convert H.mul_mem hi hx,
rw [group.pow_add, group.pow_one] },
{ intros i hi,
convert H.mul_mem hi (H.inv_mem hx),
rw [← group.pow_neg_one_inv, ← group.pow_add ], congr' }
end
@[simp] theorem inv_mem_iff {x :G} : x⁻¹ ∈ H ↔ x ∈ H :=
⟨ λ hx, group.inv_inv x ▸ H.inv_mem hx, H.inv_mem ⟩
-- Coersion to group
-- Coercion from subgroup to underlying type
instance : has_coe (subgroup G) (set G) := ⟨subgroup.carrier⟩
lemma mem_coe' {g : G} : g ∈ (H : set G) ↔ g ∈ H := iff.rfl
instance of_subgroup (K : subgroup G) : group ↥K :=
{ mul := λ a b, ⟨a.1 * b.1, K.mul_mem' a.2 b.2⟩,
one := ⟨1, K.one_mem'⟩,
inv := λ a, ⟨a⁻¹, K.inv_mem' a.2⟩,
mul_assoc := λ a b c, by { cases a, cases b, cases c, refine subtype.ext _,
apply group.mul_assoc },
one_mul := λ a, by { cases a, apply subtype.ext, apply group.one_mul },
mul_left_inv := λ a, by { cases a, apply subtype.ext,
apply group.mul_left_inv } }
/-- Returns index of a subgroup in a group -/
noncomputable def index (H : subgroup G) : ℕ := fincard G / fincard H
/-- `index' H J` returns the index of J in H -/
noncomputable def index'(H : subgroup G) (J : subgroup G): ℕ := fincard H / fincard J
-- Defining cosets thats used in some lemmas
def lcoset (g : G) (K : subgroup G) := {s : G | ∃ k ∈ K, s = g * k}
def rcoset (g : G) (K : subgroup G) := {s : G | ∃ k ∈ K, s = k * g}
notation g ` ⋆ ` :70 H :70 := lcoset g H
notation H ` ⋆ ` :70 g :70 := rcoset g H
attribute [reducible] lcoset rcoset
@[simp] lemma coe_mul (a b : G) (ha : a ∈ H) (hb : b ∈ H) :
((⟨a, ha⟩ * ⟨b, hb⟩ : H) : G) = a * b := rfl
end subgroup
namespace normal
variables {G : Type} [group G]
instance : has_coe (normal G) (subgroup G) :=
⟨λ K, K.to_subgroup⟩
-- This saves me from writting m ∈ (K : subgroup G) every time
instance : has_mem G (normal G) := ⟨λ m K, m ∈ K.carrier⟩
instance to_set : has_coe (normal G) (set G) := ⟨λ K, K.carrier⟩
@[simp] lemma mem_to_subgroup {K : normal G} (x : G) :
x ∈ K.to_subgroup ↔ x ∈ K := iff.rfl
@[simp] lemma mem_carrier {K : normal G} (x : G) :
x ∈ K.carrier ↔ x ∈ K := iff.rfl
lemma conj_mem (N : normal G) (n : G) (hn : n ∈ N) (g : G) :
g * n * g⁻¹ ∈ N := N.conj_mem' n hn g
@[ext] lemma ext (A B : normal G) (h : ∀ g, g ∈ A ↔ g ∈ B) : A = B :=
begin
cases A with A, cases B with B, cases A with A, cases B with B,
suffices : A = B,
simp * at *,
ext x, exact h x
end
theorem ext' {H K : normal G} (h : H.to_subgroup = K.to_subgroup) : H = K :=
by cases H; cases K; congr'
instance of_normal (N : normal G) : group ↥N :=
subgroup.of_subgroup (N : subgroup G)
def of_subgroup (H : subgroup G)
(hH : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H) : normal G :=
{ conj_mem' := hH, .. H }
def of_comm_subgroup {G : Type} [comm_group G] (H : subgroup G) :
normal G :=
{ conj_mem' := λ _ _ _, by simpa [group.mul_comm, group.mul_assoc], .. H}
end normal
/-
An API for subgroups
Mathematician-friendly
Let G be a group. The type of subgroups of G is `subgroup G`.
In other words, if `H : subgroup G` then H is a subgroup of G.
The three basic facts you need to know about H are:
H.one_mem : (1 : G) ∈ H
H.mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H
H.inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H
-/
variables {G : Type} [group G]
namespace lagrange
variables {H : subgroup G}
lemma self_mem_coset (a : G) (H : subgroup G): a ∈ a ⋆ H :=
⟨1, H.one_mem, (group.mul_one a).symm⟩
/-- Two cosets `a ⋆ H`, `b ⋆ H` are equal if and only if `b⁻¹ * a ∈ H` -/
theorem lcoset_eq {a b : G} :
a ⋆ H = b ⋆ H ↔ b⁻¹ * a ∈ H :=
begin
split; intro h,
{ replace h : a ∈ b ⋆ H, rw ←h, exact self_mem_coset a H,
rcases h with ⟨g, hg₀, hg₁⟩,
rw hg₁, simp [←group.mul_assoc, hg₀] },
{ ext, split; intro hx,
{ rcases hx with ⟨g, hg₀, hg₁⟩, rw hg₁,
exact ⟨b⁻¹ * a * g, H.mul_mem h hg₀, by simp [←group.mul_assoc]⟩ },
{ rcases hx with ⟨g, hg₀, hg₁⟩, rw hg₁,
refine ⟨a⁻¹ * b * g, H.mul_mem _ hg₀, by simp [←group.mul_assoc]⟩,
convert H.inv_mem h, simp } }
end
-- A corollary of this is a ⋆ H = H iff a ∈ H
/-- The coset of `H`, `1 ⋆ H` equals `H` -/
theorem lcoset_of_one : 1 ⋆ H = H :=
begin
ext, split; intro hx,
{ rcases hx with ⟨h, hh₀, hh₁⟩,
rwa [hh₁, group.one_mul] },
{ exact ⟨x, hx, (group.one_mul x).symm⟩ }
end
/-- A left coset `a ⋆ H` equals `H` if and only if `a ∈ H` -/
theorem lcoset_of_mem {a : G} :
a ⋆ H = H ↔ a ∈ H := by rw [←lcoset_of_one, lcoset_eq]; simp
/-- Two left cosets `a ⋆ H` and `b ⋆ H` are equal if they are not disjoint -/
theorem lcoset_digj {a b c : G} (ha : c ∈ a ⋆ H) (hb : c ∈ b ⋆ H) :
a ⋆ H = b ⋆ H :=
begin
rcases ha with ⟨g₀, hg₀, hca⟩,
rcases hb with ⟨g₁, hg₁, hcb⟩,
rw lcoset_eq, rw (show a = c * g₀⁻¹, by simp [hca, group.mul_assoc]),
rw (show b⁻¹ = g₁ * c⁻¹,
by rw (show b = c * g₁⁻¹, by simp [hcb, group.mul_assoc]); simp),
suffices : g₁ * g₀⁻¹ ∈ H,
{ rw [group.mul_assoc, ←@group.mul_assoc _ _ c⁻¹],
simp [this] },
exact H.mul_mem hg₁ (H.inv_mem hg₀)
end
-- Now we would like to prove that all lcosets have the same order
open function
private def aux_map (a : G) (H : subgroup G) : H → a ⋆ H :=
λ h, ⟨a * h, h, h.2, rfl⟩
private lemma aux_map_biject {a : G} : bijective $ aux_map a H :=
begin
split,
{ intros x y hxy,
suffices : (x : G) = y,
{ ext, assumption },
{ simp [aux_map] at hxy, assumption } },
{ rintro ⟨y, y_prop⟩,
rcases y_prop with ⟨h, hh₀, hh₁⟩,
refine ⟨⟨h, hh₀⟩, by simp [aux_map, hh₁]⟩ }
end
/-- There is a bijection between `H` and its left cosets -/
noncomputable theorem lcoset_equiv {a : G} : H ≃ a ⋆ H :=
equiv.of_bijective (aux_map a H) aux_map_biject
-- We are going to use fincard which maps a fintype to its fintype.card
-- and maps to 0 otherwise
/-- The cardinality of `H` equals its left cosets-/
lemma eq_card_of_lcoset {a : G} : fincard H = fincard (a ⋆ H) :=
fincard.of_equiv lcoset_equiv
/-- The cardinality of all left cosets are equal -/
theorem card_of_lcoset_eq {a b : G} :
fincard (a ⋆ H) = fincard (b ⋆ H) := by iterate 2 { rw ←eq_card_of_lcoset }
-- The rest of the proof will requires quotient
end lagrange
namespace normal
lemma mem_normal {x} {N : normal G} :
x ∈ N ↔ ∃ (g : G) (n ∈ N), x = g * n * g⁻¹ :=
begin
split; intro h,
{ exact ⟨1, x, h, by simp⟩ },
{ rcases h with ⟨g, n, hn, rfl⟩,
exact conj_mem _ _ hn _ }
end
lemma mem_normal' {x} {N : normal G} :
x ∈ N ↔ ∃ (g : G) (n ∈ N), x = g⁻¹ * n * g :=
begin
rw mem_normal,
split; rintro ⟨g, n, hn, rfl⟩;
{ exact ⟨g⁻¹, n, hn, by simp⟩ }
end
-- Any two elements commute regarding the normal subgroup membership relation
lemma comm_mem_of_normal {K : normal G}
{g k : G} (h : g * k ∈ K) : k * g ∈ K :=
begin
suffices : k * (g * k) * k⁻¹ ∈ K,
{ simp [group.mul_assoc] at this, assumption },
refine normal.conj_mem _ _ h _
end
def normal_of_mem_comm {K : subgroup G}
(h : ∀ g k : G, g * k ∈ K → k * g ∈ K) : normal G :=
{ conj_mem' :=
begin
intros n hn g,
suffices : g * (n * g⁻¹) ∈ K,
{ rwa ←group.mul_assoc at this },
refine h _ _ _, simpa [group.mul_assoc]
end, .. K } -- The .. tells Lean that we use K for the unfilled fields
-- If K is a normal subgroup of the group G, then the sets of left and right
-- cosets of K in the G coincide
lemma nomal_coset_eq {K : normal G} :
∀ g : G, g ⋆ (K : subgroup G) = (K : subgroup G) ⋆ g :=
begin
-- dsimp,
-- Without the dsimp it displays weridly,
-- dsimp not required if we write out right_coset g K however?
intros g,
ext, split; intro hx,
{ rcases hx with ⟨k, hk, rfl⟩,
refine ⟨_, K.2 k hk g, _⟩,
simp [group.mul_assoc] },
{ rcases hx with ⟨k, hk, rfl⟩,
refine ⟨_, K.2 k hk g⁻¹, _⟩,
simp [←group.mul_assoc] }
end
def normal_of_coset_eq {K : subgroup G}
(h : ∀ g : G, g ⋆ K = K ⋆ g) : normal G :=
{ conj_mem' :=
begin
intros n hn g,
have : ∃ s ∈ K ⋆ g, s = g * n,
{ refine ⟨g * n, _, rfl⟩,
rw ←h, exact ⟨n, hn, rfl⟩ },
rcases this with ⟨s, ⟨l, hl₁, hl₂⟩, hs₂⟩,
rw [←hs₂, hl₂],
simpa [group.mul_assoc]
end, .. K}
-- If K is normal then if x ∈ g K and y ∈ h K then x * y ∈ (g * h) K
lemma prod_in_coset_of_normal {K : normal G} {x y g h : G}
(hx : x ∈ g ⋆ K) (hy : y ∈ h ⋆ K) : x * y ∈ (g * h) ⋆ K :=
begin
rcases hx with ⟨k₀, hx₁, rfl⟩,
rcases hy with ⟨k₁, hy₁, rfl⟩,
refine ⟨h⁻¹ * k₀ * h * k₁, _, _⟩,
{ refine K.1.3 _ hy₁,
convert K.2 _ hx₁ _, exact (group.inv_inv _).symm },
{ iterate 2 { rw group.mul_assoc },
rw group.mul_left_cancel_iff g _ _,
simp [←group.mul_assoc] }
end
def normal_of_prod_in_coset {K : subgroup G}
(h : ∀ x y g h : G, x ∈ g ⋆ K → y ∈ h ⋆ K → x * y ∈ (g * h) ⋆ K) : normal G :=
{ conj_mem' :=
begin
intros n hn g,
rcases h (g * n) (g⁻¹ * n) g g⁻¹
⟨n, hn, rfl⟩ ⟨n, hn, rfl⟩ with ⟨m, hm₀, hm₁⟩,
rw [←group.mul_right_cancel_iff n⁻¹,
group.mul_assoc, group.mul_assoc, group.mul_assoc] at hm₁,
suffices : g * n * g⁻¹ = m * n⁻¹,
rw this, exact K.mul_mem hm₀ (K.inv_mem hn),
simp [←group.mul_assoc] at hm₁; assumption
end, .. K }
end normal
end mygroup
|
1ba06081b6dc7cc5db747b722520691cf554d189
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/linear_algebra/pi_tensor_product.lean
|
11fbb0d2578f3538b0e7bce49403cbfb5f6ca83e
|
[
"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
| 25,038
|
lean
|
/-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Eric Wieser
-/
import group_theory.congruence
import linear_algebra.multilinear.tensor_product
/-!
# Tensor product of an indexed family of modules over commutative semirings
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative
semirings. We denote this space by `⨂[R] i, s i` and define it as `free_add_monoid (R × Π i, s i)`
quotiented by the appropriate equivalence relation. The treatment follows very closely that of the
binary tensor product in `linear_algebra/tensor_product.lean`.
## Main definitions
* `pi_tensor_product R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product
of all the `s i`'s. This is denoted by `⨂[R] i, s i`.
* `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`.
This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`.
* `lift_add_hom` constructs an `add_monoid_hom` from `(⨂[R] i, s i)` to some space `F` from a
function `φ : (R × Π i, s i) → F` with the appropriate properties.
* `lift φ` with `φ : multilinear_map R s E` is the corresponding linear map
`(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence.
* `pi_tensor_product.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`.
* `pi_tensor_product.tmul_equiv` equivalence between a `tensor_product` of `pi_tensor_product`s and
a single `pi_tensor_product`.
## Notations
* `⨂[R] i, s i` is defined as localized notation in locale `tensor_product`
* `⨂ₜ[R] i, f i` with `f : Π i, f i` is defined globally as the tensor product of all the `f i`'s.
## Implementation notes
* We define it via `free_add_monoid (R × Π i, s i)` with the `R` representing a "hidden" tensor
factor, rather than `free_add_monoid (Π i, s i)` to ensure that, if `ι` is an empty type,
the space is isomorphic to the base ring `R`.
* We have not restricted the index type `ι` to be a `fintype`, as nothing we do here strictly
requires it. However, problems may arise in the case where `ι` is infinite; use at your own
caution.
* Instead of requiring `decidable_eq ι` as an argument to `pi_tensor_product` itself, we include it
as an argument in the constructors of the relation. A decidability isntance still has to come
from somewhere due to the use of `function.update`, but this hides it from the downstream user.
See the implementation notes for `multilinear_map` for an extended discussion of this choice.
## TODO
* Define tensor powers, symmetric subspace, etc.
* API for the various ways `ι` can be split into subsets; connect this with the binary
tensor product.
* Include connection with holors.
* Port more of the API from the binary tensor product over to this case.
## Tags
multilinear, tensor, tensor product
-/
open function
section semiring
variables {ι ι₂ ι₃ : Type*}
variables {R : Type*} [comm_semiring R]
variables {R₁ R₂ : Type*}
variables {s : ι → Type*} [∀ i, add_comm_monoid (s i)] [∀ i, module R (s i)]
variables {M : Type*} [add_comm_monoid M] [module R M]
variables {E : Type*} [add_comm_monoid E] [module R E]
variables {F : Type*} [add_comm_monoid F]
namespace pi_tensor_product
include R
variables (R) (s)
/-- The relation on `free_add_monoid (R × Π i, s i)` that generates a congruence whose quotient is
the tensor product. -/
inductive eqv : free_add_monoid (R × Π i, s i) → free_add_monoid (R × Π i, s i) → Prop
| of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (hf : f i = 0), eqv (free_add_monoid.of (r, f)) 0
| of_zero_scalar : ∀ (f : Π i, s i), eqv (free_add_monoid.of (0, f)) 0
| of_add : ∀ (inst : decidable_eq ι) (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i), eqv
(free_add_monoid.of (r, update f i m₁) + free_add_monoid.of (r, update f i m₂))
(free_add_monoid.of (r, update f i (m₁ + m₂)))
| of_add_scalar : ∀ (r r' : R) (f : Π i, s i), eqv
(free_add_monoid.of (r, f) + free_add_monoid.of (r', f))
(free_add_monoid.of (r + r', f))
| of_smul : ∀ (inst : decidable_eq ι) (r : R) (f : Π i, s i) (i : ι) (r' : R), eqv
(free_add_monoid.of (r, update f i (r' • (f i))))
(free_add_monoid.of (r' * r, f))
| add_comm : ∀ x y, eqv (x + y) (y + x)
end pi_tensor_product
variables (R) (s)
/-- `pi_tensor_product R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor
product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/
def pi_tensor_product : Type* :=
(add_con_gen (pi_tensor_product.eqv R s)).quotient
variables {R}
/- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product, given `s : ι → Type*`. -/
localized "notation (name := pi_tensor_product)
`⨂[`:100 R `] ` binders `, ` r:(scoped:67 f, pi_tensor_product R f) := r" in tensor_product
open_locale tensor_product
namespace pi_tensor_product
section module
instance : add_comm_monoid (⨂[R] i, s i) :=
{ add_comm := λ x y, add_con.induction_on₂ x y $ λ x y, quotient.sound' $
add_con_gen.rel.of _ _ $ eqv.add_comm _ _,
.. (add_con_gen (pi_tensor_product.eqv R s)).add_monoid }
instance : inhabited (⨂[R] i, s i) := ⟨0⟩
variables (R) {s}
/-- `tprod_coeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i`
over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary
definition for this file alone, and that one should use `tprod` defined below for most purposes. -/
def tprod_coeff (r : R) (f : Π i, s i) : ⨂[R] i, s i := add_con.mk' _ $ free_add_monoid.of (r, f)
variables {R}
lemma zero_tprod_coeff (f : Π i, s i) : tprod_coeff R 0 f = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero_scalar _
lemma zero_tprod_coeff' (z : R) (f : Π i, s i) (i : ι) (hf: f i = 0) : tprod_coeff R z f = 0 :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_zero _ _ i hf
lemma add_tprod_coeff [decidable_eq ι] (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) :
tprod_coeff R z (update f i m₁) + tprod_coeff R z (update f i m₂) =
tprod_coeff R z (update f i (m₁ + m₂)) :=
quotient.sound' $ add_con_gen.rel.of _ _ (eqv.of_add _ z f i m₁ m₂)
lemma add_tprod_coeff' (z₁ z₂ : R) (f : Π i, s i) :
tprod_coeff R z₁ f + tprod_coeff R z₂ f = tprod_coeff R (z₁ + z₂) f :=
quotient.sound' $ add_con_gen.rel.of _ _ (eqv.of_add_scalar z₁ z₂ f)
lemma smul_tprod_coeff_aux [decidable_eq ι] (z : R) (f : Π i, s i) (i : ι) (r : R) :
tprod_coeff R z (update f i (r • f i)) = tprod_coeff R (r * z) f :=
quotient.sound' $ add_con_gen.rel.of _ _ $ eqv.of_smul _ _ _ _ _
lemma smul_tprod_coeff [decidable_eq ι] (z : R) (f : Π i, s i) (i : ι) (r : R₁)
[has_smul R₁ R] [is_scalar_tower R₁ R R] [has_smul R₁ (s i)] [is_scalar_tower R₁ R (s i)] :
tprod_coeff R z (update f i (r • f i)) = tprod_coeff R (r • z) f :=
begin
have h₁ : r • z = (r • (1 : R)) * z := by rw [smul_mul_assoc, one_mul],
have h₂ : r • (f i) = (r • (1 : R)) • f i := (smul_one_smul _ _ _).symm,
rw [h₁, h₂],
exact smul_tprod_coeff_aux z f i _,
end
/-- Construct an `add_monoid_hom` from `(⨂[R] i, s i)` to some space `F` from a function
`φ : (R × Π i, s i) → F` with the appropriate properties. -/
def lift_add_hom (φ : (R × Π i, s i) → F)
(C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (hf : f i = 0), φ (r, f) = 0)
(C0' : ∀ (f : Π i, s i), φ (0, f) = 0)
(C_add : ∀ [decidable_eq ι] (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i), by exactI
φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂)))
(C_add_scalar : ∀ (r r' : R) (f : Π i, s i),
φ (r , f) + φ (r', f) = φ (r + r', f))
(C_smul : ∀ [decidable_eq ι] (r : R) (f : Π i, s i) (i : ι) (r' : R), by exactI
φ (r, update f i (r' • (f i))) = φ (r' * r, f))
: (⨂[R] i, s i) →+ F :=
(add_con_gen (pi_tensor_product.eqv R s)).lift (free_add_monoid.lift φ) $ add_con.add_con_gen_le $
λ x y hxy, match x, y, hxy with
| _, _, (eqv.of_zero r' f i hf) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C0 r' f i hf]
| _, _, (eqv.of_zero_scalar f) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C0']
| _, _, (eqv.of_add inst z f i m₁ m₂) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, @C_add inst]
| _, _, (eqv.of_add_scalar z₁ z₂ f) := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, C_add_scalar]
| _, _, (eqv.of_smul inst z f i r') := (add_con.ker_rel _).2 $
by simp [free_add_monoid.lift_eval_of, @C_smul inst]
| _, _, (eqv.add_comm x y) := (add_con.ker_rel _).2 $
by simp_rw [add_monoid_hom.map_add, add_comm]
end
@[elab_as_eliminator]
protected theorem induction_on'
{C : (⨂[R] i, s i) → Prop}
(z : ⨂[R] i, s i)
(C1 : ∀ {r : R} {f : Π i, s i}, C (tprod_coeff R r f))
(Cp : ∀ {x y}, C x → C y → C (x + y)) : C z :=
begin
have C0 : C 0,
{ have h₁ := @C1 0 0,
rwa [zero_tprod_coeff] at h₁ },
refine add_con.induction_on z (λ x, free_add_monoid.rec_on x C0 _),
simp_rw add_con.coe_add,
refine λ f y ih, Cp _ ih,
convert @C1 f.1 f.2,
simp only [prod.mk.eta],
end
section distrib_mul_action
variables [monoid R₁] [distrib_mul_action R₁ R] [smul_comm_class R₁ R R]
variables [monoid R₂] [distrib_mul_action R₂ R] [smul_comm_class R₂ R R]
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance has_smul' : has_smul R₁ (⨂[R] i, s i) :=
⟨λ r, lift_add_hom (λ f : R × Π i, s i, tprod_coeff R (r • f.1) f.2)
(λ r' f i hf, by simp_rw [zero_tprod_coeff' _ f i hf])
(λ f, by simp [zero_tprod_coeff])
(λ r' f i m₁ m₂, by simp [add_tprod_coeff])
(λ r' r'' f, by simp [add_tprod_coeff', mul_add])
(λ z f i r', by simp [smul_tprod_coeff, mul_smul_comm])⟩
instance : has_smul R (⨂[R] i, s i) := pi_tensor_product.has_smul'
lemma smul_tprod_coeff' (r : R₁) (z : R) (f : Π i, s i) :
r • (tprod_coeff R z f) = tprod_coeff R (r • z) f := rfl
protected theorem smul_add (r : R₁) (x y : ⨂[R] i, s i) :
r • (x + y) = r • x + r • y :=
add_monoid_hom.map_add _ _ _
instance distrib_mul_action' : distrib_mul_action R₁ (⨂[R] i, s i) :=
{ smul := (•),
smul_add := λ r x y, add_monoid_hom.map_add _ _ _,
mul_smul := λ r r' x, pi_tensor_product.induction_on' x
(λ r'' f, by simp [smul_tprod_coeff', smul_smul])
(λ x y ihx ihy, by simp_rw [pi_tensor_product.smul_add, ihx, ihy]),
one_smul := λ x, pi_tensor_product.induction_on' x
(λ f, by simp [smul_tprod_coeff' _ _])
(λ z y ihz ihy, by simp_rw [pi_tensor_product.smul_add, ihz, ihy]),
smul_zero := λ r, add_monoid_hom.map_zero _ }
instance smul_comm_class' [smul_comm_class R₁ R₂ R] : smul_comm_class R₁ R₂ (⨂[R] i, s i) :=
⟨λ r' r'' x, pi_tensor_product.induction_on' x
(λ xr xf, by simp only [smul_tprod_coeff', smul_comm])
(λ z y ihz ihy, by simp_rw [pi_tensor_product.smul_add, ihz, ihy])⟩
instance is_scalar_tower' [has_smul R₁ R₂] [is_scalar_tower R₁ R₂ R] :
is_scalar_tower R₁ R₂ (⨂[R] i, s i) :=
⟨λ r' r'' x, pi_tensor_product.induction_on' x
(λ xr xf, by simp only [smul_tprod_coeff', smul_assoc])
(λ z y ihz ihy, by simp_rw [pi_tensor_product.smul_add, ihz, ihy])⟩
end distrib_mul_action
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance module' [semiring R₁] [module R₁ R] [smul_comm_class R₁ R R] : module R₁ (⨂[R] i, s i) :=
{ smul := (•),
add_smul := λ r r' x, pi_tensor_product.induction_on' x
(λ r f, by simp [smul_tprod_coeff' _ _, add_smul, add_tprod_coeff'])
(λ x y ihx ihy, by simp [pi_tensor_product.smul_add, ihx, ihy, add_add_add_comm]),
zero_smul := λ x, pi_tensor_product.induction_on' x
(λ r f, by { simp_rw [smul_tprod_coeff' _ _, zero_smul], exact zero_tprod_coeff _ })
(λ x y ihx ihy, by rw [pi_tensor_product.smul_add, ihx, ihy, add_zero]),
..pi_tensor_product.distrib_mul_action' }
-- shortcut instances
instance : module R (⨂[R] i, s i) := pi_tensor_product.module'
instance : smul_comm_class R R (⨂[R] i, s i) := pi_tensor_product.smul_comm_class'
instance : is_scalar_tower R R (⨂[R] i, s i) := pi_tensor_product.is_scalar_tower'
variables {R}
variables (R)
/-- The canonical `multilinear_map R s (⨂[R] i, s i)`. -/
def tprod : multilinear_map R s (⨂[R] i, s i) :=
{ to_fun := tprod_coeff R 1,
map_add' := λ _ f i x y, by exactI (add_tprod_coeff (1 : R) f i x y).symm,
map_smul' := λ _ f i r x, by
resetI; simp_rw [smul_tprod_coeff', ←smul_tprod_coeff (1 : R) _ i, update_idem, update_same] }
variables {R}
notation `⨂ₜ[`:100 R`] ` binders `, ` r:(scoped:67 f, tprod R f) := r
@[simp]
lemma tprod_coeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprod_coeff R z f = z • tprod R f :=
begin
have : z = z • (1 : R) := by simp only [mul_one, algebra.id.smul_eq_mul],
conv_lhs { rw this },
rw ←smul_tprod_coeff',
refl,
end
@[elab_as_eliminator]
protected theorem induction_on
{C : (⨂[R] i, s i) → Prop}
(z : ⨂[R] i, s i)
(C1 : ∀ {r : R} {f : Π i, s i}, C (r • (tprod R f)))
(Cp : ∀ {x y}, C x → C y → C (x + y)) : C z :=
begin
simp_rw ←tprod_coeff_eq_smul_tprod at C1,
exact pi_tensor_product.induction_on' z @C1 @Cp,
end
@[ext]
theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E}
(H : φ₁.comp_multilinear_map (tprod R) = φ₂.comp_multilinear_map (tprod R)) : φ₁ = φ₂ :=
begin
refine linear_map.ext _,
refine λ z,
(pi_tensor_product.induction_on' z _ (λ x y hx hy, by rw [φ₁.map_add, φ₂.map_add, hx, hy])),
{ intros r f,
rw [tprod_coeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul],
apply _root_.congr_arg,
exact multilinear_map.congr_fun H f }
end
end module
section multilinear
open multilinear_map
variables {s}
/-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a
`multilinear map R s E` with the property that its composition with the canonical
`multilinear_map R s (⨂[R] i, s i)` is the given multilinear map. -/
def lift_aux (φ : multilinear_map R s E) : (⨂[R] i, s i) →+ E :=
lift_add_hom (λ (p : R × Π i, s i), p.1 • (φ p.2))
(λ z f i hf, by rw [map_coord_zero φ i hf, smul_zero])
(λ f, by rw [zero_smul])
(λ _ z f i m₁ m₂, by { resetI, rw [←smul_add, φ.map_add] })
(λ z₁ z₂ f, by rw [←add_smul])
(λ _ z f i r, by { resetI, simp [φ.map_smul, smul_smul, mul_comm] })
lemma lift_aux_tprod (φ : multilinear_map R s E) (f : Π i, s i) : lift_aux φ (tprod R f) = φ f :=
by simp only [lift_aux, lift_add_hom, tprod, multilinear_map.coe_mk, tprod_coeff,
free_add_monoid.lift_eval_of, one_smul, add_con.lift_mk']
lemma lift_aux_tprod_coeff (φ : multilinear_map R s E) (z : R) (f : Π i, s i) :
lift_aux φ (tprod_coeff R z f) = z • φ f :=
by simp [lift_aux, lift_add_hom, tprod_coeff, free_add_monoid.lift_eval_of]
lemma lift_aux.smul {φ : multilinear_map R s E} (r : R) (x : ⨂[R] i, s i) :
lift_aux φ (r • x) = r • lift_aux φ x :=
begin
refine pi_tensor_product.induction_on' x _ _,
{ intros z f,
rw [smul_tprod_coeff' r z f, lift_aux_tprod_coeff, lift_aux_tprod_coeff, smul_assoc] },
{ intros z y ihz ihy,
rw [smul_add, (lift_aux φ).map_add, ihz, ihy, (lift_aux φ).map_add, smul_add] }
end
/-- Constructing a linear map `(⨂[R] i, s i) → E` given a `multilinear_map R s E` with the
property that its composition with the canonical `multilinear_map R s E` is
the given multilinear map `φ`. -/
def lift : (multilinear_map R s E) ≃ₗ[R] ((⨂[R] i, s i) →ₗ[R] E) :=
{ to_fun := λ φ, { map_smul' := lift_aux.smul, .. lift_aux φ },
inv_fun := λ φ', φ'.comp_multilinear_map (tprod R),
left_inv := λ φ, by { ext, simp [lift_aux_tprod, linear_map.comp_multilinear_map] },
right_inv := λ φ, by { ext, simp [lift_aux_tprod] },
map_add' := λ φ₁ φ₂, by { ext, simp [lift_aux_tprod] },
map_smul' := λ r φ₂, by { ext, simp [lift_aux_tprod] } }
variables {φ : multilinear_map R s E}
@[simp] lemma lift.tprod (f : Π i, s i) : lift φ (tprod R f) = φ f := lift_aux_tprod φ f
theorem lift.unique' {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : φ'.comp_multilinear_map (tprod R) = φ) :
φ' = lift φ :=
ext $ H.symm ▸ (lift.symm_apply_apply φ).symm
theorem lift.unique {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : ∀ f, φ' (tprod R f) = φ f) :
φ' = lift φ :=
lift.unique' (multilinear_map.ext H)
@[simp]
theorem lift_symm (φ' : (⨂[R] i, s i) →ₗ[R] E) : lift.symm φ' = φ'.comp_multilinear_map (tprod R) :=
rfl
@[simp]
theorem lift_tprod : lift (tprod R : multilinear_map R s _) = linear_map.id :=
eq.symm $ lift.unique' rfl
section
variables (R M)
/-- Re-index the components of the tensor power by `e`.
For simplicity, this is defined only for homogeneously- (rather than dependently-) typed components.
-/
def reindex (e : ι ≃ ι₂) : ⨂[R] i : ι, M ≃ₗ[R] ⨂[R] i : ι₂, M :=
linear_equiv.of_linear
(lift (dom_dom_congr e.symm (tprod R : multilinear_map R _ (⨂[R] i : ι₂, M))))
(lift (dom_dom_congr e (tprod R : multilinear_map R _ (⨂[R] i : ι, M))))
(by { ext, simp only [linear_map.comp_apply, linear_map.id_apply, lift_tprod,
linear_map.comp_multilinear_map_apply, lift.tprod,
dom_dom_congr_apply, equiv.apply_symm_apply] })
(by { ext, simp only [linear_map.comp_apply, linear_map.id_apply, lift_tprod,
linear_map.comp_multilinear_map_apply, lift.tprod,
dom_dom_congr_apply, equiv.symm_apply_apply] })
end
@[simp] lemma reindex_tprod (e : ι ≃ ι₂) (f : Π i, M) :
reindex R M e (tprod R f) = tprod R (λ i, f (e.symm i)) :=
lift_aux_tprod _ f
@[simp] lemma reindex_comp_tprod (e : ι ≃ ι₂) :
(reindex R M e : ⨂[R] i : ι, M →ₗ[R] ⨂[R] i : ι₂, M).comp_multilinear_map (tprod R) =
(tprod R : multilinear_map R (λ i, M) _).dom_dom_congr e.symm :=
multilinear_map.ext $ reindex_tprod e
@[simp] lemma lift_comp_reindex (e : ι ≃ ι₂) (φ : multilinear_map R (λ _ : ι₂, M) E) :
(lift φ) ∘ₗ ↑(reindex R M e) = lift (φ.dom_dom_congr e.symm) :=
by { ext, simp, }
@[simp]
lemma lift_reindex (e : ι ≃ ι₂) (φ : multilinear_map R (λ _, M) E) (x : ⨂[R] i, M) :
lift φ (reindex R M e x) = lift (φ.dom_dom_congr e.symm) x :=
linear_map.congr_fun (lift_comp_reindex e φ) x
@[simp] lemma reindex_trans (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) :
(reindex R M e).trans (reindex R M e') = reindex R M (e.trans e') :=
begin
apply linear_equiv.to_linear_map_injective,
ext f,
simp only [linear_equiv.trans_apply, linear_equiv.coe_coe, reindex_tprod,
linear_map.coe_comp_multilinear_map, function.comp_app, multilinear_map.dom_dom_congr_apply,
reindex_comp_tprod],
congr,
end
@[simp] lemma reindex_reindex (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) (x : ⨂[R] i, M) :
reindex R M e' (reindex R M e x) = reindex R M (e.trans e') x :=
linear_equiv.congr_fun (reindex_trans e e' : _ = reindex R M (e.trans e')) x
@[simp] lemma reindex_symm (e : ι ≃ ι₂) :
(reindex R M e).symm = reindex R M e.symm := rfl
@[simp] lemma reindex_refl : reindex R M (equiv.refl ι) = linear_equiv.refl R _ :=
begin
apply linear_equiv.to_linear_map_injective,
ext1,
rw [reindex_comp_tprod, linear_equiv.refl_to_linear_map, equiv.refl_symm],
refl,
end
variables (ι)
/-- The tensor product over an empty index type `ι` is isomorphic to the base ring. -/
@[simps symm_apply]
def is_empty_equiv [is_empty ι] : ⨂[R] i : ι, M ≃ₗ[R] R :=
{ to_fun := lift (const_of_is_empty R _ 1),
inv_fun := λ r, r • tprod R (@is_empty_elim _ _ _),
left_inv := λ x, by
{ apply x.induction_on,
{ intros r f,
have := subsingleton.elim f is_empty_elim,
simp [this], },
{ simp only,
intros x y hx hy,
simp [add_smul, hx, hy] }},
right_inv := λ t, by simp only [mul_one, algebra.id.smul_eq_mul, const_of_is_empty_apply,
linear_map.map_smul, pi_tensor_product.lift.tprod],
map_add' := linear_map.map_add _,
map_smul' := linear_map.map_smul _, }
@[simp]
lemma is_empty_equiv_apply_tprod [is_empty ι] (f : ι → M) : is_empty_equiv ι (tprod R f) = 1 :=
lift.tprod _
variables {ι}
/-- The tensor product over an single index is isomorphic to the module -/
@[simps symm_apply]
def subsingleton_equiv [subsingleton ι] (i₀ : ι) : ⨂[R] i : ι, M ≃ₗ[R] M :=
{ to_fun := lift (multilinear_map.of_subsingleton R M i₀),
inv_fun := λ m, tprod R (λ v, m),
left_inv := λ x, by
{ dsimp only,
have : ∀ (f : ι → M) (z : M), (λ i : ι, z) = update f i₀ z,
{ intros f z,
ext i,
rw [subsingleton.elim i i₀, function.update_same] },
apply x.induction_on,
{ intros r f,
simp only [linear_map.map_smul, lift.tprod, of_subsingleton_apply, function.eval,
this f, multilinear_map.map_smul, update_eq_self], },
{ intros x y hx hy,
simp only [multilinear_map.map_add, this 0 (_ + _), linear_map.map_add, ←this 0 (lift _ _),
hx, hy] } },
right_inv := λ t, by simp only [of_subsingleton_apply, lift.tprod, function.eval_apply],
map_add' := linear_map.map_add _,
map_smul' := linear_map.map_smul _, }
@[simp]
lemma subsingleton_equiv_apply_tprod [subsingleton ι] (i : ι) (f : ι → M) :
subsingleton_equiv i (tprod R f) = f i :=
lift.tprod _
section tmul
/-- Collapse a `tensor_product` of `pi_tensor_product`s. -/
private def tmul : (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) →ₗ[R] ⨂[R] i : ι ⊕ ι₂, M :=
tensor_product.lift
{ to_fun := λ a, pi_tensor_product.lift $ pi_tensor_product.lift
(multilinear_map.curry_sum_equiv R _ _ M _ (tprod R)) a,
map_add' := λ a b, by simp only [linear_equiv.map_add, linear_map.map_add],
map_smul' := λ r a, by simp only [linear_equiv.map_smul, linear_map.map_smul,
ring_hom.id_apply], }
private lemma tmul_apply (a : ι → M) (b : ι₂ → M) :
tmul ((⨂ₜ[R] i, a i) ⊗ₜ[R] (⨂ₜ[R] i, b i)) = ⨂ₜ[R] i, sum.elim a b i :=
begin
erw [tensor_product.lift.tmul, pi_tensor_product.lift.tprod, pi_tensor_product.lift.tprod],
refl
end
/-- Expand `pi_tensor_product` into a `tensor_product` of two factors. -/
private def tmul_symm : ⨂[R] i : ι ⊕ ι₂, M →ₗ[R] (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) :=
-- by using tactic mode, we avoid the need for a lot of `@`s and `_`s
pi_tensor_product.lift $ by apply multilinear_map.dom_coprod; [exact tprod R, exact tprod R]
private lemma tmul_symm_apply (a : ι ⊕ ι₂ → M) :
tmul_symm (⨂ₜ[R] i, a i) = (⨂ₜ[R] i, a (sum.inl i)) ⊗ₜ[R] (⨂ₜ[R] i, a (sum.inr i)) :=
pi_tensor_product.lift.tprod _
variables (R M)
local attribute [ext] tensor_product.ext
/-- Equivalence between a `tensor_product` of `pi_tensor_product`s and a single
`pi_tensor_product` indexed by a `sum` type.
For simplicity, this is defined only for homogeneously- (rather than dependently-) typed components.
-/
def tmul_equiv : (⨂[R] i : ι, M) ⊗[R] (⨂[R] i : ι₂, M) ≃ₗ[R] ⨂[R] i : ι ⊕ ι₂, M :=
linear_equiv.of_linear tmul tmul_symm
(by { ext x,
show tmul (tmul_symm (tprod R x)) = tprod R x, -- Speed up the call to `simp`.
simp only [tmul_symm_apply, tmul_apply, sum.elim_comp_inl_inr], })
(by { ext x y,
show tmul_symm (tmul (tprod R x ⊗ₜ[R] tprod R y)) = tprod R x ⊗ₜ[R] tprod R y,
simp only [tmul_apply, tmul_symm_apply, sum.elim_inl, sum.elim_inr], })
@[simp] lemma tmul_equiv_apply (a : ι → M) (b : ι₂ → M) :
tmul_equiv R M ((⨂ₜ[R] i, a i) ⊗ₜ[R] (⨂ₜ[R] i, b i)) = ⨂ₜ[R] i, sum.elim a b i :=
tmul_apply a b
@[simp] lemma tmul_equiv_symm_apply (a : ι ⊕ ι₂ → M) :
(tmul_equiv R M).symm (⨂ₜ[R] i, a i) = (⨂ₜ[R] i, a (sum.inl i)) ⊗ₜ[R] (⨂ₜ[R] i, a (sum.inr i)) :=
tmul_symm_apply a
end tmul
end multilinear
end pi_tensor_product
end semiring
section ring
namespace pi_tensor_product
open pi_tensor_product
open_locale tensor_product
variables {ι : Type*} {R : Type*} [comm_ring R]
variables {s : ι → Type*} [∀ i, add_comm_group (s i)] [∀ i, module R (s i)]
/- Unlike for the binary tensor product, we require `R` to be a `comm_ring` here, otherwise
this is false in the case where `ι` is empty. -/
instance : add_comm_group (⨂[R] i, s i) := module.add_comm_monoid_to_add_comm_group R
end pi_tensor_product
end ring
|
541ede22d1df47f760edd91ae05762e782626367
|
8c95816d6379a6864848d68ce735a5700c1cbbc3
|
/src/smt2/lol.lean
|
a3678e075bcc3144a29e84600fa012d8012d5da9
|
[
"Apache-2.0"
] |
permissive
|
aqjune/smt2_interface
|
f00ed0a4317d7c9112deb0806c8e89e6512a901e
|
598848a7a6fa47520fadcfe1b16891053a296084
|
refs/heads/master
| 1,631,518,664,718
| 1,524,489,340,000
| 1,524,489,340,000
| 115,204,811
| 0
| 0
| null | 1,514,043,428,000
| 1,514,043,427,000
| null |
UTF-8
|
Lean
| false
| false
| 13,138
|
lean
|
import smt2.syntax
import smt2.builder
open native
namespace lol
structure refinement (T : Type) :=
(refinment : T → T)
mutual inductive type, term
with type : Type
| bool : type
| int : type
| var : string → type
| fn : list type → type → type
| refinement : type → (string → term) → type
with term : Type
-- TODO: eventually allow for term in head position, and generalize in trans
-- TODO: stratify this so that Prop > Ordering > Arith
| apply : string → list term → term
| true : term
| false : term
| var : string → term
| not : term → term
| equals : term → term → term
| and : term → term → term
| or : term → term → term
| iff : term → term → term
| implies : term → term → term
| add : term → term → term
| sub : term → term → term
| mul : term → term → term
| div : term → term → term
| mod : term → term → term
| lt : term → term → term
| lte : term → term → term
| gt : term → term → term
| gte : term → term → term
| neg : term → term
| int : int → term
| forallq : string → type → term → term
meta def term.subst (n : string) (subst : term) : term → term
| (term.apply f args) := term.apply f (list.map term.subst args)
| term.true := term.true
| term.false := term.false
| (term.var s) :=
if s = n
then subst
else term.var s
| (term.not t) := term.subst t
| (term.equals t u) :=
term.equals (term.subst t) (term.subst u)
| (term.and t u) :=
term.and (term.subst t) (term.subst u)
| (term.or t u) :=
term.or (term.subst t) (term.subst u)
| (term.iff t u) :=
term.iff (term.subst t) (term.subst u)
| (term.implies t u) :=
term.implies (term.subst t) (term.subst u)
| (term.add t u) :=
term.add (term.subst t) (term.subst u)
| (term.sub t u) :=
term.sub (term.subst t) (term.subst u)
| (term.mul t u) :=
term.mul (term.subst t) (term.subst u)
| (term.div t u) :=
term.div (term.subst t) (term.subst u)
| (term.mod t u) :=
term.mod (term.subst t) (term.subst u)
| (term.lt t u) :=
term.lt (term.subst t) (term.subst u)
| (term.lte t u) :=
term.lte (term.subst t) (term.subst u)
| (term.gt t u) :=
term.gt (term.subst t) (term.subst u)
| (term.gte t u) :=
term.gte (term.subst t) (term.subst u)
| (term.neg t) :=
term.neg (term.subst t)
| (term.int i) := term.int i
| (term.forallq n ty body) := term.forallq n ty body
-- term.forallq (term.subst t) (term.subst u)
-- meta def term.ordering_nat : term → nat
-- | term.true := 1
-- | term.false := 2
-- | (term.apply f args) := 1 + f.length + list.foldl (+) 0 (list.map term.ordering_nat args)
-- | (term.var s) :=
-- if s = n
-- then subst
-- else term.var s
-- | (term.not t) := term.subst t
-- | (term.equals t u) :=
-- term.equals (term.subst t) (term.subst u)
-- | (term.and t u) :=
-- term.and (term.subst t) (term.subst u)
-- | (term.or t u) :=
-- term.or (term.subst t) (term.subst u)
-- | (term.iff t u) :=
-- term.iff (term.subst t) (term.subst u)
-- | (term.implies t u) :=
-- term.implies (term.subst t) (term.subst u)
-- | (term.add t u) :=
-- term.add (term.subst t) (term.subst u)
-- | (term.sub t u) :=
-- term.sub (term.subst t) (term.subst u)
-- | (term.mul t u) :=
-- term.mul (term.subst t) (term.subst u)
-- | (term.div t u) :=
-- term.div (term.subst t) (term.subst u)
-- | (term.add t u) :=
-- term.add (term.subst t) (term.subst u)
-- | (term.sub t u) :=
-- term.sub (term.subst t) (term.subst u)
-- | (term.mul t u) :=
-- term.mul (term.subst t) (term.subst u)
-- | (term.lt t u) :=
-- term.lt (term.subst t) (term.subst u)
-- | (term.lte t u) :=
-- term.lte (term.subst t) (term.subst u)
-- | (term.gt t u) :=
-- term.gt (term.subst t) (term.subst u)
-- | (term.gte t u) :=
-- term.gte (term.subst t) (term.subst u)
-- | (term.neg t u) :=
-- term.neg (term.subst t) (term.subst u)
-- | (term.int t u) :=
-- term.int (term.subst t) (term.subst u)
-- | (term.forallq n ty body) := term.forallq n ty body
-- meta instance term.has_ordering : has_ordering term :=
-- ⟨ fun a b, ordering.lt ⟩
-- Jared, has_ordering is obsolete, we use has_lt to define maps.
-- I'm confused by the instance above. It is a constant function function?!?!?
-- So, I defined the following instance using a trivial predicate.
meta instance term.has_lt : has_lt term :=
⟨λ a b, true⟩
meta instance term.decidable_lt : decidable_rel ((<) : term → term → Prop) :=
λ a b, is_true trivial
mutual def type.to_string, list_map
with type.to_string : type → string
| (type.int) := "int"
| (type.bool) := "bool"
| (type.var s) := s
| (type.refinement t ref) := type.to_string t ++ " { x | }" -- thid doesn't work
| (type.fn args rt) := string.join (list_map args) ++ (type.to_string rt)
with list_map : list type → list string
| [] := []
| (t :: ts) := type.to_string t :: (list_map ts)
-- with term.to_string : term → string
-- | _ := "term"
instance type.has_to_string : has_to_string type :=
⟨ type.to_string ⟩
inductive decl
| fn : string → type → (option term) → decl
def decl.name : decl → string
| (decl.fn n _ _) := n
meta structure context :=
(type_decl : rb_map string type)
(decls : rb_map string decl)
(assertions : list term)
meta def context.empty : context :=
⟨ rb_map.mk _ _ , rb_map.mk _ _ , [] ⟩
meta def context.declare_type : context → string → type → context
| ⟨ type_decl, decls, assertions ⟩ n ty :=
match ty with
| type.fn _ _ := ⟨ type_decl.insert n ty, decls, assertions ⟩
| _ := ⟨ type_decl, decls, assertions ⟩
end
meta def context.assert : context → term → context
| ⟨ type_decl, decls, assertions ⟩ t := ⟨ type_decl, decls, t :: assertions ⟩
meta def context.declare : context → decl → context
| ctxt decl :=
{ ctxt with decls := ctxt.decls.insert decl.name decl }
meta def context.lookup_type : context → string → option type
| ctxt n :=
do d ← ctxt.decls.find n,
match d with
| (decl.fn _ ty _) := some ty
end
open smt2.builder
meta structure smt2_compiler_state :=
(refinement_map : rb_map lol.term unit)
(ctxt : context)
(commands : list smt2.cmd)
meta def smt2_compiler := except_t string (state smt2_compiler_state)
meta instance smt2_compiler.monad : monad smt2_compiler :=
begin
dunfold smt2_compiler, apply_instance
end
meta def add_command (c : smt2.cmd) : smt2_compiler unit :=
do st ← except_t.lift get,
except_t.lift $ put { st with commands := c :: st.commands }
meta def declare_fun (sym : string) (ps : list smt2.sort) (ret : smt2.sort) : smt2_compiler unit :=
add_command $ smt2.cmd.declare_fun sym ps ret
meta def declare_sort (sym : string) (arity : nat) : smt2_compiler unit :=
add_command $ smt2.cmd.declare_sort sym arity
meta def assert (t : smt2.term) : smt2_compiler unit :=
add_command $ smt2.cmd.assert_cmd t
meta def smt2_compiler.fail {α : Type} : string → smt2_compiler α :=
fun msg, except_t.mk (state_t.mk (fun s, (except.error msg, s)))
private meta def compile_type_simple : type → smt2_compiler smt2.sort
| (type.bool) := return "Bool"
| (type.int) := return "Int"
| (type.var s) := return s
| (type.fn [] rt) := compile_type_simple rt
-- There is a bug here.
| (type.refinement t _) := compile_type_simple t
| t := smt2_compiler.fail $ "compile_simple_type: unsupported" ++ to_string t
@[reducible] meta def refinements : Type := string → smt2_compiler unit
meta def refinements.empty : refinements :=
fun _, return ()
meta def get_refinement : (term × type) → option term
| (t, type.refinement ty refn) := some $ term.subst "__bogus__" t (refn "__bogus__")
| _ := none
def filter_map {A B : Type} (f : A → option B) : list A → list B
| [] := []
| (x :: xs) :=
match f x with
| some r := r :: filter_map xs
| none := filter_map xs
end
meta def compile_type'
(compile_term : lol.term → smt2_compiler smt2.term) : type → smt2_compiler ((list smt2.sort) × smt2.sort × refinements)
| (type.bool) := return ([], "Bool", refinements.empty)
| (type.int) := return ([], "Int", refinements.empty)
| (type.fn args ret) :=
do args' ← monad.mapm compile_type_simple args,
ret' ← compile_type_simple ret,
return (args', ret', refinements.empty)
| (type.var s) := return ([], s, refinements.empty)
| (type.refinement t ref) :=
let rs := (λ x,
do let t := ref x,
ct ← compile_term t,
assert ct) in
do sort ← compile_type_simple t,
pure $ ([], sort, rs)
meta def inst_ref (f : string → term) : term → term :=
fun t, term.subst "__bogus__" t (f "__bogus__")
meta def unless_cached (t : term) (action : smt2_compiler unit) : smt2_compiler unit :=
do st ← except_t.lift get,
match st.refinement_map.find t with
| none :=
do let st' := { st with refinement_map := st.refinement_map.insert t () },
except_t.lift $ smt2.builder.put st',
action
| some _ := return ()
end
private meta def add_refinement_post_cond
(compile_term : lol.term → smt2_compiler smt2.term) : string → lol.type → list lol.term → smt2_compiler unit
| n ty [] := return ()
| n (type.fn arg_tys ret_ty) args :=
match get_refinement (term.apply n args, ret_ty) with
| none := return ()
| some ret_ref :=
let refns := filter_map get_refinement (list.zip args arg_tys) in
if refns.length = 0
then return ()
else do s_refns ← monad.mapm compile_term refns,
s_ret_ref ← compile_term ret_ref,
assert (smt2.builder.implies (smt2.builder.and s_refns) s_ret_ref)
end
| _ _ _ := return ()
private meta def compile_term_app
(compile_term : lol.term → smt2_compiler smt2.term)
(t : string)
(us : list term) : smt2_compiler smt2.term :=
do args ← monad.mapm compile_term us,
st ← except_t.lift get,
match st.ctxt.lookup_type t with
| none := smt2_compiler.fail "unknown function"
| some ty :=
do -- unless_cached (term.apply t us) (add_refinement_post_cond compile_term t ty us),
pure $ smt2.term.apply t args
end
private meta def compile_term : lol.term → smt2_compiler smt2.term
| (term.apply t us) := compile_term_app compile_term t us
| (term.true) := pure $ smt2.term.qual_id "true"
| (term.false) := pure $ smt2.term.qual_id "false"
| (term.var str) := pure $ smt2.term.qual_id str
| (term.not t) := smt2.builder.not <$> compile_term t
| (term.equals t u) := smt2.builder.equals <$> compile_term t <*> compile_term u
| (term.and t u) := smt2.builder.and2 <$> compile_term t <*> compile_term u
| (term.or t u) := smt2.builder.or2 <$> compile_term t <*> compile_term u
| (term.implies t u) := smt2.builder.implies <$> compile_term t <*> compile_term u
| (term.iff t u) := smt2.builder.iff <$> compile_term t <*> compile_term u
| (term.add a b) := smt2.builder.add <$> compile_term a <*> compile_term b
| (term.sub a b) := smt2.builder.sub <$> compile_term a <*> compile_term b
| (term.mul a b) := smt2.builder.mul <$> compile_term a <*> compile_term b
| (term.div a b) := smt2.builder.div <$> compile_term a <*> compile_term b
| (term.lt a b) := smt2.builder.lt <$> compile_term a <*> compile_term b
| (term.lte a b) := smt2.builder.lte <$> compile_term a <*> compile_term b
| (term.gt a b) := smt2.builder.gt <$> compile_term a <*> compile_term b
| (term.gte a b) := smt2.builder.gte <$> compile_term a <*> compile_term b
| (term.mod a b) := smt2.builder.mod <$> compile_term a <*> compile_term b
| (term.int i) := return $ smt2.builder.int_const i
| (term.forallq n ty body) := smt2.builder.forallq n <$> (compile_type_simple ty) <*> compile_term body
| (term.neg a) := smt2.builder.neg <$> compile_term a
-- TODO fix me
meta def compile_type := compile_type' compile_term
private meta def compile_types : list (string × type) → smt2_compiler unit
| [] := return ()
| ((n, ty) :: decls) :=
do match ty with
| type.fn args ret :=
declare_sort n 0
| type.int := return ()
| type.bool := return ()
| type.var _ := return ()
| type.refinement t ref := return ()
end,
compile_types decls.
private meta def compile_decl : decl → smt2_compiler unit
| (decl.fn n ty none) :=
do (args, rt, ref) ← compile_type ty,
declare_fun n args rt,
ref n -- add refinments, revisit this after internship
| _ := return () -- TODO: fix me
private meta def compile_decls : list (string × decl) → smt2_compiler unit
| [] := return ()
| ((n, d) :: rs) := do compile_decl d, compile_decls rs
private meta def compile_assertions : list term → smt2_compiler unit
| [] := return ()
| (t :: ts) :=
do t' ← compile_term t,
assert t',
compile_assertions ts
meta def compile : smt2_compiler unit :=
do st ← except_t.lift get,
compile_types st.ctxt.type_decl.to_list,
compile_decls st.ctxt.decls.to_list,
compile_assertions st.ctxt.assertions
meta def to_builder {α : Type} (st : smt2_compiler_state) : smt2_compiler α → smt2.builder α
| action := let (exc, st') := action.run.run st in
except_t.mk (state_t.mk (fun cs, (exc, cs ++ st'.commands)))
end lol
|
2057507d20d57d1e8cedec0f3eb51bd6bb06387e
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/hott/init/function.hlean
|
655ff42b9bbb45341ceaf9dcb5f5ca288db9c9db
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean-osx
|
4a954262c780e404c1369d6c06516161d07fcb40
|
3670278342d2f4faa49d95b46d86642d7875b47c
|
refs/heads/master
| 1,611,410,334,552
| 1,474,425,686,000
| 1,474,425,686,000
| 12,043,103
| 5
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,904
|
hlean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
General operations on functions.
-/
prelude
import init.reserved_notation .types
open prod
namespace function
variables {A B C D E : Type}
definition compose [reducible] [unfold_full] (f : B → C) (g : A → B) : A → C :=
λx, f (g x)
definition compose_right [reducible] [unfold_full] (f : B → B → B) (g : A → B) : B → A → B :=
λ b a, f b (g a)
definition compose_left [reducible] [unfold_full] (f : B → B → B) (g : A → B) : A → B → B :=
λ a b, f (g a) b
definition on_fun [reducible] [unfold_full] (f : B → B → C) (g : A → B) : A → A → C :=
λx y, f (g x) (g y)
definition combine [reducible] [unfold_full] (f : A → B → C) (op : C → D → E) (g : A → B → D)
: A → B → E :=
λx y, op (f x y) (g x y)
definition const [reducible] [unfold_full] (B : Type) (a : A) : B → A :=
λx, a
definition dcompose [reducible] [unfold_full] {B : A → Type} {C : Π {x : A}, B x → Type}
(f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
λx, f (g x)
definition flip [reducible] [unfold_full] {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
λy x, f x y
definition app [reducible] [unfold_full] {B : A → Type} (f : Πx, B x) (x : A) : B x :=
f x
definition curry [reducible] [unfold_full] : (A × B → C) → A → B → C :=
λ f a b, f (a, b)
definition uncurry [reducible] [unfold 5] : (A → B → C) → (A × B → C) :=
λ f p, match p with (a, b) := f a b end
infixr ` ∘ ` := compose
infixr ` ∘' `:60 := dcompose
infixl ` on `:1 := on_fun
infixr ` $ `:1 := app
notation f ` -[` op `]- ` g := combine f op g
end function
-- copy reducible annotations to top-level
export [reducible] [unfold] function
|
16070a5d5f822b062c6182fbda8ba34b1b48e21b
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/lua7.lean
|
964ecabdb76e9cf2a78cdbe0ca694b1f4d1af3e0
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean0.1
|
1ce92751d664aacff0529e139083304a7bbc8a71
|
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
|
refs/heads/master
| 1,610,830,535,062
| 1,402,150,480,000
| 1,402,150,480,000
| 19,588,851
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 82
|
lean
|
(*
x = Const("x")
y = Const("y")
N = Const("N")
print(fun({{x, N}, {y, N}}, x))
*)
|
09c79544ec5882b0bd44111b6e076864a805bdc0
|
e61a235b8468b03aee0120bf26ec615c045005d2
|
/stage0/src/Init/Lean/Message.lean
|
a5fa6419436ae38d9a266dbe02ee17c261e1d1f7
|
[
"Apache-2.0"
] |
permissive
|
SCKelemen/lean4
|
140dc63a80539f7c61c8e43e1c174d8500ec3230
|
e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc
|
refs/heads/master
| 1,660,973,595,917
| 1,590,278,033,000
| 1,590,278,033,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 9,604
|
lean
|
/-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich, Leonardo de Moura
Message Type used by the Lean frontend
-/
prelude
import Init.Data.ToString
import Init.Lean.Data.Position
import Init.Lean.Syntax
import Init.Lean.MetavarContext
import Init.Lean.Environment
import Init.Lean.Util.PPExt
import Init.Lean.Util.PPGoal
namespace Lean
def mkErrorStringWithPos (fileName : String) (line col : Nat) (msg : String) : String :=
fileName ++ ":" ++ toString line ++ ":" ++ toString col ++ " " ++ toString msg
inductive MessageSeverity
| information | warning | error
structure MessageDataContext :=
(env : Environment) (mctx : MetavarContext) (lctx : LocalContext) (opts : Options)
/- Structure message data. We use it for reporting errors, trace messages, etc. -/
inductive MessageData
| ofFormat : Format → MessageData
| ofSyntax : Syntax → MessageData
| ofExpr : Expr → MessageData
| ofLevel : Level → MessageData
| ofName : Name → MessageData
| ofGoal : MVarId → MessageData
/- `withContext ctx d` specifies the pretty printing context `(env, mctx, lctx, opts)` for the nested expressions in `d`. -/
| withContext : MessageDataContext → MessageData → MessageData
/- Lifted `Format.nest` -/
| nest : Nat → MessageData → MessageData
/- Lifted `Format.group` -/
| group : MessageData → MessageData
/- Lifted `Format.compose` -/
| compose : MessageData → MessageData → MessageData
/- Tagged sections. `Name` should be viewed as a "kind", and is used by `MessageData` inspector functions.
Example: an inspector that tries to find "definitional equality failures" may look for the tag "DefEqFailure". -/
| tagged : Name → MessageData → MessageData
| node : Array MessageData → MessageData
namespace MessageData
instance : Inhabited MessageData := ⟨MessageData.ofFormat (arbitrary _)⟩
@[init] def stxMaxDepthOption : IO Unit :=
registerOption `syntaxMaxDepth { defValue := (2 : Nat), group := "", descr := "maximum depth when displaying syntax objects in messages" }
def getSyntaxMaxDepth (opts : Options) : Nat :=
opts.getNat `syntaxMaxDepth 2
partial def formatAux : Option MessageDataContext → MessageData → Format
| _, ofFormat fmt => fmt
| _, ofLevel u => fmt u
| _, ofName n => fmt n
| some ctx, ofSyntax s => s.formatStx (getSyntaxMaxDepth ctx.opts)
| none, ofSyntax s => s.formatStx
| none, ofExpr e => format (toString e)
| some ctx, ofExpr e => ppExpr ctx.env ctx.mctx ctx.lctx ctx.opts e
| none, ofGoal mvarId => "goal " ++ format (mkMVar mvarId)
| some ctx, ofGoal mvarId => ppGoal ctx.env ctx.mctx ctx.opts mvarId
| _, withContext ctx d => formatAux (some ctx) d
| ctx, tagged cls d => Format.sbracket (format cls) ++ " " ++ formatAux ctx d
| ctx, nest n d => Format.nest n (formatAux ctx d)
| ctx, compose d₁ d₂ => formatAux ctx d₁ ++ formatAux ctx d₂
| ctx, group d => Format.group (formatAux ctx d)
| ctx, node ds => Format.nest 2 $ ds.foldl (fun r d => r ++ Format.line ++ formatAux ctx d) Format.nil
instance : HasAppend MessageData := ⟨compose⟩
instance : HasFormat MessageData := ⟨fun d => formatAux none d⟩
instance coeOfFormat : HasCoe Format MessageData := ⟨ofFormat⟩
instance coeOfLevel : HasCoe Level MessageData := ⟨ofLevel⟩
instance coeOfExpr : HasCoe Expr MessageData := ⟨ofExpr⟩
instance coeOfName : HasCoe Name MessageData := ⟨ofName⟩
instance coeOfSyntax : HasCoe Syntax MessageData := ⟨ofSyntax⟩
instance coeOfOptExpr : HasCoe (Option Expr) MessageData :=
⟨fun o => match o with | none => "none" | some e => ofExpr e⟩
partial def arrayExpr.toMessageData (es : Array Expr) : Nat → MessageData → MessageData
| i, acc =>
if h : i < es.size then
let e := es.get ⟨i, h⟩;
let acc := if i == 0 then acc ++ ofExpr e else acc ++ ", " ++ ofExpr e;
arrayExpr.toMessageData (i+1) acc
else
acc ++ "]"
instance coeOfArrayExpr : HasCoe (Array Expr) MessageData := ⟨fun es => arrayExpr.toMessageData es 0 "#["⟩
def bracket (l : String) (f : MessageData) (r : String) : MessageData := group (nest l.length $ l ++ f ++ r)
def paren (f : MessageData) : MessageData := bracket "(" f ")"
def sbracket (f : MessageData) : MessageData := bracket "[" f "]"
def joinSep : List MessageData → MessageData → MessageData
| [], sep => Format.nil
| [a], sep => a
| a::as, sep => a ++ sep ++ joinSep as sep
def ofList: List MessageData → MessageData
| [] => "[]"
| xs => sbracket $ joinSep xs ("," ++ Format.line)
def ofArray (msgs : Array MessageData) : MessageData :=
ofList msgs.toList
end MessageData
structure Message :=
(fileName : String)
(pos : Position)
(endPos : Option Position := none)
(severity : MessageSeverity := MessageSeverity.error)
(caption : String := "")
(data : MessageData)
@[export lean_mk_message]
def mkMessageEx (fileName : String) (pos : Position) (endPos : Option Position) (severity : MessageSeverity) (caption : String) (text : String) : Message :=
{ fileName := fileName, pos := pos, endPos := endPos, severity := severity, caption := caption, data := text }
namespace Message
protected def toString (msg : Message) : String :=
mkErrorStringWithPos msg.fileName msg.pos.line msg.pos.column
((match msg.severity with
| MessageSeverity.information => ""
| MessageSeverity.warning => "warning: "
| MessageSeverity.error => "error: ") ++
(if msg.caption == "" then "" else msg.caption ++ ":\n") ++ toString (fmt msg.data))
instance : Inhabited Message :=
⟨{ fileName := "", pos := ⟨0, 1⟩, data := arbitrary _}⟩
instance : HasToString Message :=
⟨Message.toString⟩
@[export lean_message_pos] def getPostEx (msg : Message) : Position := msg.pos
@[export lean_message_severity] def getSeverityEx (msg : Message) : MessageSeverity := msg.severity
@[export lean_message_string] def getMessageStringEx (msg : Message) : String := toString (fmt msg.data)
end Message
structure MessageLog :=
(msgs : PersistentArray Message := {})
namespace MessageLog
def empty : MessageLog := ⟨{}⟩
def isEmpty (log : MessageLog) : Bool :=
log.msgs.isEmpty
instance : Inhabited MessageLog := ⟨{}⟩
def add (msg : Message) (log : MessageLog) : MessageLog :=
⟨log.msgs.push msg⟩
protected def append (l₁ l₂ : MessageLog) : MessageLog :=
⟨l₁.msgs ++ l₂.msgs⟩
instance : HasAppend MessageLog :=
⟨MessageLog.append⟩
def hasErrors (log : MessageLog) : Bool :=
log.msgs.any $ fun m => match m.severity with
| MessageSeverity.error => true
| _ => false
def errorsToWarnings (log : MessageLog) : MessageLog :=
{ msgs := log.msgs.map (fun m => match m.severity with | MessageSeverity.error => { m with severity := MessageSeverity.warning } | _ => m) }
def forM {m : Type → Type} [Monad m] (log : MessageLog) (f : Message → m Unit) : m Unit :=
log.msgs.forM f
def toList (log : MessageLog) : List Message :=
(log.msgs.foldl (fun acc msg => msg :: acc) []).reverse
end MessageLog
def indentExpr (msg : MessageData) : MessageData :=
MessageData.nest 2 (Format.line ++ msg)
namespace KernelException
private def mkCtx (env : Environment) (lctx : LocalContext) (opts : Options) (msg : MessageData) : MessageData :=
MessageData.withContext { env := env, mctx := {}, lctx := lctx, opts := opts } msg
def toMessageData (e : KernelException) (opts : Options) : MessageData :=
match e with
| unknownConstant env constName => mkCtx env {} opts $ "(kernel) unknown constant " ++ constName
| alreadyDeclared env constName => mkCtx env {} opts $ "(kernel) constant has already been declared " ++ constName
| declTypeMismatch env decl givenType =>
let process (n : Name) (expectedType : Expr) : MessageData :=
"(kernel) declaration type mismatch " ++ n
++ Format.line ++ "has type" ++ indentExpr givenType
++ Format.line ++ "but it is expected to have type" ++ indentExpr expectedType;
match decl with
| Declaration.defnDecl { name := n, type := type, .. } => process n type
| Declaration.thmDecl { name := n, type := type, .. } => process n type
| _ => "(kernel) declaration type mismatch" -- TODO fix type checker, type mismatch for mutual decls does not have enough information
| declHasMVars env constName _ => mkCtx env {} opts $ "(kernel) declaration has metavariables " ++ constName
| declHasFVars env constName _ => mkCtx env {} opts $ "(kernel) declaration has free variables " ++ constName
| funExpected env lctx e => mkCtx env lctx opts $ "(kernel) function expected" ++ indentExpr e
| typeExpected env lctx e => mkCtx env lctx opts $ "(kernel) type expected" ++ indentExpr e
| letTypeMismatch env lctx n _ _ => mkCtx env lctx opts $ "(kernel) let-declaration type mismatch " ++ n
| exprTypeMismatch env lctx e _ => mkCtx env lctx opts $ "(kernel) type mismatch at " ++ indentExpr e
| appTypeMismatch env lctx e fnType argType =>
mkCtx env lctx opts $
"application type mismatch" ++ indentExpr e
++ "argument has type" ++ indentExpr argType
++ "but function has type" ++ indentExpr fnType
| invalidProj env lctx e => mkCtx env lctx opts $ "(kernel) invalid projection" ++ indentExpr e
| other msg => "(kernel) " ++ msg
end KernelException
end Lean
|
fc344b4c3cd4065b6e7c12dde9256b4e54ddb8c2
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/linear_algebra/affine_space/independent.lean
|
7918c3ff4d4a873fc0d38c41a1f476400f91ffd3
|
[
"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
| 44,078
|
lean
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import data.finset.sort
import data.fin.vec_notation
import data.sign
import linear_algebra.affine_space.combination
import linear_algebra.affine_space.affine_equiv
import linear_algebra.basis
/-!
# Affine independence
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines affinely independent families of points.
## Main definitions
* `affine_independent` defines affinely independent families of points
as those where no nontrivial weighted subtraction is `0`. This is
proved equivalent to two other formulations: linear independence of
the results of subtracting a base point in the family from the other
points in the family, or any equal affine combinations having the
same weights. A bundled type `simplex` is provided for finite
affinely independent families of points, with an abbreviation
`triangle` for the case of three points.
## References
* https://en.wikipedia.org/wiki/Affine_space
-/
noncomputable theory
open_locale big_operators affine
open function
section affine_independent
variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
variables [affine_space V P] {ι : Type*}
include V
/-- An indexed family is said to be affinely independent if no
nontrivial weighted subtractions (where the sum of weights is 0) are
0. -/
def affine_independent (p : ι → P) : Prop :=
∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0:V) → ∀ i ∈ s, w i = 0
/-- The definition of `affine_independent`. -/
lemma affine_independent_def (p : ι → P) :
affine_independent k p ↔
∀ (s : finset ι) (w : ι → k),
∑ i in s, w i = 0 → s.weighted_vsub p w = (0 : V) → ∀ i ∈ s, w i = 0 :=
iff.rfl
/-- A family with at most one point is affinely independent. -/
lemma affine_independent_of_subsingleton [subsingleton ι] (p : ι → P) :
affine_independent k p :=
λ s w h hs i hi, fintype.eq_of_subsingleton_of_sum_eq h i hi
/-- A family indexed by a `fintype` is affinely independent if and
only if no nontrivial weighted subtractions over `finset.univ` (where
the sum of the weights is 0) are 0. -/
lemma affine_independent_iff_of_fintype [fintype ι] (p : ι → P) :
affine_independent k p ↔
∀ w : ι → k, ∑ i, w i = 0 → finset.univ.weighted_vsub p w = (0 : V) → ∀ i, w i = 0 :=
begin
split,
{ exact λ h w hw hs i, h finset.univ w hw hs i (finset.mem_univ _) },
{ intros h s w hw hs i hi,
rw finset.weighted_vsub_indicator_subset _ _ (finset.subset_univ s) at hs,
rw set.sum_indicator_subset _ (finset.subset_univ s) at hw,
replace h := h ((↑s : set ι).indicator w) hw hs i,
simpa [hi] using h }
end
/-- A family is affinely independent if and only if the differences
from a base point in that family are linearly independent. -/
lemma affine_independent_iff_linear_independent_vsub (p : ι → P) (i1 : ι) :
affine_independent k p ↔ linear_independent k (λ i : {x // x ≠ i1}, (p i -ᵥ p i1 : V)) :=
begin
classical,
split,
{ intro h,
rw linear_independent_iff',
intros s g hg i hi,
set f : ι → k := λ x, if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef,
let s2 : finset ι := insert i1 (s.map (embedding.subtype _)),
have hfg : ∀ x : {x // x ≠ i1}, g x = f x,
{ intro x,
rw hfdef,
dsimp only [],
erw [dif_neg x.property, subtype.coe_eta] },
rw hfg,
have hf : ∑ ι in s2, f ι = 0,
{ rw [finset.sum_insert (finset.not_mem_map_subtype_of_not_property s (not_not.2 rfl)),
finset.sum_subtype_map_embedding (λ x hx, (hfg x).symm)],
rw hfdef,
dsimp only [],
rw dif_pos rfl,
exact neg_add_self _ },
have hs2 : s2.weighted_vsub p f = (0:V),
{ set f2 : ι → V := λ x, f x • (p x -ᵥ p i1) with hf2def,
set g2 : {x // x ≠ i1} → V := λ x, g x • (p x -ᵥ p i1) with hg2def,
have hf2g2 : ∀ x : {x // x ≠ i1}, f2 x = g2 x,
{ simp_rw [hf2def, hg2def, hfg],
exact λ x, rfl },
rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s2 f p hf (p i1),
finset.weighted_vsub_of_point_insert, finset.weighted_vsub_of_point_apply,
finset.sum_subtype_map_embedding (λ x hx, hf2g2 x)],
exact hg },
exact h s2 f hf hs2 i (finset.mem_insert_of_mem (finset.mem_map.2 ⟨i, hi, rfl⟩)) },
{ intro h,
rw linear_independent_iff' at h,
intros s w hw hs i hi,
rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s w p hw (p i1),
←s.weighted_vsub_of_point_erase w p i1, finset.weighted_vsub_of_point_apply] at hs,
let f : ι → V := λ i, w i • (p i -ᵥ p i1),
have hs2 : ∑ i in (s.erase i1).subtype (λ i, i ≠ i1), f i = 0,
{ rw [←hs],
convert finset.sum_subtype_of_mem f (λ x, finset.ne_of_mem_erase) },
have h2 := h ((s.erase i1).subtype (λ i, i ≠ i1)) (λ x, w x) hs2,
simp_rw [finset.mem_subtype] at h2,
have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 :=
λ i his hi, h2 ⟨i, hi⟩ (finset.mem_erase_of_ne_of_mem hi his),
exact finset.eq_zero_of_sum_eq_zero hw h2b i hi }
end
/-- A set is affinely independent if and only if the differences from
a base point in that set are linearly independent. -/
lemma affine_independent_set_iff_linear_independent_vsub {s : set P} {p₁ : P} (hp₁ : p₁ ∈ s) :
affine_independent k (λ p, p : s → P) ↔
linear_independent k (λ v, v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) :=
begin
rw affine_independent_iff_linear_independent_vsub k (λ p, p : s → P) ⟨p₁, hp₁⟩,
split,
{ intro h,
have hv : ∀ v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} :=
λ v, (vsub_left_injective p₁).mem_set_image.1
((vadd_vsub (v : V) p₁).symm ▸ v.property),
let f : (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → {x : s // x ≠ ⟨p₁, hp₁⟩} :=
λ x, ⟨⟨(x : V) +ᵥ p₁, set.mem_of_mem_diff (hv x)⟩,
λ hx, set.not_mem_of_mem_diff (hv x) (subtype.ext_iff.1 hx)⟩,
convert h.comp f
(λ x1 x2 hx, (subtype.ext (vadd_right_cancel p₁ (subtype.ext_iff.1 (subtype.ext_iff.1 hx))))),
ext v,
exact (vadd_vsub (v : V) p₁).symm },
{ intro h,
let f : {x : s // x ≠ ⟨p₁, hp₁⟩} → (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) :=
λ x, ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, λ hx, x.property (subtype.ext hx)⟩, rfl⟩⟩⟩,
convert h.comp f
(λ x1 x2 hx, subtype.ext (subtype.ext (vsub_left_cancel (subtype.ext_iff.1 hx)))) }
end
/-- A set of nonzero vectors is linearly independent if and only if,
given a point `p₁`, the vectors added to `p₁` and `p₁` itself are
affinely independent. -/
lemma linear_independent_set_iff_affine_independent_vadd_union_singleton {s : set V}
(hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : linear_independent k (λ v, v : s → V) ↔
affine_independent k (λ p, p : {p₁} ∪ ((λ v, v +ᵥ p₁) '' s) → P) :=
begin
rw affine_independent_set_iff_linear_independent_vsub k
(set.mem_union_left _ (set.mem_singleton p₁)),
have h : (λ p, (p -ᵥ p₁ : V)) '' (({p₁} ∪ (λ v, v +ᵥ p₁) '' s) \ {p₁}) = s,
{ simp_rw [set.union_diff_left, set.image_diff (vsub_left_injective p₁), set.image_image,
set.image_singleton, vsub_self, vadd_vsub, set.image_id'],
exact set.diff_singleton_eq_self (λ h, hs 0 h rfl) },
rw h
end
/-- A family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point
have equal `set.indicator`. -/
lemma affine_independent_iff_indicator_eq_of_affine_combination_eq (p : ι → P) :
affine_independent k p ↔ ∀ (s1 s2 : finset ι) (w1 w2 : ι → k), ∑ i in s1, w1 i = 1 →
∑ i in s2, w2 i = 1 → s1.affine_combination k p w1 = s2.affine_combination k p w2 →
set.indicator ↑s1 w1 = set.indicator ↑s2 w2 :=
begin
classical,
split,
{ intros ha s1 s2 w1 w2 hw1 hw2 heq,
ext i,
by_cases hi : i ∈ (s1 ∪ s2),
{ rw ←sub_eq_zero,
rw set.sum_indicator_subset _ (finset.subset_union_left s1 s2) at hw1,
rw set.sum_indicator_subset _ (finset.subset_union_right s1 s2) at hw2,
have hws : ∑ i in s1 ∪ s2, (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) i = 0,
{ simp [hw1, hw2] },
rw [finset.affine_combination_indicator_subset _ _ (finset.subset_union_left s1 s2),
finset.affine_combination_indicator_subset _ _ (finset.subset_union_right s1 s2),
←@vsub_eq_zero_iff_eq V, finset.affine_combination_vsub] at heq,
exact ha (s1 ∪ s2) (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) hws heq i hi },
{ rw [←finset.mem_coe, finset.coe_union] at hi,
simp [mt (set.mem_union_left ↑s2) hi, mt (set.mem_union_right ↑s1) hi] } },
{ intros ha s w hw hs i0 hi0,
let w1 : ι → k := function.update (function.const ι 0) i0 1,
have hw1 : ∑ i in s, w1 i = 1,
{ rw [finset.sum_update_of_mem hi0, finset.sum_const_zero, add_zero] },
have hw1s : s.affine_combination k p w1 = p i0 :=
s.affine_combination_of_eq_one_of_eq_zero w1 p hi0 (function.update_same _ _ _)
(λ _ _ hne, function.update_noteq hne _ _),
let w2 := w + w1,
have hw2 : ∑ i in s, w2 i = 1,
{ simp [w2, finset.sum_add_distrib, hw, hw1] },
have hw2s : s.affine_combination k p w2 = p i0,
{ simp [w2, ←finset.weighted_vsub_vadd_affine_combination, hs, hw1s] },
replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s),
have hws : w2 i0 - w1 i0 = 0,
{ rw ←finset.mem_coe at hi0,
rw [←set.indicator_of_mem hi0 w2, ←set.indicator_of_mem hi0 w1, ha, sub_self] },
simpa [w2] using hws }
end
/-- A finite family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point are equal. -/
lemma affine_independent_iff_eq_of_fintype_affine_combination_eq [fintype ι] (p : ι → P) :
affine_independent k p ↔ ∀ (w1 w2 : ι → k), ∑ i, w1 i = 1 → ∑ i, w2 i = 1 →
finset.univ.affine_combination k p w1 = finset.univ.affine_combination k p w2 → w1 = w2 :=
begin
rw affine_independent_iff_indicator_eq_of_affine_combination_eq,
split,
{ intros h w1 w2 hw1 hw2 hweq,
simpa only [set.indicator_univ, finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq, },
{ intros h s1 s2 w1 w2 hw1 hw2 hweq,
have hw1' : ∑ i, (s1 : set ι).indicator w1 i = 1,
{ rwa set.sum_indicator_subset _ (finset.subset_univ s1) at hw1, },
have hw2' : ∑ i, (s2 : set ι).indicator w2 i = 1,
{ rwa set.sum_indicator_subset _ (finset.subset_univ s2) at hw2, },
rw [finset.affine_combination_indicator_subset w1 p (finset.subset_univ s1),
finset.affine_combination_indicator_subset w2 p (finset.subset_univ s2)] at hweq,
exact h _ _ hw1' hw2' hweq, },
end
variables {k}
/-- If we single out one member of an affine-independent family of points and affinely transport
all others along the line joining them to this member, the resulting new family of points is affine-
independent.
This is the affine version of `linear_independent.units_smul`. -/
lemma affine_independent.units_line_map
{p : ι → P} (hp : affine_independent k p) (j : ι) (w : ι → units k) :
affine_independent k (λ i, affine_map.line_map (p j) (p i) (w i : k)) :=
begin
rw affine_independent_iff_linear_independent_vsub k _ j at hp ⊢,
simp only [affine_map.line_map_vsub_left, affine_map.coe_const, affine_map.line_map_same],
exact hp.units_smul (λ i, w i),
end
lemma affine_independent.indicator_eq_of_affine_combination_eq {p : ι → P}
(ha : affine_independent k p) (s₁ s₂ : finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i in s₁, w₁ i = 1)
(hw₂ : ∑ i in s₂, w₂ i = 1) (h : s₁.affine_combination k p w₁ = s₂.affine_combination k p w₂) :
set.indicator ↑s₁ w₁ = set.indicator ↑s₂ w₂ :=
(affine_independent_iff_indicator_eq_of_affine_combination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h
/-- An affinely independent family is injective, if the underlying
ring is nontrivial. -/
protected lemma affine_independent.injective [nontrivial k] {p : ι → P}
(ha : affine_independent k p) :
function.injective p :=
begin
intros i j hij,
rw affine_independent_iff_linear_independent_vsub _ _ j at ha,
by_contra hij',
exact ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr hij)
end
/-- If a family is affinely independent, so is any subfamily given by
composition of an embedding into index type with the original
family. -/
lemma affine_independent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P}
(ha : affine_independent k p) : affine_independent k (p ∘ f) :=
begin
classical,
intros fs w hw hs i0 hi0,
let fs' := fs.map f,
let w' := λ i, if h : ∃ i2, f i2 = i then w h.some else 0,
have hw' : ∀ i2 : ι2, w' (f i2) = w i2,
{ intro i2,
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩,
have hs : h.some = i2 := f.injective h.some_spec,
simp_rw [w', dif_pos h, hs] },
have hw's : ∑ i in fs', w' i = 0,
{ rw [←hw, finset.sum_map],
simp [hw'] },
have hs' : fs'.weighted_vsub p w' = (0:V),
{ rw [←hs, finset.weighted_vsub_map],
congr' with i,
simp [hw'] },
rw [←ha fs' w' hw's hs' (f i0) ((finset.mem_map' _).2 hi0), hw']
end
/-- If a family is affinely independent, so is any subfamily indexed
by a subtype of the index type. -/
protected lemma affine_independent.subtype {p : ι → P}
(ha : affine_independent k p) (s : set ι) : affine_independent k (λ i : s, p i) :=
ha.comp_embedding (embedding.subtype _)
/-- If an indexed family of points is affinely independent, so is the
corresponding set of points. -/
protected lemma affine_independent.range {p : ι → P} (ha : affine_independent k p) :
affine_independent k (λ x, x : set.range p → P) :=
begin
let f : set.range p → ι := λ x, x.property.some,
have hf : ∀ x, p (f x) = x := λ x, x.property.some_spec,
let fe : set.range p ↪ ι := ⟨f, λ x₁ x₂ he, subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩,
convert ha.comp_embedding fe,
ext,
simp [hf]
end
lemma affine_independent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} :
affine_independent k (p ∘ e) ↔ affine_independent k p :=
begin
refine ⟨_, affine_independent.comp_embedding e.to_embedding⟩,
intros h,
have : p = p ∘ e ∘ e.symm.to_embedding, { ext, simp, },
rw this,
exact h.comp_embedding e.symm.to_embedding,
end
/-- If a set of points is affinely independent, so is any subset. -/
protected lemma affine_independent.mono {s t : set P}
(ha : affine_independent k (λ x, x : t → P)) (hs : s ⊆ t) :
affine_independent k (λ x, x : s → P) :=
ha.comp_embedding (s.embedding_of_subset t hs)
/-- If the range of an injective indexed family of points is affinely
independent, so is that family. -/
lemma affine_independent.of_set_of_injective {p : ι → P}
(ha : affine_independent k (λ x, x : set.range p → P)) (hi : function.injective p) :
affine_independent k p :=
ha.comp_embedding
(⟨λ i, ⟨p i, set.mem_range_self _⟩, λ x y h, hi (subtype.mk_eq_mk.1 h)⟩ : ι ↪ set.range p)
section composition
variables {V₂ P₂ : Type*} [add_comm_group V₂] [module k V₂] [affine_space V₂ P₂]
include V₂
/-- If the image of a family of points in affine space under an affine transformation is affine-
independent, then the original family of points is also affine-independent. -/
lemma affine_independent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : affine_independent k (f ∘ p)) :
affine_independent k p :=
begin
cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, },
obtain ⟨i⟩ := h,
rw affine_independent_iff_linear_independent_vsub k p i,
simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app,
← f.linear_map_vsub] at hai,
exact linear_independent.of_comp f.linear hai,
end
/-- The image of a family of points in affine space, under an injective affine transformation, is
affine-independent. -/
lemma affine_independent.map'
{p : ι → P} (hai : affine_independent k p) (f : P →ᵃ[k] P₂) (hf : function.injective f) :
affine_independent k (f ∘ p) :=
begin
cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, },
obtain ⟨i⟩ := h,
rw affine_independent_iff_linear_independent_vsub k p i at hai,
simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app,
← f.linear_map_vsub],
have hf' : f.linear.ker = ⊥, { rwa [linear_map.ker_eq_bot, f.linear_injective_iff], },
exact linear_independent.map' hai f.linear hf',
end
/-- Injective affine maps preserve affine independence. -/
lemma affine_map.affine_independent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : function.injective f) :
affine_independent k (f ∘ p) ↔ affine_independent k p :=
⟨affine_independent.of_comp f, λ hai, affine_independent.map' hai f hf⟩
/-- Affine equivalences preserve affine independence of families of points. -/
lemma affine_equiv.affine_independent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) :
affine_independent k (e ∘ p) ↔ affine_independent k p :=
e.to_affine_map.affine_independent_iff e.to_equiv.injective
/-- Affine equivalences preserve affine independence of subsets. -/
lemma affine_equiv.affine_independent_set_of_eq_iff {s : set P} (e : P ≃ᵃ[k] P₂) :
affine_independent k (coe : (e '' s) → P₂) ↔ affine_independent k (coe : s → P) :=
begin
have : e ∘ (coe : s → P) = (coe : e '' s → P₂) ∘ ((e : P ≃ P₂).image s) := rfl,
rw [← e.affine_independent_iff, this, affine_independent_equiv],
end
end composition
/-- If a family is affinely independent, and the spans of points
indexed by two subsets of the index type have a point in common, those
subsets of the index type have an element in common, if the underlying
ring is nontrivial. -/
lemma affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span [nontrivial k]
{p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} {p0 : P}
(hp0s1 : p0 ∈ affine_span k (p '' s1)) (hp0s2 : p0 ∈ affine_span k (p '' s2)):
∃ (i : ι), i ∈ s1 ∩ s2 :=
begin
rw set.image_eq_range at hp0s1 hp0s2,
rw [mem_affine_span_iff_eq_affine_combination,
←finset.eq_affine_combination_subset_iff_eq_affine_combination_subtype] at hp0s1 hp0s2,
rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩,
rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩,
rw affine_independent_iff_indicator_eq_of_affine_combination_eq at ha,
replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2),
have hnz : ∑ i in fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero,
rcases finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩,
simp_rw [←set.indicator_of_mem (finset.mem_coe.2 hifs1) w1, ha] at hinz,
use [i, hfs1 hifs1, hfs2 (set.mem_of_indicator_ne_zero hinz)]
end
/-- If a family is affinely independent, the spans of points indexed
by disjoint subsets of the index type are disjoint, if the underlying
ring is nontrivial. -/
lemma affine_independent.affine_span_disjoint_of_disjoint [nontrivial k] {p : ι → P}
(ha : affine_independent k p) {s1 s2 : set ι} (hd : disjoint s1 s2) :
disjoint (affine_span k (p '' s1) : set P) (affine_span k (p '' s2)) :=
begin
refine set.disjoint_left.2 (λ p0 hp0s1 hp0s2, _),
cases ha.exists_mem_inter_of_exists_mem_inter_affine_span hp0s1 hp0s2 with i hi,
exact set.disjoint_iff.1 hd hi,
end
/-- If a family is affinely independent, a point in the family is in
the span of some of the points given by a subset of the index type if
and only if that point's index is in the subset, if the underlying
ring is nontrivial. -/
@[simp] protected lemma affine_independent.mem_affine_span_iff [nontrivial k] {p : ι → P}
(ha : affine_independent k p) (i : ι) (s : set ι) :
p i ∈ affine_span k (p '' s) ↔ i ∈ s :=
begin
split,
{ intro hs,
have h := affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span
ha hs (mem_affine_span k (set.mem_image_of_mem _ (set.mem_singleton _))),
rwa [←set.nonempty_def, set.inter_singleton_nonempty] at h },
{ exact λ h, mem_affine_span k (set.mem_image_of_mem p h) }
end
/-- If a family is affinely independent, a point in the family is not
in the affine span of the other points, if the underlying ring is
nontrivial. -/
lemma affine_independent.not_mem_affine_span_diff [nontrivial k] {p : ι → P}
(ha : affine_independent k p) (i : ι) (s : set ι) :
p i ∉ affine_span k (p '' (s \ {i})) :=
by simp [ha]
lemma exists_nontrivial_relation_sum_zero_of_not_affine_ind
{t : finset V} (h : ¬ affine_independent k (coe : t → V)) :
∃ f : V → k, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 :=
begin
classical,
rw affine_independent_iff_of_fintype at h,
simp only [exists_prop, not_forall] at h,
obtain ⟨w, hw, hwt, i, hi⟩ := h,
simp only [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero _ w (coe : t → V) hw 0,
vsub_eq_sub, finset.weighted_vsub_of_point_apply, sub_zero] at hwt,
let f : Π (x : V), x ∈ t → k := λ x hx, w ⟨x, hx⟩,
refine ⟨λ x, if hx : x ∈ t then f x hx else (0 : k), _, _, by { use i, simp [hi, f], }⟩,
suffices : ∑ (e : V) in t, dite (e ∈ t) (λ hx, (f e hx) • e) (λ hx, 0) = 0,
{ convert this, ext, by_cases hx : x ∈ t; simp [hx], },
all_goals
{ simp only [finset.sum_dite_of_true (λx h, h), subtype.val_eq_coe, finset.mk_coe, f, hwt, hw], },
end
/-- Viewing a module as an affine space modelled on itself, we can characterise affine independence
in terms of linear combinations. -/
lemma affine_independent_iff {ι} {p : ι → V} :
affine_independent k p ↔
∀ (s : finset ι) (w : ι → k), s.sum w = 0 → ∑ e in s, w e • p e = 0 → ∀ (e ∈ s), w e = 0 :=
forall₃_congr (λ s w hw, by simp [s.weighted_vsub_eq_linear_combination hw])
/-- Given an affinely independent family of points, a weighted subtraction lies in the
`vector_span` of two points given as affine combinations if and only if it is a weighted
subtraction with weights a multiple of the difference between the weights of the two points. -/
lemma weighted_vsub_mem_vector_span_pair {p : ι → P} (h : affine_independent k p)
{w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 0) (hw₁ : ∑ i in s, w₁ i = 1)
(hw₂ : ∑ i in s, w₂ i = 1) :
s.weighted_vsub p w ∈
vector_span k ({s.affine_combination k p w₁, s.affine_combination k p w₂} : set P) ↔
∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) :=
begin
rw mem_vector_span_pair,
refine ⟨λ h, _, λ h, _⟩,
{ rcases h with ⟨r, hr⟩,
refine ⟨r, λ i hi, _⟩,
rw [s.affine_combination_vsub, ←s.weighted_vsub_const_smul, ←sub_eq_zero, ←map_sub] at hr,
have hw' : ∑ j in s, (r • (w₁ - w₂) - w) j = 0,
{ simp_rw [pi.sub_apply, pi.smul_apply, pi.sub_apply, smul_sub, finset.sum_sub_distrib,
←finset.smul_sum, hw, hw₁, hw₂, sub_self] },
have hr' := h s _ hw' hr i hi,
rw [eq_comm, ←sub_eq_zero, ←smul_eq_mul],
exact hr' },
{ rcases h with ⟨r, hr⟩,
refine ⟨r, _⟩,
let w' := λ i, r * (w₁ i - w₂ i),
change ∀ i ∈ s, w i = w' i at hr,
rw [s.weighted_vsub_congr hr (λ _ _, rfl), s.affine_combination_vsub,
←s.weighted_vsub_const_smul],
congr }
end
/-- Given an affinely independent family of points, an affine combination lies in the
span of two points given as affine combinations if and only if it is an affine combination
with weights those of one point plus a multiple of the difference between the weights of the
two points. -/
lemma affine_combination_mem_affine_span_pair {p : ι → P} (h : affine_independent k p)
{w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1) (hw₁ : ∑ i in s, w₁ i = 1)
(hw₂ : ∑ i in s, w₂ i = 1) :
s.affine_combination k p w ∈
line[k, s.affine_combination k p w₁, s.affine_combination k p w₂] ↔
∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i :=
begin
rw [←vsub_vadd (s.affine_combination k p w) (s.affine_combination k p w₁),
affine_subspace.vadd_mem_iff_mem_direction _ (left_mem_affine_span_pair _ _ _),
direction_affine_span, s.affine_combination_vsub, set.pair_comm,
weighted_vsub_mem_vector_span_pair h _ hw₂ hw₁],
{ simp only [pi.sub_apply, sub_eq_iff_eq_add] },
{ simp_rw [pi.sub_apply, finset.sum_sub_distrib, hw, hw₁, sub_self] }
end
end affine_independent
section division_ring
variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V]
variables [affine_space V P] {ι : Type*}
include V
/-- An affinely independent set of points can be extended to such a
set that spans the whole space. -/
lemma exists_subset_affine_independent_affine_span_eq_top {s : set P}
(h : affine_independent k (λ p, p : s → P)) :
∃ t : set P, s ⊆ t ∧ affine_independent k (λ p, p : t → P) ∧ affine_span k t = ⊤ :=
begin
rcases s.eq_empty_or_nonempty with rfl | ⟨p₁, hp₁⟩,
{ have p₁ : P := add_torsor.nonempty.some,
let hsv := basis.of_vector_space k V,
have hsvi := hsv.linear_independent,
have hsvt := hsv.span_eq,
rw basis.coe_of_vector_space at hsvi hsvt,
have h0 : ∀ v : V, v ∈ (basis.of_vector_space_index _ _) → v ≠ 0,
{ intros v hv, simpa using hsv.ne_zero ⟨v, hv⟩ },
rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi,
exact ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' _, set.empty_subset _, hsvi,
affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ },
{ rw affine_independent_set_iff_linear_independent_vsub k hp₁ at h,
let bsv := basis.extend h,
have hsvi := bsv.linear_independent,
have hsvt := bsv.span_eq,
rw basis.coe_extend at hsvi hsvt,
have hsv := h.subset_extend (set.subset_univ _),
have h0 : ∀ v : V, v ∈ (h.extend _) → v ≠ 0,
{ intros v hv, simpa using bsv.ne_zero ⟨v, hv⟩ },
rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi,
refine ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' h.extend (set.subset_univ _), _, _⟩,
{ refine set.subset.trans _ (set.union_subset_union_right _ (set.image_subset _ hsv)),
simp [set.image_image] },
{ use [hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt] } }
end
variables (k V)
lemma exists_affine_independent (s : set P) :
∃ t ⊆ s, affine_span k t = affine_span k s ∧ affine_independent k (coe : t → P) :=
begin
rcases s.eq_empty_or_nonempty with rfl | ⟨p, hp⟩,
{ exact ⟨∅, set.empty_subset ∅, rfl, affine_independent_of_subsingleton k _⟩, },
obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linear_independent k ((equiv.vadd_const p).symm '' s),
have hb₀ : ∀ (v : V), v ∈ b → v ≠ 0, { exact λ v hv, hb₃.ne_zero (⟨v, hv⟩ : b), },
rw linear_independent_set_iff_affine_independent_vadd_union_singleton k hb₀ p at hb₃,
refine ⟨{p} ∪ (equiv.vadd_const p) '' b, _, _, hb₃⟩,
{ apply set.union_subset (set.singleton_subset_iff.mpr hp),
rwa ← (equiv.vadd_const p).subset_image' b s, },
{ rw [equiv.coe_vadd_const_symm, ← vector_span_eq_span_vsub_set_right k hp] at hb₂,
apply affine_subspace.ext_of_direction_eq,
{ have : submodule.span k b = submodule.span k (insert 0 b), { simp, },
simp only [direction_affine_span, ← hb₂, equiv.coe_vadd_const, set.singleton_union,
vector_span_eq_span_vsub_set_right k (set.mem_insert p _), this],
congr,
change (equiv.vadd_const p).symm '' insert p ((equiv.vadd_const p) '' b) = _,
rw [set.image_insert_eq, ← set.image_comp],
simp, },
{ use p,
simp only [equiv.coe_vadd_const, set.singleton_union, set.mem_inter_iff, coe_affine_span],
exact ⟨mem_span_points k _ _ (set.mem_insert p _), mem_span_points k _ _ hp⟩, }, },
end
variables (k) {V P}
/-- Two different points are affinely independent. -/
lemma affine_independent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : affine_independent k ![p₁, p₂] :=
begin
rw affine_independent_iff_linear_independent_vsub k ![p₁, p₂] 0,
let i₁ : {x // x ≠ (0 : fin 2)} := ⟨1, by norm_num⟩,
have he' : ∀ i, i = i₁,
{ rintro ⟨i, hi⟩,
ext,
fin_cases i,
{ simpa using hi } },
haveI : unique {x // x ≠ (0 : fin 2)} := ⟨⟨i₁⟩, he'⟩,
have hz : (![p₁, p₂] ↑default -ᵥ ![p₁, p₂] 0 : V) ≠ 0,
{ rw he' default, simpa using h.symm },
exact linear_independent_unique _ hz
end
variables {k V P}
/-- If all but one point of a family are affinely independent, and that point does not lie in
the affine span of that family, the family is affinely independent. -/
lemma affine_independent.affine_independent_of_not_mem_span {p : ι → P} {i : ι}
(ha : affine_independent k (λ x : {y // y ≠ i}, p x))
(hi : p i ∉ affine_span k (p '' {x | x ≠ i})) : affine_independent k p :=
begin
classical,
intros s w hw hs,
let s' : finset {y // y ≠ i} := s.subtype (≠ i),
let p' : {y // y ≠ i} → P := λ x, p x,
by_cases his : i ∈ s ∧ w i ≠ 0,
{ refine false.elim (hi _),
let wm : ι → k := -(w i)⁻¹ • w,
have hms : s.weighted_vsub p wm = (0 : V), { simp [wm, hs] },
have hwm : ∑ i in s, wm i = 0, { simp [wm, ←finset.mul_sum, hw] },
have hwmi : wm i = -1, { simp [wm, his.2] },
let w' : {y // y ≠ i} → k := λ x, wm x,
have hw' : ∑ x in s', w' x = 1,
{ simp_rw [w', finset.sum_subtype_eq_sum_filter],
rw ←s.sum_filter_add_sum_filter_not (≠ i) at hwm,
simp_rw [not_not, finset.filter_eq', if_pos his.1, finset.sum_singleton, ←wm, hwmi,
←sub_eq_add_neg, sub_eq_zero] at hwm,
exact hwm },
rw [←s.affine_combination_eq_of_weighted_vsub_eq_zero_of_eq_neg_one hms his.1 hwmi,
←(subtype.range_coe : _ = {x | x ≠ i}), ←set.range_comp,
←s.affine_combination_subtype_eq_filter],
exact affine_combination_mem_affine_span hw' p' },
{ rw [not_and_distrib, not_not] at his,
let w' : {y // y ≠ i} → k := λ x, w x,
have hw' : ∑ x in s', w' x = 0,
{ simp_rw [finset.sum_subtype_eq_sum_filter],
rw [finset.sum_filter_of_ne, hw],
rintro x hxs hwx rfl,
exact hwx (his.neg_resolve_left hxs) },
have hs' : s'.weighted_vsub p' w' = (0 : V),
{ simp_rw finset.weighted_vsub_subtype_eq_filter,
rw [finset.weighted_vsub_filter_of_ne, hs],
rintro x hxs hwx rfl,
exact hwx (his.neg_resolve_left hxs) },
intros j hj,
by_cases hji : j = i,
{ rw hji at hj,
exact hji.symm ▸ (his.neg_resolve_left hj) },
{ exact ha s' w' hw' hs' ⟨j, hji⟩ (finset.mem_subtype.2 hj) } }
end
/-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely
independent. -/
lemma affine_independent_of_ne_of_mem_of_mem_of_not_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P}
(hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) :
affine_independent k ![p₁, p₂, p₃] :=
begin
have ha : affine_independent k (λ x : {x : fin 3 // x ≠ 2}, ![p₁, p₂, p₃] x),
{ rw ←affine_independent_equiv ((fin_succ_above_equiv (2 : fin 3)).to_equiv),
convert affine_independent_of_ne k hp₁p₂,
ext x,
fin_cases x;
refl },
refine ha.affine_independent_of_not_mem_span _,
intro h,
refine hp₃ ((affine_subspace.le_def' _ s).1 _ p₃ h),
simp_rw [affine_span_le, set.image_subset_iff, set.subset_def, set.mem_preimage],
intro x,
fin_cases x;
simp [hp₁, hp₂]
end
/-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely
independent. -/
lemma affine_independent_of_ne_of_mem_of_not_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P}
(hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) :
affine_independent k ![p₁, p₂, p₃] :=
begin
rw ←affine_independent_equiv (equiv.swap (1 : fin 3) 2),
convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1,
ext x,
fin_cases x;
refl
end
/-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely
independent. -/
lemma affine_independent_of_ne_of_not_mem_of_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P}
(hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) :
affine_independent k ![p₁, p₂, p₃] :=
begin
rw ←affine_independent_equiv (equiv.swap (0 : fin 3) 2),
convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1,
ext x,
fin_cases x;
refl
end
end division_ring
section ordered
variables {k : Type*} {V : Type*} {P : Type*} [linear_ordered_ring k] [add_comm_group V]
variables [module k V] [affine_space V P] {ι : Type*}
include V
local attribute [instance] linear_ordered_ring.decidable_lt
/-- Given an affinely independent family of points, suppose that an affine combination lies in
the span of two points given as affine combinations, and suppose that, for two indices, the
coefficients in the first point in the span are zero and those in the second point in the span
have the same sign. Then the coefficients in the combination lying in the span have the same
sign. -/
lemma sign_eq_of_affine_combination_mem_affine_span_pair {p : ι → P} (h : affine_independent k p)
{w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1) (hw₁ : ∑ i in s, w₁ i = 1)
(hw₂ : ∑ i in s, w₂ i = 1)
(hs : s.affine_combination k p w ∈
line[k, s.affine_combination k p w₁, s.affine_combination k p w₂])
{i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hi0 : w₁ i = 0) (hj0 : w₁ j = 0)
(hij : sign (w₂ i) = sign (w₂ j)) : sign (w i) = sign (w j) :=
begin
rw affine_combination_mem_affine_span_pair h hw hw₁ hw₂ at hs,
rcases hs with ⟨r, hr⟩,
dsimp only at hr,
rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij]
end
/-- Given an affinely independent family of points, suppose that an affine combination lies in
the span of one point of that family and a combination of another two points of that family given
by `line_map` with coefficient between 0 and 1. Then the coefficients of those two points in the
combination lying in the span have the same sign. -/
lemma sign_eq_of_affine_combination_mem_affine_span_single_line_map {p : ι → P}
(h : affine_independent k p) {w : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1)
{i₁ i₂ i₃ : ι} (h₁ : i₁ ∈ s) (h₂ : i₂ ∈ s) (h₃ : i₃ ∈ s) (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃)
(h₂₃ : i₂ ≠ i₃) {c : k} (hc0 : 0 < c) (hc1 : c < 1)
(hs : s.affine_combination k p w ∈ line[k, p i₁, affine_map.line_map (p i₂) (p i₃) c]) :
sign (w i₂) = sign (w i₃) :=
begin
classical,
rw [←s.affine_combination_affine_combination_single_weights k p h₁,
←s.affine_combination_affine_combination_line_map_weights p h₂ h₃ c] at hs,
refine sign_eq_of_affine_combination_mem_affine_span_pair h hw
(s.sum_affine_combination_single_weights k h₁)
(s.sum_affine_combination_line_map_weights h₂ h₃ c) hs h₂ h₃
(finset.affine_combination_single_weights_apply_of_ne k h₁₂.symm)
(finset.affine_combination_single_weights_apply_of_ne k h₁₃.symm) _,
rw [finset.affine_combination_line_map_weights_apply_left h₂₃,
finset.affine_combination_line_map_weights_apply_right h₂₃],
simp [hc0, sub_pos.2 hc1]
end
end ordered
namespace affine
variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V]
variables [affine_space V P]
include V
/-- A `simplex k P n` is a collection of `n + 1` affinely
independent points. -/
structure simplex (n : ℕ) :=
(points : fin (n + 1) → P)
(independent : affine_independent k points)
/-- A `triangle k P` is a collection of three affinely independent points. -/
abbreviation triangle := simplex k P 2
namespace simplex
variables {P}
/-- Construct a 0-simplex from a point. -/
def mk_of_point (p : P) : simplex k P 0 :=
⟨λ _, p, affine_independent_of_subsingleton k _⟩
/-- The point in a simplex constructed with `mk_of_point`. -/
@[simp] lemma mk_of_point_points (p : P) (i : fin 1) : (mk_of_point k p).points i = p :=
rfl
instance [inhabited P] : inhabited (simplex k P 0) :=
⟨mk_of_point k default⟩
instance nonempty : nonempty (simplex k P 0) :=
⟨mk_of_point k $ add_torsor.nonempty.some⟩
variables {k V}
/-- Two simplices are equal if they have the same points. -/
@[ext] lemma ext {n : ℕ} {s1 s2 : simplex k P n} (h : ∀ i, s1.points i = s2.points i) :
s1 = s2 :=
begin
cases s1,
cases s2,
congr' with i,
exact h i
end
/-- Two simplices are equal if and only if they have the same points. -/
lemma ext_iff {n : ℕ} (s1 s2 : simplex k P n): s1 = s2 ↔ ∀ i, s1.points i = s2.points i :=
⟨λ h _, h ▸ rfl, ext⟩
/-- A face of a simplex is a simplex with the given subset of
points. -/
def face {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) :
simplex k P m :=
⟨s.points ∘ fs.order_emb_of_fin h,
s.independent.comp_embedding (fs.order_emb_of_fin h).to_embedding⟩
/-- The points of a face of a simplex are given by `mono_of_fin`. -/
lemma face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ}
(h : fs.card = m + 1) (i : fin (m + 1)) :
(s.face h).points i = s.points (fs.order_emb_of_fin h i) :=
rfl
/-- The points of a face of a simplex are given by `mono_of_fin`. -/
lemma face_points' {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ}
(h : fs.card = m + 1) : (s.face h).points = s.points ∘ (fs.order_emb_of_fin h) :=
rfl
/-- A single-point face equals the 0-simplex constructed with
`mk_of_point`. -/
@[simp] lemma face_eq_mk_of_point {n : ℕ} (s : simplex k P n) (i : fin (n + 1)) :
s.face (finset.card_singleton i) = mk_of_point k (s.points i) :=
by { ext, simp [face_points] }
/-- The set of points of a face. -/
@[simp] lemma range_face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))}
{m : ℕ} (h : fs.card = m + 1) : set.range (s.face h).points = s.points '' ↑fs :=
by rw [face_points', set.range_comp, finset.range_order_emb_of_fin]
/-- Remap a simplex along an `equiv` of index types. -/
@[simps]
def reindex {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) : simplex k P n :=
⟨s.points ∘ e.symm, (affine_independent_equiv e.symm).2 s.independent⟩
/-- Reindexing by `equiv.refl` yields the original simplex. -/
@[simp] lemma reindex_refl {n : ℕ} (s : simplex k P n) :
s.reindex (equiv.refl (fin (n + 1))) = s :=
ext $ λ _, rfl
/-- Reindexing by the composition of two equivalences is the same as reindexing twice. -/
@[simp] lemma reindex_trans {n₁ n₂ n₃ : ℕ} (e₁₂ : fin (n₁ + 1) ≃ fin (n₂ + 1))
(e₂₃ : fin (n₂ + 1) ≃ fin (n₃ + 1)) (s : simplex k P n₁) :
s.reindex (e₁₂.trans e₂₃) = (s.reindex e₁₂).reindex e₂₃ :=
rfl
/-- Reindexing by an equivalence and its inverse yields the original simplex. -/
@[simp] lemma reindex_reindex_symm {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) :
(s.reindex e).reindex e.symm = s :=
by rw [←reindex_trans, equiv.self_trans_symm, reindex_refl]
/-- Reindexing by the inverse of an equivalence and that equivalence yields the original simplex. -/
@[simp] lemma reindex_symm_reindex {m n : ℕ} (s : simplex k P m) (e : fin (n + 1) ≃ fin (m + 1)) :
(s.reindex e.symm).reindex e = s :=
by rw [←reindex_trans, equiv.symm_trans_self, reindex_refl]
/-- Reindexing a simplex produces one with the same set of points. -/
@[simp] lemma reindex_range_points {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) :
set.range (s.reindex e).points = set.range s.points :=
by rw [reindex, set.range_comp, equiv.range_eq_univ, set.image_univ]
end simplex
end affine
namespace affine
namespace simplex
variables {k : Type*} {V : Type*} {P : Type*} [division_ring k]
[add_comm_group V] [module k V] [affine_space V P]
include V
/-- The centroid of a face of a simplex as the centroid of a subset of
the points. -/
@[simp] lemma face_centroid_eq_centroid {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))}
{m : ℕ} (h : fs.card = m + 1) :
finset.univ.centroid k (s.face h).points = fs.centroid k s.points :=
begin
convert (finset.univ.centroid_map k (fs.order_emb_of_fin h).to_embedding s.points).symm,
rw [← finset.coe_inj, finset.coe_map, finset.coe_univ, set.image_univ],
simp
end
/-- Over a characteristic-zero division ring, the centroids given by
two subsets of the points of a simplex are equal if and only if those
faces are given by the same subset of points. -/
@[simp] lemma centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n)
{fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) :
fs₁.centroid k s.points = fs₂.centroid k s.points ↔ fs₁ = fs₂ :=
begin
refine ⟨λ h, _, congr_arg _⟩,
rw [finset.centroid_eq_affine_combination_fintype,
finset.centroid_eq_affine_combination_fintype] at h,
have ha := (affine_independent_iff_indicator_eq_of_affine_combination_eq k s.points).1
s.independent _ _ _ _ (fs₁.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₁)
(fs₂.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₂) h,
simp_rw [finset.coe_univ, set.indicator_univ, function.funext_iff,
finset.centroid_weights_indicator_def, finset.centroid_weights, h₁, h₂] at ha,
ext i,
specialize ha i,
have key : ∀ n : ℕ, (n : k) + 1 ≠ 0 := λ n h, by norm_cast at h,
-- we should be able to golf this to `refine ⟨λ hi, decidable.by_contradiction (λ hni, _), ...⟩`,
-- but for some unknown reason it doesn't work.
split; intro hi; by_contra hni,
{ simpa [hni, hi, key] using ha },
{ simpa [hni, hi, key] using ha.symm }
end
/-- Over a characteristic-zero division ring, the centroids of two
faces of a simplex are equal if and only if those faces are given by
the same subset of points. -/
lemma face_centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n)
{fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) :
finset.univ.centroid k (s.face h₁).points = finset.univ.centroid k (s.face h₂).points ↔
fs₁ = fs₂ :=
begin
rw [face_centroid_eq_centroid, face_centroid_eq_centroid],
exact s.centroid_eq_iff h₁ h₂
end
/-- Two simplices with the same points have the same centroid. -/
lemma centroid_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex k P n}
(h : set.range s₁.points = set.range s₂.points) :
finset.univ.centroid k s₁.points = finset.univ.centroid k s₂.points :=
begin
rw [←set.image_univ, ←set.image_univ, ←finset.coe_univ] at h,
exact finset.univ.centroid_eq_of_inj_on_of_image_eq k _
(λ _ _ _ _ he, affine_independent.injective s₁.independent he)
(λ _ _ _ _ he, affine_independent.injective s₂.independent he) h
end
end simplex
end affine
|
a66472b305f3b18e03b2ce3b805fd9878f6f2084
|
5756a081670ba9c1d1d3fca7bd47cb4e31beae66
|
/Mathport/Syntax/Translate/Tactic/Mathlib/DocCommands.lean
|
168db27d2fd40eb2d1bd23690849c02722bbefd9
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathport
|
2c9bdc8292168febf59799efdc5451dbf0450d4a
|
13051f68064f7638970d39a8fecaede68ffbf9e1
|
refs/heads/master
| 1,693,841,364,079
| 1,693,813,111,000
| 1,693,813,111,000
| 379,357,010
| 27
| 10
|
Apache-2.0
| 1,691,309,132,000
| 1,624,384,521,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,291
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathport.Syntax.Translate.Tactic.Basic
open Lean
open Lean.Elab.Tactic (Location)
namespace Mathport.Translate.Tactic
open AST3 Parser
-- # tactic.doc_commands
@[tr_user_cmd «copy_doc_string»] def trCopyDocString : Parse1 Unit :=
parse1 (return (← ident, ← tk "->" *> ident*)) fun (fr, to_) => do
unless to_.isEmpty do
pushM `(command| attribute [inherit_doc $(← mkIdentI fr)] $(← liftM $ to_.mapM mkIdentI)*)
@[tr_user_cmd «library_note»] def trLibraryNote (doc : Option String) : Parse1 Syntax.Command :=
parse1 pExpr fun e => do
let ⟨_, Expr.string s⟩ := e | warn! "unsupported: weird string"
`(command| library_note $(Syntax.mkStrLit s) $(trDocComment doc.get!):docComment)
@[tr_user_cmd «add_tactic_doc»] def trAddTacticDoc (doc : Option String) : Parse1 Syntax.Command :=
parse1 pExpr fun e => do
`(command| $[$(doc.map trDocComment)]? add_tactic_doc $(← trExpr e))
@[tr_user_cmd «add_decl_doc»] def trAddDeclDoc (doc : Option String) : Parse1 Syntax.Command :=
parse1 ident fun n => do
`(command| $(trDocComment doc.get!):docComment add_decl_doc $(← mkIdentI n))
|
e2ccccd561d2bf5a8a054f9455e6e855ec18b119
|
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
|
/src/Lean/Meta/WHNF.lean
|
adf0e087fccae94f2de9bba0931e27fb2bd6a962
|
[
"Apache-2.0"
] |
permissive
|
subfish-zhou/leanprover-zh_CN.github.io
|
30b9fba9bd790720bd95764e61ae796697d2f603
|
8b2985d4a3d458ceda9361ac454c28168d920d3f
|
refs/heads/master
| 1,689,709,967,820
| 1,632,503,056,000
| 1,632,503,056,000
| 409,962,097
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 26,335
|
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.ToExpr
import Lean.AuxRecursor
import Lean.ProjFns
import Lean.Meta.Basic
import Lean.Meta.LevelDefEq
import Lean.Meta.GetConst
import Lean.Meta.Match.MatcherInfo
namespace Lean.Meta
/- ===========================
Smart unfolding support
=========================== -/
def smartUnfoldingSuffix := "_sunfold"
@[inline] def mkSmartUnfoldingNameFor (declName : Name) : Name :=
Name.mkStr declName smartUnfoldingSuffix
register_builtin_option smartUnfolding : Bool := {
defValue := true
descr := "when computing weak head normal form, use auxiliary definition created for functions defined by structural recursion"
}
/-- Add auxiliary annotation to indicate the `match`-expression `e` must be reduced when performing smart unfolding. -/
def markSmartUnfoldingMatch (e : Expr) : Expr :=
mkAnnotation `sunfoldMatch e
def smartUnfoldingMatch? (e : Expr) : Option Expr :=
annotation? `sunfoldMatch e
/-- Add auxiliary annotation to indicate expression `e` (a `match` alternative rhs) was successfully reduced by smart unfolding. -/
def markSmartUnfoldigMatchAlt (e : Expr) : Expr :=
mkAnnotation `sunfoldMatchAlt e
def smartUnfoldingMatchAlt? (e : Expr) : Option Expr :=
annotation? `sunfoldMatchAlt e
/- ===========================
Helper methods
=========================== -/
def isAuxDef (constName : Name) : MetaM Bool := do
let env ← getEnv
return isAuxRecursor env constName || isNoConfusion env constName
@[inline] private def matchConstAux {α} (e : Expr) (failK : Unit → MetaM α) (k : ConstantInfo → List Level → MetaM α) : MetaM α :=
match e with
| Expr.const name lvls _ => do
let (some cinfo) ← getConst? name | failK ()
k cinfo lvls
| _ => failK ()
/- ===========================
Helper functions for reducing recursors
=========================== -/
private def getFirstCtor (d : Name) : MetaM (Option Name) := do
let some (ConstantInfo.inductInfo { ctors := ctor::_, ..}) ← getConstNoEx? d | pure none
return some ctor
private def mkNullaryCtor (type : Expr) (nparams : Nat) : MetaM (Option Expr) := do
match type.getAppFn with
| Expr.const d lvls _ =>
let (some ctor) ← getFirstCtor d | pure none
return mkAppN (mkConst ctor lvls) (type.getAppArgs.shrink nparams)
| _ =>
return none
def toCtorIfLit : Expr → Expr
| Expr.lit (Literal.natVal v) _ =>
if v == 0 then mkConst `Nat.zero
else mkApp (mkConst `Nat.succ) (mkRawNatLit (v-1))
| Expr.lit (Literal.strVal v) _ =>
mkApp (mkConst `String.mk) (toExpr v.toList)
| e => e
private def getRecRuleFor (recVal : RecursorVal) (major : Expr) : Option RecursorRule :=
match major.getAppFn with
| Expr.const fn _ _ => recVal.rules.find? fun r => r.ctor == fn
| _ => none
private def toCtorWhenK (recVal : RecursorVal) (major : Expr) : MetaM (Option Expr) := do
let majorType ← inferType major
let majorType ← instantiateMVars (← whnf majorType)
let majorTypeI := majorType.getAppFn
if !majorTypeI.isConstOf recVal.getInduct then
return none
else if majorType.hasExprMVar && majorType.getAppArgs[recVal.numParams:].any Expr.hasExprMVar then
return none
else do
let (some newCtorApp) ← mkNullaryCtor majorType recVal.numParams | pure none
let newType ← inferType newCtorApp
if (← isDefEq majorType newType) then
return newCtorApp
else
return none
/-- Auxiliary function for reducing recursor applications. -/
private def reduceRec (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit → MetaM α) (successK : Expr → MetaM α) : MetaM α :=
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get ⟨majorIdx, h⟩
let mut major ← whnf major
if recVal.k then
let newMajor ← toCtorWhenK recVal major
major := newMajor.getD major
major := toCtorIfLit major
match getRecRuleFor recVal major with
| some rule =>
let majorArgs := major.getAppArgs
if recLvls.length != recVal.levelParams.length then
failK ()
else
let rhs := rule.rhs.instantiateLevelParams recVal.levelParams recLvls
-- Apply parameters, motives and minor premises from recursor application.
let rhs := mkAppRange rhs 0 (recVal.numParams+recVal.numMotives+recVal.numMinors) recArgs
/- The number of parameters in the constructor is not necessarily
equal to the number of parameters in the recursor when we have
nested inductive types. -/
let nparams := majorArgs.size - rule.nfields
let rhs := mkAppRange rhs nparams majorArgs.size majorArgs
let rhs := mkAppRange rhs (majorIdx + 1) recArgs.size recArgs
successK rhs
| none => failK ()
else
failK ()
/- ===========================
Helper functions for reducing Quot.lift and Quot.ind
=========================== -/
/-- Auxiliary function for reducing `Quot.lift` and `Quot.ind` applications. -/
private def reduceQuotRec (recVal : QuotVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit → MetaM α) (successK : Expr → MetaM α) : MetaM α :=
let process (majorPos argPos : Nat) : MetaM α :=
if h : majorPos < recArgs.size then do
let major := recArgs.get ⟨majorPos, h⟩
let major ← whnf major
match major with
| Expr.app (Expr.app (Expr.app (Expr.const majorFn _ _) _ _) _ _) majorArg _ => do
let some (ConstantInfo.quotInfo { kind := QuotKind.ctor, .. }) ← getConstNoEx? majorFn | failK ()
let f := recArgs[argPos]
let r := mkApp f majorArg
let recArity := majorPos + 1
successK $ mkAppRange r recArity recArgs.size recArgs
| _ => failK ()
else
failK ()
match recVal.kind with
| QuotKind.lift => process 5 3
| QuotKind.ind => process 4 3
| _ => failK ()
/- ===========================
Helper function for extracting "stuck term"
=========================== -/
mutual
private partial def isRecStuck? (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) : MetaM (Option MVarId) :=
if recVal.k then
-- TODO: improve this case
return none
else do
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get ⟨majorIdx, h⟩
let major ← whnf major
getStuckMVar? major
else
return none
private partial def isQuotRecStuck? (recVal : QuotVal) (recLvls : List Level) (recArgs : Array Expr) : MetaM (Option MVarId) :=
let process? (majorPos : Nat) : MetaM (Option MVarId) :=
if h : majorPos < recArgs.size then do
let major := recArgs.get ⟨majorPos, h⟩
let major ← whnf major
getStuckMVar? major
else
return none
match recVal.kind with
| QuotKind.lift => process? 5
| QuotKind.ind => process? 4
| _ => return none
/-- Return `some (Expr.mvar mvarId)` if metavariable `mvarId` is blocking reduction. -/
partial def getStuckMVar? : Expr → MetaM (Option MVarId)
| Expr.mdata _ e _ => getStuckMVar? e
| Expr.proj _ _ e _ => do getStuckMVar? (← whnf e)
| e@(Expr.mvar ..) => do
let e ← instantiateMVars e
match e with
| Expr.mvar mvarId _ => pure (some mvarId)
| _ => getStuckMVar? e
| e@(Expr.app f _ _) =>
let f := f.getAppFn
match f with
| Expr.mvar mvarId _ => return some mvarId
| Expr.const fName fLvls _ => do
let cinfo? ← getConstNoEx? fName
match cinfo? with
| some $ ConstantInfo.recInfo recVal => isRecStuck? recVal fLvls e.getAppArgs
| some $ ConstantInfo.quotInfo recVal => isQuotRecStuck? recVal fLvls e.getAppArgs
| _ => return none
| _ => return none
| _ => return none
end
/- ===========================
Weak Head Normal Form auxiliary combinators
=========================== -/
/-- Auxiliary combinator for handling easy WHNF cases. It takes a function for handling the "hard" cases as an argument -/
@[specialize] partial def whnfEasyCases (e : Expr) (k : Expr → MetaM Expr) : MetaM Expr := do
match e with
| Expr.forallE .. => return e
| Expr.lam .. => return e
| Expr.sort .. => return e
| Expr.lit .. => return e
| Expr.bvar .. => unreachable!
| Expr.letE .. => k e
| Expr.const .. => k e
| Expr.app .. => k e
| Expr.proj .. => k e
| Expr.mdata _ e _ => whnfEasyCases e k
| Expr.fvar fvarId _ =>
let decl ← getLocalDecl fvarId
match decl with
| LocalDecl.cdecl .. => return e
| LocalDecl.ldecl (value := v) (nonDep := nonDep) .. =>
let cfg ← getConfig
if nonDep && !cfg.zetaNonDep then
return e
else
if cfg.trackZeta then
modify fun s => { s with zetaFVarIds := s.zetaFVarIds.insert fvarId }
whnfEasyCases v k
| Expr.mvar mvarId _ =>
match (← getExprMVarAssignment? mvarId) with
| some v => whnfEasyCases v k
| none => return e
@[specialize] private def deltaDefinition (c : ConstantInfo) (lvls : List Level)
(failK : Unit → α) (successK : Expr → α) : α :=
if c.levelParams.length != lvls.length then failK ()
else
let val := c.instantiateValueLevelParams lvls
successK val
@[specialize] private def deltaBetaDefinition (c : ConstantInfo) (lvls : List Level) (revArgs : Array Expr)
(failK : Unit → α) (successK : Expr → α) : α :=
if c.levelParams.length != lvls.length then
failK ()
else
let val := c.instantiateValueLevelParams lvls
let val := val.betaRev revArgs
successK val
inductive ReduceMatcherResult where
| reduced (val : Expr)
| stuck (val : Expr)
| notMatcher
| partialApp
def reduceMatcher? (e : Expr) : MetaM ReduceMatcherResult := do
match e.getAppFn with
| Expr.const declName declLevels _ =>
let some info ← getMatcherInfo? declName
| return ReduceMatcherResult.notMatcher
let args := e.getAppArgs
let prefixSz := info.numParams + 1 + info.numDiscrs
if args.size < prefixSz + info.numAlts then
return ReduceMatcherResult.partialApp
else
let constInfo ← getConstInfo declName
let f := constInfo.instantiateValueLevelParams declLevels
let auxApp := mkAppN f args[0:prefixSz]
let auxAppType ← inferType auxApp
forallBoundedTelescope auxAppType info.numAlts fun hs _ => do
let auxApp := mkAppN auxApp hs
/- When reducing `match` expressions, if the reducibility setting is at `TransparencyMode.reducible`,
we increase it to `TransparencyMode.instance`. We use the `TransparencyMode.reducible` in many places (e.g., `simp`),
and this setting prevents us from reducing `match` expressions where the discriminants are terms such as `OfNat.ofNat α n inst`.
For example, `simp [Int.div]` will not unfold the application `Int.div 2 1` occuring in the target.
TODO: consider other solutions; investigate whether the solution above produces counterintuitive behavior. -/
let mut transparency ← getTransparency
if transparency == TransparencyMode.reducible then
transparency := TransparencyMode.instances
let auxApp ← withTransparency transparency <| whnf auxApp
let auxAppFn := auxApp.getAppFn
let mut i := prefixSz
for h in hs do
if auxAppFn == h then
let result := mkAppN args[i] auxApp.getAppArgs
let result := mkAppN result args[prefixSz + info.numAlts:args.size]
return ReduceMatcherResult.reduced result.headBeta
i := i + 1
return ReduceMatcherResult.stuck auxApp
| _ => pure ReduceMatcherResult.notMatcher
/- Given an expression `e`, compute its WHNF and if the result is a constructor, return field #i. -/
def project? (e : Expr) (i : Nat) : MetaM (Option Expr) := do
let e ← whnf e
let e := toCtorIfLit e
matchConstCtor e.getAppFn (fun _ => pure none) fun ctorVal _ =>
let numArgs := e.getAppNumArgs
let idx := ctorVal.numParams + i
if idx < numArgs then
return some (e.getArg! idx)
else
return none
/-- Reduce kernel projection `Expr.proj ..` expression. -/
def reduceProj? (e : Expr) : MetaM (Option Expr) := do
match e with
| Expr.proj _ i c _ => project? c i
| _ => return none
/-
Auxiliary method for reducing terms of the form `?m t_1 ... t_n` where `?m` is delayed assigned.
Recall that we can only expand a delayed assignment when all holes/metavariables in the assigned value have been "filled".
-/
private def whnfDelayedAssigned? (f' : Expr) (e : Expr) : MetaM (Option Expr) := do
if f'.isMVar then
match (← getDelayedAssignment? f'.mvarId!) with
| none => return none
| some { fvars := fvars, val := val, .. } =>
let args := e.getAppArgs
if fvars.size > args.size then
-- Insufficient number of argument to expand delayed assignment
return none
else
let newVal ← instantiateMVars val
if newVal.hasExprMVar then
-- Delayed assignment still contains metavariables
return none
else
let newVal := newVal.abstract fvars
let result := newVal.instantiateRevRange 0 fvars.size args
return mkAppRange result fvars.size args.size args
else
return none
/--
Apply beta-reduction, zeta-reduction (i.e., unfold let local-decls), iota-reduction,
expand let-expressions, expand assigned meta-variables. -/
partial def whnfCore (e : Expr) : MetaM Expr :=
whnfEasyCases e fun e => do
trace[Meta.whnf] e
match e with
| Expr.const .. => pure e
| Expr.letE _ _ v b _ => whnfCore $ b.instantiate1 v
| Expr.app f .. =>
let f := f.getAppFn
let f' ← whnfCore f
if f'.isLambda then
let revArgs := e.getAppRevArgs
whnfCore <| f'.betaRev revArgs
else if let some eNew ← whnfDelayedAssigned? f' e then
whnfCore eNew
else
let e := if f == f' then e else e.updateFn f'
match (← reduceMatcher? e) with
| ReduceMatcherResult.reduced eNew => whnfCore eNew
| ReduceMatcherResult.partialApp => pure e
| ReduceMatcherResult.stuck _ => pure e
| ReduceMatcherResult.notMatcher =>
matchConstAux f' (fun _ => return e) fun cinfo lvls =>
match cinfo with
| ConstantInfo.recInfo rec => reduceRec rec lvls e.getAppArgs (fun _ => return e) whnfCore
| ConstantInfo.quotInfo rec => reduceQuotRec rec lvls e.getAppArgs (fun _ => return e) whnfCore
| c@(ConstantInfo.defnInfo _) => do
if (← isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => return e) whnfCore
else
return e
| _ => return e
| Expr.proj .. => match (← reduceProj? e) with
| some e => whnfCore e
| none => return e
| _ => unreachable!
/--
Recall that `_sunfold` auxiliary definitions contains the markers: `markSmartUnfoldigMatch` (*) and `markSmartUnfoldigMatchAlt` (**).
For example, consider the following definition
```
def r (i j : Nat) : Nat :=
i +
match j with
| Nat.zero => 1
| Nat.succ j =>
i + match j with
| Nat.zero => 2
| Nat.succ j => r i j
```
produces the following `_sunfold` auxiliary definition with the markers
```
def r._sunfold (i j : Nat) : Nat :=
i +
(*) match j with
| Nat.zero => (**) 1
| Nat.succ j =>
i + (*) match j with
| Nat.zero => (**) 2
| Nat.succ j => (**) r i j
```
`match` expressions marked with `markSmartUnfoldigMatch` (*) must be reduced, otherwise the resulting term is not definitionally
equal to the given expression. The recursion may be interrupted as soon as the annotation `markSmartUnfoldingAlt` (**) is reached.
For example, the term `r i j.succ.succ` reduces to the definitionally equal term `i + i * r i j`
-/
partial def smartUnfoldingReduce? (e : Expr) : MetaM (Option Expr) :=
go e |>.run
where
go (e : Expr) : OptionT MetaM Expr := do
match e with
| Expr.letE n t v b _ => withLetDecl n t (← go v) fun x => do mkLetFVars #[x] (← go b)
| Expr.lam .. => lambdaTelescope e fun xs b => do mkLambdaFVars xs (← go b)
| Expr.app f a .. => mkApp (← go f) (← go a)
| Expr.proj _ _ s _ => e.updateProj! (← go s)
| Expr.mdata _ b _ =>
if let some m := smartUnfoldingMatch? e then
goMatch m
else
e.updateMData! (← go b)
| _ => return e
goMatch (e : Expr) : OptionT MetaM Expr := do
match (← reduceMatcher? e) with
| ReduceMatcherResult.reduced e =>
if let some alt := smartUnfoldingMatchAlt? e then
return alt
else
go e
| ReduceMatcherResult.stuck e' =>
let mvarId ← getStuckMVar? e'
/- Try to "unstuck" by resolving pending TC problems -/
if (← Meta.synthPending mvarId) then
goMatch e
else
failure
| _ => failure
mutual
/--
Auxiliary method for unfolding a class projection when transparency is set to `TransparencyMode.instances`.
Recall that class instance projections are not marked with `[reducible]` because we want them to be
in "reducible canonical form".
-/
private partial def unfoldProjInst (e : Expr) : MetaM (Option Expr) := do
if (← getTransparency) != TransparencyMode.instances then
return none
else
match e.getAppFn with
| Expr.const declName .. =>
match (← getProjectionFnInfo? declName) with
| some { fromClass := true, .. } =>
match (← withDefault <| unfoldDefinition? e) with
| none => return none
| some e =>
match (← reduceProj? e.getAppFn) with
| none => return none
| some r => return mkAppN r e.getAppArgs |>.headBeta
| _ => return none
| _ => return none
/-- Unfold definition using "smart unfolding" if possible. -/
partial def unfoldDefinition? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app f _ _ =>
matchConstAux f.getAppFn (fun _ => unfoldProjInst e) fun fInfo fLvls => do
if fInfo.levelParams.length != fLvls.length then
return none
else
let unfoldDefault (_ : Unit) : MetaM (Option Expr) :=
if fInfo.hasValue then
deltaBetaDefinition fInfo fLvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
if smartUnfolding.get (← getOptions) then
match (← getConstNoEx? (mkSmartUnfoldingNameFor fInfo.name)) with
| some fAuxInfo@(ConstantInfo.defnInfo _) =>
deltaBetaDefinition fAuxInfo fLvls e.getAppRevArgs (fun _ => pure none) fun e₁ =>
smartUnfoldingReduce? e₁
| _ =>
if (← getMatcherInfo? fInfo.name).isSome then
-- Recall that `whnfCore` tries to reduce "matcher" applications.
return none
else
unfoldDefault ()
else
unfoldDefault ()
| Expr.const declName lvls _ => do
if smartUnfolding.get (← getOptions) && (← getEnv).contains (mkSmartUnfoldingNameFor declName) then
return none
else
let (some (cinfo@(ConstantInfo.defnInfo _))) ← getConstNoEx? declName | pure none
deltaDefinition cinfo lvls
(fun _ => pure none)
(fun e => pure (some e))
| _ => return none
end
def unfoldDefinition (e : Expr) : MetaM Expr := do
let some e ← unfoldDefinition? e | throwError "failed to unfold definition{indentExpr e}"
return e
@[specialize] partial def whnfHeadPred (e : Expr) (pred : Expr → MetaM Bool) : MetaM Expr :=
whnfEasyCases e fun e => do
let e ← whnfCore e
if (← pred e) then
match (← unfoldDefinition? e) with
| some e => whnfHeadPred e pred
| none => return e
else
return e
def whnfUntil (e : Expr) (declName : Name) : MetaM (Option Expr) := do
let e ← whnfHeadPred e (fun e => return !e.isAppOf declName)
if e.isAppOf declName then
return e
else
return none
/-- Try to reduce matcher/recursor/quot applications. We say they are all "morally" recursor applications. -/
def reduceRecMatcher? (e : Expr) : MetaM (Option Expr) := do
if !e.isApp then
return none
else match (← reduceMatcher? e) with
| ReduceMatcherResult.reduced e => return e
| _ => matchConstAux e.getAppFn (fun _ => pure none) fun cinfo lvls => do
match cinfo with
| ConstantInfo.recInfo «rec» => reduceRec «rec» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| ConstantInfo.quotInfo «rec» => reduceQuotRec «rec» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| c@(ConstantInfo.defnInfo _) =>
if (← isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
| _ => return none
unsafe def reduceBoolNativeUnsafe (constName : Name) : MetaM Bool := evalConstCheck Bool `Bool constName
unsafe def reduceNatNativeUnsafe (constName : Name) : MetaM Nat := evalConstCheck Nat `Nat constName
@[implementedBy reduceBoolNativeUnsafe] constant reduceBoolNative (constName : Name) : MetaM Bool
@[implementedBy reduceNatNativeUnsafe] constant reduceNatNative (constName : Name) : MetaM Nat
def reduceNative? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app (Expr.const fName _ _) (Expr.const argName _ _) _ =>
if fName == `Lean.reduceBool then do
return toExpr (← reduceBoolNative argName)
else if fName == `Lean.reduceNat then do
return toExpr (← reduceNatNative argName)
else
return none
| _ =>
return none
@[inline] def withNatValue {α} (a : Expr) (k : Nat → MetaM (Option α)) : MetaM (Option α) := do
let a ← whnf a
match a with
| Expr.const `Nat.zero _ _ => k 0
| Expr.lit (Literal.natVal v) _ => k v
| _ => return none
def reduceUnaryNatOp (f : Nat → Nat) (a : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
return mkRawNatLit <| f a
def reduceBinNatOp (f : Nat → Nat → Nat) (a b : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
withNatValue b fun b => do
trace[Meta.isDefEq.whnf.reduceBinOp] "{a} op {b}"
return mkRawNatLit <| f a b
def reduceBinNatPred (f : Nat → Nat → Bool) (a b : Expr) : MetaM (Option Expr) := do
withNatValue a fun a =>
withNatValue b fun b =>
return toExpr <| f a b
def reduceNat? (e : Expr) : MetaM (Option Expr) :=
if e.hasFVar || e.hasMVar then
return none
else match e with
| Expr.app (Expr.const fn _ _) a _ =>
if fn == `Nat.succ then
reduceUnaryNatOp Nat.succ a
else
return none
| Expr.app (Expr.app (Expr.const fn _ _) a1 _) a2 _ =>
if fn == `Nat.add then reduceBinNatOp Nat.add a1 a2
else if fn == `Nat.sub then reduceBinNatOp Nat.sub a1 a2
else if fn == `Nat.mul then reduceBinNatOp Nat.mul a1 a2
else if fn == `Nat.div then reduceBinNatOp Nat.div a1 a2
else if fn == `Nat.mod then reduceBinNatOp Nat.mod a1 a2
else if fn == `Nat.beq then reduceBinNatPred Nat.beq a1 a2
else if fn == `Nat.ble then reduceBinNatPred Nat.ble a1 a2
else return none
| _ =>
return none
@[inline] private def useWHNFCache (e : Expr) : MetaM Bool := do
-- We cache only closed terms without expr metavars.
-- Potential refinement: cache if `e` is not stuck at a metavariable
if e.hasFVar || e.hasExprMVar then
return false
else
match (← getConfig).transparency with
| TransparencyMode.default => true
| TransparencyMode.all => true
| _ => false
@[inline] private def cached? (useCache : Bool) (e : Expr) : MetaM (Option Expr) := do
if useCache then
match (← getConfig).transparency with
| TransparencyMode.default => return (← get).cache.whnfDefault.find? e
| TransparencyMode.all => return (← get).cache.whnfAll.find? e
| _ => unreachable!
else
return none
private def cache (useCache : Bool) (e r : Expr) : MetaM Expr := do
if useCache then
match (← getConfig).transparency with
| TransparencyMode.default => modify fun s => { s with cache.whnfDefault := s.cache.whnfDefault.insert e r }
| TransparencyMode.all => modify fun s => { s with cache.whnfAll := s.cache.whnfAll.insert e r }
| _ => unreachable!
return r
@[export lean_whnf]
partial def whnfImp (e : Expr) : MetaM Expr :=
withIncRecDepth <| whnfEasyCases e fun e => do
checkMaxHeartbeats "whnf"
let useCache ← useWHNFCache e
match (← cached? useCache e) with
| some e' => pure e'
| none =>
let e' ← whnfCore e
match (← reduceNat? e') with
| some v => cache useCache e v
| none =>
match (← reduceNative? e') with
| some v => cache useCache e v
| none =>
match (← unfoldDefinition? e') with
| some e => whnfImp e
| none => cache useCache e e'
/-- If `e` is a projection function that satisfies `p`, then reduce it -/
def reduceProjOf? (e : Expr) (p : Name → Bool) : MetaM (Option Expr) := do
if !e.isApp then
pure none
else match e.getAppFn with
| Expr.const name .. => do
let env ← getEnv
match env.getProjectionStructureName? name with
| some structName =>
if p structName then
Meta.unfoldDefinition? e
else
pure none
| none => pure none
| _ => pure none
builtin_initialize
registerTraceClass `Meta.whnf
end Lean.Meta
|
6327c5e311439e13f8fb8be62ae119fbbe8dd42b
|
f3849be5d845a1cb97680f0bbbe03b85518312f0
|
/tests/lean/auto_quote_error2.lean
|
1e9cd714eac5e20c571e8b48f44400e863c12b62
|
[
"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
| 938
|
lean
|
example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
apply eq.refl, -- Error: unification
assumption,
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
begin
tactic.trace "hello world",
end, -- Error unsolved goals
assumption,
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
tactic.intros,
apply eq.symm,
apply eq.trans,
begin
tactic.trace "hello world",
end, -- Error unsolved goals (remark: nested 'begin ... end' blocks focus on the main goal)
assumption
end
example (a b c : nat) : a = b → b = c → c = a :=
begin
intro h1, intro h2,
apply eq.symm,
begin
exact eq.trans h1 _, -- Error unsolved
end,
end
example (a b : nat) : a = 0 → b = 0 → a = b ∧ b = a :=
begin
intros h1 h2,
split,
{ subst h1 },
--^ error should be at `}`
end
|
9ff949c99060b8ae7ae60c28a68cc3be2615d61f
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/analysis/box_integral/integrability.lean
|
0cd3e3289fc467bb183bbb04a956ba6b5e73a472
|
[
"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
| 17,971
|
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 analysis.box_integral.basic
import measure_theory.measure.regular
/-!
# McShane integrability vs Bochner integrability
In this file we prove that any Bochner integrable function is McShane integrable (hence, it is
Henstock and `⊥` integrable) with the same integral. The proof is based on
[Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55].
## Tags
integral, McShane integral, Bochner integral
-/
open_locale classical nnreal ennreal topological_space big_operators
universes u v
variables {ι : Type u} {E : Type v} [fintype ι] [normed_add_comm_group E] [normed_space ℝ E]
open measure_theory metric set finset filter box_integral
namespace box_integral
/-- The indicator function of a measurable set is McShane integrable with respect to any
locally-finite measure. -/
lemma has_integral_indicator_const (l : integration_params) (hl : l.bRiemann = ff)
{s : set (ι → ℝ)} (hs : measurable_set s) (I : box ι) (y : E)
(μ : measure (ι → ℝ)) [is_locally_finite_measure μ] :
has_integral.{u v v} I l (s.indicator (λ _, y)) μ.to_box_additive.to_smul
((μ (s ∩ I)).to_real • y) :=
begin
refine has_integral_of_mul (‖y‖) (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le, rw nnreal.coe_pos at ε0,
/- First we choose a closed set `F ⊆ s ∩ I.Icc` and an open set `U ⊇ s` such that
both `(s ∩ I.Icc) \ F` and `U \ s` have measuer less than `ε`. -/
have A : μ (s ∩ I.Icc) ≠ ∞,
from ((measure_mono $ set.inter_subset_right _ _).trans_lt (I.measure_Icc_lt_top μ)).ne,
have B : μ (s ∩ I) ≠ ∞,
from ((measure_mono $ set.inter_subset_right _ _).trans_lt (I.measure_coe_lt_top μ)).ne,
obtain ⟨F, hFs, hFc, hμF⟩ : ∃ F ⊆ s ∩ I.Icc, is_closed F ∧ μ ((s ∩ I.Icc) \ F) < ε,
from (hs.inter I.measurable_set_Icc).exists_is_closed_diff_lt A (ennreal.coe_pos.2 ε0).ne',
obtain ⟨U, hsU, hUo, hUt, hμU⟩ : ∃ U ⊇ s ∩ I.Icc, is_open U ∧ μ U < ∞ ∧ μ (U \ (s ∩ I.Icc)) < ε,
from (hs.inter I.measurable_set_Icc).exists_is_open_diff_lt A (ennreal.coe_pos.2 ε0).ne',
/- Then we choose `r` so that `closed_ball x (r x) ⊆ U` whenever `x ∈ s ∩ I.Icc` and
`closed_ball x (r x)` is disjoint with `F` otherwise. -/
have : ∀ x ∈ s ∩ I.Icc, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ U,
from λ x hx, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 (hUo.mem_nhds $ hsU hx)),
choose! rs hrsU,
have : ∀ x ∈ I.Icc \ s, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ Fᶜ,
from λ x hx, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 (hFc.is_open_compl.mem_nhds $
λ hx', hx.2 (hFs hx').1)),
choose! rs' hrs'F,
set r : (ι → ℝ) → Ioi (0 : ℝ) := s.piecewise rs rs',
refine ⟨λ c, r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩, rw mul_comm,
/- Then the union of boxes `J ∈ π` such that `π.tag ∈ s` includes `F` and is included by `U`,
hence its measure is `ε`-close to the measure of `s`. -/
dsimp [integral_sum],
simp only [mem_closed_ball, dist_eq_norm, ← indicator_const_smul_apply,
sum_indicator_eq_sum_filter, ← sum_smul, ← sub_smul, norm_smul, real.norm_eq_abs,
← prepartition.filter_boxes, ← prepartition.measure_Union_to_real],
refine mul_le_mul_of_nonneg_right _ (norm_nonneg y),
set t := (π.to_prepartition.filter (λ J, π.tag J ∈ s)).Union,
change abs ((μ t).to_real - (μ (s ∩ I)).to_real) ≤ ε,
have htU : t ⊆ U ∩ I,
{ simp only [t, prepartition.Union_def, Union_subset_iff, prepartition.mem_filter, and_imp],
refine λ J hJ hJs x hx, ⟨hrsU _ ⟨hJs, π.tag_mem_Icc J⟩ _, π.le_of_mem' J hJ hx⟩,
simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hπ.1 J hJ (box.coe_subset_Icc hx) },
refine abs_sub_le_iff.2 ⟨_, _⟩,
{ refine (ennreal.le_to_real_sub B).trans (ennreal.to_real_le_coe_of_le_coe _),
refine (tsub_le_tsub (measure_mono htU) le_rfl).trans (le_measure_diff.trans _),
refine (measure_mono $ λ x hx, _).trans hμU.le,
exact ⟨hx.1.1, λ hx', hx.2 ⟨hx'.1, hx.1.2⟩⟩ },
{ have hμt : μ t ≠ ∞ :=
((measure_mono (htU.trans (inter_subset_left _ _))).trans_lt hUt).ne,
refine (ennreal.le_to_real_sub hμt).trans (ennreal.to_real_le_coe_of_le_coe _),
refine le_measure_diff.trans ((measure_mono _).trans hμF.le),
rintro x ⟨⟨hxs, hxI⟩, hxt⟩,
refine ⟨⟨hxs, box.coe_subset_Icc hxI⟩, λ hxF, hxt _⟩,
simp only [t, prepartition.Union_def, prepartition.mem_filter, set.mem_Union, exists_prop],
rcases hπp x hxI with ⟨J, hJπ, hxJ⟩,
refine ⟨J, ⟨hJπ, _⟩, hxJ⟩,
contrapose hxF,
refine hrs'F _ ⟨π.tag_mem_Icc J, hxF⟩ _,
simpa only [r, s.piecewise_eq_of_not_mem _ _ hxF] using hπ.1 J hJπ (box.coe_subset_Icc hxJ) }
end
/-- If `f` is a.e. equal to zero on a rectangular box, then it has McShane integral zero on this
box. -/
lemma has_integral_zero_of_ae_eq_zero {l : integration_params} {I : box ι} {f : (ι → ℝ) → E}
{μ : measure (ι → ℝ)} [is_locally_finite_measure μ] (hf : f =ᵐ[μ.restrict I] 0)
(hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul 0 :=
begin
/- Each set `{x | n < ‖f x‖ ≤ n + 1}`, `n : ℕ`, has measure zero. We cover it by an open set of
measure less than `ε / 2 ^ n / (n + 1)`. Then the norm of the integral sum is less than `ε`. -/
refine has_integral_iff.2 (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.lt.le, rw [gt_iff_lt, nnreal.coe_pos] at ε0,
rcases nnreal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩,
haveI := fact.mk (I.measure_coe_lt_top μ),
change μ.restrict I {x | f x ≠ 0} = 0 at hf,
set N : (ι → ℝ) → ℕ := λ x, ⌈‖f x‖⌉₊,
have N0 : ∀ {x}, N x = 0 ↔ f x = 0, by { intro x, simp [N] },
have : ∀ n, ∃ U ⊇ N ⁻¹' {n}, is_open U ∧ μ.restrict I U < δ n / n,
{ refine λ n, (N ⁻¹' {n}).exists_is_open_lt_of_lt _ _,
cases n,
{ simpa [ennreal.div_zero (ennreal.coe_pos.2 (δ0 _)).ne']
using measure_lt_top (μ.restrict I) _ },
{ refine (measure_mono_null _ hf).le.trans_lt _,
{ exact λ x hxN hxf, n.succ_ne_zero ((eq.symm hxN).trans $ N0.2 hxf) },
{ simp [(δ0 _).ne'] } } },
choose U hNU hUo hμU,
have : ∀ x, ∃ r : Ioi (0 : ℝ), closed_ball x r ⊆ U (N x),
from λ x, subtype.exists'.1 (nhds_basis_closed_ball.mem_iff.1 ((hUo _).mem_nhds (hNU _ rfl))),
choose r hrU,
refine ⟨λ _, r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩,
rw [dist_eq_norm, sub_zero, ← integral_sum_fiberwise (λ J, N (π.tag J))],
refine le_trans _ (nnreal.coe_lt_coe.2 hcε).le,
refine (norm_sum_le_of_le _ _).trans
(sum_le_has_sum _ (λ n _, (δ n).2) (nnreal.has_sum_coe.2 hδc)),
rintro n -,
dsimp [integral_sum],
have : ∀ J ∈ π.filter (λ J, N (π.tag J) = n),
‖(μ ↑J).to_real • f (π.tag J)‖ ≤ (μ J).to_real * n,
{ intros J hJ, rw tagged_prepartition.mem_filter at hJ,
rw [norm_smul, real.norm_eq_abs, abs_of_nonneg ennreal.to_real_nonneg],
exact mul_le_mul_of_nonneg_left (hJ.2 ▸ nat.le_ceil _) ennreal.to_real_nonneg },
refine (norm_sum_le_of_le _ this).trans _, clear this,
rw [← sum_mul, ← prepartition.measure_Union_to_real],
generalize hm : μ (π.filter (λ J, N (π.tag J) = n)).Union = m,
have : m < δ n / n,
{ simp only [measure.restrict_apply (hUo _).measurable_set] at hμU,
refine hm ▸ (measure_mono _).trans_lt (hμU _),
simp only [set.subset_def, tagged_prepartition.mem_Union, exists_prop,
tagged_prepartition.mem_filter],
rintro x ⟨J, ⟨hJ, rfl⟩, hx⟩,
exact ⟨hrU _ (hπ.1 _ hJ (box.coe_subset_Icc hx)), π.le_of_mem' J hJ hx⟩ },
lift m to ℝ≥0 using ne_top_of_lt this,
rw [ennreal.coe_to_real, ← nnreal.coe_nat_cast, ← nnreal.coe_mul, nnreal.coe_le_coe,
← ennreal.coe_le_coe, ennreal.coe_mul, ennreal.coe_nat, mul_comm],
exact (mul_le_mul_left' this.le _).trans ennreal.mul_div_le
end
/-- If `f` has integral `y` on a box `I` with respect to a locally finite measure `μ` and `g` is
a.e. equal to `f` on `I`, then `g` has the same integral on `I`. -/
lemma has_integral.congr_ae {l : integration_params} {I : box ι} {y : E} {f g : (ι → ℝ) → E}
{μ : measure (ι → ℝ)} [is_locally_finite_measure μ]
(hf : has_integral.{u v v} I l f μ.to_box_additive.to_smul y)
(hfg : f =ᵐ[μ.restrict I] g) (hl : l.bRiemann = ff) :
has_integral.{u v v} I l g μ.to_box_additive.to_smul y :=
begin
have : (g - f) =ᵐ[μ.restrict I] 0, from hfg.mono (λ x hx, sub_eq_zero.2 hx.symm),
simpa using hf.add (has_integral_zero_of_ae_eq_zero this hl)
end
end box_integral
namespace measure_theory
namespace simple_func
/-- A simple function is McShane integrable w.r.t. any locally finite measure. -/
lemma has_box_integral (f : simple_func (ι → ℝ) E) (μ : measure (ι → ℝ))
[is_locally_finite_measure μ] (I : box ι) (l : integration_params) (hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul (f.integral (μ.restrict I)) :=
begin
induction f using measure_theory.simple_func.induction with y s hs f g hd hfi hgi,
{ simpa only [measure.restrict_apply hs, const_zero, integral_piecewise_zero, integral_const,
measure.restrict_apply, measurable_set.univ, set.univ_inter]
using box_integral.has_integral_indicator_const l hl hs I y μ },
{ borelize E, haveI := fact.mk (I.measure_coe_lt_top μ),
rw integral_add,
exacts [hfi.add hgi, integrable_iff.2 $ λ _ _, measure_lt_top _ _,
integrable_iff.2 $ λ _ _, measure_lt_top _ _] }
end
/-- For a simple function, its McShane (or Henstock, or `⊥`) box integral is equal to its
integral in the sense of `measure_theory.simple_func.integral`. -/
lemma box_integral_eq_integral (f : simple_func (ι → ℝ) E) (μ : measure (ι → ℝ))
[is_locally_finite_measure μ] (I : box ι) (l : integration_params) (hl : l.bRiemann = ff) :
box_integral.integral.{u v v} I l f μ.to_box_additive.to_smul = f.integral (μ.restrict I) :=
(f.has_box_integral μ I l hl).integral_eq
end simple_func
open topological_space
/-- If `f : ℝⁿ → E` is Bochner integrable w.r.t. a locally finite measure `μ` on a rectangular box
`I`, then it is McShane integrable on `I` with the same integral. -/
lemma integrable_on.has_box_integral [complete_space E] {f : (ι → ℝ) → E} {μ : measure (ι → ℝ)}
[is_locally_finite_measure μ] {I : box ι} (hf : integrable_on f I μ) (l : integration_params)
(hl : l.bRiemann = ff) :
has_integral.{u v v} I l f μ.to_box_additive.to_smul (∫ x in I, f x ∂ μ) :=
begin
borelize E,
/- First we replace an `ae_strongly_measurable` function by a measurable one. -/
rcases hf.ae_strongly_measurable with ⟨g, hg, hfg⟩,
haveI : separable_space (range g ∪ {0} : set E) := hg.separable_space_range_union_singleton,
rw integral_congr_ae hfg, have hgi : integrable_on g I μ := (integrable_congr hfg).1 hf,
refine box_integral.has_integral.congr_ae _ hfg.symm hl,
clear_dependent f,
/- Now consider the sequence of simple functions
`simple_func.approx_on g hg.measurable (range g ∪ {0}) 0 (by simp)`
approximating `g`. Recall some properties of this sequence. -/
set f : ℕ → simple_func (ι → ℝ) E :=
simple_func.approx_on g hg.measurable (range g ∪ {0}) 0 (by simp),
have hfi : ∀ n, integrable_on (f n) I μ,
from simple_func.integrable_approx_on_range hg.measurable hgi,
have hfi' := λ n, ((f n).has_box_integral μ I l hl).integrable,
have hfgi : tendsto (λ n, (f n).integral (μ.restrict I)) at_top (𝓝 $ ∫ x in I, g x ∂μ),
from tendsto_integral_approx_on_of_measurable_of_range_subset hg.measurable hgi _ subset.rfl,
have hfg_mono : ∀ x {m n}, m ≤ n → ‖f n x - g x‖ ≤ ‖f m x - g x‖,
{ intros x m n hmn,
rw [← dist_eq_norm, ← dist_eq_norm, dist_nndist, dist_nndist, nnreal.coe_le_coe,
← ennreal.coe_le_coe, ← edist_nndist, ← edist_nndist],
exact simple_func.edist_approx_on_mono hg.measurable _ x hmn },
/- Now consider `ε > 0`. We need to find `r` such that for any tagged partition subordinate
to `r`, the integral sum is `(μ I + 1 + 1) * ε`-close to the Bochner integral. -/
refine has_integral_of_mul ((μ I).to_real + 1 + 1) (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le, rw nnreal.coe_pos at ε0, have ε0' := ennreal.coe_pos.2 ε0,
/- Choose `N` such that the integral of `‖f N x - g x‖` is less than or equal to `ε`. -/
obtain ⟨N₀, hN₀⟩ : ∃ N : ℕ, ∫ x in I, ‖f N x - g x‖ ∂μ ≤ ε,
{ have : tendsto (λ n, ∫⁻ x in I, ‖f n x - g x‖₊ ∂μ) at_top (𝓝 0),
from simple_func.tendsto_approx_on_range_L1_nnnorm hg.measurable hgi,
refine (this.eventually (ge_mem_nhds ε0')).exists.imp (λ N hN, _),
exact integral_coe_le_of_lintegral_coe_le hN },
/- For each `x`, we choose `Nx x ≥ N₀` such that `dist (f Nx x) (g x) ≤ ε`. -/
have : ∀ x, ∃ N₁, N₀ ≤ N₁ ∧ dist (f N₁ x) (g x) ≤ ε,
{ intro x,
have : tendsto (λ n, f n x) at_top (𝓝 $ g x),
from simple_func.tendsto_approx_on hg.measurable _ (subset_closure (by simp)),
exact ((eventually_ge_at_top N₀).and $ this $ closed_ball_mem_nhds _ ε0).exists },
choose Nx hNx hNxε,
/- We also choose a convergent series with `∑' i : ℕ, δ i < ε`. -/
rcases nnreal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩,
/- Since each simple function `fᵢ` is integrable, there exists `rᵢ : ℝⁿ → (0, ∞)` such that
the integral sum of `f` over any tagged prepartition is `δᵢ`-close to the sum of integrals
of `fᵢ` over the boxes of this prepartition. For each `x`, we choose `r (Nx x)` as the radius
at `x`. -/
set r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) := λ c x, (hfi' $ Nx x).convergence_r (δ $ Nx x) c x,
refine ⟨r, λ c, l.r_cond_of_bRiemann_eq_ff hl, λ c π hπ hπp, _⟩,
/- Now we prove the estimate in 3 "jumps": first we replace `g x` in the formula for the
integral sum by `f (Nx x)`; then we replace each `μ J • f (Nx (π.tag J)) (π.tag J)`
by the Bochner integral of `f (Nx (π.tag J)) x` over `J`, then we jump to the Bochner
integral of `g`. -/
refine (dist_triangle4 _ (∑ J in π.boxes, (μ J).to_real • f (Nx $ π.tag J) (π.tag J))
(∑ J in π.boxes, ∫ x in J, f (Nx $ π.tag J) x ∂μ) _).trans _,
rw [add_mul, add_mul, one_mul],
refine add_le_add_three _ _ _,
{ /- Since each `f (Nx $ π.tag J)` is `ε`-close to `g (π.tag J)`, replacing the latter with
the former in the formula for the integral sum changes the sum at most by `μ I * ε`. -/
rw [← hπp.Union_eq, π.to_prepartition.measure_Union_to_real, sum_mul, integral_sum],
refine dist_sum_sum_le_of_le _ (λ J hJ, _), dsimp,
rw [dist_eq_norm, ← smul_sub, norm_smul, real.norm_eq_abs,
abs_of_nonneg ennreal.to_real_nonneg],
refine mul_le_mul_of_nonneg_left _ ennreal.to_real_nonneg,
rw [← dist_eq_norm'], exact hNxε _ },
{ /- We group the terms of both sums by the values of `Nx (π.tag J)`.
For each `N`, the sum of Bochner integrals over the boxes is equal
to the sum of box integrals, and the sum of box integrals is `δᵢ`-close
to the corresponding integral sum due to the Henstock-Sacks inequality. -/
rw [← π.to_prepartition.sum_fiberwise (λ J, Nx (π.tag J)),
← π.to_prepartition.sum_fiberwise (λ J, Nx (π.tag J))],
refine le_trans _ (nnreal.coe_lt_coe.2 hcε).le,
refine (dist_sum_sum_le_of_le _ (λ n hn, _)).trans
(sum_le_has_sum _ (λ n _, (δ n).2) (nnreal.has_sum_coe.2 hδc)),
have hNxn : ∀ J ∈ π.filter (λ J, Nx (π.tag J) = n), Nx (π.tag J) = n,
from λ J hJ, (π.mem_filter.1 hJ).2,
have hrn : ∀ J ∈ π.filter (λ J, Nx (π.tag J) = n),
r c (π.tag J) = (hfi' n).convergence_r (δ n) c (π.tag J),
{ intros J hJ,
obtain rfl := hNxn J hJ,
refl },
have : l.mem_base_set I c ((hfi' n).convergence_r (δ n) c) (π.filter (λ J, Nx (π.tag J) = n)),
from (hπ.filter _).mono' _ le_rfl le_rfl (λ J hJ, (hrn J hJ).le),
convert (hfi' n).dist_integral_sum_sum_integral_le_of_mem_base_set (δ0 _) this using 2,
{ refine sum_congr rfl (λ J hJ, _),
simp [hNxn J hJ] },
{ refine sum_congr rfl (λ J hJ, _),
rw [← simple_func.integral_eq_integral, simple_func.box_integral_eq_integral _ _ _ _ hl,
hNxn J hJ],
exact (hfi _).mono_set (prepartition.le_of_mem _ hJ) } },
{ /- For the last jump, we use the fact that the distance between `f (Nx x) x` and `g x` is less
than or equal to the distance between `f N₀ x` and `g x` and the integral of `‖f N₀ x - g x‖`
is less than or equal to `ε`. -/
refine le_trans _ hN₀,
have hfi : ∀ n (J ∈ π), integrable_on (f n) ↑J μ,
from λ n J hJ, (hfi n).mono_set (π.le_of_mem' J hJ),
have hgi : ∀ J ∈ π, integrable_on g ↑J μ, from λ J hJ, hgi.mono_set (π.le_of_mem' J hJ),
have hfgi : ∀ n (J ∈ π), integrable_on (λ x, ‖f n x - g x‖) J μ,
from λ n J hJ, ((hfi n J hJ).sub (hgi J hJ)).norm,
rw [← hπp.Union_eq, prepartition.Union_def',
integral_finset_bUnion π.boxes (λ J hJ, J.measurable_set_coe) π.pairwise_disjoint hgi,
integral_finset_bUnion π.boxes (λ J hJ, J.measurable_set_coe) π.pairwise_disjoint (hfgi _)],
refine dist_sum_sum_le_of_le _ (λ J hJ, _),
rw [dist_eq_norm, ← integral_sub (hfi _ J hJ) (hgi J hJ)],
refine norm_integral_le_of_norm_le (hfgi _ J hJ) (eventually_of_forall $ λ x, _),
exact hfg_mono x (hNx (π.tag J)) }
end
end measure_theory
|
a40c25fef28f563320582069f7769b59cb82129d
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/algebra/homology/homology.lean
|
90187963d3e24447d8be5908a8f43115a95fb729
|
[
"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
| 3,899
|
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.homology.chain_complex
import category_theory.limits.shapes.images
import category_theory.limits.shapes.kernels
/-!
# Non-functorial cohomology groups for cochain complexes
We setup that part of the theory of cohomology groups which works in
any category with kernels and images.
We define the cohomology groups themselves, and while we can show that
chain maps induce maps on the kernels, at this level of generality
chain maps do not induce maps on the images, and so not on the cohomology groups.
We'll do this with stronger assumptions, later.
-/
universes v u
namespace cochain_complex
open category_theory
open category_theory.limits
variables {V : Type u} [𝒱 : category.{v} V] [has_zero_morphisms.{v} V]
include 𝒱
variable [has_kernels.{v} V]
/-- The map induceed by a chain map between the kernels of the differentials. -/
def induced_map_on_cycles {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
kernel (C.d i) ⟶ kernel (C'.d i) :=
kernel.lift _ (kernel.ι _ ≫ f.f i)
begin
rw [category.assoc, ←comm_at f, ←category.assoc, kernel.condition, has_zero_morphisms.zero_comp],
end
/-!
At this point we assume that we have all images, and all equalizers.
We need to assume all equalizers, not just kernels, so that
`factor_thru_image` is an epimorphism.
-/
variables [has_images.{v} V] [has_equalizers.{v} V]
/--
The connecting morphism from the image of `d i` to the kernel of `d (i+1)`.
-/
def image_to_kernel_map (C : cochain_complex V) (i : ℤ) :
image (C.d i) ⟶ kernel (C.d (i+1)) :=
kernel.lift _ (image.ι (C.d i))
begin
rw ←cancel_epi (factor_thru_image (C.d i)),
rw [has_zero_morphisms.comp_zero, image.fac_assoc, d_squared],
refl,
end
-- TODO (a good project!):
-- At this level of generality, it's just not true that a chain map
-- induces maps on boundaries
--
-- Let's add these later, with appropriate (but hopefully fairly minimal)
-- assumptions: perhaps that the category is regular?
-- I think in that case we can compute `image` as the regular coimage,
-- i.e. the coequalizer of the kernel pair,
-- and that image has the appropriate mapping property.
-- def induced_map_on_boundaries {C C' : chain_complex.{v} V} (f : C ⟶ C') (i : ℤ) :
-- image (C.d i) ⟶ image (C'.d i) :=
-- sorry
-- -- I'm not certain what the minimal assumptions required to prove the following
-- -- lemma are:
-- lemma induced_maps_commute {C C' : cochain_complex.{v} V} (f : C ⟶ C') (i : ℤ) :
-- image_to_kernel_map C i ≫ induced_map_on_cycles f (i+1) =
-- induced_map_on_boundaries f i ≫ image_to_kernel_map C' i :=
-- sorry
variables [has_cokernels.{v} V]
/-- The `i`-th cohomology group of the cochain complex `C`. -/
def cohomology (C : cochain_complex V) (i : ℤ) : V :=
cokernel (image_to_kernel_map C (i-1))
-- TODO:
-- As noted above, as we don't get induced maps on boundaries with this generality,
-- we can't assemble the cohomology groups into a functor. Hopefully, however,
-- the commented out code below will work
-- (with whatever added assumptions are needed above.)
-- def induced_map_on_cohomology {C C' : chain_cocomplex.{v} V} (f : C ⟶ C') (i : ℤ) :
-- C.cohomology i ⟶ C'.cohomology i :=
-- cokernel.desc _ (induced_map_on_cycles f (i-1) ≫ cokernel.π _)
-- begin
-- rw [←category.assoc, induced_maps_commute, category.assoc, cokernel.condition],
-- erw [has_zero_morphisms.comp_zero],
-- end
-- /-- The cohomology functor from chain complexes to `ℤ` graded objects in `V`. -/
-- def cohomology_functor : cochain_complex.{v} V ⥤ graded_object ℤ V :=
-- { obj := λ C i, cohomology C i,
-- map := λ C C' f i, induced_map_on_cohomology f i,
-- map_id' := sorry,
-- map_comp' := sorry, }
end cochain_complex
|
db3a9f05d05681963ea8a7d814d99c2c01b5f99d
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/algebra/ring/pi.lean
|
8ffec41b44d3f170f6e942501aaa75e54d6e09e6
|
[
"Apache-2.0"
] |
permissive
|
AntoineChambert-Loir/mathlib
|
64aabb896129885f12296a799818061bc90da1ff
|
07be904260ab6e36a5769680b6012f03a4727134
|
refs/heads/master
| 1,693,187,631,771
| 1,636,719,886,000
| 1,636,719,886,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,323
|
lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import tactic.pi_instances
import algebra.group.pi
import algebra.ring.basic
/-!
# Pi instances for ring
This file defines instances for ring, semiring and related structures on Pi Types
-/
namespace pi
universes u v w
variable {I : Type u} -- The indexing type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
instance distrib [Π i, distrib $ f i] : distrib (Π i : I, f i) :=
by refine_struct { add := (+), mul := (*), .. }; tactic.pi_instance_derive_field
instance non_unital_non_assoc_semiring [∀ i, non_unital_non_assoc_semiring $ f i] :
non_unital_non_assoc_semiring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), add := (+), mul := (*), .. };
tactic.pi_instance_derive_field
instance non_unital_semiring [∀ i, non_unital_semiring $ f i] :
non_unital_semiring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), add := (+), mul := (*), .. };
tactic.pi_instance_derive_field
instance non_assoc_semiring [∀ i, non_assoc_semiring $ f i] :
non_assoc_semiring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*), .. };
tactic.pi_instance_derive_field
instance semiring [∀ i, semiring $ f i] : semiring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*),
nsmul := add_monoid.nsmul, npow := monoid.npow };
tactic.pi_instance_derive_field
instance comm_semiring [∀ i, comm_semiring $ f i] : comm_semiring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*),
nsmul := add_monoid.nsmul, npow := monoid.npow };
tactic.pi_instance_derive_field
instance ring [∀ i, ring $ f i] : ring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*),
neg := has_neg.neg, nsmul := add_monoid.nsmul, zsmul := sub_neg_monoid.zsmul,
npow := monoid.npow };
tactic.pi_instance_derive_field
instance comm_ring [∀ i, comm_ring $ f i] : comm_ring (Π i : I, f i) :=
by refine_struct { zero := (0 : Π i, f i), one := 1, add := (+), mul := (*),
neg := has_neg.neg, nsmul := add_monoid.nsmul, zsmul := sub_neg_monoid.zsmul,
npow := monoid.npow };
tactic.pi_instance_derive_field
/-- A family of ring homomorphisms `f a : γ →+* β a` defines a ring homomorphism
`pi.ring_hom f : γ →+* Π a, β a` given by `pi.ring_hom f x b = f b x`. -/
@[simps]
protected def ring_hom {γ : Type w} [Π i, non_assoc_semiring (f i)] [non_assoc_semiring γ]
(g : Π i, γ →+* f i) : γ →+* Π i, f i :=
{ to_fun := λ x b, g b x,
map_add' := λ x y, funext $ λ z, (g z).map_add x y,
map_mul' := λ x y, funext $ λ z, (g z).map_mul x y,
map_one' := funext $ λ z, (g z).map_one,
map_zero' := funext $ λ z, (g z).map_zero }
lemma ring_hom_injective {γ : Type w} [nonempty I] [Π i, non_assoc_semiring (f i)]
[non_assoc_semiring γ] (g : Π i, γ →+* f i) (hg : ∀ i, function.injective (g i)) :
function.injective (pi.ring_hom g) :=
λ x y h, let ⟨i⟩ := ‹nonempty I› in hg i ((function.funext_iff.mp h : _) i)
end pi
section ring_hom
universes u v
variable {I : Type u}
/-- Evaluation of functions into an indexed collection of monoids at a point is a monoid
homomorphism. This is `function.eval` as a `ring_hom`. -/
@[simps]
def pi.eval_ring_hom (f : I → Type v) [Π i, non_assoc_semiring (f i)] (i : I) :
(Π i, f i) →+* f i :=
{ ..(pi.eval_monoid_hom f i),
..(pi.eval_add_monoid_hom f i) }
/-- `function.const` as a `ring_hom`. -/
@[simps]
def pi.const_ring_hom (α β : Type*) [non_assoc_semiring β] : β →+* (α → β) :=
{ to_fun := function.const _,
.. pi.ring_hom (λ _, ring_hom.id β) }
/-- Ring homomorphism between the function spaces `I → α` and `I → β`, induced by a ring
homomorphism `f` between `α` and `β`. -/
@[simps] protected def ring_hom.comp_left {α β : Type*} [non_assoc_semiring α]
[non_assoc_semiring β] (f : α →+* β) (I : Type*) :
(I → α) →+* (I → β) :=
{ to_fun := λ h, f ∘ h,
.. f.to_monoid_hom.comp_left I,
.. f.to_add_monoid_hom.comp_left I }
end ring_hom
|
ba65f745e5d72b6fb48fdb8d3da15d467d3b942f
|
1a9d3677cccdaaccacb163507570e75d34043a38
|
/src/week_5/Part_A_filters.lean
|
ba50bfc420b3a126c5b3419a5f89f0d4cc94b50a
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/formalising-mathematics
|
687d386a72065795e784e270f5c05ea3948b67dd
|
65869362cd7a2ac74dd1a97c7f9471835726570b
|
refs/heads/master
| 1,680,260,936,332
| 1,616,563,371,000
| 1,616,563,371,000
| 348,780,769
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,656
|
lean
|
import order.filter.basic -- the basics
/-
# Filters
## Introduction
A topological space structure on a type `α` is a collection of subsets of `α`
(the open sets) satisfying some axioms. A filter is a similar kind of thing --
it's a collection of subsets of `α` satisfying some different axioms.
Before we go into the formal definition, let us start with the picture.
A filter on `α` is an extremely powerful generalisation of the concept
of a subset of `α`. If `S : set α` is a subset, then there is a principal
filter `𝓟 S` corresponding to `S` -- it is just the collection of all subsets
of `α` which contain `S`. However there may be other filters on `α`
corresponding to things which are a bit more general than subsets. For example
if `α` is a topological space and `x : α` then there is a filter `𝓝 x`
corresponding to "an infinitesimal neighbourhood of `x`" even if
there is no smallest open set containing `x`. As another example, if `α` has an
ordering then there is a filter of "neighbourhoods of infinity" on `α` even
though there might be no `∞` in `α`.
If `F` is a filter, then you can think of `F` as a generalised kind of
subset `F` of `α`, and you should think of `S ∈ F` as meaning `F ⊆ S`.
Keeping this in mind will help to motivate the axioms below.
## Definition
Here's the formal definition. A filter on `α` is a collection `F` of subsets
of `α` satisfying the following three axioms:
1) `α ∈ F` (in Lean this is written `univ ∈ F` because a distinction is made
between the type `α` and the term `univ : set α` corresponding to `α`)
2) If `S ∈ F` and `S ⊆ T` then `T ∈ F` -- i.e. `F` is "upwards-closed",
3) If `A ∈ F` and `B ∈ F` then `A ∩ B ∈ F` -- i.e. `F` is closed under
binary intersections.
Note that (1) and (3) together imply (and are indeed equivalent to)
the statement that `F` is closed under all finite intersections,
i.e. the intersection of finitely many elements of `F` is in `F`.
Here's the Lean definition:
```
structure filter (α : Type*) :=
(sets : set (set α))
(univ_sets : set.univ ∈ sets)
(sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets)
(inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets)
```
In words, `filter α` is the type of filters on `α`, so to give a filter
on `α` is to give a term `F : filter α` of type `filter α`. To make a term
of type `filter α` you need to give a collection `sets` of subsets of `α`
and then three proofs of the three axioms.
A rather simple example of a filter is the filter of *all* subsets of `α`.
Those of you who have seen definitions of filters in other places (for
example in Bourbaki) might have seen an extra axiom in the definition of a
filter, saying that a filter is not allowed to be the collection of all
subsets of `α`. This turns out to be rather an unnatural axiom, it is like
demanding in ideal theory that if `R` is a ring then `R` is not allowed to be
an ideal of `R`. An advantage of such a definition of an ideal would be that
a maximal ideal of `R` would literally be a maximal element of the ideals
of `R`, but this advantage is outweighed by the disadvantage that the
definition then becomes much less functorial -- e.g. the image of an ideal
along a ring homomorphism might not be an ideal [this is right! The image of Z under Z→Z[x] isn't an ideal], you cannot in general add two
ideals etc). To preserve the functoriality of filters, mathlib does not have
this Bourbaki axiom as an axiom for filters. As a result there are two
"extreme" filters on `α`, namely the one which only contains
`univ` (note that this is forced by `univ_sets`), and then the one we mentioned
above, which contains all subsets of `α`. These two filters are called
`⊥` and `⊤`, although you might be surprised to find out which one is which!
The filter consisting of all subsets of `α` is the one corresponding to
the empty set, so it is `⊥`, and the one consisting of just `univ` is the
one corresponding to the whole of `α` so it is `⊤`.
## Notation, helpful tactics and helpful theorems
We are not going to build filters from first principles, we will be
using Lean's API for filters.
Say `α : Type` and `F : filter α` and `S : set α`. The notation `S ∈ F` is
defined to mean `S ∈ F.sets`.
The `ext` tactic can be used to reduce a goal `F = G` to a goal of
the form `∀ S, S ∈ F ↔ S ∈ G`.
The fields of the structure mention things like `S ∈ F.sets`, so the
axioms are restated with different names, but using the `S ∈ F` notation.
The lemmas corresponding to the definitions are:
`univ_mem_sets : univ ∈ F`
`mem_sets_of_superset : S ∈ F → S ⊆ T → T ∈ F`
`inter_mem_sets : S ∈ F → T ∈ F → S ∩ T ∈ F`
These lemmas in the `filter` namespace, i.e. their full names are
`filter.univ_mem_sets` etc. But we are about to say `open filter`
which means that you don't have to type this `filter.` thing in front of every
lemma you need about filters. In fact we'll also be using a bunch of
stuff about sets, like `set.inter_subset_left`, so why don't we `open set`
as well.
-/
open filter set
-- Variables!
-- let `α` be a type, let `F` be a filter on `α`, and let `S` and `T`
-- denote subsets of `α`.
variables (α : Type) (F : filter α) (S T : set α)
/-
Here's a lemma about filters: Two sets `S` and `T` are both in
a filter `F` iff their intersection is. See if you can deduce
it from the axioms of a filter.
For this one it's useful to know the following results (from the set namespace)
`inter_subset_left S T : S ∩ T ⊆ S`
and
`inter_subset_right S T : S ∩ T ⊆ T`
-/
example : S ∩ T ∈ F ↔ S ∈ F ∧ T ∈ F :=
begin
split, intro h, split;
apply mem_sets_of_superset h,
apply inter_subset_left, apply inter_subset_right,
exact λh, inter_mem_sets h.1 h.2
end
/-
The principal filter `𝓟 X` generated by `X : set α` is the subsets of `α`
which contain `X`. Prove that it's a filter.
Helpful for this exercise:
`mem_univ s : s ∈ univ`
`subset.trans : A ⊆ B → B ⊆ C → A ⊆ C`
`subset_inter : X ⊆ S → X ⊆ T → X ⊆ S ∩ T`
(note that you could probably prove those last two things directly yourself,
but we may as well use the interface for sets given that it's there)
`mem_set_of_eq : x ∈ {a : α | p a} = p x`
(this one is definitional, so you could use `change` instead, or just
not rewrite it at all)
-/
-- this is called `𝓟 X` in mathlib but let's just make it ourselves.
example (X : set α) : filter α :=
{ sets := {S : set α | X ⊆ S},
univ_sets := begin
intros _ _, triv -- or apply mem_univ
end,
sets_of_superset := begin
intros S T h1 h2, exact subset.trans h1 h2
end,
inter_sets := begin
intros S T hS hT, exact subset_inter hS hT
end }
-- The notation for the principal filter generated by `X : set α` is `𝓟 X`.
-- This notation is in the "filter locale", which is just a posh way
-- of saying that you have to type
open_locale filter
-- in order to get the notation.
/-
## The order (≤) on filters
The following is unsurprising: the collection of all filters on `α` is
partially ordered. Perhaps more surprising: the order is the other way
around to what you think it should be! If `F` and `G` are filters
on `α`, then `F ≤ G` is defined to mean that `G.sets ⊆ F.sets`, i.e.
every set in the `G`-filter is also in the `F`-filter. Why is this?
Well, think about principal filters. If `S ⊆ T` are two subsets,
then `X ∈ 𝓟 T` implies `T ⊆ X`, so `S ⊆ X`, so `X ∈ 𝓟 S`.
The smaller the set, the bigger the collection of sets in the filter.
Let's formalise this. Show that 𝓟 S ≤ 𝓟 T ↔ S ⊆ T.
Note that this is called `principal_mono` in mathlib but
there's no harm in proving it yourself.
Some helpful lemmas:
`mem_principal_sets : T ∈ 𝓟 S ↔ S ⊆ T`
`mem_principal_self S : S ∈ 𝓟 S`
`le_def : F ≤ G ↔ ∀ (S : set α), S ∈ G → S ∈ F`
-/
example (S T : set α) : 𝓟 S ≤ 𝓟 T ↔ S ⊆ T :=
begin
rw le_def, split,
intro h, exact h T (subset.refl T),
intros h X hX, exact subset.trans h hX
end
-- Here's another useful lemma about principal filters.
-- It's called `le_principal_iff` in mathlib but why
-- not try proving it yourself?
example : F ≤ 𝓟 S ↔ S ∈ F :=
begin
rw le_def, split,
intro h, exact h S (λ_,id /- or subset.refl S -/),
intros h T hT, exact mem_sets_of_superset h hT
end
/-
## Filters are a complete lattice
Just like it's possible to talk about the topological space generated
by a collection of subsets of `α` -- this is the smallest topology
for which the given subsets are all open -- it's also possible to talk
about the filter generated by a collection of subsets of `α`. One
can define it as the intersection of all the filters that contain your
given collection of subsets.
In order theory, given a partial order (like the partial order on filters)
you can start asking whether infs and sups exist. Filters are an example
where all these things exist (finite and infinite infs and sups) and they
satisfy a natural collection of axioms, making them into what is called a
*complete lattice*. One can prove this by showing that "filter generated by
these sets" and "underlying sets of a filter" are adjoint functors and then
using the theory of Galois insertions. I talked about this a bit when doing
subgroups, and won't talk about it again.
-/
/-
## Other examples of filters.
### `at_top` filter on a totally ordered set
Let `L` be a non-empty totally ordered set. Let's say that a subset `X` of `L` is
"big" if there exists `x : L` such for all `y ≥ x`, `y ∈ X`.
I claim that the big subsets are a filter. Check this. The mathematical idea
is that the "big subsets" are the neighbourhoods of `∞`, so the corresponding
filter is some representation of an infinitesimal neighbourhood of `∞`.
Implementation notes: `linear_order L` is the type of linear orders on `L`.
`e : L` is just an easy way of saying that `L` is nonempty.
Recall that `max x y` is the max of x and y in a `linear_order`, and
`le_max_left a b : a ≤ max a b` and similarly `le_max_right`.
-/
def at_top (L : Type) [linear_order L] (e : L) : filter L :=
{ sets := {X : set L | ∃ x : L, ∀ y, x ≤ y → y ∈ X},
univ_sets := begin
use e, intros y _, triv
end,
sets_of_superset := begin
rintros S T ⟨x,hS⟩ hc, use x, intros y hy, exact hc (hS y hy)
end,
inter_sets := begin
rintros S T ⟨x,hS⟩ ⟨z,hT⟩, use max x z, intros y hy,
split, apply hS, exact le_trans (le_max_left _ _) hy,
apply hT, exact le_trans (le_max_right _ _) hy
end }
/-
### the cofinite filter
The _cofinite filter_ on a type `α` has as its sets the subsets `S : set α`
with the property that `Sᶜ`, the complement of `S`, is finite.
Let's show that these are a filter.
Things you might find helpful:
`compl_univ : univᶜ = ∅`
`finite_empty : finite ∅`
`compl_subset_compl : Xᶜ ⊆ Yᶜ ↔ Y ⊆ X`
`finite.subset : S.finite → ∀ {T : set α}, T ⊆ S → T.finite`
`compl_inter S T : (S ∩ T)ᶜ = Sᶜ ∪ Tᶜ`
`finite.union : S.finite → T.finite → (S ∪ T).finite`
NB if you are thinking "I could never use Lean by myself, I don't know
the names of all the lemmas so I have to rely on Kevin telling them all to
me" then what you don't realise is that I myself don't know the names
of all the lemmas either -- I am literally just guessing them and pressing
ctrl-space to check. Look at the names of the lemmas and begin to understand
that you can probably guess them yourself.
-/
def cofinite (α : Type) : filter α :=
{ sets := { S : set α | (Sᶜ).finite },
univ_sets := begin
dsimp, rw compl_univ, exact finite_empty
end,
sets_of_superset := begin
intros S T hS hc, rw ← compl_subset_compl at hc,
exact finite.subset hS hc
end,
inter_sets := begin
intros S T hS hT, dsimp, rw compl_inter, exact finite.union hS hT
end }
/-
### Exercises (to do on paper):
You don't need to be able to do these in order to move onto the topology part
of this workshop.
(1) prove that the cofinite filter on a finite type is the entire power set filter.
(2) prove that the cofinite filter on `ℕ` is equal to the `at_top` filter.
(3) Prove that the cofinite filter on `ℤ` is not equal to the `at_top` filter.
(4) Prove that the cofinite filter on `ℕ` is not principal.
You can try them in Lean but you will have to be a master of finiteness.
Here, for example, are some of the ideas you'll need to do (4) in Lean.
The proof uses a bunch of lemmas from the set API.
Here are some of the things I used:
`filter.ext_iff : F = G ↔ ∀ (S : set α), s ∈ F ↔ s ∈ G`
Facts about `S \ {a}` and other sets:
`diff_eq_compl_inter`, `compl_inter`, `compl_compl`, `finite_singleton`,
`mem_diff_singleton`.
I also needed the following two lemmas, which weren't in mathlib
so I had to prove them myself (my proof of the first one was longer;
thanks to Yakov Pechersky on Zulip for coming up with the one-liner)
-/
lemma infinite_of_finite_compl {α : Type} [infinite α] {s : set α}
(hs : sᶜ.finite) : s.infinite :=
λ h, infinite_univ (by simpa using hs.union h)
lemma set.infinite.nonempty {α} {s : set α} (h : s.infinite) : ∃ a : α, a ∈ s :=
let a := set.infinite.nat_embedding s h 37 in ⟨a.1, a.2⟩
-- This is also convenient for rewriting purposes:
lemma mem_cofinite {S : set ℕ} : S ∈ cofinite ℕ ↔ Sᶜ.finite :=
begin
-- true by definition
refl
end
-- Here's a proof which I formalised: if natural_cofinite = 𝓟 S then S must
-- be cofinite and hence infinite and hence non-empty, but then if a ∈ S
-- then S \ {a} causes us problems as it's cofinite but doesn't contain `S`.
-- This is harder than anything else in this file and is not necessary
-- for the application to topological spaces in Part B so feel free
-- to skip it.
theorem cofinite_not_principal : ∀ S : set ℕ, cofinite ℕ ≠ 𝓟 S :=
begin
intros S hS, by_cases h : S.nonempty,
{ cases h with x hx,
have : {x}ᶜ ∈ cofinite ℕ,
rw [mem_cofinite, compl_compl], apply finite_singleton,
rw hS at this, exact this hx (mem_singleton x)
/-have : {y : ℕ | y < x.succ}ᶜ ∈ cofinite ℕ,
rw [mem_cofinite, compl_compl],
exact ⟨fin.fintype x.succ⟩,
rw hS at this,
apply this hx,
apply nat.le_refl-/ },
{ have : ∅ ∈ 𝓟 S,
rw not_nonempty_iff_eq_empty at h,
rw h, apply subset.refl,
revert this,
rw [←hS, mem_cofinite, compl_empty],
exact infinite_univ }
end
|
b65b0029beec818a9e2a66b4a7e49be53999ec9c
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/tests/lean/t10.lean
|
8943c5260fd06ba28066cb74662a8c87c6e815dd
|
[
"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
| 582
|
lean
|
constant N : Type.{1}
definition B : Type.{1} := Type.{0}
constant ite : B → N → N → N
constant and : B → B → B
constant f : N → N
constant p : B
constant q : B
constant x : N
constant y : N
constant z : N
infixr `∧`:25 := and
notation `if` c `then` t:45 `else` e:45 := ite c t e
check if p ∧ q then f x else y
check if p ∧ q then q else y
constant list : Type.{1}
constant nil : list
constant cons : N → list → list
-- Non empty lists
notation `[` l:(foldr `,` (h t, cons h t) nil) `]` := l
check [x, y, z, x, y, y]
check [x]
notation `[` `]` := nil
check []
|
48f20bd24d6a37aa4c7cca802d379e87771febef
|
c8af905dcd8475f414868d303b2eb0e9d3eb32f9
|
/examples/enzyme.lean
|
ba5174fcfa0d0231ae34c4036a1fcd8cfc1e2e02
|
[
"BSD-3-Clause"
] |
permissive
|
continuouspi/lean-cpi
|
81480a13842d67ff5f3698643210d8ed5dd08de4
|
443bf2cb236feadc45a01387099c236ab2b78237
|
refs/heads/master
| 1,650,307,316,582
| 1,587,033,364,000
| 1,587,033,364,000
| 207,499,661
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,127
|
lean
|
import .common
open cpi
open cpi.species
open_locale normalise
def k_bind : ℍ := fin_poly.X "k_bind"
def k_degrade : ℍ := fin_poly.X "k_degrade"
def k_unbind : ℍ := fin_poly.X "k_unbind"
def k_react : ℍ := fin_poly.X "k_react"
def aff : affinity ℍ := affinity.mk_pair k_bind -- x, y
def M : affinity ℍ -- u, r, t
:= affinity.mk 3 0 2 k_unbind -- u - t
∘[] affinity.mk 3 1 2 k_react -- r - t
def ω : context := context.extend 0 (context.extend M.arity (context.extend 0 (context.extend 0 context.nil)))
def Γ : context := context.extend aff.arity context.nil
def s : name Γ := name.zero ⟨ 0, nat.succ_pos 1 ⟩
def e : name Γ := name.zero ⟨ 1, lt_add_one 1 ⟩
@[pattern] def S : reference 0 ω := reference.zero 0
@[pattern] def E : reference M.arity ω := reference.extend $ reference.zero M.arity
@[pattern] def P₁ : reference 0 ω := reference.extend ∘ reference.extend $ reference.zero 0
@[pattern] def P₂ : reference 0 ω := reference.extend ∘ reference.extend ∘ reference.extend $ reference.zero 0
def x {Γ} : name (context.extend 2 Γ) := name.zero ⟨ 0, nat.succ_pos 1 ⟩
def y {Γ} : name (context.extend 2 Γ) := name.zero ⟨ 1, lt_add_one 1 ⟩
def u {Γ} : name (context.extend M.arity Γ) := name.zero ⟨ 0, nat.succ_pos 2 ⟩
def r {Γ} : name (context.extend M.arity Γ) := name.zero ⟨ 1, int.coe_nat_lt.mp trivial ⟩
def t {Γ} : name (context.extend M.arity Γ) := name.zero ⟨ 2, lt_add_one 2 ⟩
-- S = s(x, y). (x. S + y. (P|P'))
def Sₛ_ : species ℍ ω Γ :=
s #( 2 ) ⬝ Σ# ( whole.cons (x #) (apply S ∅)
$ whole.cons (y #) (apply P₁ ∅ |ₛ apply P₂ ∅)
$ whole.empty )
def S_ : choices ℍ ω Γ :=
s #( 2 ) ⬝' Σ# ( whole.cons (x #) (apply S ∅)
∘ whole.cons (y #) (apply P₁ ∅ |ₛ apply P₂ ∅)
$ whole.empty )
-- E = ν(u, r, t : M) . e⟨u, r⟩. t. E)
def Eₛ : reference 0 ω := reference.zero 0
def Eₛ_ : species ℍ ω Γ :=
ν(M) (name.extend e #⟨ [u, r] ⟩) ⬝ (name.extend t # ⬝ apply Eₛ ∅)
def E_ : choices ℍ ω (context.extend M.arity Γ) :=
(name.extend e #⟨ [u, r] ⟩) ⬝' (name.extend t # ⬝ ν(M) apply E (u :: r :: t :: ∅))
-- P = P' = τ@k_degrade. 0
def Pₛ_ : species ℍ ω Γ := τ@k_degrade ⬝ nil
def P_ : choices ℍ ω Γ := τ@k_degrade ⬝' nil
def P'_ : species ℍ ω Γ := Σ# P_
def ℓ : lookup ℍ ω Γ
| _ S := species.rename name.extend S_
| _ E := E_
| _ P₁ := species.rename name.extend P_
| _ P₂ := species.rename name.extend P_
| (nat.succ n) (reference.extend (reference.extend a)) := by { cases a, cases a_a, cases a_a_a }
-- S [s]—→ (; x, y) (x.S + y.(P|P'))
example : (Σ# S_) [ℓ, # s]⟶ (production.concretion (#( vector.nil; 2 )
Σ# ( whole.cons (x#) (apply S ∅)
∘ whole.cons (y#) (apply P₁ ∅ |ₛ apply P₂ ∅)
$ whole.empty )))
:= transition.choice₁ _ _ _ _ _ _
-- P₁ [τ@k_degrade]⟶ 0
example : P'_ [ℓ, τ@' k_degrade]⟶ (production.species nil)
:= transition.choice₂ k_degrade whole.nil whole.empty
/- Various intermediates -/
def E'_ {Γ} : species ℍ ω Γ := ν(M) apply E (u :: r :: t :: ∅)
def C'_ : species ℍ ω Γ :=
ν(M) ( ( Σ# ( whole.cons (u#) (apply S ∅)
$ whole.cons (r#) (apply P₁ ∅ |ₛ apply P₂ ∅)
$ whole.empty ) )
|ₛ t# ⬝ E'_)
#eval process_immediate aff ℓ conc ((2 : ℂ) ◯ E'_ |ₚ 2 ◯ (apply S ∅) )
def system : process ℂ ℍ ω Γ :=
fin_poly.X "S" ◯ (apply S ∅) |ₚ
fin_poly.X "E" ◯ E'_ |ₚ
fin_poly.X "S" ◯ C'_ |ₚ
fin_poly.X "P₁" ◯ (apply P₁ ∅) |ₚ
fin_poly.X "P₂" ◯ (apply P₂ ∅)
#eval process_immediate aff ℓ conc system
/-
-- Run the result of the above through enzyme.py
(-1•(E•S•k_bind) + 1•(S•k_react) + 1•(S•k_unbind)) • E
(-1•(E•S•k_bind) + 1•(S•k_unbind)) • S
(-1•(P₁•k_degrade) + 1•(S•k_react)) • P₁
(-1•(P₂•k_degrade) + 1•(S•k_react)) • P₂
(-1•(S•k_react) + -1•(S•k_unbind) + 1•(E•S•k_bind)) • C
-/
|
52e410a2a4cecd67141598ecc6005420d1e06368
|
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
|
/src/category_theory/limits/shapes/constructions/over/connected.lean
|
934d04b9d266a35176fff0503496ec21f8658e0c
|
[
"Apache-2.0"
] |
permissive
|
dupuisf/mathlib
|
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
|
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
|
refs/heads/master
| 1,669,494,854,016
| 1,595,692,409,000
| 1,595,692,409,000
| 272,046,630
| 0
| 0
|
Apache-2.0
| 1,592,066,143,000
| 1,592,066,142,000
| null |
UTF-8
|
Lean
| false
| false
| 2,668
|
lean
|
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import category_theory.over
import category_theory.limits.connected
import category_theory.limits.creates
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
open category_theory category_theory.limits
variables {J : Type v} [small_category J]
variables {C : Type u} [category.{v} C]
variable {X : C}
namespace category_theory.over
namespace creates_connected
/--
(Impl) Given a diagram in the over category, produce a natural transformation from the
diagram legs to the specific object.
-/
def nat_trans_in_over {B : C} (F : J ⥤ over B) :
F ⋙ forget ⟶ (category_theory.functor.const J).obj B :=
{ app := λ j, (F.obj j).hom }
local attribute [tidy] tactic.case_bash
/--
(Impl) Given a cone in the base category, raise it to a cone in the over category. Note this is
where the connected assumption is used.
-/
@[simps]
def raise_cone [connected J] {B : C} {F : J ⥤ over B} (c : cone (F ⋙ forget)) :
cone F :=
{ X := over.mk (c.π.app (default J) ≫ (F.obj (default J)).hom),
π :=
{ app := λ j, over.hom_mk (c.π.app j) (nat_trans_from_connected (c.π ≫ nat_trans_in_over F) j) } }
lemma raised_cone_lowers_to_original [connected J] {B : C} {F : J ⥤ over B}
(c : cone (F ⋙ forget)) (t : is_limit c) :
forget.map_cone (raise_cone c) = c :=
by tidy
/-- (Impl) Show that the raised cone is a limit. -/
def raised_cone_is_limit [connected J] {B : C} {F : J ⥤ over B} {c : cone (F ⋙ forget)} (t : is_limit c) :
is_limit (raise_cone c) :=
{ lift := λ s, over.hom_mk (t.lift (forget.map_cone s))
(by { dsimp, simp }),
uniq' := λ s m K, by { ext1, apply t.hom_ext, intro j, simp [← K j] } }
end creates_connected
/-- The forgetful functor from the over category creates any connected limit. -/
instance forget_creates_connected_limits [connected J] {B : C} : creates_limits_of_shape J (forget : over B ⥤ C) :=
{ creates_limit := λ K,
creates_limit_of_reflects_iso (λ c t,
{ lifted_cone := creates_connected.raise_cone c,
valid_lift := eq_to_iso (creates_connected.raised_cone_lowers_to_original c t),
makes_limit := creates_connected.raised_cone_is_limit t } ) }
/-- The over category has any connected limit which the original category has. -/
instance has_connected_limits {B : C} [connected J] [has_limits_of_shape J C] : has_limits_of_shape J (over B) :=
{ has_limit := λ F, has_limit_of_created F (forget : over B ⥤ C) }
end category_theory.over
|
63eb1fa3c0838575435fc19ed200c47ea7f6543b
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/finset/basic.lean
|
a9d02b47de16fb3d6549b5f497581b81b5b913c6
|
[
"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
| 124,204
|
lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import data.multiset.finset_ops
import tactic.monotonicity
import tactic.apply
import tactic.nth_rewrite
/-!
# Finite sets
Terms of type `finset α` are one way of talking about finite subsets of `α` in mathlib.
Below, `finset α` is defined as a structure with 2 fields:
1. `val` is a `multiset α` of elements;
2. `nodup` is a proof that `val` has no duplicates.
Finsets in Lean are constructive in that they have an underlying `list` that enumerates their
elements. In particular, any function that uses the data of the underlying list cannot depend on its
ordering. This is handled on the `multiset` level by multiset API, so in most cases one needn't
worry about it explicitly.
Finsets give a basic foundation for defining finite sums and products over types:
1. `∑ i in (s : finset α), f i`;
2. `∏ i in (s : finset α), f i`.
Lean refers to these operations as `big_operator`s.
More information can be found in `algebra.big_operators.basic`.
Finsets are directly used to define fintypes in Lean.
A `fintype α` instance for a type `α` consists of
a universal `finset α` containing every term of `α`, called `univ`. See `data.fintype.basic`.
There is also `univ'`, the noncomputable partner to `univ`,
which is defined to be `α` as a finset if `α` is finite,
and the empty finset otherwise. See `data.fintype.basic`.
## Main declarations
### Main definitions
* `finset`: Defines a type for the finite subsets of `α`.
Constructing a `finset` requires two pieces of data: `val`, a `multiset α` of elements,
and `nodup`, a proof that `val` has no duplicates.
* `finset.has_mem`: Defines membership `a ∈ (s : finset α)`.
* `finset.has_coe`: Provides a coercion `s : finset α` to `s : set α`.
* `finset.has_coe_to_sort`: Coerce `s : finset α` to the type of all `x ∈ s`.
* `finset.induction_on`: Induction on finsets. To prove a proposition about an arbitrary `finset α`,
it suffices to prove it for the empty finset, and to show that if it holds for some `finset α`,
then it holds for the finset obtained by inserting a new element.
* `finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
* `finset.card`: `card s : ℕ` returns the cardinalilty of `s : finset α`.
The API for `card`'s interaction with operations on finsets is extensive.
TODO: The noncomputable sister `fincard` is about to be added into mathlib.
### Finset constructions
* `singleton`: Denoted by `{a}`; the finset consisting of one element.
* `finset.empty`: Denoted by `∅`. The finset associated to any type consisting of no elements.
* `finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`.
This convention is consistent with other languages and normalizes `card (range n) = n`.
Beware, `n` is not in `range n`.
* `finset.diag`: Given `s`, `diag s` is the set of pairs `(a, a)` with `a ∈ s`. See also
`finset.off_diag`: Given a finite set `s`, the off-diagonal,
`s.off_diag` is the set of pairs `(a, b)` with `a ≠ b` for `a, b ∈ s`.
* `finset.attach`: Given `s : finset α`, `attach s` forms a finset of elements of the subtype
`{a // a ∈ s}`; in other words, it attaches elements to a proof of membership in the set.
### Finsets from functions
* `finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`.
* `finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`.
* `finset.filter`: Given a predicate `p : α → Prop`, `s.filter p` is
the finset consisting of those elements in `s` satisfying the predicate `p`.
### The lattice structure on subsets of finsets
There is a natural lattice structure on the subsets of a set.
In Lean, we use lattice notation to talk about things involving unions and intersections. See
`order.lattice`. For the lattice structure on finsets, `⊥` is called `bot` with `⊥ = ∅` and `⊤` is
called `top` with `⊤ = univ`.
* `finset.subset`: Lots of API about lattices, otherwise behaves exactly as one would expect.
* `finset.union`: Defines `s ∪ t` (or `s ⊔ t`) as the union of `s` and `t`.
See `finset.bUnion` for finite unions.
* `finset.inter`: Defines `s ∩ t` (or `s ⊓ t`) as the intersection of `s` and `t`.
TODO: `finset.bInter` for finite intersections.
* `finset.disj_union`: Given a hypothesis `h` which states that finsets `s` and `t` are disjoint,
`s.disj_union t h` is the set such that `a ∈ disj_union s t h` iff `a ∈ s` or `a ∈ t`; this does
not require decidable equality on the type `α`.
### Operations on two or more finsets
* `finset.insert` and `finset.cons`: For any `a : α`, `insert s a` returns `s ∪ {a}`. `cons s a h`
returns the same except that it requires a hypothesis stating that `a` is not already in `s`.
This does not require decidable equality on the type `α`.
* `finset.union`: see "The lattice structure on subsets of finsets"
* `finset.inter`: see "The lattice structure on subsets of finsets"
* `finset.erase`: For any `a : α`, `erase s a` returns `s` with the element `a` removed.
* `finset.sdiff`: Defines the set difference `s \ t` for finsets `s` and `t`.
* `finset.prod`: Given finsets of `α` and `β`, defines finsets of `α × β`.
For arbitrary dependent products, see `data.finset.pi`.
* `finset.sigma`: Given finsets of `α` and `β`, defines finsets of the dependent sum type `Σ α, β`
* `finset.bUnion`: Finite unions of finsets; given an indexing function `f : α → finset β` and a
`s : finset α`, `s.bUnion f` is the union of all finsets of the form `f a` for `a ∈ s`.
* `finset.bInter`: TODO: Implemement finite intersections.
### Maps constructed using finsets
* `finset.piecewise`: Given two functions `f`, `g`, `s.piecewise f g` is a function which is equal
to `f` on `s` and `g` on the complement.
### Predicates on finsets
* `disjoint`: defined via the lattice structure on finsets; two sets are disjoint if their
intersection is empty.
* `finset.nonempty`: A finset is nonempty if it has elements.
This is equivalent to saying `s ≠ ∅`. TODO: Decide on the simp normal form.
### Equivalences between finsets
* The `data.equiv` files describe a general type of equivalence, so look in there for any lemmas.
There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`.
TODO: examples
## Tags
finite sets, finset
-/
open multiset subtype nat function
variables {α : Type*} {β : Type*} {γ : Type*}
/-- `finset α` is the type of finite sets of elements of `α`. It is implemented
as a multiset (a list up to permutation) which has no duplicate elements. -/
structure finset (α : Type*) :=
(val : multiset α)
(nodup : nodup val)
namespace finset
theorem eq_of_veq : ∀ {s t : finset α}, s.1 = t.1 → s = t
| ⟨s, _⟩ ⟨t, _⟩ rfl := rfl
@[simp] theorem val_inj {s t : finset α} : s.1 = t.1 ↔ s = t :=
⟨eq_of_veq, congr_arg _⟩
@[simp] theorem erase_dup_eq_self [decidable_eq α] (s : finset α) : erase_dup s.1 = s.1 :=
erase_dup_eq_self.2 s.2
instance has_decidable_eq [decidable_eq α] : decidable_eq (finset α)
| s₁ s₂ := decidable_of_iff _ val_inj
/-! ### membership -/
instance : has_mem α (finset α) := ⟨λ a s, a ∈ s.1⟩
theorem mem_def {a : α} {s : finset α} : a ∈ s ↔ a ∈ s.1 := iff.rfl
@[simp] theorem mem_mk {a : α} {s nd} : a ∈ @finset.mk α s nd ↔ a ∈ s := iff.rfl
instance decidable_mem [h : decidable_eq α] (a : α) (s : finset α) : decidable (a ∈ s) :=
multiset.decidable_mem _ _
/-! ### set coercion -/
/-- Convert a finset to a set in the natural way. -/
instance : has_coe_t (finset α) (set α) := ⟨λ s, {x | x ∈ s}⟩
@[simp, norm_cast] lemma mem_coe {a : α} {s : finset α} : a ∈ (s : set α) ↔ a ∈ s := iff.rfl
@[simp] lemma set_of_mem {α} {s : finset α} : {a | a ∈ s} = s := rfl
@[simp] lemma coe_mem {s : finset α} (x : (s : set α)) : ↑x ∈ s := x.2
@[simp] lemma mk_coe {s : finset α} (x : (s : set α)) {h} :
(⟨x, h⟩ : (s : set α)) = x :=
subtype.coe_eta _ _
instance decidable_mem' [decidable_eq α] (a : α) (s : finset α) :
decidable (a ∈ (s : set α)) := s.decidable_mem _
/-! ### extensionality -/
theorem ext_iff {s₁ s₂ : finset α} : s₁ = s₂ ↔ ∀ a, a ∈ s₁ ↔ a ∈ s₂ :=
val_inj.symm.trans $ nodup_ext s₁.2 s₂.2
@[ext]
theorem ext {s₁ s₂ : finset α} : (∀ a, a ∈ s₁ ↔ a ∈ s₂) → s₁ = s₂ :=
ext_iff.2
@[simp, norm_cast] theorem coe_inj {s₁ s₂ : finset α} : (s₁ : set α) = s₂ ↔ s₁ = s₂ :=
set.ext_iff.trans ext_iff.symm
lemma coe_injective {α} : injective (coe : finset α → set α) :=
λ s t, coe_inj.1
/-! ### type coercion -/
/-- Coercion from a finset to the corresponding subtype. -/
instance {α : Type*} : has_coe_to_sort (finset α) := ⟨_, λ s, {x // x ∈ s}⟩
instance pi_finset_coe.can_lift (ι : Type*) (α : Π i : ι, Type*) [ne : Π i, nonempty (α i)]
(s : finset ι) :
can_lift (Π i : s, α i) (Π i, α i) :=
{ coe := λ f i, f i,
.. pi_subtype.can_lift ι α (∈ s) }
instance pi_finset_coe.can_lift' (ι α : Type*) [ne : nonempty α] (s : finset ι) :
can_lift (s → α) (ι → α) :=
pi_finset_coe.can_lift ι (λ _, α) s
instance finset_coe.can_lift (s : finset α) : can_lift α s :=
{ coe := coe,
cond := λ a, a ∈ s,
prf := λ a ha, ⟨⟨a, ha⟩, rfl⟩ }
@[simp, norm_cast] lemma coe_sort_coe (s : finset α) :
((s : set α) : Sort*) = s := rfl
/-! ### subset -/
instance : has_subset (finset α) := ⟨λ s₁ s₂, ∀ ⦃a⦄, a ∈ s₁ → a ∈ s₂⟩
theorem subset_def {s₁ s₂ : finset α} : s₁ ⊆ s₂ ↔ s₁.1 ⊆ s₂.1 := iff.rfl
@[simp] theorem subset.refl (s : finset α) : s ⊆ s := subset.refl _
theorem subset_of_eq {s t : finset α} (h : s = t) : s ⊆ t := h ▸ subset.refl _
theorem subset.trans {s₁ s₂ s₃ : finset α} : s₁ ⊆ s₂ → s₂ ⊆ s₃ → s₁ ⊆ s₃ := subset.trans
theorem superset.trans {s₁ s₂ s₃ : finset α} : s₁ ⊇ s₂ → s₂ ⊇ s₃ → s₁ ⊇ s₃ :=
λ h' h, subset.trans h h'
-- TODO: these should be global attributes, but this will require fixing other files
local attribute [trans] subset.trans superset.trans
theorem mem_of_subset {s₁ s₂ : finset α} {a : α} : s₁ ⊆ s₂ → a ∈ s₁ → a ∈ s₂ := mem_of_subset
theorem subset.antisymm {s₁ s₂ : finset α} (H₁ : s₁ ⊆ s₂) (H₂ : s₂ ⊆ s₁) : s₁ = s₂ :=
ext $ λ a, ⟨@H₁ a, @H₂ a⟩
theorem subset_iff {s₁ s₂ : finset α} : s₁ ⊆ s₂ ↔ ∀ ⦃x⦄, x ∈ s₁ → x ∈ s₂ := iff.rfl
@[simp, norm_cast] theorem coe_subset {s₁ s₂ : finset α} :
(s₁ : set α) ⊆ s₂ ↔ s₁ ⊆ s₂ := iff.rfl
@[simp] theorem val_le_iff {s₁ s₂ : finset α} : s₁.1 ≤ s₂.1 ↔ s₁ ⊆ s₂ := le_iff_subset s₁.2
instance : has_ssubset (finset α) := ⟨λa b, a ⊆ b ∧ ¬ b ⊆ a⟩
instance : partial_order (finset α) :=
{ le := (⊆),
lt := (⊂),
le_refl := subset.refl,
le_trans := @subset.trans _,
le_antisymm := @subset.antisymm _ }
theorem subset.antisymm_iff {s₁ s₂ : finset α} : s₁ = s₂ ↔ s₁ ⊆ s₂ ∧ s₂ ⊆ s₁ :=
le_antisymm_iff
@[simp] theorem le_eq_subset : ((≤) : finset α → finset α → Prop) = (⊆) := rfl
@[simp] theorem lt_eq_subset : ((<) : finset α → finset α → Prop) = (⊂) := rfl
theorem le_iff_subset {s₁ s₂ : finset α} : s₁ ≤ s₂ ↔ s₁ ⊆ s₂ := iff.rfl
theorem lt_iff_ssubset {s₁ s₂ : finset α} : s₁ < s₂ ↔ s₁ ⊂ s₂ := iff.rfl
@[simp, norm_cast] lemma coe_ssubset {s₁ s₂ : finset α} : (s₁ : set α) ⊂ s₂ ↔ s₁ ⊂ s₂ :=
show (s₁ : set α) ⊂ s₂ ↔ s₁ ⊆ s₂ ∧ ¬s₂ ⊆ s₁,
by simp only [set.ssubset_def, finset.coe_subset]
@[simp] theorem val_lt_iff {s₁ s₂ : finset α} : s₁.1 < s₂.1 ↔ s₁ ⊂ s₂ :=
and_congr val_le_iff $ not_congr val_le_iff
lemma ssubset_iff_subset_ne {s t : finset α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne _ _ s t
theorem ssubset_iff_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁ ⊂ s₂ ↔ ∃ x ∈ s₂, x ∉ s₁ :=
set.ssubset_iff_of_subset h
lemma ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : finset α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) :
s₁ ⊂ s₃ :=
set.ssubset_of_ssubset_of_subset hs₁s₂ hs₂s₃
lemma ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : finset α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) :
s₁ ⊂ s₃ :=
set.ssubset_of_subset_of_ssubset hs₁s₂ hs₂s₃
lemma exists_of_ssubset {s₁ s₂ : finset α} (h : s₁ ⊂ s₂) :
∃ x ∈ s₂, x ∉ s₁ :=
set.exists_of_ssubset h
/-! ### Nonempty -/
/-- The property `s.nonempty` expresses the fact that the finset `s` is not empty. It should be used
in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks
to the dot notation. -/
protected def nonempty (s : finset α) : Prop := ∃ x:α, x ∈ s
@[simp, norm_cast] lemma coe_nonempty {s : finset α} : (s:set α).nonempty ↔ s.nonempty := iff.rfl
lemma nonempty.bex {s : finset α} (h : s.nonempty) : ∃ x:α, x ∈ s := h
lemma nonempty.mono {s t : finset α} (hst : s ⊆ t) (hs : s.nonempty) : t.nonempty :=
set.nonempty.mono hst hs
lemma nonempty.forall_const {s : finset α} (h : s.nonempty) {p : Prop} : (∀ x ∈ s, p) ↔ p :=
let ⟨x, hx⟩ := h in ⟨λ h, h x hx, λ h x hx, h⟩
/-! ### empty -/
/-- The empty finset -/
protected def empty : finset α := ⟨0, nodup_zero⟩
instance : has_emptyc (finset α) := ⟨finset.empty⟩
instance inhabited_finset : inhabited (finset α) := ⟨∅⟩
@[simp] theorem empty_val : (∅ : finset α).1 = 0 := rfl
@[simp] theorem not_mem_empty (a : α) : a ∉ (∅ : finset α) := id
@[simp] theorem not_nonempty_empty : ¬(∅ : finset α).nonempty :=
λ ⟨x, hx⟩, not_mem_empty x hx
@[simp] theorem mk_zero : (⟨0, nodup_zero⟩ : finset α) = ∅ := rfl
theorem ne_empty_of_mem {a : α} {s : finset α} (h : a ∈ s) : s ≠ ∅ :=
λ e, not_mem_empty a $ e ▸ h
theorem nonempty.ne_empty {s : finset α} (h : s.nonempty) : s ≠ ∅ :=
exists.elim h $ λ a, ne_empty_of_mem
@[simp] theorem empty_subset (s : finset α) : ∅ ⊆ s := zero_subset _
theorem eq_empty_of_forall_not_mem {s : finset α} (H : ∀x, x ∉ s) : s = ∅ :=
eq_of_veq (eq_zero_of_forall_not_mem H)
lemma eq_empty_iff_forall_not_mem {s : finset α} : s = ∅ ↔ ∀ x, x ∉ s :=
⟨by rintro rfl x; exact id, λ h, eq_empty_of_forall_not_mem h⟩
@[simp] theorem val_eq_zero {s : finset α} : s.1 = 0 ↔ s = ∅ := @val_inj _ s ∅
theorem subset_empty {s : finset α} : s ⊆ ∅ ↔ s = ∅ := subset_zero.trans val_eq_zero
theorem nonempty_of_ne_empty {s : finset α} (h : s ≠ ∅) : s.nonempty :=
exists_mem_of_ne_zero (mt val_eq_zero.1 h)
theorem nonempty_iff_ne_empty {s : finset α} : s.nonempty ↔ s ≠ ∅ :=
⟨nonempty.ne_empty, nonempty_of_ne_empty⟩
@[simp] theorem not_nonempty_iff_eq_empty {s : finset α} : ¬s.nonempty ↔ s = ∅ :=
by { rw nonempty_iff_ne_empty, exact not_not, }
theorem eq_empty_or_nonempty (s : finset α) : s = ∅ ∨ s.nonempty :=
classical.by_cases or.inl (λ h, or.inr (nonempty_of_ne_empty h))
@[simp, norm_cast] lemma coe_empty : ((∅ : finset α) : set α) = ∅ := rfl
@[simp, norm_cast] lemma coe_eq_empty {s : finset α} :
(s : set α) = ∅ ↔ s = ∅ :=
by rw [← coe_empty, coe_inj]
/-- A `finset` for an empty type is empty. -/
lemma eq_empty_of_is_empty [is_empty α] (s : finset α) : s = ∅ :=
finset.eq_empty_of_forall_not_mem is_empty_elim
/-- A `finset` for an empty type is empty. -/
lemma eq_empty_of_not_nonempty (h : ¬ nonempty α) (s : finset α) : s = ∅ :=
finset.eq_empty_of_forall_not_mem $ λ x, false.elim $ not_nonempty_iff_imp_false.1 h x
/-! ### singleton -/
/--
`{a} : finset a` is the set `{a}` containing `a` and nothing else.
This differs from `insert a ∅` in that it does not require a `decidable_eq` instance for `α`.
-/
instance : has_singleton α (finset α) := ⟨λ a, ⟨{a}, nodup_singleton a⟩⟩
@[simp] theorem singleton_val (a : α) : ({a} : finset α).1 = a ::ₘ 0 := rfl
@[simp] theorem mem_singleton {a b : α} : b ∈ ({a} : finset α) ↔ b = a := mem_singleton
theorem not_mem_singleton {a b : α} : a ∉ ({b} : finset α) ↔ a ≠ b := not_congr mem_singleton
theorem mem_singleton_self (a : α) : a ∈ ({a} : finset α) := or.inl rfl
theorem singleton_inj {a b : α} : ({a} : finset α) = {b} ↔ a = b :=
⟨λ h, mem_singleton.1 (h ▸ mem_singleton_self _), congr_arg _⟩
@[simp] theorem singleton_nonempty (a : α) : ({a} : finset α).nonempty := ⟨a, mem_singleton_self a⟩
@[simp] theorem singleton_ne_empty (a : α) : ({a} : finset α) ≠ ∅ := (singleton_nonempty a).ne_empty
@[simp, norm_cast] lemma coe_singleton (a : α) : (({a} : finset α) : set α) = {a} :=
by { ext, simp }
lemma eq_singleton_iff_unique_mem {s : finset α} {a : α} :
s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a :=
begin
split; intro t,
rw t,
refine ⟨finset.mem_singleton_self _, λ _, finset.mem_singleton.1⟩,
ext, rw finset.mem_singleton,
refine ⟨t.right _, λ r, r.symm ▸ t.left⟩
end
lemma eq_singleton_iff_nonempty_unique_mem {s : finset α} {a : α} :
s = {a} ↔ s.nonempty ∧ ∀ x ∈ s, x = a :=
begin
split,
{ intros h, subst h, simp, },
{ rintros ⟨hne, h_uniq⟩, rw eq_singleton_iff_unique_mem, refine ⟨_, h_uniq⟩,
rw ← h_uniq hne.some hne.some_spec, apply hne.some_spec, },
end
lemma singleton_iff_unique_mem (s : finset α) : (∃ a, s = {a}) ↔ ∃! a, a ∈ s :=
by simp only [eq_singleton_iff_unique_mem, exists_unique]
lemma singleton_subset_set_iff {s : set α} {a : α} :
↑({a} : finset α) ⊆ s ↔ a ∈ s :=
by rw [coe_singleton, set.singleton_subset_iff]
@[simp] lemma singleton_subset_iff {s : finset α} {a : α} :
{a} ⊆ s ↔ a ∈ s :=
singleton_subset_set_iff
@[simp] lemma subset_singleton_iff {s : finset α} {a : α} : s ⊆ {a} ↔ s = ∅ ∨ s = {a} :=
begin
split,
{ intro hs,
apply or.imp_right _ s.eq_empty_or_nonempty,
rintro ⟨t, ht⟩,
apply subset.antisymm hs,
rwa [singleton_subset_iff, ←mem_singleton.1 (hs ht)] },
rintro (rfl | rfl),
{ exact empty_subset _ },
exact subset.refl _,
end
@[simp] lemma ssubset_singleton_iff {s : finset α} {a : α} :
s ⊂ {a} ↔ s = ∅ :=
by rw [←coe_ssubset, coe_singleton, set.ssubset_singleton_iff, coe_eq_empty]
lemma eq_empty_of_ssubset_singleton {s : finset α} {x : α} (hs : s ⊂ {x}) : s = ∅ :=
ssubset_singleton_iff.1 hs
/-! ### cons -/
/-- `cons a s h` is the set `{a} ∪ s` containing `a` and the elements of `s`. It is the same as
`insert a s` when it is defined, but unlike `insert a s` it does not require `decidable_eq α`,
and the union is guaranteed to be disjoint. -/
def cons {α} (a : α) (s : finset α) (h : a ∉ s) : finset α :=
⟨a ::ₘ s.1, multiset.nodup_cons.2 ⟨h, s.2⟩⟩
@[simp] theorem mem_cons {α a s h b} : b ∈ @cons α a s h ↔ b = a ∨ b ∈ s :=
by rcases s with ⟨⟨s⟩⟩; apply list.mem_cons_iff
@[simp] theorem cons_val {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).1 = a ::ₘ s.1 := rfl
@[simp] theorem mk_cons {a : α} {s : multiset α} (h : (a ::ₘ s).nodup) :
(⟨a ::ₘ s, h⟩ : finset α) = cons a ⟨s, (multiset.nodup_cons.1 h).2⟩ (multiset.nodup_cons.1 h).1 :=
rfl
@[simp] theorem nonempty_cons {a : α} {s : finset α} (h : a ∉ s) : (cons a s h).nonempty :=
⟨a, mem_cons.2 (or.inl rfl)⟩
@[simp] lemma nonempty_mk_coe : ∀ {l : list α} {hl}, (⟨↑l, hl⟩ : finset α).nonempty ↔ l ≠ []
| [] hl := by simp
| (a::l) hl := by simp [← multiset.cons_coe]
/-! ### disjoint union -/
/-- `disj_union s t h` is the set such that `a ∈ disj_union s t h` iff `a ∈ s` or `a ∈ t`.
It is the same as `s ∪ t`, but it does not require decidable equality on the type. The hypothesis
ensures that the sets are disjoint. -/
def disj_union {α} (s t : finset α) (h : ∀ a ∈ s, a ∉ t) : finset α :=
⟨s.1 + t.1, multiset.nodup_add.2 ⟨s.2, t.2, h⟩⟩
@[simp] theorem mem_disj_union {α s t h a} :
a ∈ @disj_union α s t h ↔ a ∈ s ∨ a ∈ t :=
by rcases s with ⟨⟨s⟩⟩; rcases t with ⟨⟨t⟩⟩; apply list.mem_append
/-! ### insert -/
section decidable_eq
variables [decidable_eq α]
/-- `insert a s` is the set `{a} ∪ s` containing `a` and the elements of `s`. -/
instance : has_insert α (finset α) := ⟨λ a s, ⟨_, nodup_ndinsert a s.2⟩⟩
theorem insert_def (a : α) (s : finset α) : insert a s = ⟨_, nodup_ndinsert a s.2⟩ := rfl
@[simp] theorem insert_val (a : α) (s : finset α) : (insert a s).1 = ndinsert a s.1 := rfl
theorem insert_val' (a : α) (s : finset α) : (insert a s).1 = erase_dup (a ::ₘ s.1) :=
by rw [erase_dup_cons, erase_dup_eq_self]; refl
theorem insert_val_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : (insert a s).1 = a ::ₘ s.1 :=
by rw [insert_val, ndinsert_of_not_mem h]
@[simp] theorem mem_insert {a b : α} {s : finset α} : a ∈ insert b s ↔ a = b ∨ a ∈ s := mem_ndinsert
theorem mem_insert_self (a : α) (s : finset α) : a ∈ insert a s := mem_ndinsert_self a s.1
theorem mem_insert_of_mem {a b : α} {s : finset α} (h : a ∈ s) : a ∈ insert b s :=
mem_ndinsert_of_mem h
theorem mem_of_mem_insert_of_ne {a b : α} {s : finset α} (h : b ∈ insert a s) : b ≠ a → b ∈ s :=
(mem_insert.1 h).resolve_left
@[simp] theorem cons_eq_insert {α} [decidable_eq α] (a s h) : @cons α a s h = insert a s :=
ext $ λ a, by simp
@[simp, norm_cast] lemma coe_insert (a : α) (s : finset α) :
↑(insert a s) = (insert a s : set α) :=
set.ext $ λ x, by simp only [mem_coe, mem_insert, set.mem_insert_iff]
lemma mem_insert_coe {s : finset α} {x y : α} : x ∈ insert y s ↔ x ∈ insert y (s : set α) :=
by simp
instance : is_lawful_singleton α (finset α) := ⟨λ a, by { ext, simp }⟩
@[simp] theorem insert_eq_of_mem {a : α} {s : finset α} (h : a ∈ s) : insert a s = s :=
eq_of_veq $ ndinsert_of_mem h
@[simp] theorem insert_singleton_self_eq (a : α) : ({a, a} : finset α) = {a} :=
insert_eq_of_mem $ mem_singleton_self _
theorem insert.comm (a b : α) (s : finset α) : insert a (insert b s) = insert b (insert a s) :=
ext $ λ x, by simp only [mem_insert, or.left_comm]
theorem insert_singleton_comm (a b : α) : ({a, b} : finset α) = {b, a} :=
begin
ext,
simp [or.comm]
end
@[simp] theorem insert_idem (a : α) (s : finset α) : insert a (insert a s) = insert a s :=
ext $ λ x, by simp only [mem_insert, or.assoc.symm, or_self]
@[simp] theorem insert_nonempty (a : α) (s : finset α) : (insert a s).nonempty :=
⟨a, mem_insert_self a s⟩
@[simp] theorem insert_ne_empty (a : α) (s : finset α) : insert a s ≠ ∅ :=
(insert_nonempty a s).ne_empty
section
universe u
/-!
The universe annotation is required for the following instance, possibly this is a bug in Lean. See
leanprover.zulipchat.com/#narrow/stream/113488-general/topic/strange.20error.20(universe.20issue.3F)
-/
instance {α : Type u} [decidable_eq α] (i : α) (s : finset α) :
nonempty.{u + 1} ((insert i s : finset α) : set α) :=
(finset.coe_nonempty.mpr (s.insert_nonempty i)).to_subtype
end
lemma ne_insert_of_not_mem (s t : finset α) {a : α} (h : a ∉ s) :
s ≠ insert a t :=
by { contrapose! h, simp [h] }
theorem insert_subset {a : α} {s t : finset α} : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t :=
by simp only [subset_iff, mem_insert, forall_eq, or_imp_distrib, forall_and_distrib]
theorem subset_insert (a : α) (s : finset α) : s ⊆ insert a s :=
λ b, mem_insert_of_mem
theorem insert_subset_insert (a : α) {s t : finset α} (h : s ⊆ t) : insert a s ⊆ insert a t :=
insert_subset.2 ⟨mem_insert_self _ _, subset.trans h (subset_insert _ _)⟩
lemma ssubset_iff {s t : finset α} : s ⊂ t ↔ (∃a ∉ s, insert a s ⊆ t) :=
by exact_mod_cast @set.ssubset_iff_insert α s t
lemma ssubset_insert {s : finset α} {a : α} (h : a ∉ s) : s ⊂ insert a s :=
ssubset_iff.mpr ⟨a, h, subset.refl _⟩
@[elab_as_eliminator]
lemma cons_induction {α : Type*} {p : finset α → Prop}
(h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α} (h : a ∉ s), p s → p (cons a s h)) : ∀ s, p s
| ⟨s, nd⟩ := multiset.induction_on s (λ _, h₁) (λ a s IH nd, begin
cases nodup_cons.1 nd with m nd',
rw [← (eq_of_veq _ : cons a (finset.mk s _) m = ⟨a ::ₘ s, nd⟩)],
{ exact h₂ (by exact m) (IH nd') },
{ rw [cons_val] }
end) nd
@[elab_as_eliminator]
lemma cons_induction_on {α : Type*} {p : finset α → Prop} (s : finset α)
(h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α} (h : a ∉ s), p s → p (cons a s h)) : p s :=
cons_induction h₁ h₂ s
@[elab_as_eliminator]
protected theorem induction {α : Type*} {p : finset α → Prop} [decidable_eq α]
(h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α}, a ∉ s → p s → p (insert a s)) : ∀ s, p s :=
cons_induction h₁ $ λ a s ha, (s.cons_eq_insert a ha).symm ▸ h₂ ha
/--
To prove a proposition about an arbitrary `finset α`,
it suffices to prove it for the empty `finset`,
and to show that if it holds for some `finset α`,
then it holds for the `finset` obtained by inserting a new element.
-/
@[elab_as_eliminator]
protected theorem induction_on {α : Type*} {p : finset α → Prop} [decidable_eq α]
(s : finset α) (h₁ : p ∅) (h₂ : ∀ ⦃a : α⦄ {s : finset α}, a ∉ s → p s → p (insert a s)) : p s :=
finset.induction h₁ h₂ s
/--
To prove a proposition about `S : finset α`,
it suffices to prove it for the empty `finset`,
and to show that if it holds for some `finset α ⊆ S`,
then it holds for the `finset` obtained by inserting a new element of `S`.
-/
@[elab_as_eliminator]
theorem induction_on' {α : Type*} {p : finset α → Prop} [decidable_eq α]
(S : finset α) (h₁ : p ∅) (h₂ : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → p s → p (insert a s)) : p S :=
@finset.induction_on α (λ T, T ⊆ S → p T) _ S (λ _, h₁) (λ a s has hqs hs,
let ⟨hS, sS⟩ := finset.insert_subset.1 hs in h₂ hS sS has (hqs sS)) (finset.subset.refl S)
/-- Inserting an element to a finite set is equivalent to the option type. -/
def subtype_insert_equiv_option {t : finset α} {x : α} (h : x ∉ t) :
{i // i ∈ insert x t} ≃ option {i // i ∈ t} :=
begin
refine
{ to_fun := λ y, if h : ↑y = x then none else some ⟨y, (mem_insert.mp y.2).resolve_left h⟩,
inv_fun := λ y, y.elim ⟨x, mem_insert_self _ _⟩ $ λ z, ⟨z, mem_insert_of_mem z.2⟩,
.. },
{ intro y, by_cases h : ↑y = x,
simp only [subtype.ext_iff, h, option.elim, dif_pos, subtype.coe_mk],
simp only [h, option.elim, dif_neg, not_false_iff, subtype.coe_eta, subtype.coe_mk] },
{ rintro (_|y), simp only [option.elim, dif_pos, subtype.coe_mk],
have : ↑y ≠ x, { rintro ⟨⟩, exact h y.2 },
simp only [this, option.elim, subtype.eta, dif_neg, not_false_iff, subtype.coe_eta,
subtype.coe_mk] },
end
/-! ### union -/
/-- `s ∪ t` is the set such that `a ∈ s ∪ t` iff `a ∈ s` or `a ∈ t`. -/
instance : has_union (finset α) := ⟨λ s₁ s₂, ⟨_, nodup_ndunion s₁.1 s₂.2⟩⟩
theorem union_val_nd (s₁ s₂ : finset α) : (s₁ ∪ s₂).1 = ndunion s₁.1 s₂.1 := rfl
@[simp] theorem union_val (s₁ s₂ : finset α) : (s₁ ∪ s₂).1 = s₁.1 ∪ s₂.1 :=
ndunion_eq_union s₁.2
@[simp] theorem mem_union {a : α} {s₁ s₂ : finset α} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ := mem_ndunion
@[simp] theorem disj_union_eq_union {α} [decidable_eq α] (s t h) : @disj_union α s t h = s ∪ t :=
ext $ λ a, by simp
theorem mem_union_left {a : α} {s₁ : finset α} (s₂ : finset α) (h : a ∈ s₁) : a ∈ s₁ ∪ s₂ :=
mem_union.2 $ or.inl h
theorem mem_union_right {a : α} {s₂ : finset α} (s₁ : finset α) (h : a ∈ s₂) : a ∈ s₁ ∪ s₂ :=
mem_union.2 $ or.inr h
theorem forall_mem_union {s₁ s₂ : finset α} {p : α → Prop} :
(∀ ab ∈ (s₁ ∪ s₂), p ab) ↔ (∀ a ∈ s₁, p a) ∧ (∀ b ∈ s₂, p b) :=
⟨λ h, ⟨λ a, h a ∘ mem_union_left _, λ b, h b ∘ mem_union_right _⟩,
λ h ab hab, (mem_union.mp hab).elim (h.1 _) (h.2 _)⟩
theorem not_mem_union {a : α} {s₁ s₂ : finset α} : a ∉ s₁ ∪ s₂ ↔ a ∉ s₁ ∧ a ∉ s₂ :=
by rw [mem_union, not_or_distrib]
@[simp, norm_cast]
lemma coe_union (s₁ s₂ : finset α) : ↑(s₁ ∪ s₂) = (s₁ ∪ s₂ : set α) := set.ext $ λ x, mem_union
theorem union_subset {s₁ s₂ s₃ : finset α} (h₁ : s₁ ⊆ s₃) (h₂ : s₂ ⊆ s₃) : s₁ ∪ s₂ ⊆ s₃ :=
val_le_iff.1 (ndunion_le.2 ⟨h₁, val_le_iff.2 h₂⟩)
theorem subset_union_left (s₁ s₂ : finset α) : s₁ ⊆ s₁ ∪ s₂ := λ x, mem_union_left _
theorem subset_union_right (s₁ s₂ : finset α) : s₂ ⊆ s₁ ∪ s₂ := λ x, mem_union_right _
lemma union_subset_union {s₁ t₁ s₂ t₂ : finset α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∪ s₂ ⊆ t₁ ∪ t₂ :=
by { intros x hx, rw finset.mem_union at hx ⊢, tauto }
theorem union_comm (s₁ s₂ : finset α) : s₁ ∪ s₂ = s₂ ∪ s₁ :=
ext $ λ x, by simp only [mem_union, or_comm]
instance : is_commutative (finset α) (∪) := ⟨union_comm⟩
@[simp] theorem union_assoc (s₁ s₂ s₃ : finset α) : (s₁ ∪ s₂) ∪ s₃ = s₁ ∪ (s₂ ∪ s₃) :=
ext $ λ x, by simp only [mem_union, or_assoc]
instance : is_associative (finset α) (∪) := ⟨union_assoc⟩
@[simp] theorem union_idempotent (s : finset α) : s ∪ s = s :=
ext $ λ _, mem_union.trans $ or_self _
instance : is_idempotent (finset α) (∪) := ⟨union_idempotent⟩
theorem union_left_comm (s₁ s₂ s₃ : finset α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext $ λ _, by simp only [mem_union, or.left_comm]
theorem union_right_comm (s₁ s₂ s₃ : finset α) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ :=
ext $ λ x, by simp only [mem_union, or_assoc, or_comm (x ∈ s₂)]
theorem union_self (s : finset α) : s ∪ s = s := union_idempotent s
@[simp] theorem union_empty (s : finset α) : s ∪ ∅ = s :=
ext $ λ x, mem_union.trans $ or_false _
@[simp] theorem empty_union (s : finset α) : ∅ ∪ s = s :=
ext $ λ x, mem_union.trans $ false_or _
theorem insert_eq (a : α) (s : finset α) : insert a s = {a} ∪ s := rfl
@[simp] theorem insert_union (a : α) (s t : finset α) : insert a s ∪ t = insert a (s ∪ t) :=
by simp only [insert_eq, union_assoc]
@[simp] theorem union_insert (a : α) (s t : finset α) : s ∪ insert a t = insert a (s ∪ t) :=
by simp only [insert_eq, union_left_comm]
theorem insert_union_distrib (a : α) (s t : finset α) :
insert a (s ∪ t) = insert a s ∪ insert a t :=
by simp only [insert_union, union_insert, insert_idem]
@[simp] lemma union_eq_left_iff_subset {s t : finset α} :
s ∪ t = s ↔ t ⊆ s :=
begin
split,
{ assume h,
have : t ⊆ s ∪ t := subset_union_right _ _,
rwa h at this },
{ assume h,
exact subset.antisymm (union_subset (subset.refl _) h) (subset_union_left _ _) }
end
@[simp] lemma left_eq_union_iff_subset {s t : finset α} :
s = s ∪ t ↔ t ⊆ s :=
by rw [← union_eq_left_iff_subset, eq_comm]
@[simp] lemma union_eq_right_iff_subset {s t : finset α} :
t ∪ s = s ↔ t ⊆ s :=
by rw [union_comm, union_eq_left_iff_subset]
@[simp] lemma right_eq_union_iff_subset {s t : finset α} :
s = t ∪ s ↔ t ⊆ s :=
by rw [← union_eq_right_iff_subset, eq_comm]
/--
To prove a relation on pairs of `finset X`, it suffices to show that it is
* symmetric,
* it holds when one of the `finset`s is empty,
* it holds for pairs of singletons,
* if it holds for `[a, c]` and for `[b, c]`, then it holds for `[a ∪ b, c]`.
-/
lemma induction_on_union (P : finset α → finset α → Prop)
(symm : ∀ {a b}, P a b → P b a)
(empty_right : ∀ {a}, P a ∅)
(singletons : ∀ {a b}, P {a} {b})
(union_of : ∀ {a b c}, P a c → P b c → P (a ∪ b) c) :
∀ a b, P a b :=
begin
intros a b,
refine finset.induction_on b empty_right (λ x s xs hi, symm _),
rw finset.insert_eq,
apply union_of _ (symm hi),
refine finset.induction_on a empty_right (λ a t ta hi, symm _),
rw finset.insert_eq,
exact union_of singletons (symm hi),
end
lemma exists_mem_subset_of_subset_bUnion_of_directed_on {α ι : Type*}
{f : ι → set α} {c : set ι} {a : ι} (hac : a ∈ c) (hc : directed_on (λ i j, f i ⊆ f j) c)
{s : finset α} (hs : (s : set α) ⊆ ⋃ i ∈ c, f i) : ∃ i ∈ c, (s : set α) ⊆ f i :=
begin
classical,
revert hs,
apply s.induction_on,
{ intros,
use [a, hac],
simp },
{ intros b t hbt htc hbtc,
obtain ⟨i : ι , hic : i ∈ c, hti : (t : set α) ⊆ f i⟩ :=
htc (set.subset.trans (t.subset_insert b) hbtc),
obtain ⟨j, hjc, hbj⟩ : ∃ j ∈ c, b ∈ f j,
by simpa [set.mem_bUnion_iff] using hbtc (t.mem_insert_self b),
rcases hc j hjc i hic with ⟨k, hkc, hk, hk'⟩,
use [k, hkc],
rw [coe_insert, set.insert_subset],
exact ⟨hk hbj, trans hti hk'⟩ }
end
/-! ### inter -/
/-- `s ∩ t` is the set such that `a ∈ s ∩ t` iff `a ∈ s` and `a ∈ t`. -/
instance : has_inter (finset α) := ⟨λ s₁ s₂, ⟨_, nodup_ndinter s₂.1 s₁.2⟩⟩
-- TODO: some of these results may have simpler proofs, once there are enough results
-- to obtain the `lattice` instance.
theorem inter_val_nd (s₁ s₂ : finset α) : (s₁ ∩ s₂).1 = ndinter s₁.1 s₂.1 := rfl
@[simp] theorem inter_val (s₁ s₂ : finset α) : (s₁ ∩ s₂).1 = s₁.1 ∩ s₂.1 :=
ndinter_eq_inter s₁.2
@[simp] theorem mem_inter {a : α} {s₁ s₂ : finset α} : a ∈ s₁ ∩ s₂ ↔ a ∈ s₁ ∧ a ∈ s₂ := mem_ndinter
theorem mem_of_mem_inter_left {a : α} {s₁ s₂ : finset α} (h : a ∈ s₁ ∩ s₂) :
a ∈ s₁ := (mem_inter.1 h).1
theorem mem_of_mem_inter_right {a : α} {s₁ s₂ : finset α} (h : a ∈ s₁ ∩ s₂) :
a ∈ s₂ := (mem_inter.1 h).2
theorem mem_inter_of_mem {a : α} {s₁ s₂ : finset α} : a ∈ s₁ → a ∈ s₂ → a ∈ s₁ ∩ s₂ :=
and_imp.1 mem_inter.2
theorem inter_subset_left (s₁ s₂ : finset α) : s₁ ∩ s₂ ⊆ s₁ := λ a, mem_of_mem_inter_left
theorem inter_subset_right (s₁ s₂ : finset α) : s₁ ∩ s₂ ⊆ s₂ := λ a, mem_of_mem_inter_right
theorem subset_inter {s₁ s₂ s₃ : finset α} : s₁ ⊆ s₂ → s₁ ⊆ s₃ → s₁ ⊆ s₂ ∩ s₃ :=
by simp only [subset_iff, mem_inter] {contextual:=tt}; intros; split; trivial
@[simp, norm_cast]
lemma coe_inter (s₁ s₂ : finset α) : ↑(s₁ ∩ s₂) = (s₁ ∩ s₂ : set α) := set.ext $ λ _, mem_inter
@[simp] theorem union_inter_cancel_left {s t : finset α} : (s ∪ t) ∩ s = s :=
by rw [← coe_inj, coe_inter, coe_union, set.union_inter_cancel_left]
@[simp] theorem union_inter_cancel_right {s t : finset α} : (s ∪ t) ∩ t = t :=
by rw [← coe_inj, coe_inter, coe_union, set.union_inter_cancel_right]
theorem inter_comm (s₁ s₂ : finset α) : s₁ ∩ s₂ = s₂ ∩ s₁ :=
ext $ λ _, by simp only [mem_inter, and_comm]
@[simp] theorem inter_assoc (s₁ s₂ s₃ : finset α) : (s₁ ∩ s₂) ∩ s₃ = s₁ ∩ (s₂ ∩ s₃) :=
ext $ λ _, by simp only [mem_inter, and_assoc]
theorem inter_left_comm (s₁ s₂ s₃ : finset α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext $ λ _, by simp only [mem_inter, and.left_comm]
theorem inter_right_comm (s₁ s₂ s₃ : finset α) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ :=
ext $ λ _, by simp only [mem_inter, and.right_comm]
@[simp] theorem inter_self (s : finset α) : s ∩ s = s :=
ext $ λ _, mem_inter.trans $ and_self _
@[simp] theorem inter_empty (s : finset α) : s ∩ ∅ = ∅ :=
ext $ λ _, mem_inter.trans $ and_false _
@[simp] theorem empty_inter (s : finset α) : ∅ ∩ s = ∅ :=
ext $ λ _, mem_inter.trans $ false_and _
@[simp] lemma inter_union_self (s t : finset α) : s ∩ (t ∪ s) = s :=
by rw [inter_comm, union_inter_cancel_right]
@[simp] theorem insert_inter_of_mem {s₁ s₂ : finset α} {a : α} (h : a ∈ s₂) :
insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) :=
ext $ λ x, have x = a ∨ x ∈ s₂ ↔ x ∈ s₂, from or_iff_right_of_imp $ by rintro rfl; exact h,
by simp only [mem_inter, mem_insert, or_and_distrib_left, this]
@[simp] theorem inter_insert_of_mem {s₁ s₂ : finset α} {a : α} (h : a ∈ s₁) :
s₁ ∩ insert a s₂ = insert a (s₁ ∩ s₂) :=
by rw [inter_comm, insert_inter_of_mem h, inter_comm]
@[simp] theorem insert_inter_of_not_mem {s₁ s₂ : finset α} {a : α} (h : a ∉ s₂) :
insert a s₁ ∩ s₂ = s₁ ∩ s₂ :=
ext $ λ x, have ¬ (x = a ∧ x ∈ s₂), by rintro ⟨rfl, H⟩; exact h H,
by simp only [mem_inter, mem_insert, or_and_distrib_right, this, false_or]
@[simp] theorem inter_insert_of_not_mem {s₁ s₂ : finset α} {a : α} (h : a ∉ s₁) :
s₁ ∩ insert a s₂ = s₁ ∩ s₂ :=
by rw [inter_comm, insert_inter_of_not_mem h, inter_comm]
@[simp] theorem singleton_inter_of_mem {a : α} {s : finset α} (H : a ∈ s) : {a} ∩ s = {a} :=
show insert a ∅ ∩ s = insert a ∅, by rw [insert_inter_of_mem H, empty_inter]
@[simp] theorem singleton_inter_of_not_mem {a : α} {s : finset α} (H : a ∉ s) : {a} ∩ s = ∅ :=
eq_empty_of_forall_not_mem $ by simp only [mem_inter, mem_singleton]; rintro x ⟨rfl, h⟩; exact H h
@[simp] theorem inter_singleton_of_mem {a : α} {s : finset α} (h : a ∈ s) : s ∩ {a} = {a} :=
by rw [inter_comm, singleton_inter_of_mem h]
@[simp] theorem inter_singleton_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : s ∩ {a} = ∅ :=
by rw [inter_comm, singleton_inter_of_not_mem h]
@[mono]
lemma inter_subset_inter {x y s t : finset α} (h : x ⊆ y) (h' : s ⊆ t) : x ∩ s ⊆ y ∩ t :=
begin
intros a a_in,
rw finset.mem_inter at a_in ⊢,
exact ⟨h a_in.1, h' a_in.2⟩
end
lemma inter_subset_inter_right {x y s : finset α} (h : x ⊆ y) : x ∩ s ⊆ y ∩ s :=
finset.inter_subset_inter h (finset.subset.refl _)
lemma inter_subset_inter_left {x y s : finset α} (h : x ⊆ y) : s ∩ x ⊆ s ∩ y :=
finset.inter_subset_inter (finset.subset.refl _) h
/-! ### lattice laws -/
instance : lattice (finset α) :=
{ sup := (∪),
sup_le := assume a b c, union_subset,
le_sup_left := subset_union_left,
le_sup_right := subset_union_right,
inf := (∩),
le_inf := assume a b c, subset_inter,
inf_le_left := inter_subset_left,
inf_le_right := inter_subset_right,
..finset.partial_order }
@[simp] theorem sup_eq_union : ((⊔) : finset α → finset α → finset α) = (∪) := rfl
@[simp] theorem inf_eq_inter : ((⊓) : finset α → finset α → finset α) = (∩) := rfl
instance : semilattice_inf_bot (finset α) :=
{ bot := ∅, bot_le := empty_subset, ..finset.lattice }
@[simp] lemma bot_eq_empty : (⊥ : finset α) = ∅ := rfl
instance {α : Type*} [decidable_eq α] : semilattice_sup_bot (finset α) :=
{ ..finset.semilattice_inf_bot, ..finset.lattice }
instance : distrib_lattice (finset α) :=
{ le_sup_inf := assume a b c, show (a ∪ b) ∩ (a ∪ c) ⊆ a ∪ b ∩ c,
by simp only [subset_iff, mem_inter, mem_union, and_imp, or_imp_distrib] {contextual:=tt};
simp only [true_or, imp_true_iff, true_and, or_true],
..finset.lattice }
theorem inter_distrib_left (s t u : finset α) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) := inf_sup_left
theorem inter_distrib_right (s t u : finset α) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) := inf_sup_right
theorem union_distrib_left (s t u : finset α) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) := sup_inf_left
theorem union_distrib_right (s t u : finset α) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right
lemma union_eq_empty_iff (A B : finset α) : A ∪ B = ∅ ↔ A = ∅ ∧ B = ∅ := sup_eq_bot_iff
lemma union_subset_iff {s₁ s₂ s₃ : finset α} :
s₁ ∪ s₂ ⊆ s₃ ↔ s₁ ⊆ s₃ ∧ s₂ ⊆ s₃ :=
(sup_le_iff : s₁ ⊔ s₂ ≤ s₃ ↔ s₁ ≤ s₃ ∧ s₂ ≤ s₃)
lemma subset_inter_iff {s₁ s₂ s₃ : finset α} :
s₁ ⊆ s₂ ∩ s₃ ↔ s₁ ⊆ s₂ ∧ s₁ ⊆ s₃ :=
(le_inf_iff : s₁ ≤ s₂ ⊓ s₃ ↔ s₁ ≤ s₂ ∧ s₁ ≤ s₃)
theorem inter_eq_left_iff_subset (s t : finset α) :
s ∩ t = s ↔ s ⊆ t :=
(inf_eq_left : s ⊓ t = s ↔ s ≤ t)
theorem inter_eq_right_iff_subset (s t : finset α) :
t ∩ s = s ↔ s ⊆ t :=
(inf_eq_right : t ⊓ s = s ↔ s ≤ t)
/-! ### erase -/
/-- `erase s a` is the set `s - {a}`, that is, the elements of `s` which are
not equal to `a`. -/
def erase (s : finset α) (a : α) : finset α := ⟨_, nodup_erase_of_nodup a s.2⟩
@[simp] theorem erase_val (s : finset α) (a : α) : (erase s a).1 = s.1.erase a := rfl
@[simp] theorem mem_erase {a b : α} {s : finset α} : a ∈ erase s b ↔ a ≠ b ∧ a ∈ s :=
mem_erase_iff_of_nodup s.2
theorem not_mem_erase (a : α) (s : finset α) : a ∉ erase s a := mem_erase_of_nodup s.2
@[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl
theorem ne_of_mem_erase {a b : α} {s : finset α} : b ∈ erase s a → b ≠ a :=
by simp only [mem_erase]; exact and.left
theorem mem_of_mem_erase {a b : α} {s : finset α} : b ∈ erase s a → b ∈ s := mem_of_mem_erase
theorem mem_erase_of_ne_of_mem {a b : α} {s : finset α} : a ≠ b → a ∈ s → a ∈ erase s b :=
by simp only [mem_erase]; exact and.intro
/-- An element of `s` that is not an element of `erase s a` must be
`a`. -/
lemma eq_of_mem_of_not_mem_erase {a b : α} {s : finset α} (hs : b ∈ s)
(hsa : b ∉ s.erase a) : b = a :=
begin
rw [mem_erase, not_and] at hsa,
exact not_imp_not.mp hsa hs
end
theorem erase_insert {a : α} {s : finset α} (h : a ∉ s) : erase (insert a s) a = s :=
ext $ assume x, by simp only [mem_erase, mem_insert, and_or_distrib_left, not_and_self, false_or];
apply and_iff_right_of_imp; rintro H rfl; exact h H
theorem insert_erase {a : α} {s : finset α} (h : a ∈ s) : insert a (erase s a) = s :=
ext $ assume x, by simp only [mem_insert, mem_erase, or_and_distrib_left, dec_em, true_and];
apply or_iff_right_of_imp; rintro rfl; exact h
theorem erase_subset_erase (a : α) {s t : finset α} (h : s ⊆ t) : erase s a ⊆ erase t a :=
val_le_iff.1 $ erase_le_erase _ $ val_le_iff.2 h
theorem erase_subset (a : α) (s : finset α) : erase s a ⊆ s := erase_subset _ _
@[simp, norm_cast] lemma coe_erase (a : α) (s : finset α) : ↑(erase s a) = (s \ {a} : set α) :=
set.ext $ λ _, mem_erase.trans $ by rw [and_comm, set.mem_diff, set.mem_singleton_iff]; refl
lemma erase_ssubset {a : α} {s : finset α} (h : a ∈ s) : s.erase a ⊂ s :=
calc s.erase a ⊂ insert a (s.erase a) : ssubset_insert $ not_mem_erase _ _
... = _ : insert_erase h
theorem erase_eq_of_not_mem {a : α} {s : finset α} (h : a ∉ s) : erase s a = s :=
eq_of_veq $ erase_of_not_mem h
theorem subset_insert_iff {a : α} {s t : finset α} : s ⊆ insert a t ↔ erase s a ⊆ t :=
by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp];
exact forall_congr (λ x, forall_swap)
theorem erase_insert_subset (a : α) (s : finset α) : erase (insert a s) a ⊆ s :=
subset_insert_iff.1 $ subset.refl _
theorem insert_erase_subset (a : α) (s : finset α) : s ⊆ insert a (erase s a) :=
subset_insert_iff.2 $ subset.refl _
lemma erase_inj {x y : α} (s : finset α) (hx : x ∈ s) :
s.erase x = s.erase y ↔ x = y :=
begin
refine ⟨λ h, _, congr_arg _⟩,
rw eq_of_mem_of_not_mem_erase hx,
rw ←h,
simp,
end
lemma erase_inj_on (s : finset α) : set.inj_on s.erase s :=
λ _ _ _ _, (erase_inj s ‹_›).mp
/-! ### sdiff -/
/-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/
instance : has_sdiff (finset α) := ⟨λs₁ s₂, ⟨s₁.1 - s₂.1, nodup_of_le (sub_le_self _ _) s₁.2⟩⟩
@[simp] theorem mem_sdiff {a : α} {s₁ s₂ : finset α} :
a ∈ s₁ \ s₂ ↔ a ∈ s₁ ∧ a ∉ s₂ := mem_sub_of_nodup s₁.2
@[simp] theorem inter_sdiff_self (s₁ s₂ : finset α) : s₁ ∩ (s₂ \ s₁) = ∅ :=
eq_empty_of_forall_not_mem $
by simp only [mem_inter, mem_sdiff]; rintro x ⟨h, _, hn⟩; exact hn h
instance : generalized_boolean_algebra (finset α) :=
{ sup_inf_sdiff := λ x y, by { simp only [ext_iff, mem_union, mem_sdiff, inf_eq_inter, sup_eq_union,
mem_inter], tauto },
inf_inf_sdiff := λ x y, by { simp only [ext_iff, inter_sdiff_self, inter_empty, inter_assoc,
false_iff, inf_eq_inter, not_mem_empty], tauto },
..finset.has_sdiff,
..finset.distrib_lattice,
..finset.semilattice_inf_bot }
lemma not_mem_sdiff_of_mem_right {a : α} {s t : finset α} (h : a ∈ t) : a ∉ s \ t :=
by simp only [mem_sdiff, h, not_true, not_false_iff, and_false]
theorem union_sdiff_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁ ∪ (s₂ \ s₁) = s₂ :=
sup_sdiff_of_le h
theorem sdiff_union_of_subset {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : (s₂ \ s₁) ∪ s₁ = s₂ :=
(union_comm _ _).trans (union_sdiff_of_subset h)
theorem inter_sdiff (s t u : finset α) : s ∩ (t \ u) = s ∩ t \ u :=
by { ext x, simp [and_assoc] }
@[simp] theorem sdiff_inter_self (s₁ s₂ : finset α) : (s₂ \ s₁) ∩ s₁ = ∅ :=
inf_sdiff_self_left
@[simp] theorem sdiff_self (s₁ : finset α) : s₁ \ s₁ = ∅ :=
sdiff_self
theorem sdiff_inter_distrib_right (s₁ s₂ s₃ : finset α) : s₁ \ (s₂ ∩ s₃) = (s₁ \ s₂) ∪ (s₁ \ s₃) :=
sdiff_inf
@[simp] theorem sdiff_inter_self_left (s₁ s₂ : finset α) : s₁ \ (s₁ ∩ s₂) = s₁ \ s₂ :=
sdiff_inf_self_left
@[simp] theorem sdiff_inter_self_right (s₁ s₂ : finset α) : s₁ \ (s₂ ∩ s₁) = s₁ \ s₂ :=
sdiff_inf_self_right
@[simp] theorem sdiff_empty {s₁ : finset α} : s₁ \ ∅ = s₁ :=
sdiff_bot
@[mono]
theorem sdiff_subset_sdiff {s₁ s₂ t₁ t₂ : finset α} (h₁ : t₁ ⊆ t₂) (h₂ : s₂ ⊆ s₁) :
t₁ \ s₁ ⊆ t₂ \ s₂ :=
sdiff_le_sdiff ‹t₁ ≤ t₂› ‹s₂ ≤ s₁›
@[simp, norm_cast] lemma coe_sdiff (s₁ s₂ : finset α) : ↑(s₁ \ s₂) = (s₁ \ s₂ : set α) :=
set.ext $ λ _, mem_sdiff
@[simp] theorem union_sdiff_self_eq_union {s t : finset α} : s ∪ (t \ s) = s ∪ t :=
sup_sdiff_self_right
@[simp] theorem sdiff_union_self_eq_union {s t : finset α} : (s \ t) ∪ t = s ∪ t :=
sup_sdiff_self_left
lemma union_sdiff_symm {s t : finset α} : s ∪ (t \ s) = t ∪ (s \ t) :=
sup_sdiff_symm
lemma sdiff_union_inter (s t : finset α) : (s \ t) ∪ (s ∩ t) = s :=
by { rw union_comm, exact sup_inf_sdiff _ _ }
@[simp] lemma sdiff_idem (s t : finset α) : s \ t \ t = s \ t :=
sdiff_idem
lemma sdiff_eq_empty_iff_subset {s t : finset α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
@[simp] lemma empty_sdiff (s : finset α) : ∅ \ s = ∅ :=
bot_sdiff
lemma insert_sdiff_of_not_mem (s : finset α) {t : finset α} {x : α} (h : x ∉ t) :
(insert x s) \ t = insert x (s \ t) :=
begin
rw [← coe_inj, coe_insert, coe_sdiff, coe_sdiff, coe_insert],
exact set.insert_diff_of_not_mem s h
end
lemma insert_sdiff_of_mem (s : finset α) {t : finset α} {x : α} (h : x ∈ t) :
(insert x s) \ t = s \ t :=
begin
rw [← coe_inj, coe_sdiff, coe_sdiff, coe_insert],
exact set.insert_diff_of_mem s h
end
@[simp] lemma insert_sdiff_insert (s t : finset α) (x : α) :
(insert x s) \ (insert x t) = s \ insert x t :=
insert_sdiff_of_mem _ (mem_insert_self _ _)
lemma sdiff_insert_of_not_mem {s : finset α} {x : α} (h : x ∉ s) (t : finset α) :
s \ (insert x t) = s \ t :=
begin
refine subset.antisymm (sdiff_subset_sdiff (subset.refl _) (subset_insert _ _)) (λ y hy, _),
simp only [mem_sdiff, mem_insert, not_or_distrib] at hy ⊢,
exact ⟨hy.1, λ hxy, h $ hxy ▸ hy.1, hy.2⟩
end
@[simp] lemma sdiff_subset (s t : finset α) : s \ t ⊆ s :=
show s \ t ≤ s, from sdiff_le
lemma union_sdiff_distrib (s₁ s₂ t : finset α) : (s₁ ∪ s₂) \ t = s₁ \ t ∪ s₂ \ t :=
sup_sdiff
lemma sdiff_union_distrib (s t₁ t₂ : finset α) : s \ (t₁ ∪ t₂) = (s \ t₁) ∩ (s \ t₂) :=
sdiff_sup
lemma union_sdiff_self (s t : finset α) : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
lemma sdiff_singleton_eq_erase (a : α) (s : finset α) : s \ singleton a = erase s a :=
by { ext, rw [mem_erase, mem_sdiff, mem_singleton], tauto }
lemma sdiff_sdiff_self_left (s t : finset α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
lemma sdiff_eq_sdiff_iff_inter_eq_inter {s t₁ t₂ : finset α} : s \ t₁ = s \ t₂ ↔ s ∩ t₁ = s ∩ t₂ :=
sdiff_eq_sdiff_iff_inf_eq_inf
lemma union_eq_sdiff_union_sdiff_union_inter (s t : finset α) :
s ∪ t = (s \ t) ∪ (t \ s) ∪ (s ∩ t) :=
sup_eq_sdiff_sup_sdiff_sup_inf
end decidable_eq
/-! ### attach -/
/-- `attach s` takes the elements of `s` and forms a new set of elements of the subtype
`{x // x ∈ s}`. -/
def attach (s : finset α) : finset {x // x ∈ s} := ⟨attach s.1, nodup_attach.2 s.2⟩
theorem sizeof_lt_sizeof_of_mem [has_sizeof α] {x : α} {s : finset α} (hx : x ∈ s) :
sizeof x < sizeof s := by
{ cases s, dsimp [sizeof, has_sizeof.sizeof, finset.sizeof],
apply lt_add_left, exact multiset.sizeof_lt_sizeof_of_mem hx }
@[simp] theorem attach_val (s : finset α) : s.attach.1 = s.1.attach := rfl
@[simp] theorem mem_attach (s : finset α) : ∀ x, x ∈ s.attach := mem_attach _
@[simp] theorem attach_empty : attach (∅ : finset α) = ∅ := rfl
@[simp] lemma attach_nonempty_iff (s : finset α) : s.attach.nonempty ↔ s.nonempty :=
by simp [finset.nonempty]
@[simp] lemma attach_eq_empty_iff (s : finset α) : s.attach = ∅ ↔ s = ∅ :=
by simpa [eq_empty_iff_forall_not_mem]
/-! ### piecewise -/
section piecewise
/-- `s.piecewise f g` is the function equal to `f` on the finset `s`, and to `g` on its
complement. -/
def piecewise {α : Type*} {δ : α → Sort*} (s : finset α) (f g : Πi, δ i) [∀j, decidable (j ∈ s)] :
Πi, δ i :=
λi, if i ∈ s then f i else g i
variables {δ : α → Sort*} (s : finset α) (f g : Πi, δ i)
@[simp] lemma piecewise_insert_self [decidable_eq α] {j : α} [∀i, decidable (i ∈ insert j s)] :
(insert j s).piecewise f g j = f j :=
by simp [piecewise]
@[simp] lemma piecewise_empty [∀i : α, decidable (i ∈ (∅ : finset α))] : piecewise ∅ f g = g :=
by { ext i, simp [piecewise] }
variable [∀j, decidable (j ∈ s)]
@[norm_cast] lemma piecewise_coe [∀j, decidable (j ∈ (s : set α))] :
(s : set α).piecewise f g = s.piecewise f g :=
by { ext, congr }
@[simp, priority 980]
lemma piecewise_eq_of_mem {i : α} (hi : i ∈ s) : s.piecewise f g i = f i :=
by simp [piecewise, hi]
@[simp, priority 980]
lemma piecewise_eq_of_not_mem {i : α} (hi : i ∉ s) : s.piecewise f g i = g i :=
by simp [piecewise, hi]
lemma piecewise_congr {f f' g g' : Π i, δ i} (hf : ∀ i ∈ s, f i = f' i) (hg : ∀ i ∉ s, g i = g' i) :
s.piecewise f g = s.piecewise f' g' :=
funext $ λ i, if_ctx_congr iff.rfl (hf i) (hg i)
@[simp, priority 990]
lemma piecewise_insert_of_ne [decidable_eq α] {i j : α} [∀i, decidable (i ∈ insert j s)]
(h : i ≠ j) : (insert j s).piecewise f g i = s.piecewise f g i :=
by simp [piecewise, h]
lemma piecewise_insert [decidable_eq α] (j : α) [∀i, decidable (i ∈ insert j s)] :
(insert j s).piecewise f g = update (s.piecewise f g) j (f j) :=
begin
classical,
rw [← piecewise_coe, ← piecewise_coe, ← set.piecewise_insert, ← coe_insert j s],
congr
end
lemma piecewise_cases {i} (p : δ i → Prop) (hf : p (f i)) (hg : p (g i)) : p (s.piecewise f g i) :=
by by_cases hi : i ∈ s; simpa [hi]
lemma piecewise_mem_set_pi {δ : α → Type*} {t : set α} {t' : Π i, set (δ i)}
{f g} (hf : f ∈ set.pi t t') (hg : g ∈ set.pi t t') : s.piecewise f g ∈ set.pi t t' :=
by { classical, rw ← piecewise_coe, exact set.piecewise_mem_pi ↑s hf hg }
lemma piecewise_singleton [decidable_eq α] (i : α) :
piecewise {i} f g = update g i (f i) :=
by rw [← insert_emptyc_eq, piecewise_insert, piecewise_empty]
lemma piecewise_piecewise_of_subset_left {s t : finset α} [Π i, decidable (i ∈ s)]
[Π i, decidable (i ∈ t)] (h : s ⊆ t) (f₁ f₂ g : Π a, δ a) :
s.piecewise (t.piecewise f₁ f₂) g = s.piecewise f₁ g :=
s.piecewise_congr (λ i hi, piecewise_eq_of_mem _ _ _ (h hi)) (λ _ _, rfl)
@[simp] lemma piecewise_idem_left (f₁ f₂ g : Π a, δ a) :
s.piecewise (s.piecewise f₁ f₂) g = s.piecewise f₁ g :=
piecewise_piecewise_of_subset_left (subset.refl _) _ _ _
lemma piecewise_piecewise_of_subset_right {s t : finset α} [Π i, decidable (i ∈ s)]
[Π i, decidable (i ∈ t)] (h : t ⊆ s) (f g₁ g₂ : Π a, δ a) :
s.piecewise f (t.piecewise g₁ g₂) = s.piecewise f g₂ :=
s.piecewise_congr (λ _ _, rfl) (λ i hi, t.piecewise_eq_of_not_mem _ _ (mt (@h _) hi))
@[simp] lemma piecewise_idem_right (f g₁ g₂ : Π a, δ a) :
s.piecewise f (s.piecewise g₁ g₂) = s.piecewise f g₂ :=
piecewise_piecewise_of_subset_right (subset.refl _) f g₁ g₂
lemma update_eq_piecewise {β : Type*} [decidable_eq α] (f : α → β) (i : α) (v : β) :
update f i v = piecewise (singleton i) (λj, v) f :=
(piecewise_singleton _ _ _).symm
lemma update_piecewise [decidable_eq α] (i : α) (v : δ i) :
update (s.piecewise f g) i v = s.piecewise (update f i v) (update g i v) :=
begin
ext j,
rcases em (j = i) with (rfl|hj); by_cases hs : j ∈ s; simp *
end
lemma update_piecewise_of_mem [decidable_eq α] {i : α} (hi : i ∈ s) (v : δ i) :
update (s.piecewise f g) i v = s.piecewise (update f i v) g :=
begin
rw update_piecewise,
refine s.piecewise_congr (λ _ _, rfl) (λ j hj, update_noteq _ _ _),
exact λ h, hj (h.symm ▸ hi)
end
lemma update_piecewise_of_not_mem [decidable_eq α] {i : α} (hi : i ∉ s) (v : δ i) :
update (s.piecewise f g) i v = s.piecewise f (update g i v) :=
begin
rw update_piecewise,
refine s.piecewise_congr (λ j hj, update_noteq _ _ _) (λ _ _, rfl),
exact λ h, hi (h ▸ hj)
end
lemma piecewise_le_of_le_of_le {δ : α → Type*} [Π i, preorder (δ i)] {f g h : Π i, δ i}
(Hf : f ≤ h) (Hg : g ≤ h) : s.piecewise f g ≤ h :=
λ x, piecewise_cases s f g (≤ h x) (Hf x) (Hg x)
lemma le_piecewise_of_le_of_le {δ : α → Type*} [Π i, preorder (δ i)] {f g h : Π i, δ i}
(Hf : h ≤ f) (Hg : h ≤ g) : h ≤ s.piecewise f g :=
λ x, piecewise_cases s f g (λ y, h x ≤ y) (Hf x) (Hg x)
lemma piecewise_le_piecewise' {δ : α → Type*} [Π i, preorder (δ i)] {f g f' g' : Π i, δ i}
(Hf : ∀ x ∈ s, f x ≤ f' x) (Hg : ∀ x ∉ s, g x ≤ g' x) : s.piecewise f g ≤ s.piecewise f' g' :=
λ x, by { by_cases hx : x ∈ s; simp [hx, *] }
lemma piecewise_le_piecewise {δ : α → Type*} [Π i, preorder (δ i)] {f g f' g' : Π i, δ i}
(Hf : f ≤ f') (Hg : g ≤ g') : s.piecewise f g ≤ s.piecewise f' g' :=
s.piecewise_le_piecewise' (λ x _, Hf x) (λ x _, Hg x)
lemma piecewise_mem_Icc_of_mem_of_mem {δ : α → Type*} [Π i, preorder (δ i)] {f f₁ g g₁ : Π i, δ i}
(hf : f ∈ set.Icc f₁ g₁) (hg : g ∈ set.Icc f₁ g₁) :
s.piecewise f g ∈ set.Icc f₁ g₁ :=
⟨le_piecewise_of_le_of_le _ hf.1 hg.1, piecewise_le_of_le_of_le _ hf.2 hg.2⟩
lemma piecewise_mem_Icc {δ : α → Type*} [Π i, preorder (δ i)] {f g : Π i, δ i} (h : f ≤ g) :
s.piecewise f g ∈ set.Icc f g :=
piecewise_mem_Icc_of_mem_of_mem _ (set.left_mem_Icc.2 h) (set.right_mem_Icc.2 h)
lemma piecewise_mem_Icc' {δ : α → Type*} [Π i, preorder (δ i)] {f g : Π i, δ i} (h : g ≤ f) :
s.piecewise f g ∈ set.Icc g f :=
piecewise_mem_Icc_of_mem_of_mem _ (set.right_mem_Icc.2 h) (set.left_mem_Icc.2 h)
end piecewise
section decidable_pi_exists
variables {s : finset α}
instance decidable_dforall_finset {p : Πa∈s, Prop} [hp : ∀a (h : a ∈ s), decidable (p a h)] :
decidable (∀a (h : a ∈ s), p a h) :=
multiset.decidable_dforall_multiset
/-- decidable equality for functions whose domain is bounded by finsets -/
instance decidable_eq_pi_finset {β : α → Type*} [h : ∀a, decidable_eq (β a)] :
decidable_eq (Πa∈s, β a) :=
multiset.decidable_eq_pi_multiset
instance decidable_dexists_finset {p : Πa∈s, Prop} [hp : ∀a (h : a ∈ s), decidable (p a h)] :
decidable (∃a (h : a ∈ s), p a h) :=
multiset.decidable_dexists_multiset
end decidable_pi_exists
/-! ### filter -/
section filter
variables (p q : α → Prop) [decidable_pred p] [decidable_pred q]
/-- `filter p s` is the set of elements of `s` that satisfy `p`. -/
def filter (s : finset α) : finset α :=
⟨_, nodup_filter p s.2⟩
@[simp] theorem filter_val (s : finset α) : (filter p s).1 = s.1.filter p := rfl
@[simp] theorem filter_subset (s : finset α) : s.filter p ⊆ s := filter_subset _ _
variable {p}
@[simp] theorem mem_filter {s : finset α} {a : α} : a ∈ s.filter p ↔ a ∈ s ∧ p a := mem_filter
theorem filter_ssubset {s : finset α} : s.filter p ⊂ s ↔ ∃ x ∈ s, ¬ p x :=
⟨λ h, let ⟨x, hs, hp⟩ := set.exists_of_ssubset h in ⟨x, hs, mt (λ hp, mem_filter.2 ⟨hs, hp⟩) hp⟩,
λ ⟨x, hs, hp⟩, ⟨s.filter_subset _, λ h, hp (mem_filter.1 (h hs)).2⟩⟩
variable (p)
theorem filter_filter (s : finset α) : (s.filter p).filter q = s.filter (λa, p a ∧ q a) :=
ext $ assume a, by simp only [mem_filter, and_comm, and.left_comm]
lemma filter_true {s : finset α} [h : decidable_pred (λ _, true)] :
@finset.filter α (λ _, true) h s = s :=
by ext; simp
@[simp] theorem filter_false {h} (s : finset α) : @filter α (λa, false) h s = ∅ :=
ext $ assume a, by simp only [mem_filter, and_false]; refl
variables {p q}
/-- If all elements of a `finset` satisfy the predicate `p`, `s.filter p` is `s`. -/
@[simp] lemma filter_true_of_mem {s : finset α} (h : ∀ x ∈ s, p x) : s.filter p = s :=
ext $ λ x, ⟨λ h, (mem_filter.1 h).1, λ hx, mem_filter.2 ⟨hx, h x hx⟩⟩
/-- If all elements of a `finset` fail to satisfy the predicate `p`, `s.filter p` is `∅`. -/
lemma filter_false_of_mem {s : finset α} (h : ∀ x ∈ s, ¬ p x) : s.filter p = ∅ :=
eq_empty_of_forall_not_mem (by simpa)
lemma filter_congr {s : finset α} (H : ∀ x ∈ s, p x ↔ q x) : filter p s = filter q s :=
eq_of_veq $ filter_congr H
variables (p q)
lemma filter_empty : filter p ∅ = ∅ := subset_empty.1 $ filter_subset _ _
lemma filter_subset_filter {s t : finset α} (h : s ⊆ t) : s.filter p ⊆ t.filter p :=
assume a ha, mem_filter.2 ⟨h (mem_filter.1 ha).1, (mem_filter.1 ha).2⟩
@[simp, norm_cast] lemma coe_filter (s : finset α) : ↑(s.filter p) = ({x ∈ ↑s | p x} : set α) :=
set.ext $ λ _, mem_filter
theorem filter_singleton (a : α) : filter p (singleton a) = if p a then singleton a else ∅ :=
by { classical, ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] }
variable [decidable_eq α]
theorem filter_union (s₁ s₂ : finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p :=
ext $ λ _, by simp only [mem_filter, mem_union, or_and_distrib_right]
theorem filter_union_right (s : finset α) : s.filter p ∪ s.filter q = s.filter (λx, p x ∨ q x) :=
ext $ λ x, by simp only [mem_filter, mem_union, and_or_distrib_left.symm]
lemma filter_mem_eq_inter {s t : finset α} [Π i, decidable (i ∈ t)] :
s.filter (λ i, i ∈ t) = s ∩ t :=
ext $ λ i, by rw [mem_filter, mem_inter]
theorem filter_inter (s t : finset α) : filter p s ∩ t = filter p (s ∩ t) :=
by { ext, simp only [mem_inter, mem_filter, and.right_comm] }
theorem inter_filter (s t : finset α) : s ∩ filter p t = filter p (s ∩ t) :=
by rw [inter_comm, filter_inter, inter_comm]
theorem filter_insert (a : α) (s : finset α) :
filter p (insert a s) = if p a then insert a (filter p s) else filter p s :=
by { ext x, simp, split_ifs with h; by_cases h' : x = a; simp [h, h'] }
theorem filter_or [decidable_pred (λ a, p a ∨ q a)] (s : finset α) :
s.filter (λ a, p a ∨ q a) = s.filter p ∪ s.filter q :=
ext $ λ _, by simp only [mem_filter, mem_union, and_or_distrib_left]
theorem filter_and [decidable_pred (λ a, p a ∧ q a)] (s : finset α) :
s.filter (λ a, p a ∧ q a) = s.filter p ∩ s.filter q :=
ext $ λ _, by simp only [mem_filter, mem_inter, and_comm, and.left_comm, and_self]
theorem filter_not [decidable_pred (λ a, ¬ p a)] (s : finset α) :
s.filter (λ a, ¬ p a) = s \ s.filter p :=
ext $ by simpa only [mem_filter, mem_sdiff, and_comm, not_and] using λ a, and_congr_right $
λ h : a ∈ s, (imp_iff_right h).symm.trans imp_not_comm
theorem sdiff_eq_filter (s₁ s₂ : finset α) :
s₁ \ s₂ = filter (∉ s₂) s₁ := ext $ λ _, by simp only [mem_sdiff, mem_filter]
theorem sdiff_eq_self (s₁ s₂ : finset α) :
s₁ \ s₂ = s₁ ↔ s₁ ∩ s₂ ⊆ ∅ :=
by { simp [subset.antisymm_iff],
split; intro h,
{ transitivity' ((s₁ \ s₂) ∩ s₂), mono, simp },
{ calc s₁ \ s₂
⊇ s₁ \ (s₁ ∩ s₂) : by simp [(⊇)]
... ⊇ s₁ \ ∅ : by mono using [(⊇)]
... ⊇ s₁ : by simp [(⊇)] } }
theorem filter_union_filter_neg_eq [decidable_pred (λ a, ¬ p a)]
(s : finset α) : s.filter p ∪ s.filter (λa, ¬ p a) = s :=
by simp only [filter_not, union_sdiff_of_subset (filter_subset p s)]
theorem filter_inter_filter_neg_eq (s : finset α) : s.filter p ∩ s.filter (λa, ¬ p a) = ∅ :=
by simp only [filter_not, inter_sdiff_self]
lemma subset_union_elim {s : finset α} {t₁ t₂ : set α} (h : ↑s ⊆ t₁ ∪ t₂) :
∃s₁ s₂ : finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ :=
begin
classical,
refine ⟨s.filter (∈ t₁), s.filter (∉ t₁), _, _ , _⟩,
{ simp [filter_union_right, em] },
{ intro x, simp },
{ intro x, simp, intros hx hx₂, refine ⟨or.resolve_left (h hx) hx₂, hx₂⟩ }
end
/- We can simplify an application of filter where the decidability is inferred in "the wrong way" -/
@[simp] lemma filter_congr_decidable {α} (s : finset α) (p : α → Prop) (h : decidable_pred p)
[decidable_pred p] : @filter α p h s = s.filter p :=
by congr
section classical
open_locale classical
/-- The following instance allows us to write `{x ∈ s | p x}` for `finset.filter p s`.
Since the former notation requires us to define this for all propositions `p`, and `finset.filter`
only works for decidable propositions, the notation `{x ∈ s | p x}` is only compatible with
classical logic because it uses `classical.prop_decidable`.
We don't want to redo all lemmas of `finset.filter` for `has_sep.sep`, so we make sure that `simp`
unfolds the notation `{x ∈ s | p x}` to `finset.filter p s`. If `p` happens to be decidable, the
simp-lemma `finset.filter_congr_decidable` will make sure that `finset.filter` uses the right
instance for decidability.
-/
noncomputable instance {α : Type*} : has_sep α (finset α) := ⟨λ p x, x.filter p⟩
@[simp] lemma sep_def {α : Type*} (s : finset α) (p : α → Prop) : {x ∈ s | p x} = s.filter p := rfl
end classical
/--
After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq'` with the equality the other way.
-/
-- This is not a good simp lemma, as it would prevent `finset.mem_filter` from firing
-- on, e.g. `x ∈ s.filter(eq b)`.
lemma filter_eq [decidable_eq β] (s : finset β) (b : β) :
s.filter (eq b) = ite (b ∈ s) {b} ∅ :=
begin
split_ifs,
{ ext,
simp only [mem_filter, mem_singleton],
exact ⟨λ h, h.2.symm, by { rintro ⟨h⟩, exact ⟨h, rfl⟩, }⟩ },
{ ext,
simp only [mem_filter, not_and, iff_false, not_mem_empty],
rintros m ⟨e⟩, exact h m, }
end
/--
After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq` with the equality the other way.
-/
lemma filter_eq' [decidable_eq β] (s : finset β) (b : β) :
s.filter (λ a, a = b) = ite (b ∈ s) {b} ∅ :=
trans (filter_congr (λ _ _, ⟨eq.symm, eq.symm⟩)) (filter_eq s b)
lemma filter_ne [decidable_eq β] (s : finset β) (b : β) :
s.filter (λ a, b ≠ a) = s.erase b :=
by { ext, simp only [mem_filter, mem_erase, ne.def], tauto, }
lemma filter_ne' [decidable_eq β] (s : finset β) (b : β) :
s.filter (λ a, a ≠ b) = s.erase b :=
trans (filter_congr (λ _ _, ⟨ne.symm, ne.symm⟩)) (filter_ne s b)
end filter
/-! ### range -/
section range
variables {n m l : ℕ}
/-- `range n` is the set of natural numbers less than `n`. -/
def range (n : ℕ) : finset ℕ := ⟨_, nodup_range n⟩
@[simp] theorem range_coe (n : ℕ) : (range n).1 = multiset.range n := rfl
@[simp] theorem mem_range : m ∈ range n ↔ m < n := mem_range
@[simp] theorem range_zero : range 0 = ∅ := rfl
@[simp] theorem range_one : range 1 = {0} := rfl
theorem range_succ : range (succ n) = insert n (range n) :=
eq_of_veq $ (range_succ n).trans $ (ndinsert_of_not_mem not_mem_range_self).symm
theorem range_add_one : range (n + 1) = insert n (range n) :=
range_succ
@[simp] theorem not_mem_range_self : n ∉ range n := not_mem_range_self
@[simp] theorem self_mem_range_succ (n : ℕ) : n ∈ range (n + 1) := multiset.self_mem_range_succ n
@[simp] theorem range_subset {n m} : range n ⊆ range m ↔ n ≤ m := range_subset
theorem range_mono : monotone range := λ _ _, range_subset.2
lemma mem_range_succ_iff {a b : ℕ} : a ∈ finset.range b.succ ↔ a ≤ b :=
finset.mem_range.trans nat.lt_succ_iff
lemma mem_range_le {n x : ℕ} (hx : x ∈ range n) : x ≤ n :=
(mem_range.1 hx).le
lemma mem_range_sub_ne_zero {n x : ℕ} (hx : x ∈ range n) : n - x ≠ 0 :=
ne_of_gt $ nat.sub_pos_of_lt $ mem_range.1 hx
end range
/- useful rules for calculations with quantifiers -/
theorem exists_mem_empty_iff (p : α → Prop) : (∃ x, x ∈ (∅ : finset α) ∧ p x) ↔ false :=
by simp only [not_mem_empty, false_and, exists_false]
theorem exists_mem_insert [d : decidable_eq α]
(a : α) (s : finset α) (p : α → Prop) :
(∃ x, x ∈ insert a s ∧ p x) ↔ p a ∨ (∃ x, x ∈ s ∧ p x) :=
by simp only [mem_insert, or_and_distrib_right, exists_or_distrib, exists_eq_left]
theorem forall_mem_empty_iff (p : α → Prop) : (∀ x, x ∈ (∅ : finset α) → p x) ↔ true :=
iff_true_intro $ λ _, false.elim
theorem forall_mem_insert [d : decidable_eq α]
(a : α) (s : finset α) (p : α → Prop) :
(∀ x, x ∈ insert a s → p x) ↔ p a ∧ (∀ x, x ∈ s → p x) :=
by simp only [mem_insert, or_imp_distrib, forall_and_distrib, forall_eq]
end finset
/-- Equivalence between the set of natural numbers which are `≥ k` and `ℕ`, given by `n → n - k`. -/
def not_mem_range_equiv (k : ℕ) : {n // n ∉ range k} ≃ ℕ :=
{ to_fun := λ i, i.1 - k,
inv_fun := λ j, ⟨j + k, by simp⟩,
left_inv :=
begin
assume j,
rw subtype.ext_iff_val,
apply nat.sub_add_cancel,
simpa using j.2
end,
right_inv := λ j, nat.add_sub_cancel _ _ }
@[simp] lemma coe_not_mem_range_equiv (k : ℕ) :
(not_mem_range_equiv k : {n // n ∉ range k} → ℕ) = (λ i, i - k) := rfl
@[simp] lemma coe_not_mem_range_equiv_symm (k : ℕ) :
((not_mem_range_equiv k).symm : ℕ → {n // n ∉ range k}) = λ j, ⟨j + k, by simp⟩ := rfl
namespace option
/-- Construct an empty or singleton finset from an `option` -/
def to_finset (o : option α) : finset α :=
match o with
| none := ∅
| some a := {a}
end
@[simp] theorem to_finset_none : none.to_finset = (∅ : finset α) := rfl
@[simp] theorem to_finset_some {a : α} : (some a).to_finset = {a} := rfl
@[simp] theorem mem_to_finset {a : α} {o : option α} : a ∈ o.to_finset ↔ a ∈ o :=
by cases o; simp only [to_finset, finset.mem_singleton, option.mem_def, eq_comm]; refl
end option
/-! ### erase_dup on list and multiset -/
namespace multiset
variable [decidable_eq α]
/-- `to_finset s` removes duplicates from the multiset `s` to produce a finset. -/
def to_finset (s : multiset α) : finset α := ⟨_, nodup_erase_dup s⟩
@[simp] theorem to_finset_val (s : multiset α) : s.to_finset.1 = s.erase_dup := rfl
theorem to_finset_eq {s : multiset α} (n : nodup s) : finset.mk s n = s.to_finset :=
finset.val_inj.1 (erase_dup_eq_self.2 n).symm
lemma nodup.to_finset_inj {l l' : multiset α} (hl : nodup l) (hl' : nodup l')
(h : l.to_finset = l'.to_finset) : l = l' :=
by simpa [←to_finset_eq hl, ←to_finset_eq hl'] using h
@[simp] theorem mem_to_finset {a : α} {s : multiset α} : a ∈ s.to_finset ↔ a ∈ s :=
mem_erase_dup
@[simp] lemma to_finset_zero :
to_finset (0 : multiset α) = ∅ :=
rfl
@[simp] lemma to_finset_cons (a : α) (s : multiset α) :
to_finset (a ::ₘ s) = insert a (to_finset s) :=
finset.eq_of_veq erase_dup_cons
@[simp] lemma to_finset_add (s t : multiset α) :
to_finset (s + t) = to_finset s ∪ to_finset t :=
finset.ext $ by simp
@[simp] lemma to_finset_nsmul (s : multiset α) :
∀(n : ℕ) (hn : n ≠ 0), (n • s).to_finset = s.to_finset
| 0 h := by contradiction
| (n+1) h :=
begin
by_cases n = 0,
{ rw [h, zero_add, one_nsmul] },
{ rw [add_nsmul, to_finset_add, one_nsmul, to_finset_nsmul n h, finset.union_idempotent] }
end
@[simp] lemma to_finset_inter (s t : multiset α) :
to_finset (s ∩ t) = to_finset s ∩ to_finset t :=
finset.ext $ by simp
@[simp] lemma to_finset_union (s t : multiset α) :
(s ∪ t).to_finset = s.to_finset ∪ t.to_finset :=
by ext; simp
theorem to_finset_eq_empty {m : multiset α} : m.to_finset = ∅ ↔ m = 0 :=
finset.val_inj.symm.trans multiset.erase_dup_eq_zero
@[simp] lemma to_finset_subset (m1 m2 : multiset α) :
m1.to_finset ⊆ m2.to_finset ↔ m1 ⊆ m2 :=
by simp only [finset.subset_iff, multiset.subset_iff, multiset.mem_to_finset]
end multiset
namespace finset
@[simp] lemma val_to_finset [decidable_eq α] (s : finset α) : s.val.to_finset = s :=
by { ext, rw [multiset.mem_to_finset, ←mem_def] }
end finset
namespace list
variable [decidable_eq α]
/-- `to_finset l` removes duplicates from the list `l` to produce a finset. -/
def to_finset (l : list α) : finset α := multiset.to_finset l
@[simp] theorem to_finset_val (l : list α) : l.to_finset.1 = (l.erase_dup : multiset α) := rfl
theorem to_finset_eq {l : list α} (n : nodup l) : @finset.mk α l n = l.to_finset :=
multiset.to_finset_eq n
@[simp] theorem mem_to_finset {a : α} {l : list α} : a ∈ l.to_finset ↔ a ∈ l :=
mem_erase_dup
@[simp] theorem to_finset_nil : to_finset (@nil α) = ∅ :=
rfl
@[simp] theorem to_finset_cons {a : α} {l : list α} : to_finset (a :: l) = insert a (to_finset l) :=
finset.eq_of_veq $ by by_cases h : a ∈ l; simp [finset.insert_val', multiset.erase_dup_cons, h]
lemma to_finset_surj_on : set.surj_on to_finset {l : list α | l.nodup} set.univ :=
begin
rintro s -,
cases s with t hl, induction t using quot.ind with l,
refine ⟨l, hl, (to_finset_eq hl).symm⟩
end
theorem to_finset_surjective : surjective (to_finset : list α → finset α) :=
by { intro s, rcases to_finset_surj_on (set.mem_univ s) with ⟨l, -, hls⟩, exact ⟨l, hls⟩ }
lemma to_finset_eq_iff_perm_erase_dup {l l' : list α} :
l.to_finset = l'.to_finset ↔ l.erase_dup ~ l'.erase_dup :=
by simp [finset.ext_iff, perm_ext (nodup_erase_dup _) (nodup_erase_dup _)]
lemma to_finset_eq_of_perm (l l' : list α) (h : l ~ l') :
l.to_finset = l'.to_finset :=
to_finset_eq_iff_perm_erase_dup.mpr h.erase_dup
lemma perm_of_nodup_nodup_to_finset_eq {l l' : list α} (hl : nodup l) (hl' : nodup l')
(h : l.to_finset = l'.to_finset) : l ~ l' :=
begin
rw ←multiset.coe_eq_coe,
exact multiset.nodup.to_finset_inj hl hl' h
end
@[simp] lemma to_finset_append {l l' : list α} :
to_finset (l ++ l') = l.to_finset ∪ l'.to_finset :=
begin
induction l with hd tl hl,
{ simp },
{ simp [hl] }
end
@[simp] lemma to_finset_reverse {l : list α} :
to_finset l.reverse = l.to_finset :=
to_finset_eq_of_perm _ _ (reverse_perm l)
end list
namespace finset
lemma exists_list_nodup_eq [decidable_eq α] (s : finset α) :
∃ (l : list α), l.nodup ∧ l.to_finset = s :=
begin
obtain ⟨⟨l⟩, hs⟩ := s,
exact ⟨l, hs, (list.to_finset_eq _).symm⟩,
end
/-! ### map -/
section map
open function
/-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image
finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/
def map (f : α ↪ β) (s : finset α) : finset β :=
⟨s.1.map f, nodup_map f.2 s.2⟩
@[simp] theorem map_val (f : α ↪ β) (s : finset α) : (map f s).1 = s.1.map f := rfl
@[simp] theorem map_empty (f : α ↪ β) : (∅ : finset α).map f = ∅ := rfl
variables {f : α ↪ β} {s : finset α}
@[simp] theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b :=
mem_map.trans $ by simp only [exists_prop]; refl
@[simp] theorem mem_map_equiv {f : α ≃ β} {b : β} :
b ∈ s.map f.to_embedding ↔ f.symm b ∈ s :=
by { rw mem_map, exact ⟨by { rintro ⟨a, H, rfl⟩, simpa }, λ h, ⟨_, h, by simp⟩⟩ }
theorem mem_map' (f : α ↪ β) {a} {s : finset α} : f a ∈ s.map f ↔ a ∈ s :=
mem_map_of_injective f.2
theorem mem_map_of_mem (f : α ↪ β) {a} {s : finset α} : a ∈ s → f a ∈ s.map f :=
(mem_map' _).2
lemma apply_coe_mem_map (f : α ↪ β) (s : finset α) (x : s) : f x ∈ s.map f :=
mem_map_of_mem f x.prop
@[simp, norm_cast] theorem coe_map (f : α ↪ β) (s : finset α) : (s.map f : set β) = f '' s :=
set.ext $ λ x, mem_map.trans set.mem_image_iff_bex.symm
theorem coe_map_subset_range (f : α ↪ β) (s : finset α) : (s.map f : set β) ⊆ set.range f :=
calc ↑(s.map f) = f '' s : coe_map f s
... ⊆ set.range f : set.image_subset_range f ↑s
theorem map_to_finset [decidable_eq α] [decidable_eq β] {s : multiset α} :
s.to_finset.map f = (s.map f).to_finset :=
ext $ λ _, by simp only [mem_map, multiset.mem_map, exists_prop, multiset.mem_to_finset]
@[simp] theorem map_refl : s.map (embedding.refl _) = s :=
ext $ λ _, by simpa only [mem_map, exists_prop] using exists_eq_right
@[simp] theorem map_cast_heq {α β} (h : α = β) (s : finset α) :
s.map (equiv.cast h).to_embedding == s :=
by { subst h, simp }
theorem map_map {g : β ↪ γ} : (s.map f).map g = s.map (f.trans g) :=
eq_of_veq $ by simp only [map_val, multiset.map_map]; refl
theorem map_subset_map {s₁ s₂ : finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ :=
⟨λ h x xs, (mem_map' _).1 $ h $ (mem_map' f).2 xs,
λ h, by simp [subset_def, map_subset_map h]⟩
theorem map_inj {s₁ s₂ : finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ :=
by simp only [subset.antisymm_iff, map_subset_map]
/-- Associate to an embedding `f` from `α` to `β` the embedding that maps a finset to its image
under `f`. -/
def map_embedding (f : α ↪ β) : finset α ↪ finset β := ⟨map f, λ s₁ s₂, map_inj.1⟩
@[simp] theorem map_embedding_apply : map_embedding f s = map f s := rfl
theorem map_filter {p : β → Prop} [decidable_pred p] :
(s.map f).filter p = (s.filter (p ∘ f)).map f :=
eq_of_veq (map_filter _ _ _)
theorem map_union [decidable_eq α] [decidable_eq β]
{f : α ↪ β} (s₁ s₂ : finset α) : (s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f :=
ext $ λ _, by simp only [mem_map, mem_union, exists_prop, or_and_distrib_right, exists_or_distrib]
theorem map_inter [decidable_eq α] [decidable_eq β]
{f : α ↪ β} (s₁ s₂ : finset α) : (s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f :=
ext $ λ b, by simp only [mem_map, mem_inter, exists_prop]; exact
⟨by rintro ⟨a, ⟨m₁, m₂⟩, rfl⟩; exact ⟨⟨a, m₁, rfl⟩, ⟨a, m₂, rfl⟩⟩,
by rintro ⟨⟨a, m₁, e⟩, ⟨a', m₂, rfl⟩⟩; cases f.2 e; exact ⟨_, ⟨m₁, m₂⟩, rfl⟩⟩
@[simp] theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} :=
ext $ λ _, by simp only [mem_map, mem_singleton, exists_prop, exists_eq_left]; exact eq_comm
@[simp] theorem map_insert [decidable_eq α] [decidable_eq β]
(f : α ↪ β) (a : α) (s : finset α) :
(insert a s).map f = insert (f a) (s.map f) :=
by simp only [insert_eq, map_union, map_singleton]
@[simp] theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ :=
⟨λ h, eq_empty_of_forall_not_mem $
λ a m, ne_empty_of_mem (mem_map_of_mem _ m) h, λ e, e.symm ▸ rfl⟩
lemma attach_map_val {s : finset α} : s.attach.map (embedding.subtype _) = s :=
eq_of_veq $ by rw [map_val, attach_val]; exact attach_map_val _
lemma nonempty.map (h : s.nonempty) (f : α ↪ β) : (s.map f).nonempty :=
let ⟨a, ha⟩ := h in ⟨f a, (mem_map' f).mpr ha⟩
end map
lemma range_add_one' (n : ℕ) :
range (n + 1) = insert 0 ((range n).map ⟨λi, i + 1, assume i j, nat.succ.inj⟩) :=
by ext (⟨⟩ | ⟨n⟩); simp [nat.succ_eq_add_one, nat.zero_lt_succ n]
/-! ### image -/
section image
variables [decidable_eq β]
/-- `image f s` is the forward image of `s` under `f`. -/
def image (f : α → β) (s : finset α) : finset β := (s.1.map f).to_finset
@[simp] theorem image_val (f : α → β) (s : finset α) : (image f s).1 = (s.1.map f).erase_dup := rfl
@[simp] theorem image_empty (f : α → β) : (∅ : finset α).image f = ∅ := rfl
variables {f : α → β} {s : finset α}
@[simp] theorem mem_image {b : β} : b ∈ s.image f ↔ ∃ a ∈ s, f a = b :=
by simp only [mem_def, image_val, mem_erase_dup, multiset.mem_map, exists_prop]
theorem mem_image_of_mem (f : α → β) {a} {s : finset α} (h : a ∈ s) : f a ∈ s.image f :=
mem_image.2 ⟨_, h, rfl⟩
lemma filter_mem_image_eq_image (f : α → β) (s : finset α) (t : finset β) (h : ∀ x ∈ s, f x ∈ t) :
t.filter (λ y, y ∈ s.image f) = s.image f :=
by { ext, rw [mem_filter, mem_image],
simp only [and_imp, exists_prop, and_iff_right_iff_imp, exists_imp_distrib],
rintros x xel rfl, exact h _ xel }
lemma fiber_nonempty_iff_mem_image (f : α → β) (s : finset α) (y : β) :
(s.filter (λ x, f x = y)).nonempty ↔ y ∈ s.image f :=
by simp [finset.nonempty]
@[simp, norm_cast] lemma coe_image {f : α → β} : ↑(s.image f) = f '' ↑s :=
set.ext $ λ _, mem_image.trans set.mem_image_iff_bex.symm
lemma nonempty.image (h : s.nonempty) (f : α → β) : (s.image f).nonempty :=
let ⟨a, ha⟩ := h in ⟨f a, mem_image_of_mem f ha⟩
@[simp]
lemma nonempty.image_iff (f : α → β) : (s.image f).nonempty ↔ s.nonempty :=
⟨λ ⟨y, hy⟩, let ⟨x, hx, _⟩ := mem_image.mp hy in ⟨x, hx⟩, λ h, h.image f⟩
theorem image_to_finset [decidable_eq α] {s : multiset α} :
s.to_finset.image f = (s.map f).to_finset :=
ext $ λ _, by simp only [mem_image, multiset.mem_to_finset, exists_prop, multiset.mem_map]
theorem image_val_of_inj_on (H : set.inj_on f s) : (image f s).1 = s.1.map f :=
multiset.erase_dup_eq_self.2 (nodup_map_on H s.2)
@[simp]
theorem image_id [decidable_eq α] : s.image id = s :=
ext $ λ _, by simp only [mem_image, exists_prop, id, exists_eq_right]
theorem image_image [decidable_eq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) :=
eq_of_veq $ by simp only [image_val, erase_dup_map_erase_dup_eq, multiset.map_map]
theorem image_subset_image {s₁ s₂ : finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f :=
by simp only [subset_def, image_val, subset_erase_dup', erase_dup_subset',
multiset.map_subset_map h]
theorem image_subset_iff {s : finset α} {t : finset β} {f : α → β} :
s.image f ⊆ t ↔ ∀ x ∈ s, f x ∈ t :=
calc s.image f ⊆ t ↔ f '' ↑s ⊆ ↑t : by norm_cast
... ↔ _ : set.image_subset_iff
theorem image_mono (f : α → β) : monotone (finset.image f) := λ _ _, image_subset_image
theorem coe_image_subset_range : ↑(s.image f) ⊆ set.range f :=
calc ↑(s.image f) = f '' ↑s : coe_image
... ⊆ set.range f : set.image_subset_range f ↑s
theorem image_filter {p : β → Prop} [decidable_pred p] :
(s.image f).filter p = (s.filter (p ∘ f)).image f :=
ext $ λ b, by simp only [mem_filter, mem_image, exists_prop]; exact
⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩,
by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩
theorem image_union [decidable_eq α] {f : α → β} (s₁ s₂ : finset α) :
(s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f :=
ext $ λ _, by simp only [mem_image, mem_union, exists_prop, or_and_distrib_right,
exists_or_distrib]
theorem image_inter [decidable_eq α] (s₁ s₂ : finset α) (hf : ∀x y, f x = f y → x = y) :
(s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f :=
ext $ by simp only [mem_image, exists_prop, mem_inter]; exact λ b,
⟨λ ⟨a, ⟨m₁, m₂⟩, e⟩, ⟨⟨a, m₁, e⟩, ⟨a, m₂, e⟩⟩,
λ ⟨⟨a, m₁, e₁⟩, ⟨a', m₂, e₂⟩⟩, ⟨a, ⟨m₁, hf _ _ (e₂.trans e₁.symm) ▸ m₂⟩, e₁⟩⟩.
@[simp] theorem image_singleton (f : α → β) (a : α) : image f {a} = {f a} :=
ext $ λ x, by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm
@[simp] theorem image_insert [decidable_eq α] (f : α → β) (a : α) (s : finset α) :
(insert a s).image f = insert (f a) (s.image f) :=
by simp only [insert_eq, image_singleton, image_union]
@[simp] theorem image_eq_empty : s.image f = ∅ ↔ s = ∅ :=
⟨λ h, eq_empty_of_forall_not_mem $
λ a m, ne_empty_of_mem (mem_image_of_mem _ m) h, λ e, e.symm ▸ rfl⟩
lemma mem_range_iff_mem_finset_range_of_mod_eq' [decidable_eq α] {f : ℕ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀i, f (i % n) = f i) :
a ∈ set.range f ↔ a ∈ (finset.range n).image (λi, f i) :=
begin
split,
{ rintros ⟨i, hi⟩,
simp only [mem_image, exists_prop, mem_range],
exact ⟨i % n, nat.mod_lt i hn, (rfl.congr hi).mp (h i)⟩ },
{ rintro h,
simp only [mem_image, exists_prop, set.mem_range, mem_range] at *,
rcases h with ⟨i, hi, ha⟩,
use ⟨i, ha⟩ },
end
lemma mem_range_iff_mem_finset_range_of_mod_eq [decidable_eq α] {f : ℤ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀i, f (i % n) = f i) :
a ∈ set.range f ↔ a ∈ (finset.range n).image (λi, f i) :=
suffices (∃i, f (i % n) = a) ↔ ∃i, i < n ∧ f ↑i = a, by simpa [h],
have hn' : 0 < (n : ℤ), from int.coe_nat_lt.mpr hn,
iff.intro
(assume ⟨i, hi⟩,
have 0 ≤ i % ↑n, from int.mod_nonneg _ (ne_of_gt hn'),
⟨int.to_nat (i % n),
by rw [←int.coe_nat_lt, int.to_nat_of_nonneg this]; exact ⟨int.mod_lt_of_pos i hn', hi⟩⟩)
(assume ⟨i, hi, ha⟩,
⟨i, by rw [int.mod_eq_of_lt (int.coe_zero_le _) (int.coe_nat_lt_coe_nat_of_lt hi), ha]⟩)
lemma attach_image_val [decidable_eq α] {s : finset α} : s.attach.image subtype.val = s :=
eq_of_veq $ by rw [image_val, attach_val, multiset.attach_map_val, erase_dup_eq_self]
@[simp] lemma attach_insert [decidable_eq α] {a : α} {s : finset α} :
attach (insert a s) = insert (⟨a, mem_insert_self a s⟩ : {x // x ∈ insert a s})
((attach s).image (λx, ⟨x.1, mem_insert_of_mem x.2⟩)) :=
ext $ λ ⟨x, hx⟩, ⟨or.cases_on (mem_insert.1 hx)
(λ h : x = a, λ _, mem_insert.2 $ or.inl $ subtype.eq h)
(λ h : x ∈ s, λ _, mem_insert_of_mem $ mem_image.2 $ ⟨⟨x, h⟩, mem_attach _ _, subtype.eq rfl⟩),
λ _, finset.mem_attach _ _⟩
theorem map_eq_image (f : α ↪ β) (s : finset α) : s.map f = s.image f :=
eq_of_veq $ (multiset.erase_dup_eq_self.2 (s.map f).2).symm
lemma image_const {s : finset α} (h : s.nonempty) (b : β) : s.image (λa, b) = singleton b :=
ext $ assume b', by simp only [mem_image, exists_prop, exists_and_distrib_right,
h.bex, true_and, mem_singleton, eq_comm]
/--
Because `finset.image` requires a `decidable_eq` instances for the target type,
we can only construct a `functor finset` when working classically.
-/
instance [Π P, decidable P] : functor finset :=
{ map := λ α β f s, s.image f, }
instance [Π P, decidable P] : is_lawful_functor finset :=
{ id_map := λ α x, image_id,
comp_map := λ α β γ f g s, image_image.symm, }
/-- Given a finset `s` and a predicate `p`, `s.subtype p` is the finset of `subtype p` whose
elements belong to `s`. -/
protected def subtype {α} (p : α → Prop) [decidable_pred p] (s : finset α) : finset (subtype p) :=
(s.filter p).attach.map ⟨λ x, ⟨x.1, (finset.mem_filter.1 x.2).2⟩,
λ x y H, subtype.eq $ subtype.mk.inj H⟩
@[simp] lemma mem_subtype {p : α → Prop} [decidable_pred p] {s : finset α} :
∀{a : subtype p}, a ∈ s.subtype p ↔ (a : α) ∈ s
| ⟨a, ha⟩ := by simp [finset.subtype, ha]
lemma subtype_eq_empty {p : α → Prop} [decidable_pred p] {s : finset α} :
s.subtype p = ∅ ↔ ∀ x, p x → x ∉ s :=
by simp [ext_iff, subtype.forall, subtype.coe_mk]; refl
/-- `s.subtype p` converts back to `s.filter p` with
`embedding.subtype`. -/
@[simp] lemma subtype_map (p : α → Prop) [decidable_pred p] :
(s.subtype p).map (embedding.subtype _) = s.filter p :=
begin
ext x,
rw mem_map,
change (∃ a : {x // p x}, ∃ H, (a : α) = x) ↔ _,
split,
{ rintros ⟨y, hy, hyval⟩,
rw [mem_subtype, hyval] at hy,
rw mem_filter,
use hy,
rw ← hyval,
use y.property },
{ intro hx,
rw mem_filter at hx,
use ⟨⟨x, hx.2⟩, mem_subtype.2 hx.1, rfl⟩ }
end
/-- If all elements of a `finset` satisfy the predicate `p`,
`s.subtype p` converts back to `s` with `embedding.subtype`. -/
lemma subtype_map_of_mem {p : α → Prop} [decidable_pred p] (h : ∀ x ∈ s, p x) :
(s.subtype p).map (embedding.subtype _) = s :=
by rw [subtype_map, filter_true_of_mem h]
/-- If a `finset` of a subtype is converted to the main type with
`embedding.subtype`, all elements of the result have the property of
the subtype. -/
lemma property_of_mem_map_subtype {p : α → Prop} (s : finset {x // p x}) {a : α}
(h : a ∈ s.map (embedding.subtype _)) : p a :=
begin
rcases mem_map.1 h with ⟨x, hx, rfl⟩,
exact x.2
end
/-- If a `finset` of a subtype is converted to the main type with
`embedding.subtype`, the result does not contain any value that does
not satisfy the property of the subtype. -/
lemma not_mem_map_subtype_of_not_property {p : α → Prop} (s : finset {x // p x})
{a : α} (h : ¬ p a) : a ∉ (s.map (embedding.subtype _)) :=
mt s.property_of_mem_map_subtype h
/-- If a `finset` of a subtype is converted to the main type with
`embedding.subtype`, the result is a subset of the set giving the
subtype. -/
lemma map_subtype_subset {t : set α} (s : finset t) :
↑(s.map (embedding.subtype _)) ⊆ t :=
begin
intros a ha,
rw mem_coe at ha,
convert property_of_mem_map_subtype s ha
end
lemma subset_image_iff {f : α → β}
{s : finset β} {t : set α} : ↑s ⊆ f '' t ↔ ∃s' : finset α, ↑s' ⊆ t ∧ s'.image f = s :=
begin
classical,
split, swap,
{ rintro ⟨s, hs, rfl⟩, rw [coe_image], exact set.image_subset f hs },
intro h, induction s using finset.induction with a s has ih h,
{ refine ⟨∅, set.empty_subset _, _⟩,
convert finset.image_empty _ },
rw [finset.coe_insert, set.insert_subset] at h,
rcases ih h.2 with ⟨s', hst, hsi⟩,
rcases h.1 with ⟨x, hxt, rfl⟩,
refine ⟨insert x s', _, _⟩,
{ rw [finset.coe_insert, set.insert_subset], exact ⟨hxt, hst⟩ },
rw [finset.image_insert, hsi],
congr
end
end image
end finset
theorem multiset.to_finset_map [decidable_eq α] [decidable_eq β] (f : α → β) (m : multiset α) :
(m.map f).to_finset = m.to_finset.image f :=
finset.val_inj.1 (multiset.erase_dup_map_erase_dup_eq _ _).symm
namespace finset
/-! ### card -/
section card
/-- `card s` is the cardinality (number of elements) of `s`. -/
def card (s : finset α) : nat := s.1.card
theorem card_def (s : finset α) : s.card = s.1.card := rfl
@[simp] lemma card_mk {m nodup} : (⟨m, nodup⟩ : finset α).card = m.card := rfl
@[simp] theorem card_empty : card (∅ : finset α) = 0 := rfl
theorem card_le_of_subset {s t : finset α} : s ⊆ t → card s ≤ card t :=
multiset.card_le_of_le ∘ val_le_iff.mpr
@[simp] theorem card_eq_zero {s : finset α} : card s = 0 ↔ s = ∅ :=
card_eq_zero.trans val_eq_zero
theorem card_pos {s : finset α} : 0 < card s ↔ s.nonempty :=
pos_iff_ne_zero.trans $ (not_congr card_eq_zero).trans nonempty_iff_ne_empty.symm
theorem card_ne_zero_of_mem {s : finset α} {a : α} (h : a ∈ s) : card s ≠ 0 :=
(not_congr card_eq_zero).2 (ne_empty_of_mem h)
theorem card_eq_one {s : finset α} : s.card = 1 ↔ ∃ a, s = {a} :=
by cases s; simp only [multiset.card_eq_one, finset.card, ← val_inj, singleton_val]
theorem card_le_one {s : finset α} : s.card ≤ 1 ↔ ∀ (a ∈ s) (b ∈ s), a = b :=
begin
rcases s.eq_empty_or_nonempty with rfl|⟨x, hx⟩, { simp },
refine (nat.succ_le_of_lt (card_pos.2 ⟨x, hx⟩)).le_iff_eq.trans (card_eq_one.trans ⟨_, _⟩),
{ rintro ⟨y, rfl⟩, simp },
{ exact λ h, ⟨x, eq_singleton_iff_unique_mem.2 ⟨hx, λ y hy, h _ hy _ hx⟩⟩ }
end
theorem card_le_one_iff {s : finset α} : s.card ≤ 1 ↔ ∀ {a b}, a ∈ s → b ∈ s → a = b :=
by { rw card_le_one, tauto }
lemma card_le_one_iff_subset_singleton [nonempty α] {s : finset α} :
s.card ≤ 1 ↔ ∃ (x : α), s ⊆ {x} :=
begin
split,
{ assume H,
by_cases h : ∃ x, x ∈ s,
{ rcases h with ⟨x, hx⟩,
refine ⟨x, λ y hy, _⟩,
rw [card_le_one.1 H y hy x hx, mem_singleton] },
{ push_neg at h,
inhabit α,
exact ⟨default α, λ y hy, (h y hy).elim⟩ } },
{ rintros ⟨x, hx⟩,
rw ← card_singleton x,
exact card_le_of_subset hx }
end
/-- A `finset` of a subsingleton type has cardinality at most one. -/
lemma card_le_one_of_subsingleton [subsingleton α] (s : finset α) : s.card ≤ 1 :=
finset.card_le_one_iff.2 $ λ _ _ _ _, subsingleton.elim _ _
theorem one_lt_card {s : finset α} : 1 < s.card ↔ ∃ (a ∈ s) (b ∈ s), a ≠ b :=
by { rw ← not_iff_not, push_neg, exact card_le_one }
lemma one_lt_card_iff {s : finset α} :
1 < s.card ↔ ∃ x y, (x ∈ s) ∧ (y ∈ s) ∧ x ≠ y :=
by { rw one_lt_card, simp only [exists_prop, exists_and_distrib_left] }
@[simp] theorem card_insert_of_not_mem [decidable_eq α]
{a : α} {s : finset α} (h : a ∉ s) : card (insert a s) = card s + 1 :=
by simpa only [card_cons, card, insert_val] using
congr_arg multiset.card (ndinsert_of_not_mem h)
theorem card_insert_of_mem [decidable_eq α] {a : α} {s : finset α}
(h : a ∈ s) : card (insert a s) = card s := by rw insert_eq_of_mem h
theorem card_insert_le [decidable_eq α] (a : α) (s : finset α) : card (insert a s) ≤ card s + 1 :=
by by_cases a ∈ s; [{rw [insert_eq_of_mem h], apply nat.le_add_right},
rw [card_insert_of_not_mem h]]
@[simp] theorem card_singleton (a : α) : card ({a} : finset α) = 1 := card_singleton _
lemma card_singleton_inter [decidable_eq α] {x : α} {s : finset α} : ({x} ∩ s).card ≤ 1 :=
begin
cases (finset.decidable_mem x s),
{ simp [finset.singleton_inter_of_not_mem h] },
{ simp [finset.singleton_inter_of_mem h] },
end
theorem card_erase_of_mem [decidable_eq α] {a : α} {s : finset α} :
a ∈ s → card (erase s a) = pred (card s) := card_erase_of_mem
theorem card_erase_lt_of_mem [decidable_eq α] {a : α} {s : finset α} :
a ∈ s → card (erase s a) < card s := card_erase_lt_of_mem
theorem card_erase_le [decidable_eq α] {a : α} {s : finset α} :
card (erase s a) ≤ card s := card_erase_le
theorem pred_card_le_card_erase [decidable_eq α] {a : α} {s : finset α} :
card s - 1 ≤ card (erase s a) :=
begin
by_cases h : a ∈ s,
{ rw [card_erase_of_mem h], refl },
{ rw [erase_eq_of_not_mem h], apply nat.sub_le }
end
@[simp] theorem card_range (n : ℕ) : card (range n) = n := card_range n
@[simp] theorem card_attach {s : finset α} : card (attach s) = card s := multiset.card_attach
end card
end finset
theorem multiset.to_finset_card_le [decidable_eq α] (m : multiset α) : m.to_finset.card ≤ m.card :=
card_le_of_le (erase_dup_le _)
lemma list.card_to_finset [decidable_eq α] (l : list α) :
finset.card l.to_finset = l.erase_dup.length := rfl
theorem list.to_finset_card_le [decidable_eq α] (l : list α) : l.to_finset.card ≤ l.length :=
multiset.to_finset_card_le ⟦l⟧
namespace finset
section card
theorem card_image_le [decidable_eq β] {f : α → β} {s : finset α} : card (image f s) ≤ card s :=
by simpa only [card_map] using (s.1.map f).to_finset_card_le
theorem card_image_of_inj_on [decidable_eq β] {f : α → β} {s : finset α}
(H : set.inj_on f s) : card (image f s) = card s :=
by simp only [card, image_val_of_inj_on H, card_map]
theorem inj_on_of_card_image_eq [decidable_eq β] {f : α → β} {s : finset α}
(H : card (image f s) = card s) :
set.inj_on f s :=
begin
change (s.1.map f).erase_dup.card = s.1.card at H,
have : (s.1.map f).erase_dup = s.1.map f,
{ apply multiset.eq_of_le_of_card_le,
{ apply multiset.erase_dup_le },
rw H,
simp only [multiset.card_map] },
rw multiset.erase_dup_eq_self at this,
apply inj_on_of_nodup_map this,
end
theorem card_image_eq_iff_inj_on [decidable_eq β] {f : α → β} {s : finset α} :
(s.image f).card = s.card ↔ set.inj_on f s :=
⟨inj_on_of_card_image_eq, card_image_of_inj_on⟩
theorem card_image_of_injective [decidable_eq β] {f : α → β} (s : finset α)
(H : injective f) : card (image f s) = card s :=
card_image_of_inj_on $ λ x _ y _ h, H h
lemma fiber_card_ne_zero_iff_mem_image (s : finset α) (f : α → β) [decidable_eq β] (y : β) :
(s.filter (λ x, f x = y)).card ≠ 0 ↔ y ∈ s.image f :=
by { rw [←pos_iff_ne_zero, card_pos, fiber_nonempty_iff_mem_image] }
@[simp] lemma card_map {α β} (f : α ↪ β) {s : finset α} : (s.map f).card = s.card :=
multiset.card_map _ _
@[simp] lemma card_subtype (p : α → Prop) [decidable_pred p] (s : finset α) :
(s.subtype p).card = (s.filter p).card :=
by simp [finset.subtype]
lemma card_eq_of_bijective {s : finset α} {n : ℕ}
(f : ∀i, i < n → α)
(hf : ∀a∈s, ∃i, ∃h:i<n, f i h = a) (hf' : ∀i (h : i < n), f i h ∈ s)
(f_inj : ∀i j (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) :
card s = n :=
begin
classical,
have : ∀ (a : α), a ∈ s ↔ ∃i (hi : i ∈ range n), f i (mem_range.1 hi) = a,
from assume a, ⟨assume ha, let ⟨i, hi, eq⟩ := hf a ha in ⟨i, mem_range.2 hi, eq⟩,
assume ⟨i, hi, eq⟩, eq ▸ hf' i (mem_range.1 hi)⟩,
have : s = ((range n).attach.image $ λi, f i.1 (mem_range.1 i.2)),
by simpa only [ext_iff, mem_image, exists_prop, subtype.exists, mem_attach, true_and],
calc card s = card ((range n).attach.image $ λi, f i.1 (mem_range.1 i.2)) :
by rw [this]
... = card ((range n).attach) :
card_image_of_injective _ $ assume ⟨i, hi⟩ ⟨j, hj⟩ eq,
subtype.eq $ f_inj i j (mem_range.1 hi) (mem_range.1 hj) eq
... = card (range n) : card_attach
... = n : card_range n
end
lemma card_eq_succ [decidable_eq α] {s : finset α} {n : ℕ} :
s.card = n + 1 ↔ (∃a t, a ∉ t ∧ insert a t = s ∧ card t = n) :=
iff.intro
(assume eq,
have 0 < card s, from eq.symm ▸ nat.zero_lt_succ _,
let ⟨a, has⟩ := card_pos.mp this in
⟨a, s.erase a, s.not_mem_erase a, insert_erase has,
by simp only [eq, card_erase_of_mem has, pred_succ]⟩)
(assume ⟨a, t, hat, s_eq, n_eq⟩, s_eq ▸ n_eq ▸ card_insert_of_not_mem hat)
theorem card_filter_le (s : finset α) (p : α → Prop) [decidable_pred p] :
card (s.filter p) ≤ card s :=
card_le_of_subset $ filter_subset _ _
theorem eq_of_subset_of_card_le {s t : finset α} (h : s ⊆ t) (h₂ : card t ≤ card s) : s = t :=
eq_of_veq $ multiset.eq_of_le_of_card_le (val_le_iff.mpr h) h₂
lemma card_lt_card {s t : finset α} (h : s ⊂ t) : s.card < t.card :=
card_lt_of_lt (val_lt_iff.2 h)
lemma card_le_card_of_inj_on {s : finset α} {t : finset β}
(f : α → β) (hf : ∀a∈s, f a ∈ t) (f_inj : ∀a₁∈s, ∀a₂∈s, f a₁ = f a₂ → a₁ = a₂) :
card s ≤ card t :=
begin
classical,
calc card s = card (s.image f) : by rw [card_image_of_inj_on f_inj]
... ≤ card t : card_le_of_subset $ image_subset_iff.2 hf
end
/--
If there are more pigeons than pigeonholes, then there are two pigeons
in the same pigeonhole.
-/
lemma exists_ne_map_eq_of_card_lt_of_maps_to {s : finset α} {t : finset β} (hc : t.card < s.card)
{f : α → β} (hf : ∀ a ∈ s, f a ∈ t) :
∃ (x ∈ s) (y ∈ s), x ≠ y ∧ f x = f y :=
begin
classical, by_contra hz, push_neg at hz,
refine hc.not_le (card_le_card_of_inj_on f hf _),
intros x hx y hy, contrapose, exact hz x hx y hy,
end
lemma le_card_of_inj_on_range {n} {s : finset α}
(f : ℕ → α) (hf : ∀i<n, f i ∈ s) (f_inj : ∀ (i<n) (j<n), f i = f j → i = j) : n ≤ card s :=
calc n = card (range n) : (card_range n).symm
... ≤ card s : card_le_card_of_inj_on f (by simpa only [mem_range]) (by simpa only [mem_range])
/-- Suppose that, given objects defined on all strict subsets of any finset `s`, one knows how to
define an object on `s`. Then one can inductively define an object on all finsets, starting from
the empty set and iterating. This can be used either to define data, or to prove properties. -/
def strong_induction {p : finset α → Sort*} (H : ∀ s, (∀ t ⊂ s, p t) → p s) :
∀ (s : finset α), p s
| s := H s (λ t h, have card t < card s, from card_lt_card h, strong_induction t)
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf card⟩]}
lemma strong_induction_eq {p : finset α → Sort*} (H : ∀ s, (∀ t ⊂ s, p t) → p s) (s : finset α) :
strong_induction H s = H s (λ t h, strong_induction H t) :=
by rw strong_induction
/-- Analogue of `strong_induction` with order of arguments swapped. -/
@[elab_as_eliminator] def strong_induction_on {p : finset α → Sort*} :
∀ (s : finset α), (∀s, (∀ t ⊂ s, p t) → p s) → p s :=
λ s H, strong_induction H s
lemma strong_induction_on_eq {p : finset α → Sort*} (s : finset α) (H : ∀ s, (∀ t ⊂ s, p t) → p s) :
s.strong_induction_on H = H s (λ t h, t.strong_induction_on H) :=
by { dunfold strong_induction_on, rw strong_induction }
@[elab_as_eliminator] lemma case_strong_induction_on [decidable_eq α] {p : finset α → Prop}
(s : finset α) (h₀ : p ∅) (h₁ : ∀ a s, a ∉ s → (∀ t ⊆ s, p t) → p (insert a s)) : p s :=
finset.strong_induction_on s $ λ s,
finset.induction_on s (λ _, h₀) $ λ a s n _ ih, h₁ a s n $
λ t ss, ih _ (lt_of_le_of_lt ss (ssubset_insert n) : t < _)
/-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than
`n`, one knows how to define `p s`. Then one can inductively define `p s` for all finsets `s` of
cardinality less than `n`, starting from finsets of card `n` and iterating. This
can be used either to define data, or to prove properties. -/
def strong_downward_induction {p : finset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : finset α},
t₂.card ≤ n → t₁ ⊂ t₂ → p t₂) → t₁.card ≤ n → p t₁) :
∀ (s : finset α), s.card ≤ n → p s
| s := H s (λ t ht h, have n - card t < n - card s,
from (nat.sub_lt_sub_left_iff ht).2 (finset.card_lt_card h),
strong_downward_induction t ht)
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ (t : finset α), n - t.card)⟩]}
lemma strong_downward_induction_eq {p : finset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : finset α},
t₂.card ≤ n → t₁ ⊂ t₂ → p t₂) → t₁.card ≤ n → p t₁) (s : finset α) :
strong_downward_induction H s = H s (λ t ht hst, strong_downward_induction H t ht) :=
by rw strong_downward_induction
/-- Analogue of `strong_downward_induction` with order of arguments swapped. -/
@[elab_as_eliminator] def strong_downward_induction_on {p : finset α → Sort*} {n : ℕ} :
∀ (s : finset α), (∀ t₁, (∀ {t₂ : finset α}, t₂.card ≤ n → t₁ ⊂ t₂ → p t₂) → t₁.card ≤ n → p t₁)
→ s.card ≤ n → p s :=
λ s H, strong_downward_induction H s
lemma strong_downward_induction_on_eq {p : finset α → Sort*} (s : finset α) {n : ℕ} (H : ∀ t₁,
(∀ {t₂ : finset α}, t₂.card ≤ n → t₁ ⊂ t₂ → p t₂) → t₁.card ≤ n → p t₁) :
s.strong_downward_induction_on H = H s (λ t ht h, t.strong_downward_induction_on H ht) :=
by { dunfold strong_downward_induction_on, rw strong_downward_induction }
lemma card_congr {s : finset α} {t : finset β} (f : Π a ∈ s, β)
(h₁ : ∀ a ha, f a ha ∈ t) (h₂ : ∀ a b ha hb, f a ha = f b hb → a = b)
(h₃ : ∀ b ∈ t, ∃ a ha, f a ha = b) : s.card = t.card :=
by haveI := classical.prop_decidable; exact
calc s.card = s.attach.card : card_attach.symm
... = (s.attach.image (λ (a : {a // a ∈ s}), f a.1 a.2)).card :
eq.symm (card_image_of_injective _ (λ a b h, subtype.eq (h₂ _ _ _ _ h)))
... = t.card : congr_arg card (finset.ext $ λ b,
⟨λ h, let ⟨a, ha₁, ha₂⟩ := mem_image.1 h in ha₂ ▸ h₁ _ _,
λ h, let ⟨a, ha₁, ha₂⟩ := h₃ b h in mem_image.2 ⟨⟨a, ha₁⟩, by simp [ha₂]⟩⟩)
lemma card_union_add_card_inter [decidable_eq α] (s t : finset α) :
(s ∪ t).card + (s ∩ t).card = s.card + t.card :=
finset.induction_on t (by simp) $ λ a r har, by by_cases a ∈ s; simp *; cc
lemma card_union_le [decidable_eq α] (s t : finset α) :
(s ∪ t).card ≤ s.card + t.card :=
card_union_add_card_inter s t ▸ le_add_right _ _
lemma card_union_eq [decidable_eq α] {s t : finset α} (h : disjoint s t) :
(s ∪ t).card = s.card + t.card :=
begin
rw [← card_union_add_card_inter],
convert (add_zero _).symm, rw [card_eq_zero], rwa [disjoint_iff] at h
end
lemma surj_on_of_inj_on_of_card_le {s : finset α} {t : finset β}
(f : Π a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂)
(hst : card t ≤ card s) :
(∀ b ∈ t, ∃ a ha, b = f a ha) :=
by haveI := classical.dec_eq β; exact
λ b hb,
have h : card (image (λ (a : {a // a ∈ s}), f a a.prop) (attach s)) = card s,
from @card_attach _ s ▸ card_image_of_injective _
(λ ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ h, subtype.eq $ hinj _ _ _ _ h),
have h₁ : image (λ a : {a // a ∈ s}, f a a.prop) s.attach = t :=
eq_of_subset_of_card_le (λ b h, let ⟨a, ha₁, ha₂⟩ := mem_image.1 h in
ha₂ ▸ hf _ _) (by simp [hst, h]),
begin
rw ← h₁ at hb,
rcases mem_image.1 hb with ⟨a, ha₁, ha₂⟩,
exact ⟨a, a.2, ha₂.symm⟩,
end
open function
lemma inj_on_of_surj_on_of_card_le {s : finset α} {t : finset β}
(f : Π a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hsurj : ∀ b ∈ t, ∃ a ha, b = f a ha)
(hst : card s ≤ card t)
⦃a₁ a₂⦄ (ha₁ : a₁ ∈ s) (ha₂ : a₂ ∈ s)
(ha₁a₂: f a₁ ha₁ = f a₂ ha₂) : a₁ = a₂ :=
by haveI : inhabited {x // x ∈ s} := ⟨⟨a₁, ha₁⟩⟩; exact
let f' : {x // x ∈ s} → {x // x ∈ t} := λ x, ⟨f x.1 x.2, hf x.1 x.2⟩ in
let g : {x // x ∈ t} → {x // x ∈ s} :=
@surj_inv _ _ f'
(λ x, let ⟨y, hy₁, hy₂⟩ := hsurj x.1 x.2 in ⟨⟨y, hy₁⟩, subtype.eq hy₂.symm⟩) in
have hg : injective g, from injective_surj_inv _,
have hsg : surjective g, from λ x,
let ⟨y, hy⟩ := surj_on_of_inj_on_of_card_le (λ (x : {x // x ∈ t}) (hx : x ∈ t.attach), g x)
(λ x _, show (g x) ∈ s.attach, from mem_attach _ _)
(λ x y _ _ hxy, hg hxy) (by simpa) x (mem_attach _ _) in
⟨y, hy.snd.symm⟩,
have hif : injective f',
from (left_inverse_of_surjective_of_right_inverse hsg
(right_inverse_surj_inv _)).injective,
subtype.ext_iff_val.1 (@hif ⟨a₁, ha₁⟩ ⟨a₂, ha₂⟩ (subtype.eq ha₁a₂))
end card
section bUnion
/-!
### bUnion
This section is about the bounded union of an indexed family `t : α → finset β` of finite sets
over a finite set `s : finset α`.
-/
variables [decidable_eq β] {s : finset α} {t : α → finset β}
/-- `bUnion s t` is the union of `t x` over `x ∈ s`.
(This was formerly `bind` due to the monad structure on types with `decidable_eq`.) -/
protected def bUnion (s : finset α) (t : α → finset β) : finset β :=
(s.1.bind (λ a, (t a).1)).to_finset
@[simp] theorem bUnion_val (s : finset α) (t : α → finset β) :
(s.bUnion t).1 = (s.1.bind (λ a, (t a).1)).erase_dup := rfl
@[simp] theorem bUnion_empty : finset.bUnion ∅ t = ∅ := rfl
@[simp] theorem mem_bUnion {b : β} : b ∈ s.bUnion t ↔ ∃a∈s, b ∈ t a :=
by simp only [mem_def, bUnion_val, mem_erase_dup, mem_bind, exists_prop]
@[simp] theorem bUnion_insert [decidable_eq α] {a : α} : (insert a s).bUnion t = t a ∪ s.bUnion t :=
ext $ λ x, by simp only [mem_bUnion, exists_prop, mem_union, mem_insert,
or_and_distrib_right, exists_or_distrib, exists_eq_left]
-- ext $ λ x, by simp [or_and_distrib_right, exists_or_distrib]
@[simp] lemma singleton_bUnion {a : α} : finset.bUnion {a} t = t a :=
begin
classical,
rw [← insert_emptyc_eq, bUnion_insert, bUnion_empty, union_empty]
end
theorem bUnion_inter (s : finset α) (f : α → finset β) (t : finset β) :
s.bUnion f ∩ t = s.bUnion (λ x, f x ∩ t) :=
begin
ext x,
simp only [mem_bUnion, mem_inter],
tauto
end
theorem inter_bUnion (t : finset β) (s : finset α) (f : α → finset β) :
t ∩ s.bUnion f = s.bUnion (λ x, t ∩ f x) :=
by rw [inter_comm, bUnion_inter]; simp [inter_comm]
theorem image_bUnion [decidable_eq γ] {f : α → β} {s : finset α} {t : β → finset γ} :
(s.image f).bUnion t = s.bUnion (λa, t (f a)) :=
by haveI := classical.dec_eq α; exact
finset.induction_on s rfl (λ a s has ih,
by simp only [image_insert, bUnion_insert, ih])
theorem bUnion_image [decidable_eq γ] {s : finset α} {t : α → finset β} {f : β → γ} :
(s.bUnion t).image f = s.bUnion (λa, (t a).image f) :=
by haveI := classical.dec_eq α; exact
finset.induction_on s rfl (λ a s has ih,
by simp only [bUnion_insert, image_union, ih])
theorem bind_to_finset [decidable_eq α] (s : multiset α) (t : α → multiset β) :
(s.bind t).to_finset = s.to_finset.bUnion (λa, (t a).to_finset) :=
ext $ λ x, by simp only [multiset.mem_to_finset, mem_bUnion, multiset.mem_bind, exists_prop]
lemma bUnion_mono {t₁ t₂ : α → finset β} (h : ∀a∈s, t₁ a ⊆ t₂ a) : s.bUnion t₁ ⊆ s.bUnion t₂ :=
have ∀b a, a ∈ s → b ∈ t₁ a → (∃ (a : α), a ∈ s ∧ b ∈ t₂ a),
from assume b a ha hb, ⟨a, ha, finset.mem_of_subset (h a ha) hb⟩,
by simpa only [subset_iff, mem_bUnion, exists_imp_distrib, and_imp, exists_prop]
lemma bUnion_subset_bUnion_of_subset_left {α : Type*} {s₁ s₂ : finset α}
(t : α → finset β) (h : s₁ ⊆ s₂) : s₁.bUnion t ⊆ s₂.bUnion t :=
begin
intro x,
simp only [and_imp, mem_bUnion, exists_prop],
exact Exists.imp (λ a ha, ⟨h ha.1, ha.2⟩)
end
lemma subset_bUnion_of_mem {s : finset α}
(u : α → finset β) {x : α} (xs : x ∈ s) :
u x ⊆ s.bUnion u :=
begin
apply subset.trans _ (bUnion_subset_bUnion_of_subset_left u (singleton_subset_iff.2 xs)),
exact subset_of_eq singleton_bUnion.symm,
end
lemma bUnion_singleton {f : α → β} : s.bUnion (λa, {f a}) = s.image f :=
ext $ λ x, by simp only [mem_bUnion, mem_image, mem_singleton, eq_comm]
@[simp] lemma bUnion_singleton_eq_self [decidable_eq α] :
s.bUnion (singleton : α → finset α) = s :=
by { rw bUnion_singleton, exact image_id }
lemma bUnion_filter_eq_of_maps_to [decidable_eq α] {s : finset α} {t : finset β} {f : α → β}
(h : ∀ x ∈ s, f x ∈ t) :
t.bUnion (λa, s.filter $ (λc, f c = a)) = s :=
ext $ λ b, by simpa using h b
lemma image_bUnion_filter_eq [decidable_eq α] (s : finset β) (g : β → α) :
(s.image g).bUnion (λa, s.filter $ (λc, g c = a)) = s :=
bUnion_filter_eq_of_maps_to (λ x, mem_image_of_mem g)
lemma erase_bUnion (f : α → finset β) (s : finset α) (b : β) :
(s.bUnion f).erase b = s.bUnion (λ x, (f x).erase b) :=
by { ext, simp only [finset.mem_bUnion, iff_self, exists_and_distrib_left, finset.mem_erase] }
end bUnion
/-! ### prod -/
section prod
variables {s : finset α} {t : finset β}
/-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/
protected def product (s : finset α) (t : finset β) : finset (α × β) := ⟨_, nodup_product s.2 t.2⟩
@[simp] theorem product_val : (s.product t).1 = s.1.product t.1 := rfl
@[simp] theorem mem_product {p : α × β} : p ∈ s.product t ↔ p.1 ∈ s ∧ p.2 ∈ t := mem_product
theorem subset_product [decidable_eq α] [decidable_eq β] {s : finset (α × β)} :
s ⊆ (s.image prod.fst).product (s.image prod.snd) :=
λ p hp, mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩
theorem product_eq_bUnion [decidable_eq α] [decidable_eq β] (s : finset α) (t : finset β) :
s.product t = s.bUnion (λa, t.image $ λb, (a, b)) :=
ext $ λ ⟨x, y⟩, by simp only [mem_product, mem_bUnion, mem_image, exists_prop, prod.mk.inj_iff,
and.left_comm, exists_and_distrib_left, exists_eq_right, exists_eq_left]
@[simp] theorem card_product (s : finset α) (t : finset β) : card (s.product t) = card s * card t :=
multiset.card_product _ _
theorem filter_product (p : α → Prop) (q : β → Prop) [decidable_pred p] [decidable_pred q] :
(s.product t).filter (λ (x : α × β), p x.1 ∧ q x.2) = (s.filter p).product (t.filter q) :=
by { ext ⟨a, b⟩, simp only [mem_filter, mem_product], finish, }
lemma filter_product_card (s : finset α) (t : finset β)
(p : α → Prop) (q : β → Prop) [decidable_pred p] [decidable_pred q] :
((s.product t).filter (λ (x : α × β), p x.1 ↔ q x.2)).card =
(s.filter p).card * (t.filter q).card + (s.filter (not ∘ p)).card * (t.filter (not ∘ q)).card :=
begin
classical,
rw [← card_product, ← card_product, ← filter_product, ← filter_product, ← card_union_eq],
{ apply congr_arg, ext ⟨a, b⟩, simp only [filter_union_right, mem_filter, mem_product],
split; intros; finish, },
{ rw disjoint_iff, change _ ∩ _ = ∅, ext ⟨a, b⟩, rw mem_inter, finish, },
end
lemma empty_product (t : finset β) :
(∅ : finset α).product t = ∅ :=
rfl
lemma product_empty (s : finset α) :
s.product (∅ : finset β) = ∅ :=
eq_empty_of_forall_not_mem (λ x h, (finset.mem_product.1 h).2)
end prod
/-! ### sigma -/
section sigma
variables {σ : α → Type*} {s : finset α} {t : Πa, finset (σ a)}
/-- `sigma s t` is the set of dependent pairs `⟨a, b⟩` such that `a ∈ s` and `b ∈ t a`. -/
protected def sigma (s : finset α) (t : Πa, finset (σ a)) : finset (Σa, σ a) :=
⟨_, nodup_sigma s.2 (λ a, (t a).2)⟩
@[simp] theorem mem_sigma {p : sigma σ} : p ∈ s.sigma t ↔ p.1 ∈ s ∧ p.2 ∈ t (p.1) := mem_sigma
theorem sigma_mono {s₁ s₂ : finset α} {t₁ t₂ : Πa, finset (σ a)}
(H1 : s₁ ⊆ s₂) (H2 : ∀a, t₁ a ⊆ t₂ a) : s₁.sigma t₁ ⊆ s₂.sigma t₂ :=
λ ⟨x, sx⟩ H, let ⟨H3, H4⟩ := mem_sigma.1 H in mem_sigma.2 ⟨H1 H3, H2 x H4⟩
theorem sigma_eq_bUnion [decidable_eq (Σ a, σ a)] (s : finset α)
(t : Πa, finset (σ a)) :
s.sigma t = s.bUnion (λa, (t a).map $ embedding.sigma_mk a) :=
by { ext ⟨x, y⟩, simp [and.left_comm] }
end sigma
/-! ### disjoint -/
section disjoint
variable [decidable_eq α]
theorem disjoint_left {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t :=
by simp only [_root_.disjoint, inf_eq_inter, le_iff_subset, subset_iff, mem_inter, not_and,
and_imp]; refl
theorem disjoint_val {s t : finset α} : disjoint s t ↔ s.1.disjoint t.1 :=
disjoint_left
theorem disjoint_iff_inter_eq_empty {s t : finset α} : disjoint s t ↔ s ∩ t = ∅ :=
disjoint_iff
instance decidable_disjoint (U V : finset α) : decidable (disjoint U V) :=
decidable_of_decidable_of_iff (by apply_instance) eq_bot_iff
theorem disjoint_right {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s :=
by rw [disjoint.comm, disjoint_left]
theorem disjoint_iff_ne {s t : finset α} : disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b :=
by simp only [disjoint_left, imp_not_comm, forall_eq']
theorem disjoint_of_subset_left {s t u : finset α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t :=
disjoint_left.2 (λ x m₁, (disjoint_left.1 d) (h m₁))
theorem disjoint_of_subset_right {s t u : finset α} (h : t ⊆ u) (d : disjoint s u) : disjoint s t :=
disjoint_right.2 (λ x m₁, (disjoint_right.1 d) (h m₁))
@[simp] theorem disjoint_empty_left (s : finset α) : disjoint ∅ s := disjoint_bot_left
@[simp] theorem disjoint_empty_right (s : finset α) : disjoint s ∅ := disjoint_bot_right
@[simp] theorem singleton_disjoint {s : finset α} {a : α} : disjoint (singleton a) s ↔ a ∉ s :=
by simp only [disjoint_left, mem_singleton, forall_eq]
@[simp] theorem disjoint_singleton {s : finset α} {a : α} : disjoint s (singleton a) ↔ a ∉ s :=
disjoint.comm.trans singleton_disjoint
@[simp] theorem disjoint_insert_left {a : α} {s t : finset α} :
disjoint (insert a s) t ↔ a ∉ t ∧ disjoint s t :=
by simp only [disjoint_left, mem_insert, or_imp_distrib, forall_and_distrib, forall_eq]
@[simp] theorem disjoint_insert_right {a : α} {s t : finset α} :
disjoint s (insert a t) ↔ a ∉ s ∧ disjoint s t :=
disjoint.comm.trans $ by rw [disjoint_insert_left, disjoint.comm]
@[simp] theorem disjoint_union_left {s t u : finset α} :
disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u :=
by simp only [disjoint_left, mem_union, or_imp_distrib, forall_and_distrib]
@[simp] theorem disjoint_union_right {s t u : finset α} :
disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u :=
by simp only [disjoint_right, mem_union, or_imp_distrib, forall_and_distrib]
lemma sdiff_disjoint {s t : finset α} : disjoint (t \ s) s :=
disjoint_left.2 $ assume a ha, (mem_sdiff.1 ha).2
lemma disjoint_sdiff {s t : finset α} : disjoint s (t \ s) :=
sdiff_disjoint.symm
lemma disjoint_sdiff_inter (s t : finset α) : disjoint (s \ t) (s ∩ t) :=
disjoint_of_subset_right (inter_subset_right _ _) sdiff_disjoint
lemma sdiff_eq_self_iff_disjoint {s t : finset α} : s \ t = s ↔ disjoint s t :=
by rw [sdiff_eq_self, subset_empty, disjoint_iff_inter_eq_empty]
lemma sdiff_eq_self_of_disjoint {s t : finset α} (h : disjoint s t) : s \ t = s :=
sdiff_eq_self_iff_disjoint.2 h
lemma disjoint_self_iff_empty (s : finset α) : disjoint s s ↔ s = ∅ :=
disjoint_self
lemma disjoint_bUnion_left {ι : Type*}
(s : finset ι) (f : ι → finset α) (t : finset α) :
disjoint (s.bUnion f) t ↔ (∀i∈s, disjoint (f i) t) :=
begin
classical,
refine s.induction _ _,
{ simp only [forall_mem_empty_iff, bUnion_empty, disjoint_empty_left] },
{ assume i s his ih,
simp only [disjoint_union_left, bUnion_insert, his, forall_mem_insert, ih] }
end
lemma disjoint_bUnion_right {ι : Type*}
(s : finset α) (t : finset ι) (f : ι → finset α) :
disjoint s (t.bUnion f) ↔ (∀i∈t, disjoint s (f i)) :=
by simpa only [disjoint.comm] using disjoint_bUnion_left t f s
@[simp] theorem card_disjoint_union {s t : finset α} (h : disjoint s t) :
card (s ∪ t) = card s + card t :=
by rw [← card_union_add_card_inter, disjoint_iff_inter_eq_empty.1 h, card_empty, add_zero]
theorem card_sdiff {s t : finset α} (h : s ⊆ t) : card (t \ s) = card t - card s :=
suffices card (t \ s) = card ((t \ s) ∪ s) - card s, by rwa sdiff_union_of_subset h at this,
by rw [card_disjoint_union sdiff_disjoint, nat.add_sub_cancel]
lemma disjoint_filter {s : finset α} {p q : α → Prop} [decidable_pred p] [decidable_pred q] :
disjoint (s.filter p) (s.filter q) ↔ (∀ x ∈ s, p x → ¬ q x) :=
by split; simp [disjoint_left] {contextual := tt}
lemma disjoint_filter_filter {s t : finset α} {p q : α → Prop} [decidable_pred p]
[decidable_pred q] :
(disjoint s t) → disjoint (s.filter p) (t.filter q) :=
disjoint.mono (filter_subset _ _) (filter_subset _ _)
lemma disjoint_iff_disjoint_coe {α : Type*} {a b : finset α} [decidable_eq α] :
disjoint a b ↔ disjoint (↑a : set α) (↑b : set α) :=
by { rw [finset.disjoint_left, set.disjoint_left], refl }
lemma filter_card_add_filter_neg_card_eq_card {α : Type*} {s : finset α} (p : α → Prop)
[decidable_pred p] :
(s.filter p).card + (s.filter (not ∘ p)).card = s.card :=
by { classical, simp [← card_union_eq, filter_union_filter_neg_eq, disjoint_filter], }
end disjoint
section self_prod
variables (s : finset α) [decidable_eq α]
/-- Given a finite set `s`, the diagonal, `s.diag` is the set of pairs of the form `(a, a)` for
`a ∈ s`. -/
def diag := (s.product s).filter (λ (a : α × α), a.fst = a.snd)
/-- Given a finite set `s`, the off-diagonal, `s.off_diag` is the set of pairs `(a, b)` with `a ≠ b`
for `a, b ∈ s`. -/
def off_diag := (s.product s).filter (λ (a : α × α), a.fst ≠ a.snd)
@[simp] lemma mem_diag (x : α × α) : x ∈ s.diag ↔ x.1 ∈ s ∧ x.1 = x.2 :=
by { simp only [diag, mem_filter, mem_product], split; intros; finish, }
@[simp] lemma mem_off_diag (x : α × α) : x ∈ s.off_diag ↔ x.1 ∈ s ∧ x.2 ∈ s ∧ x.1 ≠ x.2 :=
by { simp only [off_diag, mem_filter, mem_product], split; intros; finish, }
@[simp] lemma diag_card : (diag s).card = s.card :=
begin
suffices : diag s = s.image (λ a, (a, a)), { rw this, apply card_image_of_inj_on, finish, },
ext ⟨a₁, a₂⟩, rw mem_diag, split; intros; finish,
end
@[simp] lemma off_diag_card : (off_diag s).card = s.card * s.card - s.card :=
begin
suffices : (diag s).card + (off_diag s).card = s.card * s.card,
{ nth_rewrite 2 ← s.diag_card, finish, },
rw ← card_product,
apply filter_card_add_filter_neg_card_eq_card,
end
end self_prod
/--
Given a set A and a set B inside it, we can shrink A to any appropriate size, and keep B
inside it.
-/
lemma exists_intermediate_set {A B : finset α} (i : ℕ)
(h₁ : i + card B ≤ card A) (h₂ : B ⊆ A) :
∃ (C : finset α), B ⊆ C ∧ C ⊆ A ∧ card C = i + card B :=
begin
classical,
rcases nat.le.dest h₁ with ⟨k, _⟩,
clear h₁,
induction k with k ih generalizing A,
{ exact ⟨A, h₂, subset.refl _, h.symm⟩ },
{ have : (A \ B).nonempty,
{ rw [← card_pos, card_sdiff h₂, ← h, nat.add_right_comm,
nat.add_sub_cancel, nat.add_succ],
apply nat.succ_pos },
rcases this with ⟨a, ha⟩,
have z : i + card B + k = card (erase A a),
{ rw [card_erase_of_mem, ← h, nat.add_succ, nat.pred_succ],
rw mem_sdiff at ha,
exact ha.1 },
rcases ih _ z with ⟨B', hB', B'subA', cards⟩,
{ exact ⟨B', hB', trans B'subA' (erase_subset _ _), cards⟩ },
{ rintros t th,
apply mem_erase_of_ne_of_mem _ (h₂ th),
rintro rfl,
exact not_mem_sdiff_of_mem_right th ha } }
end
/-- We can shrink A to any smaller size. -/
lemma exists_smaller_set (A : finset α) (i : ℕ) (h₁ : i ≤ card A) :
∃ (B : finset α), B ⊆ A ∧ card B = i :=
let ⟨B, _, x₁, x₂⟩ := exists_intermediate_set i (by simpa) (empty_subset A) in ⟨B, x₁, x₂⟩
/-- `finset.fin_range k` is the finset `{0, 1, ..., k-1}`, as a `finset (fin k)`. -/
def fin_range (k : ℕ) : finset (fin k) :=
⟨list.fin_range k, list.nodup_fin_range k⟩
@[simp]
lemma fin_range_card {k : ℕ} : (fin_range k).card = k :=
by simp [fin_range]
@[simp]
lemma mem_fin_range {k : ℕ} (m : fin k) : m ∈ fin_range k :=
list.mem_fin_range m
@[simp] lemma coe_fin_range (k : ℕ) : (fin_range k : set (fin k)) = set.univ :=
set.eq_univ_of_forall mem_fin_range
/-- Given a finset `s` of `ℕ` contained in `{0,..., n-1}`, the corresponding finset in `fin n`
is `s.attach_fin h` where `h` is a proof that all elements of `s` are less than `n`. -/
def attach_fin (s : finset ℕ) {n : ℕ} (h : ∀ m ∈ s, m < n) : finset (fin n) :=
⟨s.1.pmap (λ a ha, ⟨a, ha⟩) h, multiset.nodup_pmap (λ _ _ _ _, fin.veq_of_eq) s.2⟩
@[simp] lemma mem_attach_fin {n : ℕ} {s : finset ℕ} (h : ∀ m ∈ s, m < n) {a : fin n} :
a ∈ s.attach_fin h ↔ (a : ℕ) ∈ s :=
⟨λ h, let ⟨b, hb₁, hb₂⟩ := multiset.mem_pmap.1 h in hb₂ ▸ hb₁,
λ h, multiset.mem_pmap.2 ⟨a, h, fin.eta _ _⟩⟩
@[simp] lemma card_attach_fin {n : ℕ} (s : finset ℕ) (h : ∀ m ∈ s, m < n) :
(s.attach_fin h).card = s.card := multiset.card_pmap _ _ _
/-! ### choose -/
section choose
variables (p : α → Prop) [decidable_pred p] (l : finset α)
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the corresponding subtype. -/
def choose_x (hp : (∃! a, a ∈ l ∧ p a)) : { a // a ∈ l ∧ p a } :=
multiset.choose_x p l.val hp
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the ambient type. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α := choose_x p l hp
lemma choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(choose_x p l hp).property
lemma choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1
lemma choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2
end choose
theorem lt_wf {α} : well_founded (@has_lt.lt (finset α) _) :=
have H : subrelation (@has_lt.lt (finset α) _)
(inv_image (<) card),
from λ x y hxy, card_lt_card hxy,
subrelation.wf H $ inv_image.wf _ $ nat.lt_wf
end finset
namespace equiv
/-- Given an equivalence `α` to `β`, produce an equivalence between `finset α` and `finset β`. -/
protected def finset_congr (e : α ≃ β) : finset α ≃ finset β :=
{ to_fun := λ s, s.map e.to_embedding,
inv_fun := λ s, s.map e.symm.to_embedding,
left_inv := λ s, by simp [finset.map_map],
right_inv := λ s, by simp [finset.map_map] }
@[simp] lemma finset_congr_apply (e : α ≃ β) (s : finset α) :
e.finset_congr s = s.map e.to_embedding :=
rfl
@[simp] lemma finset_congr_refl :
(equiv.refl α).finset_congr = equiv.refl _ :=
by { ext, simp }
@[simp] lemma finset_congr_symm (e : α ≃ β) :
e.finset_congr.symm = e.symm.finset_congr :=
rfl
@[simp] lemma finset_congr_trans (e : α ≃ β) (e' : β ≃ γ) :
e.finset_congr.trans (e'.finset_congr) = (e.trans e').finset_congr :=
by { ext, simp [-finset.mem_map, -equiv.trans_to_embedding] }
end equiv
namespace list
variable [decidable_eq α]
theorem to_finset_card_of_nodup {l : list α} (h : l.nodup) : l.to_finset.card = l.length :=
congr_arg card $ (@multiset.erase_dup_eq_self α _ l).2 h
end list
namespace multiset
variable [decidable_eq α]
theorem to_finset_card_of_nodup {l : multiset α} (h : l.nodup) : l.to_finset.card = l.card :=
congr_arg card $ (@multiset.erase_dup_eq_self α _ l).2 h
lemma disjoint_to_finset (m1 m2 : multiset α) :
_root_.disjoint m1.to_finset m2.to_finset ↔ m1.disjoint m2 :=
begin
rw finset.disjoint_iff_ne,
split,
{ intro h,
intros a ha1 ha2,
rw ← multiset.mem_to_finset at ha1 ha2,
exact h _ ha1 _ ha2 rfl },
{ rintros h a ha b hb rfl,
rw multiset.mem_to_finset at ha hb,
exact h ha hb }
end
end multiset
|
9ed0cb657d61c54782dacd444e2d2d0ccf3e50be
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/algebra/char_zero.lean
|
e9779836aa8d8ab8c926290d143d1416d0f40eda
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,476
|
lean
|
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Natural homomorphism from the natural numbers into a monoid with one.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.nat.cast
import Mathlib.data.fintype.basic
import Mathlib.tactic.wlog
import Mathlib.PostPort
universes u_1 l
namespace Mathlib
/-- Typeclass for monoids with characteristic zero.
(This is usually stated on fields but it makes sense for any additive monoid with 1.) -/
class char_zero (R : Type u_1) [add_monoid R] [HasOne R]
where
cast_injective : function.injective coe
theorem char_zero_of_inj_zero {R : Type u_1} [add_left_cancel_monoid R] [HasOne R] (H : ∀ (n : ℕ), ↑n = 0 → n = 0) : char_zero R := sorry
protected instance linear_ordered_semiring.to_char_zero {R : Type u_1} [linear_ordered_semiring R] : char_zero R :=
char_zero.mk (strict_mono.injective nat.strict_mono_cast)
namespace nat
theorem cast_injective {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] : function.injective coe :=
char_zero.cast_injective
@[simp] theorem cast_inj {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {m : ℕ} {n : ℕ} : ↑m = ↑n ↔ m = n :=
function.injective.eq_iff cast_injective
@[simp] theorem cast_eq_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {n : ℕ} : ↑n = 0 ↔ n = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑n = 0 ↔ n = 0)) (Eq.symm cast_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (↑n = ↑0 ↔ n = 0)) (propext cast_inj))) (iff.refl (n = 0)))
theorem cast_ne_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] {n : ℕ} : ↑n ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
theorem cast_add_one_ne_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] (n : ℕ) : ↑n + 1 ≠ 0 := sorry
@[simp] theorem cast_dvd_char_zero {k : Type u_1} [field k] [char_zero k] {m : ℕ} {n : ℕ} (n_dvd : n ∣ m) : ↑(m / n) = ↑m / ↑n := sorry
end nat
protected instance char_zero.infinite (M : Type u_1) [add_monoid M] [HasOne M] [char_zero M] : infinite M :=
infinite.of_injective coe nat.cast_injective
theorem two_ne_zero' {M : Type u_1} [add_monoid M] [HasOne M] [char_zero M] : bit0 1 ≠ 0 :=
(fun (this : ↑(bit0 1) ≠ 0) => eq.mp (Eq._oldrec (Eq.refl (↑(bit0 1) ≠ 0)) nat.cast_two) this)
(iff.mpr nat.cast_ne_zero (of_as_true trivial))
theorem add_self_eq_zero {R : Type u_1} [semiring R] [no_zero_divisors R] [char_zero R] {a : R} : a + a = 0 ↔ a = 0 := sorry
theorem bit0_eq_zero {R : Type u_1} [semiring R] [no_zero_divisors R] [char_zero R] {a : R} : bit0 a = 0 ↔ a = 0 :=
add_self_eq_zero
@[simp] theorem half_add_self {R : Type u_1} [division_ring R] [char_zero R] (a : R) : (a + a) / bit0 1 = a :=
eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (Eq.symm (mul_two a))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * bit0 1 / bit0 1 = a)) (mul_div_cancel a two_ne_zero'))) (Eq.refl a))
@[simp] theorem add_halves' {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a / bit0 1 + a / bit0 1 = a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 + a / bit0 1 = a)) (Eq.symm (add_div a a (bit0 1)))))
(eq.mpr (id (Eq._oldrec (Eq.refl ((a + a) / bit0 1 = a)) (half_add_self a))) (Eq.refl a))
theorem sub_half {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a - a / bit0 1 = a / bit0 1 :=
eq.mpr (id (Eq._oldrec (Eq.refl (a - a / bit0 1 = a / bit0 1)) (propext sub_eq_iff_eq_add)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a = a / bit0 1 + a / bit0 1)) (add_halves' a))) (Eq.refl a))
theorem half_sub {R : Type u_1} [division_ring R] [char_zero R] (a : R) : a / bit0 1 - a = -(a / bit0 1) :=
eq.mpr (id (Eq._oldrec (Eq.refl (a / bit0 1 - a = -(a / bit0 1))) (Eq.symm (neg_sub a (a / bit0 1)))))
(eq.mpr (id (Eq._oldrec (Eq.refl (-(a - a / bit0 1) = -(a / bit0 1))) (sub_half a))) (Eq.refl (-(a / bit0 1))))
namespace with_top
protected instance char_zero {R : Type u_1} [add_monoid R] [HasOne R] [char_zero R] : char_zero (with_top R) :=
char_zero.mk
fun (m n : ℕ) (h : ↑m = ↑n) =>
eq.mp (Eq._oldrec (Eq.refl (↑m = ↑n)) (propext nat.cast_inj))
(eq.mp (Eq._oldrec (Eq.refl (↑↑m = ↑↑n)) (propext coe_eq_coe))
(eq.mp (Eq._oldrec (Eq.refl (↑↑m = ↑n)) (Eq.symm (coe_nat n)))
(eq.mp (Eq._oldrec (Eq.refl (↑m = ↑n)) (Eq.symm (coe_nat m))) h)))
|
2ab9382d3989183e685dd30b8f698e3af0316a60
|
43390109ab88557e6090f3245c47479c123ee500
|
/src/chris_hughes_various/disjoint_finset.lean
|
d2ed2176655cffcfb5a7de62517d59294f9d4808
|
[
"Apache-2.0"
] |
permissive
|
Ja1941/xena-UROP-2018
|
41f0956519f94d56b8bf6834a8d39473f4923200
|
b111fb87f343cf79eca3b886f99ee15c1dd9884b
|
refs/heads/master
| 1,662,355,955,139
| 1,590,577,325,000
| 1,590,577,325,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,652
|
lean
|
import data.finset
namespace finset
variable {α : Type*}
def disjoint (s t : finset α) : Prop := ∀ ⦃a⦄, a ∈ s → a ∈ t → false
theorem disjoint.symm {s t : finset α} (d : disjoint s t) : disjoint t s
| a i₂ i₁ := d i₁ i₂
@[simp] theorem disjoint_comm {s t : finset α} : disjoint s t ↔ disjoint t s :=
⟨disjoint.symm, disjoint.symm⟩
theorem disjoint_left {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ s → a ∉ t := iff.rfl
theorem disjoint_right {s t : finset α} : disjoint s t ↔ ∀ {a}, a ∈ t → a ∉ s :=
disjoint_comm
theorem disjoint_iff_ne {s t : finset α} : disjoint s t ↔ ∀ a ∈ s, ∀ b ∈ t, a ≠ b :=
by simp [disjoint_left, imp_not_comm]
theorem disjoint_of_subset_left {s t u : finset α} (h : s ⊆ u) (d : disjoint u t) : disjoint s t
| x m₁ := d (h m₁)
theorem disjoint_of_subset_right {s t u : finset α} (h : t ⊆ u) (d : disjoint s u) : disjoint s t
| x m m₁ := d m (h m₁)
@[simp] theorem empty_disjoint (l : finset α) : disjoint ∅ l
| a := (not_mem_empty a).elim
@[simp] theorem singleton_disjoint [decidable_eq α] {l : finset α} {a : α} : disjoint (singleton a) l ↔ a ∉ l :=
by simp [disjoint]; refl
@[simp] theorem disjoint_singleton [decidable_eq α] {l : finset α} {a : α} : disjoint l (singleton a) ↔ a ∉ l :=
by rw disjoint_comm; simp
@[simp] theorem disjoint_insert_left [decidable_eq α] {a : α} {s t : finset α} :
disjoint (insert a s) t ↔ a ∉ t ∧ disjoint s t :=
by simp [disjoint, or_imp_distrib, forall_and_distrib]; refl
@[simp] theorem disjoint_insert_right [decidable_eq α] {a : α} {s t : finset α} :
disjoint s (insert a t) ↔ a ∉ s ∧ disjoint s t :=
disjoint_comm.trans $ by simp [disjoint_insert_left]
theorem inter_eq_zero_iff_disjoint [decidable_eq α] {s t : finset α} : s ∩ t = ∅ ↔ disjoint s t :=
by rw ← subset_empty; simp [subset_iff, disjoint]
@[simp] theorem disjoint_union_left [decidable_eq α] {s t u : finset α} :
disjoint (s ∪ t) u ↔ disjoint s u ∧ disjoint t u :=
by simp [disjoint, or_imp_distrib, forall_and_distrib]
@[simp] theorem disjoint_union_right [decidable_eq α] {s t u : finset α} :
disjoint s (t ∪ u) ↔ disjoint s t ∧ disjoint s u :=
by simp [disjoint, or_imp_distrib, forall_and_distrib]
@[simp] theorem disjoint_val {s t : finset α} : multiset.disjoint s.1 t.1 ↔ disjoint s t :=
by simp [disjoint, multiset.disjoint, mem_def]
@[simp] theorem card_disjoint_union [decidable_eq α] {s t : finset α} :
disjoint s t → card (s ∪ t) = card s + card t :=
finset.induction_on s (by simp) $ begin simp {contextual := tt} end
end finset
|
5b31acd60309f426262505467e547d7a481b5e38
|
968e2f50b755d3048175f176376eff7139e9df70
|
/examples/prop_logic_theory/unnamed_1984.lean
|
55b011d383e394fce1064d66156b7c4103ec4e3d
|
[] |
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
| 175
|
lean
|
variables {p q : Prop}
-- BEGIN
example : (p → false) → (p → q) :=
begin
assume h₁ : p → false,
assume h₂ : p,
show q, from false.elim (h₁ h₂)
end
-- END
|
87282412458374f9157ec5144e16eb950f465b7d
|
19cc34575500ee2e3d4586c15544632aa07a8e66
|
/src/algebra/char_p.lean
|
9245866e4967eab246fb3ef779e9e620b59c0acf
|
[
"Apache-2.0"
] |
permissive
|
LibertasSpZ/mathlib
|
b9fcd46625eb940611adb5e719a4b554138dade6
|
33f7870a49d7cc06d2f3036e22543e6ec5046e68
|
refs/heads/master
| 1,672,066,539,347
| 1,602,429,158,000
| 1,602,429,158,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 14,161
|
lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Kenny Lau, Joey van Langen, Casper Putz
-/
import data.fintype.basic
import data.nat.choose
import data.int.modeq
import algebra.module.basic
import algebra.iterate_hom
import group_theory.order_of_element
import algebra.group.type_tags
/-!
# Characteristic of semirings
-/
universes u v
/-- The generator of the kernel of the unique homomorphism ℕ → α for a semiring α -/
class char_p (α : Type u) [semiring α] (p : ℕ) : Prop :=
(cast_eq_zero_iff [] : ∀ x:ℕ, (x:α) = 0 ↔ p ∣ x)
theorem char_p.cast_eq_zero (α : Type u) [semiring α] (p : ℕ) [char_p α p] : (p:α) = 0 :=
(char_p.cast_eq_zero_iff α p p).2 (dvd_refl p)
@[simp] lemma char_p.cast_card_eq_zero (R : Type*) [ring R] [fintype R] : (fintype.card R : R) = 0 :=
begin
have : fintype.card R •ℕ (1 : R) = 0 :=
@pow_card_eq_one (multiplicative R) _ _ (multiplicative.of_add 1),
simpa only [mul_one, nsmul_eq_mul]
end
lemma char_p.int_cast_eq_zero_iff (R : Type u) [ring R] (p : ℕ) [char_p R p] (a : ℤ) :
(a : R) = 0 ↔ (p:ℤ) ∣ a :=
begin
rcases lt_trichotomy a 0 with h|rfl|h,
{ rw [← neg_eq_zero, ← int.cast_neg, ← dvd_neg],
lift -a to ℕ using neg_nonneg.mpr (le_of_lt h) with b,
rw [int.cast_coe_nat, char_p.cast_eq_zero_iff R p, int.coe_nat_dvd] },
{ simp only [int.cast_zero, eq_self_iff_true, dvd_zero] },
{ lift a to ℕ using (le_of_lt h) with b,
rw [int.cast_coe_nat, char_p.cast_eq_zero_iff R p, int.coe_nat_dvd] }
end
lemma char_p.int_coe_eq_int_coe_iff (R : Type*) [ring R] (p : ℕ) [char_p R p] (a b : ℤ) :
(a : R) = (b : R) ↔ a ≡ b [ZMOD p] :=
by rw [eq_comm, ←sub_eq_zero, ←int.cast_sub,
char_p.int_cast_eq_zero_iff R p, int.modeq.modeq_iff_dvd]
theorem char_p.eq (α : Type u) [semiring α] {p q : ℕ} (c1 : char_p α p) (c2 : char_p α q) : p = q :=
nat.dvd_antisymm
((char_p.cast_eq_zero_iff α p q).1 (char_p.cast_eq_zero _ _))
((char_p.cast_eq_zero_iff α q p).1 (char_p.cast_eq_zero _ _))
instance char_p.of_char_zero (α : Type u) [semiring α] [char_zero α] : char_p α 0 :=
⟨λ x, by rw [zero_dvd_iff, ← nat.cast_zero, nat.cast_inj]⟩
theorem char_p.exists (α : Type u) [semiring α] : ∃ p, char_p α p :=
by letI := classical.dec_eq α; exact
classical.by_cases
(assume H : ∀ p:ℕ, (p:α) = 0 → p = 0, ⟨0,
⟨λ x, by rw [zero_dvd_iff]; exact ⟨H x, by rintro rfl; refl⟩⟩⟩)
(λ H, ⟨nat.find (not_forall.1 H), ⟨λ x,
⟨λ H1, nat.dvd_of_mod_eq_zero (by_contradiction $ λ H2,
nat.find_min (not_forall.1 H)
(nat.mod_lt x $ nat.pos_of_ne_zero $ not_of_not_imp $
nat.find_spec (not_forall.1 H))
(not_imp_of_and_not ⟨by rwa [← nat.mod_add_div x (nat.find (not_forall.1 H)),
nat.cast_add, nat.cast_mul, of_not_not (not_not_of_not_imp $ nat.find_spec (not_forall.1 H)),
zero_mul, add_zero] at H1, H2⟩)),
λ H1, by rw [← nat.mul_div_cancel' H1, nat.cast_mul,
of_not_not (not_not_of_not_imp $ nat.find_spec (not_forall.1 H)), zero_mul]⟩⟩⟩)
theorem char_p.exists_unique (α : Type u) [semiring α] : ∃! p, char_p α p :=
let ⟨c, H⟩ := char_p.exists α in ⟨c, H, λ y H2, char_p.eq α H2 H⟩
/-- Noncomputable function that outputs the unique characteristic of a semiring. -/
noncomputable def ring_char (α : Type u) [semiring α] : ℕ :=
classical.some (char_p.exists_unique α)
theorem ring_char.spec (α : Type u) [semiring α] : ∀ x:ℕ, (x:α) = 0 ↔ ring_char α ∣ x :=
by letI := (classical.some_spec (char_p.exists_unique α)).1;
unfold ring_char; exact char_p.cast_eq_zero_iff α (ring_char α)
theorem ring_char.eq (α : Type u) [semiring α] {p : ℕ} (C : char_p α p) : p = ring_char α :=
(classical.some_spec (char_p.exists_unique α)).2 p C
theorem add_pow_char_of_commute (R : Type u) [ring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) (h : commute x y) :
(x + y)^p = x^p + y^p :=
begin
rw [commute.add_pow h, finset.sum_range_succ, nat.sub_self, pow_zero, nat.choose_self],
rw [nat.cast_one, mul_one, mul_one, add_right_inj],
convert finset.sum_eq_single 0 _ _, { simp },
swap, { intro h1, contrapose! h1, rw finset.mem_range, apply nat.prime.pos, assumption },
intros b h1 h2,
suffices : (p.choose b : R) = 0, { rw this, simp },
rw char_p.cast_eq_zero_iff R p,
apply nat.prime.dvd_choose_self, assumption', { omega },
rwa ← finset.mem_range
end
theorem add_pow_char_pow_of_commute (R : Type u) [ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) (h : commute x y) :
(x + y) ^ (p ^ n) = x ^ (p ^ n) + y ^ (p ^ n) :=
begin
induction n, { simp, },
rw [pow_succ', pow_mul, pow_mul, pow_mul, n_ih],
apply add_pow_char_of_commute, apply commute.pow_pow h,
end
theorem sub_pow_char_of_commute (R : Type u) [ring R] {p : ℕ} [fact p.prime]
[char_p R p] (x y : R) (h : commute x y) :
(x - y)^p = x^p - y^p :=
begin
rw [eq_sub_iff_add_eq, ← add_pow_char_of_commute _ _ _ (commute.sub_left h rfl)],
simp, repeat {apply_instance},
end
theorem sub_pow_char_pow_of_commute (R : Type u) [ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) (h : commute x y) :
(x - y) ^ (p ^ n) = x ^ (p ^ n) - y ^ (p ^ n) :=
begin
induction n, { simp, },
rw [pow_succ', pow_mul, pow_mul, pow_mul, n_ih],
apply sub_pow_char_of_commute, apply commute.pow_pow h,
end
theorem add_pow_char (α : Type u) [comm_ring α] {p : ℕ} [fact p.prime]
[char_p α p] (x y : α) : (x + y)^p = x^p + y^p :=
add_pow_char_of_commute _ _ _ (commute.all _ _)
theorem add_pow_char_pow (R : Type u) [comm_ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) :
(x + y) ^ (p ^ n) = x ^ (p ^ n) + y ^ (p ^ n) :=
add_pow_char_pow_of_commute _ _ _ (commute.all _ _)
theorem sub_pow_char (α : Type u) [comm_ring α] {p : ℕ} [fact p.prime]
[char_p α p] (x y : α) : (x - y)^p = x^p - y^p :=
sub_pow_char_of_commute _ _ _ (commute.all _ _)
theorem sub_pow_char_pow (R : Type u) [comm_ring R] {p : ℕ} [fact p.prime]
[char_p R p] {n : ℕ} (x y : R) :
(x - y) ^ (p ^ n) = x ^ (p ^ n) - y ^ (p ^ n) :=
sub_pow_char_pow_of_commute _ _ _ (commute.all _ _)
lemma eq_iff_modeq_int (R : Type*) [ring R] (p : ℕ) [char_p R p] (a b : ℤ) :
(a : R) = b ↔ a ≡ b [ZMOD p] :=
by rw [eq_comm, ←sub_eq_zero, ←int.cast_sub,
char_p.int_cast_eq_zero_iff R p, int.modeq.modeq_iff_dvd]
lemma char_p.neg_one_ne_one (R : Type*) [ring R] (p : ℕ) [char_p R p] [fact (2 < p)] :
(-1 : R) ≠ (1 : R) :=
begin
suffices : (2 : R) ≠ 0,
{ symmetry, rw [ne.def, ← sub_eq_zero, sub_neg_eq_add], exact this },
assume h,
rw [show (2 : R) = (2 : ℕ), by norm_cast] at h,
have := (char_p.cast_eq_zero_iff R p 2).mp h,
have := nat.le_of_dvd dec_trivial this,
rw fact at *, linarith,
end
section frobenius
variables (R : Type u) [comm_ring R] {S : Type v} [comm_ring S] (f : R →* S) (g : R →+* S)
(p : ℕ) [fact p.prime] [char_p R p] [char_p S p] (x y : R)
/-- The frobenius map that sends x to x^p -/
def frobenius : R →+* R :=
{ to_fun := λ x, x^p,
map_one' := one_pow p,
map_mul' := λ x y, mul_pow x y p,
map_zero' := zero_pow (lt_trans zero_lt_one ‹nat.prime p›.one_lt),
map_add' := add_pow_char R }
variable {R}
theorem frobenius_def : frobenius R p x = x ^ p := rfl
theorem iterate_frobenius (n : ℕ) : (frobenius R p)^[n] x = x ^ p ^ n :=
begin
induction n, {simp},
rw [function.iterate_succ', pow_succ', pow_mul, function.comp_apply, frobenius_def, n_ih]
end
theorem frobenius_mul : frobenius R p (x * y) = frobenius R p x * frobenius R p y :=
(frobenius R p).map_mul x y
theorem frobenius_one : frobenius R p 1 = 1 := one_pow _
variable {R}
theorem monoid_hom.map_frobenius : f (frobenius R p x) = frobenius S p (f x) :=
f.map_pow x p
theorem ring_hom.map_frobenius : g (frobenius R p x) = frobenius S p (g x) :=
g.map_pow x p
theorem monoid_hom.map_iterate_frobenius (n : ℕ) :
f (frobenius R p^[n] x) = (frobenius S p^[n] (f x)) :=
function.semiconj.iterate_right (f.map_frobenius p) n x
theorem ring_hom.map_iterate_frobenius (n : ℕ) :
g (frobenius R p^[n] x) = (frobenius S p^[n] (g x)) :=
g.to_monoid_hom.map_iterate_frobenius p x n
theorem monoid_hom.iterate_map_frobenius (f : R →* R) (p : ℕ) [fact p.prime] [char_p R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
f.iterate_map_pow _ _ _
theorem ring_hom.iterate_map_frobenius (f : R →+* R) (p : ℕ) [fact p.prime] [char_p R p] (n : ℕ) :
f^[n] (frobenius R p x) = frobenius R p (f^[n] x) :=
f.iterate_map_pow _ _ _
variable (R)
theorem frobenius_zero : frobenius R p 0 = 0 := (frobenius R p).map_zero
theorem frobenius_add : frobenius R p (x + y) = frobenius R p x + frobenius R p y :=
(frobenius R p).map_add x y
theorem frobenius_neg : frobenius R p (-x) = -frobenius R p x := (frobenius R p).map_neg x
theorem frobenius_sub : frobenius R p (x - y) = frobenius R p x - frobenius R p y :=
(frobenius R p).map_sub x y
theorem frobenius_nat_cast (n : ℕ) : frobenius R p n = n := (frobenius R p).map_nat_cast n
end frobenius
theorem frobenius_inj (α : Type u) [integral_domain α] (p : ℕ) [fact p.prime] [char_p α p] :
function.injective (frobenius α p) :=
λ x h H, by { rw ← sub_eq_zero at H ⊢, rw ← frobenius_sub at H, exact pow_eq_zero H }
namespace char_p
section
variables (α : Type u) [ring α]
lemma char_p_to_char_zero [char_p α 0] : char_zero α :=
char_zero_of_inj_zero $
λ n h0, eq_zero_of_zero_dvd ((cast_eq_zero_iff α 0 n).mp h0)
lemma cast_eq_mod (p : ℕ) [char_p α p] (k : ℕ) : (k : α) = (k % p : ℕ) :=
calc (k : α) = ↑(k % p + p * (k / p)) : by rw [nat.mod_add_div]
... = ↑(k % p) : by simp[cast_eq_zero]
theorem char_ne_zero_of_fintype (p : ℕ) [hc : char_p α p] [fintype α] : p ≠ 0 :=
assume h : p = 0,
have char_zero α := @char_p_to_char_zero α _ (h ▸ hc),
absurd (@nat.cast_injective α _ _ this) (not_injective_infinite_fintype coe)
end
section integral_domain
open nat
variables (α : Type u) [integral_domain α]
theorem char_ne_one (p : ℕ) [hc : char_p α p] : p ≠ 1 :=
assume hp : p = 1,
have ( 1 : α) = 0, by simpa using (cast_eq_zero_iff α p 1).mpr (hp ▸ dvd_refl p),
absurd this one_ne_zero
theorem char_is_prime_of_two_le (p : ℕ) [hc : char_p α p] (hp : 2 ≤ p) : nat.prime p :=
suffices ∀d ∣ p, d = 1 ∨ d = p, from ⟨hp, this⟩,
assume (d : ℕ) (hdvd : ∃ e, p = d * e),
let ⟨e, hmul⟩ := hdvd in
have (p : α) = 0, from (cast_eq_zero_iff α p p).mpr (dvd_refl p),
have (d : α) * e = 0, from (@cast_mul α _ d e) ▸ (hmul ▸ this),
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this)
(assume hd : (d : α) = 0,
have p ∣ d, from (cast_eq_zero_iff α p d).mp hd,
show d = 1 ∨ d = p, from or.inr (dvd_antisymm ⟨e, hmul⟩ this))
(assume he : (e : α) = 0,
have p ∣ e, from (cast_eq_zero_iff α p e).mp he,
have e ∣ p, from dvd_of_mul_left_eq d (eq.symm hmul),
have e = p, from dvd_antisymm ‹e ∣ p› ‹p ∣ e›,
have h₀ : p > 0, from gt_of_ge_of_gt hp (nat.zero_lt_succ 1),
have d * p = 1 * p, by rw ‹e = p› at hmul; rw [one_mul]; exact eq.symm hmul,
show d = 1 ∨ d = p, from or.inl (eq_of_mul_eq_mul_right h₀ this))
theorem char_is_prime_or_zero (p : ℕ) [hc : char_p α p] : nat.prime p ∨ p = 0 :=
match p, hc with
| 0, _ := or.inr rfl
| 1, hc := absurd (eq.refl (1 : ℕ)) (@char_ne_one α _ (1 : ℕ) hc)
| (m+2), hc := or.inl (@char_is_prime_of_two_le α _ (m+2) hc (nat.le_add_left 2 m))
end
lemma char_is_prime_of_pos (p : ℕ) [h : fact (0 < p)] [char_p α p] : fact p.prime :=
(char_p.char_is_prime_or_zero α _).resolve_right (nat.pos_iff_ne_zero.1 h)
theorem char_is_prime [fintype α] (p : ℕ) [char_p α p] : p.prime :=
or.resolve_right (char_is_prime_or_zero α p) (char_ne_zero_of_fintype α p)
end integral_domain
section char_one
variables {R : Type*}
@[priority 100] -- see Note [lower instance priority]
instance [semiring R] [char_p R 1] : subsingleton R :=
subsingleton.intro $
suffices ∀ (r : R), r = 0,
from assume a b, show a = b, by rw [this a, this b],
assume r,
calc r = 1 * r : by rw one_mul
... = (1 : ℕ) * r : by rw nat.cast_one
... = 0 * r : by rw char_p.cast_eq_zero
... = 0 : by rw zero_mul
lemma false_of_nontrivial_of_char_one [semiring R] [nontrivial R] [char_p R 1] : false :=
false_of_nontrivial_of_subsingleton R
lemma ring_char_ne_one [semiring R] [nontrivial R] : ring_char R ≠ 1 :=
by { intros h, apply @zero_ne_one R, symmetry, rw [←nat.cast_one, ring_char.spec, h], }
lemma nontrivial_of_char_ne_one {v : ℕ} (hv : v ≠ 1) {R : Type*} [semiring R] [hr : char_p R v] :
nontrivial R :=
⟨⟨(1 : ℕ), 0, λ h, hv $ by rwa [char_p.cast_eq_zero_iff _ v, nat.dvd_one] at h; assumption ⟩⟩
end char_one
end char_p
section
variables (n : ℕ) (R : Type*) [comm_ring R] [fintype R]
lemma char_p_of_ne_zero (hn : fintype.card R = n) (hR : ∀ i < n, (i : R) = 0 → i = 0) :
char_p R n :=
{ cast_eq_zero_iff :=
begin
have H : (n : R) = 0, by { rw [← hn, char_p.cast_card_eq_zero] },
intro k,
split,
{ intro h,
rw [← nat.mod_add_div k n, nat.cast_add, nat.cast_mul, H, zero_mul, add_zero] at h,
rw nat.dvd_iff_mod_eq_zero,
apply hR _ (nat.mod_lt _ _) h,
rw [← hn, gt, fintype.card_pos_iff],
exact ⟨0⟩, },
{ rintro ⟨k, rfl⟩, rw [nat.cast_mul, H, zero_mul] }
end }
lemma char_p_of_prime_pow_injective (p : ℕ) [hp : fact p.prime] (n : ℕ) (hn : fintype.card R = p ^ n)
(hR : ∀ i ≤ n, (p ^ i : R) = 0 → i = n) :
char_p R (p ^ n) :=
begin
obtain ⟨c, hc⟩ := char_p.exists R, resetI,
have hcpn : c ∣ p ^ n,
{ rw [← char_p.cast_eq_zero_iff R c, ← hn, char_p.cast_card_eq_zero], },
obtain ⟨i, hi, hc⟩ : ∃ i ≤ n, c = p ^ i, by rwa nat.dvd_prime_pow hp at hcpn,
obtain rfl : i = n,
{ apply hR i hi, rw [← nat.cast_pow, ← hc, char_p.cast_eq_zero] },
rwa ← hc
end
end
|
bb447a25ce143dc05636c90108c428a342521bfb
|
e4e5bde6f14c01a8a34267a9d7bb45e137735696
|
/src/exercises/logic_and_proof/14.lean
|
ee0903046e6385ad31c3133995b463d288cbc155
|
[] |
no_license
|
jamesdabbs/proofs
|
fb5dab6f3c4f3f5f952fca033ec649888ae787c6
|
00baf355b08e7aec00de34208e1b2cb4a8d7b701
|
refs/heads/master
| 1,645,645,735,797
| 1,569,559,636,000
| 1,569,559,636,000
| 211,238,170
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,391
|
lean
|
/-
Exercises from https://leanprover.github.io/logic_and_proof
Chapter 14. Relations in Lean
-/
/-
Replace the sorry commands in the following proofs to show that we can create
a partial order R' out of a strict partial order R.
-/
section ex1
parameters {A : Type} {R : A → A → Prop}
parameter (irreflR : irreflexive R)
parameter (transR : transitive R)
local infix < := R
def R' (a b : A) : Prop := R a b ∨ a = b
local infix ≤ := R'
theorem reflR' (a : A) : a ≤ a :=
have a = a, by refl,
show a ≤ a, from or.inr this
theorem transR' {a b c : A} (h1 : a ≤ b) (h2 : b ≤ c) :
a ≤ c :=
h1.elim
(assume ab,
(h2.elim
(assume bc, or.inl (transR ab bc))
(assume h : b = c, show a ≤ c, from h ▸ h1)))
(assume h : a = b, show a ≤ c, from h.symm ▸ h2)
theorem antisymmR' {a b : A} (h1 : a ≤ b) (h2 : b ≤ a) :
a = b :=
h1.elim
(assume ab : a < b,
h2.elim
(assume ba : b < a,
have na : ¬(a < a), from irreflR a,
have a : a < a, from transR ab ba,
absurd a na)
symm)
id
end ex1
/-
Replace the sorry by a proof.
-/
section ex2
parameters {A : Type} {R : A → A → Prop}
parameter (reflR : reflexive R)
parameter (transR : transitive R)
include reflR transR
def S (a b : A) : Prop := R a b ∧ R b a
example : transitive S :=
begin
rw transitive,
intros a b c sab sbc,
rw S at *,
exact ⟨transR sab.left sbc.left, transR sbc.right sab.right⟩
end
end ex2
/-
Only one of the following two theorems is provable. Figure out which one is
true, and replace the sorry command with a complete proof.
-/
section ex3
parameters {A : Type} {a b c : A} {R : A → A → Prop}
parameter (Rab : R a b)
parameter (Rbc : R b c)
parameter (nRac : ¬ R a c)
include Rab Rbc nRac
-- Prove one of the following two theorems:
-- theorem R_is_strict_partial_order :
-- irreflexive R ∧ transitive R :=
-- sorry
theorem R_is_not_strict_partial_order :
¬(irreflexive R ∧ transitive R) :=
assume it,
have transR : transitive R, from it.right,
have R a c, from transR Rab Rbc,
absurd this nRac
end ex3
/-
Complete the following proof.
-/
section ex4
open nat
example : 1 ≤ 4 :=
calc 1 ≤ 2 : le_succ 1
... ≤ 3 : le_succ 2
... ≤ 4 : le_succ 3
end ex4
|
062d613ececa6185fe8b3f96ca63bf74b9af07dd
|
1d335ec6ac4181a0a762b12797936770cc9fcef9
|
/override/geomOverride.lean
|
0747e2955aaf3c17aaea26c466e31e0885b7e1d7
|
[] |
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
| 359
|
lean
|
import ..imperative_DSL.environment
import ..eval.geometryEval
open lang.classicalGeometry
def assignGeometry : environment.env → lang.classicalGeometry.var → lang.classicalGeometry.expr → environment.env
| i v e := environment.env.mk
(λ r,
if (varEq v r)
then (classicalGeometryEval e i)
else (i.g r))
i.t i.v i.a
|
bda44ec15d16579d37bb193dad7d14d6aeda285a
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/real/cardinality.lean
|
b70daf1d8d6c3afd0358080eb080ab9e47067e41
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 9,491
|
lean
|
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import set_theory.cardinal_ordinal
import analysis.specific_limits
import data.rat.denumerable
import data.set.intervals.image_preimage
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#ℝ = 2^ω`.
We shows that `#ℝ ≤ 2^ω` by noting that every real number is determined by a Cauchy-sequence of the
form `ℕ → ℚ`, which has cardinality `2^ω`. To show that `#ℝ ≥ 2^ω` we define an injection from
`{0, 1} ^ ℕ` to `ℝ` with `f ↦ Σ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ ℕ` to `ℝ` by
`f ↦ Σ' n, f n * (1 / 3) ^ n`
## Main statements
* `cardinal.mk_real : #ℝ = 2 ^ omega`: the reals have cardinality continuum.
* `cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y ∈ {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open nat set
open_locale cardinal
noncomputable theory
namespace cardinal
variables {c : ℝ} {f g : ℕ → bool} {n : ℕ}
/-- The body of the sum in `cantor_function`.
`cantor_function_aux c f n = c ^ n` if `f n = tt`;
`cantor_function_aux c f n = 0` if `f n = ff`. -/
def cantor_function_aux (c : ℝ) (f : ℕ → bool) (n : ℕ) : ℝ := cond (f n) (c ^ n) 0
@[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n :=
by simp [cantor_function_aux, h]
@[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 :=
by simp [cantor_function_aux, h]
lemma cantor_function_aux_nonneg (h : 0 ≤ c) : 0 ≤ cantor_function_aux c f n :=
by { cases h' : f n; simp [h'], apply pow_nonneg h }
lemma cantor_function_aux_eq (h : f n = g n) :
cantor_function_aux c f n = cantor_function_aux c g n :=
by simp [cantor_function_aux, h]
lemma cantor_function_aux_succ (f : ℕ → bool) :
(λ n, cantor_function_aux c f (n + 1)) = λ n, c * cantor_function_aux c (λ n, f (n + 1)) n :=
by { ext n, cases h : f (n + 1); simp [h, pow_succ] }
lemma summable_cantor_function (f : ℕ → bool) (h1 : 0 ≤ c) (h2 : c < 1) :
summable (cantor_function_aux c f) :=
begin
apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self,
intro n, cases h : f n; simp [h]
end
/-- `cantor_function c (f : ℕ → bool)` is `Σ n, f n * c ^ n`, where `tt` is interpreted as `1` and
`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/
def cantor_function (c : ℝ) (f : ℕ → bool) : ℝ := ∑' n, cantor_function_aux c f n
lemma cantor_function_le (h1 : 0 ≤ c) (h2 : c < 1) (h3 : ∀ n, f n → g n) :
cantor_function c f ≤ cantor_function c g :=
begin
apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2),
intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1],
replace h3 : g n = tt := h3 n h, simp [h, h3]
end
lemma cantor_function_succ (f : ℕ → bool) (h1 : 0 ≤ c) (h2 : c < 1) :
cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (λ n, f (n+1)) :=
begin
rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)],
rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero],
refl
end
/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `ℕ → bool` with a
lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we
explicitly write out what it means. -/
lemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : ℕ} {f g : ℕ → bool}
(hn : ∀(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) :
cantor_function c f < cantor_function c g :=
begin
have h3 : c < 1, { apply h2.trans, norm_num },
induction n with n ih generalizing f g,
{ let f_max : ℕ → bool := λ n, nat.rec ff (λ _ _, tt) n,
have hf_max : ∀n, f n → f_max n,
{ intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },
let g_min : ℕ → bool := λ n, nat.rec tt (λ _ _, ff) n,
have hg_min : ∀n, g_min n → g n,
{ intros n hn, cases n, rw [gn], apply rfl, contradiction },
apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt,
refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min),
have : c / (1 - c) < 1,
{ rw [div_lt_one, lt_sub_iff_add_lt],
{ convert add_lt_add h2 h2, norm_num },
rwa sub_pos },
convert this,
{ rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv,
←tsum_geometric_of_lt_1 (le_of_lt h1) h3],
apply zero_add },
{ convert tsum_eq_single 0 _,
{ apply_instance },
{ intros n hn, cases n, contradiction, refl } } },
rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3],
rw [hn 0 $ zero_lt_succ n],
apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (λ k hk, hn _ $ succ_lt_succ hk) fn gn
end
/-- `cantor_function c` is injective if `0 < c < 1/2`. -/
lemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) :
function.injective (cantor_function c) :=
begin
intros f g hfg, classical, by_contra h, revert hfg,
have : ∃n, f n ≠ g n,
{ rw [←not_forall], intro h', apply h, ext, apply h' },
let n := nat.find this,
have hn : ∀ (k : ℕ), k < n → f k = g k,
{ intros k hk, apply of_not_not, exact nat.find_min this hk },
cases fn : f n,
{ apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _,
apply eq_tt_of_not_eq_ff, rw [←fn], apply ne.symm, exact nat.find_spec this },
{ apply ne_of_gt, refine increasing_cantor_function h1 h2 (λ k hk, (hn k hk).symm) _ fn,
apply eq_ff_of_not_eq_tt, rw [←fn], apply ne.symm, exact nat.find_spec this }
end
/-- The cardinality of the reals, as a type. -/
lemma mk_real : #ℝ = 2 ^ omega.{0} :=
begin
apply le_antisymm,
{ rw real.equiv_Cauchy.cardinal_eq,
apply mk_quotient_le.trans, apply (mk_subtype_le _).trans,
rw [←power_def, mk_nat, mk_rat, power_self_eq (le_refl _)] },
{ convert mk_le_of_injective (cantor_function_injective _ _),
rw [←power_def, mk_bool, mk_nat], exact 1 / 3, norm_num, norm_num }
end
/-- The cardinality of the reals, as a set. -/
lemma mk_univ_real : #(set.univ : set ℝ) = 2 ^ omega.{0} :=
by rw [mk_univ, mk_real]
/-- The reals are not countable. -/
lemma not_countable_real : ¬ countable (set.univ : set ℝ) :=
by { rw [countable_iff, not_le, mk_univ_real], apply cantor }
/-- The cardinality of the interval (a, ∞). -/
lemma mk_Ioi_real (a : ℝ) : #(Ioi a) = 2 ^ omega.{0} :=
begin
refine le_antisymm (mk_real ▸ mk_set_le _) _,
rw [← not_lt], intro h,
refine ne_of_lt _ mk_univ_real,
have hu : Iio a ∪ {a} ∪ Ioi a = set.univ,
{ convert Iic_union_Ioi, exact Iio_union_right },
rw ← hu,
refine lt_of_le_of_lt (mk_union_le _ _) _,
refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _,
have h2 : (λ x, a + a - x) '' Ioi a = Iio a,
{ convert image_const_sub_Ioi _ _, simp },
rw ← h2,
refine add_lt_of_lt (cantor _).le _ h,
refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _,
rw mk_singleton,
exact one_lt_omega.trans (cantor _)
end
/-- The cardinality of the interval [a, ∞). -/
lemma mk_Ici_real (a : ℝ) : #(Ici a) = 2 ^ omega.{0} :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Ioi_real a ▸ mk_le_mk_of_subset Ioi_subset_Ici_self)
/-- The cardinality of the interval (-∞, a). -/
lemma mk_Iio_real (a : ℝ) : #(Iio a) = 2 ^ omega.{0} :=
begin
refine le_antisymm (mk_real ▸ mk_set_le _) _,
have h2 : (λ x, a + a - x) '' Iio a = Ioi a,
{ convert image_const_sub_Iio _ _, simp },
exact mk_Ioi_real a ▸ h2 ▸ mk_image_le
end
/-- The cardinality of the interval (-∞, a]. -/
lemma mk_Iic_real (a : ℝ) : #(Iic a) = 2 ^ omega.{0} :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Iio_real a ▸ mk_le_mk_of_subset Iio_subset_Iic_self)
/-- The cardinality of the interval (a, b). -/
lemma mk_Ioo_real {a b : ℝ} (h : a < b) : #(Ioo a b) = 2 ^ omega.{0} :=
begin
refine le_antisymm (mk_real ▸ mk_set_le _) _,
have h1 : #((λ x, x - a) '' Ioo a b) ≤ #(Ioo a b) := mk_image_le,
refine le_trans _ h1,
rw [image_sub_const_Ioo, sub_self],
replace h := sub_pos_of_lt h,
have h2 : #(has_inv.inv '' Ioo 0 (b - a)) ≤ #(Ioo 0 (b - a)) := mk_image_le,
refine le_trans _ h2,
rw [image_inv_Ioo_0_left h, mk_Ioi_real]
end
/-- The cardinality of the interval [a, b). -/
lemma mk_Ico_real {a b : ℝ} (h : a < b) : #(Ico a b) = 2 ^ omega.{0} :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Ico_self)
/-- The cardinality of the interval [a, b]. -/
lemma mk_Icc_real {a b : ℝ} (h : a < b) : #(Icc a b) = 2 ^ omega.{0} :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Icc_self)
/-- The cardinality of the interval (a, b]. -/
lemma mk_Ioc_real {a b : ℝ} (h : a < b) : #(Ioc a b) = 2 ^ omega.{0} :=
le_antisymm (mk_real ▸ mk_set_le _) (mk_Ioo_real h ▸ mk_le_mk_of_subset Ioo_subset_Ioc_self)
end cardinal
|
f453bdbde32feaf8afa72413d14cd73892935a25
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/tactic/localized.lean
|
c6d2b77820d26a881d1cca8ff353591216a00506
|
[
"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,467
|
lean
|
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import meta.rb_map
import tactic.core
/-!
# Localized notation
This consists of two user-commands which allow you to declare notation and commands localized to a
locale.
See the tactic doc entry below for more information.
The code is inspired by code from Gabriel Ebner from the
[hott3 repository](https://github.com/gebner/hott3).
-/
open lean lean.parser interactive tactic native
@[user_attribute]
meta def localized_attr : user_attribute (rb_lmap name string) unit :=
{ name := "_localized",
descr := "(interal) attribute that flags localized commands",
parser := failed,
cache_cfg := ⟨λ ns, (do dcls ← ns.mmap (λ n, mk_const n >>= eval_expr (name × string)),
return $ rb_lmap.of_list dcls), []⟩ }
/-- Get all commands in the given locale and return them as a list of strings -/
meta def get_localized (ns : list name) : tactic (list string) :=
do m ← localized_attr.get_cache,
ns.mfoldl (λ l nm, match m.find nm with
| [] := fail format!"locale {nm} does not exist"
| new_l := return $ l.append new_l
end) []
/-- Execute all commands in the given locale -/
@[user_command] meta def open_locale_cmd (_ : parse $ tk "open_locale") : parser unit :=
do ns ← many ident,
cmds ← get_localized ns,
cmds.mmap' emit_code_here
/-- Add a new command to a locale and execute it right now.
The new command is added as a declaration to the environment with name `_localized_decl.<number>`.
This declaration has attribute `_localized` and as value a name-string pair. -/
@[user_command] meta def localized_cmd (_ : parse $ tk "localized") : parser unit :=
do cmd ← parser.pexpr, cmd ← i_to_expr cmd, cmd ← eval_expr string cmd,
let cmd := "local " ++ cmd,
emit_code_here cmd,
tk "in",
nm ← ident,
env ← get_env,
let dummy_decl_name := mk_num_name `_localized_decl
((string.hash (cmd ++ nm.to_string) + env.fingerprint) % unsigned_sz),
add_decl (declaration.defn dummy_decl_name [] `(name × string)
(reflect (⟨nm, cmd⟩ : name × string)) (reducibility_hints.regular 1 tt) ff),
localized_attr.set dummy_decl_name unit.star tt
/--
This consists of two user-commands which allow you to declare notation and commands localized to a
locale.
* Declare notation which is localized to a locale using:
```lean
localized "infix (name := my_add) ` ⊹ `:60 := my_add" in my.add
```
* After this command it will be available in the same section/namespace/file, just as if you wrote
`local infix (name := my_add) ` ⊹ `:60 := my_add`
* You can open it in other places. The following command will declare the notation again as local
notation in that section/namespace/file:
```lean
open_locale my.add
```
* More generally, the following will declare all localized notation in the specified locales.
```lean
open_locale locale1 locale2 ...
```
* You can also declare other localized commands, like local attributes
```lean
localized "attribute [simp] le_refl" in le
```
* To see all localized commands in a given locale, run:
```lean
run_cmd print_localized_commands [`my.add].
```
* To see a list of all locales with localized commands, run:
```lean
run_cmd do
m ← localized_attr.get_cache,
tactic.trace m.keys -- change to `tactic.trace m.to_list` to list all the commands in each locale
```
* Warning: You have to give full names of all declarations used in localized notation,
so that the localized notation also works when the appropriate namespaces are not opened.
* Note: In mathlib, you should always provide names for localized notations using the
`(name := ...)` parameter. This prevents issues if the localized notation overrides
an existing notation when it gets opened.
* Warning: Due to limitations in the implementation, you cannot use `_` in localized notations.
(Otherwise `open_locale foo` will fail if `foo` is already opened or partially opened.)
Instead, you should use the `hole!` notation as a drop-in replacement. For example:
```lean
-- BAD
-- localized "infix (name := my_add) ` ⊹[` R `] ` := my_add _ R" in foo
-- GOOD
localized "infix (name := my_add) ` ⊹[` R `] ` := my_add hole! R" in foo
```
-/
add_tactic_doc
{ name := "localized notation",
category := doc_category.cmd,
decl_names := [`localized_cmd, `open_locale_cmd],
tags := ["notation", "type classes"] }
/-- Print all commands in a given locale -/
meta def print_localized_commands (ns : list name) : tactic unit :=
do cmds ← get_localized ns, cmds.mmap' trace
-- This should be used instead of `_` inside localized commands,
-- because otherwise `open_locale` will fail if some of the notations are already available.
notation `hole!` := _
-- you can run `open_locale classical` to get the decidability of all propositions, and downgrade
-- the priority of decidability instances that make Lean run through all the algebraic hierarchy
-- whenever it wants to solve a decidability question
localized "attribute [instance, priority 9] classical.prop_decidable" in classical
localized "attribute [instance, priority 8] eq.decidable" in classical
localized "postfix (name := parser.optional) `?`:9001 := optional" in parser
localized "postfix (name := parser.many) *:9001 := lean.parser.many" in parser
|
fa6635ea74aef57f65aeb04978f9516c27b6a3bf
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/src/analysis/normed_space/affine_isometry.lean
|
fc1d7cdb39bf70941e38e9144cdec75d4a63bb4a
|
[
"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
| 22,462
|
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 analysis.normed_space.add_torsor
import analysis.normed_space.linear_isometry
import linear_algebra.affine_space.affine_subspace
/-!
# Affine isometries
In this file we define `affine_isometry 𝕜 P P₂` to be an affine isometric embedding of normed
add-torsors `P` into `P₂` over normed `𝕜`-spaces and `affine_isometry_equiv` to be an affine
isometric equivalence between `P` and `P₂`.
We also prove basic lemmas and provide convenience constructors. The choice of these lemmas and
constructors is closely modelled on those for the `linear_isometry` and `affine_map` theories.
Since many elementary properties don't require `∥x∥ = 0 → x = 0` we initially set up the theory for
`semi_normed_add_torsor` and specialize to `normed_add_torsor` only when needed.
## Notation
We introduce the notation `P →ᵃⁱ[𝕜] P₂` for `affine_isometry 𝕜 P P₂`, and `P ≃ᵃⁱ[𝕜] P₂` for
`affine_isometry_equiv 𝕜 P P₂`. In contrast with the notation `→ₗᵢ` for linear isometries, `≃ᵢ`
for isometric equivalences, etc., the "i" here is a superscript. This is for aesthetic reasons to
match the superscript "a" (note that in mathlib `→ᵃ` is an affine map, since `→ₐ` has been taken by
algebra-homomorphisms.)
-/
open function set
variables (𝕜 : Type*) {V V₁ V₂ V₃ V₄ : Type*} {P₁ : Type*} (P P₂ : Type*) {P₃ P₄ : Type*}
[normed_field 𝕜]
[semi_normed_group V] [normed_group V₁] [semi_normed_group V₂] [semi_normed_group V₃]
[semi_normed_group V₄]
[semi_normed_space 𝕜 V] [normed_space 𝕜 V₁] [semi_normed_space 𝕜 V₂] [semi_normed_space 𝕜 V₃]
[semi_normed_space 𝕜 V₄]
[pseudo_metric_space P] [metric_space P₁] [pseudo_metric_space P₂] [pseudo_metric_space P₃]
[pseudo_metric_space P₄]
[semi_normed_add_torsor V P] [normed_add_torsor V₁ P₁] [semi_normed_add_torsor V₂ P₂]
[semi_normed_add_torsor V₃ P₃] [semi_normed_add_torsor V₄ P₄]
include V V₂
/-- An `𝕜`-affine isometric embedding of one normed add-torsor over a normed `𝕜`-space into
another. -/
structure affine_isometry extends P →ᵃ[𝕜] P₂ :=
(norm_map : ∀ x : V, ∥linear x∥ = ∥x∥)
omit V V₂
variables {𝕜 P P₂}
-- `→ᵃᵢ` would be more consistent with the linear isometry notation, but it is uglier
notation P ` →ᵃⁱ[`:25 𝕜:25 `] `:0 P₂:0 := affine_isometry 𝕜 P P₂
namespace affine_isometry
variables (f : P →ᵃⁱ[𝕜] P₂)
/-- The underlying linear map of an affine isometry is in fact a linear isometry. -/
protected def linear_isometry : V →ₗᵢ[𝕜] V₂ :=
{ norm_map' := f.norm_map,
.. f.linear }
@[simp] lemma linear_eq_linear_isometry : f.linear = f.linear_isometry.to_linear_map :=
by { ext, refl }
include V V₂
instance : has_coe_to_fun (P →ᵃⁱ[𝕜] P₂) := ⟨_, λ f, f.to_fun⟩
omit V V₂
@[simp] lemma coe_to_affine_map : ⇑f.to_affine_map = f := rfl
include V V₂
lemma to_affine_map_injective : injective (to_affine_map : (P →ᵃⁱ[𝕜] P₂) → (P →ᵃ[𝕜] P₂))
| ⟨f, _⟩ ⟨g, _⟩ rfl := rfl
lemma coe_fn_injective : @injective (P →ᵃⁱ[𝕜] P₂) (P → P₂) coe_fn :=
affine_map.coe_fn_injective.comp to_affine_map_injective
@[ext] lemma ext {f g : P →ᵃⁱ[𝕜] P₂} (h : ∀ x, f x = g x) : f = g :=
coe_fn_injective $ funext h
omit V V₂
end affine_isometry
namespace linear_isometry
variables (f : V →ₗᵢ[𝕜] V₂)
/-- Reinterpret a linear isometry as an affine isometry. -/
def to_affine_isometry : V →ᵃⁱ[𝕜] V₂ :=
{ norm_map := f.norm_map,
.. f.to_linear_map.to_affine_map }
@[simp] lemma coe_to_affine_isometry : ⇑(f.to_affine_isometry : V →ᵃⁱ[𝕜] V₂) = f := rfl
@[simp] lemma to_affine_isometry_linear_isometry : f.to_affine_isometry.linear_isometry = f :=
by { ext, refl }
-- somewhat arbitrary choice of simp direction
@[simp] lemma to_affine_isometry_to_affine_map :
f.to_affine_isometry.to_affine_map = f.to_linear_map.to_affine_map :=
rfl
end linear_isometry
namespace affine_isometry
/-- We use `f₁` when we need the domain to be a `normed_space`. -/
variables (f : P →ᵃⁱ[𝕜] P₂) (f₁ : P₁ →ᵃⁱ[𝕜] P₂)
@[simp] lemma map_vadd (p : P) (v : V) : f (v +ᵥ p) = f.linear_isometry v +ᵥ f p :=
f.to_affine_map.map_vadd p v
@[simp] lemma map_vsub (p1 p2 : P) : f.linear_isometry (p1 -ᵥ p2) = f p1 -ᵥ f p2 :=
f.to_affine_map.linear_map_vsub p1 p2
@[simp] lemma dist_map (x y : P) : dist (f x) (f y) = dist x y :=
by rw [dist_eq_norm_vsub V₂, dist_eq_norm_vsub V, ← map_vsub, f.linear_isometry.norm_map]
@[simp] lemma nndist_map (x y : P) : nndist (f x) (f y) = nndist x y := by simp [nndist_dist]
@[simp] lemma edist_map (x y : P) : edist (f x) (f y) = edist x y := by simp [edist_dist]
protected lemma isometry : isometry f := f.edist_map
protected lemma injective : injective f₁ := f₁.isometry.injective
@[simp] lemma map_eq_iff {x y : P₁} : f₁ x = f₁ y ↔ x = y := f₁.injective.eq_iff
lemma map_ne {x y : P₁} (h : x ≠ y) : f₁ x ≠ f₁ y := f₁.injective.ne h
protected lemma lipschitz : lipschitz_with 1 f := f.isometry.lipschitz
protected lemma antilipschitz : antilipschitz_with 1 f := f.isometry.antilipschitz
@[continuity] protected lemma continuous : continuous f := f.isometry.continuous
lemma ediam_image (s : set P) : emetric.diam (f '' s) = emetric.diam s :=
f.isometry.ediam_image s
lemma ediam_range : emetric.diam (range f) = emetric.diam (univ : set P) :=
f.isometry.ediam_range
lemma diam_image (s : set P) : metric.diam (f '' s) = metric.diam s :=
f.isometry.diam_image s
lemma diam_range : metric.diam (range f) = metric.diam (univ : set P) :=
f.isometry.diam_range
@[simp] lemma comp_continuous_iff {α : Type*} [topological_space α] {g : α → P} :
continuous (f ∘ g) ↔ continuous g :=
f.isometry.comp_continuous_iff
include V
/-- The identity affine isometry. -/
def id : P →ᵃⁱ[𝕜] P := ⟨affine_map.id 𝕜 P, λ x, rfl⟩
@[simp] lemma coe_id : ⇑(id : P →ᵃⁱ[𝕜] P) = _root_.id := rfl
@[simp] lemma id_apply (x : P) : (affine_isometry.id : P →ᵃⁱ[𝕜] P) x = x := rfl
@[simp] lemma id_to_affine_map : (id.to_affine_map : P →ᵃ[𝕜] P) = affine_map.id 𝕜 P := rfl
instance : inhabited (P →ᵃⁱ[𝕜] P) := ⟨id⟩
include V₂ V₃
/-- Composition of affine isometries. -/
def comp (g : P₂ →ᵃⁱ[𝕜] P₃) (f : P →ᵃⁱ[𝕜] P₂) : P →ᵃⁱ[𝕜] P₃ :=
⟨g.to_affine_map.comp f.to_affine_map, λ x, (g.norm_map _).trans (f.norm_map _)⟩
@[simp] lemma coe_comp (g : P₂ →ᵃⁱ[𝕜] P₃) (f : P →ᵃⁱ[𝕜] P₂) :
⇑(g.comp f) = g ∘ f :=
rfl
omit V V₂ V₃
@[simp] lemma id_comp : (id : P₂ →ᵃⁱ[𝕜] P₂).comp f = f := ext $ λ x, rfl
@[simp] lemma comp_id : f.comp id = f := ext $ λ x, rfl
include V V₂ V₃ V₄
lemma comp_assoc (f : P₃ →ᵃⁱ[𝕜] P₄) (g : P₂ →ᵃⁱ[𝕜] P₃) (h : P →ᵃⁱ[𝕜] P₂) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
omit V₂ V₃ V₄
instance : monoid (P →ᵃⁱ[𝕜] P) :=
{ one := id,
mul := comp,
mul_assoc := comp_assoc,
one_mul := id_comp,
mul_one := comp_id }
@[simp] lemma coe_one : ⇑(1 : P →ᵃⁱ[𝕜] P) = id := rfl
@[simp] lemma coe_mul (f g : P →ᵃⁱ[𝕜] P) : ⇑(f * g) = f ∘ g := rfl
end affine_isometry
-- remark: by analogy with the `linear_isometry` file from which this is adapted, there should
-- follow here a section defining an "inclusion" affine isometry from `p : affine_subspace 𝕜 P`
-- into `P`; we omit this for now
variables (𝕜 P P₂)
include V V₂
/-- A affine isometric equivalence between two normed vector spaces. -/
structure affine_isometry_equiv extends P ≃ᵃ[𝕜] P₂ :=
(norm_map : ∀ x, ∥linear x∥ = ∥x∥)
variables {𝕜 P P₂}
omit V V₂
-- `≃ᵃᵢ` would be more consistent with the linear isometry equiv notation, but it is uglier
notation P ` ≃ᵃⁱ[`:25 𝕜:25 `] `:0 P₂:0 := affine_isometry_equiv 𝕜 P P₂
namespace affine_isometry_equiv
variables (e : P ≃ᵃⁱ[𝕜] P₂)
/-- The underlying linear equiv of an affine isometry equiv is in fact a linear isometry equiv. -/
protected def linear_isometry_equiv : V ≃ₗᵢ[𝕜] V₂ :=
{ norm_map' := e.norm_map,
.. e.linear }
@[simp] lemma linear_eq_linear_isometry : e.linear = e.linear_isometry_equiv.to_linear_equiv :=
by { ext, refl }
include V V₂
instance : has_coe_to_fun (P ≃ᵃⁱ[𝕜] P₂) := ⟨_, λ f, f.to_fun⟩
@[simp] lemma coe_mk (e : P ≃ᵃ[𝕜] P₂) (he : ∀ x, ∥e.linear x∥ = ∥x∥) :
⇑(mk e he) = e :=
rfl
@[simp] lemma coe_to_affine_equiv (e : P ≃ᵃⁱ[𝕜] P₂) : ⇑e.to_affine_equiv = e := rfl
lemma to_affine_equiv_injective : injective (to_affine_equiv : (P ≃ᵃⁱ[𝕜] P₂) → (P ≃ᵃ[𝕜] P₂))
| ⟨e, _⟩ ⟨_, _⟩ rfl := rfl
@[ext] lemma ext {e e' : P ≃ᵃⁱ[𝕜] P₂} (h : ∀ x, e x = e' x) : e = e' :=
to_affine_equiv_injective $ affine_equiv.ext h
omit V V₂
/-- Reinterpret a `affine_isometry_equiv` as a `affine_isometry`. -/
def to_affine_isometry : P →ᵃⁱ[𝕜] P₂ := ⟨e.1.to_affine_map, e.2⟩
@[simp] lemma coe_to_affine_isometry : ⇑e.to_affine_isometry = e := rfl
/-- Construct an affine isometry equivalence by verifying the relation between the map and its
linear part at one base point. Namely, this function takes a map `e : P₁ → P₂`, a linear isometry
equivalence `e' : V₁ ≃ᵢₗ[k] V₂`, and a point `p` such that for any other point `p'` we have
`e p' = e' (p' -ᵥ p) +ᵥ e p`. -/
def mk' (e : P₁ → P₂) (e' : V₁ ≃ₗᵢ[𝕜] V₂) (p : P₁) (h : ∀ p' : P₁, e p' = e' (p' -ᵥ p) +ᵥ e p) :
P₁ ≃ᵃⁱ[𝕜] P₂ :=
{ norm_map := e'.norm_map,
.. affine_equiv.mk' e e'.to_linear_equiv p h }
@[simp] lemma coe_mk' (e : P₁ → P₂) (e' : V₁ ≃ₗᵢ[𝕜] V₂) (p h) : ⇑(mk' e e' p h) = e := rfl
@[simp] lemma linear_isometry_equiv_mk' (e : P₁ → P₂) (e' : V₁ ≃ₗᵢ[𝕜] V₂) (p h) :
(mk' e e' p h).linear_isometry_equiv = e' := by { ext, refl }
end affine_isometry_equiv
namespace linear_isometry_equiv
variables (e : V ≃ₗᵢ[𝕜] V₂)
/-- Reinterpret a linear isometry equiv as an affine isometry equiv. -/
def to_affine_isometry_equiv : V ≃ᵃⁱ[𝕜] V₂ :=
{ norm_map := e.norm_map,
.. e.to_linear_equiv.to_affine_equiv }
@[simp] lemma coe_to_affine_isometry_equiv : ⇑(e.to_affine_isometry_equiv : V ≃ᵃⁱ[𝕜] V₂) = e := rfl
@[simp] lemma to_affine_isometry_equiv_linear_isometry_equiv :
e.to_affine_isometry_equiv.linear_isometry_equiv = e :=
by { ext, refl }
-- somewhat arbitrary choice of simp direction
@[simp] lemma to_affine_isometry_equiv_to_affine_equiv :
e.to_affine_isometry_equiv.to_affine_equiv = e.to_linear_equiv.to_affine_equiv :=
rfl
-- somewhat arbitrary choice of simp direction
@[simp] lemma to_affine_isometry_equiv_to_affine_isometry :
e.to_affine_isometry_equiv.to_affine_isometry = e.to_linear_isometry.to_affine_isometry :=
rfl
end linear_isometry_equiv
namespace affine_isometry_equiv
variables (e : P ≃ᵃⁱ[𝕜] P₂)
protected lemma isometry : isometry e := e.to_affine_isometry.isometry
/-- Reinterpret a `affine_isometry_equiv` as an `isometric`. -/
def to_isometric : P ≃ᵢ P₂ := ⟨e.to_affine_equiv.to_equiv, e.isometry⟩
@[simp] lemma coe_to_isometric : ⇑e.to_isometric = e := rfl
include V V₂
lemma range_eq_univ (e : P ≃ᵃⁱ[𝕜] P₂) : set.range e = set.univ :=
by { rw ← coe_to_isometric, exact isometric.range_eq_univ _, }
omit V V₂
/-- Reinterpret a `affine_isometry_equiv` as an `homeomorph`. -/
def to_homeomorph : P ≃ₜ P₂ := e.to_isometric.to_homeomorph
@[simp] lemma coe_to_homeomorph : ⇑e.to_homeomorph = e := rfl
protected lemma continuous : continuous e := e.isometry.continuous
protected lemma continuous_at {x} : continuous_at e x := e.continuous.continuous_at
protected lemma continuous_on {s} : continuous_on e s := e.continuous.continuous_on
protected lemma continuous_within_at {s x} : continuous_within_at e s x :=
e.continuous.continuous_within_at
variables (𝕜 P)
include V
/-- Identity map as a `affine_isometry_equiv`. -/
def refl : P ≃ᵃⁱ[𝕜] P := ⟨affine_equiv.refl 𝕜 P, λ x, rfl⟩
variables {𝕜 P}
instance : inhabited (P ≃ᵃⁱ[𝕜] P) := ⟨refl 𝕜 P⟩
@[simp] lemma coe_refl : ⇑(refl 𝕜 P) = id := rfl
@[simp] lemma to_affine_equiv_refl : (refl 𝕜 P).to_affine_equiv = affine_equiv.refl 𝕜 P := rfl
@[simp] lemma to_isometric_refl : (refl 𝕜 P).to_isometric = isometric.refl P := rfl
@[simp] lemma to_homeomorph_refl : (refl 𝕜 P).to_homeomorph = homeomorph.refl P := rfl
omit V
/-- The inverse `affine_isometry_equiv`. -/
def symm : P₂ ≃ᵃⁱ[𝕜] P :=
{ norm_map := e.linear_isometry_equiv.symm.norm_map,
.. e.to_affine_equiv.symm }
@[simp] lemma apply_symm_apply (x : P₂) : e (e.symm x) = x := e.to_affine_equiv.apply_symm_apply x
@[simp] lemma symm_apply_apply (x : P) : e.symm (e x) = x := e.to_affine_equiv.symm_apply_apply x
@[simp] lemma symm_symm : e.symm.symm = e := ext $ λ x, rfl
@[simp] lemma to_affine_equiv_symm : e.to_affine_equiv.symm = e.symm.to_affine_equiv := rfl
@[simp] lemma to_isometric_symm : e.to_isometric.symm = e.symm.to_isometric := rfl
@[simp] lemma to_homeomorph_symm : e.to_homeomorph.symm = e.symm.to_homeomorph := rfl
include V₃
/-- Composition of `affine_isometry_equiv`s as a `affine_isometry_equiv`. -/
def trans (e' : P₂ ≃ᵃⁱ[𝕜] P₃) : P ≃ᵃⁱ[𝕜] P₃ :=
⟨e.to_affine_equiv.trans e'.to_affine_equiv, λ x, (e'.norm_map _).trans (e.norm_map _)⟩
include V V₂
@[simp] lemma coe_trans (e₁ : P ≃ᵃⁱ[𝕜] P₂) (e₂ : P₂ ≃ᵃⁱ[𝕜] P₃) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl
omit V V₂ V₃
@[simp] lemma trans_refl : e.trans (refl 𝕜 P₂) = e := ext $ λ x, rfl
@[simp] lemma refl_trans : (refl 𝕜 P).trans e = e := ext $ λ x, rfl
@[simp] lemma trans_symm : e.trans e.symm = refl 𝕜 P := ext e.symm_apply_apply
@[simp] lemma symm_trans : e.symm.trans e = refl 𝕜 P₂ := ext e.apply_symm_apply
include V V₂ V₃
@[simp] lemma coe_symm_trans (e₁ : P ≃ᵃⁱ[𝕜] P₂) (e₂ : P₂ ≃ᵃⁱ[𝕜] P₃) :
⇑(e₁.trans e₂).symm = e₁.symm ∘ e₂.symm :=
rfl
include V₄
lemma trans_assoc (ePP₂ : P ≃ᵃⁱ[𝕜] P₂) (eP₂G : P₂ ≃ᵃⁱ[𝕜] P₃) (eGG' : P₃ ≃ᵃⁱ[𝕜] P₄) :
ePP₂.trans (eP₂G.trans eGG') = (ePP₂.trans eP₂G).trans eGG' :=
rfl
omit V₂ V₃ V₄
/-- The group of affine isometries of a `normed_add_torsor`, `P`. -/
instance : group (P ≃ᵃⁱ[𝕜] P) :=
{ mul := λ e₁ e₂, e₂.trans e₁,
one := refl _ _,
inv := symm,
one_mul := trans_refl,
mul_one := refl_trans,
mul_assoc := λ _ _ _, trans_assoc _ _ _,
mul_left_inv := trans_symm }
@[simp] lemma coe_one : ⇑(1 : P ≃ᵃⁱ[𝕜] P) = id := rfl
@[simp] lemma coe_mul (e e' : P ≃ᵃⁱ[𝕜] P) : ⇑(e * e') = e ∘ e' := rfl
@[simp] lemma coe_inv (e : P ≃ᵃⁱ[𝕜] P) : ⇑(e⁻¹) = e.symm := rfl
omit V
@[simp] lemma map_vadd (p : P) (v : V) : e (v +ᵥ p) = e.linear_isometry_equiv v +ᵥ e p :=
e.to_affine_isometry.map_vadd p v
@[simp] lemma map_vsub (p1 p2 : P) : e.linear_isometry_equiv (p1 -ᵥ p2) = e p1 -ᵥ e p2 :=
e.to_affine_isometry.map_vsub p1 p2
@[simp] lemma dist_map (x y : P) : dist (e x) (e y) = dist x y :=
e.to_affine_isometry.dist_map x y
@[simp] lemma edist_map (x y : P) : edist (e x) (e y) = edist x y :=
e.to_affine_isometry.edist_map x y
protected lemma bijective : bijective e := e.1.bijective
protected lemma injective : injective e := e.1.injective
protected lemma surjective : surjective e := e.1.surjective
@[simp] lemma map_eq_iff {x y : P} : e x = e y ↔ x = y := e.injective.eq_iff
lemma map_ne {x y : P} (h : x ≠ y) : e x ≠ e y := e.injective.ne h
protected lemma lipschitz : lipschitz_with 1 e := e.isometry.lipschitz
protected lemma antilipschitz : antilipschitz_with 1 e := e.isometry.antilipschitz
@[simp] lemma ediam_image (s : set P) : emetric.diam (e '' s) = emetric.diam s :=
e.isometry.ediam_image s
@[simp] lemma diam_image (s : set P) : metric.diam (e '' s) = metric.diam s :=
e.isometry.diam_image s
variables {α : Type*} [topological_space α]
@[simp] lemma comp_continuous_on_iff {f : α → P} {s : set α} :
continuous_on (e ∘ f) s ↔ continuous_on f s :=
e.isometry.comp_continuous_on_iff
@[simp] lemma comp_continuous_iff {f : α → P} :
continuous (e ∘ f) ↔ continuous f :=
e.isometry.comp_continuous_iff
section constructions
variables (𝕜)
/-- The map `v ↦ v +ᵥ p` as an affine isometric equivalence between `V` and `P`. -/
def vadd_const (p : P) : V ≃ᵃⁱ[𝕜] P :=
{ norm_map := λ x, rfl,
.. affine_equiv.vadd_const 𝕜 p }
variables {𝕜}
include V
@[simp] lemma coe_vadd_const (p : P) : ⇑(vadd_const 𝕜 p) = λ v, v +ᵥ p := rfl
@[simp] lemma coe_vadd_const_symm (p : P) : ⇑(vadd_const 𝕜 p).symm = λ p', p' -ᵥ p :=
rfl
@[simp] lemma vadd_const_to_affine_equiv (p : P) :
(vadd_const 𝕜 p).to_affine_equiv = affine_equiv.vadd_const 𝕜 p :=
rfl
omit V
variables (𝕜)
/-- `p' ↦ p -ᵥ p'` as an affine isometric equivalence. -/
def const_vsub (p : P) : P ≃ᵃⁱ[𝕜] V :=
{ norm_map := norm_neg,
.. affine_equiv.const_vsub 𝕜 p }
variables {𝕜}
include V
@[simp] lemma coe_const_vsub (p : P) : ⇑(const_vsub 𝕜 p) = (-ᵥ) p := rfl
@[simp] lemma symm_const_vsub (p : P) :
(const_vsub 𝕜 p).symm
= (linear_isometry_equiv.neg 𝕜).to_affine_isometry_equiv.trans (vadd_const 𝕜 p) :=
by { ext, refl }
omit V
variables (𝕜 P)
/-- Translation by `v` (that is, the map `p ↦ v +ᵥ p`) as an affine isometric automorphism of `P`.
-/
def const_vadd (v : V) : P ≃ᵃⁱ[𝕜] P :=
{ norm_map := λ x, rfl,
.. affine_equiv.const_vadd 𝕜 P v }
variables {𝕜 P}
@[simp] lemma coe_const_vadd (v : V) : ⇑(const_vadd 𝕜 P v : P ≃ᵃⁱ[𝕜] P) = (+ᵥ) v := rfl
@[simp] lemma const_vadd_zero : const_vadd 𝕜 P (0:V) = refl 𝕜 P := ext $ zero_vadd V
include 𝕜 V
/-- The map `g` from `V` to `V₂` corresponding to a map `f` from `P` to `P₂`, at a base point `p`,
is an isometry if `f` is one. -/
lemma vadd_vsub {f : P → P₂} (hf : isometry f) {p : P} {g : V → V₂}
(hg : ∀ v, g v = f (v +ᵥ p) -ᵥ f p) : isometry g :=
begin
convert (vadd_const 𝕜 (f p)).symm.isometry.comp (hf.comp (vadd_const 𝕜 p).isometry),
exact funext hg
end
omit 𝕜
variables (𝕜)
/-- Point reflection in `x` as an affine isometric automorphism. -/
def point_reflection (x : P) : P ≃ᵃⁱ[𝕜] P := (const_vsub 𝕜 x).trans (vadd_const 𝕜 x)
variables {𝕜}
lemma point_reflection_apply (x y : P) : (point_reflection 𝕜 x) y = x -ᵥ y +ᵥ x := rfl
@[simp] lemma point_reflection_to_affine_equiv (x : P) :
(point_reflection 𝕜 x).to_affine_equiv = affine_equiv.point_reflection 𝕜 x := rfl
@[simp] lemma point_reflection_self (x : P) : point_reflection 𝕜 x x = x :=
affine_equiv.point_reflection_self 𝕜 x
lemma point_reflection_involutive (x : P) : function.involutive (point_reflection 𝕜 x) :=
equiv.point_reflection_involutive x
@[simp] lemma point_reflection_symm (x : P) : (point_reflection 𝕜 x).symm = point_reflection 𝕜 x :=
to_affine_equiv_injective $ affine_equiv.point_reflection_symm 𝕜 x
@[simp] lemma dist_point_reflection_fixed (x y : P) :
dist (point_reflection 𝕜 x y) x = dist y x :=
by rw [← (point_reflection 𝕜 x).dist_map y x, point_reflection_self]
lemma dist_point_reflection_self' (x y : P) :
dist (point_reflection 𝕜 x y) y = ∥bit0 (x -ᵥ y)∥ :=
by rw [point_reflection_apply, dist_eq_norm_vsub V, vadd_vsub_assoc, bit0]
lemma dist_point_reflection_self (x y : P) :
dist (point_reflection 𝕜 x y) y = ∥(2:𝕜)∥ * dist x y :=
by rw [dist_point_reflection_self', ← two_smul' 𝕜 (x -ᵥ y), norm_smul, ← dist_eq_norm_vsub V]
lemma point_reflection_fixed_iff [invertible (2:𝕜)] {x y : P} :
point_reflection 𝕜 x y = y ↔ y = x :=
affine_equiv.point_reflection_fixed_iff_of_module 𝕜
variables [semi_normed_space ℝ V]
lemma dist_point_reflection_self_real (x y : P) :
dist (point_reflection ℝ x y) y = 2 * dist x y :=
by { rw [dist_point_reflection_self, real.norm_two] }
@[simp] lemma point_reflection_midpoint_left (x y : P) :
point_reflection ℝ (midpoint ℝ x y) x = y :=
affine_equiv.point_reflection_midpoint_left x y
@[simp] lemma point_reflection_midpoint_right (x y : P) :
point_reflection ℝ (midpoint ℝ x y) y = x :=
affine_equiv.point_reflection_midpoint_right x y
end constructions
end affine_isometry_equiv
namespace affine_isometry
open finite_dimensional affine_map
variables [finite_dimensional 𝕜 V₁] [finite_dimensional 𝕜 V₂]
/-- A affine isometry between finite dimensional spaces of equal dimension can be upgraded
to an affine isometry equivalence. -/
noncomputable def to_affine_isometry_equiv [inhabited P₁]
(li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) : P₁ ≃ᵃⁱ[𝕜] P₂ :=
affine_isometry_equiv.mk' li (li.linear_isometry.to_linear_isometry_equiv h) (arbitrary P₁)
(λ p, by simp)
@[simp] lemma coe_to_affine_isometry_equiv [inhabited P₁]
(li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) :
(li.to_affine_isometry_equiv h : P₁ → P₂) = li := rfl
@[simp] lemma to_affine_isometry_equiv_apply [inhabited P₁]
(li : P₁ →ᵃⁱ[𝕜] P₂) (h : finrank 𝕜 V₁ = finrank 𝕜 V₂) (x : P₁) :
(li.to_affine_isometry_equiv h) x = li x := rfl
end affine_isometry
include V V₂
/-- If `f` is an affine map, then its linear part is continuous iff `f` is continuous. -/
lemma affine_map.continuous_linear_iff {f : P →ᵃ[𝕜] P₂} :
continuous f.linear ↔ continuous f :=
begin
inhabit P,
have : (f.linear : V → V₂) =
(affine_isometry_equiv.vadd_const 𝕜 $ f $ default P).to_homeomorph.symm ∘ f ∘
(affine_isometry_equiv.vadd_const 𝕜 $ default P).to_homeomorph,
{ ext v, simp },
rw this,
simp only [homeomorph.comp_continuous_iff, homeomorph.comp_continuous_iff'],
end
|
ba1de14cbcce568371ec40a94d4afbab7ebde829
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/topology/dense_embedding.lean
|
062831193ad407ea09637ec8c3a2f65808e77e37
|
[
"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
| 12,900
|
lean
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import topology.separation
import topology.bases
/-!
# Dense embeddings
This file defines three properties of functions:
* `dense_range f` means `f` has dense image;
* `dense_inducing i` means `i` is also `inducing`;
* `dense_embedding e` means `e` is also an `embedding`.
The main theorem `continuous_extend` gives a criterion for a function
`f : X → Z` to a regular (T₃) space Z to extend along a dense embedding
`i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only
has to be `dense_inducing` (not necessarily injective).
-/
noncomputable theory
open set filter
open_locale classical topological_space filter
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α`
is the one induced by `i` from the topology on `β`. -/
structure dense_inducing [topological_space α] [topological_space β] (i : α → β)
extends inducing i : Prop :=
(dense : dense_range i)
namespace dense_inducing
variables [topological_space α] [topological_space β]
variables {i : α → β} (di : dense_inducing i)
lemma nhds_eq_comap (di : dense_inducing i) :
∀ a : α, 𝓝 a = comap i (𝓝 $ i a) :=
di.to_inducing.nhds_eq_comap
protected lemma continuous (di : dense_inducing i) : continuous i :=
di.to_inducing.continuous
lemma closure_range : closure (range i) = univ :=
di.dense.closure_range
lemma self_sub_closure_image_preimage_of_open {s : set β} (di : dense_inducing i) :
is_open s → s ⊆ closure (i '' (i ⁻¹' s)) :=
begin
intros s_op b b_in_s,
rw [image_preimage_eq_inter_range, mem_closure_iff],
intros U U_op b_in,
rw ←inter_assoc,
exact (dense_iff_inter_open.1 di.dense) _ (is_open_inter U_op s_op) ⟨b, b_in, b_in_s⟩
end
lemma closure_image_nhds_of_nhds {s : set α} {a : α} (di : dense_inducing i) :
s ∈ 𝓝 a → closure (i '' s) ∈ 𝓝 (i a) :=
begin
rw [di.nhds_eq_comap a, mem_comap_sets],
intro h,
rcases h with ⟨t, t_nhd, sub⟩,
rw mem_nhds_sets_iff at t_nhd,
rcases t_nhd with ⟨U, U_sub, ⟨U_op, e_a_in_U⟩⟩,
have := calc i ⁻¹' U ⊆ i⁻¹' t : preimage_mono U_sub
... ⊆ s : sub,
have := calc U ⊆ closure (i '' (i ⁻¹' U)) : self_sub_closure_image_preimage_of_open di U_op
... ⊆ closure (i '' s) : closure_mono (image_subset i this),
have U_nhd : U ∈ 𝓝 (i a) := mem_nhds_sets U_op e_a_in_U,
exact (𝓝 (i a)).sets_of_superset U_nhd this
end
/-- The product of two dense inducings is a dense inducing -/
protected lemma prod [topological_space γ] [topological_space δ]
{e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_inducing e₁) (de₂ : dense_inducing e₂) :
dense_inducing (λ(p : α × γ), (e₁ p.1, e₂ p.2)) :=
{ induced := (de₁.to_inducing.prod_mk de₂.to_inducing).induced,
dense := de₁.dense.prod_map de₂.dense }
open topological_space
/-- If the domain of a `dense_inducing` map is a separable space, then so is the codomain. -/
protected lemma separable_space [separable_space α] : separable_space β :=
di.dense.separable_space di.continuous
variables [topological_space δ] {f : γ → α} {g : γ → δ} {h : δ → β}
/--
γ -f→ α
g↓ ↓e
δ -h→ β
-/
lemma tendsto_comap_nhds_nhds {d : δ} {a : α} (di : dense_inducing i) (H : tendsto h (𝓝 d) (𝓝 (i a)))
(comm : h ∘ g = i ∘ f) : tendsto f (comap g (𝓝 d)) (𝓝 a) :=
begin
have lim1 : map g (comap g (𝓝 d)) ≤ 𝓝 d := map_comap_le,
replace lim1 : map h (map g (comap g (𝓝 d))) ≤ map h (𝓝 d) := map_mono lim1,
rw [filter.map_map, comm, ← filter.map_map, map_le_iff_le_comap] at lim1,
have lim2 : comap i (map h (𝓝 d)) ≤ comap i (𝓝 (i a)) := comap_mono H,
rw ← di.nhds_eq_comap at lim2,
exact le_trans lim1 lim2,
end
protected lemma nhds_within_ne_bot (di : dense_inducing i) (b : β) :
ne_bot (𝓝[range i] b) :=
di.dense.nhds_within_ne_bot b
lemma comap_nhds_ne_bot (di : dense_inducing i) (b : β) : ne_bot (comap i (𝓝 b)) :=
comap_ne_bot $ λ s hs,
let ⟨_, ⟨ha, a, rfl⟩⟩ := mem_closure_iff_nhds.1 (di.dense b) s hs in ⟨a, ha⟩
variables [topological_space γ]
/-- If `i : α → β` is a dense inducing, then any function `f : α → γ` "extends"
to a function `g = extend di f : β → γ`. If `γ` is Hausdorff and `f` has a
continuous extension, then `g` is the unique such extension. In general,
`g` might not be continuous or even extend `f`. -/
def extend (di : dense_inducing i) (f : α → γ) (b : β) : γ :=
@@lim _ ⟨f (di.dense.some b)⟩ (comap i (𝓝 b)) f
lemma extend_eq_of_tendsto [t2_space γ] {b : β} {c : γ} {f : α → γ}
(hf : tendsto f (comap i (𝓝 b)) (𝓝 c)) :
di.extend f b = c :=
by haveI := di.comap_nhds_ne_bot; exact hf.lim_eq
lemma extend_eq_at [t2_space γ] {f : α → γ} (a : α) (hf : continuous_at f a) :
di.extend f (i a) = f a :=
extend_eq_of_tendsto _ $ di.nhds_eq_comap a ▸ hf
lemma extend_eq [t2_space γ] {f : α → γ} (hf : continuous f) (a : α) :
di.extend f (i a) = f a :=
di.extend_eq_at a hf.continuous_at
lemma extend_unique_at [t2_space γ] {b : β} {f : α → γ} {g : β → γ} (di : dense_inducing i)
(hf : ∀ᶠ x in comap i (𝓝 b), g (i x) = f x) (hg : continuous_at g b) :
di.extend f b = g b :=
begin
refine di.extend_eq_of_tendsto (λ s hs, mem_map.2 _),
suffices : ∀ᶠ (x : α) in comap i (𝓝 b), g (i x) ∈ s,
from hf.mp (this.mono $ λ x hgx hfx, hfx ▸ hgx),
clear hf f,
refine eventually_comap.2 ((hg.eventually hs).mono _),
rintros _ hxs x rfl,
exact hxs
end
lemma extend_unique [t2_space γ] {f : α → γ} {g : β → γ} (di : dense_inducing i)
(hf : ∀ x, g (i x) = f x) (hg : continuous g) :
di.extend f = g :=
funext $ λ b, extend_unique_at di (eventually_of_forall hf) hg.continuous_at
lemma continuous_at_extend [regular_space γ] {b : β} {f : α → γ} (di : dense_inducing i)
(hf : ∀ᶠ x in 𝓝 b, ∃c, tendsto f (comap i $ 𝓝 x) (𝓝 c)) :
continuous_at (di.extend f) b :=
begin
set φ := di.extend f,
haveI := di.comap_nhds_ne_bot,
suffices : ∀ V' ∈ 𝓝 (φ b), is_closed V' → φ ⁻¹' V' ∈ 𝓝 b,
by simpa [continuous_at, (closed_nhds_basis _).tendsto_right_iff],
intros V' V'_in V'_closed,
set V₁ := {x | tendsto f (comap i $ 𝓝 x) (𝓝 $ φ x)},
have V₁_in : V₁ ∈ 𝓝 b,
{ filter_upwards [hf],
rintros x ⟨c, hc⟩,
dsimp [V₁, φ],
rwa di.extend_eq_of_tendsto hc },
obtain ⟨V₂, V₂_in, V₂_op, hV₂⟩ : ∃ V₂ ∈ 𝓝 b, is_open V₂ ∧ ∀ x ∈ i ⁻¹' V₂, f x ∈ V',
{ simpa [and_assoc] using ((nhds_basis_opens' b).comap i).tendsto_left_iff.mp
(mem_of_nhds V₁_in : b ∈ V₁) V' V'_in },
suffices : ∀ x ∈ V₁ ∩ V₂, φ x ∈ V',
{ filter_upwards [inter_mem_sets V₁_in V₂_in], exact this },
rintros x ⟨x_in₁, x_in₂⟩,
have hV₂x : V₂ ∈ 𝓝 x := mem_nhds_sets V₂_op x_in₂,
apply V'_closed.mem_of_tendsto x_in₁,
use V₂,
tauto,
end
lemma continuous_extend [regular_space γ] {f : α → γ} (di : dense_inducing i)
(hf : ∀b, ∃c, tendsto f (comap i (𝓝 b)) (𝓝 c)) : continuous (di.extend f) :=
continuous_iff_continuous_at.mpr $ assume b, di.continuous_at_extend $ univ_mem_sets' hf
lemma mk'
(i : α → β)
(c : continuous i)
(dense : ∀x, x ∈ closure (range i))
(H : ∀ (a:α) s ∈ 𝓝 a,
∃t ∈ 𝓝 (i a), ∀ b, i b ∈ t → b ∈ s) :
dense_inducing i :=
{ induced := (induced_iff_nhds_eq i).2 $
λ a, le_antisymm (tendsto_iff_comap.1 $ c.tendsto _) (by simpa [le_def] using H a),
dense := dense }
end dense_inducing
/-- A dense embedding is an embedding with dense image. -/
structure dense_embedding [topological_space α] [topological_space β] (e : α → β)
extends dense_inducing e : Prop :=
(inj : function.injective e)
theorem dense_embedding.mk'
[topological_space α] [topological_space β] (e : α → β)
(c : continuous e)
(dense : dense_range e)
(inj : function.injective e)
(H : ∀ (a:α) s ∈ 𝓝 a,
∃t ∈ 𝓝 (e a), ∀ b, e b ∈ t → b ∈ s) :
dense_embedding e :=
{ inj := inj,
..dense_inducing.mk' e c dense H}
namespace dense_embedding
open topological_space
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
variables {e : α → β} (de : dense_embedding e)
lemma inj_iff {x y} : e x = e y ↔ x = y := de.inj.eq_iff
lemma to_embedding : embedding e :=
{ induced := de.induced,
inj := de.inj }
/-- If the domain of a `dense_embedding` is a separable space, then so is its codomain. -/
protected lemma separable_space [separable_space α] : separable_space β :=
de.to_dense_inducing.separable_space
/-- The product of two dense embeddings is a dense embedding -/
protected lemma prod {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_embedding e₁) (de₂ : dense_embedding e₂) :
dense_embedding (λ(p : α × γ), (e₁ p.1, e₂ p.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩,
by simp; exact assume h₁ h₂, ⟨de₁.inj h₁, de₂.inj h₂⟩,
..dense_inducing.prod de₁.to_dense_inducing de₂.to_dense_inducing }
/-- The dense embedding of a subtype inside its closure. -/
def subtype_emb {α : Type*} (p : α → Prop) (e : α → β) (x : {x // p x}) :
{x // x ∈ closure (e '' {x | p x})} :=
⟨e x, subset_closure $ mem_image_of_mem e x.prop⟩
protected lemma subtype (p : α → Prop) : dense_embedding (subtype_emb p e) :=
{ dense_embedding .
dense := assume ⟨x, hx⟩, closure_subtype.mpr $
have (λ (x : {x // p x}), e x) = e ∘ coe, from rfl,
begin
rw ← image_univ,
simp [(image_comp _ _ _).symm, (∘), subtype_emb, -image_univ],
rw [this, image_comp, subtype.coe_image],
simp,
assumption
end,
inj := assume ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq $ de.inj $ @@congr_arg subtype.val h,
induced := (induced_iff_nhds_eq _).2 (assume ⟨x, hx⟩,
by simp [subtype_emb, nhds_subtype_eq_comap, de.to_inducing.nhds_eq_comap, comap_comap, (∘)]) }
end dense_embedding
lemma is_closed_property [topological_space β] {e : α → β} {p : β → Prop}
(he : dense_range e) (hp : is_closed {x | p x}) (h : ∀a, p (e a)) :
∀b, p b :=
have univ ⊆ {b | p b},
from calc univ = closure (range e) : he.closure_range.symm
... ⊆ closure {b | p b} : closure_mono $ range_subset_iff.mpr h
... = _ : hp.closure_eq,
assume b, this trivial
lemma is_closed_property2 [topological_space β] {e : α → β} {p : β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) :
∀b₁ b₂, p b₁ b₂ :=
have ∀q:β×β, p q.1 q.2,
from is_closed_property (he.prod_map he) hp $ λ _, h _ _,
assume b₁ b₂, this ⟨b₁, b₂⟩
lemma is_closed_property3 [topological_space β] {e : α → β} {p : β → β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) :
∀b₁ b₂ b₃, p b₁ b₂ b₃ :=
have ∀q:β×β×β, p q.1 q.2.1 q.2.2,
from is_closed_property (he.prod_map $ he.prod_map he) hp $ λ _, h _ _ _,
assume b₁ b₂ b₃, this ⟨b₁, b₂, b₃⟩
@[elab_as_eliminator]
lemma dense_range.induction_on [topological_space β] {e : α → β} (he : dense_range e) {p : β → Prop}
(b₀ : β) (hp : is_closed {b | p b}) (ih : ∀a:α, p $ e a) : p b₀ :=
is_closed_property he hp ih b₀
@[elab_as_eliminator]
lemma dense_range.induction_on₂ [topological_space β] {e : α → β} {p : β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂))
(b₁ b₂ : β) : p b₁ b₂ := is_closed_property2 he hp h _ _
@[elab_as_eliminator]
lemma dense_range.induction_on₃ [topological_space β] {e : α → β} {p : β → β → β → Prop}
(he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃))
(b₁ b₂ b₃ : β) : p b₁ b₂ b₃ := is_closed_property3 he hp h _ _ _
section
variables [topological_space β] [topological_space γ] [t2_space γ]
variables {f : α → β}
/-- Two continuous functions to a t2-space that agree on the dense range of a function are equal. -/
lemma dense_range.equalizer (hfd : dense_range f)
{g h : β → γ} (hg : continuous g) (hh : continuous h) (H : g ∘ f = h ∘ f) :
g = h :=
funext $ λ y, hfd.induction_on y (is_closed_eq hg hh) $ congr_fun H
end
|
3317863cdab282a062fc0eb8d90ea92669f0094c
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/measure_theory/function/ae_eq_fun.lean
|
f7a32c4765cf2e496927df97a163c46a25f64d58
|
[
"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
| 22,389
|
lean
|
/-
Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Zhouhang Zhou
-/
import measure_theory.integral.lebesgue
import order.filter.germ
import topology.continuous_function.algebra
/-!
# Almost everywhere equal functions
Two measurable functions are treated as identical if they are almost everywhere equal. We form the
set of equivalence classes under the relation of being almost everywhere equal, which is sometimes
known as the `L⁰` space.
See `l1_space.lean` for `L¹` space.
## Notation
* `α →ₘ[μ] β` is the type of `L⁰` space, where `α` and `β` are measurable spaces and `μ`
is a measure on `α`. `f : α →ₘ β` is a "function" in `L⁰`. In comments, `[f]` is also used
to denote an `L⁰` function.
`ₘ` can be typed as `\_m`. Sometimes it is shown as a box if font is missing.
## Main statements
* The linear structure of `L⁰` :
Addition and scalar multiplication are defined on `L⁰` in the natural way, i.e.,
`[f] + [g] := [f + g]`, `c • [f] := [c • f]`. So defined, `α →ₘ β` inherits the linear structure
of `β`. For example, if `β` is a module, then `α →ₘ β` is a module over the same ring.
See `mk_add_mk`, `neg_mk`, `mk_sub_mk`, `smul_mk`,
`add_to_fun`, `neg_to_fun`, `sub_to_fun`, `smul_to_fun`
* The order structure of `L⁰` :
`≤` can be defined in a similar way: `[f] ≤ [g]` if `f a ≤ g a` for almost all `a` in domain.
And `α →ₘ β` inherits the preorder and partial order of `β`.
TODO: Define `sup` and `inf` on `L⁰` so that it forms a lattice. It seems that `β` must be a
linear order, since otherwise `f ⊔ g` may not be a measurable function.
## Implementation notes
* `f.to_fun` : To find a representative of `f : α →ₘ β`, use `f.to_fun`.
For each operation `op` in `L⁰`, there is a lemma called `op_to_fun`,
characterizing, say, `(f op g).to_fun`.
* `ae_eq_fun.mk` : To constructs an `L⁰` function `α →ₘ β` from a measurable function `f : α → β`,
use `ae_eq_fun.mk`
* `comp` : Use `comp g f` to get `[g ∘ f]` from `g : β → γ` and `[f] : α →ₘ γ`
* `comp₂` : Use `comp₂ g f₁ f₂ to get `[λa, g (f₁ a) (f₂ a)]`.
For example, `[f + g]` is `comp₂ (+)`
## Tags
function space, almost everywhere equal, `L⁰`, ae_eq_fun
-/
noncomputable theory
open_locale classical ennreal
open set filter topological_space ennreal emetric measure_theory function
variables {α β γ δ : Type*} [measurable_space α] {μ ν : measure α}
namespace measure_theory
section measurable_space
variables [measurable_space β]
variable (β)
/-- The equivalence relation of being almost everywhere equal -/
def measure.ae_eq_setoid (μ : measure α) : setoid { f : α → β // ae_measurable f μ } :=
⟨λf g, (f : α → β) =ᵐ[μ] g, λ f, ae_eq_refl f, λ f g, ae_eq_symm, λ f g h, ae_eq_trans⟩
variable (α)
/-- The space of equivalence classes of measurable functions, where two measurable functions are
equivalent if they agree almost everywhere, i.e., they differ on a set of measure `0`. -/
def ae_eq_fun (μ : measure α) : Type* := quotient (μ.ae_eq_setoid β)
variables {α β}
notation α ` →ₘ[`:25 μ `] ` β := ae_eq_fun α β μ
end measurable_space
namespace ae_eq_fun
variables [measurable_space β] [measurable_space γ] [measurable_space δ]
/-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based
on the equivalence relation of being almost everywhere equal. -/
def mk (f : α → β) (hf : ae_measurable f μ) : α →ₘ[μ] β := quotient.mk' ⟨f, hf⟩
/-- A measurable representative of an `ae_eq_fun` [f] -/
instance : has_coe_to_fun (α →ₘ[μ] β) (λ _, α → β) :=
⟨λf, ae_measurable.mk _ (quotient.out' f : {f : α → β // ae_measurable f μ}).2⟩
protected lemma measurable (f : α →ₘ[μ] β) : measurable f :=
ae_measurable.measurable_mk _
protected lemma ae_measurable (f : α →ₘ[μ] β) : ae_measurable f μ :=
f.measurable.ae_measurable
@[simp] lemma quot_mk_eq_mk (f : α → β) (hf) :
(quot.mk (@setoid.r _ $ μ.ae_eq_setoid β) ⟨f, hf⟩ : α →ₘ[μ] β) = mk f hf :=
rfl
@[simp] lemma mk_eq_mk {f g : α → β} {hf hg} :
(mk f hf : α →ₘ[μ] β) = mk g hg ↔ f =ᵐ[μ] g :=
quotient.eq'
@[simp] lemma mk_coe_fn (f : α →ₘ[μ] β) : mk f f.ae_measurable = f :=
begin
conv_rhs { rw ← quotient.out_eq' f },
set g : {f : α → β // ae_measurable f μ} := quotient.out' f with hg,
have : g = ⟨g.1, g.2⟩ := subtype.eq rfl,
rw [this, ← mk, mk_eq_mk],
exact (ae_measurable.ae_eq_mk _).symm,
end
@[ext] lemma ext {f g : α →ₘ[μ] β} (h : f =ᵐ[μ] g) : f = g :=
by rwa [← f.mk_coe_fn, ← g.mk_coe_fn, mk_eq_mk]
lemma ext_iff {f g : α →ₘ[μ] β} : f = g ↔ f =ᵐ[μ] g :=
⟨λ h, by rw h, λ h, ext h⟩
lemma coe_fn_mk (f : α → β) (hf) : (mk f hf : α →ₘ[μ] β) =ᵐ[μ] f :=
begin
apply (ae_measurable.ae_eq_mk _).symm.trans,
exact @quotient.mk_out' _ (μ.ae_eq_setoid β) (⟨f, hf⟩ : {f // ae_measurable f μ})
end
@[elab_as_eliminator]
lemma induction_on (f : α →ₘ[μ] β) {p : (α →ₘ[μ] β) → Prop} (H : ∀ f hf, p (mk f hf)) : p f :=
quotient.induction_on' f $ subtype.forall.2 H
@[elab_as_eliminator]
lemma induction_on₂ {α' β' : Type*} [measurable_space α'] [measurable_space β'] {μ' : measure α'}
(f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') {p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → Prop}
(H : ∀ f hf f' hf', p (mk f hf) (mk f' hf')) :
p f f' :=
induction_on f $ λ f hf, induction_on f' $ H f hf
@[elab_as_eliminator]
lemma induction_on₃ {α' β' : Type*} [measurable_space α'] [measurable_space β'] {μ' : measure α'}
{α'' β'' : Type*} [measurable_space α''] [measurable_space β''] {μ'' : measure α''}
(f : α →ₘ[μ] β) (f' : α' →ₘ[μ'] β') (f'' : α'' →ₘ[μ''] β'')
{p : (α →ₘ[μ] β) → (α' →ₘ[μ'] β') → (α'' →ₘ[μ''] β'') → Prop}
(H : ∀ f hf f' hf' f'' hf'', p (mk f hf) (mk f' hf') (mk f'' hf'')) :
p f f' f'' :=
induction_on f $ λ f hf, induction_on₂ f' f'' $ H f hf
/-- Given a measurable function `g : β → γ`, and an almost everywhere equal function `[f] : α →ₘ β`,
return the equivalence class of `g ∘ f`, i.e., the almost everywhere equal function
`[g ∘ f] : α →ₘ γ`. -/
def comp (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) : α →ₘ[μ] γ :=
quotient.lift_on' f (λ f, mk (g ∘ (f : α → β)) (hg.comp_ae_measurable f.2)) $
λ f f' H, mk_eq_mk.2 $ H.fun_comp g
@[simp] lemma comp_mk (g : β → γ) (hg : measurable g)
(f : α → β) (hf) :
comp g hg (mk f hf : α →ₘ[μ] β) = mk (g ∘ f) (hg.comp_ae_measurable hf) :=
rfl
lemma comp_eq_mk (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) :
comp g hg f = mk (g ∘ f) (hg.comp_ae_measurable f.ae_measurable) :=
by rw [← comp_mk g hg f f.ae_measurable, mk_coe_fn]
lemma coe_fn_comp (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) :
comp g hg f =ᵐ[μ] g ∘ f :=
by { rw [comp_eq_mk], apply coe_fn_mk }
/-- The class of `x ↦ (f x, g x)`. -/
def pair (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : α →ₘ[μ] β × γ :=
quotient.lift_on₂' f g (λ f g, mk (λ x, (f.1 x, g.1 x)) (f.2.prod_mk g.2)) $
λ f g f' g' Hf Hg, mk_eq_mk.2 $ Hf.prod_mk Hg
@[simp] lemma pair_mk_mk (f : α → β) (hf) (g : α → γ) (hg) :
(mk f hf : α →ₘ[μ] β).pair (mk g hg) = mk (λ x, (f x, g x)) (hf.prod_mk hg) :=
rfl
lemma pair_eq_mk (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) :
f.pair g = mk (λ x, (f x, g x)) (f.ae_measurable.prod_mk g.ae_measurable) :=
by simp only [← pair_mk_mk, mk_coe_fn]
lemma coe_fn_pair (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) :
f.pair g =ᵐ[μ] (λ x, (f x, g x)) :=
by { rw pair_eq_mk, apply coe_fn_mk }
/-- Given a measurable function `g : β → γ → δ`, and almost everywhere equal functions
`[f₁] : α →ₘ β` and `[f₂] : α →ₘ γ`, return the equivalence class of the function
`λa, g (f₁ a) (f₂ a)`, i.e., the almost everywhere equal function
`[λa, g (f₁ a) (f₂ a)] : α →ₘ γ` -/
def comp₂ {γ δ : Type*} [measurable_space γ] [measurable_space δ] (g : β → γ → δ)
(hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) : α →ₘ[μ] δ :=
comp _ hg (f₁.pair f₂)
@[simp] lemma comp₂_mk_mk {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α → β) (f₂ : α → γ) (hf₁ hf₂) :
comp₂ g hg (mk f₁ hf₁ : α →ₘ[μ] β) (mk f₂ hf₂) =
mk (λa, g (f₁ a) (f₂ a)) (hg.comp_ae_measurable (hf₁.prod_mk hf₂)) :=
rfl
lemma comp₂_eq_pair {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) :
comp₂ g hg f₁ f₂ = comp _ hg (f₁.pair f₂) :=
rfl
lemma comp₂_eq_mk {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) :
comp₂ g hg f₁ f₂ = mk (λ a, g (f₁ a) (f₂ a))
(hg.comp_ae_measurable (f₁.ae_measurable.prod_mk f₂.ae_measurable)) :=
by rw [comp₂_eq_pair, pair_eq_mk, comp_mk]; refl
lemma coe_fn_comp₂ {γ δ : Type*} [measurable_space γ] [measurable_space δ]
(g : β → γ → δ) (hg : measurable (uncurry g)) (f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) :
comp₂ g hg f₁ f₂ =ᵐ[μ] λ a, g (f₁ a) (f₂ a) :=
by { rw comp₂_eq_mk, apply coe_fn_mk }
/-- Interpret `f : α →ₘ[μ] β` as a germ at `μ.ae` forgetting that `f` is almost everywhere
measurable. -/
def to_germ (f : α →ₘ[μ] β) : germ μ.ae β :=
quotient.lift_on' f (λ f, ((f : α → β) : germ μ.ae β)) $ λ f g H, germ.coe_eq.2 H
@[simp] lemma mk_to_germ (f : α → β) (hf) : (mk f hf : α →ₘ[μ] β).to_germ = f := rfl
lemma to_germ_eq (f : α →ₘ[μ] β) : f.to_germ = (f : α → β) :=
by rw [← mk_to_germ, mk_coe_fn]
lemma to_germ_injective : injective (to_germ : (α →ₘ[μ] β) → germ μ.ae β) :=
λ f g H, ext $ germ.coe_eq.1 $ by rwa [← to_germ_eq, ← to_germ_eq]
lemma comp_to_germ (g : β → γ) (hg : measurable g) (f : α →ₘ[μ] β) :
(comp g hg f).to_germ = f.to_germ.map g :=
induction_on f $ λ f hf, by simp
lemma comp₂_to_germ (g : β → γ → δ) (hg : measurable (uncurry g))
(f₁ : α →ₘ[μ] β) (f₂ : α →ₘ[μ] γ) :
(comp₂ g hg f₁ f₂).to_germ = f₁.to_germ.map₂ g f₂.to_germ :=
induction_on₂ f₁ f₂ $ λ f₁ hf₁ f₂ hf₂, by simp
/-- Given a predicate `p` and an equivalence class `[f]`, return true if `p` holds of `f a`
for almost all `a` -/
def lift_pred (p : β → Prop) (f : α →ₘ[μ] β) : Prop := f.to_germ.lift_pred p
/-- Given a relation `r` and equivalence class `[f]` and `[g]`, return true if `r` holds of
`(f a, g a)` for almost all `a` -/
def lift_rel (r : β → γ → Prop) (f : α →ₘ[μ] β) (g : α →ₘ[μ] γ) : Prop :=
f.to_germ.lift_rel r g.to_germ
lemma lift_rel_mk_mk {r : β → γ → Prop} {f : α → β} {g : α → γ} {hf hg} :
lift_rel r (mk f hf : α →ₘ[μ] β) (mk g hg) ↔ ∀ᵐ a ∂μ, r (f a) (g a) :=
iff.rfl
lemma lift_rel_iff_coe_fn {r : β → γ → Prop} {f : α →ₘ[μ] β} {g : α →ₘ[μ] γ} :
lift_rel r f g ↔ ∀ᵐ a ∂μ, r (f a) (g a) :=
by rw [← lift_rel_mk_mk, mk_coe_fn, mk_coe_fn]
section order
instance [preorder β] : preorder (α →ₘ[μ] β) := preorder.lift to_germ
@[simp] lemma mk_le_mk [preorder β] {f g : α → β} (hf hg) :
(mk f hf : α →ₘ[μ] β) ≤ mk g hg ↔ f ≤ᵐ[μ] g :=
iff.rfl
@[simp, norm_cast] lemma coe_fn_le [preorder β] {f g : α →ₘ[μ] β} :
(f : α → β) ≤ᵐ[μ] g ↔ f ≤ g :=
lift_rel_iff_coe_fn.symm
instance [partial_order β] : partial_order (α →ₘ[μ] β) :=
partial_order.lift to_germ to_germ_injective
section lattice
section sup
variables [semilattice_sup β] [has_measurable_sup₂ β]
instance : has_sup (α →ₘ[μ] β) := { sup := λ f g, ae_eq_fun.comp₂ (⊔) measurable_sup f g }
lemma coe_fn_sup (f g : α →ₘ[μ] β) : ⇑(f ⊔ g) =ᵐ[μ] λ x, f x ⊔ g x := coe_fn_comp₂ _ _ _ _
protected lemma le_sup_left (f g : α →ₘ[μ] β) : f ≤ f ⊔ g :=
by { rw ← coe_fn_le, filter_upwards [coe_fn_sup f g] with _ ha, rw ha, exact le_sup_left, }
protected lemma le_sup_right (f g : α →ₘ[μ] β) : g ≤ f ⊔ g :=
by { rw ← coe_fn_le, filter_upwards [coe_fn_sup f g] with _ ha, rw ha, exact le_sup_right, }
protected lemma sup_le (f g f' : α →ₘ[μ] β) (hf : f ≤ f') (hg : g ≤ f') : f ⊔ g ≤ f' :=
begin
rw ← coe_fn_le at hf hg ⊢,
filter_upwards [hf, hg, coe_fn_sup f g] with _ haf hag ha_sup,
rw ha_sup,
exact sup_le haf hag,
end
end sup
section inf
variables [semilattice_inf β] [has_measurable_inf₂ β]
instance : has_inf (α →ₘ[μ] β) := { inf := λ f g, ae_eq_fun.comp₂ (⊓) measurable_inf f g }
lemma coe_fn_inf (f g : α →ₘ[μ] β) : ⇑(f ⊓ g) =ᵐ[μ] λ x, f x ⊓ g x := coe_fn_comp₂ _ _ _ _
protected lemma inf_le_left (f g : α →ₘ[μ] β) : f ⊓ g ≤ f :=
by { rw ← coe_fn_le, filter_upwards [coe_fn_inf f g] with _ ha, rw ha, exact inf_le_left, }
protected lemma inf_le_right (f g : α →ₘ[μ] β) : f ⊓ g ≤ g :=
by { rw ← coe_fn_le, filter_upwards [coe_fn_inf f g] with _ ha, rw ha, exact inf_le_right, }
protected lemma le_inf (f' f g : α →ₘ[μ] β) (hf : f' ≤ f) (hg : f' ≤ g) : f' ≤ f ⊓ g :=
begin
rw ← coe_fn_le at hf hg ⊢,
filter_upwards [hf, hg, coe_fn_inf f g] with _ haf hag ha_inf,
rw ha_inf,
exact le_inf haf hag,
end
end inf
instance [lattice β] [has_measurable_sup₂ β] [has_measurable_inf₂ β] : lattice (α →ₘ[μ] β) :=
{ sup := has_sup.sup,
le_sup_left := ae_eq_fun.le_sup_left,
le_sup_right := ae_eq_fun.le_sup_right,
sup_le := ae_eq_fun.sup_le,
inf := has_inf.inf,
inf_le_left := ae_eq_fun.inf_le_left,
inf_le_right := ae_eq_fun.inf_le_right,
le_inf := ae_eq_fun.le_inf,
..ae_eq_fun.partial_order}
end lattice
end order
variable (α)
/-- The equivalence class of a constant function: `[λa:α, b]`, based on the equivalence relation of
being almost everywhere equal -/
def const (b : β) : α →ₘ[μ] β := mk (λa:α, b) ae_measurable_const
lemma coe_fn_const (b : β) : (const α b : α →ₘ[μ] β) =ᵐ[μ] function.const α b :=
coe_fn_mk _ _
variable {α}
instance [inhabited β] : inhabited (α →ₘ[μ] β) := ⟨const α default⟩
@[to_additive] instance [has_one β] : has_one (α →ₘ[μ] β) := ⟨const α 1⟩
@[to_additive] lemma one_def [has_one β] :
(1 : α →ₘ[μ] β) = mk (λa:α, 1) ae_measurable_const := rfl
@[to_additive] lemma coe_fn_one [has_one β] : ⇑(1 : α →ₘ[μ] β) =ᵐ[μ] 1 := coe_fn_const _ _
@[simp, to_additive] lemma one_to_germ [has_one β] : (1 : α →ₘ[μ] β).to_germ = 1 := rfl
section monoid
variables
[topological_space γ] [second_countable_topology γ] [borel_space γ]
[monoid γ] [has_continuous_mul γ]
@[to_additive]
instance : has_mul (α →ₘ[μ] γ) := ⟨comp₂ (*) measurable_mul⟩
@[simp, to_additive] lemma mk_mul_mk (f g : α → γ) (hf hg) :
(mk f hf : α →ₘ[μ] γ) * (mk g hg) = mk (f * g) (hf.mul hg) :=
rfl
@[to_additive] lemma coe_fn_mul (f g : α →ₘ[μ] γ) : ⇑(f * g) =ᵐ[μ] f * g := coe_fn_comp₂ _ _ _ _
@[simp, to_additive] lemma mul_to_germ (f g : α →ₘ[μ] γ) :
(f * g).to_germ = f.to_germ * g.to_germ :=
comp₂_to_germ _ _ _ _
@[to_additive]
instance : monoid (α →ₘ[μ] γ) :=
to_germ_injective.monoid to_germ one_to_germ mul_to_germ
end monoid
@[to_additive]
instance comm_monoid [topological_space γ] [second_countable_topology γ] [borel_space γ]
[comm_monoid γ] [has_continuous_mul γ] : comm_monoid (α →ₘ[μ] γ) :=
to_germ_injective.comm_monoid to_germ one_to_germ mul_to_germ
section group
variables [topological_space γ] [borel_space γ] [group γ] [topological_group γ]
@[to_additive] instance : has_inv (α →ₘ[μ] γ) := ⟨comp has_inv.inv measurable_inv⟩
@[simp, to_additive] lemma inv_mk (f : α → γ) (hf) : (mk f hf : α →ₘ[μ] γ)⁻¹ = mk f⁻¹ hf.inv := rfl
@[to_additive] lemma coe_fn_inv (f : α →ₘ[μ] γ) : ⇑(f⁻¹) =ᵐ[μ] f⁻¹ := coe_fn_comp _ _ _
@[to_additive] lemma inv_to_germ (f : α →ₘ[μ] γ) : (f⁻¹).to_germ = f.to_germ⁻¹ := comp_to_germ _ _ _
variables [second_countable_topology γ]
@[to_additive] instance : has_div (α →ₘ[μ] γ) := ⟨comp₂ has_div.div measurable_div⟩
@[simp, to_additive] lemma mk_div (f g : α → γ) (hf hg) :
mk (f / g) (ae_measurable.div hf hg) = (mk f hf : α →ₘ[μ] γ) / (mk g hg) :=
rfl
@[to_additive] lemma coe_fn_div (f g : α →ₘ[μ] γ) : ⇑(f / g) =ᵐ[μ] f / g := coe_fn_comp₂ _ _ _ _
@[to_additive] lemma div_to_germ (f g : α →ₘ[μ] γ) : (f / g).to_germ = f.to_germ / g.to_germ :=
comp₂_to_germ _ _ _ _
@[to_additive]
instance : group (α →ₘ[μ] γ) :=
to_germ_injective.group _ one_to_germ mul_to_germ inv_to_germ div_to_germ
end group
@[to_additive]
instance [topological_space γ] [borel_space γ] [comm_group γ] [topological_group γ]
[second_countable_topology γ] : comm_group (α →ₘ[μ] γ) :=
{ .. ae_eq_fun.group, .. ae_eq_fun.comm_monoid }
section module
variables {𝕜 : Type*} [semiring 𝕜] [topological_space 𝕜] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
variables [topological_space γ] [borel_space γ] [add_comm_monoid γ] [module 𝕜 γ]
[has_continuous_smul 𝕜 γ]
instance : has_scalar 𝕜 (α →ₘ[μ] γ) :=
⟨λ c f, comp ((•) c) (measurable_id.const_smul c) f⟩
@[simp] lemma smul_mk (c : 𝕜) (f : α → γ) (hf) :
c • (mk f hf : α →ₘ[μ] γ) = mk (c • f) (hf.const_smul _) :=
rfl
lemma coe_fn_smul (c : 𝕜) (f : α →ₘ[μ] γ) : ⇑(c • f) =ᵐ[μ] c • f := coe_fn_comp _ _ _
lemma smul_to_germ (c : 𝕜) (f : α →ₘ[μ] γ) : (c • f).to_germ = c • f.to_germ :=
comp_to_germ _ _ _
variables [second_countable_topology γ] [has_continuous_add γ]
instance : module 𝕜 (α →ₘ[μ] γ) :=
to_germ_injective.module 𝕜 ⟨@to_germ α γ _ μ _, zero_to_germ, add_to_germ⟩ smul_to_germ
end module
open ennreal
/-- For `f : α → ℝ≥0∞`, define `∫ [f]` to be `∫ f` -/
def lintegral (f : α →ₘ[μ] ℝ≥0∞) : ℝ≥0∞ :=
quotient.lift_on' f (λf, ∫⁻ a, (f : α → ℝ≥0∞) a ∂μ) (assume f g, lintegral_congr_ae)
@[simp] lemma lintegral_mk (f : α → ℝ≥0∞) (hf) :
(mk f hf : α →ₘ[μ] ℝ≥0∞).lintegral = ∫⁻ a, f a ∂μ := rfl
lemma lintegral_coe_fn (f : α →ₘ[μ] ℝ≥0∞) : ∫⁻ a, f a ∂μ = f.lintegral :=
by rw [← lintegral_mk, mk_coe_fn]
@[simp] lemma lintegral_zero : lintegral (0 : α →ₘ[μ] ℝ≥0∞) = 0 := lintegral_zero
@[simp] lemma lintegral_eq_zero_iff {f : α →ₘ[μ] ℝ≥0∞} : lintegral f = 0 ↔ f = 0 :=
induction_on f $ λ f hf, (lintegral_eq_zero_iff' hf).trans mk_eq_mk.symm
lemma lintegral_add (f g : α →ₘ[μ] ℝ≥0∞) : lintegral (f + g) = lintegral f + lintegral g :=
induction_on₂ f g $ λ f hf g hg, by simp [lintegral_add' hf hg]
lemma lintegral_mono {f g : α →ₘ[μ] ℝ≥0∞} : f ≤ g → lintegral f ≤ lintegral g :=
induction_on₂ f g $ λ f hf g hg hfg, lintegral_mono_ae hfg
section pos_part
variables [topological_space γ] [linear_order γ] [order_closed_topology γ]
[second_countable_topology γ] [has_zero γ] [opens_measurable_space γ]
/-- Positive part of an `ae_eq_fun`. -/
def pos_part (f : α →ₘ[μ] γ) : α →ₘ[μ] γ :=
comp (λ x, max x 0) (measurable_id.max measurable_const) f
@[simp] lemma pos_part_mk (f : α → γ) (hf) :
pos_part (mk f hf : α →ₘ[μ] γ) = mk (λ x, max (f x) 0) (hf.max ae_measurable_const) :=
rfl
lemma coe_fn_pos_part (f : α →ₘ[μ] γ) : ⇑(pos_part f) =ᵐ[μ] (λ a, max (f a) 0) :=
coe_fn_comp _ _ _
end pos_part
end ae_eq_fun
end measure_theory
namespace continuous_map
open measure_theory
variables [topological_space α] [borel_space α] (μ)
variables [topological_space β] [measurable_space β] [borel_space β]
/-- The equivalence class of `μ`-almost-everywhere measurable functions associated to a continuous
map. -/
def to_ae_eq_fun (f : C(α, β)) : α →ₘ[μ] β :=
ae_eq_fun.mk f f.continuous.measurable.ae_measurable
lemma coe_fn_to_ae_eq_fun (f : C(α, β)) : f.to_ae_eq_fun μ =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk f _
variables [group β] [topological_group β] [second_countable_topology β]
/-- The `mul_hom` from the group of continuous maps from `α` to `β` to the group of equivalence
classes of `μ`-almost-everywhere measurable functions. -/
@[to_additive "The `add_hom` from the group of continuous maps from `α` to `β` to the group of
equivalence classes of `μ`-almost-everywhere measurable functions."]
def to_ae_eq_fun_mul_hom : C(α, β) →* α →ₘ[μ] β :=
{ to_fun := continuous_map.to_ae_eq_fun μ,
map_one' := rfl,
map_mul' := λ f g, ae_eq_fun.mk_mul_mk f g f.continuous.measurable.ae_measurable
g.continuous.measurable.ae_measurable }
variables {𝕜 : Type*} [semiring 𝕜] [topological_space 𝕜] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
variables [topological_space γ] [measurable_space γ] [borel_space γ] [add_comm_group γ]
[module 𝕜 γ] [topological_add_group γ] [has_continuous_smul 𝕜 γ]
[second_countable_topology γ]
/-- The linear map from the group of continuous maps from `α` to `β` to the group of equivalence
classes of `μ`-almost-everywhere measurable functions. -/
def to_ae_eq_fun_linear_map : C(α, γ) →ₗ[𝕜] α →ₘ[μ] γ :=
{ map_smul' := λ c f, ae_eq_fun.smul_mk c f f.continuous.measurable.ae_measurable,
.. to_ae_eq_fun_add_hom μ }
end continuous_map
|
b3f957fafd3eba511eb091eb0c182ce3709aeb5b
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/compiler/reusebug.lean
|
c711e62dfa1a7759e05dc3dce183e4c5edc48087
|
[
"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
| 756
|
lean
|
inductive Expr
| Val : Int → Expr
| Var : String → Expr
| Add : Expr → Expr → Expr
| Mul : Expr → Expr → Expr
namespace Expr
protected def Expr.toString : Expr → String
| Val n => toString n
| Var x => x
| Add f g => "(" ++ Expr.toString f ++ " + " ++ Expr.toString g ++ ")"
| Mul f g => "(" ++ Expr.toString f ++ " * " ++ Expr.toString g ++ ")"
instance : ToString Expr :=
⟨Expr.toString⟩
partial def addAux : Expr → Expr → Expr
| f, Add (Val n) g => addAux (Val n) (addAux f g)
| f, g => Add f g
def add (a b : Expr) : Expr :=
addAux a b
end Expr
open Expr
def main (xs : List String) : IO UInt32 :=
do let x := Var "x";
IO.println (add (Val 1) (Add (Mul (Val 2) x) x));
pure 0
|
59bde3d80a628b1ae1a1d2dd804a8a84fa3d5f96
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/group_theory/specific_groups/alternating.lean
|
60ad95cd0e16fa76aee8bdf24732ce6fc24b4650
|
[
"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
| 15,088
|
lean
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import group_theory.perm.fin
import tactic.interval_cases
/-!
# Alternating Groups
The alternating group on a finite type `α` is the subgroup of the permutation group `perm α`
consisting of the even permutations.
## Main definitions
* `alternating_group α` is the alternating group on `α`, defined as a `subgroup (perm α)`.
## Main results
* `two_mul_card_alternating_group` shows that the alternating group is half as large as
the permutation group it is a subgroup of.
* `closure_three_cycles_eq_alternating` shows that the alternating group is
generated by 3-cycles.
* `alternating_group.is_simple_group_five` shows that the alternating group on `fin 5` is simple.
The proof shows that the normal closure of any non-identity element of this group contains a
3-cycle.
## Tags
alternating group permutation
## TODO
* Show that `alternating_group α` is simple if and only if `fintype.card α ≠ 4`.
-/
open equiv equiv.perm subgroup fintype
variables (α : Type*) [fintype α] [decidable_eq α]
/-- The alternating group on a finite type, realized as a subgroup of `equiv.perm`.
For $A_n$, use `alternating_group (fin n)`. -/
@[derive fintype] def alternating_group : subgroup (perm α) :=
sign.ker
instance [subsingleton α] : unique (alternating_group α) :=
⟨⟨1⟩, λ ⟨p, hp⟩, subtype.eq (subsingleton.elim p _)⟩
variables {α}
lemma alternating_group_eq_sign_ker : alternating_group α = sign.ker := rfl
namespace equiv.perm
@[simp]
lemma mem_alternating_group {f : perm α} :
f ∈ alternating_group α ↔ sign f = 1 :=
sign.mem_ker
lemma prod_list_swap_mem_alternating_group_iff_even_length {l : list (perm α)}
(hl : ∀ g ∈ l, is_swap g) :
l.prod ∈ alternating_group α ↔ even l.length :=
begin
rw [mem_alternating_group, sign_prod_list_swap hl, ← units.coe_eq_one, units.coe_pow,
units.coe_neg_one, nat.neg_one_pow_eq_one_iff_even],
dec_trivial
end
lemma is_three_cycle.mem_alternating_group {f : perm α} (h : is_three_cycle f) :
f ∈ alternating_group α :=
mem_alternating_group.2 h.sign
lemma fin_rotate_bit1_mem_alternating_group {n : ℕ} :
fin_rotate (bit1 n) ∈ alternating_group (fin (bit1 n)) :=
by rw [mem_alternating_group, bit1, sign_fin_rotate, pow_bit0', int.units_mul_self, one_pow]
end equiv.perm
lemma two_mul_card_alternating_group [nontrivial α] :
2 * card (alternating_group α) = card (perm α) :=
begin
let := (quotient_group.quotient_ker_equiv_of_surjective _ (sign_surjective α)).to_equiv,
rw [←fintype.card_units_int, ←fintype.card_congr this],
exact (subgroup.card_eq_card_quotient_mul_card_subgroup _).symm,
end
namespace alternating_group
open equiv.perm
instance normal : (alternating_group α).normal := sign.normal_ker
lemma is_conj_of {σ τ : alternating_group α}
(hc : is_conj (σ : perm α) (τ : perm α)) (hσ : (σ : perm α).support.card + 2 ≤ fintype.card α) :
is_conj σ τ :=
begin
obtain ⟨σ, hσ⟩ := σ,
obtain ⟨τ, hτ⟩ := τ,
obtain ⟨π, hπ⟩ := is_conj_iff.1 hc,
rw [subtype.coe_mk, subtype.coe_mk] at hπ,
cases int.units_eq_one_or (sign π) with h h,
{ rw is_conj_iff,
refine ⟨⟨π, mem_alternating_group.mp h⟩, subtype.val_injective _⟩,
simpa only [subtype.val_eq_coe, subgroup.coe_mul, coe_inv, coe_mk] using hπ },
{ have h2 : 2 ≤ σ.supportᶜ.card,
{ rw [finset.card_compl, le_tsub_iff_left σ.support.card_le_univ],
exact hσ },
obtain ⟨a, ha, b, hb, ab⟩ := finset.one_lt_card.1 h2,
refine is_conj_iff.2 ⟨⟨π * swap a b, _⟩, subtype.val_injective _⟩,
{ rw [mem_alternating_group, monoid_hom.map_mul, h, sign_swap ab, int.units_mul_self] },
{ simp only [←hπ, coe_mk, subgroup.coe_mul, subtype.val_eq_coe],
have hd : disjoint (swap a b) σ,
{ rw [disjoint_iff_disjoint_support, support_swap ab, finset.disjoint_insert_left,
finset.disjoint_singleton_left],
exact ⟨finset.mem_compl.1 ha, finset.mem_compl.1 hb⟩ },
rw [mul_assoc π _ σ, hd.commute.eq, coe_inv, coe_mk],
simp [mul_assoc] } }
end
lemma is_three_cycle_is_conj (h5 : 5 ≤ fintype.card α)
{σ τ : alternating_group α}
(hσ : is_three_cycle (σ : perm α)) (hτ : is_three_cycle (τ : perm α)) :
is_conj σ τ :=
alternating_group.is_conj_of (is_conj_iff_cycle_type_eq.2 (hσ.trans hτ.symm))
(by rwa hσ.card_support)
end alternating_group
namespace equiv.perm
open alternating_group
@[simp]
theorem closure_three_cycles_eq_alternating :
closure {σ : perm α | is_three_cycle σ} = alternating_group α :=
closure_eq_of_le _ (λ σ hσ, mem_alternating_group.2 hσ.sign) $ λ σ hσ, begin
suffices hind : ∀ (n : ℕ) (l : list (perm α)) (hl : ∀ g, g ∈ l → is_swap g)
(hn : l.length = 2 * n), l.prod ∈ closure {σ : perm α | is_three_cycle σ},
{ obtain ⟨l, rfl, hl⟩ := trunc_swap_factors σ,
obtain ⟨n, hn⟩ := (prod_list_swap_mem_alternating_group_iff_even_length hl).1 hσ,
exact hind n l hl hn },
intro n,
induction n with n ih; intros l hl hn,
{ simp [list.length_eq_zero.1 hn, one_mem] },
rw [nat.mul_succ] at hn,
obtain ⟨a, l, rfl⟩ := l.exists_of_length_succ hn,
rw [list.length_cons, nat.succ_inj'] at hn,
obtain ⟨b, l, rfl⟩ := l.exists_of_length_succ hn,
rw [list.prod_cons, list.prod_cons, ← mul_assoc],
rw [list.length_cons, nat.succ_inj'] at hn,
exact mul_mem _ (is_swap.mul_mem_closure_three_cycles (hl a (list.mem_cons_self a _))
(hl b (list.mem_cons_of_mem a (l.mem_cons_self b))))
(ih _ (λ g hg, hl g (list.mem_cons_of_mem _ (list.mem_cons_of_mem _ hg))) hn),
end
/-- A key lemma to prove $A_5$ is simple. Shows that any normal subgroup of an alternating group on
at least 5 elements is the entire alternating group if it contains a 3-cycle. -/
lemma is_three_cycle.alternating_normal_closure (h5 : 5 ≤ fintype.card α)
{f : perm α} (hf : is_three_cycle f) :
normal_closure ({⟨f, hf.mem_alternating_group⟩} : set (alternating_group α)) = ⊤ :=
eq_top_iff.2 begin
have hi : function.injective (alternating_group α).subtype := subtype.coe_injective,
refine eq_top_iff.1 (map_injective hi (le_antisymm (map_mono le_top) _)),
rw [← monoid_hom.range_eq_map, subtype_range, normal_closure, monoid_hom.map_closure],
refine (le_of_eq closure_three_cycles_eq_alternating.symm).trans (closure_mono _),
intros g h,
obtain ⟨c, rfl⟩ := is_conj_iff.1 (is_conj_iff_cycle_type_eq.2 (hf.trans h.symm)),
refine ⟨⟨c * f * c⁻¹, h.mem_alternating_group⟩, _, rfl⟩,
rw group.mem_conjugates_of_set_iff,
exact ⟨⟨f, hf.mem_alternating_group⟩, set.mem_singleton _, is_three_cycle_is_conj h5 hf h⟩
end
/-- Part of proving $A_5$ is simple. Shows that the square of any element of $A_5$ with a 3-cycle in
its cycle decomposition is a 3-cycle, so the normal closure of the original element must be
$A_5$. -/
lemma is_three_cycle_sq_of_three_mem_cycle_type_five {g : perm (fin 5)} (h : 3 ∈ cycle_type g) :
is_three_cycle (g * g) :=
begin
obtain ⟨c, g', rfl, hd, hc, h3⟩ := mem_cycle_type_iff.1 h,
simp only [mul_assoc],
rw [hd.commute.eq, ← mul_assoc g'],
suffices hg' : order_of g' ∣ 2,
{ rw [← pow_two, order_of_dvd_iff_pow_eq_one.1 hg', one_mul],
exact (card_support_eq_three_iff.1 h3).is_three_cycle_sq },
rw [← lcm_cycle_type, multiset.lcm_dvd],
intros n hn,
rw le_antisymm (two_le_of_mem_cycle_type hn) (le_trans (le_card_support_of_mem_cycle_type hn) _),
apply le_of_add_le_add_left,
rw [← hd.card_support_mul, h3],
exact (c * g').support.card_le_univ,
end
end equiv.perm
namespace alternating_group
open equiv.perm
lemma nontrivial_of_three_le_card (h3 : 3 ≤ card α) : nontrivial (alternating_group α) :=
begin
haveI := fintype.one_lt_card_iff_nontrivial.1 (lt_trans dec_trivial h3),
rw ← fintype.one_lt_card_iff_nontrivial,
refine lt_of_mul_lt_mul_left _ (le_of_lt nat.prime_two.pos),
rw [two_mul_card_alternating_group, card_perm, ← nat.succ_le_iff],
exact le_trans h3 (card α).self_le_factorial,
end
instance {n : ℕ} : nontrivial (alternating_group (fin (n + 3))) :=
nontrivial_of_three_le_card (by { rw card_fin, exact le_add_left (le_refl 3) })
/-- The normal closure of the 5-cycle `fin_rotate 5` within $A_5$ is the whole group. This will be
used to show that the normal closure of any 5-cycle within $A_5$ is the whole group. -/
lemma normal_closure_fin_rotate_five :
(normal_closure ({⟨fin_rotate 5, fin_rotate_bit1_mem_alternating_group⟩} :
set (alternating_group (fin 5)))) = ⊤ :=
eq_top_iff.2 begin
have h3 : is_three_cycle ((fin.cycle_range 2) * (fin_rotate 5) *
(fin.cycle_range 2)⁻¹ * (fin_rotate 5)⁻¹) := card_support_eq_three_iff.1 dec_trivial,
rw ← h3.alternating_normal_closure (by rw [card_fin]),
refine normal_closure_le_normal _,
rw [set.singleton_subset_iff, set_like.mem_coe],
have h : (⟨fin_rotate 5, fin_rotate_bit1_mem_alternating_group⟩ :
alternating_group (fin 5)) ∈ normal_closure _ :=
set_like.mem_coe.1 (subset_normal_closure (set.mem_singleton _)),
exact mul_mem _ (subgroup.normal_closure_normal.conj_mem _ h
⟨fin.cycle_range 2, fin.is_three_cycle_cycle_range_two.mem_alternating_group⟩) (inv_mem _ h),
end
/-- The normal closure of $(04)(13)$ within $A_5$ is the whole group. This will be
used to show that the normal closure of any permutation of cycle type $(2,2)$ is the whole group.
-/
lemma normal_closure_swap_mul_swap_five :
(normal_closure ({⟨swap 0 4 * swap 1 3, mem_alternating_group.2 dec_trivial⟩} :
set (alternating_group (fin 5)))) = ⊤ :=
begin
let g1 := (⟨swap 0 2 * swap 0 1, mem_alternating_group.2 dec_trivial⟩ :
alternating_group (fin 5)),
let g2 := (⟨swap 0 4 * swap 1 3, mem_alternating_group.2 dec_trivial⟩ :
alternating_group (fin 5)),
have h5 : g1 * g2 * g1⁻¹ * g2⁻¹ = ⟨fin_rotate 5, fin_rotate_bit1_mem_alternating_group⟩,
{ rw subtype.ext_iff,
simp only [fin.coe_mk, subgroup.coe_mul, subgroup.coe_inv, fin.coe_mk],
dec_trivial },
rw [eq_top_iff, ← normal_closure_fin_rotate_five],
refine normal_closure_le_normal _,
rw [set.singleton_subset_iff, set_like.mem_coe, ← h5],
have h : g2 ∈ normal_closure {g2} :=
set_like.mem_coe.1 (subset_normal_closure (set.mem_singleton _)),
exact mul_mem _ (subgroup.normal_closure_normal.conj_mem _ h g1) (inv_mem _ h),
end
/-- Shows that any non-identity element of $A_5$ whose cycle decomposition consists only of swaps
is conjugate to $(04)(13)$. This is used to show that the normal closure of such a permutation
in $A_5$ is $A_5$. -/
lemma is_conj_swap_mul_swap_of_cycle_type_two {g : perm (fin 5)}
(ha : g ∈ alternating_group (fin 5))
(h1 : g ≠ 1)
(h2 : ∀ n, n ∈ cycle_type (g : perm (fin 5)) → n = 2) :
is_conj (swap 0 4 * swap 1 3) g :=
begin
have h := g.support.card_le_univ,
rw [← sum_cycle_type, multiset.eq_repeat_of_mem h2, multiset.sum_repeat, smul_eq_mul] at h,
rw [← multiset.eq_repeat'] at h2,
have h56 : 5 ≤ 3 * 2 := nat.le_succ 5,
have h := le_of_mul_le_mul_right (le_trans h h56) dec_trivial,
rw [mem_alternating_group, sign_of_cycle_type, h2, multiset.map_repeat, multiset.prod_repeat,
int.units_pow_two, units.ext_iff, units.coe_one, units.coe_pow, units.coe_neg_one,
nat.neg_one_pow_eq_one_iff_even _] at ha,
swap, { dec_trivial },
rw [is_conj_iff_cycle_type_eq, h2],
interval_cases multiset.card g.cycle_type,
{ exact (h1 (card_cycle_type_eq_zero.1 h_1)).elim },
{ contrapose! ha,
simp [h_1] },
{ have h04 : (0 : fin 5) ≠ 4 := dec_trivial,
have h13 : (1 : fin 5) ≠ 3 := dec_trivial,
rw [h_1, disjoint.cycle_type, (is_cycle_swap h04).cycle_type, (is_cycle_swap h13).cycle_type,
card_support_swap h04, card_support_swap h13],
{ refl },
{ rw [disjoint_iff_disjoint_support, support_swap h04, support_swap h13],
dec_trivial } },
{ contrapose! ha,
simp [h_1] }
end
/-- Shows that $A_5$ is simple by taking an arbitrary non-identity element and showing by casework
on its cycle type that its normal closure is all of $A_5$. -/
instance is_simple_group_five : is_simple_group (alternating_group (fin 5)) :=
⟨exists_pair_ne _, λ H, begin
introI Hn,
refine or_not.imp (id) (λ Hb, _),
rw [eq_bot_iff_forall] at Hb,
push_neg at Hb,
obtain ⟨⟨g, gA⟩, gH, g1⟩ : ∃ (x : ↥(alternating_group (fin 5))), x ∈ H ∧ x ≠ 1 := Hb,
-- `g` is a non-identity alternating permutation in a normal subgroup `H` of $A_5$.
rw [← set_like.mem_coe, ← set.singleton_subset_iff] at gH,
refine eq_top_iff.2 (le_trans (ge_of_eq _) (normal_closure_le_normal gH)),
-- It suffices to show that the normal closure of `g` in $A_5$ is $A_5$.
by_cases h2 : ∀ n ∈ g.cycle_type, n = 2,
{ -- If the cycle decomposition of `g` consists entirely of swaps, then the cycle type is $(2,2)$.
-- This means that it is conjugate to $(04)(13)$, whose normal closure is $A_5$.
rw [ne.def, subtype.ext_iff] at g1,
exact (is_conj_swap_mul_swap_of_cycle_type_two gA g1 h2).normal_closure_eq_top_of
normal_closure_swap_mul_swap_five },
push_neg at h2,
obtain ⟨n, ng, n2⟩ : ∃ (n : ℕ), n ∈ g.cycle_type ∧ n ≠ 2 := h2,
-- `n` is the size of a non-swap cycle in the decomposition of `g`.
have n2' : 2 < n := lt_of_le_of_ne (two_le_of_mem_cycle_type ng) n2.symm,
have n5 : n ≤ 5 := le_trans _ g.support.card_le_univ,
-- We check that `2 < n ≤ 5`, so that `interval_cases` has a precise range to check.
swap, { obtain ⟨m, hm⟩ := multiset.exists_cons_of_mem ng,
rw [← sum_cycle_type, hm, multiset.sum_cons],
exact le_add_right le_rfl },
interval_cases n, -- This breaks into cases `n = 3`, `n = 4`, `n = 5`.
{ -- If `n = 3`, then `g` has a 3-cycle in its decomposition, so `g^2` is a 3-cycle.
-- `g^2` is in the normal closure of `g`, so that normal closure must be $A_5$.
rw [eq_top_iff, ← (is_three_cycle_sq_of_three_mem_cycle_type_five ng).alternating_normal_closure
(by rw card_fin )],
refine normal_closure_le_normal _,
rw [set.singleton_subset_iff, set_like.mem_coe],
have h := set_like.mem_coe.1 (subset_normal_closure (set.mem_singleton _)),
exact mul_mem _ h h },
{ -- The case `n = 4` leads to contradiction, as no element of $A_5$ includes a 4-cycle.
have con := mem_alternating_group.1 gA,
contrapose! con,
rw [sign_of_cycle_type, cycle_type_of_card_le_mem_cycle_type_add_two dec_trivial ng,
multiset.map_singleton, multiset.prod_singleton],
dec_trivial },
{ -- If `n = 5`, then `g` is itself a 5-cycle, conjugate to `fin_rotate 5`.
refine (is_conj_iff_cycle_type_eq.2 _).normal_closure_eq_top_of
normal_closure_fin_rotate_five,
rw [cycle_type_of_card_le_mem_cycle_type_add_two dec_trivial ng, cycle_type_fin_rotate] }
end⟩
end alternating_group
|
dbdca23501fb44bf2d2b40191104f1ee3fd22ccb
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/measure_theory/integral/bochner.lean
|
5db105492850fa698114a97b101c0732ec17298b
|
[
"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
| 67,204
|
lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import measure_theory.integral.set_to_l1
import measure_theory.group.basic
import analysis.normed_space.bounded_linear_maps
import topology.sequences
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `set_to_L1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weighted_smul μ s x = (μ s).to_real * x`.
`weighted_smul μ` is shown to be linear in the value `x` and `dominated_fin_meas_additive`
(defined in the file `set_to_L1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `simple_func α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `simple_func.integral` for details.)
3. Transfer this definition to define the integral on `L1.simple_func α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simple_func.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `continuous_linear_map.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`set_to_fun (dominated_fin_meas_additive_weighted_smul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `set_to_fun` (which are described in the
file `set_to_L1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `∥∫ x, f x ∂μ∥ ≤ ∫ x, ∥f x∥ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_max_sub_lintegral_min` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `set_integral`) integration commutes with continuous linear maps.
* `continuous_linear_map.integral_comp_comm`
* `linear_isometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `integrable.induction` in the file `simple_func_dense` (or one of
the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something
for an arbitrary measurable + integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_max_sub_lintegral_min` for a complicated example, which proves that
`∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_max_sub_lintegral_min` is
scattered in sections with the name `pos_part`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ennreal.to_real (∫⁻ a, ennreal.of_real $ ∥f a∥)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `is_closed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `simple_func` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `is_closed_property` or `dense_range.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `measure_theory/integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`measure_theory/lp_space`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `measure_theory/simple_func_dense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`measure_theory/set_integral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
noncomputable theory
open_locale classical topological_space big_operators nnreal ennreal measure_theory
open set filter topological_space ennreal emetric
local attribute [instance] fact_one_le_one_ennreal
namespace measure_theory
variables {α E F 𝕜 : Type*}
section weighted_smul
open continuous_linear_map
variables [normed_group F] [normed_space ℝ F] {m : measurable_space α} {μ : measure α}
/-- Given a set `s`, return the continuous linear map `λ x, (μ s).to_real • x`. The extension of
that set function through `set_to_L1` gives the Bochner integral of L1 functions. -/
def weighted_smul {m : measurable_space α} (μ : measure α) (s : set α) : F →L[ℝ] F :=
(μ s).to_real • (continuous_linear_map.id ℝ F)
lemma weighted_smul_apply {m : measurable_space α} (μ : measure α) (s : set α) (x : F) :
weighted_smul μ s x = (μ s).to_real • x :=
by simp [weighted_smul]
@[simp] lemma weighted_smul_zero_measure {m : measurable_space α} :
weighted_smul (0 : measure α) = (0 : set α → F →L[ℝ] F) :=
by { ext1, simp [weighted_smul], }
@[simp] lemma weighted_smul_empty {m : measurable_space α} (μ : measure α) :
weighted_smul μ ∅ = (0 : F →L[ℝ] F) :=
by { ext1 x, rw [weighted_smul_apply], simp, }
lemma weighted_smul_add_measure {m : measurable_space α} (μ ν : measure α) {s : set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weighted_smul (μ + ν) s : F →L[ℝ] F) = weighted_smul μ s + weighted_smul ν s :=
begin
ext1 x,
push_cast,
simp_rw [pi.add_apply, weighted_smul_apply],
push_cast,
rw [pi.add_apply, ennreal.to_real_add hμs hνs, add_smul],
end
lemma weighted_smul_congr (s t : set α) (hst : μ s = μ t) :
(weighted_smul μ s : F →L[ℝ] F) = weighted_smul μ t :=
by { ext1 x, simp_rw weighted_smul_apply, congr' 2, }
lemma weighted_smul_null {s : set α} (h_zero : μ s = 0) : (weighted_smul μ s : F →L[ℝ] F) = 0 :=
by { ext1 x, rw [weighted_smul_apply, h_zero], simp, }
lemma weighted_smul_union (s t : set α) (hs : measurable_set s) (ht : measurable_set t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weighted_smul μ (s ∪ t) : F →L[ℝ] F) = weighted_smul μ s + weighted_smul μ t :=
begin
ext1 x,
simp_rw [add_apply, weighted_smul_apply,
measure_union (set.disjoint_iff_inter_eq_empty.mpr h_inter) hs ht,
ennreal.to_real_add hs_finite ht_finite, add_smul],
end
lemma weighted_smul_smul [normed_field 𝕜] [normed_space 𝕜 F] [smul_comm_class ℝ 𝕜 F]
(c : 𝕜) (s : set α) (x : F) :
weighted_smul μ s (c • x) = c • weighted_smul μ s x :=
by { simp_rw [weighted_smul_apply, smul_comm], }
lemma norm_weighted_smul_le (s : set α) : ∥(weighted_smul μ s : F →L[ℝ] F)∥ ≤ (μ s).to_real :=
calc ∥(weighted_smul μ s : F →L[ℝ] F)∥ = ∥(μ s).to_real∥ * ∥continuous_linear_map.id ℝ F∥ :
norm_smul _ _
... ≤ ∥(μ s).to_real∥ : (mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le
... = abs (μ s).to_real : real.norm_eq_abs _
... = (μ s).to_real : abs_eq_self.mpr ennreal.to_real_nonneg
lemma dominated_fin_meas_additive_weighted_smul {m : measurable_space α} (μ : measure α) :
dominated_fin_meas_additive μ (weighted_smul μ : set α → F →L[ℝ] F) 1 :=
⟨weighted_smul_union, λ s, (norm_weighted_smul_le s).trans (one_mul _).symm.le⟩
end weighted_smul
local infixr ` →ₛ `:25 := simple_func
namespace simple_func
section pos_part
variables [linear_order E] [has_zero E] [measurable_space α]
/-- Positive part of a simple function. -/
def pos_part (f : α →ₛ E) : α →ₛ E := f.map (λ b, max b 0)
/-- Negative part of a simple function. -/
def neg_part [has_neg E] (f : α →ₛ E) : α →ₛ E := pos_part (-f)
lemma pos_part_map_norm (f : α →ₛ ℝ) : (pos_part f).map norm = pos_part f :=
by { ext, rw [map_apply, real.norm_eq_abs, abs_of_nonneg], exact le_max_right _ _ }
lemma neg_part_map_norm (f : α →ₛ ℝ) : (neg_part f).map norm = neg_part f :=
by { rw neg_part, exact pos_part_map_norm _ }
lemma pos_part_sub_neg_part (f : α →ₛ ℝ) : f.pos_part - f.neg_part = f :=
begin
simp only [pos_part, neg_part],
ext a,
rw coe_sub,
exact max_zero_sub_eq_self (f a)
end
end pos_part
section integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open finset
variables [normed_group E] [measurable_space E] [normed_group F] [normed_space ℝ F] {p : ℝ≥0∞}
{G F' : Type*} [normed_group G] [normed_group F'] [normed_space ℝ F']
{m : measurable_space α} {μ : measure α}
/-- Bochner integral of simple functions whose codomain is a real `normed_space`.
This is equal to `∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x` (see `integral_eq`). -/
def integral {m : measurable_space α} (μ : measure α) (f : α →ₛ F) : F :=
f.set_to_simple_func (weighted_smul μ)
lemma integral_def {m : measurable_space α} (μ : measure α) (f : α →ₛ F) :
f.integral μ = f.set_to_simple_func (weighted_smul μ) := rfl
lemma integral_eq {m : measurable_space α} (μ : measure α) (f : α →ₛ F) :
f.integral μ = ∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x :=
by simp [integral, set_to_simple_func, weighted_smul_apply]
lemma integral_eq_sum_filter {m : measurable_space α} (f : α →ₛ F) (μ : measure α) :
f.integral μ = ∑ x in f.range.filter (λ x, x ≠ 0), (μ (f ⁻¹' {x})).to_real • x :=
by { rw [integral_def, set_to_simple_func_eq_sum_filter], simp_rw weighted_smul_apply, }
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
lemma integral_eq_sum_of_subset {f : α →ₛ F} {s : finset F}
(hs : f.range.filter (λ x, x ≠ 0) ⊆ s) : f.integral μ = ∑ x in s, (μ (f ⁻¹' {x})).to_real • x :=
begin
rw [simple_func.integral_eq_sum_filter, finset.sum_subset hs],
rintro x - hx, rw [finset.mem_filter, not_and_distrib, ne.def, not_not] at hx,
rcases hx with hx|rfl; [skip, simp],
rw [simple_func.mem_range] at hx, rw [preimage_eq_empty]; simp [set.disjoint_singleton_left, hx]
end
@[simp] lemma integral_const {m : measurable_space α} (μ : measure α) (y : F) :
(const α y).integral μ = (μ univ).to_real • y :=
calc (const α y).integral μ = ∑ z in {y}, (μ ((const α y) ⁻¹' {z})).to_real • z :
integral_eq_sum_of_subset $ (filter_subset _ _).trans (range_const_subset _ _)
... = (μ univ).to_real • y : by simp
@[simp] lemma integral_piecewise_zero {m : measurable_space α} (f : α →ₛ F) (μ : measure α)
{s : set α} (hs : measurable_set s) :
(piecewise s hs f 0).integral μ = f.integral (μ.restrict s) :=
begin
refine (integral_eq_sum_of_subset _).trans
((sum_congr rfl $ λ y hy, _).trans (integral_eq_sum_filter _ _).symm),
{ intros y hy,
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *,
rcases hy with ⟨⟨rfl, -⟩|⟨x, hxs, rfl⟩, h₀⟩,
exacts [(h₀ rfl).elim, ⟨set.mem_range_self _, h₀⟩] },
{ dsimp,
rw [indicator_preimage_of_not_mem, measure.restrict_apply (f.measurable_set_preimage _)],
exact λ h₀, (mem_filter.1 hy).2 (eq.symm h₀) }
end
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
lemma map_integral (f : α →ₛ E) (g : E → F) (hf : integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • (g x) :=
map_set_to_simple_func _ weighted_smul_union hf hg
/-- `simple_func.integral` and `simple_func.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
lemma integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ennreal.to_real ∘ g)).integral μ = ennreal.to_real (∫⁻ a, g (f a) ∂μ) :=
begin
have hf' : f.fin_meas_supp μ := integrable_iff_fin_meas_supp.1 hf,
simp only [← map_apply g f, lintegral_eq_lintegral],
rw [map_integral f _ hf, map_lintegral, ennreal.to_real_sum],
{ refine finset.sum_congr rfl (λb hb, _),
rw [smul_eq_mul, to_real_mul, mul_comm] },
{ assume a ha,
by_cases a0 : a = 0,
{ rw [a0, hg0, zero_mul], exact with_top.zero_ne_top },
{ apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne } },
{ simp [hg0] }
end
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E]
lemma integral_congr {f g : α →ₛ E} (hf : integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
set_to_simple_func_congr (weighted_smul μ) (λ s hs, weighted_smul_null) weighted_smul_union hf h
/-- `simple_func.bintegral` and `simple_func.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion. -/
lemma integral_eq_lintegral {f : α →ₛ ℝ} (hf : integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ennreal.to_real (∫⁻ a, ennreal.of_real (f a) ∂μ) :=
begin
have : f =ᵐ[μ] f.map (ennreal.to_real ∘ ennreal.of_real) :=
h_pos.mono (λ a h, (ennreal.to_real_of_real h).symm),
rw [← integral_eq_lintegral' hf],
exacts [integral_congr hf this, ennreal.of_real_zero, λ b, ennreal.of_real_ne_top]
end
lemma integral_add {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
set_to_simple_func_add _ weighted_smul_union hf hg
lemma integral_neg {f : α →ₛ E} (hf : integrable f μ) : integral μ (-f) = - integral μ f :=
set_to_simple_func_neg _ weighted_smul_union hf
lemma integral_sub {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
set_to_simple_func_sub _ weighted_smul_union hf hg
lemma integral_smul (c : 𝕜) {f : α →ₛ E} (hf : integrable f μ) :
integral μ (c • f) = c • integral μ f :=
set_to_simple_func_smul _ weighted_smul_union weighted_smul_smul c hf
lemma norm_set_to_simple_func_le_integral_norm (T : set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, ∥T s∥ ≤ C * (μ s).to_real) {f : α →ₛ E} (hf : integrable f μ) :
∥f.set_to_simple_func T∥ ≤ C * (f.map norm).integral μ :=
calc ∥f.set_to_simple_func T∥
≤ C * ∑ x in f.range, ennreal.to_real (μ (f ⁻¹' {x})) * ∥x∥ :
norm_set_to_simple_func_le_sum_mul_norm T hT_norm f
... = C * (f.map norm).integral μ : by { rw map_integral f norm hf norm_zero, simp_rw smul_eq_mul, }
lemma norm_integral_le_integral_norm (f : α →ₛ E) (hf : integrable f μ) :
∥f.integral μ∥ ≤ (f.map norm).integral μ :=
begin
refine (norm_set_to_simple_func_le_integral_norm _ (λ s, _) hf).trans (one_mul _).le,
exact (norm_weighted_smul_le s).trans (one_mul _).symm.le,
end
lemma integral_add_measure {ν} (f : α →ₛ E) (hf : integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν :=
begin
simp_rw [integral_def],
refine set_to_simple_func_add_left' (weighted_smul μ) (weighted_smul ν) (weighted_smul (μ + ν))
(λ s hs hμνs, _) hf,
rw [measure.coe_add, pi.add_apply, ennreal.add_ne_top] at hμνs,
rw weighted_smul_add_measure _ _ hμνs.1 hμνs.2,
end
end integral
end simple_func
namespace L1
open ae_eq_fun Lp.simple_func Lp
variables
[normed_group E] [second_countable_topology E] [measurable_space E] [borel_space E]
[normed_group F] [second_countable_topology F] [measurable_space F] [borel_space F]
{m : measurable_space α} {μ : measure α}
variables {α E μ}
namespace simple_func
lemma norm_eq_integral (f : α →₁ₛ[μ] E) : ∥f∥ = ((to_simple_func f).map norm).integral μ :=
begin
rw [norm_eq_sum_mul f, (to_simple_func f).map_integral norm (simple_func.integrable f) norm_zero],
simp_rw smul_eq_mul,
end
section pos_part
/-- Positive part of a simple function in L1 space. -/
def pos_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.pos_part (f : α →₁[μ] ℝ),
begin
rcases f with ⟨f, s, hsf⟩,
use s.pos_part,
simp only [subtype.coe_mk, Lp.coe_pos_part, ← hsf, ae_eq_fun.pos_part_mk, simple_func.pos_part,
simple_func.coe_map]
end ⟩
/-- Negative part of a simple function in L1 space. -/
def neg_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : α →₁ₛ[μ] ℝ) : (pos_part f : α →₁[μ] ℝ) = Lp.pos_part (f : α →₁[μ] ℝ) := rfl
@[norm_cast]
lemma coe_neg_part (f : α →₁ₛ[μ] ℝ) : (neg_part f : α →₁[μ] ℝ) = Lp.neg_part (f : α →₁[μ] ℝ) := rfl
end pos_part
section simple_func_integral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E]
{F' : Type*} [normed_group F'] [normed_space ℝ F']
local attribute [instance] simple_func.normed_space
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E := ((to_simple_func f)).integral μ
lemma integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = ((to_simple_func f)).integral μ := rfl
lemma integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] (to_simple_func f)) :
integral f = ennreal.to_real (∫⁻ a, ennreal.of_real ((to_simple_func f) a) ∂μ) :=
by rw [integral, simple_func.integral_eq_lintegral (simple_func.integrable f) h_pos]
lemma integral_eq_set_to_L1s (f : α →₁ₛ[μ] E) : integral f = set_to_L1s (weighted_smul μ) f := rfl
lemma integral_congr {f g : α →₁ₛ[μ] E} (h : to_simple_func f =ᵐ[μ] to_simple_func g) :
integral f = integral g :=
simple_func.integral_congr (simple_func.integrable f) h
lemma integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
set_to_L1s_add _ (λ _ _, weighted_smul_null) weighted_smul_union _ _
lemma integral_smul [measurable_space 𝕜] [opens_measurable_space 𝕜] (c : 𝕜) (f : α →₁ₛ[μ] E) :
integral (c • f) = c • integral f :=
set_to_L1s_smul _ (λ _ _, weighted_smul_null) weighted_smul_union weighted_smul_smul c f
lemma norm_integral_le_norm (f : α →₁ₛ[μ] E) : ∥integral f∥ ≤ ∥f∥ :=
begin
rw [integral, norm_eq_integral],
exact (to_simple_func f).norm_integral_le_integral_norm (simple_func.integrable f)
end
variables {E' : Type*} [normed_group E'] [second_countable_topology E'] [measurable_space E']
[borel_space E'] [normed_space ℝ E'] [normed_space 𝕜 E']
[measurable_space 𝕜] [opens_measurable_space 𝕜]
variables (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integral_clm' : (α →₁ₛ[μ] E) →L[𝕜] E :=
linear_map.mk_continuous ⟨integral, integral_add, integral_smul⟩
1 (λf, le_trans (norm_integral_le_norm _) $ by rw one_mul)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integral_clm : (α →₁ₛ[μ] E) →L[ℝ] E := integral_clm' α E ℝ μ
variables {α E μ 𝕜}
local notation `Integral` := integral_clm α E μ
open continuous_linear_map
lemma norm_Integral_le_one : ∥Integral∥ ≤ 1 :=
linear_map.mk_continuous_norm_le _ (zero_le_one) _
section pos_part
lemma pos_part_to_simple_func (f : α →₁ₛ[μ] ℝ) :
to_simple_func (pos_part f) =ᵐ[μ] (to_simple_func f).pos_part :=
begin
have eq : ∀ a, (to_simple_func f).pos_part a = max ((to_simple_func f) a) 0 := λa, rfl,
have ae_eq : ∀ᵐ a ∂μ, to_simple_func (pos_part f) a = max ((to_simple_func f) a) 0,
{ filter_upwards [to_simple_func_eq_to_fun (pos_part f), Lp.coe_fn_pos_part (f : α →₁[μ] ℝ),
to_simple_func_eq_to_fun f],
assume a h₁ h₂ h₃,
convert h₂ },
refine ae_eq.mono (assume a h, _),
rw [h, eq]
end
lemma neg_part_to_simple_func (f : α →₁ₛ[μ] ℝ) :
to_simple_func (neg_part f) =ᵐ[μ] (to_simple_func f).neg_part :=
begin
rw [simple_func.neg_part, measure_theory.simple_func.neg_part],
filter_upwards [pos_part_to_simple_func (-f), neg_to_simple_func f],
assume a h₁ h₂,
rw h₁,
show max _ _ = max _ _,
rw h₂,
refl
end
lemma integral_eq_norm_pos_part_sub (f : α →₁ₛ[μ] ℝ) :
integral f = ∥pos_part f∥ - ∥neg_part f∥ :=
begin
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq₁ : (to_simple_func f).pos_part =ᵐ[μ] (to_simple_func (pos_part f)).map norm,
{ filter_upwards [pos_part_to_simple_func f],
assume a h,
rw [simple_func.map_apply, h],
conv_lhs { rw [← simple_func.pos_part_map_norm, simple_func.map_apply] } },
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq₂ : (to_simple_func f).neg_part =ᵐ[μ] (to_simple_func (neg_part f)).map norm,
{ filter_upwards [neg_part_to_simple_func f],
assume a h,
rw [simple_func.map_apply, h],
conv_lhs { rw [← simple_func.neg_part_map_norm, simple_func.map_apply] } },
-- Convert things in `L¹` to their `simple_func` counterpart
have ae_eq : ∀ᵐ a ∂μ, (to_simple_func f).pos_part a - (to_simple_func f).neg_part a =
(to_simple_func (pos_part f)).map norm a - (to_simple_func (neg_part f)).map norm a,
{ filter_upwards [ae_eq₁, ae_eq₂],
assume a h₁ h₂,
rw [h₁, h₂] },
rw [integral, norm_eq_integral, norm_eq_integral, ← simple_func.integral_sub],
{ show (to_simple_func f).integral μ =
((to_simple_func (pos_part f)).map norm - (to_simple_func (neg_part f)).map norm).integral μ,
apply measure_theory.simple_func.integral_congr (simple_func.integrable f),
filter_upwards [ae_eq₁, ae_eq₂],
assume a h₁ h₂, show _ = _ - _,
rw [← h₁, ← h₂],
have := (to_simple_func f).pos_part_sub_neg_part,
conv_lhs {rw ← this},
refl },
{ exact (simple_func.integrable f).max_zero.congr ae_eq₁ },
{ exact (simple_func.integrable f).neg.max_zero.congr ae_eq₂ }
end
end pos_part
end simple_func_integral
end simple_func
open simple_func
local notation `Integral` := @integral_clm α E _ _ _ _ _ μ _
variables [normed_space ℝ E] [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E]
[smul_comm_class ℝ 𝕜 E] [normed_space ℝ F] [complete_space E]
section integration_in_L1
local attribute [instance] simple_func.normed_space
open continuous_linear_map
variables (𝕜) [measurable_space 𝕜] [opens_measurable_space 𝕜]
/-- The Bochner integral in L1 space as a continuous linear map. -/
def integral_clm' : (α →₁[μ] E) →L[𝕜] E :=
(integral_clm' α E 𝕜 μ).extend
(coe_to_Lp α E 𝕜) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing
variables {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integral_clm : (α →₁[μ] E) →L[ℝ] E := integral_clm' ℝ
/-- The Bochner integral in L1 space -/
def integral (f : α →₁[μ] E) : E := integral_clm f
lemma integral_eq (f : α →₁[μ] E) : integral f = integral_clm f := rfl
lemma integral_eq_set_to_L1 (f : α →₁[μ] E) :
integral f = set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f :=
rfl
@[norm_cast] lemma simple_func.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
integral (f : α →₁[μ] E) = (simple_func.integral f) :=
set_to_L1_eq_set_to_L1s_clm (dominated_fin_meas_additive_weighted_smul μ) f
variables (α E)
@[simp] lemma integral_zero : integral (0 : α →₁[μ] E) = 0 :=
map_zero integral_clm
variables {α E}
lemma integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g :=
map_add integral_clm f g
lemma integral_neg (f : α →₁[μ] E) : integral (-f) = - integral f :=
map_neg integral_clm f
lemma integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g :=
map_sub integral_clm f g
lemma integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f :=
map_smul (integral_clm' 𝕜) c f
local notation `Integral` := @integral_clm α E _ _ _ _ _ μ _ _
local notation `sIntegral` := @simple_func.integral_clm α E _ _ _ _ _ μ _
lemma norm_Integral_le_one : ∥Integral∥ ≤ 1 :=
calc ∥Integral∥ ≤ (1 : ℝ≥0) * ∥sIntegral∥ :
op_norm_extend_le _ _ _ $ λs, by {rw [nnreal.coe_one, one_mul], refl}
... = ∥sIntegral∥ : one_mul _
... ≤ 1 : norm_Integral_le_one
lemma norm_integral_le (f : α →₁[μ] E) : ∥integral f∥ ≤ ∥f∥ :=
calc ∥integral f∥ = ∥Integral f∥ : rfl
... ≤ ∥Integral∥ * ∥f∥ : le_op_norm _ _
... ≤ 1 * ∥f∥ : mul_le_mul_of_nonneg_right norm_Integral_le_one $ norm_nonneg _
... = ∥f∥ : one_mul _
@[continuity]
lemma continuous_integral : continuous (λ (f : α →₁[μ] E), integral f) :=
L1.integral_clm.continuous
section pos_part
local attribute [instance] fact_one_le_one_ennreal
lemma integral_eq_norm_pos_part_sub (f : α →₁[μ] ℝ) :
integral f = ∥Lp.pos_part f∥ - ∥Lp.neg_part f∥ :=
begin
-- Use `is_closed_property` and `is_closed_eq`
refine @is_closed_property _ _ _ (coe : (α →₁ₛ[μ] ℝ) → (α →₁[μ] ℝ))
(λ f : α →₁[μ] ℝ, integral f = ∥Lp.pos_part f∥ - ∥Lp.neg_part f∥)
(simple_func.dense_range one_ne_top) (is_closed_eq _ _) _ f,
{ exact cont _ },
{ refine continuous.sub (continuous_norm.comp Lp.continuous_pos_part)
(continuous_norm.comp Lp.continuous_neg_part) },
-- Show that the property holds for all simple functions in the `L¹` space.
{ assume s,
norm_cast,
exact simple_func.integral_eq_norm_pos_part_sub _ }
end
end pos_part
end integration_in_L1
end L1
/-!
### The Bochner integral on functions
Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable
functions, and 0 otherwise; prove its basic properties.
-/
variables [normed_group E] [second_countable_topology E] [normed_space ℝ E] [complete_space E]
[measurable_space E] [borel_space E]
[nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [smul_comm_class ℝ 𝕜 E]
[normed_group F] [second_countable_topology F] [normed_space ℝ F] [complete_space F]
[measurable_space F] [borel_space F]
/-- The Bochner integral -/
def integral {m : measurable_space α} (μ : measure α) (f : α → E) : E :=
if hf : integrable f μ then L1.integral (hf.to_L1 f) else 0
/-! In the notation for integrals, an expression like `∫ x, g ∥x∥ ∂μ` will not be parsed correctly,
and needs parentheses. We do not set the binding power of `r` to `0`, because then
`∫ x, f x = 0` will be parsed incorrectly. -/
notation `∫` binders `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral μ r
notation `∫` binders `, ` r:(scoped:60 f, integral volume f) := r
notation `∫` binders ` in ` s `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral (measure.restrict μ s) r
notation `∫` binders ` in ` s `, ` r:(scoped:60 f, integral (measure.restrict volume s) f) := r
section properties
open continuous_linear_map measure_theory.simple_func
variables {f g : α → E} {m : measurable_space α} {μ : measure α}
lemma integral_eq (f : α → E) (hf : integrable f μ) :
∫ a, f a ∂μ = L1.integral (hf.to_L1 f) :=
dif_pos hf
lemma integral_eq_set_to_fun (f : α → E) :
∫ a, f a ∂μ = set_to_fun (dominated_fin_meas_additive_weighted_smul μ) f :=
rfl
lemma L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ :=
(L1.set_to_fun_eq_set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f).symm
lemma integral_undef (h : ¬ integrable f μ) : ∫ a, f a ∂μ = 0 :=
dif_neg h
lemma integral_non_ae_measurable (h : ¬ ae_measurable f μ) : ∫ a, f a ∂μ = 0 :=
integral_undef $ not_and_of_not_left _ h
variables (α E)
lemma integral_zero : ∫ a : α, (0:E) ∂μ = 0 :=
set_to_fun_zero (dominated_fin_meas_additive_weighted_smul μ)
@[simp] lemma integral_zero' : integral μ (0 : α → E) = 0 :=
integral_zero α E
variables {α E}
lemma integral_add (hf : integrable f μ) (hg : integrable g μ) :
∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
set_to_fun_add (dominated_fin_meas_additive_weighted_smul μ) hf hg
lemma integral_add' (hf : integrable f μ) (hg : integrable g μ) :
∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ :=
integral_add hf hg
lemma integral_neg (f : α → E) : ∫ a, -f a ∂μ = - ∫ a, f a ∂μ :=
set_to_fun_neg (dominated_fin_meas_additive_weighted_smul μ) f
lemma integral_neg' (f : α → E) : ∫ a, (-f) a ∂μ = - ∫ a, f a ∂μ :=
integral_neg f
lemma integral_sub (hf : integrable f μ) (hg : integrable g μ) :
∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
set_to_fun_sub (dominated_fin_meas_additive_weighted_smul μ) hf hg
lemma integral_sub' (hf : integrable f μ) (hg : integrable g μ) :
∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ :=
integral_sub hf hg
lemma integral_smul [measurable_space 𝕜] [opens_measurable_space 𝕜] (c : 𝕜) (f : α → E) :
∫ a, c • (f a) ∂μ = c • ∫ a, f a ∂μ :=
set_to_fun_smul (dominated_fin_meas_additive_weighted_smul μ) weighted_smul_smul c f
lemma integral_mul_left (r : ℝ) (f : α → ℝ) : ∫ a, r * (f a) ∂μ = r * ∫ a, f a ∂μ :=
integral_smul r f
lemma integral_mul_right (r : ℝ) (f : α → ℝ) : ∫ a, (f a) * r ∂μ = ∫ a, f a ∂μ * r :=
by { simp only [mul_comm], exact integral_mul_left r f }
lemma integral_div (r : ℝ) (f : α → ℝ) : ∫ a, (f a) / r ∂μ = ∫ a, f a ∂μ / r :=
integral_mul_right r⁻¹ f
lemma integral_congr_ae (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ :=
set_to_fun_congr_ae (dominated_fin_meas_additive_weighted_smul μ) h
@[simp] lemma L1.integral_of_fun_eq_integral {f : α → E} (hf : integrable f μ) :
∫ a, (hf.to_L1 f) a ∂μ = ∫ a, f a ∂μ :=
integral_congr_ae $ by simp [integrable.coe_fn_to_L1]
@[continuity]
lemma continuous_integral : continuous (λ (f : α →₁[μ] E), ∫ a, f a ∂μ) :=
by { simp only [← L1.integral_eq_integral], exact L1.continuous_integral }
lemma norm_integral_le_lintegral_norm (f : α → E) :
∥∫ a, f a ∂μ∥ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :=
begin
by_cases hf : integrable f μ,
{ rw [integral_eq f hf, ← integrable.norm_to_L1_eq_lintegral_norm f hf],
exact L1.norm_integral_le _ },
{ rw [integral_undef hf, norm_zero], exact to_real_nonneg }
end
lemma ennnorm_integral_le_lintegral_ennnorm (f : α → E) :
(nnnorm (∫ a, f a ∂μ) : ℝ≥0∞) ≤ ∫⁻ a, (nnnorm (f a)) ∂μ :=
by { simp_rw [← of_real_norm_eq_coe_nnnorm], apply ennreal.of_real_le_of_le_to_real,
exact norm_integral_le_lintegral_norm f }
lemma integral_eq_zero_of_ae {f : α → E} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 :=
by simp [integral_congr_ae hf, integral_zero]
/-- If `f` has finite integral, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
lemma has_finite_integral.tendsto_set_integral_nhds_zero {ι} {f : α → E}
(hf : has_finite_integral f μ) {l : filter ι} {s : ι → set α}
(hs : tendsto (μ ∘ s) l (𝓝 0)) :
tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) :=
begin
rw [tendsto_zero_iff_norm_tendsto_zero],
simp_rw [← coe_nnnorm, ← nnreal.coe_zero, nnreal.tendsto_coe, ← ennreal.tendsto_coe,
ennreal.coe_zero],
exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_set_lintegral_zero (ne_of_lt hf) hs) (λ i, zero_le _)
(λ i, ennnorm_integral_le_lintegral_ennnorm _)
end
/-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends
to zero as `μ s` tends to zero. -/
lemma integrable.tendsto_set_integral_nhds_zero {ι} {f : α → E}
(hf : integrable f μ) {l : filter ι} {s : ι → set α} (hs : tendsto (μ ∘ s) l (𝓝 0)) :
tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) :=
hf.2.tendsto_set_integral_nhds_zero hs
/-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x∂μ`. -/
lemma tendsto_integral_of_L1 {ι} (f : α → E) (hfi : integrable f μ)
{F : ι → α → E} {l : filter ι} (hFi : ∀ᶠ i in l, integrable (F i) μ)
(hF : tendsto (λ i, ∫⁻ x, ∥F i x - f x∥₊ ∂μ) l (𝓝 0)) :
tendsto (λ i, ∫ x, F i x ∂μ) l (𝓝 $ ∫ x, f x ∂μ) :=
begin
rw [tendsto_iff_norm_tendsto_zero],
replace hF : tendsto (λ i, ennreal.to_real $ ∫⁻ x, ∥F i x - f x∥₊ ∂μ) l (𝓝 0) :=
(ennreal.tendsto_to_real zero_ne_top).comp hF,
refine squeeze_zero_norm' (hFi.mp $ hFi.mono $ λ i hFi hFm, _) hF,
simp only [norm_norm, ← integral_sub hFi hfi],
convert norm_integral_le_lintegral_norm (λ x, F i x - f x),
ext1 x,
exact coe_nnreal_eq _
end
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their integrals. -/
theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(F_measurable : ∀ n, ae_measurable (F n) μ)
(f_measurable : ae_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, F n a ∂μ) at_top (𝓝 $ ∫ a, f a ∂μ) :=
begin
/- To show `(∫ a, F n a) --> (∫ f)`, suffices to show `∥∫ a, F n a - ∫ f∥ --> 0` -/
rw tendsto_iff_norm_tendsto_zero,
/- But `0 ≤ ∥∫ a, F n a - ∫ f∥ = ∥∫ a, (F n a - f a) ∥ ≤ ∫ a, ∥F n a - f a∥, and thus we apply the
sandwich theorem and prove that `∫ a, ∥F n a - f a∥ --> 0` -/
have lintegral_norm_tendsto_zero :
tendsto (λn, ennreal.to_real $ ∫⁻ a, (ennreal.of_real ∥F n a - f a∥) ∂μ) at_top (𝓝 0) :=
(tendsto_to_real zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence
F_measurable f_measurable bound_integrable.has_finite_integral h_bound h_lim),
-- Use the sandwich theorem
refine squeeze_zero (λ n, norm_nonneg _) _ lintegral_norm_tendsto_zero,
-- Show `∥∫ a, F n a - ∫ f∥ ≤ ∫ a, ∥F n a - f a∥` for all `n`
{ assume n,
have h₁ : integrable (F n) μ := bound_integrable.mono' (F_measurable n) (h_bound _),
have h₂ : integrable f μ :=
⟨f_measurable, has_finite_integral_of_dominated_convergence
bound_integrable.has_finite_integral h_bound h_lim⟩,
rw ← integral_sub h₁ h₂,
exact norm_integral_le_lintegral_norm _ }
end
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
lemma tendsto_integral_filter_of_dominated_convergence {ι} {l : filter ι}
{F : ι → α → E} {f : α → E} (bound : α → ℝ)
(hl_cb : l.is_countably_generated)
(hF_meas : ∀ᶠ n in l, ae_measurable (F n) μ)
(f_measurable : ae_measurable f μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ∥F n a∥ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) l (𝓝 (f a))) :
tendsto (λn, ∫ a, F n a ∂μ) l (𝓝 $ ∫ a, f a ∂μ) :=
begin
rw hl_cb.tendsto_iff_seq_tendsto,
{ intros x xl,
have hxl, { rw tendsto_at_top' at xl, exact xl },
have h := inter_mem hF_meas h_bound,
replace h := hxl _ h,
rcases h with ⟨k, h⟩,
rw ← tendsto_add_at_top_iff_nat k,
refine tendsto_integral_of_dominated_convergence _ _ _ _ _ _,
{ exact bound },
{ intro, refine (h _ _).1, exact nat.le_add_left _ _ },
{ assumption },
{ assumption },
{ intro, refine (h _ _).2, exact nat.le_add_left _ _ },
{ filter_upwards [h_lim],
assume a h_lim,
apply @tendsto.comp _ _ _ (λn, x (n + k)) (λn, F n a),
{ assumption },
rw tendsto_add_at_top_iff_nat,
assumption } },
end
variables {X : Type*} [topological_space X] [first_countable_topology X]
lemma continuous_at_of_dominated {F : X → α → E} {x₀ : X} {bound : α → ℝ}
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ∥F x a∥ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_at (λ x, F x a) x₀) :
continuous_at (λ x, ∫ a, F x a ∂μ) x₀ :=
tendsto_integral_filter_of_dominated_convergence bound
(first_countable_topology.nhds_generated_countable x₀) ‹_›
(mem_of_mem_nhds hF_meas : _) ‹_› ‹_› ‹_›
lemma continuous_of_dominated {F : X → α → E} {bound : α → ℝ}
(hF_meas : ∀ x, ae_measurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ∥F x a∥ ≤ bound a)
(bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous (λ x, F x a)) :
continuous (λ x, ∫ a, F x a ∂μ) :=
continuous_iff_continuous_at.mpr (λ x₀, continuous_at_of_dominated (eventually_of_forall hF_meas)
(eventually_of_forall h_bound) ‹_› $ h_cont.mono $ λ _, continuous.continuous_at)
/-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the
integral of the positive part of `f` and the integral of the negative part of `f`. -/
lemma integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : integrable f μ) :
∫ a, f a ∂μ =
ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) -
ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) :=
let f₁ := hf.to_L1 f in
-- Go to the `L¹` space
have eq₁ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) = ∥Lp.pos_part f₁∥ :=
begin
rw L1.norm_def,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [Lp.coe_fn_pos_part f₁, hf.coe_fn_to_L1],
assume a h₁ h₂,
rw [h₁, h₂, ennreal.of_real],
congr' 1,
apply nnreal.eq,
simp [real.norm_of_nonneg, le_max_right, real.coe_to_nnreal]
end,
-- Go to the `L¹` space
have eq₂ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) = ∥Lp.neg_part f₁∥ :=
begin
rw L1.norm_def,
congr' 1,
apply lintegral_congr_ae,
filter_upwards [Lp.coe_fn_neg_part f₁, hf.coe_fn_to_L1],
assume a h₁ h₂,
rw [h₁, h₂, ennreal.of_real],
congr' 1,
apply nnreal.eq,
simp only [real.norm_of_nonneg, min_le_right, neg_nonneg, real.coe_to_nnreal', subtype.coe_mk],
rw [← max_neg_neg, coe_nnnorm, neg_zero, real.norm_of_nonneg (le_max_right (-f a) 0)]
end,
begin
rw [eq₁, eq₂, integral, dif_pos],
exact L1.integral_eq_norm_pos_part_sub _
end
lemma integral_eq_lintegral_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfm : ae_measurable f μ) :
∫ a, f a ∂μ = ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) :=
begin
by_cases hfi : integrable f μ,
{ rw integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi,
have h_min : ∫⁻ a, ennreal.of_real (-f a) ∂μ = 0,
{ rw lintegral_eq_zero_iff',
{ refine hf.mono _,
simp only [pi.zero_apply],
assume a h,
simp only [h, neg_nonpos, of_real_eq_zero], },
{ exact measurable_of_real.comp_ae_measurable hfm.neg } },
rw [h_min, zero_to_real, _root_.sub_zero] },
{ rw integral_undef hfi,
simp_rw [integrable, hfm, has_finite_integral_iff_norm, lt_top_iff_ne_top, ne.def, true_and,
not_not] at hfi,
have : ∫⁻ (a : α), ennreal.of_real (f a) ∂μ = ∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ,
{ refine lintegral_congr_ae (hf.mono $ assume a h, _),
rw [real.norm_eq_abs, abs_of_nonneg h] },
rw [this, hfi], refl }
end
lemma of_real_integral_norm_eq_lintegral_nnnorm {G} [normed_group G] [measurable_space G]
[opens_measurable_space G] {f : α → G} (hf : integrable f μ) :
ennreal.of_real ∫ x, ∥f x∥ ∂μ = ∫⁻ x, ∥f x∥₊ ∂μ :=
begin
rw integral_eq_lintegral_of_nonneg_ae _ hf.1.norm,
{ simp_rw [of_real_norm_eq_coe_nnnorm, ennreal.of_real_to_real (lt_top_iff_ne_top.mp hf.2)], },
{ refine ae_of_all _ _, simp, },
end
lemma integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : integrable f μ) :
∫ a, f a ∂μ = (∫ a, real.to_nnreal (f a) ∂μ) - (∫ a, real.to_nnreal (-f a) ∂μ) :=
begin
rw [← integral_sub hf.real_to_nnreal],
{ simp },
{ exact hf.neg.real_to_nnreal }
end
lemma integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ :=
begin
by_cases hfm : ae_measurable f μ,
{ rw integral_eq_lintegral_of_nonneg_ae hf hfm, exact to_real_nonneg },
{ rw integral_non_ae_measurable hfm }
end
lemma lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : integrable (λ x, (f x : ℝ)) μ) :
∫⁻ a, f a ∂μ = ennreal.of_real ∫ a, f a ∂μ :=
begin
simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (λ x, (f x).coe_nonneg))
hfi.ae_measurable, ← ennreal.coe_nnreal_eq], rw [ennreal.of_real_to_real],
rw [← lt_top_iff_ne_top], convert hfi.has_finite_integral, ext1 x, rw [nnreal.nnnorm_eq]
end
lemma integral_to_real {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) :
∫ a, (f a).to_real ∂μ = (∫⁻ a, f a ∂μ).to_real :=
begin
rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_to_real],
{ rw lintegral_congr_ae, refine hf.mp (eventually_of_forall _),
intros x hx, rw [lt_top_iff_ne_top] at hx, simp [hx] },
{ exact (eventually_of_forall $ λ x, ennreal.to_real_nonneg) }
end
lemma lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : integrable (λ x, (f x : ℝ)) μ)
{b : ℝ≥0} :
∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b :=
by rw [lintegral_coe_eq_integral f hfi, ennreal.of_real, ennreal.coe_le_coe,
real.to_nnreal_le_iff_le_coe]
lemma integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) :
∫ a, (f a : ℝ) ∂μ ≤ b :=
begin
by_cases hf : integrable (λ a, (f a : ℝ)) μ,
{ exact (lintegral_coe_le_coe_iff_integral_le hf).1 h },
{ rw integral_undef hf, exact b.2 }
end
lemma integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ :=
integral_nonneg_of_ae $ eventually_of_forall hf
lemma integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 :=
begin
have hf : 0 ≤ᵐ[μ] (-f) := hf.mono (assume a h, by rwa [pi.neg_apply, pi.zero_apply, neg_nonneg]),
have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf,
rwa [integral_neg, neg_nonneg] at this,
end
lemma integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 :=
integral_nonpos_of_ae $ eventually_of_forall hf
lemma integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
by simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ennreal.to_real_eq_zero_iff,
lintegral_eq_zero_iff' (ennreal.measurable_of_real.comp_ae_measurable hfi.1),
← ennreal.not_lt_top, ← has_finite_integral_iff_of_real hf, hfi.2, not_true, or_false,
← hf.le_iff_eq, filter.eventually_eq, filter.eventually_le, (∘), pi.zero_apply,
ennreal.of_real_eq_zero]
lemma integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) :
∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 :=
integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi
lemma integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) :=
by simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, ne.def, @eq_comm ℝ 0,
integral_eq_zero_iff_of_nonneg_ae hf hfi, filter.eventually_eq, ae_iff, pi.zero_apply,
function.support]
lemma integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) :
(0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) :=
integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi
section normed_group
variables {H : Type*} [normed_group H] [second_countable_topology H] [measurable_space H]
[borel_space H]
lemma L1.norm_eq_integral_norm (f : α →₁[μ] H) : ∥f∥ = ∫ a, ∥f a∥ ∂μ :=
begin
simp only [snorm, snorm', ennreal.one_to_real, ennreal.rpow_one, Lp.norm_def,
if_false, ennreal.one_ne_top, one_ne_zero, _root_.div_one],
rw integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg]))
(continuous_norm.measurable.comp_ae_measurable (Lp.ae_measurable f)),
simp [of_real_norm_eq_coe_nnnorm]
end
lemma L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : integrable f μ) :
∥hf.to_L1 f∥ = ∫ a, ∥f a∥ ∂μ :=
begin
rw L1.norm_eq_integral_norm,
refine integral_congr_ae _,
apply hf.coe_fn_to_L1.mono,
intros a ha,
simp [ha]
end
end normed_group
lemma integral_mono_ae {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ᵐ[μ] g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
le_of_sub_nonneg $ integral_sub hg hf ▸ integral_nonneg_of_ae $ h.mono (λ a, sub_nonneg_of_le)
@[mono] lemma integral_mono {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ g) :
∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
integral_mono_ae hf hg $ eventually_of_forall h
lemma integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : integrable g μ)
(h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ :=
begin
by_cases hfm : ae_measurable f μ,
{ refine integral_mono_ae ⟨hfm, _⟩ hgi h,
refine (hgi.has_finite_integral.mono $ h.mp $ hf.mono $ λ x hf hfg, _),
simpa [real.norm_eq_abs, abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)] },
{ rw [integral_non_ae_measurable hfm],
exact integral_nonneg_of_ae (hf.trans h) }
end
lemma norm_integral_le_integral_norm (f : α → E) : ∥(∫ a, f a ∂μ)∥ ≤ ∫ a, ∥f a∥ ∂μ :=
have le_ae : ∀ᵐ a ∂μ, 0 ≤ ∥f a∥ := eventually_of_forall (λa, norm_nonneg _),
classical.by_cases
( λh : ae_measurable f μ,
calc ∥∫ a, f a ∂μ∥ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ∥f a∥) ∂μ) :
norm_integral_le_lintegral_norm _
... = ∫ a, ∥f a∥ ∂μ : (integral_eq_lintegral_of_nonneg_ae le_ae $ ae_measurable.norm h).symm )
( λh : ¬ae_measurable f μ,
begin
rw [integral_non_ae_measurable h, norm_zero],
exact integral_nonneg_of_ae le_ae
end )
lemma norm_integral_le_of_norm_le {f : α → E} {g : α → ℝ} (hg : integrable g μ)
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ g x) : ∥∫ x, f x ∂μ∥ ≤ ∫ x, g x ∂μ :=
calc ∥∫ x, f x ∂μ∥ ≤ ∫ x, ∥f x∥ ∂μ : norm_integral_le_integral_norm f
... ≤ ∫ x, g x ∂μ :
integral_mono_of_nonneg (eventually_of_forall $ λ x, norm_nonneg _) hg h
lemma integral_finset_sum {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i, integrable (f i) μ) :
∫ a, ∑ i in s, f i a ∂μ = ∑ i in s, ∫ a, f i a ∂μ :=
begin
refine finset.induction_on s _ _,
{ simp only [integral_zero, finset.sum_empty] },
{ assume i s his ih,
simp only [his, finset.sum_insert, not_false_iff],
rw [integral_add (hf _) (integrable_finset_sum s hf), ih] }
end
lemma simple_func.integral_eq_integral (f : α →ₛ E) (hfi : integrable f μ) :
f.integral μ = ∫ x, f x ∂μ :=
begin
rw [integral_eq f hfi, ← L1.simple_func.to_Lp_one_eq_to_L1,
L1.simple_func.integral_L1_eq_integral, L1.simple_func.integral_eq_integral],
exact simple_func.integral_congr hfi (Lp.simple_func.to_simple_func_to_Lp _ _).symm
end
lemma simple_func.integral_eq_sum (f : α →ₛ E) (hfi : integrable f μ) :
∫ x, f x ∂μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • x :=
by { rw [← f.integral_eq_integral hfi, simple_func.integral, ← simple_func.integral_eq], refl, }
@[simp] lemma integral_const (c : E) : ∫ x : α, c ∂μ = (μ univ).to_real • c :=
begin
cases (@le_top _ _ (μ univ)).lt_or_eq with hμ hμ,
{ haveI : is_finite_measure μ := ⟨hμ⟩,
calc ∫ x : α, c ∂μ = (simple_func.const α c).integral μ :
((simple_func.const α c).integral_eq_integral (integrable_const _)).symm
... = _ : simple_func.integral_const _ _ },
{ by_cases hc : c = 0,
{ simp [hc, integral_zero] },
{ have : ¬integrable (λ x : α, c) μ,
{ simp only [integrable_const_iff, not_or_distrib],
exact ⟨hc, hμ.not_lt⟩ },
simp [integral_undef, *] } }
end
lemma norm_integral_le_of_norm_le_const [is_finite_measure μ] {f : α → E} {C : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
∥∫ x, f x ∂μ∥ ≤ C * (μ univ).to_real :=
calc ∥∫ x, f x ∂μ∥ ≤ ∫ x, C ∂μ : norm_integral_le_of_norm_le (integrable_const C) h
... = C * (μ univ).to_real : by rw [integral_const, smul_eq_mul, mul_comm]
lemma tendsto_integral_approx_on_univ_of_measurable
{f : α → E} (fmeas : measurable f) (hf : integrable f μ) :
tendsto (λ n, (simple_func.approx_on f fmeas univ 0 trivial n).integral μ) at_top
(𝓝 $ ∫ x, f x ∂μ) :=
begin
have : tendsto (λ n, ∫ x, simple_func.approx_on f fmeas univ 0 trivial n x ∂μ)
at_top (𝓝 $ ∫ x, f x ∂μ) :=
tendsto_integral_of_L1 _ hf
(eventually_of_forall $ simple_func.integrable_approx_on_univ fmeas hf)
(simple_func.tendsto_approx_on_univ_L1_nnnorm fmeas hf),
simpa only [simple_func.integral_eq_integral, simple_func.integrable_approx_on_univ fmeas hf]
end
variable {ν : measure α}
private lemma integral_add_measure_of_measurable
{f : α → E} (fmeas : measurable f) (hμ : integrable f μ) (hν : integrable f ν) :
∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν :=
begin
have hfi := hμ.add_measure hν,
refine tendsto_nhds_unique (tendsto_integral_approx_on_univ_of_measurable fmeas hfi) _,
simpa only [simple_func.integral_add_measure _
(simple_func.integrable_approx_on_univ fmeas hfi _)]
using (tendsto_integral_approx_on_univ_of_measurable fmeas hμ).add
(tendsto_integral_approx_on_univ_of_measurable fmeas hν)
end
lemma integral_add_measure {f : α → E} (hμ : integrable f μ) (hν : integrable f ν) :
∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν :=
begin
have h : ae_measurable f (μ + ν) := hμ.ae_measurable.add_measure hν.ae_measurable,
let g := h.mk f,
have A : f =ᵐ[μ + ν] g := h.ae_eq_mk,
have B : f =ᵐ[μ] g := A.filter_mono (ae_mono (measure.le_add_right (le_refl μ))),
have C : f =ᵐ[ν] g := A.filter_mono (ae_mono (measure.le_add_left (le_refl ν))),
calc ∫ x, f x ∂(μ + ν) = ∫ x, g x ∂(μ + ν) : integral_congr_ae A
... = ∫ x, g x ∂μ + ∫ x, g x ∂ν :
integral_add_measure_of_measurable h.measurable_mk ((integrable_congr B).1 hμ)
((integrable_congr C).1 hν)
... = ∫ x, f x ∂μ + ∫ x, f x ∂ν :
by { congr' 1, { exact integral_congr_ae B.symm }, { exact integral_congr_ae C.symm } }
end
@[simp] lemma integral_zero_measure {m : measurable_space α} (f : α → E) :
∫ x, f x ∂(0 : measure α) = 0 :=
norm_le_zero_iff.1 $ le_trans (norm_integral_le_lintegral_norm f) $ by simp
private lemma integral_smul_measure_aux {f : α → E} {c : ℝ≥0∞}
(h0 : c ≠ 0) (hc : c ≠ ∞) (fmeas : measurable f) (hfi : integrable f μ) :
∫ x, f x ∂(c • μ) = c.to_real • ∫ x, f x ∂μ :=
begin
refine tendsto_nhds_unique _
(tendsto_const_nhds.smul (tendsto_integral_approx_on_univ_of_measurable fmeas hfi)),
convert tendsto_integral_approx_on_univ_of_measurable fmeas (hfi.smul_measure hc),
simp only [simple_func.integral_eq, measure.smul_apply, finset.smul_sum, smul_smul,
ennreal.to_real_mul]
end
@[simp] lemma integral_smul_measure (f : α → E) (c : ℝ≥0∞) :
∫ x, f x ∂(c • μ) = c.to_real • ∫ x, f x ∂μ :=
begin
-- First we consider “degenerate” cases:
-- `c = 0`
rcases eq_or_ne c 0 with rfl|h0, { simp },
-- `f` is not almost everywhere measurable
by_cases hfm : ae_measurable f μ, swap,
{ have : ¬ (ae_measurable f (c • μ)), by simpa [h0] using hfm,
simp [integral_non_ae_measurable, hfm, this] },
-- `c = ∞`
rcases eq_or_ne c ∞ with rfl|hc,
{ rw [ennreal.top_to_real, zero_smul],
by_cases hf : f =ᵐ[μ] 0,
{ have : f =ᵐ[∞ • μ] 0 := ae_smul_measure hf ∞,
exact integral_eq_zero_of_ae this },
{ apply integral_undef,
rw [integrable, has_finite_integral, iff_true_intro (hfm.smul_measure ∞), true_and,
lintegral_smul_measure, top_mul, if_neg],
{ apply lt_irrefl },
{ rw [lintegral_eq_zero_iff' hfm.ennnorm],
refine λ h, hf (h.mono $ λ x, _),
simp } } },
-- `f` is not integrable and `0 < c < ∞`
by_cases hfi : integrable f μ, swap,
{ rw [integral_undef hfi, smul_zero],
refine integral_undef (mt (λ h, _) hfi),
convert h.smul_measure (ennreal.inv_ne_top.2 h0),
rw [smul_smul, ennreal.inv_mul_cancel h0 hc, one_smul] },
-- Main case: `0 < c < ∞`, `f` is almost everywhere measurable and integrable
let g := hfm.mk f,
calc ∫ x, f x ∂(c • μ) = ∫ x, g x ∂(c • μ) : integral_congr_ae $ ae_smul_measure hfm.ae_eq_mk c
... = c.to_real • ∫ x, g x ∂μ :
integral_smul_measure_aux h0 hc hfm.measurable_mk $ hfi.congr hfm.ae_eq_mk
... = c.to_real • ∫ x, f x ∂μ :
by { congr' 1, exact integral_congr_ae (hfm.ae_eq_mk.symm) }
end
lemma integral_map_of_measurable {β} [measurable_space β] {φ : α → β} (hφ : measurable φ)
{f : β → E} (hfm : measurable f) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
begin
by_cases hfi : integrable f (measure.map φ μ), swap,
{ rw [integral_undef hfi, integral_undef],
rwa [← integrable_map_measure hfm.ae_measurable hφ] },
refine tendsto_nhds_unique (tendsto_integral_approx_on_univ_of_measurable hfm hfi) _,
convert tendsto_integral_approx_on_univ_of_measurable (hfm.comp hφ)
((integrable_map_measure hfm.ae_measurable hφ).1 hfi),
ext1 i,
simp only [simple_func.approx_on_comp, simple_func.integral_eq, measure.map_apply, hφ,
simple_func.measurable_set_preimage, ← preimage_comp, simple_func.coe_comp],
refine (finset.sum_subset (simple_func.range_comp_subset_range _ hφ) (λ y _ hy, _)).symm,
rw [simple_func.mem_range, ← set.preimage_singleton_eq_empty, simple_func.coe_comp] at hy,
simp [hy]
end
lemma integral_map {β} [measurable_space β] {φ : α → β} (hφ : measurable φ)
{f : β → E} (hfm : ae_measurable f (measure.map φ μ)) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
let g := hfm.mk f in calc
∫ y, f y ∂(measure.map φ μ) = ∫ y, g y ∂(measure.map φ μ) : integral_congr_ae hfm.ae_eq_mk
... = ∫ x, g (φ x) ∂μ : integral_map_of_measurable hφ hfm.measurable_mk
... = ∫ x, f (φ x) ∂μ : integral_congr_ae $ ae_eq_comp hφ (hfm.ae_eq_mk).symm
lemma integral_map_of_closed_embedding {β} [topological_space α] [borel_space α]
[topological_space β] [measurable_space β] [borel_space β]
{φ : α → β} (hφ : closed_embedding φ) (f : β → E) :
∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ :=
begin
by_cases hfm : ae_measurable f (measure.map φ μ),
{ exact integral_map hφ.continuous.measurable hfm },
{ rw [integral_non_ae_measurable hfm, integral_non_ae_measurable],
rwa ae_measurable_comp_right_iff_of_closed_embedding hφ }
end
lemma integral_map_equiv {β} [measurable_space β] (e : α ≃ᵐ β) (f : β → E) :
∫ y, f y ∂(measure.map e μ) = ∫ x, f (e x) ∂μ :=
begin
by_cases hfm : ae_measurable f (measure.map e μ),
{ exact integral_map e.measurable hfm },
{ rw [integral_non_ae_measurable hfm, integral_non_ae_measurable],
rwa ← ae_measurable_map_equiv_iff }
end
lemma integral_dirac' [measurable_space α] (f : α → E) (a : α) (hfm : measurable f) :
∫ x, f x ∂(measure.dirac a) = f a :=
calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) :
integral_congr_ae $ ae_eq_dirac' hfm
... = f a : by simp [measure.dirac_apply_of_mem]
lemma integral_dirac [measurable_space α] [measurable_singleton_class α] (f : α → E) (a : α) :
∫ x, f x ∂(measure.dirac a) = f a :=
calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) :
integral_congr_ae $ ae_eq_dirac f
... = f a : by simp [measure.dirac_apply_of_mem]
end properties
section group
variables {G : Type*} [measurable_space G] [topological_space G] [group G] [has_continuous_mul G]
[borel_space G]
variables {μ : measure G}
open measure
/-- Translating a function by left-multiplication does not change its integral with respect to a
left-invariant measure. -/
@[to_additive]
lemma integral_mul_left_eq_self (hμ : is_mul_left_invariant μ) {f : G → E} (g : G) :
∫ x, f (g * x) ∂μ = ∫ x, f x ∂μ :=
begin
have hgμ : measure.map (has_mul.mul g) μ = μ,
{ rw ← map_mul_left_eq_self at hμ,
exact hμ g },
have h_mul : closed_embedding (λ x, g * x) := (homeomorph.mul_left g).closed_embedding,
rw [← integral_map_of_closed_embedding h_mul, hgμ],
apply_instance,
end
/-- Translating a function by right-multiplication does not change its integral with respect to a
right-invariant measure. -/
@[to_additive]
lemma integral_mul_right_eq_self (hμ : is_mul_right_invariant μ) {f : G → E} (g : G) :
∫ x, f (x * g) ∂μ = ∫ x, f x ∂μ :=
begin
have hgμ : measure.map (λ x, x * g) μ = μ,
{ rw ← map_mul_right_eq_self at hμ,
exact hμ g },
have h_mul : closed_embedding (λ x, x * g) := (homeomorph.mul_right g).closed_embedding,
rw [← integral_map_of_closed_embedding h_mul, hgμ],
apply_instance,
end
/-- If some left-translate of a function negates it, then the integral of the function with respect
to a left-invariant measure is 0. -/
@[to_additive]
lemma integral_zero_of_mul_left_eq_neg (hμ : is_mul_left_invariant μ) {f : G → E} {g : G}
(hf' : ∀ x, f (g * x) = - f x) :
∫ x, f x ∂μ = 0 :=
begin
refine eq_zero_of_eq_neg ℝ (eq.symm _),
have : ∫ x, f (g * x) ∂μ = ∫ x, - f x ∂μ,
{ congr,
ext x,
exact hf' x },
convert integral_mul_left_eq_self hμ g using 1,
rw [this, integral_neg]
end
/-- If some right-translate of a function negates it, then the integral of the function with respect
to a right-invariant measure is 0. -/
@[to_additive]
lemma integral_zero_of_mul_right_eq_neg (hμ : is_mul_right_invariant μ) {f : G → E} {g : G}
(hf' : ∀ x, f (x * g) = - f x) :
∫ x, f x ∂μ = 0 :=
begin
refine eq_zero_of_eq_neg ℝ (eq.symm _),
have : ∫ x, f (x * g) ∂μ = ∫ x, - f x ∂μ,
{ congr,
ext x,
exact hf' x },
convert integral_mul_right_eq_self hμ g using 1,
rw [this, integral_neg]
end
end group
mk_simp_attribute integral_simps "Simp set for integral rules."
attribute [integral_simps] integral_neg integral_smul L1.integral_add L1.integral_sub
L1.integral_smul L1.integral_neg
attribute [irreducible] integral L1.integral
section integral_trim
variables {H β γ : Type*} [normed_group H] [measurable_space H]
{m m0 : measurable_space β} {μ : measure β}
/-- Simple function seen as simple function of a larger `measurable_space`. -/
def simple_func.to_larger_space (hm : m ≤ m0) (f : @simple_func β m γ) : simple_func β γ :=
⟨@simple_func.to_fun β m γ f, λ x, hm _ (@simple_func.measurable_set_fiber β γ m f x),
@simple_func.finite_range β γ m f⟩
lemma simple_func.coe_to_larger_space_eq (hm : m ≤ m0) (f : @simple_func β m γ) :
⇑(f.to_larger_space hm) = f :=
rfl
lemma integral_simple_func_larger_space (hm : m ≤ m0) (f : @simple_func β m F)
(hf_int : integrable f μ) :
∫ x, f x ∂μ = ∑ x in (@simple_func.range β F m f), (ennreal.to_real (μ (f ⁻¹' {x}))) • x :=
begin
simp_rw ← f.coe_to_larger_space_eq hm,
have hf_int : integrable (f.to_larger_space hm) μ, by rwa simple_func.coe_to_larger_space_eq,
rw simple_func.integral_eq_sum _ hf_int,
congr,
end
lemma integral_trim_simple_func (hm : m ≤ m0) (f : @simple_func β m F) (hf_int : integrable f μ) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
have hf : @measurable _ _ m _ f, from @simple_func.measurable β F m _ f,
have hf_int_m := hf_int.trim hm hf,
rw [integral_simple_func_larger_space le_rfl f hf_int_m,
integral_simple_func_larger_space hm f hf_int],
congr,
ext1 x,
congr,
exact (trim_measurable_set_eq hm (@simple_func.measurable_set_fiber β F m f x)).symm,
end
lemma integral_trim (hm : m ≤ m0) {f : β → F} (hf : @measurable β F m _ f) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
by_cases hf_int : integrable f μ,
swap,
{ have hf_int_m : ¬ integrable f (μ.trim hm),
from λ hf_int_m, hf_int (integrable_of_integrable_trim hm hf_int_m),
rw [integral_undef hf_int, integral_undef hf_int_m], },
let f_seq := @simple_func.approx_on F β _ _ _ m _ hf set.univ 0 (set.mem_univ 0) _,
have hf_seq_meas : ∀ n, @measurable _ _ m _ (f_seq n),
from λ n, @simple_func.measurable β F m _ (f_seq n),
have hf_seq_int : ∀ n, integrable (f_seq n) μ,
from simple_func.integrable_approx_on_univ (hf.mono hm le_rfl) hf_int,
have hf_seq_int_m : ∀ n, integrable (f_seq n) (μ.trim hm),
from λ n, (hf_seq_int n).trim hm (hf_seq_meas n) ,
have hf_seq_eq : ∀ n, ∫ x, f_seq n x ∂μ = ∫ x, f_seq n x ∂(μ.trim hm),
from λ n, integral_trim_simple_func hm (f_seq n) (hf_seq_int n),
have h_lim_1 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂μ)),
{ refine tendsto_integral_of_L1 f hf_int (eventually_of_forall hf_seq_int) _,
exact simple_func.tendsto_approx_on_univ_L1_nnnorm (hf.mono hm le_rfl) hf_int, },
have h_lim_2 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂(μ.trim hm))),
{ simp_rw hf_seq_eq,
refine @tendsto_integral_of_L1 β F _ _ _ _ _ _ m (μ.trim hm) _ f
(hf_int.trim hm hf) _ _ (eventually_of_forall hf_seq_int_m) _,
exact @simple_func.tendsto_approx_on_univ_L1_nnnorm β F m _ _ _ _ f _ hf (hf_int.trim hm hf), },
exact tendsto_nhds_unique h_lim_1 h_lim_2,
end
lemma integral_trim_ae (hm : m ≤ m0) {f : β → F} (hf : ae_measurable f (μ.trim hm)) :
∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) :=
begin
rw [integral_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk), integral_congr_ae hf.ae_eq_mk],
exact integral_trim hm hf.measurable_mk,
end
lemma ae_eq_trim_of_measurable [measurable_space γ] [add_group γ] [measurable_singleton_class γ]
[has_measurable_sub₂ γ] (hm : m ≤ m0) {f g : β → γ} (hf : @measurable _ _ m _ f)
(hg : @measurable _ _ m _ g) (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.trim hm] g :=
begin
rwa [eventually_eq, ae_iff, trim_measurable_set_eq hm _],
exact (@measurable_set.compl β _ m (@measurable_set_eq_fun β m γ _ _ _ _ _ _ hf hg)),
end
lemma ae_eq_trim_iff [measurable_space γ] [add_group γ] [measurable_singleton_class γ]
[has_measurable_sub₂ γ]
(hm : m ≤ m0) {f g : β → γ} (hf : @measurable _ _ m _ f) (hg : @measurable _ _ m _ g) :
f =ᵐ[μ.trim hm] g ↔ f =ᵐ[μ] g :=
⟨ae_eq_of_ae_eq_trim, ae_eq_trim_of_measurable hm hf hg⟩
end integral_trim
end measure_theory
|
9484366187d8819910a26c6ec81593481547c461
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/data/real/ennreal.lean
|
46b5bcf69496ce5e3210c80dcd5c895c1ab1bd8f
|
[
"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
| 44,218
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl, Yury Kudryashov
Extended non-negative reals
-/
import data.real.nnreal order.bounds data.set.intervals tactic.norm_num
noncomputable theory
open classical set
open_locale classical
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]
def ennreal := with_top nnreal
localized "notation `∞` := (⊤ : ennreal)" in ennreal
namespace ennreal
variables {a b c d : ennreal} {r p q : nnreal}
instance : inhabited ennreal := ⟨0⟩
instance : has_coe nnreal ennreal := ⟨ option.some ⟩
instance : can_lift ennreal nnreal :=
{ 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 : ennreal) = (⊤ : ennreal) := rfl
@[simp] lemma some_eq_coe (a : nnreal) : (some a : ennreal) = (↑a : ennreal) := rfl
/-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/
protected def to_nnreal : ennreal → nnreal
| (some r) := r
| none := 0
/-- `to_real x` returns `x` if it is real, `0` otherwise. -/
protected def to_real (a : ennreal) : real := coe (a.to_nnreal)
/-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/
protected def of_real (r : real) : ennreal := coe (nnreal.of_real r)
@[simp, elim_cast] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl
@[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a
| (some r) h := rfl
| none h := (h rfl).elim
@[simp] lemma of_real_to_real {a : ennreal} (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 : real} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r :=
by simp [ennreal.to_real, ennreal.of_real, nnreal.coe_of_real _ h]
lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(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 : nnreal) : (r : ennreal) = ennreal.of_real r :=
by { rw [ennreal.of_real, nnreal.of_real], cases r with r h, congr, dsimp, rw max_eq_left h }
lemma of_real_eq_coe_nnreal {x : real} (h : 0 ≤ x) :
ennreal.of_real x = @coe nnreal ennreal _ (⟨x, h⟩ : nnreal) :=
by { rw [coe_nnreal_eq], refl }
@[simp, elim_cast] lemma coe_zero : ↑(0 : nnreal) = (0 : ennreal) := rfl
@[simp, elim_cast] lemma coe_one : ↑(1 : nnreal) = (1 : ennreal) := rfl
@[simp] lemma to_real_nonneg {a : ennreal} : 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 coe_to_real (r : nnreal) : (r : ennreal).to_real = r := rfl
@[simp] lemma zero_to_nnreal : (0 : ennreal).to_nnreal = 0 := rfl
@[simp] lemma zero_to_real : (0 : ennreal).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 : ennreal) :=
by simp [ennreal.of_real]
lemma of_real_to_real_le {a : ennreal} : 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 : ennreal → Prop} : (∀a, p a) ↔ (∀r:nnreal, p r) ∧ p ∞ :=
⟨assume h, ⟨assume r, h _, h _⟩,
assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩
lemma to_nnreal_eq_zero_iff (x : ennreal) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ⊤ :=
⟨begin
cases x,
{ simp [none_eq_top] },
{ have A : some (0:nnreal) = (0:ennreal) := rfl,
simp [ennreal.to_nnreal, A] {contextual := tt} }
end,
by intro h; cases h; simp [h]⟩
lemma to_real_eq_zero_iff (x : ennreal) : x.to_real = 0 ↔ x = 0 ∨ x = ⊤ :=
by simp [ennreal.to_real, to_nnreal_eq_zero_iff]
@[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top
@[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe
@[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real]
@[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, elim_cast] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe
@[simp, elim_cast] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe
@[simp, elim_cast] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe
lemma coe_mono : monotone (coe : nnreal → ennreal) := λ _ _, coe_le_coe.2
@[simp, elim_cast] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe
@[simp, elim_cast] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe
@[simp, elim_cast] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe
@[simp, elim_cast] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe
@[simp, elim_cast] lemma coe_nonneg : 0 ≤ (↑r : ennreal) ↔ 0 ≤ r := coe_le_coe
@[simp, elim_cast] lemma coe_pos : 0 < (↑r : ennreal) ↔ 0 < r := coe_lt_coe
@[simp, move_cast] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add
@[simp, move_cast] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul
@[simp, move_cast] lemma coe_bit0 : (↑(bit0 r) : ennreal) = bit0 r := coe_add
@[simp, move_cast] lemma coe_bit1 : (↑(bit1 r) : ennreal) = bit1 r := by simp [bit1]
lemma coe_two : ((2:nnreal) : ennreal) = 2 := by norm_cast
protected lemma zero_lt_one : 0 < (1 : ennreal) :=
canonically_ordered_semiring.zero_lt_one
@[simp] lemma one_lt_two : (1:ennreal) < 2 := coe_one ▸ coe_two ▸ by exact_mod_cast one_lt_two
@[simp] lemma two_pos : (0:ennreal) < 2 := lt_trans ennreal.zero_lt_one one_lt_two
lemma two_ne_zero : (2:ennreal) ≠ 0 := ne_of_gt two_pos
lemma two_ne_top : (2:ennreal) ≠ ∞ := coe_two ▸ coe_ne_top
@[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top
@[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add
instance : is_semiring_hom (coe : nnreal → ennreal) :=
by refine_struct {..}; simp
@[simp, move_cast] lemma coe_pow (n : ℕ) : (↑(r^n) : ennreal) = r^n :=
is_monoid_hom.map_pow coe r n
lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top _ _
lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top _ _
lemma to_nnreal_add {r₁ r₂ : ennreal} (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 ennreal _ _ ⊤,
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 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 : ennreal} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) :=
with_top.mul_eq_top_iff
lemma mul_ne_top {a b : ennreal} : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ :=
by simp [(≠), mul_eq_top] {contextual := tt}
lemma mul_lt_top {a b : ennreal} : a < ⊤ → b < ⊤ → a * b < ⊤ :=
by simpa only [ennreal.lt_top_iff_ne_top] using mul_ne_top
lemma pow_eq_top : ∀ n:ℕ, a^n=∞ → a=∞
| 0 := by simp
| (n+1) := λ o, (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, move_cast] lemma coe_finset_sum {s : finset α} {f : α → nnreal} :
↑(s.sum f) = (s.sum (λa, f a) : ennreal) :=
(s.sum_hom coe).symm
@[simp, move_cast] lemma coe_finset_prod {s : finset α} {f : α → nnreal} :
↑(s.prod f) = (s.prod (λa, f a) : ennreal) :=
(s.prod_hom coe).symm
section order
@[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl
@[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r
@[simp] lemma not_top_le_coe : ¬ (⊤:ennreal) ≤ ↑r := with_top.not_top_le_coe r
lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe
@[simp, elim_cast] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe
@[simp, elim_cast] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe
@[simp, elim_cast] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe
@[simp, elim_cast] lemma one_lt_coe_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe
@[simp, squash_cast] lemma coe_nat (n : nat) : ((n : nnreal) : ennreal) = n := with_top.coe_nat n
@[simp] lemma nat_ne_top (n : nat) : (n : ennreal) ≠ ⊤ := with_top.nat_ne_top n
@[simp] lemma top_ne_nat (n : nat) : (⊤ : ennreal) ≠ n := with_top.top_ne_nat n
lemma le_coe_iff : a ≤ ↑r ↔ (∃p:nnreal, a = p ∧ p ≤ r) := with_top.le_coe_iff r a
lemma coe_le_iff : ↑r ≤ a ↔ (∀p:nnreal, a = p → r ≤ p) := with_top.coe_le_iff r a
lemma lt_iff_exists_coe : a < b ↔ (∃p:nnreal, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe a b
@[simp] lemma max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 :=
by simp only [le_zero_iff_eq.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_semiring.pow_pos
protected lemma pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a^n ≠ 0 :=
by simpa only [zero_lt_iff_ne_zero] using ennreal.pow_pos
@[simp] lemma not_lt_zero : ¬ a < 0 := by simp
lemma add_lt_add_iff_left : a < ⊤ → (a + c < a + b ↔ c < b) :=
with_top.add_lt_add_iff_left
lemma add_lt_add_iff_right : a < ⊤ → (c + a < b + a ↔ c < b) :=
with_top.add_lt_add_iff_right
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_epsilon_le : ∀{a b : ennreal}, (∀ε:nnreal, 0 < ε → b < ∞ → a ≤ b + ε) → a ≤ b
| a none h := le_top
| none (some a) h :=
have (⊤:ennreal) ≤ ↑a + ↑(1:nnreal), 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_epsilon_le h
lemma lt_iff_exists_rat_btwn :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) :=
⟨λ h,
begin
rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩,
rcases dense 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:ennreal) < 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_add_pos_lt : a < b ↔ (∃ r : nnreal, 0 < r ∧ a + r < b) :=
begin
refine ⟨λ hab, _, λ ⟨r, rpos, hr⟩, lt_of_le_of_lt (le_add_right (le_refl _)) hr⟩,
cases a, { simpa using hab },
rcases lt_iff_exists_real_btwn.1 hab with ⟨c, c_nonneg, ac, cb⟩,
let d : nnreal := ⟨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 : nnreal.of_real c = d,
by { rw [← nnreal.coe_eq, nnreal.coe_of_real _ 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 : ennreal) < r ↔ ↑n < r := ennreal.coe_nat n ▸ coe_lt_coe
lemma coe_lt_coe_nat {n : ℕ} : (r : ennreal) < n ↔ r < n := ennreal.coe_nat n ▸ coe_lt_coe
@[elim_cast] lemma coe_nat_lt_coe_nat {m n : ℕ} : (m : ennreal) < n ↔ m < n :=
ennreal.coe_nat n ▸ coe_nat_lt_coe.trans nat.cast_lt
lemma coe_nat_ne_top {n : ℕ} : (n : ennreal) ≠ ∞ := ennreal.coe_nat n ▸ coe_ne_top
lemma coe_nat_mono : strict_mono (coe : ℕ → ennreal) := λ _ _, coe_nat_lt_coe_nat.2
@[elim_cast] lemma coe_nat_le_coe_nat {m n : ℕ} : (m : ennreal) ≤ n ↔ m ≤ n :=
coe_nat_mono.le_iff_le
instance : char_zero ennreal := ⟨coe_nat_mono.injective⟩
protected lemma exists_nat_gt {r : ennreal} (h : r ≠ ⊤) : ∃n:ℕ, r < n :=
begin
rcases lt_iff_exists_coe.1 (lt_top_iff_ne_top.2 h) with ⟨r, rfl, hb⟩,
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
rcases dense ac with ⟨a', aa', a'c⟩,
rcases lt_iff_exists_coe.1 aa' with ⟨aR, rfl, _⟩,
rcases lt_iff_exists_coe.1 a'c with ⟨a'R, rfl, _⟩,
rcases dense bd with ⟨b', bb', b'd⟩,
rcases lt_iff_exists_coe.1 bb' with ⟨bR, rfl, _⟩,
rcases lt_iff_exists_coe.1 b'd with ⟨b'R, rfl, _⟩,
have I : ↑aR + ↑bR < ↑a'R + ↑b'R :=
begin
rw [← coe_add, ← coe_add, coe_lt_coe],
apply add_lt_add (coe_lt_coe.1 aa') (coe_lt_coe.1 bb')
end,
have J : ↑a'R + ↑b'R ≤ c + d := add_le_add' (le_of_lt a'c) (le_of_lt b'd),
apply lt_of_lt_of_le I J
end
@[move_cast] lemma coe_min : ((min r p:nnreal):ennreal) = min r p :=
coe_mono.map_min
@[move_cast] lemma coe_max : ((max r p:nnreal):ennreal) = max r p :=
coe_mono.map_max
end order
section complete_lattice
lemma coe_Sup {s : set nnreal} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup
lemma coe_Inf {s : set nnreal} : s.nonempty → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf
@[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s :=
assume x hx, le_top
lemma coe_mem_upper_bounds {s : set nnreal} :
↑r ∈ upper_bounds ((coe : nnreal → ennreal) '' s) ↔ r ∈ upper_bounds s :=
by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt}
lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} :
(⨅n, f n) = (⨅n:nnreal, f n) ⊓ f ⊤ :=
le_antisymm
(le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _))
(le_infi $ forall_ennreal.2 ⟨assume r, inf_le_left_of_le $ infi_le _ _, inf_le_right⟩)
end complete_lattice
section mul
lemma mul_le_mul : a ≤ b → c ≤ d → a * c ≤ b * d :=
canonically_ordered_semiring.mul_le_mul
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 (zero_lt_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
lemma mul_eq_zero {a b : ennreal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
canonically_ordered_comm_semiring.mul_eq_zero_iff _ _
end mul
section sub
instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩
@[move_cast] lemma coe_sub : ↑(p - r) = (↑p:ennreal) - 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 : ennreal) ≤ ↑(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 _) (zero_le _)
@[simp] lemma sub_infty : 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 : ennreal}, 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_left_inj (h : a < ∞) : a + b = a + c ↔ b = c :=
⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩
lemma add_right_inj (h : a < ∞) : b + a = c + a ↔ b = c :=
by rw [add_comm, add_comm c, add_left_inj h]
@[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, 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,
calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _)
... ≤ c : Inf_le (le_refl (c + b)))
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_sub_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_infty, zero_lt_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 zero_lt_iff_ne_zero.2 h₂
end
end
@[simp] 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, -sub_eq_zero_iff_le] using not_iff_not.2 (@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 : ennreal) : a - b ≤ a :=
ennreal.sub_le_iff_le_add.2 $ le_add_of_nonneg_right' $ zero_le _
@[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_right_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_left_inj {a b c : ennreal} (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
/-- sum of finte numbers is still finite -/
lemma sum_lt_top [decidable_eq α] {s : finset α} {f : α → ennreal} :
(∀a∈s, f a < ⊤) → s.sum f < ⊤ :=
with_top.sum_lt_top
/-- sum of finte numbers is still finite -/
lemma sum_lt_top_iff [decidable_eq α] {s : finset α} {f : α → ennreal} :
s.sum f < ⊤ ↔ (∀a∈s, f a < ⊤) :=
with_top.sum_lt_top_iff
/-- seeing `ennreal` as `nnreal` does not change their sum, unless one of the `ennreal` is infinity -/
lemma to_nnreal_sum [decidable_eq α] {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ⊤) :
ennreal.to_nnreal (s.sum f) = s.sum (λa, ennreal.to_nnreal (f a)) :=
begin
rw [← coe_eq_coe, coe_to_nnreal, coe_finset_sum, sum_congr],
{ refl },
{ intros x hx, rw coe_to_nnreal, rw ← ennreal.lt_top_iff_ne_top, exact hf x hx },
{ rw ← ennreal.lt_top_iff_ne_top, exact sum_lt_top hf }
end
/-- seeing `ennreal` as `real` does not change their sum, unless one of the `ennreal` is infinity -/
lemma to_real_sum [decidable_eq α] {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ⊤) :
ennreal.to_real (s.sum f) = s.sum (λa, ennreal.to_real (f a)) :=
by { rw [ennreal.to_real, to_nnreal_sum hf, nnreal.coe_sum], refl }
end sum
section interval
variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal}
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 (by rwa lt_top_iff_ne_top) ε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_sub_self xt x0 ε0, lt_add_right (by rwa [lt_top_iff_ne_top]) ε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_right_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 ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩
instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩
lemma div_def : a / b = a * b⁻¹ := rfl
lemma mul_div_assoc : (a * b) / c = a * (b / c) :=
mul_assoc _ _ _
@[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ :=
show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl
@[simp] lemma inv_top : (∞ : ennreal)⁻¹ = 0 :=
bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul]
@[simp] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ennreal) = (↑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, nnreal.mul_inv_cancel hr]; exact le_refl 1)
lemma coe_inv_le : (↑r⁻¹ : ennreal) ≤ (↑r)⁻¹ :=
if hr : r = 0 then by simp only [hr, nnreal.inv_zero, inv_zero, coe_zero, zero_le]
else by simp only [coe_inv hr, le_refl]
@[elim_cast] lemma coe_inv_two : ((2⁻¹:nnreal):ennreal) = 2⁻¹ :=
by rw [coe_inv (ne_of_gt zero_lt_two), coe_two]
@[simp, elim_cast] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ennreal) = p / r :=
show ↑(p * r⁻¹) = ↑p * (↑r)⁻¹, by rw [coe_mul, coe_inv hr]
@[simp] lemma inv_one : (1:ennreal)⁻¹ = 1 :=
by simpa only [coe_inv one_ne_zero, coe_one] using coe_eq_coe.2 nnreal.inv_one
@[simp] lemma div_one {a : ennreal} : a / 1 = a :=
by simp [ennreal.div_def]
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, nnreal.inv_pow', coe_pow],
rw [← ne.def] at h,
rw [← zero_lt_iff_ne_zero] at *,
apply pow_pos h
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:ennreal, a⁻¹) :=
λ a, ennreal.inv_inv
lemma inv_bijective : function.bijective (λ a:ennreal, 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_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 ≠ ∞ :=
zero_lt_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 [zero_lt_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_lt_one : a⁻¹ < 1 ↔ 1 < a :=
inv_lt_iff_inv_lt.trans $ by rw [inv_one]
lemma top_div : ∞ / a = if a = ∞ then 0 else ∞ :=
by by_cases a = ∞; simp [div_def, top_mul, *]
@[simp] lemma div_top : a / ∞ = 0 := by simp only [div_def, inv_top, mul_zero]
@[simp] lemma zero_div : 0 / a = 0 := zero_mul a⁻¹
lemma div_eq_top : a / b = ⊤ ↔ (a ≠ 0 ∧ b = 0) ∨ (a = ⊤ ∧ b ≠ ⊤) :=
by simp [ennreal.div_def, 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 : ennreal) ≠ 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_def, hb, mul_left_comm, mul_comm, mul_assoc] },
rw [← coe_mul, nnreal.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_def],
apply (le_div_iff_mul_le _ _).symm,
simpa [inv_ne_zero] using hbt,
simpa [inv_ne_zero] using hb0
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 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_def, 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 nnreal using ht,
norm_cast at h0,
rw [← coe_inv h0],
norm_cast,
exact nnreal.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 mul_le_iff_le_inv {a b r : ennreal} (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_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y :=
forall_ennreal.2 $ and.intro
(assume r, forall_ennreal.2 $ and.intro
(assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha,
begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end)
(assume h, le_top))
(assume r hr,
have ((1 / 2 : nnreal) : ennreal) * ⊤ ≤ r :=
hr _ (coe_lt_coe.2 ((@nnreal.coe_lt_coe (1/2) 1).1 one_half_lt_one)),
have ne : ((1 / 2 : nnreal) : ennreal) ≠ 0,
begin
rw [(≠), coe_eq_zero],
refine zero_lt_iff_ne_zero.1 _,
show 0 < (1 / 2 : ℝ),
exact div_pos zero_lt_one _root_.two_pos
end,
by rwa [mul_top, if_neg ne] at this)
lemma div_add_div_same {a b c : ennreal} : 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_def, 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 inv_two_add_inv_two : (2:ennreal)⁻¹ + 2⁻¹ = 1 :=
by rw [← two_mul, ← div_def, div_self two_ne_zero two_ne_top]
lemma add_halves (a : ennreal) : a / 2 + a / 2 = a :=
by rw [div_def, ← mul_add, inv_two_add_inv_two, mul_one]
@[simp] lemma div_zero_iff {a b : ennreal} : a / b = 0 ↔ a = 0 ∨ b = ⊤ :=
by simp [div_def, mul_eq_zero]
@[simp] lemma div_pos_iff {a b : ennreal} : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ⊤ :=
by simp [zero_lt_iff_ne_zero, not_or_distrib]
lemma half_pos {a : ennreal} (h : 0 < a) : 0 < a / 2 :=
by simp [ne_of_gt h]
lemma one_half_lt_one : (2⁻¹:ennreal) < 1 := inv_lt_one.2 $ one_lt_two
lemma half_lt_self {a : ennreal} (hz : a ≠ 0) (ht : a ≠ ⊤) : a / 2 < a :=
begin
lift a to nnreal using ht,
norm_cast at *,
rw [← coe_div _root_.two_ne_zero'], -- `norm_cast` fails to apply `coe_div`
norm_cast,
exact nnreal.half_lt_self hz
end
lemma sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 :=
begin
lift a to nnreal using h,
exact sub_eq_of_add_eq (mul_ne_top coe_ne_top $ by simp) (add_halves a)
end
lemma one_sub_inv_two : (1:ennreal) - 2⁻¹ = 2⁻¹ :=
by simpa only [div_def, one_mul] using sub_half one_ne_top
lemma exists_inv_nat_lt {a : ennreal} (h : a ≠ 0) :
∃n:ℕ, (n:ennreal)⁻¹ < a :=
@inv_inv a ▸ by simp only [inv_lt_inv, ennreal.exists_nat_gt (inv_ne_top.2 h)]
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 nnreal using ha,
lift b to nnreal using hb,
refl
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, nnreal.of_real_add hp hq]
@[simp] lemma to_real_le_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real ≤ b.to_real ↔ a ≤ b :=
begin
lift a to nnreal using ha,
lift b to nnreal using hb,
norm_cast
end
@[simp] lemma to_real_lt_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real < b.to_real ↔ a < b :=
begin
lift a to nnreal using ha,
lift b to nnreal using hb,
norm_cast
end
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, nnreal.of_real_le_of_real h]
@[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, nnreal.of_real_le_of_real_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, nnreal.of_real_lt_of_real_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, nnreal.of_real_lt_of_real_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]
lemma of_real_le_iff_le_to_real {a : ℝ} {b : ennreal} (hb : b ≠ ⊤) :
ennreal.of_real a ≤ b ↔ a ≤ ennreal.to_real b :=
begin
lift b to nnreal using hb,
simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_le_iff_le_coe
end
lemma of_real_lt_iff_lt_to_real {a : ℝ} {b : ennreal} (ha : 0 ≤ a) (hb : b ≠ ⊤) :
ennreal.of_real a < b ↔ a < ennreal.to_real b :=
begin
lift b to nnreal using hb,
simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_lt_iff_lt_coe ha
end
lemma le_of_real_iff_to_real_le {a : ennreal} {b : ℝ} (ha : a ≠ ⊤) (hb : 0 ≤ b) :
a ≤ ennreal.of_real b ↔ ennreal.to_real a ≤ b :=
begin
lift a to nnreal using ha,
simpa [ennreal.of_real, ennreal.to_real] using nnreal.le_of_real_iff_coe_le hb
end
lemma to_real_le_of_le_of_real {a : ennreal} {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 : ennreal} {b : ℝ} (ha : a ≠ ⊤) :
a < ennreal.of_real b ↔ ennreal.to_real a < b :=
begin
lift a to nnreal using ha,
simpa [ennreal.of_real, ennreal.to_real] using nnreal.lt_of_real_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 nnreal.of_real_mul hp }
lemma to_real_of_real_mul (c : ℝ) (a : ennreal) (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 nnreal.coe_of_real, exact h }
end
@[simp] lemma to_real_mul_top (a : ennreal) : ennreal.to_real (a * ⊤) = 0 :=
begin
by_cases h : a = 0,
{ rw [h, zero_mul, zero_to_real] },
{ rw [mul_top, if_neg h, top_to_real] }
end
@[simp] lemma to_real_top_mul (a : ennreal) : ennreal.to_real (⊤ * a) = 0 :=
by { rw mul_comm, exact to_real_mul_top _ }
lemma to_real_eq_to_real {a b : ennreal} (ha : a < ⊤) (hb : b < ⊤) :
ennreal.to_real a = ennreal.to_real b ↔ a = b :=
begin
rw ennreal.lt_top_iff_ne_top at *,
split,
{ assume h, apply le_antisymm,
rw ← to_real_le_to_real ha hb, exact le_of_eq h,
rw ← to_real_le_to_real hb ha, exact le_of_eq h.symm },
{ assume h, rw h }
end
lemma to_real_mul_to_real {a b : ennreal} :
(ennreal.to_real a) * (ennreal.to_real b) = ennreal.to_real (a * b) :=
begin
by_cases ha : a = ⊤,
{ rw ha, simp },
by_cases hb : b = ⊤,
{ rw hb, simp },
have ha : ennreal.of_real (ennreal.to_real a) = a := of_real_to_real ha,
have hb : ennreal.of_real (ennreal.to_real b) = b := of_real_to_real hb,
conv_rhs { rw [← ha, ← hb, ← of_real_mul to_real_nonneg] },
rw [to_real_of_real (mul_nonneg to_real_nonneg to_real_nonneg)]
end
end real
section infi
variables {ι : Sort*} {f g : ι → ennreal}
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 ennreal} : Inf s + a = ⨅b∈s, b + a :=
by simp [Inf_eq_infi, infi_add]
lemma add_infi {a : ennreal} : 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 : ι → α → ennreal} {s : finset α} [nonempty ι]
(h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) :
(⨅i, s.sum (f i)) = s.sum (λa, ⨅i, f i a) :=
finset.induction_on s (by simp) $ assume a s ha ih,
have ∀ (i j : ι), ∃ (k : ι), f k a + s.sum (f k) ≤ f i a + s.sum (f j),
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]
end infi
section supr
lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ⊤ :=
(supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb)
end supr
end ennreal
|
5aabd20e45e253e79e5ee0915a32476d721f10af
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/category_theory/limits/bicones.lean
|
ced55c90ecb55c5962d8523e46e70d3128f1f3ba
|
[
"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
| 4,770
|
lean
|
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import category_theory.limits.cones
import category_theory.fin_category
/-!
# Bicones
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Given a category `J`, a walking `bicone J` is a category whose objects are the objects of `J` and
two extra vertices `bicone.left` and `bicone.right`. The morphisms are the morphisms of `J` and
`left ⟶ j`, `right ⟶ j` for each `j : J` such that `⬝ ⟶ j` and `⬝ ⟶ k` commutes with each
`f : j ⟶ k`.
Given a diagram `F : J ⥤ C` and two `cone F`s, we can join them into a diagram `bicone J ⥤ C` via
`bicone_mk`.
This is used in `category_theory.flat_functors.preserves_finite_limits_of_flat`.
-/
universes v₁ u₁
noncomputable theory
open category_theory.limits
open_locale classical
namespace category_theory
section bicone
variables (J : Type u₁)
/-- Given a category `J`, construct a walking `bicone J` by adjoining two elements. -/
@[derive decidable_eq]
inductive bicone
| left : bicone
| right : bicone
| diagram (val : J) : bicone
instance : inhabited (bicone J) := ⟨bicone.left⟩
instance fin_bicone [fintype J] : fintype (bicone J) :=
{ elems := [bicone.left, bicone.right].to_finset ∪ finset.image bicone.diagram (fintype.elems J),
complete := λ j, by { cases j; simp, exact fintype.complete j, }, }
variables [category.{v₁} J]
/-- The homs for a walking `bicone J`. -/
inductive bicone_hom : bicone J → bicone J → Type (max u₁ v₁)
| left_id : bicone_hom bicone.left bicone.left
| right_id : bicone_hom bicone.right bicone.right
| left (j : J) : bicone_hom bicone.left (bicone.diagram j)
| right (j : J) : bicone_hom bicone.right (bicone.diagram j)
| diagram {j k : J} (f : j ⟶ k) : bicone_hom (bicone.diagram j) (bicone.diagram k)
instance : inhabited (bicone_hom J bicone.left bicone.left) := ⟨bicone_hom.left_id⟩
instance bicone_hom.decidable_eq {j k : bicone J} : decidable_eq (bicone_hom J j k) :=
λ f g, by { cases f; cases g; simp; apply_instance }
@[simps]
instance bicone_category_struct : category_struct (bicone J) :=
{ hom := bicone_hom J,
id := λ j, bicone.cases_on j
bicone_hom.left_id bicone_hom.right_id (λ k, bicone_hom.diagram (𝟙 k)),
comp := λ X Y Z f g, by
{ cases f, exact g, exact g,
cases g, exact bicone_hom.left g_k,
cases g, exact bicone_hom.right g_k,
cases g, exact bicone_hom.diagram (f_f ≫ g_f) } }
instance bicone_category : category (bicone J) :=
{ id_comp' := λ X Y f, by { cases f; simp },
comp_id' := λ X Y f, by { cases f; simp },
assoc' := λ W X Y Z f g h, by { cases f; cases g; cases h; simp } }
end bicone
section small_category
variables (J : Type v₁) [small_category J]
/--
Given a diagram `F : J ⥤ C` and two `cone F`s, we can join them into a diagram `bicone J ⥤ C`.
-/
@[simps] def bicone_mk {C : Type u₁} [category.{v₁} C]
{F : J ⥤ C} (c₁ c₂ : cone F) : bicone J ⥤ C :=
{ obj := λ X, bicone.cases_on X c₁.X c₂.X (λ j, F.obj j),
map := λ X Y f, by
{ cases f, exact (𝟙 _), exact (𝟙 _),
exact c₁.π.app f_1,
exact c₂.π.app f_1,
exact F.map f_f, },
map_id' := λ X, by { cases X; simp },
map_comp' := λ X Y Z f g, by
{ cases f,
exact (category.id_comp _).symm,
exact (category.id_comp _).symm,
cases g, exact (category.id_comp _).symm.trans (c₁.π.naturality g_f : _),
cases g, exact (category.id_comp _).symm.trans (c₂.π.naturality g_f : _),
cases g, exact F.map_comp _ _ } }
instance fin_bicone_hom [fin_category J] (j k : bicone J) : fintype (j ⟶ k) :=
begin
cases j; cases k,
exact { elems := {bicone_hom.left_id}, complete := λ f, by { cases f, simp } },
exact { elems := ∅, complete := λ f, by { cases f } },
exact { elems := {bicone_hom.left k}, complete := λ f, by { cases f, simp } },
exact { elems := ∅, complete := λ f, by { cases f } },
exact { elems := {bicone_hom.right_id}, complete := λ f, by { cases f, simp } },
exact { elems := {bicone_hom.right k}, complete := λ f, by { cases f, simp } },
exact { elems := ∅, complete := λ f, by { cases f } },
exact { elems := ∅, complete := λ f, by { cases f } },
exact { elems := finset.image (bicone_hom.diagram) (fintype.elems (j ⟶ k)),
complete := λ f, by
{ cases f, simp only [finset.mem_image], use f_f, simpa using fintype.complete _, } },
end
instance bicone_small_category : small_category (bicone J) :=
category_theory.bicone_category J
instance bicone_fin_category [fin_category J] : fin_category (bicone J) := {}
end small_category
end category_theory
|
15209d13e523bc2c53ecc392b894d54ae0b932c8
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/category_theory/sites/spaces_auto.lean
|
fe5a8857c15f6e8707689b1f52f547c76fc2af86
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,361
|
lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.opens
import Mathlib.category_theory.sites.grothendieck
import Mathlib.category_theory.sites.pretopology
import Mathlib.category_theory.limits.lattice
import Mathlib.PostPort
universes u
namespace Mathlib
/-!
# Grothendieck topology on a topological space
Define the Grothendieck topology and the pretopology associated to a topological space, and show
that the pretopology induces the topology.
The covering (pre)sieves on `X` are those for which the union of domains contains `X`.
## Tags
site, Grothendieck topology, space
## References
* [https://ncatlab.org/nlab/show/Grothendieck+topology][nlab]
* [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM92]
## Implementation notes
We define the two separately, rather than defining the Grothendieck topology as that generated
by the pretopology for the purpose of having nice definitional properties for the sieves.
-/
namespace opens
/-- The Grothendieck topology associated to a topological space. -/
def grothendieck_topology (T : Type u) [topological_space T] :
category_theory.grothendieck_topology (topological_space.opens T) :=
category_theory.grothendieck_topology.mk
(fun (X : topological_space.opens T) (S : category_theory.sieve X) =>
∀ (x : T), x ∈ X → ∃ (U : topological_space.opens T), ∃ (f : U ⟶ X), coe_fn S U f ∧ x ∈ U)
sorry sorry sorry
/-- The Grothendieck pretopology associated to a topological space. -/
def pretopology (T : Type u) [topological_space T] :
category_theory.pretopology (topological_space.opens T) :=
category_theory.pretopology.mk
(fun (X : topological_space.opens T) (R : category_theory.presieve X) =>
∀ (x : T), x ∈ X → ∃ (U : topological_space.opens T), ∃ (f : U ⟶ X), R f ∧ x ∈ U)
sorry sorry sorry
/--
The pretopology associated to a space induces the Grothendieck topology associated to the space.
-/
@[simp] theorem pretopology_to_grothendieck (T : Type u) [topological_space T] :
category_theory.pretopology.to_grothendieck (topological_space.opens T) (pretopology T) =
grothendieck_topology T :=
sorry
end Mathlib
|
724db0118a9afcb949c78b73984f6409283c10e5
|
947b78d97130d56365ae2ec264df196ce769371a
|
/tests/lean/run/coeIssue2.lean
|
c0baca2ce2a85fb7fda179c49c4c8c41bd8533d2
|
[
"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
| 850
|
lean
|
new_frontend
structure A :=
(a : Nat)
structure B :=
(a : Nat)
structure C :=
(a : Nat)
instance : Coe A B := ⟨fun s => ⟨s.1⟩⟩
instance : Coe A C := ⟨fun s => ⟨s.1⟩⟩
def f {α} (a b : α) := a
def forceB {α} (b : B) (a : α) := a
def forceC {α} (c : C) (a : α) := a
def forceA {α} (a : A) (o : α) := o
def f1 (x : _) (y : _) (z : _) :=
let a1 := f x y;
let a2 := f y z;
forceB x a1 -- works
def f2 (x : _) (y : _) (z : _) :=
let a1 := f x (coe y);
let a2 := f (coe y) z;
forceB x (forceC z (forceA y (a1, a2))) -- works because we manually added the coercions above
#exit
def f3 (x : _) (y : _) (z : _) :=
let a1 := f x y;
let a2 := f y z;
/- Fails because we "missed" the opportunity to insert coercions around `y`.
I think we should **not** support this kind of example. -/
forceB x (forceC z (forceA y (a1, a2)))
|
e7eedc8afeeb957e2a453c436699a5ca91ca1aad
|
130c49f47783503e462c16b2eff31933442be6ff
|
/src/Lean/Util/Recognizers.lean
|
5df6fb7d9c2f79dd2d58ab85d70d97b954562e50
|
[
"Apache-2.0"
] |
permissive
|
Hazel-Brown/lean4
|
8aa5860e282435ffc30dcdfccd34006c59d1d39c
|
79e6732fc6bbf5af831b76f310f9c488d44e7a16
|
refs/heads/master
| 1,689,218,208,951
| 1,629,736,869,000
| 1,629,736,896,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,929
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Environment
namespace Lean
namespace Expr
@[inline] def const? (e : Expr) : Option (Name × List Level) :=
match e with
| Expr.const n us _ => some (n, us)
| _ => none
@[inline] def app1? (e : Expr) (fName : Name) : Option Expr :=
if e.isAppOfArity fName 1 then
some e.appArg!
else
none
@[inline] def app2? (e : Expr) (fName : Name) : Option (Expr × Expr) :=
if e.isAppOfArity fName 2 then
some (e.appFn!.appArg!, e.appArg!)
else
none
@[inline] def app3? (e : Expr) (fName : Name) : Option (Expr × Expr × Expr) :=
if e.isAppOfArity fName 3 then
some (e.appFn!.appFn!.appArg!, e.appFn!.appArg!, e.appArg!)
else
none
@[inline] def app4? (e : Expr) (fName : Name) : Option (Expr × Expr × Expr × Expr) :=
if e.isAppOfArity fName 4 then
some (e.appFn!.appFn!.appFn!.appArg!, e.appFn!.appFn!.appArg!, e.appFn!.appArg!, e.appArg!)
else
none
@[inline] def eq? (p : Expr) : Option (Expr × Expr × Expr) :=
p.app3? ``Eq
@[inline] def ne? (p : Expr) : Option (Expr × Expr × Expr) :=
p.app3? ``Ne
@[inline] def iff? (p : Expr) : Option (Expr × Expr) :=
p.app2? ``Iff
@[inline] def not? (p : Expr) : Option Expr :=
p.app1? ``Not
@[inline] def notNot? (p : Expr) : Option Expr :=
match p.not? with
| some p => p.not?
| none => none
@[inline] def and? (p : Expr) : Option (Expr × Expr) :=
p.app2? ``And
@[inline] def heq? (p : Expr) : Option (Expr × Expr × Expr × Expr) :=
p.app4? ``HEq
def natAdd? (e : Expr) : Option (Expr × Expr) :=
e.app2? ``Nat.add
@[inline] def arrow? : Expr → Option (Expr × Expr)
| Expr.forallE _ α β _ => if β.hasLooseBVars then none else some (α, β)
| _ => none
def isEq (e : Expr) :=
e.isAppOfArity ``Eq 3
def isHEq (e : Expr) :=
e.isAppOfArity ``HEq 4
partial def listLit? (e : Expr) : Option (Expr × List Expr) :=
let rec loop (e : Expr) (acc : List Expr) :=
if e.isAppOfArity ``List.nil 1 then
some (e.appArg!, acc.reverse)
else if e.isAppOfArity ``List.cons 3 then
loop e.appArg! (e.appFn!.appArg! :: acc)
else
none
loop e []
def arrayLit? (e : Expr) : Option (Expr × List Expr) :=
match e.app2? ``List.toArray with
| some (_, e) => e.listLit?
| none => none
/-- Recognize `α × β` -/
def prod? (e : Expr) : Option (Expr × Expr) :=
e.app2? ``Prod
private def getConstructorVal? (env : Environment) (ctorName : Name) : Option ConstructorVal := do
match env.find? ctorName with
| some (ConstantInfo.ctorInfo v) => v
| _ => none
def isConstructorApp? (env : Environment) (e : Expr) : Option ConstructorVal :=
match e with
| Expr.lit (Literal.natVal n) _ => if n == 0 then getConstructorVal? env `Nat.zero else getConstructorVal? env `Nat.succ
| _ =>
match e.getAppFn with
| Expr.const n _ _ => match getConstructorVal? env n with
| some v => if v.numParams + v.numFields == e.getAppNumArgs then some v else none
| none => none
| _ => none
def isConstructorApp (env : Environment) (e : Expr) : Bool :=
e.isConstructorApp? env |>.isSome
def constructorApp? (env : Environment) (e : Expr) : Option (ConstructorVal × Array Expr) :=
OptionM.run do
match e with
| Expr.lit (Literal.natVal n) _ =>
if n == 0 then do
let v ← getConstructorVal? env `Nat.zero
pure (v, #[])
else do
let v ← getConstructorVal? env `Nat.succ
pure (v, #[mkNatLit (n-1)])
| _ =>
match e.getAppFn with
| Expr.const n _ _ => do
let v ← getConstructorVal? env n
if v.numParams + v.numFields == e.getAppNumArgs then
pure (v, e.getAppArgs)
else
none
| _ => none
end Lean.Expr
|
77949f278150076a50881565d56b206445c4a581
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/topology/metric_space/metrizable.lean
|
8a016f62e60c763a2fad9304649ffc929cb30e78
|
[
"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
| 11,776
|
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 analysis.specific_limits.basic
import topology.urysohns_lemma
import topology.continuous_function.bounded
import topology.uniform_space.cauchy
/-!
# Metrizability of a T₃ topological space with second countable topology
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define metrizable topological spaces, i.e., topological spaces for which there
exists a metric space structure that generates the same topology.
We also show that a T₃ topological space with second countable topology `X` is metrizable.
First we prove that `X` can be embedded into `l^∞`, then use this embedding to pull back the metric
space structure.
-/
open set filter metric
open_locale bounded_continuous_function filter topology
namespace topological_space
variables {ι X Y : Type*} {π : ι → Type*} [topological_space X] [topological_space Y]
[finite ι] [Π i, topological_space (π i)]
/-- A topological space is *pseudo metrizable* if there exists a pseudo metric space structure
compatible with the topology. To endow such a space with a compatible distance, use
`letI : pseudo_metric_space X := topological_space.pseudo_metrizable_space_pseudo_metric X`. -/
class pseudo_metrizable_space (X : Type*) [t : topological_space X] : Prop :=
(exists_pseudo_metric : ∃ (m : pseudo_metric_space X), m.to_uniform_space.to_topological_space = t)
@[priority 100]
instance _root_.pseudo_metric_space.to_pseudo_metrizable_space {X : Type*}
[m : pseudo_metric_space X] :
pseudo_metrizable_space X :=
⟨⟨m, rfl⟩⟩
/-- Construct on a metrizable space a metric compatible with the topology. -/
noncomputable def pseudo_metrizable_space_pseudo_metric
(X : Type*) [topological_space X] [h : pseudo_metrizable_space X] :
pseudo_metric_space X :=
h.exists_pseudo_metric.some.replace_topology h.exists_pseudo_metric.some_spec.symm
instance pseudo_metrizable_space_prod [pseudo_metrizable_space X] [pseudo_metrizable_space Y] :
pseudo_metrizable_space (X × Y) :=
begin
letI : pseudo_metric_space X := pseudo_metrizable_space_pseudo_metric X,
letI : pseudo_metric_space Y := pseudo_metrizable_space_pseudo_metric Y,
apply_instance
end
/-- Given an inducing map of a topological space into a pseudo metrizable space, the source space
is also pseudo metrizable. -/
lemma _root_.inducing.pseudo_metrizable_space [pseudo_metrizable_space Y] {f : X → Y}
(hf : inducing f) :
pseudo_metrizable_space X :=
begin
letI : pseudo_metric_space Y := pseudo_metrizable_space_pseudo_metric Y,
exact ⟨⟨hf.comap_pseudo_metric_space, rfl⟩⟩
end
/-- Every pseudo-metrizable space is first countable. -/
@[priority 100]
instance pseudo_metrizable_space.first_countable_topology [h : pseudo_metrizable_space X] :
topological_space.first_countable_topology X :=
begin
unfreezingI { rcases h with ⟨_, hm⟩, rw ←hm },
exact @uniform_space.first_countable_topology X pseudo_metric_space.to_uniform_space
emetric.uniformity.filter.is_countably_generated,
end
instance pseudo_metrizable_space.subtype [pseudo_metrizable_space X]
(s : set X) : pseudo_metrizable_space s :=
inducing_coe.pseudo_metrizable_space
instance pseudo_metrizable_space_pi [Π i, pseudo_metrizable_space (π i)] :
pseudo_metrizable_space (Π i, π i) :=
by { casesI nonempty_fintype ι, letI := λ i, pseudo_metrizable_space_pseudo_metric (π i),
apply_instance }
/-- A topological space is metrizable if there exists a metric space structure compatible with the
topology. To endow such a space with a compatible distance, use
`letI : metric_space X := topological_space.metrizable_space_metric X` -/
class metrizable_space (X : Type*) [t : topological_space X] : Prop :=
(exists_metric : ∃ (m : metric_space X), m.to_uniform_space.to_topological_space = t)
@[priority 100]
instance _root_.metric_space.to_metrizable_space {X : Type*} [m : metric_space X] :
metrizable_space X :=
⟨⟨m, rfl⟩⟩
@[priority 100]
instance metrizable_space.to_pseudo_metrizable_space [h : metrizable_space X] :
pseudo_metrizable_space X :=
⟨let ⟨m, hm⟩ := h.1 in ⟨m.to_pseudo_metric_space, hm⟩⟩
/-- Construct on a metrizable space a metric compatible with the topology. -/
noncomputable def metrizable_space_metric (X : Type*) [topological_space X]
[h : metrizable_space X] :
metric_space X :=
h.exists_metric.some.replace_topology h.exists_metric.some_spec.symm
@[priority 100]
instance t2_space_of_metrizable_space [metrizable_space X] : t2_space X :=
by { letI : metric_space X := metrizable_space_metric X, apply_instance }
instance metrizable_space_prod [metrizable_space X] [metrizable_space Y] :
metrizable_space (X × Y) :=
begin
letI : metric_space X := metrizable_space_metric X,
letI : metric_space Y := metrizable_space_metric Y,
apply_instance
end
/-- Given an embedding of a topological space into a metrizable space, the source space is also
metrizable. -/
lemma _root_.embedding.metrizable_space [metrizable_space Y] {f : X → Y} (hf : embedding f) :
metrizable_space X :=
begin
letI : metric_space Y := metrizable_space_metric Y,
exact ⟨⟨hf.comap_metric_space f, rfl⟩⟩
end
instance metrizable_space.subtype [metrizable_space X] (s : set X) : metrizable_space s :=
embedding_subtype_coe.metrizable_space
instance metrizable_space_pi [Π i, metrizable_space (π i)] : metrizable_space (Π i, π i) :=
by { casesI nonempty_fintype ι, letI := λ i, metrizable_space_metric (π i), apply_instance }
variables (X) [t3_space X] [second_countable_topology X]
/-- A T₃ topological space with second countable topology can be embedded into `l^∞ = ℕ →ᵇ ℝ`.
-/
lemma exists_embedding_l_infty : ∃ f : X → (ℕ →ᵇ ℝ), embedding f :=
begin
haveI : normal_space X := normal_space_of_t3_second_countable X,
-- Choose a countable basis, and consider the set `s` of pairs of set `(U, V)` such that `U ∈ B`,
-- `V ∈ B`, and `closure U ⊆ V`.
rcases exists_countable_basis X with ⟨B, hBc, -, hB⟩,
set s : set (set X × set X) := {UV ∈ B ×ˢ B| closure UV.1 ⊆ UV.2},
-- `s` is a countable set.
haveI : encodable s := ((hBc.prod hBc).mono (inter_subset_left _ _)).to_encodable,
-- We don't have the space of bounded (possibly discontinuous) functions, so we equip `s`
-- with the discrete topology and deal with `s →ᵇ ℝ` instead.
letI : topological_space s := ⊥, haveI : discrete_topology s := ⟨rfl⟩,
rsuffices ⟨f, hf⟩ : ∃ f : X → (s →ᵇ ℝ), embedding f,
{ exact ⟨λ x, (f x).extend (encodable.encode' s) 0, (bounded_continuous_function.isometry_extend
(encodable.encode' s) (0 : ℕ →ᵇ ℝ)).embedding.comp hf⟩ },
have hd : ∀ UV : s, disjoint (closure UV.1.1) (UV.1.2ᶜ) :=
λ UV, disjoint_compl_right.mono_right (compl_subset_compl.2 UV.2.2),
-- Choose a sequence of `εₙ > 0`, `n : s`, that is bounded above by `1` and tends to zero
-- along the `cofinite` filter.
obtain ⟨ε, ε01, hε⟩ : ∃ ε : s → ℝ, (∀ UV, ε UV ∈ Ioc (0 : ℝ) 1) ∧ tendsto ε cofinite (𝓝 0),
{ rcases pos_sum_of_encodable zero_lt_one s with ⟨ε, ε0, c, hεc, hc1⟩,
refine ⟨ε, λ UV, ⟨ε0 UV, _⟩, hεc.summable.tendsto_cofinite_zero⟩,
exact (le_has_sum hεc UV $ λ _ _, (ε0 _).le).trans hc1 },
/- For each `UV = (U, V) ∈ s` we use Urysohn's lemma to choose a function `f UV` that is equal to
zero on `U` and is equal to `ε UV` on the complement to `V`. -/
have : ∀ UV : s, ∃ f : C(X, ℝ), eq_on f 0 UV.1.1 ∧ eq_on f (λ _, ε UV) UV.1.2ᶜ ∧
∀ x, f x ∈ Icc 0 (ε UV),
{ intro UV,
rcases exists_continuous_zero_one_of_closed is_closed_closure
(hB.is_open UV.2.1.2).is_closed_compl (hd UV) with ⟨f, hf₀, hf₁, hf01⟩,
exact ⟨ε UV • f, λ x hx, by simp [hf₀ (subset_closure hx)], λ x hx, by simp [hf₁ hx],
λ x, ⟨mul_nonneg (ε01 _).1.le (hf01 _).1, mul_le_of_le_one_right (ε01 _).1.le (hf01 _).2⟩⟩ },
choose f hf0 hfε hf0ε,
have hf01 : ∀ UV x, f UV x ∈ Icc (0 : ℝ) 1,
from λ UV x, Icc_subset_Icc_right (ε01 _).2 (hf0ε _ _),
/- The embedding is given by `F x UV = f UV x`. -/
set F : X → s →ᵇ ℝ := λ x, ⟨⟨λ UV, f UV x, continuous_of_discrete_topology⟩, 1, λ UV₁ UV₂,
real.dist_le_of_mem_Icc_01 (hf01 _ _) (hf01 _ _)⟩,
have hF : ∀ x UV, F x UV = f UV x := λ _ _, rfl,
refine ⟨F, embedding.mk' _ (λ x y hxy, _) (λ x, le_antisymm _ _)⟩,
{ /- First we prove that `F` is injective. Indeed, if `F x = F y` and `x ≠ y`, then we can find
`(U, V) ∈ s` such that `x ∈ U` and `y ∉ V`, hence `F x UV = 0 ≠ ε UV = F y UV`. -/
refine not_not.1 (λ Hne, _), -- `by_contra Hne` timeouts
rcases hB.mem_nhds_iff.1 (is_open_ne.mem_nhds Hne) with ⟨V, hVB, hxV, hVy⟩,
rcases hB.exists_closure_subset (hB.mem_nhds hVB hxV) with ⟨U, hUB, hxU, hUV⟩,
set UV : ↥s := ⟨(U, V), ⟨hUB, hVB⟩, hUV⟩,
apply (ε01 UV).1.ne,
calc (0 : ℝ) = F x UV : (hf0 UV hxU).symm
... = F y UV : by rw hxy
... = ε UV : hfε UV (λ h : y ∈ V, hVy h rfl) },
{ /- Now we prove that each neighborhood `V` of `x : X` include a preimage of a neighborhood of
`F x` under `F`. Without loss of generality, `V` belongs to `B`. Choose `U ∈ B` such that
`x ∈ V` and `closure V ⊆ U`. Then the preimage of the `(ε (U, V))`-neighborhood of `F x`
is included by `V`. -/
refine ((nhds_basis_ball.comap _).le_basis_iff hB.nhds_has_basis).2 _,
rintro V ⟨hVB, hxV⟩,
rcases hB.exists_closure_subset (hB.mem_nhds hVB hxV) with ⟨U, hUB, hxU, hUV⟩,
set UV : ↥s := ⟨(U, V), ⟨hUB, hVB⟩, hUV⟩,
refine ⟨ε UV, (ε01 UV).1, λ y (hy : dist (F y) (F x) < ε UV), _⟩,
replace hy : dist (F y UV) (F x UV) < ε UV,
from (bounded_continuous_function.dist_coe_le_dist _).trans_lt hy,
contrapose! hy,
rw [hF, hF, hfε UV hy, hf0 UV hxU, pi.zero_apply, dist_zero_right],
exact le_abs_self _ },
{ /- Finally, we prove that `F` is continuous. Given `δ > 0`, consider the set `T` of `(U, V) ∈ s`
such that `ε (U, V) ≥ δ`. Since `ε` tends to zero, `T` is finite. Since each `f` is continuous,
we can choose a neighborhood such that `dist (F y (U, V)) (F x (U, V)) ≤ δ` for any
`(U, V) ∈ T`. For `(U, V) ∉ T`, the same inequality is true because both `F y (U, V)` and
`F x (U, V)` belong to the interval `[0, ε (U, V)]`. -/
refine (nhds_basis_closed_ball.comap _).ge_iff.2 (λ δ δ0, _),
have h_fin : {UV : s | δ ≤ ε UV}.finite, by simpa only [← not_lt] using hε (gt_mem_nhds δ0),
have : ∀ᶠ y in 𝓝 x, ∀ UV, δ ≤ ε UV → dist (F y UV) (F x UV) ≤ δ,
{ refine (eventually_all_finite h_fin).2 (λ UV hUV, _),
exact (f UV).continuous.tendsto x (closed_ball_mem_nhds _ δ0) },
refine this.mono (λ y hy, (bounded_continuous_function.dist_le δ0.le).2 $ λ UV, _),
cases le_total δ (ε UV) with hle hle,
exacts [hy _ hle, (real.dist_le_of_mem_Icc (hf0ε _ _) (hf0ε _ _)).trans (by rwa sub_zero)] }
end
/-- *Urysohn's metrization theorem* (Tychonoff's version): a T₃ topological space with second
countable topology `X` is metrizable, i.e., there exists a metric space structure that generates the
same topology. -/
lemma metrizable_space_of_t3_second_countable : metrizable_space X :=
let ⟨f, hf⟩ := exists_embedding_l_infty X in hf.metrizable_space
instance : metrizable_space ennreal := metrizable_space_of_t3_second_countable ennreal
end topological_space
|
84d467c0e0226f4a6dfe204392fd9658bc3702bc
|
9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e
|
/src/undergraduate/MAS114/Semester 1/Q18.lean
|
11d17b5d4b4b0953a047a2fb883a472a3e5cb460
|
[] |
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
| 1,192
|
lean
|
import data.int.basic tactic.ring
namespace MAS114
namespace exercises_1
namespace Q18
variables (a b c d : ℤ)
lemma L_i : a ∣ b → b ∣ c → a ∣ c :=
begin
rintros ⟨uab,hab⟩ ⟨ubc,hbc⟩,
use uab * ubc,
rw[← mul_assoc,← hab,← hbc],
end
lemma L_ii : a ∣ b → a ∣ c → a ∣ (b + c) :=
begin
rintros ⟨uab,hab⟩ ⟨uac,hac⟩,
use uab + uac,
rw[mul_add,hab,hac],
end
lemma L_iii_false : ¬ (∀ a b c : ℤ, (a ∣ (b + c)) → (a ∣ b) ∧ (a ∣ c)) :=
begin
intro h0,
have h1 : (2 : ℤ) ∣ 1 := (h0 2 1 1 dec_trivial).left,
have h2 : ¬ ((2 : ℤ) ∣ 1) := dec_trivial,
exact h2 h1,
end
lemma L_iv : a ∣ b → a ∣ c → a ∣ (b * c) :=
begin
rintros ⟨uab,hab⟩ ⟨uac,hac⟩,
use uab * c,
rw[← mul_assoc,hab]
end
lemma L_v_false : ¬ (∀ a b c : ℤ, (a ∣ (b * c)) → (a ∣ b) ∧ (a ∣ c)) :=
begin
intro h0,
have h1 : (4 : ℤ) ∣ 2 := (h0 4 2 2 dec_trivial).left,
have h2 : ¬ ((4 : ℤ) ∣ 2) := dec_trivial,
exact h2 h1,
end
lemma L_vi : a ∣ b → c ∣ d → (a * c) ∣ (b * d) :=
begin
rintros ⟨uab,hab⟩ ⟨ucd,hcd⟩,
use uab * ucd,
rw[hab,hcd],
ring
end
end Q18
end exercises_1
end MAS114
|
f3133cc59508eee2047add65030d7d345cb27c30
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/set/constructions.lean
|
2c46bacbb68d9ba773839a101588d02efc2842b6
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,865
|
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 data.finset.basic
/-!
# Constructions involving sets of sets.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Finite Intersections
We define a structure `has_finite_inter` which asserts that a set `S` of subsets of `α` is
closed under finite intersections.
We define `finite_inter_closure` which, given a set `S` of subsets of `α`, is the smallest
set of subsets of `α` which is closed under finite intersections.
`finite_inter_closure S` is endowed with a term of type `has_finite_inter` using
`finite_inter_closure_has_finite_inter`.
-/
variables {α : Type*} (S : set (set α))
/-- A structure encapsulating the fact that a set of sets is closed under finite intersection. -/
structure has_finite_inter : Prop :=
(univ_mem : set.univ ∈ S)
(inter_mem : ∀ ⦃s⦄, s ∈ S → ∀ ⦃t⦄, t ∈ S → s ∩ t ∈ S)
namespace has_finite_inter
/-- The smallest set of sets containing `S` which is closed under finite intersections. -/
inductive finite_inter_closure : set (set α)
| basic {s} : s ∈ S → finite_inter_closure s
| univ : finite_inter_closure set.univ
| inter {s t} : finite_inter_closure s → finite_inter_closure t → finite_inter_closure (s ∩ t)
lemma finite_inter_closure_has_finite_inter : has_finite_inter (finite_inter_closure S) :=
{ univ_mem := finite_inter_closure.univ,
inter_mem := λ _ h _, finite_inter_closure.inter h }
variable {S}
lemma finite_inter_mem (cond : has_finite_inter S) (F : finset (set α)) :
↑F ⊆ S → ⋂₀ (↑F : set (set α)) ∈ S :=
begin
classical,
refine finset.induction_on F (λ _, _) _,
{ simp [cond.univ_mem] },
{ intros a s h1 h2 h3,
suffices : a ∩ ⋂₀ ↑s ∈ S, by simpa,
exact cond.inter_mem (h3 (finset.mem_insert_self a s))
(h2 $ λ x hx, h3 $ finset.mem_insert_of_mem hx) }
end
lemma finite_inter_closure_insert {A : set α} (cond : has_finite_inter S)
(P ∈ finite_inter_closure (insert A S)) : P ∈ S ∨ ∃ Q ∈ S, P = A ∩ Q :=
begin
induction H with S h T1 T2 _ _ h1 h2,
{ cases h,
{ exact or.inr ⟨set.univ, cond.univ_mem, by simpa⟩ },
{ exact or.inl h } },
{ exact or.inl cond.univ_mem },
{ rcases h1 with (h | ⟨Q, hQ, rfl⟩); rcases h2 with (i | ⟨R, hR, rfl⟩),
{ exact or.inl (cond.inter_mem h i) },
{ exact or.inr ⟨T1 ∩ R, cond.inter_mem h hR,
by simp only [ ←set.inter_assoc, set.inter_comm _ A]⟩ },
{ exact or.inr ⟨Q ∩ T2, cond.inter_mem hQ i, by simp only [set.inter_assoc]⟩ },
{ exact or.inr ⟨Q ∩ R, cond.inter_mem hQ hR,
by { ext x, split; simp { contextual := tt} }⟩ } }
end
end has_finite_inter
|
5bba1995a505c73bcccb830b206214c168fee352
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/interactive_expr_auto.lean
|
91a79cf72ac16fc6b4e8cce606d3df394742a49e
|
[] |
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,120
|
lean
|
/-
Copyright (c) 2020 E.W.Ayers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: E.W.Ayers
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.PostPort
namespace Mathlib
/-!
# Widgets used for tactic state and term-mode goal display
The vscode extension supports the display of interactive widgets.
Default implementation of these widgets are included in the core
library. We override them here using `vm_override` so that we can
change them quickly without waiting for the next Lean release.
The function `widget_override.interactive_expression.mk` renders a single
expression as a widget component. Each goal in a tactic state is rendered
using the `widget_override.tactic_view_goal` function,
a complete tactic state is rendered using
`widget_override.tactic_view_component`.
Lean itself calls the `widget_override.term_goal_widget` function to render
term-mode goals and `widget_override.tactic_state_widget` to render the
tactic state in a tactic proof.
-/
namespace widget_override
namespace interactive_expression
end Mathlib
|
22bf8df132a7b1e1c410213aad8ace6c5820cc55
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/src/Init/Control/Lawful.lean
|
ab1848d88d54394de811aed7aa55c407ff597106
|
[
"Apache-2.0"
] |
permissive
|
WojciechKarpiel/lean4
|
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
|
f6e1314fa08293dea66a329e05b6c196a0189163
|
refs/heads/master
| 1,686,633,402,214
| 1,625,821,189,000
| 1,625,821,258,000
| 384,640,886
| 0
| 0
|
Apache-2.0
| 1,625,903,617,000
| 1,625,903,026,000
| null |
UTF-8
|
Lean
| false
| false
| 14,444
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich, Leonardo de Moura
-/
prelude
import Init.SimpLemmas
import Init.Control.Except
import Init.Control.StateRef
open Function
@[simp] theorem monadLift_self [Monad m] (x : m α) : monadLift x = x :=
rfl
class LawfulFunctor (f : Type u → Type v) [Functor f] : Prop where
map_const : (Functor.mapConst : α → f β → f α) = Functor.map ∘ const β
id_map (x : f α) : id <$> x = x
comp_map (g : α → β) (h : β → γ) (x : f α) : (h ∘ g) <$> x = h <$> g <$> x
export LawfulFunctor (map_const id_map comp_map)
attribute [simp] id_map
@[simp] theorem id_map' [Functor m] [LawfulFunctor m] (x : m α) : (fun a => a) <$> x = x :=
id_map x
class LawfulApplicative (f : Type u → Type v) [Applicative f] extends LawfulFunctor f : Prop where
seqLeft_eq (x : f α) (y : f β) : x <* y = const β <$> x <*> y
seqRight_eq (x : f α) (y : f β) : x *> y = const α id <$> x <*> y
pure_seq (g : α → β) (x : f α) : pure g <*> x = g <$> x
map_pure (g : α → β) (x : α) : g <$> (pure x : f α) = pure (g x)
seq_pure {α β : Type u} (g : f (α → β)) (x : α) : g <*> pure x = (fun h => h x) <$> g
seq_assoc {α β γ : Type u} (x : f α) (g : f (α → β)) (h : f (β → γ)) : h <*> (g <*> x) = ((@comp α β γ) <$> h) <*> g <*> x
comp_map g h x := by
repeat rw [← pure_seq]
simp [seq_assoc, map_pure, seq_pure]
export LawfulApplicative (seqLeft_eq seqRight_eq pure_seq map_pure seq_pure seq_assoc)
attribute [simp] map_pure seq_pure
@[simp] theorem pure_id_seq [Applicative f] [LawfulApplicative f] (x : f α) : pure id <*> x = x := by
simp [pure_seq]
class LawfulMonad (m : Type u → Type v) [Monad m] extends LawfulApplicative m : Prop where
bind_pure_comp (f : α → β) (x : m α) : x >>= pure ∘ f = f <$> x
bind_map {α β : Type u} (f : m (α → β)) (x : m α) : f >>= (. <$> x) = f <*> x
pure_bind (x : α) (f : α → m β) : pure x >>= f = f x
bind_assoc (x : m α) (f : α → m β) (g : β → m γ) : x >>= f >>= g = x >>= fun x => f x >>= g
map_pure g x := by rw [← bind_pure_comp, pure_bind]
seq_pure g x := by rw [← bind_map]; simp [map_pure, bind_pure_comp]
seq_assoc x g h := by
-- TODO: support for applying `symm` at `simp` arguments
let bind_pure_comp_symm {α β : Type u} (f : α → β) (x : m α) : f <$> x = x >>= pure ∘ f := by
rw [bind_pure_comp]
let bind_map_symm {α β : Type u} (f : m (α → (β : Type u))) (x : m α) : f <*> x = f >>= (. <$> x) := by
rw [bind_map]
simp[bind_pure_comp_symm, bind_map_symm, bind_assoc, pure_bind]
export LawfulMonad (bind_pure_comp bind_map pure_bind bind_assoc)
attribute [simp] pure_bind bind_assoc
@[simp] theorem bind_pure [Monad m] [LawfulMonad m] (x : m α) : x >>= pure = x := by
show x >>= pure ∘ id = x
rw [bind_pure_comp, id_map]
theorem map_eq_pure_bind [Monad m] [LawfulMonad m] (f : α → β) (x : m α) : f <$> x = x >>= fun a => pure (f a) := by
rw [← bind_pure_comp]
theorem seq_eq_bind_map {α β : Type u} [Monad m] [LawfulMonad m] (f : m (α → β)) (x : m α) : f <*> x = f >>= (. <$> x) := by
rw [← bind_map]
theorem bind_congr [Bind m] {x : m α} {f g : α → m β} (h : ∀ a, f a = g a) : x >>= f = x >>= g := by
simp [funext h]
@[simp] theorem bind_pure_unit [Monad m] [LawfulMonad m] {x : m PUnit} : (x >>= fun _ => pure ⟨⟩) = x := by
have : (x >>= fun _ => pure ⟨⟩) = (x >>= pure) := by
apply bind_congr; intro u
cases u; simp
rw [bind_pure] at this
assumption
theorem map_congr [Functor m] {x : m α} {f g : α → β} (h : ∀ a, f a = g a) : (f <$> x : m β) = g <$> x := by
simp [funext h]
theorem seq_eq_bind {α β : Type u} [Monad m] [LawfulMonad m] (mf : m (α → β)) (x : m α) : mf <*> x = mf >>= fun f => f <$> x := by
rw [bind_map]
theorem seqRight_eq_bind [Monad m] [LawfulMonad m] (x : m α) (y : m β) : x *> y = x >>= fun _ => y := by
rw [seqRight_eq]; simp [map_eq_pure_bind, seq_eq_bind_map]
theorem seqLeft_eq_bind [Monad m] [LawfulMonad m] (x : m α) (y : m β) : x <* y = x >>= fun a => y >>= fun _ => pure a := by
rw [seqLeft_eq]; simp [map_eq_pure_bind, seq_eq_bind_map]
/- Id -/
namespace Id
@[simp] theorem map_eq (x : Id α) (f : α → β) : f <$> x = f x := rfl
@[simp] theorem bind_eq (x : Id α) (f : α → id β) : x >>= f = f x := rfl
@[simp] theorem pure_eq (a : α) : (pure a : Id α) = a := rfl
instance : LawfulMonad Id := by
refine' { .. } <;> intros <;> rfl
end Id
/- ExceptT -/
namespace ExceptT
theorem ext [Monad m] {x y : ExceptT ε m α} (h : x.run = y.run) : x = y := by
simp [run] at h
assumption
@[simp] theorem run_pure [Monad m] : run (pure x : ExceptT ε m α) = pure (Except.ok x) := rfl
@[simp] theorem run_lift [Monad m] (x : m α) : run (ExceptT.lift x : ExceptT ε m α) = (Except.ok <$> x : m (Except ε α)) := rfl
@[simp] theorem run_throw [Monad m] : run (throw e : ExceptT ε m β) = pure (Except.error e) := rfl
@[simp] theorem run_bind_lift [Monad m] [LawfulMonad m] (x : m α) (f : α → ExceptT ε m β) : run (ExceptT.lift x >>= f : ExceptT ε m β) = x >>= fun a => run (f a) := by
simp[ExceptT.run, ExceptT.lift, bind, ExceptT.bind, ExceptT.mk, ExceptT.bindCont, map_eq_pure_bind]
@[simp] theorem bind_throw [Monad m] [LawfulMonad m] (f : α → ExceptT ε m β) : (throw e >>= f) = throw e := by
simp [throw, throwThe, MonadExceptOf.throw, bind, ExceptT.bind, ExceptT.bindCont, ExceptT.mk]
theorem run_bind [Monad m] (x : ExceptT ε m α)
: run (x >>= f : ExceptT ε m β)
=
run x >>= fun
| Except.ok x => run (f x)
| Except.error e => pure (Except.error e) :=
rfl
@[simp] theorem lift_pure [Monad m] [LawfulMonad m] (a : α) : ExceptT.lift (pure a) = (pure a : ExceptT ε m α) := by
simp [ExceptT.lift, pure, ExceptT.pure]
@[simp] theorem run_map [Monad m] [LawfulMonad m] (f : α → β) (x : ExceptT ε m α)
: (f <$> x).run = Except.map f <$> x.run := by
simp [Functor.map, ExceptT.map, map_eq_pure_bind]
apply bind_congr
intro a; cases a <;> simp [Except.map]
protected theorem seq_eq {α β ε : Type u} [Monad m] (mf : ExceptT ε m (α → β)) (x : ExceptT ε m α) : mf <*> x = mf >>= fun f => f <$> x :=
rfl
protected theorem bind_pure_comp [Monad m] [LawfulMonad m] (f : α → β) (x : ExceptT ε m α) : x >>= pure ∘ f = f <$> x := by
intros; rfl
protected theorem seqLeft_eq {α β ε : Type u} {m : Type u → Type v} [Monad m] [LawfulMonad m] (x : ExceptT ε m α) (y : ExceptT ε m β) : x <* y = const β <$> x <*> y := by
show (x >>= fun a => y >>= fun _ => pure a) = (const (α := α) β <$> x) >>= fun f => f <$> y
rw [← ExceptT.bind_pure_comp]
apply ext
simp [run_bind]
apply bind_congr
intro
| Except.error _ => simp
| Except.ok _ =>
simp [map_eq_pure_bind]; apply bind_congr; intro b;
cases b <;> simp [comp, Except.map, const]
protected theorem seqRight_eq [Monad m] [LawfulMonad m] (x : ExceptT ε m α) (y : ExceptT ε m β) : x *> y = const α id <$> x <*> y := by
show (x >>= fun _ => y) = (const α id <$> x) >>= fun f => f <$> y
rw [← ExceptT.bind_pure_comp]
apply ext
simp [run_bind]
apply bind_congr
intro a; cases a <;> simp
instance [Monad m] [LawfulMonad m] : LawfulMonad (ExceptT ε m) where
id_map := by intros; apply ext; simp
map_const := by intros; rfl
seqLeft_eq := ExceptT.seqLeft_eq
seqRight_eq := ExceptT.seqRight_eq
pure_seq := by intros; apply ext; simp [ExceptT.seq_eq, run_bind]
bind_pure_comp := ExceptT.bind_pure_comp
bind_map := by intros; rfl
pure_bind := by intros; apply ext; simp [run_bind]
bind_assoc := by intros; apply ext; simp [run_bind]; apply bind_congr; intro a; cases a <;> simp
end ExceptT
/- ReaderT -/
namespace ReaderT
theorem ext [Monad m] {x y : ReaderT ρ m α} (h : ∀ ctx, x.run ctx = y.run ctx) : x = y := by
simp [run] at h
exact funext h
@[simp] theorem run_pure [Monad m] (a : α) (ctx : ρ) : (pure a : ReaderT ρ m α).run ctx = pure a := rfl
@[simp] theorem run_bind [Monad m] (x : ReaderT ρ m α) (f : α → ReaderT ρ m β) (ctx : ρ)
: (x >>= f).run ctx = x.run ctx >>= λ a => (f a).run ctx := rfl
@[simp] theorem run_map [Monad m] (f : α → β) (x : ReaderT ρ m α) (ctx : ρ)
: (f <$> x).run ctx = f <$> x.run ctx := rfl
@[simp] theorem run_monadLift [MonadLiftT n m] (x : n α) (ctx : ρ)
: (monadLift x : ReaderT ρ m α).run ctx = (monadLift x : m α) := rfl
@[simp] theorem run_monadMap [Monad m] [MonadFunctor n m] (f : {β : Type u} → n β → n β) (x : ReaderT ρ m α) (ctx : ρ)
: (monadMap @f x : ReaderT ρ m α).run ctx = monadMap @f (x.run ctx) := rfl
@[simp] theorem run_read [Monad m] (ctx : ρ) : (ReaderT.read : ReaderT ρ m ρ).run ctx = pure ctx := rfl
@[simp] theorem run_seq {α β : Type u} [Monad m] [LawfulMonad m] (f : ReaderT ρ m (α → β)) (x : ReaderT ρ m α) (ctx : ρ) : (f <*> x).run ctx = (f.run ctx <*> x.run ctx) := by
rw [seq_eq_bind (m := m)]; rfl
@[simp] theorem run_seqRight [Monad m] [LawfulMonad m] (x : ReaderT ρ m α) (y : ReaderT ρ m β) (ctx : ρ) : (x *> y).run ctx = (x.run ctx *> y.run ctx) := by
rw [seqRight_eq_bind (m := m)]; rfl
@[simp] theorem run_seqLeft [Monad m] [LawfulMonad m] (x : ReaderT ρ m α) (y : ReaderT ρ m β) (ctx : ρ) : (x <* y).run ctx = (x.run ctx <* y.run ctx) := by
rw [seqLeft_eq_bind (m := m)]; rfl
instance [Monad m] [LawfulMonad m] : LawfulMonad (ReaderT ρ m) where
id_map := by intros; apply ext; intros; simp
map_const := by intros; rfl
seqLeft_eq := by intros; apply ext; intros; simp; apply LawfulApplicative.seqLeft_eq
seqRight_eq := by intros; apply ext; intros; simp; apply LawfulApplicative.seqRight_eq
pure_seq := by intros; apply ext; intros; simp; apply LawfulApplicative.pure_seq
bind_pure_comp := by intros; apply ext; intros; simp; apply LawfulMonad.bind_pure_comp
bind_map := by intros; rfl
pure_bind := by intros; apply ext; intros; simp
bind_assoc := by intros; apply ext; intros; simp
end ReaderT
/- StateRefT -/
instance [Monad m] [LawfulMonad m] : LawfulMonad (StateRefT' ω σ m) :=
inferInstanceAs (LawfulMonad (ReaderT (ST.Ref ω σ) m))
/- StateT -/
namespace StateT
theorem ext {x y : StateT σ m α} (h : ∀ s, x.run s = y.run s) : x = y :=
funext h
@[simp] theorem run'_eq [Monad m] (x : StateT σ m α) (s : σ) : run' x s = (·.1) <$> run x s :=
rfl
@[simp] theorem run_pure [Monad m] (a : α) (s : σ) : (pure a : StateT σ m α).run s = pure (a, s) := rfl
@[simp] theorem run_bind [Monad m] (x : StateT σ m α) (f : α → StateT σ m β) (s : σ)
: (x >>= f).run s = x.run s >>= λ p => (f p.1).run p.2 := by
simp [bind, StateT.bind, run]
apply bind_congr
intro p; cases p; rfl
@[simp] theorem run_map {α β σ : Type u} [Monad m] [LawfulMonad m] (f : α → β) (x : StateT σ m α) (s : σ) : (f <$> x).run s = (fun (p : α × σ) => (f p.1, p.2)) <$> x.run s := by
simp [Functor.map, StateT.map, run, map_eq_pure_bind]
apply bind_congr
intro p; cases p; rfl
@[simp] theorem run_get [Monad m] (s : σ) : (get : StateT σ m σ).run s = pure (s, s) := rfl
@[simp] theorem run_set [Monad m] (s s' : σ) : (set s' : StateT σ m PUnit).run s = pure (⟨⟩, s') := rfl
@[simp] theorem run_modify [Monad m] (f : σ → σ) (s : σ) : (modify f : StateT σ m PUnit).run s = pure (⟨⟩, f s) := rfl
@[simp] theorem run_modifyGet [Monad m] (f : σ → α × σ) (s : σ) : (modifyGet f : StateT σ m α).run s = pure ((f s).1, (f s).2) := by
simp [modifyGet, MonadStateOf.modifyGet, StateT.modifyGet, run]; cases f s <;> rfl
@[simp] theorem run_lift {α σ : Type u} [Monad m] (x : m α) (s : σ) : (StateT.lift x : StateT σ m α).run s = x >>= fun a => pure (a, s) := rfl
@[simp] theorem run_bind_lift {α σ : Type u} [Monad m] [LawfulMonad m] (x : m α) (f : α → StateT σ m β) (s : σ) : (StateT.lift x >>= f).run s = x >>= fun a => (f a).run s := by
simp [StateT.lift, StateT.run, bind, StateT.bind]
@[simp] theorem run_monadLift {α σ : Type u} [Monad m] [MonadLiftT n m] (x : n α) (s : σ) : (monadLift x : StateT σ m α).run s = (monadLift x : m α) >>= fun a => pure (a, s) := rfl
@[simp] theorem run_monadMap [Monad m] [MonadFunctor n m] (f : {β : Type u} → n β → n β) (x : StateT σ m α) (s : σ)
: (monadMap @f x : StateT σ m α).run s = monadMap @f (x.run s) := rfl
@[simp] theorem run_seq {α β σ : Type u} [Monad m] [LawfulMonad m] (f : StateT σ m (α → β)) (x : StateT σ m α) (s : σ) : (f <*> x).run s = (f.run s >>= fun fs => (fun (p : α × σ) => (fs.1 p.1, p.2)) <$> x.run fs.2) := by
show (f >>= fun g => g <$> x).run s = _
simp
@[simp] theorem run_seqRight [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x *> y).run s = (x.run s >>= fun p => y.run p.2) := by
show (x >>= fun _ => y).run s = _
simp
@[simp] theorem run_seqLeft {α β σ : Type u} [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) (s : σ) : (x <* y).run s = (x.run s >>= fun p => y.run p.2 >>= fun p' => pure (p.1, p'.2)) := by
show (x >>= fun a => y >>= fun _ => pure a).run s = _
simp
theorem seqRight_eq [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) : x *> y = const α id <$> x <*> y := by
apply ext; intro s
simp [map_eq_pure_bind]
apply bind_congr; intro p; cases p
simp [Prod.ext]
theorem seqLeft_eq [Monad m] [LawfulMonad m] (x : StateT σ m α) (y : StateT σ m β) : x <* y = const β <$> x <*> y := by
apply ext; intro s
simp [map_eq_pure_bind]
instance [Monad m] [LawfulMonad m] : LawfulMonad (StateT σ m) where
id_map := by intros; apply ext; intros; simp[Prod.ext]
map_const := by intros; rfl
seqLeft_eq := seqLeft_eq
seqRight_eq := seqRight_eq
pure_seq := by intros; apply ext; intros; simp
bind_pure_comp := by intros; apply ext; intros; simp; apply LawfulMonad.bind_pure_comp
bind_map := by intros; rfl
pure_bind := by intros; apply ext; intros; simp
bind_assoc := by intros; apply ext; intros; simp
end StateT
|
44898c35ca1d09420f0027c9bb5d1fa85d989a6d
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/real/irrational.lean
|
4a55f51166043047d5c1a25f28165fe434bfc1a3
|
[] |
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
| 7,247
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Yury Kudryashov.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.real.sqrt
import Mathlib.data.rat.sqrt
import Mathlib.ring_theory.int.basic
import Mathlib.data.polynomial.eval
import Mathlib.data.polynomial.degree.default
import Mathlib.tactic.interval_cases
import Mathlib.PostPort
namespace Mathlib
/-!
# Irrational real numbers
In this file we define a predicate `irrational` on `ℝ`, prove that the `n`-th root of an integer
number is irrational if it is not integer, and that `sqrt q` is irrational if and only if
`rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q`.
We also provide dot-style constructors like `irrational.add_rat`, `irrational.rat_sub` etc.
-/
/-- A real number is irrational if it is not equal to any rational number. -/
def irrational (x : ℝ) :=
¬x ∈ set.range coe
theorem irrational_iff_ne_rational (x : ℝ) : irrational x ↔ ∀ (a b : ℤ), x ≠ ↑a / ↑b := sorry
/-!
### Irrationality of roots of integer and rational numbers
-/
/-- If `x^n`, `n > 0`, is integer and is not the `n`-th power of an integer, then
`x` is irrational. -/
theorem irrational_nrt_of_notint_nrt {x : ℝ} (n : ℕ) (m : ℤ) (hxr : x ^ n = ↑m) (hv : ¬∃ (y : ℤ), x = ↑y) (hnpos : 0 < n) : irrational x := sorry
/-- If `x^n = m` is an integer and `n` does not divide the `multiplicity p m`, then `x`
is irrational. -/
theorem irrational_nrt_of_n_not_dvd_multiplicity {x : ℝ} (n : ℕ) {m : ℤ} (hm : m ≠ 0) (p : ℕ) [hp : fact (nat.prime p)] (hxr : x ^ n = ↑m) (hv : roption.get (multiplicity (↑p) m) (iff.mpr multiplicity.finite_int_iff { left := nat.prime.ne_one hp, right := hm }) %
n ≠
0) : irrational x := sorry
theorem irrational_sqrt_of_multiplicity_odd (m : ℤ) (hm : 0 < m) (p : ℕ) [hp : fact (nat.prime p)] (Hpv : roption.get (multiplicity (↑p) m)
(iff.mpr multiplicity.finite_int_iff { left := nat.prime.ne_one hp, right := ne.symm (ne_of_lt hm) }) %
bit0 1 =
1) : irrational (real.sqrt ↑m) := sorry
theorem nat.prime.irrational_sqrt {p : ℕ} (hp : nat.prime p) : irrational (real.sqrt ↑p) := sorry
theorem irrational_sqrt_two : irrational (real.sqrt (bit0 1)) := sorry
theorem irrational_sqrt_rat_iff (q : ℚ) : irrational (real.sqrt ↑q) ↔ rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q := sorry
protected instance irrational.decidable (q : ℚ) : Decidable (irrational (real.sqrt ↑q)) :=
decidable_of_iff' (rat.sqrt q * rat.sqrt q ≠ q ∧ 0 ≤ q) (irrational_sqrt_rat_iff q)
/-!
### Adding/subtracting/multiplying by rational numbers
-/
theorem rat.not_irrational (q : ℚ) : ¬irrational ↑q :=
fun (h : irrational ↑q) => h (Exists.intro q rfl)
namespace irrational
theorem add_cases {x : ℝ} {y : ℝ} : irrational (x + y) → irrational x ∨ irrational y := sorry
theorem of_rat_add (q : ℚ) {x : ℝ} (h : irrational (↑q + x)) : irrational x :=
or.elim (add_cases h) (fun (h : irrational ↑q) => absurd h (rat.not_irrational q)) id
theorem rat_add (q : ℚ) {x : ℝ} (h : irrational x) : irrational (↑q + x) :=
of_rat_add (-q)
(eq.mpr (id (Eq._oldrec (Eq.refl (irrational (↑(-q) + (↑q + x)))) (rat.cast_neg q)))
(eq.mpr (id (Eq._oldrec (Eq.refl (irrational (-↑q + (↑q + x)))) (neg_add_cancel_left (↑q) x))) h))
theorem of_add_rat (q : ℚ) {x : ℝ} : irrational (x + ↑q) → irrational x :=
add_comm (↑q) x ▸ of_rat_add q
theorem add_rat (q : ℚ) {x : ℝ} (h : irrational x) : irrational (x + ↑q) :=
add_comm (↑q) x ▸ rat_add q h
theorem of_neg {x : ℝ} (h : irrational (-x)) : irrational x := sorry
protected theorem neg {x : ℝ} (h : irrational x) : irrational (-x) :=
of_neg (eq.mpr (id (Eq._oldrec (Eq.refl (irrational ( --x))) (neg_neg x))) h)
theorem sub_rat (q : ℚ) {x : ℝ} (h : irrational x) : irrational (x - ↑q) := sorry
theorem rat_sub (q : ℚ) {x : ℝ} (h : irrational x) : irrational (↑q - x) :=
eq.mpr (id ((fun (x x_1 : ℝ) (e_1 : x = x_1) => congr_arg irrational e_1) (↑q - x) (↑q + -x) (sub_eq_add_neg (↑q) x)))
(eq.mp (Eq.refl (irrational (↑q + -x))) (rat_add q (irrational.neg h)))
theorem of_sub_rat (q : ℚ) {x : ℝ} (h : irrational (x - ↑q)) : irrational x := sorry
theorem of_rat_sub (q : ℚ) {x : ℝ} (h : irrational (↑q - x)) : irrational x := sorry
theorem mul_cases {x : ℝ} {y : ℝ} : irrational (x * y) → irrational x ∨ irrational y := sorry
theorem of_mul_rat (q : ℚ) {x : ℝ} (h : irrational (x * ↑q)) : irrational x :=
or.elim (mul_cases h) id fun (h : irrational ↑q) => absurd h (rat.not_irrational q)
theorem mul_rat {x : ℝ} (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (x * ↑q) := sorry
theorem of_rat_mul (q : ℚ) {x : ℝ} : irrational (↑q * x) → irrational x :=
mul_comm x ↑q ▸ of_mul_rat q
theorem rat_mul {x : ℝ} (h : irrational x) {q : ℚ} (hq : q ≠ 0) : irrational (↑q * x) :=
mul_comm x ↑q ▸ mul_rat h hq
theorem of_mul_self {x : ℝ} (h : irrational (x * x)) : irrational x :=
or.elim (mul_cases h) id id
theorem of_inv {x : ℝ} (h : irrational (x⁻¹)) : irrational x := sorry
protected theorem inv {x : ℝ} (h : irrational x) : irrational (x⁻¹) :=
of_inv (eq.mpr (id (Eq._oldrec (Eq.refl (irrational (x⁻¹⁻¹))) (inv_inv' x))) h)
theorem div_cases {x : ℝ} {y : ℝ} (h : irrational (x / y)) : irrational x ∨ irrational y :=
or.imp id of_inv (mul_cases h)
theorem of_rat_div (q : ℚ) {x : ℝ} (h : irrational (↑q / x)) : irrational x :=
of_inv (of_rat_mul q h)
theorem of_one_div {x : ℝ} (h : irrational (1 / x)) : irrational x :=
of_rat_div 1 (eq.mpr (id (Eq._oldrec (Eq.refl (irrational (↑1 / x))) rat.cast_one)) h)
theorem of_pow {x : ℝ} (n : ℕ) : irrational (x ^ n) → irrational x := sorry
theorem of_fpow {x : ℝ} (m : ℤ) : irrational (x ^ m) → irrational x := sorry
end irrational
theorem one_lt_nat_degree_of_irrational_root (x : ℝ) (p : polynomial ℤ) (hx : irrational x) (p_nonzero : p ≠ 0) (x_is_root : coe_fn (polynomial.aeval x) p = 0) : 1 < polynomial.nat_degree p := sorry
@[simp] theorem irrational_rat_add_iff {q : ℚ} {x : ℝ} : irrational (↑q + x) ↔ irrational x :=
{ mp := irrational.of_rat_add q, mpr := irrational.rat_add q }
@[simp] theorem irrational_add_rat_iff {q : ℚ} {x : ℝ} : irrational (x + ↑q) ↔ irrational x :=
{ mp := irrational.of_add_rat q, mpr := irrational.add_rat q }
@[simp] theorem irrational_rat_sub_iff {q : ℚ} {x : ℝ} : irrational (↑q - x) ↔ irrational x :=
{ mp := irrational.of_rat_sub q, mpr := irrational.rat_sub q }
@[simp] theorem irrational_sub_rat_iff {q : ℚ} {x : ℝ} : irrational (x - ↑q) ↔ irrational x :=
{ mp := irrational.of_sub_rat q, mpr := irrational.sub_rat q }
@[simp] theorem irrational_neg_iff {x : ℝ} : irrational (-x) ↔ irrational x :=
{ mp := irrational.of_neg, mpr := irrational.neg }
@[simp] theorem irrational_inv_iff {x : ℝ} : irrational (x⁻¹) ↔ irrational x :=
{ mp := irrational.of_inv, mpr := irrational.inv }
|
db2a2534c8efd0aaafd4c6d331cbc15c5776e716
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/linear_algebra/affine_space/affine_equiv.lean
|
7177d57104ed53a133e11f72824738e50aa251a4
|
[
"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
| 17,546
|
lean
|
/-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import linear_algebra.affine_space.affine_map
import algebra.invertible
/-!
# Affine equivalences
In this file we define `affine_equiv k P₁ P₂` (notation: `P₁ ≃ᵃ[k] P₂`) to be the type of affine
equivalences between `P₁` and `P₂, i.e., equivalences such that both forward and inverse maps are
affine maps.
We define the following equivalences:
* `affine_equiv.refl k P`: the identity map as an `affine_equiv`;
* `e.symm`: the inverse map of an `affine_equiv` as an `affine_equiv`;
* `e.trans e'`: composition of two `affine_equiv`s; note that the order follows `mathlib`'s
`category_theory` convention (apply `e`, then `e'`), not the convention used in function
composition and compositions of bundled morphisms.
We equip `affine_equiv k P P` with a `group` structure with multiplication corresponding to
composition in `affine_equiv.group`.
## Tags
affine space, affine equivalence
-/
open function set
open_locale affine
/-- An affine equivalence is an equivalence between affine spaces such that both forward
and inverse maps are affine.
We define it using an `equiv` for the map and a `linear_equiv` for the linear part in order
to allow affine equivalences with good definitional equalities. -/
@[nolint has_inhabited_instance]
structure affine_equiv (k P₁ P₂ : Type*) {V₁ V₂ : Type*} [ring k]
[add_comm_group V₁] [module k V₁] [add_torsor V₁ P₁]
[add_comm_group V₂] [module k V₂] [add_torsor V₂ P₂] extends P₁ ≃ P₂ :=
(linear : V₁ ≃ₗ[k] V₂)
(map_vadd' : ∀ (p : P₁) (v : V₁), to_equiv (v +ᵥ p) = linear v +ᵥ to_equiv p)
notation P₁ ` ≃ᵃ[`:25 k:25 `] `:0 P₂:0 := affine_equiv k P₁ P₂
variables {k P₁ P₂ P₃ P₄ V₁ V₂ V₃ V₄ : Type*} [ring k]
[add_comm_group V₁] [module k V₁] [add_torsor V₁ P₁]
[add_comm_group V₂] [module k V₂] [add_torsor V₂ P₂]
[add_comm_group V₃] [module k V₃] [add_torsor V₃ P₃]
[add_comm_group V₄] [module k V₄] [add_torsor V₄ P₄]
namespace affine_equiv
include V₁ V₂
instance : has_coe_to_fun (P₁ ≃ᵃ[k] P₂) (λ _, P₁ → P₂) := ⟨λ e, e.to_fun⟩
instance : has_coe (P₁ ≃ᵃ[k] P₂) (P₁ ≃ P₂) := ⟨affine_equiv.to_equiv⟩
variables {k P₁}
@[simp] lemma map_vadd (e : P₁ ≃ᵃ[k] P₂) (p : P₁) (v : V₁) : e (v +ᵥ p) = e.linear v +ᵥ e p :=
e.map_vadd' p v
@[simp] lemma coe_to_equiv (e : P₁ ≃ᵃ[k] P₂) : ⇑e.to_equiv = e := rfl
/-- Reinterpret an `affine_equiv` as an `affine_map`. -/
def to_affine_map (e : P₁ ≃ᵃ[k] P₂) : P₁ →ᵃ[k] P₂ := { to_fun := e, .. e }
instance : has_coe (P₁ ≃ᵃ[k] P₂) (P₁ →ᵃ[k] P₂) := ⟨to_affine_map⟩
@[simp] lemma coe_to_affine_map (e : P₁ ≃ᵃ[k] P₂) :
(e.to_affine_map : P₁ → P₂) = (e : P₁ → P₂) :=
rfl
@[simp] lemma to_affine_map_mk (f : P₁ ≃ P₂) (f' : V₁ ≃ₗ[k] V₂) (h) :
to_affine_map (mk f f' h) = ⟨f, f', h⟩ :=
rfl
@[norm_cast, simp] lemma coe_coe (e : P₁ ≃ᵃ[k] P₂) : ((e : P₁ →ᵃ[k] P₂) : P₁ → P₂) = e := rfl
@[simp] lemma linear_to_affine_map (e : P₁ ≃ᵃ[k] P₂) : e.to_affine_map.linear = e.linear := rfl
lemma to_affine_map_injective : injective (to_affine_map : (P₁ ≃ᵃ[k] P₂) → (P₁ →ᵃ[k] P₂)) :=
begin
rintros ⟨e, el, h⟩ ⟨e', el', h'⟩ H,
simp only [to_affine_map_mk, equiv.coe_inj, linear_equiv.to_linear_map_inj] at H,
congr,
exacts [H.1, H.2]
end
@[simp] lemma to_affine_map_inj {e e' : P₁ ≃ᵃ[k] P₂} :
e.to_affine_map = e'.to_affine_map ↔ e = e' :=
to_affine_map_injective.eq_iff
@[ext] lemma ext {e e' : P₁ ≃ᵃ[k] P₂} (h : ∀ x, e x = e' x) : e = e' :=
to_affine_map_injective $ affine_map.ext h
lemma coe_fn_injective : @injective (P₁ ≃ᵃ[k] P₂) (P₁ → P₂) coe_fn :=
λ e e' H, ext $ congr_fun H
@[simp, norm_cast] lemma coe_fn_inj {e e' : P₁ ≃ᵃ[k] P₂} : (e : P₁ → P₂) = e' ↔ e = e' :=
coe_fn_injective.eq_iff
lemma to_equiv_injective : injective (to_equiv : (P₁ ≃ᵃ[k] P₂) → (P₁ ≃ P₂)) :=
λ e e' H, ext $ equiv.ext_iff.1 H
@[simp] lemma to_equiv_inj {e e' : P₁ ≃ᵃ[k] P₂} : e.to_equiv = e'.to_equiv ↔ e = e' :=
to_equiv_injective.eq_iff
@[simp] lemma coe_mk (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (h) :
((⟨e, e', h⟩ : P₁ ≃ᵃ[k] P₂) : P₁ → P₂) = e :=
rfl
/-- Construct an affine equivalence by verifying the relation between the map and its linear part at
one base point. Namely, this function takes a map `e : P₁ → P₂`, a linear equivalence
`e' : V₁ ≃ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have
`e p' = e' (p' -ᵥ p) +ᵥ e p`. -/
def mk' (e : P₁ → P₂) (e' : V₁ ≃ₗ[k] V₂) (p : P₁) (h : ∀ p' : P₁, e p' = e' (p' -ᵥ p) +ᵥ e p) :
P₁ ≃ᵃ[k] P₂ :=
{ to_fun := e,
inv_fun := λ q' : P₂, e'.symm (q' -ᵥ e p) +ᵥ p,
left_inv := λ p', by simp [h p'],
right_inv := λ q', by simp [h (e'.symm (q' -ᵥ e p) +ᵥ p)],
linear := e',
map_vadd' := λ p' v, by { simp [h p', h (v +ᵥ p'), vadd_vsub_assoc, vadd_vadd] } }
@[simp] lemma coe_mk' (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (p h) : ⇑(mk' e e' p h) = e := rfl
@[simp] lemma linear_mk' (e : P₁ ≃ P₂) (e' : V₁ ≃ₗ[k] V₂) (p h) :
(mk' e e' p h).linear = e' := rfl
/-- Inverse of an affine equivalence as an affine equivalence. -/
@[symm] def symm (e : P₁ ≃ᵃ[k] P₂) : P₂ ≃ᵃ[k] P₁ :=
{ to_equiv := e.to_equiv.symm,
linear := e.linear.symm,
map_vadd' := λ v p, e.to_equiv.symm.apply_eq_iff_eq_symm_apply.2 $
by simpa using (e.to_equiv.apply_symm_apply v).symm }
@[simp] lemma symm_to_equiv (e : P₁ ≃ᵃ[k] P₂) : e.to_equiv.symm = e.symm.to_equiv := rfl
@[simp] lemma symm_linear (e : P₁ ≃ᵃ[k] P₂) : e.linear.symm = e.symm.linear := rfl
/-- See Note [custom simps projection] -/
def simps.apply (e : P₁ ≃ᵃ[k] P₂) : P₁ → P₂ := e
/-- See Note [custom simps projection] -/
def simps.symm_apply (e : P₁ ≃ᵃ[k] P₂) : P₂ → P₁ := e.symm
initialize_simps_projections affine_equiv
(to_equiv_to_fun → apply, to_equiv_inv_fun → symm_apply, linear → linear as_prefix, -to_equiv)
protected lemma bijective (e : P₁ ≃ᵃ[k] P₂) : bijective e := e.to_equiv.bijective
protected lemma surjective (e : P₁ ≃ᵃ[k] P₂) : surjective e := e.to_equiv.surjective
protected lemma injective (e : P₁ ≃ᵃ[k] P₂) : injective e := e.to_equiv.injective
@[simp] lemma range_eq (e : P₁ ≃ᵃ[k] P₂) : range e = univ := e.surjective.range_eq
@[simp] lemma apply_symm_apply (e : P₁ ≃ᵃ[k] P₂) (p : P₂) : e (e.symm p) = p :=
e.to_equiv.apply_symm_apply p
@[simp] lemma symm_apply_apply (e : P₁ ≃ᵃ[k] P₂) (p : P₁) : e.symm (e p) = p :=
e.to_equiv.symm_apply_apply p
lemma apply_eq_iff_eq_symm_apply (e : P₁ ≃ᵃ[k] P₂) {p₁ p₂} : e p₁ = p₂ ↔ p₁ = e.symm p₂ :=
e.to_equiv.apply_eq_iff_eq_symm_apply
@[simp] lemma apply_eq_iff_eq (e : P₁ ≃ᵃ[k] P₂) {p₁ p₂ : P₁} : e p₁ = e p₂ ↔ p₁ = p₂ :=
e.to_equiv.apply_eq_iff_eq
variables (k P₁)
omit V₂
/-- Identity map as an `affine_equiv`. -/
@[refl] def refl : P₁ ≃ᵃ[k] P₁ :=
{ to_equiv := equiv.refl P₁,
linear := linear_equiv.refl k V₁,
map_vadd' := λ _ _, rfl }
@[simp] lemma coe_refl : ⇑(refl k P₁) = id := rfl
@[simp] lemma coe_refl_to_affine_map : ↑(refl k P₁) = affine_map.id k P₁ := rfl
@[simp] lemma refl_apply (x : P₁) : refl k P₁ x = x := rfl
@[simp] lemma to_equiv_refl : (refl k P₁).to_equiv = equiv.refl P₁ := rfl
@[simp] lemma linear_refl : (refl k P₁).linear = linear_equiv.refl k V₁ := rfl
@[simp] lemma symm_refl : (refl k P₁).symm = refl k P₁ := rfl
variables {k P₁}
include V₂ V₃
/-- Composition of two `affine_equiv`alences, applied left to right. -/
@[trans] def trans (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) : P₁ ≃ᵃ[k] P₃ :=
{ to_equiv := e.to_equiv.trans e'.to_equiv,
linear := e.linear.trans e'.linear,
map_vadd' := λ p v, by simp only [linear_equiv.trans_apply, coe_to_equiv, (∘),
equiv.coe_trans, map_vadd] }
@[simp] lemma coe_trans (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) : ⇑(e.trans e') = e' ∘ e := rfl
@[simp]
lemma trans_apply (e : P₁ ≃ᵃ[k] P₂) (e' : P₂ ≃ᵃ[k] P₃) (p : P₁) : e.trans e' p = e' (e p) := rfl
include V₄
lemma trans_assoc (e₁ : P₁ ≃ᵃ[k] P₂) (e₂ : P₂ ≃ᵃ[k] P₃) (e₃ : P₃ ≃ᵃ[k] P₄) :
(e₁.trans e₂).trans e₃ = e₁.trans (e₂.trans e₃) :=
ext $ λ _, rfl
omit V₃ V₄
@[simp] lemma trans_refl (e : P₁ ≃ᵃ[k] P₂) : e.trans (refl k P₂) = e :=
ext $ λ _, rfl
@[simp] lemma refl_trans (e : P₁ ≃ᵃ[k] P₂) : (refl k P₁).trans e = e :=
ext $ λ _, rfl
@[simp] lemma self_trans_symm (e : P₁ ≃ᵃ[k] P₂) : e.trans e.symm = refl k P₁ :=
ext e.symm_apply_apply
@[simp] lemma symm_trans_self (e : P₁ ≃ᵃ[k] P₂) : e.symm.trans e = refl k P₂ :=
ext e.apply_symm_apply
@[simp] lemma apply_line_map (e : P₁ ≃ᵃ[k] P₂) (a b : P₁) (c : k) :
e (affine_map.line_map a b c) = affine_map.line_map (e a) (e b) c :=
e.to_affine_map.apply_line_map a b c
omit V₂
instance : group (P₁ ≃ᵃ[k] P₁) :=
{ one := refl k P₁,
mul := λ e e', e'.trans e,
inv := symm,
mul_assoc := λ e₁ e₂ e₃, trans_assoc _ _ _,
one_mul := trans_refl,
mul_one := refl_trans,
mul_left_inv := self_trans_symm }
lemma one_def : (1 : P₁ ≃ᵃ[k] P₁) = refl k P₁ := rfl
@[simp] lemma coe_one : ⇑(1 : P₁ ≃ᵃ[k] P₁) = id := rfl
lemma mul_def (e e' : P₁ ≃ᵃ[k] P₁) : e * e' = e'.trans e := rfl
@[simp] lemma coe_mul (e e' : P₁ ≃ᵃ[k] P₁) : ⇑(e * e') = e ∘ e' := rfl
lemma inv_def (e : P₁ ≃ᵃ[k] P₁) : e⁻¹ = e.symm := rfl
/-- `affine_equiv.linear` on automorphisms is a `monoid_hom`. -/
@[simps] def linear_hom : (P₁ ≃ᵃ[k] P₁) →* (V₁ ≃ₗ[k] V₁) :=
{ to_fun := linear,
map_one' := rfl,
map_mul' := λ _ _, rfl }
/-- The group of `affine_equiv`s are equivalent to the group of units of `affine_map`.
This is the affine version of `linear_map.general_linear_group.general_linear_equiv`. -/
@[simps]
def equiv_units_affine_map : (P₁ ≃ᵃ[k] P₁) ≃* (P₁ →ᵃ[k] P₁)ˣ :=
{ to_fun := λ e, ⟨e, e.symm, congr_arg coe e.symm_trans_self, congr_arg coe e.self_trans_symm⟩,
inv_fun := λ u,
{ to_fun := (u : P₁ →ᵃ[k] P₁), inv_fun := (↑(u⁻¹) : P₁ →ᵃ[k] P₁),
left_inv := affine_map.congr_fun u.inv_mul,
right_inv := affine_map.congr_fun u.mul_inv,
linear := linear_map.general_linear_group.general_linear_equiv _ _ $
units.map (by exact affine_map.linear_hom) u,
map_vadd' := λ _ _, (u : P₁ →ᵃ[k] P₁).map_vadd _ _ },
left_inv := λ e, affine_equiv.ext $ λ x, rfl,
right_inv := λ u, units.ext $ affine_map.ext $ λ x, rfl,
map_mul' := λ e₁ e₂, rfl }
variable (k)
/-- The map `v ↦ v +ᵥ b` as an affine equivalence between a module `V` and an affine space `P` with
tangent space `V`. -/
@[simps]
def vadd_const (b : P₁) : V₁ ≃ᵃ[k] P₁ :=
{ to_equiv := equiv.vadd_const b,
linear := linear_equiv.refl _ _,
map_vadd' := λ p v, add_vadd _ _ _ }
/-- `p' ↦ p -ᵥ p'` as an equivalence. -/
def const_vsub (p : P₁) : P₁ ≃ᵃ[k] V₁ :=
{ to_equiv := equiv.const_vsub p,
linear := linear_equiv.neg k,
map_vadd' := λ p' v, by simp [vsub_vadd_eq_vsub_sub, neg_add_eq_sub] }
@[simp] lemma coe_const_vsub (p : P₁) : ⇑(const_vsub k p) = (-ᵥ) p := rfl
@[simp] lemma coe_const_vsub_symm (p : P₁) : ⇑(const_vsub k p).symm = λ v, -v +ᵥ p := rfl
variable (P₁)
/-- The map `p ↦ v +ᵥ p` as an affine automorphism of an affine space.
Note that there is no need for an `affine_map.const_vadd` as it is always an equivalence.
This is roughly to `distrib_mul_action.to_linear_equiv` as `+ᵥ` is to `•`. -/
@[simps apply linear]
def const_vadd (v : V₁) : P₁ ≃ᵃ[k] P₁ :=
{ to_equiv := equiv.const_vadd P₁ v,
linear := linear_equiv.refl _ _,
map_vadd' := λ p w, vadd_comm _ _ _ }
@[simp] lemma const_vadd_zero : const_vadd k P₁ 0 = affine_equiv.refl _ _ := ext $ zero_vadd _
@[simp] lemma const_vadd_add (v w : V₁) :
const_vadd k P₁ (v + w) = (const_vadd k P₁ w).trans (const_vadd k P₁ v) := ext $ add_vadd _ _
@[simp] lemma const_vadd_symm (v : V₁) : (const_vadd k P₁ v).symm = const_vadd k P₁ (-v) :=
ext $ λ _, rfl
/-- A more bundled version of `affine_equiv.const_vadd`. -/
@[simps]
def const_vadd_hom : multiplicative V₁ →* P₁ ≃ᵃ[k] P₁ :=
{ to_fun := λ v, const_vadd k P₁ v.to_add,
map_one' := const_vadd_zero _ _,
map_mul' := const_vadd_add _ _ }
lemma const_vadd_nsmul (n : ℕ) (v : V₁) : const_vadd k P₁ (n • v) = (const_vadd k P₁ v)^n :=
(const_vadd_hom k P₁).map_pow _ _
lemma const_vadd_zsmul (z : ℤ) (v : V₁) : const_vadd k P₁ (z • v) = (const_vadd k P₁ v)^z :=
(const_vadd_hom k P₁).map_zpow _ _
section homothety
omit V₁
variables {R V P : Type*} [comm_ring R] [add_comm_group V] [module R V] [affine_space V P]
include V
/-- Fixing a point in affine space, homothety about this point gives a group homomorphism from (the
centre of) the units of the scalars into the group of affine equivalences. -/
def homothety_units_mul_hom (p : P) : Rˣ →* P ≃ᵃ[R] P :=
equiv_units_affine_map.symm.to_monoid_hom.comp $ units.map (affine_map.homothety_hom p)
@[simp] lemma coe_homothety_units_mul_hom_apply (p : P) (t : Rˣ) :
(homothety_units_mul_hom p t : P → P) = affine_map.homothety p (t : R) :=
rfl
@[simp] lemma coe_homothety_units_mul_hom_apply_symm (p : P) (t : Rˣ) :
((homothety_units_mul_hom p t).symm : P → P) = affine_map.homothety p (↑t⁻¹ : R) :=
rfl
@[simp] lemma coe_homothety_units_mul_hom_eq_homothety_hom_coe (p : P) :
(coe : (P ≃ᵃ[R] P) → P →ᵃ[R] P) ∘ homothety_units_mul_hom p =
(affine_map.homothety_hom p) ∘ (coe : Rˣ → R) :=
funext $ λ _, rfl
end homothety
variable {P₁}
open function
/-- Point reflection in `x` as a permutation. -/
def point_reflection (x : P₁) : P₁ ≃ᵃ[k] P₁ := (const_vsub k x).trans (vadd_const k x)
lemma point_reflection_apply (x y : P₁) : point_reflection k x y = x -ᵥ y +ᵥ x := rfl
@[simp] lemma point_reflection_symm (x : P₁) : (point_reflection k x).symm = point_reflection k x :=
to_equiv_injective $ equiv.point_reflection_symm x
@[simp] lemma to_equiv_point_reflection (x : P₁) :
(point_reflection k x).to_equiv = equiv.point_reflection x :=
rfl
@[simp] lemma point_reflection_self (x : P₁) : point_reflection k x x = x := vsub_vadd _ _
lemma point_reflection_involutive (x : P₁) : involutive (point_reflection k x : P₁ → P₁) :=
equiv.point_reflection_involutive x
/-- `x` is the only fixed point of `point_reflection x`. This lemma requires
`x + x = y + y ↔ x = y`. There is no typeclass to use here, so we add it as an explicit argument. -/
lemma point_reflection_fixed_iff_of_injective_bit0 {x y : P₁} (h : injective (bit0 : V₁ → V₁)) :
point_reflection k x y = y ↔ y = x :=
equiv.point_reflection_fixed_iff_of_injective_bit0 h
lemma injective_point_reflection_left_of_injective_bit0 (h : injective (bit0 : V₁ → V₁)) (y : P₁) :
injective (λ x : P₁, point_reflection k x y) :=
equiv.injective_point_reflection_left_of_injective_bit0 h y
lemma injective_point_reflection_left_of_module [invertible (2:k)]:
∀ y, injective (λ x : P₁, point_reflection k x y) :=
injective_point_reflection_left_of_injective_bit0 k $ λ x y h,
by rwa [bit0, bit0, ← two_smul k x, ← two_smul k y,
(is_unit_of_invertible (2:k)).smul_left_cancel] at h
lemma point_reflection_fixed_iff_of_module [invertible (2:k)] {x y : P₁} :
point_reflection k x y = y ↔ y = x :=
((injective_point_reflection_left_of_module k y).eq_iff' (point_reflection_self k y)).trans eq_comm
end affine_equiv
namespace linear_equiv
/-- Interpret a linear equivalence between modules as an affine equivalence. -/
def to_affine_equiv (e : V₁ ≃ₗ[k] V₂) : V₁ ≃ᵃ[k] V₂ :=
{ to_equiv := e.to_equiv,
linear := e,
map_vadd' := λ p v, e.map_add v p }
@[simp] lemma coe_to_affine_equiv (e : V₁ ≃ₗ[k] V₂) : ⇑e.to_affine_equiv = e := rfl
end linear_equiv
namespace affine_map
open affine_equiv
include V₁
lemma line_map_vadd (v v' : V₁) (p : P₁) (c : k) :
line_map v v' c +ᵥ p = line_map (v +ᵥ p) (v' +ᵥ p) c :=
(vadd_const k p).apply_line_map v v' c
lemma line_map_vsub (p₁ p₂ p₃ : P₁) (c : k) :
line_map p₁ p₂ c -ᵥ p₃ = line_map (p₁ -ᵥ p₃) (p₂ -ᵥ p₃) c :=
(vadd_const k p₃).symm.apply_line_map p₁ p₂ c
lemma vsub_line_map (p₁ p₂ p₃ : P₁) (c : k) :
p₁ -ᵥ line_map p₂ p₃ c = line_map (p₁ -ᵥ p₂) (p₁ -ᵥ p₃) c :=
(const_vsub k p₁).apply_line_map p₂ p₃ c
lemma vadd_line_map (v : V₁) (p₁ p₂ : P₁) (c : k) :
v +ᵥ line_map p₁ p₂ c = line_map (v +ᵥ p₁) (v +ᵥ p₂) c :=
(const_vadd k P₁ v).apply_line_map p₁ p₂ c
variables {R' : Type*} [comm_ring R'] [module R' V₁]
lemma homothety_neg_one_apply (c p : P₁) :
homothety c (-1:R') p = point_reflection R' c p :=
by simp [homothety_apply, point_reflection_apply]
end affine_map
|
16603ee5f0b77ee98ac42beb243ed710249f81a5
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/tactic/omega/misc.lean
|
64718d92e33f9a762613401e8e6f8e62256f79cb
|
[
"Apache-2.0"
] |
permissive
|
kodyvajjha/mathlib
|
9bead00e90f68269a313f45f5561766cfd8d5cad
|
b98af5dd79e13a38d84438b850a2e8858ec21284
|
refs/heads/master
| 1,624,350,366,310
| 1,615,563,062,000
| 1,615,563,062,000
| 162,666,963
| 0
| 0
|
Apache-2.0
| 1,545,367,651,000
| 1,545,367,651,000
| null |
UTF-8
|
Lean
| false
| false
| 2,141
|
lean
|
/-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
-/
/-
Miscellaneous.
-/
import tactic.localized
variables {α β γ : Type}
namespace omega
lemma fun_mono_2 {p : α → β → γ} {a1 a2 : α} {b1 b2 : β} :
a1 = a2 → b1 = b2 → (p a1 b1 = p a2 b2) :=
λ h1 h2, by rw [h1, h2]
lemma pred_mono_2 {p : α → β → Prop} {a1 a2 : α} {b1 b2 : β} :
a1 = a2 → b1 = b2 → (p a1 b1 ↔ p a2 b2) :=
λ h1 h2, by rw [h1, h2]
lemma pred_mono_2' {c : Prop → Prop → Prop} {a1 a2 b1 b2 : Prop} :
(a1 ↔ a2) → (b1 ↔ b2) → (c a1 b1 ↔ c a2 b2) :=
λ h1 h2, by rw [h1, h2]
/-- Update variable assignment for a specific variable
and leave everything else unchanged -/
def update (m : nat) (a : α) (v : nat → α) : nat → α
| n := if n = m then a else v n
localized "notation v ` ⟨` m ` ↦ ` a `⟩` := omega.update m a v" in omega
lemma update_eq (m : nat) (a : α) (v : nat → α) : (v ⟨m ↦ a⟩) m = a :=
by simp only [update, if_pos rfl]
lemma update_eq_of_ne {m : nat} {a : α} {v : nat → α} (k : nat) :
k ≠ m → update m a v k = v k :=
by {intro h1, unfold update, rw if_neg h1}
/-- Assign a new value to the zeroth variable, and push all
other assignments up by 1 -/
def update_zero (a : α) (v : nat → α) : nat → α
| 0 := a
| (k+1) := v k
open tactic
/-- Intro with a fresh name -/
meta def intro_fresh : tactic unit :=
do n ← mk_fresh_name,
intro n,
skip
/-- Revert an expr if it passes the given test -/
meta def revert_cond (t : expr → tactic unit) (x : expr) : tactic unit :=
(t x >> revert x >> skip) <|> skip
/-- Revert all exprs in the context that pass the given test -/
meta def revert_cond_all (t : expr → tactic unit) : tactic unit :=
do hs ← local_context, mmap (revert_cond t) hs, skip
/-- Try applying a tactic to each of the element in a list
until success, and return the first successful result -/
meta def app_first {α β : Type} (t : α → tactic β) : list α → tactic β
| [] := failed
| (a :: as) := t a <|> app_first as
end omega
|
d3946777c8ae77d44c9f19dca2b00f84cf032d49
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/examples/lean/tactic1.lean
|
4d1fa6b2494360af5a313b3216ea0a95a4e35440
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean0.1
|
1ce92751d664aacff0529e139083304a7bbc8a71
|
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
|
refs/heads/master
| 1,610,830,535,062
| 1,402,150,480,000
| 1,402,150,480,000
| 19,588,851
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,729
|
lean
|
-- This example demonstrates how to specify a proof skeleton that contains
-- "holes" that must be filled using user-defined tactics.
import tactic
(*
-- Define a simple tactic using Lua
auto = Repeat(OrElse(assumption_tac(), conj_tac(), conj_hyp_tac()))
conj_hyp = conj_hyp_tac()
conj = conj_tac()
*)
-- The (by [tactic]) expression is essentially creating a "hole" and associating a "hint" to it.
-- The "hint" is a tactic that should be used to fill the "hole".
-- In the following example, we use the tactic "auto" defined by the Lua code above.
--
-- The (show [expr], by [tactic]) expression is also creating a "hole" and associating a "hint" to it.
-- The expression [expr] after the shows is fixing the type of the "hole"
theorem T1 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,
let lemma1 : A := (by auto),
lemma2 : B := (by auto)
in (show B /\ A, by auto)
print environment 1. -- print proof for the previous theorem
-- When hints are not provided, the user must fill the (remaining) holes using tactic command sequences.
-- Each hole must be filled with a tactic command sequence that terminates with the command 'done' and
-- successfully produces a proof term for filling the hole. Here is the same example without hints
-- This style is more convenient for interactive proofs
theorem T2 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,
let lemma1 : A := _, -- first hole
lemma2 : B := _ -- second hole
in _. -- third hole
auto. done. -- tactic command sequence for the first hole
auto. done. -- tactic command sequence for the second hole
auto. done. -- tactic command sequence for the third hole
-- In the following example, instead of using the "auto" tactic, we apply a sequence of even simpler tactics.
theorem T3 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,
let lemma1 : A := _, -- first hole
lemma2 : B := _ -- second hole
in _. -- third hole
conj_hyp. exact. done. -- tactic command sequence for the first hole
conj_hyp. exact. done. -- tactic command sequence for the second hole
conj. exact. done. -- tactic command sequence for the third hole
-- We can also mix the two styles (hints and command sequences)
theorem T4 (A B : Bool) : A /\ B -> B /\ A :=
fun assumption : A /\ B,
let lemma1 : A := _, -- first hole
lemma2 : B := _ -- second hole
in (show B /\ A, by auto).
auto. done. -- tactic command sequence for the first hole
auto. done. -- tactic command sequence for the second hole
|
02ac7a02e07f92ca0b37ed5a13902b60e75a17a0
|
6b45072eb2b3db3ecaace2a7a0241ce81f815787
|
/algebra/lattice/filter.lean
|
1da71d4825ad7f0074519bbdbce33ffa64127b7f
|
[] |
no_license
|
avigad/library_dev
|
27b47257382667b5eb7e6476c4f5b0d685dd3ddc
|
9d8ac7c7798ca550874e90fed585caad030bbfac
|
refs/heads/master
| 1,610,452,468,791
| 1,500,712,839,000
| 1,500,713,478,000
| 69,311,142
| 1
| 0
| null | 1,474,942,903,000
| 1,474,942,902,000
| null |
UTF-8
|
Lean
| false
| false
| 66,123
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
Theory of filters on sets.
-/
import .complete_lattice ...data.set .zorn
open lattice set
universes u v w x
section applicative
variables {f : Type u → Type v} [applicative f] {α β : Type u}
lemma pure_seq_eq_map : ∀ {α β : Type u} (g : α → β) (x : f α), pure g <*> x = g <$> x :=
@applicative.pure_seq_eq_map f _
end applicative
section monad
variables {α β γ : Type u} {m : Type u → Type v} [monad m]
theorem map_bind (x : m α) {g : α → m β} {f : β → γ} : f <$> (x >>= g) = (x >>= λa, f <$> g a) :=
by simp [monad.bind_assoc, (∘), (monad.bind_pure_comp_eq_map _ _ _).symm]
theorem seq_bind_eq (x : m α) {g : β → m γ} {f : α → β} : (f <$> x) >>= g = (x >>= g ∘ f) :=
show bind (f <$> x) g = bind x (g ∘ f),
by rw [←monad.bind_pure_comp_eq_map, monad.bind_assoc]; simp [monad.pure_bind]
theorem seq_eq_bind_map {x : m α} {f : m (α → β)} : f <*> x = (f >>= (<$> x)) :=
(monad.bind_map_eq_seq m f x)^.symm
theorem bind_assoc : ∀ {α β γ : Type u} (x : m α) (f : α → m β) (g : β → m γ),
x >>= f >>= g = x >>= λ x, f x >>= g :=
@monad.bind_assoc m _
end monad
section prod
variables {α : Type u} {β : Type v}
@[simp] -- copied from parser
lemma prod.mk.eta : ∀{p : α × β}, (p.1, p.2) = p
| (a, b) := rfl
def prod.swap : (α×β) → (β×α) := λp, (p.2, p.1)
@[simp]
lemma prod.swap_swap : ∀x:α×β, prod.swap (prod.swap x) = x
| ⟨a, b⟩ := rfl
@[simp]
lemma prod.fst_swap {p : α×β} : (prod.swap p).1 = p.2 := rfl
@[simp]
lemma prod.snd_swap {p : α×β} : (prod.swap p).2 = p.1 := rfl
@[simp]
lemma prod.swap_prod_mk {a : α} {b : β} : prod.swap (a, b) = (b, a) := rfl
@[simp]
lemma prod.swap_swap_eq : prod.swap ∘ prod.swap = @id (α × β) :=
funext $ prod.swap_swap
end prod
namespace lattice
variables {α : Type u} {ι : Sort v} [complete_lattice α]
lemma Inf_eq_finite_sets {s : set α} :
Inf s = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t) :=
le_antisymm
(le_infi $ assume t, le_infi $ assume ⟨_, h⟩, Inf_le_Inf h)
(le_Inf $ assume b h, infi_le_of_le {b} $ infi_le_of_le (by simp [h]) $ Inf_le $ by simp)
lemma Sup_le_iff {s : set α} {a : α} : Sup s ≤ a ↔ (∀x∈s, x ≤ a) :=
⟨assume h x hx, le_trans (le_Sup hx) h, Sup_le⟩
end lattice
instance : monad set :=
{ monad .
pure := λ(α : Type u) a, {a},
bind := λ(α β : Type u) s f, ⋃i∈s, f i,
map := λ(α β : Type u), set.image,
pure_bind := assume α β x f, by simp,
bind_assoc := assume α β γ s f g, set.ext $ assume a,
by simp; exact ⟨assume ⟨b, ag, a, as, bf⟩, ⟨a, as, b, bf, ag⟩,
assume ⟨a, as, b, bf, ag⟩, ⟨b, ag, a, as, bf⟩⟩,
id_map := assume α, functor.id_map,
bind_pure_comp_eq_map := assume α β f s, set.ext $ by simp [set.image, eq_comm] }
namespace set
section
variables {α β : Type u}
@[simp] theorem bind_def (s : set α) (f : α → set β) : s >>= f = ⋃i∈s, f i := rfl
theorem ne_empty_iff_exists_mem {s : set α} : s ≠ ∅ ↔ ∃ x, x ∈ s :=
⟨exists_mem_of_ne_empty, assume ⟨x, (hx : x ∈ s)⟩ h, by rw [h] at hx; assumption⟩
lemma fmap_eq_image {f : α → β} {s : set α} : f <$> s = f '' s :=
rfl
lemma mem_seq_iff {f : set (α → β)} {s : set α} {b : β} :
b ∈ (f <*> s) ↔ (∃(f' : α → β), ∃a ∈ s, f' ∈ f ∧ b = f' a) :=
begin
simp [seq_eq_bind_map],
apply exists_congr,
intro f',
exact ⟨assume ⟨hf', a, ha, h_eq⟩, ⟨a, h_eq^.symm, ha, hf'⟩,
assume ⟨a, h_eq, ha, hf'⟩, ⟨hf', a, ha, h_eq^.symm⟩⟩
end
end
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
protected def prod (s : set α) (t : set β) : set (α × β) :=
{p | p.1 ∈ s ∧ p.2 ∈ t}
lemma mem_prod_eq {s : set α} {t : set β} {p : α × β} :
p ∈ set.prod s t = (p.1 ∈ s ∧ p.2 ∈ t) :=
rfl
lemma prod_vimage_eq {s : set α} {t : set β} {f : γ → α} {g : δ → β} :
set.prod (vimage f s) (vimage g t) = vimage (λp, (f p.1, g p.2)) (set.prod s t) :=
rfl
lemma prod_mono {s₁ s₂ : set α} {t₁ t₂ : set β} (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) :
set.prod s₁ t₁ ⊆ set.prod s₂ t₂ :=
assume x ⟨h₁, h₂⟩, ⟨hs h₁, ht h₂⟩
lemma prod_inter_prod {s₁ s₂ : set α} {t₁ t₂ : set β} :
set.prod s₁ t₁ ∩ set.prod s₂ t₂ = set.prod (s₁ ∩ s₂) (t₁ ∩ t₂) :=
subset.antisymm
(assume ⟨a, b⟩ ⟨⟨ha₁, hb₁⟩, ⟨ha₂, hb₂⟩⟩, ⟨⟨ha₁, ha₂⟩, ⟨hb₁, hb₂⟩⟩)
(subset_inter
(prod_mono (inter_subset_left _ _) (inter_subset_left _ _))
(prod_mono (inter_subset_right _ _) (inter_subset_right _ _)))
lemma monotone_prod [weak_order α] {f : α → set β} {g : α → set γ}
(hf : monotone f) (hg : monotone g) : monotone (λx, set.prod (f x) (g x)) :=
assume a b h, prod_mono (hf h) (hg h)
lemma image_swap_prod {s : set α} {t : set β} :
image (λp:β×α, (p.2, p.1)) (set.prod t s) = set.prod s t :=
set.ext $ assume ⟨a, b⟩, by simp [mem_image_eq, set.prod]; exact
⟨ assume ⟨b', a', h_a, h_b, h⟩, by rw [h_a, h_b] at h; assumption,
assume ⟨ha, hb⟩, ⟨b, a, rfl, rfl, ⟨ha, hb⟩⟩⟩
lemma prod_image_image_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{s₁ : set α₁} {s₂ : set α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
set.prod (image m₁ s₁) (image m₂ s₂) = image (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) (set.prod s₁ s₂) :=
set.ext $ assume ⟨b₁, b₂⟩,
⟨assume ⟨⟨a₁, ha₁, (eq₁ : m₁ a₁ = b₁)⟩, ⟨a₂, ha₂, (eq₂ : m₂ a₂ = b₂)⟩⟩,
mem_image
(show (a₁, a₂) ∈ set.prod s₁ s₂, from ⟨ha₁, ha₂⟩)
(by simp [eq₁, eq₂]),
assume ⟨⟨a₁, a₂⟩, ⟨ha₁, ha₂⟩, eq⟩, eq ▸ ⟨mem_image_of_mem m₁ ha₁, mem_image_of_mem m₂ ha₂⟩⟩
@[simp]
lemma prod_singleton_singleton {a : α} {b : β} :
set.prod {a} {b} = ({(a, b)} : set (α×β)) :=
set.ext $ assume ⟨a', b'⟩, by simp [set.prod]
lemma prod_neq_empty_iff {s : set α} {t : set β} :
set.prod s t ≠ ∅ ↔ (s ≠ ∅ ∧ t ≠ ∅) :=
begin
rw [ne_empty_iff_exists_mem, ne_empty_iff_exists_mem, ne_empty_iff_exists_mem,
prod.exists],
exact ⟨assume ⟨a, b, ha, hb⟩, ⟨⟨a, ha⟩, ⟨b, hb⟩⟩,
assume ⟨⟨a, ha⟩, ⟨b, hb⟩⟩, ⟨a, b, ha, hb⟩⟩
end
@[simp]
lemma prod_mk_mem_set_prod_eq {a : α} {b : β} {s : set α} {t : set β} :
(a, b) ∈ set.prod s t = (a ∈ s ∧ b ∈ t) :=
rfl
lemma monotone_inter [weak_order β] {f g : β → set α}
(hf : monotone f) (hg : monotone g) : monotone (λx, (f x) ∩ (g x)) :=
assume a b h x ⟨h₁, h₂⟩, ⟨hf h h₁, hg h h₂⟩
@[simp]
lemma vimage_set_of_eq {p : α → Prop} {f : β → α} :
vimage f {a | p a} = {a | p (f a)} :=
rfl
@[simp]
lemma set_of_mem_eq {s : set α} : {x | x ∈ s} = s :=
rfl
lemma mem_image_iff_of_inverse (f : α → β) (g : β → α) {b : β} {s : set α}
(h₁ : ∀a, g (f a) = a ) (h₂ : ∀b, f (g b) = b ) : b ∈ f '' s ↔ g b ∈ s :=
⟨assume ⟨a, ha, fa_eq⟩, fa_eq ▸ (h₁ a)^.symm ▸ ha,
assume h, ⟨g b, h, h₂ b⟩⟩
lemma image_eq_vimage_of_inverse (f : α → β) (g : β → α)
(h₁ : ∀a, g (f a) = a ) (h₂ : ∀b, f (g b) = b ) : image f = vimage g :=
funext $ assume s, set.ext $ assume b, mem_image_iff_of_inverse f g h₁ h₂
lemma image_swap_eq_vimage_swap : image (@prod.swap α β) = vimage prod.swap :=
image_eq_vimage_of_inverse (@prod.swap α β) (@prod.swap β α)
begin simp; intros; trivial end
begin simp; intros; trivial end
lemma monotone_set_of [weak_order α] {p : α → β → Prop}
(hp : ∀b, monotone (λa, p a b)) : monotone (λa, {b | p a b}) :=
assume a a' h b, hp b h
lemma diff_right_antimono {s t u : set α} (h : t ⊆ u) : s - u ⊆ s - t :=
assume x ⟨hs, hnx⟩, ⟨hs, assume hx, hnx $ h hx⟩
end set
section
variables {α : Type u} {ι : Sort v}
lemma sUnion_mono {s t : set (set α)} (h : s ⊆ t) : (⋃₀ s) ⊆ (⋃₀ t) :=
sUnion_subset $ assume t' ht', subset_sUnion_of_mem $ h ht'
lemma Union_subset_Union {s t : ι → set α} (h : ∀i, s i ⊆ t i) : (⋃i, s i) ⊆ (⋃i, t i) :=
@supr_le_supr (set α) ι _ s t h
lemma Union_subset_Union2 {ι₂ : Sort x} {s : ι → set α} {t : ι₂ → set α} (h : ∀i, ∃j, s i ⊆ t j) : (⋃i, s i) ⊆ (⋃i, t i) :=
@supr_le_supr2 (set α) ι ι₂ _ s t h
lemma Union_subset_Union_const {ι₂ : Sort x} {s : set α} (h : ι → ι₂) : (⋃ i:ι, s) ⊆ (⋃ j:ι₂, s) :=
@supr_le_supr_const (set α) ι ι₂ _ s h
lemma diff_neq_empty {s t : set α} : s - t = ∅ ↔ s ⊆ t :=
⟨assume h x hx, classical.by_contradiction $ assume : x ∉ t, show x ∈ (∅ : set α), from h ▸ ⟨hx, this⟩,
assume h, bot_unique $ assume x ⟨hx, hnx⟩, hnx $ h hx⟩
@[simp]
lemma diff_empty {s : set α} : s - ∅ = s :=
set.ext $ assume x, ⟨assume ⟨hx, _⟩, hx, assume h, ⟨h, not_false⟩⟩
end
@[simp] -- should be handled by implies_true_iff
lemma implies_implies_true_iff {α : Sort u} {β : Sort v} : (α → β → true) ↔ true :=
⟨assume _, trivial, assume _ _ _ , trivial⟩
@[simp]
lemma not_not_mem_iff {α : Type u} {a : α} {s : set α} : ¬ (a ∉ s) ↔ a ∈ s :=
classical.not_not_iff _
@[simp]
lemma singleton_neq_emptyset {α : Type u} {a : α} : {a} ≠ (∅ : set α) :=
assume h,
have a ∉ ({a} : set α),
by simp [h],
this $ mem_singleton a
lemma eq_of_sup_eq_inf_eq {α : Type u} [distrib_lattice α] {a b c : α}
(h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c :=
le_antisymm
(calc b ≤ (c ⊓ a) ⊔ b : le_sup_right
... = (c ⊔ b) ⊓ (a ⊔ b) : sup_inf_right
... = c ⊔ (c ⊓ a) : by rw [←h₁, sup_inf_left, ←h₂]; simp [sup_comm]
... = c : sup_inf_self)
(calc c ≤ (b ⊓ a) ⊔ c : le_sup_right
... = (b ⊔ c) ⊓ (a ⊔ c) : sup_inf_right
... = b ⊔ (b ⊓ a) : by rw [h₁, sup_inf_left, h₂]; simp [sup_comm]
... = b : sup_inf_self)
lemma inf_eq_bot_iff_le_compl {α : Type u} [bounded_distrib_lattice α] {a b c : α}
(h₁ : b ⊔ c = ⊤) (h₂ : b ⊓ c = ⊥) : a ⊓ b = ⊥ ↔ a ≤ c :=
⟨assume : a ⊓ b = ⊥,
calc a ≤ a ⊓ (b ⊔ c) : by simp [h₁]
... = (a ⊓ b) ⊔ (a ⊓ c) : by simp [inf_sup_left]
... ≤ c : by simp [this, inf_le_right],
assume : a ≤ c,
bot_unique $
calc a ⊓ b ≤ b ⊓ c : by rw [inf_comm]; exact inf_le_inf (le_refl _) this
... = ⊥ : h₂⟩
lemma compl_image_set_of {α : Type u} {p : set α → Prop} :
compl '' {x | p x} = {x | p (- x)} :=
set.ext $ assume x, ⟨assume ⟨y, (hy : p y), (h_eq : -y = x)⟩,
show p (- x), by rw [←h_eq, lattice.neg_neg]; assumption,
assume h : p (-x), ⟨_, h, lattice.neg_neg⟩⟩
lemma neg_subset_neg_iff_subset {α : Type u} {x y : set α} : - y ⊆ - x ↔ x ⊆ y :=
@neg_le_neg_iff_le (set α) _ _ _
lemma sUnion_eq_Union {α : Type u} {s : set (set α)} :
(⋃₀ s) = (⋃ (i : set α) (h : i ∈ s), i) :=
set.ext $ by simp
lemma not_or_iff_implies {a b : Prop} : (¬ a ∨ b) ↔ (a → b) :=
⟨assume h ha, h.neg_resolve_left ha, classical.not_or_of_implies⟩
section order
variables {α : Type u} (r : α → α → Prop)
local infix `≼` : 50 := r
def directed {ι : Sort v} (f : ι → α) := ∀x, ∀y, ∃z, f z ≼ f x ∧ f z ≼ f y
def directed_on (s : set α) := ∀x ∈ s, ∀y ∈ s, ∃z ∈ s, z ≼ x ∧ z ≼ y
lemma directed_on_Union {r} {ι : Sort v} {f : ι → set α} (hd : directed (⊇) f)
(h : ∀x, directed_on r (f x)) : directed_on r (⋃x, f x) :=
by simp [directed_on]; exact
assume a₁ ⟨b₁, fb₁⟩ a₂ ⟨b₂, fb₂⟩,
let
⟨z, zb₁, zb₂⟩ := hd b₁ b₂,
⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂)
in
⟨x, xa₁, xa₂, z, xf⟩
def upwards (s : set α) := ∀{x y}, x ∈ s → x ≼ y → y ∈ s
end order
lemma directed_of_chain {α : Type u} {β : Type v} [weak_order β] {f : α → β} {c : set α}
(h : @zorn.chain α (λa b, f b ≤ f a) c) :
directed (≤) (λx:{a:α // a ∈ c}, f (x.val)) :=
assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
(assume : a = b, begin simp [this]; exact ⟨⟨b, hb⟩, le_refl _⟩ end)
(assume : a ≠ b,
have f b ≤ f a ∨ f a ≤ f b, from h a ha b hb this,
or.elim this
(assume : f b ≤ f a, ⟨⟨b, hb⟩, this, le_refl _⟩)
(assume : f a ≤ f b, ⟨⟨a, ha⟩, le_refl _, this⟩))
structure filter (α : Type u) :=
(sets : set (set α))
(inhabited : ∃x, x ∈ sets)
(upwards_sets : upwards (⊆) sets)
(directed_sets : directed_on (⊆) sets)
namespace filter
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
lemma filter_eq : ∀{f g : filter α}, f^.sets = g^.sets → f = g
| ⟨a, _, _, _⟩ ⟨._, _, _, _⟩ rfl := rfl
lemma univ_mem_sets' {f : filter α} {s : set α} (h : ∀ a, a ∈ s): s ∈ f^.sets :=
let ⟨x, x_in_s⟩ := f^.inhabited in
f^.upwards_sets x_in_s (assume x _, h x)
lemma univ_mem_sets {f : filter α} : univ ∈ f^.sets :=
univ_mem_sets' mem_univ
lemma inter_mem_sets {f : filter α} {x y : set α} (hx : x ∈ f^.sets) (hy : y ∈ f^.sets) :
x ∩ y ∈ f^.sets :=
let ⟨z, ⟨z_in_s, z_le_x, z_le_y⟩⟩ := f^.directed_sets _ hx _ hy in
f^.upwards_sets z_in_s (subset_inter z_le_x z_le_y)
lemma Inter_mem_sets {f : filter α} {s : β → set α}
{is : set β} (hf : finite is) (hs : ∀i∈is, s i ∈ f^.sets) : (⋂i∈is, s i) ∈ f^.sets :=
begin /- equation compiler complains that this is requires well-founded recursion -/
induction hf with i is _ hf hi,
{ simp [univ_mem_sets] },
begin
simp,
apply inter_mem_sets,
apply hs i,
simp,
exact (hi $ assume a ha, hs _ $ by simp [ha])
end
end
lemma exists_sets_subset_iff {f : filter α} {x : set α} :
(∃y∈f^.sets, y ⊆ x) ↔ x ∈ f^.sets :=
⟨assume ⟨y, hy, yx⟩, f^.upwards_sets hy yx,
assume hx, ⟨x, hx, subset.refl _⟩⟩
lemma monotone_mem_sets {f : filter α} : monotone (λs, s ∈ f^.sets) :=
assume s t hst h, f^.upwards_sets h hst
def principal (s : set α) : filter α :=
{ filter .
sets := {t | s ⊆ t},
inhabited := ⟨s, subset.refl _⟩,
upwards_sets := assume x y hx hy, subset.trans hx hy,
directed_sets := assume x hx y hy, ⟨s, subset.refl _, hx, hy⟩ }
def join (f : filter (filter α)) : filter α :=
{ filter .
sets := {s | {t | s ∈ filter.sets t} ∈ f^.sets},
inhabited := ⟨univ, by simp [univ_mem_sets]; exact univ_mem_sets⟩,
upwards_sets := assume x y hx xy, f^.upwards_sets hx $ assume a h, a^.upwards_sets h xy,
directed_sets := assume x hx y hy, ⟨x ∩ y,
f^.upwards_sets (inter_mem_sets hx hy) $ assume z ⟨h₁, h₂⟩, inter_mem_sets h₁ h₂,
inter_subset_left _ _, inter_subset_right _ _⟩ }
def map (m : α → β) (f : filter α) : filter β :=
{ filter .
sets := vimage (vimage m) f^.sets,
inhabited := ⟨univ, univ_mem_sets⟩,
upwards_sets := assume s t hs st, f^.upwards_sets hs (assume x h, st h),
directed_sets := assume s hs t ht, ⟨s ∩ t, inter_mem_sets hs ht,
inter_subset_left _ _, inter_subset_right _ _⟩ }
def vmap (m : α → β) (f : filter β) : filter α :=
{ filter .
sets := { s | ∃t∈f.sets, vimage m t ⊆ s },
inhabited := ⟨univ, univ, univ_mem_sets, by simp⟩,
upwards_sets := assume a b ⟨a', ha', ma'a⟩ ab, ⟨a', ha', subset.trans ma'a ab⟩,
directed_sets := assume a ⟨a', ha₁, ha₂⟩ b ⟨b', hb₁, hb₂⟩,
⟨vimage m (a' ∩ b'),
⟨a' ∩ b', inter_mem_sets ha₁ hb₁, subset.refl _⟩,
subset.trans (vimage_mono $ inter_subset_left _ _) ha₂,
subset.trans (vimage_mono $ inter_subset_right _ _) hb₂⟩ }
protected def sup (f g : filter α) : filter α :=
{ filter .
sets := f^.sets ∩ g^.sets,
inhabited := ⟨univ, by simp [univ_mem_sets]; exact univ_mem_sets⟩,
upwards_sets := assume x y hx xy,
and.imp (assume h, f^.upwards_sets h xy) (assume h, g^.upwards_sets h xy) hx,
directed_sets := assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∩ y,
⟨inter_mem_sets hx₁ hy₁, inter_mem_sets hx₂ hy₂⟩,
inter_subset_left _ _, inter_subset_right _ _⟩ }
protected def inf (f g : filter α) :=
{ filter .
sets := {s | ∃ a ∈ f^.sets, ∃ b ∈ g^.sets, a ∩ b ⊆ s },
inhabited := ⟨univ, univ, univ_mem_sets, univ, univ_mem_sets, subset_univ _⟩,
upwards_sets := assume x y ⟨a, ha, b, hb, h⟩ xy,
⟨a, ha, b, hb, subset.trans h xy⟩,
directed_sets := assume x ⟨a₁, ha₁, b₁, hb₁, h₁⟩ y ⟨a₂, ha₂, b₂, hb₂, h₂⟩,
⟨x ∩ y,
⟨_, inter_mem_sets ha₁ ha₂, _, inter_mem_sets hb₁ hb₂,
calc (a₁ ⊓ a₂) ⊓ (b₁ ⊓ b₂) = (a₁ ⊓ b₁) ⊓ (a₂ ⊓ b₂) : by ac_refl
... ≤ x ∩ y : inf_le_inf h₁ h₂ ⟩,
inter_subset_left _ _, inter_subset_right _ _⟩ }
def cofinite : filter α :=
{ filter .
sets := {s | finite (- s)},
inhabited := ⟨univ, by simp⟩,
upwards_sets := assume s t, assume hs : finite (-s), assume st: s ⊆ t,
finite_subset hs $ @lattice.neg_le_neg (set α) _ _ _ st,
directed_sets := assume s, assume hs : finite (-s), assume t, assume ht : finite (-t),
⟨s ∩ t, by simp [compl_inter, finite_union, ht, hs],
inter_subset_left _ _, inter_subset_right _ _⟩ }
instance weak_order_filter : weak_order (filter α) :=
{ weak_order .
le := λf g, g^.sets ⊆ f^.sets,
le_antisymm := assume a b h₁ h₂, filter_eq $ subset.antisymm h₂ h₁,
le_refl := assume a, subset.refl _,
le_trans := assume a b c h₁ h₂, subset.trans h₂ h₁ }
instance : has_Sup (filter α) := ⟨join ∘ principal⟩
instance inhabited' : _root_.inhabited (filter α) :=
⟨principal ∅⟩
protected lemma le_Sup {s : set (filter α)} {f : filter α} : f ∈ s → f ≤ Sup s :=
assume f_in_s t' h, h f_in_s
protected lemma Sup_le {s : set (filter α)} {f : filter α} : (∀g∈s, g ≤ f) → Sup s ≤ f :=
assume h a ha g hg, h g hg ha
@[simp]
lemma mem_join_sets {s : set α} {f : filter (filter α)} : s ∈ (join f)^.sets = ({t | s ∈ filter.sets t} ∈ f^.sets) :=
rfl
@[simp]
lemma mem_principal_sets {s t : set α} : s ∈ (principal t)^.sets = (t ⊆ s) :=
rfl
@[simp]
lemma le_principal_iff {s : set α} {f : filter α} : f ≤ principal s ↔ s ∈ f^.sets :=
show (∀{t}, s ⊆ t → t ∈ f^.sets) ↔ s ∈ f^.sets,
from ⟨assume h, h (subset.refl s), assume hs t ht, f^.upwards_sets hs ht⟩
lemma principal_mono {s t : set α} : principal s ≤ principal t ↔ s ⊆ t :=
by simp
lemma monotone_principal : monotone (principal : set α → filter α) :=
by simp [monotone, principal_mono]; exact assume a b h, h
@[simp]
lemma principal_eq_iff_eq {s t : set α} : principal s = principal t ↔ s = t :=
by simp [eq_iff_le_and_le]; refl
instance complete_lattice_filter : complete_lattice (filter α) :=
{ filter.weak_order_filter with
sup := filter.sup,
le_sup_left := assume a b, inter_subset_left _ _,
le_sup_right := assume a b, inter_subset_right _ _,
sup_le := assume a b c h₁ h₂, subset_inter h₁ h₂,
inf := filter.inf,
le_inf := assume f g h fg fh s ⟨a, ha, b, hb, h⟩,
f^.upwards_sets (inter_mem_sets (fg ha) (fh hb)) h,
inf_le_left := assume f g s h, ⟨s, h, univ, univ_mem_sets, inter_subset_left _ _⟩,
inf_le_right := assume f g s h, ⟨univ, univ_mem_sets, s, h, inter_subset_right _ _⟩,
top := principal univ,
le_top := assume a, show a ≤ principal univ, by simp [univ_mem_sets],
bot := principal ∅,
bot_le := assume a, show a^.sets ⊆ {x | ∅ ⊆ x}, by simp; apply subset_univ,
Sup := Sup,
le_Sup := assume s f, filter.le_Sup,
Sup_le := assume s f, filter.Sup_le,
Inf := λs, Sup {x | ∀y∈s, x ≤ y},
le_Inf := assume s a h, filter.le_Sup h,
Inf_le := assume s a ha, filter.Sup_le $ assume b h, h _ ha }
@[simp]
lemma map_principal {s : set α} {f : α → β} :
map f (principal s) = principal (set.image f s) :=
filter_eq $ set.ext $ assume a, image_subset_iff_subset_vimage^.symm
@[simp]
lemma join_principal_eq_Sup {s : set (filter α)} : join (principal s) = Sup s :=
rfl
instance monad_filter : monad filter :=
{ monad .
bind := λ(α β : Type u) f m, join (map m f),
pure := λ(α : Type u) x, principal {x},
map := λ(α β : Type u), filter.map,
id_map := assume α f, filter_eq $ rfl,
pure_bind := assume α β a f, by simp [Sup_image],
bind_assoc := assume α β γ f m₁ m₂, filter_eq $ rfl,
bind_pure_comp_eq_map := assume α β f x, filter_eq $ by simp [join, map, vimage, principal] }
@[simp] theorem pure_def (x : α) : pure x = principal {x} := rfl
@[simp] theorem bind_def {α β} (f : filter α) (m : α → filter β) : f >>= m = join (map m f) := rfl
instance : alternative filter :=
{ filter.monad_filter with
failure := λα, ⊥,
orelse := λα x y, x ⊔ y }
def at_top [weak_order α] : filter α := ⨅ a, principal {b | a ≤ b}
def at_bot [weak_order α] : filter α := ⨅ a, principal {b | b ≤ a}
/- lattice equations -/
lemma mem_inf_sets_of_left {f g : filter α} {s : set α} :
s ∈ f.sets → s ∈ (f ⊓ g)^.sets :=
have f ⊓ g ≤ f, from inf_le_left,
assume hs, this hs
lemma mem_inf_sets_of_right {f g : filter α} {s : set α} :
s ∈ g.sets → s ∈ (f ⊓ g)^.sets :=
have f ⊓ g ≤ g, from inf_le_right,
assume hs, this hs
@[simp]
lemma mem_bot_sets {s : set α} : s ∈ (⊥ : filter α)^.sets :=
assume x, false.elim
lemma empty_in_sets_eq_bot {f : filter α} : ∅ ∈ f^.sets ↔ f = ⊥ :=
⟨assume h, bot_unique $ assume s _, f.upwards_sets h (empty_subset s),
assume : f = ⊥, this.symm ▸ mem_bot_sets⟩
lemma inhabited_of_mem_sets {f : filter α} {s : set α} (hf : f ≠ ⊥) (hs : s ∈ f^.sets) :
∃x, x ∈ s :=
have ∅ ∉ f^.sets, from assume h, hf $ empty_in_sets_eq_bot.mp h,
have s ≠ ∅, from assume h, this (h ▸ hs),
exists_mem_of_ne_empty this
lemma filter_eq_bot_of_not_nonempty {f : filter α} (ne : ¬ nonempty α) : f = ⊥ :=
empty_in_sets_eq_bot.mp $ f.upwards_sets univ_mem_sets $
assume x, false.elim (ne ⟨x⟩)
lemma forall_sets_neq_empty_iff_neq_bot {f : filter α} :
(∀ (s : set α), s ∈ f.sets → s ≠ ∅) ↔ f ≠ ⊥ :=
by
simp [(@empty_in_sets_eq_bot α f).symm];
exact ⟨assume h hs, h _ hs rfl, assume h s hs eq, h $ eq ▸ hs⟩
lemma mem_sets_of_neq_bot {f : filter α} {s : set α} (h : f ⊓ principal (-s) = ⊥) : s ∈ f.sets :=
have ∅ ∈ (f ⊓ principal (- s)).sets, from h.symm ▸ mem_bot_sets,
let ⟨s₁, hs₁, s₂, (hs₂ : -s ⊆ s₂), (hs : s₁ ∩ s₂ ⊆ ∅)⟩ := this in
have s₁ ⊆ s, from assume a ha, classical.by_contradiction $ assume ha', hs ⟨ha, hs₂ ha'⟩,
f.upwards_sets hs₁ this
@[simp]
lemma mem_sup_sets {f g : filter α} {s : set α} :
s ∈ (f ⊔ g)^.sets = (s ∈ f^.sets ∧ s ∈ g^.sets) :=
by refl
@[simp]
lemma mem_inf_sets {f g : filter α} {s : set α} :
s ∈ (f ⊓ g)^.sets = (∃t₁∈f^.sets, ∃t₂∈g^.sets, t₁ ∩ t₂ ⊆ s) :=
by refl
lemma infi_sets_eq {f : ι → filter α} (h : directed (≤) f) (ne : nonempty ι) :
(infi f)^.sets = (⋃ i, (f i)^.sets) :=
let
⟨i⟩ := ne,
u := { filter .
sets := (⋃ i, (f i)^.sets),
inhabited := ⟨univ, begin simp, exact ⟨i, univ_mem_sets⟩ end⟩,
directed_sets := directed_on_Union (show directed (≤) f, from h) (assume i, (f i)^.directed_sets),
upwards_sets := by simp [upwards]; exact assume x y ⟨j, xf⟩ xy, ⟨j, (f j)^.upwards_sets xf xy⟩ }
in
subset.antisymm
(show u ≤ infi f, from le_infi $ assume i, le_supr (λi, (f i)^.sets) i)
(Union_subset $ assume i, infi_le f i)
lemma infi_sets_eq' {f : β → filter α} {s : set β} (h : directed_on (λx y, f x ≤ f y) s) (ne : ∃i, i ∈ s) :
(⨅ i∈s, f i)^.sets = (⋃ i ∈ s, (f i)^.sets) :=
let ⟨i, hi⟩ := ne in
calc (⨅ i ∈ s, f i)^.sets = (⨅ t : {t // t ∈ s}, (f t^.val))^.sets : by simp [infi_subtype]; refl
... = (⨆ t : {t // t ∈ s}, (f t^.val)^.sets) : infi_sets_eq
(assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end)
⟨⟨i, hi⟩⟩
... = (⨆ t ∈ {t | t ∈ s}, (f t)^.sets) : by simp [supr_subtype]; refl
lemma Inf_sets_eq_finite {s : set (filter α)} :
(complete_lattice.Inf s)^.sets = (⋃ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t)^.sets) :=
calc (Inf s)^.sets = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t)^.sets : by rw [lattice.Inf_eq_finite_sets]
... = (⨆ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t)^.sets) : infi_sets_eq'
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∪ y, ⟨finite_union hx₁ hy₁, union_subset hx₂ hy₂⟩,
Inf_le_Inf $ subset_union_left _ _, Inf_le_Inf $ subset_union_right _ _⟩)
⟨∅, by simp⟩
lemma supr_sets_eq {f : ι → filter α} : (supr f)^.sets = (⋂i, (f i)^.sets) :=
set.ext $ assume s,
show s ∈ (join (principal {a : filter α | ∃i : ι, a = f i}))^.sets ↔ s ∈ (⋂i, (f i)^.sets),
begin
rw [mem_join_sets],
simp,
exact ⟨assume h i, h (f i) ⟨_, rfl⟩, assume h x ⟨i, eq⟩, eq^.symm ▸ h i⟩
end
@[simp]
lemma sup_join {f₁ f₂ : filter (filter α)} : (join f₁ ⊔ join f₂) = join (f₁ ⊔ f₂) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq, join]
@[simp]
lemma supr_join {ι : Sort w} {f : ι → filter (filter α)} : (⨆x, join (f x)) = join (⨆x, f x) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq, join]
instance : bounded_distrib_lattice (filter α) :=
{ filter.complete_lattice_filter with
le_sup_inf := assume x y z s h,
begin
cases h with h₁ h₂, revert h₂,
simp,
exact assume ⟨t₁, ht₁, t₂, ht₂, hs⟩, ⟨s ∪ t₁,
x^.upwards_sets h₁ $ subset_union_left _ _,
y^.upwards_sets ht₁ $ subset_union_right _ _,
s ∪ t₂,
x^.upwards_sets h₁ $ subset_union_left _ _,
z^.upwards_sets ht₂ $ subset_union_right _ _,
subset.trans (@le_sup_inf (set α) _ _ _ _) (union_subset (subset.refl _) hs)⟩
end }
private theorem infi_finite_distrib {s : set (filter α)} {f : filter α} (h : finite s) :
(⨅ a ∈ s, f ⊔ a) = f ⊔ (Inf s) :=
begin
induction h with a s hn hs hi,
{ simp, exact infi_const ⊥ },
{ rw [infi_insert], simp [hi, infi_or, sup_inf_left] }
end
/- the complementary version with ⨆ g∈s, f ⊓ g does not hold! -/
lemma binfi_sup_eq { f : filter α } {s : set (filter α)} :
(⨅ g∈s, f ⊔ g) = f ⊔ complete_lattice.Inf s :=
le_antisymm
begin
intros t h,
cases h with h₁ h₂,
rw [Inf_sets_eq_finite] at h₂,
simp at h₂,
cases h₂ with s' hs', cases hs' with hs' hs'', cases hs'' with hs's ht',
have ht : t ∈ (⨅ a ∈ s', f ⊔ a)^.sets,
{ rw [infi_finite_distrib], exact ⟨h₁, ht'⟩, exact hs' },
clear h₁ ht',
revert ht t,
change (⨅ a ∈ s, f ⊔ a) ≤ (⨅ a ∈ s', f ⊔ a),
apply infi_le_infi2 _,
exact assume i, ⟨i, infi_le_infi2 $ assume h, ⟨hs's h, le_refl _⟩⟩
end
(le_infi $ assume g, le_infi $ assume h, sup_le_sup (le_refl f) $ Inf_le h)
lemma infi_sup_eq { f : filter α } {g : ι → filter α} :
(⨅ x, f ⊔ g x) = f ⊔ infi g :=
calc (⨅ x, f ⊔ g x) = (⨅ x (h : ∃i, g i = x), f ⊔ x) : by simp; rw [infi_comm]; simp
... = f ⊔ Inf {x | ∃i, g i = x} : binfi_sup_eq
... = f ⊔ infi g : by rw [Inf_eq_infi]; dsimp; simp; rw [infi_comm]; simp
/- principal equations -/
@[simp]
lemma inf_principal {s t : set α} : principal s ⊓ principal t = principal (s ∩ t) :=
le_antisymm
(by simp; exact ⟨s, subset.refl s, t, subset.refl t, subset.refl _⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp]
lemma sup_principal {s t : set α} : principal s ⊔ principal t = principal (s ∪ t) :=
filter_eq $ set.ext $ by simp [union_subset_iff]
@[simp]
lemma supr_principal {ι : Sort w} {s : ι → set α} : (⨆x, principal (s x)) = principal (⋃i, s i) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq]; exact (@supr_le_iff (set α) _ _ _ _)^.symm
lemma principal_univ : principal (univ : set α) = ⊤ :=
rfl
lemma principal_empty : principal (∅ : set α) = ⊥ :=
rfl
@[simp]
lemma principal_eq_bot_iff {s : set α} : principal s = ⊥ ↔ s = ∅ :=
⟨assume h, principal_eq_iff_eq.mp $ by simp [principal_empty, h], assume h, by simp [*, principal_empty]⟩
@[simp]
lemma mem_pure {a : α} {s : set α} : a ∈ s → s ∈ (pure a : filter α).sets :=
by simp; exact id
/- map equations -/
@[simp]
lemma mem_map {f : filter α} {s : set β} {m : α → β} :
(s ∈ (map m f)^.sets) = ({x | m x ∈ s} ∈ f^.sets) :=
rfl
lemma image_mem_map {f : filter α} {m : α → β} {s : set α} (hs : s ∈ f.sets):
m '' s ∈ (map m f).sets :=
f.upwards_sets hs $ assume x hx, ⟨x, hx, rfl⟩
@[simp]
lemma map_id {f : filter α} : filter.map id f = f :=
filter_eq $ rfl
@[simp]
lemma map_compose {γ : Type w} {f : α → β} {g : β → γ} :
filter.map g ∘ filter.map f = filter.map (g ∘ f) :=
funext $ assume _, filter_eq $ rfl
@[simp]
lemma map_sup {f g : filter α} {m : α → β} : map m (f ⊔ g) = map m f ⊔ map m g :=
filter_eq $ set.ext $ assume x, by simp
@[simp]
lemma supr_map {ι : Sort w} {f : ι → filter α} {m : α → β} : (⨆x, map m (f x)) = map m (⨆x, f x) :=
filter_eq $ set.ext $ assume x, by simp [supr_sets_eq, map]
@[simp]
lemma map_bot {m : α → β} : map m ⊥ = ⊥ :=
filter_eq $ set.ext $ assume x, by simp
@[simp]
lemma map_eq_bot_iff {f : filter α} {m : α → β} : map m f = ⊥ ↔ f = ⊥ :=
⟨by rw [←empty_in_sets_eq_bot, ←empty_in_sets_eq_bot]; exact id,
assume h, by simp [*]⟩
lemma map_mono {f g : filter α} {m : α → β} (h : f ≤ g) : map m f ≤ map m g :=
le_of_sup_eq $ calc
map m f ⊔ map m g = map m (f ⊔ g) : map_sup
... = map m g : congr_arg (map m) $ sup_of_le_right h
lemma monotone_map {m : α → β} : monotone (map m : filter α → filter β) :=
assume a b h, map_mono h
-- this is a generic rule for monotone functions:
lemma map_infi_le {f : ι → filter α} {m : α → β} :
map m (infi f) ≤ (⨅ i, map m (f i)) :=
le_infi $ assume i, map_mono $ infi_le _ _
lemma map_infi_eq {f : ι → filter α} {m : α → β} (hf : directed (≤) f) (hι : nonempty ι) :
map m (infi f) = (⨅ i, map m (f i)) :=
le_antisymm
map_infi_le
(assume s (hs : vimage m s ∈ (infi f).sets),
have ∃i, vimage m s ∈ (f i).sets,
by simp [infi_sets_eq hf hι] at hs; assumption,
let ⟨i, hi⟩ := this in
have (⨅ i, map m (f i)) ≤ principal s,
from infi_le_of_le i $ by simp; assumption,
by simp at this; assumption)
lemma map_binfi_eq {ι : Type w} {f : ι → filter α} {m : α → β} {s : set ι}
(h : directed_on (λx y, f x ≤ f y) s) (ne : ∃i, i ∈ s) : map m (⨅i∈s, f i) = (⨅i∈s, map m (f i)) :=
let ⟨i, hi⟩ := ne in
calc map m (⨅i∈s, f i) = map m (⨅i:{i // i ∈ s}, f i.val) : by simp [infi_subtype]
... = (⨅i:{i // i ∈ s}, map m (f i.val)) : map_infi_eq
(assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end)
⟨⟨i, hi⟩⟩
... = (⨅i∈s, map m (f i)) : by simp [infi_subtype]
/- bind equations -/
lemma mem_bind_sets {β : Type u} {s : set β} {f : filter α} {m : α → filter β} :
s ∈ (f >>= m)^.sets ↔ (∃t ∈ f^.sets, ∀x ∈ t, s ∈ (m x)^.sets) :=
calc s ∈ (f >>= m)^.sets ↔ {a | s ∈ (m a)^.sets} ∈ f^.sets : by simp
... ↔ (∃t ∈ f^.sets, t ⊆ {a | s ∈ (m a)^.sets}) : exists_sets_subset_iff^.symm
... ↔ (∃t ∈ f^.sets, ∀x ∈ t, s ∈ (m x)^.sets) : iff.refl _
lemma bind_mono {β : Type u} {f : filter α} {g h : α → filter β} (h₁ : {a | g a ≤ h a} ∈ f^.sets) :
f >>= g ≤ f >>= h :=
assume x h₂, f^.upwards_sets (inter_mem_sets h₁ h₂) $ assume s ⟨gh', h'⟩, gh' h'
lemma bind_sup {β : Type u} {f g : filter α} {h : α → filter β} :
(f ⊔ g) >>= h = (f >>= h) ⊔ (g >>= h) :=
by simp
lemma bind_mono2 {β : Type u} {f g : filter α} {h : α → filter β} (h₁ : f ≤ g) :
f >>= h ≤ g >>= h :=
assume s h', h₁ h'
lemma principal_bind {β : Type u} {s : set α} {f : α → filter β} :
(principal s >>= f) = (⨆x ∈ s, f x) :=
show join (map f (principal s)) = (⨆x ∈ s, f x),
by simp [Sup_image]
lemma seq_mono {β : Type u} {f₁ f₂ : filter (α → β)} {g₁ g₂ : filter α}
(hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ <*> g₁ ≤ f₂ <*> g₂ :=
le_trans (bind_mono2 hf) (bind_mono $ univ_mem_sets' $ assume f, map_mono hg)
@[simp]
lemma fmap_principal {β : Type u} {s : set α} {f : α → β} :
f <$> principal s = principal (set.image f s) :=
filter_eq $ set.ext $ assume a, image_subset_iff_subset_vimage^.symm
lemma mem_return_sets {a : α} {s : set α} : s ∈ (return a : filter α)^.sets ↔ a ∈ s :=
show s ∈ (principal {a})^.sets ↔ a ∈ s,
by simp
lemma infi_neq_bot_of_directed {f : ι → filter α}
(hn : nonempty α) (hd : directed (≤) f) (hb : ∀i, f i ≠ ⊥): (infi f) ≠ ⊥ :=
let ⟨x⟩ := hn in
assume h, have he: ∅ ∈ (infi f)^.sets, from h.symm ▸ mem_bot_sets,
classical.by_cases
(assume : nonempty ι,
have ∃i, ∅ ∈ (f i).sets,
by rw [infi_sets_eq hd this] at he; simp at he; assumption,
let ⟨i, hi⟩ := this in
hb i $ bot_unique $
assume s _, (f i)^.upwards_sets hi $ empty_subset _)
(assume : ¬ nonempty ι,
have univ ⊆ (∅ : set α),
begin
rw [←principal_mono, principal_univ, principal_empty, ←h],
exact (le_infi $ assume i, false.elim $ this ⟨i⟩)
end,
this $ mem_univ x)
lemma infi_neq_bot_iff_of_directed {f : ι → filter α}
(hn : nonempty α) (hd : directed (≤) f) : (infi f) ≠ ⊥ ↔ (∀i, f i ≠ ⊥) :=
⟨assume neq_bot i eq_bot, neq_bot $ bot_unique $ infi_le_of_le i $ eq_bot ▸ le_refl _,
infi_neq_bot_of_directed hn hd⟩
@[simp] lemma return_neq_bot {α : Type u} {a : α} : return a ≠ (⊥ : filter α) :=
by simp [return]
section vmap
variables {f f₁ f₂ : filter β} {m : α → β}
lemma mem_vmap_of_mem {s : set β} (h : s ∈ f.sets) : vimage m s ∈ (vmap m f).sets :=
⟨s, h, subset.refl _⟩
lemma vmap_mono (h : f₁ ≤ f₂) : vmap m f₁ ≤ vmap m f₂ :=
assume s ⟨t, ht, h_sub⟩, ⟨t, h ht, h_sub⟩
lemma monotone_vmap : monotone (vmap m : filter β → filter α) :=
assume a b h, vmap_mono h
@[simp]
lemma vmap_principal {t : set β} : vmap m (principal t) = principal (vimage m t) :=
filter_eq $ set.ext $ assume s,
⟨assume ⟨u, (hu : t ⊆ u), (b : vimage m u ⊆ s)⟩, subset.trans (vimage_mono hu) b,
assume : vimage m t ⊆ s, ⟨t, subset.refl t, this⟩⟩
lemma vimage_mem_vmap {f : filter β} {m : α → β} {s : set β} (hs : s ∈ f.sets):
vimage m s ∈ (vmap m f).sets :=
⟨s, hs, subset.refl _⟩
lemma le_map_vmap {f : filter β} {m : α → β} (hm : ∀x, ∃y, m y = x) :
f ≤ map m (vmap m f) :=
assume s ⟨t, ht, (sub : ∀x, m x ∈ t → m x ∈ s)⟩,
f.upwards_sets ht $
assume x, let ⟨y, (hy : m y = x)⟩ := hm x in
hy ▸ sub y
lemma vmap_map {f : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) :
vmap m (map m f) = f :=
have ∀s, vimage m (image m s) = s,
from assume s, vimage_image_eq h,
le_antisymm
(assume s hs, ⟨
image m s,
f.upwards_sets hs $ by simp [this, subset.refl],
by simp [this, subset.refl]⟩)
(assume s ⟨t, (h₁ : vimage m t ∈ f.sets), (h₂ : vimage m t ⊆ s)⟩,
f.upwards_sets h₁ h₂)
lemma vmap_neq_bot {f : filter β} {m : α → β}
(hm : ∀t∈f.sets, ∃a, m a ∈ t) : vmap m f ≠ ⊥ :=
forall_sets_neq_empty_iff_neq_bot.mp $ assume s ⟨t, ht, t_s⟩,
let ⟨a, (ha : a ∈ vimage m t)⟩ := hm t ht in
neq_bot_of_le_neq_bot (ne_empty_of_mem ha) t_s
lemma vmap_neq_bot_of_surj {f : filter β} {m : α → β}
(hf : f ≠ ⊥) (hm : ∀b, ∃a, m a = b) : vmap m f ≠ ⊥ :=
vmap_neq_bot $ assume t ht,
let
⟨b, (hx : b ∈ t)⟩ := inhabited_of_mem_sets hf ht,
⟨a, (ha : m a = b)⟩ := hm b
in ⟨a, ha.symm ▸ hx⟩
lemma map_vmap_le {f : filter β} {m : α → β} : map m (vmap m f) ≤ f :=
assume s hs, ⟨s, hs, subset.refl _⟩
lemma le_vmap_map {f : filter α} {m : α → β} : f ≤ vmap m (map m f) :=
assume s ⟨t, ht, h_eq⟩, f.upwards_sets ht h_eq
lemma vmap_vmap_comp {f : filter α} {m : γ → β} {n : β → α} :
vmap m (vmap n f) = vmap (n ∘ m) f :=
le_antisymm
(assume c ⟨b, hb, (h : vimage (n ∘ m) b ⊆ c)⟩, ⟨vimage n b, vimage_mem_vmap hb, h⟩)
(assume c ⟨b, ⟨a, ha, (h₁ : vimage n a ⊆ b)⟩, (h₂ : vimage m b ⊆ c)⟩,
⟨a, ha, show vimage m (vimage n a) ⊆ c, from subset.trans (vimage_mono h₁) h₂⟩)
lemma le_vmap_iff_map_le {f : filter α} {g : filter β} {m : α → β} :
f ≤ vmap m g ↔ map m f ≤ g :=
⟨assume h, le_trans (map_mono h) map_vmap_le,
assume h, le_trans le_vmap_map (vmap_mono h)⟩
end vmap
section lift
protected def lift (f : filter α) (g : set α → filter β) :=
(⨅s ∈ f^.sets, g s)
section
variables {f f₁ f₂ : filter α} {g g₁ g₂ : set α → filter β}
lemma lift_sets_eq (hg : monotone g) : (f^.lift g)^.sets = (⋃t∈f^.sets, (g t)^.sets) :=
infi_sets_eq'
(assume s hs t ht, ⟨s ∩ t, inter_mem_sets hs ht,
hg $ inter_subset_left s t, hg $ inter_subset_right s t⟩)
⟨univ, univ_mem_sets⟩
lemma mem_lift {s : set β} {t : set α} (ht : t ∈ f^.sets) (hs : s ∈ (g t)^.sets) :
s ∈ (f^.lift g)^.sets :=
le_principal_iff.mp $ show f^.lift g ≤ principal s,
from infi_le_of_le t $ infi_le_of_le ht $ le_principal_iff.mpr hs
lemma mem_lift_iff (hg : monotone g) {s : set β} :
s ∈ (f^.lift g)^.sets ↔ (∃t∈f^.sets, s ∈ (g t)^.sets) :=
by rw [lift_sets_eq hg]; simp
lemma lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁^.lift g₁ ≤ f₂^.lift g₂ :=
infi_le_infi $ assume s, infi_le_infi2 $ assume hs, ⟨hf hs, hg s⟩
lemma lift_mono' (hg : ∀s∈f^.sets, g₁ s ≤ g₂ s) : f^.lift g₁ ≤ f^.lift g₂ :=
infi_le_infi $ assume s, infi_le_infi $ assume hs, hg s hs
lemma map_lift_eq {m : β → γ} (hg : monotone g) :
map m (f^.lift g) = f^.lift (map m ∘ g) :=
have monotone (map m ∘ g),
from monotone_comp hg monotone_map,
filter_eq $ set.ext $
by simp [mem_lift_iff, hg, @mem_lift_iff _ _ f _ this]
lemma vmap_lift_eq {m : γ → β} (hg : monotone g) :
vmap m (f^.lift g) = f^.lift (vmap m ∘ g) :=
have monotone (vmap m ∘ g),
from monotone_comp hg monotone_vmap,
filter_eq $ set.ext $
begin
simp [vmap, mem_lift_iff, hg, @mem_lift_iff _ _ f _ this],
simp [vmap, function.comp],
exact assume s, ⟨assume ⟨t₁, hs, t₂, ht, ht₁⟩, ⟨t₂, ht, t₁, hs, ht₁⟩,
assume ⟨t₂, ht, t₁, hs, ht₁⟩, ⟨t₁, hs, t₂, ht, ht₁⟩⟩
end
lemma vmap_lift_eq2 {m : β → α} {g : set β → filter γ} (hg : monotone g) :
(vmap m f)^.lift g = f^.lift (g ∘ vimage m) :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le (vimage m s) $ infi_le _ ⟨s, hs, subset.refl _⟩)
(le_infi $ assume s, le_infi $ assume ⟨s', hs', (h_sub : vimage m s' ⊆ s)⟩,
infi_le_of_le s' $ infi_le_of_le hs' $ hg h_sub)
lemma map_lift_eq2 {g : set β → filter γ} {m : α → β} (hg : monotone g) :
(map m f)^.lift g = f^.lift (g ∘ image m) :=
le_antisymm
(infi_le_infi2 $ assume s, ⟨image m s,
infi_le_infi2 $ assume hs, ⟨
f^.upwards_sets hs $ assume a h, mem_image_of_mem _ h,
le_refl _⟩⟩)
(infi_le_infi2 $ assume t, ⟨vimage m t,
infi_le_infi2 $ assume ht, ⟨ht,
hg $ assume x, assume h : x ∈ m '' vimage m t,
let ⟨y, hy, h_eq⟩ := h in
show x ∈ t, from h_eq ▸ hy⟩⟩)
lemma lift_comm {g : filter β} {h : set α → set β → filter γ} :
f^.lift (λs, g^.lift (h s)) = g^.lift (λt, f^.lift (λs, h s t)) :=
le_antisymm
(le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj,
infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi)
(le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj,
infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi)
lemma lift_assoc {h : set β → filter γ} (hg : monotone g) :
(f^.lift g)^.lift h = f^.lift (λs, (g s)^.lift h) :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le t $ infi_le _ $ (mem_lift_iff hg)^.mpr ⟨_, hs, ht⟩)
(le_infi $ assume t, le_infi $ assume ht,
let ⟨s, hs, h'⟩ := (mem_lift_iff hg)^.mp ht in
infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le t $ infi_le _ h')
lemma lift_lift_same_le_lift {g : set α → set α → filter β} :
f^.lift (λs, f^.lift (g s)) ≤ f^.lift (λs, g s s) :=
le_infi $ assume s, le_infi $ assume hs, infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le _ hs
lemma lift_lift_same_eq_lift {g : set α → set α → filter β}
(hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)):
f^.lift (λs, f^.lift (g s)) = f^.lift (λs, g s s) :=
le_antisymm
lift_lift_same_le_lift
(le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le (s ∩ t) $
infi_le_of_le (inter_mem_sets hs ht) $
calc g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) : hg₂ (s ∩ t) (inter_subset_left _ _)
... ≤ g s t : hg₁ s (inter_subset_right _ _))
lemma lift_principal {s : set α} (hg : monotone g) :
(principal s)^.lift g = g s :=
le_antisymm
(infi_le_of_le s $ infi_le _ $ subset.refl _)
(le_infi $ assume t, le_infi $ assume hi, hg hi)
lemma monotone_lift [weak_order γ] {f : γ → filter α} {g : γ → set α → filter β}
(hf : monotone f) (hg : monotone g) : monotone (λc, (f c)^.lift (g c)) :=
assume a b h, lift_mono (hf h) (hg h)
lemma lift_neq_bot_iff (hm : monotone g) : (f^.lift g ≠ ⊥) ↔ (∀s∈f.sets, g s ≠ ⊥) :=
classical.by_cases
(assume hn : nonempty β,
calc f^.lift g ≠ ⊥ ↔ (⨅s : { s // s ∈ f^.sets}, g s.val) ≠ ⊥ : by simp [filter.lift, infi_subtype]
... ↔ (∀s:{ s // s ∈ f^.sets}, g s.val ≠ ⊥) :
infi_neq_bot_iff_of_directed hn
(assume ⟨a, ha⟩ ⟨b, hb⟩, ⟨⟨a ∩ b, inter_mem_sets ha hb⟩,
hm $ inter_subset_left _ _, hm $ inter_subset_right _ _⟩)
... ↔ (∀s∈f.sets, g s ≠ ⊥) : ⟨assume h s hs, h ⟨s, hs⟩, assume h ⟨s, hs⟩, h s hs⟩)
(assume hn : ¬ nonempty β,
have h₁ : f.lift g = ⊥, from filter_eq_bot_of_not_nonempty hn,
have h₂ : ∀s, g s = ⊥, from assume s, filter_eq_bot_of_not_nonempty hn,
calc (f.lift g ≠ ⊥) ↔ false : by simp [h₁]
... ↔ (∀s∈f.sets, false) : ⟨false.elim, assume h, h univ univ_mem_sets⟩
... ↔ (∀s∈f.sets, g s ≠ ⊥) : by simp [h₂])
end
section
protected def lift' (f : filter α) (h : set α → set β) :=
f^.lift (principal ∘ h)
variables {f f₁ f₂ : filter α} {h h₁ h₂ : set α → set β}
lemma mem_lift' {t : set α} (ht : t ∈ f^.sets) : h t ∈ (f^.lift' h)^.sets :=
le_principal_iff.mp $ show f^.lift' h ≤ principal (h t),
from infi_le_of_le t $ infi_le_of_le ht $ le_refl _
lemma mem_lift'_iff (hh : monotone h) {s : set β} : s ∈ (f^.lift' h)^.sets ↔ (∃t∈f^.sets, h t ⊆ s) :=
have monotone (principal ∘ h),
from assume a b h, principal_mono.mpr $ hh h,
by simp [filter.lift', @mem_lift_iff α β f _ this]
lemma lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁^.lift' h₁ ≤ f₂^.lift' h₂ :=
lift_mono hf $ assume s, principal_mono.mpr $ hh s
lemma lift'_mono' (hh : ∀s∈f^.sets, h₁ s ⊆ h₂ s) : f^.lift' h₁ ≤ f^.lift' h₂ :=
infi_le_infi $ assume s, infi_le_infi $ assume hs, principal_mono.mpr $ hh s hs
lemma lift'_cong (hh : ∀s∈f^.sets, h₁ s = h₂ s) : f^.lift' h₁ = f^.lift' h₂ :=
le_antisymm (lift'_mono' $ assume s hs, le_of_eq $ hh s hs) (lift'_mono' $ assume s hs, le_of_eq $ (hh s hs).symm)
lemma map_lift'_eq {m : β → γ} (hh : monotone h) : map m (f^.lift' h) = f^.lift' (image m ∘ h) :=
calc map m (f^.lift' h) = f^.lift (map m ∘ principal ∘ h) :
map_lift_eq $ monotone_comp hh monotone_principal
... = f^.lift' (image m ∘ h) : by simp [function.comp, filter.lift']
lemma map_lift'_eq2 {g : set β → set γ} {m : α → β} (hg : monotone g) :
(map m f)^.lift' g = f^.lift' (g ∘ image m) :=
map_lift_eq2 $ monotone_comp hg monotone_principal
lemma vmap_lift'_eq {m : γ → β} (hh : monotone h) :
vmap m (f^.lift' h) = f^.lift' (vimage m ∘ h) :=
calc vmap m (f^.lift' h) = f^.lift (vmap m ∘ principal ∘ h) :
vmap_lift_eq $ monotone_comp hh monotone_principal
... = f^.lift' (vimage m ∘ h) : by simp [function.comp, filter.lift']
lemma vmap_lift'_eq2 {m : β → α} {g : set β → set γ} (hg : monotone g) :
(vmap m f)^.lift' g = f^.lift' (g ∘ vimage m) :=
vmap_lift_eq2 $ monotone_comp hg monotone_principal
lemma lift'_principal {s : set α} (hh : monotone h) :
(principal s)^.lift' h = principal (h s) :=
lift_principal $ monotone_comp hh monotone_principal
lemma principal_le_lift' {t : set β} (hh : ∀s∈f^.sets, t ⊆ h s) :
principal t ≤ f^.lift' h :=
le_infi $ assume s, le_infi $ assume hs, principal_mono^.mpr (hh s hs)
lemma monotone_lift' [weak_order γ] {f : γ → filter α} {g : γ → set α → set β}
(hf : monotone f) (hg : monotone g) : monotone (λc, (f c)^.lift' (g c)) :=
assume a b h, lift'_mono (hf h) (hg h)
lemma lift_lift'_assoc {g : set α → set β} {h : set β → filter γ}
(hg : monotone g) (hh : monotone h) :
(f^.lift' g)^.lift h = f^.lift (λs, h (g s)) :=
calc (f^.lift' g)^.lift h = f^.lift (λs, (principal (g s))^.lift h) :
lift_assoc (monotone_comp hg monotone_principal)
... = f^.lift (λs, h (g s)) : by simp [lift_principal, hh]
lemma lift'_lift'_assoc {g : set α → set β} {h : set β → set γ}
(hg : monotone g) (hh : monotone h) :
(f^.lift' g)^.lift' h = f^.lift' (λs, h (g s)) :=
lift_lift'_assoc hg (monotone_comp hh monotone_principal)
lemma lift'_lift_assoc {g : set α → filter β} {h : set β → set γ}
(hg : monotone g) : (f^.lift g)^.lift' h = f^.lift (λs, (g s)^.lift' h) :=
lift_assoc hg
lemma lift_lift'_same_le_lift' {g : set α → set α → set β} :
f^.lift (λs, f^.lift' (g s)) ≤ f^.lift' (λs, g s s) :=
lift_lift_same_le_lift
lemma lift_lift'_same_eq_lift' {g : set α → set α → set β}
(hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)):
f^.lift (λs, f^.lift' (g s)) = f^.lift' (λs, g s s) :=
lift_lift_same_eq_lift
(assume s, monotone_comp monotone_id $ monotone_comp (hg₁ s) monotone_principal)
(assume t, monotone_comp (hg₂ t) monotone_principal)
lemma lift'_inf_principal_eq {h : set α → set β} {s : set β} :
f^.lift' h ⊓ principal s = f^.lift' (λt, h t ∩ s) :=
le_antisymm
(le_infi $ assume t, le_infi $ assume ht,
calc filter.lift' f h ⊓ principal s ≤ principal (h t) ⊓ principal s :
inf_le_inf (infi_le_of_le t $ infi_le _ ht) (le_refl _)
... = _ : by simp)
(le_inf
(le_infi $ assume t, le_infi $ assume ht,
infi_le_of_le t $ infi_le_of_le ht $ by simp; exact inter_subset_right _ _)
(infi_le_of_le univ $ infi_le_of_le univ_mem_sets $ by simp; exact inter_subset_left _ _))
lemma lift'_neq_bot_iff (hh : monotone h) : (f^.lift' h ≠ ⊥) ↔ (∀s∈f.sets, h s ≠ ∅) :=
calc (f^.lift' h ≠ ⊥) ↔ (∀s∈f.sets, principal (h s) ≠ ⊥) :
lift_neq_bot_iff (monotone_comp hh monotone_principal)
... ↔ (∀s∈f.sets, h s ≠ ∅) : by simp [principal_eq_bot_iff]
@[simp]
lemma lift'_id {f : filter α} : f.lift' id = f :=
le_antisymm
(assume s hs, mem_lift' hs)
(le_infi $ assume s, le_infi $ assume hs, by simp [hs])
lemma le_lift' {f : filter α} {h : set α → set β} {g : filter β}
(h_le : ∀s∈f.sets, h s ∈ g.sets) : g ≤ f.lift' h :=
le_infi $ assume s, le_infi $ assume hs, by simp [h_le]; exact h_le s hs
end
end lift
lemma vmap_eq_lift' {f : filter β} {m : α → β} :
vmap m f = f.lift' (vimage m) :=
filter_eq $ set.ext $ by simp [mem_lift'_iff, monotone_vimage, vmap]
/- product filter -/
/- The product filter cannot be defined using the monad structure on filters. For example:
F := do {x <- seq, y <- top, return (x, y)}
hence:
s ∈ F <-> ∃n, [n..∞] × univ ⊆ s
G := do {y <- top, x <- seq, return (x, y)}
hence:
s ∈ G <-> ∀i:ℕ, ∃n, [n..∞] × {i} ⊆ s
Now ⋃i, [i..∞] × {i} is in G but not in F.
As product filter we want to have F as result.
-/
section prod
protected def prod (f : filter α) (g : filter β) : filter (α × β) :=
f^.lift $ λs, g^.lift' $ λt, set.prod s t
lemma prod_mem_prod {s : set α} {t : set β} {f : filter α} {g : filter β}
(hs : s ∈ f^.sets) (ht : t ∈ g^.sets) : set.prod s t ∈ (filter.prod f g)^.sets :=
le_principal_iff^.mp $ show filter.prod f g ≤ principal (set.prod s t),
from infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le t $ infi_le _ ht
lemma prod_same_eq {f : filter α} : filter.prod f f = f^.lift' (λt, set.prod t t) :=
lift_lift'_same_eq_lift'
(assume s, set.monotone_prod monotone_const monotone_id)
(assume t, set.monotone_prod monotone_id monotone_const)
lemma mem_prod_iff {s : set (α×β)} {f : filter α} {g : filter β} :
s ∈ (filter.prod f g)^.sets ↔ (∃t₁∈f^.sets, ∃t₂∈g^.sets, set.prod t₁ t₂ ⊆ s) :=
begin
delta filter.prod,
rw [mem_lift_iff],
apply exists_congr, intro t₁,
apply exists_congr, intro ht₁,
rw [mem_lift'_iff],
exact set.monotone_prod monotone_const monotone_id,
exact (monotone_lift' monotone_const $ monotone_lam $ assume b, set.monotone_prod monotone_id monotone_const)
end
lemma mem_prod_same_iff {s : set (α×α)} {f : filter α} :
s ∈ (filter.prod f f)^.sets ↔ (∃t∈f^.sets, set.prod t t ⊆ s) :=
by rw [prod_same_eq, mem_lift'_iff]; exact set.monotone_prod monotone_id monotone_id
lemma prod_mono {f₁ f₂ : filter α} {g₁ g₂ : filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
filter.prod f₁ g₁ ≤ filter.prod f₂ g₂ :=
lift_mono hf $ assume s, lift'_mono hg $ le_refl _
lemma prod_comm {f : filter α} {g : filter β} :
filter.prod f g = map (λp:β×α, (p.2, p.1)) (filter.prod g f) :=
eq.symm $ calc map (λp:β×α, (p.2, p.1)) (filter.prod g f) =
(g^.lift $ λt, map (λp:β×α, (p.2, p.1)) (f^.lift' $ λs, set.prod t s)) :
map_lift_eq $ assume a b h, lift'_mono (le_refl f) (assume t, set.prod_mono h (subset.refl t))
... = (g^.lift $ λt, f^.lift' $ λs, image (λp:β×α, (p.2, p.1)) (set.prod t s)) :
congr_arg (filter.lift g) $ funext $ assume s, map_lift'_eq $ assume a b h, set.prod_mono (subset.refl s) h
... = (g^.lift $ λt, f^.lift' $ λs, set.prod s t) : by simp [set.image_swap_prod]
... = filter.prod f g : lift_comm
lemma prod_lift_lift {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → filter β₁} {g₂ : set α₂ → filter β₂}
(hg₁ : monotone g₁) (hg₂ : monotone g₂) :
filter.prod (f₁.lift g₁) (f₂.lift g₂) = f₁.lift (λs, f₂.lift (λt, filter.prod (g₁ s) (g₂ t))) :=
begin
delta filter.prod,
rw [lift_assoc],
apply congr_arg, apply funext, intro x,
rw [lift_comm],
apply congr_arg, apply funext, intro y,
rw [lift'_lift_assoc],
exact hg₂,
exact hg₁
end
lemma prod_lift'_lift' {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → set β₁} {g₂ : set α₂ → set β₂}
(hg₁ : monotone g₁) (hg₂ : monotone g₂) :
filter.prod (f₁.lift' g₁) (f₂.lift' g₂) = f₁.lift (λs, f₂.lift' (λt, set.prod (g₁ s) (g₂ t))) :=
begin
delta filter.prod,
rw [lift_lift'_assoc],
apply congr_arg, apply funext, intro x,
rw [lift'_lift'_assoc],
exact hg₂,
exact set.monotone_prod monotone_const monotone_id,
exact hg₁,
exact (monotone_lift' monotone_const $ monotone_lam $
assume x, set.monotone_prod monotone_id monotone_const)
end
lemma prod_map_map_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
filter.prod (map m₁ f₁) (map m₂ f₂) = map (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) :=
begin
simp [filter.prod],
rw [map_lift_eq], tactic.swap, exact (monotone_lift' monotone_const $
monotone_lam $ assume t, set.monotone_prod monotone_id monotone_const),
rw [map_lift_eq2], tactic.swap, exact (monotone_lift' monotone_const $
monotone_lam $ assume t, set.monotone_prod monotone_id monotone_const),
apply congr_arg, apply funext, intro t,
dsimp [(∘)],
rw [map_lift'_eq], tactic.swap, exact set.monotone_prod monotone_const monotone_id,
rw [map_lift'_eq2], tactic.swap, exact set.monotone_prod monotone_const monotone_id,
apply congr_arg, apply funext, intro t,
exact set.prod_image_image_eq
end
lemma prod_vmap_vmap_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : filter α₁} {f₂ : filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
filter.prod (vmap m₁ f₁) (vmap m₂ f₂) = vmap (λp:β₁×β₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) :=
have ∀s t, set.prod (vimage m₁ s) (vimage m₂ t) = vimage (λp:β₁×β₂, (m₁ p.1, m₂ p.2)) (set.prod s t),
from assume s t, rfl,
begin
rw [vmap_eq_lift', vmap_eq_lift', prod_lift'_lift'],
simp [this, filter.prod],
rw [vmap_lift_eq], tactic.swap, exact (monotone_lift' monotone_const $
monotone_lam $ assume t, set.monotone_prod monotone_id monotone_const),
apply congr_arg, apply funext, intro t',
dsimp [function.comp],
rw [vmap_lift'_eq],
exact set.monotone_prod monotone_const monotone_id,
exact monotone_vimage,
exact monotone_vimage
end
lemma prod_inf_prod {f₁ f₂ : filter α} {g₁ g₂ : filter β} :
filter.prod f₁ g₁ ⊓ filter.prod f₂ g₂ = filter.prod (f₁ ⊓ f₂) (g₁ ⊓ g₂) :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht,
begin
revert s hs t ht,
simp,
exact assume s ⟨s₁, hs₁, s₂, hs₂, hs⟩ t ⟨t₁, ht₁, t₂, ht₂, ht⟩,
⟨set.prod s₁ t₁, prod_mem_prod hs₁ ht₁, set.prod s₂ t₂, prod_mem_prod hs₂ ht₂,
by rw [set.prod_inter_prod]; exact set.prod_mono hs ht⟩
end)
(le_inf (prod_mono inf_le_left inf_le_left) (prod_mono inf_le_right inf_le_right))
lemma prod_neq_bot {f : filter α} {g : filter β} :
filter.prod f g ≠ ⊥ ↔ (f ≠ ⊥ ∧ g ≠ ⊥) :=
calc filter.prod f g ≠ ⊥ ↔ (∀s∈f.sets, g.lift' (set.prod s) ≠ ⊥) :
begin
delta filter.prod,
rw [lift_neq_bot_iff],
exact (monotone_lift' monotone_const $ monotone_lam $ assume s, set.monotone_prod monotone_id monotone_const)
end
... ↔ (∀s∈f.sets, ∀t∈g.sets, s ≠ ∅ ∧ t ≠ ∅) :
begin
apply forall_congr, intro s,
apply forall_congr, intro hs,
rw [lift'_neq_bot_iff],
apply forall_congr, intro t,
apply forall_congr, intro ht,
rw [set.prod_neq_empty_iff],
exact set.monotone_prod monotone_const monotone_id
end
... ↔ (∀s∈f.sets, s ≠ ∅) ∧ (∀t∈g.sets, t ≠ ∅) :
⟨assume h, ⟨assume s hs, (h s hs univ univ_mem_sets).left,
assume t ht, (h univ univ_mem_sets t ht).right⟩,
assume ⟨h₁, h₂⟩ s hs t ht, ⟨h₁ s hs, h₂ t ht⟩⟩
... ↔ _ : by simp [forall_sets_neq_empty_iff_neq_bot]
lemma prod_principal_principal {s : set α} {t : set β} :
filter.prod (principal s) (principal t) = principal (set.prod s t) :=
begin
delta filter.prod,
rw [lift_principal, lift'_principal],
exact set.monotone_prod monotone_const monotone_id,
exact (monotone_lift' monotone_const $ monotone_lam $
assume s, set.monotone_prod monotone_id monotone_const)
end
end prod
lemma mem_infi_sets {f : ι → filter α} (i : ι) : ∀{s}, s ∈ (f i).sets → s ∈ (⨅i, f i).sets :=
show (⨅i, f i) ≤ f i, from infi_le _ _
@[simp]
lemma mem_top_sets_iff {s : set α} : s ∈ (⊤ : filter α).sets ↔ s = univ :=
⟨assume h, top_unique $ h, assume h, h.symm ▸ univ_mem_sets⟩
@[elab_as_eliminator]
lemma infi_sets_induct {f : ι → filter α} {s : set α} (hs : s ∈ (infi f).sets) {p : set α → Prop}
(uni : p univ)
(ins : ∀{i s₁ s₂}, s₁ ∈ (f i).sets → p s₂ → p (s₁ ∩ s₂))
(upw : ∀{s₁ s₂}, s₁ ⊆ s₂ → p s₁ → p s₂) : p s :=
begin
have hs' : s ∈ (complete_lattice.Inf {a : filter α | ∃ (i : ι), a = f i}).sets := hs,
rw [Inf_sets_eq_finite] at hs',
simp at hs',
cases hs' with is hs, cases hs with fin_is hs, cases hs with hs his,
induction fin_is generalizing s,
case finite.empty hs' s hs' hs {
simp at hs, subst hs, assumption },
case finite.insert fi is fi_ne_is fin_is ih fi_sub s hs' hs {
simp at hs,
cases hs with s₁ hs, cases hs with hs₁ hs, cases hs with s₂ hs, cases hs with hs hs₂,
have hi : ∃i, fi = f i := fi_sub (mem_insert _ _),
cases hi with i hi,
exact have hs₁ : s₁ ∈ (f i).sets, from hi ▸ hs₁,
have hs₂ : p s₂, from
have his : is ⊆ {x | ∃i, x = f i}, from assume i hi, fi_sub $ mem_insert_of_mem _ hi,
have infi f ≤ Inf is, from Inf_le_Inf his,
ih his (this hs₂) hs₂,
show p s, from upw hs $ ins hs₁ hs₂ }
end
lemma lift_infi {f : ι → filter α} {g : set α → filter β}
(hι : nonempty ι) (hg : ∀{s t}, g s ⊓ g t = g (s ∩ t)) : (infi f)^.lift g = (⨅i, (f i).lift g) :=
le_antisymm
(le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _))
(assume s,
have g_mono : monotone g,
from assume s t h, le_of_inf_eq $ eq.trans hg $ congr_arg g $ inter_eq_self_of_subset_left h,
have ∀t∈(infi f).sets, (⨅ (i : ι), filter.lift (f i) g) ≤ g t,
from assume t ht, infi_sets_induct ht
(let ⟨i⟩ := hι in infi_le_of_le i $ infi_le_of_le univ $ infi_le _ univ_mem_sets)
(assume i s₁ s₂ hs₁ hs₂,
@hg s₁ s₂ ▸ le_inf (infi_le_of_le i $ infi_le_of_le s₁ $ infi_le _ hs₁) hs₂)
(assume s₁ s₂ hs₁ hs₂, le_trans hs₂ $ g_mono hs₁),
by rw [lift_sets_eq g_mono]; simp; exact assume ⟨t, hs, ht⟩, this t ht hs)
lemma lift_infi' {f : ι → filter α} {g : set α → filter β}
(hι : nonempty ι) (hf : directed (≤) f) (hg : monotone g) : (infi f)^.lift g = (⨅i, (f i).lift g) :=
le_antisymm
(le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _))
(assume s,
begin
rw [lift_sets_eq hg],
simp [infi_sets_eq hf hι],
exact assume ⟨t, hs, i, ht⟩, mem_infi_sets i $ mem_lift ht hs
end)
lemma lift'_infi {f : ι → filter α} {g : set α → set β}
(hι : nonempty ι) (hg : ∀{s t}, g s ∩ g t = g (s ∩ t)) : (infi f)^.lift' g = (⨅i, (f i).lift' g) :=
lift_infi hι $ by simp; apply assume s t, hg
lemma map_eq_vmap_of_inverse {f : filter α} {m : α → β} {n : β → α}
(h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = vmap n f :=
le_antisymm
(assume b ⟨a, ha, (h : vimage n a ⊆ b)⟩, f.upwards_sets ha $
calc a = vimage (n ∘ m) a : by simp [h₂, vimage_id]
... ⊆ vimage m b : vimage_mono h)
(assume b (hb : vimage m b ∈ f.sets),
⟨vimage m b, hb, show vimage (m ∘ n) b ⊆ b, by simp [h₁]; apply subset.refl⟩)
lemma map_swap_vmap_swap_eq {f : filter (α × β)} : prod.swap <$> f = vmap prod.swap f :=
map_eq_vmap_of_inverse prod.swap_swap_eq prod.swap_swap_eq
/- towards -/
def towards (f : α → β) (l₁ : filter α) (l₂ : filter β) := filter.map f l₁ ≤ l₂
/- ultrafilter -/
section ultrafilter
open classical zorn
local attribute [instance] prop_decidable
variables {f g : filter α}
def ultrafilter (f : filter α) := f ≠ ⊥ ∧ ∀g, g ≠ ⊥ → g ≤ f → f ≤ g
lemma ultrafilter_pure {a : α} : ultrafilter (pure a) :=
⟨return_neq_bot,
assume g hg ha,
have {a} ∈ g.sets, by simp at ha; assumption,
show ∀s∈g.sets, {a} ⊆ s, from classical.by_contradiction $
begin
simp [classical.not_forall_iff_exists_not, classical.not_implies_iff_and_not],
exact assume ⟨s, hna, hs⟩,
have {a} ∩ s ∈ g.sets, from inter_mem_sets ‹{a} ∈ g.sets› hs,
have ∅ ∈ g.sets, from g.upwards_sets this $
assume x ⟨hxa, hxs⟩, begin simp at hxa; simp [hxa] at hxs, exact hna hxs end,
have g = ⊥, from empty_in_sets_eq_bot.mp this,
hg this
end⟩
lemma ultrafilter_unique (hg : ultrafilter g) (hf : f ≠ ⊥) (h : f ≤ g) : f = g :=
le_antisymm h (hg.right _ hf h)
lemma exists_ultrafilter (h : f ≠ ⊥) : ∃u, u ≤ f ∧ ultrafilter u :=
let
τ := {f' // f' ≠ ⊥ ∧ f' ≤ f},
r : τ → τ → Prop := λt₁ t₂, t₂.val ≤ t₁.val,
⟨a, ha⟩ := inhabited_of_mem_sets h univ_mem_sets,
top : τ := ⟨f, h, le_refl f⟩,
sup : Π(c:set τ), chain c → τ :=
λc hc, ⟨⨅a:{a:τ // a ∈ insert top c}, a.val.val,
infi_neq_bot_of_directed ⟨a⟩
(directed_of_chain $ chain_insert hc $ assume ⟨b, _, hb⟩ _ _, or.inl hb)
(assume ⟨⟨a, ha, _⟩, _⟩, ha),
infi_le_of_le ⟨top, mem_insert _ _⟩ (le_refl _)⟩
in
have ∀c (hc: chain c) a (ha : a ∈ c), r a (sup c hc),
from assume c hc a ha, infi_le_of_le ⟨a, mem_insert_of_mem _ ha⟩ (le_refl _),
have (∃ (u : τ), ∀ (a : τ), r u a → r a u),
from zorn (assume c hc, ⟨sup c hc, this c hc⟩) (assume f₁ f₂ f₃ h₁ h₂, le_trans h₂ h₁),
let ⟨uτ, hmin⟩ := this in
⟨uτ.val, uτ.property.right, uτ.property.left, assume g hg₁ hg₂,
hmin ⟨g, hg₁, le_trans hg₂ uτ.property.right⟩ hg₂⟩
lemma le_of_ultrafilter {g : filter α} (hf : ultrafilter f) (h : f ⊓ g ≠ ⊥) :
f ≤ g :=
le_of_inf_eq $ ultrafilter_unique hf h inf_le_left
lemma mem_or_compl_mem_of_ultrafilter (hf : ultrafilter f) (s : set α) :
s ∈ f.sets ∨ - s ∈ f.sets :=
or_of_not_implies $ assume : - s ∉ f.sets,
have f ≤ principal s,
from le_of_ultrafilter hf $ assume h, this $ mem_sets_of_neq_bot $ by simp [*],
by simp at this; assumption
lemma mem_or_mem_of_ultrafilter {s t : set α} (hf : ultrafilter f) (h : s ∪ t ∈ f.sets) :
s ∈ f.sets ∨ t ∈ f.sets :=
(mem_or_compl_mem_of_ultrafilter hf s).imp_right
(assume : -s ∈ f.sets, f.upwards_sets (inter_mem_sets this h) $
assume x ⟨hnx, hx⟩, hx.resolve_left hnx)
lemma mem_of_finite_sUnion_ultrafilter {s : set (set α)} (hf : ultrafilter f) (hs : finite s)
: ⋃₀ s ∈ f.sets → ∃t∈s, t ∈ f.sets :=
begin
induction hs,
case finite.empty { simp [empty_in_sets_eq_bot, hf.left] },
case finite.insert t s' ht' hs' ih {
simp,
exact assume h, (mem_or_mem_of_ultrafilter hf h).elim
(assume : t ∈ f.sets, ⟨t, this, or.inl rfl⟩)
(assume h, let ⟨t, hts', ht⟩ := ih h in ⟨t, ht, or.inr hts'⟩) }
end
lemma mem_of_finite_Union_ultrafilter {is : set β} {s : β → set α}
(hf : ultrafilter f) (his : finite is) (h : (⋃i∈is, s i) ∈ f.sets) : ∃i∈is, s i ∈ f.sets :=
have his : finite (image s is), from finite_image his,
have h : (⋃₀ image s is) ∈ f.sets, from by simp [sUnion_image]; assumption,
let ⟨t, ⟨i, hi, h_eq⟩, (ht : t ∈ f.sets)⟩ := mem_of_finite_sUnion_ultrafilter hf his h in
⟨i, hi, h_eq.symm ▸ ht⟩
lemma ultrafilter_of_split {f : filter α} (hf : f ≠ ⊥) (h : ∀s, s ∈ f.sets ∨ - s ∈ f.sets) :
ultrafilter f :=
⟨hf, assume g hg g_le s hs, (h s).elim id $
assume : - s ∈ f.sets,
have s ∩ -s ∈ g.sets, from inter_mem_sets hs (g_le this),
by simp [empty_in_sets_eq_bot, hg] at this; contradiction⟩
lemma ultrafilter_map {f : filter α} {m : α → β} (h : ultrafilter f) : ultrafilter (map m f) :=
ultrafilter_of_split (by simp [map_eq_bot_iff, h.left]) $
assume s, show vimage m s ∈ f.sets ∨ - vimage m s ∈ f.sets,
from mem_or_compl_mem_of_ultrafilter h (vimage m s)
noncomputable def ultrafilter_of (f : filter α) : filter α :=
if h : f = ⊥ then ⊥ else epsilon (λu, u ≤ f ∧ ultrafilter u)
lemma ultrafilter_of_spec (h : f ≠ ⊥) : ultrafilter_of f ≤ f ∧ ultrafilter (ultrafilter_of f) :=
begin
have h' := epsilon_spec (exists_ultrafilter h),
simp [ultrafilter_of, dif_neg, h],
simp at h',
assumption
end
lemma ultrafilter_of_le : ultrafilter_of f ≤ f :=
if h : f = ⊥ then by simp [ultrafilter_of, dif_pos, h]; exact le_refl _
else (ultrafilter_of_spec h).left
lemma ultrafilter_ultrafilter_of (h : f ≠ ⊥) : ultrafilter (ultrafilter_of f) :=
(ultrafilter_of_spec h).right
lemma ultrafilter_of_ultrafilter (h : ultrafilter f) : ultrafilter_of f = f :=
ultrafilter_unique h (ultrafilter_ultrafilter_of h.left).left ultrafilter_of_le
end ultrafilter
end filter
|
1f8d951a03066f491252b6c8a31f7ee7ab2b7aeb
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/test/norm_num.lean
|
d2b98fdec5b8497e312177e398ae8617352d1c38
|
[
"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
| 14,516
|
lean
|
/-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Mario Carneiro
-/
import tactic.norm_num
import algebra.ring.pi
/-!
# Tests for `norm_num` extensions
-/
constant real : Type
notation `ℝ` := real
@[instance] constant real.linear_ordered_ring : linear_ordered_field ℝ
constant complex : Type
notation `ℂ` := complex
@[instance] constant complex.field : field ℂ
@[instance] constant complex.char_zero : char_zero ℂ
example : 374 + (32 - (2 * 8123) : ℤ) - 61 * 50 = 86 + 32 * 32 - 4 * 5000
∧ 43 ≤ 74 + (33 : ℤ) := by norm_num
example : ¬ (7-2)/(2*3) ≥ (1:ℝ) + 2/(3^2) := by norm_num
example : (6:real) + 9 = 15 := by norm_num
example : (2:real)/4 + 4 = 3*3/2 := by norm_num
example : (((3:real)/4)-12)<6 := by norm_num
example : (5:real) ≠ 8 := by norm_num
example : (10:real) > 7 := by norm_num
example : (2:real) * 2 + 3 = 7 := by norm_num
example : (6:real) < 10 := by norm_num
example : (7:real)/2 > 3 := by norm_num
example : (4:real)⁻¹ < 1 := by norm_num
example : ((1:real) / 2)⁻¹ = 2 := by norm_num
example : 2 ^ 17 - 1 = 131071 :=
by {norm_num, tactic.try_for 200 (tactic.result >>= tactic.type_check)}
example : (3 : real) ^ (-2 : ℤ) = 1/9 := by norm_num
example : (3 : real) ^ (-2 : ℤ) = 1/9 := by norm_num1
example : (-3 : real) ^ (0 : ℤ) = 1 := by norm_num
example : (-3 : real) ^ (-1 : ℤ) = -1/3 := by norm_num
example : (-3 : real) ^ (2 : ℤ) = 9 := by norm_num
example : (1:complex) ≠ 2 := by norm_num
example : (1:complex) / 3 ≠ 2 / 7 := by norm_num
example : (1:real) ≠ 2 := by norm_num
example {α} [semiring α] [char_zero α] : (1:α) ≠ 2 := by norm_num
example {α} [ring α] [char_zero α] : (-1:α) ≠ 2 := by norm_num
example {α} [division_ring α] [char_zero α] : (-1:α) ≠ 2 := by norm_num
example {α} [division_ring α] [char_zero α] : (1:α) / 3 ≠ 2 / 7 := by norm_num
example {α} [division_ring α] [char_zero α] : (1:α) / 3 ≠ 0 := by norm_num
example : (5 / 2:ℕ) = 2 := by norm_num
example : (5 / -2:ℤ) < -1 := by norm_num
example : (0 + 1) / 2 < 0 + 1 := by norm_num
example : nat.succ (nat.succ (2 ^ 3)) = 10 := by norm_num
example : 10 = (-1 : ℤ) % 11 := by norm_num
example : (12321 - 2 : ℤ) = 12319 := by norm_num
example : (63:ℚ) ≥ 5 := by norm_num
example : nat.zero.succ.succ.succ.succ.succ.succ % 4 = 2 := by norm_num1
example (x : ℤ) (h : 1000 + 2000 < x) : 100 * 30 < x :=
by norm_num at *; try_for 100 {exact h}
example : (1103 : ℤ) ≤ (2102 : ℤ) := by norm_num
example : (110474 : ℤ) ≤ (210485 : ℤ) := by norm_num
example : (11047462383473829263 : ℤ) ≤ (21048574677772382462 : ℤ) := by norm_num
example : (210485742382937847263 : ℤ) ≤ (1104857462382937847262 : ℤ) := by norm_num
example : (210485987642382937847263 : ℕ) ≤ (11048512347462382937847262 : ℕ) := by norm_num
example : (210485987642382937847263 : ℚ) ≤ (11048512347462382937847262 : ℚ) := by norm_num
example : (2 * 12868 + 25705) * 11621 ^ 2 ≤ 23235 ^ 2 * 12868 := by norm_num
example (x : ℕ) : ℕ := begin
let n : ℕ, {apply_normed (2^32 - 71)},
exact n
end
example (a : ℚ) (h : 3⁻¹ * a = a) : true :=
begin
norm_num at h,
guard_hyp h : 1 / 3 * a = a,
trivial
end
example (h : (5 : ℤ) ∣ 2) : false := by norm_num at h
example (h : false) : false := by norm_num at h
example : true := by norm_num
example : true ∧ true := by { split, norm_num, norm_num }
example : 10 + 2 = 1 + 11 := by norm_num
example : 10 - 1 = 9 := by norm_num
example : 12 - 5 = 3 + 4 := by norm_num
example : 5 - 20 = 0 := by norm_num
example : 0 - 2 = 0 := by norm_num
example : 4 - (5 - 10) = 2 + (3 - 1) := by norm_num
example : 0 - 0 = 0 := by norm_num
example : 100 - 100 = 0 := by norm_num
example : 5 * (2 - 3) = 0 := by norm_num
example : 10 - 5 * 5 + (7 - 3) * 6 = 27 - 3 := by norm_num
def foo : ℕ := 1
@[norm_num] meta def eval_foo : expr → tactic (expr × expr)
| `(foo) := pure (`(1:ℕ), `(eq.refl 1))
| _ := tactic.failed
example : foo = 1 := by norm_num
-- ordered field examples
variable {α : Type}
variable [linear_ordered_field α]
example : (-1 :α) * 1 = -1 := by norm_num
example : (-2 :α) * 1 = -2 := by norm_num
example : (-2 :α) * -1 = 2 := by norm_num
example : (-2 :α) * -2 = 4 := by norm_num
example : (1 : α) * 0 = 0 := by norm_num
example : ((1 : α) + 1) * 5 = 6 + 4 := by norm_num
example : (1 : α) = 0 + 1 := by norm_num
example : (1 : α) = 1 + 0 := by norm_num
example : (2 : α) = 1 + 1 := by norm_num
example : (2 : α) = 0 + 2 := by norm_num
example : (3 : α) = 1 + 2 := by norm_num
example : (3 : α) = 2 + 1 := by norm_num
example : (4 : α) = 3 + 1 := by norm_num
example : (4 : α) = 2 + 2 := by norm_num
example : (5 : α) = 4 + 1 := by norm_num
example : (5 : α) = 3 + 2 := by norm_num
example : (5 : α) = 2 + 3 := by norm_num
example : (6 : α) = 0 + 6 := by norm_num
example : (6 : α) = 3 + 3 := by norm_num
example : (6 : α) = 4 + 2 := by norm_num
example : (6 : α) = 5 + 1 := by norm_num
example : (7 : α) = 4 + 3 := by norm_num
example : (7 : α) = 1 + 6 := by norm_num
example : (7 : α) = 6 + 1 := by norm_num
example : 33 = 5 + (28 : α) := by norm_num
example : (12 : α) = 0 + (2 + 3) + 7 := by norm_num
example : (105 : α) = 70 + (33 + 2) := by norm_num
example : (45000000000 : α) = 23000000000 + 22000000000 := by norm_num
example : (0 : α) - 3 = -3 := by norm_num
example : (0 : α) - 2 = -2 := by norm_num
example : (1 : α) - 3 = -2 := by norm_num
example : (1 : α) - 1 = 0 := by norm_num
example : (0 : α) - 3 = -3 := by norm_num
example : (0 : α) - 3 = -3 := by norm_num
example : (12 : α) - 4 - (5 + -2) = 5 := by norm_num
example : (12 : α) - 4 - (5 + -2) - 20 = -15 := by norm_num
example : (0 : α) * 0 = 0 := by norm_num
example : (0 : α) * 1 = 0 := by norm_num
example : (0 : α) * 2 = 0 := by norm_num
example : (2 : α) * 0 = 0 := by norm_num
example : (1 : α) * 0 = 0 := by norm_num
example : (1 : α) * 1 = 1 := by norm_num
example : (2 : α) * 1 = 2 := by norm_num
example : (1 : α) * 2 = 2 := by norm_num
example : (2 : α) * 2 = 4 := by norm_num
example : (3 : α) * 2 = 6 := by norm_num
example : (2 : α) * 3 = 6 := by norm_num
example : (4 : α) * 1 = 4 := by norm_num
example : (1 : α) * 4 = 4 := by norm_num
example : (3 : α) * 3 = 9 := by norm_num
example : (3 : α) * 4 = 12 := by norm_num
example : (4 : α) * 4 = 16 := by norm_num
example : (11 : α) * 2 = 22 := by norm_num
example : (15 : α) * 6 = 90 := by norm_num
example : (123456 : α) * 123456 = 15241383936 := by norm_num
example : (4 : α) / 2 = 2 := by norm_num
example : (4 : α) / 1 = 4 := by norm_num
example : (4 : α) / 3 = 4 / 3 := by norm_num
example : (50 : α) / 5 = 10 := by norm_num
example : (1056 : α) / 1 = 1056 := by norm_num
example : (6 : α) / 4 = 3/2 := by norm_num
example : (0 : α) / 3 = 0 := by norm_num
example : (3 : α) / 0 = 0 := by norm_num
example : (9 * 9 * 9) * (12 : α) / 27 = 81 * (2 + 2) := by norm_num
example : (-2 : α) * 4 / 3 = -8 / 3 := by norm_num
example : - (-4 / 3) = 1 / (3 / (4 : α)) := by norm_num
-- user command
set_option trace.silence_norm_num_if_true true
#norm_num 1 = 1
example : 1 = 1 := by norm_num
#norm_num 2^4-1 ∣ 2^16-1
example : 2^4-1 ∣ 2^16-1 := by norm_num
#norm_num (3 : real) ^ (-2 : ℤ) = 1/9
example : (3 : real) ^ (-2 : ℤ) = 1/9 := by norm_num
section norm_num_cmd_variable
variables (x y : ℕ)
#norm_num bit0 x < bit0 (y + x) ↔ 0 < y
example : bit0 x < bit0 (y + x) ↔ 0 < y := by norm_num
#norm_num bit0 x < bit0 (y + (2^10%11 - 1) + x) ↔ 0 < y
example : bit0 x < bit0 (y + (2^10%11 - 1) + x) ↔ 0 < y := by norm_num
#norm_num bit0 x < bit0 (y + (2^10%11 - 1) + x) + 3*2-6 ↔ 0 < y
example : bit0 x < bit0 (y + (2^10%11 - 1) + x) + 3*2-6 ↔ 0 < y := by norm_num
end norm_num_cmd_variable
-- auto gen tests
example : ((25 * (1 / 1)) + (30 - 16)) = (39 : α) := by norm_num
example : ((19 * (- 2 - 3)) / 6) = (-95/6 : α) := by norm_num
example : - (3 * 28) = (-84 : α) := by norm_num
example : - - (16 / ((11 / (- - (6 * 19) + 12)) * 21)) = (96/11 : α) := by norm_num
example : (- (- 21 + 24) - - (- - (28 + (- 21 / - (16 / ((1 * 26) * ((0 * - 11) + 13))))) * 21)) =
(79209/8 : α) := by norm_num
example : (27 * (((16 + - (12 + 4)) + (22 - - 19)) - 23)) = (486 : α) := by norm_num
example : - (13 * (- 30 / ((7 / 24) + - 7))) = (-9360/161 : α) := by norm_num
example : - (0 + 20) = (-20 : α) := by norm_num
example : (- 2 - (27 + (((2 / 14) - (7 + 21)) + (16 - - - 14)))) = (-22/7 : α) := by norm_num
example : (25 + ((8 - 2) + 16)) = (47 : α) := by norm_num
example : (- - 26 / 27) = (26/27 : α) := by norm_num
example : ((((16 * (22 / 14)) - 18) / 11) + 30) = (2360/77 : α) := by norm_num
example : (((- 28 * 28) / (29 - 24)) * 24) = (-18816/5 : α) := by norm_num
example : ((- (18 - ((- - (10 + - 2) - - (23 / 5)) / 5)) - (21 * 22)) -
(((20 / - ((((19 + 18) + 15) + 3) + - 22)) + 14) / 17)) = (-394571/825 : α) := by norm_num
example : ((3 + 25) - - 4) = (32 : α) := by norm_num
example : ((1 - 0) - 22) = (-21 : α) := by norm_num
example : (((- (8 / 7) / 14) + 20) + 22) = (2054/49 : α) := by norm_num
example : ((21 / 20) - 29) = (-559/20 : α) := by norm_num
example : - - 20 = (20 : α) := by norm_num
example : (24 - (- 9 / 4)) = (105/4 : α) := by norm_num
example : (((7 / ((23 * 19) + (27 * 10))) - ((28 - - 15) * 24)) + (9 / - (10 * - 3))) =
(-1042007/1010 : α) := by norm_num
example : (26 - (- 29 + (12 / 25))) = (1363/25 : α) := by norm_num
example : ((11 * 27) / (4 - 5)) = (-297 : α) := by norm_num
example : (24 - (9 + 15)) = (0 : α) := by norm_num
example : (- 9 - - 0) = (-9 : α) := by norm_num
example : (- 10 / (30 + 10)) = (-1/4 : α) := by norm_num
example : (22 - (6 * (28 * - 8))) = (1366 : α) := by norm_num
example : ((- - 2 * (9 * - 3)) + (22 / 30)) = (-799/15 : α) := by norm_num
example : - (26 / ((3 + 7) / - (27 * (12 / - 16)))) = (-1053/20 : α) := by norm_num
example : ((- 29 / 1) + 28) = (-1 : α) := by norm_num
example : ((21 * ((10 - (((17 + 28) - - 0) + 20)) + 26)) + ((17 + - 16) * 7)) = (-602 : α) :=
by norm_num
example : (((- 5 - ((24 + - - 8) + 3)) + 20) + - 23) = (-43 : α) := by norm_num
example : ((- ((14 - 15) * (14 + 8)) + ((- (18 - 27) - 0) + 12)) - 11) = (32 : α) := by norm_num
example : (((15 / 17) * (26 / 27)) + 28) = (4414/153 : α) := by norm_num
example : (14 - ((- 16 - 3) * - (20 * 19))) = (-7206 : α) := by norm_num
example : (21 - - - (28 - (12 * 11))) = (125 : α) := by norm_num
example : ((0 + (7 + (25 + 8))) * - (11 * 27)) = (-11880 : α) := by norm_num
example : (19 * - 5) = (-95 : α) := by norm_num
example : (29 * - 8) = (-232 : α) := by norm_num
example : ((22 / 9) - 29) = (-239/9 : α) := by norm_num
example : (3 + (19 / 12)) = (55/12 : α) := by norm_num
example : - (13 + 30) = (-43 : α) := by norm_num
example : - - - (((21 * - - ((- 25 - (- (30 - 5) / (- 5 - 5))) /
(((6 + ((25 * - 13) + 22)) - 3) / 2))) / (- 3 / 10)) * (- 8 - 0)) = (-308/3 : α) := by norm_num
example : - (2 * - (- 24 * 22)) = (-1056 : α) := by norm_num
example : - - (((28 / - ((- 13 * - 5) / - (((7 - 30) / 16) + 6))) * 0) - 24) = (-24 : α) :=
by norm_num
example : ((13 + 24) - (27 / (21 * 13))) = (3358/91 : α) := by norm_num
example : ((3 / - 21) * 25) = (-25/7 : α) := by norm_num
example : (17 - (29 - 18)) = (6 : α) := by norm_num
example : ((28 / 20) * 15) = (21 : α) := by norm_num
example : ((((26 * (- (23 - 13) - 3)) / 20) / (14 - (10 + 20))) / ((16 / 6) / (16 * - (3 / 28)))) =
(-1521/2240 : α) := by norm_num
example : (46 / (- ((- 17 * 28) - 77) + 87)) = (23/320 : α) := by norm_num
example : (73 * - (67 - (74 * - - 11))) = (54531 : α) := by norm_num
example : ((8 * (25 / 9)) + 59) = (731/9 : α) := by norm_num
example : - ((59 + 85) * - 70) = (10080 : α) := by norm_num
example : (66 + (70 * 58)) = (4126 : α) := by norm_num
example : (- - 49 * 0) = (0 : α) := by norm_num
example : ((- 78 - 69) * 9) = (-1323 : α) := by norm_num
example : - - (7 - - (50 * 79)) = (3957 : α) := by norm_num
example : - (85 * (((4 * 93) * 19) * - 31)) = (18624180 : α) := by norm_num
example : (21 + (- 5 / ((74 * 85) / 45))) = (26373/1258 : α) := by norm_num
example : (42 - ((27 + 64) + 26)) = (-75 : α) := by norm_num
example : (- ((38 - - 17) + 86) - (74 + 58)) = (-273 : α) := by norm_num
example : ((29 * - (75 + - 68)) + (- 41 / 28)) = (-5725/28 : α) := by norm_num
example : (- - (40 - 11) - (68 * 86)) = (-5819 : α) := by norm_num
example : (6 + ((65 - 14) + - 89)) = (-32 : α) := by norm_num
example : (97 * - (29 * 35)) = (-98455 : α) := by norm_num
example : - (66 / 33) = (-2 : α) := by norm_num
example : - ((94 * 89) + (79 - (23 - (((- 1 / 55) + 95) * (28 - (54 / - - - 22)))))) =
(-1369070/121 : α) := by norm_num
example : (- 23 + 61) = (38 : α) := by norm_num
example : - (93 / 69) = (-31/23 : α) := by norm_num
example : (- - ((68 / (39 + (((45 * - (59 - (37 + 35))) / (53 - 75)) -
- (100 + - (50 / (- 30 - 59)))))) - (69 - (23 * 30))) / (57 + 17)) = (137496481/16368578 : α) :=
by norm_num
example : (- 19 * - - (75 * - - 41)) = (-58425 : α) := by norm_num
example : ((3 / ((- 28 * 45) * (19 + ((- (- 88 - (- (- 1 + 90) + 8)) + 87) * 48)))) + 1) =
(1903019/1903020 : α) := by norm_num
example : ((- - (28 + 48) / 75) + ((- 59 - 14) - 0)) = (-5399/75 : α) := by norm_num
example : (- ((- (((66 - 86) - 36) / 94) - 3) / - - (77 / (56 - - - 79))) + 87) =
(312254/3619 : α) := by norm_num
example : 2 ^ 13 - 1 = int.of_nat 8191 := by norm_num
-- `^` and `•` do not have to match `monoid.has_pow` and `add_monoid.has_smul` syntactically
example {α} [ring α] : (2 ^ 3 : ℕ → α) = 8 := by norm_num
example {α} [ring α] : (2 • 3 : ℕ → α) = 6 := by norm_num
/-! Test the behaviour of removing one `norm_num` extension tactic. -/
section remove_extension
-- turn off the `norm_num` extension which deals with `/`, `%`, `∣`
local attribute [-norm_num] norm_num.eval_nat_int_ext
example : (5 / 2:ℕ) = 2 := by success_if_fail { solve1 { norm_num } }; refl
example : 10 = (-1 : ℤ) % 11 := by success_if_fail { solve1 { norm_num } }; refl
example (h : (5 : ℤ) ∣ 2) : false :=
begin
success_if_fail { norm_num at h },
have : (2:ℤ) ≠ 0 := by norm_num,
exact this (int.mod_eq_zero_of_dvd h),
end
example : 2^4-1 ∣ 2^16-1 :=
begin
success_if_fail { solve1 { norm_num } },
use 4369,
norm_num,
end
end remove_extension
|
0b44d165087b0d7ad616b98a8f20e4d11c30c861
|
947b78d97130d56365ae2ec264df196ce769371a
|
/tests/lean/abst.lean
|
e355e3809ca9153f44abca935911590860f02594
|
[
"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
| 522
|
lean
|
import Lean.Expr
new_frontend
open Lean
def tst : IO Unit :=
do
let f := mkConst `f;
let x := mkFVar `x;
let y := mkFVar `y;
let t := mkApp (mkApp (mkApp f x) y) (mkApp f x);
IO.println t;
let p := t.abstract [x, y].toArray;
IO.println p;
IO.println $ p.instantiateRev #[x, y];
let a := mkConst `a;
let b := mkApp f (mkConst `b);
IO.println $ p.instantiateRev #[a, b];
IO.println $ p.instantiate #[a];
let p := t.abstractRange 1 #[x, y];
IO.println p;
let p := t.abstractRange 3 #[x, y];
IO.println p;
pure ()
#eval tst
|
8b2ef9893c08f6dfcaddd6ca5216601082af12b0
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/list/func.lean
|
31d291be9da9cfe0d6676c63f78114e81a49fe00
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 10,362
|
lean
|
/-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Seul Baek
-/
import data.nat.basic
open list
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
namespace list
namespace func
variables {a : α}
variables {as as1 as2 as3 : list α}
/- Definitions for using lists as finite
representations of functions with domain ℕ. -/
def neg [has_neg α] (as : list α) := as.map (λ a, -a)
variables [inhabited α] [inhabited β]
@[simp] def set (a : α) : list α → ℕ → list α
| (_::as) 0 := a::as
| [] 0 := [a]
| (h::as) (k+1) := h::(set as k)
| [] (k+1) := (default α)::(set ([] : list α) k)
localized "notation as ` {` m ` ↦ ` a `}` := list.func.set a as m" in list.func
@[simp] def get : ℕ → list α → α
| _ [] := default α
| 0 (a::as) := a
| (n+1) (a::as) := get n as
def equiv (as1 as2 : list α) : Prop :=
∀ (m : nat), get m as1 = get m as2
@[simp] def pointwise (f : α → β → γ) : list α → list β → list γ
| [] [] := []
| [] (b::bs) := map (f $ default α) (b::bs)
| (a::as) [] := map (λ x, f x $ default β) (a::as)
| (a::as) (b::bs) := (f a b)::(pointwise as bs)
def add {α : Type u} [has_zero α] [has_add α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (+)
def sub {α : Type u} [has_zero α] [has_sub α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (@has_sub.sub α _)
/- set -/
lemma length_set : ∀ {m : ℕ} {as : list α},
(as {m ↦ a}).length = _root_.max as.length (m+1)
| 0 [] := rfl
| 0 (a::as) := by {rw max_eq_left, refl, simp [nat.le_add_right]}
| (m+1) [] := by simp only [set, nat.zero_max, length, @length_set m]
| (m+1) (a::as) := by simp only [set, nat.max_succ_succ, length, @length_set m]
@[simp] lemma get_nil {k : ℕ} : get k [] = default α :=
by {cases k; refl}
lemma get_eq_default_of_le :
∀ (k : ℕ) {as : list α}, as.length ≤ k → get k as = default α
| 0 [] h1 := rfl
| 0 (a::as) h1 := by cases h1
| (k+1) [] h1 := rfl
| (k+1) (a::as) h1 :=
begin
apply get_eq_default_of_le k,
rw ← nat.succ_le_succ_iff, apply h1,
end
@[simp] lemma get_set {a : α} :
∀ {k : ℕ} {as : list α}, get k (as {k ↦ a}) = a
| 0 as := by {cases as; refl, }
| (k+1) as := by {cases as; simp [get_set]}
lemma eq_get_of_mem {a : α} :
∀ {as : list α}, a ∈ as → ∃ n : nat, ∀ d : α, a = (get n as)
| [] h := by cases h
| (b::as) h :=
begin
rw mem_cons_iff at h, cases h,
{ existsi 0, intro d, apply h },
{ cases eq_get_of_mem h with n h2,
existsi (n+1), apply h2 }
end
lemma mem_get_of_le :
∀ {n : ℕ} {as : list α}, n < as.length → get n as ∈ as
| _ [] h1 := by cases h1
| 0 (a::as) _ := or.inl rfl
| (n+1) (a::as) h1 :=
begin
apply or.inr, unfold get,
apply mem_get_of_le,
apply nat.lt_of_succ_lt_succ h1,
end
lemma mem_get_of_ne_zero :
∀ {n : ℕ} {as : list α},
get n as ≠ default α → get n as ∈ as
| _ [] h1 := begin exfalso, apply h1, rw get_nil end
| 0 (a::as) h1 := or.inl rfl
| (n+1) (a::as) h1 :=
begin
unfold get,
apply (or.inr (mem_get_of_ne_zero _)),
apply h1
end
lemma get_set_eq_of_ne {a : α} :
∀ {as : list α} (k : ℕ) (m : ℕ),
m ≠ k → get m (as {k ↦ a}) = get m as
| as 0 m h1 :=
by { cases m, contradiction, cases as;
simp only [set, get, get_nil] }
| as (k+1) m h1 :=
begin
cases as; cases m,
simp only [set, get],
{ have h3 : get m (nil {k ↦ a}) = default α,
{ rw [get_set_eq_of_ne k m, get_nil],
intro hc, apply h1, simp [hc] },
apply h3 },
simp only [set, get],
{ apply get_set_eq_of_ne k m,
intro hc, apply h1, simp [hc], }
end
lemma get_map {f : α → β} : ∀ {n : ℕ} {as : list α}, n < as.length →
get n (as.map f) = f (get n as)
| _ [] h := by cases h
| 0 (a::as) h := rfl
| (n+1) (a::as) h1 :=
begin
have h2 : n < length as,
{ rw [← nat.succ_le_iff, ← nat.lt_succ_iff],
apply h1 },
apply get_map h2,
end
lemma get_map' {f : α → β} {n : ℕ} {as : list α} :
f (default α) = (default β) →
get n (as.map f) = f (get n as) :=
begin
intro h1, by_cases h2 : n < as.length,
{ apply get_map h2, },
{ rw not_lt at h2,
rw [get_eq_default_of_le _ h2, get_eq_default_of_le, h1],
rw [length_map], apply h2 }
end
lemma forall_val_of_forall_mem {as : list α} {p : α → Prop} :
p (default α) → (∀ x ∈ as, p x) → (∀ n, p (get n as)) :=
begin
intros h1 h2 n,
by_cases h3 : n < as.length,
{ apply h2 _ (mem_get_of_le h3) },
{ rw not_lt at h3,
rw get_eq_default_of_le _ h3, apply h1 }
end
/- equiv -/
lemma equiv_refl : equiv as as := λ k, rfl
lemma equiv_symm : equiv as1 as2 → equiv as2 as1 :=
λ h1 k, (h1 k).symm
lemma equiv_trans :
equiv as1 as2 → equiv as2 as3 → equiv as1 as3 :=
λ h1 h2 k, eq.trans (h1 k) (h2 k)
lemma equiv_of_eq : as1 = as2 → equiv as1 as2 :=
begin intro h1, rw h1, apply equiv_refl end
lemma eq_of_equiv : ∀ {as1 as2 : list α}, as1.length = as2.length →
equiv as1 as2 → as1 = as2
| [] [] h1 h2 := rfl
| (_::_) [] h1 h2 := by cases h1
| [] (_::_) h1 h2 := by cases h1
| (a1::as1) (a2::as2) h1 h2 :=
begin
congr,
{ apply h2 0 },
have h3 : as1.length = as2.length,
{ simpa [add_left_inj, add_comm, length] using h1 },
apply eq_of_equiv h3,
intro m, apply h2 (m+1)
end
end func
-- We want to drop the `inhabited` instances for a moment,
-- so we close and open the namespace
namespace func
/- neg -/
@[simp] lemma get_neg [add_group α] {k : ℕ} {as : list α} :
@get α ⟨0⟩ k (neg as) = -(@get α ⟨0⟩ k as) :=
by {unfold neg, rw (@get_map' α α ⟨0⟩), apply neg_zero}
@[simp] lemma length_neg [has_neg α] (as : list α) : (neg as).length = as.length :=
by simp only [neg, length_map]
variables [inhabited α] [inhabited β]
/- pointwise -/
lemma nil_pointwise {f : α → β → γ} : ∀ bs : list β, pointwise f [] bs = bs.map (f $ default α)
| [] := rfl
| (b::bs) :=
by simp only [nil_pointwise bs, pointwise,
eq_self_iff_true, and_self, map]
lemma pointwise_nil {f : α → β → γ} :
∀ as : list α, pointwise f as [] = as.map (λ a, f a $ default β)
| [] := rfl
| (a::as) :=
by simp only [pointwise_nil as, pointwise,
eq_self_iff_true, and_self, list.map]
lemma get_pointwise [inhabited γ] {f : α → β → γ} (h1 : f (default α) (default β) = default γ) :
∀ (k : nat) (as : list α) (bs : list β),
get k (pointwise f as bs) = f (get k as) (get k bs)
| k [] [] := by simp only [h1, get_nil, pointwise, get]
| 0 [] (b::bs) :=
by simp only [get_pointwise, get_nil,
pointwise, get, nat.nat_zero_eq_zero, map]
| (k+1) [] (b::bs) :=
by { have : get k (map (f $ default α) bs) = f (default α) (get k bs),
{ simpa [nil_pointwise, get_nil] using (get_pointwise k [] bs) },
simpa [get, get_nil, pointwise, map] }
| 0 (a::as) [] :=
by simp only [get_pointwise, get_nil,
pointwise, get, nat.nat_zero_eq_zero, map]
| (k+1) (a::as) [] :=
by simpa [get, get_nil, pointwise, map, pointwise_nil, get_nil]
using get_pointwise k as []
| 0 (a::as) (b::bs) := by simp only [pointwise, get]
| (k+1) (a::as) (b::bs) :=
by simp only [pointwise, get, get_pointwise k]
lemma length_pointwise {f : α → β → γ} :
∀ {as : list α} {bs : list β},
(pointwise f as bs).length = _root_.max as.length bs.length
| [] [] := rfl
| [] (b::bs) :=
by simp only [pointwise, length, length_map,
max_eq_right (nat.zero_le (length bs + 1))]
| (a::as) [] :=
by simp only [pointwise, length, length_map,
max_eq_left (nat.zero_le (length as + 1))]
| (a::as) (b::bs) :=
by simp only [pointwise, length,
nat.max_succ_succ, @length_pointwise as bs]
end func
namespace func
/- add -/
@[simp] lemma get_add {α : Type u} [add_monoid α] {k : ℕ} {xs ys : list α} :
@get α ⟨0⟩ k (add xs ys) = ( @get α ⟨0⟩ k xs + @get α ⟨0⟩ k ys) :=
by {apply get_pointwise, apply zero_add}
@[simp] lemma length_add {α : Type u}
[has_zero α] [has_add α] {xs ys : list α} :
(add xs ys).length = _root_.max xs.length ys.length :=
@length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _
@[simp] lemma nil_add {α : Type u} [add_monoid α]
(as : list α) : add [] as = as :=
begin
rw [add, @nil_pointwise α α α ⟨0⟩ ⟨0⟩],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, zero_add], refl
end
@[simp] lemma add_nil {α : Type u} [add_monoid α]
(as : list α) : add as [] = as :=
begin
rw [add, @pointwise_nil α α α ⟨0⟩ ⟨0⟩],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, add_zero], refl
end
lemma map_add_map {α : Type u} [add_monoid α] (f g : α → α) {as : list α} :
add (as.map f) (as.map g) = as.map (λ x, f x + g x) :=
begin
apply @eq_of_equiv _ (⟨0⟩ : inhabited α),
{ rw [length_map, length_add, max_eq_left, length_map],
apply le_of_eq,
rw [length_map, length_map] },
intros m,
rw [get_add],
by_cases h : m < length as,
{ repeat {rw [@get_map α α ⟨0⟩ ⟨0⟩ _ _ _ h]} },
rw not_lt at h,
repeat {rw [get_eq_default_of_le m]};
try {rw length_map, apply h},
apply zero_add
end
/- sub -/
@[simp] lemma get_sub {α : Type u}
[add_group α] {k : ℕ} {xs ys : list α} :
@get α ⟨0⟩ k (sub xs ys) = (@get α ⟨0⟩ k xs - @get α ⟨0⟩ k ys) :=
by {apply get_pointwise, apply sub_zero}
@[simp] lemma length_sub [has_zero α] [has_sub α] {xs ys : list α} :
(sub xs ys).length = _root_.max xs.length ys.length :=
@length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _
@[simp] lemma nil_sub {α : Type} [add_group α]
(as : list α) : sub [] as = neg as :=
begin
rw [sub, nil_pointwise],
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, zero_sub]
end
@[simp] lemma sub_nil {α : Type} [add_group α]
(as : list α) : sub as [] = as :=
begin
rw [sub, pointwise_nil],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, sub_zero], refl
end
end func
end list
|
5cf607bd1d64a2e3c0a7873ae9451adf3b3c7381
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/analysis/special_functions/complex/log.lean
|
5a55d5b154cfc64199da1a8a0a0bd6d1b9542693
|
[
"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
| 9,290
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.complex.arg
import analysis.special_functions.log.basic
/-!
# The complex `log` function
Basic properties, relationship with `exp`.
-/
noncomputable theory
namespace complex
open set filter
open_locale real topology complex_conjugate
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0`-/
@[pp_nodot] noncomputable def log (x : ℂ) : ℂ := x.abs.log + arg x * I
lemma log_re (x : ℂ) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
lemma neg_pi_lt_log_im (x : ℂ) : -π < (log x).im := by simp only [log_im, neg_pi_lt_arg]
lemma log_im_le_pi (x : ℂ) : (log x).im ≤ π := by simp only [log_im, arg_le_pi]
lemma exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, ← of_real_sin, sin_arg, ← of_real_cos, cos_arg hx,
← of_real_exp, real.exp_log (abs.pos hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 $ abs.ne_zero hx), ← mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 $ abs.ne_zero hx), re_add_im]
@[simp] lemma range_exp : range exp = {0}ᶜ :=
set.ext $ λ x, ⟨by { rintro ⟨x, rfl⟩, exact exp_ne_zero x }, λ hx, ⟨log x, exp_log hx⟩⟩
lemma log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂: x.im ≤ π) : log (exp x) = x :=
by rw [log, abs_exp, real.log_exp, exp_eq_exp_re_mul_sin_add_cos, ← of_real_exp,
arg_mul_cos_add_sin_mul_I (real.exp_pos _) ⟨hx₁, hx₂⟩, re_add_im]
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π)
(hy₁ : - π < y.im) (hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y :=
by rw [← log_exp hx₁ hx₂, ← log_exp hy₁ hy₂, hxy]
lemma of_real_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : ℝ) : (log (x : ℂ)).re = real.log x := by simp [log_re]
lemma log_of_real_mul {r : ℝ} (hr : 0 < r) {x : ℂ} (hx : x ≠ 0) :
log (r * x) = real.log r + log x :=
begin
replace hx := complex.abs.ne_zero_iff.mpr hx,
simp_rw [log, map_mul, abs_of_real, arg_real_mul _ hr, abs_of_pos hr, real.log_mul hr.ne' hx,
of_real_add, add_assoc],
end
lemma log_mul_of_real (r : ℝ) (hr : 0 < r) (x : ℂ) (hx : x ≠ 0) :
log (x * r) = real.log r + log x :=
by rw [mul_comm, log_of_real_mul hr hx, add_comm]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = π * I := by simp [log]
lemma log_I : log I = π / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
lemma log_conj_eq_ite (x : ℂ) :
log (conj x) = if x.arg = π then log x else conj (log x) :=
begin
simp_rw [log, abs_conj, arg_conj, map_add, map_mul, conj_of_real],
split_ifs with hx,
{ rw hx },
simp_rw [of_real_neg, conj_I, mul_neg, neg_mul]
end
lemma log_conj (x : ℂ) (h : x.arg ≠ π) : log (conj x) = conj (log x) :=
by rw [log_conj_eq_ite, if_neg h]
lemma log_inv_eq_ite (x : ℂ) : log (x⁻¹) = if x.arg = π then -conj (log x) else -log x :=
begin
by_cases hx : x = 0,
{ simp [hx] },
rw [inv_def, log_mul_of_real, real.log_inv, of_real_neg, ←sub_eq_neg_add, log_conj_eq_ite],
{ simp_rw [log, map_add, map_mul, conj_of_real, conj_I, norm_sq_eq_abs, real.log_pow,
nat.cast_two, of_real_mul, of_real_bit0, of_real_one, neg_add, mul_neg, two_mul, neg_neg],
split_ifs,
{ rw [add_sub_right_comm, sub_add_cancel'] },
{ rw [add_sub_right_comm, sub_add_cancel'] } },
{ rwa [inv_pos, complex.norm_sq_pos] },
{ rwa map_ne_zero },
end
lemma log_inv (x : ℂ) (hx : x.arg ≠ π) : log (x⁻¹) = -log x :=
by rw [log_inv_eq_ite, if_neg hx]
lemma two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 :=
by norm_num [real.pi_ne_zero, I_ne_zero]
lemma exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * ((2 * π) * I) :=
begin
split,
{ intro h,
rcases exists_unique_add_zsmul_mem_Ioc real.two_pi_pos x.im (-π) with ⟨n, hn, -⟩,
use -n,
rw [int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero],
have : (x + n * (2 * π * I)).im ∈ Ioc (-π) π, by simpa [two_mul, mul_add] using hn,
rw [← log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one] },
{ rintro ⟨n, rfl⟩, exact (exp_periodic.int_mul n).eq.trans exp_zero }
end
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * ((2 * π) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
@[simp] lemma countable_preimage_exp {s : set ℂ} : (exp ⁻¹' s).countable ↔ s.countable :=
begin
refine ⟨λ hs, _, λ hs, _⟩,
{ refine ((hs.image exp).insert 0).mono _,
rw [image_preimage_eq_inter_range, range_exp, ← diff_eq, ← union_singleton, diff_union_self],
exact subset_union_left _ _ },
{ rw ← bUnion_preimage_singleton,
refine hs.bUnion (λ z hz, _),
rcases em (∃ w, exp w = z) with ⟨w, rfl⟩|hne,
{ simp only [preimage, mem_singleton_iff, exp_eq_exp_iff_exists_int, set_of_exists],
exact countable_Union (λ m, countable_singleton _) },
{ push_neg at hne, simp [preimage, hne] } }
end
alias countable_preimage_exp ↔ _ _root_.set.countable.preimage_cexp
lemma tendsto_log_nhds_within_im_neg_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
tendsto log (𝓝[{z : ℂ | z.im < 0}] z) (𝓝 $ real.log (abs z) - π * I) :=
begin
have := (continuous_of_real.continuous_at.comp_continuous_within_at
(continuous_abs.continuous_within_at.log _)).tendsto.add
(((continuous_of_real.tendsto _).comp $
tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),
convert this,
{ simp [sub_eq_add_neg] },
{ lift z to ℝ using him, simpa using hre.ne }
end
lemma continuous_within_at_log_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
continuous_within_at log {z : ℂ | 0 ≤ z.im} z :=
begin
have := (continuous_of_real.continuous_at.comp_continuous_within_at
(continuous_abs.continuous_within_at.log _)).tendsto.add
((continuous_of_real.continuous_at.comp_continuous_within_at $
continuous_within_at_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),
convert this,
{ lift z to ℝ using him, simpa using hre.ne }
end
lemma tendsto_log_nhds_within_im_nonneg_of_re_neg_of_im_zero
{z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
tendsto log (𝓝[{z : ℂ | 0 ≤ z.im}] z) (𝓝 $ real.log (abs z) + π * I) :=
by simpa only [log, arg_eq_pi_iff.2 ⟨hre, him⟩]
using (continuous_within_at_log_of_re_neg_of_im_zero hre him).tendsto
@[simp] lemma map_exp_comap_re_at_bot : map exp (comap re at_bot) = 𝓝[≠] 0 :=
by rw [← comap_exp_nhds_zero, map_comap, range_exp, nhds_within]
@[simp] lemma map_exp_comap_re_at_top : map exp (comap re at_top) = comap abs at_top :=
begin
rw [← comap_exp_comap_abs_at_top, map_comap, range_exp, inf_eq_left, le_principal_iff],
exact eventually_ne_of_tendsto_norm_at_top tendsto_comap 0
end
end complex
section log_deriv
open complex filter
open_locale topology
variables {α : Type*}
lemma continuous_at_clog {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) :
continuous_at log x :=
begin
refine continuous_at.add _ _,
{ refine continuous_of_real.continuous_at.comp _,
refine (real.continuous_at_log _).comp complex.continuous_abs.continuous_at,
rw complex.abs.ne_zero_iff,
rintro rfl,
simpa using h },
{ have h_cont_mul : continuous (λ x : ℂ, x * I), from continuous_id'.mul continuous_const,
refine h_cont_mul.continuous_at.comp (continuous_of_real.continuous_at.comp _),
exact continuous_at_arg h, },
end
lemma filter.tendsto.clog {l : filter α} {f : α → ℂ} {x : ℂ} (h : tendsto f l (𝓝 x))
(hx : 0 < x.re ∨ x.im ≠ 0) :
tendsto (λ t, log (f t)) l (𝓝 $ log x) :=
(continuous_at_clog hx).tendsto.comp h
variables [topological_space α]
lemma continuous_at.clog {f : α → ℂ} {x : α} (h₁ : continuous_at f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_at (λ t, log (f t)) x :=
h₁.clog h₂
lemma continuous_within_at.clog {f : α → ℂ} {s : set α} {x : α} (h₁ : continuous_within_at f s x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_within_at (λ t, log (f t)) s x :=
h₁.clog h₂
lemma continuous_on.clog {f : α → ℂ} {s : set α} (h₁ : continuous_on f s)
(h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous_on (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma continuous.clog {f : α → ℂ} (h₁ : continuous f) (h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
continuous (λ t, log (f t)) :=
continuous_iff_continuous_at.2 $ λ x, h₁.continuous_at.clog (h₂ x)
end log_deriv
|
6072a3984fdbd637230606143f3ea88f829de4bc
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/ring_theory/fractional_ideal.lean
|
3abf8d6da03036b75c3da610b9a882328d5db5f4
|
[
"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
| 50,274
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Filippo A. E. Nuccio
-/
import ring_theory.localization
import ring_theory.noetherian
import ring_theory.principal_ideal_domain
import tactic.field_simp
/-!
# Fractional ideals
This file defines fractional ideals of an integral domain and proves basic facts about them.
## Main definitions
Let `S` be a submonoid of an integral domain `R`, `P` the localization of `R` at `S`, and `f` the
natural ring hom from `R` to `P`.
* `is_fractional` defines which `R`-submodules of `P` are fractional ideals
* `fractional_ideal S P` is the type of fractional ideals in `P`
* `has_coe_t (ideal R) (fractional_ideal S P)` instance
* `comm_semiring (fractional_ideal S P)` instance:
the typical ideal operations generalized to fractional ideals
* `lattice (fractional_ideal S P)` instance
* `map` is the pushforward of a fractional ideal along an algebra morphism
Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions).
* `fractional_ideal R⁰ K` is the type of fractional ideals in the field of fractions
* `has_div (fractional_ideal R⁰ K)` instance:
the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined)
## Main statements
* `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone
* `prod_one_self_div_eq` states that `1 / I` is the inverse of `I` if one exists
* `is_noetherian` states that very fractional ideal of a noetherian integral domain is noetherian
## Implementation notes
Fractional ideals are considered equal when they contain the same elements,
independent of the denominator `a : R` such that `a I ⊆ R`.
Thus, we define `fractional_ideal` to be the subtype of the predicate `is_fractional`,
instead of having `fractional_ideal` be a structure of which `a` is a field.
Most definitions in this file specialize operations from submodules to fractional ideals,
proving that the result of this operation is fractional if the input is fractional.
Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`,
in order to re-use their respective proof terms.
We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`.
Many results in fact do not need that `P` is a localization, only that `P` is an
`R`-algebra. We omit the `is_localization` parameter whenever this is practical.
Similarly, we don't assume that the localization is a field until we need it to
define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`,
making the localization a field.
## References
* https://en.wikipedia.org/wiki/Fractional_ideal
## Tags
fractional ideal, fractional ideals, invertible ideal
-/
open is_localization
open_locale pointwise
open_locale non_zero_divisors
section defs
variables {R : Type*} [comm_ring R] {S : submonoid R} {P : Type*} [comm_ring P]
variables [algebra R P]
variables (S)
/-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/
def is_fractional (I : submodule R P) :=
∃ a ∈ S, ∀ b ∈ I, is_integer R (a • b)
variables (S P)
/-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`.
More precisely, let `P` be a localization of `R` at some submonoid `S`,
then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`,
such that there is a nonzero `a : R` with `a I ⊆ R`.
-/
def fractional_ideal :=
{I : submodule R P // is_fractional S I}
end defs
namespace fractional_ideal
open set
open submodule
variables {R : Type*} [comm_ring R] {S : submonoid R} {P : Type*} [comm_ring P]
variables [algebra R P] [loc : is_localization S P]
/-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`.
This coercion is typically called `coe_to_submodule` in lemma names
(or `coe` when the coercion is clear from the context),
not to be confused with `is_localization.coe_submodule : ideal R → submodule R P`
(which we use to define `coe : ideal R → fractional_ideal S P`,
referred to as `coe_ideal` in theorem names).
-/
instance : has_coe (fractional_ideal S P) (submodule R P) := ⟨λ I, I.val⟩
protected lemma is_fractional (I : fractional_ideal S P) :
is_fractional S (I : submodule R P) :=
I.prop
section set_like
instance : set_like (fractional_ideal S P) P :=
{ coe := λ I, ↑(I : submodule R P),
coe_injective' := set_like.coe_injective.comp subtype.coe_injective }
@[simp] lemma mem_coe {I : fractional_ideal S P} {x : P} :
x ∈ (I : submodule R P) ↔ x ∈ I :=
iff.rfl
@[ext] lemma ext {I J : fractional_ideal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := set_like.ext
/-- Copy of a `fractional_ideal` with a new underlying set equal to the old one.
Useful to fix definitional equalities. -/
protected def copy (p : fractional_ideal S P) (s : set P) (hs : s = ↑p) : fractional_ideal S P :=
⟨submodule.copy p s hs, by { convert p.is_fractional, ext, simp only [hs], refl }⟩
end set_like
@[simp] lemma val_eq_coe (I : fractional_ideal S P) : I.val = I := rfl
@[simp, norm_cast] lemma coe_mk (I : submodule R P) (hI : is_fractional S I) :
(subtype.mk I hI : submodule R P) = I := rfl
lemma coe_to_submodule_injective :
function.injective (coe : fractional_ideal S P → submodule R P) :=
subtype.coe_injective
lemma is_fractional_of_le_one (I : submodule R P) (h : I ≤ 1) :
is_fractional S I :=
begin
use [1, S.one_mem],
intros b hb,
rw one_smul,
obtain ⟨b', b'_mem, rfl⟩ := h hb,
exact set.mem_range_self b',
end
lemma is_fractional_of_le {I : submodule R P} {J : fractional_ideal S P}
(hIJ : I ≤ J) : is_fractional S I :=
begin
obtain ⟨a, a_mem, ha⟩ := J.is_fractional,
use [a, a_mem],
intros b b_mem,
exact ha b (hIJ b_mem)
end
/-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral.
This is a bundled version of `is_localization.coe_submodule : ideal R → submodule R P`,
which is not to be confused with the `coe : fractional_ideal S P → submodule R P`,
also called `coe_to_submodule` in theorem names.
This map is available as a ring hom, called `fractional_ideal.coe_ideal_hom`.
-/
-- Is a `coe_t` rather than `coe` to speed up failing inference, see library note [use has_coe_t]
instance coe_to_fractional_ideal : has_coe_t (ideal R) (fractional_ideal S P) :=
⟨λ I, ⟨coe_submodule P I, is_fractional_of_le_one _
(by simpa using coe_submodule_mono P (le_top : I ≤ ⊤))⟩⟩
@[simp, norm_cast] lemma coe_coe_ideal (I : ideal R) :
((I : fractional_ideal S P) : submodule R P) = coe_submodule P I := rfl
variables (S)
@[simp] lemma mem_coe_ideal {x : P} {I : ideal R} :
x ∈ (I : fractional_ideal S P) ↔ ∃ x', x' ∈ I ∧ algebra_map R P x' = x :=
mem_coe_submodule _ _
lemma mem_coe_ideal_of_mem {x : R} {I : ideal R} (hx : x ∈ I) :
algebra_map R P x ∈ (I : fractional_ideal S P) :=
(mem_coe_ideal S).mpr ⟨x, hx, rfl⟩
lemma coe_ideal_le_coe_ideal' [is_localization S P] (h : S ≤ non_zero_divisors R)
{I J : ideal R} : (I : fractional_ideal S P) ≤ J ↔ I ≤ J :=
coe_submodule_le_coe_submodule h
@[simp] lemma coe_ideal_le_coe_ideal (K : Type*) [comm_ring K] [algebra R K] [is_fraction_ring R K]
{I J : ideal R} : (I : fractional_ideal R⁰ K) ≤ J ↔ I ≤ J :=
is_fraction_ring.coe_submodule_le_coe_submodule
instance : has_zero (fractional_ideal S P) := ⟨(0 : ideal R)⟩
@[simp] lemma mem_zero_iff {x : P} : x ∈ (0 : fractional_ideal S P) ↔ x = 0 :=
⟨(λ ⟨x', x'_mem_zero, x'_eq_x⟩,
have x'_eq_zero : x' = 0 := x'_mem_zero,
by simp [x'_eq_x.symm, x'_eq_zero]),
(λ hx, ⟨0, rfl, by simp [hx]⟩)⟩
variables {S}
@[simp, norm_cast] lemma coe_zero : ↑(0 : fractional_ideal S P) = (⊥ : submodule R P) :=
submodule.ext $ λ _, mem_zero_iff S
@[simp, norm_cast] lemma coe_to_fractional_ideal_bot : ((⊥ : ideal R) : fractional_ideal S P) = 0 :=
rfl
variables (P)
include loc
@[simp] lemma exists_mem_to_map_eq {x : R} {I : ideal R} (h : S ≤ non_zero_divisors R) :
(∃ x', x' ∈ I ∧ algebra_map R P x' = algebra_map R P x) ↔ x ∈ I :=
⟨λ ⟨x', hx', eq⟩, is_localization.injective _ h eq ▸ hx', λ h, ⟨x, h, rfl⟩⟩
variables {P}
lemma coe_to_fractional_ideal_injective (h : S ≤ non_zero_divisors R) :
function.injective (coe : ideal R → fractional_ideal S P) :=
λ I J heq, have
∀ (x : R), algebra_map R P x ∈ (I : fractional_ideal S P) ↔
algebra_map R P x ∈ (J : fractional_ideal S P) :=
λ x, heq ▸ iff.rfl,
ideal.ext (by simpa only [mem_coe_ideal, exists_prop, exists_mem_to_map_eq P h] using this)
lemma coe_to_fractional_ideal_eq_zero {I : ideal R} (hS : S ≤ non_zero_divisors R) :
(I : fractional_ideal S P) = 0 ↔ I = (⊥ : ideal R) :=
⟨λ h, coe_to_fractional_ideal_injective hS h,
λ h, by rw [h, coe_to_fractional_ideal_bot]⟩
lemma coe_to_fractional_ideal_ne_zero {I : ideal R} (hS : S ≤ non_zero_divisors R) :
(I : fractional_ideal S P) ≠ 0 ↔ I ≠ (⊥ : ideal R) :=
not_iff_not.mpr (coe_to_fractional_ideal_eq_zero hS)
omit loc
lemma coe_to_submodule_eq_bot {I : fractional_ideal S P} :
(I : submodule R P) = ⊥ ↔ I = 0 :=
⟨λ h, coe_to_submodule_injective (by simp [h]),
λ h, by simp [h]⟩
lemma coe_to_submodule_ne_bot {I : fractional_ideal S P} :
↑I ≠ (⊥ : submodule R P) ↔ I ≠ 0 :=
not_iff_not.mpr coe_to_submodule_eq_bot
instance : inhabited (fractional_ideal S P) := ⟨0⟩
instance : has_one (fractional_ideal S P) :=
⟨(⊤ : ideal R)⟩
variables (S)
@[simp, norm_cast] lemma coe_ideal_top : ((⊤ : ideal R) : fractional_ideal S P) = 1 :=
rfl
lemma mem_one_iff {x : P} : x ∈ (1 : fractional_ideal S P) ↔ ∃ x' : R, algebra_map R P x' = x :=
iff.intro (λ ⟨x', _, h⟩, ⟨x', h⟩) (λ ⟨x', h⟩, ⟨x', ⟨⟩, h⟩)
lemma coe_mem_one (x : R) : algebra_map R P x ∈ (1 : fractional_ideal S P) :=
(mem_one_iff S).mpr ⟨x, rfl⟩
lemma one_mem_one : (1 : P) ∈ (1 : fractional_ideal S P) :=
(mem_one_iff S).mpr ⟨1, ring_hom.map_one _⟩
variables {S}
/-- `(1 : fractional_ideal S P)` is defined as the R-submodule `f(R) ≤ P`.
However, this is not definitionally equal to `1 : submodule R P`,
which is proved in the actual `simp` lemma `coe_one`. -/
lemma coe_one_eq_coe_submodule_top :
↑(1 : fractional_ideal S P) = coe_submodule P (⊤ : ideal R) :=
rfl
@[simp, norm_cast] lemma coe_one :
(↑(1 : fractional_ideal S P) : submodule R P) = 1 :=
by rw [coe_one_eq_coe_submodule_top, coe_submodule_top]
section lattice
/-!
### `lattice` section
Defines the order on fractional ideals as inclusion of their underlying sets,
and ports the lattice structure on submodules to fractional ideals.
-/
@[simp] lemma coe_le_coe {I J : fractional_ideal S P} :
(I : submodule R P) ≤ (J : submodule R P) ↔ I ≤ J :=
iff.rfl
lemma zero_le (I : fractional_ideal S P) : 0 ≤ I :=
begin
intros x hx,
convert submodule.zero_mem _,
simpa using hx
end
instance order_bot : order_bot (fractional_ideal S P) :=
{ bot := 0,
bot_le := zero_le,
..set_like.partial_order }
@[simp] lemma bot_eq_zero : (⊥ : fractional_ideal S P) = 0 :=
rfl
@[simp] lemma le_zero_iff {I : fractional_ideal S P} : I ≤ 0 ↔ I = 0 :=
le_bot_iff
lemma eq_zero_iff {I : fractional_ideal S P} : I = 0 ↔ (∀ x ∈ I, x = (0 : P)) :=
⟨ (λ h x hx, by simpa [h, mem_zero_iff] using hx),
(λ h, le_bot_iff.mp (λ x hx, (mem_zero_iff S).mpr (h x hx))) ⟩
lemma fractional_sup (I J : fractional_ideal S P) : is_fractional S (I ⊔ J : submodule R P) :=
begin
rcases I.is_fractional with ⟨aI, haI, hI⟩,
rcases J.is_fractional with ⟨aJ, haJ, hJ⟩,
use aI * aJ,
use S.mul_mem haI haJ,
intros b hb,
rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, rfl⟩,
rw smul_add,
apply is_integer_add,
{ rw [mul_smul, smul_comm],
exact is_integer_smul (hI bI hbI), },
{ rw mul_smul,
exact is_integer_smul (hJ bJ hbJ) }
end
lemma fractional_inf (I J : fractional_ideal S P) : is_fractional S (I ⊓ J : submodule R P) :=
begin
rcases I.is_fractional with ⟨aI, haI, hI⟩,
use aI,
use haI,
intros b hb,
rcases mem_inf.mp hb with ⟨hbI, hbJ⟩,
exact hI b hbI
end
instance lattice : lattice (fractional_ideal S P) :=
{ inf := λ I J, ⟨I ⊓ J, fractional_inf I J⟩,
sup := λ I J, ⟨I ⊔ J, fractional_sup I J⟩,
inf_le_left := λ I J, show (I ⊓ J : submodule R P) ≤ I, from inf_le_left,
inf_le_right := λ I J, show (I ⊓ J : submodule R P) ≤ J, from inf_le_right,
le_inf := λ I J K hIJ hIK, show (I : submodule R P) ≤ J ⊓ K, from le_inf hIJ hIK,
le_sup_left := λ I J, show (I : submodule R P) ≤ I ⊔ J, from le_sup_left,
le_sup_right := λ I J, show (J : submodule R P) ≤ I ⊔ J, from le_sup_right,
sup_le := λ I J K hIK hJK, show (I ⊔ J : submodule R P) ≤ K, from sup_le hIK hJK,
..set_like.partial_order }
instance : semilattice_sup_bot (fractional_ideal S P) :=
{ ..fractional_ideal.order_bot, ..fractional_ideal.lattice }
end lattice
section semiring
instance : has_add (fractional_ideal S P) := ⟨(⊔)⟩
@[simp]
lemma sup_eq_add (I J : fractional_ideal S P) : I ⊔ J = I + J := rfl
@[simp, norm_cast]
lemma coe_add (I J : fractional_ideal S P) : (↑(I + J) : submodule R P) = I + J := rfl
@[simp, norm_cast]
lemma coe_ideal_sup (I J : ideal R) : ↑(I ⊔ J) = (I + J : fractional_ideal S P) :=
coe_to_submodule_injective $ coe_submodule_sup _ _ _
lemma fractional_mul (I J : fractional_ideal S P) : is_fractional S (I * J : submodule R P) :=
begin
rcases I with ⟨I, aI, haI, hI⟩,
rcases J with ⟨J, aJ, haJ, hJ⟩,
use aI * aJ,
use S.mul_mem haI haJ,
intros b hb,
apply submodule.mul_induction_on hb,
{ intros m hm n hn,
obtain ⟨n', hn'⟩ := hJ n hn,
rw [mul_smul, mul_comm m, ← smul_mul_assoc, ← hn', ← algebra.smul_def],
apply hI,
exact submodule.smul_mem _ _ hm },
{ rw smul_zero,
exact ⟨0, ring_hom.map_zero _⟩ },
{ intros x y hx hy,
rw smul_add,
apply is_integer_add hx hy },
{ intros r x hx,
rw smul_comm,
exact is_integer_smul hx },
end
/-- `fractional_ideal.mul` is the product of two fractional ideals,
used to define the `has_mul` instance.
This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`.
Elaborated terms involving `fractional_ideal` tend to grow quite large,
so by making definitions irreducible, we hope to avoid deep unfolds.
-/
@[irreducible]
def mul (I J : fractional_ideal S P) : fractional_ideal S P :=
⟨I * J, fractional_mul I J⟩
local attribute [semireducible] mul
instance : has_mul (fractional_ideal S P) := ⟨λ I J, mul I J⟩
@[simp] lemma mul_eq_mul (I J : fractional_ideal S P) : mul I J = I * J := rfl
@[simp, norm_cast]
lemma coe_mul (I J : fractional_ideal S P) : (↑(I * J) : submodule R P) = I * J := rfl
@[simp, norm_cast]
lemma coe_ideal_mul (I J : ideal R) : (↑(I * J) : fractional_ideal S P) = I * J :=
coe_to_submodule_injective $ coe_submodule_mul _ _ _
lemma mul_left_mono (I : fractional_ideal S P) : monotone ((*) I) :=
λ J J' h, mul_le.mpr (λ x hx y hy, mul_mem_mul hx (h hy))
lemma mul_right_mono (I : fractional_ideal S P) : monotone (λ J, J * I) :=
λ J J' h, mul_le.mpr (λ x hx y hy, mul_mem_mul (h hx) hy)
lemma mul_mem_mul {I J : fractional_ideal S P} {i j : P} (hi : i ∈ I) (hj : j ∈ J) :
i * j ∈ I * J := submodule.mul_mem_mul hi hj
lemma mul_le {I J K : fractional_ideal S P} :
I * J ≤ K ↔ (∀ (i ∈ I) (j ∈ J), i * j ∈ K) :=
submodule.mul_le
@[elab_as_eliminator] protected theorem mul_induction_on
{I J : fractional_ideal S P}
{C : P → Prop} {r : P} (hr : r ∈ I * J)
(hm : ∀ (i ∈ I) (j ∈ J), C (i * j))
(h0 : C 0) (ha : ∀ x y, C x → C y → C (x + y))
(hs : ∀ (r : R) x, C x → C (r • x)) : C r :=
submodule.mul_induction_on hr hm h0 ha hs
instance comm_semiring : comm_semiring (fractional_ideal S P) :=
{ add_assoc := λ I J K, sup_assoc,
add_comm := λ I J, sup_comm,
add_zero := λ I, sup_bot_eq,
zero_add := λ I, bot_sup_eq,
mul_assoc := λ I J K, coe_to_submodule_injective (submodule.mul_assoc _ _ _),
mul_comm := λ I J, coe_to_submodule_injective (submodule.mul_comm _ _),
mul_one := λ I, begin
ext,
split; intro h,
{ apply mul_le.mpr _ h,
rintros x hx y ⟨y', y'_mem_R, rfl⟩,
convert submodule.smul_mem _ y' hx,
rw [mul_comm, eq_comm],
exact algebra.smul_def y' x },
{ have : x * 1 ∈ (I * 1) := mul_mem_mul h (one_mem_one _),
rwa [mul_one] at this }
end,
one_mul := λ I, begin
ext,
split; intro h,
{ apply mul_le.mpr _ h,
rintros x ⟨x', x'_mem_R, rfl⟩ y hy,
convert submodule.smul_mem _ x' hy,
rw eq_comm,
exact algebra.smul_def x' y },
{ have : 1 * x ∈ (1 * I) := mul_mem_mul (one_mem_one _) h,
rwa one_mul at this }
end,
mul_zero := λ I, eq_zero_iff.mpr (λ x hx, submodule.mul_induction_on hx
(λ x hx y hy, by simp [(mem_zero_iff S).mp hy])
rfl
(λ x y hx hy, by simp [hx, hy])
(λ r x hx, by simp [hx])),
zero_mul := λ I, eq_zero_iff.mpr (λ x hx, submodule.mul_induction_on hx
(λ x hx y hy, by simp [(mem_zero_iff S).mp hx])
rfl
(λ x y hx hy, by simp [hx, hy])
(λ r x hx, by simp [hx])),
left_distrib := λ I J K, coe_to_submodule_injective (mul_add _ _ _),
right_distrib := λ I J K, coe_to_submodule_injective (add_mul _ _ _),
..fractional_ideal.has_zero S,
..fractional_ideal.has_add,
..fractional_ideal.has_one,
..fractional_ideal.has_mul }
section order
lemma add_le_add_left {I J : fractional_ideal S P} (hIJ : I ≤ J) (J' : fractional_ideal S P) :
J' + I ≤ J' + J :=
sup_le_sup_left hIJ J'
lemma mul_le_mul_left {I J : fractional_ideal S P} (hIJ : I ≤ J) (J' : fractional_ideal S P) :
J' * I ≤ J' * J :=
mul_le.mpr (λ k hk j hj, mul_mem_mul hk (hIJ hj))
lemma le_self_mul_self {I : fractional_ideal S P} (hI: 1 ≤ I) : I ≤ I * I :=
begin
convert mul_left_mono I hI,
exact (mul_one I).symm
end
lemma mul_self_le_self {I : fractional_ideal S P} (hI: I ≤ 1) : I * I ≤ I :=
begin
convert mul_left_mono I hI,
exact (mul_one I).symm
end
lemma coe_ideal_le_one {I : ideal R} : (I : fractional_ideal S P) ≤ 1 :=
λ x hx, let ⟨y, _, hy⟩ := (fractional_ideal.mem_coe_ideal S).mp hx
in (fractional_ideal.mem_one_iff S).mpr ⟨y, hy⟩
lemma le_one_iff_exists_coe_ideal {J : fractional_ideal S P} :
J ≤ (1 : fractional_ideal S P) ↔ ∃ (I : ideal R), ↑I = J :=
begin
split,
{ intro hJ,
refine ⟨⟨{x : R | algebra_map R P x ∈ J}, _, _, _⟩, _⟩,
{ rw [mem_set_of_eq, ring_hom.map_zero],
exact J.val.zero_mem },
{ intros a b ha hb,
rw [mem_set_of_eq, ring_hom.map_add],
exact J.val.add_mem ha hb },
{ intros c x hx,
rw [smul_eq_mul, mem_set_of_eq, ring_hom.map_mul, ← algebra.smul_def],
exact J.val.smul_mem c hx },
{ ext x,
split,
{ rintros ⟨y, hy, eq_y⟩,
rwa ← eq_y },
{ intro hx,
obtain ⟨y, eq_x⟩ := (fractional_ideal.mem_one_iff S).mp (hJ hx),
rw ← eq_x at *,
exact ⟨y, hx, rfl⟩ } } },
{ rintro ⟨I, hI⟩,
rw ← hI,
apply coe_ideal_le_one },
end
variables (S P)
/-- `coe_ideal_hom (S : submonoid R) P` is `coe : ideal R → fractional_ideal S P` as a ring hom -/
@[simps]
def coe_ideal_hom : ideal R →+* fractional_ideal S P :=
{ to_fun := coe,
map_add' := coe_ideal_sup,
map_mul' := coe_ideal_mul,
map_one' := by rw [ideal.one_eq_top, coe_ideal_top],
map_zero' := coe_to_fractional_ideal_bot }
end order
variables {P' : Type*} [comm_ring P'] [algebra R P'] [loc' : is_localization S P']
variables {P'' : Type*} [comm_ring P''] [algebra R P''] [loc'' : is_localization S P'']
lemma fractional_map (g : P →ₐ[R] P') (I : fractional_ideal S P) :
is_fractional S (submodule.map g.to_linear_map I) :=
begin
rcases I with ⟨I, a, a_nonzero, hI⟩,
use [a, a_nonzero],
intros b hb,
obtain ⟨b', b'_mem, hb'⟩ := submodule.mem_map.mp hb,
obtain ⟨x, hx⟩ := hI b' b'_mem,
use x,
erw [←g.commutes, hx, g.map_smul, hb']
end
/-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/
def map (g : P →ₐ[R] P') :
fractional_ideal S P → fractional_ideal S P' :=
λ I, ⟨submodule.map g.to_linear_map I, fractional_map g I⟩
@[simp, norm_cast] lemma coe_map (g : P →ₐ[R] P') (I : fractional_ideal S P) :
↑(map g I) = submodule.map g.to_linear_map I := rfl
@[simp] lemma mem_map {I : fractional_ideal S P} {g : P →ₐ[R] P'}
{y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y :=
submodule.mem_map
variables (I J : fractional_ideal S P) (g : P →ₐ[R] P')
@[simp] lemma map_id : I.map (alg_hom.id _ _) = I :=
coe_to_submodule_injective (submodule.map_id I)
@[simp] lemma map_comp (g' : P' →ₐ[R] P'') :
I.map (g'.comp g) = (I.map g).map g' :=
coe_to_submodule_injective (submodule.map_comp g.to_linear_map g'.to_linear_map I)
@[simp, norm_cast] lemma map_coe_ideal (I : ideal R) :
(I : fractional_ideal S P).map g = I :=
begin
ext x,
simp only [mem_coe_ideal],
split,
{ rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩,
exact ⟨y, hy, (g.commutes y).symm⟩ },
{ rintro ⟨y, hy, rfl⟩,
exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩ },
end
@[simp] lemma map_one :
(1 : fractional_ideal S P).map g = 1 :=
map_coe_ideal g ⊤
@[simp] lemma map_zero :
(0 : fractional_ideal S P).map g = 0 :=
map_coe_ideal g 0
@[simp] lemma map_add : (I + J).map g = I.map g + J.map g :=
coe_to_submodule_injective (submodule.map_sup _ _ _)
@[simp] lemma map_mul : (I * J).map g = I.map g * J.map g :=
coe_to_submodule_injective (submodule.map_mul _ _ _)
@[simp] lemma map_map_symm (g : P ≃ₐ[R] P') :
(I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I :=
by rw [←map_comp, g.symm_comp, map_id]
@[simp] lemma map_symm_map (I : fractional_ideal S P') (g : P ≃ₐ[R] P') :
(I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I :=
by rw [←map_comp, g.comp_symm, map_id]
lemma map_mem_map {f : P →ₐ[R] P'} (h : function.injective f) {x : P} {I : fractional_ideal S P} :
f x ∈ map f I ↔ x ∈ I :=
mem_map.trans ⟨λ ⟨x', hx', x'_eq⟩, h x'_eq ▸ hx', λ h, ⟨x, h, rfl⟩⟩
lemma map_injective (f : P →ₐ[R] P') (h : function.injective f) :
function.injective (map f : fractional_ideal S P → fractional_ideal S P') :=
λ I J hIJ, fractional_ideal.ext (λ x, (fractional_ideal.map_mem_map h).symm.trans
(hIJ.symm ▸ fractional_ideal.map_mem_map h))
/-- If `g` is an equivalence, `map g` is an isomorphism -/
def map_equiv (g : P ≃ₐ[R] P') :
fractional_ideal S P ≃+* fractional_ideal S P' :=
{ to_fun := map g,
inv_fun := map g.symm,
map_add' := λ I J, map_add I J _,
map_mul' := λ I J, map_mul I J _,
left_inv := λ I, by { rw [←map_comp, alg_equiv.symm_comp, map_id] },
right_inv := λ I, by { rw [←map_comp, alg_equiv.comp_symm, map_id] } }
@[simp] lemma coe_fun_map_equiv (g : P ≃ₐ[R] P') :
(map_equiv g : fractional_ideal S P → fractional_ideal S P') = map g :=
rfl
@[simp] lemma map_equiv_apply (g : P ≃ₐ[R] P') (I : fractional_ideal S P) :
map_equiv g I = map ↑g I := rfl
@[simp] lemma map_equiv_symm (g : P ≃ₐ[R] P') :
((map_equiv g).symm : fractional_ideal S P' ≃+* _) = map_equiv g.symm := rfl
@[simp] lemma map_equiv_refl :
map_equiv alg_equiv.refl = ring_equiv.refl (fractional_ideal S P) :=
ring_equiv.ext (λ x, by simp)
lemma is_fractional_span_iff {s : set P} :
is_fractional S (span R s) ↔ ∃ a ∈ S, ∀ (b : P), b ∈ s → is_integer R (a • b) :=
⟨λ ⟨a, a_mem, h⟩, ⟨a, a_mem, λ b hb, h b (subset_span hb)⟩,
λ ⟨a, a_mem, h⟩, ⟨a, a_mem, λ b hb, span_induction hb
h
(by { rw smul_zero, exact is_integer_zero })
(λ x y hx hy, by { rw smul_add, exact is_integer_add hx hy })
(λ s x hx, by { rw smul_comm, exact is_integer_smul hx })⟩⟩
include loc
lemma is_fractional_of_fg {I : submodule R P} (hI : I.fg) :
is_fractional S I :=
begin
rcases hI with ⟨I, rfl⟩,
rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩,
rw is_fractional_span_iff,
exact ⟨s, hs1, hs⟩,
end
omit loc
lemma mem_span_mul_finite_of_mem_mul {I J : fractional_ideal S P} {x : P} (hx : x ∈ I * J) :
∃ (T T' : finset P), (T : set P) ⊆ I ∧ (T' : set P) ⊆ J ∧ x ∈ span R (T * T' : set P) :=
submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx)
variables (S)
lemma coe_ideal_fg (inj : function.injective (algebra_map R P)) (I : ideal R) :
fg ((I : fractional_ideal S P) : submodule R P) ↔ fg I :=
coe_submodule_fg _ inj _
variables {S}
lemma fg_unit (I : units (fractional_ideal S P)) :
fg (I : submodule R P) :=
begin
have : (1 : P) ∈ (I * ↑I⁻¹ : fractional_ideal S P),
{ rw units.mul_inv, exact one_mem_one _ },
obtain ⟨T, T', hT, hT', one_mem⟩ := mem_span_mul_finite_of_mem_mul this,
refine ⟨T, submodule.span_eq_of_le _ hT _⟩,
rw [← one_mul ↑I, ← mul_one (span R ↑T)],
conv_rhs { rw [← fractional_ideal.coe_one, ← units.mul_inv I, fractional_ideal.coe_mul,
mul_comm ↑↑I, ← mul_assoc] },
refine submodule.mul_le_mul_left
(le_trans _ (submodule.mul_le_mul_right (submodule.span_le.mpr hT'))),
rwa [submodule.one_le, submodule.span_mul_span]
end
lemma fg_of_is_unit (I : fractional_ideal S P) (h : is_unit I) :
fg (I : submodule R P) :=
by { rcases h with ⟨I, rfl⟩, exact fg_unit I }
lemma _root_.ideal.fg_of_is_unit (inj : function.injective (algebra_map R P))
(I : ideal R) (h : is_unit (I : fractional_ideal S P)) :
I.fg :=
by { rw ← coe_ideal_fg S inj I, exact fg_of_is_unit I h }
variables (S P P')
include loc loc'
/-- `canonical_equiv f f'` is the canonical equivalence between the fractional
ideals in `P` and in `P'` -/
@[irreducible]
noncomputable def canonical_equiv :
fractional_ideal S P ≃+* fractional_ideal S P' :=
map_equiv
{ commutes' := λ r, ring_equiv_of_ring_equiv_eq _ _,
..ring_equiv_of_ring_equiv P P' (ring_equiv.refl R)
(show S.map _ = S, by rw [ring_equiv.to_monoid_hom_refl, submonoid.map_id]) }
@[simp] lemma mem_canonical_equiv_apply {I : fractional_ideal S P} {x : P'} :
x ∈ canonical_equiv S P P' I ↔
∃ y ∈ I, is_localization.map P' (ring_hom.id R)
(λ y (hy : y ∈ S), show ring_hom.id R y ∈ S, from hy) (y : P) = x :=
begin
rw [canonical_equiv, map_equiv_apply, mem_map],
exact ⟨λ ⟨y, mem, eq⟩, ⟨y, mem, eq⟩, λ ⟨y, mem, eq⟩, ⟨y, mem, eq⟩⟩
end
@[simp] lemma canonical_equiv_symm :
(canonical_equiv S P P').symm = canonical_equiv S P' P :=
ring_equiv.ext $ λ I, set_like.ext_iff.mpr $ λ x,
by { rw [mem_canonical_equiv_apply, canonical_equiv, map_equiv_symm, map_equiv,
ring_equiv.coe_mk, mem_map],
exact ⟨λ ⟨y, mem, eq⟩, ⟨y, mem, eq⟩, λ ⟨y, mem, eq⟩, ⟨y, mem, eq⟩⟩ }
@[simp] lemma canonical_equiv_flip (I) :
canonical_equiv S P P' (canonical_equiv S P' P I) = I :=
by rw [←canonical_equiv_symm, ring_equiv.symm_apply_apply]
end semiring
section is_fraction_ring
/-!
### `is_fraction_ring` section
This section concerns fractional ideals in the field of fractions,
i.e. the type `fractional_ideal R⁰ K` where `is_fraction_ring R K`.
-/
variables {K K' : Type*} [field K] [field K']
variables [algebra R K] [is_fraction_ring R K] [algebra R K'] [is_fraction_ring R K']
variables {I J : fractional_ideal R⁰ K} (h : K →ₐ[R] K')
/-- Nonzero fractional ideals contain a nonzero integer. -/
lemma exists_ne_zero_mem_is_integer [nontrivial R] (hI : I ≠ 0) :
∃ x ≠ (0 : R), algebra_map R K x ∈ I :=
begin
obtain ⟨y, y_mem, y_not_mem⟩ := set_like.exists_of_lt (bot_lt_iff_ne_bot.mpr hI),
have y_ne_zero : y ≠ 0 := by simpa using y_not_mem,
obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y,
refine ⟨x, _, _⟩,
{ rw [ne.def, ← @is_fraction_ring.to_map_eq_zero_iff R _ K, hx, algebra.smul_def],
exact mul_ne_zero (is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors z.2) y_ne_zero },
{ rw hx,
exact smul_mem _ _ y_mem }
end
lemma map_ne_zero [nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 :=
begin
obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_is_integer hI,
contrapose! x_ne_zero with map_eq_zero,
refine is_fraction_ring.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr _)),
exact ⟨algebra_map R K x, hx, h.commutes x⟩,
end
@[simp] lemma map_eq_zero_iff [nontrivial R] : I.map h = 0 ↔ I = 0 :=
⟨imp_of_not_imp_not _ _ (map_ne_zero _),
λ hI, hI.symm ▸ map_zero h⟩
lemma coe_ideal_injective :
function.injective (coe : ideal R → fractional_ideal R⁰ K) :=
injective_of_le_imp_le _ (λ _ _, (coe_ideal_le_coe_ideal _).mp)
@[simp]
lemma coe_ideal_eq_zero_iff
{I : ideal R} : (I : fractional_ideal R⁰ K) = 0 ↔ I = ⊥ :=
by { rw ← coe_to_fractional_ideal_bot, exact coe_ideal_injective.eq_iff }
lemma coe_ideal_ne_zero_iff
{I : ideal R} : (I : fractional_ideal R⁰ K) ≠ 0 ↔ I ≠ ⊥ :=
not_iff_not.mpr coe_ideal_eq_zero_iff
lemma coe_ideal_ne_zero
{I : ideal R} (hI : I ≠ ⊥) : (I : fractional_ideal R⁰ K) ≠ 0 :=
coe_ideal_ne_zero_iff.mpr hI
end is_fraction_ring
section quotient
/-!
### `quotient` section
This section defines the ideal quotient of fractional ideals.
In this section we need that each non-zero `y : R` has an inverse in
the localization, i.e. that the localization is a field. We satisfy this
assumption by taking `S = non_zero_divisors R`, `R`'s localization at which
is a field because `R` is a domain.
-/
open_locale classical
variables {R₁ : Type*} [comm_ring R₁] {K : Type*} [field K]
variables [algebra R₁ K] [frac : is_fraction_ring R₁ K]
instance : nontrivial (fractional_ideal R₁⁰ K) :=
⟨⟨0, 1, λ h,
have this : (1 : K) ∈ (0 : fractional_ideal R₁⁰ K) :=
by { rw ← (algebra_map R₁ K).map_one, simpa only [h] using coe_mem_one R₁⁰ 1 },
one_ne_zero ((mem_zero_iff _).mp this)⟩⟩
lemma ne_zero_of_mul_eq_one (I J : fractional_ideal R₁⁰ K) (h : I * J = 1) : I ≠ 0 :=
λ hI, @zero_ne_one (fractional_ideal R₁⁰ K) _ _ (by { convert h, simp [hI], })
variables [integral_domain R₁]
include frac
lemma fractional_div_of_nonzero {I J : fractional_ideal R₁⁰ K} (h : J ≠ 0) :
is_fractional R₁⁰ (I / J : submodule R₁ K) :=
begin
rcases I with ⟨I, aI, haI, hI⟩,
rcases J with ⟨J, aJ, haJ, hJ⟩,
obtain ⟨y, mem_J, not_mem_zero⟩ := set_like.exists_of_lt (bot_lt_iff_ne_bot.mpr h),
obtain ⟨y', hy'⟩ := hJ y mem_J,
use (aI * y'),
split,
{ apply (non_zero_divisors R₁).mul_mem haI (mem_non_zero_divisors_iff_ne_zero.mpr _),
intro y'_eq_zero,
have : algebra_map R₁ K aJ * y = 0,
{ rw [← algebra.smul_def, ←hy', y'_eq_zero, ring_hom.map_zero] },
have y_zero := (mul_eq_zero.mp this).resolve_left
(mt ((algebra_map R₁ K).injective_iff.1 (is_fraction_ring.injective _ _) _)
(mem_non_zero_divisors_iff_ne_zero.mp haJ)),
exact not_mem_zero ((mem_zero_iff R₁⁰).mpr y_zero) },
intros b hb,
convert hI _ (hb _ (submodule.smul_mem _ aJ mem_J)) using 1,
rw [← hy', mul_comm b, ← algebra.smul_def, mul_smul]
end
noncomputable instance fractional_ideal_has_div :
has_div (fractional_ideal R₁⁰ K) :=
⟨ λ I J, if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩ ⟩
variables {I J : fractional_ideal R₁⁰ K} [ J ≠ 0 ]
@[simp] lemma div_zero {I : fractional_ideal R₁⁰ K} :
I / 0 = 0 :=
dif_pos rfl
lemma div_nonzero {I J : fractional_ideal R₁⁰ K} (h : J ≠ 0) :
(I / J) = ⟨I / J, fractional_div_of_nonzero h⟩ :=
dif_neg h
@[simp] lemma coe_div {I J : fractional_ideal R₁⁰ K} (hJ : J ≠ 0) :
(↑(I / J) : submodule R₁ K) = ↑I / (↑J : submodule R₁ K) :=
begin
unfold has_div.div,
simp only [dif_neg hJ, coe_mk, val_eq_coe],
end
lemma mem_div_iff_of_nonzero {I J : fractional_ideal R₁⁰ K} (h : J ≠ 0) {x} :
x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I :=
by { rw div_nonzero h, exact submodule.mem_div_iff_forall_mul_mem }
lemma mul_one_div_le_one {I : fractional_ideal R₁⁰ K} : I * (1 / I) ≤ 1 :=
begin
by_cases hI : I = 0,
{ rw [hI, div_zero, mul_zero],
exact zero_le 1 },
{ rw [← coe_le_coe, coe_mul, coe_div hI, coe_one],
apply submodule.mul_one_div_le_one },
end
lemma le_self_mul_one_div {I : fractional_ideal R₁⁰ K} (hI : I ≤ (1 : fractional_ideal R₁⁰ K)) :
I ≤ I * (1 / I) :=
begin
by_cases hI_nz : I = 0,
{ rw [hI_nz, div_zero, mul_zero], exact zero_le 0 },
{ rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one],
rw [← coe_le_coe, coe_one] at hI,
exact submodule.le_self_mul_one_div hI },
end
lemma le_div_iff_of_nonzero {I J J' : fractional_ideal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ ∀ (x ∈ I) (y ∈ J'), x * y ∈ J :=
⟨ λ h x hx, (mem_div_iff_of_nonzero hJ').mp (h hx),
λ h x hx, (mem_div_iff_of_nonzero hJ').mpr (h x hx) ⟩
lemma le_div_iff_mul_le {I J J' : fractional_ideal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ I * J' ≤ J :=
begin
rw div_nonzero hJ',
convert submodule.le_div_iff_mul_le using 1,
rw [← coe_mul, coe_le_coe]
end
@[simp] lemma div_one {I : fractional_ideal R₁⁰ K} : I / 1 = I :=
begin
rw [div_nonzero (@one_ne_zero (fractional_ideal R₁⁰ K) _ _)],
ext,
split; intro h,
{ simpa using mem_div_iff_forall_mul_mem.mp h 1
((algebra_map R₁ K).map_one ▸ coe_mem_one R₁⁰ 1) },
{ apply mem_div_iff_forall_mul_mem.mpr,
rintros y ⟨y', _, rfl⟩,
rw mul_comm,
convert submodule.smul_mem _ y' h,
exact (algebra.smul_def _ _).symm }
end
theorem eq_one_div_of_mul_eq_one (I J : fractional_ideal R₁⁰ K) (h : I * J = 1) :
J = 1 / I :=
begin
have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h,
suffices h' : I * (1 / I) = 1,
{ exact (congr_arg units.inv $
@units.ext _ _ (units.mk_of_mul_eq_one _ _ h) (units.mk_of_mul_eq_one _ _ h') rfl) },
apply le_antisymm,
{ apply mul_le.mpr _,
intros x hx y hy,
rw mul_comm,
exact (mem_div_iff_of_nonzero hI).mp hy x hx },
rw ← h,
apply mul_left_mono I,
apply (le_div_iff_of_nonzero hI).mpr _,
intros y hy x hx,
rw mul_comm,
exact mul_mem_mul hx hy,
end
theorem mul_div_self_cancel_iff {I : fractional_ideal R₁⁰ K} :
I * (1 / I) = 1 ↔ ∃ J, I * J = 1 :=
⟨λ h, ⟨(1 / I), h⟩, λ ⟨J, hJ⟩, by rwa [← eq_one_div_of_mul_eq_one I J hJ]⟩
variables {K' : Type*} [field K'] [algebra R₁ K'] [is_fraction_ring R₁ K']
@[simp] lemma map_div (I J : fractional_ideal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h :=
begin
by_cases H : J = 0,
{ rw [H, div_zero, map_zero, div_zero] },
{ apply coe_to_submodule_injective,
simp [div_nonzero H, div_nonzero (map_ne_zero _ H), submodule.map_div] }
end
@[simp] lemma map_one_div (I : fractional_ideal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h :=
by rw [map_div, map_one]
end quotient
section field
variables {R₁ K L : Type*} [comm_ring R₁] [integral_domain R₁] [field K] [field L]
variables [algebra R₁ K] [is_fraction_ring R₁ K] [algebra K L] [is_fraction_ring K L]
lemma eq_zero_or_one (I : fractional_ideal K⁰ L) : I = 0 ∨ I = 1 :=
begin
rw or_iff_not_imp_left,
intro hI,
simp_rw [@set_like.ext_iff _ _ _ I 1, fractional_ideal.mem_one_iff],
intro x,
split,
{ intro x_mem,
obtain ⟨n, d, rfl⟩ := is_localization.mk'_surjective K⁰ x,
refine ⟨n / d, _⟩,
rw [ring_hom.map_div, is_fraction_ring.mk'_eq_div] },
{ rintro ⟨x, rfl⟩,
obtain ⟨y, y_ne, y_mem⟩ := fractional_ideal.exists_ne_zero_mem_is_integer hI,
rw [← div_mul_cancel x y_ne, ring_hom.map_mul, ← algebra.smul_def],
exact submodule.smul_mem I _ y_mem }
end
lemma eq_zero_or_one_of_is_field (hF : is_field R₁) (I : fractional_ideal R₁⁰ K) : I = 0 ∨ I = 1 :=
begin
letI : field R₁ := hF.to_field R₁,
-- TODO can this be less ugly?
exact @eq_zero_or_one R₁ K _ _ _ (by { unfreezingI {cases _inst_4}, convert _inst_9 }) I
end
end field
section principal_ideal_ring
variables {R₁ : Type*} [comm_ring R₁] {K : Type*} [field K]
variables [algebra R₁ K] [is_fraction_ring R₁ K]
open_locale classical
open submodule submodule.is_principal
include loc
lemma is_fractional_span_singleton (x : P) : is_fractional S (span R {x} : submodule R P) :=
let ⟨a, ha⟩ := exists_integer_multiple S x in
is_fractional_span_iff.mpr ⟨a, a.2, λ x' hx', (set.mem_singleton_iff.mp hx').symm ▸ ha⟩
variables (S)
/-- `span_singleton x` is the fractional ideal generated by `x` if `0 ∉ S` -/
@[irreducible]
def span_singleton (x : P) : fractional_ideal S P :=
⟨span R {x}, is_fractional_span_singleton x⟩
local attribute [semireducible] span_singleton
@[simp] lemma coe_span_singleton (x : P) :
(span_singleton S x : submodule R P) = span R {x} := rfl
@[simp] lemma mem_span_singleton {x y : P} :
x ∈ span_singleton S y ↔ ∃ (z : R), z • y = x :=
submodule.mem_span_singleton
lemma mem_span_singleton_self (x : P) :
x ∈ span_singleton S x :=
(mem_span_singleton S).mpr ⟨1, one_smul _ _⟩
variables {S}
lemma eq_span_singleton_of_principal (I : fractional_ideal S P)
[is_principal (I : submodule R P)] :
I = span_singleton S (generator (I : submodule R P)) :=
coe_to_submodule_injective (span_singleton_generator ↑I).symm
lemma is_principal_iff (I : fractional_ideal S P) :
is_principal (I : submodule R P) ↔ ∃ x, I = span_singleton S x :=
⟨λ h, ⟨@generator _ _ _ _ _ ↑I h, @eq_span_singleton_of_principal _ _ _ _ _ _ _ I h⟩,
λ ⟨x, hx⟩, { principal := ⟨x, trans (congr_arg _ hx) (coe_span_singleton _ x)⟩ } ⟩
@[simp] lemma span_singleton_zero : span_singleton S (0 : P) = 0 :=
by { ext, simp [submodule.mem_span_singleton, eq_comm] }
lemma span_singleton_eq_zero_iff {y : P} : span_singleton S y = 0 ↔ y = 0 :=
⟨λ h, span_eq_bot.mp (by simpa using congr_arg subtype.val h : span R {y} = ⊥) y (mem_singleton y),
λ h, by simp [h] ⟩
lemma span_singleton_ne_zero_iff {y : P} : span_singleton S y ≠ 0 ↔ y ≠ 0 :=
not_congr span_singleton_eq_zero_iff
@[simp] lemma span_singleton_one : span_singleton S (1 : P) = 1 :=
begin
ext,
refine (mem_span_singleton S).trans ((exists_congr _).trans (mem_one_iff S).symm),
intro x',
rw [algebra.smul_def, mul_one]
end
@[simp]
lemma span_singleton_mul_span_singleton (x y : P) :
span_singleton S x * span_singleton S y = span_singleton S (x * y) :=
begin
apply coe_to_submodule_injective,
simp only [coe_mul, coe_span_singleton, span_mul_span, singleton_mul_singleton],
end
@[simp]
lemma coe_ideal_span_singleton (x : R) :
(↑(ideal.span {x} : ideal R) : fractional_ideal S P) = span_singleton S (algebra_map R P x) :=
begin
ext y,
refine (mem_coe_ideal S).trans (iff.trans _ (mem_span_singleton S).symm),
split,
{ rintros ⟨y', hy', rfl⟩,
obtain ⟨x', rfl⟩ := submodule.mem_span_singleton.mp hy',
use x',
rw [smul_eq_mul, ring_hom.map_mul, algebra.smul_def] },
{ rintros ⟨y', rfl⟩,
refine ⟨y' * x, submodule.mem_span_singleton.mpr ⟨y', rfl⟩, _⟩,
rw [ring_hom.map_mul, algebra.smul_def] }
end
@[simp]
lemma canonical_equiv_span_singleton {P'} [comm_ring P'] [algebra R P'] [is_localization S P']
(x : P) :
canonical_equiv S P P' (span_singleton S x) =
span_singleton S (is_localization.map P' (ring_hom.id R)
(λ y (hy : y ∈ S), show ring_hom.id R y ∈ S, from hy) x) :=
begin
apply set_like.ext_iff.mpr,
intro y,
split; intro h,
{ rw mem_span_singleton,
obtain ⟨x', hx', rfl⟩ := (mem_canonical_equiv_apply _ _ _).mp h,
obtain ⟨z, rfl⟩ := (mem_span_singleton _).mp hx',
use z,
rw is_localization.map_smul,
refl },
{ rw mem_canonical_equiv_apply,
obtain ⟨z, rfl⟩ := (mem_span_singleton _).mp h,
use z • x,
use (mem_span_singleton _).mpr ⟨z, rfl⟩,
simp [is_localization.map_smul] }
end
lemma mem_singleton_mul {x y : P} {I : fractional_ideal S P} :
y ∈ span_singleton S x * I ↔ ∃ y' ∈ I, y = x * y' :=
begin
split,
{ intro h,
apply fractional_ideal.mul_induction_on h,
{ intros x' hx' y' hy',
obtain ⟨a, ha⟩ := (mem_span_singleton S).mp hx',
use [a • y', submodule.smul_mem I a hy'],
rw [←ha, algebra.mul_smul_comm, algebra.smul_mul_assoc] },
{ exact ⟨0, submodule.zero_mem I, (mul_zero x).symm⟩ },
{ rintros _ _ ⟨y, hy, rfl⟩ ⟨y', hy', rfl⟩,
exact ⟨y + y', submodule.add_mem I hy hy', (mul_add _ _ _).symm⟩ },
{ rintros r _ ⟨y', hy', rfl⟩,
exact ⟨r • y', submodule.smul_mem I r hy', (algebra.mul_smul_comm _ _ _).symm ⟩ } },
{ rintros ⟨y', hy', rfl⟩,
exact mul_mem_mul ((mem_span_singleton S).mpr ⟨1, one_smul _ _⟩) hy' }
end
omit loc
variables (K)
lemma mk'_mul_coe_ideal_eq_coe_ideal {I J : ideal R₁} {x y : R₁} (hy : y ∈ R₁⁰) :
span_singleton R₁⁰ (is_localization.mk' K x ⟨y, hy⟩) * I = (J : fractional_ideal R₁⁰ K) ↔
ideal.span {x} * I = ideal.span {y} * J :=
begin
have inj : function.injective (coe : ideal R₁ → fractional_ideal R₁⁰ K) :=
fractional_ideal.coe_ideal_injective,
have : span_singleton R₁⁰ (is_localization.mk' _ 1 ⟨y, hy⟩) *
span_singleton R₁⁰ (algebra_map R₁ K y) = 1,
{ rw [span_singleton_mul_span_singleton, mul_comm, ← is_localization.mk'_eq_mul_mk'_one,
is_localization.mk'_self, span_singleton_one] },
let y' : units (fractional_ideal R₁⁰ K) := units.mk_of_mul_eq_one _ _ this,
have coe_y' : ↑y' = span_singleton R₁⁰ (is_localization.mk' K 1 ⟨y, hy⟩) := rfl,
refine iff.trans _ (y'.mul_right_inj.trans inj.eq_iff),
rw [coe_y', coe_ideal_mul, coe_ideal_span_singleton, coe_ideal_mul, coe_ideal_span_singleton,
←mul_assoc, span_singleton_mul_span_singleton, ←mul_assoc, span_singleton_mul_span_singleton,
mul_comm (mk' _ _ _), ← is_localization.mk'_eq_mul_mk'_one,
mul_comm (mk' _ _ _), ← is_localization.mk'_eq_mul_mk'_one,
is_localization.mk'_self, span_singleton_one, one_mul],
end
variables {K}
lemma span_singleton_mul_coe_ideal_eq_coe_ideal {I J : ideal R₁} {z : K} :
span_singleton R₁⁰ z * (I : fractional_ideal R₁⁰ K) = J ↔
ideal.span {((is_localization.sec R₁⁰ z).1 : R₁)} * I =
ideal.span {(is_localization.sec R₁⁰ z).2} * J :=
-- `erw` to deal with the distinction between `y` and `⟨y.1, y.2⟩`
by erw [← mk'_mul_coe_ideal_eq_coe_ideal K (is_localization.sec R₁⁰ z).2.prop,
is_localization.mk'_sec K z]
variables [integral_domain R₁]
lemma one_div_span_singleton (x : K) :
1 / span_singleton R₁⁰ x = span_singleton R₁⁰ (x⁻¹) :=
if h : x = 0 then by simp [h] else (eq_one_div_of_mul_eq_one _ _ (by simp [h])).symm
@[simp] lemma div_span_singleton (J : fractional_ideal R₁⁰ K) (d : K) :
J / span_singleton R₁⁰ d = span_singleton R₁⁰ (d⁻¹) * J :=
begin
rw ← one_div_span_singleton,
by_cases hd : d = 0,
{ simp only [hd, span_singleton_zero, div_zero, zero_mul] },
have h_spand : span_singleton R₁⁰ d ≠ 0 := mt span_singleton_eq_zero_iff.mp hd,
apply le_antisymm,
{ intros x hx,
rw [← mem_coe, coe_div h_spand, submodule.mem_div_iff_forall_mul_mem] at hx,
specialize hx d (mem_span_singleton_self R₁⁰ d),
have h_xd : x = d⁻¹ * (x * d), { field_simp },
rw [← mem_coe, coe_mul, one_div_span_singleton, h_xd],
exact submodule.mul_mem_mul (mem_span_singleton_self R₁⁰ _) hx },
{ rw [le_div_iff_mul_le h_spand, mul_assoc, mul_left_comm, one_div_span_singleton,
span_singleton_mul_span_singleton, inv_mul_cancel hd, span_singleton_one, mul_one],
exact le_refl J },
end
lemma exists_eq_span_singleton_mul (I : fractional_ideal R₁⁰ K) :
∃ (a : R₁) (aI : ideal R₁), a ≠ 0 ∧ I = span_singleton R₁⁰ (algebra_map R₁ K a)⁻¹ * aI :=
begin
obtain ⟨a_inv, nonzero, ha⟩ := I.is_fractional,
have nonzero := mem_non_zero_divisors_iff_ne_zero.mp nonzero,
have map_a_nonzero : algebra_map R₁ K a_inv ≠ 0 :=
mt is_fraction_ring.to_map_eq_zero_iff.mp nonzero,
refine ⟨a_inv,
submodule.comap (algebra.linear_map R₁ K)
↑(span_singleton R₁⁰ (algebra_map R₁ K a_inv) * I),
nonzero,
ext (λ x, iff.trans ⟨_, _⟩ mem_singleton_mul.symm)⟩,
{ intro hx,
obtain ⟨x', hx'⟩ := ha x hx,
rw algebra.smul_def at hx',
refine ⟨algebra_map R₁ K x', (mem_coe_ideal _).mpr ⟨x', mem_singleton_mul.mpr _, rfl⟩, _⟩,
{ exact ⟨x, hx, hx'⟩ },
{ rw [hx', ← mul_assoc, inv_mul_cancel map_a_nonzero, one_mul] } },
{ rintros ⟨y, hy, rfl⟩,
obtain ⟨x', hx', rfl⟩ := (mem_coe_ideal _).mp hy,
obtain ⟨y', hy', hx'⟩ := mem_singleton_mul.mp hx',
rw algebra.linear_map_apply at hx',
rwa [hx', ←mul_assoc, inv_mul_cancel map_a_nonzero, one_mul] }
end
instance is_principal {R} [comm_ring R] [integral_domain R] [is_principal_ideal_ring R]
[algebra R K] [is_fraction_ring R K]
(I : fractional_ideal R⁰ K) : (I : submodule R K).is_principal :=
begin
obtain ⟨a, aI, -, ha⟩ := exists_eq_span_singleton_mul I,
use (algebra_map R K a)⁻¹ * algebra_map R K (generator aI),
suffices : I = span_singleton R⁰ ((algebra_map R K a)⁻¹ * algebra_map R K (generator aI)),
{ exact congr_arg subtype.val this },
conv_lhs { rw [ha, ←span_singleton_generator aI] },
rw [ideal.submodule_span_eq, coe_ideal_span_singleton (generator aI),
span_singleton_mul_span_singleton]
end
include loc
lemma le_span_singleton_mul_iff {x : P} {I J : fractional_ideal S P} :
I ≤ span_singleton S x * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI :=
show (∀ {zI} (hzI : zI ∈ I), zI ∈ span_singleton _ x * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI,
by simp only [fractional_ideal.mem_singleton_mul, eq_comm]
lemma span_singleton_mul_le_iff {x : P} {I J : fractional_ideal S P} :
span_singleton _ x * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J :=
begin
simp only [fractional_ideal.mul_le, fractional_ideal.mem_singleton_mul,
fractional_ideal.mem_span_singleton],
split,
{ intros h zI hzI,
exact h x ⟨1, one_smul _ _⟩ zI hzI },
{ rintros h _ ⟨z, rfl⟩ zI hzI,
rw [algebra.smul_mul_assoc],
exact submodule.smul_mem J.1 _ (h zI hzI) },
end
lemma eq_span_singleton_mul {x : P} {I J : fractional_ideal S P} :
I = span_singleton _ x * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I :=
by simp only [le_antisymm_iff, fractional_ideal.le_span_singleton_mul_iff,
fractional_ideal.span_singleton_mul_le_iff]
end principal_ideal_ring
variables {R₁ : Type*} [comm_ring R₁]
variables {K : Type*} [field K] [algebra R₁ K] [frac : is_fraction_ring R₁ K]
local attribute [instance] classical.prop_decidable
lemma is_noetherian_zero : is_noetherian R₁ (0 : fractional_ideal R₁⁰ K) :=
is_noetherian_submodule.mpr (λ I (hI : I ≤ (0 : fractional_ideal R₁⁰ K)),
by { rw coe_zero at hI, rw le_bot_iff.mp hI, exact fg_bot })
lemma is_noetherian_iff {I : fractional_ideal R₁⁰ K} :
is_noetherian R₁ I ↔ ∀ J ≤ I, (J : submodule R₁ K).fg :=
is_noetherian_submodule.trans ⟨λ h J hJ, h _ hJ, λ h J hJ, h ⟨J, is_fractional_of_le hJ⟩ hJ⟩
lemma is_noetherian_coe_to_fractional_ideal [_root_.is_noetherian_ring R₁] (I : ideal R₁) :
is_noetherian R₁ (I : fractional_ideal R₁⁰ K) :=
begin
rw is_noetherian_iff,
intros J hJ,
obtain ⟨J, rfl⟩ := le_one_iff_exists_coe_ideal.mp (le_trans hJ coe_ideal_le_one),
exact fg_map (is_noetherian.noetherian J),
end
include frac
variables [integral_domain R₁]
lemma is_noetherian_span_singleton_inv_to_map_mul (x : R₁) {I : fractional_ideal R₁⁰ K}
(hI : is_noetherian R₁ I) :
is_noetherian R₁ (span_singleton R₁⁰ (algebra_map R₁ K x)⁻¹ * I : fractional_ideal R₁⁰ K) :=
begin
by_cases hx : x = 0,
{ rw [hx, ring_hom.map_zero, _root_.inv_zero, span_singleton_zero, zero_mul],
exact is_noetherian_zero },
have h_gx : algebra_map R₁ K x ≠ 0,
from mt ((algebra_map R₁ K).injective_iff.mp (is_fraction_ring.injective _ _) x) hx,
have h_spanx : span_singleton R₁⁰ (algebra_map R₁ K x) ≠ 0,
from span_singleton_ne_zero_iff.mpr h_gx,
rw is_noetherian_iff at ⊢ hI,
intros J hJ,
rw [← div_span_singleton, le_div_iff_mul_le h_spanx] at hJ,
obtain ⟨s, hs⟩ := hI _ hJ,
use s * {(algebra_map R₁ K x)⁻¹},
rw [finset.coe_mul, finset.coe_singleton, ← span_mul_span, hs, ← coe_span_singleton R₁⁰,
← coe_mul, mul_assoc, span_singleton_mul_span_singleton, mul_inv_cancel h_gx,
span_singleton_one, mul_one],
end
/-- Every fractional ideal of a noetherian integral domain is noetherian. -/
theorem is_noetherian [_root_.is_noetherian_ring R₁] (I : fractional_ideal R₁⁰ K) :
is_noetherian R₁ I :=
begin
obtain ⟨d, J, h_nzd, rfl⟩ := exists_eq_span_singleton_mul I,
apply is_noetherian_span_singleton_inv_to_map_mul,
apply is_noetherian_coe_to_fractional_ideal,
end
section adjoin
include loc
omit frac
variables {R P} (S) (x : P) (hx : is_integral R x)
/-- `A[x]` is a fractional ideal for every integral `x`. -/
lemma is_fractional_adjoin_integral :
is_fractional S (algebra.adjoin R ({x} : set P)).to_submodule :=
is_fractional_of_fg (fg_adjoin_singleton_of_integral x hx)
/-- `fractional_ideal.adjoin_integral (S : submonoid R) x hx` is `R[x]` as a fractional ideal,
where `hx` is a proof that `x : P` is integral over `R`. -/
@[simps]
def adjoin_integral : fractional_ideal S P :=
⟨_, is_fractional_adjoin_integral S x hx⟩
lemma mem_adjoin_integral_self :
x ∈ adjoin_integral S x hx :=
algebra.subset_adjoin (set.mem_singleton x)
end adjoin
end fractional_ideal
|
b8809a9e4b72e6231eb28d69e9701bf1846384c2
|
37a833c924892ee3ecb911484775a6d6ebb8984d
|
/src/category_theory/examples/groups/default.lean
|
48171e84f2a51c1b041a829b761de32d58d6d2e7
|
[] |
no_license
|
silky/lean-category-theory
|
28126e80564a1f99e9c322d86b3f7d750da0afa1
|
0f029a2364975f56ac727d31d867a18c95c22fd8
|
refs/heads/master
| 1,589,555,811,646
| 1,554,673,665,000
| 1,554,673,665,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,511
|
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.functor
import category_theory.tactics.obviously
open category_theory
namespace category_theory.examples.groups
universe u₁
def Group : Type (u₁+1) := Σ α : Type u₁, group α
instance group_from_Group (G : Group) : group G.1 := G.2
structure GroupHomomorphism (G H : Group.{u₁}) : Type u₁ :=
(map: G.1 → H.1)
(is_group_hom : is_group_hom map . obviously)
instance (G H : Group.{u₁}) (f : GroupHomomorphism G H) : is_group_hom f.map := f.is_group_hom
@[simp,search] lemma GroupHomomorphism.is_group_hom_lemma (G H : Group) (f : GroupHomomorphism G H) (x y : G.1) : f.map(x * y) = f.map(x) * f.map(y) := by rw f.is_group_hom.mul
def GroupHomomorphism.identity (G : Group) : GroupHomomorphism G G :=
{ map := id }
def GroupHomomorphism.composition {G H K : Group} (f: GroupHomomorphism G H) (g: GroupHomomorphism H K) : GroupHomomorphism G K :=
{ map := λ x, g.map (f.map x) }
@[extensionality] lemma GroupHomomorphism_pointwise_equality {G H : Group} (f g : GroupHomomorphism G H) (w : ∀ x : G.1, f.map x = g.map x) : f = g :=
begin
induction f with fc,
induction g with gc,
tidy,
end
instance CategoryOfGroups : large_category Group :=
{ hom := GroupHomomorphism,
id := GroupHomomorphism.identity,
comp := @GroupHomomorphism.composition }
end category_theory.examples.groups
|
8c03954f9b862f704288c2a344c3f4ddd7386823
|
9338c56dfd6ceacc3e5e63e32a7918cfec5d5c69
|
/src/Kenny/sites/lattice.lean
|
667023a3564853b844f32ee46adae9451c0aa7e6
|
[] |
no_license
|
Project-Reykjavik/lean-scheme
|
7322eefce504898ba33737970be89dc751108e2b
|
6d3ec18fecfd174b79d0ce5c85a783f326dd50f6
|
refs/heads/master
| 1,669,426,172,632
| 1,578,284,588,000
| 1,578,284,588,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,638
|
lean
|
import Kenny.sites.basic order.complete_boolean_algebra
universes u v
namespace lattice
class Sup_lattice (X : Type u) extends lattice X, has_Sup X :=
(le_Sup : ∀ {s : set X} {a : X}, a ∈ s → a ≤ Sup s)
(Sup_le : ∀ {s : set X} {a : X}, (∀ (b : X), b ∈ s → b ≤ a) → Sup s ≤ a)
class Sup_distrib_lattice (X : Type u) extends Sup_lattice X :=
(inf_Sup_le {} : ∀ {x : X} {s : set X}, x ⊓ lattice.Sup s ≤ lattice.Sup ((⊓) x '' s))
section Sup_lattice
instance complete_lattice.to_Sup_lattice {X : Type u} [complete_lattice X] : Sup_lattice X :=
{ .. (infer_instance : complete_lattice X) }
variables {X : Type u} [Sup_lattice X]
theorem le_Sup' {s : set X} {a : X} : a ∈ s → a ≤ Sup s :=
Sup_lattice.le_Sup
theorem Sup_le' {s : set X} {a : X} : (∀ (b : X), b ∈ s → b ≤ a) → Sup s ≤ a :=
Sup_lattice.Sup_le
theorem Sup_singleton' (x : X) : Sup {x} = x :=
le_antisymm (Sup_le' $ λ b hb, set.eq_of_mem_singleton hb ▸ le_refl _) $
le_Sup' $ set.mem_singleton x
end Sup_lattice
section Sup_discrete_lattice
instance complete_distrib_lattice.to_Sup_distrib_lattice {X : Type u} [complete_distrib_lattice X] : Sup_distrib_lattice X :=
{ inf_Sup_le := λ x s, by rw [inf_Sup_eq, Sup_image],
.. (infer_instance : complete_distrib_lattice X) }
variables {X : Type u} [Sup_distrib_lattice X]
theorem inf_Sup {x : X} {s : set X} : x ⊓ lattice.Sup s = lattice.Sup ((⊓) x '' s) :=
le_antisymm Sup_distrib_lattice.inf_Sup_le $ Sup_le' $ λ b ⟨c, hcs, hxcb⟩, hxcb ▸ inf_le_inf (le_refl x) (le_Sup' hcs)
end Sup_discrete_lattice
end lattice
namespace category_theory
open lattice
variables {X : Type u}
class is_univalent (X : Type u) [category.{v} X] : Prop :=
(univalent : ∀ x y : X, ∀ e : x ≅ y, x = y)
theorem eq_of_iso [category.{v} X] [is_univalent X] {x y : X} (e : x ≅ y) : x = y :=
is_univalent.univalent x y e
instance is_univalent_partial_order [partial_order X] : is_univalent X :=
⟨λ x y e, le_antisymm e.1.1.1 e.2.1.1⟩
instance semilattice_inf.has_pullback [semilattice_inf X] : has_pullback X :=
⟨λ F,
{ cone :=
{ X := F.obj pullback_diagram.base_left ⊓ F.obj pullback_diagram.base_right,
π :=
{ app := λ p, pullback_diagram.rec_on p ⟨⟨inf_le_left⟩⟩ ⟨⟨inf_le_right⟩⟩
⟨⟨le_trans inf_le_left (F.map pullback_diagram.hom.to_target_left).down.down⟩⟩,
naturality' := by intros; ext } },
is_limit :=
{ lift := λ c, ⟨⟨le_inf (c.π.app pullback_diagram.base_left).down.down (c.π.app pullback_diagram.base_right).down.down⟩⟩,
fac' := by intros; ext,
uniq' := by intros; ext } }⟩
instance Sup_lattice.has_site [Sup_distrib_lattice X] : has_site X :=
{ cov := λ U, { c | U ≤ Sup (sigma.fst '' c) },
iso_mem := λ U V e, show U ≤ _, by rw [set.image_singleton, Sup_singleton']; exact e.2.1.1,
comp_mem := λ U S HS F HF, le_trans HS $ Sup_le' $ λ x hx, let ⟨m, hmS, hmx⟩ := hx in
hmx ▸ le_trans (HF m hmS) (Sup_le' $ λ y hy, let ⟨n, hnFS, hny⟩ := hy in
le_Sup' ⟨⟨n.1, ⟨⟨le_trans n.2.1.1 m.2.1.1⟩⟩⟩, ⟨m, hmS, n, hnFS, rfl⟩, hny⟩),
pullback_mem := λ U S HS V f,
calc V
≤ V ⊓ Sup (sigma.fst '' S) : le_inf (le_refl V) (le_trans f.1.1 HS)
... = Sup ((⊓) V '' (sigma.fst '' S)) : inf_Sup
... = Sup ((⊓) V ∘ sigma.fst '' S) : congr_arg Sup (set.image_comp _ _ S).symm
... ≤ Sup (sigma.fst '' {m | ∃ t ∈ S, (⟨_, pullback.fst f t.2⟩ : Σ W, W ⟶ V) = m}) :
Sup_le' (λ b ⟨c, hcs, hb⟩, le_Sup' ⟨⟨V ⊓ c.1, ⟨⟨inf_le_left⟩⟩⟩, ⟨c, hcs, rfl⟩, hb⟩) }
end category_theory
|
0f5c36a2a84855b1f0183b0a67d24388aedf2b2f
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/zsqrtd/basic.lean
|
b120cc4079d915976fce0c146df3b7cf416632cd
|
[] |
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
| 20,566
|
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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.associated
import Mathlib.tactic.ring
import Mathlib.PostPort
universes l
namespace Mathlib
/-- The ring of integers adjoined with a square root of `d`.
These have the form `a + b √d` where `a b : ℤ`. The components
are called `re` and `im` by analogy to the negative `d` case,
but of course both parts are real here since `d` is nonnegative. -/
structure zsqrtd (d : ℤ)
where
re : ℤ
im : ℤ
prefix:100 "ℤ√" => Mathlib.zsqrtd
namespace zsqrtd
protected instance decidable_eq {d : ℤ} : DecidableEq (ℤ√d) :=
id
fun (_v : ℤ√d) =>
cases_on _v
fun (re im : ℤ) (w : ℤ√d) =>
cases_on w
fun (w_re w_im : ℤ) =>
decidable.by_cases
(fun (ᾰ : re = w_re) =>
Eq._oldrec
(decidable.by_cases (fun (ᾰ : im = w_im) => Eq._oldrec (is_true sorry) ᾰ)
fun (ᾰ : ¬im = w_im) => isFalse sorry)
ᾰ)
fun (ᾰ : ¬re = w_re) => isFalse sorry
theorem ext {d : ℤ} {z : ℤ√d} {w : ℤ√d} : z = w ↔ re z = re w ∧ im z = im w := sorry
/-- Convert an integer to a `ℤ√d` -/
def of_int {d : ℤ} (n : ℤ) : ℤ√d :=
mk n 0
theorem of_int_re {d : ℤ} (n : ℤ) : re (of_int n) = n :=
rfl
theorem of_int_im {d : ℤ} (n : ℤ) : im (of_int n) = 0 :=
rfl
/-- The zero of the ring -/
def zero {d : ℤ} : ℤ√d :=
of_int 0
protected instance has_zero {d : ℤ} : HasZero (ℤ√d) :=
{ zero := zero }
@[simp] theorem zero_re {d : ℤ} : re 0 = 0 :=
rfl
@[simp] theorem zero_im {d : ℤ} : im 0 = 0 :=
rfl
protected instance inhabited {d : ℤ} : Inhabited (ℤ√d) :=
{ default := 0 }
/-- The one of the ring -/
def one {d : ℤ} : ℤ√d :=
of_int 1
protected instance has_one {d : ℤ} : HasOne (ℤ√d) :=
{ one := one }
@[simp] theorem one_re {d : ℤ} : re 1 = 1 :=
rfl
@[simp] theorem one_im {d : ℤ} : im 1 = 0 :=
rfl
/-- The representative of `√d` in the ring -/
def sqrtd {d : ℤ} : ℤ√d :=
mk 0 1
@[simp] theorem sqrtd_re {d : ℤ} : re sqrtd = 0 :=
rfl
@[simp] theorem sqrtd_im {d : ℤ} : im sqrtd = 1 :=
rfl
/-- Addition of elements of `ℤ√d` -/
def add {d : ℤ} : ℤ√d → ℤ√d → ℤ√d :=
sorry
protected instance has_add {d : ℤ} : Add (ℤ√d) :=
{ add := add }
@[simp] theorem add_def {d : ℤ} (x : ℤ) (y : ℤ) (x' : ℤ) (y' : ℤ) : mk x y + mk x' y' = mk (x + x') (y + y') :=
rfl
@[simp] theorem add_re {d : ℤ} (z : ℤ√d) (w : ℤ√d) : re (z + w) = re z + re w :=
cases_on z
fun (z_re z_im : ℤ) =>
cases_on w fun (w_re w_im : ℤ) => idRhs (re (mk z_re z_im + mk w_re w_im) = re (mk z_re z_im + mk w_re w_im)) rfl
@[simp] theorem add_im {d : ℤ} (z : ℤ√d) (w : ℤ√d) : im (z + w) = im z + im w :=
cases_on z
fun (z_re z_im : ℤ) =>
cases_on w fun (w_re w_im : ℤ) => idRhs (im (mk z_re z_im + mk w_re w_im) = im (mk z_re z_im + mk w_re w_im)) rfl
@[simp] theorem bit0_re {d : ℤ} (z : ℤ√d) : re (bit0 z) = bit0 (re z) :=
add_re z z
@[simp] theorem bit0_im {d : ℤ} (z : ℤ√d) : im (bit0 z) = bit0 (im z) :=
add_im z z
@[simp] theorem bit1_re {d : ℤ} (z : ℤ√d) : re (bit1 z) = bit1 (re z) := sorry
@[simp] theorem bit1_im {d : ℤ} (z : ℤ√d) : im (bit1 z) = bit0 (im z) := sorry
/-- Negation in `ℤ√d` -/
def neg {d : ℤ} : ℤ√d → ℤ√d :=
sorry
protected instance has_neg {d : ℤ} : Neg (ℤ√d) :=
{ neg := neg }
@[simp] theorem neg_re {d : ℤ} (z : ℤ√d) : re (-z) = -re z :=
cases_on z fun (z_re z_im : ℤ) => idRhs (re (-mk z_re z_im) = re (-mk z_re z_im)) rfl
@[simp] theorem neg_im {d : ℤ} (z : ℤ√d) : im (-z) = -im z :=
cases_on z fun (z_re z_im : ℤ) => idRhs (im (-mk z_re z_im) = im (-mk z_re z_im)) rfl
/-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/
def conj {d : ℤ} : ℤ√d → ℤ√d :=
sorry
@[simp] theorem conj_re {d : ℤ} (z : ℤ√d) : re (conj z) = re z :=
cases_on z fun (z_re z_im : ℤ) => idRhs (re (conj (mk z_re z_im)) = re (conj (mk z_re z_im))) rfl
@[simp] theorem conj_im {d : ℤ} (z : ℤ√d) : im (conj z) = -im z :=
cases_on z fun (z_re z_im : ℤ) => idRhs (im (conj (mk z_re z_im)) = im (conj (mk z_re z_im))) rfl
/-- Multiplication in `ℤ√d` -/
def mul {d : ℤ} : ℤ√d → ℤ√d → ℤ√d :=
sorry
protected instance has_mul {d : ℤ} : Mul (ℤ√d) :=
{ mul := mul }
@[simp] theorem mul_re {d : ℤ} (z : ℤ√d) (w : ℤ√d) : re (z * w) = re z * re w + d * im z * im w :=
cases_on z
fun (z_re z_im : ℤ) =>
cases_on w fun (w_re w_im : ℤ) => idRhs (re (mk z_re z_im * mk w_re w_im) = re (mk z_re z_im * mk w_re w_im)) rfl
@[simp] theorem mul_im {d : ℤ} (z : ℤ√d) (w : ℤ√d) : im (z * w) = re z * im w + im z * re w :=
cases_on z
fun (z_re z_im : ℤ) =>
cases_on w fun (w_re w_im : ℤ) => idRhs (im (mk z_re z_im * mk w_re w_im) = im (mk z_re z_im * mk w_re w_im)) rfl
protected instance comm_ring {d : ℤ} : comm_ring (ℤ√d) :=
comm_ring.mk Add.add sorry 0 sorry sorry Neg.neg (fun (a b : ℤ√d) => a + -b) sorry sorry Mul.mul sorry 1 sorry sorry
sorry sorry sorry
protected instance add_comm_monoid {d : ℤ} : add_comm_monoid (ℤ√d) :=
add_comm_group.to_add_comm_monoid (ℤ√d)
protected instance add_monoid {d : ℤ} : add_monoid (ℤ√d) :=
sub_neg_monoid.to_add_monoid (ℤ√d)
protected instance monoid {d : ℤ} : monoid (ℤ√d) :=
ring.to_monoid (ℤ√d)
protected instance comm_monoid {d : ℤ} : comm_monoid (ℤ√d) :=
comm_semiring.to_comm_monoid (ℤ√d)
protected instance comm_semigroup {d : ℤ} : comm_semigroup (ℤ√d) :=
comm_ring.to_comm_semigroup (ℤ√d)
protected instance semigroup {d : ℤ} : semigroup (ℤ√d) :=
monoid.to_semigroup (ℤ√d)
protected instance add_comm_semigroup {d : ℤ} : add_comm_semigroup (ℤ√d) :=
add_comm_monoid.to_add_comm_semigroup (ℤ√d)
protected instance add_semigroup {d : ℤ} : add_semigroup (ℤ√d) :=
add_monoid.to_add_semigroup (ℤ√d)
protected instance comm_semiring {d : ℤ} : comm_semiring (ℤ√d) :=
comm_ring.to_comm_semiring
protected instance semiring {d : ℤ} : semiring (ℤ√d) :=
ring.to_semiring
protected instance ring {d : ℤ} : ring (ℤ√d) :=
comm_ring.to_ring (ℤ√d)
protected instance distrib {d : ℤ} : distrib (ℤ√d) :=
ring.to_distrib (ℤ√d)
protected instance nontrivial {d : ℤ} : nontrivial (ℤ√d) :=
nontrivial.mk (Exists.intro 0 (Exists.intro 1 (of_as_true trivial)))
@[simp] theorem coe_nat_re {d : ℤ} (n : ℕ) : re ↑n = ↑n := sorry
@[simp] theorem coe_nat_im {d : ℤ} (n : ℕ) : im ↑n = 0 := sorry
theorem coe_nat_val {d : ℤ} (n : ℕ) : ↑n = mk (↑n) 0 := sorry
@[simp] theorem coe_int_re {d : ℤ} (n : ℤ) : re ↑n = n := sorry
@[simp] theorem coe_int_im {d : ℤ} (n : ℤ) : im ↑n = 0 := sorry
theorem coe_int_val {d : ℤ} (n : ℤ) : ↑n = mk n 0 := sorry
protected instance char_zero {d : ℤ} : char_zero (ℤ√d) := sorry
@[simp] theorem of_int_eq_coe {d : ℤ} (n : ℤ) : of_int n = ↑n := sorry
@[simp] theorem smul_val {d : ℤ} (n : ℤ) (x : ℤ) (y : ℤ) : ↑n * mk x y = mk (n * x) (n * y) := sorry
@[simp] theorem muld_val {d : ℤ} (x : ℤ) (y : ℤ) : sqrtd * mk x y = mk (d * y) x := sorry
@[simp] theorem dmuld {d : ℤ} : sqrtd * sqrtd = ↑d := sorry
@[simp] theorem smuld_val {d : ℤ} (n : ℤ) (x : ℤ) (y : ℤ) : sqrtd * ↑n * mk x y = mk (d * n * y) (n * x) := sorry
theorem decompose {d : ℤ} {x : ℤ} {y : ℤ} : mk x y = ↑x + sqrtd * ↑y := sorry
theorem mul_conj {d : ℤ} {x : ℤ} {y : ℤ} : mk x y * conj (mk x y) = ↑x * ↑x - ↑d * ↑y * ↑y := sorry
theorem conj_mul {d : ℤ} {a : ℤ√d} {b : ℤ√d} : conj (a * b) = conj a * conj b := sorry
protected theorem coe_int_add {d : ℤ} (m : ℤ) (n : ℤ) : ↑(m + n) = ↑m + ↑n :=
ring_hom.map_add (int.cast_ring_hom (ℤ√d)) m n
protected theorem coe_int_sub {d : ℤ} (m : ℤ) (n : ℤ) : ↑(m - n) = ↑m - ↑n :=
ring_hom.map_sub (int.cast_ring_hom (ℤ√d)) m n
protected theorem coe_int_mul {d : ℤ} (m : ℤ) (n : ℤ) : ↑(m * n) = ↑m * ↑n :=
ring_hom.map_mul (int.cast_ring_hom (ℤ√d)) m n
protected theorem coe_int_inj {d : ℤ} {m : ℤ} {n : ℤ} (h : ↑m = ↑n) : m = n := sorry
/-- Read `sq_le a c b d` as `a √c ≤ b √d` -/
def sq_le (a : ℕ) (c : ℕ) (b : ℕ) (d : ℕ) :=
c * a * a ≤ d * b * b
theorem sq_le_of_le {c : ℕ} {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : sq_le x c y d) : sq_le z c w d :=
le_trans (mul_le_mul (nat.mul_le_mul_left c xz) xz (nat.zero_le z) (nat.zero_le (c * x)))
(le_trans xy (mul_le_mul (nat.mul_le_mul_left d yw) yw (nat.zero_le y) (nat.zero_le (d * w))))
theorem sq_le_add_mixed {c : ℕ} {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} (xy : sq_le x c y d) (zw : sq_le z c w d) : c * (x * z) ≤ d * (y * w) := sorry
theorem sq_le_add {c : ℕ} {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} (xy : sq_le x c y d) (zw : sq_le z c w d) : sq_le (x + z) c (y + w) d := sorry
theorem sq_le_cancel {c : ℕ} {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} (zw : sq_le y d x c) (h : sq_le (x + z) c (y + w) d) : sq_le z c w d := sorry
theorem sq_le_smul {c : ℕ} {d : ℕ} {x : ℕ} {y : ℕ} (n : ℕ) (xy : sq_le x c y d) : sq_le (n * x) c (n * y) d := sorry
theorem sq_le_mul {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} : (sq_le x 1 y d → sq_le z 1 w d → sq_le (x * w + y * z) d (x * z + d * y * w) 1) ∧
(sq_le x 1 y d → sq_le w d z 1 → sq_le (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(sq_le y d x 1 → sq_le z 1 w d → sq_le (x * z + d * y * w) 1 (x * w + y * z) d) ∧
(sq_le y d x 1 → sq_le w d z 1 → sq_le (x * w + y * z) d (x * z + d * y * w) 1) := sorry
/-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d ≥ 0`;
we are interested in the case `c = 1` but this is more symmetric -/
def nonnegg (c : ℕ) (d : ℕ) : ℤ → ℤ → Prop :=
sorry
theorem nonnegg_comm {c : ℕ} {d : ℕ} {x : ℤ} {y : ℤ} : nonnegg c d x y = nonnegg d c y x := sorry
theorem nonnegg_neg_pos {c : ℕ} {d : ℕ} {a : ℕ} {b : ℕ} : nonnegg c d (-↑a) ↑b ↔ sq_le a d b c := sorry
theorem nonnegg_pos_neg {c : ℕ} {d : ℕ} {a : ℕ} {b : ℕ} : nonnegg c d (↑a) (-↑b) ↔ sq_le b c a d :=
eq.mpr (id (Eq._oldrec (Eq.refl (nonnegg c d (↑a) (-↑b) ↔ sq_le b c a d)) nonnegg_comm)) nonnegg_neg_pos
theorem nonnegg_cases_right {c : ℕ} {d : ℕ} {a : ℕ} {b : ℤ} : (∀ (x : ℕ), b = -↑x → sq_le x c a d) → nonnegg c d (↑a) b :=
fun (ᾰ : ∀ (x : ℕ), b = -↑x → sq_le x c a d) =>
int.cases_on b (fun (b : ℕ) (ᾰ : ∀ (x : ℕ), Int.ofNat b = -↑x → sq_le x c a d) => idRhs True trivial)
(fun (b : ℕ) (ᾰ : ∀ (x : ℕ), Int.negSucc b = -↑x → sq_le x c a d) => idRhs (sq_le (b + 1) c a d) (ᾰ (b + 1) rfl)) ᾰ
theorem nonnegg_cases_left {c : ℕ} {d : ℕ} {b : ℕ} {a : ℤ} (h : ∀ (x : ℕ), a = -↑x → sq_le x d b c) : nonnegg c d a ↑b :=
cast nonnegg_comm (nonnegg_cases_right h)
def norm {d : ℤ} (n : ℤ√d) : ℤ :=
re n * re n - d * im n * im n
@[simp] theorem norm_zero {d : ℤ} : norm 0 = 0 := sorry
@[simp] theorem norm_one {d : ℤ} : norm 1 = 1 := sorry
@[simp] theorem norm_int_cast {d : ℤ} (n : ℤ) : norm ↑n = n * n := sorry
@[simp] theorem norm_nat_cast {d : ℤ} (n : ℕ) : norm ↑n = ↑n * ↑n :=
norm_int_cast ↑n
@[simp] theorem norm_mul {d : ℤ} (n : ℤ√d) (m : ℤ√d) : norm (n * m) = norm n * norm m := sorry
theorem norm_eq_mul_conj {d : ℤ} (n : ℤ√d) : ↑(norm n) = n * conj n := sorry
protected instance norm.is_monoid_hom {d : ℤ} : is_monoid_hom norm :=
is_monoid_hom.mk norm_one
theorem norm_nonneg {d : ℤ} (hd : d ≤ 0) (n : ℤ√d) : 0 ≤ norm n := sorry
theorem norm_eq_one_iff {d : ℤ} {x : ℤ√d} : int.nat_abs (norm x) = 1 ↔ is_unit x := sorry
/-- Nonnegativity of an element of `ℤ√d`. -/
def nonneg {d : ℕ} : ℤ√↑d → Prop :=
sorry
protected def le {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) :=
nonneg (b - a)
protected instance has_le {d : ℕ} : HasLessEq (ℤ√↑d) :=
{ LessEq := zsqrtd.le }
protected def lt {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) :=
¬b ≤ a
protected instance has_lt {d : ℕ} : HasLess (ℤ√↑d) :=
{ Less := zsqrtd.lt }
protected instance decidable_nonnegg (c : ℕ) (d : ℕ) (a : ℤ) (b : ℤ) : Decidable (nonnegg c d a b) :=
int.cases_on a
(fun (a : ℕ) =>
int.cases_on b (fun (b : ℕ) => eq.mpr sorry (eq.mpr sorry (eq.mpr sorry decidable.true)))
fun (b : ℕ) => eq.mpr sorry (eq.mpr sorry (nat.decidable_le (c * (b + 1) * (b + 1)) (d * a * a))))
fun (a : ℕ) =>
int.cases_on b (fun (b : ℕ) => eq.mpr sorry (eq.mpr sorry (nat.decidable_le (d * (a + 1) * (a + 1)) (c * b * b))))
fun (b : ℕ) => eq.mpr sorry decidable.false
protected instance decidable_nonneg {d : ℕ} (a : ℤ√↑d) : Decidable (nonneg a) :=
sorry
protected instance decidable_le {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) : Decidable (a ≤ b) :=
zsqrtd.decidable_nonneg (b - a)
theorem nonneg_cases {d : ℕ} {a : ℤ√↑d} : nonneg a → ∃ (x : ℕ), ∃ (y : ℕ), a = mk ↑x ↑y ∨ a = mk (↑x) (-↑y) ∨ a = mk (-↑x) ↑y := sorry
theorem nonneg_add_lem {d : ℕ} {x : ℕ} {y : ℕ} {z : ℕ} {w : ℕ} (xy : nonneg (mk (↑x) (-↑y))) (zw : nonneg (mk (-↑z) ↑w)) : nonneg (mk (↑x) (-↑y) + mk (-↑z) ↑w) := sorry
theorem nonneg_add {d : ℕ} {a : ℤ√↑d} {b : ℤ√↑d} (ha : nonneg a) (hb : nonneg b) : nonneg (a + b) := sorry
theorem le_refl {d : ℕ} (a : ℤ√↑d) : a ≤ a :=
(fun (this : nonneg (a - a)) => this)
(eq.mpr (id ((fun (ᾰ ᾰ_1 : ℤ√↑d) (e_1 : ᾰ = ᾰ_1) => congr_arg nonneg e_1) (a - a) 0 (sub_self a))) trivial)
protected theorem le_trans {d : ℕ} {a : ℤ√↑d} {b : ℤ√↑d} {c : ℤ√↑d} (ab : a ≤ b) (bc : b ≤ c) : a ≤ c := sorry
theorem nonneg_iff_zero_le {d : ℕ} {a : ℤ√↑d} : nonneg a ↔ 0 ≤ a := sorry
theorem le_of_le_le {d : ℕ} {x : ℤ} {y : ℤ} {z : ℤ} {w : ℤ} (xz : x ≤ z) (yw : y ≤ w) : mk x y ≤ mk z w := sorry
theorem le_arch {d : ℕ} (a : ℤ√↑d) : ∃ (n : ℕ), a ≤ ↑n := sorry
protected theorem nonneg_total {d : ℕ} (a : ℤ√↑d) : nonneg a ∨ nonneg (-a) := sorry
protected theorem le_total {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) : a ≤ b ∨ b ≤ a :=
let t : nonneg (b - a) ∨ nonneg (-(b - a)) := zsqrtd.nonneg_total (b - a);
eq.mp
(Eq._oldrec (Eq.refl (nonneg (b - a) ∨ nonneg (-(b - a)))) ((fun (this : -(b - a) = a - b) => this) (neg_sub b a))) t
protected instance preorder {d : ℕ} : preorder (ℤ√↑d) :=
preorder.mk zsqrtd.le zsqrtd.lt le_refl zsqrtd.le_trans
protected theorem add_le_add_left {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) (ab : a ≤ b) (c : ℤ√↑d) : c + a ≤ c + b :=
(fun (this : nonneg (c + b - (c + a))) => this)
(eq.mpr (id (Eq._oldrec (Eq.refl (nonneg (c + b - (c + a)))) (add_sub_add_left_eq_sub b a c))) ab)
protected theorem le_of_add_le_add_left {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) (c : ℤ√↑d) (h : c + a ≤ c + b) : a ≤ b := sorry
protected theorem add_lt_add_left {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) (h : a < b) (c : ℤ√↑d) : c + a < c + b :=
fun (h' : c + b ≤ c + a) => h (zsqrtd.le_of_add_le_add_left b a c h')
theorem nonneg_smul {d : ℕ} {a : ℤ√↑d} {n : ℕ} (ha : nonneg a) : nonneg (↑n * a) := sorry
theorem nonneg_muld {d : ℕ} {a : ℤ√↑d} (ha : nonneg a) : nonneg (sqrtd * a) := sorry
theorem nonneg_mul_lem {d : ℕ} {x : ℕ} {y : ℕ} {a : ℤ√↑d} (ha : nonneg a) : nonneg (mk ↑x ↑y * a) := sorry
theorem nonneg_mul {d : ℕ} {a : ℤ√↑d} {b : ℤ√↑d} (ha : nonneg a) (hb : nonneg b) : nonneg (a * b) := sorry
protected theorem mul_nonneg {d : ℕ} (a : ℤ√↑d) (b : ℤ√↑d) : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := sorry
theorem not_sq_le_succ (c : ℕ) (d : ℕ) (y : ℕ) (h : 0 < c) : ¬sq_le (y + 1) c 0 d :=
not_le_of_gt (mul_pos (mul_pos h (nat.succ_pos y)) (nat.succ_pos y))
/-- A nonsquare is a natural number that is not equal to the square of an
integer. This is implemented as a typeclass because it's a necessary condition
for much of the Pell equation theory. -/
class nonsquare (x : ℕ)
where
ns : ∀ (n : ℕ), x ≠ n * n
theorem d_pos {d : ℕ} [dnsq : nonsquare d] : 0 < d :=
lt_of_le_of_ne (nat.zero_le d) (ne.symm (nonsquare.ns d 0))
theorem divides_sq_eq_zero {d : ℕ} [dnsq : nonsquare d] {x : ℕ} {y : ℕ} (h : x * x = d * y * y) : x = 0 ∧ y = 0 := sorry
theorem divides_sq_eq_zero_z {d : ℕ} [dnsq : nonsquare d] {x : ℤ} {y : ℤ} (h : x * x = ↑d * y * y) : x = 0 ∧ y = 0 := sorry
theorem not_divides_square {d : ℕ} [dnsq : nonsquare d] (x : ℕ) (y : ℕ) : (x + 1) * (x + 1) ≠ d * (y + 1) * (y + 1) :=
fun (e : (x + 1) * (x + 1) = d * (y + 1) * (y + 1)) => nat.no_confusion (and.left (divides_sq_eq_zero e))
theorem nonneg_antisymm {d : ℕ} [dnsq : nonsquare d] {a : ℤ√↑d} : nonneg a → nonneg (-a) → a = 0 := sorry
theorem le_antisymm {d : ℕ} [dnsq : nonsquare d] {a : ℤ√↑d} {b : ℤ√↑d} (ab : a ≤ b) (ba : b ≤ a) : a = b :=
eq_of_sub_eq_zero (nonneg_antisymm ba (eq.mpr (id (Eq._oldrec (Eq.refl (nonneg (-(a - b)))) (neg_sub a b))) ab))
protected instance linear_order {d : ℕ} [dnsq : nonsquare d] : linear_order (ℤ√↑d) :=
linear_order.mk preorder.le preorder.lt sorry sorry le_antisymm zsqrtd.le_total zsqrtd.decidable_le
Mathlib.decidable_eq_of_decidable_le Mathlib.decidable_lt_of_decidable_le
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {d : ℕ} [dnsq : nonsquare d] {a : ℤ√↑d} {b : ℤ√↑d} : a * b = 0 → a = 0 ∨ b = 0 := sorry
protected instance integral_domain {d : ℕ} [dnsq : nonsquare d] : integral_domain (ℤ√↑d) :=
integral_domain.mk comm_ring.add sorry comm_ring.zero sorry sorry comm_ring.neg comm_ring.sub sorry sorry comm_ring.mul
sorry comm_ring.one sorry sorry sorry sorry sorry sorry zsqrtd.eq_zero_or_eq_zero_of_mul_eq_zero
protected theorem mul_pos {d : ℕ} [dnsq : nonsquare d] (a : ℤ√↑d) (b : ℤ√↑d) (a0 : 0 < a) (b0 : 0 < b) : 0 < a * b := sorry
protected instance linear_ordered_comm_ring {d : ℕ} [dnsq : nonsquare d] : linear_ordered_comm_ring (ℤ√↑d) :=
linear_ordered_comm_ring.mk comm_ring.add sorry comm_ring.zero sorry sorry comm_ring.neg comm_ring.sub sorry sorry
comm_ring.mul sorry comm_ring.one sorry sorry sorry sorry linear_order.le linear_order.lt sorry sorry sorry
zsqrtd.add_le_add_left sorry zsqrtd.mul_pos sorry linear_order.decidable_le linear_order.decidable_eq
linear_order.decidable_lt sorry sorry
protected instance linear_ordered_semiring {d : ℕ} [dnsq : nonsquare d] : linear_ordered_semiring (ℤ√↑d) :=
linear_ordered_comm_ring.to_linear_ordered_semiring
protected instance ordered_semiring {d : ℕ} [dnsq : nonsquare d] : ordered_semiring (ℤ√↑d) :=
ordered_ring.to_ordered_semiring
theorem norm_eq_zero {d : ℤ} (h_nonsquare : ∀ (n : ℤ), d ≠ n * n) (a : ℤ√d) : norm a = 0 ↔ a = 0 := sorry
theorem hom_ext {R : Type} [comm_ring R] {d : ℤ} (f : ℤ√d →+* R) (g : ℤ√d →+* R) (h : coe_fn f sqrtd = coe_fn g sqrtd) : f = g := sorry
/-- The unique `ring_hom` from `ℤ√d` to a ring `R`, constructed by replacing `√d` with the provided
root. Conversely, this associates to every mapping `ℤ√d →+* R` a value of `√d` in `R`. -/
@[simp] theorem lift_symm_apply_coe {R : Type} [comm_ring R] {d : ℤ} (f : ℤ√d →+* R) : ↑(coe_fn (equiv.symm lift) f) = coe_fn f sqrtd :=
Eq.refl ↑(coe_fn (equiv.symm lift) f)
/-- `lift r` is injective if `d` is non-square, and R has characteristic zero (that is, the map from
`ℤ` into `R` is injective). -/
theorem lift_injective {R : Type} [comm_ring R] [char_zero R] {d : ℤ} (r : Subtype fun (r : R) => r * r = ↑d) (hd : ∀ (n : ℤ), d ≠ n * n) : function.injective ⇑(coe_fn lift r) := sorry
|
64beb667ccef253b1a90706735b952aaeec3e7e7
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/seq/seq.lean
|
182edc11ec884c27cacf4e8a3219aacf1fd4456a
|
[
"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
| 28,870
|
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.list.basic
import data.lazy_list
import data.nat.basic
import data.stream.init
import data.seq.computation
namespace stream
universes u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/--
A stream `s : option α` is a sequence if `s.nth n = none` implies `s.nth (n + 1) = none`.
-/
def is_seq {α : Type u} (s : stream (option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def seq (α : Type u) : Type u := {f : stream (option α) // f.is_seq}
/-- `seq1 α` is the type of nonempty sequences. -/
def seq1 (α) := α × seq α
namespace seq
variables {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : seq α := ⟨stream.const none, λ n h, rfl⟩
instance : inhabited (seq α) := ⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : seq α) : seq α :=
⟨some a :: s.1, begin
rintros (n | _) h,
{ contradiction },
{ exact s.2 h }
end⟩
@[simp] lemma val_cons (s : seq α) (x : α) : (cons x s).val = some x :: s.val := rfl
/-- Get the nth element of a sequence (if it exists) -/
def nth : seq α → ℕ → option α := subtype.val
@[simp] theorem nth_mk (f hf) : @nth α ⟨f, hf⟩ = f := rfl
@[simp] theorem nth_nil (n : ℕ) : (@nil α).nth n = none := rfl
@[simp] theorem nth_cons_zero (a : α) (s : seq α) : (cons a s).nth 0 = some a := rfl
@[simp] theorem nth_cons_succ (a : α) (s : seq α) (n : ℕ) : (cons a s).nth (n + 1) = s.nth n := rfl
@[ext] protected lemma ext {s t : seq α} (h : ∀ n : ℕ, s.nth n = t.nth n) : s = t :=
subtype.eq $ funext h
lemma cons_injective2 : function.injective2 (cons : α → seq α → seq α) :=
λ x y s t h, ⟨by rw [←option.some_inj, ←nth_cons_zero, h, nth_cons_zero],
seq.ext $ λ n, by simp_rw [←nth_cons_succ x s n, h, nth_cons_succ]⟩
lemma cons_left_injective (s : seq α) : function.injective (λ x, cons x s) :=
cons_injective2.left _
lemma cons_right_injective (x : α) : function.injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def terminated_at (s : seq α) (n : ℕ) : Prop := s.nth n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminated_at_decidable (s : seq α) (n : ℕ) : decidable (s.terminated_at n) :=
decidable_of_iff' (s.nth n).is_none $ by unfold terminated_at; cases s.nth n; simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def terminates (s : seq α) : Prop := ∃ (n : ℕ), s.terminated_at n
theorem not_terminates_iff {s : seq α} : ¬ s.terminates ↔ ∀ n, (s.nth n).is_some :=
by simp [terminates, terminated_at, ←ne.def, option.ne_none_iff_is_some]
/-- Functorial action of the functor `option (α × _)` -/
@[simp] def omap (f : β → γ) : option (α × β) → option (α × γ)
| none := none
| (some (a, b)) := some (a, f b)
/-- Get the first element of a sequence -/
def head (s : seq α) : option α := nth s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : seq α) : seq α := ⟨s.1.tail, λ n, by { cases s with f al, exact al }⟩
/-- member definition for `seq`-/
protected def mem (a : α) (s : seq α) := some a ∈ s.1
instance : has_mem α (seq α) :=
⟨seq.mem⟩
theorem le_stable (s : seq α) {m n} (h : m ≤ n) : s.nth m = none → s.nth n = none :=
by { cases s with f al, induction h with n h IH, exacts [id, λ h2, al (IH h2)] }
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n `. -/
lemma terminated_stable : ∀ (s : seq α) {m n : ℕ}, m ≤ n → s.terminated_at m →
s.terminated_at n :=
le_stable
/--
If `s.nth n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.nth = some aₘ` for `m ≤ n`.
-/
lemma ge_stable (s : seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.nth n = some aₙ) :
∃ (aₘ : α), s.nth m = some aₘ :=
have s.nth n ≠ none, by simp [s_nth_eq_some],
have s.nth m ≠ none, from mt (s.le_stable m_le_n) this,
option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α :=
λ ⟨n, (h : some a = none)⟩, by injection h
theorem mem_cons (a : α) : ∀ (s : seq α), a ∈ cons a s
| ⟨f, al⟩ := stream.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : seq α}, a ∈ s → a ∈ cons y s
| ⟨f, al⟩ := stream.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨f, al⟩ h := (stream.eq_or_mem_of_mem_cons h).imp_left (λ h, by injection h)
@[simp] theorem mem_cons_iff {a b : α} {s : seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl|m); [apply mem_cons, exact mem_cons_of_mem _ m]⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : seq α) : option (seq1 α) :=
(λ a', (a', s.tail)) <$> nth s 0
theorem destruct_eq_nil {s : seq α} : destruct s = none → s = nil :=
begin
dsimp [destruct],
induction f0 : nth s 0; intro h,
{ apply subtype.eq,
funext n,
induction n with n IH, exacts [f0, s.2 IH] },
{ contradiction }
end
theorem destruct_eq_cons {s : seq α} {a s'} : destruct s = some (a, s') → s = cons a s' :=
begin
dsimp [destruct],
induction f0 : nth s 0 with a'; intro h,
{ contradiction },
{ cases s with f al,
injections with _ h1 h2,
rw ←h2, apply subtype.eq, dsimp [tail, cons],
rw h1 at f0, rw ←f0,
exact (stream.eta f).symm }
end
@[simp] theorem destruct_nil : destruct (nil : seq α) = none := rfl
@[simp] theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ := begin
unfold cons destruct functor.map,
apply congr_arg (λ s, some (a, s)),
apply subtype.eq, dsimp [tail], rw [stream.tail_cons]
end
theorem head_eq_destruct (s : seq α) : head s = prod.fst <$> destruct s :=
by unfold destruct head; cases nth s 0; refl
@[simp] theorem head_nil : head (nil : seq α) = none := rfl
@[simp] theorem head_cons (a : α) (s) : head (cons a s) = some a :=
by rw [head_eq_destruct, destruct_cons]; refl
@[simp] theorem tail_nil : tail (nil : seq α) = nil := rfl
@[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s :=
by cases s with f al; apply subtype.eq; dsimp [tail, cons]; rw [stream.tail_cons]
@[simp] theorem nth_tail (s : seq α) (n) : nth (tail s) n = nth s (n + 1) := rfl
/-- Recursion principle for sequences, compare with `list.rec_on`. -/
def rec_on {C : seq α → Sort v} (s : seq α)
(h1 : C nil) (h2 : ∀ x s, C (cons x s)) : C s := begin
induction H : destruct s with v v,
{ rw destruct_eq_nil H, apply h1 },
{ cases v with a s', rw destruct_eq_cons H, apply h2 }
end
theorem mem_rec_on {C : seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', (a = b ∨ C s') → C (cons b s')) : C s :=
begin
cases M with k e, unfold stream.nth at e,
induction k with k IH generalizing s,
{ have TH : s = cons a (tail s),
{ apply destruct_eq_cons,
unfold destruct nth functor.map, rw ←e, refl },
rw TH, apply h1 _ _ (or.inl rfl) },
revert e, apply s.rec_on _ (λ b s', _); intro e,
{ injection e },
{ have h_eq : (cons b s').val (nat.succ k) = s'.val k, { cases s'; refl },
rw [h_eq] at e,
apply h1 _ _ (or.inr (IH e)) }
end
/-- Corecursor over pairs of `option` values-/
def corec.F (f : β → option (α × β)) : option β → option α × option β
| none := (none, none)
| (some b) := match f b with none := (none, none) | some (a, b') := (some a, some b') end
/-- Corecursor for `seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → option (α × β)) (b : β) : seq α :=
begin
refine ⟨stream.corec' (corec.F f) (some b), λ n h, _⟩,
rw stream.corec'_eq,
change stream.corec' (corec.F f) (corec.F f (some b)).2 n = none,
revert h, generalize : some b = o, revert o,
induction n with n IH; intro o,
{ change (corec.F f o).1 = none → (corec.F f (corec.F f o).2).1 = none,
cases o with b; intro h, { refl },
dsimp [corec.F] at h, dsimp [corec.F],
cases f b with s, { refl },
{ cases s with a b', contradiction } },
{ rw [stream.corec'_eq (corec.F f) (corec.F f o).2,
stream.corec'_eq (corec.F f) o],
exact IH (corec.F f o).2 }
end
@[simp] theorem corec_eq (f : β → option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) :=
begin
dsimp [corec, destruct, nth],
change stream.corec' (corec.F f) (some b) 0 with (corec.F f (some b)).1,
dsimp [corec.F],
induction h : f b with s, { refl },
cases s with a b', dsimp [corec.F],
apply congr_arg (λ b', some (a, b')),
apply subtype.eq,
dsimp [corec, tail],
rw [stream.corec'_eq, stream.tail_cons],
dsimp [corec.F], rw h, refl
end
section bisim
variable (R : seq α → seq α → Prop)
local infix (name := R) ` ~ `:50 := R
/-- Bisimilarity relation over `option` of `seq1 α`-/
def bisim_o : option (seq1 α) → option (seq1 α) → Prop
| none none := true
| (some (a, s)) (some (a', s')) := a = a' ∧ R s s'
| _ _ := false
attribute [simp] bisim_o
/-- a relation is bisimiar if it meets the `bisim_o` test-/
def is_bisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → bisim_o R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : is_bisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ :=
begin
apply subtype.eq,
apply stream.eq_of_bisim (λ x y, ∃ s s' : seq α, s.1 = x ∧ s'.1 = y ∧ R s s'),
dsimp [stream.is_bisimulation],
intros t₁ t₂ e,
exact match t₁, t₂, e with ._, ._, ⟨s, s', rfl, rfl, r⟩ :=
suffices head s = head s' ∧ R (tail s) (tail s'), from
and.imp id (λ r, ⟨tail s, tail s',
by cases s; refl, by cases s'; refl, r⟩) this,
begin
have := bisim r, revert r this,
apply rec_on s _ _; intros; apply rec_on s' _ _; intros; intros r this,
{ constructor, refl, assumption },
{ rw [destruct_nil, destruct_cons] at this,
exact false.elim this },
{ rw [destruct_nil, destruct_cons] at this,
exact false.elim this },
{ rw [destruct_cons, destruct_cons] at this,
rw [head_cons, head_cons, tail_cons, tail_cons],
cases this with h1 h2,
constructor, rw h1, exact h2 }
end
end,
exact ⟨s₁, s₂, rfl, rfl, r⟩
end
end bisim
theorem coinduction : ∀ {s₁ s₂ : seq α}, head s₁ = head s₂ →
(∀ (β : Type u) (fr : seq α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| ⟨f₁, a₁⟩ ⟨f₂, a₂⟩ hh ht :=
subtype.eq (stream.coinduction hh (λ β fr, ht β (λ s, fr s.1)))
theorem coinduction2 (s) (f g : seq α → seq β)
(H : ∀ s, bisim_o (λ (s1 s2 : seq β), ∃ (s : seq α), s1 = f s ∧ s2 = g s)
(destruct (f s)) (destruct (g s)))
: f s = g s :=
begin
refine eq_of_bisim (λ s1 s2, ∃ s, s1 = f s ∧ s2 = g s) _ ⟨s, rfl, rfl⟩,
intros s1 s2 h, rcases h with ⟨s, h1, h2⟩,
rw [h1, h2], apply H
end
/-- Embed a list as a sequence -/
def of_list (l : list α) : seq α :=
⟨list.nth l, λ n h, begin
rw list.nth_eq_none_iff at h ⊢,
exact h.trans (nat.le_succ n)
end⟩
instance coe_list : has_coe (list α) (seq α) := ⟨of_list⟩
@[simp] theorem of_list_nil : of_list [] = (nil : seq α) := rfl
@[simp] theorem of_list_nth (l : list α) (n : ℕ) : (of_list l).nth n = l.nth n := rfl
@[simp] theorem of_list_cons (a : α) (l : list α) : of_list (a :: l) = cons a (of_list l) :=
by ext1 (_|n); refl
/-- Embed an infinite stream as a sequence -/
def of_stream (s : stream α) : seq α :=
⟨s.map some, λ n h, by contradiction⟩
instance coe_stream : has_coe (stream α) (seq α) := ⟨of_stream⟩
/-- Embed a `lazy_list α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `lazy_list`s created by meta constructions. -/
def of_lazy_list : lazy_list α → seq α :=
corec (λ l, match l with
| lazy_list.nil := none
| lazy_list.cons a l' := some (a, l' ())
end)
instance coe_lazy_list : has_coe (lazy_list α) (seq α) := ⟨of_lazy_list⟩
/-- Translate a sequence into a `lazy_list`. Since `lazy_list` and `list`
are isomorphic as non-meta types, this function is necessarily meta. -/
meta def to_lazy_list : seq α → lazy_list α | s :=
match destruct s with
| none := lazy_list.nil
| some (a, s') := lazy_list.cons a (to_lazy_list s')
end
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
meta def force_to_list (s : seq α) : list α := (to_lazy_list s).to_list
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : seq ℕ := stream.nats
@[simp]
lemma nats_nth (n : ℕ) : nats.nth n = some n := rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : seq α) : seq α :=
@corec α (seq α × seq α) (λ ⟨s₁, s₂⟩,
match destruct s₁ with
| none := omap (λ s₂, (nil, s₂)) (destruct s₂)
| some (a, s₁') := some (a, s₁', s₂)
end) (s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : seq α → seq β | ⟨s, al⟩ :=
⟨s.map (option.map f),
λ n, begin
dsimp [stream.map, stream.nth],
induction e : s n; intro,
{ rw al e, assumption }, { contradiction }
end⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : seq (seq1 α) → seq α :=
corec (λ S, match destruct S with
| none := none
| some ((a, s), S') := some (a, match destruct s with
| none := S'
| some s' := cons s' S'
end)
end)
/-- Remove the first `n` elements from the sequence. -/
def drop (s : seq α) : ℕ → seq α
| 0 := s
| (n+1) := tail (drop n)
attribute [simp] drop
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → seq α → list α
| 0 s := []
| (n+1) s := match destruct s with
| none := []
| some (x, r) := list.cons x (take n r)
end
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def split_at : ℕ → seq α → list α × seq α
| 0 s := ([], s)
| (n+1) s := match destruct s with
| none := ([], nil)
| some (x, s') := let (l, r) := split_at n s' in (list.cons x l, r)
end
section zip_with
/-- Combine two sequences with a function -/
def zip_with (f : α → β → γ) (s₁ : seq α) (s₂ : seq β) : seq γ :=
⟨λ n, option.map₂ f (s₁.nth n) (s₂.nth n), λ n hn,
option.map₂_eq_none_iff.2 $ (option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
variables {s : seq α} {s' : seq β} {n : ℕ}
@[simp] lemma nth_zip_with (f : α → β → γ) (s s' n) :
(zip_with f s s').nth n = option.map₂ f (s.nth n) (s'.nth n) :=
rfl
end zip_with
/-- Pair two sequences into a sequence of pairs -/
def zip : seq α → seq β → seq (α × β) := zip_with prod.mk
lemma nth_zip (s : seq α) (t : seq β) (n : ℕ) :
nth (zip s t) n = option.map₂ prod.mk (nth s n) (nth t n) :=
nth_zip_with _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : seq (α × β)) : seq α × seq β := (map prod.fst s, map prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : seq α) : seq (ℕ × α) := seq.zip nats s
@[simp] lemma nth_enum (s : seq α) (n : ℕ) : nth (enum s) n = option.map (prod.mk n) (nth s n) :=
nth_zip _ _ _
@[simp] lemma enum_nil : enum (nil : seq α) = nil := rfl
/-- Convert a sequence which is known to terminate into a list -/
def to_list (s : seq α) (h : s.terminates) : list α :=
take (nat.find h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def to_stream (s : seq α) (h : ¬ s.terminates) : stream α :=
λ n, option.get $ not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def to_list_or_stream (s : seq α) [decidable s.terminates] : list α ⊕ stream α :=
if h : s.terminates
then sum.inl (to_list s h)
else sum.inr (to_stream s h)
@[simp] theorem nil_append (s : seq α) : append nil s = s :=
begin
apply coinduction2, intro s,
dsimp [append], rw [corec_eq],
dsimp [append], apply rec_on s _ _,
{ trivial },
{ intros x s,
rw [destruct_cons], dsimp,
exact ⟨rfl, s, rfl, rfl⟩ }
end
@[simp] theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) :=
destruct_eq_cons $ begin
dsimp [append], rw [corec_eq],
dsimp [append], rw [destruct_cons],
dsimp [append], refl
end
@[simp] theorem append_nil (s : seq α) : append s nil = s :=
begin
apply coinduction2 s, intro s,
apply rec_on s _ _,
{ trivial },
{ intros x s,
rw [cons_append, destruct_cons, destruct_cons], dsimp,
exact ⟨rfl, s, rfl, rfl⟩ }
end
@[simp] theorem append_assoc (s t u : seq α) :
append (append s t) u = append s (append t u) :=
begin
apply eq_of_bisim (λ s1 s2, ∃ s t u,
s1 = append (append s t) u ∧ s2 = append s (append t u)),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, t, u, rfl, rfl⟩ := begin
apply rec_on s; simp,
{ apply rec_on t; simp,
{ apply rec_on u; simp,
{ intros x u, refine ⟨nil, nil, u, _, _⟩; simp } },
{ intros x t, refine ⟨nil, t, u, _, _⟩; simp } },
{ intros x s, exact ⟨s, t, u, rfl, rfl⟩ }
end end },
{ exact ⟨s, t, u, rfl, rfl⟩ }
end
@[simp] theorem map_nil (f : α → β) : map f nil = nil := rfl
@[simp] theorem map_cons (f : α → β) (a) : ∀ s, map f (cons a s) = cons (f a) (map f s)
| ⟨s, al⟩ := by apply subtype.eq; dsimp [cons, map]; rw stream.map_cons; refl
@[simp] theorem map_id : ∀ (s : seq α), map id s = s
| ⟨s, al⟩ := begin
apply subtype.eq; dsimp [map],
rw [option.map_id, stream.map_id]; refl
end
@[simp] theorem map_tail (f : α → β) : ∀ s, map f (tail s) = tail (map f s)
| ⟨s, al⟩ := by apply subtype.eq; dsimp [tail, map]; rw stream.map_tail; refl
theorem map_comp (f : α → β) (g : β → γ) : ∀ (s : seq α), map (g ∘ f) s = map g (map f s)
| ⟨s, al⟩ := begin
apply subtype.eq; dsimp [map],
rw stream.map_map,
apply congr_arg (λ f : _ → option γ, stream.map f s),
ext ⟨⟩; refl
end
@[simp] theorem map_append (f : α → β) (s t) : map f (append s t) = append (map f s) (map f t) :=
begin
apply eq_of_bisim (λ s1 s2, ∃ s t,
s1 = map f (append s t) ∧ s2 = append (map f s) (map f t)) _ ⟨s, t, rfl, rfl⟩,
intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, t, rfl, rfl⟩ := begin
apply rec_on s; simp,
{ apply rec_on t; simp,
{ intros x t, refine ⟨nil, t, _, _⟩; simp } },
{ intros x s, refine ⟨s, t, rfl, rfl⟩ }
end end
end
@[simp] theorem map_nth (f : α → β) : ∀ s n, nth (map f s) n = (nth s n).map f
| ⟨s, al⟩ n := rfl
instance : functor seq := {map := @map}
instance : is_lawful_functor seq :=
{ id_map := @map_id, comp_map := @map_comp }
@[simp] theorem join_nil : join nil = (nil : seq α) := destruct_eq_nil rfl
@[simp] theorem join_cons_nil (a : α) (S) :
join (cons (a, nil) S) = cons a (join S) :=
destruct_eq_cons $ by simp [join]
@[simp] theorem join_cons_cons (a b : α) (s S) :
join (cons (a, cons b s) S) = cons a (join (cons (b, s) S)) :=
destruct_eq_cons $ by simp [join]
@[simp, priority 990] theorem join_cons (a : α) (s S) :
join (cons (a, s) S) = cons a (append s (join S)) :=
begin
apply eq_of_bisim (λ s1 s2, s1 = s2 ∨
∃ a s S, s1 = join (cons (a, s) S) ∧
s2 = cons a (append s (join S))) _ (or.inr ⟨a, s, S, rfl, rfl⟩),
intros s1 s2 h,
exact match s1, s2, h with
| _, _, (or.inl $ eq.refl s) := begin
apply rec_on s, { trivial },
{ intros x s, rw [destruct_cons], exact ⟨rfl, or.inl rfl⟩ }
end
| ._, ._, (or.inr ⟨a, s, S, rfl, rfl⟩) := begin
apply rec_on s,
{ simp },
{ intros x s, simp, refine or.inr ⟨x, s, S, rfl, rfl⟩ }
end
end
end
@[simp] theorem join_append (S T : seq (seq1 α)) :
join (append S T) = append (join S) (join T) :=
begin
apply eq_of_bisim (λ s1 s2, ∃ s S T,
s1 = append s (join (append S T)) ∧
s2 = append s (append (join S) (join T))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, S, T, rfl, rfl⟩ := begin
apply rec_on s; simp,
{ apply rec_on S; simp,
{ apply rec_on T, { simp },
{ intros s T, cases s with a s; simp,
refine ⟨s, nil, T, _, _⟩; simp } },
{ intros s S, cases s with a s; simp,
exact ⟨s, S, T, rfl, rfl⟩ } },
{ intros x s, exact ⟨s, S, T, rfl, rfl⟩ }
end end },
{ refine ⟨nil, S, T, _, _⟩; simp }
end
@[simp] theorem of_stream_cons (a : α) (s) :
of_stream (a :: s) = cons a (of_stream s) :=
by apply subtype.eq; simp [of_stream, cons]; rw stream.map_cons
@[simp] theorem of_list_append (l l' : list α) :
of_list (l ++ l') = append (of_list l) (of_list l') :=
by induction l; simp [*]
@[simp] theorem of_stream_append (l : list α) (s : stream α) :
of_stream (l ++ₛ s) = append (of_list l) (of_stream s) :=
by induction l; simp [*, stream.nil_append_stream, stream.cons_append_stream]
/-- Convert a sequence into a list, embedded in a computation to allow for
the possibility of infinite sequences (in which case the computation
never returns anything). -/
def to_list' {α} (s : seq α) : computation (list α) :=
@computation.corec (list α) (list α × seq α) (λ ⟨l, s⟩,
match destruct s with
| none := sum.inl l.reverse
| some (a, s') := sum.inr (a::l, s')
end) ([], s)
theorem dropn_add (s : seq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n
| 0 := rfl
| (n+1) := congr_arg tail (dropn_add n)
theorem dropn_tail (s : seq α) (n) : drop (tail s) n = drop s (n + 1) :=
by rw add_comm; symmetry; apply dropn_add
@[simp] theorem head_dropn (s : seq α) (n) : head (drop s n) = nth s n :=
begin
induction n with n IH generalizing s, { refl },
rw [nat.succ_eq_add_one, ←nth_tail, ←dropn_tail], apply IH
end
theorem mem_map (f : α → β) {a : α} : ∀ {s : seq α}, a ∈ s → f a ∈ map f s
| ⟨g, al⟩ := stream.mem_map (option.map f)
theorem exists_of_mem_map {f} {b : β} : ∀ {s : seq α}, b ∈ map f s → ∃ a, a ∈ s ∧ f a = b
| ⟨g, al⟩ h := let ⟨o, om, oe⟩ := stream.exists_of_mem_map h in
by cases o with a; injection oe with h'; exact ⟨a, om, h'⟩
theorem of_mem_append {s₁ s₂ : seq α} {a : α} (h : a ∈ append s₁ s₂) : a ∈ s₁ ∨ a ∈ s₂ :=
begin
have := h, revert this,
generalize e : append s₁ s₂ = ss, intro h, revert s₁,
apply mem_rec_on h _,
intros b s' o s₁,
apply s₁.rec_on _ (λ c t₁, _); intros m e;
have := congr_arg destruct e,
{ apply or.inr, simpa using m },
{ cases (show a = c ∨ a ∈ append t₁ s₂, by simpa using m) with e' m,
{ rw e', exact or.inl (mem_cons _ _) },
{ cases (show c = b ∧ append t₁ s₂ = s', by simpa) with i1 i2,
cases o with e' IH,
{ simp [i1, e'] },
{ exact or.imp_left (mem_cons_of_mem _) (IH m i2) } } }
end
theorem mem_append_left {s₁ s₂ : seq α} {a : α} (h : a ∈ s₁) : a ∈ append s₁ s₂ :=
by apply mem_rec_on h; intros; simp [*]
@[simp] lemma enum_cons (s : seq α) (x : α) :
enum (cons x s) = cons (0, x) (map (prod.map nat.succ id) (enum s)) :=
begin
ext ⟨n⟩ : 1,
{ simp, },
{ simp only [nth_enum, nth_cons_succ, map_nth, option.map_map],
congr }
end
end seq
namespace seq1
variables {α : Type u} {β : Type v} {γ : Type w}
open stream.seq
/-- Convert a `seq1` to a sequence. -/
def to_seq : seq1 α → seq α
| (a, s) := seq.cons a s
instance coe_seq : has_coe (seq1 α) (seq α) := ⟨to_seq⟩
/-- Map a function on a `seq1` -/
def map (f : α → β) : seq1 α → seq1 β
| (a, s) := (f a, seq.map f s)
theorem map_id : ∀ (s : seq1 α), map id s = s | ⟨a, s⟩ := by simp [map]
/-- Flatten a nonempty sequence of nonempty sequences -/
def join : seq1 (seq1 α) → seq1 α
| ((a, s), S) := match destruct s with
| none := (a, seq.join S)
| some s' := (a, seq.join (seq.cons s' S))
end
@[simp] theorem join_nil (a : α) (S) : join ((a, nil), S) = (a, seq.join S) := rfl
@[simp] theorem join_cons (a b : α) (s S) :
join ((a, seq.cons b s), S) = (a, seq.join (seq.cons (b, s) S)) :=
by dsimp [join]; rw [destruct_cons]; refl
/-- The `return` operator for the `seq1` monad,
which produces a singleton sequence. -/
def ret (a : α) : seq1 α := (a, nil)
instance [inhabited α] : inhabited (seq1 α) := ⟨ret default⟩
/-- The `bind` operator for the `seq1` monad,
which maps `f` on each element of `s` and appends the results together.
(Not all of `s` may be evaluated, because the first few elements of `s`
may already produce an infinite result.) -/
def bind (s : seq1 α) (f : α → seq1 β) : seq1 β :=
join (map f s)
@[simp] theorem join_map_ret (s : seq α) : seq.join (seq.map ret s) = s :=
by apply coinduction2 s; intro s; apply rec_on s; simp [ret]
@[simp] theorem bind_ret (f : α → β) : ∀ s, bind s (ret ∘ f) = map f s
| ⟨a, s⟩ := begin
dsimp [bind, map], change (λ x, ret (f x)) with (ret ∘ f),
rw [map_comp], simp [function.comp, ret]
end
@[simp] theorem ret_bind (a : α) (f : α → seq1 β) : bind (ret a) f = f a :=
begin
simp [ret, bind, map],
cases f a with a s,
apply rec_on s; intros; simp
end
@[simp] theorem map_join' (f : α → β) (S) :
seq.map f (seq.join S) = seq.join (seq.map (map f) S) :=
begin
apply seq.eq_of_bisim (λ s1 s2,
∃ s S, s1 = seq.append s (seq.map f (seq.join S)) ∧
s2 = append s (seq.join (seq.map (map f) S))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, S, rfl, rfl⟩ := begin
apply rec_on s; simp,
{ apply rec_on S; simp,
{ intros x S, cases x with a s; simp [map],
exact ⟨_, _, rfl, rfl⟩ } },
{ intros x s, refine ⟨s, S, rfl, rfl⟩ }
end end },
{ refine ⟨nil, S, _, _⟩; simp }
end
@[simp] theorem map_join (f : α → β) : ∀ S, map f (join S) = join (map (map f) S)
| ((a, s), S) := by apply rec_on s; intros; simp [map]
@[simp] theorem join_join (SS : seq (seq1 (seq1 α))) :
seq.join (seq.join SS) = seq.join (seq.map join SS) :=
begin
apply seq.eq_of_bisim (λ s1 s2,
∃ s SS, s1 = seq.append s (seq.join (seq.join SS)) ∧
s2 = seq.append s (seq.join (seq.map join SS))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, SS, rfl, rfl⟩ := begin
apply rec_on s; simp,
{ apply rec_on SS; simp,
{ intros S SS, cases S with s S; cases s with x s; simp [map],
apply rec_on s; simp,
{ exact ⟨_, _, rfl, rfl⟩ },
{ intros x s,
refine ⟨seq.cons x (append s (seq.join S)), SS, _, _⟩; simp } } },
{ intros x s, exact ⟨s, SS, rfl, rfl⟩ }
end end },
{ refine ⟨nil, SS, _, _⟩; simp }
end
@[simp] theorem bind_assoc (s : seq1 α) (f : α → seq1 β) (g : β → seq1 γ) :
bind (bind s f) g = bind s (λ (x : α), bind (f x) g) :=
begin
cases s with a s,
simp [bind, map],
rw [←map_comp],
change (λ x, join (map g (f x))) with (join ∘ ((map g) ∘ f)),
rw [map_comp _ join],
generalize : seq.map (map g ∘ f) s = SS,
rcases map g (f a) with ⟨⟨a, s⟩, S⟩,
apply rec_on s; intros; apply rec_on S; intros; simp,
{ cases x with x t, apply rec_on t; intros; simp },
{ cases x_1 with y t; simp }
end
instance : monad seq1 :=
{ map := @map,
pure := @ret,
bind := @bind }
instance : is_lawful_monad seq1 :=
{ id_map := @map_id,
bind_pure_comp_eq_map := @bind_ret,
pure_bind := @ret_bind,
bind_assoc := @bind_assoc }
end seq1
end stream
|
541d8efe1db045d7a77ad4cb6c166dcf5a9ba27a
|
1abd1ed12aa68b375cdef28959f39531c6e95b84
|
/src/measure_theory/function/lp_space.lean
|
75a62f4de02cd62a4d8a15414eaca46e383f01ee
|
[
"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
| 111,370
|
lean
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import analysis.normed_space.indicator_function
import analysis.normed.group.hom
import measure_theory.function.ess_sup
import measure_theory.function.ae_eq_fun
import measure_theory.integral.mean_inequalities
import topology.continuous_function.compact
/-!
# ℒp space and Lp space
This file describes properties of almost everywhere measurable functions with finite seminorm,
denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`, `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for
`0 < p < ∞` and `ess_sup ∥f∥ μ` for `p=∞`.
The Prop-valued `mem_ℒp f p μ` states that a function `f : α → E` has finite seminorm.
The space `Lp E p μ` is the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun) such that
`snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric space.
## Main definitions
* `snorm' f p μ` : `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable
space and `F` is a normed group.
* `snorm_ess_sup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ∥f∥ μ`.
* `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ`
for `0 < p < ∞` and to `snorm_ess_sup f μ` for `p = ∞`.
* `mem_ℒp f p μ` : property that the function `f` is almost everywhere measurable and has finite
p-seminorm for measure `μ` (`snorm f p μ < ∞`)
* `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined
as an `add_subgroup` of `α →ₘ[μ] E`.
Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove
that it is continuous. In particular,
* `continuous_linear_map.comp_Lp` defines the action on `Lp` of a continuous linear map.
* `Lp.pos_part` is the positive part of an `Lp` function.
* `Lp.neg_part` is the negative part of an `Lp` function.
When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map
from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this
as `bounded_continuous_function.to_Lp`.
## Notations
* `α →₁[μ] E` : the type `Lp E 1 μ`.
* `α →₂[μ] E` : the type `Lp E 2 μ`.
## Implementation
Since `Lp` is defined as an `add_subgroup`, dot notation does not work. Use `Lp.measurable f` to
say that the coercion of `f` to a genuine function is measurable, instead of the non-working
`f.measurable`.
To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions
coincide almost everywhere (this is registered as an `ext` rule). This can often be done using
`filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h`
could read (in the `Lp` namespace)
```
example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) :=
begin
ext1,
filter_upwards [coe_fn_add (f + g) h, coe_fn_add f g, coe_fn_add f (g + h), coe_fn_add g h],
assume a ha1 ha2 ha3 ha4,
simp only [ha1, ha2, ha3, ha4, add_assoc],
end
```
The lemma `coe_fn_add` states that the coercion of `f + g` coincides almost everywhere with the sum
of the coercions of `f` and `g`. All such lemmas use `coe_fn` in their name, to distinguish the
function coercion from the coercion to almost everywhere defined functions.
-/
noncomputable theory
open topological_space measure_theory filter
open_locale nnreal ennreal big_operators topological_space measure_theory
lemma fact_one_le_one_ennreal : fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_refl _⟩
lemma fact_one_le_two_ennreal : fact ((1 : ℝ≥0∞) ≤ 2) :=
⟨ennreal.coe_le_coe.2 (show (1 : ℝ≥0) ≤ 2, by norm_num)⟩
lemma fact_one_le_top_ennreal : fact ((1 : ℝ≥0∞) ≤ ∞) := ⟨le_top⟩
local attribute [instance] fact_one_le_one_ennreal fact_one_le_two_ennreal fact_one_le_top_ennreal
variables {α E F G : Type*} {m m0 : measurable_space α} {p : ℝ≥0∞} {q : ℝ} {μ ν : measure α}
[measurable_space E] [normed_group E]
[normed_group F] [normed_group G]
namespace measure_theory
section ℒp
/-!
### ℒp seminorm
We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral
formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential
supremum (for which we use the notation `snorm_ess_sup f μ`).
We also define a predicate `mem_ℒp f p μ`, requesting that a function is almost everywhere
measurable and has finite `snorm f p μ`.
This paragraph is devoted to the basic properties of these definitions. It is constructed as
follows: for a given property, we prove it for `snorm'` and `snorm_ess_sup` when it makes sense,
deduce it for `snorm`, and translate it in terms of `mem_ℒp`.
-/
section ℒp_space_definition
/-- `(∫ ∥f a∥^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which
this quantity is finite -/
def snorm' {m : measurable_space α} (f : α → F) (q : ℝ) (μ : measure α) : ℝ≥0∞ :=
(∫⁻ a, (nnnorm (f a))^q ∂μ) ^ (1/q)
/-- seminorm for `ℒ∞`, equal to the essential supremum of `∥f∥`. -/
def snorm_ess_sup {m : measurable_space α} (f : α → F) (μ : measure α) :=
ess_sup (λ x, (nnnorm (f x) : ℝ≥0∞)) μ
/-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to
`ess_sup ∥f∥ μ` for `p = ∞`. -/
def snorm {m : measurable_space α} (f : α → F) (p : ℝ≥0∞) (μ : measure α) : ℝ≥0∞ :=
if p = 0 then 0 else (if p = ∞ then snorm_ess_sup f μ else snorm' f (ennreal.to_real p) μ)
lemma snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = snorm' f (ennreal.to_real p) μ :=
by simp [snorm, hp_ne_zero, hp_ne_top]
lemma snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = (∫⁻ x, (nnnorm (f x)) ^ p.to_real ∂μ) ^ (1 / p.to_real) :=
by rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm']
lemma snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, nnnorm (f x) ∂μ :=
by simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ennreal.coe_ne_top, ennreal.one_to_real,
one_div_one, ennreal.rpow_one]
@[simp] lemma snorm_exponent_top {f : α → F} : snorm f ∞ μ = snorm_ess_sup f μ := by simp [snorm]
/-- The property that `f:α→E` is ae_measurable and `(∫ ∥f a∥^p ∂μ)^(1/p)` is finite if `p < ∞`, or
`ess_sup f < ∞` if `p = ∞`. -/
def mem_ℒp {α} {m : measurable_space α} (f : α → E) (p : ℝ≥0∞) (μ : measure α) : Prop :=
ae_measurable f μ ∧ snorm f p μ < ∞
lemma mem_ℒp.ae_measurable {f : α → E} {p : ℝ≥0∞} (h : mem_ℒp f p μ) : ae_measurable f μ := h.1
lemma lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) :
∫⁻ a, (nnnorm (f a)) ^ q ∂μ = (snorm' f q μ) ^ q :=
begin
rw [snorm', ←ennreal.rpow_mul, one_div, inv_mul_cancel, ennreal.rpow_one],
exact (ne_of_lt hq0_lt).symm,
end
end ℒp_space_definition
section top
lemma mem_ℒp.snorm_lt_top {f : α → E} (hfp : mem_ℒp f p μ) : snorm f p μ < ∞ := hfp.2
lemma mem_ℒp.snorm_ne_top {f : α → E} (hfp : mem_ℒp f p μ) : snorm f p μ ≠ ∞ := ne_of_lt (hfp.2)
lemma lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q)
(hfq : snorm' f q μ < ∞) :
∫⁻ a, (nnnorm (f a)) ^ q ∂μ < ∞ :=
begin
rw lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt,
exact ennreal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq),
end
lemma lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) :
∫⁻ a, (nnnorm (f a)) ^ p.to_real ∂μ < ∞ :=
begin
apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top,
{ exact ennreal.to_real_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr hp_ne_zero, hp_ne_top⟩ },
{ simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp }
end
lemma snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) :
snorm f p μ < ∞ ↔ ∫⁻ a, (nnnorm (f a)) ^ p.to_real ∂μ < ∞ :=
⟨lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_ne_zero hp_ne_top,
begin
intros h,
have hp' := ennreal.to_real_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr hp_ne_zero, hp_ne_top⟩,
have : 0 < 1 / p.to_real := div_pos zero_lt_one hp',
simpa [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top] using
ennreal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)
end⟩
end top
section zero
@[simp] lemma snorm'_exponent_zero {f : α → F} : snorm' f 0 μ = 1 :=
by rw [snorm', div_zero, ennreal.rpow_zero]
@[simp] lemma snorm_exponent_zero {f : α → F} : snorm f 0 μ = 0 :=
by simp [snorm]
lemma mem_ℒp_zero_iff_ae_measurable {f : α → E} : mem_ℒp f 0 μ ↔ ae_measurable f μ :=
by simp [mem_ℒp, snorm_exponent_zero]
@[simp] lemma snorm'_zero (hp0_lt : 0 < q) : snorm' (0 : α → F) q μ = 0 :=
by simp [snorm', hp0_lt]
@[simp] lemma snorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : snorm' (0 : α → F) q μ = 0 :=
begin
cases le_or_lt 0 q with hq0 hq_neg,
{ exact snorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm), },
{ simp [snorm', ennreal.rpow_eq_zero_iff, hμ, hq_neg], },
end
@[simp] lemma snorm_ess_sup_zero : snorm_ess_sup (0 : α → F) μ = 0 :=
begin
simp_rw [snorm_ess_sup, pi.zero_apply, nnnorm_zero, ennreal.coe_zero, ←ennreal.bot_eq_zero],
exact ess_sup_const_bot,
end
@[simp] lemma snorm_zero : snorm (0 : α → F) p μ = 0 :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp only [h_top, snorm_exponent_top, snorm_ess_sup_zero], },
rw ←ne.def at h0,
simp [snorm_eq_snorm' h0 h_top,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
@[simp] lemma snorm_zero' : snorm (λ x : α, (0 : F)) p μ = 0 :=
by convert snorm_zero
lemma zero_mem_ℒp : mem_ℒp (0 : α → E) p μ :=
⟨measurable_zero.ae_measurable, by { rw snorm_zero, exact ennreal.coe_lt_top, } ⟩
lemma zero_mem_ℒp' : mem_ℒp (λ x : α, (0 : E)) p μ :=
by convert zero_mem_ℒp
variables [measurable_space α]
lemma snorm'_measure_zero_of_pos {f : α → F} (hq_pos : 0 < q) :
snorm' f q (0 : measure α) = 0 :=
by simp [snorm', hq_pos]
lemma snorm'_measure_zero_of_exponent_zero {f : α → F} : snorm' f 0 (0 : measure α) = 1 :=
by simp [snorm']
lemma snorm'_measure_zero_of_neg {f : α → F} (hq_neg : q < 0) : snorm' f q (0 : measure α) = ∞ :=
by simp [snorm', hq_neg]
@[simp] lemma snorm_ess_sup_measure_zero {f : α → F} : snorm_ess_sup f (0 : measure α) = 0 :=
by simp [snorm_ess_sup]
@[simp] lemma snorm_measure_zero {f : α → F} : snorm f p (0 : measure α) = 0 :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top], },
rw ←ne.def at h0,
simp [snorm_eq_snorm' h0 h_top, snorm',
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
end zero
section const
lemma snorm'_const (c : F) (hq_pos : 0 < q) :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/q) :=
begin
rw [snorm', lintegral_const, ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)],
congr,
rw ←ennreal.rpow_mul,
suffices hq_cancel : q * (1/q) = 1, by rw [hq_cancel, ennreal.rpow_one],
rw [one_div, mul_inv_cancel (ne_of_lt hq_pos).symm],
end
lemma snorm'_const' [is_finite_measure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/q) :=
begin
rw [snorm', lintegral_const, ennreal.mul_rpow_of_ne_top _ (measure_ne_top μ set.univ)],
{ congr,
rw ←ennreal.rpow_mul,
suffices hp_cancel : q * (1/q) = 1, by rw [hp_cancel, ennreal.rpow_one],
rw [one_div, mul_inv_cancel hq_ne_zero], },
{ rw [ne.def, ennreal.rpow_eq_top_iff, auto.not_or_eq, auto.not_and_eq, auto.not_and_eq],
split,
{ left,
rwa [ennreal.coe_eq_zero, nnnorm_eq_zero], },
{ exact or.inl ennreal.coe_ne_top, }, },
end
lemma snorm_ess_sup_const (c : F) (hμ : μ ≠ 0) :
snorm_ess_sup (λ x : α, c) μ = (nnnorm c : ℝ≥0∞) :=
by rw [snorm_ess_sup, ess_sup_const _ hμ]
lemma snorm'_const_of_is_probability_measure (c : F) (hq_pos : 0 < q) [is_probability_measure μ] :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) :=
by simp [snorm'_const c hq_pos, measure_univ]
lemma snorm_const (c : F) (h0 : p ≠ 0) (hμ : μ ≠ 0) :
snorm (λ x : α , c) p μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/(ennreal.to_real p)) :=
begin
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup_const c hμ], },
simp [snorm_eq_snorm' h0 h_top, snorm'_const,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
lemma snorm_const' (c : F) (h0 : p ≠ 0) (h_top: p ≠ ∞) :
snorm (λ x : α , c) p μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/(ennreal.to_real p)) :=
begin
simp [snorm_eq_snorm' h0 h_top, snorm'_const,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
lemma snorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
snorm (λ x : α, c) p μ < ∞ ↔ c = 0 ∨ μ set.univ < ∞ :=
begin
have hp : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp_ne_zero.bot_lt, hp_ne_top⟩,
by_cases hμ : μ = 0,
{ simp only [hμ, measure.coe_zero, pi.zero_apply, or_true, with_top.zero_lt_top,
snorm_measure_zero], },
by_cases hc : c = 0,
{ simp only [hc, true_or, eq_self_iff_true, with_top.zero_lt_top, snorm_zero'], },
rw snorm_const' c hp_ne_zero hp_ne_top,
by_cases hμ_top : μ set.univ = ∞,
{ simp [hc, hμ_top, hp], },
rw ennreal.mul_lt_top_iff,
simp only [true_and, one_div, ennreal.rpow_eq_zero_iff, hμ, false_or, or_false,
ennreal.coe_lt_top, nnnorm_eq_zero, ennreal.coe_eq_zero,
measure_theory.measure.measure_univ_eq_zero, hp, inv_lt_zero, hc, and_false, false_and,
_root_.inv_pos, or_self, hμ_top, ne.lt_top hμ_top, iff_true],
exact ennreal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_top,
end
lemma mem_ℒp_const (c : E) [is_finite_measure μ] : mem_ℒp (λ a:α, c) p μ :=
begin
refine ⟨measurable_const.ae_measurable, _⟩,
by_cases h0 : p = 0,
{ simp [h0], },
by_cases hμ : μ = 0,
{ simp [hμ], },
rw snorm_const c h0 hμ,
refine ennreal.mul_lt_top ennreal.coe_ne_top _,
refine (ennreal.rpow_lt_top_of_nonneg _ (measure_ne_top μ set.univ)).ne,
simp,
end
lemma mem_ℒp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
mem_ℒp (λ x : α, c) p μ ↔ c = 0 ∨ μ set.univ < ∞ :=
begin
rw ← snorm_const_lt_top_iff hp_ne_zero hp_ne_top,
exact ⟨λ h, h.2, λ h, ⟨ae_measurable_const, h⟩⟩,
end
end const
lemma snorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) :
snorm' f q μ ≤ snorm' g q μ :=
begin
rw [snorm'],
refine ennreal.rpow_le_rpow _ (one_div_nonneg.2 hq),
refine lintegral_mono_ae (h.mono $ λ x hx, _),
exact ennreal.rpow_le_rpow (ennreal.coe_le_coe.2 hx) hq
end
lemma snorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ∥f x∥ = ∥g x∥) :
snorm' f q μ = snorm' g q μ :=
begin
have : (λ x, (nnnorm (f x) ^ q : ℝ≥0∞)) =ᵐ[μ] (λ x, nnnorm (g x) ^ q),
from hfg.mono (λ x hx, by { simp only [← coe_nnnorm, nnreal.coe_eq] at hx, simp [hx] }),
simp only [snorm', lintegral_congr_ae this]
end
lemma snorm'_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm' f q μ = snorm' g q μ :=
snorm'_congr_norm_ae (hfg.fun_comp _)
lemma snorm_ess_sup_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) :
snorm_ess_sup f μ = snorm_ess_sup g μ :=
ess_sup_congr_ae (hfg.fun_comp (coe ∘ nnnorm))
lemma snorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) :
snorm f p μ ≤ snorm g p μ :=
begin
simp only [snorm],
split_ifs,
{ exact le_rfl },
{ refine ess_sup_mono_ae (h.mono $ λ x hx, _),
exact_mod_cast hx },
{ exact snorm'_mono_ae ennreal.to_real_nonneg h }
end
lemma snorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ g x) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae $ h.mono (λ x hx, hx.trans ((le_abs_self _).trans (real.norm_eq_abs _).symm.le))
lemma snorm_mono {f : α → F} {g : α → G} (h : ∀ x, ∥f x∥ ≤ ∥g x∥) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae (eventually_of_forall (λ x, h x))
lemma snorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ∥f x∥ ≤ g x) :
snorm f p μ ≤ snorm g p μ :=
snorm_mono_ae_real (eventually_of_forall (λ x, h x))
lemma snorm_ess_sup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm_ess_sup f μ ≤ ennreal.of_real C:=
begin
simp_rw [snorm_ess_sup, ← of_real_norm_eq_coe_nnnorm],
refine ess_sup_le_of_ae_le (ennreal.of_real C) (hfC.mono (λ x hx, _)),
exact ennreal.of_real_le_of_real hx,
end
lemma snorm_ess_sup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm_ess_sup f μ < ∞ :=
(snorm_ess_sup_le_of_ae_bound hfC).trans_lt ennreal.of_real_lt_top
lemma snorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm f p μ ≤ ((μ set.univ) ^ p.to_real⁻¹) * (ennreal.of_real C) :=
begin
by_cases hμ : μ = 0,
{ simp [hμ] },
haveI : μ.ae.ne_bot := ae_ne_bot.mpr hμ,
by_cases hp : p = 0,
{ simp [hp] },
have hC : 0 ≤ C, from le_trans (norm_nonneg _) hfC.exists.some_spec,
have hC' : ∥C∥ = C := by rw [real.norm_eq_abs, abs_eq_self.mpr hC],
have : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥(λ _, C) x∥, from hfC.mono (λ x hx, hx.trans (le_of_eq hC'.symm)),
convert snorm_mono_ae this,
rw [snorm_const _ hp hμ, mul_comm, ← of_real_norm_eq_coe_nnnorm, hC', one_div]
end
lemma snorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ∥f x∥ = ∥g x∥) :
snorm f p μ = snorm g p μ :=
le_antisymm (snorm_mono_ae $ eventually_eq.le hfg)
(snorm_mono_ae $ (eventually_eq.symm hfg).le)
@[simp] lemma snorm'_norm {f : α → F} : snorm' (λ a, ∥f a∥) q μ = snorm' f q μ :=
by simp [snorm']
@[simp] lemma snorm_norm (f : α → F) : snorm (λ x, ∥f x∥) p μ = snorm f p μ :=
snorm_congr_norm_ae $ eventually_of_forall $ λ x, norm_norm _
lemma snorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) :
snorm' (λ x, ∥f x∥ ^ q) p μ = (snorm' f (p * q) μ) ^ q :=
begin
simp_rw snorm',
rw [← ennreal.rpow_mul, ←one_div_mul_one_div],
simp_rw one_div,
rw [mul_assoc, inv_mul_cancel hq_pos.ne.symm, mul_one],
congr,
ext1 x,
simp_rw ← of_real_norm_eq_coe_nnnorm,
rw [real.norm_eq_abs, abs_eq_self.mpr (real.rpow_nonneg_of_nonneg (norm_nonneg _) _),
mul_comm, ← ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ennreal.rpow_mul],
end
lemma snorm_norm_rpow (f : α → F) (hq_pos : 0 < q) :
snorm (λ x, ∥f x∥ ^ q) p μ = (snorm f (p * ennreal.of_real q) μ) ^ q :=
begin
by_cases h0 : p = 0,
{ simp [h0, ennreal.zero_rpow_of_pos hq_pos], },
by_cases hp_top : p = ∞,
{ simp only [hp_top, snorm_exponent_top, ennreal.top_mul, hq_pos.not_le, ennreal.of_real_eq_zero,
if_false, snorm_exponent_top, snorm_ess_sup],
have h_rpow : ess_sup (λ (x : α), (nnnorm (∥f x∥ ^ q) : ℝ≥0∞)) μ
= ess_sup (λ (x : α), (↑(nnnorm (f x))) ^ q) μ,
{ congr,
ext1 x,
nth_rewrite 1 ← nnnorm_norm,
rw [ennreal.coe_rpow_of_nonneg _ hq_pos.le, ennreal.coe_eq_coe],
ext,
push_cast,
rw real.norm_rpow_of_nonneg (norm_nonneg _), },
rw h_rpow,
have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos hq_pos,
have h_rpow_surj := (ennreal.rpow_left_bijective hq_pos.ne.symm).2,
let iso := h_rpow_mono.order_iso_of_surjective _ h_rpow_surj,
exact (iso.ess_sup_apply (λ x, ((nnnorm (f x)) : ℝ≥0∞)) μ).symm, },
rw [snorm_eq_snorm' h0 hp_top, snorm_eq_snorm' _ _],
swap, { refine mul_ne_zero h0 _, rwa [ne.def, ennreal.of_real_eq_zero, not_le], },
swap, { exact ennreal.mul_ne_top hp_top ennreal.of_real_ne_top, },
rw [ennreal.to_real_mul, ennreal.to_real_of_real hq_pos.le],
exact snorm'_norm_rpow f p.to_real q hq_pos,
end
lemma snorm_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm f p μ = snorm g p μ :=
snorm_congr_norm_ae $ hfg.mono (λ x hx, hx ▸ rfl)
lemma mem_ℒp_congr_ae {f g : α → E} (hfg : f =ᵐ[μ] g) : mem_ℒp f p μ ↔ mem_ℒp g p μ :=
by simp only [mem_ℒp, snorm_congr_ae hfg, ae_measurable_congr hfg]
lemma mem_ℒp.ae_eq {f g : α → E} (hfg : f =ᵐ[μ] g) (hf_Lp : mem_ℒp f p μ) : mem_ℒp g p μ :=
(mem_ℒp_congr_ae hfg).1 hf_Lp
lemma mem_ℒp.of_le [measurable_space F] {f : α → E} {g : α → F}
(hg : mem_ℒp g p μ) (hf : ae_measurable f μ) (hfg : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : mem_ℒp f p μ :=
⟨hf, (snorm_mono_ae hfg).trans_lt hg.snorm_lt_top⟩
alias mem_ℒp.of_le ← measure_theory.mem_ℒp.mono
lemma mem_ℒp.mono' {f : α → E} {g : α → ℝ} (hg : mem_ℒp g p μ)
(hf : ae_measurable f μ) (h : ∀ᵐ a ∂μ, ∥f a∥ ≤ g a) : mem_ℒp f p μ :=
hg.mono hf $ h.mono $ λ x hx, le_trans hx (le_abs_self _)
lemma mem_ℒp.congr_norm [measurable_space F] {f : α → E} {g : α → F} (hf : mem_ℒp f p μ)
(hg : ae_measurable g μ) (h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
mem_ℒp g p μ :=
hf.mono hg $ eventually_eq.le $ eventually_eq.symm h
lemma mem_ℒp_congr_norm [measurable_space F] {f : α → E} {g : α → F}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) (h : ∀ᵐ a ∂μ, ∥f a∥ = ∥g a∥) :
mem_ℒp f p μ ↔ mem_ℒp g p μ :=
⟨λ h2f, h2f.congr_norm hg h, λ h2g, h2g.congr_norm hf $ eventually_eq.symm h⟩
lemma mem_ℒp_top_of_bound {f : α → E} (hf : ae_measurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
mem_ℒp f ∞ μ :=
⟨hf, by { rw snorm_exponent_top, exact snorm_ess_sup_lt_top_of_ae_bound hfC, }⟩
lemma mem_ℒp.of_bound [is_finite_measure μ] {f : α → E} (hf : ae_measurable f μ)
(C : ℝ) (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
mem_ℒp f p μ :=
(mem_ℒp_const C).of_le hf (hfC.mono (λ x hx, le_trans hx (le_abs_self _)))
@[mono] lemma snorm'_mono_measure (f : α → F) (hμν : ν ≤ μ) (hq : 0 ≤ q) :
snorm' f q ν ≤ snorm' f q μ :=
begin
simp_rw snorm',
suffices h_integral_mono : (∫⁻ a, (nnnorm (f a) : ℝ≥0∞) ^ q ∂ν) ≤ ∫⁻ a, (nnnorm (f a)) ^ q ∂μ,
from ennreal.rpow_le_rpow h_integral_mono (by simp [hq]),
exact lintegral_mono' hμν le_rfl,
end
@[mono] lemma snorm_ess_sup_mono_measure (f : α → F) (hμν : ν ≪ μ) :
snorm_ess_sup f ν ≤ snorm_ess_sup f μ :=
by { simp_rw snorm_ess_sup, exact ess_sup_mono_measure hμν, }
@[mono] lemma snorm_mono_measure (f : α → F) (hμν : ν ≤ μ) :
snorm f p ν ≤ snorm f p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_mono_measure f (measure.absolutely_continuous_of_le hμν)], },
simp_rw snorm_eq_snorm' hp0 hp_top,
exact snorm'_mono_measure f hμν ennreal.to_real_nonneg,
end
lemma mem_ℒp.mono_measure {f : α → E} (hμν : ν ≤ μ) (hf : mem_ℒp f p μ) :
mem_ℒp f p ν :=
⟨hf.1.mono_measure hμν, (snorm_mono_measure f hμν).trans_lt hf.2⟩
lemma mem_ℒp.restrict (s : set α) {f : α → E} (hf : mem_ℒp f p μ) :
mem_ℒp f p (μ.restrict s) :=
hf.mono_measure measure.restrict_le_self
lemma snorm'_smul_measure {p : ℝ} (hp : 0 ≤ p) {f : α → F} (c : ℝ≥0∞) :
snorm' f p (c • μ) = c ^ (1 / p) * snorm' f p μ :=
by { rw [snorm', lintegral_smul_measure, ennreal.mul_rpow_of_nonneg, snorm'], simp [hp], }
lemma snorm_ess_sup_smul_measure {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) :
snorm_ess_sup f (c • μ) = snorm_ess_sup f μ :=
by { simp_rw [snorm_ess_sup], exact ess_sup_smul_measure hc, }
/-- Use `snorm_smul_measure_of_ne_top` instead. -/
private lemma snorm_smul_measure_of_ne_zero_of_ne_top {p : ℝ≥0∞} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) :
snorm f p (c • μ) = c ^ (1 / p).to_real • snorm f p μ :=
begin
simp_rw snorm_eq_snorm' hp_ne_zero hp_ne_top,
rw snorm'_smul_measure ennreal.to_real_nonneg,
congr,
simp_rw one_div,
rw ennreal.to_real_inv,
end
lemma snorm_smul_measure_of_ne_zero {p : ℝ≥0∞} {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) :
snorm f p (c • μ) = c ^ (1 / p).to_real • snorm f p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_smul_measure hc], },
exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_top c,
end
lemma snorm_smul_measure_of_ne_top {p : ℝ≥0∞} (hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) :
snorm f p (c • μ) = c ^ (1 / p).to_real • snorm f p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
{ exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_ne_top c, },
end
lemma snorm_one_smul_measure {f : α → F} (c : ℝ≥0∞) :
snorm f 1 (c • μ) = c * snorm f 1 μ :=
by { rw @snorm_smul_measure_of_ne_top _ _ _ μ _ 1 (@ennreal.coe_ne_top 1) f c, simp, }
section opens_measurable_space
variable [opens_measurable_space E]
lemma mem_ℒp.norm {f : α → E} (h : mem_ℒp f p μ) : mem_ℒp (λ x, ∥f x∥) p μ :=
h.of_le h.ae_measurable.norm (eventually_of_forall (λ x, by simp))
lemma mem_ℒp_norm_iff {f : α → E} (hf : ae_measurable f μ) :
mem_ℒp (λ x, ∥f x∥) p μ ↔ mem_ℒp f p μ :=
⟨λ h, ⟨hf, by { rw ← snorm_norm, exact h.2, }⟩, λ h, h.norm⟩
lemma snorm'_eq_zero_of_ae_zero {f : α → F} (hq0_lt : 0 < q) (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 :=
by rw [snorm'_congr_ae hf_zero, snorm'_zero hq0_lt]
lemma snorm'_eq_zero_of_ae_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) {f : α → F} (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 :=
by rw [snorm'_congr_ae hf_zero, snorm'_zero' hq0_ne hμ]
lemma ae_eq_zero_of_snorm'_eq_zero {f : α → E} (hq0 : 0 ≤ q) (hf : ae_measurable f μ)
(h : snorm' f q μ = 0) : f =ᵐ[μ] 0 :=
begin
rw [snorm', ennreal.rpow_eq_zero_iff] at h,
cases h,
{ rw lintegral_eq_zero_iff' (hf.ennnorm.pow_const q) at h,
refine h.left.mono (λ x hx, _),
rw [pi.zero_apply, ennreal.rpow_eq_zero_iff] at hx,
cases hx,
{ cases hx with hx _,
rwa [←ennreal.coe_zero, ennreal.coe_eq_coe, nnnorm_eq_zero] at hx, },
{ exact absurd hx.left ennreal.coe_ne_top, }, },
{ exfalso,
rw [one_div, inv_lt_zero] at h,
exact hq0.not_lt h.right },
end
lemma snorm'_eq_zero_iff (hq0_lt : 0 < q) {f : α → E} (hf : ae_measurable f μ) :
snorm' f q μ = 0 ↔ f =ᵐ[μ] 0 :=
⟨ae_eq_zero_of_snorm'_eq_zero (le_of_lt hq0_lt) hf, snorm'_eq_zero_of_ae_zero hq0_lt⟩
lemma coe_nnnorm_ae_le_snorm_ess_sup {m : measurable_space α} (f : α → F) (μ : measure α) :
∀ᵐ x ∂μ, (nnnorm (f x) : ℝ≥0∞) ≤ snorm_ess_sup f μ :=
ennreal.ae_le_ess_sup (λ x, (nnnorm (f x) : ℝ≥0∞))
@[simp] lemma snorm_ess_sup_eq_zero_iff {f : α → F} : snorm_ess_sup f μ = 0 ↔ f =ᵐ[μ] 0 :=
by simp [eventually_eq, snorm_ess_sup]
lemma snorm_eq_zero_iff {f : α → E} (hf : ae_measurable f μ) (h0 : p ≠ 0) :
snorm f p μ = 0 ↔ f =ᵐ[μ] 0 :=
begin
by_cases h_top : p = ∞,
{ rw [h_top, snorm_exponent_top, snorm_ess_sup_eq_zero_iff], },
rw snorm_eq_snorm' h0 h_top,
exact snorm'_eq_zero_iff
(ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩) hf,
end
lemma snorm'_add_le {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) (hq1 : 1 ≤ q) :
snorm' (f + g) q μ ≤ snorm' f q μ + snorm' g q μ :=
calc (∫⁻ a, ↑(nnnorm ((f + g) a)) ^ q ∂μ) ^ (1 / q)
≤ (∫⁻ a, (((λ a, (nnnorm (f a) : ℝ≥0∞))
+ (λ a, (nnnorm (g a) : ℝ≥0∞))) a) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow _ (by simp [le_trans zero_le_one hq1] : 0 ≤ 1 / q),
refine lintegral_mono (λ a, ennreal.rpow_le_rpow _ (le_trans zero_le_one hq1)),
simp [←ennreal.coe_add, nnnorm_add_le],
end
... ≤ snorm' f q μ + snorm' g q μ :
ennreal.lintegral_Lp_add_le hf.ennnorm hg.ennnorm hq1
lemma snorm_ess_sup_add_le {f g : α → F} :
snorm_ess_sup (f + g) μ ≤ snorm_ess_sup f μ + snorm_ess_sup g μ :=
begin
refine le_trans (ess_sup_mono_ae (eventually_of_forall (λ x, _)))
(ennreal.ess_sup_add_le _ _),
simp_rw [pi.add_apply, ←ennreal.coe_add, ennreal.coe_le_coe],
exact nnnorm_add_le _ _,
end
lemma snorm_add_le {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) (hp1 : 1 ≤ p) :
snorm (f + g) p μ ≤ snorm f p μ + snorm g p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_add_le], },
have hp1_real : 1 ≤ p.to_real,
by rwa [← ennreal.one_to_real, ennreal.to_real_le_to_real ennreal.one_ne_top hp_top],
repeat { rw snorm_eq_snorm' hp0 hp_top, },
exact snorm'_add_le hf hg hp1_real,
end
lemma snorm_sub_le {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) (hp1 : 1 ≤ p) :
snorm (f - g) p μ ≤ snorm f p μ + snorm g p μ :=
calc snorm (f - g) p μ = snorm (f + - g) p μ : by rw sub_eq_add_neg
-- We cannot use snorm_add_le on f and (-g) because we don't have `ae_measurable (-g) μ`, since
-- we don't suppose `[borel_space E]`.
... = snorm (λ x, ∥f x + - g x∥) p μ : (snorm_norm (f + - g)).symm
... ≤ snorm (λ x, ∥f x∥ + ∥- g x∥) p μ : by
{ refine snorm_mono_real (λ x, _), rw norm_norm, exact norm_add_le _ _, }
... = snorm (λ x, ∥f x∥ + ∥g x∥) p μ : by simp_rw norm_neg
... ≤ snorm (λ x, ∥f x∥) p μ + snorm (λ x, ∥g x∥) p μ : snorm_add_le hf.norm hg.norm hp1
... = snorm f p μ + snorm g p μ : by rw [← snorm_norm f, ← snorm_norm g]
lemma snorm_add_lt_top_of_one_le {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ)
(hq1 : 1 ≤ p) : snorm (f + g) p μ < ∞ :=
lt_of_le_of_lt (snorm_add_le hf.1 hg.1 hq1) (ennreal.add_lt_top.mpr ⟨hf.2, hg.2⟩)
lemma snorm'_add_lt_top_of_le_one {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ)
(hf_snorm : snorm' f q μ < ∞) (hg_snorm : snorm' g q μ < ∞) (hq_pos : 0 < q) (hq1 : q ≤ 1) :
snorm' (f + g) q μ < ∞ :=
calc (∫⁻ a, ↑(nnnorm ((f + g) a)) ^ q ∂μ) ^ (1 / q)
≤ (∫⁻ a, (((λ a, (nnnorm (f a) : ℝ≥0∞))
+ (λ a, (nnnorm (g a) : ℝ≥0∞))) a) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow _ (by simp [hq_pos.le] : 0 ≤ 1 / q),
refine lintegral_mono (λ a, ennreal.rpow_le_rpow _ hq_pos.le),
simp [←ennreal.coe_add, nnnorm_add_le],
end
... ≤ (∫⁻ a, (nnnorm (f a) : ℝ≥0∞) ^ q + (nnnorm (g a) : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow (lintegral_mono (λ a, _)) (by simp [hq_pos.le] : 0 ≤ 1 / q),
exact ennreal.rpow_add_le_add_rpow _ _ hq_pos hq1,
end
... < ∞ :
begin
refine ennreal.rpow_lt_top_of_nonneg (by simp [hq_pos.le] : 0 ≤ 1 / q) _,
rw [lintegral_add' (hf.ennnorm.pow_const q)
(hg.ennnorm.pow_const q), ennreal.add_ne_top, ←lt_top_iff_ne_top,
←lt_top_iff_ne_top],
exact ⟨lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top hq_pos hf_snorm,
lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top hq_pos hg_snorm⟩,
end
lemma snorm_add_lt_top {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
snorm (f + g) p μ < ∞ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
rw ←ne.def at h0,
cases le_total 1 p with hp1 hp1,
{ exact snorm_add_lt_top_of_one_le hf hg hp1, },
have hp_top : p ≠ ∞, from (lt_of_le_of_lt hp1 ennreal.coe_lt_top).ne,
have hp_pos : 0 < p.to_real,
{ rw [← ennreal.zero_to_real, @ennreal.to_real_lt_to_real 0 p ennreal.coe_ne_top hp_top],
exact ((zero_le p).lt_of_ne h0.symm), },
have hp1_real : p.to_real ≤ 1,
{ rwa [← ennreal.one_to_real, @ennreal.to_real_le_to_real p 1 hp_top ennreal.coe_ne_top], },
rw snorm_eq_snorm' h0 hp_top,
rw [mem_ℒp, snorm_eq_snorm' h0 hp_top] at hf hg,
exact snorm'_add_lt_top_of_le_one hf.1 hg.1 hf.2 hg.2 hp_pos hp1_real,
end
section trim
lemma snorm'_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm' f q (ν.trim hm) = snorm' f q ν :=
begin
simp_rw snorm',
congr' 1,
refine lintegral_trim hm _,
refine @measurable.pow_const _ _ _ _ _ _ _ m _ (@measurable.coe_nnreal_ennreal _ m _ _) _,
exact @measurable.nnnorm E _ _ _ _ m _ hf,
end
lemma limsup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : @measurable _ _ m _ f) :
(ν.trim hm).ae.limsup f = ν.ae.limsup f :=
begin
simp_rw limsup_eq,
suffices h_set_eq : {a : ℝ≥0∞ | ∀ᵐ n ∂(ν.trim hm), f n ≤ a} = {a : ℝ≥0∞ | ∀ᵐ n ∂ν, f n ≤ a},
by rw h_set_eq,
ext1 a,
suffices h_meas_eq : ν {x | ¬ f x ≤ a} = ν.trim hm {x | ¬ f x ≤ a},
by simp_rw [set.mem_set_of_eq, ae_iff, h_meas_eq],
refine (trim_measurable_set_eq hm _).symm,
refine @measurable_set.compl _ _ m (@measurable_set_le ℝ≥0∞ _ _ _ _ m _ _ _ _ _ hf _),
exact @measurable_const _ _ _ m _,
end
lemma ess_sup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : @measurable _ _ m _ f) :
ess_sup f (ν.trim hm) = ess_sup f ν :=
by { simp_rw ess_sup, exact limsup_trim hm hf, }
lemma snorm_ess_sup_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm_ess_sup f (ν.trim hm) = snorm_ess_sup f ν :=
ess_sup_trim hm (@measurable.coe_nnreal_ennreal _ m _ (@measurable.nnnorm E _ _ _ _ m _ hf))
lemma snorm_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm f p (ν.trim hm) = snorm f p ν :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simpa only [h_top, snorm_exponent_top] using snorm_ess_sup_trim hm hf, },
simpa only [snorm_eq_snorm' h0 h_top] using snorm'_trim hm hf,
end
lemma snorm_trim_ae (hm : m ≤ m0) {f : α → E} (hf : ae_measurable f (ν.trim hm)) :
snorm f p (ν.trim hm) = snorm f p ν :=
begin
rw [snorm_congr_ae hf.ae_eq_mk, snorm_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk)],
exact snorm_trim hm hf.measurable_mk,
end
lemma mem_ℒp_of_mem_ℒp_trim (hm : m ≤ m0) {f : α → E} (hf : mem_ℒp f p (ν.trim hm)) :
mem_ℒp f p ν :=
⟨ae_measurable_of_ae_measurable_trim hm hf.1, (le_of_eq (snorm_trim_ae hm hf.1).symm).trans_lt hf.2⟩
end trim
end opens_measurable_space
@[simp] lemma snorm'_neg {f : α → F} : snorm' (-f) q μ = snorm' f q μ := by simp [snorm']
@[simp] lemma snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup], },
simp [snorm_eq_snorm' h0 h_top],
end
section borel_space
variable [borel_space E]
lemma mem_ℒp.neg {f : α → E} (hf : mem_ℒp f p μ) : mem_ℒp (-f) p μ :=
⟨ae_measurable.neg hf.1, by simp [hf.right]⟩
lemma mem_ℒp_neg_iff {f : α → E} : mem_ℒp (-f) p μ ↔ mem_ℒp f p μ :=
⟨λ h, neg_neg f ▸ h.neg, mem_ℒp.neg⟩
lemma snorm'_le_snorm'_mul_rpow_measure_univ {p q : ℝ} (hp0_lt : 0 < p) (hpq : p ≤ q)
{f : α → E} (hf : ae_measurable f μ) :
snorm' f p μ ≤ snorm' f q μ * (μ set.univ) ^ (1/p - 1/q) :=
begin
have hq0_lt : 0 < q, from lt_of_lt_of_le hp0_lt hpq,
by_cases hpq_eq : p = q,
{ rw [hpq_eq, sub_self, ennreal.rpow_zero, mul_one],
exact le_refl _, },
have hpq : p < q, from lt_of_le_of_ne hpq hpq_eq,
let g := λ a : α, (1 : ℝ≥0∞),
have h_rw : ∫⁻ a, ↑(nnnorm (f a))^p ∂ μ = ∫⁻ a, (nnnorm (f a) * (g a))^p ∂ μ,
from lintegral_congr (λ a, by simp),
repeat {rw snorm'},
rw h_rw,
let r := p * q / (q - p),
have hpqr : 1/p = 1/q + 1/r,
{ field_simp [(ne_of_lt hp0_lt).symm,
(ne_of_lt hq0_lt).symm],
ring, },
calc (∫⁻ (a : α), (↑(nnnorm (f a)) * g a) ^ p ∂μ) ^ (1/p)
≤ (∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ) ^ (1/q) * (∫⁻ (a : α), (g a) ^ r ∂μ) ^ (1/r) :
ennreal.lintegral_Lp_mul_le_Lq_mul_Lr hp0_lt hpq hpqr μ hf.ennnorm
ae_measurable_const
... = (∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ) ^ (1/q) * μ set.univ ^ (1/p - 1/q) :
by simp [hpqr],
end
lemma snorm'_le_snorm_ess_sup_mul_rpow_measure_univ (hq_pos : 0 < q) {f : α → F} :
snorm' f q μ ≤ snorm_ess_sup f μ * (μ set.univ) ^ (1/q) :=
begin
have h_le : ∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ ≤ ∫⁻ (a : α), (snorm_ess_sup f μ) ^ q ∂μ,
{ refine lintegral_mono_ae _,
have h_nnnorm_le_snorm_ess_sup := coe_nnnorm_ae_le_snorm_ess_sup f μ,
refine h_nnnorm_le_snorm_ess_sup.mono (λ x hx, ennreal.rpow_le_rpow hx (le_of_lt hq_pos)), },
rw [snorm', ←ennreal.rpow_one (snorm_ess_sup f μ)],
nth_rewrite 1 ←mul_inv_cancel (ne_of_lt hq_pos).symm,
rw [ennreal.rpow_mul, one_div,
←ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ q⁻¹)],
refine ennreal.rpow_le_rpow _ (by simp [hq_pos.le]),
rwa lintegral_const at h_le,
end
lemma snorm_le_snorm_mul_rpow_measure_univ {p q : ℝ≥0∞} (hpq : p ≤ q) {f : α → E}
(hf : ae_measurable f μ) :
snorm f p μ ≤ snorm f q μ * (μ set.univ) ^ (1/p.to_real - 1/q.to_real) :=
begin
by_cases hp0 : p = 0,
{ simp [hp0, zero_le], },
rw ← ne.def at hp0,
have hp0_lt : 0 < p, from lt_of_le_of_ne (zero_le _) hp0.symm,
have hq0_lt : 0 < q, from lt_of_lt_of_le hp0_lt hpq,
by_cases hq_top : q = ∞,
{ simp only [hq_top, div_zero, one_div, ennreal.top_to_real, sub_zero, snorm_exponent_top,
inv_zero],
by_cases hp_top : p = ∞,
{ simp only [hp_top, ennreal.rpow_zero, mul_one, ennreal.top_to_real, sub_zero, inv_zero,
snorm_exponent_top],
exact le_rfl, },
rw snorm_eq_snorm' hp0 hp_top,
have hp_pos : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp0_lt, hp_top⟩,
refine (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hp_pos).trans (le_of_eq _),
congr,
exact one_div _, },
have hp_lt_top : p < ∞, from hpq.trans_lt (lt_top_iff_ne_top.mpr hq_top),
have hp_pos : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp0_lt, hp_lt_top.ne⟩,
rw [snorm_eq_snorm' hp0_lt.ne.symm hp_lt_top.ne, snorm_eq_snorm' hq0_lt.ne.symm hq_top],
have hpq_real : p.to_real ≤ q.to_real, by rwa ennreal.to_real_le_to_real hp_lt_top.ne hq_top,
exact snorm'_le_snorm'_mul_rpow_measure_univ hp_pos hpq_real hf,
end
lemma snorm'_le_snorm'_of_exponent_le {m : measurable_space α} {p q : ℝ} (hp0_lt : 0 < p)
(hpq : p ≤ q) (μ : measure α) [is_probability_measure μ] {f : α → E} (hf : ae_measurable f μ) :
snorm' f p μ ≤ snorm' f q μ :=
begin
have h_le_μ := snorm'_le_snorm'_mul_rpow_measure_univ hp0_lt hpq hf,
rwa [measure_univ, ennreal.one_rpow, mul_one] at h_le_μ,
end
lemma snorm'_le_snorm_ess_sup (hq_pos : 0 < q) {f : α → F} [is_probability_measure μ] :
snorm' f q μ ≤ snorm_ess_sup f μ :=
le_trans (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hq_pos) (le_of_eq (by simp [measure_univ]))
lemma snorm_le_snorm_of_exponent_le {p q : ℝ≥0∞} (hpq : p ≤ q) [is_probability_measure μ]
{f : α → E} (hf : ae_measurable f μ) :
snorm f p μ ≤ snorm f q μ :=
(snorm_le_snorm_mul_rpow_measure_univ hpq hf).trans (le_of_eq (by simp [measure_univ]))
lemma snorm'_lt_top_of_snorm'_lt_top_of_exponent_le {p q : ℝ} [is_finite_measure μ] {f : α → E}
(hf : ae_measurable f μ) (hfq_lt_top : snorm' f q μ < ∞) (hp_nonneg : 0 ≤ p) (hpq : p ≤ q) :
snorm' f p μ < ∞ :=
begin
cases le_or_lt p 0 with hp_nonpos hp_pos,
{ rw le_antisymm hp_nonpos hp_nonneg,
simp, },
have hq_pos : 0 < q, from lt_of_lt_of_le hp_pos hpq,
calc snorm' f p μ
≤ snorm' f q μ * (μ set.univ) ^ (1/p - 1/q) :
snorm'_le_snorm'_mul_rpow_measure_univ hp_pos hpq hf
... < ∞ :
begin
rw ennreal.mul_lt_top_iff,
refine or.inl ⟨hfq_lt_top, ennreal.rpow_lt_top_of_nonneg _ (measure_ne_top μ set.univ)⟩,
rwa [le_sub, sub_zero, one_div, one_div, inv_le_inv hq_pos hp_pos],
end
end
lemma mem_ℒp.mem_ℒp_of_exponent_le {p q : ℝ≥0∞} [is_finite_measure μ] {f : α → E}
(hfq : mem_ℒp f q μ) (hpq : p ≤ q) :
mem_ℒp f p μ :=
begin
cases hfq with hfq_m hfq_lt_top,
by_cases hp0 : p = 0,
{ rwa [hp0, mem_ℒp_zero_iff_ae_measurable], },
rw ←ne.def at hp0,
refine ⟨hfq_m, _⟩,
by_cases hp_top : p = ∞,
{ have hq_top : q = ∞,
by rwa [hp_top, top_le_iff] at hpq,
rw [hp_top],
rwa hq_top at hfq_lt_top, },
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp0.symm, hp_top⟩,
by_cases hq_top : q = ∞,
{ rw snorm_eq_snorm' hp0 hp_top,
rw [hq_top, snorm_exponent_top] at hfq_lt_top,
refine lt_of_le_of_lt (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hp_pos) _,
refine ennreal.mul_lt_top hfq_lt_top.ne _,
exact (ennreal.rpow_lt_top_of_nonneg (by simp [hp_pos.le]) (measure_ne_top μ set.univ)).ne },
have hq0 : q ≠ 0,
{ by_contra hq_eq_zero,
have hp_eq_zero : p = 0, from le_antisymm (by rwa hq_eq_zero at hpq) (zero_le _),
rw [hp_eq_zero, ennreal.zero_to_real] at hp_pos,
exact (lt_irrefl _) hp_pos, },
have hpq_real : p.to_real ≤ q.to_real, by rwa ennreal.to_real_le_to_real hp_top hq_top,
rw snorm_eq_snorm' hp0 hp_top,
rw snorm_eq_snorm' hq0 hq_top at hfq_lt_top,
exact snorm'_lt_top_of_snorm'_lt_top_of_exponent_le hfq_m hfq_lt_top (le_of_lt hp_pos) hpq_real,
end
lemma snorm'_sum_le [second_countable_topology E] {ι} {f : ι → α → E} {s : finset ι}
(hfs : ∀ i, i ∈ s → ae_measurable (f i) μ) (hq1 : 1 ≤ q) :
snorm' (∑ i in s, f i) q μ ≤ ∑ i in s, snorm' (f i) q μ :=
finset.le_sum_of_subadditive_on_pred (λ (f : α → E), snorm' f q μ)
(λ f, ae_measurable f μ) (snorm'_zero (zero_lt_one.trans_le hq1))
(λ f g hf hg, snorm'_add_le hf hg hq1) (λ x y, ae_measurable.add) _ hfs
lemma snorm_sum_le [second_countable_topology E] {ι} {f : ι → α → E} {s : finset ι}
(hfs : ∀ i, i ∈ s → ae_measurable (f i) μ) (hp1 : 1 ≤ p) :
snorm (∑ i in s, f i) p μ ≤ ∑ i in s, snorm (f i) p μ :=
finset.le_sum_of_subadditive_on_pred (λ (f : α → E), snorm f p μ)
(λ f, ae_measurable f μ) snorm_zero (λ f g hf hg, snorm_add_le hf hg hp1)
(λ x y, ae_measurable.add) _ hfs
section second_countable_topology
variable [second_countable_topology E]
lemma mem_ℒp.add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) : mem_ℒp (f + g) p μ :=
⟨ae_measurable.add hf.1 hg.1, snorm_add_lt_top hf hg⟩
lemma mem_ℒp.sub {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) : mem_ℒp (f - g) p μ :=
by { rw sub_eq_add_neg, exact hf.add hg.neg }
lemma mem_ℒp_finset_sum {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, mem_ℒp (f i) p μ) :
mem_ℒp (λ a, ∑ i in s, f i a) p μ :=
begin
haveI : decidable_eq ι := classical.dec_eq _,
revert hf,
refine finset.induction_on s _ _,
{ simp only [zero_mem_ℒp', finset.sum_empty, implies_true_iff], },
{ intros i s his ih hf,
simp only [his, finset.sum_insert, not_false_iff],
exact (hf i (s.mem_insert_self i)).add (ih (λ j hj, hf j (finset.mem_insert_of_mem hj))), },
end
end second_countable_topology
end borel_space
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F]
lemma snorm'_const_smul {f : α → F} (c : 𝕜) (hq_pos : 0 < q) :
snorm' (c • f) q μ = (nnnorm c : ℝ≥0∞) * snorm' f q μ :=
begin
rw snorm',
simp_rw [pi.smul_apply, nnnorm_smul, ennreal.coe_mul,
ennreal.mul_rpow_of_nonneg _ _ hq_pos.le],
suffices h_integral : ∫⁻ a, ↑(nnnorm c) ^ q * ↑(nnnorm (f a)) ^ q ∂μ
= (nnnorm c : ℝ≥0∞)^q * ∫⁻ a, (nnnorm (f a)) ^ q ∂μ,
{ apply_fun (λ x, x ^ (1/q)) at h_integral,
rw [h_integral, ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)],
congr,
simp_rw [←ennreal.rpow_mul, one_div, mul_inv_cancel hq_pos.ne.symm, ennreal.rpow_one], },
rw lintegral_const_mul',
rw ennreal.coe_rpow_of_nonneg _ hq_pos.le,
exact ennreal.coe_ne_top,
end
lemma snorm_ess_sup_const_smul {f : α → F} (c : 𝕜) :
snorm_ess_sup (c • f) μ = (nnnorm c : ℝ≥0∞) * snorm_ess_sup f μ :=
by simp_rw [snorm_ess_sup, pi.smul_apply, nnnorm_smul, ennreal.coe_mul, ennreal.ess_sup_const_mul]
lemma snorm_const_smul {f : α → F} (c : 𝕜) :
snorm (c • f) p μ = (nnnorm c : ℝ≥0∞) * snorm f p μ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup_const_smul], },
repeat { rw snorm_eq_snorm' h0 h_top, },
rw ←ne.def at h0,
exact snorm'_const_smul c
(ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩),
end
lemma mem_ℒp.const_smul [measurable_space 𝕜] [opens_measurable_space 𝕜] [borel_space E] {f : α → E}
(hf : mem_ℒp f p μ) (c : 𝕜) :
mem_ℒp (c • f) p μ :=
⟨ae_measurable.const_smul hf.1 c,
(snorm_const_smul c).le.trans_lt (ennreal.mul_lt_top ennreal.coe_ne_top hf.2.ne)⟩
lemma mem_ℒp.const_mul [measurable_space 𝕜] [borel_space 𝕜]
{f : α → 𝕜} (hf : mem_ℒp f p μ) (c : 𝕜) : mem_ℒp (λ x, c * f x) p μ :=
hf.const_smul c
lemma snorm'_smul_le_mul_snorm' [opens_measurable_space E] [measurable_space 𝕜]
[opens_measurable_space 𝕜] {p q r : ℝ}
{f : α → E} (hf : ae_measurable f μ) {φ : α → 𝕜} (hφ : ae_measurable φ μ)
(hp0_lt : 0 < p) (hpq : p < q) (hpqr : 1/p = 1/q + 1/r) :
snorm' (φ • f) p μ ≤ snorm' φ q μ * snorm' f r μ :=
begin
simp_rw [snorm', pi.smul_apply', nnnorm_smul, ennreal.coe_mul],
exact ennreal.lintegral_Lp_mul_le_Lq_mul_Lr hp0_lt hpq hpqr μ hφ.ennnorm
hf.ennnorm,
end
end normed_space
section monotonicity
lemma snorm_le_mul_snorm_aux_of_nonneg {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (hc : 0 ≤ c) (p : ℝ≥0∞) :
snorm f p μ ≤ (ennreal.of_real c) * snorm g p μ :=
begin
lift c to ℝ≥0 using hc,
rw [ennreal.of_real_coe_nnreal, ← c.nnnorm_eq, ← snorm_norm g, ← snorm_const_smul (c : ℝ)],
swap, apply_instance,
refine snorm_mono_ae _,
simpa
end
lemma snorm_le_mul_snorm_aux_of_neg {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (hc : c < 0) (p : ℝ≥0∞) :
snorm f p μ = 0 ∧ snorm g p μ = 0 :=
begin
suffices : f =ᵐ[μ] 0 ∧ g =ᵐ[μ] 0,
by simp [snorm_congr_ae this.1, snorm_congr_ae this.2],
refine ⟨h.mono $ λ x hx, _, h.mono $ λ x hx, _⟩,
{ refine norm_le_zero_iff.1 (hx.trans _),
exact mul_nonpos_of_nonpos_of_nonneg hc.le (norm_nonneg _) },
{ refine norm_le_zero_iff.1 (nonpos_of_mul_nonneg_right _ hc),
exact (norm_nonneg _).trans hx }
end
lemma snorm_le_mul_snorm_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (p : ℝ≥0∞) :
snorm f p μ ≤ (ennreal.of_real c) * snorm g p μ :=
begin
cases le_or_lt 0 c with hc hc,
{ exact snorm_le_mul_snorm_aux_of_nonneg h hc p },
{ simp [snorm_le_mul_snorm_aux_of_neg h hc p] }
end
lemma mem_ℒp.of_le_mul [measurable_space F] {f : α → E} {g : α → F} {c : ℝ}
(hg : mem_ℒp g p μ) (hf : ae_measurable f μ) (hfg : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) :
mem_ℒp f p μ :=
begin
simp only [mem_ℒp, hf, true_and],
apply lt_of_le_of_lt (snorm_le_mul_snorm_of_ae_le_mul hfg p),
simp [lt_top_iff_ne_top, hg.snorm_ne_top],
end
end monotonicity
section is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜] {f : α → 𝕜}
lemma mem_ℒp.re (hf : mem_ℒp f p μ) : mem_ℒp (λ x, is_R_or_C.re (f x)) p μ :=
begin
have : ∀ x, ∥is_R_or_C.re (f x)∥ ≤ 1 * ∥f x∥,
by { intro x, rw one_mul, exact is_R_or_C.norm_re_le_norm (f x), },
exact hf.of_le_mul hf.1.re (eventually_of_forall this),
end
lemma mem_ℒp.im (hf : mem_ℒp f p μ) : mem_ℒp (λ x, is_R_or_C.im (f x)) p μ :=
begin
have : ∀ x, ∥is_R_or_C.im (f x)∥ ≤ 1 * ∥f x∥,
by { intro x, rw one_mul, exact is_R_or_C.norm_im_le_norm (f x), },
exact hf.of_le_mul hf.1.im (eventually_of_forall this),
end
end is_R_or_C
section inner_product
variables {E' 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [borel_space 𝕜]
[inner_product_space 𝕜 E']
[measurable_space E'] [opens_measurable_space E'] [second_countable_topology E']
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E' _ x y
lemma mem_ℒp.const_inner (c : E') {f : α → E'} (hf : mem_ℒp f p μ) :
mem_ℒp (λ a, ⟪c, f a⟫) p μ :=
hf.of_le_mul (ae_measurable.inner ae_measurable_const hf.1)
(eventually_of_forall (λ x, norm_inner_le_norm _ _))
lemma mem_ℒp.inner_const {f : α → E'} (hf : mem_ℒp f p μ) (c : E') :
mem_ℒp (λ a, ⟪f a, c⟫) p μ :=
hf.of_le_mul (ae_measurable.inner hf.1 ae_measurable_const)
(eventually_of_forall (λ x, by { rw mul_comm, exact norm_inner_le_norm _ _, }))
end inner_product
end ℒp
/-!
### Lp space
The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`.
-/
@[simp] lemma snorm_ae_eq_fun {α E : Type*} [measurable_space α] {μ : measure α}
[measurable_space E] [normed_group E] {p : ℝ≥0∞} {f : α → E} (hf : ae_measurable f μ) :
snorm (ae_eq_fun.mk f hf) p μ = snorm f p μ :=
snorm_congr_ae (ae_eq_fun.coe_fn_mk _ _)
lemma mem_ℒp.snorm_mk_lt_top {α E : Type*} [measurable_space α] {μ : measure α}
[measurable_space E] [normed_group E] {p : ℝ≥0∞} {f : α → E} (hfp : mem_ℒp f p μ) :
snorm (ae_eq_fun.mk f hfp.1) p μ < ∞ :=
by simp [hfp.2]
/-- Lp space -/
def Lp {α} (E : Type*) {m : measurable_space α} [measurable_space E] [normed_group E]
[borel_space E] [second_countable_topology E]
(p : ℝ≥0∞) (μ : measure α) : add_subgroup (α →ₘ[μ] E) :=
{ carrier := {f | snorm f p μ < ∞},
zero_mem' := by simp [snorm_congr_ae ae_eq_fun.coe_fn_zero, snorm_zero],
add_mem' := λ f g hf hg, by simp [snorm_congr_ae (ae_eq_fun.coe_fn_add _ _),
snorm_add_lt_top ⟨f.ae_measurable, hf⟩ ⟨g.ae_measurable, hg⟩],
neg_mem' := λ f hf,
by rwa [set.mem_set_of_eq, snorm_congr_ae (ae_eq_fun.coe_fn_neg _), snorm_neg] }
localized "notation α ` →₁[`:25 μ `] ` E := measure_theory.Lp E 1 μ" in measure_theory
localized "notation α ` →₂[`:25 μ `] ` E := measure_theory.Lp E 2 μ" in measure_theory
namespace mem_ℒp
variables [borel_space E] [second_countable_topology E]
/-- make an element of Lp from a function verifying `mem_ℒp` -/
def to_Lp (f : α → E) (h_mem_ℒp : mem_ℒp f p μ) : Lp E p μ :=
⟨ae_eq_fun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩
lemma coe_fn_to_Lp {f : α → E} (hf : mem_ℒp f p μ) : hf.to_Lp f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk _ _
@[simp] lemma to_Lp_eq_to_Lp_iff {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
hf.to_Lp f = hg.to_Lp g ↔ f =ᵐ[μ] g :=
by simp [to_Lp]
@[simp] lemma to_Lp_zero (h : mem_ℒp (0 : α → E) p μ) : h.to_Lp 0 = 0 := rfl
lemma to_Lp_add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
(hf.add hg).to_Lp (f + g) = hf.to_Lp f + hg.to_Lp g := rfl
lemma to_Lp_neg {f : α → E} (hf : mem_ℒp f p μ) : hf.neg.to_Lp (-f) = - hf.to_Lp f := rfl
lemma to_Lp_sub {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
(hf.sub hg).to_Lp (f - g) = hf.to_Lp f - hg.to_Lp g := rfl
end mem_ℒp
namespace Lp
variables [borel_space E] [second_countable_topology E]
instance : has_coe_to_fun (Lp E p μ) (λ _, α → E) := ⟨λ f, ((f : α →ₘ[μ] E) : α → E)⟩
@[ext] lemma ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g :=
begin
cases f,
cases g,
simp only [subtype.mk_eq_mk],
exact ae_eq_fun.ext h
end
lemma ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g :=
⟨λ h, by rw h, λ h, ext h⟩
lemma mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := iff.refl _
lemma mem_Lp_iff_mem_ℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ mem_ℒp f p μ :=
by simp [mem_Lp_iff_snorm_lt_top, mem_ℒp, f.measurable.ae_measurable]
protected lemma antitone [is_finite_measure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ :=
λ f hf, (mem_ℒp.mem_ℒp_of_exponent_le ⟨f.ae_measurable, hf⟩ hpq).2
@[simp] lemma coe_fn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) :
((⟨f, hf⟩ : Lp E p μ) : α → E) = f := rfl
@[simp] lemma coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) :
((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f := rfl
@[simp] lemma to_Lp_coe_fn (f : Lp E p μ) (hf : mem_ℒp f p μ) : hf.to_Lp f = f :=
by { cases f, simp [mem_ℒp.to_Lp] }
lemma snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ := f.prop
lemma snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ := (snorm_lt_top f).ne
@[measurability]
protected lemma measurable (f : Lp E p μ) : measurable f := f.val.measurable
@[measurability]
protected lemma ae_measurable (f : Lp E p μ) : ae_measurable f μ := f.val.ae_measurable
protected lemma mem_ℒp (f : Lp E p μ) : mem_ℒp f p μ := ⟨Lp.ae_measurable f, f.prop⟩
variables (E p μ)
lemma coe_fn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 := ae_eq_fun.coe_fn_zero
variables {E p μ}
lemma coe_fn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f := ae_eq_fun.coe_fn_neg _
lemma coe_fn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g := ae_eq_fun.coe_fn_add _ _
lemma coe_fn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g := ae_eq_fun.coe_fn_sub _ _
lemma mem_Lp_const (α) {m : measurable_space α} (μ : measure α) (c : E) [is_finite_measure μ] :
@ae_eq_fun.const α _ _ μ _ c ∈ Lp E p μ :=
(mem_ℒp_const c).snorm_mk_lt_top
instance : has_norm (Lp E p μ) := { norm := λ f, ennreal.to_real (snorm f p μ) }
instance : has_dist (Lp E p μ) := { dist := λ f g, ∥f - g∥}
instance : has_edist (Lp E p μ) := { edist := λ f g, ennreal.of_real (dist f g) }
lemma norm_def (f : Lp E p μ) : ∥f∥ = ennreal.to_real (snorm f p μ) := rfl
@[simp] lemma norm_to_Lp (f : α → E) (hf : mem_ℒp f p μ) :
∥hf.to_Lp f∥ = ennreal.to_real (snorm f p μ) :=
by rw [norm_def, snorm_congr_ae (mem_ℒp.coe_fn_to_Lp hf)]
lemma dist_def (f g : Lp E p μ) : dist f g = (snorm (f - g) p μ).to_real :=
begin
simp_rw [dist, norm_def],
congr' 1,
apply snorm_congr_ae (coe_fn_sub _ _),
end
lemma edist_def (f g : Lp E p μ) : edist f g = snorm (f - g) p μ :=
begin
simp_rw [edist, dist, norm_def, ennreal.of_real_to_real (snorm_ne_top _)],
exact snorm_congr_ae (coe_fn_sub _ _)
end
@[simp] lemma edist_to_Lp_to_Lp (f g : α → E) (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
edist (hf.to_Lp f) (hg.to_Lp g) = snorm (f - g) p μ :=
by { rw edist_def, exact snorm_congr_ae (hf.coe_fn_to_Lp.sub hg.coe_fn_to_Lp) }
@[simp] lemma edist_to_Lp_zero (f : α → E) (hf : mem_ℒp f p μ) :
edist (hf.to_Lp f) 0 = snorm f p μ :=
by { convert edist_to_Lp_to_Lp f 0 hf zero_mem_ℒp, simp }
@[simp] lemma norm_zero : ∥(0 : Lp E p μ)∥ = 0 :=
begin
change (snorm ⇑(0 : α →ₘ[μ] E) p μ).to_real = 0,
simp [snorm_congr_ae ae_eq_fun.coe_fn_zero, snorm_zero]
end
lemma norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ∥f∥ = 0 ↔ f = 0 :=
begin
refine ⟨λ hf, _, λ hf, by simp [hf]⟩,
rw [norm_def, ennreal.to_real_eq_zero_iff] at hf,
cases hf,
{ rw snorm_eq_zero_iff (Lp.ae_measurable f) hp.ne.symm at hf,
exact subtype.eq (ae_eq_fun.ext (hf.trans ae_eq_fun.coe_fn_zero.symm)), },
{ exact absurd hf (snorm_ne_top f), },
end
lemma eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 :=
begin
split,
{ assume h,
rw h,
exact ae_eq_fun.coe_fn_const _ _ },
{ assume h,
ext1,
filter_upwards [h, ae_eq_fun.coe_fn_const α (0 : E)],
assume a ha h'a,
rw ha,
exact h'a.symm }
end
@[simp] lemma norm_neg {f : Lp E p μ} : ∥-f∥ = ∥f∥ :=
by rw [norm_def, norm_def, snorm_congr_ae (coe_fn_neg _), snorm_neg]
lemma norm_le_mul_norm_of_ae_le_mul
[second_countable_topology F] [measurable_space F] [borel_space F]
{c : ℝ} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) : ∥f∥ ≤ c * ∥g∥ :=
begin
by_cases pzero : p = 0,
{ simp [pzero, norm_def] },
cases le_or_lt 0 c with hc hc,
{ have := snorm_le_mul_snorm_aux_of_nonneg h hc p,
rw [← ennreal.to_real_le_to_real, ennreal.to_real_mul, ennreal.to_real_of_real hc] at this,
{ exact this },
{ exact (Lp.mem_ℒp _).snorm_ne_top },
{ simp [(Lp.mem_ℒp _).snorm_ne_top] } },
{ have := snorm_le_mul_snorm_aux_of_neg h hc p,
simp only [snorm_eq_zero_iff (Lp.ae_measurable _) pzero, ← eq_zero_iff_ae_eq_zero] at this,
simp [this] }
end
lemma norm_le_norm_of_ae_le [second_countable_topology F] [measurable_space F] [borel_space F]
{f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : ∥f∥ ≤ ∥g∥ :=
begin
rw [norm_def, norm_def, ennreal.to_real_le_to_real (snorm_ne_top _) (snorm_ne_top _)],
exact snorm_mono_ae h
end
lemma mem_Lp_of_ae_le_mul [second_countable_topology F] [measurable_space F] [borel_space F]
{c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) : f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_le_mul (Lp.mem_ℒp g) f.ae_measurable h
lemma mem_Lp_of_ae_le [second_countable_topology F] [measurable_space F] [borel_space F]
{f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_le (Lp.mem_ℒp g) f.ae_measurable h
lemma mem_Lp_of_ae_bound [is_finite_measure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_bound f.ae_measurable _ hfC
lemma norm_le_of_ae_bound [is_finite_measure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C)
(hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
∥f∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * C :=
begin
by_cases hμ : μ = 0,
{ by_cases hp : p.to_real⁻¹ = 0,
{ simpa [hp, hμ, norm_def] using hC },
{ simp [hμ, norm_def, real.zero_rpow hp] } },
let A : ℝ≥0 := (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * ⟨C, hC⟩,
suffices : snorm f p μ ≤ A,
{ exact ennreal.to_real_le_coe_of_le_coe this },
convert snorm_le_of_ae_bound hfC,
rw [← coe_measure_univ_nnreal μ, ennreal.coe_rpow_of_ne_zero (measure_univ_nnreal_pos hμ).ne',
ennreal.coe_mul],
congr,
rw max_eq_left hC
end
instance [hp : fact (1 ≤ p)] : normed_group (Lp E p μ) :=
normed_group.of_core _
{ norm_eq_zero_iff := λ f, norm_eq_zero_iff (ennreal.zero_lt_one.trans_le hp.1),
triangle := begin
assume f g,
simp only [norm_def],
rw ← ennreal.to_real_add (snorm_ne_top f) (snorm_ne_top g),
suffices h_snorm : snorm ⇑(f + g) p μ ≤ snorm ⇑f p μ + snorm ⇑g p μ,
{ rwa ennreal.to_real_le_to_real (snorm_ne_top (f + g)),
exact ennreal.add_ne_top.mpr ⟨snorm_ne_top f, snorm_ne_top g⟩, },
rw [snorm_congr_ae (coe_fn_add _ _)],
exact snorm_add_le (Lp.ae_measurable f) (Lp.ae_measurable g) hp.1,
end,
norm_neg := by simp }
instance normed_group_L1 : normed_group (Lp E 1 μ) := by apply_instance
instance normed_group_L2 : normed_group (Lp E 2 μ) := by apply_instance
instance normed_group_Ltop : normed_group (Lp E ∞ μ) := by apply_instance
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
lemma mem_Lp_const_smul (c : 𝕜) (f : Lp E p μ) : c • ↑f ∈ Lp E p μ :=
begin
rw [mem_Lp_iff_snorm_lt_top, snorm_congr_ae (ae_eq_fun.coe_fn_smul _ _), snorm_const_smul,
ennreal.mul_lt_top_iff],
exact or.inl ⟨ennreal.coe_lt_top, f.prop⟩,
end
variables (E p μ 𝕜)
/-- The `𝕜`-submodule of elements of `α →ₘ[μ] E` whose `Lp` norm is finite. This is `Lp E p μ`,
with extra structure. -/
def Lp_submodule : submodule 𝕜 (α →ₘ[μ] E) :=
{ smul_mem' := λ c f hf, by simpa using mem_Lp_const_smul c ⟨f, hf⟩,
.. Lp E p μ }
variables {E p μ 𝕜}
lemma coe_Lp_submodule : (Lp_submodule E p μ 𝕜).to_add_subgroup = Lp E p μ := rfl
instance : module 𝕜 (Lp E p μ) :=
{ .. (Lp_submodule E p μ 𝕜).module }
lemma coe_fn_smul (c : 𝕜) (f : Lp E p μ) : ⇑(c • f) =ᵐ[μ] c • f := ae_eq_fun.coe_fn_smul _ _
lemma norm_const_smul (c : 𝕜) (f : Lp E p μ) : ∥c • f∥ = ∥c∥ * ∥f∥ :=
by rw [norm_def, snorm_congr_ae (coe_fn_smul _ _), snorm_const_smul c,
ennreal.to_real_mul, ennreal.coe_to_real, coe_nnnorm, norm_def]
instance [fact (1 ≤ p)] : normed_space 𝕜 (Lp E p μ) :=
{ norm_smul_le := λ _ _, by simp [norm_const_smul] }
instance normed_space_L1 : normed_space 𝕜 (Lp E 1 μ) := by apply_instance
instance normed_space_L2 : normed_space 𝕜 (Lp E 2 μ) := by apply_instance
instance normed_space_Ltop : normed_space 𝕜 (Lp E ∞ μ) := by apply_instance
instance [normed_space ℝ E] [has_scalar ℝ 𝕜] [is_scalar_tower ℝ 𝕜 E] :
is_scalar_tower ℝ 𝕜 (Lp E p μ) :=
begin
refine ⟨λ r c f, _⟩,
ext1,
refine (Lp.coe_fn_smul _ _).trans _,
rw smul_assoc,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
refine (Lp.coe_fn_smul c f).mono (λ x hx, _),
rw [pi.smul_apply, pi.smul_apply, pi.smul_apply, hx, pi.smul_apply],
end
end normed_space
end Lp
namespace mem_ℒp
variables
[borel_space E] [second_countable_topology E]
{𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma to_Lp_const_smul {f : α → E} (c : 𝕜) (hf : mem_ℒp f p μ) :
(hf.const_smul c).to_Lp (c • f) = c • hf.to_Lp f := rfl
end mem_ℒp
/-! ### Indicator of a set as an element of Lᵖ
For a set `s` with `(hs : measurable_set s)` and `(hμs : μ s < ∞)`, we build
`indicator_const_Lp p hs hμs c`, the element of `Lp` corresponding to `s.indicator (λ x, c)`.
-/
section indicator
variables {s : set α} {hs : measurable_set s} {c : E} {f : α → E} {hf : ae_measurable f μ}
lemma snorm_ess_sup_indicator_le (s : set α) (f : α → G) :
snorm_ess_sup (s.indicator f) μ ≤ snorm_ess_sup f μ :=
begin
refine ess_sup_mono_ae (eventually_of_forall (λ x, _)),
rw [ennreal.coe_le_coe, nnnorm_indicator_eq_indicator_nnnorm],
exact set.indicator_le_self s _ x,
end
lemma snorm_ess_sup_indicator_const_le (s : set α) (c : G) :
snorm_ess_sup (s.indicator (λ x : α , c)) μ ≤ ∥c∥₊ :=
begin
by_cases hμ0 : μ = 0,
{ rw [hμ0, snorm_ess_sup_measure_zero, ennreal.coe_nonneg],
exact zero_le', },
{ exact (snorm_ess_sup_indicator_le s (λ x, c)).trans (snorm_ess_sup_const c hμ0).le, },
end
lemma snorm_ess_sup_indicator_const_eq (s : set α) (c : G) (hμs : μ s ≠ 0) :
snorm_ess_sup (s.indicator (λ x : α , c)) μ = ∥c∥₊ :=
begin
refine le_antisymm (snorm_ess_sup_indicator_const_le s c) _,
by_contra h,
push_neg at h,
have h' := ae_iff.mp (ae_lt_of_ess_sup_lt h),
push_neg at h',
refine hμs (measure_mono_null (λ x hx_mem, _) h'),
rw [set.mem_set_of_eq, set.indicator_of_mem hx_mem],
exact le_rfl,
end
variables (hs)
lemma snorm_indicator_le {E : Type*} [normed_group E] (f : α → E) :
snorm (s.indicator f) p μ ≤ snorm f p μ :=
begin
refine snorm_mono_ae (eventually_of_forall (λ x, _)),
suffices : ∥s.indicator f x∥₊ ≤ ∥f x∥₊,
{ exact nnreal.coe_mono this },
rw nnnorm_indicator_eq_indicator_nnnorm,
exact s.indicator_le_self _ x,
end
variables {hs}
lemma snorm_indicator_const {c : G} (hs : measurable_set s) (hp : p ≠ 0) (hp_top : p ≠ ∞) :
snorm (s.indicator (λ x, c)) p μ = ∥c∥₊ * (μ s) ^ (1 / p.to_real) :=
begin
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp.symm, hp_top⟩,
rw snorm_eq_lintegral_rpow_nnnorm hp hp_top,
simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ennreal.coe_indicator],
have h_indicator_pow : (λ a : α, s.indicator (λ (x : α), (∥c∥₊ : ℝ≥0∞)) a ^ p.to_real)
= s.indicator (λ (x : α), ↑∥c∥₊ ^ p.to_real),
{ rw set.comp_indicator_const (∥c∥₊ : ℝ≥0∞) (λ x, x ^ p.to_real) _,
simp [hp_pos], },
rw [h_indicator_pow, lintegral_indicator _ hs, set_lintegral_const, ennreal.mul_rpow_of_nonneg],
{ rw [← ennreal.rpow_mul, mul_one_div_cancel hp_pos.ne.symm, ennreal.rpow_one], },
{ simp [hp_pos.le], },
end
lemma snorm_indicator_const' {c : G} (hs : measurable_set s) (hμs : μ s ≠ 0) (hp : p ≠ 0) :
snorm (s.indicator (λ _, c)) p μ = ∥c∥₊ * (μ s) ^ (1 / p.to_real) :=
begin
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_indicator_const_eq s c hμs], },
{ exact snorm_indicator_const hs hp hp_top, },
end
lemma mem_ℒp.indicator (hs : measurable_set s) (hf : mem_ℒp f p μ) :
mem_ℒp (s.indicator f) p μ :=
⟨hf.ae_measurable.indicator hs, lt_of_le_of_lt (snorm_indicator_le f) hf.snorm_lt_top⟩
lemma snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict {f : α → F} (hs : measurable_set s) :
snorm_ess_sup (s.indicator f) μ = snorm_ess_sup f (μ.restrict s) :=
begin
simp_rw [snorm_ess_sup, nnnorm_indicator_eq_indicator_nnnorm, ennreal.coe_indicator],
by_cases hs_null : μ s = 0,
{ rw measure.restrict_zero_set hs_null,
simp only [ess_sup_measure_zero, ennreal.ess_sup_eq_zero_iff, ennreal.bot_eq_zero],
have hs_empty : s =ᵐ[μ] (∅ : set α), by { rw ae_eq_set, simpa using hs_null, },
refine (indicator_ae_eq_of_ae_eq_set hs_empty).trans _,
rw set.indicator_empty,
refl, },
rw ess_sup_indicator_eq_ess_sup_restrict (eventually_of_forall (λ x, _)) hs hs_null,
rw pi.zero_apply,
exact zero_le _,
end
lemma snorm_indicator_eq_snorm_restrict {f : α → F} (hs : measurable_set s) :
snorm (s.indicator f) p μ = snorm f p (μ.restrict s) :=
begin
by_cases hp_zero : p = 0,
{ simp only [hp_zero, snorm_exponent_zero], },
by_cases hp_top : p = ∞,
{ simp_rw [hp_top, snorm_exponent_top],
exact snorm_ess_sup_indicator_eq_snorm_ess_sup_restrict hs, },
simp_rw snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top,
suffices : ∫⁻ x, ∥s.indicator f x∥₊ ^ p.to_real ∂μ = ∫⁻ x in s, ∥f x∥₊ ^ p.to_real ∂μ,
by rw this,
rw ← lintegral_indicator _ hs,
congr,
simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ennreal.coe_indicator],
have h_zero : (λ x, x ^ p.to_real) (0 : ℝ≥0∞) = 0,
by simp [ennreal.to_real_pos_iff.mpr ⟨ne.bot_lt hp_zero, hp_top⟩],
exact (set.indicator_comp_of_zero h_zero).symm,
end
lemma mem_ℒp_indicator_iff_restrict (hs : measurable_set s) :
mem_ℒp (s.indicator f) p μ ↔ mem_ℒp f p (μ.restrict s) :=
by simp [mem_ℒp, ae_measurable_indicator_iff hs, snorm_indicator_eq_snorm_restrict hs]
lemma mem_ℒp_indicator_const (p : ℝ≥0∞) (hs : measurable_set s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) :
mem_ℒp (s.indicator (λ _, c)) p μ :=
begin
rw mem_ℒp_indicator_iff_restrict hs,
by_cases hp_zero : p = 0,
{ rw hp_zero, exact mem_ℒp_zero_iff_ae_measurable.mpr ae_measurable_const, },
by_cases hp_top : p = ∞,
{ rw hp_top,
exact mem_ℒp_top_of_bound ae_measurable_const (∥c∥) (eventually_of_forall (λ x, le_rfl)), },
rw [mem_ℒp_const_iff hp_zero hp_top, measure.restrict_apply_univ],
cases hμsc,
{ exact or.inl hμsc, },
{ exact or.inr hμsc.lt_top, },
end
end indicator
section indicator_const_Lp
open set function
variables {s : set α} {hs : measurable_set s} {hμs : μ s ≠ ∞} {c : E}
[borel_space E] [second_countable_topology E]
/-- Indicator of a set as an element of `Lp`. -/
def indicator_const_Lp (p : ℝ≥0∞) (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : E) : Lp E p μ :=
mem_ℒp.to_Lp (s.indicator (λ _, c)) (mem_ℒp_indicator_const p hs c (or.inr hμs))
lemma indicator_const_Lp_coe_fn : ⇑(indicator_const_Lp p hs hμs c) =ᵐ[μ] s.indicator (λ _, c) :=
mem_ℒp.coe_fn_to_Lp (mem_ℒp_indicator_const p hs c (or.inr hμs))
lemma indicator_const_Lp_coe_fn_mem :
∀ᵐ (x : α) ∂μ, x ∈ s → indicator_const_Lp p hs hμs c x = c :=
indicator_const_Lp_coe_fn.mono (λ x hx hxs, hx.trans (set.indicator_of_mem hxs _))
lemma indicator_const_Lp_coe_fn_nmem :
∀ᵐ (x : α) ∂μ, x ∉ s → indicator_const_Lp p hs hμs c x = 0 :=
indicator_const_Lp_coe_fn.mono (λ x hx hxs, hx.trans (set.indicator_of_not_mem hxs _))
lemma norm_indicator_const_Lp (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
∥indicator_const_Lp p hs hμs c∥ = ∥c∥ * (μ s).to_real ^ (1 / p.to_real) :=
by rw [Lp.norm_def, snorm_congr_ae indicator_const_Lp_coe_fn,
snorm_indicator_const hs hp_ne_zero hp_ne_top, ennreal.to_real_mul, ennreal.to_real_rpow,
ennreal.coe_to_real, coe_nnnorm]
lemma norm_indicator_const_Lp_top (hμs_ne_zero : μ s ≠ 0) : ∥indicator_const_Lp ∞ hs hμs c∥ = ∥c∥ :=
by rw [Lp.norm_def, snorm_congr_ae indicator_const_Lp_coe_fn,
snorm_indicator_const' hs hμs_ne_zero ennreal.top_ne_zero, ennreal.top_to_real, div_zero,
ennreal.rpow_zero, mul_one, ennreal.coe_to_real, coe_nnnorm]
lemma norm_indicator_const_Lp' (hp_pos : p ≠ 0) (hμs_pos : μ s ≠ 0) :
∥indicator_const_Lp p hs hμs c∥ = ∥c∥ * (μ s).to_real ^ (1 / p.to_real) :=
begin
by_cases hp_top : p = ∞,
{ rw [hp_top, ennreal.top_to_real, div_zero, real.rpow_zero, mul_one],
exact norm_indicator_const_Lp_top hμs_pos, },
{ exact norm_indicator_const_Lp hp_pos hp_top, },
end
@[simp] lemma indicator_const_empty :
indicator_const_Lp p measurable_set.empty (by simp : μ ∅ ≠ ∞) c = 0 :=
begin
rw Lp.eq_zero_iff_ae_eq_zero,
convert indicator_const_Lp_coe_fn,
simp [set.indicator_empty'],
end
lemma mem_ℒp_add_of_disjoint {f g : α → E}
(h : disjoint (support f) (support g)) (hf : measurable f) (hg : measurable g) :
mem_ℒp (f + g) p μ ↔ mem_ℒp f p μ ∧ mem_ℒp g p μ :=
begin
refine ⟨λ hfg, ⟨_, _⟩, λ h, h.1.add h.2⟩,
{ rw ← indicator_add_eq_left h, exact hfg.indicator (measurable_set_support hf) },
{ rw ← indicator_add_eq_right h, exact hfg.indicator (measurable_set_support hg) }
end
/-- The indicator of a disjoint union of two sets is the sum of the indicators of the sets. -/
lemma indicator_const_Lp_disjoint_union {s t : set α} (hs : measurable_set s)
(ht : measurable_set t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (c : E) :
(indicator_const_Lp p (hs.union ht) ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne c)
= indicator_const_Lp p hs hμs c + indicator_const_Lp p ht hμt c :=
begin
ext1,
refine indicator_const_Lp_coe_fn.trans (eventually_eq.trans _ (Lp.coe_fn_add _ _).symm),
refine eventually_eq.trans _
(eventually_eq.add indicator_const_Lp_coe_fn.symm indicator_const_Lp_coe_fn.symm),
rw set.indicator_union_of_disjoint (set.disjoint_iff_inter_eq_empty.mpr hst) _,
end
end indicator_const_Lp
end measure_theory
open measure_theory
/-!
### Composition on `L^p`
We show that Lipschitz functions vanishing at zero act by composition on `L^p`, and specialize
this to the composition with continuous linear maps, and to the definition of the positive
part of an `L^p` function.
-/
section composition
variables [second_countable_topology E] [borel_space E]
[second_countable_topology F] [measurable_space F] [borel_space F]
{g : E → F} {c : ℝ≥0}
lemma lipschitz_with.comp_mem_ℒp {α E F} {K} [measurable_space α] {μ : measure α}
[measurable_space E] [measurable_space F] [normed_group E] [normed_group F] [borel_space E]
[borel_space F] {f : α → E} {g : E → F} (hg : lipschitz_with K g)
(g0 : g 0 = 0) (hL : mem_ℒp f p μ) : mem_ℒp (g ∘ f) p μ :=
begin
have : ∀ᵐ x ∂μ, ∥g (f x)∥ ≤ K * ∥f x∥,
{ apply filter.eventually_of_forall (λ x, _),
rw [← dist_zero_right, ← dist_zero_right, ← g0],
apply hg.dist_le_mul },
exact hL.of_le_mul (hg.continuous.measurable.comp_ae_measurable hL.1) this,
end
lemma measure_theory.mem_ℒp.of_comp_antilipschitz_with {α E F} {K'}
[measurable_space α] {μ : measure α} [measurable_space E] [measurable_space F] [normed_group E]
[normed_group F] [borel_space E] [borel_space F] [complete_space E]
{f : α → E} {g : E → F} (hL : mem_ℒp (g ∘ f) p μ)
(hg : uniform_continuous g) (hg' : antilipschitz_with K' g) (g0 : g 0 = 0) : mem_ℒp f p μ :=
begin
have : ∀ᵐ x ∂μ, ∥f x∥ ≤ K' * ∥g (f x)∥,
{ apply filter.eventually_of_forall (λ x, _),
rw [← dist_zero_right, ← dist_zero_right, ← g0],
apply hg'.le_mul_dist },
exact hL.of_le_mul ((ae_measurable_comp_iff_of_closed_embedding g
(hg'.closed_embedding hg)).1 hL.1) this,
end
namespace lipschitz_with
lemma mem_ℒp_comp_iff_of_antilipschitz {α E F} {K K'} [measurable_space α] {μ : measure α}
[measurable_space E] [measurable_space F] [normed_group E] [normed_group F] [borel_space E]
[borel_space F] [complete_space E]
{f : α → E} {g : E → F} (hg : lipschitz_with K g) (hg' : antilipschitz_with K' g) (g0 : g 0 = 0) :
mem_ℒp (g ∘ f) p μ ↔ mem_ℒp f p μ :=
⟨λ h, h.of_comp_antilipschitz_with hg.uniform_continuous hg' g0, λ h, hg.comp_mem_ℒp g0 h⟩
/-- When `g` is a Lipschitz function sending `0` to `0` and `f` is in `Lp`, then `g ∘ f` is well
defined as an element of `Lp`. -/
def comp_Lp (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) : Lp F p μ :=
⟨ae_eq_fun.comp g hg.continuous.measurable (f : α →ₘ[μ] E),
begin
suffices : ∀ᵐ x ∂μ, ∥ae_eq_fun.comp g hg.continuous.measurable (f : α →ₘ[μ] E) x∥ ≤ c * ∥f x∥,
{ exact Lp.mem_Lp_of_ae_le_mul this },
filter_upwards [ae_eq_fun.coe_fn_comp g hg.continuous.measurable (f : α →ₘ[μ] E)],
assume a ha,
simp only [ha],
rw [← dist_zero_right, ← dist_zero_right, ← g0],
exact hg.dist_le_mul (f a) 0,
end⟩
lemma coe_fn_comp_Lp (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) :
hg.comp_Lp g0 f =ᵐ[μ] g ∘ f :=
ae_eq_fun.coe_fn_comp _ _ _
@[simp] lemma comp_Lp_zero (hg : lipschitz_with c g) (g0 : g 0 = 0) :
hg.comp_Lp g0 (0 : Lp E p μ) = 0 :=
begin
rw Lp.eq_zero_iff_ae_eq_zero,
apply (coe_fn_comp_Lp _ _ _).trans,
filter_upwards [Lp.coe_fn_zero E p μ],
assume a ha,
simp [ha, g0]
end
lemma norm_comp_Lp_sub_le (hg : lipschitz_with c g) (g0 : g 0 = 0) (f f' : Lp E p μ) :
∥hg.comp_Lp g0 f - hg.comp_Lp g0 f'∥ ≤ c * ∥f - f'∥ :=
begin
apply Lp.norm_le_mul_norm_of_ae_le_mul,
filter_upwards [hg.coe_fn_comp_Lp g0 f, hg.coe_fn_comp_Lp g0 f',
Lp.coe_fn_sub (hg.comp_Lp g0 f) (hg.comp_Lp g0 f'), Lp.coe_fn_sub f f'],
assume a ha1 ha2 ha3 ha4,
simp [ha1, ha2, ha3, ha4, ← dist_eq_norm],
exact hg.dist_le_mul (f a) (f' a)
end
lemma norm_comp_Lp_le (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) :
∥hg.comp_Lp g0 f∥ ≤ c * ∥f∥ :=
by simpa using hg.norm_comp_Lp_sub_le g0 f 0
lemma lipschitz_with_comp_Lp [fact (1 ≤ p)] (hg : lipschitz_with c g) (g0 : g 0 = 0) :
lipschitz_with c (hg.comp_Lp g0 : Lp E p μ → Lp F p μ) :=
lipschitz_with.of_dist_le_mul $ λ f g, by simp [dist_eq_norm, norm_comp_Lp_sub_le]
lemma continuous_comp_Lp [fact (1 ≤ p)] (hg : lipschitz_with c g) (g0 : g 0 = 0) :
continuous (hg.comp_Lp g0 : Lp E p μ → Lp F p μ) :=
(lipschitz_with_comp_Lp hg g0).continuous
end lipschitz_with
namespace continuous_linear_map
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F]
/-- Composing `f : Lp ` with `L : E →L[𝕜] F`. -/
def comp_Lp (L : E →L[𝕜] F) (f : Lp E p μ) : Lp F p μ :=
L.lipschitz.comp_Lp (map_zero L) f
lemma coe_fn_comp_Lp (L : E →L[𝕜] F) (f : Lp E p μ) :
∀ᵐ a ∂μ, (L.comp_Lp f) a = L (f a) :=
lipschitz_with.coe_fn_comp_Lp _ _ _
lemma coe_fn_comp_Lp' (L : E →L[𝕜] F) (f : Lp E p μ) :
L.comp_Lp f =ᵐ[μ] λ a, L (f a) :=
L.coe_fn_comp_Lp f
lemma comp_mem_ℒp (L : E →L[𝕜] F) (f : Lp E p μ) : mem_ℒp (L ∘ f) p μ :=
(Lp.mem_ℒp (L.comp_Lp f)).ae_eq (L.coe_fn_comp_Lp' f)
lemma comp_mem_ℒp' (L : E →L[𝕜] F) {f : α → E} (hf : mem_ℒp f p μ) : mem_ℒp (L ∘ f) p μ :=
(L.comp_mem_ℒp (hf.to_Lp f)).ae_eq (eventually_eq.fun_comp (hf.coe_fn_to_Lp) _)
section is_R_or_C
variables {K : Type*} [is_R_or_C K] [measurable_space K] [borel_space K]
lemma _root_.measure_theory.mem_ℒp.of_real
{f : α → ℝ} (hf : mem_ℒp f p μ) : mem_ℒp (λ x, (f x : K)) p μ :=
(@is_R_or_C.of_real_clm K _).comp_mem_ℒp' hf
lemma _root_.measure_theory.mem_ℒp_re_im_iff {f : α → K} :
mem_ℒp (λ x, is_R_or_C.re (f x)) p μ ∧ mem_ℒp (λ x, is_R_or_C.im (f x)) p μ ↔
mem_ℒp f p μ :=
begin
refine ⟨_, λ hf, ⟨hf.re, hf.im⟩⟩,
rintro ⟨hre, him⟩,
convert hre.of_real.add (him.of_real.const_mul is_R_or_C.I),
{ ext1 x,
rw [pi.add_apply, mul_comm, is_R_or_C.re_add_im] },
all_goals { apply_instance }
end
end is_R_or_C
lemma add_comp_Lp (L L' : E →L[𝕜] F) (f : Lp E p μ) :
(L + L').comp_Lp f = L.comp_Lp f + L'.comp_Lp f :=
begin
ext1,
refine (coe_fn_comp_Lp' (L + L') f).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,
refine eventually_eq.trans _
(eventually_eq.add (L.coe_fn_comp_Lp' f).symm (L'.coe_fn_comp_Lp' f).symm),
refine eventually_of_forall (λ x, _),
refl,
end
lemma smul_comp_Lp {𝕜'} [normed_field 𝕜'] [measurable_space 𝕜'] [opens_measurable_space 𝕜']
[normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] (c : 𝕜') (L : E →L[𝕜] F) (f : Lp E p μ) :
(c • L).comp_Lp f = c • L.comp_Lp f :=
begin
ext1,
refine (coe_fn_comp_Lp' (c • L) f).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
refine (L.coe_fn_comp_Lp' f).mono (λ x hx, _),
rw [pi.smul_apply, hx],
refl,
end
lemma norm_comp_Lp_le (L : E →L[𝕜] F) (f : Lp E p μ) : ∥L.comp_Lp f∥ ≤ ∥L∥ * ∥f∥ :=
lipschitz_with.norm_comp_Lp_le _ _ _
variables (μ p) [measurable_space 𝕜] [opens_measurable_space 𝕜]
/-- Composing `f : Lp E p μ` with `L : E →L[𝕜] F`, seen as a `𝕜`-linear map on `Lp E p μ`. -/
def comp_Lpₗ (L : E →L[𝕜] F) : (Lp E p μ) →ₗ[𝕜] (Lp F p μ) :=
{ to_fun := λ f, L.comp_Lp f,
map_add' := begin
intros f g,
ext1,
filter_upwards [Lp.coe_fn_add f g, coe_fn_comp_Lp L (f + g), coe_fn_comp_Lp L f,
coe_fn_comp_Lp L g, Lp.coe_fn_add (L.comp_Lp f) (L.comp_Lp g)],
assume a ha1 ha2 ha3 ha4 ha5,
simp only [ha1, ha2, ha3, ha4, ha5, map_add, pi.add_apply],
end,
map_smul' := begin
intros c f,
dsimp,
ext1,
filter_upwards [Lp.coe_fn_smul c f, coe_fn_comp_Lp L (c • f), Lp.coe_fn_smul c (L.comp_Lp f),
coe_fn_comp_Lp L f],
assume a ha1 ha2 ha3 ha4,
simp only [ha1, ha2, ha3, ha4, map_smul, pi.smul_apply],
end }
/-- Composing `f : Lp E p μ` with `L : E →L[𝕜] F`, seen as a continuous `𝕜`-linear map on
`Lp E p μ`. See also the similar
* `linear_map.comp_left` for functions,
* `continuous_linear_map.comp_left_continuous` for continuous functions,
* `continuous_linear_map.comp_left_continuous_bounded` for bounded continuous functions,
* `continuous_linear_map.comp_left_continuous_compact` for continuous functions on compact spaces.
-/
def comp_LpL [fact (1 ≤ p)] (L : E →L[𝕜] F) : (Lp E p μ) →L[𝕜] (Lp F p μ) :=
linear_map.mk_continuous (L.comp_Lpₗ p μ) ∥L∥ L.norm_comp_Lp_le
variables {μ p}
lemma coe_fn_comp_LpL [fact (1 ≤ p)] (L : E →L[𝕜] F) (f : Lp E p μ) :
L.comp_LpL p μ f =ᵐ[μ] λ a, L (f a) :=
L.coe_fn_comp_Lp f
lemma add_comp_LpL [fact (1 ≤ p)] (L L' : E →L[𝕜] F) :
(L + L').comp_LpL p μ = L.comp_LpL p μ + L'.comp_LpL p μ :=
by { ext1 f, exact add_comp_Lp L L' f }
lemma smul_comp_LpL [fact (1 ≤ p)] (c : 𝕜) (L : E →L[𝕜] F) :
(c • L).comp_LpL p μ = c • (L.comp_LpL p μ) :=
by { ext1 f, exact smul_comp_Lp c L f }
/-- TODO: written in an "apply" way because of a missing `has_scalar` instance. -/
lemma smul_comp_LpL_apply [fact (1 ≤ p)] {𝕜'} [normed_field 𝕜'] [measurable_space 𝕜']
[opens_measurable_space 𝕜'] [normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F]
(c : 𝕜') (L : E →L[𝕜] F) (f : Lp E p μ) :
(c • L).comp_LpL p μ f = c • (L.comp_LpL p μ f) :=
smul_comp_Lp c L f
lemma norm_compLpL_le [fact (1 ≤ p)] (L : E →L[𝕜] F) :
∥L.comp_LpL p μ∥ ≤ ∥L∥ :=
linear_map.mk_continuous_norm_le _ (norm_nonneg _) _
end continuous_linear_map
namespace measure_theory
lemma indicator_const_Lp_eq_to_span_singleton_comp_Lp {s : set α} [normed_space ℝ F]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : F) :
indicator_const_Lp 2 hs hμs x =
(continuous_linear_map.to_span_singleton ℝ x).comp_Lp (indicator_const_Lp 2 hs hμs (1 : ℝ)) :=
begin
ext1,
refine indicator_const_Lp_coe_fn.trans _,
have h_comp_Lp := (continuous_linear_map.to_span_singleton ℝ x).coe_fn_comp_Lp
(indicator_const_Lp 2 hs hμs (1 : ℝ)),
rw ← eventually_eq at h_comp_Lp,
refine eventually_eq.trans _ h_comp_Lp.symm,
refine (@indicator_const_Lp_coe_fn _ _ _ 2 μ _ _ s hs hμs (1 : ℝ) _ _).mono (λ y hy, _),
dsimp only,
rw hy,
simp_rw [continuous_linear_map.to_span_singleton_apply],
by_cases hy_mem : y ∈ s; simp [hy_mem, continuous_linear_map.lsmul_apply],
end
namespace Lp
section pos_part
lemma lipschitz_with_pos_part : lipschitz_with 1 (λ (x : ℝ), max x 0) :=
lipschitz_with.of_dist_le_mul $ λ x y, by simp [dist, abs_max_sub_max_le_abs]
/-- Positive part of a function in `L^p`. -/
def pos_part (f : Lp ℝ p μ) : Lp ℝ p μ :=
lipschitz_with_pos_part.comp_Lp (max_eq_right (le_refl _)) f
/-- Negative part of a function in `L^p`. -/
def neg_part (f : Lp ℝ p μ) : Lp ℝ p μ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : Lp ℝ p μ) : (pos_part f : α →ₘ[μ] ℝ) = (f : α →ₘ[μ] ℝ).pos_part := rfl
lemma coe_fn_pos_part (f : Lp ℝ p μ) : ⇑(pos_part f) =ᵐ[μ] λ a, max (f a) 0 :=
ae_eq_fun.coe_fn_pos_part _
lemma coe_fn_neg_part_eq_max (f : Lp ℝ p μ) : ∀ᵐ a ∂μ, neg_part f a = max (- f a) 0 :=
begin
rw neg_part,
filter_upwards [coe_fn_pos_part (-f), coe_fn_neg f],
assume a h₁ h₂,
rw [h₁, h₂, pi.neg_apply]
end
lemma coe_fn_neg_part (f : Lp ℝ p μ) : ∀ᵐ a ∂μ, neg_part f a = - min (f a) 0 :=
(coe_fn_neg_part_eq_max f).mono $ assume a h,
by rw [h, ← max_neg_neg, neg_zero]
lemma continuous_pos_part [fact (1 ≤ p)] : continuous (λf : Lp ℝ p μ, pos_part f) :=
lipschitz_with.continuous_comp_Lp _ _
lemma continuous_neg_part [fact (1 ≤ p)] : continuous (λf : Lp ℝ p μ, neg_part f) :=
have eq : (λf : Lp ℝ p μ, neg_part f) = (λf : Lp ℝ p μ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
end Lp
end measure_theory
end composition
/-!
## `L^p` is a complete space
We show that `L^p` is a complete space for `1 ≤ p`.
-/
section complete_space
variables [borel_space E] [second_countable_topology E]
namespace measure_theory
namespace Lp
lemma snorm'_lim_eq_lintegral_liminf {ι} [nonempty ι] [linear_order ι] {f : ι → α → G} {p : ℝ}
(hp_nonneg : 0 ≤ p) {f_lim : α → G}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm' f_lim p μ = (∫⁻ a, at_top.liminf (λ m, (nnnorm (f m a) : ℝ≥0∞)^p) ∂μ) ^ (1/p) :=
begin
suffices h_no_pow : (∫⁻ a, (nnnorm (f_lim a)) ^ p ∂μ)
= (∫⁻ a, at_top.liminf (λ m, (nnnorm (f m a) : ℝ≥0∞)^p) ∂μ),
{ rw [snorm', h_no_pow], },
refine lintegral_congr_ae (h_lim.mono (λ a ha, _)),
rw tendsto.liminf_eq,
simp_rw [ennreal.coe_rpow_of_nonneg _ hp_nonneg, ennreal.tendsto_coe],
refine ((nnreal.continuous_rpow_const hp_nonneg).tendsto (nnnorm (f_lim a))).comp _,
exact (continuous_nnnorm.tendsto (f_lim a)).comp ha,
end
lemma snorm'_lim_le_liminf_snorm' {E} [measurable_space E]
[normed_group E] [borel_space E] {f : ℕ → α → E} {p : ℝ} (hp_pos : 0 < p)
(hf : ∀ n, ae_measurable (f n) μ) {f_lim : α → E}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm' f_lim p μ ≤ at_top.liminf (λ n, snorm' (f n) p μ) :=
begin
rw snorm'_lim_eq_lintegral_liminf hp_pos.le h_lim,
rw [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div],
refine (lintegral_liminf_le' (λ m, ((hf m).ennnorm.pow_const _))).trans_eq _,
have h_pow_liminf : at_top.liminf (λ n, snorm' (f n) p μ) ^ p
= at_top.liminf (λ n, (snorm' (f n) p μ) ^ p),
{ have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos hp_pos,
have h_rpow_surj := (ennreal.rpow_left_bijective hp_pos.ne.symm).2,
refine (h_rpow_mono.order_iso_of_surjective _ h_rpow_surj).liminf_apply _ _ _ _,
all_goals { is_bounded_default }, },
rw h_pow_liminf,
simp_rw [snorm', ← ennreal.rpow_mul, one_div, inv_mul_cancel hp_pos.ne.symm, ennreal.rpow_one],
end
lemma snorm_exponent_top_lim_eq_ess_sup_liminf {ι} [nonempty ι] [linear_order ι] {f : ι → α → G}
{f_lim : α → G}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim ∞ μ = ess_sup (λ x, at_top.liminf (λ m, (nnnorm (f m x) : ℝ≥0∞))) μ :=
begin
rw [snorm_exponent_top, snorm_ess_sup],
refine ess_sup_congr_ae (h_lim.mono (λ x hx, _)),
rw tendsto.liminf_eq,
rw ennreal.tendsto_coe,
exact (continuous_nnnorm.tendsto (f_lim x)).comp hx,
end
lemma snorm_exponent_top_lim_le_liminf_snorm_exponent_top {ι} [nonempty ι] [encodable ι]
[linear_order ι] {f : ι → α → F} {f_lim : α → F}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim ∞ μ ≤ at_top.liminf (λ n, snorm (f n) ∞ μ) :=
begin
rw snorm_exponent_top_lim_eq_ess_sup_liminf h_lim,
simp_rw [snorm_exponent_top, snorm_ess_sup],
exact ennreal.ess_sup_liminf_le (λ n, (λ x, (nnnorm (f n x) : ℝ≥0∞))),
end
lemma snorm_lim_le_liminf_snorm {E} [measurable_space E] [normed_group E] [borel_space E]
{f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ) (f_lim : α → E)
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim p μ ≤ at_top.liminf (λ n, snorm (f n) p μ) :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
rw ← ne.def at hp0,
by_cases hp_top : p = ∞,
{ simp_rw [hp_top],
exact snorm_exponent_top_lim_le_liminf_snorm_exponent_top h_lim, },
simp_rw snorm_eq_snorm' hp0 hp_top,
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp0.symm, hp_top⟩,
exact snorm'_lim_le_liminf_snorm' hp_pos hf h_lim,
end
/-! ### `Lp` is complete iff Cauchy sequences of `ℒp` have limits in `ℒp` -/
lemma tendsto_Lp_iff_tendsto_ℒp' {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → Lp E p μ) (f_lim : Lp E p μ) :
fi.tendsto f (𝓝 f_lim) ↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw tendsto_iff_dist_tendsto_zero,
simp_rw dist_def,
rw [← ennreal.zero_to_real, ennreal.tendsto_to_real_iff (λ n, _) ennreal.zero_ne_top],
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact Lp.snorm_ne_top _,
end
lemma tendsto_Lp_iff_tendsto_ℒp {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → Lp E p μ) (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ) :
fi.tendsto f (𝓝 (f_lim_ℒp.to_Lp f_lim)) ↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw tendsto_Lp_iff_tendsto_ℒp',
suffices h_eq : (λ n, snorm (f n - mem_ℒp.to_Lp f_lim f_lim_ℒp) p μ)
= (λ n, snorm (f n - f_lim) p μ),
by rw h_eq,
exact funext (λ n, snorm_congr_ae (eventually_eq.rfl.sub (mem_ℒp.coe_fn_to_Lp f_lim_ℒp))),
end
lemma tendsto_Lp_iff_tendsto_ℒp'' {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → α → E) (f_ℒp : ∀ n, mem_ℒp (f n) p μ) (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ) :
fi.tendsto (λ n, (f_ℒp n).to_Lp (f n)) (𝓝 (f_lim_ℒp.to_Lp f_lim))
↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
convert Lp.tendsto_Lp_iff_tendsto_ℒp' _ _,
ext1 n,
apply snorm_congr_ae,
filter_upwards [((f_ℒp n).sub f_lim_ℒp).coe_fn_to_Lp,
Lp.coe_fn_sub ((f_ℒp n).to_Lp (f n)) (f_lim_ℒp.to_Lp f_lim)],
intros x hx₁ hx₂,
rw ← hx₂,
exact hx₁.symm
end
lemma tendsto_Lp_of_tendsto_ℒp {ι} {fi : filter ι} [hp : fact (1 ≤ p)]
{f : ι → Lp E p μ} (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ)
(h_tendsto : fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
fi.tendsto f (𝓝 (f_lim_ℒp.to_Lp f_lim)) :=
(tendsto_Lp_iff_tendsto_ℒp f f_lim f_lim_ℒp).mpr h_tendsto
lemma cauchy_seq_Lp_iff_cauchy_seq_ℒp {ι} [nonempty ι] [semilattice_sup ι] [hp : fact (1 ≤ p)]
(f : ι → Lp E p μ) :
cauchy_seq f ↔ tendsto (λ (n : ι × ι), snorm (f n.fst - f n.snd) p μ) at_top (𝓝 0) :=
begin
simp_rw [cauchy_seq_iff_tendsto_dist_at_top_0, dist_def],
rw [← ennreal.zero_to_real, ennreal.tendsto_to_real_iff (λ n, _) ennreal.zero_ne_top],
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact snorm_ne_top _,
end
lemma complete_space_Lp_of_cauchy_complete_ℒp [hp : fact (1 ≤ p)]
(H : ∀ (f : ℕ → α → E) (hf : ∀ n, mem_ℒp (f n) p μ) (B : ℕ → ℝ≥0∞) (hB : ∑' i, B i < ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N),
∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
complete_space (Lp E p μ) :=
begin
let B := λ n : ℕ, ((1:ℝ) / 2) ^ n,
have hB_pos : ∀ n, 0 < B n, from λ n, pow_pos (div_pos zero_lt_one zero_lt_two) n,
refine metric.complete_of_convergent_controlled_sequences B hB_pos (λ f hf, _),
suffices h_limit : ∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0),
{ rcases h_limit with ⟨f_lim, hf_lim_meas, h_tendsto⟩,
exact ⟨hf_lim_meas.to_Lp f_lim, tendsto_Lp_of_tendsto_ℒp f_lim hf_lim_meas h_tendsto⟩, },
have hB : summable B, from summable_geometric_two,
cases hB with M hB,
let B1 := λ n, ennreal.of_real (B n),
have hB1_has : has_sum B1 (ennreal.of_real M),
{ have h_tsum_B1 : ∑' i, B1 i = (ennreal.of_real M),
{ change (∑' (n : ℕ), ennreal.of_real (B n)) = ennreal.of_real M,
rw ←hB.tsum_eq,
exact (ennreal.of_real_tsum_of_nonneg (λ n, le_of_lt (hB_pos n)) hB.summable).symm, },
have h_sum := (@ennreal.summable _ B1).has_sum,
rwa h_tsum_B1 at h_sum, },
have hB1 : ∑' i, B1 i < ∞, by {rw hB1_has.tsum_eq, exact ennreal.of_real_lt_top, },
let f1 : ℕ → α → E := λ n, f n,
refine H f1 (λ n, Lp.mem_ℒp (f n)) B1 hB1 (λ N n m hn hm, _),
specialize hf N n m hn hm,
rw dist_def at hf,
simp_rw [f1, B1],
rwa ennreal.lt_of_real_iff_to_real_lt,
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact Lp.snorm_ne_top _,
end
/-! ### Prove that controlled Cauchy sequences of `ℒp` have limits in `ℒp` -/
private lemma snorm'_sum_norm_sub_le_tsum_of_cauchy_snorm' {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p)
{B : ℕ → ℝ≥0∞} (h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) p μ < B N) (n : ℕ) :
snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ ≤ ∑' i, B i :=
begin
let f_norm_diff := λ i x, norm (f (i + 1) x - f i x),
have hgf_norm_diff : ∀ n, (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x))
= ∑ i in finset.range (n + 1), f_norm_diff i,
from λ n, funext (λ x, by simp [f_norm_diff]),
rw hgf_norm_diff,
refine (snorm'_sum_le (λ i _, ((hf (i+1)).sub (hf i)).norm) hp1).trans _,
simp_rw [←pi.sub_apply, snorm'_norm],
refine (finset.sum_le_sum _).trans (sum_le_tsum _ (λ m _, zero_le _) ennreal.summable),
exact λ m _, (h_cau m (m + 1) m (nat.le_succ m) (le_refl m)).le,
end
private lemma lintegral_rpow_sum_coe_nnnorm_sub_le_rpow_tsum {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞} (n : ℕ)
(hn : snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ ≤ ∑' i, B i) :
∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
rw [←one_div_one_div p, @ennreal.le_rpow_one_div_iff _ _ (1/p) (by simp [hp_pos]),
one_div_one_div p],
simp_rw snorm' at hn,
have h_nnnorm_nonneg :
(λ a, (nnnorm (∑ i in finset.range (n + 1), ∥f (i + 1) a - f i a∥) : ℝ≥0∞) ^ p)
= λ a, (∑ i in finset.range (n + 1), (nnnorm(f (i + 1) a - f i a) : ℝ≥0∞)) ^ p,
{ ext1 a,
congr,
simp_rw ←of_real_norm_eq_coe_nnnorm,
rw ←ennreal.of_real_sum_of_nonneg,
{ rw real.norm_of_nonneg _,
exact finset.sum_nonneg (λ x hx, norm_nonneg _), },
{ exact λ x hx, norm_nonneg _, }, },
change (∫⁻ a, (λ x, ↑(nnnorm (∑ i in finset.range (n + 1), ∥f (i+1) x - f i x∥))^p) a ∂μ)^(1/p)
≤ ∑' i, B i at hn,
rwa h_nnnorm_nonneg at hn,
end
private lemma lintegral_rpow_tsum_coe_nnnorm_sub_le_tsum {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞}
(h : ∀ n, ∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p) :
(∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
suffices h_pow : ∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ ≤ (∑' i, B i) ^ p,
by rwa [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div],
have h_tsum_1 : ∀ g : ℕ → ℝ≥0∞,
∑' i, g i = at_top.liminf (λ n, ∑ i in finset.range (n + 1), g i),
by { intro g, rw [ennreal.tsum_eq_liminf_sum_nat, ← liminf_nat_add _ 1], },
simp_rw h_tsum_1 _,
rw ← h_tsum_1,
have h_liminf_pow : ∫⁻ a, at_top.liminf (λ n, ∑ i in finset.range (n + 1),
(nnnorm (f (i + 1) a - f i a)))^p ∂μ
= ∫⁻ a, at_top.liminf (λ n, (∑ i in finset.range (n + 1), (nnnorm (f (i + 1) a - f i a)))^p) ∂μ,
{ refine lintegral_congr (λ x, _),
have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos (zero_lt_one.trans_le hp1),
have h_rpow_surj := (ennreal.rpow_left_bijective hp_pos.ne.symm).2,
refine (h_rpow_mono.order_iso_of_surjective _ h_rpow_surj).liminf_apply _ _ _ _,
all_goals { is_bounded_default }, },
rw h_liminf_pow,
refine (lintegral_liminf_le' _).trans _,
{ exact λ n, (finset.ae_measurable_sum (finset.range (n+1))
(λ i _, ((hf (i+1)).sub (hf i)).ennnorm)).pow_const _, },
{ exact liminf_le_of_frequently_le' (frequently_of_forall h), },
end
private lemma tsum_nnnorm_sub_ae_lt_top
{f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞}
(hB : ∑' i, B i ≠ ∞)
(h : (∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i) :
∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞) < ∞ :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
have h_integral : ∫⁻ a, (∑' i, ∥f (i + 1) a - f i a∥₊ : ℝ≥0∞)^p ∂μ < ∞,
{ have h_tsum_lt_top : (∑' i, B i) ^ p < ∞,
from ennreal.rpow_lt_top_of_nonneg hp_pos.le hB,
refine lt_of_le_of_lt _ h_tsum_lt_top,
rwa [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div] at h, },
have rpow_ae_lt_top : ∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞)^p < ∞,
{ refine ae_lt_top' (ae_measurable.pow_const _ _) h_integral.ne,
exact ae_measurable.ennreal_tsum (λ n, ((hf (n+1)).sub (hf n)).ennnorm), },
refine rpow_ae_lt_top.mono (λ x hx, _),
rwa [←ennreal.lt_rpow_one_div_iff hp_pos,
ennreal.top_rpow_of_pos (by simp [hp_pos] : 0 < 1 / p)] at hx,
end
lemma ae_tendsto_of_cauchy_snorm' [complete_space E] {f : ℕ → α → E} {p : ℝ}
(hf : ∀ n, ae_measurable (f n) μ) (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i ≠ ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) p μ < B N) :
∀ᵐ x ∂μ, ∃ l : E, at_top.tendsto (λ n, f n x) (𝓝 l) :=
begin
have h_summable : ∀ᵐ x ∂μ, summable (λ (i : ℕ), f (i + 1) x - f i x),
{ have h1 : ∀ n, snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ
≤ ∑' i, B i,
from snorm'_sum_norm_sub_le_tsum_of_cauchy_snorm' hf hp1 h_cau,
have h2 : ∀ n, ∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p,
from λ n, lintegral_rpow_sum_coe_nnnorm_sub_le_rpow_tsum hf hp1 n (h1 n),
have h3 : (∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i,
from lintegral_rpow_tsum_coe_nnnorm_sub_le_tsum hf hp1 h2,
have h4 : ∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞) < ∞,
from tsum_nnnorm_sub_ae_lt_top hf hp1 hB h3,
exact h4.mono (λ x hx, summable_of_summable_nnnorm
(ennreal.tsum_coe_ne_top_iff_summable.mp (lt_top_iff_ne_top.mp hx))), },
have h : ∀ᵐ x ∂μ, ∃ l : E,
at_top.tendsto (λ n, ∑ i in finset.range n, (f (i + 1) x - f i x)) (𝓝 l),
{ refine h_summable.mono (λ x hx, _),
let hx_sum := hx.has_sum.tendsto_sum_nat,
exact ⟨∑' i, (f (i + 1) x - f i x), hx_sum⟩, },
refine h.mono (λ x hx, _),
cases hx with l hx,
have h_rw_sum : (λ n, ∑ i in finset.range n, (f (i + 1) x - f i x)) = λ n, f n x - f 0 x,
{ ext1 n,
change ∑ (i : ℕ) in finset.range n, ((λ m, f m x) (i + 1) - (λ m, f m x) i) = f n x - f 0 x,
rw finset.sum_range_sub, },
rw h_rw_sum at hx,
have hf_rw : (λ n, f n x) = λ n, f n x - f 0 x + f 0 x, by { ext1 n, abel, },
rw hf_rw,
exact ⟨l + f 0 x, tendsto.add_const _ hx⟩,
end
lemma ae_tendsto_of_cauchy_snorm [complete_space E] {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) (hp : 1 ≤ p) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i ≠ ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N) :
∀ᵐ x ∂μ, ∃ l : E, at_top.tendsto (λ n, f n x) (𝓝 l) :=
begin
by_cases hp_top : p = ∞,
{ simp_rw [hp_top] at *,
have h_cau_ae : ∀ᵐ x ∂μ, ∀ N n m, N ≤ n → N ≤ m → (nnnorm ((f n - f m) x) : ℝ≥0∞) < B N,
{ simp_rw [ae_all_iff, ae_imp_iff],
exact λ N n m hnN hmN, ae_lt_of_ess_sup_lt (h_cau N n m hnN hmN), },
simp_rw [snorm_exponent_top, snorm_ess_sup] at h_cau,
refine h_cau_ae.mono (λ x hx, cauchy_seq_tendsto_of_complete _),
refine cauchy_seq_of_le_tendsto_0 (λ n, (B n).to_real) _ _,
{ intros n m N hnN hmN,
specialize hx N n m hnN hmN,
rw [dist_eq_norm, ←ennreal.to_real_of_real (norm_nonneg _),
ennreal.to_real_le_to_real ennreal.of_real_ne_top
(ennreal.ne_top_of_tsum_ne_top hB N)],
rw ←of_real_norm_eq_coe_nnnorm at hx,
exact hx.le, },
{ rw ← ennreal.zero_to_real,
exact tendsto.comp (ennreal.tendsto_to_real ennreal.zero_ne_top)
(ennreal.tendsto_at_top_zero_of_tsum_ne_top hB), }, },
have hp1 : 1 ≤ p.to_real,
{ rw [← ennreal.of_real_le_iff_le_to_real hp_top, ennreal.of_real_one],
exact hp, },
have h_cau' : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) (p.to_real) μ < B N,
{ intros N n m hn hm,
specialize h_cau N n m hn hm,
rwa snorm_eq_snorm' (ennreal.zero_lt_one.trans_le hp).ne.symm hp_top at h_cau, },
exact ae_tendsto_of_cauchy_snorm' hf hp1 hB h_cau',
end
lemma cauchy_tendsto_of_tendsto {f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ)
(f_lim : α → E) {B : ℕ → ℝ≥0∞}
(hB : ∑' i, B i ≠ ∞) (h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N)
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw ennreal.tendsto_at_top_zero,
intros ε hε,
have h_B : ∃ (N : ℕ), B N ≤ ε,
{ suffices h_tendsto_zero : ∃ (N : ℕ), ∀ n : ℕ, N ≤ n → B n ≤ ε,
from ⟨h_tendsto_zero.some, h_tendsto_zero.some_spec _ (le_refl _)⟩,
exact (ennreal.tendsto_at_top_zero.mp (ennreal.tendsto_at_top_zero_of_tsum_ne_top hB))
ε hε, },
cases h_B with N h_B,
refine ⟨N, λ n hn, _⟩,
have h_sub : snorm (f n - f_lim) p μ ≤ at_top.liminf (λ m, snorm (f n - f m) p μ),
{ refine snorm_lim_le_liminf_snorm (λ m, (hf n).sub (hf m)) (f n - f_lim) _,
refine h_lim.mono (λ x hx, _),
simp_rw sub_eq_add_neg,
exact tendsto.add tendsto_const_nhds (tendsto.neg hx), },
refine h_sub.trans _,
refine liminf_le_of_frequently_le' (frequently_at_top.mpr _),
refine λ N1, ⟨max N N1, le_max_right _ _, _⟩,
exact (h_cau N n (max N N1) hn (le_max_left _ _)).le.trans h_B,
end
lemma mem_ℒp_of_cauchy_tendsto (hp : 1 ≤ p) {f : ℕ → α → E} (hf : ∀ n, mem_ℒp (f n) p μ)
(f_lim : α → E) (h_lim_meas : ae_measurable f_lim μ)
(h_tendsto : at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
mem_ℒp f_lim p μ :=
begin
refine ⟨h_lim_meas, _⟩,
rw ennreal.tendsto_at_top_zero at h_tendsto,
cases (h_tendsto 1 ennreal.zero_lt_one) with N h_tendsto_1,
specialize h_tendsto_1 N (le_refl N),
have h_add : f_lim = f_lim - f N + f N, by abel,
rw h_add,
refine lt_of_le_of_lt (snorm_add_le (h_lim_meas.sub (hf N).1) (hf N).1 hp) _,
rw ennreal.add_lt_top,
split,
{ refine lt_of_le_of_lt _ ennreal.one_lt_top,
have h_neg : f_lim - f N = -(f N - f_lim), by simp,
rwa [h_neg, snorm_neg], },
{ exact (hf N).2, },
end
lemma cauchy_complete_ℒp [complete_space E] (hp : 1 ≤ p)
{f : ℕ → α → E} (hf : ∀ n, mem_ℒp (f n) p μ) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i ≠ ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N) :
∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
obtain ⟨f_lim, h_f_lim_meas, h_lim⟩ : ∃ (f_lim : α → E) (hf_lim_meas : measurable f_lim),
∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (nhds (f_lim x)),
from measurable_limit_of_tendsto_metric_ae (λ n, (hf n).1)
(ae_tendsto_of_cauchy_snorm (λ n, (hf n).1) hp hB h_cau),
have h_tendsto' : at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0),
from cauchy_tendsto_of_tendsto (λ m, (hf m).1) f_lim hB h_cau h_lim,
have h_ℒp_lim : mem_ℒp f_lim p μ,
from mem_ℒp_of_cauchy_tendsto hp hf f_lim h_f_lim_meas.ae_measurable h_tendsto',
exact ⟨f_lim, h_ℒp_lim, h_tendsto'⟩,
end
/-! ### `Lp` is complete for `1 ≤ p` -/
instance [complete_space E] [hp : fact (1 ≤ p)] : complete_space (Lp E p μ) :=
complete_space_Lp_of_cauchy_complete_ℒp $
λ f hf B hB h_cau, cauchy_complete_ℒp hp.elim hf hB.ne h_cau
end Lp
end measure_theory
end complete_space
/-! ### Continuous functions in `Lp` -/
open_locale bounded_continuous_function
open bounded_continuous_function
variables [borel_space E] [second_countable_topology E] [topological_space α] [borel_space α]
variables (E p μ)
/-- An additive subgroup of `Lp E p μ`, consisting of the equivalence classes which contain a
bounded continuous representative. -/
def measure_theory.Lp.bounded_continuous_function : add_subgroup (Lp E p μ) :=
add_subgroup.add_subgroup_of
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E)).range
(Lp E p μ)
variables {E p μ}
/-- By definition, the elements of `Lp.bounded_continuous_function E p μ` are the elements of
`Lp E p μ` which contain a bounded continuous representative. -/
lemma measure_theory.Lp.mem_bounded_continuous_function_iff {f : (Lp E p μ)} :
f ∈ measure_theory.Lp.bounded_continuous_function E p μ
↔ ∃ f₀ : (α →ᵇ E), f₀.to_continuous_map.to_ae_eq_fun μ = (f : α →ₘ[μ] E) :=
add_subgroup.mem_add_subgroup_of
namespace bounded_continuous_function
variables [is_finite_measure μ]
/-- A bounded continuous function on a finite-measure space is in `Lp`. -/
lemma mem_Lp (f : α →ᵇ E) :
f.to_continuous_map.to_ae_eq_fun μ ∈ Lp E p μ :=
begin
refine Lp.mem_Lp_of_ae_bound (∥f∥) _,
filter_upwards [f.to_continuous_map.coe_fn_to_ae_eq_fun μ],
intros x hx,
convert f.norm_coe_le_norm x
end
/-- The `Lp`-norm of a bounded continuous function is at most a constant (depending on the measure
of the whole space) times its sup-norm. -/
lemma Lp_norm_le (f : α →ᵇ E) :
∥(⟨f.to_continuous_map.to_ae_eq_fun μ, mem_Lp f⟩ : Lp E p μ)∥
≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * ∥f∥ :=
begin
apply Lp.norm_le_of_ae_bound (norm_nonneg f),
{ refine (f.to_continuous_map.coe_fn_to_ae_eq_fun μ).mono _,
intros x hx,
convert f.norm_coe_le_norm x },
{ apply_instance }
end
variables (p μ)
/-- The normed group homomorphism of considering a bounded continuous function on a finite-measure
space as an element of `Lp`. -/
def to_Lp_hom [fact (1 ≤ p)] : normed_group_hom (α →ᵇ E) (Lp E p μ) :=
{ bound' := ⟨_, Lp_norm_le⟩,
.. add_monoid_hom.cod_restrict
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E))
(Lp E p μ)
mem_Lp }
lemma range_to_Lp_hom [fact (1 ≤ p)] :
((to_Lp_hom p μ).range : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
begin
symmetry,
convert add_monoid_hom.add_subgroup_of_range_eq_of_le
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E))
(by { rintros - ⟨f, rfl⟩, exact mem_Lp f } : _ ≤ Lp E p μ),
end
variables (𝕜 : Type*) [measurable_space 𝕜]
/-- The bounded linear map of considering a bounded continuous function on a finite-measure space
as an element of `Lp`. -/
def to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)] :
(α →ᵇ E) →L[𝕜] (Lp E p μ) :=
linear_map.mk_continuous
(linear_map.cod_restrict
(Lp.Lp_submodule E p μ 𝕜)
((continuous_map.to_ae_eq_fun_linear_map μ).comp (forget_boundedness_linear_map α E 𝕜))
mem_Lp)
_
Lp_norm_le
variables {𝕜}
lemma range_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)] :
((to_Lp p μ 𝕜).range.to_add_subgroup : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
range_to_Lp_hom p μ
variables {p}
lemma coe_fn_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)]
(f : α →ᵇ E) :
to_Lp p μ 𝕜 f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk f _
lemma to_Lp_norm_le [nondiscrete_normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
[fact (1 ≤ p)] :
∥(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ :=
linear_map.mk_continuous_norm_le _ ((measure_univ_nnreal μ) ^ (p.to_real)⁻¹).coe_nonneg _
end bounded_continuous_function
namespace continuous_map
variables [compact_space α] [is_finite_measure μ]
variables (𝕜 : Type*) [measurable_space 𝕜] (p μ) [fact (1 ≤ p)]
/-- The bounded linear map of considering a continuous function on a compact finite-measure
space `α` as an element of `Lp`. By definition, the norm on `C(α, E)` is the sup-norm, transferred
from the space `α →ᵇ E` of bounded continuous functions, so this construction is just a matter of
transferring the structure from `bounded_continuous_function.to_Lp` along the isometry. -/
def to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] :
C(α, E) →L[𝕜] (Lp E p μ) :=
(bounded_continuous_function.to_Lp p μ 𝕜).comp
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_isometry.to_continuous_linear_map
variables {𝕜}
lemma range_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] :
((to_Lp p μ 𝕜).range.to_add_subgroup : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
begin
refine set_like.ext' _,
have := (linear_isometry_bounded_of_compact α E 𝕜).surjective,
convert function.surjective.range_comp this (bounded_continuous_function.to_Lp p μ 𝕜),
rw ← bounded_continuous_function.range_to_Lp p μ,
refl,
end
variables {p}
lemma coe_fn_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] (f : C(α, E)) :
to_Lp p μ 𝕜 f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk f _
lemma to_Lp_def [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] (f : C(α, E)) :
to_Lp p μ 𝕜 f
= bounded_continuous_function.to_Lp p μ 𝕜 (linear_isometry_bounded_of_compact α E 𝕜 f) :=
rfl
@[simp] lemma to_Lp_comp_forget_boundedness [normed_field 𝕜] [opens_measurable_space 𝕜]
[normed_space 𝕜 E] (f : α →ᵇ E) :
to_Lp p μ 𝕜 (bounded_continuous_function.forget_boundedness α E f)
= bounded_continuous_function.to_Lp p μ 𝕜 f :=
rfl
@[simp] lemma coe_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
(f : C(α, E)) :
(to_Lp p μ 𝕜 f : α →ₘ[μ] E) = f.to_ae_eq_fun μ :=
rfl
variables [nondiscrete_normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
lemma to_Lp_norm_eq_to_Lp_norm_coe :
∥(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] (Lp E p μ))∥
= ∥(bounded_continuous_function.to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))∥ :=
continuous_linear_map.op_norm_comp_linear_isometry_equiv _ _
/-- Bound for the operator norm of `continuous_map.to_Lp`. -/
lemma to_Lp_norm_le :
∥(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] (Lp E p μ))∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ :=
by { rw to_Lp_norm_eq_to_Lp_norm_coe, exact bounded_continuous_function.to_Lp_norm_le μ }
end continuous_map
--(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))
|
aa2a388bd49dd0f04b54462a50357b31e7b977f5
|
7cdf3413c097e5d36492d12cdd07030eb991d394
|
/src/my_solutions/world3_le.lean
|
897f4e3cf3fbeb8f54b58439fa35044fb3600d12
|
[] |
no_license
|
alreadydone/natural_number_game
|
3135b9385a9f43e74cfbf79513fc37e69b99e0b3
|
1a39e693df4f4e871eb449890d3c7715a25c2ec9
|
refs/heads/master
| 1,599,387,390,105
| 1,573,200,587,000
| 1,573,200,691,000
| 220,397,084
| 0
| 0
| null | 1,573,192,734,000
| 1,573,192,733,000
| null |
UTF-8
|
Lean
| false
| false
| 4,759
|
lean
|
import solutions.world2_multiplication
import mynat.le
/- Here's what you get from the import:
1) The following data:
* a binary relation called mynat.le, and notation a ≤ b for this relation.
The definition is: a ≤ b ↔ ∃ c : mynat, b = a + c
2) The following axiom:
* `le_def (a b : mynat) : a ≤ b ↔ ∃ (c : mynat), b = a + c`
You can rewrite `le_def`.
If a goal is of the form `∃ c, ...` then to make progress you can use the `use` tactic.
For example `use 7` will replace all c's in the goal with 7's.
-/
namespace mynat
-- example
theorem le_refl (a : mynat) : a ≤ a :=
begin [less_leaky]
rw le_def,
use 0,
rw add_zero,
refl,
end
example : one ≤ one := le_refl one
-- ignore this; it's making the "refl" tactic work with goals of the form a ≤ a
attribute [_refl_lemma] le_refl
theorem le_succ {a b : mynat} (h : a ≤ b) : a ≤ (succ b) :=
begin [less_leaky]
rw le_def at h,
cases h with c hc,
use succ(c),
rw hc,
rw add_succ,
refl,
end
lemma zero_le (a : mynat) : 0 ≤ a :=
begin [less_leaky]
rw le_def,
use a,
rw zero_add,
refl,
end
-- advanced
lemma le_zero {a : mynat} (h : a ≤ 0) : a = 0 :=
begin [less_leaky]
cases h with c hc,
-- this is in world 2 advanced, I don't know how to do it without
-- using zero_ne_succ
sorry,
end
theorem le_trans ⦃a b c : mynat⦄ (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c :=
begin
cases hab with d hd,
cases hbc with e he,
use d + e,
rw he,
rw hd,
exact add_assoc a d e,
end
instance : preorder mynat := by structure_helper
-- need a = a + x -> x = 0 which is proved using functions
theorem le_antisymm {{a b : mynat}} (hab : a ≤ b) (hba : b ≤ a) : a = b :=
begin
cases hab with d hd,
cases hba with e he,
rw hd at he,
sorry,
end
instance : partial_order mynat := by structure_helper
-- ignore this, it's the definition.
theorem lt_iff_le_not_le {a b : mynat} : a < b ↔ a ≤ b ∧ ¬ b ≤ a := iff.rfl
-- functions everywhere
theorem lt_iff_le_and_ne ⦃a b : mynat⦄ : a < b ↔ a ≤ b ∧ a ≠ b :=
begin
sorry
end
-- beginner
lemma succ_le_succ {a b : mynat} (h : a ≤ b) : succ a ≤ succ b :=
begin [less_leaky]
cases h with c hc,
use c,
rw hc,
rw succ_add,
refl,
end
-- haven't introduced left/right tactic
theorem le_total (a b : mynat) : a ≤ b ∨ b ≤ a :=
begin
revert a,
induction b with d hd,
intro a,
right,
exact zero_le a,
intro a,
sorry,
end
instance : linear_order mynat := by structure_helper
-- beginner
theorem add_le_add_right (a b : mynat) (hab : a ≤ b) (t : mynat) : (a + t) ≤ (b + t) :=
begin
cases hab with c hc,
use c,
rw hc,
simp,
end
-- odd use of exact
theorem le_succ_self (a : mynat) : a ≤ succ a :=
begin
use 1,
exact succ_eq_add_one a,
end
-- advanced
theorem le_of_succ_le_succ {a b : mynat} : succ a ≤ succ b → a ≤ b :=
begin
intro h,
cases h with d hd,
use d,
rw succ_add at hd,
exact succ_inj(hd),
end
-- advanced
theorem not_succ_le_self {{d : mynat}} (h : succ d ≤ d) : false :=
begin
sorry
end
-- beginner
theorem add_le_add_left (a b : mynat) (hab : a ≤ b) (c : mynat) : c + a ≤ c + b :=
begin
cases hab with d hd,
use d,
rw hd,
simp,
end
-- split
def succ_le_succ_iff (a b : mynat) : succ a ≤ succ b ↔ a ≤ b :=
begin
sorry
end
-- split and <
def succ_lt_succ_iff (a b : mynat) : succ a < succ b ↔ a < b :=
begin
sorry
end
theorem lt_of_add_lt_add_left : ∀ {{a b c : mynat}}, a + b < a + c → b < c :=
begin
sorry
end
theorem le_iff_exists_add : ∀ (a b : mynat), a ≤ b ↔ ∃ (c : mynat), b = a + c :=
begin
sorry
end
theorem zero_ne_one : (0 : mynat) ≠ 1 :=
begin
sorry
end
instance : ordered_comm_monoid mynat := by structure_helper
-- beginner -- just
theorem le_of_add_le_add_left ⦃a b c : mynat⦄ (h : a + b ≤ a + c) : b ≤ c :=
begin
cases h with d hd,
use d,
rw add_assoc at hd,
exact add_left_cancel hd, -- add_left_cancel is 2-10 and needs succ_inj
end
instance : ordered_cancel_comm_monoid mynat := by structure_helper
theorem mul_le_mul_of_nonneg_left ⦃a b c : mynat⦄ : a ≤ b → 0 ≤ c → c * a ≤ c * b :=
begin
sorry
end
theorem mul_le_mul_of_nonneg_right ⦃a b c : mynat⦄ : a ≤ b → 0 ≤ c → a * c ≤ b * c :=
begin
sorry
end
theorem ne_zero_of_pos ⦃a : mynat⦄ : 0 < a → a ≠ 0 :=
begin
sorry
end
theorem mul_lt_mul_of_pos_left ⦃a b c : mynat⦄ : a < b → 0 < c → c * a < c * b :=
begin
sorry
end
theorem mul_lt_mul_of_pos_right ⦃a b c : mynat⦄ : a < b → 0 < c → a * c < b * c :=
begin
sorry
end
instance : ordered_semiring mynat := by structure_helper
lemma lt_irrefl (a : mynat) : ¬ (a < a) :=
begin
sorry
end
end mynat
|
8ad984ff1ecc1095522e884503322f51d62a1c5b
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/analysis/complex/circle.lean
|
da36d03cc234599023ba8b14a5ac16ccef8fa8b3
|
[
"Apache-2.0"
] |
permissive
|
AntoineChambert-Loir/mathlib
|
64aabb896129885f12296a799818061bc90da1ff
|
07be904260ab6e36a5769680b6012f03a4727134
|
refs/heads/master
| 1,693,187,631,771
| 1,636,719,886,000
| 1,636,719,886,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,390
|
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 analysis.special_functions.exp
import topology.continuous_function.basic
/-!
# The circle
This file defines `circle` to be the metric sphere (`metric.sphere`) in `ℂ` centred at `0` of
radius `1`. We equip it with the following structure:
* a submonoid of `ℂ`
* a group
* a topological group
We furthermore define `exp_map_circle` to be the natural map `λ t, exp (t * I)` from `ℝ` to
`circle`, and show that this map is a group homomorphism.
## Implementation notes
Because later (in `geometry.manifold.instances.sphere`) one wants to equip the circle with a smooth
manifold structure borrowed from `metric.sphere`, the underlying set is
`{z : ℂ | abs (z - 0) = 1}`. This prevents certain algebraic facts from working definitionally --
for example, the circle is not defeq to `{z : ℂ | abs z = 1}`, which is the kernel of `complex.abs`
considered as a homomorphism from `ℂ` to `ℝ`, nor is it defeq to `{z : ℂ | norm_sq z = 1}`, which
is the kernel of the homomorphism `complex.norm_sq` from `ℂ` to `ℝ`.
-/
noncomputable theory
open complex metric
open_locale complex_conjugate
/-- The unit circle in `ℂ`, here given the structure of a submonoid of `ℂ`. -/
def circle : submonoid ℂ :=
{ carrier := sphere (0:ℂ) 1,
one_mem' := by simp,
mul_mem' := λ a b, begin
simp only [norm_eq_abs, mem_sphere_zero_iff_norm],
intros ha hb,
simp [ha, hb],
end }
@[simp] lemma mem_circle_iff_abs (z : ℂ) : z ∈ circle ↔ abs z = 1 := mem_sphere_zero_iff_norm
lemma circle_def : ↑circle = {z : ℂ | abs z = 1} := by { ext, simp }
@[simp] lemma abs_eq_of_mem_circle (z : circle) : abs z = 1 := by { convert z.2, simp }
@[simp] lemma norm_sq_eq_of_mem_circle (z : circle) : norm_sq z = 1 := by simp [norm_sq_eq_abs]
lemma nonzero_of_mem_circle (z : circle) : (z:ℂ) ≠ 0 := nonzero_of_mem_unit_sphere z
instance : group circle :=
{ inv := λ z, ⟨conj (z : ℂ), by simp⟩,
mul_left_inv := λ z, subtype.ext $ by { simp [has_inv.inv, ← norm_sq_eq_conj_mul_self,
← mul_self_abs] },
.. circle.to_monoid }
lemma coe_inv_circle_eq_conj (z : circle) : ↑(z⁻¹) = (conj : ring_aut ℂ) z := rfl
@[simp] lemma coe_inv_circle (z : circle) : ↑(z⁻¹) = (z : ℂ)⁻¹ :=
begin
rw coe_inv_circle_eq_conj,
apply eq_inv_of_mul_right_eq_one,
rw [mul_comm, ← complex.norm_sq_eq_conj_mul_self],
simp,
end
@[simp] lemma coe_div_circle (z w : circle) : ↑(z / w) = (z:ℂ) / w :=
show ↑(z * w⁻¹) = (z:ℂ) * w⁻¹, by simp
instance : compact_space circle := metric.sphere.compact_space _ _
-- the following result could instead be deduced from the Lie group structure on the circle using
-- `topological_group_of_lie_group`, but that seems a little awkward since one has to first provide
-- and then forget the model space
instance : topological_group circle :=
{ continuous_mul := let h : continuous (λ x : circle, (x : ℂ)) := continuous_subtype_coe in
continuous_induced_rng (continuous_mul.comp (h.prod_map h)),
continuous_inv := continuous_induced_rng $
complex.conj_cle.continuous.comp continuous_subtype_coe }
/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`. -/
def exp_map_circle : C(ℝ, circle) :=
{ to_fun := λ t, ⟨exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]⟩ }
@[simp] lemma exp_map_circle_apply (t : ℝ) : ↑(exp_map_circle t) = complex.exp (t * complex.I) :=
rfl
@[simp] lemma exp_map_circle_zero : exp_map_circle 0 = 1 :=
subtype.ext $ by rw [exp_map_circle_apply, of_real_zero, zero_mul, exp_zero, submonoid.coe_one]
@[simp] lemma exp_map_circle_add (x y : ℝ) :
exp_map_circle (x + y) = exp_map_circle x * exp_map_circle y :=
subtype.ext $ by simp only [exp_map_circle_apply, submonoid.coe_mul, of_real_add, add_mul,
complex.exp_add]
/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ`, considered as a homomorphism of
groups. -/
def exp_map_circle_hom : ℝ →+ (additive circle) :=
{ to_fun := additive.of_mul ∘ exp_map_circle,
map_zero' := exp_map_circle_zero,
map_add' := exp_map_circle_add }
@[simp] lemma exp_map_circle_sub (x y : ℝ) :
exp_map_circle (x - y) = exp_map_circle x / exp_map_circle y :=
exp_map_circle_hom.map_sub x y
|
bf925bb08a3036c2de922caf5847e1ef014ca18d
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/set_theory/game/impartial.lean
|
c39d6a61a9c481a9dfb737aa208a83753f748a8c
|
[
"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,349
|
lean
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson
-/
import set_theory.game.winner
import tactic.nth_rewrite.default
import tactic.equiv_rw
/-!
# Basic definitions about impartial (pre-)games
We will define an impartial game, one in which left and right can make exactly the same moves.
Our definition differs slightly by saying that the game is always equivalent to its negative,
no matter what moves are played. This allows for games such as poker-nim to be classifed as
impartial.
-/
universe u
namespace pgame
local infix ` ≈ ` := equiv
/-- The definition for a impartial game, defined using Conway induction -/
def impartial_aux : pgame → Prop
| G := G ≈ -G ∧ (∀ i, impartial_aux (G.move_left i)) ∧ (∀ j, impartial_aux (G.move_right j))
using_well_founded { dec_tac := pgame_wf_tac }
lemma impartial_aux_def {G : pgame} : G.impartial_aux ↔ G ≈ -G ∧
(∀ i, impartial_aux (G.move_left i)) ∧ (∀ j, impartial_aux (G.move_right j)) :=
begin
split,
{ intro hi,
unfold1 impartial_aux at hi,
exact hi },
{ intro hi,
unfold1 impartial_aux,
exact hi }
end
/-- A typeclass on impartial games. -/
class impartial (G : pgame) : Prop := (out : impartial_aux G)
lemma impartial_iff_aux {G : pgame} : G.impartial ↔ G.impartial_aux :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
lemma impartial_def {G : pgame} : G.impartial ↔ G ≈ -G ∧
(∀ i, impartial (G.move_left i)) ∧ (∀ j, impartial (G.move_right j)) :=
by simpa only [impartial_iff_aux] using impartial_aux_def
namespace impartial
instance impartial_zero : impartial 0 :=
by { rw impartial_def, dsimp, simp }
lemma neg_equiv_self (G : pgame) [h : G.impartial] : G ≈ -G := (impartial_def.1 h).1
instance move_left_impartial {G : pgame} [h : G.impartial] (i : G.left_moves) :
(G.move_left i).impartial :=
(impartial_def.1 h).2.1 i
instance move_right_impartial {G : pgame} [h : G.impartial] (j : G.right_moves) :
(G.move_right j).impartial :=
(impartial_def.1 h).2.2 j
instance impartial_add : ∀ (G H : pgame) [G.impartial] [H.impartial], (G + H).impartial
| G H :=
begin
introsI hG hH,
rw impartial_def,
split,
{ apply equiv_trans _ (neg_add_relabelling G H).equiv.symm,
exact add_congr (neg_equiv_self _) (neg_equiv_self _) },
split,
all_goals
{ intro i,
equiv_rw pgame.left_moves_add G H at i <|> equiv_rw pgame.right_moves_add G H at i,
cases i },
all_goals
{ simp only [add_move_left_inl, add_move_right_inl, add_move_left_inr, add_move_right_inr],
exact impartial_add _ _ }
end
using_well_founded { dec_tac := pgame_wf_tac }
instance impartial_neg : ∀ (G : pgame) [G.impartial], (-G).impartial
| G :=
begin
introI hG,
rw impartial_def,
split,
{ rw neg_neg,
symmetry,
exact neg_equiv_self G },
split,
all_goals
{ intro i,
equiv_rw G.left_moves_neg at i <|> equiv_rw G.right_moves_neg at i,
simp only [move_left_left_moves_neg_symm, move_right_right_moves_neg_symm],
exact impartial_neg _ }
end
using_well_founded { dec_tac := pgame_wf_tac }
lemma winner_cases (G : pgame) [G.impartial] : G.first_loses ∨ G.first_wins :=
begin
rcases G.winner_cases with hl | hr | hp | hn,
{ cases hl with hpos hnonneg,
rw ←not_lt at hnonneg,
have hneg := lt_of_lt_of_equiv hpos (neg_equiv_self G),
rw [lt_iff_neg_gt, neg_neg, neg_zero] at hneg,
contradiction },
{ cases hr with hnonpos hneg,
rw ←not_lt at hnonpos,
have hpos := lt_of_equiv_of_lt (neg_equiv_self G).symm hneg,
rw [lt_iff_neg_gt, neg_neg, neg_zero] at hpos,
contradiction },
{ left, assumption },
{ right, assumption }
end
lemma not_first_wins (G : pgame) [G.impartial] : ¬G.first_wins ↔ G.first_loses :=
by cases winner_cases G; finish using [not_first_loses_of_first_wins]
lemma not_first_loses (G : pgame) [G.impartial] : ¬G.first_loses ↔ G.first_wins :=
iff.symm $ iff_not_comm.1 $ iff.symm $ not_first_wins G
lemma add_self (G : pgame) [G.impartial] : (G + G).first_loses :=
first_loses_is_zero.2 $ equiv_trans (add_congr (neg_equiv_self G) G.equiv_refl)
add_left_neg_equiv
lemma equiv_iff_sum_first_loses (G H : pgame) [G.impartial] [H.impartial] :
G ≈ H ↔ (G + H).first_loses :=
begin
split,
{ intro heq,
exact first_loses_of_equiv (add_congr (equiv_refl _) heq) (add_self G) },
{ intro hGHp,
split,
{ rw le_iff_sub_nonneg,
exact le_trans hGHp.2
(le_trans add_comm_le $ le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _)
(neg_equiv_self G)) },
{ rw le_iff_sub_nonneg,
exact le_trans hGHp.2
(le_of_le_of_equiv (le_refl _) $ add_congr (equiv_refl _) (neg_equiv_self H)) } }
end
lemma le_zero_iff {G : pgame} [G.impartial] : G ≤ 0 ↔ 0 ≤ G :=
by rw [le_zero_iff_zero_le_neg, le_congr (equiv_refl 0) (neg_equiv_self G)]
lemma lt_zero_iff {G : pgame} [G.impartial] : G < 0 ↔ 0 < G :=
by rw [lt_iff_neg_gt, neg_zero, lt_congr (equiv_refl 0) (neg_equiv_self G)]
lemma first_loses_symm (G : pgame) [G.impartial] : G.first_loses ↔ G ≤ 0 :=
⟨and.left, λ h, ⟨h, le_zero_iff.1 h⟩⟩
lemma first_wins_symm (G : pgame) [G.impartial] : G.first_wins ↔ G < 0 :=
⟨and.right, λ h, ⟨lt_zero_iff.1 h, h⟩⟩
lemma first_loses_symm' (G : pgame) [G.impartial] : G.first_loses ↔ 0 ≤ G :=
⟨and.right, λ h, ⟨le_zero_iff.2 h, h⟩⟩
lemma first_wins_symm' (G : pgame) [G.impartial] : G.first_wins ↔ 0 < G :=
⟨and.left, λ h, ⟨h, lt_zero_iff.2 h⟩⟩
lemma no_good_left_moves_iff_first_loses (G : pgame) [G.impartial] :
(∀ (i : G.left_moves), (G.move_left i).first_wins) ↔ G.first_loses :=
begin
split,
{ intro hbad,
rw [first_loses_symm G, le_def_lt],
split,
{ intro i,
specialize hbad i,
exact hbad.2 },
{ intro j,
exact pempty.elim j } },
{ intros hp i,
rw first_wins_symm,
exact (le_def_lt.1 $ (first_loses_symm G).1 hp).1 i }
end
lemma no_good_right_moves_iff_first_loses (G : pgame) [G.impartial] :
(∀ (j : G.right_moves), (G.move_right j).first_wins) ↔ G.first_loses :=
begin
rw [first_loses_of_equiv_iff (neg_equiv_self G), ←no_good_left_moves_iff_first_loses],
refine ⟨λ h i, _, λ h i, _⟩,
{ simpa [first_wins_of_equiv_iff (neg_equiv_self ((-G).move_left i))]
using h (left_moves_neg _ i) },
{ simpa [first_wins_of_equiv_iff (neg_equiv_self (G.move_right i))]
using h ((left_moves_neg _).symm i) }
end
lemma good_left_move_iff_first_wins (G : pgame) [G.impartial] :
(∃ (i : G.left_moves), (G.move_left i).first_loses) ↔ G.first_wins :=
begin
refine ⟨λ ⟨i, hi⟩, (first_wins_symm' G).2 (lt_def_le.2 $ or.inl ⟨i, hi.2⟩), λ hn, _⟩,
rw [first_wins_symm' G, lt_def_le] at hn,
rcases hn with ⟨i, hi⟩ | ⟨j, _⟩,
{ exact ⟨i, (first_loses_symm' _).2 hi⟩ },
{ exact pempty.elim j }
end
lemma good_right_move_iff_first_wins (G : pgame) [G.impartial] :
(∃ j : G.right_moves, (G.move_right j).first_loses) ↔ G.first_wins :=
begin
refine ⟨λ ⟨j, hj⟩, (first_wins_symm G).2 (lt_def_le.2 $ or.inr ⟨j, hj.1⟩), λ hn, _⟩,
rw [first_wins_symm G, lt_def_le] at hn,
rcases hn with ⟨i, _⟩ | ⟨j, hj⟩,
{ exact pempty.elim i },
{ exact ⟨j, (first_loses_symm _).2 hj⟩ }
end
end impartial
end pgame
|
c613adbb8595e9b3bb516ac003e6bc000eb43685
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/control/functor/multivariate.lean
|
1a381259d2df169279bf7d102330b040fb23977b
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,583
|
lean
|
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad, Mario Carneiro, Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fin2
import Mathlib.data.typevec
import Mathlib.logic.function.basic
import Mathlib.tactic.basic
import Mathlib.PostPort
universes u_1 u_2 l u v
namespace Mathlib
/-!
Functors between the category of tuples of types, and the category Type
Features:
`mvfunctor n` : the type class of multivariate functors
`f <$$> x` : notation for map
-/
/-- multivariate functors, i.e. functor between the category of type vectors
and the category of Type -/
class mvfunctor {n : ℕ} (F : typevec n → Type u_2)
where
map : {α β : typevec n} → typevec.arrow α β → F α → F β
namespace mvfunctor
/-- predicate lifting over multivariate functors -/
def liftp {n : ℕ} {F : typevec n → Type v} [mvfunctor F] {α : typevec n} (p : (i : fin2 n) → α i → Prop) (x : F α) :=
∃ (u : F fun (i : fin2 n) => Subtype (p i)), map (fun (i : fin2 n) => subtype.val) u = x
/-- relational lifting over multivariate functors -/
def liftr {n : ℕ} {F : typevec n → Type v} [mvfunctor F] {α : typevec n} (r : {i : fin2 n} → α i → α i → Prop) (x : F α) (y : F α) :=
∃ (u : F fun (i : fin2 n) => Subtype fun (p : α i × α i) => r (prod.fst p) (prod.snd p)),
map (fun (i : fin2 n) (t : Subtype fun (p : α i × α i) => r (prod.fst p) (prod.snd p)) => prod.fst (subtype.val t))
u =
x ∧
map (fun (i : fin2 n) (t : Subtype fun (p : α i × α i) => r (prod.fst p) (prod.snd p)) => prod.snd (subtype.val t))
u =
y
/-- given `x : F α` and a projection `i` of type vector `α`, `supp x i` is the set
of `α.i` contained in `x` -/
def supp {n : ℕ} {F : typevec n → Type v} [mvfunctor F] {α : typevec n} (x : F α) (i : fin2 n) : set (α i) :=
set_of fun (y : α i) => ∀ {p : (i : fin2 n) → α i → Prop}, liftp p x → p i y
theorem of_mem_supp {n : ℕ} {F : typevec n → Type v} [mvfunctor F] {α : typevec n} {x : F α} {p : {i : fin2 n} → α i → Prop} (h : liftp p x) (i : fin2 n) (y : α i) (H : y ∈ supp x i) : p y :=
hy h
end mvfunctor
/-- laws for `mvfunctor` -/
class is_lawful_mvfunctor {n : ℕ} (F : typevec n → Type u_2) [mvfunctor F]
where
id_map : ∀ {α : typevec n} (x : F α), mvfunctor.map typevec.id x = x
comp_map : ∀ {α β γ : typevec n} (g : typevec.arrow α β) (h : typevec.arrow β γ) (x : F α),
mvfunctor.map (typevec.comp h g) x = mvfunctor.map h (mvfunctor.map g x)
namespace mvfunctor
/-- adapt `mvfunctor.liftp` to accept predicates as arrows -/
def liftp' {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] (p : typevec.arrow α (typevec.repeat n Prop)) : F α → Prop :=
liftp fun (i : fin2 n) (x : α i) => typevec.of_repeat (p i x)
/-- adapt `mvfunctor.liftp` to accept relations as arrows -/
def liftr' {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] (r : typevec.arrow (typevec.prod α α) (typevec.repeat n Prop)) : F α → F α → Prop :=
liftr fun (i : fin2 n) (x y : α i) => typevec.of_repeat (r i (typevec.prod.mk i x y))
@[simp] theorem id_map {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] [is_lawful_mvfunctor F] (x : F α) : map typevec.id x = x :=
is_lawful_mvfunctor.id_map x
@[simp] theorem id_map' {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] [is_lawful_mvfunctor F] (x : F α) : map (fun (i : fin2 n) (a : α i) => a) x = x :=
id_map x
theorem map_map {n : ℕ} {α : typevec n} {β : typevec n} {γ : typevec n} {F : typevec n → Type v} [mvfunctor F] [is_lawful_mvfunctor F] (g : typevec.arrow α β) (h : typevec.arrow β γ) (x : F α) : map h (map g x) = map (typevec.comp h g) x :=
Eq.symm (comp_map g h x)
theorem exists_iff_exists_of_mono {n : ℕ} {α : typevec n} {β : typevec n} (F : typevec n → Type v) [mvfunctor F] [is_lawful_mvfunctor F] {p : F α → Prop} {q : F β → Prop} (f : typevec.arrow α β) (g : typevec.arrow β α) (h₀ : typevec.comp f g = typevec.id) (h₁ : ∀ (u : F α), p u ↔ q (map f u)) : (∃ (u : F α), p u) ↔ ∃ (u : F β), q u := sorry
theorem liftp_def {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] (p : typevec.arrow α (typevec.repeat n Prop)) [is_lawful_mvfunctor F] (x : F α) : liftp' p x ↔ ∃ (u : F (typevec.subtype_ p)), map (typevec.subtype_val p) u = x := sorry
theorem liftr_def {n : ℕ} {α : typevec n} {F : typevec n → Type v} [mvfunctor F] (r : typevec.arrow (typevec.prod α α) (typevec.repeat n Prop)) [is_lawful_mvfunctor F] (x : F α) (y : F α) : liftr' r x y ↔
∃ (u : F (typevec.subtype_ r)),
map (typevec.comp typevec.prod.fst (typevec.subtype_val r)) u = x ∧
map (typevec.comp typevec.prod.snd (typevec.subtype_val r)) u = y := sorry
end mvfunctor
namespace mvfunctor
theorem liftp_last_pred_iff {n : ℕ} {F : typevec (n + 1) → Type u_1} [mvfunctor F] [is_lawful_mvfunctor F] {α : typevec n} {β : Type u} (p : β → Prop) (x : F (α ::: β)) : liftp' (typevec.pred_last' α p) x ↔ liftp (typevec.pred_last α p) x := sorry
theorem liftr_last_rel_iff {n : ℕ} {F : typevec (n + 1) → Type u_1} [mvfunctor F] [is_lawful_mvfunctor F] {α : typevec n} {β : Type u} (rr : β → β → Prop) (x : F (α ::: β)) (y : F (α ::: β)) : liftr' (typevec.rel_last' α rr) x y ↔ liftr (typevec.rel_last α rr) x y := sorry
|
0b6064f510ca66f9124652338cc6c67b4dc853ac
|
618003631150032a5676f229d13a079ac875ff77
|
/archive/examples/prop_encodable.lean
|
e441124c42a981fed12a36cd661245cbf1a04f69
|
[
"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
| 2,972
|
lean
|
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
-/
import data.W
/-!
# W types
The file `data/W.lean` shows that if `α` is an an encodable fintype and for every `a : α`,
`β a` is encodable, then `W β` is encodable.
As an example of how this can be used, we show that the type of propositional formulas with
variables labeled from an encodable type is encodable.
The strategy is to define a type of labels corresponding to the constructors.
From the definition (using `sum`, `unit`, and an encodable type), Lean can infer
that it is encodable. We then define a map from propositional formulas to the
corresponding `Wfin` type, and show that map has a left inverse.
We mark the auxiliary constructions `private`, since their only purpose is to
show encodability.
-/
/-- Propositional formulas with labels from `α`. -/
inductive prop_form (α : Type*)
| var : α → prop_form
| not : prop_form → prop_form
| and : prop_form → prop_form → prop_form
| or : prop_form → prop_form → prop_form
/-!
The next three functions make it easier to construct functions from a small
`fin`.
-/
section
variable {α : Type*}
/-- the trivial function out of `fin 0`. -/
def mk_fn0 : fin 0 → α
| ⟨_, h⟩ := absurd h dec_trivial
/-- defines a function out of `fin 1` -/
def mk_fn1 (t : α) : fin 1 → α
| ⟨0, _⟩ := t
| ⟨n+1, h⟩ := absurd h dec_trivial
/-- defines a function out of `fin 2` -/
def mk_fn2 (s t : α) : fin 2 → α
| ⟨0, _⟩ := s
| ⟨1, _⟩ := t
| ⟨n+2, h⟩ := absurd h dec_trivial
attribute [simp] mk_fn0 mk_fn1 mk_fn2
end
namespace prop_form
private def constructors (α : Type*) := α ⊕ unit ⊕ unit ⊕ unit
local notation `cvar` a := sum.inl a
local notation `cnot` := sum.inr (sum.inl unit.star)
local notation `cand` := sum.inr (sum.inr (sum.inr unit.star))
local notation `cor` := sum.inr (sum.inr (sum.inl unit.star))
@[simp]
private def arity (α : Type*) : constructors α → nat
| (cvar a) := 0
| cnot := 1
| cand := 2
| cor := 2
variable {α : Type*}
private def f : prop_form α → W (λ i, fin (arity α i))
| (var a) := ⟨cvar a, mk_fn0⟩
| (not p) := ⟨cnot, mk_fn1 (f p)⟩
| (and p q) := ⟨cand, mk_fn2 (f p) (f q)⟩
| (or p q) := ⟨cor, mk_fn2 (f p) (f q)⟩
private def finv : W (λ i, fin (arity α i)) → prop_form α
| ⟨cvar a, fn⟩ := var a
| ⟨cnot, fn⟩ := not (finv (fn ⟨0, dec_trivial⟩))
| ⟨cand, fn⟩ := and (finv (fn ⟨0, dec_trivial⟩)) (finv (fn ⟨1, dec_trivial⟩))
| ⟨cor, fn⟩ := or (finv (fn ⟨0, dec_trivial⟩)) (finv (fn ⟨1, dec_trivial⟩))
instance [encodable α] : encodable (prop_form α) :=
begin
haveI : encodable (constructors α) :=
by { unfold constructors, apply_instance },
exact encodable.of_left_inverse f finv
(by { intro p, induction p; simp [f, finv, *] })
end
end prop_form
|
29bc0e3c67fa24b7d07b91556f50e65e5fc2566a
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/1315b.lean
|
6bf710ce3547f5a618bf6a1cc413dc3f3259b7e5
|
[
"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
| 997
|
lean
|
open nat
def k : ℕ := 0
def fails : Π (n : ℕ) (m : ℕ), ℕ
| 0 m := 0
| (succ n) m :=
match k with
| 0 := 0
| (succ i) :=
let val := m+1 in
match fails n val with
| 0 := 0
| (succ l) := 0
end
end
def test (k : ℕ) : Π (n : ℕ) (m : ℕ), ℕ
| 0 m := 0
| (succ n) m :=
match k with
| 0 := 1
| (succ i) :=
let val := m+1 in
match test n val with
| 0 := 2
| (succ l) := 3
end
end
example (k m : ℕ) : test k 0 m = 0 :=
rfl
example (m n : ℕ) : test 0 (succ n) m = 1 :=
rfl
example (k m : ℕ) : test (succ k) 1 m = 2 :=
rfl
example (k m : ℕ) : test (succ k) 2 m = 3 :=
rfl
example (k m : ℕ) : test (succ k) 3 m = 3 :=
rfl
open tactic
run_cmd do
t ← infer_type `(test._match_2),
trace t,
tactic.interactive.guard_expr_eq t ```(nat → nat)
example (k m n : ℕ) : test (succ k) (succ (succ n)) m = 3 :=
begin
revert m,
induction n with n',
{ intro, reflexivity},
{ intro,
simp [test, n_ih] }
end
|
97b033ce77446387f631d4cc99404cea50c2db65
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/topology/instances/ennreal.lean
|
854a59f00a93a092b44f02d16046c0bb2d854451
|
[
"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
| 41,822
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
-/
import topology.instances.nnreal
/-!
# Extended non-negative reals
-/
noncomputable theory
open classical set filter metric
open_locale classical topological_space ennreal nnreal big_operators filter
variables {α : Type*} {β : Type*} {γ : Type*}
namespace ennreal
variables {a b c d : ennreal} {r p q : nnreal}
variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal}
section topological_space
open topological_space
/-- Topology on `ennreal`.
Note: this is different from the `emetric_space` topology. The `emetric_space` topology has
`is_open {⊤}`, while this topology doesn't have singleton elements. -/
instance : topological_space ennreal := preorder.topology ennreal
instance : order_topology ennreal := ⟨rfl⟩
instance : t2_space ennreal := by apply_instance -- short-circuit type class inference
instance : second_countable_topology ennreal :=
⟨⟨⋃q ≥ (0:ℚ), {{a : ennreal | a < nnreal.of_real q}, {a : ennreal | ↑(nnreal.of_real q) < a}},
(countable_encodable _).bUnion $ assume a ha, (countable_singleton _).insert _,
le_antisymm
(le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt})
(le_generate_from $ λ s h, begin
rcases h with ⟨a, hs | hs⟩;
[ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < nnreal.of_real q}, {b | ↑(nnreal.of_real q) < b},
from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]),
rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(nnreal.of_real q) < a}, {b | b < ↑(nnreal.of_real q)},
from set.ext (assume b,
by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])];
{ apply is_open_Union, intro q,
apply is_open_Union, intro hq,
exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) }
end)⟩⟩
lemma embedding_coe : embedding (coe : nnreal → ennreal) :=
⟨⟨begin
refine le_antisymm _ _,
{ rw [@order_topology.topology_eq_generate_intervals ennreal _,
← coinduced_le_iff_le_induced],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
show is_open {b : nnreal | a < ↑b},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] },
show is_open {b : nnreal | ↑b < a},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } },
{ rw [@order_topology.topology_eq_generate_intervals nnreal _],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
exact ⟨Ioi a, is_open_Ioi, by simp [Ioi]⟩,
exact ⟨Iio a, is_open_Iio, by simp [Iio]⟩ }
end⟩,
assume a b, coe_eq_coe.1⟩
lemma is_open_ne_top : is_open {a : ennreal | a ≠ ⊤} := is_open_ne
lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio}
lemma coe_range_mem_nhds : range (coe : nnreal → ennreal) ∈ 𝓝 (r : ennreal) :=
have {a : ennreal | a ≠ ⊤} = range (coe : nnreal → ennreal),
from set.ext $ assume a, by cases a; simp [none_eq_top, some_eq_coe],
this ▸ mem_nhds_sets is_open_ne_top coe_ne_top
@[norm_cast] lemma tendsto_coe {f : filter α} {m : α → nnreal} {a : nnreal} :
tendsto (λa, (m a : ennreal)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) :=
embedding_coe.tendsto_nhds_iff.symm
lemma continuous_coe : continuous (coe : nnreal → ennreal) :=
embedding_coe.continuous
lemma continuous_coe_iff {α} [topological_space α] {f : α → nnreal} :
continuous (λa, (f a : ennreal)) ↔ continuous f :=
embedding_coe.continuous_iff.symm
lemma nhds_coe {r : nnreal} : 𝓝 (r : ennreal) = (𝓝 r).map coe :=
by rw [embedding_coe.induced, map_nhds_induced_eq coe_range_mem_nhds]
lemma nhds_coe_coe {r p : nnreal} : 𝓝 ((r : ennreal), (p : ennreal)) =
(𝓝 (r, p)).map (λp:nnreal×nnreal, (p.1, p.2)) :=
begin
rw [(embedding_coe.prod_mk embedding_coe).map_nhds_eq],
rw [← prod_range_range_eq],
exact prod_mem_nhds_sets coe_range_mem_nhds coe_range_mem_nhds
end
lemma continuous_of_real : continuous ennreal.of_real :=
(continuous_coe_iff.2 continuous_id).comp nnreal.continuous_of_real
lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (𝓝 a)) :
tendsto (λa, ennreal.of_real (m a)) f (𝓝 (ennreal.of_real a)) :=
tendsto.comp (continuous.tendsto continuous_of_real _) h
lemma tendsto_to_nnreal {a : ennreal} : a ≠ ⊤ →
tendsto (ennreal.to_nnreal) (𝓝 a) (𝓝 a.to_nnreal) :=
begin
cases a; simp [some_eq_coe, none_eq_top, nhds_coe, tendsto_map'_iff, (∘)],
exact tendsto_id
end
lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a ≠ ∞} :=
continuous_on_iff_continuous_restrict.2 $ continuous_iff_continuous_at.2 $ λ x,
(tendsto_to_nnreal x.2).comp continuous_at_subtype_coe
lemma tendsto_to_real {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_real) (𝓝 a) (𝓝 a.to_real) :=
λ ha, tendsto.comp ((@nnreal.tendsto_coe _ (𝓝 a.to_nnreal) id (a.to_nnreal)).2 tendsto_id)
(tendsto_to_nnreal ha)
/-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/
def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ nnreal :=
{ continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal,
continuous_inv_fun := continuous_subtype_mk _ continuous_coe,
.. ne_top_equiv_nnreal }
/-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/
def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ nnreal :=
by refine (homeomorph.set_congr $ set.ext $ λ x, _).trans ne_top_homeomorph_nnreal;
simp only [mem_set_of_eq, lt_top_iff_ne_top]
lemma nhds_top : 𝓝 ∞ = ⨅ a ≠ ∞, 𝓟 (Ioi a) :=
nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi]
lemma nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi r) :=
nhds_top.trans $ infi_ne_top _
lemma tendsto_nhds_top_iff_nnreal {m : α → ennreal} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a :=
by simp only [nhds_top', tendsto_infi, tendsto_principal, mem_Ioi]
lemma tendsto_nhds_top_iff_nat {m : α → ennreal} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a :=
tendsto_nhds_top_iff_nnreal.trans ⟨λ h n, by simpa only [ennreal.coe_nat] using h n,
λ h x, let ⟨n, hn⟩ := exists_nat_gt x in
(h n).mono (λ y, lt_trans $ by rwa [← ennreal.coe_nat, coe_lt_coe])⟩
lemma tendsto_nhds_top {m : α → ennreal} {f : filter α}
(h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : tendsto m f (𝓝 ⊤) :=
tendsto_nhds_top_iff_nat.2 h
lemma tendsto_nat_nhds_top : tendsto (λ n : ℕ, ↑n) at_top (𝓝 ∞) :=
tendsto_nhds_top $ λ n, mem_at_top_sets.2
⟨n+1, λ m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hm⟩
@[simp, norm_cast] lemma tendsto_coe_nhds_top {f : α → ℝ≥0} {l : filter α} :
tendsto (λ x, (f x : ennreal)) l (𝓝 ∞) ↔ tendsto f l at_top :=
by rw [tendsto_nhds_top_iff_nnreal, at_top_basis_Ioi.tendsto_right_iff];
[simp, apply_instance, apply_instance]
lemma nhds_zero : 𝓝 (0 : ennreal) = ⨅a ≠ 0, 𝓟 (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio]
-- using Icc because
-- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0
-- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not
lemma Icc_mem_nhds : x ≠ ⊤ → 0 < ε → Icc (x - ε) (x + ε) ∈ 𝓝 x :=
begin
assume xt ε0, rw mem_nhds_sets_iff,
by_cases x0 : x = 0,
{ use Iio (x + ε),
have : Iio (x + ε) ⊆ Icc (x - ε) (x + ε), assume a, rw x0, simpa using le_of_lt,
use this, exact ⟨is_open_Iio, mem_Iio_self_add xt ε0⟩ },
{ use Ioo (x - ε) (x + ε), use Ioo_subset_Icc_self,
exact ⟨is_open_Ioo, mem_Ioo_self_sub_add xt x0 ε0 ε0 ⟩ }
end
lemma nhds_of_ne_top : x ≠ ⊤ → 𝓝 x = ⨅ε > 0, 𝓟 (Icc (x - ε) (x + ε)) :=
begin
assume xt, refine le_antisymm _ _,
-- first direction
simp only [le_infi_iff, le_principal_iff], assume ε ε0, exact Icc_mem_nhds xt ε0,
-- second direction
rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _),
simp only [mem_set_of_eq] at hs, rcases hs with ⟨xs, ⟨a, ha⟩⟩,
cases ha,
{ rw ha at *,
rcases exists_between xs with ⟨b, ⟨ab, bx⟩⟩,
have xb_pos : x - b > 0 := zero_lt_sub_iff_lt.2 bx,
have xxb : x - (x - b) = b := sub_sub_cancel (by rwa lt_top_iff_ne_top) (le_of_lt bx),
refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _),
simp only [mem_principal_sets, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xxb at h₁, calc a < b : ab ... ≤ y : h₁ },
{ rw ha at *,
rcases exists_between xs with ⟨b, ⟨xb, ba⟩⟩,
have bx_pos : b - x > 0 := zero_lt_sub_iff_lt.2 xb,
have xbx : x + (b - x) = b := add_sub_cancel_of_le (le_of_lt xb),
refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _),
simp only [mem_principal_sets, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xbx at h₂, calc y ≤ b : h₂ ... < a : ba },
end
/-- Characterization of neighborhoods for `ennreal` numbers. See also `tendsto_order`
for a version with strict inequalities. -/
protected theorem tendsto_nhds {f : filter α} {u : α → ennreal} {a : ennreal} (ha : a ≠ ⊤) :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, (u x) ∈ Icc (a - ε) (a + ε) :=
by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc]
protected lemma tendsto_at_top [nonempty β] [semilattice_sup β] {f : β → ennreal} {a : ennreal}
(ha : a ≠ ⊤) : tendsto f at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, (f n) ∈ Icc (a - ε) (a + ε) :=
by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually]
instance : has_continuous_add ennreal :=
begin
refine ⟨continuous_iff_continuous_at.2 _⟩,
rintro ⟨(_|a), b⟩,
{ exact tendsto_nhds_top_mono' continuous_at_fst (λ p, le_add_right le_rfl) },
rcases b with (_|b),
{ exact tendsto_nhds_top_mono' continuous_at_snd (λ p, le_add_left le_rfl) },
simp only [continuous_at, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (∘),
tendsto_coe, tendsto_add]
end
protected lemma tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) :=
have ht : ∀b:ennreal, b ≠ 0 → tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 ((⊤:ennreal), b)) (𝓝 ⊤),
begin
refine assume b hb, tendsto_nhds_top $ assume n, _,
rcases exists_between (zero_lt_iff_ne_zero.2 hb) with ⟨ε', hε', hεb'⟩,
rcases ennreal.lt_iff_exists_coe.1 hεb' with ⟨ε, rfl, h⟩,
rcases exists_nat_gt (↑n / ε) with ⟨m, hm⟩,
have hε : ε > 0, from coe_lt_coe.1 hε',
filter_upwards [prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top m) (lt_mem_nhds $ h)],
rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩,
dsimp at h₁ h₂ ⊢,
calc (n:ennreal) = ↑(((n:nnreal) / ε) * ε) :
begin
norm_cast,
simp [nnreal.div_def, mul_assoc, nnreal.inv_mul_cancel (ne_of_gt hε)]
end
... < (↑m * ε : nnreal) : coe_lt_coe.2 $ mul_lt_mul hm (le_refl _) hε (nat.cast_nonneg _)
... ≤ a₁ * a₂ : by rw [coe_mul]; exact canonically_ordered_semiring.mul_le_mul
(le_of_lt h₁)
(le_of_lt h₂)
end,
begin
cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] },
cases b, {
simp [none_eq_top] at ha,
simp [*, nhds_swap (a : ennreal) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘),
mul_comm] },
simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)],
simp only [coe_mul.symm, tendsto_coe, tendsto_mul]
end
protected lemma tendsto.mul {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λa, ma a * mb a) f (𝓝 (a * b)) :=
show tendsto ((λp:ennreal×ennreal, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (𝓝 (a * b)), from
tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb)
protected lemma tendsto.const_mul {f : filter α} {m : α → ennreal} {a b : ennreal}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (𝓝 (a * b)) :=
by_cases
(assume : a = 0, by simp [this, tendsto_const_nhds])
(assume ha : a ≠ 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb)
protected lemma tendsto.mul_const {f : filter α} {m : α → ennreal} {a b : ennreal}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : tendsto (λx, m x * b) f (𝓝 (a * b)) :=
by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha
protected lemma continuous_at_const_mul {a b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at ((*) a) b :=
tendsto.const_mul tendsto_id h.symm
protected lemma continuous_at_mul_const {a b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at (λ x, x * a) b :=
tendsto.mul_const tendsto_id h.symm
protected lemma continuous_const_mul {a : ennreal} (ha : a ≠ ⊤) : continuous ((*) a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_const_mul (or.inl ha)
protected lemma continuous_mul_const {a : ennreal} (ha : a ≠ ⊤) : continuous (λ x, x * a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_mul_const (or.inl ha)
lemma infi_mul_left {ι} [nonempty ι] {f : ι → ennreal} {a : ennreal}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, a * f i) = a * ⨅ i, f i :=
begin
by_cases H : a = ⊤ ∧ (⨅ i, f i) = 0,
{ rcases h H.1 H.2 with ⟨i, hi⟩,
rw [H.2, mul_zero, ← bot_eq_zero, infi_eq_bot],
exact λ b hb, ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ },
{ rw not_and_distrib at H,
exact (map_infi_of_continuous_at_of_monotone' (ennreal.continuous_at_const_mul H)
ennreal.mul_left_mono).symm }
end
lemma infi_mul_right {ι} [nonempty ι] {f : ι → ennreal} {a : ennreal}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, f i * a) = (⨅ i, f i) * a :=
by simpa only [mul_comm a] using infi_mul_left h
protected lemma continuous_inv : continuous (has_inv.inv : ennreal → ennreal) :=
continuous_iff_continuous_at.2 $ λ a, tendsto_order.2
⟨begin
assume b hb,
simp only [@ennreal.lt_inv_iff_lt_inv b],
exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb),
end,
begin
assume b hb,
simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b],
exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb)
end⟩
@[simp] protected lemma tendsto_inv_iff {f : filter α} {m : α → ennreal} {a : ennreal} :
tendsto (λ x, (m x)⁻¹) f (𝓝 a⁻¹) ↔ tendsto m f (𝓝 a) :=
⟨λ h, by simpa only [function.comp, ennreal.inv_inv]
using (ennreal.continuous_inv.tendsto a⁻¹).comp h,
(ennreal.continuous_inv.tendsto a).comp⟩
protected lemma tendsto.div {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) :
tendsto (λa, ma a / mb a) f (𝓝 (a / b)) :=
by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] }
protected lemma tendsto.const_div {f : filter α} {m : α → ennreal} {a b : ennreal}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λb, a / m b) f (𝓝 (a / b)) :=
by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] }
protected lemma tendsto.div_const {f : filter α} {m : α → ennreal} {a b : ennreal}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : tendsto (λx, m x / b) f (𝓝 (a / b)) :=
by { apply tendsto.mul_const hm, simp [ha] }
protected lemma tendsto_inv_nat_nhds_zero : tendsto (λ n : ℕ, (n : ennreal)⁻¹) at_top (𝓝 0) :=
ennreal.inv_top ▸ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top
lemma Sup_add {s : set ennreal} (hs : s.nonempty) : Sup s + a = ⨆b∈s, b + a :=
have Sup ((λb, b + a) '' s) = Sup s + a,
from is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto
(assume x _ y _ h, add_le_add h (le_refl _))
(is_lub_Sup s)
hs
(tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds)),
by simp [Sup_image, -add_comm] at this; exact this.symm
lemma supr_add {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : supr s + a = ⨆b, s b + a :=
let ⟨x⟩ := h in
calc supr s + a = Sup (range s) + a : by simp [Sup_range]
... = (⨆b∈range s, b + a) : Sup_add ⟨s x, x, rfl⟩
... = _ : supr_range
lemma add_supr {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : a + supr s = ⨆b, a + s b :=
by rw [add_comm, supr_add]; simp [add_comm]
lemma supr_add_supr {ι : Sort*} {f g : ι → ennreal} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) :
supr f + supr g = (⨆ a, f a + g a) :=
begin
by_cases hι : nonempty ι,
{ letI := hι,
refine le_antisymm _ (supr_le $ λ a, add_le_add (le_supr _ _) (le_supr _ _)),
simpa [add_supr, supr_add] using
λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from
let ⟨k, hk⟩ := h i j in le_supr_of_le k hk },
{ have : ∀f:ι → ennreal, (⨆i, f i) = 0 := λ f, bot_unique (supr_le $ assume i, (hι ⟨i⟩).elim),
rw [this, this, this, zero_add] }
end
lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι]
{f g : ι → ennreal} (hf : monotone f) (hg : monotone g) :
supr f + supr g = (⨆ a, f a + g a) :=
supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add (hf $ le_sup_left) (hg $ le_sup_right)⟩
lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ennreal}
(hf : ∀a, monotone (f a)) :
∑ a in s, supr (f a) = (⨆ n, ∑ a in s, f a n) :=
begin
refine finset.induction_on s _ _,
{ simp,
exact (bot_unique $ supr_le $ assume i, le_refl ⊥).symm },
{ assume a s has ih,
simp only [finset.sum_insert has],
rw [ih, supr_add_supr_of_monotone (hf a)],
assume i j h,
exact (finset.sum_le_sum $ assume a ha, hf a h) }
end
section priority
-- for some reason the next proof fails without changing the priority of this instance
local attribute [instance, priority 1000] classical.prop_decidable
lemma mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = ⨆i∈s, a * i :=
begin
by_cases hs : ∀x∈s, x = (0:ennreal),
{ have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0),
have h₂ : (⨆i ∈ s, a * i) = 0 :=
(bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]),
rw [h₁, h₂, mul_zero] },
{ simp only [not_forall] at hs,
rcases hs with ⟨x, hx, hx0⟩,
have s₁ : Sup s ≠ 0 :=
zero_lt_iff_ne_zero.1 (lt_of_lt_of_le (zero_lt_iff_ne_zero.2 hx0) (le_Sup hx)),
have : Sup ((λb, a * b) '' s) = a * Sup s :=
is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto
(assume x _ y _ h, canonically_ordered_semiring.mul_le_mul (le_refl _) h)
(is_lub_Sup _)
⟨x, hx⟩
(ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl s₁))),
rw [this.symm, Sup_image] }
end
end priority
lemma mul_supr {ι : Sort*} {f : ι → ennreal} {a : ennreal} : a * supr f = ⨆i, a * f i :=
by rw [← Sup_range, mul_Sup, supr_range]
lemma supr_mul {ι : Sort*} {f : ι → ennreal} {a : ennreal} : supr f * a = ⨆i, f i * a :=
by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm]
protected lemma tendsto_coe_sub : ∀{b:ennreal}, tendsto (λb:ennreal, ↑r - b) (𝓝 b) (𝓝 (↑r - b)) :=
begin
refine (forall_ennreal.2 $ and.intro (assume a, _) _),
{ simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, coe_sub.symm],
exact tendsto_const_nhds.sub tendsto_id },
simp,
exact (tendsto.congr' (mem_sets_of_superset (lt_mem_nhds $ @coe_lt_top r) $
by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds
end
lemma sub_supr {ι : Sort*} [hι : nonempty ι] {b : ι → ennreal} (hr : a < ⊤) :
a - (⨆i, b i) = (⨅i, a - b i) :=
let ⟨i⟩ := hι in
let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in
have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i),
from is_glb.Inf_eq $ is_glb_of_is_lub_of_tendsto
(assume x _ y _, sub_le_sub (le_refl _))
is_lub_supr
⟨_, i, rfl⟩
(tendsto.comp ennreal.tendsto_coe_sub (tendsto_id' inf_le_left)),
by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _
end topological_space
section tsum
variables {f g : α → ennreal}
@[norm_cast] protected lemma has_sum_coe {f : α → ℝ≥0} {r : nnreal} :
has_sum (λa, (f a : ennreal)) ↑r ↔ has_sum f r :=
have (λs:finset α, ∑ a in s, ↑(f a)) = (coe : nnreal → ennreal) ∘ (λs:finset α, ∑ a in s, f a),
from funext $ assume s, ennreal.coe_finset_sum.symm,
by unfold has_sum; rw [this, tendsto_coe]
protected lemma tsum_coe_eq {f : α → nnreal} (h : has_sum f r) : (∑'a, (f a : ennreal)) = r :=
(ennreal.has_sum_coe.2 h).tsum_eq
protected lemma coe_tsum {f : α → nnreal} : summable f → ↑(tsum f) = (∑'a, (f a : ennreal))
| ⟨r, hr⟩ := by rw [hr.tsum_eq, ennreal.tsum_coe_eq hr]
protected lemma has_sum : has_sum f (⨆s:finset α, ∑ a in s, f a) :=
tendsto_order.2
⟨assume a' ha',
let ⟨s, hs⟩ := lt_supr_iff.mp ha' in
mem_at_top_sets.mpr ⟨s, assume t ht, lt_of_lt_of_le hs $ finset.sum_le_sum_of_subset ht⟩,
assume a' ha',
univ_mem_sets' $ assume s,
have ∑ a in s, f a ≤ ⨆(s : finset α), ∑ a in s, f a,
from le_supr (λ(s : finset α), ∑ a in s, f a) s,
lt_of_le_of_lt this ha'⟩
@[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩
lemma tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} :
(∑' b, (f b:ennreal)) ≠ ∞ ↔ summable f :=
begin
refine ⟨λ h, _, λ h, ennreal.coe_tsum h ▸ ennreal.coe_ne_top⟩,
lift (∑' b, (f b:ennreal)) to nnreal using h with a ha,
refine ⟨a, ennreal.has_sum_coe.1 _⟩,
rw ha,
exact ennreal.summable.has_sum
end
protected lemma tsum_eq_supr_sum : (∑'a, f a) = (⨆s:finset α, ∑ a in s, f a) :=
ennreal.has_sum.tsum_eq
protected lemma tsum_eq_supr_sum' {ι : Type*} (s : ι → finset α) (hs : ∀ t, ∃ i, t ⊆ s i) :
(∑' a, f a) = ⨆ i, ∑ a in s i, f a :=
begin
rw [ennreal.tsum_eq_supr_sum],
symmetry,
change (⨆i:ι, (λ t : finset α, ∑ a in t, f a) (s i)) = ⨆s:finset α, ∑ a in s, f a,
exact (finset.sum_mono_set f).supr_comp_eq hs
end
protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ennreal) :
(∑'p:Σa, β a, f p.1 p.2) = (∑'a b, f a b) :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_sigma' {β : α → Type*} (f : (Σ a, β a) → ennreal) :
(∑'p:(Σa, β a), f p) = (∑'a b, f ⟨a, b⟩) :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_prod {f : α → β → ennreal} : (∑'p:α×β, f p.1 p.2) = (∑'a, ∑'b, f a b) :=
tsum_prod' ennreal.summable $ λ _, ennreal.summable
protected lemma tsum_comm {f : α → β → ennreal} : (∑'a, ∑'b, f a b) = (∑'b, ∑'a, f a b) :=
tsum_comm' ennreal.summable (λ _, ennreal.summable) (λ _, ennreal.summable)
protected lemma tsum_add : (∑'a, f a + g a) = (∑'a, f a) + (∑'a, g a) :=
tsum_add ennreal.summable ennreal.summable
protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : (∑'a, f a) ≤ (∑'a, g a) :=
tsum_le_tsum h ennreal.summable ennreal.summable
protected lemma sum_le_tsum {f : α → ennreal} (s : finset α) : ∑ x in s, f x ≤ ∑' x, f x :=
sum_le_tsum s (λ x hx, zero_le _) ennreal.summable
protected lemma tsum_eq_supr_nat' {f : ℕ → ennreal} {N : ℕ → ℕ} (hN : tendsto N at_top at_top) :
(∑'i:ℕ, f i) = (⨆i:ℕ, ∑ a in finset.range (N i), f a) :=
ennreal.tsum_eq_supr_sum' _ $ λ t,
let ⟨n, hn⟩ := t.exists_nat_subset_range,
⟨k, _, hk⟩ := exists_le_of_tendsto_at_top hN 0 n in
⟨k, finset.subset.trans hn (finset.range_mono hk)⟩
protected lemma tsum_eq_supr_nat {f : ℕ → ennreal} :
(∑'i:ℕ, f i) = (⨆i:ℕ, ∑ a in finset.range i, f a) :=
ennreal.tsum_eq_supr_sum' _ finset.exists_nat_subset_range
protected lemma le_tsum (a : α) : f a ≤ (∑'a, f a) :=
le_tsum' ennreal.summable a
protected lemma tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → (∑' a, f a) = ∞
| ⟨a, ha⟩ := top_unique $ ha ▸ ennreal.le_tsum a
protected lemma ne_top_of_tsum_ne_top (h : (∑' a, f a) ≠ ∞) (a : α) : f a ≠ ∞ :=
λ ha, h $ ennreal.tsum_eq_top_of_eq_top ⟨a, ha⟩
protected lemma tsum_mul_left : (∑'i, a * f i) = a * (∑'i, f i) :=
if h : ∀i, f i = 0 then by simp [h] else
let ⟨i, (hi : f i ≠ 0)⟩ := not_forall.mp h in
have sum_ne_0 : (∑'i, f i) ≠ 0, from ne_of_gt $
calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm
... ≤ (∑'i, f i) : ennreal.le_tsum _,
have tendsto (λs:finset α, ∑ j in s, a * f j) at_top (𝓝 (a * (∑'i, f i))),
by rw [← show (*) a ∘ (λs:finset α, ∑ j in s, f j) = λs, ∑ j in s, a * f j,
from funext $ λ s, finset.mul_sum];
exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0),
has_sum.tsum_eq this
protected lemma tsum_mul_right : (∑'i, f i * a) = (∑'i, f i) * a :=
by simp [mul_comm, ennreal.tsum_mul_left]
@[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ennreal} :
(∑'b:α, ⨆ (h : a = b), f b) = f a :=
le_antisymm
(by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s,
calc (∑ b in s, ⨆ (h : a = b), f b) ≤ ∑ b in {a}, ⨆ (h : a = b), f b :
finset.sum_le_sum_of_ne_zero $ assume b _ hb,
suffices a = b, by simpa using this.symm,
classical.by_contradiction $ assume h,
by simpa [h] using hb
... = f a : by simp))
(calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl
... ≤ (∑'b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _)
lemma has_sum_iff_tendsto_nat {f : ℕ → ennreal} (r : ennreal) :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
refine ⟨has_sum.tendsto_sum_nat, assume h, _⟩,
rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat],
{ exact ennreal.summable.has_sum },
{ exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) }
end
lemma to_nnreal_apply_of_tsum_ne_top {α : Type*} {f : α → ennreal} (hf : (∑' i, f i) ≠ ∞) (x : α) :
(((ennreal.to_nnreal ∘ f) x : nnreal) : ennreal) = f x :=
coe_to_nnreal $ ennreal.ne_top_of_tsum_ne_top hf _
lemma summable_to_nnreal_of_tsum_ne_top {α : Type*} {f : α → ennreal} (hf : (∑' i, f i) ≠ ∞) :
summable (ennreal.to_nnreal ∘ f) :=
by simpa only [←tsum_coe_ne_top_iff_summable, to_nnreal_apply_of_tsum_ne_top hf] using hf
protected lemma tsum_apply {ι α : Type*} {f : ι → α → ennreal} {x : α} :
(∑' i, f i) x = ∑' i, f i x :=
tsum_apply $ pi.summable.mpr $ λ _, ennreal.summable
lemma tsum_sub {f : ℕ → ennreal} {g : ℕ → ennreal} (h₁ : (∑' i, g i) < ∞) (h₂ : g ≤ f) :
(∑' i, (f i - g i)) = (∑' i, f i) - (∑' i, g i) :=
begin
have h₃:(∑' i, (f i - g i)) = (∑' i, (f i - g i) + (g i))-(∑' i, g i),
{ rw [ennreal.tsum_add, add_sub_self h₁]},
have h₄:(λ i, (f i - g i) + (g i)) = f,
{ ext n, rw ennreal.sub_add_cancel_of_le (h₂ n)},
rw h₄ at h₃, apply h₃,
end
end tsum
end ennreal
namespace nnreal
open_locale nnreal
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma exists_le_has_sum_of_le {f g : β → ℝ≥0} {r : ℝ≥0}
(hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p :=
have (∑'b, (g b : ennreal)) ≤ r,
begin
refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr),
exact ennreal.coe_le_coe.2 (hgf _)
end,
let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in
⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ ennreal.summable.has_sum⟩
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma summable_of_le {f g : β → ℝ≥0} (hgf : ∀b, g b ≤ f b) : summable f → summable g
| ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in hp.summable
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat],
simp only [ennreal.coe_finset_sum.symm],
exact ennreal.tendsto_coe
end
lemma not_summable_iff_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
split,
{ intros h,
refine ((tendsto_of_monotone _).resolve_right h).comp _,
exacts [finset.sum_mono_set _, tendsto_finset_range] },
{ rintros hnat ⟨r, hr⟩,
exact not_tendsto_nhds_of_tendsto_at_top hnat _ (has_sum_iff_tendsto_nat.1 hr) }
end
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : summable f)
{i : β → α} (hi : function.injective i) : (∑' x, f (i x)) ≤ ∑' x, f x :=
tsum_le_tsum_of_inj i hi (λ c hc, zero_le _) (λ b, le_refl _) (summable_comp_injective hf hi) hf
open finset
/-- If `f : ℕ → ℝ≥0` and `∑' f` exists, then `∑' k, f (k + i)` tends to zero. -/
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0) (hf : summable f) :
tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
have h₀ : (λ i, (∑' i, f i) - ∑ j in range i, f j) = λ i, ∑' (k : ℕ), f (k + i),
{ ext1 i,
rw [sub_eq_iff_eq_add, sum_add_tsum_nat_add i hf, add_comm],
exact sum_le_tsum _ (λ _ _, zero_le _) hf },
have h₁ : tendsto (λ i : ℕ, ∑' i, f i) at_top (𝓝 (∑' i, f i)) := tendsto_const_nhds,
simpa only [h₀, sub_self] using tendsto.sub h₁ hf.has_sum.tendsto_sum_nat
end
end nnreal
namespace ennreal
lemma tendsto_sum_nat_add (f : ℕ → ennreal) (hf : (∑' i, f i) ≠ ∞) :
tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
have : ∀ i, (∑' k, (((ennreal.to_nnreal ∘ f) (k + i) : nnreal) : ennreal)) =
(∑' k, (ennreal.to_nnreal ∘ f) (k + i) : nnreal) :=
λ i, (ennreal.coe_tsum
(nnreal.summable_nat_add _ (summable_to_nnreal_of_tsum_ne_top hf) _)).symm,
simp only [λ x, (to_nnreal_apply_of_tsum_ne_top hf x).symm, ←ennreal.coe_zero,
this, ennreal.tendsto_coe] { single_pass := tt },
exact nnreal.tendsto_sum_nat_add _ (summable_to_nnreal_of_tsum_ne_top hf)
end
end ennreal
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : summable f) (hn : ∀ a, 0 ≤ f a)
{i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f :=
begin
let g : α → nnreal := λ a, ⟨f a, hn a⟩,
have hg : summable g, by rwa ← nnreal.summable_coe,
convert nnreal.coe_le_coe.2 (nnreal.tsum_comp_le_tsum_of_inj hg hi);
{ rw nnreal.coe_tsum, congr }
end
/-- Comparison test of convergence of series of non-negative real numbers. -/
lemma summable_of_nonneg_of_le {f g : β → ℝ}
(hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g :=
let f' (b : β) : nnreal := ⟨f b, le_trans (hg b) (hgf b)⟩ in
let g' (b : β) : nnreal := ⟨g b, hg b⟩ in
have summable f', from nnreal.summable_coe.1 hf,
have summable g', from
nnreal.summable_of_le (assume b, (@nnreal.coe_le_coe (g' b) (f' b)).2 $ hgf b) this,
show summable (λb, g' b : β → ℝ), from nnreal.summable_coe.2 this
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) :
has_sum f r ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
lift f to ℕ → ℝ≥0 using hf,
simp only [has_sum, ← nnreal.coe_sum, nnreal.tendsto_coe'],
exact exists_congr (λ hr, nnreal.has_sum_iff_tendsto_nat)
end
lemma not_summable_iff_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
lift f to ℕ → ℝ≥0 using hf,
exact_mod_cast nnreal.not_summable_iff_tendsto_nat_at_top
end
section
variables [emetric_space β]
open ennreal filter emetric
/-- In an emetric ball, the distance between points is everywhere finite -/
lemma edist_ne_top_of_mem_ball {a : β} {r : ennreal} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ :=
lt_top_iff_ne_top.1 $
calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a
... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2
... ≤ ⊤ : le_top
/-- Each ball in an extended metric space gives us a metric space, as the edist
is everywhere finite. -/
def metric_space_emetric_ball (a : β) (r : ennreal) : metric_space (ball a r) :=
emetric_space.to_metric_space edist_ne_top_of_mem_ball
local attribute [instance] metric_space_emetric_ball
lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ennreal) (h : x ∈ ball a r) :
𝓝 x = map (coe : ball a r → β) (𝓝 ⟨x, h⟩) :=
(map_nhds_subtype_coe_eq _ $ mem_nhds_sets emetric.is_open_ball h).symm
end
section
variable [emetric_space α]
open emetric
lemma tendsto_iff_edist_tendsto_0 {l : filter β} {f : β → α} {y : α} :
tendsto f l (𝓝 y) ↔ tendsto (λ x, edist (f x) y) l (𝓝 0) :=
by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball,
@tendsto_order ennreal β _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and]
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty β] [semilattice_sup β] {s : β → α} :
cauchy_seq s ↔ (∃ (b: β → ennreal), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N)
∧ (tendsto b at_top (𝓝 0))) :=
⟨begin
assume hs,
rw emetric.cauchy_seq_iff at hs,
/- `s` is 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`-/
let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}),
--Prove that it bounds the distances of points in the Cauchy sequence
have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
{ refine λm n N hm hn, le_Sup _,
use (prod.mk m n),
simp only [and_true, eq_self_iff_true, set.mem_set_of_eq],
exact ⟨hm, hn⟩ },
--Prove that it tends to `0`, by using the Cauchy property of `s`
have D : tendsto b at_top (𝓝 0),
{ refine tendsto_order.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩,
rcases exists_between εpos with ⟨δ, δpos, δlt⟩,
rcases hs δ δpos with ⟨N, hN⟩,
refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩,
have : b n ≤ δ := Sup_le begin
simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists],
intros d p q hp hq hd,
rw ← hd,
exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq))
end,
simpa using lt_of_le_of_lt this δlt },
-- Conclude
exact ⟨b, ⟨C, D⟩⟩
end,
begin
rintros ⟨b, ⟨b_bound, b_lim⟩⟩,
/-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
b_lim : tendsto b at_top (𝓝 0)-/
refine emetric.cauchy_seq_iff.2 (λε εpos, _),
have : ∀ᶠ n in at_top, b n < ε := (tendsto_order.1 b_lim ).2 _ εpos,
rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩,
exact ⟨N, λm n hm hn, calc
edist (s m) (s n) ≤ b N : b_bound m n N hm hn
... < ε : (hN _ (le_refl N)) ⟩
end⟩
lemma continuous_of_le_add_edist {f : α → ennreal} (C : ennreal)
(hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f :=
begin
refine continuous_iff_continuous_at.2 (λx, tendsto_order.2 ⟨_, _⟩),
show ∀e, e < f x → ∀ᶠ y in 𝓝 x, e < f y,
{ assume e he,
let ε := min (f x - e) 1,
have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < ε := by simp [ε, hC, he, ennreal.zero_lt_one],
have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]),
have I : C * (C⁻¹ * (ε/2)) < ε,
{ by_cases C_zero : C = 0,
{ simp [C_zero, ‹0 < ε›] },
{ calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc]
... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) }},
have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | e < f y},
{ rintros y hy,
by_cases htop : f y = ⊤,
{ simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] },
{ simp at hy,
have : e + ε < f y + ε := calc
e + ε ≤ e + (f x - e) : add_le_add_left (min_le_left _ _) _
... = f x : by simp [le_of_lt he]
... ≤ f y + C * edist x y : h x y
... = f y + C * edist y x : by simp [edist_comm]
... ≤ f y + C * (C⁻¹ * (ε/2)) :
add_le_add_left (canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)) _
... < f y + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I,
show e < f y, from
(ennreal.add_lt_add_iff_right ‹ε < ⊤›).1 this }},
apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this },
show ∀e, f x < e → ∀ᶠ y in 𝓝 x, f y < e,
{ assume e he,
let ε := min (e - f x) 1,
have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]),
have : 0 < ε := by simp [ε, he, ennreal.zero_lt_one],
have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]),
have I : C * (C⁻¹ * (ε/2)) < ε,
{ by_cases C_zero : C = 0,
simp [C_zero, ‹0 < ε›],
calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc]
... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC]
... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) },
have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | f y < e},
{ rintros y hy,
have htop : f x ≠ ⊤ := ne_top_of_lt he,
show f y < e, from calc
f y ≤ f x + C * edist y x : h y x
... ≤ f x + C * (C⁻¹ * (ε/2)) :
add_le_add_left (canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)) _
... < f x + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I
... ≤ f x + (e - f x) : add_le_add_left (min_le_left _ _) _
... = e : by simp [le_of_lt he] },
apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this },
end
theorem continuous_edist : continuous (λp:α×α, edist p.1 p.2) :=
begin
apply continuous_of_le_add_edist 2 (by norm_num),
rintros ⟨x, y⟩ ⟨x', y'⟩,
calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _
... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc
... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) :
add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _
... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm]
end
theorem continuous.edist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) :=
continuous_edist.comp (hf.prod_mk hg)
theorem filter.tendsto.edist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, edist (f x) (g x)) x (𝓝 (edist a b)) :=
(continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ennreal)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) :
cauchy_seq f :=
begin
lift d to (ℕ → nnreal) using (λ i, ennreal.ne_top_of_tsum_ne_top hd i),
rw ennreal.tsum_coe_ne_top_iff_summable at hd,
exact cauchy_seq_of_edist_le_of_summable d hf hd
end
lemma emetric.is_closed_ball {a : α} {r : ennreal} : is_closed (closed_ball a r) :=
is_closed_le (continuous_id.edist continuous_const) continuous_const
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`,
then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto {f : ℕ → α} (d : ℕ → ennreal)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.edist ha)
(mem_at_top_sets.2 ⟨n, λ m hnm, _⟩),
refine le_trans (edist_le_Ico_sum_of_edist_le hnm (λ k _ _, hf k)) _,
rw [finset.sum_Ico_eq_sum_range],
exact sum_le_tsum _ (λ _ _, zero_le _) ennreal.summable
end
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`,
then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto₀ {f : ℕ → α} (d : ℕ → ennreal)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ ∑' m, d m :=
by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0
end --section
|
48054129d03027045014fa92db010531929e15d8
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/pnat/factors.lean
|
97c1e25bfb319d743162796b803557a78b5b7e21
|
[
"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
| 14,845
|
lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
-/
import data.pnat.prime
import data.multiset.sort
import data.int.gcd
import algebra.group
/-!
# Prime factors of nonzero naturals
This file defines the factorization of a nonzero natural number `n` as a multiset of primes,
the multiplicity of `p` in this factors multiset being the p-adic valuation of `n`.
## Main declarations
* `prime_multiset`: Type of multisets of prime numbers.
* `factor_multiset n`: Multiset of prime factors of `n`.
-/
/-- The type of multisets of prime numbers. Unique factorization
gives an equivalence between this set and ℕ+, as we will formalize
below. -/
def prime_multiset := multiset nat.primes
namespace prime_multiset
instance : inhabited prime_multiset :=
by unfold prime_multiset; apply_instance
instance : has_repr prime_multiset :=
by { dsimp [prime_multiset], apply_instance }
instance : canonically_ordered_add_monoid prime_multiset :=
by { dsimp [prime_multiset], apply_instance }
instance : distrib_lattice prime_multiset :=
by { dsimp [prime_multiset], apply_instance }
instance : semilattice_sup_bot prime_multiset :=
by { dsimp [prime_multiset], apply_instance }
instance : has_sub prime_multiset :=
by { dsimp [prime_multiset], apply_instance }
theorem add_sub_of_le {u v : prime_multiset} : u ≤ v → u + (v - u) = v :=
multiset.add_sub_of_le
/-- The multiset consisting of a single prime -/
def of_prime (p : nat.primes) : prime_multiset := (p ::ₘ 0)
theorem card_of_prime (p : nat.primes) : multiset.card (of_prime p) = 1 := rfl
/-- We can forget the primality property and regard a multiset
of primes as just a multiset of positive integers, or a multiset
of natural numbers. In the opposite direction, if we have a
multiset of positive integers or natural numbers, together with
a proof that all the elements are prime, then we can regard it
as a multiset of primes. The next block of results records
obvious properties of these coercions.
-/
def to_nat_multiset : prime_multiset → multiset ℕ :=
λ v, v.map (λ p, (p : ℕ))
instance coe_nat : has_coe prime_multiset (multiset ℕ) := ⟨to_nat_multiset⟩
instance coe_nat_hom : is_add_monoid_hom (coe : prime_multiset → multiset ℕ) :=
by { unfold_coes, dsimp [to_nat_multiset], apply_instance }
theorem coe_nat_injective : function.injective (coe : prime_multiset → multiset ℕ) :=
multiset.map_injective nat.primes.coe_nat_inj
theorem coe_nat_of_prime (p : nat.primes) :
((of_prime p) : multiset ℕ) = (p : ℕ) ::ₘ 0 := rfl
theorem coe_nat_prime (v : prime_multiset)
(p : ℕ) (h : p ∈ (v : multiset ℕ)) : p.prime :=
by { rcases multiset.mem_map.mp h with ⟨⟨p', hp'⟩, ⟨h_mem, h_eq⟩⟩,
exact h_eq ▸ hp' }
/-- Converts a `prime_multiset` to a `multiset ℕ+`. -/
def to_pnat_multiset : prime_multiset → multiset ℕ+ :=
λ v, v.map (λ p, (p : ℕ+))
instance coe_pnat : has_coe prime_multiset (multiset ℕ+) := ⟨to_pnat_multiset⟩
instance coe_pnat_hom : is_add_monoid_hom (coe : prime_multiset → multiset ℕ+) :=
by { unfold_coes, dsimp [to_pnat_multiset], apply_instance }
theorem coe_pnat_injective : function.injective (coe : prime_multiset → multiset ℕ+) :=
multiset.map_injective nat.primes.coe_pnat_inj
theorem coe_pnat_of_prime (p : nat.primes) :
((of_prime p) : multiset ℕ+) = (p : ℕ+) ::ₘ 0 := rfl
theorem coe_pnat_prime (v : prime_multiset)
(p : ℕ+) (h : p ∈ (v : multiset ℕ+)) : p.prime :=
by { rcases multiset.mem_map.mp h with ⟨⟨p', hp'⟩, ⟨h_mem, h_eq⟩⟩,
exact h_eq ▸ hp' }
instance coe_multiset_pnat_nat : has_coe (multiset ℕ+) (multiset ℕ) :=
⟨λ v, v.map (λ n, (n : ℕ))⟩
theorem coe_pnat_nat (v : prime_multiset) :
((v : (multiset ℕ+)) : (multiset ℕ)) = (v : multiset ℕ) :=
by { change (v.map (coe : nat.primes → ℕ+)).map subtype.val = v.map subtype.val,
rw [multiset.map_map], congr }
/-- The product of a `prime_multiset`, as a `ℕ+`. -/
def prod (v : prime_multiset) : ℕ+ := (v : multiset pnat).prod
theorem coe_prod (v : prime_multiset) : (v.prod : ℕ) = (v : multiset ℕ).prod :=
begin
let h : (v.prod : ℕ) = ((v.map coe).map coe).prod :=
((monoid_hom.of coe).map_multiset_prod v.to_pnat_multiset),
rw [multiset.map_map] at h,
have : (coe : ℕ+ → ℕ) ∘ (coe : nat.primes → ℕ+) = coe := funext (λ p, rfl),
rw[this] at h, exact h,
end
theorem prod_of_prime (p : nat.primes) : (of_prime p).prod = (p : ℕ+) :=
by { change multiset.prod ((p : ℕ+) ::ₘ 0) = (p : ℕ+),
rw [multiset.prod_cons, multiset.prod_zero, mul_one] }
/-- If a `multiset ℕ` consists only of primes, it can be recast as a `prime_multiset`. -/
def of_nat_multiset
(v : multiset ℕ) (h : ∀ (p : ℕ), p ∈ v → p.prime) : prime_multiset :=
@multiset.pmap ℕ nat.primes nat.prime (λ p hp, ⟨p, hp⟩) v h
theorem to_of_nat_multiset (v : multiset ℕ) (h) :
((of_nat_multiset v h) : multiset ℕ) = v :=
begin
unfold_coes,
dsimp [of_nat_multiset, to_nat_multiset],
have : (λ (p : ℕ) (h : p.prime), ((⟨p, h⟩ : nat.primes) : ℕ)) = (λ p h, id p) :=
by {funext p h, refl},
rw [multiset.map_pmap, this, multiset.pmap_eq_map, multiset.map_id]
end
theorem prod_of_nat_multiset (v : multiset ℕ) (h) :
((of_nat_multiset v h).prod : ℕ) = (v.prod : ℕ) :=
by rw[coe_prod, to_of_nat_multiset]
/-- If a `multiset ℕ+` consists only of primes, it can be recast as a `prime_multiset`. -/
def of_pnat_multiset
(v : multiset ℕ+) (h : ∀ (p : ℕ+), p ∈ v → p.prime) : prime_multiset :=
@multiset.pmap ℕ+ nat.primes pnat.prime (λ p hp, ⟨(p : ℕ), hp⟩) v h
theorem to_of_pnat_multiset (v : multiset ℕ+) (h) :
((of_pnat_multiset v h) : multiset ℕ+) = v :=
begin
unfold_coes, dsimp[of_pnat_multiset, to_pnat_multiset],
have : (λ (p : ℕ+) (h : p.prime), ((coe : nat.primes → ℕ+) ⟨p, h⟩)) = (λ p h, id p) :=
by {funext p h, apply subtype.eq, refl},
rw[multiset.map_pmap, this, multiset.pmap_eq_map, multiset.map_id]
end
theorem prod_of_pnat_multiset (v : multiset ℕ+) (h) :
((of_pnat_multiset v h).prod : ℕ+) = v.prod :=
by { dsimp [prod], rw [to_of_pnat_multiset] }
/-- Lists can be coerced to multisets; here we have some results
about how this interacts with our constructions on multisets. -/
def of_nat_list (l : list ℕ) (h : ∀ (p : ℕ), p ∈ l → p.prime) : prime_multiset :=
of_nat_multiset (l : multiset ℕ) h
theorem prod_of_nat_list (l : list ℕ) (h) : ((of_nat_list l h).prod : ℕ) = l.prod :=
by { have := prod_of_nat_multiset (l : multiset ℕ) h,
rw [multiset.coe_prod] at this, exact this }
/-- If a `list ℕ+` consists only of primes, it can be recast as a `prime_multiset` with
the coercion from lists to multisets. -/
def of_pnat_list (l : list ℕ+) (h : ∀ (p : ℕ+), p ∈ l → p.prime) : prime_multiset :=
of_pnat_multiset (l : multiset ℕ+) h
theorem prod_of_pnat_list (l : list ℕ+) (h) : (of_pnat_list l h).prod = l.prod :=
by { have := prod_of_pnat_multiset (l : multiset ℕ+) h,
rw [multiset.coe_prod] at this, exact this }
/-- The product map gives a homomorphism from the additive monoid
of multisets to the multiplicative monoid ℕ+. -/
theorem prod_zero : (0 : prime_multiset).prod = 1 :=
by { dsimp [prod], exact multiset.prod_zero }
theorem prod_add (u v : prime_multiset) : (u + v).prod = u.prod * v.prod :=
by { dsimp [prod],
rw [is_add_monoid_hom.map_add (coe : prime_multiset → multiset ℕ+)],
rw [multiset.prod_add] }
theorem prod_smul (d : ℕ) (u : prime_multiset) :
(d • u).prod = u.prod ^ d :=
by { induction d with d ih, refl,
rw [succ_nsmul, prod_add, ih, nat.succ_eq_add_one, pow_succ, mul_comm] }
end prime_multiset
namespace pnat
/-- The prime factors of n, regarded as a multiset -/
def factor_multiset (n : ℕ+) : prime_multiset :=
prime_multiset.of_nat_list (nat.factors n) (@nat.prime_of_mem_factors n)
/-- The product of the factors is the original number -/
theorem prod_factor_multiset (n : ℕ+) : (factor_multiset n).prod = n :=
eq $ by { dsimp [factor_multiset],
rw [prime_multiset.prod_of_nat_list],
exact nat.prod_factors n.pos }
theorem coe_nat_factor_multiset (n : ℕ+) :
((factor_multiset n) : (multiset ℕ)) = ((nat.factors n) : multiset ℕ) :=
prime_multiset.to_of_nat_multiset (nat.factors n) (@nat.prime_of_mem_factors n)
end pnat
namespace prime_multiset
/-- If we start with a multiset of primes, take the product and
then factor it, we get back the original multiset. -/
theorem factor_multiset_prod (v : prime_multiset) :
v.prod.factor_multiset = v :=
begin
apply prime_multiset.coe_nat_injective,
rw [v.prod.coe_nat_factor_multiset, prime_multiset.coe_prod],
rcases v with ⟨l⟩,
unfold_coes,
dsimp [prime_multiset.to_nat_multiset],
rw [multiset.coe_prod],
let l' := l.map (coe : nat.primes → ℕ),
have : ∀ (p : ℕ), p ∈ l' → p.prime :=
λ p hp, by {rcases list.mem_map.mp hp with ⟨⟨p', hp'⟩, ⟨h_mem, h_eq⟩⟩,
exact h_eq ▸ hp'},
exact multiset.coe_eq_coe.mpr (@nat.factors_unique _ l' rfl this).symm,
end
end prime_multiset
namespace pnat
/-- Positive integers biject with multisets of primes. -/
def factor_multiset_equiv : ℕ+ ≃ prime_multiset :=
{ to_fun := factor_multiset,
inv_fun := prime_multiset.prod,
left_inv := prod_factor_multiset,
right_inv := prime_multiset.factor_multiset_prod }
/-- Factoring gives a homomorphism from the multiplicative
monoid ℕ+ to the additive monoid of multisets. -/
theorem factor_multiset_one : factor_multiset 1 = 0 :=
by simp [factor_multiset, prime_multiset.of_nat_list, prime_multiset.of_nat_multiset]
theorem factor_multiset_mul (n m : ℕ+) :
factor_multiset (n * m) = (factor_multiset n) + (factor_multiset m) :=
begin
let u := factor_multiset n,
let v := factor_multiset m,
have : n = u.prod := (prod_factor_multiset n).symm, rw[this],
have : m = v.prod := (prod_factor_multiset m).symm, rw[this],
rw[← prime_multiset.prod_add],
repeat {rw[prime_multiset.factor_multiset_prod]},
end
theorem factor_multiset_pow (n : ℕ+) (m : ℕ) :
factor_multiset (n ^ m) = m • (factor_multiset n) :=
begin
let u := factor_multiset n,
have : n = u.prod := (prod_factor_multiset n).symm,
rw[this, ← prime_multiset.prod_smul],
repeat {rw[prime_multiset.factor_multiset_prod]},
end
/-- Factoring a prime gives the corresponding one-element multiset. -/
theorem factor_multiset_of_prime (p : nat.primes) :
(p : ℕ+).factor_multiset = prime_multiset.of_prime p :=
begin
apply factor_multiset_equiv.symm.injective,
change (p : ℕ+).factor_multiset.prod = (prime_multiset.of_prime p).prod,
rw[(p : ℕ+).prod_factor_multiset, prime_multiset.prod_of_prime],
end
/-- We now have four different results that all encode the
idea that inequality of multisets corresponds to divisibility
of positive integers. -/
theorem factor_multiset_le_iff {m n : ℕ+} :
factor_multiset m ≤ factor_multiset n ↔ m ∣ n :=
begin
split,
{ intro h,
rw [← prod_factor_multiset m, ← prod_factor_multiset m],
apply dvd.intro (n.factor_multiset - m.factor_multiset).prod,
rw [← prime_multiset.prod_add, prime_multiset.factor_multiset_prod,
prime_multiset.add_sub_of_le h, prod_factor_multiset] },
{ intro h,
rw [← mul_div_exact h, factor_multiset_mul],
exact le_self_add }
end
theorem factor_multiset_le_iff' {m : ℕ+} {v : prime_multiset}:
factor_multiset m ≤ v ↔ m ∣ v.prod :=
by { let h := @factor_multiset_le_iff m v.prod,
rw [v.factor_multiset_prod] at h, exact h }
end pnat
namespace prime_multiset
theorem prod_dvd_iff {u v : prime_multiset} : u.prod ∣ v.prod ↔ u ≤ v :=
by { let h := @pnat.factor_multiset_le_iff' u.prod v,
rw [u.factor_multiset_prod] at h, exact h.symm }
theorem prod_dvd_iff' {u : prime_multiset} {n : ℕ+} : u.prod ∣ n ↔ u ≤ n.factor_multiset :=
by { let h := @prod_dvd_iff u n.factor_multiset,
rw [n.prod_factor_multiset] at h, exact h }
end prime_multiset
namespace pnat
/-- The gcd and lcm operations on positive integers correspond
to the inf and sup operations on multisets. -/
theorem factor_multiset_gcd (m n : ℕ+) :
factor_multiset (gcd m n) = (factor_multiset m) ⊓ (factor_multiset n) :=
begin
apply le_antisymm,
{ apply le_inf_iff.mpr; split; apply factor_multiset_le_iff.mpr,
exact gcd_dvd_left m n, exact gcd_dvd_right m n},
{ rw[← prime_multiset.prod_dvd_iff, prod_factor_multiset],
apply dvd_gcd; rw[prime_multiset.prod_dvd_iff'],
exact inf_le_left, exact inf_le_right}
end
theorem factor_multiset_lcm (m n : ℕ+) :
factor_multiset (lcm m n) = (factor_multiset m) ⊔ (factor_multiset n) :=
begin
apply le_antisymm,
{ rw[← prime_multiset.prod_dvd_iff, prod_factor_multiset],
apply lcm_dvd; rw[← factor_multiset_le_iff'],
exact le_sup_left, exact le_sup_right},
{ apply sup_le_iff.mpr; split; apply factor_multiset_le_iff.mpr,
exact dvd_lcm_left m n, exact dvd_lcm_right m n },
end
/-- The number of occurrences of p in the factor multiset of m
is the same as the p-adic valuation of m. -/
theorem count_factor_multiset (m : ℕ+) (p : nat.primes) (k : ℕ) :
(p : ℕ+) ^ k ∣ m ↔ k ≤ m.factor_multiset.count p :=
begin
intros,
rw [multiset.le_count_iff_repeat_le],
rw [← factor_multiset_le_iff, factor_multiset_pow, factor_multiset_of_prime],
congr' 2,
apply multiset.eq_repeat.mpr,
split,
{ rw [multiset.card_nsmul, prime_multiset.card_of_prime, mul_one] },
{ have : ∀ (m : ℕ), m • (p ::ₘ 0) = multiset.repeat p m :=
λ m, by {induction m with m ih, { refl },
rw [succ_nsmul, multiset.repeat_succ, ih],
rw[multiset.cons_add, zero_add] },
intros q h, rw [prime_multiset.of_prime, this k] at h,
exact multiset.eq_of_mem_repeat h }
end
end pnat
namespace prime_multiset
theorem prod_inf (u v : prime_multiset) :
(u ⊓ v).prod = pnat.gcd u.prod v.prod :=
begin
let n := u.prod,
let m := v.prod,
change (u ⊓ v).prod = pnat.gcd n m,
have : u = n.factor_multiset := u.factor_multiset_prod.symm, rw [this],
have : v = m.factor_multiset := v.factor_multiset_prod.symm, rw [this],
rw [← pnat.factor_multiset_gcd n m, pnat.prod_factor_multiset]
end
theorem prod_sup (u v : prime_multiset) :
(u ⊔ v).prod = pnat.lcm u.prod v.prod :=
begin
let n := u.prod,
let m := v.prod,
change (u ⊔ v).prod = pnat.lcm n m,
have : u = n.factor_multiset := u.factor_multiset_prod.symm, rw [this],
have : v = m.factor_multiset := v.factor_multiset_prod.symm, rw [this],
rw[← pnat.factor_multiset_lcm n m, pnat.prod_factor_multiset]
end
end prime_multiset
|
a810f443df0cea9cdbdddfe4fe513d6bd6e3afdf
|
c7114155c06e8d4370c3ac2c1919ac456fdbf3e7
|
/src/solutions/01_equality_rewriting.lean
|
4f975859f123f5ea71fcc1ece6a4eee9c8d8c09c
|
[
"Apache-2.0"
] |
permissive
|
fcasal/tutorials
|
c2c04a30f756964b7db31159be216ba7a2779272
|
0644a78265959f576888824e11e78f89d210eaf7
|
refs/heads/master
| 1,658,194,417,828
| 1,590,057,408,000
| 1,590,057,408,000
| 265,922,436
| 0
| 0
|
Apache-2.0
| 1,590,085,590,000
| 1,590,085,589,000
| null |
UTF-8
|
Lean
| false
| false
| 5,601
|
lean
|
import data.real.basic
/-
One of the earliest kind of proofs one encounters while learning mathematics is proving by
a calculation. It may not sound like a proof, but this is actually using lemmas expressing
properties of operations on numbers. It also uses the fundamental property of equality: if two
mathematical objects A and B are equal then, in any statement involving A, one can replace A
by B. This operation is called rewriting, and the Lean "tactic" for this is `rw`.
In the following exercises, we will use the following two lemmas:
mul_assoc a b c : a * b * c = a * (b * c)
mul_comm a b : a*b = b*a
Hence the command
rw mul_assoc a b c,
will replace a*b*c by a*(b*c) in the current goal.
In order to replace backward, we use
rw ← mul_assoc a b c,
replacing a*(b*c) by a*b*c in the current goal.
Of course we don't want to constantly invoke those lemmas, and we will eventually introduce
more powerful solutions.
-/
example (a b c : ℝ) : (a * b) * c = b * (a * c) :=
begin
rw mul_comm a b,
rw mul_assoc b a c,
end
-- 0001
example (a b c : ℝ) : (c * b) * a = b * (a * c) :=
begin
-- sorry
rw mul_comm c b,
rw mul_assoc b c a,
rw mul_comm c a,
-- sorry
end
-- 0002
example (a b c : ℝ) : a * (b * c) = b * (a * c) :=
begin
-- sorry
rw ← mul_assoc a b c,
rw mul_comm a b,
rw mul_assoc b a c,
-- sorry
end
/-
Now let's return to the preceding example to experiment with what happens
if we don't give arguments to mul_assoc or mul_comm.
For instance, you can start the next proof with
rw ← mul_assoc,
Try to figure out what happens.
-/
-- 0003
example (a b c : ℝ) : a * (b * c) = b * (a * c) :=
begin
-- sorry
rw ← mul_assoc,
-- "rw mul_comm," doesn't do what we want.
rw mul_comm a b,
rw mul_assoc,
-- sorry
end
/-
We can also perform rewriting in an assumption of the local context, using for instance
rw mul_comm a b at hyp,
in order to replace a*b by b*a in assumption hyp.
The next example will use a third lemma:
two_mul a : 2*a = a + a
Also we use the `exact` tactic, which allows to provide a direct proof term.
-/
example (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=
begin
rw hyp' at hyp,
rw mul_comm d a at hyp,
rw ← two_mul (a*d) at hyp,
rw ← mul_assoc 2 a d at hyp,
exact hyp, -- Our assumption hyp is now exactly what we have to prove
end
/-
And the next one can use:
sub_self x : x - x = 0
-/
-- 0004
example (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=
begin
-- sorry
rw hyp' at hyp,
rw mul_comm b a at hyp,
rw sub_self (a*b) at hyp,
exact hyp,
-- sorry
end
/-
What is written in the two preceding example is very far away from what we would write on
paper. Let's now see how to get a more natural layout.
Inside each pair of curly braces below, the goal is to prove equality with the preceding line.
-/
example (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=
begin
calc c = d*a + b : by { rw hyp }
... = d*a + a*d : by { rw hyp' }
... = a*d + a*d : by { rw mul_comm d a }
... = 2*(a*d) : by { rw two_mul }
... = 2*a*d : by { rw mul_assoc },
end
/-
Let's note there is no comma at the end of each line of calculation. `calc` is really one
command, and the comma comes only after it's fully done.
From a practical point of view, when writing such a proof, it is convenient to:
* pause the tactic state view update in VScode by clicking the Pause icon button
in the top right corner of the Lean Goal buffer
* write the full calculation, ending each line with ": by {}"
* resume tactic state update by clicking the Play icon button and fill in proofs between
curly braces.
Let's return to the other example using this method.
-/
-- 0005
example (a b c d : ℝ) (hyp : c = b*a - d) (hyp' : d = a*b) : c = 0 :=
begin
-- sorry
calc c = b*a - d : by { rw hyp }
... = b*a - a*b : by { rw hyp' }
... = a*b - a*b : by { rw mul_comm a b }
... = 0 : by { rw sub_self (a*b) },
-- sorry
end
/-
The preceding proofs have exhauted our supply of "mul_comm" patience. Now it's time
to get the computer to work harder. The `ring` tactic will prove any goal that follows by
applying only the axioms of commutative (semi-)rings, in particuler commutativity and
associativity of addition and multiplication, as well as distributivity.
We also note that curly braces are not necessary when we write a single tactic proof, so
let's get rid of them.
-/
example (a b c d : ℝ) (hyp : c = d*a + b) (hyp' : b = a*d) : c = 2*a*d :=
begin
calc c = d*a + b : by rw hyp
... = d*a + a*d : by rw hyp'
... = 2*a*d : by ring,
end
/-
Of course we can use `ring` outside of `calc`. Let's do the next one in one line.
-/
-- 0006
example (a b c : ℝ) : a * (b * c) = b * (a * c) :=
begin
-- sorry
ring,
-- sorry
end
/-
This is too much fun. Let's do it again.
-/
-- 0007
example (a b : ℝ) : (a + b) + a = 2*a + b :=
begin
-- sorry
ring,
-- sorry
end
/-
Maybe this is cheating. Let's try to do the next computation without ring.
We could use:
pow_two x : x^2 = x*x
mul_sub a b c : a*(b-c) = a*b - a*c
add_mul a b c : (a+b)*c = a*c + b*c
add_sub a b c : a + (b - c) = (a + b) - c
sub_sub a b c : a - b - c = a - (b + c)
add_zero a : a + 0 = a
-/
-- 0008
example (a b : ℝ) : (a + b)*(a - b) = a^2 - b^2 :=
begin
-- sorry
rw pow_two a,
rw pow_two b,
rw mul_sub (a+b) a b,
rw add_mul a b a,
rw add_mul a b b,
rw mul_comm b a,
rw ← sub_sub,
rw ← add_sub,
rw sub_self,
rw add_zero,
-- sorry
end
/- Let's stick to ring in the end. -/
|
303843c8abf44ac6f6c8c131f92f98e5ffda2cf2
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/ring_theory/ring_hom/surjective.lean
|
b5d723521a0904f39a877bf43265e7445e0c0e9c
|
[
"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,421
|
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 ring_theory.local_properties
/-!
# The meta properties of surjective ring homomorphisms.
-/
namespace ring_hom
open_locale tensor_product
open tensor_product algebra.tensor_product
local notation `surjective` := λ {X Y : Type*} [comm_ring X] [comm_ring Y] ,
by exactI λ (f : X →+* Y), function.surjective f
lemma surjective_stable_under_composition :
stable_under_composition surjective :=
by { introv R hf hg, exactI hg.comp hf }
lemma surjective_respects_iso :
respects_iso surjective :=
begin
apply surjective_stable_under_composition.respects_iso,
introsI,
exact e.surjective
end
lemma surjective_stable_under_base_change :
stable_under_base_change surjective :=
begin
classical,
introv R h,
resetI,
intro x,
induction x using tensor_product.induction_on with x y x y ex ey,
{ exact ⟨0, map_zero _⟩ },
{ obtain ⟨y, rfl⟩ := h y, use y • x, dsimp,
rw [tensor_product.smul_tmul, algebra.algebra_map_eq_smul_one] },
{ obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ⟨ex, ey⟩, exact ⟨x + y, map_add _ x y⟩ }
end
open_locale big_operators
lemma surjective_of_localization_span :
of_localization_span surjective :=
begin
introv R hs H,
resetI,
letI := f.to_algebra,
show function.surjective (algebra.of_id R S),
rw [← algebra.range_top_iff_surjective, eq_top_iff],
rintro x -,
obtain ⟨l, hl⟩ :=
(finsupp.mem_span_iff_total R s 1).mp (show _ ∈ ideal.span s, by { rw hs, trivial }),
fapply subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _
l.support (λ x : s, f x) (λ x : s, f (l x)),
{ dsimp only, simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one], exact f.congr_arg hl },
{ exact λ _, set.mem_range_self _ },
{ exact λ _, set.mem_range_self _ },
{ intro r,
obtain ⟨y, hy⟩ := H r (is_localization.mk' _ x (1 : submonoid.powers (f r))),
obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := is_localization.mk'_surjective (submonoid.powers (r : R)) y,
erw [is_localization.map_mk', is_localization.eq] at hy,
obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy,
dsimp at hm,
simp_rw [_root_.mul_assoc, _root_.one_mul, ← map_pow, ← f.map_mul, ← pow_add, mul_comm x] at hm,
rw map_pow at hm,
refine ⟨n + m, _, hm⟩ }
end
end ring_hom
|
eb5b28bdd7ba6984fdac814113d42d153772f0ca
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/io_unsafe_perform_io.lean
|
39f78b3f4c7c7998bbd8eed01834cae104e9e660
|
[
"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
| 285
|
lean
|
import system.io
open list io
def getD {ε α : Type} (d : α): except ε α → α
| (except.ok a) := a
| (except.error e) := d
meta def f (i : nat) : nat :=
getD 100 $ io.unsafe_perform_io (do put_str "value: ", print i, put_str "\n", pure i)
#eval list.map f [0,1,2,3,4]
|
5a69239a98a832232693a0d4f7c01a80755a4042
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/opposite.lean
|
356e4876a73d8a9352e1570c1c9f01f94d5cdf0f
|
[
"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
| 4,444
|
lean
|
/-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton, Simon Hudon, Kenny Lau
-/
import logic.equiv.basic
/-!
# Opposites
In this file we define a type synonym `opposite α := α`, denoted by `αᵒᵖ` and two synonyms for the
identity map, `op : α → αᵒᵖ` and `unop : αᵒᵖ → α`. If `α` is a category, then `αᵒᵖ` is the opposite
category, with all arrows reversed.
-/
universes v u -- morphism levels before object levels. See note [category_theory universes].
variable (α : Sort u)
/-- The type of objects of the opposite of `α`; used to define the opposite category.
In order to avoid confusion between `α` and its opposite type, we
set up the type of objects `opposite α` using the following pattern,
which will be repeated later for the morphisms.
1. Define `opposite α := α`.
2. Define the isomorphisms `op : α → opposite α`, `unop : opposite α → α`.
3. Make the definition `opposite` irreducible.
This has the following consequences.
* `opposite α` and `α` are distinct types in the elaborator, so you
must use `op` and `unop` explicitly to convert between them.
* Both `unop (op X) = X` and `op (unop X) = X` are definitional
equalities. Notably, every object of the opposite category is
definitionally of the form `op X`, which greatly simplifies the
definition of the structure of the opposite category, for example.
(If Lean supported definitional eta equality for records, we could
achieve the same goals using a structure with one field.)
-/
def opposite : Sort u := α
-- Use a high right binding power (like that of postfix ⁻¹) so that, for example,
-- `presheaf Cᵒᵖ` parses as `presheaf (Cᵒᵖ)` and not `(presheaf C)ᵒᵖ`.
notation α `ᵒᵖ`:std.prec.max_plus := opposite α
namespace opposite
variables {α}
/-- The canonical map `α → αᵒᵖ`. -/
@[pp_nodot]
def op : α → αᵒᵖ := id
/-- The canonical map `αᵒᵖ → α`. -/
@[pp_nodot]
def unop : αᵒᵖ → α := id
lemma op_injective : function.injective (op : α → αᵒᵖ) := λ _ _, id
lemma unop_injective : function.injective (unop : αᵒᵖ → α) := λ _ _, id
@[simp] lemma op_inj_iff (x y : α) : op x = op y ↔ x = y := iff.rfl
@[simp] lemma unop_inj_iff (x y : αᵒᵖ) : unop x = unop y ↔ x = y := iff.rfl
@[simp] lemma op_unop (x : αᵒᵖ) : op (unop x) = x := rfl
@[simp] lemma unop_op (x : α) : unop (op x) = x := rfl
attribute [irreducible] opposite
/-- The type-level equivalence between a type and its opposite. -/
def equiv_to_opposite : α ≃ αᵒᵖ :=
{ to_fun := op,
inv_fun := unop,
left_inv := unop_op,
right_inv := op_unop }
@[simp]
lemma equiv_to_opposite_coe : (equiv_to_opposite : α → αᵒᵖ) = op := rfl
@[simp]
lemma equiv_to_opposite_symm_coe : (equiv_to_opposite.symm : αᵒᵖ → α) = unop := rfl
lemma op_eq_iff_eq_unop {x : α} {y} : op x = y ↔ x = unop y :=
equiv_to_opposite.apply_eq_iff_eq_symm_apply
lemma unop_eq_iff_eq_op {x} {y : α} : unop x = y ↔ x = op y :=
equiv_to_opposite.symm.apply_eq_iff_eq_symm_apply
instance [inhabited α] : inhabited αᵒᵖ := ⟨op default⟩
/-- A recursor for `opposite`. Use as `induction x using opposite.rec`. -/
@[simp]
protected def rec {F : Π (X : αᵒᵖ), Sort v} (h : Π X, F (op X)) : Π X, F X :=
λ X, h (unop X)
end opposite
namespace tactic
open opposite
namespace op_induction
/-- Test if `e : expr` is of type `opposite α` for some `α`. -/
meta def is_opposite (e : expr) : tactic bool :=
do t ← infer_type e,
`(opposite _) ← whnf t | return ff,
return tt
/-- Find the first hypothesis of type `opposite _`. Fail if no such hypothesis exist in the local
context. -/
meta def find_opposite_hyp : tactic name :=
do lc ← local_context,
h :: _ ← lc.mfilter $ is_opposite | fail "No hypotheses of the form Xᵒᵖ",
return h.local_pp_name
end op_induction
open op_induction
/-- A version of `induction x using opposite.rec` which finds the appropriate hypothesis
automatically, for use with `local attribute [tidy] op_induction'`. This is necessary because
`induction x` is not able to deduce that `opposite.rec` should be used. -/
meta def op_induction' : tactic unit :=
do h ← find_opposite_hyp,
h' ← tactic.get_local h,
tactic.induction' h' [] `opposite.rec
end tactic
|
b3c38226d1bb7cdfea8a19a2c43e188811099ba3
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/ring_theory/witt_vector/truncated.lean
|
763f6b736c84167165dd2f217aa568266fc18d0f
|
[
"Apache-2.0"
] |
permissive
|
kodyvajjha/mathlib
|
9bead00e90f68269a313f45f5561766cfd8d5cad
|
b98af5dd79e13a38d84438b850a2e8858ec21284
|
refs/heads/master
| 1,624,350,366,310
| 1,615,563,062,000
| 1,615,563,062,000
| 162,666,963
| 0
| 0
|
Apache-2.0
| 1,545,367,651,000
| 1,545,367,651,000
| null |
UTF-8
|
Lean
| false
| false
| 14,177
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import ring_theory.witt_vector.init_tail
import tactic.equiv_rw
/-!
# Truncated Witt vectors
The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors.
It retains the first `n` coefficients of each Witt vector.
In this file, we set up the basic quotient API for this ring.
The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors.
## Main declarations
- `truncated_witt_vector`: the underlying type of the ring of truncated Witt vectors
- `truncated_witt_vector.comm_ring`: the ring structure on truncated Witt vectors
- `witt_vector.truncate`: the quotient homomorphism that truncates a Witt vector,
to obtain a truncated Witt vector
- `truncated_witt_vector.truncate`: the homomorphism that truncates
a truncated Witt vector of length `n` to one of length `m` (for some `m ≤ n`)
- `witt_vector.lift`: the unique ring homomorphism into the ring of Witt vectors
that is compatible with a family of ring homomorphisms to the truncated Witt vectors:
this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open function (injective surjective)
noncomputable theory
variables {p : ℕ} [hp : fact p.prime] (n : ℕ) (R : Type*)
local notation `𝕎` := witt_vector p -- type as `\bbW`
/--
A truncated Witt vector over `R` is a vector of elements of `R`,
i.e., the first `n` coefficients of a Witt vector.
We will define operations on this type that are compatible with the (untruncated) Witt
vector operations.
`truncated_witt_vector p n R` takes a parameter `p : ℕ` that is not used in the definition.
In practice, this number `p` is assumed to be a prime number,
and under this assumption we construct a ring structure on `truncated_witt_vector p n R`.
(`truncated_witt_vector p₁ n R` and `truncated_witt_vector p₂ n R` are definitionally
equal as types but will have different ring operations.)
-/
@[nolint unused_arguments]
def truncated_witt_vector (p : ℕ) (n : ℕ) (R : Type*) := fin n → R
instance (p n : ℕ) (R : Type*) [inhabited R] : inhabited (truncated_witt_vector p n R) :=
⟨λ _, default R⟩
variables {n R}
namespace truncated_witt_vector
variables (p)
/-- Create a `truncated_witt_vector` from a vector `x`. -/
def mk (x : fin n → R) : truncated_witt_vector p n R := x
variables {p}
/-- `x.coeff i` is the `i`th entry of `x`. -/
def coeff (i : fin n) (x : truncated_witt_vector p n R) : R := x i
@[ext]
lemma ext {x y : truncated_witt_vector p n R} (h : ∀ i, x.coeff i = y.coeff i) : x = y :=
funext h
lemma ext_iff {x y : truncated_witt_vector p n R} : x = y ↔ ∀ i, x.coeff i = y.coeff i :=
⟨λ h i, by rw h, ext⟩
@[simp] lemma coeff_mk (x : fin n → R) (i : fin n) :
(mk p x).coeff i = x i := rfl
@[simp] lemma mk_coeff (x : truncated_witt_vector p n R) :
mk p (λ i, x.coeff i) = x :=
by { ext i, rw [coeff_mk] }
variable [comm_ring R]
/--
We can turn a truncated Witt vector `x` into a Witt vector
by setting all coefficients after `x` to be 0.
-/
def out (x : truncated_witt_vector p n R) : 𝕎 R :=
witt_vector.mk p $ λ i, if h : i < n then x.coeff ⟨i, h⟩ else 0
@[simp]
lemma coeff_out (x : truncated_witt_vector p n R) (i : fin n) :
x.out.coeff i = x.coeff i :=
by rw [out, witt_vector.coeff_mk, dif_pos i.is_lt, fin.eta]
lemma out_injective : injective (@out p n R _) :=
begin
intros x y h,
ext i,
rw [witt_vector.ext_iff] at h,
simpa only [coeff_out] using h ↑i
end
end truncated_witt_vector
namespace witt_vector
variables {p} (n)
section
/-- `truncate_fun n x` uses the first `n` entries of `x` to construct a `truncated_witt_vector`,
which has the same base `p` as `x`.
This function is bundled into a ring homomorphism in `witt_vector.truncate` -/
def truncate_fun (x : 𝕎 R) : truncated_witt_vector p n R :=
truncated_witt_vector.mk p $ λ i, x.coeff i
end
variables {n}
@[simp] lemma coeff_truncate_fun (x : 𝕎 R) (i : fin n) :
(truncate_fun n x).coeff i = x.coeff i :=
by rw [truncate_fun, truncated_witt_vector.coeff_mk]
variable [comm_ring R]
@[simp] lemma out_truncate_fun (x : 𝕎 R) :
(truncate_fun n x).out = init n x :=
begin
ext i,
dsimp [truncated_witt_vector.out, init, select],
split_ifs with hi, swap, { refl },
rw [coeff_truncate_fun, fin.coe_mk],
end
end witt_vector
namespace truncated_witt_vector
variable [comm_ring R]
@[simp] lemma truncate_fun_out (x : truncated_witt_vector p n R) :
x.out.truncate_fun n = x :=
by simp only [witt_vector.truncate_fun, coeff_out, mk_coeff]
open witt_vector
variables (p n R)
include hp
instance : has_zero (truncated_witt_vector p n R) :=
⟨truncate_fun n 0⟩
instance : has_one (truncated_witt_vector p n R) :=
⟨truncate_fun n 1⟩
instance : has_add (truncated_witt_vector p n R) :=
⟨λ x y, truncate_fun n (x.out + y.out)⟩
instance : has_mul (truncated_witt_vector p n R) :=
⟨λ x y, truncate_fun n (x.out * y.out)⟩
instance : has_neg (truncated_witt_vector p n R) :=
⟨λ x, truncate_fun n (- x.out)⟩
@[simp] lemma coeff_zero (i : fin n) :
(0 : truncated_witt_vector p n R).coeff i = 0 :=
begin
show coeff i (truncate_fun _ 0 : truncated_witt_vector p n R) = 0,
rw [coeff_truncate_fun, witt_vector.zero_coeff],
end
end truncated_witt_vector
/-- A macro tactic used to prove that `truncate_fun` respects ring operations. -/
meta def tactic.interactive.witt_truncate_fun_tac : tactic unit :=
`[show _ = truncate_fun n _,
apply truncated_witt_vector.out_injective,
iterate { rw [out_truncate_fun] },
rw init_add <|> rw init_mul <|> rw init_neg]
namespace witt_vector
variables (p n R)
variable [comm_ring R]
lemma truncate_fun_surjective :
surjective (@truncate_fun p n R) :=
λ x, ⟨x.out, truncated_witt_vector.truncate_fun_out x⟩
include hp
@[simp]
lemma truncate_fun_zero : truncate_fun n (0 : 𝕎 R) = 0 := rfl
@[simp]
lemma truncate_fun_one : truncate_fun n (1 : 𝕎 R) = 1 := rfl
variables {p R}
@[simp]
lemma truncate_fun_add (x y : 𝕎 R) :
truncate_fun n (x + y) = truncate_fun n x + truncate_fun n y :=
by witt_truncate_fun_tac
@[simp]
lemma truncate_fun_mul (x y : 𝕎 R) :
truncate_fun n (x * y) = truncate_fun n x * truncate_fun n y :=
by witt_truncate_fun_tac
lemma truncate_fun_neg (x : 𝕎 R) :
truncate_fun n (-x) = -truncate_fun n x :=
by witt_truncate_fun_tac
end witt_vector
namespace truncated_witt_vector
open witt_vector
variables (p n R)
variable [comm_ring R]
include hp
instance : comm_ring (truncated_witt_vector p n R) :=
(truncate_fun_surjective p n R).comm_ring _
(truncate_fun_zero p n R)
(truncate_fun_one p n R)
(truncate_fun_add n)
(truncate_fun_mul n)
(truncate_fun_neg n)
end truncated_witt_vector
namespace witt_vector
open truncated_witt_vector
variables (n)
variable [comm_ring R]
include hp
/-- `truncate n` is a ring homomorphism that truncates `x` to its first `n` entries
to obtain a `truncated_witt_vector`, which has the same base `p` as `x`. -/
def truncate : 𝕎 R →+* truncated_witt_vector p n R :=
{ to_fun := truncate_fun n,
map_zero' := truncate_fun_zero p n R,
map_add' := truncate_fun_add n,
map_one' := truncate_fun_one p n R,
map_mul' := truncate_fun_mul n }
variables (p n R)
lemma truncate_surjective : surjective (truncate n : 𝕎 R → truncated_witt_vector p n R) :=
truncate_fun_surjective p n R
variables {p n R}
@[simp] lemma coeff_truncate (x : 𝕎 R) (i : fin n) :
(truncate n x).coeff i = x.coeff i :=
coeff_truncate_fun _ _
variables (n)
lemma mem_ker_truncate (x : 𝕎 R) :
x ∈ (@truncate p _ n R _).ker ↔ ∀ i < n, x.coeff i = 0 :=
begin
simp only [ring_hom.mem_ker, truncate, truncate_fun, ring_hom.coe_mk,
truncated_witt_vector.ext_iff, truncated_witt_vector.coeff_mk, coeff_zero],
exact subtype.forall
end
variables (p)
@[simp] lemma truncate_mk (f : ℕ → R) :
truncate n (mk p f) = truncated_witt_vector.mk _ (λ k, f k) :=
begin
ext i,
rw [coeff_truncate, coeff_mk, truncated_witt_vector.coeff_mk],
end
end witt_vector
namespace truncated_witt_vector
variable [comm_ring R]
include hp
/--
A ring homomorphism that truncates a truncated Witt vector of length `m` to
a truncated Witt vector of length `n`, for `n ≤ m`.
-/
def truncate {m : ℕ} (hm : n ≤ m) : truncated_witt_vector p m R →+* truncated_witt_vector p n R :=
ring_hom.lift_of_surjective
(witt_vector.truncate m)
(witt_vector.truncate_surjective p m R)
(witt_vector.truncate n)
begin
intro x,
simp only [witt_vector.mem_ker_truncate],
intros h i hi,
exact h i (lt_of_lt_of_le hi hm)
end
@[simp] lemma truncate_comp_witt_vector_truncate {m : ℕ} (hm : n ≤ m) :
(@truncate p _ n R _ m hm).comp (witt_vector.truncate m) = witt_vector.truncate n :=
ring_hom.lift_of_surjective_comp _ _ _ _
@[simp] lemma truncate_witt_vector_truncate {m : ℕ} (hm : n ≤ m) (x : 𝕎 R) :
truncate hm (witt_vector.truncate m x) = witt_vector.truncate n x :=
ring_hom.lift_of_surjective_comp_apply _ _ _ _ _
@[simp] lemma truncate_truncate {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃)
(x : truncated_witt_vector p n₃ R) :
(truncate h1) (truncate h2 x) = truncate (h1.trans h2) x :=
begin
obtain ⟨x, rfl⟩ := witt_vector.truncate_surjective p n₃ R x,
simp only [truncate_witt_vector_truncate],
end
@[simp] lemma truncate_comp {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃) :
(@truncate p _ _ R _ _ h1).comp (truncate h2) = truncate (h1.trans h2) :=
begin
ext1 x, simp only [truncate_truncate, function.comp_app, ring_hom.coe_comp]
end
lemma truncate_surjective {m : ℕ} (hm : n ≤ m) : surjective (@truncate p _ _ R _ _ hm) :=
begin
intro x,
obtain ⟨x, rfl⟩ := witt_vector.truncate_surjective p _ R x,
exact ⟨witt_vector.truncate _ x, truncate_witt_vector_truncate _ _⟩
end
@[simp] lemma coeff_truncate {m : ℕ} (hm : n ≤ m) (i : fin n) (x : truncated_witt_vector p m R) :
(truncate hm x).coeff i = x.coeff (fin.cast_le hm i) :=
begin
obtain ⟨y, rfl⟩ := witt_vector.truncate_surjective p _ _ x,
simp only [truncate_witt_vector_truncate, witt_vector.coeff_truncate, fin.coe_cast_le],
end
section fintype
omit hp
instance {R : Type*} [fintype R] : fintype (truncated_witt_vector p n R) := pi.fintype
variables (p n R)
lemma card {R : Type*} [fintype R] :
fintype.card (truncated_witt_vector p n R) = fintype.card R ^ n :=
by simp only [truncated_witt_vector, fintype.card_fin, fintype.card_fun]
end fintype
lemma infi_ker_truncate : (⨅ i : ℕ, (@witt_vector.truncate p _ i R _).ker) = ⊥ :=
begin
rw [submodule.eq_bot_iff],
intros x hx,
ext,
simp only [witt_vector.mem_ker_truncate, ideal.mem_infi, witt_vector.zero_coeff] at hx ⊢,
exact hx _ _ (nat.lt_succ_self _)
end
end truncated_witt_vector
namespace witt_vector
open truncated_witt_vector (hiding truncate coeff)
section lift
variable [comm_ring R]
variables {S : Type*} [semiring S]
variable (f : Π k : ℕ, S →+* truncated_witt_vector p k R)
variable f_compat : ∀ (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂),
(truncated_witt_vector.truncate hk).comp (f k₂) = f k₁
variables {p R}
variable (n)
/--
Given a family `fₖ : S → truncated_witt_vector p k R` and `s : S`, we produce a Witt vector by
defining the `k`th entry to be the final entry of `fₖ s`.
-/
def lift_fun (s : S) : 𝕎 R :=
witt_vector.mk p $ λ k, truncated_witt_vector.coeff (fin.last k) (f (k+1) s)
variables {f}
include f_compat
@[simp] lemma truncate_lift_fun (s : S) :
witt_vector.truncate n (lift_fun f s) = f n s :=
begin
ext i,
simp only [lift_fun, truncated_witt_vector.coeff_mk, witt_vector.truncate_mk],
rw [← f_compat (i+1) n i.is_lt, ring_hom.comp_apply, truncated_witt_vector.coeff_truncate],
-- this is a bit unfortunate
congr' with _,
simp only [fin.coe_last, fin.coe_cast_le],
end
variable (f)
/--
Given compatible ring homs from `S` into `truncated_witt_vector n` for each `n`, we can lift these
to a ring hom `S → 𝕎 R`.
`lift` defines the universal property of `𝕎 R` as the inverse limit of `truncated_witt_vector n`.
-/
def lift : S →+* 𝕎 R :=
by refine_struct { to_fun := lift_fun f };
{ intros,
rw [← sub_eq_zero, ← ideal.mem_bot, ← infi_ker_truncate, ideal.mem_infi],
simp [ring_hom.mem_ker, f_compat] }
variable {f}
@[simp] lemma truncate_lift (s : S) :
witt_vector.truncate n (lift _ f_compat s) = f n s :=
truncate_lift_fun _ f_compat s
@[simp] lemma truncate_comp_lift :
(witt_vector.truncate n).comp (lift _ f_compat) = f n :=
by { ext1, rw [ring_hom.comp_apply, truncate_lift] }
/-- The uniqueness part of the universal property of `𝕎 R`. -/
lemma lift_unique (g : S →+* 𝕎 R) (g_compat : ∀ k, (witt_vector.truncate k).comp g = f k) :
lift _ f_compat = g :=
begin
ext1 x,
rw [← sub_eq_zero, ← ideal.mem_bot, ← infi_ker_truncate, ideal.mem_infi],
intro i,
simp only [ring_hom.mem_ker, g_compat, ←ring_hom.comp_apply,
truncate_comp_lift, ring_hom.map_sub, sub_self],
end
omit f_compat
include hp
/-- The universal property of `𝕎 R` as projective limit of truncated Witt vector rings. -/
@[simps] def lift_equiv : {f : Π k, S →+* truncated_witt_vector p k R // ∀ k₁ k₂ (hk : k₁ ≤ k₂),
(truncated_witt_vector.truncate hk).comp (f k₂) = f k₁} ≃ (S →+* 𝕎 R) :=
{ to_fun := λ f, lift f.1 f.2,
inv_fun := λ g, ⟨λ k, (truncate k).comp g,
by { intros _ _ h, simp only [←ring_hom.comp_assoc, truncate_comp_witt_vector_truncate] }⟩,
left_inv := by { rintro ⟨f, hf⟩, simp only [truncate_comp_lift] },
right_inv := λ g, lift_unique _ _ $ λ _, rfl }
lemma hom_ext (g₁ g₂ : S →+* 𝕎 R) (h : ∀ k, (truncate k).comp g₁ = (truncate k).comp g₂) :
g₁ = g₂ :=
lift_equiv.symm.injective $ subtype.ext $ funext h
end lift
end witt_vector
|
a0d63834847ddf44f96ee3b39e7df88743b75e72
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/number_theory/padics/padic_numbers.lean
|
778e8937e1c6eebf43ade9df2e698ac126ef7a53
|
[
"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
| 39,217
|
lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import number_theory.padics.padic_norm
import analysis.normed.field.basic
/-!
# p-adic numbers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as
the completion of `ℚ` with respect to the `p`-adic norm.
We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`,
and that `ℚ_[p]` is Cauchy complete.
## Important definitions
* `padic` : the type of `p`-adic numbers
* `padic_norm_e` : the rational valued `p`-adic norm on `ℚ_[p]`
* `padic.add_valuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `with_top ℤ`
## Notation
We introduce the notation `ℚ_[p]` for the `p`-adic numbers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[fact p.prime]` as a type class argument.
We use the same concrete Cauchy sequence construction that is used to construct `ℝ`.
`ℚ_[p]` inherits a field structure from this construction.
The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to
`ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete.
A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence
indices in the proof that the norm extends.
`padic_norm_e` is the rational-valued `p`-adic norm on `ℚ_[p]`.
To instantiate `ℚ_[p]` as a normed field, we must cast this into a `ℝ`-valued norm.
The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces,
is the canonical representation of this norm.
`simp` prefers `padic_norm` to `padic_norm_e` when possible.
Since `padic_norm_e` and `‖ ‖` have different types, `simp` does not rewrite one to the other.
Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable theory
open_locale classical
open nat multiplicity padic_norm cau_seq cau_seq.completion metric
/-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/
@[reducible] def padic_seq (p : ℕ) := cau_seq _ (padic_norm p)
namespace padic_seq
section
variables {p : ℕ} [fact p.prime]
/-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
lemma stationary {f : cau_seq ℚ (padic_norm p)} (hf : ¬ f ≈ 0) :
∃ N, ∀ m n, N ≤ m → N ≤ n → padic_norm p (f n) = padic_norm p (f m) :=
have ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padic_norm p (f j),
from cau_seq.abv_pos_of_not_lim_zero $ not_lim_zero_of_not_congr_zero hf,
let ⟨ε, hε, N1, hN1⟩ := this,
⟨N2, hN2⟩ := cau_seq.cauchy₂ f hε in
⟨ max N1 N2,
λ n m hn hm,
have padic_norm p (f n - f m) < ε, from hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2,
have padic_norm p (f n - f m) < padic_norm p (f n),
from lt_of_lt_of_le this $ hN1 _ (max_le_iff.1 hn).1,
have padic_norm p (f n - f m) < max (padic_norm p (f n)) (padic_norm p (f m)),
from lt_max_iff.2 (or.inl this),
begin
by_contradiction hne,
rw ← padic_norm.neg (f m) at hne,
have hnam := add_eq_max_of_ne hne,
rw [padic_norm.neg, max_comm] at hnam,
rw [← hnam, sub_eq_add_neg, add_comm] at this,
apply _root_.lt_irrefl _ this
end ⟩
/-- For all `n ≥ stationary_point f hf`, the `p`-adic norm of `f n` is the same. -/
def stationary_point {f : padic_seq p} (hf : ¬ f ≈ 0) : ℕ := classical.some $ stationary hf
lemma stationary_point_spec {f : padic_seq p} (hf : ¬ f ≈ 0) :
∀ {m n}, stationary_point hf ≤ m → stationary_point hf ≤ n →
padic_norm p (f n) = padic_norm p (f m) :=
classical.some_spec $ stationary hf
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,
we can lift the norm to sequences. -/
def norm (f : padic_seq p) : ℚ := if hf : f ≈ 0 then 0 else padic_norm p (f (stationary_point hf))
lemma norm_zero_iff (f : padic_seq p) : f.norm = 0 ↔ f ≈ 0 :=
begin
constructor,
{ intro h,
by_contradiction hf,
unfold norm at h, split_ifs at h,
apply hf,
intros ε hε,
existsi stationary_point hf,
intros j hj,
have heq := stationary_point_spec hf le_rfl hj,
simpa [h, heq] },
{ intro h,
simp [norm, h] }
end
end
section embedding
open cau_seq
variables {p : ℕ} [fact p.prime]
lemma equiv_zero_of_val_eq_of_equiv_zero {f g : padic_seq p}
(h : ∀ k, padic_norm p (f k) = padic_norm p (g k)) (hf : f ≈ 0) : g ≈ 0 :=
λ ε hε, let ⟨i, hi⟩ := hf _ hε in ⟨i, λ j hj, by simpa [h] using hi _ hj⟩
lemma norm_nonzero_of_not_equiv_zero {f : padic_seq p} (hf : ¬ f ≈ 0) : f.norm ≠ 0 :=
hf ∘ f.norm_zero_iff.1
lemma norm_eq_norm_app_of_nonzero {f : padic_seq p} (hf : ¬ f ≈ 0) :
∃ k, f.norm = padic_norm p k ∧ k ≠ 0 :=
have heq : f.norm = padic_norm p (f $ stationary_point hf), by simp [norm, hf],
⟨f $ stationary_point hf, heq, λ h, norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩
lemma not_lim_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬ lim_zero (const (padic_norm p) q) :=
λ h', hq $ const_lim_zero.1 h'
lemma not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬ const (padic_norm p) q ≈ 0 :=
λ h : lim_zero (const (padic_norm p) q - 0), not_lim_zero_const_of_nonzero hq $ by simpa using h
lemma norm_nonneg (f : padic_seq p) : 0 ≤ f.norm :=
if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padic_norm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left_left {f : padic_seq p} (hf : ¬ f ≈ 0) (v2 v3 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max (stationary_point hf) (max v2 v3))) :=
begin
apply stationary_point_spec hf,
{ apply le_max_left },
{ exact le_rfl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_left {f : padic_seq p} (hf : ¬ f ≈ 0) (v1 v3 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max (stationary_point hf) v3))) :=
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_left _ v3 },
{ apply le_max_right } },
{ exact le_rfl }
end
/-- An auxiliary lemma for manipulating sequence indices. -/
lemma lift_index_right {f : padic_seq p} (hf : ¬ f ≈ 0) (v1 v2 : ℕ) :
padic_norm p (f (stationary_point hf)) =
padic_norm p (f (max v1 (max v2 (stationary_point hf)))) :=
begin
apply stationary_point_spec hf,
{ apply le_trans,
{ apply le_max_right v2 },
{ apply le_max_right } },
{ exact le_rfl }
end
end embedding
section valuation
open cau_seq
variables {p : ℕ} [fact p.prime]
/-! ### Valuation on `padic_seq` -/
/-- The `p`-adic valuation on `ℚ` lifts to `padic_seq p`.
`valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/
def valuation (f : padic_seq p) : ℤ :=
if hf : f ≈ 0 then 0 else padic_val_rat p (f (stationary_point hf))
lemma norm_eq_pow_val {f : padic_seq p} (hf : ¬ f ≈ 0) : f.norm = p ^ (-f.valuation : ℤ) :=
begin
rw [norm, valuation, dif_neg hf, dif_neg hf, padic_norm, if_neg],
intro H,
apply cau_seq.not_lim_zero_of_not_congr_zero hf,
intros ε hε,
use (stationary_point hf),
intros n hn,
rw stationary_point_spec hf le_rfl hn,
simpa [H] using hε
end
lemma val_eq_iff_norm_eq {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) :
f.valuation = g.valuation ↔ f.norm = g.norm :=
begin
rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj],
{ exact_mod_cast (fact.out p.prime).pos },
{ exact_mod_cast (fact.out p.prime).ne_one }
end
end valuation
end padic_seq
section
open padic_seq
private meta def index_simp_core (hh hf hg : expr)
(at_ : interactive.loc := interactive.loc.ns [none]) : tactic unit :=
do [v1, v2, v3] ← [hh, hf, hg].mmap
(λ n, tactic.mk_app ``stationary_point [n] <|> return n),
e1 ← tactic.mk_app ``lift_index_left_left [hh, v2, v3] <|> return `(true),
e2 ← tactic.mk_app ``lift_index_left [hf, v1, v3] <|> return `(true),
e3 ← tactic.mk_app ``lift_index_right [hg, v1, v2] <|> return `(true),
sl ← [e1, e2, e3].mfoldl (λ s e, simp_lemmas.add s e) simp_lemmas.mk,
when at_.include_goal (tactic.simp_target sl >> tactic.skip),
hs ← at_.get_locals, hs.mmap' (tactic.simp_hyp sl [])
/-- This is a special-purpose tactic that lifts `padic_norm (f (stationary_point f))` to
`padic_norm (f (max _ _ _))`. -/
meta def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic unit :=
do [h, f, g] ← l.mmap tactic.i_to_expr,
index_simp_core h f g at_
end
namespace padic_seq
section embedding
open cau_seq
variables {p : ℕ} [hp : fact p.prime]
include hp
lemma norm_mul (f g : padic_seq p) : (f * g).norm = f.norm * g.norm :=
if hf : f ≈ 0 then
have hg : f * g ≈ 0, from mul_equiv_zero' _ hf,
by simp only [hf, hg, norm, dif_pos, zero_mul]
else if hg : g ≈ 0 then
have hf : f * g ≈ 0, from mul_equiv_zero _ hg,
by simp only [hf, hg, norm, dif_pos, mul_zero]
else
have hfg : ¬ f * g ≈ 0, by apply mul_not_equiv_zero; assumption,
begin
unfold norm,
split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.mul
end
lemma eq_zero_iff_equiv_zero (f : padic_seq p) : mk f = 0 ↔ f ≈ 0 := mk_eq
lemma ne_zero_iff_nequiv_zero (f : padic_seq p) : mk f ≠ 0 ↔ ¬ f ≈ 0 :=
not_iff_not.2 (eq_zero_iff_equiv_zero _)
lemma norm_const (q : ℚ) : norm (const (padic_norm p) q) = padic_norm p q :=
if hq : q = 0 then
have (const (padic_norm p) q) ≈ 0,
by simp [hq]; apply setoid.refl (const (padic_norm p) 0),
by subst hq; simp [norm, this]
else
have ¬ (const (padic_norm p) q) ≈ 0, from not_equiv_zero_const_of_nonzero hq,
by simp [norm, this]
lemma norm_values_discrete (a : padic_seq p) (ha : ¬ a ≈ 0) : ∃ z : ℤ, a.norm = p ^ -z :=
let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha in
by simpa [hk] using padic_norm.values_discrete hk'
lemma norm_one : norm (1 : padic_seq p) = 1 :=
have h1 : ¬ (1 : padic_seq p) ≈ 0, from one_not_equiv_zero _,
by simp [h1, norm, hp.1.one_lt]
private lemma norm_eq_of_equiv_aux {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) (hfg : f ≈ g)
(h : padic_norm p (f (stationary_point hf)) ≠ padic_norm p (g (stationary_point hg)))
(hlt : padic_norm p (g (stationary_point hg)) < padic_norm p (f (stationary_point hf))) : false :=
begin
have hpn : 0 < padic_norm p (f (stationary_point hf)) - padic_norm p (g (stationary_point hg)),
from sub_pos_of_lt hlt,
cases hfg _ hpn with N hN,
let i := max N (max (stationary_point hf) (stationary_point hg)),
have hi : N ≤ i, from le_max_left _ _,
have hN' := hN _ hi,
padic_index_simp [N, hf, hg] at hN' h hlt,
have hpne : padic_norm p (f i) ≠ padic_norm p (-(g i)),
by rwa [← padic_norm.neg (g i)] at h,
let hpnem := add_eq_max_of_ne hpne,
have hpeq : padic_norm p ((f - g) i) = max (padic_norm p (f i)) (padic_norm p (g i)),
{ rwa padic_norm.neg at hpnem },
rw [hpeq, max_eq_left_of_lt hlt] at hN',
have : padic_norm p (f i) < padic_norm p (f i),
{ apply lt_of_lt_of_le hN', apply sub_le_self, apply padic_norm.nonneg },
exact lt_irrefl _ this
end
private lemma norm_eq_of_equiv {f g : padic_seq p} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) (hfg : f ≈ g) :
padic_norm p (f (stationary_point hf)) = padic_norm p (g (stationary_point hg)) :=
begin
by_contradiction h,
cases (decidable.em (padic_norm p (g (stationary_point hg)) <
padic_norm p (f (stationary_point hf))))
with hlt hnlt,
{ exact norm_eq_of_equiv_aux hf hg hfg h hlt },
{ apply norm_eq_of_equiv_aux hg hf (setoid.symm hfg) (ne.symm h),
apply lt_of_le_of_ne,
apply le_of_not_gt hnlt,
apply h }
end
theorem norm_equiv {f g : padic_seq p} (hfg : f ≈ g) : f.norm = g.norm :=
if hf : f ≈ 0 then
have hg : g ≈ 0, from setoid.trans (setoid.symm hfg) hf,
by simp [norm, hf, hg]
else have hg : ¬ g ≈ 0, from hf ∘ setoid.trans hfg,
by unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private lemma norm_nonarchimedean_aux {f g : padic_seq p}
(hfg : ¬ f + g ≈ 0) (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) : (f + g).norm ≤ max f.norm g.norm :=
begin
unfold norm, split_ifs,
padic_index_simp [hfg, hf, hg],
apply padic_norm.nonarchimedean
end
theorem norm_nonarchimedean (f g : padic_seq p) : (f + g).norm ≤ max f.norm g.norm :=
if hfg : f + g ≈ 0 then
have 0 ≤ max f.norm g.norm, from le_max_of_le_left (norm_nonneg _),
by simpa only [hfg, norm, ne.def, le_max_iff, cau_seq.add_apply, not_true, dif_pos]
else if hf : f ≈ 0 then
have hfg' : f + g ≈ g,
{ change lim_zero (f - 0) at hf,
show lim_zero (f + g - g), by simpa only [sub_zero, add_sub_cancel] using hf },
have hcfg : (f + g).norm = g.norm, from norm_equiv hfg',
have hcl : f.norm = 0, from (norm_zero_iff f).2 hf,
have max f.norm g.norm = g.norm,
by rw hcl; exact max_eq_right (norm_nonneg _),
by rw [this, hcfg]
else if hg : g ≈ 0 then
have hfg' : f + g ≈ f,
{ change lim_zero (g - 0) at hg,
show lim_zero (f + g - f), by simpa only [add_sub_cancel', sub_zero] using hg },
have hcfg : (f + g).norm = f.norm, from norm_equiv hfg',
have hcl : g.norm = 0, from (norm_zero_iff g).2 hg,
have max f.norm g.norm = f.norm,
by rw hcl; exact max_eq_left (norm_nonneg _),
by rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
lemma norm_eq {f g : padic_seq p} (h : ∀ k, padic_norm p (f k) = padic_norm p (g k)) :
f.norm = g.norm :=
if hf : f ≈ 0 then
have hg : g ≈ 0, from equiv_zero_of_val_eq_of_equiv_zero h hf,
by simp only [hf, hg, norm, dif_pos]
else
have hg : ¬ g ≈ 0, from λ hg, hf $ equiv_zero_of_val_eq_of_equiv_zero
(by simp only [h, forall_const, eq_self_iff_true]) hg,
begin
simp only [hg, hf, norm, dif_neg, not_false_iff],
let i := max (stationary_point hf) (stationary_point hg),
have hpf : padic_norm p (f (stationary_point hf)) = padic_norm p (f i),
{ apply stationary_point_spec, apply le_max_left, exact le_rfl },
have hpg : padic_norm p (g (stationary_point hg)) = padic_norm p (g i),
{ apply stationary_point_spec, apply le_max_right, exact le_rfl },
rw [hpf, hpg, h]
end
lemma norm_neg (a : padic_seq p) : (-a).norm = a.norm := norm_eq $ by simp
lemma norm_eq_of_add_equiv_zero {f g : padic_seq p} (h : f + g ≈ 0) : f.norm = g.norm :=
have lim_zero (f + g - 0), from h,
have f ≈ -g, from show lim_zero (f - (-g)), by simpa only [sub_zero, sub_neg_eq_add],
have f.norm = (-g).norm, from norm_equiv this,
by simpa only [norm_neg] using this
lemma add_eq_max_of_ne {f g : padic_seq p} (hfgne : f.norm ≠ g.norm) :
(f + g).norm = max f.norm g.norm :=
have hfg : ¬f + g ≈ 0, from mt norm_eq_of_add_equiv_zero hfgne,
if hf : f ≈ 0 then
have lim_zero (f - 0), from hf,
have f + g ≈ g, from show lim_zero ((f + g) - g), by simpa only [sub_zero, add_sub_cancel],
have h1 : (f + g).norm = g.norm, from norm_equiv this,
have h2 : f.norm = 0, from (norm_zero_iff _).2 hf,
by rw [h1, h2]; rw max_eq_right (norm_nonneg _)
else if hg : g ≈ 0 then
have lim_zero (g - 0), from hg,
have f + g ≈ f, from show lim_zero ((f + g) - f), by rw [add_sub_cancel']; simpa only [sub_zero],
have h1 : (f + g).norm = f.norm, from norm_equiv this,
have h2 : g.norm = 0, from (norm_zero_iff _).2 hg,
by rw [h1, h2]; rw max_eq_left (norm_nonneg _)
else
begin
unfold norm at ⊢ hfgne, split_ifs at ⊢ hfgne,
padic_index_simp [hfg, hf, hg] at ⊢ hfgne,
exact padic_norm.add_eq_max_of_ne hfgne
end
end embedding
end padic_seq
/-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm.
-/
def padic (p : ℕ) [fact p.prime] := @cau_seq.completion.Cauchy _ _ _ _ (padic_norm p) _
notation `ℚ_[` p `]` := padic p
namespace padic
section completion
variables {p : ℕ} [fact p.prime]
instance : field (ℚ_[p]) := Cauchy.field
instance : inhabited ℚ_[p] := ⟨0⟩
-- short circuits
instance : comm_ring (ℚ_[p]) := Cauchy.comm_ring
instance : ring (ℚ_[p]) := Cauchy.ring
instance : has_zero ℚ_[p] := by apply_instance
instance : has_one ℚ_[p] := by apply_instance
instance : has_add ℚ_[p] := by apply_instance
instance : has_mul ℚ_[p] := by apply_instance
instance : has_sub ℚ_[p] := by apply_instance
instance : has_neg ℚ_[p] := by apply_instance
instance : has_div ℚ_[p] := by apply_instance
instance : add_comm_group ℚ_[p] := by apply_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : padic_seq p → ℚ_[p] := quotient.mk
variables (p)
lemma zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl
lemma mk_eq {f g : padic_seq p} : mk f = mk g ↔ f ≈ g := quotient.eq
lemma const_equiv {q r : ℚ} : const (padic_norm p) q ≈ const (padic_norm p) r ↔ q = r :=
⟨ λ heq, eq_of_sub_eq_zero $ const_lim_zero.1 heq, λ heq, by rw heq; apply setoid.refl _ ⟩
@[norm_cast] lemma coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r :=
⟨(const_equiv p).1 ∘ quotient.eq.1, λ h, by rw h⟩
instance : char_zero ℚ_[p] := ⟨λ m n, by { rw ← rat.cast_coe_nat, norm_cast, exact id }⟩
@[norm_cast] lemma coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y := rat.cast_add
@[norm_cast] lemma coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x := rat.cast_neg
@[norm_cast] lemma coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y := rat.cast_mul
@[norm_cast] lemma coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y := rat.cast_sub
@[norm_cast] lemma coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y := rat.cast_div
@[norm_cast] lemma coe_one : (↑1 : ℚ_[p]) = 1 := rfl
@[norm_cast] lemma coe_zero : (↑0 : ℚ_[p]) = 0 := rfl
end completion
end padic
/-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `‖ ‖`. -/
def padic_norm_e {p : ℕ} [hp : fact p.prime] : absolute_value ℚ_[p] ℚ :=
{ to_fun := quotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _,
map_mul' := λ q r, quotient.induction_on₂ q r $ padic_seq.norm_mul,
nonneg' := λ q, quotient.induction_on q $ padic_seq.norm_nonneg,
eq_zero' := λ q, quotient.induction_on q $
by simpa only [padic.zero_def, quotient.eq] using padic_seq.norm_zero_iff,
add_le' := λ q r, begin
transitivity max ((quotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _) q)
((quotient.lift padic_seq.norm $ @padic_seq.norm_equiv _ _) r),
exact (quotient.induction_on₂ q r $ padic_seq.norm_nonarchimedean),
refine max_le_add_of_nonneg (quotient.induction_on q $ padic_seq.norm_nonneg) _,
exact (quotient.induction_on r $ padic_seq.norm_nonneg)
end }
namespace padic_norm_e
section embedding
open padic_seq
variables {p : ℕ} [fact p.prime]
lemma defn (f : padic_seq p) {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padic_norm_e (⟦f⟧ - f i) < ε :=
begin
dsimp [padic_norm_e],
change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε,
by_contra' h,
cases cauchy₂ f hε with N hN,
rcases h N with ⟨i, hi, hge⟩,
have hne : ¬ (f - const (padic_norm p) (f i)) ≈ 0,
{ intro h, unfold padic_seq.norm at hge; split_ifs at hge, exact not_lt_of_ge hge hε },
unfold padic_seq.norm at hge; split_ifs at hge,
apply not_le_of_gt _ hge,
cases em (N ≤ stationary_point hne) with hgen hngen,
{ apply hN _ hgen _ hi },
{ have := stationary_point_spec hne le_rfl (le_of_not_le hngen),
rw ← this,
exact hN _ le_rfl _ hi }
end
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem nonarchimedean' (q r : ℚ_[p]) :
padic_norm_e (q + r) ≤ max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_on₂ q r $ norm_nonarchimedean
/-- Theorems about `padic_norm_e` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem add_eq_max_of_ne' {q r : ℚ_[p]} :
padic_norm_e q ≠ padic_norm_e r → padic_norm_e (q + r) = max (padic_norm_e q) (padic_norm_e r) :=
quotient.induction_on₂ q r $ λ _ _, padic_seq.add_eq_max_of_ne
@[simp] lemma eq_padic_norm' (q : ℚ) : padic_norm_e (q : ℚ_[p]) = padic_norm p q :=
norm_const _
protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padic_norm_e q = p ^ -n :=
quotient.induction_on q $ λ f hf,
have ¬ f ≈ 0, from (ne_zero_iff_nequiv_zero f).1 hf,
norm_values_discrete f this
end embedding
end padic_norm_e
namespace padic
section complete
open padic_seq padic
variables {p : ℕ} [fact p.prime] (f : cau_seq _ (@padic_norm_e p _))
theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) :
∃ r : ℚ, padic_norm_e (q - r) < ε :=
quotient.induction_on q $ λ q',
have ∃ N, ∀ m n ≥ N, padic_norm p (q' m - q' n) < ε, from cauchy₂ _ hε,
let ⟨N, hN⟩ := this in
⟨q' N,
begin
dsimp [padic_norm_e],
change padic_seq.norm (q' - const _ (q' N)) < ε,
cases decidable.em ((q' - const (padic_norm p) (q' N)) ≈ 0) with heq hne',
{ simpa only [heq, padic_seq.norm, dif_pos] },
{ simp only [padic_seq.norm, dif_neg hne'],
change padic_norm p (q' _ - q' _) < ε,
have := stationary_point_spec hne',
cases decidable.em (stationary_point hne' ≤ N) with hle hle,
{ have := eq.symm (this le_rfl hle),
simp only [const_apply, sub_apply, padic_norm.zero, sub_self] at this,
simpa only [this] },
{ exact hN _ (lt_of_not_ge hle).le _ le_rfl } }
end⟩
open classical
private lemma div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) :=
div_pos zero_lt_one (by exact_mod_cast succ_pos _)
/-- `lim_seq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the
same limit point as `f`. -/
def lim_seq : ℕ → ℚ := λ n, classical.some (rat_dense' (f n) (div_nat_pos n))
lemma exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padic_norm_e (f i - (lim_seq f i : ℚ_[p])) < ε :=
begin
refine (exists_nat_gt (1 / ε)).imp (λ N hN i hi, _),
have h := classical.some_spec (rat_dense' (f i) (div_nat_pos i)),
refine lt_of_lt_of_le h ((div_le_iff' $ by exact_mod_cast succ_pos _).mpr _),
rw right_distrib,
apply le_add_of_le_of_nonneg,
{ exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (by exact_mod_cast hi)) },
{ apply le_of_lt, simpa }
end
lemma exi_rat_seq_conv_cauchy : is_cau_seq (padic_norm p) (lim_seq f) :=
assume ε hε,
have hε3 : 0 < ε / 3, from div_pos hε (by norm_num),
let ⟨N, hN⟩ := exi_rat_seq_conv f hε3,
⟨N2, hN2⟩ := f.cauchy₂ hε3 in
begin
existsi max N N2,
intros j hj,
suffices :
padic_norm_e ((lim_seq f j - f (max N N2)) + (f (max N N2) - lim_seq f (max N N2))) < ε,
{ ring_nf at this ⊢,
rw [← padic_norm_e.eq_padic_norm'],
exact_mod_cast this },
{ apply lt_of_le_of_lt,
{ apply padic_norm_e.add_le },
{ have : (3 : ℚ) ≠ 0, by norm_num,
have : ε = ε / 3 + ε / 3 + ε / 3,
{ field_simp [this], simp only [bit0, bit1, mul_add, mul_one] },
rw this,
apply add_lt_add,
{ suffices : padic_norm_e ((lim_seq f j - f j) + (f j - f (max N N2))) < ε / 3 + ε / 3,
by simpa only [sub_add_sub_cancel],
apply lt_of_le_of_lt,
{ apply padic_norm_e.add_le },
{ apply add_lt_add,
{ rw [padic_norm_e.map_sub],
apply_mod_cast hN,
exact le_of_max_le_left hj },
{ exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _) } } },
{ apply_mod_cast hN,
apply le_max_left }}}
end
private def lim' : padic_seq p := ⟨_, exi_rat_seq_conv_cauchy f⟩
private def lim : ℚ_[p] := ⟦lim' f⟧
theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padic_norm_e (q - f i) < ε :=
⟨ lim f,
λ ε hε,
begin
obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε),
obtain ⟨N2, hN2⟩ := padic_norm_e.defn (lim' f) (half_pos hε),
refine ⟨max N N2, λ i hi, _⟩,
rw ←sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _,
refine (padic_norm_e.add_le _ _).trans_lt _,
rw ←add_halves ε,
apply add_lt_add,
{ apply hN2 _ (le_of_max_le_right hi) },
{ rw [padic_norm_e.map_sub],
exact hN _ (le_of_max_le_left hi) }
end ⟩
end complete
section normed_space
variables (p : ℕ) [fact p.prime]
instance : has_dist ℚ_[p] := ⟨λ x y, padic_norm_e (x - y)⟩
instance : metric_space ℚ_[p] :=
{ dist_self := by simp [dist],
dist := dist,
dist_comm := λ x y, by simp [dist, ←padic_norm_e.map_neg (x - y)],
dist_triangle := λ x y z,
begin
unfold dist,
exact_mod_cast padic_norm_e.sub_le _ _ _,
end,
eq_of_dist_eq_zero :=
begin
unfold dist, intros _ _ h,
apply eq_of_sub_eq_zero,
apply padic_norm_e.eq_zero.1,
exact_mod_cast h
end }
instance : has_norm ℚ_[p] := ⟨λ x, padic_norm_e x⟩
instance : normed_field ℚ_[p] :=
{ dist_eq := λ _ _, rfl,
norm_mul' := by simp [has_norm.norm, map_mul],
norm := norm, .. padic.field, .. padic.metric_space p }
instance is_absolute_value : is_absolute_value (λ a : ℚ_[p], ‖a‖) :=
{ abv_nonneg := norm_nonneg,
abv_eq_zero := λ _, norm_eq_zero,
abv_add := norm_add_le,
abv_mul := by simp [has_norm.norm, map_mul] }
theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε :=
let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε,
⟨r, hr⟩ := rat_dense' q (by simpa using hε'l) in
⟨r, lt_trans (by simpa [has_norm.norm] using hr) hε'r⟩
end normed_space
end padic
namespace padic_norm_e
section normed_space
variables {p : ℕ} [hp : fact p.prime]
include hp
@[simp] protected lemma mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ :=
by simp [has_norm.norm, map_mul]
protected lemma is_norm (q : ℚ_[p]) : ↑(padic_norm_e q) = ‖q‖ := rfl
theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max (‖q‖) (‖r‖) :=
begin
unfold has_norm.norm,
exact_mod_cast nonarchimedean' _ _
end
theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max (‖q‖) (‖r‖) :=
begin
unfold has_norm.norm,
apply_mod_cast add_eq_max_of_ne',
intro h',
apply h,
unfold has_norm.norm,
exact_mod_cast h'
end
@[simp] lemma eq_padic_norm (q : ℚ) : ‖(q : ℚ_[p])‖ = padic_norm p q :=
begin
unfold has_norm.norm,
rw [← padic_norm_e.eq_padic_norm']
end
@[simp] lemma norm_p : ‖(p : ℚ_[p])‖ = p⁻¹ :=
begin
have p₀ : p ≠ 0 := hp.1.ne_zero,
have p₁ : p ≠ 1 := hp.1.ne_one,
rw ← @rat.cast_coe_nat ℝ _ p,
rw ← @rat.cast_coe_nat (ℚ_[p]) _ p,
simp [p₀, p₁, norm, padic_norm, padic_val_rat, padic_val_int, zpow_neg, -rat.cast_coe_nat],
end
lemma norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 :=
begin
rw norm_p,
apply inv_lt_one,
exact_mod_cast hp.1.one_lt
end
@[simp] lemma norm_p_zpow (n : ℤ) : ‖(p ^ n : ℚ_[p])‖ = p ^ -n :=
by rw [norm_zpow, norm_p, zpow_neg, inv_zpow]
@[simp] lemma norm_p_pow (n : ℕ) : ‖(p ^ n : ℚ_[p])‖ = p ^ (-n : ℤ) :=
by rw [←norm_p_zpow, zpow_coe_nat]
instance : nontrivially_normed_field ℚ_[p] :=
{ non_trivial := ⟨p⁻¹, begin
rw [norm_inv, norm_p, inv_inv],
exact_mod_cast hp.1.one_lt
end⟩,
.. padic.normed_field p }
protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ -n) :=
quotient.induction_on q $ λ f hf,
have ¬ f ≈ 0, from (padic_seq.ne_zero_iff_nequiv_zero f).1 hf,
let ⟨n, hn⟩ := padic_seq.norm_values_discrete f this in
⟨n, congr_arg coe hn⟩
protected lemma is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' :=
if h : q = 0 then ⟨0, by simp [h]⟩ else let ⟨n, hn⟩ := padic_norm_e.image h in ⟨_, hn⟩
/--`rat_norm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.
The lemma `padic_norm_e.eq_rat_norm` asserts `‖q‖ = rat_norm q`. -/
def rat_norm (q : ℚ_[p]) : ℚ := classical.some (padic_norm_e.is_rat q)
lemma eq_rat_norm (q : ℚ_[p]) : ‖q‖ = rat_norm q := classical.some_spec (padic_norm_e.is_rat q)
theorem norm_rat_le_one : ∀ {q : ℚ} (hq : ¬ p ∣ q.denom), ‖(q : ℚ_[p])‖ ≤ 1
| ⟨n, d, hn, hd⟩ := λ hq : ¬ p ∣ d,
if hnz : n = 0 then
have (⟨n, d, hn, hd⟩ : ℚ) = 0,
from rat.zero_iff_num_zero.mpr hnz,
by norm_num [this]
else
begin
have hnz' : { rat . num := n, denom := d, pos := hn, cop := hd } ≠ 0,
from mt rat.zero_iff_num_zero.1 hnz,
rw [padic_norm_e.eq_padic_norm],
norm_cast,
rw [padic_norm.eq_zpow_of_nonzero hnz', padic_val_rat, neg_sub,
padic_val_nat.eq_zero_of_not_dvd hq],
norm_cast,
rw [zero_sub, zpow_neg, zpow_coe_nat],
apply inv_le_one,
{ norm_cast,
apply one_le_pow,
exact hp.1.pos }
end
theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 :=
suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1, by simpa, norm_rat_le_one $ by simp [hp.1.ne_one]
lemma norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k :=
begin
split,
{ intro h,
contrapose! h,
apply le_of_eq,
rw eq_comm,
calc ‖(k : ℚ_[p])‖ = ‖((k : ℚ) : ℚ_[p])‖ : by { norm_cast }
... = padic_norm p k : padic_norm_e.eq_padic_norm _
... = 1 : _,
rw padic_norm,
split_ifs with H,
{ exfalso,
apply h,
norm_cast at H,
rw H,
apply dvd_zero },
{ norm_cast at H ⊢,
convert zpow_zero _,
rw [neg_eq_zero, padic_val_rat.of_int],
norm_cast,
apply padic_val_int.eq_zero_of_not_dvd h } },
{ rintro ⟨x, rfl⟩,
push_cast,
rw padic_norm_e.mul,
calc _ ≤ ‖(p : ℚ_[p])‖ * 1 : mul_le_mul le_rfl (by simpa using norm_int_le_one _)
(norm_nonneg _) (norm_nonneg _)
... < 1 : _,
{ rw [mul_one, padic_norm_e.norm_p],
apply inv_lt_one,
exact_mod_cast hp.1.one_lt } }
end
lemma norm_int_le_pow_iff_dvd (k : ℤ) (n : ℕ) : ‖(k : ℚ_[p])‖ ≤ ↑p ^ (-n : ℤ) ↔ ↑(p ^ n) ∣ k :=
begin
have : (p : ℝ) ^ (-n : ℤ) = ↑(p ^ (-n : ℤ) : ℚ), {simp},
rw [show (k : ℚ_[p]) = ((k : ℚ) : ℚ_[p]), by norm_cast, eq_padic_norm, this],
norm_cast,
rw ← padic_norm.dvd_iff_norm_le
end
lemma eq_of_norm_add_lt_right {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_right) h
lemma eq_of_norm_add_lt_left {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ :=
by_contradiction $ λ hne,
not_lt_of_ge (by rw padic_norm_e.add_eq_max_of_ne hne; apply le_max_left) h
end normed_space
end padic_norm_e
namespace padic
variables {p : ℕ} [hp : fact p.prime]
include hp
set_option eqn_compiler.zeta true
instance complete : cau_seq.is_complete ℚ_[p] norm :=
begin
split, intro f,
have cau_seq_norm_e : is_cau_seq padic_norm_e f,
{ intros ε hε,
let h := is_cau f ε (by exact_mod_cast hε),
unfold norm at h,
apply_mod_cast h },
cases padic.complete' ⟨f, cau_seq_norm_e⟩ with q hq,
existsi q,
intros ε hε,
cases exists_rat_btwn hε with ε' hε',
norm_cast at hε',
cases hq ε' hε'.1 with N hN, existsi N,
intros i hi, let h := hN i hi,
unfold norm,
rw_mod_cast [padic_norm_e.map_sub],
refine lt_trans _ hε'.2,
exact_mod_cast hN i hi
end
lemma padic_norm_e_lim_le {f : cau_seq ℚ_[p] norm} {a : ℝ} (ha : 0 < a) (hf : ∀ i, ‖f i‖ ≤ a) :
‖f.lim‖ ≤ a :=
let ⟨N, hN⟩ := setoid.symm (cau_seq.equiv_lim f) _ ha in
calc ‖f.lim‖ = ‖f.lim - f N + f N‖ : by simp
... ≤ max (‖f.lim - f N‖) (‖f N‖) : padic_norm_e.nonarchimedean _ _
... ≤ a : max_le (le_of_lt (hN _ le_rfl)) (hf _)
open filter set
instance : complete_space ℚ_[p] :=
begin
apply complete_of_cauchy_seq_tendsto,
intros u hu,
let c : cau_seq ℚ_[p] norm := ⟨u, metric.cauchy_seq_iff'.mp hu⟩,
refine ⟨c.lim, λ s h, _⟩,
rcases metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩,
have := c.equiv_lim ε ε0,
simp only [mem_map, mem_at_top_sets, mem_set_of_eq],
exact this.imp (λ N hN n hn, hε (hN n hn))
end
/-! ### Valuation on `ℚ_[p]` -/
/-- `padic.valuation` lifts the `p`-adic valuation on rationals to `ℚ_[p]`. -/
def valuation : ℚ_[p] → ℤ := quotient.lift (@padic_seq.valuation p _) (λ f g h,
begin
by_cases hf : f ≈ 0,
{ have hg : g ≈ 0, from setoid.trans (setoid.symm h) hf,
simp [hf, hg, padic_seq.valuation] },
{ have hg : ¬ g ≈ 0, from (λ hg, hf (setoid.trans h hg)),
rw padic_seq.val_eq_iff_norm_eq hf hg,
exact padic_seq.norm_equiv h }
end)
@[simp] lemma valuation_zero : valuation (0 : ℚ_[p]) = 0 := dif_pos ((const_equiv p).2 rfl)
@[simp] lemma valuation_one : valuation (1 : ℚ_[p]) = 0 :=
begin
change dite (cau_seq.const (padic_norm p) 1 ≈ _) _ _ = _,
have h : ¬ cau_seq.const (padic_norm p) 1 ≈ 0,
{ assume H, erw const_equiv p at H, exact one_ne_zero H },
rw dif_neg h,
simp
end
lemma norm_eq_pow_val {x : ℚ_[p]} : x ≠ 0 → ‖x‖ = p ^ -x.valuation :=
begin
apply quotient.induction_on' x, clear x,
intros f hf,
change (padic_seq.norm _ : ℝ) = (p : ℝ) ^ -padic_seq.valuation _,
rw padic_seq.norm_eq_pow_val,
change ↑((p : ℚ) ^ -padic_seq.valuation f) = (p : ℝ) ^ -padic_seq.valuation f,
{ rw [rat.cast_zpow, rat.cast_coe_nat] },
{ apply cau_seq.not_lim_zero_of_not_congr_zero,
contrapose! hf,
apply quotient.sound,
simpa using hf }
end
@[simp] lemma valuation_p : valuation (p : ℚ_[p]) = 1 :=
begin
have h : (1 : ℝ) < p := by exact_mod_cast (fact.out p.prime).one_lt,
refine neg_injective ((zpow_strict_mono h).injective $ (norm_eq_pow_val _).symm.trans _),
{ exact_mod_cast (fact.out p.prime).ne_zero },
{ simp }
end
lemma valuation_map_add {x y : ℚ_[p]} (hxy : x + y ≠ 0) :
min (valuation x) (valuation y) ≤ valuation (x + y) :=
begin
by_cases hx : x = 0,
{ rw [hx, zero_add],
exact min_le_right _ _ },
{ by_cases hy : y = 0,
{ rw [hy, add_zero],
exact min_le_left _ _ },
{ have h_norm : ‖x + y‖ ≤ (max ‖x‖ ‖y‖) := padic_norm_e.nonarchimedean x y,
have hp_one : (1 : ℝ) < p,
{ rw [← nat.cast_one, nat.cast_lt],
exact nat.prime.one_lt hp.elim },
rwa [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val hxy,
zpow_le_max_iff_min_le hp_one] at h_norm } }
end
@[simp] lemma valuation_map_mul {x y : ℚ_[p]} (hx : x ≠ 0) (hy : y ≠ 0) :
valuation (x * y) = valuation x + valuation y :=
begin
have h_norm : ‖x * y‖ = ‖x‖ * ‖y‖ := norm_mul x y,
have hp_ne_one : (p : ℝ) ≠ 1,
{ rw [← nat.cast_one, ne.def, nat.cast_inj],
exact nat.prime.ne_one hp.elim },
have hp_pos : (0 : ℝ) < p,
{ rw [← nat.cast_zero, nat.cast_lt],
exact nat.prime.pos hp.elim },
rw [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val (mul_ne_zero hx hy),
← zpow_add₀ (ne_of_gt hp_pos), zpow_inj hp_pos hp_ne_one, ← neg_add, neg_inj] at h_norm,
exact h_norm
end
/-- The additive `p`-adic valuation on `ℚ_[p]`, with values in `with_top ℤ`. -/
def add_valuation_def : ℚ_[p] → with_top ℤ := λ x, if x = 0 then ⊤ else x.valuation
@[simp] lemma add_valuation.map_zero : add_valuation_def (0 : ℚ_[p]) = ⊤ :=
by simp only [add_valuation_def, if_pos (eq.refl _)]
@[simp] lemma add_valuation.map_one : add_valuation_def (1 : ℚ_[p]) = 0 :=
by simp only [add_valuation_def, if_neg one_ne_zero, valuation_one, with_top.coe_zero]
lemma add_valuation.map_mul (x y : ℚ_[p]) :
add_valuation_def (x * y) = add_valuation_def x + add_valuation_def y :=
begin
simp only [add_valuation_def],
by_cases hx : x = 0,
{ rw [hx, if_pos (eq.refl _), zero_mul, if_pos (eq.refl _), with_top.top_add] },
{ by_cases hy : y = 0,
{ rw [hy, if_pos (eq.refl _), mul_zero, if_pos (eq.refl _), with_top.add_top] },
{ rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← with_top.coe_add,
with_top.coe_eq_coe, valuation_map_mul hx hy] }}
end
lemma add_valuation.map_add (x y : ℚ_[p]) :
min (add_valuation_def x) (add_valuation_def y) ≤ add_valuation_def (x + y) :=
begin
simp only [add_valuation_def],
by_cases hxy : x + y = 0,
{ rw [hxy, if_pos (eq.refl _)],
exact le_top },
{ by_cases hx : x = 0,
{ simp only [hx, if_pos (eq.refl _), min_eq_right, le_top, zero_add, le_refl] },
{ by_cases hy : y = 0,
{ simp only [hy, if_pos (eq.refl _), min_eq_left, le_top, add_zero, le_refl] },
{ rw [if_neg hx, if_neg hy, if_neg hxy, ← with_top.coe_min, with_top.coe_le_coe],
exact valuation_map_add hxy }}}
end
/-- The additive `p`-adic valuation on `ℚ_[p]`, as an `add_valuation`. -/
def add_valuation : add_valuation ℚ_[p] (with_top ℤ) :=
add_valuation.of add_valuation_def add_valuation.map_zero add_valuation.map_one
add_valuation.map_add add_valuation.map_mul
@[simp] lemma add_valuation.apply {x : ℚ_[p]} (hx : x ≠ 0) : x.add_valuation = x.valuation :=
by simp only [add_valuation, add_valuation.of_apply, add_valuation_def, if_neg hx]
section norm_le_iff
/-! ### Various characterizations of open unit balls -/
lemma norm_le_pow_iff_norm_lt_pow_add_one (x : ℚ_[p]) (n : ℤ) : ‖x‖ ≤ p ^ n ↔ ‖x‖ < p ^ (n + 1) :=
begin
have aux : ∀ n : ℤ, 0 < (p ^ n : ℝ),
{ apply nat.zpow_pos_of_pos, exact hp.1.pos },
by_cases hx0 : x = 0, { simp [hx0, norm_zero, aux, le_of_lt (aux _)] },
rw norm_eq_pow_val hx0,
have h1p : 1 < (p : ℝ), { exact_mod_cast hp.1.one_lt },
have H := zpow_strict_mono h1p,
rw [H.le_iff_le, H.lt_iff_lt, int.lt_add_one_iff]
end
lemma norm_lt_pow_iff_norm_le_pow_sub_one (x : ℚ_[p]) (n : ℤ) : ‖x‖ < p ^ n ↔ ‖x‖ ≤ p ^ (n - 1) :=
by rw [norm_le_pow_iff_norm_lt_pow_add_one, sub_add_cancel]
lemma norm_le_one_iff_val_nonneg (x : ℚ_[p]) : ‖ x ‖ ≤ 1 ↔ 0 ≤ x.valuation :=
begin
by_cases hx : x = 0,
{ simp only [hx, norm_zero, valuation_zero, zero_le_one, le_refl], },
{ rw [norm_eq_pow_val hx, ← zpow_zero (p : ℝ), zpow_le_iff_le, right.neg_nonpos_iff],
exact nat.one_lt_cast.2 (nat.prime.one_lt' p).1 }
end
end norm_le_iff
end padic
|
89365888dc1caa18c70b84242cbf3a93d8da3708
|
4b4a91d762ac3b6ef8f164899a6a26fc125eddd6
|
/src/level_2_group_actions.lean
|
6cbb77a3084ec4b6c91f11b1f97b785bcd99647a
|
[
"Apache-2.0"
] |
permissive
|
ImperialCollegeLondon/group-action-exercises
|
955ceba8edb7eba7b8916690083829d321909aee
|
197b1a0e53ec8d84bf3903c9ab5cddf615a44816
|
refs/heads/master
| 1,686,020,547,415
| 1,625,354,242,000
| 1,625,354,242,000
| 382,577,731
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,911
|
lean
|
/-
Apache 2, because everyone else is doing it
Written by Kevin Buzzard summer 2021 in his shed.
Powered by `mathlib`, the leanprover-community, without which nothing
would have happened.
Thanks to Leo and everyone at Microsoft Research for Lean.
-/
-- This imports all user tactics and a whole bunch of basic mathematics
import tactic
import group_theory.group_action.basic -- group actions
import data.setoid.partition -- theory of partitions
/-!
# Level 2 : Groups acting on types
In this level we demonstrate how a mathematician works with groups
acting on types in Lean. I will assume no familiarity with the
mathematics.
In technical terms, this file is an overview of the API for `mul_action`.
-/
/-
## Introduction
We know what a mathematician means when they say "let G be a group"
or "let S be a set/type". But what do they mean when they say "Assume
G acts on S", or "assume S is a G-set"?
Here is a precise answer.
## Section 2.1 : Definition of group actions
Let `G` be a group and let `S` be a type.
`variables (G : Type) [group G] (S : Type)`
An *action* of `G` on `S` is a function `has_scalar.smul : G → S → S`,
satisfying some axioms which we'll come to later. This function name
is rather unwieldy, but fortunately there is some notation `•` for it.
The notation and the axioms plus a bunch of theorems and constructions
all come as part of the `[mul_action G S]` typeclass.
The reason it's called an "action" is that if `g : G` then `g • _` is
a function from `S` to `S`, so it's a way of moving elements of `S` around,
or *acting* on them.
or to be super-precise a *left action* of `G` on `S`
The two axioms for `•` which make it a group action and not just a random
function are the following :
`one_smul G s : 1 • s = s`
`mul_smul g h s : (g * h) • s = g • (h • s)`
The first axiom says that `1 : G` "acts" in a completely boring way,
by not moving around anything at all.
The second axiom says that the group action on the `S` is compatible
with `G`'s internal multiplication.
## Exercise 2.1 : prove some theorems
Prove the following theorems.
-/
-- Let G be a group, let S be a type, and say G acts on S
variables {G : Type} [group G] {S : Type} [mul_action G S]
{g h : G} {s t u : S}
-- We use squiggly brackets this time because Lean's unifier will
-- always be able to guess which group and set we're
-- talking about
example : (g * g⁻¹) • s = s :=
begin
sorry
end
example : g⁻¹ • g • s = s :=
begin
sorry
end
/-
## Section 2.2 : Orbits
We can think of `•` as giving us a map `S → S` for each element of `G`.
The *orbit* of `s : S` is what we might informally write `G • s`,
namely the subset of `S` consisting of terms of the form `g • s` for `g : G`
Its full name is
`mul_action.orbit G s : set S`
but if we `open mul_action` we'll just be able to call it `orbit`.
-/
open mul_action
#check orbit G s -- set S
/-
### Orbits
Here is a brief API for orbits:
`mem_orbit_iff : t ∈ orbit G s ↔ ∃ (x : G), x • s = t`
`mem_orbit s g : g • s ∈ orbit G s`
`mem_orbit_self s : s ∈ orbit G s`
## Exercise 2.2
Why don't you try some orbit questions?
Tip 1 : I usually start with `rw mem_orbit_iff at *`
Tip 2 : work out the maths proof first, on a piece of paper.
-/
theorem mem_orbit_refl (s : S) : s ∈ orbit G s :=
begin
sorry
end
theorem mem_orbit_symm : s ∈ orbit G t → t ∈ orbit G s :=
begin
sorry
end
theorem mem_orbit_trans (hst : s ∈ orbit G t) (htu : t ∈ orbit G u) :
s ∈ orbit G u :=
begin
sorry
end
-- Did you just see a bijection between the three axioms
-- of an equivalence relation, and the three pieces of a structure in a group?
/-
## Section 2.3 : orbits are a partition
Equivalence classes form a partition of a type. Orbits do too. In other
words, an action of `G` on `S` breaks `S` up into a disjoint union
of distinct orbits for the action.
What is a partition? According to Lean, a collection `C` of subsets
of a type `S` satisfies the predicate `is_partition C` if none of the
subsets are empty, and furthermore every element of `S` is an element
of exactly one subset in `C`.
Here are the maths proofs. An orbit can't be empty, because `orbit G s`
contains `s`. Every element `s` of `S` is in an orbit because it's
in `orbit G s`. Uniqueness is harder.
I first establish a boring lemma saying that if `a ∈ orbit G s` and
`a ∈ orbit G t` then `s ∈ orbit G t`. This follows from symmetry
and transitivity of `mem_orbit` .
I next claim that if `s ∈ orbit G t` then `orbit G s ⊆ orbit G t`.
This follows from transitivity of `mem_orbit`.
Finally, if `a ∈ orbit G s` and `a ∈ orbit G t`
then I claim that `orbit G s = orbit G t`. This is because we have
inclusions in each direction, using the boring lemma.
Can you prove all this in Lean?
## Exercise 2.3 Prove that orbits form a partition.
-/
open set
variable (G)
theorem orbit_nonempty (s : S) : set.nonempty (orbit G s) :=
begin
rw nonempty_def,
sorry,
end
variable {G}
theorem mem_orbit (s : S) : ∃ (t : S), s ∈ orbit G t :=
begin
sorry,
end
variable {a : S}
theorem boring_lemma (has : a ∈ orbit G s) (hat : a ∈ orbit G t) : s ∈ orbit G t :=
begin
sorry,
end
theorem orbit_subset_of_mem_orbit (hst : s ∈ orbit G t) : orbit G s ⊆ orbit G t :=
begin
-- you can just abuse definitional equality and start with `intro u`,
sorry,
end
-- finally you can prove that if two orbits contain a common element
-- then they are equal
theorem orbit_eq_orbit_of_mem_inter (has : a ∈ orbit G s) (hat : a ∈ orbit G t) :
orbit G s = orbit G t :=
begin
sorry,
end
open setoid
-- This is very fiddly, I wouldn't worry too much about it, you've done
-- the maths part, the rest is plumbing. You'll have to look up the API
-- for `is_partition` yourself.
example : is_partition {𝒪 : set S | ∃ s, orbit G s = 𝒪} :=
begin
sorry
end
|
a86ed3177d1ad21ef73ca8f43ccfc3cdf9ba65f8
|
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
|
/hott/hit/pushout.hlean
|
66b1d263a298cbf1c668fdda4d8480308310439b
|
[
"Apache-2.0"
] |
permissive
|
jroesch/lean
|
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
|
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
|
refs/heads/master
| 1,586,090,835,348
| 1,455,142,203,000
| 1,455,142,277,000
| 51,536,958
| 1
| 0
| null | 1,455,215,811,000
| 1,455,215,811,000
| null |
UTF-8
|
Lean
| false
| false
| 8,621
|
hlean
|
/-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of the pushout
-/
import .quotient cubical.square types.sigma
open quotient eq sum equiv equiv.ops is_trunc
namespace pushout
section
parameters {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
local abbreviation A := BL + TR
inductive pushout_rel : A → A → Type :=
| Rmk : Π(x : TL), pushout_rel (inl (f x)) (inr (g x))
open pushout_rel
local abbreviation R := pushout_rel
definition pushout : Type := quotient R -- TODO: define this in root namespace
parameters {f g}
definition inl (x : BL) : pushout :=
class_of R (inl x)
definition inr (x : TR) : pushout :=
class_of R (inr x)
definition glue (x : TL) : inl (f x) = inr (g x) :=
eq_of_rel pushout_rel (Rmk f g x)
protected definition rec {P : pushout → Type} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(y : pushout) : P y :=
begin
induction y,
{ cases a,
apply Pinl,
apply Pinr},
{ cases H, apply Pglue}
end
protected definition rec_on [reducible] {P : pushout → Type} (y : pushout)
(Pinl : Π(x : BL), P (inl x)) (Pinr : Π(x : TR), P (inr x))
(Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x)) : P y :=
rec Pinl Pinr Pglue y
theorem rec_glue {P : pushout → Type} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(x : TL) : apdo (rec Pinl Pinr Pglue) (glue x) = Pglue x :=
!rec_eq_of_rel
protected definition elim {P : Type} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (y : pushout) : P :=
rec Pinl Pinr (λx, pathover_of_eq (Pglue x)) y
protected definition elim_on [reducible] {P : Type} (y : pushout) (Pinl : BL → P)
(Pinr : TR → P) (Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) : P :=
elim Pinl Pinr Pglue y
theorem elim_glue {P : Type} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (x : TL)
: ap (elim Pinl Pinr Pglue) (glue x) = Pglue x :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (glue x)),
rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑pushout.elim,rec_glue],
end
protected definition elim_type (Pinl : BL → Type) (Pinr : TR → Type)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (y : pushout) : Type :=
elim Pinl Pinr (λx, ua (Pglue x)) y
protected definition elim_type_on [reducible] (y : pushout) (Pinl : BL → Type)
(Pinr : TR → Type) (Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) : Type :=
elim_type Pinl Pinr Pglue y
theorem elim_type_glue (Pinl : BL → Type) (Pinr : TR → Type)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (x : TL)
: transport (elim_type Pinl Pinr Pglue) (glue x) = Pglue x :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_glue];apply cast_ua_fn
protected definition rec_hprop {P : pushout → Type} [H : Πx, is_hprop (P x)]
(Pinl : Π(x : BL), P (inl x)) (Pinr : Π(x : TR), P (inr x)) (y : pushout) :=
rec Pinl Pinr (λx, !is_hprop.elimo) y
protected definition elim_hprop {P : Type} [H : is_hprop P] (Pinl : BL → P) (Pinr : TR → P)
(y : pushout) : P :=
elim Pinl Pinr (λa, !is_hprop.elim) y
end
end pushout
attribute pushout.inl pushout.inr [constructor]
attribute pushout.rec pushout.elim [unfold 10] [recursor 10]
attribute pushout.elim_type [unfold 9]
attribute pushout.rec_on pushout.elim_on [unfold 7]
attribute pushout.elim_type_on [unfold 6]
open sigma
namespace pushout
variables {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
/- The non-dependent universal property -/
definition pushout_arrow_equiv (C : Type)
: (pushout f g → C) ≃ (Σ(i : BL → C) (j : TR → C), Πc, i (f c) = j (g c)) :=
begin
fapply equiv.MK,
{ intro f, exact ⟨λx, f (inl x), λx, f (inr x), λx, ap f (glue x)⟩},
{ intro v x, induction v with i w, induction w with j p, induction x,
exact (i a), exact (j a), exact (p x)},
{ intro v, induction v with i w, induction w with j p, esimp,
apply ap (λp, ⟨i, j, p⟩), apply eq_of_homotopy, intro x, apply elim_glue},
{ intro f, apply eq_of_homotopy, intro x, induction x: esimp,
apply eq_pathover, apply hdeg_square, esimp, apply elim_glue},
end
end pushout
open function sigma.ops
namespace pushout
/- The flattening lemma -/
section
universe variable u
parameters {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
(Pinl : BL → Type.{u}) (Pinr : TR → Type.{u})
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x))
include Pglue
local abbreviation A := BL + TR
local abbreviation R : A → A → Type := pushout_rel f g
local abbreviation P [unfold 5] := pushout.elim_type Pinl Pinr Pglue
local abbreviation F : sigma (Pinl ∘ f) → sigma Pinl :=
λz, ⟨ f z.1 , z.2 ⟩
local abbreviation G : sigma (Pinl ∘ f) → sigma Pinr :=
λz, ⟨ g z.1 , Pglue z.1 z.2 ⟩
local abbreviation Pglue' : Π ⦃a a' : A⦄,
R a a' → sum.rec Pinl Pinr a ≃ sum.rec Pinl Pinr a' :=
@pushout_rel.rec TL BL TR f g
(λ ⦃a a' ⦄ (r : R a a'),
(sum.rec Pinl Pinr a) ≃ (sum.rec Pinl Pinr a')) Pglue
protected definition flattening : sigma P ≃ pushout F G :=
begin
assert H : Πz, P z ≃ quotient.elim_type (sum.rec Pinl Pinr) Pglue' z,
{ intro z, apply equiv_of_eq,
assert H1 : pushout.elim_type Pinl Pinr Pglue
= quotient.elim_type (sum.rec Pinl Pinr) Pglue',
{ change
quotient.rec (sum.rec Pinl Pinr)
(λa a' r, pushout_rel.cases_on r (λx, pathover_of_eq (ua (Pglue x))))
= quotient.rec (sum.rec Pinl Pinr)
(λa a' r, pathover_of_eq (ua (pushout_rel.cases_on r Pglue))),
assert H2 : Π⦃a a'⦄ r : pushout_rel f g a a',
pushout_rel.cases_on r (λx, pathover_of_eq (ua (Pglue x)))
= pathover_of_eq (ua (pushout_rel.cases_on r Pglue))
:> sum.rec Pinl Pinr a =[eq_of_rel (pushout_rel f g) r]
sum.rec Pinl Pinr a',
{ intros a a' r, cases r, reflexivity },
rewrite (eq_of_homotopy3 H2) },
apply ap10 H1 },
apply equiv.trans (sigma_equiv_sigma_id H),
apply equiv.trans (quotient.flattening.flattening_lemma R (sum.rec Pinl Pinr) Pglue'),
fapply equiv.MK,
{ intro q, induction q with z z z' fr,
{ induction z with a p, induction a with x x,
{ exact inl ⟨x, p⟩ },
{ exact inr ⟨x, p⟩ } },
{ induction fr with a a' r p, induction r with x,
exact glue ⟨x, p⟩ } },
{ intro q, induction q with xp xp xp,
{ exact class_of _ ⟨sum.inl xp.1, xp.2⟩ },
{ exact class_of _ ⟨sum.inr xp.1, xp.2⟩ },
{ apply eq_of_rel, constructor } },
{ intro q, induction q with xp xp xp: induction xp with x p,
{ apply ap inl, reflexivity },
{ apply ap inr, reflexivity },
{ unfold F, unfold G, apply eq_pathover,
rewrite [ap_id,ap_compose' (quotient.elim _ _)],
krewrite elim_glue, krewrite elim_eq_of_rel, apply hrefl } },
{ intro q, induction q with z z z' fr,
{ induction z with a p, induction a with x x,
{ reflexivity },
{ reflexivity } },
{ induction fr with a a' r p, induction r with x,
esimp, apply eq_pathover,
rewrite [ap_id,ap_compose' (pushout.elim _ _ _)],
krewrite elim_eq_of_rel, krewrite elim_glue, apply hrefl } }
end
end
-- Commutativity of pushouts
section
variables {TL BL TR : Type} (f : TL → BL) (g : TL → TR)
protected definition transpose [constructor] : pushout f g → pushout g f :=
begin
intro x, induction x, apply inr a, apply inl a, apply !glue⁻¹
end
--TODO prove without krewrite?
protected definition transpose_involutive (x : pushout f g) :
pushout.transpose g f (pushout.transpose f g x) = x :=
begin
induction x, apply idp, apply idp,
apply eq_pathover, refine _ ⬝hp !ap_id⁻¹,
refine !(ap_compose (pushout.transpose _ _)) ⬝ph _, esimp[pushout.transpose],
krewrite [elim_glue, ap_inv, elim_glue, inv_inv], apply hrfl
end
protected definition symm : pushout f g ≃ pushout g f :=
begin
fapply equiv.MK, do 2 exact !pushout.transpose,
do 2 (intro x; apply pushout.transpose_involutive),
end
end
end pushout
|
d649a793f9c6db573d16eb8bfdecdc744efbffcf
|
bb31430994044506fa42fd667e2d556327e18dfe
|
/src/category_theory/monoidal/preadditive.lean
|
9fb5c2b68234f2a05ab48a4f367747572121fb13
|
[
"Apache-2.0"
] |
permissive
|
sgouezel/mathlib
|
0cb4e5335a2ba189fa7af96d83a377f83270e503
|
00638177efd1b2534fc5269363ebf42a7871df9a
|
refs/heads/master
| 1,674,527,483,042
| 1,673,665,568,000
| 1,673,665,568,000
| 119,598,202
| 0
| 0
| null | 1,517,348,647,000
| 1,517,348,646,000
| null |
UTF-8
|
Lean
| false
| false
| 9,666
|
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 category_theory.preadditive.additive_functor
import category_theory.monoidal.functor
/-!
# Preadditive monoidal categories
A monoidal category is `monoidal_preadditive` if it is preadditive and tensor product of morphisms
is linear in both factors.
-/
noncomputable theory
open_locale classical
namespace category_theory
open category_theory.limits
open category_theory.monoidal_category
variables (C : Type*) [category C] [preadditive C] [monoidal_category C]
/--
A category is `monoidal_preadditive` if tensoring is additive in both factors.
Note we don't `extend preadditive C` here, as `abelian C` already extends it,
and we'll need to have both typeclasses sometimes.
-/
class monoidal_preadditive : Prop :=
(tensor_zero' : ∀ {W X Y Z : C} (f : W ⟶ X), f ⊗ (0 : Y ⟶ Z) = 0 . obviously)
(zero_tensor' : ∀ {W X Y Z : C} (f : Y ⟶ Z), (0 : W ⟶ X) ⊗ f = 0 . obviously)
(tensor_add' : ∀ {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z), f ⊗ (g + h) = f ⊗ g + f ⊗ h . obviously)
(add_tensor' : ∀ {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z), (f + g) ⊗ h = f ⊗ h + g ⊗ h . obviously)
restate_axiom monoidal_preadditive.tensor_zero'
restate_axiom monoidal_preadditive.zero_tensor'
restate_axiom monoidal_preadditive.tensor_add'
restate_axiom monoidal_preadditive.add_tensor'
attribute [simp] monoidal_preadditive.tensor_zero monoidal_preadditive.zero_tensor
variables {C} [monoidal_preadditive C]
local attribute [simp] monoidal_preadditive.tensor_add monoidal_preadditive.add_tensor
instance tensor_left_additive (X : C) : (tensor_left X).additive := {}
instance tensor_right_additive (X : C) : (tensor_right X).additive := {}
instance tensoring_left_additive (X : C) : ((tensoring_left C).obj X).additive := {}
instance tensoring_right_additive (X : C) : ((tensoring_right C).obj X).additive := {}
/-- A faithful additive monoidal functor to a monoidal preadditive category
ensures that the domain is monoidal preadditive. -/
lemma monoidal_preadditive_of_faithful {D} [category D] [preadditive D] [monoidal_category D]
(F : monoidal_functor D C) [faithful F.to_functor] [F.to_functor.additive] :
monoidal_preadditive D :=
{ tensor_zero' := by { intros, apply F.to_functor.map_injective, simp [F.map_tensor], },
zero_tensor' := by { intros, apply F.to_functor.map_injective, simp [F.map_tensor], },
tensor_add' := begin
intros,
apply F.to_functor.map_injective,
simp only [F.map_tensor, F.to_functor.map_add, preadditive.comp_add, preadditive.add_comp,
monoidal_preadditive.tensor_add],
end,
add_tensor' := begin
intros,
apply F.to_functor.map_injective,
simp only [F.map_tensor, F.to_functor.map_add, preadditive.comp_add, preadditive.add_comp,
monoidal_preadditive.add_tensor],
end, }
open_locale big_operators
lemma tensor_sum {P Q R S : C} {J : Type*} (s : finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) :
f ⊗ ∑ j in s, g j = ∑ j in s, f ⊗ g j :=
begin
rw ←tensor_id_comp_id_tensor,
let tQ := (((tensoring_left C).obj Q).map_add_hom : (R ⟶ S) →+ _),
change _ ≫ tQ _ = _,
rw [tQ.map_sum, preadditive.comp_sum],
dsimp [tQ],
simp only [tensor_id_comp_id_tensor],
end
lemma sum_tensor {P Q R S : C} {J : Type*} (s : finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) :
(∑ j in s, g j) ⊗ f = ∑ j in s, g j ⊗ f :=
begin
rw ←tensor_id_comp_id_tensor,
let tQ := (((tensoring_right C).obj P).map_add_hom : (R ⟶ S) →+ _),
change tQ _ ≫ _ = _,
rw [tQ.map_sum, preadditive.sum_comp],
dsimp [tQ],
simp only [tensor_id_comp_id_tensor],
end
variables {C}
-- In a closed monoidal category, this would hold because
-- `tensor_left X` is a left adjoint and hence preserves all colimits.
-- In any case it is true in any preadditive category.
instance (X : C) : preserves_finite_biproducts (tensor_left X) :=
{ preserves := λ J _, by exactI
{ preserves := λ f,
{ preserves := λ b i, is_bilimit_of_total _ begin
dsimp,
simp only [←tensor_comp, category.comp_id, ←tensor_sum, ←tensor_id, is_bilimit.total i],
end } } }
instance (X : C) : preserves_finite_biproducts (tensor_right X) :=
{ preserves := λ J _, by exactI
{ preserves := λ f,
{ preserves := λ b i, is_bilimit_of_total _ begin
dsimp,
simp only [←tensor_comp, category.comp_id, ←sum_tensor, ←tensor_id, is_bilimit.total i],
end } } }
variables [has_finite_biproducts C]
/-- The isomorphism showing how tensor product on the left distributes over direct sums. -/
def left_distributor {J : Type} [fintype J] (X : C) (f : J → C) :
X ⊗ (⨁ f) ≅ ⨁ (λ j, X ⊗ f j) :=
(tensor_left X).map_biproduct f
@[simp]
lemma left_distributor_hom {J : Type} [fintype J] (X : C) (f : J → C) :
(left_distributor X f).hom = ∑ j : J, (𝟙 X ⊗ biproduct.π f j) ≫ biproduct.ι _ j :=
begin
ext, dsimp [tensor_left, left_distributor],
simp [preadditive.sum_comp, biproduct.ι_π, comp_dite],
end
@[simp]
lemma left_distributor_inv {J : Type} [fintype J] (X : C) (f : J → C) :
(left_distributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (𝟙 X ⊗ biproduct.ι f j) :=
begin
ext, dsimp [tensor_left, left_distributor],
simp [preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp],
end
lemma left_distributor_assoc {J : Type} [fintype J] (X Y : C) (f : J → C) :
(as_iso (𝟙 X) ⊗ left_distributor Y f) ≪≫ left_distributor X _ =
(α_ X Y (⨁ f)).symm ≪≫ left_distributor (X ⊗ Y) f ≪≫ biproduct.map_iso (λ j, α_ X Y _) :=
begin
ext,
simp only [category.comp_id, category.assoc, eq_to_hom_refl,
iso.trans_hom, iso.symm_hom, as_iso_hom, comp_zero, comp_dite,
preadditive.sum_comp, preadditive.comp_sum,
tensor_sum, id_tensor_comp, tensor_iso_hom, left_distributor_hom,
biproduct.map_iso_hom, biproduct.ι_map, biproduct.ι_π,
finset.sum_dite_irrel, finset.sum_dite_eq', finset.sum_const_zero],
simp only [←id_tensor_comp, biproduct.ι_π],
simp only [id_tensor_comp, tensor_dite, comp_dite],
simp only [category.comp_id, comp_zero, monoidal_preadditive.tensor_zero, eq_to_hom_refl,
tensor_id, if_true, dif_ctx_congr, finset.sum_congr, finset.mem_univ, finset.sum_dite_eq'],
simp only [←tensor_id, associator_naturality, iso.inv_hom_id_assoc],
end
/-- The isomorphism showing how tensor product on the right distributes over direct sums. -/
def right_distributor {J : Type} [fintype J] (X : C) (f : J → C) :
(⨁ f) ⊗ X ≅ ⨁ (λ j, f j ⊗ X) :=
(tensor_right X).map_biproduct f
@[simp]
lemma right_distributor_hom {J : Type} [fintype J] (X : C) (f : J → C) :
(right_distributor X f).hom = ∑ j : J, (biproduct.π f j ⊗ 𝟙 X) ≫ biproduct.ι _ j :=
begin
ext, dsimp [tensor_right, right_distributor],
simp [preadditive.sum_comp, biproduct.ι_π, comp_dite],
end
@[simp]
lemma right_distributor_inv {J : Type} [fintype J] (X : C) (f : J → C) :
(right_distributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (biproduct.ι f j ⊗ 𝟙 X) :=
begin
ext, dsimp [tensor_right, right_distributor],
simp [preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp],
end
lemma right_distributor_assoc {J : Type} [fintype J] (X Y : C) (f : J → C) :
(right_distributor X f ⊗ as_iso (𝟙 Y)) ≪≫ right_distributor Y _ =
α_ (⨁ f) X Y ≪≫ right_distributor (X ⊗ Y) f ≪≫ biproduct.map_iso (λ j, (α_ _ X Y).symm) :=
begin
ext,
simp only [category.comp_id, category.assoc, eq_to_hom_refl, iso.symm_hom,
iso.trans_hom, as_iso_hom, comp_zero, comp_dite, preadditive.sum_comp, preadditive.comp_sum,
sum_tensor, comp_tensor_id, tensor_iso_hom, right_distributor_hom,
biproduct.map_iso_hom, biproduct.ι_map, biproduct.ι_π,
finset.sum_dite_irrel, finset.sum_dite_eq', finset.sum_const_zero, finset.mem_univ, if_true],
simp only [←comp_tensor_id, biproduct.ι_π, dite_tensor, comp_dite],
simp only [category.comp_id, comp_tensor_id, eq_to_hom_refl, tensor_id, comp_zero,
monoidal_preadditive.zero_tensor,
if_true, dif_ctx_congr, finset.mem_univ, finset.sum_congr, finset.sum_dite_eq'],
simp only [←tensor_id, associator_inv_naturality, iso.hom_inv_id_assoc]
end
lemma left_distributor_right_distributor_assoc
{J : Type*} [fintype J] (X Y : C) (f : J → C) :
(left_distributor X f ⊗ as_iso (𝟙 Y)) ≪≫ right_distributor Y _ =
α_ X (⨁ f) Y ≪≫ (as_iso (𝟙 X) ⊗ right_distributor Y _) ≪≫ left_distributor X _ ≪≫
biproduct.map_iso (λ j, (α_ _ _ _).symm) :=
begin
ext,
simp only [category.comp_id, category.assoc, eq_to_hom_refl, iso.symm_hom,
iso.trans_hom, as_iso_hom, comp_zero, comp_dite, preadditive.sum_comp, preadditive.comp_sum,
sum_tensor, tensor_sum, comp_tensor_id, tensor_iso_hom,
left_distributor_hom, right_distributor_hom,
biproduct.map_iso_hom, biproduct.ι_map, biproduct.ι_π,
finset.sum_dite_irrel, finset.sum_dite_eq', finset.sum_const_zero, finset.mem_univ, if_true],
simp only [←comp_tensor_id, ←id_tensor_comp_assoc, category.assoc, biproduct.ι_π,
comp_dite, dite_comp, tensor_dite, dite_tensor],
simp only [category.comp_id, category.id_comp, category.assoc, id_tensor_comp,
comp_zero, zero_comp, monoidal_preadditive.tensor_zero, monoidal_preadditive.zero_tensor,
comp_tensor_id, eq_to_hom_refl, tensor_id,
if_true, dif_ctx_congr, finset.sum_congr, finset.mem_univ, finset.sum_dite_eq'],
simp only [associator_inv_naturality, iso.hom_inv_id_assoc]
end
end category_theory
|
d698a01fee1088a077be17564a5cd68852fd8bf2
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/interactive/goTo2.lean
|
ca29f578e90f27acdd438d174b93c1cffc36f071
|
[
"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
| 366
|
lean
|
--
macro_rules | `($x + $y) => `(binop% HAdd.hAdd $x $y)
macro_rules | `($x ^ $y) => `(binop% HPow.hPow $x $y)
mutual
def h (x : Nat) : Int:=
match x with
| 0 => 1
--v textDocument/definition
| x+1 => r x + r x + h x ^ 2
--^ textDocument/definition
--^ textDocument/definition
def r (x : Nat) := x + 1
end
|
fb0f0c29b0093626ae6da4b78fdaabf52bc57849
|
592ee40978ac7604005a4e0d35bbc4b467389241
|
/Library/generated/mathscheme-lean/InvolutiveFixedPoint.lean
|
34192a6d76315a9656596c44cff9c426461d0d8e
|
[] |
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
| 7,093
|
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 InvolutiveFixedPoint
structure InvolutiveFixedPoint (A : Type) : Type :=
(prim : (A → A))
(one : A)
(fixes_prim_one : (prim one) = one)
(involutive_prim : (∀ {x : A} , (prim (prim x)) = x))
open InvolutiveFixedPoint
structure Sig (AS : Type) : Type :=
(primS : (AS → AS))
(oneS : AS)
structure Product (A : Type) : Type :=
(primP : ((Prod A A) → (Prod A A)))
(oneP : (Prod A A))
(fixes_prim_1P : (primP oneP) = oneP)
(involutive_primP : (∀ {xP : (Prod A A)} , (primP (primP xP)) = xP))
structure Hom {A1 : Type} {A2 : Type} (In1 : (InvolutiveFixedPoint A1)) (In2 : (InvolutiveFixedPoint A2)) : Type :=
(hom : (A1 → A2))
(pres_prim : (∀ {x1 : A1} , (hom ((prim In1) x1)) = ((prim In2) (hom x1))))
(pres_one : (hom (one In1)) = (one In2))
structure RelInterp {A1 : Type} {A2 : Type} (In1 : (InvolutiveFixedPoint A1)) (In2 : (InvolutiveFixedPoint A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_prim : (∀ {x1 : A1} {y1 : A2} , ((interp x1 y1) → (interp ((prim In1) x1) ((prim In2) y1)))))
(interp_one : (interp (one In1) (one In2)))
inductive InvolutiveFixedPointTerm : Type
| primL : (InvolutiveFixedPointTerm → InvolutiveFixedPointTerm)
| oneL : InvolutiveFixedPointTerm
open InvolutiveFixedPointTerm
inductive ClInvolutiveFixedPointTerm (A : Type) : Type
| sing : (A → ClInvolutiveFixedPointTerm)
| primCl : (ClInvolutiveFixedPointTerm → ClInvolutiveFixedPointTerm)
| oneCl : ClInvolutiveFixedPointTerm
open ClInvolutiveFixedPointTerm
inductive OpInvolutiveFixedPointTerm (n : ℕ) : Type
| v : ((fin n) → OpInvolutiveFixedPointTerm)
| primOL : (OpInvolutiveFixedPointTerm → OpInvolutiveFixedPointTerm)
| oneOL : OpInvolutiveFixedPointTerm
open OpInvolutiveFixedPointTerm
inductive OpInvolutiveFixedPointTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpInvolutiveFixedPointTerm2)
| sing2 : (A → OpInvolutiveFixedPointTerm2)
| primOL2 : (OpInvolutiveFixedPointTerm2 → OpInvolutiveFixedPointTerm2)
| oneOL2 : OpInvolutiveFixedPointTerm2
open OpInvolutiveFixedPointTerm2
def simplifyCl {A : Type} : ((ClInvolutiveFixedPointTerm A) → (ClInvolutiveFixedPointTerm A))
| (primCl oneCl) := oneCl
| (primCl (primCl x)) := x
| (primCl x1) := (primCl (simplifyCl x1))
| oneCl := oneCl
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpInvolutiveFixedPointTerm n) → (OpInvolutiveFixedPointTerm n))
| (primOL oneOL) := oneOL
| (primOL (primOL x)) := x
| (primOL x1) := (primOL (simplifyOpB x1))
| oneOL := oneOL
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpInvolutiveFixedPointTerm2 n A) → (OpInvolutiveFixedPointTerm2 n A))
| (primOL2 oneOL2) := oneOL2
| (primOL2 (primOL2 x)) := x
| (primOL2 x1) := (primOL2 (simplifyOp x1))
| oneOL2 := oneOL2
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((InvolutiveFixedPoint A) → (InvolutiveFixedPointTerm → A))
| In (primL x1) := ((prim In) (evalB In x1))
| In oneL := (one In)
def evalCl {A : Type} : ((InvolutiveFixedPoint A) → ((ClInvolutiveFixedPointTerm A) → A))
| In (sing x1) := x1
| In (primCl x1) := ((prim In) (evalCl In x1))
| In oneCl := (one In)
def evalOpB {A : Type} {n : ℕ} : ((InvolutiveFixedPoint A) → ((vector A n) → ((OpInvolutiveFixedPointTerm n) → A)))
| In vars (v x1) := (nth vars x1)
| In vars (primOL x1) := ((prim In) (evalOpB In vars x1))
| In vars oneOL := (one In)
def evalOp {A : Type} {n : ℕ} : ((InvolutiveFixedPoint A) → ((vector A n) → ((OpInvolutiveFixedPointTerm2 n A) → A)))
| In vars (v2 x1) := (nth vars x1)
| In vars (sing2 x1) := x1
| In vars (primOL2 x1) := ((prim In) (evalOp In vars x1))
| In vars oneOL2 := (one In)
def inductionB {P : (InvolutiveFixedPointTerm → Type)} : ((∀ (x1 : InvolutiveFixedPointTerm) , ((P x1) → (P (primL x1)))) → ((P oneL) → (∀ (x : InvolutiveFixedPointTerm) , (P x))))
| ppriml p1l (primL x1) := (ppriml _ (inductionB ppriml p1l x1))
| ppriml p1l oneL := p1l
def inductionCl {A : Type} {P : ((ClInvolutiveFixedPointTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 : (ClInvolutiveFixedPointTerm A)) , ((P x1) → (P (primCl x1)))) → ((P oneCl) → (∀ (x : (ClInvolutiveFixedPointTerm A)) , (P x)))))
| psing pprimcl p1cl (sing x1) := (psing x1)
| psing pprimcl p1cl (primCl x1) := (pprimcl _ (inductionCl psing pprimcl p1cl x1))
| psing pprimcl p1cl oneCl := p1cl
def inductionOpB {n : ℕ} {P : ((OpInvolutiveFixedPointTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 : (OpInvolutiveFixedPointTerm n)) , ((P x1) → (P (primOL x1)))) → ((P oneOL) → (∀ (x : (OpInvolutiveFixedPointTerm n)) , (P x)))))
| pv pprimol p1ol (v x1) := (pv x1)
| pv pprimol p1ol (primOL x1) := (pprimol _ (inductionOpB pv pprimol p1ol x1))
| pv pprimol p1ol oneOL := p1ol
def inductionOp {n : ℕ} {A : Type} {P : ((OpInvolutiveFixedPointTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 : (OpInvolutiveFixedPointTerm2 n A)) , ((P x1) → (P (primOL2 x1)))) → ((P oneOL2) → (∀ (x : (OpInvolutiveFixedPointTerm2 n A)) , (P x))))))
| pv2 psing2 pprimol2 p1ol2 (v2 x1) := (pv2 x1)
| pv2 psing2 pprimol2 p1ol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 pprimol2 p1ol2 (primOL2 x1) := (pprimol2 _ (inductionOp pv2 psing2 pprimol2 p1ol2 x1))
| pv2 psing2 pprimol2 p1ol2 oneOL2 := p1ol2
def stageB : (InvolutiveFixedPointTerm → (Staged InvolutiveFixedPointTerm))
| (primL x1) := (stage1 primL (codeLift1 primL) (stageB x1))
| oneL := (Now oneL)
def stageCl {A : Type} : ((ClInvolutiveFixedPointTerm A) → (Staged (ClInvolutiveFixedPointTerm A)))
| (sing x1) := (Now (sing x1))
| (primCl x1) := (stage1 primCl (codeLift1 primCl) (stageCl x1))
| oneCl := (Now oneCl)
def stageOpB {n : ℕ} : ((OpInvolutiveFixedPointTerm n) → (Staged (OpInvolutiveFixedPointTerm n)))
| (v x1) := (const (code (v x1)))
| (primOL x1) := (stage1 primOL (codeLift1 primOL) (stageOpB x1))
| oneOL := (Now oneOL)
def stageOp {n : ℕ} {A : Type} : ((OpInvolutiveFixedPointTerm2 n A) → (Staged (OpInvolutiveFixedPointTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (primOL2 x1) := (stage1 primOL2 (codeLift1 primOL2) (stageOp x1))
| oneOL2 := (Now oneOL2)
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(primT : ((Repr A) → (Repr A)))
(oneT : (Repr A))
end InvolutiveFixedPoint
|
92660714edf87c83dd2af5b04366f213b324f5c2
|
34c1747a946aa0941114ffca77a3b7c1e4cfb686
|
/src/sheaves/sheaf_on_standard_basis.lean
|
a6709692832c9ebb2063fdee0f61e5ae0a518723
|
[] |
no_license
|
martrik/lean-scheme
|
2b9edd63550c4579a451f793ab289af9fc79a16d
|
033dc47192ba4c61e4e771701f5e29f8007e6332
|
refs/heads/master
| 1,588,866,287,405
| 1,554,922,682,000
| 1,554,922,682,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,084
|
lean
|
/-
Sheaf (of types) on standard basis.
https://stacks.math.columbia.edu/tag/009L
-/
import topology.basic
import to_mathlib.opens
import sheaves.covering.covering_on_standard_basis
import sheaves.presheaf
import sheaves.stalk_on_basis
import sheaves.presheaf_of_rings_on_basis
universe u
open topological_space
namespace sheaf_on_standard_basis
variables {α : Type u} [topological_space α]
variables {B : set (opens α)} {HB : opens.is_basis B}
variables (Bstd : opens.univ ∈ B ∧ ∀ {U V}, U ∈ B → V ∈ B → U ∩ V ∈ B)
include Bstd
section properties
-- Compactness definition.
def basis_is_compact : Prop :=
∀ {U} (BU : U ∈ B) (OC : covering_standard_basis B U),
∃ (γ : Type u) (Hfin : fintype γ) (f : γ → OC.γ), (⋃ (OC.Uis ∘ f)) = U
end properties
section sheaf_condition
-- Restriction map from U to U ∩ V.
def res_to_inter_left (F : presheaf_on_basis α HB) {U V} (BU : U ∈ B) (BV : V ∈ B)
: (F BU) → (F (Bstd.2 BU BV)) :=
F.res BU (Bstd.2 BU BV) (set.inter_subset_left U V)
@[simp] lemma res_to_inter_left'
(F : presheaf_on_basis α HB) {U V} (BU : U ∈ B) (BV : V ∈ B)
: sheaf_on_standard_basis.res_to_inter_left Bstd F BU BV =
F.res BU (Bstd.2 BU BV) (set.inter_subset_left U V)
:= rfl
-- Restriction map from V to U ∩ V.
def res_to_inter_right (F : presheaf_on_basis α HB) {U V} (BU : U ∈ B) (BV : V ∈ B)
: (F BV) → (F (Bstd.2 BU BV)) :=
F.res BV (Bstd.2 BU BV) (set.inter_subset_right U V)
@[simp] lemma res_to_inter_right'
(F : presheaf_on_basis α HB) {U V} (BU : U ∈ B) (BV : V ∈ B)
: sheaf_on_standard_basis.res_to_inter_right Bstd F BU BV =
F.res BV (Bstd.2 BU BV) (set.inter_subset_right U V)
:= rfl
-- Sheaf condition.
def locality
(F : presheaf_on_basis α HB) {U} (BU : U ∈ B) (OC : covering_standard_basis B U) :=
∀ (s t : F BU),
(∀ i, F.res BU (OC.BUis i) (subset_covering i) s =
F.res BU (OC.BUis i) (subset_covering i) t) →
s = t
def gluing
(F : presheaf_on_basis α HB) {U} (BU : U ∈ B) (OC : covering_standard_basis B U) :=
∀ (s : Π i, F (OC.BUis i)),
(∀ j k, sheaf_on_standard_basis.res_to_inter_left Bstd F (OC.BUis j) (OC.BUis k) (s j) =
sheaf_on_standard_basis.res_to_inter_right Bstd F (OC.BUis j) (OC.BUis k) (s k)) →
∃ S, ∀ i, F.res BU (OC.BUis i) (subset_covering i) S = s i
def is_sheaf_on_standard_basis (F : presheaf_on_basis α HB) :=
∀ {U} (BU : U ∈ B) (OC : covering_standard_basis B U),
locality Bstd F BU OC ∧ gluing Bstd F BU OC
end sheaf_condition
section cofinal_system
-- Suffices to prove the sheaf condition for finite covers.
def is_sheaf_on_standard_basis_cofinal_system (F : presheaf_on_basis α HB) : Prop :=
∀ {U} (BU : U ∈ B) (OC : covering_standard_basis B U) (Hfin : fintype OC.γ),
locality Bstd F BU OC ∧ gluing Bstd F BU OC
theorem cofinal_systems_coverings_standard_case
(F : presheaf_on_basis α HB)
(Hcompact : basis_is_compact Bstd)
: is_sheaf_on_standard_basis_cofinal_system Bstd F → is_sheaf_on_standard_basis Bstd F :=
begin
intros Hcofinal,
have Hcofinal' := @Hcofinal,
intros U BU OC,
rcases (Hcompact BU OC) with ⟨γ, Hfinγ, fγ, Hcov⟩,
have BUisfin : ∀ i, ((OC.Uis ∘ fγ) i) ∈ B := λ i, OC.BUis (fγ i),
let OCfin : covering_standard_basis B U
:= {γ := γ, Uis := OC.Uis ∘ fγ, Hcov := Hcov, BUis := BUisfin},
replace Hcofinal := Hcofinal BU OCfin Hfinγ,
rcases Hcofinal with ⟨Hloc, Hglue⟩,
split,
-- Locality.
{ intros s t Hres,
apply Hloc,
intros i,
apply Hres, },
-- Gluing.
{ intros s Hinter,
have Hinterfin
: ∀ (j k),
sheaf_on_standard_basis.res_to_inter_left Bstd F _ _ (s (fγ j)) =
sheaf_on_standard_basis.res_to_inter_right Bstd F _ _ (s (fγ k)) :=
λ j k, Hinter (fγ j) (fγ k),
have Hglobal := Hglue (λ i, s (fγ i)) Hinterfin,
rcases Hglobal with ⟨S, HS⟩,
existsi S,
intros i,
let Vjs := λ j : γ, (OCfin.Uis j) ∩ (OC.Uis i),
have BVjs : ∀ j, (Vjs j) ∈ B := λ j, Bstd.2 (OCfin.BUis j) (OC.BUis i),
have HVjscov : (⋃ Vjs) = OC.Uis i,
apply opens.ext,
apply set.ext,
intros x,
split,
{ intros HxUVjs,
rcases HxUVjs with ⟨Vj, HVj, HxVj⟩,
rcases HVj with ⟨VjO, ⟨⟨j, HVjO⟩, HVjeq⟩⟩,
rw [←HVjeq, ←HVjO] at HxVj,
exact HxVj.2, },
{ intros HxUi,
have HxU : x ∈ U := OC.Hcov ▸ (opens_supr_mem OC.Uis i x HxUi),
rw ←Hcov at HxU,
rcases HxU with ⟨Uj, HUj, HxUj⟩,
rcases HUj with ⟨UjO, ⟨⟨j, HUjO⟩, HUjeq⟩⟩,
use [(Vjs j).1, ⟨(Vjs j), ⟨⟨j, rfl⟩, rfl⟩⟩],
rw [←HUjeq, ←HUjO] at HxUj,
exact ⟨HxUj, HxUi⟩, },
have HVjUVjs : ∀ j, Vjs j ⊆ OC.Uis i
:= HVjscov ▸ λ j x Hx, opens_supr_mem Vjs j x Hx,
have HVjU : ∀ j, Vjs j ⊆ U
:= λ j, set.subset.trans (HVjUVjs j) (subset_covering i),
let Ui : opens α := OC.Uis i,
let BUi : Ui ∈ B := OC.BUis i,
let OCfin' : covering_standard_basis B Ui
:= {γ := γ, Uis := Vjs, Hcov := HVjscov, BUis := BVjs},
have Hloc' := (@Hcofinal' Ui BUi OCfin' Hfinγ).1,
have Hglue' := (@Hcofinal' Ui BUi OCfin' Hfinγ).2,
have Hglue'' := Hglue' (λ j, F.res BU (BVjs j) (HVjU j) S),
have Hres' : ∀ (j k),
sheaf_on_standard_basis.res_to_inter_left Bstd
F (BVjs j) (BVjs k) (F.res BU (BVjs j) (HVjU j) S) =
sheaf_on_standard_basis.res_to_inter_right Bstd
F (BVjs j) (BVjs k) (F.res BU (BVjs k) (HVjU k) S),
intros j k,
simp,
rw ←F.Hcomp',
rw ←F.Hcomp',
rcases (Hglue'' Hres') with ⟨S', HS'⟩,
refine @eq.trans _ _ S' _ _ _,
{ apply Hloc',
intro j,
rw HS',
rw ←F.Hcomp',
refl, },
{ apply eq.symm,
apply Hloc',
intro j,
simp at Hinter,
erw ←Hinter,
rw HS',
have Hsfj : s (fγ j) = _ := (HS j).symm,
rw Hsfj,
rw ←F.Hcomp',
refl, }, },
end
end cofinal_system
end sheaf_on_standard_basis
|
339132dcca6823f6435ebe447ccaa12eb63a0966
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/algebra/hom/equiv.lean
|
4fcb7c96a05d41c571b11974efa5dfaa23c98d1b
|
[
"Apache-2.0"
] |
permissive
|
ramonfmir/mathlib
|
c5dc8b33155473fab97c38bd3aa6723dc289beaa
|
14c52e990c17f5a00c0cc9e09847af16fabbed25
|
refs/heads/master
| 1,661,979,343,526
| 1,660,830,384,000
| 1,660,830,384,000
| 182,072,989
| 0
| 0
| null | 1,555,585,876,000
| 1,555,585,876,000
| null |
UTF-8
|
Lean
| false
| false
| 29,815
|
lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
-/
import algebra.group.type_tags
import algebra.group_with_zero.basic
import data.pi.algebra
/-!
# Multiplicative and additive equivs
In this file we define two extensions of `equiv` called `add_equiv` and `mul_equiv`, which are
datatypes representing isomorphisms of `add_monoid`s/`add_group`s and `monoid`s/`group`s.
## Notations
* ``infix ` ≃* `:25 := mul_equiv``
* ``infix ` ≃+ `:25 := add_equiv``
The extended equivs all have coercions to functions, and the coercions are the canonical
notation when treating the isomorphisms as maps.
## Implementation notes
The fields for `mul_equiv`, `add_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as
these are deprecated.
## Tags
equiv, mul_equiv, add_equiv
-/
variables {F α β A B M N P Q G H : Type*}
/-- Makes a multiplicative inverse from a bijection which preserves multiplication. -/
@[to_additive "Makes an additive inverse from a bijection which preserves addition."]
def mul_hom.inverse [has_mul M] [has_mul N] (f : M →ₙ* N) (g : N → M)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : N →ₙ* M :=
{ to_fun := g,
map_mul' := λ x y,
calc g (x * y) = g (f (g x) * f (g y)) : by rw [h₂ x, h₂ y]
... = g (f (g x * g y)) : by rw f.map_mul
... = g x * g y : h₁ _, }
/-- The inverse of a bijective `monoid_hom` is a `monoid_hom`. -/
@[to_additive "The inverse of a bijective `add_monoid_hom` is an `add_monoid_hom`.", simps]
def monoid_hom.inverse {A B : Type*} [monoid A] [monoid B] (f : A →* B) (g : B → A)
(h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) :
B →* A :=
{ to_fun := g,
map_one' := by rw [← f.map_one, h₁],
.. (f : A →ₙ* B).inverse g h₁ h₂, }
set_option old_structure_cmd true
/-- add_equiv α β is the type of an equiv α ≃ β which preserves addition. -/
@[ancestor equiv add_hom]
structure add_equiv (A B : Type*) [has_add A] [has_add B] extends A ≃ B, add_hom A B
/-- `add_equiv_class F A B` states that `F` is a type of addition-preserving morphisms.
You should extend this class when you extend `add_equiv`. -/
class add_equiv_class (F A B : Type*) [has_add A] [has_add B]
extends equiv_like F A B :=
(map_add : ∀ (f : F) a b, f (a + b) = f a + f b)
/-- The `equiv` underlying an `add_equiv`. -/
add_decl_doc add_equiv.to_equiv
/-- The `add_hom` underlying a `add_equiv`. -/
add_decl_doc add_equiv.to_add_hom
/-- `mul_equiv α β` is the type of an equiv `α ≃ β` which preserves multiplication. -/
@[ancestor equiv mul_hom, to_additive]
structure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M ≃ N, M →ₙ* N
/-- The `equiv` underlying a `mul_equiv`. -/
add_decl_doc mul_equiv.to_equiv
/-- The `mul_hom` underlying a `mul_equiv`. -/
add_decl_doc mul_equiv.to_mul_hom
/-- `mul_equiv_class F A B` states that `F` is a type of multiplication-preserving morphisms.
You should extend this class when you extend `mul_equiv`. -/
@[to_additive]
class mul_equiv_class (F A B : Type*) [has_mul A] [has_mul B]
extends equiv_like F A B :=
(map_mul : ∀ (f : F) a b, f (a * b) = f a * f b)
infix ` ≃* `:25 := mul_equiv
infix ` ≃+ `:25 := add_equiv
namespace mul_equiv_class
variables (F)
@[priority 100, -- See note [lower instance priority]
to_additive]
instance [has_mul M] [has_mul N] [h : mul_equiv_class F M N] : mul_hom_class F M N :=
{ coe := (coe : F → M → N),
coe_injective' := @fun_like.coe_injective F _ _ _,
.. h }
@[priority 100, -- See note [lower instance priority]
to_additive]
instance [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N] :
monoid_hom_class F M N :=
{ coe := (coe : F → M → N),
map_one := λ e,
calc e 1 = e 1 * 1 : (mul_one _).symm
... = e 1 * e (inv e (1 : N) : M) : congr_arg _ (right_inv e 1).symm
... = e (inv e (1 : N)) : by rw [← map_mul, one_mul]
... = 1 : right_inv e 1,
.. mul_equiv_class.mul_hom_class F }
@[priority 100] -- See note [lower instance priority]
instance to_monoid_with_zero_hom_class {α β : Type*} [mul_zero_one_class α]
[mul_zero_one_class β] [mul_equiv_class F α β] : monoid_with_zero_hom_class F α β :=
{ map_zero := λ e, calc e 0 = e 0 * e (equiv_like.inv e 0) : by rw [←map_mul, zero_mul]
... = 0 : by { convert mul_zero _, exact equiv_like.right_inv e _ }
..mul_equiv_class.monoid_hom_class _ }
variables {F}
@[simp, to_additive]
lemma map_eq_one_iff {M N} [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N]
(h : F) {x : M} : h x = 1 ↔ x = 1 :=
map_eq_one_iff h (equiv_like.injective h)
@[to_additive]
lemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class N] [mul_equiv_class F M N]
(h : F) {x : M} :
h x ≠ 1 ↔ x ≠ 1 :=
map_ne_one_iff h (equiv_like.injective h)
end mul_equiv_class
@[to_additive] instance [has_mul α] [has_mul β] [mul_equiv_class F α β] : has_coe_t F (α ≃* β) :=
⟨λ f, { to_fun := f, inv_fun := equiv_like.inv f, left_inv := equiv_like.left_inv f,
right_inv := equiv_like.right_inv f, map_mul' := map_mul f }⟩
namespace mul_equiv
@[to_additive]
instance [has_mul M] [has_mul N] : has_coe_to_fun (M ≃* N) (λ _, M → N) := ⟨mul_equiv.to_fun⟩
@[to_additive]
instance [has_mul M] [has_mul N] : mul_equiv_class (M ≃* N) M N :=
{ coe := to_fun, inv := inv_fun, left_inv := left_inv, right_inv := right_inv,
coe_injective' := λ f g h₁ h₂, by { cases f, cases g, congr' },
map_mul := map_mul' }
variables [has_mul M] [has_mul N] [has_mul P] [has_mul Q]
@[simp, to_additive]
lemma to_equiv_eq_coe (f : M ≃* N) : f.to_equiv = f := rfl
@[simp, to_additive]
lemma to_fun_eq_coe {f : M ≃* N} : f.to_fun = f := rfl
@[simp, to_additive]
lemma coe_to_equiv {f : M ≃* N} : ⇑(f : M ≃ N) = f := rfl
@[simp, to_additive]
lemma coe_to_mul_hom {f : M ≃* N} : ⇑f.to_mul_hom = f := rfl
/-- A multiplicative isomorphism preserves multiplication. -/
@[to_additive "An additive isomorphism preserves addition."]
protected lemma map_mul (f : M ≃* N) : ∀ x y, f (x * y) = f x * f y := map_mul f
/-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/
@[to_additive "Makes an additive isomorphism from a bijection which preserves addition."]
def mk' (f : M ≃ N) (h : ∀ x y, f (x * y) = f x * f y) : M ≃* N :=
⟨f.1, f.2, f.3, f.4, h⟩
@[to_additive]
protected lemma bijective (e : M ≃* N) : function.bijective e := equiv_like.bijective e
@[to_additive]
protected lemma injective (e : M ≃* N) : function.injective e := equiv_like.injective e
@[to_additive]
protected lemma surjective (e : M ≃* N) : function.surjective e := equiv_like.surjective e
/-- The identity map is a multiplicative isomorphism. -/
@[refl, to_additive "The identity map is an additive isomorphism."]
def refl (M : Type*) [has_mul M] : M ≃* M :=
{ map_mul' := λ _ _, rfl,
..equiv.refl _}
@[to_additive]
instance : inhabited (M ≃* M) := ⟨refl M⟩
/-- The inverse of an isomorphism is an isomorphism. -/
@[symm, to_additive "The inverse of an isomorphism is an isomorphism."]
def symm (h : M ≃* N) : N ≃* M :=
{ map_mul' := (h.to_mul_hom.inverse h.to_equiv.symm h.left_inv h.right_inv).map_mul,
.. h.to_equiv.symm}
@[simp, to_additive]
lemma inv_fun_eq_symm {f : M ≃* N} : f.inv_fun = f.symm := rfl
/-- See Note [custom simps projection] -/
-- we don't hyperlink the note in the additive version, since that breaks syntax highlighting
-- in the whole file.
@[to_additive "See Note custom simps projection"]
def simps.symm_apply (e : M ≃* N) : N → M := e.symm
initialize_simps_projections add_equiv (to_fun → apply, inv_fun → symm_apply)
initialize_simps_projections mul_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp, to_additive]
theorem to_equiv_symm (f : M ≃* N) : f.symm.to_equiv = f.to_equiv.symm := rfl
@[simp, to_additive]
theorem coe_mk (f : M → N) (g h₁ h₂ h₃) : ⇑(mul_equiv.mk f g h₁ h₂ h₃) = f := rfl
@[simp, to_additive]
lemma to_equiv_mk (f : M → N) (g : N → M) (h₁ h₂ h₃) :
(mk f g h₁ h₂ h₃).to_equiv = ⟨f, g, h₁, h₂⟩ := rfl
@[simp, to_additive]
lemma symm_symm : ∀ (f : M ≃* N), f.symm.symm = f
| ⟨f, g, h₁, h₂, h₃⟩ := rfl
@[to_additive]
lemma symm_bijective : function.bijective (symm : (M ≃* N) → (N ≃* M)) :=
equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩
@[simp, to_additive]
theorem symm_mk (f : M → N) (g h₁ h₂ h₃) :
(mul_equiv.mk f g h₁ h₂ h₃).symm =
{ to_fun := g, inv_fun := f, ..(mul_equiv.mk f g h₁ h₂ h₃).symm} := rfl
@[simp, to_additive]
theorem refl_symm : (refl M).symm = refl M := rfl
/-- Transitivity of multiplication-preserving isomorphisms -/
@[trans, to_additive "Transitivity of addition-preserving isomorphisms"]
def trans (h1 : M ≃* N) (h2 : N ≃* P) : (M ≃* P) :=
{ map_mul' := λ x y, show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y),
by rw [h1.map_mul, h2.map_mul],
..h1.to_equiv.trans h2.to_equiv }
/-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/
@[simp, to_additive "`e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`."]
lemma apply_symm_apply (e : M ≃* N) (y : N) : e (e.symm y) = y :=
e.to_equiv.apply_symm_apply y
/-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/
@[simp, to_additive "`e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`."]
lemma symm_apply_apply (e : M ≃* N) (x : M) : e.symm (e x) = x :=
e.to_equiv.symm_apply_apply x
@[simp, to_additive]
theorem symm_comp_self (e : M ≃* N) : e.symm ∘ e = id := funext e.symm_apply_apply
@[simp, to_additive]
theorem self_comp_symm (e : M ≃* N) : e ∘ e.symm = id := funext e.apply_symm_apply
@[simp, to_additive]
theorem coe_refl : ⇑(refl M) = id := rfl
@[simp, to_additive]
theorem refl_apply (m : M) : refl M m = m := rfl
@[simp, to_additive]
theorem coe_trans (e₁ : M ≃* N) (e₂ : N ≃* P) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl
@[simp, to_additive]
theorem trans_apply (e₁ : M ≃* N) (e₂ : N ≃* P) (m : M) : e₁.trans e₂ m = e₂ (e₁ m) := rfl
@[simp, to_additive] theorem symm_trans_apply (e₁ : M ≃* N) (e₂ : N ≃* P) (p : P) :
(e₁.trans e₂).symm p = e₁.symm (e₂.symm p) := rfl
@[simp, to_additive] theorem apply_eq_iff_eq (e : M ≃* N) {x y : M} : e x = e y ↔ x = y :=
e.injective.eq_iff
@[to_additive]
lemma apply_eq_iff_symm_apply (e : M ≃* N) {x : M} {y : N} : e x = y ↔ x = e.symm y :=
e.to_equiv.apply_eq_iff_eq_symm_apply
@[to_additive]
lemma symm_apply_eq (e : M ≃* N) {x y} : e.symm x = y ↔ x = e y :=
e.to_equiv.symm_apply_eq
@[to_additive]
lemma eq_symm_apply (e : M ≃* N) {x y} : y = e.symm x ↔ e y = x :=
e.to_equiv.eq_symm_apply
@[to_additive] lemma eq_comp_symm {α : Type*} (e : M ≃* N) (f : N → α) (g : M → α) :
f = g ∘ e.symm ↔ f ∘ e = g := e.to_equiv.eq_comp_symm f g
@[to_additive] lemma comp_symm_eq {α : Type*} (e : M ≃* N) (f : N → α) (g : M → α) :
g ∘ e.symm = f ↔ g = f ∘ e := e.to_equiv.comp_symm_eq f g
@[to_additive] lemma eq_symm_comp {α : Type*} (e : M ≃* N) (f : α → M) (g : α → N) :
f = e.symm ∘ g ↔ e ∘ f = g := e.to_equiv.eq_symm_comp f g
@[to_additive] lemma symm_comp_eq {α : Type*} (e : M ≃* N) (f : α → M) (g : α → N) :
e.symm ∘ g = f ↔ g = e ∘ f := e.to_equiv.symm_comp_eq f g
/-- Two multiplicative isomorphisms agree if they are defined by the
same underlying function. -/
@[ext, to_additive
"Two additive isomorphisms agree if they are defined by the same underlying function."]
lemma ext {f g : mul_equiv M N} (h : ∀ x, f x = g x) : f = g := fun_like.ext f g h
@[to_additive] lemma ext_iff {f g : mul_equiv M N} : f = g ↔ ∀ x, f x = g x := fun_like.ext_iff
@[simp, to_additive] lemma mk_coe (e : M ≃* N) (e' h₁ h₂ h₃) :
(⟨e, e', h₁, h₂, h₃⟩ : M ≃* N) = e := ext $ λ _, rfl
@[simp, to_additive] lemma mk_coe' (e : M ≃* N) (f h₁ h₂ h₃) :
(mul_equiv.mk f ⇑e h₁ h₂ h₃ : N ≃* M) = e.symm :=
symm_bijective.injective $ ext $ λ x, rfl
@[to_additive] protected lemma congr_arg {f : mul_equiv M N} {x x' : M} : x = x' → f x = f x' :=
fun_like.congr_arg f
@[to_additive] protected lemma congr_fun {f g : mul_equiv M N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- The `mul_equiv` between two monoids with a unique element. -/
@[to_additive "The `add_equiv` between two add_monoids with a unique element."]
def mul_equiv_of_unique {M N}
[unique M] [unique N] [has_mul M] [has_mul N] : M ≃* N :=
{ map_mul' := λ _ _, subsingleton.elim _ _,
..equiv.equiv_of_unique M N }
/-- There is a unique monoid homomorphism between two monoids with a unique element. -/
@[to_additive
"There is a unique additive monoid homomorphism between two additive monoids with
a unique element."]
instance {M N} [unique M] [unique N] [has_mul M] [has_mul N] : unique (M ≃* N) :=
{ default := mul_equiv_of_unique ,
uniq := λ _, ext $ λ x, subsingleton.elim _ _}
/-!
## Monoids
-/
/-- A multiplicative isomorphism of monoids sends `1` to `1` (and is hence a monoid isomorphism). -/
@[to_additive "An additive isomorphism of additive monoids sends `0` to `0`
(and is hence an additive monoid isomorphism)."]
protected lemma map_one {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) : h 1 = 1 :=
map_one h
@[to_additive]
protected lemma map_eq_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) {x : M} :
h x = 1 ↔ x = 1 :=
mul_equiv_class.map_eq_one_iff h
@[to_additive]
lemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) {x : M} :
h x ≠ 1 ↔ x ≠ 1 :=
mul_equiv_class.map_ne_one_iff h
/-- A bijective `semigroup` homomorphism is an isomorphism -/
@[to_additive "A bijective `add_semigroup` homomorphism is an isomorphism", simps apply]
noncomputable def of_bijective {M N F} [has_mul M] [has_mul N] [mul_hom_class F M N] (f : F)
(hf : function.bijective f) : M ≃* N :=
{ map_mul' := map_mul f,
..equiv.of_bijective f hf }
@[simp]
lemma of_bijective_apply_symm_apply {M N} [mul_one_class M] [mul_one_class N] {n : N} (f : M →* N)
(hf : function.bijective f) : f ((equiv.of_bijective f hf).symm n) = n :=
(mul_equiv.of_bijective f hf).apply_symm_apply n
/--
Extract the forward direction of a multiplicative equivalence
as a multiplication-preserving function.
-/
@[to_additive "Extract the forward direction of an additive equivalence
as an addition-preserving function."]
def to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) : (M →* N) :=
{ map_one' := h.map_one, .. h }
@[simp, to_additive]
lemma coe_to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (e : M ≃* N) :
⇑e.to_monoid_hom = e :=
rfl
@[to_additive] lemma to_monoid_hom_injective {M N} [mul_one_class M] [mul_one_class N] :
function.injective (to_monoid_hom : (M ≃* N) → M →* N) :=
λ f g h, mul_equiv.ext (monoid_hom.ext_iff.1 h)
/--
A multiplicative analogue of `equiv.arrow_congr`,
where the equivalence between the targets is multiplicative.
-/
@[to_additive "An additive analogue of `equiv.arrow_congr`,
where the equivalence between the targets is additive.", simps apply]
def arrow_congr {M N P Q : Type*} [has_mul P] [has_mul Q]
(f : M ≃ N) (g : P ≃* Q) : (M → P) ≃* (N → Q) :=
{ to_fun := λ h n, g (h (f.symm n)),
inv_fun := λ k m, g.symm (k (f m)),
left_inv := λ h, by { ext, simp, },
right_inv := λ k, by { ext, simp, },
map_mul' := λ h k, by { ext, simp, }, }
/--
A multiplicative analogue of `equiv.arrow_congr`,
for multiplicative maps from a monoid to a commutative monoid.
-/
@[to_additive "An additive analogue of `equiv.arrow_congr`,
for additive maps from an additive monoid to a commutative additive monoid.", simps apply]
def monoid_hom_congr {M N P Q} [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q]
(f : M ≃* N) (g : P ≃* Q) : (M →* P) ≃* (N →* Q) :=
{ to_fun := λ h,
g.to_monoid_hom.comp (h.comp f.symm.to_monoid_hom),
inv_fun := λ k,
g.symm.to_monoid_hom.comp (k.comp f.to_monoid_hom),
left_inv := λ h, by { ext, simp, },
right_inv := λ k, by { ext, simp, },
map_mul' := λ h k, by { ext, simp, }, }
/-- A family of multiplicative equivalences `Π j, (Ms j ≃* Ns j)` generates a
multiplicative equivalence between `Π j, Ms j` and `Π j, Ns j`.
This is the `mul_equiv` version of `equiv.Pi_congr_right`, and the dependent version of
`mul_equiv.arrow_congr`.
-/
@[to_additive add_equiv.Pi_congr_right "A family of additive equivalences `Π j, (Ms j ≃+ Ns j)`
generates an additive equivalence between `Π j, Ms j` and `Π j, Ns j`.
This is the `add_equiv` version of `equiv.Pi_congr_right`, and the dependent version of
`add_equiv.arrow_congr`.", simps apply]
def Pi_congr_right {η : Type*}
{Ms Ns : η → Type*} [Π j, has_mul (Ms j)] [Π j, has_mul (Ns j)]
(es : ∀ j, Ms j ≃* Ns j) : (Π j, Ms j) ≃* (Π j, Ns j) :=
{ to_fun := λ x j, es j (x j),
inv_fun := λ x j, (es j).symm (x j),
map_mul' := λ x y, funext $ λ j, (es j).map_mul (x j) (y j),
.. equiv.Pi_congr_right (λ j, (es j).to_equiv) }
@[simp]
lemma Pi_congr_right_refl {η : Type*} {Ms : η → Type*} [Π j, has_mul (Ms j)] :
Pi_congr_right (λ j, mul_equiv.refl (Ms j)) = mul_equiv.refl _ := rfl
@[simp]
lemma Pi_congr_right_symm {η : Type*}
{Ms Ns : η → Type*} [Π j, has_mul (Ms j)] [Π j, has_mul (Ns j)]
(es : ∀ j, Ms j ≃* Ns j) : (Pi_congr_right es).symm = (Pi_congr_right $ λ i, (es i).symm) := rfl
@[simp]
lemma Pi_congr_right_trans {η : Type*}
{Ms Ns Ps : η → Type*} [Π j, has_mul (Ms j)] [Π j, has_mul (Ns j)]
[Π j, has_mul (Ps j)]
(es : ∀ j, Ms j ≃* Ns j) (fs : ∀ j, Ns j ≃* Ps j) :
(Pi_congr_right es).trans (Pi_congr_right fs) = (Pi_congr_right $ λ i, (es i).trans (fs i)) := rfl
/-- A family indexed by a nonempty subsingleton type is equivalent to the element at the single
index. -/
@[to_additive add_equiv.Pi_subsingleton "A family indexed by a nonempty subsingleton type is
equivalent to the element at the single index.", simps]
def Pi_subsingleton
{ι : Type*} (M : ι → Type*) [Π j, has_mul (M j)] [subsingleton ι] (i : ι) :
(Π j, M j) ≃* M i :=
{ map_mul' := λ f1 f2, pi.mul_apply _ _ _, ..equiv.Pi_subsingleton M i }
/-!
# Groups
-/
/-- A multiplicative equivalence of groups preserves inversion. -/
@[to_additive "An additive equivalence of additive groups preserves negation."]
protected lemma map_inv [group G] [division_monoid H] (h : G ≃* H) (x : G) : h x⁻¹ = (h x)⁻¹ :=
map_inv h x
/-- A multiplicative equivalence of groups preserves division. -/
@[to_additive "An additive equivalence of additive groups preserves subtractions."]
protected lemma map_div [group G] [division_monoid H] (h : G ≃* H) (x y : G) :
h (x / y) = h x / h y :=
map_div h x y
end mul_equiv
/-- Given a pair of monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`,
returns an multiplicative equivalence with `to_fun = f` and `inv_fun = g`. This constructor is
useful if the underlying type(s) have specialized `ext` lemmas for monoid homomorphisms. -/
@[to_additive /-"Given a pair of additive monoid homomorphisms `f`, `g` such that `g.comp f = id`
and `f.comp g = id`, returns an additive equivalence with `to_fun = f` and `inv_fun = g`. This
constructor is useful if the underlying type(s) have specialized `ext` lemmas for additive
monoid homomorphisms."-/, simps {fully_applied := ff}]
def monoid_hom.to_mul_equiv [mul_one_class M] [mul_one_class N] (f : M →* N) (g : N →* M)
(h₁ : g.comp f = monoid_hom.id _) (h₂ : f.comp g = monoid_hom.id _) :
M ≃* N :=
{ to_fun := f,
inv_fun := g,
left_inv := monoid_hom.congr_fun h₁,
right_inv := monoid_hom.congr_fun h₂,
map_mul' := f.map_mul }
/-- A group is isomorphic to its group of units. -/
@[to_additive "An additive group is isomorphic to its group of additive units"]
def to_units [group G] : G ≃* Gˣ :=
{ to_fun := λ x, ⟨x, x⁻¹, mul_inv_self _, inv_mul_self _⟩,
inv_fun := coe,
left_inv := λ x, rfl,
right_inv := λ u, units.ext rfl,
map_mul' := λ x y, units.ext rfl }
@[simp, to_additive] lemma coe_to_units [group G] (g : G) :
(to_units g : G) = g := rfl
@[to_additive]
protected lemma group.is_unit {G} [group G] (x : G) : is_unit x := (to_units x).is_unit
namespace units
variables [monoid M] [monoid N] [monoid P]
/-- A multiplicative equivalence of monoids defines a multiplicative equivalence
of their groups of units. -/
def map_equiv (h : M ≃* N) : Mˣ ≃* Nˣ :=
{ inv_fun := map h.symm.to_monoid_hom,
left_inv := λ u, ext $ h.left_inv u,
right_inv := λ u, ext $ h.right_inv u,
.. map h.to_monoid_hom }
/-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive "Left addition of an additive unit is a permutation of the underlying type.",
simps apply {fully_applied := ff}]
def mul_left (u : Mˣ) : equiv.perm M :=
{ to_fun := λx, u * x,
inv_fun := λx, ↑u⁻¹ * x,
left_inv := u.inv_mul_cancel_left,
right_inv := u.mul_inv_cancel_left }
@[simp, to_additive]
lemma mul_left_symm (u : Mˣ) : u.mul_left.symm = u⁻¹.mul_left :=
equiv.ext $ λ x, rfl
@[to_additive]
lemma mul_left_bijective (a : Mˣ) : function.bijective ((*) a : M → M) :=
(mul_left a).bijective
/-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive "Right addition of an additive unit is a permutation of the underlying type.",
simps apply {fully_applied := ff}]
def mul_right (u : Mˣ) : equiv.perm M :=
{ to_fun := λx, x * u,
inv_fun := λx, x * ↑u⁻¹,
left_inv := λ x, mul_inv_cancel_right x u,
right_inv := λ x, inv_mul_cancel_right x u }
@[simp, to_additive]
lemma mul_right_symm (u : Mˣ) : u.mul_right.symm = u⁻¹.mul_right :=
equiv.ext $ λ x, rfl
@[to_additive]
lemma mul_right_bijective (a : Mˣ) : function.bijective ((* a) : M → M) :=
(mul_right a).bijective
end units
namespace equiv
section has_involutive_neg
variables (G) [has_involutive_inv G]
/-- Inversion on a `group` or `group_with_zero` is a permutation of the underlying type. -/
@[to_additive "Negation on an `add_group` is a permutation of the underlying type.",
simps apply {fully_applied := ff}]
protected def inv : perm G := inv_involutive.to_perm _
variable {G}
@[simp, to_additive]
lemma inv_symm : (equiv.inv G).symm = equiv.inv G := rfl
end has_involutive_neg
section group
variables [group G]
/-- Left multiplication in a `group` is a permutation of the underlying type. -/
@[to_additive "Left addition in an `add_group` is a permutation of the underlying type."]
protected def mul_left (a : G) : perm G := (to_units a).mul_left
@[simp, to_additive]
lemma coe_mul_left (a : G) : ⇑(equiv.mul_left a) = (*) a := rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[simp, nolint simp_nf,
to_additive "Extra simp lemma that `dsimp` can use. `simp` will never use this."]
lemma mul_left_symm_apply (a : G) : ((equiv.mul_left a).symm : G → G) = (*) a⁻¹ := rfl
@[simp, to_additive]
lemma mul_left_symm (a : G) : (equiv.mul_left a).symm = equiv.mul_left a⁻¹ :=
ext $ λ x, rfl
@[to_additive]
lemma _root_.group.mul_left_bijective (a : G) : function.bijective ((*) a) :=
(equiv.mul_left a).bijective
/-- Right multiplication in a `group` is a permutation of the underlying type. -/
@[to_additive "Right addition in an `add_group` is a permutation of the underlying type."]
protected def mul_right (a : G) : perm G := (to_units a).mul_right
@[simp, to_additive]
lemma coe_mul_right (a : G) : ⇑(equiv.mul_right a) = λ x, x * a := rfl
@[simp, to_additive]
lemma mul_right_symm (a : G) : (equiv.mul_right a).symm = equiv.mul_right a⁻¹ :=
ext $ λ x, rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[simp, nolint simp_nf,
to_additive "Extra simp lemma that `dsimp` can use. `simp` will never use this."]
lemma mul_right_symm_apply (a : G) : ((equiv.mul_right a).symm : G → G) = λ x, x * a⁻¹ := rfl
@[to_additive]
lemma _root_.group.mul_right_bijective (a : G) : function.bijective (* a) :=
(equiv.mul_right a).bijective
/-- A version of `equiv.mul_left a b⁻¹` that is defeq to `a / b`. -/
@[to_additive /-" A version of `equiv.add_left a (-b)` that is defeq to `a - b`. "-/, simps]
protected def div_left (a : G) : G ≃ G :=
{ to_fun := λ b, a / b,
inv_fun := λ b, b⁻¹ * a,
left_inv := λ b, by simp [div_eq_mul_inv],
right_inv := λ b, by simp [div_eq_mul_inv] }
@[to_additive]
lemma div_left_eq_inv_trans_mul_left (a : G) :
equiv.div_left a = (equiv.inv G).trans (equiv.mul_left a) :=
ext $ λ _, div_eq_mul_inv _ _
/-- A version of `equiv.mul_right a⁻¹ b` that is defeq to `b / a`. -/
@[to_additive /-" A version of `equiv.add_right (-a) b` that is defeq to `b - a`. "-/, simps]
protected def div_right (a : G) : G ≃ G :=
{ to_fun := λ b, b / a,
inv_fun := λ b, b * a,
left_inv := λ b, by simp [div_eq_mul_inv],
right_inv := λ b, by simp [div_eq_mul_inv] }
@[to_additive]
lemma div_right_eq_mul_right_inv (a : G) : equiv.div_right a = equiv.mul_right a⁻¹ :=
ext $ λ _, div_eq_mul_inv _ _
end group
section group_with_zero
variables [group_with_zero G]
/-- Left multiplication by a nonzero element in a `group_with_zero` is a permutation of the
underlying type. -/
@[simps {fully_applied := ff}]
protected def mul_left₀ (a : G) (ha : a ≠ 0) : perm G :=
(units.mk0 a ha).mul_left
lemma _root_.mul_left_bijective₀ (a : G) (ha : a ≠ 0) :
function.bijective ((*) a : G → G) :=
(equiv.mul_left₀ a ha).bijective
/-- Right multiplication by a nonzero element in a `group_with_zero` is a permutation of the
underlying type. -/
@[simps {fully_applied := ff}]
protected def mul_right₀ (a : G) (ha : a ≠ 0) : perm G :=
(units.mk0 a ha).mul_right
lemma _root_.mul_right_bijective₀ (a : G) (ha : a ≠ 0) :
function.bijective ((* a) : G → G) :=
(equiv.mul_right₀ a ha).bijective
end group_with_zero
end equiv
/-- In a `division_comm_monoid`, `equiv.inv` is a `mul_equiv`. There is a variant of this
`mul_equiv.inv' G : G ≃* Gᵐᵒᵖ` for the non-commutative case. -/
@[to_additive "When the `add_group` is commutative, `equiv.neg` is an `add_equiv`.", simps apply]
def mul_equiv.inv (G : Type*) [division_comm_monoid G] : G ≃* G :=
{ to_fun := has_inv.inv,
inv_fun := has_inv.inv,
map_mul' := mul_inv,
..equiv.inv G }
@[simp] lemma mul_equiv.inv_symm (G : Type*) [division_comm_monoid G] :
(mul_equiv.inv G).symm = mul_equiv.inv G := rfl
section type_tags
/-- Reinterpret `G ≃+ H` as `multiplicative G ≃* multiplicative H`. -/
def add_equiv.to_multiplicative [add_zero_class G] [add_zero_class H] :
(G ≃+ H) ≃ (multiplicative G ≃* multiplicative H) :=
{ to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative,
f.symm.to_add_monoid_hom.to_multiplicative, f.3, f.4, f.5⟩,
inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩,
left_inv := λ x, by { ext, refl, },
right_inv := λ x, by { ext, refl, }, }
/-- Reinterpret `G ≃* H` as `additive G ≃+ additive H`. -/
def mul_equiv.to_additive [mul_one_class G] [mul_one_class H] :
(G ≃* H) ≃ (additive G ≃+ additive H) :=
{ to_fun := λ f, ⟨f.to_monoid_hom.to_additive, f.symm.to_monoid_hom.to_additive, f.3, f.4, f.5⟩,
inv_fun := λ f, ⟨f.to_add_monoid_hom, f.symm.to_add_monoid_hom, f.3, f.4, f.5⟩,
left_inv := λ x, by { ext, refl, },
right_inv := λ x, by { ext, refl, }, }
/-- Reinterpret `additive G ≃+ H` as `G ≃* multiplicative H`. -/
def add_equiv.to_multiplicative' [mul_one_class G] [add_zero_class H] :
(additive G ≃+ H) ≃ (G ≃* multiplicative H) :=
{ to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative',
f.symm.to_add_monoid_hom.to_multiplicative'', f.3, f.4, f.5⟩,
inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩,
left_inv := λ x, by { ext, refl, },
right_inv := λ x, by { ext, refl, }, }
/-- Reinterpret `G ≃* multiplicative H` as `additive G ≃+ H` as. -/
def mul_equiv.to_additive' [mul_one_class G] [add_zero_class H] :
(G ≃* multiplicative H) ≃ (additive G ≃+ H) :=
add_equiv.to_multiplicative'.symm
/-- Reinterpret `G ≃+ additive H` as `multiplicative G ≃* H`. -/
def add_equiv.to_multiplicative'' [add_zero_class G] [mul_one_class H] :
(G ≃+ additive H) ≃ (multiplicative G ≃* H) :=
{ to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative'',
f.symm.to_add_monoid_hom.to_multiplicative', f.3, f.4, f.5⟩,
inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩,
left_inv := λ x, by { ext, refl, },
right_inv := λ x, by { ext, refl, }, }
/-- Reinterpret `multiplicative G ≃* H` as `G ≃+ additive H` as. -/
def mul_equiv.to_additive'' [add_zero_class G] [mul_one_class H] :
(multiplicative G ≃* H) ≃ (G ≃+ additive H) :=
add_equiv.to_multiplicative''.symm
end type_tags
section
variables (G) (H)
/-- `additive (multiplicative G)` is just `G`. -/
def add_equiv.additive_multiplicative [add_zero_class G] : additive (multiplicative G) ≃+ G :=
mul_equiv.to_additive'' (mul_equiv.refl (multiplicative G))
/-- `multiplicative (additive H)` is just `H`. -/
def mul_equiv.multiplicative_additive [mul_one_class H] : multiplicative (additive H) ≃* H :=
add_equiv.to_multiplicative'' (add_equiv.refl (additive H))
end
|
a4b271ed6449cd7d0295e0a945980ce5903b213a
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/pathsimp.lean
|
112db1ab6e383e130317db68c1c1d9352a8d26c0
|
[
"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
| 1,276
|
lean
|
universes u v
inductive path {α : Type u} (a : α) : α → Type u
| refl : path a
namespace path
attribute [refl] path.refl
@[symm] def symm {α : Type u} {a b : α} (h : path a b) : path b a :=
by induction h; refl
@[trans] def trans {α : Type u} {a b c : α} (h : path a b) (h' : path b c) : path a c :=
by induction h; induction h'; refl
@[congr] def congr {α : Type u} {β : Type v} (f f' : α → β) (a a' : α)
(hf : path f f') (ha : path a a') : path (f a) (f' a') :=
by induction hf; induction ha; refl
def mp {α β : Type u} (h : path α β) : α → β :=
by intro; induction h; assumption
open tactic expr
meta def path_simp_target (sls : simp_lemmas) := do
tgt ← target,
(tgt', prf, lms) ← simplify sls [] tgt {lift_eq:=ff} `path,
prf ← mk_mapp `path.symm [none, tgt, tgt', prf],
mk_mapp `path.mp [tgt', tgt, prf] >>= apply
def nat_zero_add (n : ℕ) : path (0 + n) n := sorry
def foo (n : ℕ) : path (0 + (0 + n)) n := by do
let sls := simp_lemmas.mk,
-- path.congr can be used as a congruence lemma
sls ← sls.add_congr ``path.congr,
-- nat_zero_add can be used as a simplification lemma even though it has
-- associated equational lemmas
sls ← sls.add_simp ``nat_zero_add ff,
trace sls,
path_simp_target sls, reflexivity
end path
|
8ab4d65ca7af2dda16b746728a9be15f524150b4
|
cc62cd292c1acc80a10b1c645915b70d2cdee661
|
/src/category_theory/graphs/default.lean
|
467aa53d298098d45cf6259127bda695deee4ed2
|
[] |
no_license
|
RitaAhmadi/lean-category-theory
|
4afb881c4b387ee2c8ce706c454fbf9db8897a29
|
a27b4ae5eac978e9188d2e867c3d11d9a5b87a9e
|
refs/heads/master
| 1,651,786,183,402
| 1,565,604,314,000
| 1,565,604,314,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,940
|
lean
|
-- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan and Scott Morrison
import category_theory.tactics.obviously
import tidy.auto_cast
namespace category_theory.graphs
universes v₁ v₂ u₁ u₂
class graph (vertices : Type u₁) :=
(edges : vertices → vertices → Sort v₁)
variable {C : Type u₁}
variables {W X Y Z : C}
variable [𝒞 : graph.{v₁} C]
def edges : C → C → Sort v₁ := @graph.edges.{v₁} C 𝒞
structure graph_hom (G : Type u₁) [graph.{v₁} G] (H : Type u₂) [graph.{v₂} H] :=
(onVertices : G → H)
(onEdges : ∀ {X Y : G}, edges X Y → edges (onVertices X) (onVertices Y))
section
variables {G : Type u₁} [𝒢 : graph.{v₁} G] {H : Type u₂} [ℋ : graph.{v₂} H]
include 𝒢 ℋ
@[extensionality] lemma graph_hom_pointwise_equal
{p q : graph_hom G H}
(vertexWitness : ∀ X : G, p.onVertices X = q.onVertices X)
(edgeWitness : ∀ X Y : G, ∀ f : edges X Y, ⟬ p.onEdges f ⟭ = q.onEdges f) : p = q :=
begin
induction p with p_onVertices p_onEdges,
induction q with q_onVertices q_onEdges,
have h_vertices : p_onVertices = q_onVertices, exact funext vertexWitness,
subst h_vertices,
have h_edges : @p_onEdges = @q_onEdges,
apply funext, intro X, apply funext, intro Y, apply funext, intro f,
exact edgeWitness X Y f,
subst h_edges
end
end
variables {G : Type u₁} [𝒢 : graph.{v₁} G]
include 𝒢
inductive path : G → G → Type (max u₁ v₁)
| nil : Π (h : G), path h h
| cons : Π {h s t : G} (e : edges h s) (l : path s t), path h t
def path.length : Π {s t : G}, path s t → ℕ
| _ _ (path.nil _) := 0
| _ _ (@path.cons _ _ _ _ _ e l) := path.length l
notation a :: b := path.cons a b
notation `p[` l:(foldr `, ` (h t, path.cons h t) path.nil _ `]`) := l
inductive path_of_paths : G → G → Type (max u₁ v₁)
| nil : Π (h : G), path_of_paths h h
| cons : Π {h s t : G} (e : path h s) (l : path_of_paths s t), path_of_paths h t
notation a :: b := path_of_paths.cons a b
notation `pp[` l:(foldr `, ` (h t, path_of_paths.cons h t) path_of_paths.nil _ `]`) := l
-- The pattern matching trick used here was explained by Jeremy Avigad at https://groups.google.com/d/msg/lean-user/JqaI12tdk3g/F9MZDxkFDAAJ
def concatenate_paths : Π {x y z : G}, path x y → path y z → path x z
| ._ ._ _ (path.nil _) q := q
| ._ ._ _ (@path.cons ._ _ _ _ _ e p') q := path.cons e (concatenate_paths p' q)
@[simp] lemma concatenate_paths' {x' x y z : G} (e : edges x' x) (p : path x y) (q : path y z) : concatenate_paths (e :: p) q = e :: (concatenate_paths p q) := rfl
def concatenate_path_of_paths : Π {x y : G}, path_of_paths x y → path x y
| ._ ._ (path_of_paths.nil X) := path.nil X
| ._ ._ (@path_of_paths.cons ._ _ _ _ _ e p') := concatenate_paths e (concatenate_path_of_paths p')
end category_theory.graphs
|
5397e9cdb2be28c45344ccf70d41f04463eadf9e
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/inductionLetIssue.lean
|
40a2b4300ba5181bf2ae884e023b86a075e0542b
|
[
"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
| 956
|
lean
|
inductive P : Option Nat → Prop
| none : P .none
| somePos : x > 0 → P (some x)
def Option.get : (a : Option α) → a.isSome → α
| some a, _ => a
theorem aux (x? : Option Nat) (h₁ : P x?) (h₂ : x?.isSome) : x?.get h₂ > 0 := by
cases h₁ with
| none => contradiction
| somePos h => exact h
def f (x? : Option Nat) (hp : P x?) : { r? : Option Nat // P r? } :=
if h₁ : x?.isSome then
let x := x?.get h₁
have : x > 0 := by
cases h₂ : x with
| zero => have := aux x? hp h₁; simp at h₂; simp [h₂] at this
| succ x' => simp_arith
⟨some x, .somePos this⟩
else
⟨none, .none⟩
def f₁ (x : Nat) : Nat :=
let y := x + 1
by cases y with
| zero => exact 2
| succ y' => exact 1
example : f₁ x = 1 := rfl
noncomputable def f₂ (x : Nat) : Nat :=
let y := x + 1
by induction y with
| zero => exact 2
| succ y' => exact 1
example : f₂ x = 1 := rfl
|
12564085b57bac349834024743925b013ef0e4a4
|
717dd237d6a1fdd246152ec47f261c5244f9eba6
|
/lean4/division.lean
|
382d2208b65a495f3c1567337343419f6113b3b4
|
[] |
no_license
|
lacker/kata
|
32866813a6097218878f0ce327040d65a0aeb145
|
96b1d63e395c8cf02dc6abbbb5253f4cfe5fded6
|
refs/heads/master
| 1,692,275,692,563
| 1,691,955,719,000
| 1,691,955,719,000
| 87,217,280
| 19
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,917
|
lean
|
open Classical
inductive Cnat where
| zero : Cnat
| succ : Cnat → Cnat
def add (a b : Cnat) : Cnat :=
match a with
| Cnat.zero => b
| Cnat.succ c => Cnat.succ (add c b)
theorem add_zero_right (x : Cnat) : add x Cnat.zero = x := by
induction x
case zero => rfl
case succ x' ih => simp [ih, add]
theorem add_suc_right (x y : Cnat) : add x (Cnat.succ y) = Cnat.succ (add x y) := by
induction x
case zero => rfl
case succ x' ih => simp [ih, add]
theorem add_comm (x y : Cnat) : add x y = add y x := by
induction x
case zero => simp [add, add_zero_right]
case succ x' ih => simp [ih, add, add_suc_right]
theorem add_assoc (x y z : Cnat) : add (add x y) z = add x (add y z) := by
induction x
case zero => simp [add]
case succ x' ih => simp [ih, add]
def mul (a b : Cnat) : Cnat :=
match a with
| Cnat.zero => Cnat.zero
| Cnat.succ c => add b (mul c b)
theorem mul_zero_right (x : Cnat) : mul x Cnat.zero = Cnat.zero := by
induction x
case zero => rfl
case succ x' ih => simp [ih, mul, add]
theorem mul_suc_right (x y : Cnat) : mul x (Cnat.succ y) = add x (mul x y) := by
induction x
case zero => simp [mul, add]
case succ x' ih => simp [mul, add, ih, <-add_assoc, add_comm]
theorem mul_comm (x y : Cnat) : mul x y = mul y x := by
induction x
case zero => simp [mul, mul_zero_right]
case succ x' ih => simp [mul, mul_suc_right, ih]
theorem distrib (x y z : Cnat) : mul x (add y z) = add (mul x y) (mul x z) := by
induction x
case zero => simp [mul, add]
case succ x' ih => rw [mul, mul, mul, add_assoc, ih, add_assoc,
<- add_assoc (mul x' y), <- add_assoc z, add_comm z]
theorem mul_assoc (x y z : Cnat) : mul (mul x y) z = mul x (mul y z) := by
induction x
case zero => simp [mul]
case succ x' ih => simp [mul, mul_comm, distrib, <- ih]
def lt (a b : Cnat) : Prop :=
match b with
| Cnat.zero => False
| Cnat.succ d => match a with
| Cnat.zero => True
| Cnat.succ c => lt c d
theorem lt_not_ref (x : Cnat) : ¬ lt x x := by
induction x
case zero => simp [lt]
case succ x' ih => simp [lt, ih]
theorem lt_not_symm (a b : Cnat) : lt a b → ¬ lt b a := by
induction a generalizing b
case zero => simp [lt]
case succ a' ih => match b with
| Cnat.zero => simp [lt]
| Cnat.succ b' => simp [lt]; apply ih
theorem lt_trans (a b c : Cnat) : lt a b ∧ lt b c → lt a c := by
induction c generalizing a b
case zero => simp [lt]
case succ c' ih => match a with
| Cnat.zero => simp [lt]
| Cnat.succ a' => match b with
| Cnat.zero => simp [lt]
| Cnat.succ b' => simp [lt]; apply ih
theorem lt_to_sub (a b : Cnat) : lt a b → ∃ c, b = add a c := by
induction a generalizing b
case zero => simp [add]; intro; apply Exists.intro b; rfl
case succ a ih =>
simp [add]
match b with
| Cnat.zero => simp [lt]
| Cnat.succ b' => simp [lt]; apply ih
theorem lt_add_suc (a b : Cnat) : lt a (add a b.succ) := by
induction a generalizing b
case zero => simp [add, lt]
case succ a ih => simp [add, lt]; apply ih
theorem add_cancels_left (a b c : Cnat) : add a b = add a c → b = c := by
induction a generalizing b
case zero => simp [add]; intro h; exact h
case succ a ih => simp [add]; apply ih
theorem add_cancels_right (a b c : Cnat) : add a c = add b c → a = b := by
induction c
case zero => simp [add_zero_right]; intro h; exact h
case succ c ih => simp [add_suc_right]; exact ih
theorem lt_suc (a b : Cnat) (h1: lt a b) : a.succ = b ∨ lt a.succ b := by
let ⟨c, h2⟩ := lt_to_sub a b h1
match c with
| Cnat.zero => {
simp [add_zero_right] at h2; rw [h2] at h1; simp [lt_not_ref] at h1
}
| Cnat.succ c' => match c' with
| Cnat.zero => {
simp [add_suc_right, add_zero_right] at h2
simp [h2]
}
| Cnat.succ c'' => {
apply Or.inr
rw [add_suc_right] at h2
rw [h2]
simp [lt]
exact lt_add_suc _ _
}
theorem division_theorem (m n : Cnat) (h1: lt Cnat.zero n) :
∃ q r, lt r n ∧ m = add (mul q n) r := by
induction m
case zero => {
apply Exists.intro Cnat.zero
apply Exists.intro Cnat.zero
simp [h1, mul, add]
}
case succ m ih => {
let ⟨q, r, h2, h3⟩ := ih
apply Or.elim (em (r.succ = n))
case left => {
intro h4
apply Exists.intro q.succ
apply Exists.intro Cnat.zero
simp [h1, add_zero_right, h3, mul]
rw [<- h4, add, add_comm]
}
case right => {
intro h5
apply Exists.intro q
apply Exists.intro r.succ
apply And.intro
case left => {
apply Or.elim (lt_suc r n h2)
case left => simp [h5]
case right => intro h6; exact h6
}
case right => {
rw [h3]
simp [add_suc_right]
}
}
}
def is_prime (p : Cnat) : Prop := sorry
|
24bde5d7e654c9967c7f74bf3b202a4f2d599284
|
92b13ae5cb04d78dd215ae736d93f5353e0e8e87
|
/string_ext.lean
|
bc757cb11e6153b1a6028adc3e990ed9b9d4c215
|
[] |
no_license
|
jroesch/exp-compiler
|
f2dec4f17e769e7f3b41429c41ece1f004a3f209
|
6efd4512c80df947361bdada12415bc166db5e7f
|
refs/heads/master
| 1,585,267,520,150
| 1,469,047,597,000
| 1,469,047,597,000
| 63,471,055
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 555
|
lean
|
import init.string
open string
-- This version of the definition produces horrible code by doing cases_on 32
-- times, we should figure out how to make this legal, since this seems like
-- a really useful programming pattern that should not be punished.
-- definition is_space (c : char) : bool :=
-- match (fin.val c) with
-- | 32 := bool.tt
-- | _ := bool.ff
-- end
definition is_space (c : char) : bool :=
if (fin.val c = 32)
then bool.tt
else bool.ff
-- example is_space_correct (c : char) : (head " " = some c) → (is_space c = bool.tt) :=
|
5ead6b0b4ec490742dd1c985fde70c9158ac1eb3
|
d29d82a0af640c937e499f6be79fc552eae0aa13
|
/src/measure_theory/measure_space.lean
|
74f1f9276ec2173c82d11efab390074f5416f635
|
[
"Apache-2.0"
] |
permissive
|
AbdulMajeedkhurasani/mathlib
|
835f8a5c5cf3075b250b3737172043ab4fa1edf6
|
79bc7323b164aebd000524ebafd198eb0e17f956
|
refs/heads/master
| 1,688,003,895,660
| 1,627,788,521,000
| 1,627,788,521,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 114,018
|
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
-/
import measure_theory.measure_space_def
import measure_theory.measurable_space
/-!
# Measure spaces
The definition of a measure and a measure space are in `measure_theory.measure_space_def`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `measure_space_def`, and to
be available in `measure_space` (through `measurable_space`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
We introduce the following typeclasses for measures:
* `probability_measure μ`: `μ univ = 1`;
* `finite_measure μ`: `μ univ < ∞`;
* `sigma_finite μ`: there exists a countable collection of measurable sets that cover `univ`
where `μ` is finite;
* `locally_finite_measure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`;
* `has_no_atoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as
`∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `measure.of_measurable` and `outer_measure.to_measure` are two important ways to define a measure.
## Implementation notes
Given `μ : measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `measure.of_measurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `outer_measure.to_measure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generate_from_of_Union`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generate_from_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generate_from_of_Union` using
`C ∪ {univ}`, but is easier to work with.
A `measure_space` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable theory
open classical set filter (hiding map) function measurable_space
open_locale classical topological_space big_operators filter ennreal nnreal
variables {α β γ δ ι : Type*}
namespace measure_theory
section
variables [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ t : set α}
instance ae_is_measurably_generated : is_measurably_generated μ.ae :=
⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs in
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
lemma measure_Union [encodable β] {f : β → set α}
(hn : pairwise (disjoint on f)) (h : ∀ i, measurable_set (f i)) :
μ (⋃ i, f i) = ∑' i, μ (f i) :=
begin
rw [measure_eq_extend (measurable_set.Union h),
extend_Union measurable_set.empty _ measurable_set.Union _ hn h],
{ simp [measure_eq_extend, h] },
{ exact μ.empty },
{ exact μ.m_Union }
end
lemma measure_union (hd : disjoint s₁ s₂) (h₁ : measurable_set s₁) (h₂ : measurable_set s₂) :
μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
begin
rw [union_eq_Union, measure_Union, tsum_fintype, fintype.sum_bool, cond, cond],
exacts [pairwise_disjoint_on_bool.2 hd, λ b, bool.cases_on b h₂ h₁]
end
lemma measure_add_measure_compl (h : measurable_set s) :
μ s + μ sᶜ = μ univ :=
by { rw [← union_compl_self s, measure_union _ h h.compl], exact disjoint_compl_right }
lemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s)
(hd : pairwise_on s (disjoint on f)) (h : ∀ b ∈ s, measurable_set (f b)) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
begin
haveI := hs.to_encodable,
rw bUnion_eq_Union,
exact measure_Union (hd.on_injective subtype.coe_injective $ λ x, x.2) (λ x, h x x.2)
end
lemma measure_sUnion {S : set (set α)} (hs : countable S)
(hd : pairwise_on S disjoint) (h : ∀ s ∈ S, measurable_set s) :
μ (⋃₀ S) = ∑' s : S, μ s :=
by rw [sUnion_eq_bUnion, measure_bUnion hs hd h]
lemma measure_bUnion_finset {s : finset ι} {f : ι → set α} (hd : pairwise_on ↑s (disjoint on f))
(hm : ∀ b ∈ s, measurable_set (f b)) :
μ (⋃ b ∈ s, f b) = ∑ p in s, μ (f p) :=
begin
rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],
exact measure_bUnion s.countable_to_set hd hm
end
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma tsum_measure_preimage_singleton {s : set β} (hs : countable s) {f : α → β}
(hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :
∑' b : s, μ (f ⁻¹' {↑b}) = μ (f ⁻¹' s) :=
by rw [← set.bUnion_preimage_singleton, measure_bUnion hs (pairwise_on_disjoint_fiber _ _) hf]
/-- If `s` is a `finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma sum_measure_preimage_singleton (s : finset β) {f : α → β}
(hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :
∑ b in s, μ (f ⁻¹' {b}) = μ (f ⁻¹' ↑s) :=
by simp only [← measure_bUnion_finset (pairwise_on_disjoint_fiber _ _) hf,
finset.set_bUnion_preimage_singleton]
lemma measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr $ diff_ae_eq_self.2 h
lemma measure_diff_null (h : μ s₂ = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_diff_null' $ measure_mono_null (inter_subset_right _ _) h
lemma measure_diff (h : s₂ ⊆ s₁) (h₁ : measurable_set s₁) (h₂ : measurable_set s₂)
(h_fin : μ s₂ < ∞) :
μ (s₁ \ s₂) = μ s₁ - μ s₂ :=
begin
refine (ennreal.add_sub_self' h_fin).symm.trans _,
rw [← measure_union disjoint_diff h₂ (h₁.diff h₂), union_diff_cancel h]
end
lemma meas_eq_meas_of_null_diff {s t : set α}
(hst : s ⊆ t) (h_nulldiff : μ (t.diff s) = 0) : μ s = μ t :=
by { rw [←diff_diff_cancel_left hst, ←@measure_diff_null _ _ _ t _ h_nulldiff], refl, }
lemma meas_eq_meas_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) :
(μ s₁ = μ s₂) ∧ (μ s₂ = μ s₃) :=
begin
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12,
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23,
have key : μ s₃ ≤ μ s₁ := calc
μ s₃ = μ ((s₃ \ s₁) ∪ s₁) : by rw (diff_union_of_subset (h12.trans h23))
... ≤ μ (s₃ \ s₁) + μ s₁ : measure_union_le _ _
... = μ s₁ : by simp only [h_nulldiff, zero_add],
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩,
end
lemma meas_eq_meas_smaller_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃.diff s₁) = 0) : μ s₁ = μ s₂ :=
(meas_eq_meas_of_between_null_diff h12 h23 h_nulldiff).1
lemma meas_eq_meas_larger_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃.diff s₁) = 0) : μ s₂ = μ s₃ :=
(meas_eq_meas_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl (h₁ : measurable_set s) (h_fin : μ s < ∞) : μ (sᶜ) = μ univ - μ s :=
by { rw compl_eq_univ_diff, exact measure_diff (subset_univ s) measurable_set.univ h₁ h_fin }
lemma sum_measure_le_measure_univ {s : finset ι} {t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i))
(H : pairwise_on ↑s (disjoint on t)) :
∑ i in s, μ (t i) ≤ μ (univ : set α) :=
by { rw ← measure_bUnion_finset H h, exact measure_mono (subset_univ _) }
lemma tsum_measure_le_measure_univ {s : ι → set α} (hs : ∀ i, measurable_set (s i))
(H : pairwise (disjoint on s)) :
∑' i, μ (s i) ≤ μ (univ : set α) :=
begin
rw [ennreal.tsum_eq_supr_sum],
exact supr_le (λ s, sum_measure_le_measure_univ (λ i hi, hs i) (λ i hi j hj hij, H i j hij))
end
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_tsum_measure (μ : measure α) {s : ι → set α}
(hs : ∀ i, measurable_set (s i)) (H : μ (univ : set α) < ∑' i, μ (s i)) :
∃ i j (h : i ≠ j), (s i ∩ s j).nonempty :=
begin
contrapose! H,
apply tsum_measure_le_measure_univ hs,
exact λ i j hij x hx, H i j hij ⟨x, hx⟩
end
/-- Pigeonhole principle for measure spaces: if `s` is a `finset` and
`∑ i in s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_sum_measure (μ : measure α) {s : finset ι}
{t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i)) (H : μ (univ : set α) < ∑ i in s, μ (t i)) :
∃ (i ∈ s) (j ∈ s) (h : i ≠ j), (t i ∩ t j).nonempty :=
begin
contrapose! H,
apply sum_measure_le_measure_univ h,
exact λ i hi j hj hij x hx, H i hi j hj hij ⟨x, hx⟩
end
/-- Continuity from below: the measure of the union of a directed sequence of measurable sets
is the supremum of the measures. -/
lemma measure_Union_eq_supr [encodable ι] {s : ι → set α} (h : ∀ i, measurable_set (s i))
(hd : directed (⊆) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) :=
begin
by_cases hι : nonempty ι, swap,
{ simp only [supr_of_empty hι, Union], exact measure_empty },
resetI,
refine le_antisymm _ (supr_le $ λ i, measure_mono $ subset_Union _ _),
have : ∀ n, measurable_set (disjointed (λ n, ⋃ b ∈ encodable.decode₂ ι n, s b) n) :=
measurable_set.disjointed (measurable_set.bUnion_decode₂ h),
rw [← encodable.Union_decode₂, ← Union_disjointed, measure_Union disjoint_disjointed this,
ennreal.tsum_eq_supr_nat],
simp only [← measure_bUnion_finset (disjoint_disjointed.pairwise_on _) (λ n _, this n)],
refine supr_le (λ n, _),
refine le_trans (_ : _ ≤ μ (⋃ (k ∈ finset.range n) (i ∈ encodable.decode₂ ι k), s i)) _,
exact measure_mono (bUnion_subset_bUnion_right (λ k hk, disjointed_subset)),
simp only [← finset.set_bUnion_option_to_finset, ← finset.set_bUnion_bUnion],
generalize : (finset.range n).bUnion (λ k, (encodable.decode₂ ι k).to_finset) = t,
rcases hd.finset_le t with ⟨i, hi⟩,
exact le_supr_of_le i (measure_mono $ bUnion_subset hi)
end
lemma measure_bUnion_eq_supr {s : ι → set α} {t : set ι} (ht : countable t)
(h : ∀ i ∈ t, measurable_set (s i)) (hd : directed_on ((⊆) on s) t) :
μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) :=
begin
haveI := ht.to_encodable,
rw [bUnion_eq_Union, measure_Union_eq_supr (set_coe.forall'.1 h) hd.directed_coe,
supr_subtype'],
refl
end
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the infimum of the measures. -/
lemma measure_Inter_eq_infi [encodable ι] {s : ι → set α}
(h : ∀ i, measurable_set (s i)) (hd : directed (⊇) s)
(hfin : ∃ i, μ (s i) < ∞) :
μ (⋂ i, s i) = (⨅ i, μ (s i)) :=
begin
rcases hfin with ⟨k, hk⟩,
rw [← ennreal.sub_sub_cancel (by exact hk) (infi_le _ k), ennreal.sub_infi,
← ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)),
← measure_diff (Inter_subset _ k) (h k) (measurable_set.Inter h)
(lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk),
diff_Inter, measure_Union_eq_supr],
{ congr' 1,
refine le_antisymm (supr_le_supr2 $ λ i, _) (supr_le_supr $ λ i, _),
{ rcases hd i k with ⟨j, hji, hjk⟩,
use j,
rw [← measure_diff hjk (h _) (h _) ((measure_mono hjk).trans_lt hk)],
exact measure_mono (diff_subset_diff_right hji) },
{ rw [ennreal.sub_le_iff_le_add, ← measure_union disjoint_diff.symm ((h k).diff (h i)) (h i),
set.union_comm],
exact measure_mono (diff_subset_iff.1 $ subset.refl _) } },
{ exact λ i, (h k).diff (h i) },
{ exact hd.mono_comp _ (λ _ _, diff_subset_diff_right) }
end
lemma measure_eq_inter_diff (hs : measurable_set s) (ht : measurable_set t) :
μ s = μ (s ∩ t) + μ (s \ t) :=
have hd : disjoint (s ∩ t) (s \ t) := assume a ⟨⟨_, hs⟩, _, hns⟩, hns hs ,
by rw [← measure_union hd (hs.inter ht) (hs.diff ht), inter_union_diff s t]
lemma measure_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t :=
by { rw [measure_eq_inter_diff (hs.union ht) ht, set.union_inter_cancel_right,
union_diff_right, measure_eq_inter_diff hs ht], ac_refl }
/-- Continuity from below: the measure of the union of an increasing sequence of measurable sets
is the limit of the measures. -/
lemma tendsto_measure_Union {s : ℕ → set α} (hs : ∀ n, measurable_set (s n)) (hm : monotone s) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋃ n, s n))) :=
begin
rw measure_Union_eq_supr hs (directed_of_sup hm),
exact tendsto_at_top_supr (assume n m hnm, measure_mono $ hm hnm)
end
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the limit of the measures. -/
lemma tendsto_measure_Inter {s : ℕ → set α}
(hs : ∀ n, measurable_set (s n)) (hm : ∀ ⦃n m⦄, n ≤ m → s m ⊆ s n) (hf : ∃ i, μ (s i) < ∞) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋂ n, s n))) :=
begin
rw measure_Inter_eq_infi hs (directed_of_sup hm) hf,
exact tendsto_at_top_infi (assume n m hnm, measure_mono $ hm hnm),
end
/-- One direction of the **Borel-Cantelli lemma**: if (sᵢ) is a sequence of measurable sets such
that ∑ μ sᵢ exists, then the limit superior of the sᵢ is a null set. -/
lemma measure_limsup_eq_zero {s : ℕ → set α} (hs : ∀ i, measurable_set (s i))
(hs' : ∑' i, μ (s i) ≠ ∞) : μ (limsup at_top s) = 0 :=
begin
rw limsup_eq_infi_supr_of_nat',
-- We will show that both `μ (⨅ n, ⨆ i, s (i + n))` and `0` are the limit of `μ (⊔ i, s (i + n))`
-- as `n` tends to infinity. For the former, we use continuity from above.
refine tendsto_nhds_unique
(tendsto_measure_Inter (λ i, measurable_set.Union (λ b, hs (b + i))) _
⟨0, lt_of_le_of_lt (measure_Union_le s) (ennreal.lt_top_iff_ne_top.2 hs')⟩) _,
{ intros n m hnm x,
simp only [set.mem_Union],
exact λ ⟨i, hi⟩, ⟨i + (m - n), by simpa only [add_assoc, nat.sub_add_cancel hnm] using hi⟩ },
{ -- For the latter, notice that, `μ (⨆ i, s (i + n)) ≤ ∑' s (i + n)`. Since the right hand side
-- converges to `0` by hypothesis, so does the former and the proof is complete.
exact (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
(ennreal.tendsto_sum_nat_add (μ ∘ s) hs')
(eventually_of_forall (by simp only [forall_const, zero_le]))
(eventually_of_forall (λ i, measure_Union_le _))) }
end
lemma measure_if {x : β} {t : set β} {s : set α} {μ : measure α} :
μ (if x ∈ t then s else ∅) = indicator t (λ _, μ s) x :=
by { split_ifs; simp [h] }
end
section outer_measure
variables [ms : measurable_space α] {s t : set α}
include ms
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def outer_measure.to_measure (m : outer_measure α) (h : ms ≤ m.caratheodory) : measure α :=
measure.of_measurable (λ s _, m s) m.empty
(λ f hf hd, m.Union_eq_of_caratheodory (λ i, h _ (hf i)) hd)
lemma le_to_outer_measure_caratheodory (μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory :=
begin
assume s hs,
rw to_outer_measure_eq_induced_outer_measure,
refine outer_measure.of_function_caratheodory (λ t, le_infi $ λ ht, _),
rw [← measure_eq_extend (ht.inter hs),
← measure_eq_extend (ht.diff hs),
← measure_union _ (ht.inter hs) (ht.diff hs),
inter_union_diff],
exact le_refl _,
exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁
end
@[simp] lemma to_measure_to_outer_measure (m : outer_measure α) (h : ms ≤ m.caratheodory) :
(m.to_measure h).to_outer_measure = m.trim := rfl
@[simp] lemma to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory)
{s : set α} (hs : measurable_set s) : m.to_measure h s = m s :=
m.trim_eq hs
lemma le_to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory) (s : set α) :
m s ≤ m.to_measure h s :=
m.le_trim s
@[simp] lemma to_outer_measure_to_measure {μ : measure α} :
μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ :=
measure.ext $ λ s, μ.to_outer_measure.trim_eq
end outer_measure
variables [measurable_space α] [measurable_space β] [measurable_space γ]
variables {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : measure α} {s s' t : set α}
namespace measure
protected lemma caratheodory (μ : measure α) (hs : measurable_set s) :
μ (t ∩ s) + μ (t \ s) = μ t :=
(le_to_outer_measure_caratheodory μ s hs t).symm
/-! ### The `ℝ≥0∞`-module of measures -/
instance : has_zero (measure α) :=
⟨{ to_outer_measure := 0,
m_Union := λ f hf hd, tsum_zero.symm,
trimmed := outer_measure.trim_zero }⟩
@[simp] theorem zero_to_outer_measure : (0 : measure α).to_outer_measure = 0 := rfl
@[simp, norm_cast] theorem coe_zero : ⇑(0 : measure α) = 0 := rfl
lemma eq_zero_of_not_nonempty (h : ¬nonempty α) (μ : measure α) : μ = 0 :=
ext $ λ s hs, by simp only [eq_empty_of_not_nonempty h s, measure_empty]
instance : inhabited (measure α) := ⟨0⟩
instance : has_add (measure α) :=
⟨λ μ₁ μ₂, {
to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure,
m_Union := λ s hs hd,
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)),
by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs],
trimmed := by rw [outer_measure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp] theorem add_to_outer_measure (μ₁ μ₂ : measure α) :
(μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl
@[simp, norm_cast] theorem coe_add (μ₁ μ₂ : measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl
theorem add_apply (μ₁ μ₂ : measure α) (s : set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl
instance add_comm_monoid : add_comm_monoid (measure α) :=
to_outer_measure_injective.add_comm_monoid to_outer_measure zero_to_outer_measure
add_to_outer_measure
instance : has_scalar ℝ≥0∞ (measure α) :=
⟨λ c μ,
{ to_outer_measure := c • μ.to_outer_measure,
m_Union := λ s hs hd, by simp [measure_Union, *, ennreal.tsum_mul_left],
trimmed := by rw [outer_measure.trim_smul, μ.trimmed] }⟩
@[simp] theorem smul_to_outer_measure (c : ℝ≥0∞) (μ : measure α) :
(c • μ).to_outer_measure = c • μ.to_outer_measure :=
rfl
@[simp, norm_cast] theorem coe_smul (c : ℝ≥0∞) (μ : measure α) : ⇑(c • μ) = c • μ :=
rfl
theorem smul_apply (c : ℝ≥0∞) (μ : measure α) (s : set α) : (c • μ) s = c * μ s :=
rfl
instance : module ℝ≥0∞ (measure α) :=
injective.module ℝ≥0∞ ⟨to_outer_measure, zero_to_outer_measure, add_to_outer_measure⟩
to_outer_measure_injective smul_to_outer_measure
@[simp, norm_cast] theorem coe_nnreal_smul (c : ℝ≥0) (μ : measure α) : ⇑(c • μ) = c • μ :=
rfl
/-! ### The complete lattice of measures -/
/-- Measures are partially ordered.
The definition of less equal here is equivalent to the definition without the
measurable set condition, and this is shown by `measure.le_iff'`. It is defined
this way since, to prove `μ ≤ ν`, we may simply `intros s hs` instead of rewriting followed
by `intros s hs`. -/
instance : partial_order (measure α) :=
{ le := λ m₁ m₂, ∀ s, measurable_set s → m₁ s ≤ m₂ s,
le_refl := assume m s hs, le_refl _,
le_trans := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs),
le_antisymm := assume m₁ m₂ h₁ h₂, ext $
assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) }
theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, measurable_set s → μ₁ s ≤ μ₂ s := iff.rfl
theorem to_outer_measure_le : μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ :=
by rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl
theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s :=
to_outer_measure_le.symm
theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, measurable_set s ∧ μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff', not_forall, not_le]
instance covariant_add_le : covariant_class (measure α) (measure α) (+) (≤) :=
⟨λ ν μ₁ μ₂ hμ s hs, add_le_add_left (hμ s hs) _⟩
protected lemma le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν :=
λ s hs, le_add_left (h s hs)
protected lemma le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' :=
λ s hs, le_add_right (h s hs)
section Inf
variables {m : set (measure α)}
lemma Inf_caratheodory (s : set α) (hs : measurable_set s) :
(Inf (to_outer_measure '' m)).caratheodory.measurable_set' s :=
begin
rw [outer_measure.Inf_eq_bounded_by_Inf_gen],
refine outer_measure.bounded_by_caratheodory (λ t, _),
simp only [outer_measure.Inf_gen, le_infi_iff, ball_image_iff, coe_to_outer_measure,
measure_eq_infi t],
intros μ hμ u htu hu,
have hm : ∀ {s t}, s ⊆ t → outer_measure.Inf_gen (to_outer_measure '' m) s ≤ μ t,
{ intros s t hst,
rw [outer_measure.Inf_gen_def],
refine infi_le_of_le (μ.to_outer_measure) (infi_le_of_le (mem_image_of_mem _ hμ) _),
rw [to_outer_measure_apply],
refine measure_mono hst },
rw [measure_eq_inter_diff hu hs],
refine add_le_add (hm $ inter_subset_inter_left _ htu) (hm $ diff_subset_diff_left htu)
end
instance : has_Inf (measure α) :=
⟨λ m, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodory⟩
lemma Inf_apply (hs : measurable_set s) : Inf m s = Inf (to_outer_measure '' m) s :=
to_measure_apply _ _ hs
private lemma measure_Inf_le (h : μ ∈ m) : Inf m ≤ μ :=
have Inf (to_outer_measure '' m) ≤ μ.to_outer_measure := Inf_le (mem_image_of_mem _ h),
assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s
private lemma measure_le_Inf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ Inf m :=
have μ.to_outer_measure ≤ Inf (to_outer_measure '' m) :=
le_Inf $ ball_image_of_ball $ assume μ hμ, to_outer_measure_le.2 $ h _ hμ,
assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s
instance : complete_semilattice_Inf (measure α) :=
{ Inf_le := λ s a, measure_Inf_le,
le_Inf := λ s a, measure_le_Inf,
..(by apply_instance : partial_order (measure α)),
..(by apply_instance : has_Inf (measure α)), }
instance : complete_lattice (measure α) :=
{ bot := 0,
bot_le := assume a s hs, by exact bot_le,
/- Adding an explicit `top` makes `leanchecker` fail, see lean#364, disable for now
top := (⊤ : outer_measure α).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top),
le_top := assume a s hs,
by cases s.eq_empty_or_nonempty with h h;
simp [h, to_measure_apply ⊤ _ hs, outer_measure.top_apply],
-/
.. complete_lattice_of_complete_semilattice_Inf (measure α) }
end Inf
protected lemma zero_le (μ : measure α) : 0 ≤ μ := bot_le
lemma nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=
μ.zero_le.le_iff_eq
@[simp] lemma measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=
⟨λ h, bot_unique $ λ s hs, trans_rel_left (≤) (measure_mono (subset_univ s)) h, λ h, h.symm ▸ rfl⟩
/-! ### Pushforward and pullback -/
/-- Lift a linear map between `outer_measure` spaces such that for each measure `μ` every measurable
set is caratheodory-measurable w.r.t. `f μ` to a linear map between `measure` spaces. -/
def lift_linear (f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β)
(hf : ∀ μ : measure α, ‹_› ≤ (f μ.to_outer_measure).caratheodory) :
measure α →ₗ[ℝ≥0∞] measure β :=
{ to_fun := λ μ, (f μ.to_outer_measure).to_measure (hf μ),
map_add' := λ μ₁ μ₂, ext $ λ s hs, by simp [hs],
map_smul' := λ c μ, ext $ λ s hs, by simp [hs] }
@[simp] lemma lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf)
{s : set β} (hs : measurable_set s) : lift_linear f hf μ s = f μ.to_outer_measure s :=
to_measure_apply _ _ hs
lemma le_lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf) (s : set β) :
f μ.to_outer_measure s ≤ lift_linear f hf μ s :=
le_to_measure_apply _ _ s
/-- The pushforward of a measure. It is defined to be `0` if `f` is not a measurable function. -/
def map (f : α → β) : measure α →ₗ[ℝ≥0∞] measure β :=
if hf : measurable f then
lift_linear (outer_measure.map f) $ λ μ s hs t,
le_to_outer_measure_caratheodory μ _ (hf hs) (f ⁻¹' t)
else 0
/-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see
`measure_theory.measure.le_map_apply` and `measurable_equiv.map_apply`. -/
@[simp] theorem map_apply {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
map f μ s = μ (f ⁻¹' s) :=
by simp [map, dif_pos hf, hs]
theorem map_of_not_measurable {f : α → β} (hf : ¬measurable f) :
map f μ = 0 :=
by rw [map, dif_neg hf, linear_map.zero_apply]
@[simp] lemma map_id : map id μ = μ :=
ext $ λ s, map_apply measurable_id
lemma map_map {g : β → γ} {f : α → β} (hg : measurable g) (hf : measurable f) :
map g (map f μ) = map (g ∘ f) μ :=
ext $ λ s hs,
by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp]
@[mono] lemma map_mono (f : α → β) (h : μ ≤ ν) : map f μ ≤ map f ν :=
if hf : measurable f then λ s hs, by simp only [map_apply hf hs, h _ (hf hs)]
else by simp only [map_of_not_measurable hf, le_rfl]
/-- Even if `s` is not measurable, we can bound `map f μ s` from below.
See also `measurable_equiv.map_apply`. -/
theorem le_map_apply {f : α → β} (hf : measurable f) (s : set β) : μ (f ⁻¹' s) ≤ map f μ s :=
begin
rw [measure_eq_infi' (map f μ)], refine le_infi _, rintro ⟨t, hst, ht⟩,
convert measure_mono (preimage_mono hst),
exact map_apply hf ht
end
/-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/
lemma preimage_null_of_map_null {f : α → β} (hf : measurable f) {s : set β}
(hs : map f μ s = 0) : μ (f ⁻¹' s) = 0 :=
nonpos_iff_eq_zero.mp $ (le_map_apply hf s).trans_eq hs
lemma tendsto_ae_map {f : α → β} (hf : measurable f) : tendsto f μ.ae (map f μ).ae :=
λ s hs, preimage_null_of_map_null hf hs
/-- Pullback of a `measure`. If `f` sends each `measurable` set to a `measurable` set, then for each
measurable set `s` we have `comap f μ s = μ (f '' s)`. -/
def comap (f : α → β) : measure β →ₗ[ℝ≥0∞] measure α :=
if hf : injective f ∧ ∀ s, measurable_set s → measurable_set (f '' s) then
lift_linear (outer_measure.comap f) $ λ μ s hs t,
begin
simp only [coe_to_outer_measure, outer_measure.comap_apply, ← image_inter hf.1,
image_diff hf.1],
apply le_to_outer_measure_caratheodory,
exact hf.2 s hs
end
else 0
lemma comap_apply (f : α → β) (hfi : injective f)
(hf : ∀ s, measurable_set s → measurable_set (f '' s)) (μ : measure β) (hs : measurable_set s) :
comap f μ s = μ (f '' s) :=
begin
rw [comap, dif_pos, lift_linear_apply _ hs, outer_measure.comap_apply, coe_to_outer_measure],
exact ⟨hfi, hf⟩
end
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
def restrictₗ (s : set α) : measure α →ₗ[ℝ≥0∞] measure α :=
lift_linear (outer_measure.restrict s) $ λ μ s' hs' t,
begin
suffices : μ (s ∩ t) = μ (s ∩ t ∩ s') + μ (s ∩ t \ s'),
{ simpa [← set.inter_assoc, set.inter_comm _ s, ← inter_diff_assoc] },
exact le_to_outer_measure_caratheodory _ _ hs' _,
end
/-- Restrict a measure `μ` to a set `s`. -/
def restrict (μ : measure α) (s : set α) : measure α := restrictₗ s μ
@[simp] lemma restrictₗ_apply (s : set α) (μ : measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `measure.restrict_apply'`. -/
@[simp] lemma restrict_apply (ht : measurable_set t) : μ.restrict s t = μ (t ∩ s) :=
by simp [← restrictₗ_apply, restrictₗ, ht]
lemma restrict_eq_self (h_meas_t : measurable_set t) (h : t ⊆ s) : μ.restrict s t = μ t :=
by rw [restrict_apply h_meas_t, inter_eq_left_iff_subset.mpr h]
lemma restrict_apply_self (μ:measure α) (h_meas_s : measurable_set s) :
(μ.restrict s) s = μ s := (restrict_eq_self h_meas_s (set.subset.refl _))
lemma restrict_apply_univ (s : set α) : μ.restrict s univ = μ s :=
by rw [restrict_apply measurable_set.univ, set.univ_inter]
lemma le_restrict_apply (s t : set α) :
μ (t ∩ s) ≤ μ.restrict s t :=
by { rw [restrict, restrictₗ], convert le_lift_linear_apply _ t, simp }
@[simp] lemma restrict_add (μ ν : measure α) (s : set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp] lemma restrict_zero (s : set α) : (0 : measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp] lemma restrict_smul (c : ℝ≥0∞) (μ : measure α) (s : set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
@[simp] lemma restrict_restrict (hs : measurable_set s) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext $ λ u hu, by simp [*, set.inter_assoc]
lemma restrict_comm (hs : measurable_set s) (ht : measurable_set t) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t :=
by rw [restrict_restrict hs, restrict_restrict ht, inter_comm]
lemma restrict_apply_eq_zero (ht : measurable_set t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
by rw [restrict_apply ht]
lemma measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
lemma restrict_apply_eq_zero' (hs : measurable_set s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
begin
refine ⟨measure_inter_eq_zero_of_restrict, λ h, _⟩,
rcases exists_measurable_superset_of_null h with ⟨t', htt', ht', ht'0⟩,
apply measure_mono_null ((inter_subset _ _ _).1 htt'),
rw [restrict_apply (hs.compl.union ht'), union_inter_distrib_right, compl_inter_self,
set.empty_union],
exact measure_mono_null (inter_subset_left _ _) ht'0
end
@[simp] lemma restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 :=
by rw [← measure_univ_eq_zero, restrict_apply_univ]
lemma restrict_zero_set {s : set α} (h : μ s = 0) :
μ.restrict s = 0 :=
by simp only [measure.restrict_eq_zero, h]
@[simp] lemma restrict_empty : μ.restrict ∅ = 0 := ext $ λ s hs, by simp [hs]
@[simp] lemma restrict_univ : μ.restrict univ = μ := ext $ λ s hs, by simp [hs]
lemma restrict_eq_self_of_measurable_subset (ht : measurable_set t) (t_subset : t ⊆ s) :
μ.restrict s t = μ t :=
by rw [measure.restrict_apply ht, set.inter_eq_self_of_subset_left t_subset]
lemma restrict_union_apply (h : disjoint (t ∩ s) (t ∩ s')) (hs : measurable_set s)
(hs' : measurable_set s') (ht : measurable_set t) :
μ.restrict (s ∪ s') t = μ.restrict s t + μ.restrict s' t :=
begin
simp only [restrict_apply, ht, set.inter_union_distrib_left],
exact measure_union h (ht.inter hs) (ht.inter hs'),
end
lemma restrict_union (h : disjoint s t) (hs : measurable_set s) (ht : measurable_set t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
ext $ λ t' ht', restrict_union_apply (h.mono inf_le_right inf_le_right) hs ht ht'
lemma restrict_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
begin
ext1 u hu,
simp only [add_apply, restrict_apply hu, inter_union_distrib_left],
convert measure_union_add_inter (hu.inter hs) (hu.inter ht) using 3,
rw [set.inter_left_comm (u ∩ s), set.inter_assoc, ← set.inter_assoc u u, set.inter_self]
end
@[simp] lemma restrict_add_restrict_compl (hs : measurable_set s) :
μ.restrict s + μ.restrict sᶜ = μ :=
by rw [← restrict_union (@disjoint_compl_right (set α) _ _) hs hs.compl,
union_compl_self, restrict_univ]
@[simp] lemma restrict_compl_add_restrict (hs : measurable_set s) :
μ.restrict sᶜ + μ.restrict s = μ :=
by rw [add_comm, restrict_add_restrict_compl hs]
lemma restrict_union_le (s s' : set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
begin
intros t ht,
suffices : μ (t ∩ s ∪ t ∩ s') ≤ μ (t ∩ s) + μ (t ∩ s'),
by simpa [ht, inter_union_distrib_left],
apply measure_union_le
end
lemma restrict_Union_apply [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, measurable_set (s i)) {t : set α} (ht : measurable_set t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
begin
simp only [restrict_apply, ht, inter_Union],
exact measure_Union (λ i j hij, (hd i j hij).mono inf_le_right inf_le_right)
(λ i, ht.inter (hm i))
end
lemma restrict_Union_apply_eq_supr [encodable ι] {s : ι → set α}
(hm : ∀ i, measurable_set (s i)) (hd : directed (⊆) s) {t : set α} (ht : measurable_set t) :
μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t :=
begin
simp only [restrict_apply ht, inter_Union],
rw [measure_Union_eq_supr],
exacts [λ i, ht.inter (hm i), hd.mono_comp _ (λ s₁ s₂, inter_subset_inter_right _)]
end
lemma restrict_map {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
(map f μ).restrict s = map f (μ.restrict $ f ⁻¹' s) :=
ext $ λ t ht, by simp [*, hf ht]
lemma map_comap_subtype_coe (hs : measurable_set s) :
(map (coe : s → α)).comp (comap coe) = restrictₗ s :=
linear_map.ext $ λ μ, ext $ λ t ht,
by rw [restrictₗ_apply, restrict_apply ht, linear_map.comp_apply,
map_apply measurable_subtype_coe ht,
comap_apply (coe : s → α) subtype.val_injective (λ _, hs.subtype_image) _
(measurable_subtype_coe ht), subtype.image_preimage_coe]
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
lemma restrict_mono' ⦃s s' : set α⦄ ⦃μ ν : measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) :
μ.restrict s ≤ ν.restrict s' :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ (t ∩ s') : measure_mono_ae $ hs.mono $ λ x hx ⟨hxt, hxs⟩, ⟨hxt, hx hxs⟩
... ≤ ν (t ∩ s') : le_iff'.1 hμν (t ∩ s')
... = ν.restrict s' t : (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono] lemma restrict_mono ⦃s s' : set α⦄ (hs : s ⊆ s') ⦃μ ν : measure α⦄ (hμν : μ ≤ ν) :
μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
lemma restrict_le_self : μ.restrict s ≤ μ :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ t : measure_mono $ inter_subset_left t s
lemma restrict_congr_meas (hs : measurable_set s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, measurable_set t → μ t = ν t :=
⟨λ H t hts ht,
by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht],
λ H, ext $ λ t ht,
by rw [restrict_apply ht, restrict_apply ht, H _ (inter_subset_right _ _) (ht.inter hs)]⟩
lemma restrict_congr_mono (hs : s ⊆ t) (hm : measurable_set s) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s :=
by rw [← inter_eq_self_of_subset_left hs, ← restrict_restrict hm, h, restrict_restrict hm]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
lemma restrict_union_congr (hsm : measurable_set s) (htm : measurable_set t) :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t :=
begin
refine ⟨λ h, ⟨restrict_congr_mono (subset_union_left _ _) hsm h,
restrict_congr_mono (subset_union_right _ _) htm h⟩, _⟩,
simp only [restrict_congr_meas, hsm, htm, hsm.union htm],
rintros ⟨hs, ht⟩ u hu hum,
rw [measure_eq_inter_diff hum hsm, measure_eq_inter_diff hum hsm,
hs _ (inter_subset_right _ _) (hum.inter hsm),
ht _ (diff_subset_iff.2 hu) (hum.diff hsm)]
end
lemma restrict_finset_bUnion_congr {s : finset ι} {t : ι → set α}
(htm : ∀ i ∈ s, measurable_set (t i)) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=
begin
induction s using finset.induction_on with i s hi hs, { simp },
simp only [finset.mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at htm ⊢,
simp only [finset.set_bUnion_insert, ← hs htm.2],
exact restrict_union_congr htm.1 (s.measurable_set_bUnion htm.2)
end
lemma restrict_Union_congr [encodable ι] {s : ι → set α} (hm : ∀ i, measurable_set (s i)) :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔
∀ i, μ.restrict (s i) = ν.restrict (s i) :=
begin
refine ⟨λ h i, restrict_congr_mono (subset_Union _ _) (hm i) h, λ h, _⟩,
ext1 t ht,
have M : ∀ t : finset ι, measurable_set (⋃ i ∈ t, s i) :=
λ t, t.measurable_set_bUnion (λ i _, hm i),
have D : directed (⊆) (λ t : finset ι, ⋃ i ∈ t, s i) :=
directed_of_sup (λ t₁ t₂ ht, bUnion_subset_bUnion_left ht),
rw [Union_eq_Union_finset],
simp only [restrict_Union_apply_eq_supr M D ht,
(restrict_finset_bUnion_congr (λ i hi, hm i)).2 (λ i hi, h i)],
end
lemma restrict_bUnion_congr {s : set ι} {t : ι → set α} (hc : countable s)
(htm : ∀ i ∈ s, measurable_set (t i)) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=
begin
simp only [bUnion_eq_Union, set_coe.forall'] at htm ⊢,
haveI := hc.to_encodable,
exact restrict_Union_congr htm
end
lemma restrict_sUnion_congr {S : set (set α)} (hc : countable S) (hm : ∀ s ∈ S, measurable_set s) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
by rw [sUnion_eq_bUnion, restrict_bUnion_congr hc hm]
/-- This lemma shows that `restrict` and `to_outer_measure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
lemma restrict_to_outer_measure_eq_to_outer_measure_restrict (h : measurable_set s) :
(μ.restrict s).to_outer_measure = outer_measure.restrict s μ.to_outer_measure :=
by simp_rw [restrict, restrictₗ, lift_linear, linear_map.coe_mk, to_measure_to_outer_measure,
outer_measure.restrict_trim h, μ.trimmed]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
lemma restrict_Inf_eq_Inf_restrict {m : set (measure α)} (hm : m.nonempty) (ht : measurable_set t) :
(Inf m).restrict t = Inf ((λ μ : measure α, μ.restrict t) '' m) :=
begin
ext1 s hs,
simp_rw [Inf_apply hs, restrict_apply hs, Inf_apply (measurable_set.inter hs ht), set.image_image,
restrict_to_outer_measure_eq_to_outer_measure_restrict ht, ← set.image_image _ to_outer_measure,
← outer_measure.restrict_Inf_eq_Inf_restrict _ (hm.image _),
outer_measure.restrict_apply]
end
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
lemma restrict_apply' (hs : measurable_set s) : μ.restrict s t = μ (t ∩ s) :=
by rw [← coe_to_outer_measure, measure.restrict_to_outer_measure_eq_to_outer_measure_restrict hs,
outer_measure.restrict_apply s t _, coe_to_outer_measure]
lemma restrict_eq_self_of_subset_of_measurable (hs : measurable_set s) (t_subset : t ⊆ s) :
μ.restrict s t = μ t :=
by rw [restrict_apply' hs, set.inter_eq_self_of_subset_left t_subset]
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
lemma ext_iff_of_Union_eq_univ [encodable ι] {s : ι → set α}
(hm : ∀ i, measurable_set (s i)) (hs : (⋃ i, s i) = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) :=
by rw [← restrict_Union_congr hm, hs, restrict_univ, restrict_univ]
alias ext_iff_of_Union_eq_univ ↔ _ measure_theory.measure.ext_of_Union_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `bUnion`). -/
lemma ext_iff_of_bUnion_eq_univ {S : set ι} {s : ι → set α} (hc : countable S)
(hm : ∀ i ∈ S, measurable_set (s i)) (hs : (⋃ i ∈ S, s i) = univ) :
μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) :=
by rw [← restrict_bUnion_congr hc hm, hs, restrict_univ, restrict_univ]
alias ext_iff_of_bUnion_eq_univ ↔ _ measure_theory.measure.ext_of_bUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
lemma ext_iff_of_sUnion_eq_univ {S : set (set α)} (hc : countable S)
(hm : ∀ s ∈ S, measurable_set s) (hs : (⋃₀ S) = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_bUnion_eq_univ hc hm $ by rwa ← sUnion_eq_bUnion
alias ext_iff_of_sUnion_eq_univ ↔ _ measure_theory.measure.ext_of_sUnion_eq_univ
lemma ext_of_generate_from_of_cover {S T : set (set α)}
(h_gen : ‹_› = generate_from S) (hc : countable T)
(h_inter : is_pi_system S)
(hm : ∀ t ∈ T, measurable_set t) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t < ∞)
(ST_eq : ∀ (t ∈ T) (s ∈ S), μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) :
μ = ν :=
begin
refine ext_of_sUnion_eq_univ hc hm hU (λ t ht, _),
ext1 u hu,
simp only [restrict_apply hu],
refine induction_on_inter h_gen h_inter _ (ST_eq t ht) _ _ hu,
{ simp only [set.empty_inter, measure_empty] },
{ intros v hv hvt,
have := T_eq t ht,
rw [set.inter_comm] at hvt ⊢,
rwa [measure_eq_inter_diff (hm _ ht) hv, measure_eq_inter_diff (hm _ ht) hv, ← hvt,
ennreal.add_right_inj] at this,
exact (measure_mono $ set.inter_subset_left _ _).trans_lt (htop t ht) },
{ intros f hfd hfm h_eq,
have : pairwise (disjoint on λ n, f n ∩ t) :=
λ m n hmn, (hfd m n hmn).mono (inter_subset_left _ _) (inter_subset_left _ _),
simp only [Union_inter, measure_Union this (λ n, (hfm n).inter (hm t ht)), h_eq] }
end
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
lemma ext_of_generate_from_of_cover_subset {S T : set (set α)}
(h_gen : ‹_› = generate_from S)
(h_inter : is_pi_system S)
(h_sub : T ⊆ S) (hc : countable T) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s < ∞)
(h_eq : ∀ s ∈ S, μ s = ν s) :
μ = ν :=
begin
refine ext_of_generate_from_of_cover h_gen hc h_inter _ hU htop _ (λ t ht, h_eq t (h_sub ht)),
{ intros t ht, rw [h_gen], exact generate_measurable.basic _ (h_sub ht) },
{ intros t ht s hs, cases (s ∩ t).eq_empty_or_nonempty with H H,
{ simp only [H, measure_empty] },
{ exact h_eq _ (h_inter _ _ hs (h_sub ht) H) } }
end
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `Union`.
`finite_spanning_sets_in.ext` is a reformulation of this lemma. -/
lemma ext_of_generate_from_of_Union (C : set (set α)) (B : ℕ → set α)
(hA : ‹_› = generate_from C) (hC : is_pi_system C) (h1B : (⋃ i, B i) = univ)
(h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) < ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
begin
refine ext_of_generate_from_of_cover_subset hA hC _ (countable_range B) h1B _ h_eq,
{ rintro _ ⟨i, rfl⟩, apply h2B },
{ rintro _ ⟨i, rfl⟩, apply hμB }
end
/-- The dirac measure. -/
def dirac (a : α) : measure α :=
(outer_measure.dirac a).to_measure (by simp)
lemma le_dirac_apply {a} : s.indicator 1 a ≤ dirac a s :=
outer_measure.dirac_apply a s ▸ le_to_measure_apply _ _ _
@[simp] lemma dirac_apply' (a : α) (hs : measurable_set s) :
dirac a s = s.indicator 1 a :=
to_measure_apply _ _ hs
@[simp] lemma dirac_apply_of_mem {a : α} (h : a ∈ s) :
dirac a s = 1 :=
begin
have : ∀ t : set α, a ∈ t → t.indicator (1 : α → ℝ≥0∞) a = 1,
from λ t ht, indicator_of_mem ht 1,
refine le_antisymm (this univ trivial ▸ _) (this s h ▸ le_dirac_apply),
rw [← dirac_apply' a measurable_set.univ],
exact measure_mono (subset_univ s)
end
@[simp] lemma dirac_apply [measurable_singleton_class α] (a : α) (s : set α) :
dirac a s = s.indicator 1 a :=
begin
by_cases h : a ∈ s, by rw [dirac_apply_of_mem h, indicator_of_mem h, pi.one_apply],
rw [indicator_of_not_mem h, ← nonpos_iff_eq_zero],
calc dirac a s ≤ dirac a {a}ᶜ : measure_mono (subset_compl_comm.1 $ singleton_subset_iff.2 h)
... = 0 : by simp [dirac_apply' _ (measurable_set_singleton _).compl]
end
lemma map_dirac {f : α → β} (hf : measurable f) (a : α) :
map f (dirac a) = dirac (f a) :=
ext $ assume s hs, by simp [hs, map_apply hf hs, hf hs, indicator_apply]
/-- Sum of an indexed family of measures. -/
def sum (f : ι → measure α) : measure α :=
(outer_measure.sum (λ i, (f i).to_outer_measure)).to_measure $
le_trans
(by exact le_infi (λ i, le_to_outer_measure_caratheodory _))
(outer_measure.le_sum_caratheodory _)
lemma le_sum_apply (f : ι → measure α) (s : set α) :
(∑' i, f i s) ≤ sum f s :=
le_to_measure_apply _ _ _
@[simp] lemma sum_apply (f : ι → measure α) {s : set α} (hs : measurable_set s) :
sum f s = ∑' i, f i s :=
to_measure_apply _ _ hs
lemma le_sum (μ : ι → measure α) (i : ι) : μ i ≤ sum μ :=
λ s hs, by simp only [sum_apply μ hs, ennreal.le_tsum i]
lemma restrict_Union [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, measurable_set (s i)) :
μ.restrict (⋃ i, s i) = sum (λ i, μ.restrict (s i)) :=
ext $ λ t ht, by simp only [sum_apply _ ht, restrict_Union_apply hd hm ht]
lemma restrict_Union_le [encodable ι] {s : ι → set α} :
μ.restrict (⋃ i, s i) ≤ sum (λ i, μ.restrict (s i)) :=
begin
intros t ht,
suffices : μ (⋃ i, t ∩ s i) ≤ ∑' i, μ (t ∩ s i), by simpa [ht, inter_Union],
apply measure_Union_le
end
@[simp] lemma sum_bool (f : bool → measure α) : sum f = f tt + f ff :=
ext $ λ s hs, by simp [hs, tsum_fintype]
@[simp] lemma sum_cond (μ ν : measure α) : sum (λ b, cond b μ ν) = μ + ν :=
sum_bool _
@[simp] lemma restrict_sum (μ : ι → measure α) {s : set α} (hs : measurable_set s) :
(sum μ).restrict s = sum (λ i, (μ i).restrict s) :=
ext $ λ t ht, by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
/-- Counting measure on any measurable space. -/
def count : measure α := sum dirac
lemma le_count_apply : (∑' i : s, 1 : ℝ≥0∞) ≤ count s :=
calc (∑' i : s, 1 : ℝ≥0∞) = ∑' i, indicator s 1 i : tsum_subtype s 1
... ≤ ∑' i, dirac i s : ennreal.tsum_le_tsum $ λ x, le_dirac_apply
... ≤ count s : le_sum_apply _ _
lemma count_apply (hs : measurable_set s) : count s = ∑' i : s, 1 :=
by simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s 1, pi.one_apply]
@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :
count (↑s : set α) = s.card :=
calc count (↑s : set α) = ∑' i : (↑s : set α), 1 : count_apply s.measurable_set
... = ∑ i in s, 1 : s.tsum_subtype 1
... = s.card : by simp
lemma count_apply_finite [measurable_singleton_class α] (s : set α) (hs : finite s) :
count s = hs.to_finset.card :=
by rw [← count_apply_finset, finite.coe_to_finset]
/-- `count` measure evaluates to infinity at infinite sets. -/
lemma count_apply_infinite (hs : s.infinite) : count s = ∞ :=
begin
refine top_unique (le_of_tendsto' ennreal.tendsto_nat_nhds_top $ λ n, _),
rcases hs.exists_subset_card_eq n with ⟨t, ht, rfl⟩,
calc (t.card : ℝ≥0∞) = ∑ i in t, 1 : by simp
... = ∑' i : (t : set α), 1 : (t.tsum_subtype 1).symm
... ≤ count (t : set α) : le_count_apply
... ≤ count s : measure_mono ht
end
@[simp] lemma count_apply_eq_top [measurable_singleton_class α] : count s = ∞ ↔ s.infinite :=
begin
by_cases hs : s.finite,
{ simp [set.infinite, hs, count_apply_finite] },
{ change s.infinite at hs,
simp [hs, count_apply_infinite] }
end
@[simp] lemma count_apply_lt_top [measurable_singleton_class α] : count s < ∞ ↔ s.finite :=
calc count s < ∞ ↔ count s ≠ ∞ : lt_top_iff_ne_top
... ↔ ¬s.infinite : not_congr count_apply_eq_top
... ↔ s.finite : not_not
/-! ### Absolute continuity -/
/-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`,
if `ν(A) = 0` implies that `μ(A) = 0`. -/
def absolutely_continuous (μ ν : measure α) : Prop :=
∀ ⦃s : set α⦄, ν s = 0 → μ s = 0
infix ` ≪ `:50 := absolutely_continuous
lemma absolutely_continuous_of_le (h : μ ≤ ν) : μ ≪ ν :=
λ s hs, nonpos_iff_eq_zero.1 $ hs ▸ le_iff'.1 h s
alias absolutely_continuous_of_le ← has_le.le.absolutely_continuous
lemma absolutely_continuous_of_eq (h : μ = ν) : μ ≪ ν :=
h.le.absolutely_continuous
alias absolutely_continuous_of_eq ← eq.absolutely_continuous
namespace absolutely_continuous
lemma mk (h : ∀ ⦃s : set α⦄, measurable_set s → ν s = 0 → μ s = 0) : μ ≪ ν :=
begin
intros s hs,
rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩,
exact measure_mono_null h1t (h h2t h3t),
end
@[refl] protected lemma refl (μ : measure α) : μ ≪ μ := rfl.absolutely_continuous
protected lemma rfl : μ ≪ μ := λ s hs, hs
@[trans] protected lemma trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ :=
λ s hs, h1 $ h2 hs
@[mono] protected lemma map (h : μ ≪ ν) (f : α → β) : map f μ ≪ map f ν :=
if hf : measurable f then absolutely_continuous.mk $ λ s hs, by simpa [hf, hs] using @h _
else by simp only [map_of_not_measurable hf]
end absolutely_continuous
lemma ae_le_iff_absolutely_continuous : μ.ae ≤ ν.ae ↔ μ ≪ ν :=
⟨λ h s, by { rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem], exact λ hs, h hs },
λ h s hs, h hs⟩
alias ae_le_iff_absolutely_continuous ↔ has_le.le.absolutely_continuous_of_ae
measure_theory.measure.absolutely_continuous.ae_le
alias absolutely_continuous.ae_le ← ae_mono'
lemma absolutely_continuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g :=
h.ae_le h'
/-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/
/-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures
`μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/
@[protect_proj]
structure quasi_measure_preserving (f : α → β) (μa : measure α . volume_tac)
(μb : measure β . volume_tac) : Prop :=
(measurable : measurable f)
(absolutely_continuous : map f μa ≪ μb)
namespace quasi_measure_preserving
protected lemma id (μ : measure α) : quasi_measure_preserving id μ μ :=
⟨measurable_id, map_id.absolutely_continuous⟩
variables {μa μa' : measure α} {μb μb' : measure β} {μc : measure γ} {f : α → β}
lemma mono_left (h : quasi_measure_preserving f μa μb)
(ha : μa' ≪ μa) : quasi_measure_preserving f μa' μb :=
⟨h.1, (ha.map f).trans h.2⟩
lemma mono_right (h : quasi_measure_preserving f μa μb)
(ha : μb ≪ μb') : quasi_measure_preserving f μa μb' :=
⟨h.1, h.2.trans ha⟩
@[mono] lemma mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : quasi_measure_preserving f μa μb) :
quasi_measure_preserving f μa' μb' :=
(h.mono_left ha).mono_right hb
protected lemma comp {g : β → γ} {f : α → β} (hg : quasi_measure_preserving g μb μc)
(hf : quasi_measure_preserving f μa μb) :
quasi_measure_preserving (g ∘ f) μa μc :=
⟨hg.measurable.comp hf.measurable, by { rw ← map_map hg.1 hf.1, exact (hf.2.map g).trans hg.2 }⟩
protected lemma iterate {f : α → α} (hf : quasi_measure_preserving f μa μa) :
∀ n, quasi_measure_preserving (f^[n]) μa μa
| 0 := quasi_measure_preserving.id μa
| (n + 1) := (iterate n).comp hf
lemma ae_map_le (h : quasi_measure_preserving f μa μb) : (map f μa).ae ≤ μb.ae :=
h.2.ae_le
lemma tendsto_ae (h : quasi_measure_preserving f μa μb) : tendsto f μa.ae μb.ae :=
(tendsto_ae_map h.1).mono_right h.ae_map_le
lemma ae (h : quasi_measure_preserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) :
∀ᵐ x ∂μa, p (f x) :=
h.tendsto_ae hg
lemma ae_eq (h : quasi_measure_preserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) :
g₁ ∘ f =ᵐ[μa] g₂ ∘ f :=
h.ae hg
end quasi_measure_preserving
/-! ### The `cofinite` filter -/
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite (μ : measure α) : filter α :=
{ sets := {s | μ sᶜ < ∞},
univ_sets := by simp,
inter_sets := λ s t hs ht, by { simp only [compl_inter, mem_set_of_eq],
calc μ (sᶜ ∪ tᶜ) ≤ μ sᶜ + μ tᶜ : measure_union_le _ _
... < ∞ : ennreal.add_lt_top.2 ⟨hs, ht⟩ },
sets_of_superset := λ s t hs hst, lt_of_le_of_lt (measure_mono $ compl_subset_compl.2 hst) hs }
lemma mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := iff.rfl
lemma compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ :=
by rw [mem_cofinite, compl_compl]
lemma eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ {x | ¬p x} < ∞ := iff.rfl
end measure
open measure
@[simp] lemma ae_eq_bot : μ.ae = ⊥ ↔ μ = 0 :=
by rw [← empty_in_sets_eq_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
@[simp] lemma ae_ne_bot : μ.ae.ne_bot ↔ μ ≠ 0 :=
ne_bot_iff.trans (not_congr ae_eq_bot)
@[simp] lemma ae_zero : (0 : measure α).ae = ⊥ := ae_eq_bot.2 rfl
@[mono] lemma ae_mono {μ ν : measure α} (h : μ ≤ ν) : μ.ae ≤ ν.ae :=
h.absolutely_continuous.ae_le
lemma mem_ae_map_iff {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
s ∈ (map f μ).ae ↔ (f ⁻¹' s) ∈ μ.ae :=
by simp only [mem_ae_iff, map_apply hf hs.compl, preimage_compl]
lemma mem_ae_of_mem_ae_map {f : α → β} (hf : measurable f) {s : set β} (hs : s ∈ (map f μ).ae) :
f ⁻¹' s ∈ μ.ae :=
begin
apply le_antisymm _ bot_le,
calc μ (f ⁻¹' sᶜ) ≤ (map f μ) sᶜ : le_map_apply hf sᶜ
... = 0 : hs
end
lemma ae_map_iff {f : α → β} (hf : measurable f) {p : β → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ y ∂ (map f μ), p y) ↔ ∀ᵐ x ∂ μ, p (f x) :=
mem_ae_map_iff hf hp
lemma ae_of_ae_map {f : α → β} (hf : measurable f) {p : β → Prop} (h : ∀ᵐ y ∂ (map f μ), p y) :
∀ᵐ x ∂ μ, p (f x) :=
mem_ae_of_mem_ae_map hf h
lemma ae_map_mem_range (f : α → β) (hf : measurable_set (range f)) (μ : measure α) :
∀ᵐ x ∂(map f μ), x ∈ range f :=
begin
by_cases h : measurable f,
{ change range f ∈ (map f μ).ae,
rw mem_ae_map_iff h hf,
apply eventually_of_forall,
exact mem_range_self },
{ simp [map_of_not_measurable h] }
end
lemma ae_restrict_iff {p : α → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff, ← compl_set_of, restrict_apply hp.compl],
congr' with x, simp [and_comm]
end
lemma ae_imp_of_ae_restrict {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂(μ.restrict s), p x) :
∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff] at h ⊢,
simpa [set_of_and, inter_comm] using measure_inter_eq_zero_of_restrict h
end
lemma ae_restrict_iff' {s : set α} {p : α → Prop} (hs : measurable_set s) :
(∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff, ← compl_set_of, restrict_apply_eq_zero' hs],
congr' with x, simp [and_comm]
end
lemma ae_restrict_mem {s : set α} (hs : measurable_set s) :
∀ᵐ x ∂(μ.restrict s), x ∈ s :=
(ae_restrict_iff' hs).2 (filter.eventually_of_forall (λ x, id))
lemma ae_restrict_of_ae {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) :
(∀ᵐ x ∂(μ.restrict s), p x) :=
eventually.filter_mono (ae_mono measure.restrict_le_self) h
lemma ae_restrict_of_ae_restrict_of_subset {s t : set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂(μ.restrict t), p x) :
(∀ᵐ x ∂(μ.restrict s), p x) :=
h.filter_mono (ae_mono $ measure.restrict_mono hst (le_refl μ))
lemma ae_smul_measure {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) (c : ℝ≥0∞) : ∀ᵐ x ∂(c • μ), p x :=
ae_iff.2 $ by rw [smul_apply, ae_iff.1 h, mul_zero]
lemma ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) :
(∀ᵐ x ∂(c • μ), p x) ↔ ∀ᵐ x ∂μ, p x :=
by simp [ae_iff, hc]
lemma ae_add_measure_iff {p : α → Prop} {ν} : (∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero_iff
lemma ae_eq_comp' {ν : measure β} {f : α → β} {g g' : β → δ} (hf : measurable f)
(h : g =ᵐ[ν] g') (h2 : map f μ ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(quasi_measure_preserving.mk hf h2).ae_eq h
lemma ae_eq_comp {f : α → β} {g g' : β → δ} (hf : measurable f)
(h : g =ᵐ[measure.map f μ] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h absolutely_continuous.rfl
lemma le_ae_restrict : μ.ae ⊓ 𝓟 s ≤ (μ.restrict s).ae :=
λ s hs, eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
@[simp] lemma ae_restrict_eq (hs : measurable_set s) : (μ.restrict s).ae = μ.ae ⊓ 𝓟 s :=
begin
ext t,
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_set_of,
not_imp, and_comm (_ ∈ s)],
refl
end
@[simp] lemma ae_restrict_eq_bot {s} : (μ.restrict s).ae = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
@[simp] lemma ae_restrict_ne_bot {s} : (μ.restrict s).ae.ne_bot ↔ 0 < μ s :=
ne_bot_iff.trans $ (not_congr ae_restrict_eq_bot).trans pos_iff_ne_zero.symm
lemma self_mem_ae_restrict {s} (hs : measurable_set s) : s ∈ (μ.restrict s).ae :=
by simp only [ae_restrict_eq hs, exists_prop, mem_principal_sets, mem_inf_sets];
exact ⟨_, univ_mem_sets, s, by rw [univ_inter, and_self]⟩
/-- A version of the Borel-Cantelli lemma: if `sᵢ` is a sequence of measurable sets such that
`∑ μ sᵢ` exists, then for almost all `x`, `x` does not belong to almost all `sᵢ`. -/
lemma ae_eventually_not_mem {s : ℕ → set α} (hs : ∀ i, measurable_set (s i))
(hs' : ∑' i, μ (s i) ≠ ∞) : ∀ᵐ x ∂ μ, ∀ᶠ n in at_top, x ∉ s n :=
begin
refine measure_mono_null _ (measure_limsup_eq_zero hs hs'),
rw ←set.le_eq_subset,
refine le_Inf (λ t ht x hx, _),
simp only [le_eq_subset, not_exists, eventually_map, exists_prop, ge_iff_le, mem_set_of_eq,
eventually_at_top, mem_compl_eq, not_forall, not_not_mem] at hx ht,
rcases ht with ⟨i, hi⟩,
rcases hx i with ⟨j, ⟨hj, hj'⟩⟩,
exact hi j hj hj'
end
lemma mem_ae_dirac_iff {a : α} (hs : measurable_set s) : s ∈ (dirac a).ae ↔ a ∈ s :=
by by_cases a ∈ s; simp [mem_ae_iff, dirac_apply', hs.compl, indicator_apply, *]
lemma ae_dirac_iff {a : α} {p : α → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ x ∂(dirac a), p x) ↔ p a :=
mem_ae_dirac_iff hp
@[simp] lemma ae_dirac_eq [measurable_singleton_class α] (a : α) : (dirac a).ae = pure a :=
by { ext s, simp [mem_ae_iff, imp_false] }
lemma ae_eq_dirac' [measurable_singleton_class β] {a : α} {f : α → β} (hf : measurable f) :
f =ᵐ[dirac a] const α (f a) :=
(ae_dirac_iff $ show measurable_set (f ⁻¹' {f a}), from hf $ measurable_set_singleton _).2 rfl
lemma ae_eq_dirac [measurable_singleton_class α] {a : α} (f : α → δ) :
f =ᵐ[dirac a] const α (f a) :=
by simp [filter.eventually_eq]
lemma restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
begin
intros u hu,
simp only [restrict_apply hu],
exact measure_mono_ae (h.mono $ λ x hx, and.imp id hx)
end
lemma restrict_congr_set (H : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae H.le) (restrict_mono_ae H.symm.le)
section finite_measure
/-- A measure `μ` is called finite if `μ univ < ∞`. -/
class finite_measure (μ : measure α) : Prop := (measure_univ_lt_top : μ univ < ∞)
instance restrict.finite_measure (μ : measure α) [hs : fact (μ s < ∞)] :
finite_measure (μ.restrict s) :=
⟨by simp [hs.elim]⟩
lemma measure_lt_top (μ : measure α) [finite_measure μ] (s : set α) : μ s < ∞ :=
(measure_mono (subset_univ s)).trans_lt finite_measure.measure_univ_lt_top
lemma measure_ne_top (μ : measure α) [finite_measure μ] (s : set α) : μ s ≠ ∞ :=
ne_of_lt (measure_lt_top μ s)
/-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/
def measure_univ_nnreal (μ : measure α) : ℝ≥0 := (μ univ).to_nnreal
@[simp] lemma coe_measure_univ_nnreal (μ : measure α) [finite_measure μ] :
↑(measure_univ_nnreal μ) = μ univ :=
ennreal.coe_to_nnreal (measure_ne_top μ univ)
instance finite_measure_zero : finite_measure (0 : measure α) := ⟨by simp⟩
instance finite_measure_add [finite_measure μ] [finite_measure ν] : finite_measure (μ + ν) :=
{ measure_univ_lt_top :=
begin
rw [measure.coe_add, pi.add_apply, ennreal.add_lt_top],
exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩,
end }
instance finite_measure_smul_nnreal [finite_measure μ] {r : ℝ≥0} : finite_measure (r • μ) :=
{ measure_univ_lt_top := ennreal.mul_lt_top ennreal.coe_lt_top (measure_lt_top _ _) }
@[simp] lemma measure_univ_nnreal_zero : measure_univ_nnreal (0 : measure α) = 0 := rfl
@[simp] lemma measure_univ_nnreal_eq_zero [finite_measure μ] : measure_univ_nnreal μ = 0 ↔ μ = 0 :=
begin
rw [← measure_theory.measure.measure_univ_eq_zero, ← coe_measure_univ_nnreal],
norm_cast
end
lemma measure_univ_nnreal_pos [finite_measure μ] (hμ : μ ≠ 0) : 0 < measure_univ_nnreal μ :=
begin
contrapose! hμ,
simpa [measure_univ_nnreal_eq_zero, le_zero_iff] using hμ
end
/-- `le_of_add_le_add_left` is normally applicable to `ordered_cancel_add_comm_monoid`,
but it holds for measures with the additional assumption that μ is finite. -/
lemma measure.le_of_add_le_add_left {μ ν₁ ν₂ : measure α} [finite_measure μ]
(A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ :=
λ S B1, ennreal.le_of_add_le_add_left (measure_theory.measure_lt_top μ S) (A2 S B1)
lemma summable_measure_to_real [hμ : finite_measure μ]
{f : ℕ → set α} (hf₁ : ∀ (i : ℕ), measurable_set (f i)) (hf₂ : pairwise (disjoint on f)) :
summable (λ x, (μ (f x)).to_real) :=
begin
apply ennreal.summable_to_real,
rw ← measure_theory.measure_Union hf₂ hf₁,
exact ne_of_lt (measure_lt_top _ _)
end
end finite_measure
section probability_measure
/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/
class probability_measure (μ : measure α) : Prop := (measure_univ : μ univ = 1)
export probability_measure (measure_univ)
instance measure.dirac.probability_measure {x : α} : probability_measure (dirac x) :=
⟨dirac_apply_of_mem $ mem_univ x⟩
@[priority 100]
instance probability_measure.to_finite_measure (μ : measure α) [probability_measure μ] :
finite_measure μ :=
⟨by simp only [measure_univ, ennreal.one_lt_top]⟩
lemma probability_measure.ne_zero (μ : measure α) [probability_measure μ] : μ ≠ 0 :=
mt measure_univ_eq_zero.2 $ by simp [measure_univ]
lemma prob_add_prob_compl [probability_measure μ]
(h : measurable_set s) : μ s + μ sᶜ = 1 :=
(measure_add_measure_compl h).trans measure_univ
lemma prob_le_one [probability_measure μ] : μ s ≤ 1 :=
(measure_mono $ set.subset_univ _).trans_eq measure_univ
end probability_measure
section no_atoms
/-- Measure `μ` *has no atoms* if the measure of each singleton is zero.
NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure,
there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`,
the converse is not true. -/
class has_no_atoms (μ : measure α) : Prop :=
(measure_singleton : ∀ x, μ {x} = 0)
export has_no_atoms (measure_singleton)
attribute [simp] measure_singleton
variables [has_no_atoms μ]
lemma measure_subsingleton (hs : s.subsingleton) : μ s = 0 :=
hs.induction_on measure_empty measure_singleton
alias measure_subsingleton ← set.subsingleton.measure_eq
@[simp] lemma measure.restrict_singleton' {a : α} :
μ.restrict {a} = 0 :=
by simp only [measure_singleton, measure.restrict_eq_zero]
instance (s : set α) : has_no_atoms (μ.restrict s) :=
begin
refine ⟨λ x, _⟩,
obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0),
apply measure_mono_null hxt,
rw measure.restrict_apply ht1,
apply measure_mono_null (inter_subset_left t s) ht2
end
lemma _root_.set.countable.measure_zero (h : countable s) : μ s = 0 :=
begin
rw [← bUnion_of_singleton s, ← nonpos_iff_eq_zero],
refine le_trans (measure_bUnion_le h _) _,
simp
end
lemma _root_.set.finite.measure_zero (h : s.finite) : μ s = 0 :=
h.countable.measure_zero
lemma _root_.finset.measure_zero (s : finset α) : μ ↑s = 0 :=
s.finite_to_set.measure_zero
lemma insert_ae_eq_self (a : α) (s : set α) :
(insert a s : set α) =ᵐ[μ] s :=
union_ae_eq_right.2 $ measure_mono_null (diff_subset _ _) (measure_singleton _)
variables [partial_order α] {a b : α}
lemma Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a :=
by simp only [← Iic_diff_right, diff_ae_eq_self,
measure_mono_null (set.inter_subset_right _ _) (measure_singleton a)]
lemma Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a :=
@Iio_ae_eq_Iic (order_dual α) ‹_› ‹_› _ _ _
lemma Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b :=
(ae_eq_refl _).inter Iio_ae_eq_Iic
lemma Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b :=
Ioi_ae_eq_Ici.inter (ae_eq_refl _)
lemma Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b :=
Ioi_ae_eq_Ici.inter (ae_eq_refl _)
lemma Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b :=
Ioi_ae_eq_Ici.inter Iio_ae_eq_Iic
lemma Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b :=
(ae_eq_refl _).inter Iio_ae_eq_Iic
lemma Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b :=
Ioo_ae_eq_Ico.symm.trans Ioo_ae_eq_Ioc
end no_atoms
lemma ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ s = 0) :
(λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g :=
begin
have h_ss : sᶜ ⊆ {a : α | ite (a ∈ s) (f a) (g a) = g a},
from λ x hx, by simp [(set.mem_compl_iff _ _).mp hx],
refine measure_mono_null _ hs_zero,
nth_rewrite 0 ←compl_compl s,
rwa set.compl_subset_compl,
end
lemma ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ sᶜ = 0) :
(λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f :=
by { filter_upwards [hs_zero], intros, split_ifs, refl }
namespace measure
/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.
Equivalently, it is eventually finite at `s` in `f.lift' powerset`. -/
def finite_at_filter (μ : measure α) (f : filter α) : Prop := ∃ s ∈ f, μ s < ∞
lemma finite_at_filter_of_finite (μ : measure α) [finite_measure μ] (f : filter α) :
μ.finite_at_filter f :=
⟨univ, univ_mem_sets, measure_lt_top μ univ⟩
lemma finite_at_filter.exists_mem_basis {μ : measure α} {f : filter α} (hμ : finite_at_filter μ f)
{p : ι → Prop} {s : ι → set α} (hf : f.has_basis p s) :
∃ i (hi : p i), μ (s i) < ∞ :=
(hf.exists_iff (λ s t hst ht, (measure_mono hst).trans_lt ht)).1 hμ
lemma finite_at_bot (μ : measure α) : μ.finite_at_filter ⊥ :=
⟨∅, mem_bot_sets, by simp only [measure_empty, with_top.zero_lt_top]⟩
/-- `μ` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have
finite measures. This structure is a type, which is useful if we want to record extra properties
about the sets, such as that they are monotone.
`sigma_finite` is defined in terms of this: `μ` is σ-finite if there exists a sequence of
finite spanning sets in the collection of all measurable sets. -/
@[protect_proj, nolint has_inhabited_instance]
structure finite_spanning_sets_in (μ : measure α) (C : set (set α)) :=
(set : ℕ → set α)
(set_mem : ∀ i, set i ∈ C)
(finite : ∀ i, μ (set i) < ∞)
(spanning : (⋃ i, set i) = univ)
end measure
open measure
/-- A measure `μ` is called σ-finite if there is a countable collection of sets
`{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/
class sigma_finite (μ : measure α) : Prop :=
(out' : nonempty (μ.finite_spanning_sets_in {s | measurable_set s}))
theorem sigma_finite_iff {μ : measure α} : sigma_finite μ ↔
nonempty (μ.finite_spanning_sets_in {s | measurable_set s}) :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem sigma_finite.out {μ : measure α} (h : sigma_finite μ) :
nonempty (μ.finite_spanning_sets_in {s | measurable_set s}) := h.1
/-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/
def measure.to_finite_spanning_sets_in (μ : measure α) [h : sigma_finite μ] :
μ.finite_spanning_sets_in {s | measurable_set s} :=
classical.choice h.out
/-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite
measure using `classical.some`. This definition satisfies monotonicity in addition to all other
properties in `sigma_finite`. -/
def spanning_sets (μ : measure α) [sigma_finite μ] (i : ℕ) : set α :=
accumulate μ.to_finite_spanning_sets_in.set i
lemma monotone_spanning_sets (μ : measure α) [sigma_finite μ] :
monotone (spanning_sets μ) :=
monotone_accumulate
lemma measurable_spanning_sets (μ : measure α) [sigma_finite μ] (i : ℕ) :
measurable_set (spanning_sets μ i) :=
measurable_set.Union $ λ j, measurable_set.Union_Prop $
λ hij, μ.to_finite_spanning_sets_in.set_mem j
lemma measure_spanning_sets_lt_top (μ : measure α) [sigma_finite μ] (i : ℕ) :
μ (spanning_sets μ i) < ∞ :=
measure_bUnion_lt_top (finite_le_nat i) $ λ j _, μ.to_finite_spanning_sets_in.finite j
lemma Union_spanning_sets (μ : measure α) [sigma_finite μ] :
(⋃ i : ℕ, spanning_sets μ i) = univ :=
by simp_rw [spanning_sets, Union_accumulate, μ.to_finite_spanning_sets_in.spanning]
lemma is_countably_spanning_spanning_sets (μ : measure α) [sigma_finite μ] :
is_countably_spanning (range (spanning_sets μ)) :=
⟨spanning_sets μ, mem_range_self, Union_spanning_sets μ⟩
namespace measure
lemma supr_restrict_spanning_sets [sigma_finite μ] (hs : measurable_set s) :
(⨆ i, μ.restrict (spanning_sets μ i) s) = μ s :=
begin
convert (restrict_Union_apply_eq_supr (measurable_spanning_sets μ) _ hs).symm,
{ simp [Union_spanning_sets] },
{ exact directed_of_sup (monotone_spanning_sets μ) }
end
namespace finite_spanning_sets_in
variables {C D : set (set α)}
/-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/
protected def mono (h : μ.finite_spanning_sets_in C) (hC : C ⊆ D) : μ.finite_spanning_sets_in D :=
⟨h.set, λ i, hC (h.set_mem i), h.finite, h.spanning⟩
/-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite.
-/
protected lemma sigma_finite (h : μ.finite_spanning_sets_in C) (hC : ∀ s ∈ C, measurable_set s) :
sigma_finite μ :=
⟨⟨h.mono hC⟩⟩
/-- An extensionality for measures. It is `ext_of_generate_from_of_Union` formulated in terms of
`finite_spanning_sets_in`. -/
protected lemma ext {ν : measure α} {C : set (set α)} (hA : ‹_› = generate_from C)
(hC : is_pi_system C) (h : μ.finite_spanning_sets_in C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
ext_of_generate_from_of_Union C _ hA hC h.spanning h.set_mem h.finite h_eq
protected lemma is_countably_spanning (h : μ.finite_spanning_sets_in C) : is_countably_spanning C :=
⟨_, h.set_mem, h.spanning⟩
end finite_spanning_sets_in
lemma sigma_finite_of_not_nonempty (μ : measure α) (hα : ¬ nonempty α) : sigma_finite μ :=
⟨⟨⟨λ _, ∅, λ n, measurable_set.empty, λ n, by simp, by simp [eq_empty_of_not_nonempty hα univ]⟩⟩⟩
lemma sigma_finite_of_countable {S : set (set α)} (hc : countable S)
(hμ : ∀ s ∈ S, μ s < ∞) (hU : ⋃₀ S = univ) :
sigma_finite μ :=
begin
obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → set α, (∀ n, μ (s n) < ∞) ∧ (⋃ n, s n) = univ,
from (exists_seq_cover_iff_countable ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩,
refine ⟨⟨⟨λ n, to_measurable μ (s n), λ n, measurable_set_to_measurable _ _, by simpa, _⟩⟩⟩,
exact eq_univ_of_subset (Union_subset_Union $ λ n, subset_to_measurable μ (s n)) hs
end
end measure
/-- Every finite measure is σ-finite. -/
@[priority 100]
instance finite_measure.to_sigma_finite (μ : measure α) [finite_measure μ] : sigma_finite μ :=
⟨⟨⟨λ _, univ, λ _, measurable_set.univ, λ _, measure_lt_top μ _, Union_const _⟩⟩⟩
instance restrict.sigma_finite (μ : measure α) [sigma_finite μ] (s : set α) :
sigma_finite (μ.restrict s) :=
begin
refine ⟨⟨⟨spanning_sets μ, measurable_spanning_sets μ, λ i, _, Union_spanning_sets μ⟩⟩⟩,
rw [restrict_apply (measurable_spanning_sets μ i)],
exact (measure_mono $ inter_subset_left _ _).trans_lt (measure_spanning_sets_lt_top μ i)
end
instance sum.sigma_finite {ι} [fintype ι] (μ : ι → measure α) [∀ i, sigma_finite (μ i)] :
sigma_finite (sum μ) :=
begin
haveI : encodable ι := fintype.encodable ι,
have : ∀ n, measurable_set (⋂ (i : ι), spanning_sets (μ i) n) :=
λ n, measurable_set.Inter (λ i, measurable_spanning_sets (μ i) n),
refine ⟨⟨⟨λ n, ⋂ i, spanning_sets (μ i) n, this, λ n, _, _⟩⟩⟩,
{ rw [sum_apply _ (this n), tsum_fintype, ennreal.sum_lt_top_iff],
rintro i -,
exact (measure_mono $ Inter_subset _ i).trans_lt (measure_spanning_sets_lt_top (μ i) n) },
{ rw [Union_Inter_of_monotone], simp_rw [Union_spanning_sets, Inter_univ],
exact λ i, monotone_spanning_sets (μ i), }
end
instance add.sigma_finite (μ ν : measure α) [sigma_finite μ] [sigma_finite ν] :
sigma_finite (μ + ν) :=
by { rw [← sum_cond], refine @sum.sigma_finite _ _ _ _ _ (bool.rec _ _); simpa }
lemma sigma_finite.of_map (μ : measure α) {f : α → β} (hf : measurable f)
(h : sigma_finite (map f μ)) :
sigma_finite μ :=
⟨⟨⟨λ n, f ⁻¹' (spanning_sets (map f μ) n),
λ n, hf $ measurable_spanning_sets _ _,
λ n, by simp only [← map_apply hf, measurable_spanning_sets, measure_spanning_sets_lt_top],
by rw [← preimage_Union, Union_spanning_sets, preimage_univ]⟩⟩⟩
/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/
class locally_finite_measure [topological_space α] (μ : measure α) : Prop :=
(finite_at_nhds : ∀ x, μ.finite_at_filter (𝓝 x))
@[priority 100] -- see Note [lower instance priority]
instance finite_measure.to_locally_finite_measure [topological_space α] (μ : measure α)
[finite_measure μ] :
locally_finite_measure μ :=
⟨λ x, finite_at_filter_of_finite _ _⟩
lemma measure.finite_at_nhds [topological_space α] (μ : measure α)
[locally_finite_measure μ] (x : α) :
μ.finite_at_filter (𝓝 x) :=
locally_finite_measure.finite_at_nhds x
lemma measure.smul_finite {α : Type*} [measurable_space α] (μ : measure α) [finite_measure μ]
{c : ℝ≥0∞} (hc : c < ∞) :
finite_measure (c • μ) :=
begin
refine ⟨_⟩,
rw measure.smul_apply,
exact ennreal.mul_lt_top hc (measure_lt_top μ set.univ),
end
lemma measure.exists_is_open_measure_lt_top [topological_space α] (μ : measure α)
[locally_finite_measure μ] (x : α) :
∃ s : set α, x ∈ s ∧ is_open s ∧ μ s < ∞ :=
by simpa only [exists_prop, and.assoc]
using (μ.finite_at_nhds x).exists_mem_basis (nhds_basis_opens x)
@[priority 100] -- see Note [lower instance priority]
instance sigma_finite_of_locally_finite [topological_space α]
[topological_space.second_countable_topology α]
{μ : measure α} [locally_finite_measure μ] :
sigma_finite μ :=
begin
choose s hsx hsμ using μ.finite_at_nhds,
rcases topological_space.countable_cover_nhds hsx with ⟨t, htc, htU⟩,
refine measure.sigma_finite_of_countable (htc.image s) (ball_image_iff.2 $ λ x hx, hsμ x) _,
rwa sUnion_image
end
/-- If two finite measures give the same mass to the whole space and coincide on a π-system made
of measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/
lemma ext_on_measurable_space_of_generate_finite {α} (m₀ : measurable_space α)
{μ ν : measure α} [finite_measure μ]
(C : set (set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : measurable_space α}
(h : m ≤ m₀) (hA : m = measurable_space.generate_from C) (hC : is_pi_system C)
(h_univ : μ set.univ = ν set.univ) {s : set α} (hs : m.measurable_set' s) :
μ s = ν s :=
begin
haveI : @finite_measure _ m₀ ν := begin
constructor,
rw ← h_univ,
apply finite_measure.measure_univ_lt_top,
end,
refine induction_on_inter hA hC (by simp) hμν _ _ hs,
{ intros t h1t h2t,
have h1t_ : @measurable_set α m₀ t, from h _ h1t,
rw [@measure_compl α m₀ μ t h1t_ (@measure_lt_top α m₀ μ _ t),
@measure_compl α m₀ ν t h1t_ (@measure_lt_top α m₀ ν _ t), h_univ, h2t], },
{ intros f h1f h2f h3f,
have h2f_ : ∀ (i : ℕ), @measurable_set α m₀ (f i), from (λ i, h _ (h2f i)),
have h_Union : @measurable_set α m₀ (⋃ (i : ℕ), f i),from @measurable_set.Union α ℕ m₀ _ f h2f_,
simp [measure_Union, h_Union, h1f, h3f, h2f_], },
end
/-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra
(and `univ`). -/
lemma ext_of_generate_finite (C : set (set α)) (hA : _inst_1 = generate_from C)
(hC : is_pi_system C) {μ ν : measure α} [finite_measure μ]
(hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) :
μ = ν :=
measure.ext (λ s hs,
ext_on_measurable_space_of_generate_finite _inst_1 C hμν (le_refl _inst_1) hA hC h_univ hs)
namespace measure
namespace finite_at_filter
variables {f g : filter α}
lemma filter_mono (h : f ≤ g) : μ.finite_at_filter g → μ.finite_at_filter f :=
λ ⟨s, hs, hμ⟩, ⟨s, h hs, hμ⟩
lemma inf_of_left (h : μ.finite_at_filter f) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_left
lemma inf_of_right (h : μ.finite_at_filter g) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_right
@[simp] lemma inf_ae_iff : μ.finite_at_filter (f ⊓ μ.ae) ↔ μ.finite_at_filter f :=
begin
refine ⟨_, λ h, h.filter_mono inf_le_left⟩,
rintros ⟨s, ⟨t, ht, u, hu, hs⟩, hμ⟩,
suffices : μ t ≤ μ s, from ⟨t, ht, this.trans_lt hμ⟩,
exact measure_mono_ae (mem_sets_of_superset hu (λ x hu ht, hs ⟨ht, hu⟩))
end
alias inf_ae_iff ↔ measure_theory.measure.finite_at_filter.of_inf_ae _
lemma filter_mono_ae (h : f ⊓ μ.ae ≤ g) (hg : μ.finite_at_filter g) : μ.finite_at_filter f :=
inf_ae_iff.1 (hg.filter_mono h)
protected lemma measure_mono (h : μ ≤ ν) : ν.finite_at_filter f → μ.finite_at_filter f :=
λ ⟨s, hs, hν⟩, ⟨s, hs, (measure.le_iff'.1 h s).trans_lt hν⟩
@[mono] protected lemma mono (hf : f ≤ g) (hμ : μ ≤ ν) :
ν.finite_at_filter g → μ.finite_at_filter f :=
λ h, (h.filter_mono hf).measure_mono hμ
protected lemma eventually (h : μ.finite_at_filter f) : ∀ᶠ s in f.lift' powerset, μ s < ∞ :=
(eventually_lift'_powerset' $ λ s t hst ht, (measure_mono hst).trans_lt ht).2 h
lemma filter_sup : μ.finite_at_filter f → μ.finite_at_filter g → μ.finite_at_filter (f ⊔ g) :=
λ ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩,
⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ennreal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩
end finite_at_filter
lemma finite_at_nhds_within [topological_space α] (μ : measure α) [locally_finite_measure μ]
(x : α) (s : set α) :
μ.finite_at_filter (𝓝[s] x) :=
(finite_at_nhds μ x).inf_of_left
@[simp] lemma finite_at_principal : μ.finite_at_filter (𝓟 s) ↔ μ s < ∞ :=
⟨λ ⟨t, ht, hμ⟩, (measure_mono ht).trans_lt hμ, λ h, ⟨s, mem_principal_self s, h⟩⟩
/-! ### Subtraction of measures -/
/-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`.
It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures.
Compare with `ennreal.has_sub`.
Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and
`ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and
`ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/
noncomputable instance has_sub {α : Type*} [measurable_space α] : has_sub (measure α) :=
⟨λ μ ν, Inf {τ | μ ≤ τ + ν} ⟩
section measure_sub
lemma sub_def : μ - ν = Inf {d | μ ≤ d + ν} := rfl
lemma sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 :=
begin
rw [← nonpos_iff_eq_zero', measure.sub_def],
apply @Inf_le (measure α) _ _,
simp [h],
end
/-- This application lemma only works in special circumstances. Given knowledge of
when `μ ≤ ν` and `ν ≤ μ`, a more general application lemma can be written. -/
lemma sub_apply [finite_measure ν] (h₁ : measurable_set s) (h₂ : ν ≤ μ) : (μ - ν) s = μ s - ν s :=
begin
-- We begin by defining `measure_sub`, which will be equal to `(μ - ν)`.
let measure_sub : measure α := @measure_theory.measure.of_measurable α _
(λ (t : set α) (h_t_measurable_set : measurable_set t), (μ t - ν t))
begin
simp
end
begin
intros g h_meas h_disj, simp only, rw ennreal.tsum_sub,
repeat { rw ← measure_theory.measure_Union h_disj h_meas },
apply measure_theory.measure_lt_top, intro i, apply h₂, apply h_meas
end,
-- Now, we demonstrate `μ - ν = measure_sub`, and apply it.
begin
have h_measure_sub_add : (ν + measure_sub = μ),
{ ext t h_t_measurable_set,
simp only [pi.add_apply, coe_add],
rw [measure_theory.measure.of_measurable_apply _ h_t_measurable_set, add_comm,
ennreal.sub_add_cancel_of_le (h₂ t h_t_measurable_set)] },
have h_measure_sub_eq : (μ - ν) = measure_sub,
{ rw measure_theory.measure.sub_def, apply le_antisymm,
{ apply @Inf_le (measure α) measure.complete_semilattice_Inf,
simp [le_refl, add_comm, h_measure_sub_add] },
apply @le_Inf (measure α) measure.complete_semilattice_Inf,
intros d h_d, rw [← h_measure_sub_add, mem_set_of_eq, add_comm d] at h_d,
apply measure.le_of_add_le_add_left h_d },
rw h_measure_sub_eq,
apply measure.of_measurable_apply _ h₁,
end
end
lemma sub_add_cancel_of_le [finite_measure ν] (h₁ : ν ≤ μ) : μ - ν + ν = μ :=
begin
ext s h_s_meas,
rw [add_apply, sub_apply h_s_meas h₁, ennreal.sub_add_cancel_of_le (h₁ s h_s_meas)],
end
lemma sub_le : μ - ν ≤ μ :=
Inf_le (measure.le_add_right (le_refl _))
end measure_sub
lemma restrict_sub_eq_restrict_sub_restrict (h_meas_s : measurable_set s) :
(μ - ν).restrict s = (μ.restrict s) - (ν.restrict s) :=
begin
repeat {rw sub_def},
have h_nonempty : {d | μ ≤ d + ν}.nonempty,
{ apply @set.nonempty_of_mem _ _ μ, rw mem_set_of_eq, intros t h_meas,
exact le_self_add },
rw restrict_Inf_eq_Inf_restrict h_nonempty h_meas_s,
apply le_antisymm,
{ apply @Inf_le_Inf_of_forall_exists_le (measure α) _,
intros ν' h_ν'_in, rw mem_set_of_eq at h_ν'_in, apply exists.intro (ν'.restrict s),
split,
{ rw mem_image, apply exists.intro (ν' + (⊤ : measure_theory.measure α).restrict sᶜ),
rw mem_set_of_eq,
split,
{ rw [add_assoc, add_comm _ ν, ← add_assoc, measure_theory.measure.le_iff],
intros t h_meas_t,
have h_inter_inter_eq_inter : ∀ t' : set α , t ∩ t' ∩ t' = t ∩ t',
{ intro t', rw set.inter_eq_self_of_subset_left, apply set.inter_subset_right t t' },
have h_meas_t_inter_s : measurable_set (t ∩ s) :=
h_meas_t.inter h_meas_s,
repeat {rw measure_eq_inter_diff h_meas_t h_meas_s, rw set.diff_eq},
refine add_le_add _ _,
{ rw add_apply,
apply le_add_right _,
rw add_apply,
rw ← @restrict_eq_self _ _ μ s _ h_meas_t_inter_s (set.inter_subset_right _ _),
rw ← @restrict_eq_self _ _ ν s _ h_meas_t_inter_s (set.inter_subset_right _ _),
apply h_ν'_in _ h_meas_t_inter_s },
cases (@set.eq_empty_or_nonempty _ (t ∩ sᶜ)) with h_inter_empty h_inter_nonempty,
{ simp [h_inter_empty] },
{ rw add_apply,
have h_meas_inter_compl :=
h_meas_t.inter (measurable_set.compl h_meas_s),
rw [restrict_apply h_meas_inter_compl, h_inter_inter_eq_inter sᶜ],
have h_mu_le_add_top : μ ≤ ν' + ν + ⊤,
{ rw add_comm,
have h_le_top : μ ≤ ⊤ := le_top,
apply (λ t₂ h_meas, le_add_right (h_le_top t₂ h_meas)) },
apply h_mu_le_add_top _ h_meas_inter_compl } },
{ ext1 t h_meas_t,
simp [restrict_apply h_meas_t,
restrict_apply (h_meas_t.inter h_meas_s),
set.inter_assoc] } },
{ apply restrict_le_self } },
{ apply @Inf_le_Inf_of_forall_exists_le (measure α) _,
intros s h_s_in, cases h_s_in with t h_t, cases h_t with h_t_in h_t_eq, subst s,
apply exists.intro (t.restrict s), split,
{ rw [set.mem_set_of_eq, ← restrict_add],
apply restrict_mono (set.subset.refl _) h_t_in },
{ apply le_refl _ } },
end
lemma sub_apply_eq_zero_of_restrict_le_restrict
(h_le : μ.restrict s ≤ ν.restrict s) (h_meas_s : measurable_set s) :
(μ - ν) s = 0 :=
begin
rw [← restrict_apply_self _ h_meas_s, restrict_sub_eq_restrict_sub_restrict,
sub_eq_zero_of_le],
repeat {simp [*]},
end
instance finite_measure_sub [finite_measure μ] : finite_measure (μ - ν) :=
{ measure_univ_lt_top := lt_of_le_of_lt
(measure.sub_le set.univ measurable_set.univ) (measure_lt_top _ _) }
end measure
end measure_theory
open measure_theory measure_theory.measure
namespace measurable_equiv
/-! Interactions of measurable equivalences and measures -/
open equiv measure_theory.measure
variables [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β}
/-- If we map a measure along a measurable equivalence, we can compute the measure on all sets
(not just the measurable ones). -/
protected theorem map_apply (f : α ≃ᵐ β) (s : set β) : map f μ s = μ (f ⁻¹' s) :=
begin
refine le_antisymm _ (le_map_apply f.measurable s),
rw [measure_eq_infi' μ],
refine le_infi _, rintro ⟨t, hst, ht⟩,
rw [subtype.coe_mk],
have := f.symm.to_equiv.image_eq_preimage,
simp only [←coe_eq, symm_symm, symm_to_equiv] at this,
rw [← this, image_subset_iff] at hst,
convert measure_mono hst,
rw [map_apply, preimage_preimage],
{ refine congr_arg μ (eq.symm _), convert preimage_id, exact funext f.left_inv },
exacts [f.measurable, f.measurable_inv_fun ht]
end
@[simp] lemma map_symm_map (e : α ≃ᵐ β) : map e.symm (map e μ) = μ :=
by simp [map_map e.symm.measurable e.measurable]
@[simp] lemma map_map_symm (e : α ≃ᵐ β) : map e (map e.symm ν) = ν :=
by simp [map_map e.measurable e.symm.measurable]
lemma map_measurable_equiv_injective (e : α ≃ᵐ β) : injective (map e) :=
by { intros μ₁ μ₂ hμ, apply_fun map e.symm at hμ, simpa [map_symm_map e] using hμ }
lemma map_apply_eq_iff_map_symm_apply_eq (e : α ≃ᵐ β) : map e μ = ν ↔ map e.symm ν = μ :=
by rw [← (map_measurable_equiv_injective e).eq_iff, map_map_symm, eq_comm]
end measurable_equiv
section is_complete
/-- A measure is complete if every null set is also measurable.
A null set is a subset of a measurable set with measure `0`.
Since every measure is defined as a special case of an outer measure, we can more simply state
that a set `s` is null if `μ s = 0`. -/
class measure_theory.measure.is_complete {_ : measurable_space α} (μ : measure α) : Prop :=
(out' : ∀ s, μ s = 0 → measurable_set s)
theorem measure_theory.measure.is_complete_iff {_ : measurable_space α} {μ : measure α} :
μ.is_complete ↔ ∀ s, μ s = 0 → measurable_set s := ⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem measure_theory.measure.is_complete.out {_ : measurable_space α} {μ : measure α}
(h : μ.is_complete) : ∀ s, μ s = 0 → measurable_set s := h.1
variables [measurable_space α] {μ : measure α} {s t z : set α}
/-- A set is null measurable if it is the union of a null set and a measurable set. -/
def null_measurable_set (μ : measure α) (s : set α) : Prop :=
∃ t z, s = t ∪ z ∧ measurable_set t ∧ μ z = 0
theorem null_measurable_set_iff : null_measurable_set μ s ↔
∃ t, t ⊆ s ∧ measurable_set t ∧ μ (s \ t) = 0 :=
begin
split,
{ rintro ⟨t, z, rfl, ht, hz⟩,
refine ⟨t, set.subset_union_left _ _, ht, measure_mono_null _ hz⟩,
simp [union_diff_left, diff_subset] },
{ rintro ⟨t, st, ht, hz⟩,
exact ⟨t, _, (union_diff_cancel st).symm, ht, hz⟩ }
end
theorem null_measurable_set_measure_eq (st : t ⊆ s) (hz : μ (s \ t) = 0) : μ s = μ t :=
begin
refine le_antisymm _ (measure_mono st),
have := measure_union_le t (s \ t),
rw [union_diff_cancel st, hz] at this, simpa
end
theorem measurable_set.null_measurable_set (μ : measure α) (hs : measurable_set s) :
null_measurable_set μ s :=
⟨s, ∅, by simp, hs, μ.empty⟩
theorem null_measurable_set_of_complete (μ : measure α) [c : μ.is_complete] :
null_measurable_set μ s ↔ measurable_set s :=
⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact
measurable_set.union ht (c.out _ hz),
λ h, h.null_measurable_set _⟩
theorem null_measurable_set.union_null (hs : null_measurable_set μ s) (hz : μ z = 0) :
null_measurable_set μ (s ∪ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, nonpos_iff_eq_zero.1
(le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩
end
theorem null_null_measurable_set (hz : μ z = 0) : null_measurable_set μ z :=
by simpa using (measurable_set.empty.null_measurable_set _).union_null hz
theorem null_measurable_set.Union_nat {s : ℕ → set α} (hs : ∀ i, null_measurable_set μ (s i)) :
null_measurable_set μ (Union s) :=
begin
choose t ht using assume i, null_measurable_set_iff.1 (hs i),
simp [forall_and_distrib] at ht,
rcases ht with ⟨st, ht, hz⟩,
refine null_measurable_set_iff.2
⟨Union t, Union_subset_Union st, measurable_set.Union ht,
measure_mono_null _ (measure_Union_null hz)⟩,
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff)
end
theorem measurable_set.diff_null (hs : measurable_set s) (hz : μ z = 0) :
null_measurable_set μ (s \ z) :=
begin
rw measure_eq_infi at hz,
choose f hf using show ∀ q : {q : ℚ // q > 0}, ∃ t : set α,
z ⊆ t ∧ measurable_set t ∧ μ t < (real.to_nnreal q.1 : ℝ≥0∞),
{ rintro ⟨ε, ε0⟩,
have : 0 < (real.to_nnreal ε : ℝ≥0∞), { simpa using ε0 },
rw ← hz at this, simpa [infi_lt_iff] },
refine null_measurable_set_iff.2 ⟨s \ Inter f,
diff_subset_diff_right (subset_Inter (λ i, (hf i).1)),
hs.diff (measurable_set.Inter (λ i, (hf i).2.1)),
measure_mono_null _ (nonpos_iff_eq_zero.1 $ le_of_not_lt $ λ h, _)⟩,
{ exact Inter f },
{ rw [diff_subset_iff, diff_union_self],
exact subset.trans (diff_subset _ _) (subset_union_left _ _) },
rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨ε, ε0', ε0, h⟩,
simp at ε0,
apply not_le_of_lt (lt_trans (hf ⟨ε, ε0⟩).2.2 h),
exact measure_mono (Inter_subset _ _)
end
theorem null_measurable_set.diff_null (hs : null_measurable_set μ s) (hz : μ z = 0) :
null_measurable_set μ (s \ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
rw [set.union_diff_distrib],
exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz')
end
theorem null_measurable_set.compl (hs : null_measurable_set μ s) : null_measurable_set μ sᶜ :=
begin
rcases hs with ⟨t, z, rfl, ht, hz⟩,
rw compl_union,
exact ht.compl.diff_null hz
end
theorem null_measurable_set_iff_ae {s : set α} :
null_measurable_set μ s ↔ ∃ t, measurable_set t ∧ s =ᵐ[μ] t :=
begin
simp only [ae_eq_set],
split,
{ assume h,
rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,
refine ⟨t, tmeas, ht, _⟩,
rw [diff_eq_empty.2 ts, measure_empty] },
{ rintros ⟨t, tmeas, h₁, h₂⟩,
have : null_measurable_set μ (t ∪ (s \ t)) :=
null_measurable_set.union_null (tmeas.null_measurable_set _) h₁,
have A : null_measurable_set μ ((t ∪ (s \ t)) \ (t \ s)) :=
null_measurable_set.diff_null this h₂,
have : (t ∪ (s \ t)) \ (t \ s) = s,
{ apply subset.antisymm,
{ assume x hx,
simp only [mem_union_eq, not_and, mem_diff, not_not_mem] at hx,
cases hx.1, { exact hx.2 h }, { exact h.1 } },
{ assume x hx,
simp [hx, classical.em (x ∈ t)] } },
rwa this at A }
end
theorem null_measurable_set_iff_sandwich {s : set α} :
null_measurable_set μ s ↔
∃ (t u : set α), measurable_set t ∧ measurable_set u ∧ t ⊆ s ∧ s ⊆ u ∧ μ (u \ t) = 0 :=
begin
split,
{ assume h,
rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,
rcases null_measurable_set_iff.1 h.compl with ⟨u', u's, u'meas, hu'⟩,
have A : s ⊆ u'ᶜ := subset_compl_comm.mp u's,
refine ⟨t, u'ᶜ, tmeas, u'meas.compl, ts, A, _⟩,
have : sᶜ \ u' = u'ᶜ \ s, by simp [compl_eq_univ_diff, diff_diff, union_comm],
rw this at hu',
apply le_antisymm _ bot_le,
calc μ (u'ᶜ \ t) ≤ μ ((u'ᶜ \ s) ∪ (s \ t)) :
begin
apply measure_mono,
assume x hx,
simp at hx,
simp [hx, or_comm, classical.em],
end
... ≤ μ (u'ᶜ \ s) + μ (s \ t) : measure_union_le _ _
... = 0 : by rw [ht, hu', zero_add] },
{ rintros ⟨t, u, tmeas, umeas, ts, su, hμ⟩,
refine null_measurable_set_iff.2 ⟨t, ts, tmeas, _⟩,
apply le_antisymm _ bot_le,
calc μ (s \ t) ≤ μ (u \ t) : measure_mono (diff_subset_diff_left su)
... = 0 : hμ }
end
lemma restrict_apply_of_null_measurable_set {s t : set α}
(ht : null_measurable_set (μ.restrict s) t) : μ.restrict s t = μ (t ∩ s) :=
begin
rcases null_measurable_set_iff_sandwich.1 ht with ⟨u, v, umeas, vmeas, ut, tv, huv⟩,
apply le_antisymm _ (le_restrict_apply _ _),
calc μ.restrict s t ≤ μ.restrict s v : measure_mono tv
... = μ (v ∩ s) : restrict_apply vmeas
... ≤ μ ((u ∩ s) ∪ ((v \ u) ∩ s)) : measure_mono $
by { assume x hx, simp at hx, simp [hx, classical.em] }
... ≤ μ (u ∩ s) + μ ((v \ u) ∩ s) : measure_union_le _ _
... = μ (u ∩ s) + μ.restrict s (v \ u) : by rw measure.restrict_apply (vmeas.diff umeas)
... = μ (u ∩ s) : by rw [huv, add_zero]
... ≤ μ (t ∩ s) : measure_mono $ inter_subset_inter_left s ut
end
/-- The measurable space of all null measurable sets. -/
def null_measurable (μ : measure α) : measurable_space α :=
{ measurable_set' := null_measurable_set μ,
measurable_set_empty := measurable_set.empty.null_measurable_set _,
measurable_set_compl := λ s hs, hs.compl,
measurable_set_Union := λ f, null_measurable_set.Union_nat }
/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/
def completion (μ : measure α) : @measure_theory.measure α (null_measurable μ) :=
{ to_outer_measure := μ.to_outer_measure,
m_Union := λ s hs hd, show μ (Union s) = ∑' i, μ (s i), begin
choose t ht using assume i, null_measurable_set_iff.1 (hs i),
simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩,
rw null_measurable_set_measure_eq (Union_subset_Union st),
{ rw measure_Union _ ht,
{ congr, funext i,
exact (null_measurable_set_measure_eq (st i) (hz i)).symm },
{ rintro i j ij x ⟨h₁, h₂⟩,
exact hd i j ij ⟨st i h₁, st j h₂⟩ } },
{ refine measure_mono_null _ (measure_Union_null hz),
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff) }
end,
trimmed := begin
letI := null_measurable μ,
refine le_antisymm (λ s, _) (outer_measure.le_trim _),
rw outer_measure.trim_eq_infi,
dsimp,
clear _inst,
resetI,
rw measure_eq_infi s,
exact infi_le_infi (λ t, infi_le_infi $ λ st,
infi_le_infi2 $ λ ht, ⟨ht.null_measurable_set _, le_refl _⟩)
end }
instance completion.is_complete (μ : measure α) : (completion μ).is_complete :=
⟨λ z hz, null_null_measurable_set hz⟩
lemma measurable.ae_eq {α β} [measurable_space α] [measurable_space β] {μ : measure α}
[hμ : μ.is_complete] {f g : α → β} (hf : measurable f) (hfg : f =ᵐ[μ] g) :
measurable g :=
begin
intros s hs,
let t := {x | f x = g x},
have ht_compl : μ tᶜ = 0, by rwa [filter.eventually_eq, ae_iff] at hfg,
rw (set.inter_union_compl (g ⁻¹' s) t).symm,
refine measurable_set.union _ _,
{ have h_g_to_f : (g ⁻¹' s) ∩ t = (f ⁻¹' s) ∩ t,
{ ext,
simp only [set.mem_inter_iff, set.mem_preimage, and.congr_left_iff, set.mem_set_of_eq],
exact λ hx, by rw hx, },
rw h_g_to_f,
exact measurable_set.inter (hf hs) (measurable_set.compl_iff.mp (hμ.out tᶜ ht_compl)), },
{ exact hμ.out (g ⁻¹' s ∩ tᶜ) (measure_mono_null (set.inter_subset_right _ _) ht_compl), },
end
end is_complete
namespace measure_theory
lemma outer_measure.to_measure_zero [measurable_space α] : (0 : outer_measure α).to_measure
((le_top).trans outer_measure.zero_caratheodory.symm.le) = 0 :=
by rw [← measure.measure_univ_eq_zero, to_measure_apply _ _ measurable_set.univ,
outer_measure.coe_zero, pi.zero_apply]
section trim
/-- Restriction of a measure to a sub-sigma algebra.
It is common to see a measure `μ` on a measurable space structure `m0` as being also a measure on
any `m ≤ m0`. Since measures in mathlib have to be trimmed to the measurable space, `μ` itself
cannot be a measure on `m`, hence the definition of `μ.trim hm`.
This notion is related to `outer_measure.trim`, see the lemma
`to_outer_measure_trim_eq_trim_to_outer_measure`. -/
def measure.trim {m m0 : measurable_space α} (μ : @measure α m0) (hm : m ≤ m0) : @measure α m :=
@outer_measure.to_measure α m μ.to_outer_measure (hm.trans (le_to_outer_measure_caratheodory μ))
@[simp] lemma trim_eq_self [measurable_space α] {μ : measure α} : μ.trim le_rfl = μ :=
by simp [measure.trim]
variables {m m0 : measurable_space α} {μ : measure α} {s : set α}
lemma to_outer_measure_trim_eq_trim_to_outer_measure (μ : measure α) (hm : m ≤ m0) :
@measure.to_outer_measure _ m (μ.trim hm) = @outer_measure.trim _ m μ.to_outer_measure :=
by rw [measure.trim, to_measure_to_outer_measure]
@[simp] lemma zero_trim (hm : m ≤ m0) : (0 : measure α).trim hm = (0 : @measure α m) :=
by simp [measure.trim, outer_measure.to_measure_zero]
lemma trim_measurable_set_eq (hm : m ≤ m0) (hs : @measurable_set α m s) : μ.trim hm s = μ s :=
by simp [measure.trim, hs]
lemma le_trim (hm : m ≤ m0) : μ s ≤ μ.trim hm s :=
by { simp_rw [measure.trim], exact (@le_to_measure_apply _ m _ _ _), }
lemma measure_eq_zero_of_trim_eq_zero (hm : m ≤ m0) (h : μ.trim hm s = 0) : μ s = 0 :=
le_antisymm ((le_trim hm).trans (le_of_eq h)) (zero_le _)
lemma measure_trim_to_measurable_eq_zero {hm : m ≤ m0} (hs : μ.trim hm s = 0) :
μ (@to_measurable α m (μ.trim hm) s) = 0 :=
measure_eq_zero_of_trim_eq_zero hm (by rwa measure_to_measurable)
lemma ae_eq_of_ae_eq_trim {E} {hm : m ≤ m0} {f₁ f₂ : α → E}
(h12 : f₁ =ᶠ[@measure.ae α m (μ.trim hm)] f₂) :
f₁ =ᵐ[μ] f₂ :=
measure_eq_zero_of_trim_eq_zero hm h12
lemma restrict_trim (hm : m ≤ m0) (μ : measure α) (hs : @measurable_set α m s) :
@measure.restrict α m (μ.trim hm) s = (μ.restrict s).trim hm :=
begin
ext1 t ht,
rw [@measure.restrict_apply α m _ _ _ ht, trim_measurable_set_eq hm ht,
measure.restrict_apply (hm t ht),
trim_measurable_set_eq hm (@measurable_set.inter α m t s ht hs)],
end
instance finite_measure_trim (hm : m ≤ m0) [finite_measure μ] : @finite_measure α m (μ.trim hm) :=
{ measure_univ_lt_top :=
by { rw trim_measurable_set_eq hm (@measurable_set.univ _ m), exact measure_lt_top _ _, } }
end trim
end measure_theory
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `ae_measurable f μ`, is defined in the file `measure_space_def`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
section
open measure_theory
variables [measurable_space α] [measurable_space β]
{f g : α → β} {μ ν : measure α}
@[nontriviality, measurability]
lemma subsingleton.ae_measurable [subsingleton α] : ae_measurable f μ :=
subsingleton.measurable.ae_measurable
@[simp, measurability] lemma ae_measurable_zero_measure : ae_measurable f 0 :=
begin
nontriviality α, inhabit α,
exact ⟨λ x, f (default α), measurable_const, rfl⟩
end
lemma ae_measurable_iff_measurable [μ.is_complete] :
ae_measurable f μ ↔ measurable f :=
begin
split; intro h,
{ rcases h with ⟨g, hg_meas, hfg⟩,
exact hg_meas.ae_eq hfg.symm, },
{ exact h.ae_measurable, },
end
namespace ae_measurable
lemma mono_measure (h : ae_measurable f μ) (h' : ν ≤ μ) : ae_measurable f ν :=
⟨h.mk f, h.measurable_mk, eventually.filter_mono (ae_mono h') h.ae_eq_mk⟩
lemma mono_set {s t} (h : s ⊆ t) (ht : ae_measurable f (μ.restrict t)) :
ae_measurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
protected lemma mono' (h : ae_measurable f μ) (h' : ν ≪ μ) : ae_measurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
lemma ae_mem_imp_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
lemma ae_inf_principal_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :
f =ᶠ[μ.ae ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
@[measurability]
lemma add_measure {f : α → β} (hμ : ae_measurable f μ) (hν : ae_measurable f ν) :
ae_measurable f (μ + ν) :=
begin
let s := {x | f x ≠ hμ.mk f x},
have : μ s = 0 := hμ.ae_eq_mk,
obtain ⟨t, st, t_meas, μt⟩ : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 :=
exists_measurable_superset_of_null this,
let g : α → β := t.piecewise (hν.mk f) (hμ.mk f),
refine ⟨g, measurable.piecewise t_meas hν.measurable_mk hμ.measurable_mk, _⟩,
change μ {x | f x ≠ g x} + ν {x | f x ≠ g x} = 0,
suffices : μ {x | f x ≠ g x} = 0 ∧ ν {x | f x ≠ g x} = 0, by simp [this.1, this.2],
have ht : {x | f x ≠ g x} ⊆ t,
{ assume x hx,
by_contra h,
simp only [g, h, mem_set_of_eq, ne.def, not_false_iff, piecewise_eq_of_not_mem] at hx,
exact h (st hx) },
split,
{ have : μ {x | f x ≠ g x} ≤ μ t := measure_mono ht,
rw μt at this,
exact le_antisymm this bot_le },
{ have : {x | f x ≠ g x} ⊆ {x | f x ≠ hν.mk f x},
{ assume x hx,
simpa [ht hx, g] using hx },
apply le_antisymm _ bot_le,
calc ν {x | f x ≠ g x} ≤ ν {x | f x ≠ hν.mk f x} : measure_mono this
... = 0 : hν.ae_eq_mk }
end
@[measurability]
lemma smul_measure (h : ae_measurable f μ) (c : ℝ≥0∞) :
ae_measurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
lemma comp_measurable [measurable_space δ] {f : α → δ} {g : δ → β}
(hg : ae_measurable g (map f μ)) (hf : measurable f) : ae_measurable (g ∘ f) μ :=
⟨hg.mk g ∘ f, hg.measurable_mk.comp hf, ae_eq_comp hf hg.ae_eq_mk⟩
lemma comp_measurable' {δ} [measurable_space δ] {ν : measure δ} {f : α → δ} {g : δ → β}
(hg : ae_measurable g ν) (hf : measurable f) (h : map f μ ≪ ν) : ae_measurable (g ∘ f) μ :=
(hg.mono' h).comp_measurable hf
@[measurability]
lemma prod_mk {γ : Type*} [measurable_space γ] {f : α → β} {g : α → γ}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ x, (f x, g x)) μ :=
⟨λ a, (hf.mk f a, hg.mk g a), hf.measurable_mk.prod_mk hg.measurable_mk,
eventually_eq.prod_mk hf.ae_eq_mk hg.ae_eq_mk⟩
protected lemma null_measurable_set (h : ae_measurable f μ) {s : set β} (hs : measurable_set s) :
null_measurable_set μ (f ⁻¹' s) :=
begin
apply null_measurable_set_iff_ae.2,
refine ⟨(h.mk f) ⁻¹' s, h.measurable_mk hs, _⟩,
filter_upwards [h.ae_eq_mk],
assume x hx,
change (f x ∈ s) = ((h.mk f) x ∈ s),
rwa hx
end
end ae_measurable
@[simp] lemma ae_measurable_add_measure_iff :
ae_measurable f (μ + ν) ↔ ae_measurable f μ ∧ ae_measurable f ν :=
⟨λ h, ⟨h.mono_measure (measure.le_add_right (le_refl _)),
h.mono_measure (measure.le_add_left (le_refl _))⟩,
λ h, h.1.add_measure h.2⟩
@[simp, to_additive] lemma ae_measurable_one [has_one β] : ae_measurable (λ a : α, (1 : β)) μ :=
measurable_one.ae_measurable
@[simp] lemma ae_measurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
ae_measurable f (c • μ) ↔ ae_measurable f μ :=
⟨λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩,
λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
lemma ae_measurable_of_ae_measurable_trim {α} {m m0 : measurable_space α}
{μ : measure α} (hm : m ≤ m0) {f : α → β} (hf : @ae_measurable _ _ m _ f (μ.trim hm)) :
ae_measurable f μ :=
begin
let f' := @ae_measurable.mk _ _ m _ _ _ hf,
have hf'_meas : @measurable _ _ m _ f', from @ae_measurable.measurable_mk _ _ m _ _ _ hf,
have hff'_m : f' =ᶠ[@measure.ae _ m (μ.trim hm)] f,
from (@ae_measurable.ae_eq_mk _ _ m _ _ _ hf).symm,
have hff' : f' =ᵐ[μ] f, from ae_eq_of_ae_eq_trim hff'_m,
exact ⟨f', measurable.mono hf'_meas hm le_rfl, hff'.symm⟩,
end
lemma ae_measurable_restrict_of_measurable_subtype {s : set α}
(hs : measurable_set s) (hf : measurable (λ x : s, f x)) : ae_measurable f (μ.restrict s) :=
begin
by_cases h : nonempty β,
{ refine ⟨s.piecewise f (λ x, classical.choice h), _, (ae_restrict_iff' hs).mpr $ ae_of_all _
(λ x hx, (piecewise_eq_of_mem s _ _ hx).symm)⟩,
intros t ht,
rw piecewise_preimage,
refine measurable_set.union _ ((measurable_const ht).diff hs),
rw [← subtype.image_preimage_coe, ← preimage_comp],
exact hs.subtype_image (hf ht) },
{ exact (measurable_of_not_nonempty (mt (nonempty.map f) h) f).ae_measurable }
end
end
namespace is_compact
variables [topological_space α] [measurable_space α] {μ : measure α} {s : set α}
lemma finite_measure_of_nhds_within (hs : is_compact s) :
(∀ a ∈ s, μ.finite_at_filter (𝓝[s] a)) → μ s < ∞ :=
by simpa only [← measure.compl_mem_cofinite, measure.finite_at_filter]
using hs.compl_mem_sets_of_nhds_within
lemma finite_measure [locally_finite_measure μ] (hs : is_compact s) : μ s < ∞ :=
hs.finite_measure_of_nhds_within $ λ a ha, μ.finite_at_nhds_within _ _
lemma measure_zero_of_nhds_within (hs : is_compact s) :
(∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 :=
by simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhds_within
end is_compact
lemma metric.bounded.finite_measure [metric_space α] [proper_space α]
[measurable_space α] {μ : measure α} [locally_finite_measure μ] {s : set α}
(hs : metric.bounded s) :
μ s < ∞ :=
(measure_mono subset_closure).trans_lt (metric.compact_iff_closed_bounded.2
⟨is_closed_closure, metric.bounded_closure_of_bounded hs⟩).finite_measure
section piecewise
variables [measurable_space α] {μ : measure α} {s : set α} {f g : α → β}
lemma piecewise_ae_eq_restrict (hs : measurable_set s) : piecewise s f g =ᵐ[μ.restrict s] f :=
begin
rw [ae_restrict_eq hs],
exact (piecewise_eq_on s f g).eventually_eq.filter_mono inf_le_right
end
lemma piecewise_ae_eq_restrict_compl (hs : measurable_set s) :
piecewise s f g =ᵐ[μ.restrict sᶜ] g :=
begin
rw [ae_restrict_eq hs.compl],
exact (piecewise_eq_on_compl s f g).eventually_eq.filter_mono inf_le_right
end
end piecewise
section indicator_function
variables [measurable_space α] {μ : measure α} {s : set α} {f : α → β}
lemma ae_measurable.restrict [measurable_space β] (hfm : ae_measurable f μ) {s} :
ae_measurable f (μ.restrict s) :=
⟨ae_measurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
variables [has_zero β]
lemma indicator_ae_eq_restrict (hs : measurable_set s) : indicator s f =ᵐ[μ.restrict s] f :=
piecewise_ae_eq_restrict hs
lemma indicator_ae_eq_restrict_compl (hs : measurable_set s) : indicator s f =ᵐ[μ.restrict sᶜ] 0 :=
piecewise_ae_eq_restrict_compl hs
variables [measurable_space β]
lemma ae_measurable_indicator_iff {s} (hs : measurable_set s) :
ae_measurable (indicator s f) μ ↔ ae_measurable f (μ.restrict s) :=
begin
split,
{ assume h,
exact (h.mono_measure measure.restrict_le_self).congr (indicator_ae_eq_restrict hs) },
{ assume h,
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, _⟩,
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (ae_measurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans $ (indicator_ae_eq_restrict hs).symm),
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (ae_measurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm,
have : s.indicator f =ᵐ[μ.restrict s + μ.restrict sᶜ] s.indicator (ae_measurable.mk f h) :=
ae_add_measure_iff.2 ⟨A, B⟩,
simpa only [hs, measure.restrict_add_restrict_compl] using this },
end
lemma ae_measurable.indicator (hfm : ae_measurable f μ) {s} (hs : measurable_set s) :
ae_measurable (s.indicator f) μ :=
(ae_measurable_indicator_iff hs).mpr hfm.restrict
end indicator_function
|
7307dcb6199f359737528e8e27b9832f820f2db3
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/measure_theory/giry_monad.lean
|
b8ac01ad618e7c0bc73304d4bacdcec971e9b0a7
|
[
"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
| 8,542
|
lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import measure_theory.integration
/-!
# The Giry monad
Let X be a measurable space. The collection of all measures on X again
forms a measurable space. This construction forms a monad on
measurable spaces and measurable functions, called the Giry monad.
Note that most sources use the term "Giry monad" for the restriction
to *probability* measures. Here we include all measures on X.
See also `measure_theory/category/Meas.lean`, containing an upgrade of the type-level
monad to an honest monad of the functor `Measure : Meas ⥤ Meas`.
## References
* <https://ncatlab.org/nlab/show/Giry+monad>
## Tags
giry monad
-/
noncomputable theory
open_locale classical big_operators ennreal
open classical set filter
variables {α β γ δ ε : Type*}
namespace measure_theory
namespace measure
variables [measurable_space α] [measurable_space β]
/-- Measurability structure on `measure`: Measures are measurable w.r.t. all projections -/
instance : measurable_space (measure α) :=
⨆ (s : set α) (hs : measurable_set s), (borel ℝ≥0∞).comap (λμ, μ s)
lemma measurable_coe {s : set α} (hs : measurable_set s) : measurable (λμ : measure α, μ s) :=
measurable.of_comap_le $ le_supr_of_le s $ le_supr_of_le hs $ le_refl _
lemma measurable_of_measurable_coe (f : β → measure α)
(h : ∀(s : set α) (hs : measurable_set s), measurable (λb, f b s)) :
measurable f :=
measurable.of_le_map $ bsupr_le $ assume s hs, measurable_space.comap_le_iff_le_map.2 $
by rw [measurable_space.map_comp]; exact h s hs
lemma measurable_measure {μ : α → measure β} :
measurable μ ↔ ∀(s : set β) (hs : measurable_set s), measurable (λb, μ b s) :=
⟨λ hμ s hs, (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩
lemma measurable_map (f : α → β) (hf : measurable f) :
measurable (λμ : measure α, map f μ) :=
measurable_of_measurable_coe _ $ assume s hs,
suffices measurable (λ (μ : measure α), μ (f ⁻¹' s)),
by simpa [map_apply, hs, hf],
measurable_coe (hf hs)
lemma measurable_dirac :
measurable (measure.dirac : α → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
begin
simp only [dirac_apply', hs],
exact measurable_one.indicator hs
end
lemma measurable_lintegral {f : α → ℝ≥0∞} (hf : measurable f) :
measurable (λμ : measure α, ∫⁻ x, f x ∂μ) :=
begin
simp only [lintegral_eq_supr_eapprox_lintegral, hf, simple_func.lintegral],
refine measurable_supr (λ n, finset.measurable_sum _ (λ i _, _)),
refine measurable.const_mul _ _,
exact measurable_coe ((simple_func.eapprox f n).measurable_set_preimage _)
end
/-- Monadic join on `measure` in the category of measurable spaces and measurable
functions. -/
def join (m : measure (measure α)) : measure α :=
measure.of_measurable
(λs hs, ∫⁻ μ, μ s ∂m)
(by simp)
begin
assume f hf h,
simp [measure_Union h hf],
apply lintegral_tsum,
assume i, exact measurable_coe (hf i)
end
@[simp] lemma join_apply {m : measure (measure α)} :
∀{s : set α}, measurable_set s → join m s = ∫⁻ μ, μ s ∂m :=
measure.of_measurable_apply
@[simp] lemma join_zero : (0 : measure (measure α)).join = 0 :=
by { ext1 s hs, simp [hs] }
lemma measurable_join : measurable (join : measure (measure α) → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
by simp only [join_apply hs]; exact measurable_lintegral (measurable_coe hs)
lemma lintegral_join {m : measure (measure α)} {f : α → ℝ≥0∞} (hf : measurable f) :
∫⁻ x, f x ∂(join m) = ∫⁻ μ, ∫⁻ x, f x ∂μ ∂m :=
begin
rw [lintegral_eq_supr_eapprox_lintegral hf],
have : ∀n x,
join m (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x}) =
∫⁻ μ, μ ((⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x})) ∂m :=
assume n x, join_apply (simple_func.measurable_set_preimage _ _),
simp only [simple_func.lintegral, this],
transitivity,
have : ∀(s : ℕ → finset ℝ≥0∞) (f : ℕ → ℝ≥0∞ → measure α → ℝ≥0∞)
(hf : ∀n r, measurable (f n r)) (hm : monotone (λn μ, ∑ r in s n, r * f n r μ)),
(⨆n:ℕ, ∑ r in s n, r * ∫⁻ μ, f n r μ ∂m) =
∫⁻ μ, ⨆n:ℕ, ∑ r in s n, r * f n r μ ∂m,
{ assume s f hf hm,
symmetry,
transitivity,
apply lintegral_supr,
{ assume n,
exact finset.measurable_sum _ (assume r _, (hf _ _).const_mul _) },
{ exact hm },
congr, funext n,
transitivity,
apply lintegral_finset_sum,
{ assume r _, exact (hf _ _).const_mul _ },
congr, funext r,
apply lintegral_const_mul,
exact hf _ _ },
specialize this (λn, simple_func.range (simple_func.eapprox f n)),
specialize this
(λn r μ, μ (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {r})),
refine this _ _; clear this,
{ assume n r,
apply measurable_coe,
exact simple_func.measurable_set_preimage _ _ },
{ change monotone (λn μ, (simple_func.eapprox f n).lintegral μ),
assume n m h μ,
refine simple_func.lintegral_mono _ (le_refl _),
apply simple_func.monotone_eapprox,
assumption },
congr, funext μ,
symmetry,
apply lintegral_eq_supr_eapprox_lintegral,
exact hf
end
/-- Monadic bind on `measure`, only works in the category of measurable spaces and measurable
functions. When the function `f` is not measurable the result is not well defined. -/
def bind (m : measure α) (f : α → measure β) : measure β := join (map f m)
@[simp] lemma bind_zero_left (f : α → measure β) : bind 0 f = 0 :=
by simp [bind]
@[simp] lemma bind_zero_right (m : measure α) :
bind m (0 : α → measure β) = 0 :=
begin
ext1 s hs,
simp only [bind, hs, join_apply, coe_zero, pi.zero_apply],
rw [lintegral_map (measurable_coe hs) measurable_zero],
simp
end
@[simp] lemma bind_zero_right' (m : measure α) :
bind m (λ _, 0 : α → measure β) = 0 :=
bind_zero_right m
@[simp] lemma bind_apply {m : measure α} {f : α → measure β} {s : set β}
(hs : measurable_set s) (hf : measurable f) :
bind m f s = ∫⁻ a, f a s ∂m :=
by rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf]
lemma measurable_bind' {g : α → measure β} (hg : measurable g) : measurable (λm, bind m g) :=
measurable_join.comp (measurable_map _ hg)
lemma lintegral_bind {m : measure α} {μ : α → measure β} {f : β → ℝ≥0∞}
(hμ : measurable μ) (hf : measurable f) :
∫⁻ x, f x ∂ (bind m μ) = ∫⁻ a, ∫⁻ x, f x ∂(μ a) ∂m:=
(lintegral_join hf).trans (lintegral_map (measurable_lintegral hf) hμ)
lemma bind_bind {γ} [measurable_space γ] {m : measure α} {f : α → measure β} {g : β → measure γ}
(hf : measurable f) (hg : measurable g) :
bind (bind m f) g = bind m (λa, bind (f a) g) :=
measure.ext $ assume s hs,
begin
rw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf), lintegral_bind hf],
{ congr, funext a,
exact (bind_apply hs hg).symm },
exact (measurable_coe hs).comp hg
end
lemma bind_dirac {f : α → measure β} (hf : measurable f) (a : α) : bind (dirac a) f = f a :=
measure.ext $ λ s hs, by rw [bind_apply hs hf, lintegral_dirac' a ((measurable_coe hs).comp hf)]
lemma dirac_bind {m : measure α} : bind m dirac = m :=
measure.ext $ assume s hs,
by simp [bind_apply hs measurable_dirac, dirac_apply' _ hs, lintegral_indicator 1 hs]
lemma join_eq_bind (μ : measure (measure α)) : join μ = bind μ id :=
by rw [bind, map_id]
lemma join_map_map {f : α → β} (hf : measurable f) (μ : measure (measure α)) :
join (map (map f) μ) = map f (join μ) :=
measure.ext $ assume s hs,
begin
rw [join_apply hs, map_apply hf hs, join_apply,
lintegral_map (measurable_coe hs) (measurable_map f hf)],
{ congr, funext ν, exact map_apply hf hs },
exact hf hs
end
lemma join_map_join (μ : measure (measure (measure α))) :
join (map join μ) = join (join μ) :=
begin
show bind μ join = join (join μ),
rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id],
apply congr_arg (bind μ),
funext ν,
exact join_eq_bind ν
end
lemma join_map_dirac (μ : measure α) : join (map dirac μ) = μ :=
dirac_bind
lemma join_dirac (μ : measure α) : join (dirac μ) = μ :=
eq.trans (join_eq_bind (dirac μ)) (bind_dirac measurable_id _)
end measure
end measure_theory
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.